public function FrxSVGGraph::prepareGraph in Forena Reports 7.5
1 call to FrxSVGGraph::prepareGraph()
- FrxSVGGraph::render in src/
Renderer/ FrxSVGGraph.php - Render the graph.
File
- src/
Renderer/ FrxSVGGraph.php, line 234 - FrxSVGGraph php SVG Graph generator
Class
Namespace
Drupal\forena\RendererCode
public function prepareGraph() {
$skin_options = Frx::Data()
->getContext('skin');
$options = isset($skin_options['FrxSVGGraph']) ? $skin_options['FrxSVGGraph'] : array();
$attributes = $this
->mergedAttributes();
// Default in xpath for backward compatibility
// Legacy options. New charts should be generated using Frx:attribute syntax
if (isset($attributes['options'])) {
$attr_options = array();
parse_str($attributes['options'], $attr_options);
unset($attributes['options']);
foreach ($attr_options as $key => $value) {
$options[$key] = $this->frxReport
->replace($value, TRUE);
}
}
else {
$options = array_merge($options, $attributes);
}
// Main Graphing options
$path = $this
->extract('path', $options);
if (!$path) {
$path = $this
->extract('xpath', $options);
}
//Deprecated
if (!$path) {
$path = '*';
}
$group = $this
->extract('group', $options);
$series = @(array) $attributes['series'];
$sums = @(array) $attributes['sum'];
$key = @$attributes['key'];
if (!$key) {
$key = @$attributes['label'];
}
//Backward compatibility for old graphs.
$options['key'] = $key;
$dim = $this
->extract('dim', $options);
$this->wrap_label = (int) $this
->extract('wrap_label', $options);
if (!$key) {
$key = @$options['seriesx'];
}
// Deprecated
// Determine basic data to iterate.
$data = Frx::Data()
->currentContext();
if (is_object($data)) {
if (method_exists($data, 'xpath')) {
$nodes = $data
->xpath($path);
}
else {
$nodes = $data;
}
}
else {
$nodes = (array) $data;
}
// Force structured data
$options['structured_data'] = TRUE;
$options['structure'] = array(
'key' => 'key',
);
// Default in american colour;
$this->field_sources = array();
if (isset($options['color'])) {
$options['colour'] = $options['color'];
}
// Find out data that is designed to be sepecif to series.
$this->field_sources = array();
foreach ($options as $fk => $opt) {
if ($fk != 'value' && $fk != 'key' && $opt && !is_array($opt) && strpos($options[$fk], '{') !== FALSE) {
$this->field_sources[$fk] = $opt;
$options['structure'][$fk] = $fk;
}
}
if (isset($attributes['height'])) {
$options['height'] = $this->frxReport
->replace($attributes['height'], TRUE);
}
if (isset($attributes['width'])) {
$options['width'] = $this->frxReport
->replace($attributes['width'], TRUE);
}
if (isset($options['legend_entries']) && !isset($options['label']) && !isset($options['show_labels'])) {
$options['show_labels'] = FALSE;
}
$this->graphOptions = $options;
if ($group) {
$this
->generateGroupGraphData($nodes, $group, $series, $key, $dim, $sums);
}
else {
$this
->generateGraphData($nodes, $series, $key);
}
if (isset($this->graphOptions['legend_entries']) && !is_array($this->graphOptions['legend_entries'])) {
$this->graphOptions['legend_entries'] = explode('|', $this->graphOptions['legend_entries']);
}
}