public function FrxGraphTemplate::generate in Forena Reports 7.3
Same name and namespace in other branches
- 6.2 templates/FrxGraphTemplate.inc \FrxGraphTemplate::generate()
- 7.2 templates/FrxGraphTemplate.inc \FrxGraphTemplate::generate()
Enter description here ...
Parameters
string $data_block:
SimpleXMLElement $xml:
array $config:
Overrides FrxTemplate::generate
File
- templates/
FrxGraphTemplate.inc, line 104
Class
Code
public function generate($xml, $config) {
$media = $this
->extract('media', $config);
$media = $media ? $media : 'FrxSVGGraph';
$div = $this
->blockDiv($config);
if ($media == 'FrxSVGGraph' && $config) {
// Clean series
//if (count($config['series'])==1) $config['series'] = $config['series'][1];
//if (count($config['seriesx'])==1) $config['seriesx'] = $config['seriesx'][1];
foreach ($config['series'] as $i => $series) {
if (!$series) {
unset($config['series'][$i]);
}
}
// 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';
}
$xpath = $this
->extract('xpath', $config);
$clause = $this
->extract('clause', $config);
$gen_table = $this
->extract('gen_table', $config);
$style = $this
->extract('style', $config);
if (!$style) {
$style = 'BarGraph';
}
$graph_options = FrxSVGGraph::graphOptions();
if (!isset($graph_options['styles'][$type][$style])) {
$styles = array_keys($graph_options['styles'][$type]);
$style = $styles[0];
}
if ($style) {
$type = $style;
}
$frxparms = array(
'type' => $type,
'renderer' => 'FrxSVGGraph',
'xpath' => $xpath,
);
$frxparms = array_merge($config, $frxparms);
$svg = $this
->addNode($div, 2, 'svg', NULL, NULL, $frxparms);
if ($gen_table) {
$columns = $this
->columns($xml);
$table = $this
->addNode($div, 4, 'table');
$thead = $this
->addNode($table, 6, 'thead');
$throw = $this
->addNode($thead, 8, 'tr');
$tbody = $this
->addNode($table, 6, 'tbody');
$tdrow = $this
->addNode($tbody, 8, 'tr', NULL, NULL, array(
'foreach' => '*',
));
if ($columns) {
foreach ($columns as $col) {
$this
->addNode($throw, 10, 'th', $col);
$this
->addNode($tdrow, 10, 'td', '{' . $col . '}');
}
}
}
}
}