You are here

function FrxSVGGraph::renderGraph in Forena Reports 8

1 call to FrxSVGGraph::renderGraph()
FrxSVGGraph::renderChart in src/FrxPlugin/Renderer/FrxSVGGraph.php

File

src/FrxPlugin/Renderer/FrxSVGGraph.php, line 378
FrxSVGGraph php SVG Graph generator

Class

FrxSVGGraph
SVG Graphing Renderer

Namespace

Drupal\forena\FrxPlugin\Renderer

Code

function renderGraph($type) {

  // IF we don't have a library give up
  static $jsinc = '';
  $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;

  // If the library isn't installed then quit.
  $this->graphOptions = $options;
  if (!class_exists('\\SVGGraph')) {
    return NULL;
  }
  $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 (!$jsinc && $this
    ->documentManager()
    ->getDocumentType() == 'drupal') {
    if (@(!$options['no_js'])) {

      //$js =  $graph->FetchJavascript();

      //$output .= $js;
    }
    $jsinc = TRUE;
  }
  return $output;
}