Skip to content

Commit efbd9ce

Browse files
committed
Fix issues with swap XY axis.
This pull request addresses multiple issues with swapping the X-Y axis. 1) Incorrect Y-axis legend configuration when there are multple datasets using diffent axes 2) Corrupted x-axis legend configuration when "show remainder disable paging" is selected.
1 parent 18c0fb4 commit efbd9ce

1 file changed

Lines changed: 45 additions & 49 deletions

File tree

classes/DataWarehouse/Visualization/AggregateChart.php

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -765,18 +765,40 @@ public function configure(
765765
}
766766
}
767767
}
768+
}
768769

769-
// if we have just reset summarizeDatasets, recompute limit, xAxis, and yAxis
770-
// with the new limit in place. Reset dataset _total to 1 to disable paging.
771-
if ($summarizeDataseries)
770+
if ($summarizeDataseries)
771+
{
772+
// disable ME paging by setting dataset size to 1
773+
$this->_total = 1;
774+
foreach($yAxisArray as $yAxisIndex => $yAxisObject)
772775
{
773-
$yAxisArray = $this->setAxes($summarizeDataseries, $offset, $x_axis, $font_size);
774-
$yAxisCount = count($yAxisArray);
776+
foreach($yAxisObject->series as $data_description_index => $yAxisDataObjectAndDescription)
777+
{
778+
$yAxisDataObject = $yAxisDataObjectAndDescription['yAxisDataObject'];
779+
$data_description = $yAxisDataObjectAndDescription['data_description'];
780+
$valuesCount = $yAxisDataObject->getCount(true);
781+
782+
if($valuesCount - $this->limit >= 1)
783+
{
784+
// only compute average (2nd parameter) if not drawing pie chart
785+
$yAxisDataObject->truncate($this->limit, $data_description->display_type!=='pie');
775786

776-
// disable ME paging by setting dataset size to 1
777-
$this->_total = 1;
787+
// now merge the x labels, if needed, from multiple datasets:
788+
$mergedlabels = $yAxisDataObject->getXValues();
789+
foreach( $mergedlabels as $idx => $label) {
790+
if ($label === null) {
791+
$tmp = $this->_xAxisDataObject->getValues();
792+
$mergedlabels[$idx] = $tmp[$idx];
793+
}
794+
}
795+
$this->_xAxisDataObject->setValues($mergedlabels);
796+
$this->_xAxisDataObject->getCount(true);
797+
$this->setXAxis($x_axis, $font_size);
798+
}
799+
}
778800
}
779-
} // !$summarizeDatasets
801+
}
780802

781803
// OK, now let's plot something...
782804
// Each of the yAxisObjects returned from getYAxis()
@@ -902,34 +924,6 @@ public function configure(
902924
$semDecimals = $yAxisDataObjectAndDescription['semDecimals'];
903925
$filterParametersTitle = $yAxisDataObjectAndDescription['filterParametersTitle'];
904926

905-
// ============= truncate (e.g. take average, min, max, sum of remaining values) ==========
906-
907-
// Usage tab charts and ME pie charts will have their datasets summarized as follows:
908-
$dataSeriesSummarized = false;
909-
if ( $summarizeDataseries )
910-
{
911-
$valuesCount = $yAxisDataObject->getCount(true);
912-
913-
if($valuesCount - $this->limit >= 1)
914-
{
915-
// only compute average (2nd parameter) if not drawing pie chart
916-
$yAxisDataObject->truncate($this->limit, $data_description->display_type!=='pie');
917-
918-
// now merge the x labels, if needed, from multiple datasets:
919-
$mergedlabels = $yAxisDataObject->getXValues();
920-
foreach( $mergedlabels as $idx => $label) {
921-
if ($label === null) {
922-
$tmp = $this->_xAxisDataObject->getValues();
923-
$mergedlabels[$idx] = $tmp[$idx];
924-
}
925-
}
926-
$this->_xAxisDataObject->setValues($mergedlabels);
927-
$this->_xAxisDataObject->getCount(true);
928-
$this->setXAxis($x_axis, $font_size);
929-
$dataSeriesSummarized = true;
930-
}
931-
} // summarizeDataseries
932-
933927
// ================ set color ================
934928

935929
// If the first data set in the series, pick up the yAxisColorValue.
@@ -962,13 +956,14 @@ public function configure(
962956
$yValues[] = $value;
963957
$colors[] = ($index == 0) ? $yAxisColor
964958
: '#'.str_pad(dechex($this->_colorGenerator->getColor() ), 6, '0', STR_PAD_LEFT);
965-
$drillable[] = true;
959+
$drillId = $yAxisDataObject->getXId($index);
960+
$drillable[] = ($drillId > -9999);
966961
// N.B.: These are drilldown labels.
967962
// X axis labels will be the same, but are plotted
968963
// from the x axis object instance variable.
969964
// See setXAxis() and _xAxisDataObject.
970965
$drilldown[] = array(
971-
'id' => $yAxisDataObject->getXId($index),
966+
'id' => $drillId,
972967
'label' => $yAxisDataObject->getXValue($index)
973968
);
974969

@@ -1017,13 +1012,15 @@ public function configure(
10171012
// set the label for each value:
10181013
foreach( $yAxisDataObject->getValues() as $index => $value)
10191014
{
1015+
$drillId = $yAxisDataObject->getXId($index);
10201016
$yValues[] = $value;
1021-
$drillable[] = true;
1017+
$drillable[] = ($drillId > -9999);
1018+
10221019
// N.B.: The following are drilldown labels.
10231020
// Labels on the x axis come from the x axis object
10241021
// (Though they are the same labels...)
10251022
$drilldown[] = array(
1026-
'id' => $yAxisDataObject->getXId($index),
1023+
'id' => $drillId,
10271024
'label' => $yAxisDataObject->getXValue($index)
10281025
);
10291026

@@ -1033,11 +1030,6 @@ public function configure(
10331030
}
10341031
}
10351032

1036-
$values_count = count($yValues);
1037-
if ($dataSeriesSummarized && $values_count > 0) {
1038-
$drillable[$values_count - 1] = false;
1039-
}
1040-
10411033
$zIndex = isset($data_description->z_index) ? $data_description->z_index : $data_description_index;
10421034

10431035
$dataSeriesName = $yAxisDataObject->getName();
@@ -1253,10 +1245,14 @@ public function configure(
12531245
$trace['xaxis'] = "x{$yIndex}";
12541246

12551247
if (!$swapXYDone) {
1256-
$xtmp = $this->_chart['layout']['xaxis'];
1257-
$ytmp = $this->_chart['layout']["{$yAxisName}"];
1258-
$this->_chart['layout']['yaxis'] = $xtmp;
1259-
$this->_chart['layout']["{$xAxisName}"] = $ytmp;
1248+
if ($yIndex == 1) {
1249+
$xtmp = $this->_chart['layout']["{$xAxisName}"];
1250+
$this->_chart['layout']["{$xAxisName}"] = $this->_chart['layout']["{$yAxisName}"];
1251+
$this->_chart['layout']["{$yAxisName}"] = $xtmp;
1252+
} else {
1253+
$this->_chart['layout']["{$xAxisName}"] = $this->_chart['layout']["{$yAxisName}"];
1254+
unset($this->_chart['layout']["{$yAxisName}"]);
1255+
}
12601256

12611257
$this->_chart['layout']["{$xAxisName}"]['side'] = ($yAxisIndex % 2 != 0) ? 'top' : 'bottom';
12621258
if ($this->_chart['layout']["{$xAxisName}"]['side'] == 'top') {

0 commit comments

Comments
 (0)