diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php index 7267d6987..794f06cfa 100644 --- a/libraries/chart.lib.php +++ b/libraries/chart.lib.php @@ -8,6 +8,8 @@ require_once './libraries/chart/pma_pchart_multi_bar.php'; require_once './libraries/chart/pma_pchart_stacked_bar.php'; require_once './libraries/chart/pma_pchart_single_line.php'; require_once './libraries/chart/pma_pchart_multi_line.php'; +require_once './libraries/chart/pma_pchart_single_radar.php'; +require_once './libraries/chart/pma_pchart_multi_radar.php'; /** * Chart functions used to generate various types @@ -124,6 +126,9 @@ function PMA_chart_results($data, &$chartSettings) case 'line': $chart = new PMA_pChart_single_line($chartTitle, $chartData, $chartSettings); break; + case 'radar': + $chart = new PMA_pChart_single_radar($chartTitle, $chartData, $chartSettings); + break; } } } @@ -188,6 +193,9 @@ function PMA_chart_results($data, &$chartSettings) case 'line': $chart = new PMA_pChart_multi_line($chartTitle, $chartData, $chartSettings); break; + case 'radar': + $chart = new PMA_pChart_multi_radar($chartTitle, $chartData, $chartSettings); + break; } } else { diff --git a/libraries/chart/pma_pchart_multi_radar.php b/libraries/chart/pma_pchart_multi_radar.php new file mode 100644 index 000000000..e50634029 --- /dev/null +++ b/libraries/chart/pma_pchart_multi_radar.php @@ -0,0 +1,68 @@ +normalizeValues(); + } + + /* + * Get the largest value from the data and normalize all the other values. + */ + private function normalizeValues() + { + $maxValue = 0; + $keys = array_keys($this->data); + $valueKey = $keys[1]; + foreach ($this->data[$valueKey] as $values) { + if (max($values) > $maxValue) { + $maxValue = max($values); + } + } + + foreach ($this->data[$valueKey] as &$values) { + foreach ($values as &$value) { + $value = $value / $maxValue * 10; + } + } + } + + protected function drawGraphArea() + { + $this->chart->drawGraphArea(213,217,221,FALSE); + $this->chart->drawGraphAreaGradient(163,203,167,50); + } + + protected function drawChart() + { + parent::drawChart(); + + // when drawing radar graph we can specify the border from the top of + // graph area. We want border to be dynamic, so that either the top + // or the side of the radar is some distance away from the top or the + // side of the graph area. + $areaWidth = $this->chart->GArea_X2 - $this->chart->GArea_X1; + $areaHeight = $this->chart->GArea_Y2 - $this->chart->GArea_Y1; + + if ($areaHeight > $areaWidth) { + $borderOffset = ($areaHeight - $areaWidth) / 2; + } + else { + $borderOffset = 0; + } + + // the least ammount that radar is away from the graph area side. + $borderOffset += 40; + + // Draw the radar chart + $this->chart->drawRadarAxis($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),TRUE,$borderOffset,120,120,120,230,230,230,-1,2); + $this->chart->drawFilledRadar($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),50,$borderOffset); + } +} + +?> diff --git a/libraries/chart/pma_pchart_single.php b/libraries/chart/pma_pchart_single.php index a1b45e029..70b0b7101 100644 --- a/libraries/chart/pma_pchart_single.php +++ b/libraries/chart/pma_pchart_single.php @@ -20,8 +20,10 @@ abstract class PMA_pChart_single extends PMA_pChart_chart // Dataset definition $this->dataSet->AddPoint($values[1], "Values"); $this->dataSet->AddPoint($values[0], "Keys"); - $this->dataSet->AddAllSeries(); - //$DataSet->RemoveSerie("Serie3"); + + //$this->dataSet->AddAllSeries(); + $this->dataSet->AddSerie("Values"); + $this->dataSet->SetAbsciseLabelSerie("Keys"); $xLabel = $this->getXLabel(); @@ -35,8 +37,6 @@ abstract class PMA_pChart_single extends PMA_pChart_chart $yLabel = $keys[1]; } $this->dataSet->SetYAxisName($yLabel); - //$DataSet->SetYAxisUnit("°C"); - //$DataSet->SetXAxisUnit("h"); } } diff --git a/libraries/chart/pma_pchart_single_radar.php b/libraries/chart/pma_pchart_single_radar.php new file mode 100644 index 000000000..48c6d00f1 --- /dev/null +++ b/libraries/chart/pma_pchart_single_radar.php @@ -0,0 +1,59 @@ +normalizeValues(); + } + + /* + * Get the largest value from the data and normalize all the other values. + */ + private function normalizeValues() + { + $maxValue = 0; + $keys = array_keys($this->data); + $valueKey = $keys[1]; + $maxValue = max($this->data[$valueKey]); + + foreach ($this->data[$valueKey] as &$value) { + $value = $value / $maxValue * 10; + } + } + + protected function drawGraphArea() + { + $this->chart->drawGraphArea(213,217,221,FALSE); + $this->chart->drawGraphAreaGradient(163,203,167,50); + } + + protected function drawChart() + { + // when drawing radar graph we can specify the border from the top of + // graph area. We want border to be dynamic, so that either the top + // or the side of the radar is some distance away from the top or the + // side of the graph area. + $areaWidth = $this->chart->GArea_X2 - $this->chart->GArea_X1; + $areaHeight = $this->chart->GArea_Y2 - $this->chart->GArea_Y1; + + if ($areaHeight > $areaWidth) { + $borderOffset = ($areaHeight - $areaWidth) / 2; + } + else { + $borderOffset = 0; + } + + // the least ammount that radar is away from the graph area side. + $borderOffset += 40; + + $this->chart->drawRadarAxis($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),TRUE,$borderOffset,120,120,120,230,230,230,-1,2); + $this->chart->drawFilledRadar($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),50,$borderOffset); + } +} + +?> diff --git a/tbl_chart.php b/tbl_chart.php index 22b587f91..04e3db7fe 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -91,7 +91,7 @@ $url_params['reload'] = 1;