You are here

private static function ChartDataCollectorTable::initializeEmptyTable in Charts 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Element/ChartDataCollectorTable.php \Drupal\charts\Element\ChartDataCollectorTable::initializeEmptyTable()

Initializes an empty table.

Parameters

array $element: The element.

string $identifier_value: The identifier value.

Return value

array The element state storage.

1 call to ChartDataCollectorTable::initializeEmptyTable()
ChartDataCollectorTable::processDataCollectorTable in src/Element/ChartDataCollectorTable.php
Processes the element to render a table to collect a data for the chart.

File

src/Element/ChartDataCollectorTable.php, line 558

Class

ChartDataCollectorTable
Provides a chart data collector table form element.

Namespace

Drupal\charts\Element

Code

private static function initializeEmptyTable(array $element, $identifier_value) {
  $is_first_column = $identifier_value === self::FIRST_COLUMN;
  $columns = $element['#initial_columns'];
  $columns_arr = range(0, $columns - 1);
  $rows = $element['#initial_rows'];
  $rows_arr = range(0, $rows - 1);
  $data = [];
  $first_row_key = NULL;
  foreach ($rows_arr as $i) {
    $first_row_key = $first_row_key === NULL ? $i : $first_row_key;
    $table_first_row = $i === $first_row_key;
    $first_col_key = NULL;
    foreach ($columns_arr as $j) {
      $first_col_key = $first_col_key === NULL ? $j : $first_col_key;
      $table_first_col = $j === $first_col_key;

      // Used to skip category cell.
      $is_category_cell = $table_first_col && $table_first_row;
      $data[$i][$j]['data'] = '';
      if (!$is_category_cell && ($is_first_column && $i === $first_row_key || !$is_first_column && $j === $first_col_key)) {
        $data[$i][$j]['color'] = ChartsDefaultColors::randomColor();
      }
    }
  }
  return $data;
}