You are here

public function FrxSVGGraph::generateGraphData in Forena Reports 7.5

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

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

File

src/Renderer/FrxSVGGraph.php, line 41
FrxSVGGraph php SVG Graph generator

Class

FrxSVGGraph

Namespace

Drupal\forena\Renderer

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) {
    Frx::Data()
      ->push($row, '_row');
    $trow = array();

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

    // Dimensions
    foreach ($series as $col) {
      $val = $this->frxReport
        ->replace($col, TRUE);
      if ($val != '' && $val !== NULL) {
        $trow[trim("{$col}", '{}')] = $val;
        @$counts[trim("{$col}", '{}')]++;
      }
    }
    foreach ($this->field_sources as $k => $src) {
      $trow[$k] = $this->frxReport
        ->replace($src, TRUE);
    }
    if (isset($this->field_sources['legend_entries'])) {
      $legend_str = $trow['legend_entries'];
      $legend[$legend_str] = $legend_str;
    }
    Frx::Data()
      ->pop();
    $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);
  }
}