From 7da902a948336f024a805ac0350b4fe7e061ba38 Mon Sep 17 00:00:00 2001 From: cartbeforehorse Date: Wed, 24 Apr 2024 02:18:36 +0200 Subject: [PATCH] fix heatmap yaxis offset #2033 --- src/modules/axes/AxesUtils.js | 18 +++++++----------- src/modules/axes/YAxis.js | 22 ++++++++++------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/modules/axes/AxesUtils.js b/src/modules/axes/AxesUtils.js index ff46cc0f3..68165da5d 100644 --- a/src/modules/axes/AxesUtils.js +++ b/src/modules/axes/AxesUtils.js @@ -245,21 +245,17 @@ export default class AxesUtils { let graphics = new Graphics(this.ctx) // initial label position = 0; - let t = w.globals.translateY + let tY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY + if (w.globals.isBarHorizontal) { + tY = 0 + } else if (w.config.chart.type === 'heatmap') { + tY += labelsDivider / 2 + } if (axisTicks.show && tickAmount > 0) { if (w.config.yaxis[realIndex].opposite === true) x = x + axisTicks.width for (let i = tickAmount; i >= 0; i--) { - let tY = - t + tickAmount / 10 + w.config.yaxis[realIndex].labels.offsetY - 1 - if (w.globals.isBarHorizontal) { - tY = labelsDivider * i - } - - if (w.config.chart.type === 'heatmap') { - tY = tY + labelsDivider / 2 - } let elTick = graphics.drawLine( x + axisBorder.offsetX - axisTicks.width + axisTicks.offsetX, tY + axisTicks.offsetY, @@ -268,7 +264,7 @@ export default class AxesUtils { axisTicks.color ) elYaxis.add(elTick) - t = t + labelsDivider + tY += labelsDivider } } } diff --git a/src/modules/axes/YAxis.js b/src/modules/axes/YAxis.js index 35608b6b8..13faf920d 100644 --- a/src/modules/axes/YAxis.js +++ b/src/modules/axes/YAxis.js @@ -60,8 +60,6 @@ export default class YAxis { // labelsDivider is simply svg height/number of ticks let labelsDivider = w.globals.gridHeight / tickAmount - // initial label position = 0; - let l = w.globals.translateY let lbFormatter = w.globals.yLabelFormatters[realIndex] let labels = w.globals.yAxisScale[realIndex].result.slice() @@ -70,6 +68,14 @@ export default class YAxis { let firstLabel = '' if (w.config.yaxis[realIndex].labels.show) { + // initial label position = 0; + let lY = w.globals.translateY + w.config.yaxis[realIndex].labels.offsetY + if (w.globals.isBarHorizontal) { + lY = 0 + } else if (w.config.chart.type === 'heatmap') { + lY -= labelsDivider / 2 + } + lY += parseInt(w.config.yaxis[realIndex].labels.style.fontSize, 10) / 3 for (let i = tickAmount; i >= 0; i--) { let val = labels[i] @@ -99,17 +105,9 @@ export default class YAxis { const getForeColor = () => { return Array.isArray(yColors) ? yColors[i] : yColors } - - let offsetY = w.config.yaxis[realIndex].labels.offsetY - - if (w.config.chart.type === 'heatmap') { - const divisor = w.globals.gridHeight / w.globals.series.length - 1 - offsetY = offsetY - divisor / 2 - } - let label = graphics.drawText({ x: xPad, - y: l + tickAmount / 10 + offsetY + 1, + y: lY, text: val, textAnchor, fontSize: yaxisFontSize, @@ -139,7 +137,7 @@ export default class YAxis { `rotate(${w.config.yaxis[realIndex].labels.rotate} ${firstabelRotatingCenter.x} ${labelRotatingCenter.y})` ) } - l = l + labelsDivider + lY += labelsDivider } }