You are here

class FrxChart in Forena Reports 7.3

Same name and namespace in other branches
  1. 6.2 plugins/FrxChart.inc \FrxChart
  2. 7.2 plugins/FrxChart.inc \FrxChart

@file FrxChart Base class for chart generation implementations. @author davidmetzler

Hierarchy

Expanded class hierarchy of FrxChart

File

renderers/FrxChart.inc, line 8
FrxChart Base class for chart generation implementations. @author davidmetzler

View source
class FrxChart extends FrxRenderer {
  public $xy_data = FALSE;
  public function render() {

    // Get data from source
    $output = '';
    $options = array();
    $series = array();
    $seriesx = array();
    $data = array();
    $attributes = $this
      ->mergedAttributes();
    $path = isset($attributes['xpath']) ? $attributes['xpath'] : '*';
    $label = '';
    $links = '';
    $type = $attributes['type'];
    $link = @$attributes['link'];

    // Legacy options.  New charts should be generated using Frx:attribute syntax
    if (isset($attributes['options'])) {
      parse_str($attributes['options'], $options);
      unset($attributes['options']);
      $options = array_merge($attributes, $options);
    }
    else {
      $options = $attributes;
    }
    $series = @$options['series'];
    if (isset($options['seriesx'])) {
      $seriesx = $options['seriesx'];
      unset($options['seriesx']);
    }
    if (isset($options['label'])) {
      $label = $options['label'];
      unset($options['label']);
    }
    foreach ($options as $key => $value) {
      $options[$key] = $this->teng
        ->replace($value, TRUE);
    }
    if (isset($attributes['height'])) {
      $options['height'] = $this->teng
        ->replace($attributes['height']);
    }
    if (isset($attributes['width'])) {
      $options['width'] = $this->teng
        ->replace($attributes['width']);
    }

    // Extract chart series data from xml.
    if ($series) {
      foreach ((array) $series as $i => $d) {
        if ($seriesx) {
          $this->xy_data = TRUE;
          $data[] = $this
            ->xmlToValues($path, $d, $seriesx[$i], TRUE);
        }
        else {
          $data[] = $this
            ->xmlToValues($path, $d, $label, FALSE);
        }
      }
    }
    if ($link) {
      $links = $this
        ->xmlToValues($path, $link, $label);
    }

    // Deal with rare case where attributes are supposed to come from data
    if (@$attributes['color'] && !is_array($attributes['color']) && strpos($attributes['color'], '{') !== FALSE) {
      $options['colors'] = $this
        ->xmlToValues($path, $attributes['color']);
    }

    // Deal with rare case where legend are supposed to come from data
    if (@$attributes['legend_entry'] && !is_array($attributes['legend_entry']) && strpos($attributes['legend_entry'], '{') !== FALSE) {
      $options['legend_entries'] = $this
        ->xmlToValues($path, $attributes['legend_entry']);
    }
    if ($data) {
      if (method_exists($this, 'renderChart')) {
        $output = $this
          ->renderChart($type, $data, $options, $links);
      }
    }
    return $output;
  }
  public function xmlToValues($path, $data_path, $label_path = '', $pairs = FALSE) {
    $do = Frx::Data();
    $data = $do
      ->currentContext();
    $values = array();
    if (is_object($data)) {
      $nodes = $data
        ->xpath($path);
      if ($nodes) {
        foreach ($nodes as $i => $node) {
          $do
            ->push($node, $this->id);
          $val = $this->teng
            ->replace($data_path, TRUE);
          if ($label_path) {
            $key = strip_tags($this->teng
              ->replace($label_path, FALSE));
          }
          else {
            $key = $i;
          }
          if ($pairs && $label_path) {
            $values[] = array(
              floatval($key),
              floatval($val),
            );
          }
          else {
            $values[$key] = $val;
          }
          $do
            ->pop();
        }
      }
    }
    return $values;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxChart::$xy_data public property
FrxChart::render public function Overrides FrxRenderer::render
FrxChart::xmlToValues public function
FrxRenderer::$dataProvider public property
FrxRenderer::$format public property
FrxRenderer::$frxAttributes public property
FrxRenderer::$frxReport public property
FrxRenderer::$htmlAttributes public property
FrxRenderer::$id public property
FrxRenderer::$name public property
FrxRenderer::$reportDocDomNode public property
FrxRenderer::$reportDocNode public property
FrxRenderer::$teng public property
FrxRenderer::addAttributes public static function
FrxRenderer::drupalRender public function Render a drupal form in a forena template
FrxRenderer::initReportNode public function
FrxRenderer::innerXML public function Return the inside xml of the current node
FrxRenderer::mergedAttributes public function Standard php array containing merged attributes Enter description here ...
FrxRenderer::replacedAttributes public function
FrxRenderer::replaceTokens public function
FrxRenderer::__construct public function 1