From 541eed8ea8cc0bb111ad0bd5223921313256a44f Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Wed, 27 Sep 2023 12:15:43 +0200 Subject: [PATCH 1/2] fix: avoid crash in DV with some chart types DHIS2-15882 --- src/visualizations/config/adapters/dhis_highcharts/chart.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/visualizations/config/adapters/dhis_highcharts/chart.js b/src/visualizations/config/adapters/dhis_highcharts/chart.js index 9174ad816..e50a52ca9 100644 --- a/src/visualizations/config/adapters/dhis_highcharts/chart.js +++ b/src/visualizations/config/adapters/dhis_highcharts/chart.js @@ -22,7 +22,11 @@ const getEvents = () => ({ if (item.legendSymbol) { item.legendSymbol.attr({ translateY: - -((item.legendItem.getBBox().height * 0.75) / 4) + + -( + (item.legendItem.label.getBBox().height * + 0.75) / + 4 + ) + item.legendSymbol.r / 2, }) } From 7068772326134d359f662a0a6a5086e1397e2db1 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Wed, 27 Sep 2023 15:32:23 +0200 Subject: [PATCH 2/2] fix: bring back the legend symbol --- .../config/generators/highcharts/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/visualizations/config/generators/highcharts/index.js b/src/visualizations/config/generators/highcharts/index.js index ca8ad2b3d..92a775910 100644 --- a/src/visualizations/config/generators/highcharts/index.js +++ b/src/visualizations/config/generators/highcharts/index.js @@ -20,6 +20,8 @@ function drawLegendSymbolWrap() { H.seriesTypes.column.prototype, 'drawLegendSymbol', function (proceed, legend, item) { + const legendItem = item.legendItem + if (this.options.legendSet?.legends?.length) { const ys = legend.baseline - legend.symbolHeight + 1, // y start x = legend.symbolWidth / 2 > 8 ? legend.symbolWidth / 2 : 8, // x start @@ -32,7 +34,7 @@ function drawLegendSymbolWrap() { .attr({ fill: legends[legends.length >= 5 ? 1 : 0].color, }) - .add(this.legendGroup) + .add(legendItem.group) this.chart.renderer .path(['M', x, ye, 'A', 1, 1, 0, 0, 0, x, ys, 'V', ye]) .attr({ @@ -42,13 +44,14 @@ function drawLegendSymbolWrap() { : legends.length - 1 ].color, }) - .add(this.legendGroup) + .add(legendItem.group) } else { var options = legend.options, symbolHeight = legend.symbolHeight, square = options.squareSymbol, symbolWidth = square ? symbolHeight : legend.symbolWidth - item.legendSymbol = this.chart.renderer + + legendItem.symbol = this.chart.renderer .rect( square ? (legend.symbolWidth - symbolHeight) / 2 : 0, legend.baseline - symbolHeight + 1, @@ -60,7 +63,7 @@ function drawLegendSymbolWrap() { .attr({ zIndex: 3, }) - .add(item.legendGroup) + .add(legendItem.group) } } )