/** * Prepare bar/line chart specific data and parameters * * Data can be an array of y values, or an array of [label, value] pairs; * While labels are used only on the first series with labels on * subsequent series being ignored * * @since 1.8 * * @param array $rawdata label => value * @return array */ private function prepareBarData($rawdata) { // Init $total = 0; $mode = 'single'; // Find min and max values to determine the graphs axis parameter $maxValue = count($rawdata) == 0 ? 0 : max($rawdata); if ($this->params['min'] === false) { $minValue = count($rawdata) == 0 ? 0 : min($rawdata); } else { $minValue = $this->params['min']; } // Get number ticks $data['numbersticks'] = SRFjqPlot::getNumbersTicks($minValue, $maxValue); // Reorganize the data in accordance with the bar/line chart req. foreach ($rawdata as $key => $value) { if ($value >= $this->params['min']) { $data['series'][] = array($key, $value); $total = $total + $value; } } // Bar/line module SMWOutputs::requireResource('ext.srf.jqplot.bar'); // Highlighter plugin if ($this->params['highlighter']) { SMWOutputs::requireResource('ext.srf.jqplot.highlighter'); } // Pointlabels plugin if (in_array($this->params['datalabels'], array('value', 'label', 'percent'))) { SMWOutputs::requireResource('ext.srf.jqplot.pointlabels'); } return array('data' => array($data['series']), 'ticks' => $data['numbersticks'], 'labels' => array_keys($data['series']), 'numbers' => array_values($data['series']), 'max' => $maxValue, 'total' => $total, 'mode' => $mode, 'series' => array(), 'renderer' => $this->params['charttype'], 'parameters' => $this->addCommonOptions()); }
/** * Fetch numbers ticks * * @since 1.8 * * @param array $data */ protected function getNumbersTicks(array $data) { // Only look for numeric values that have been stored $numerics = array_values($data['series']); // Find min and max values to determine the graphs axis parameter $maxValue = count($numerics) == 0 ? 0 : max(array_map("max", $numerics)); if ($this->params['min'] === false) { $minValue = count($numerics) == 0 ? 0 : min(array_map("min", $numerics)); } else { $minValue = $this->params['min']; } // Get ticks info $data['numbersticks'] = SRFjqPlot::getNumbersTicks($minValue, $maxValue); $data['total'] = array_sum(array_map("array_sum", $numerics)); return $data; }