You are here

public function FrxSVGGraph::generateGraphData in Forena Reports 8

Same name in this branch
  1. 8 src/FrxPlugin/Template/FrxSVGGraph.php \Drupal\forena\Template\FrxSVGGraph::generateGraphData()
  2. 8 src/FrxPlugin/Renderer/FrxSVGGraph.php \Drupal\forena\FrxPlugin\Renderer\FrxSVGGraph::generateGraphData()

Re-architect the data into something that the graphing engine can work with

1 call to FrxSVGGraph::generateGraphData()
FrxSVGGraph::prepareGraph in src/FrxPlugin/Template/FrxSVGGraph.php

File

src/FrxPlugin/Template/FrxSVGGraph.php, line 42
FrxSVGGraph php SVG Graph generator

Class

FrxSVGGraph

Namespace

Drupal\forena\Template

Code

public function generateGraphData(&$data, $series, $key) {

  // Default controlling attributes
  $counts = array();
  $legend = array();
  $this->graphOptions['structure']['value'] = array();
  foreach ($series as $col) {
    $this->graphOptions['structure']['value'][] = trim("{$col}", '{}');
  }
  $this->graphData = array();
  foreach ($data as $row) {
    $this
      ->pushData($row, '_row');
    $trow = array();

    // Base group
    $trow['key'] = $this->wrap_label ? wordwrap($this->report
      ->replace($key, TRUE), $this->wrap_label) : $this->report
      ->replace($key, TRUE);

    // Dimensions
    foreach ($series as $col) {
      $val = $this->report
        ->replace($col, TRUE);
      if ($val != '' && $val !== NULL) {
        $trow[trim("{$col}", '{}')] = $val;
        @$counts[trim("{$col}", '{}')]++;
      }
    }
    foreach ($this->field_sources as $k => $src) {
      $trow[$k] = $this->report
        ->replace($src, TRUE);
    }
    if (isset($this->field_sources['legend_entries'])) {
      $legend_str = $trow['legend_entries'];
      $legend[$legend_str] = $legend_str;
    }
    $this
      ->popData();
    $this->graphData[] = $trow;
  }
  $this->counts = $counts;

  // Deal with rare case where legend are supposed to come from data
  if (isset($this->field_sources['legend_entries'])) {
    $this->graphOptions['legend_entries'] = array_values($legend);
  }
}