From 68907d2ef4dc1e200eeaa03c2b092229a68b9a99 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Wed, 3 Apr 2024 13:15:32 +0200 Subject: [PATCH] fix: avoid crash in DV with some chart types (DHIS2-15882) [24.x] (#1651) * fix: avoid crash in DV with some chart types DHIS2-15882 (#1582) * fix: upgrade highcharts to be compatible with code change --------- Co-authored-by: Edoardo Sabadelli --- package.json | 2 +- .../config/adapters/dhis_highcharts/chart.js | 6 +++++- .../config/generators/highcharts/index.js | 11 +++++++---- yarn.lock | 8 ++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index f1d217847..a98d0d6a2 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "classnames": "^2.3.1", "d2-utilizr": "^0.2.16", "d3-color": "^1.2.3", - "highcharts": "^10.2.0", + "highcharts": "^10.3.3", "lodash": "^4.17.21", "mathjs": "^9.4.2", "react-beautiful-dnd": "^10.1.1", 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, }) } 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) } } ) diff --git a/yarn.lock b/yarn.lock index 6d7f4cbab..5da995a54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10517,10 +10517,10 @@ hex-color-regex@^1.1.0: resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e" integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ== -highcharts@^10.2.0: - version "10.2.0" - resolved "https://registry.yarnpkg.com/highcharts/-/highcharts-10.2.0.tgz#646b1c80fb4add9e35e5813bd87419ccdf1fc6b7" - integrity sha512-MvLo4dzR2Vo7Y85dsqJ07uabBXSSIRKRRdW4l9IGP55h2jYWNm/m9JBszVVxySH5Lda6g+Ins9NdGppZJpjNCA== +highcharts@^10.3.3: + version "10.3.3" + resolved "https://registry.yarnpkg.com/highcharts/-/highcharts-10.3.3.tgz#b8acca24f2d4b1f2f726540734166e59e07b35c4" + integrity sha512-r7wgUPQI9tr3jFDn3XT36qsNwEIZYcfgz4mkKEA6E4nn5p86y+u1EZjazIG4TRkl5/gmGRtkBUiZW81g029RIw== highlight.js@^10.1.1, highlight.js@~10.5.0: version "10.5.0"