miloschuman\highcharts\SeriesDataHelper::process PHP Method

process() public method

Processes the source data and returns the result.
public process ( ) : array
return array the processed data
    public function process()
    {
        if (empty($this->data)) {
            throw new InvalidConfigException('Missing required "data" property.');
        }
        $this->normalizeColumns();
        // return simple array for single-column configs
        if (count($this->columns) === 1) {
            $column = $this->columns[0];
            $data = ArrayHelper::getColumn($this->data->models, $column[0]);
            return array_map($column[1], $data);
        }
        // use two-dimensional array for multi-column configs
        $data = [];
        foreach ($this->data->models as $model) {
            $row = [];
            foreach ($this->columns as $index => $column) {
                $row[$index] = call_user_func($column[1], $model[$column[0]]);
            }
            $data[] = $row;
        }
        return $data;
    }

Usage Example

 /**
  * test basic data processing using current setup
  */
 public function testBasicProcessing()
 {
     $data = [['date_measured' => '2016-03-01 03:00:00', 'open' => 3.14], ['date_measured' => '2016-03-02 03:00:00', 'open' => 4.14]];
     $columns = [['date_measured', 'datetime'], 'open:int'];
     $dataProvider = $this->setupDataProvider($data);
     $helper = new SeriesDataHelper($dataProvider, $columns);
     $results = $helper->process();
     $this->assertEquals(strtotime('2016-03-01 03:00:00') * 1000, $results[0][0]);
     $this->assertEquals(3, $results[0][1]);
     $this->assertEquals(strtotime('2016-03-02 03:00:00') * 1000, $results[1][0]);
     $this->assertEquals(4, $results[1][1]);
 }