From aae2498696137d10d428c67df871ba0bbe3b5cc2 Mon Sep 17 00:00:00 2001 From: Timofei Netisov Date: Mon, 25 Nov 2024 14:00:20 +0100 Subject: [PATCH] Fix logarithmic scale drawing candle-like shape Translate to logarithmic values points of y-axis for different parts of candle-like plot shapes. Change-Id: Ia99917f3b8d2718dae24e34e0ab3110e1719c16f --- src/charts/BoxCandleStick.js | 25 +++++++++++++++---------- src/modules/CoreUtils.js | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/charts/BoxCandleStick.js b/src/charts/BoxCandleStick.js index 7883200eb..876f15979 100644 --- a/src/charts/BoxCandleStick.js +++ b/src/charts/BoxCandleStick.js @@ -440,21 +440,26 @@ class BoxCandleStick extends Bar { } getOHLCValue(i, j) { const w = this.w - + const coreUtils = new CoreUtils(this.ctx, w) + const h = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleH[i][j], i); + const o = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleO[i][j], i); + const m = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleM[i][j], i); + const c = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleC[i][j], i); + const l = coreUtils.getLogValAtSeriesIndex(w.globals.seriesCandleL[i][j], i); return { o: this.isBoxPlot - ? w.globals.seriesCandleH[i][j] - : w.globals.seriesCandleO[i][j], + ? h + : o, h: this.isBoxPlot - ? w.globals.seriesCandleO[i][j] - : w.globals.seriesCandleH[i][j], - m: w.globals.seriesCandleM[i][j], + ? o + : h, + m: m, l: this.isBoxPlot - ? w.globals.seriesCandleC[i][j] - : w.globals.seriesCandleL[i][j], + ? c + : l, c: this.isBoxPlot - ? w.globals.seriesCandleL[i][j] - : w.globals.seriesCandleC[i][j], + ? l + : c, } } } diff --git a/src/modules/CoreUtils.js b/src/modules/CoreUtils.js index eb075bce3..3e5986eb1 100644 --- a/src/modules/CoreUtils.js +++ b/src/modules/CoreUtils.js @@ -540,6 +540,21 @@ class CoreUtils { return w.globals.invalidLogScale ? series : w.globals.seriesLog } + + getLogValAtSeriesIndex(val, seriesIndex) { + if (val === null) return null + const w = this.w + let yAxisIndex = w.globals.seriesYAxisReverseMap[seriesIndex] + if (w.config.yaxis[yAxisIndex] && w.config.yaxis[yAxisIndex].logarithmic) { + return this.getLogVal( + w.config.yaxis[yAxisIndex].logBase, + val, + seriesIndex + ) + } + return val + } + getBaseLog(base, value) { return Math.log(value) / Math.log(base) }