You are here

public function FrxSVGGraph::generate in Forena Reports 7.4

Generate the template from the configuration.

Parameters

string $data_block:

SimpleXMLElement $xml:

array $config:

Overrides FrxRenderer::generate

File

renderers/FrxSVGGraph.inc, line 612

Class

FrxSVGGraph

Code

public function generate($xml, &$config) {
  $config['class'] = get_class($this);
  $media = 'FrxSVGGraph';
  $div = $this
    ->blockDiv($config);
  $this
    ->removeChildren($div);

  // PUt on the header
  if (isset($config['header']['value'])) {
    $header = $this
      ->extract('header', $config);
    $this
      ->addFragment($div, $header['value']);
  }

  // Determine columns and make sure we represent them all
  $found_columns = $this
    ->columns($xml);
  if (!$found_columns) {
    $found_columns = $this
      ->columns($xml, '/*');
  }
  $numeric_columns = $this->numeric_columns;
  $new_columns = @$config['crosstab_columns'] ? FALSE : TRUE;
  foreach ($found_columns as $column => $label) {
    $token = '{' . $column . '}';
    if ($new_columns) {
      $type = isset($numeric_columns[$column]) ? 'value' : 'heading';
    }
    else {
      $type = 'ignore';
    }
    if (!isset($config['crosstab_columns'][$column])) {
      $this
        ->addColumn($type, '{' . $column . '}', $column, $config);
    }
  }

  // Generate the grouping row
  $group = '';
  $dim = array();
  foreach ($config['crosstab_columns'] as $col) {
    if ($col['type'] == 'heading') {
      $group[] = $col['contents'];
    }
    if ($col['type'] == 'crosstab') {
      $dim = $col['contents'];
    }
  }
  if ($group) {
    $config['group'] = is_array($group) ? implode(' ', $group) : $group;
  }
  if ($dim) {
    $config['dim'] = $dim;
  }
  $this
    ->seriesFromColumns($config);
  $this
    ->keyFromColumns($config);

  // Clean colors
  if (isset($config['colors'])) {
    foreach ($config['colors'] as $i => $color) {
      if (!$color) {
        unset($color[$i]);
      }
    }
  }
  $type = $this
    ->extract('type', $config);
  if (!$type) {
    $type = 'Bar Graph';
  }
  $gen_table = $this
    ->extract('gen_table', $config);

  // LImit the config
  $frxattrs = $config;

  // Unset common option configurations?
  foreach ($this->unset_attrs as $k) {
    unset($frxattrs[$k]);
  }
  $frxattrs = $this
    ->arrayAttributes($frxattrs);
  $frxattrs['renderer'] = 'FrxSVGGraph';
  $frxattrs['type'] = $type;
  $this
    ->setFirstNode($div, 2, 'svg', NULL, NULL, $frxattrs);
  if (isset($config['footer']['value'])) {
    $this
      ->addFragment($div, $config['footer']['value']);
  }
  if ($gen_table) {
    if ($group && $dim) {
      $this
        ->generateCrossTab($xml, $config, $div, $group, $dim);
    }
    else {
      $this
        ->generateTable($xml, $config, $div);
    }
  }
}