You are here

function FrxSVGGraph::renderGraph in Forena Reports 7.4

Same name and namespace in other branches
  1. 6.2 plugins/FrxSVGGraph.inc \FrxSVGGraph::renderGraph()
  2. 7.2 plugins/FrxSVGGraph.inc \FrxSVGGraph::renderGraph()
  3. 7.3 renderers/FrxSVGGraph.inc \FrxSVGGraph::renderGraph()
1 call to FrxSVGGraph::renderGraph()
FrxSVGGraph::renderChart in renderers/FrxSVGGraph.inc

File

renderers/FrxSVGGraph.inc, line 434

Class

FrxSVGGraph

Code

function renderGraph($type) {
  $options = $this
    ->replaceTokens($this->graphOptions);
  $data = $this->graphData;
  if (!isset($options['scatter_2d']) && ($type == 'ScatterGraph' || $type == 'MultiScatterGraph') && $this->xy_data && !isset($options['scatter_2d'])) {
    $options['scatter_2d'] = TRUE;
  }
  else {
    $options['scatter_2d'] = (bool) @$options['scatter_2d'];
  }

  // Sanitize label option for SVG Graph 2.20 and greater
  if (isset($options['label']) && !is_array($options['label'])) {
    unset($options['label']);
  }
  $width = @$options['width'] ? @$options['width'] : 600;
  $height = @$options['height'] ? @$options['height'] : 400;
  $graph = new SVGGraph($width, $height, $options);
  $this->graph = $graph;
  $graph
    ->Values($data);
  if (isset($options['colour']) && is_array($options['colour'])) {
    $graph
      ->Colours($options['colour']);
  }

  // Generate the graph
  $output = $graph
    ->Fetch($type, FALSE);

  // Add a viewbox to be compatible with Prince PDF generation.
  if (!@$options['noviewbox']) {
    $options['auto_fit'] = true;
  }
  if (!@$options['noviewbox'] && !strpos($output, 'viewBox')) {
    $output = str_replace('<svg width', "<svg viewBox='0 0 {$width} {$height}' width", $output);
  }
  if ($this->format == 'web') {
    if (@(!$options['no_js'])) {
      $js = $graph
        ->FetchJavascript();
      $output .= $js;
    }
  }
  return $output;
}