From 6048260fc022dcc805185d559dc519d375e0bbfa Mon Sep 17 00:00:00 2001 From: Sergey Tretiak Date: Tue, 21 Nov 2023 18:16:20 +0200 Subject: [PATCH 1/2] chore: add `currentData` for the figure `attrs` callback --- src/component/Indicator.ts | 1 + src/view/IndicatorView.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/component/Indicator.ts b/src/component/Indicator.ts index 75178d64f..ecb518669 100644 --- a/src/component/Indicator.ts +++ b/src/component/Indicator.ts @@ -50,6 +50,7 @@ export interface IndicatorFigureCallbackBrother { export type IndicatorFigureAttrsCallbackCoordinate = IndicatorFigureCallbackBrother & { x: number }> export interface IndicatorFigureAttrsCallbackParams { + currentData: D coordinate: IndicatorFigureAttrsCallbackCoordinate bounding: Bounding barSpace: BarSpace diff --git a/src/view/IndicatorView.ts b/src/view/IndicatorView.ts index 87c2baac0..765756321 100644 --- a/src/view/IndicatorView.ts +++ b/src/view/IndicatorView.ts @@ -119,7 +119,8 @@ export default class IndicatorView extends CandleBarView { bounding, barSpace, xAxis, - yAxis + yAxis, + currentData: currentIndicatorData }) if (!isValid(attrs)) { switch (figure.type) { From 3279db071edb04cb4dc7c20b926d19544c1472bf Mon Sep 17 00:00:00 2001 From: liihuu Date: Tue, 4 Jun 2024 23:56:19 +0800 Subject: [PATCH 2/2] chore: add `currentData` for the figure `attrs` callback feat: indicator figure attrs callback params add `data` Co-authored-by: _serg_ --- src/component/Indicator.ts | 4 +++- src/view/IndicatorView.ts | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/component/Indicator.ts b/src/component/Indicator.ts index bde5301ca..0c9fd223d 100644 --- a/src/component/Indicator.ts +++ b/src/component/Indicator.ts @@ -49,8 +49,10 @@ export interface IndicatorFigureCallbackBrother { export type IndicatorFigureAttrsCallbackCoordinate = IndicatorFigureCallbackBrother & { x: number }> +export type IndicatorFigureAttrsCallbackData = IndicatorFigureCallbackBrother + export interface IndicatorFigureAttrsCallbackParams { - currentData: D + data: IndicatorFigureAttrsCallbackData> coordinate: IndicatorFigureAttrsCallbackCoordinate bounding: Bounding barSpace: BarSpace diff --git a/src/view/IndicatorView.ts b/src/view/IndicatorView.ts index 900f04ae0..02ee9aa71 100644 --- a/src/view/IndicatorView.ts +++ b/src/view/IndicatorView.ts @@ -105,36 +105,36 @@ export default class IndicatorView extends CandleBarView { const { dataIndex, x } = data const prevX = xAxis.convertToPixel(dataIndex - 1) const nextX = xAxis.convertToPixel(dataIndex + 1) - const prevIndicatorData = result[dataIndex - 1] ?? {} - const currentIndicatorData = result[dataIndex] ?? {} - const nextIndicatorData = result[dataIndex + 1] ?? {} + const prevData = result[dataIndex - 1] ?? null + const currentData = result[dataIndex] ?? null + const nextData = result[dataIndex + 1] ?? null const prevCoordinate = { x: prevX } const currentCoordinate = { x } const nextCoordinate = { x: nextX } indicator.figures.forEach(({ key }) => { - const prevValue = prevIndicatorData[key] + const prevValue = prevData?.[key] if (isNumber(prevValue)) { prevCoordinate[key] = yAxis.convertToPixel(prevValue) } - const currentValue = currentIndicatorData[key] + const currentValue = currentData?.[key] if (isNumber(currentValue)) { currentCoordinate[key] = yAxis.convertToPixel(currentValue) } - const nextValue = nextIndicatorData[key] + const nextValue = nextData?.[key] if (isNumber(nextValue)) { nextCoordinate[key] = yAxis.convertToPixel(nextValue) } }) eachFigures(dataList, indicator, dataIndex, defaultStyles, (figure: IndicatorFigure, figureStyles: IndicatorFigureStyle) => { - if (isValid(currentIndicatorData[figure.key])) { + if (isValid(currentData?.[figure.key])) { const valueY = currentCoordinate[figure.key] let attrs = figure.attrs?.({ + data: { prev: prevData, current: currentData, next: nextData }, coordinate: { prev: prevCoordinate, current: currentCoordinate, next: nextCoordinate }, bounding, barSpace, xAxis, - yAxis, - currentData: currentIndicatorData + yAxis }) if (!isValid(attrs)) { switch (figure.type) { @@ -147,7 +147,7 @@ export default class IndicatorView extends CandleBarView { const baseValue = figure.baseValue ?? yAxis.getExtremum().min const baseValueY = yAxis.convertToPixel(baseValue) let height = Math.abs(baseValueY - (valueY as number)) - if (baseValue !== currentIndicatorData[figure.key]) { + if (baseValue !== currentData?.[figure.key]) { height = Math.max(1, height) } let y: number @@ -159,7 +159,7 @@ export default class IndicatorView extends CandleBarView { attrs = { x: x - halfGapBar, y, - width: gapBar, + width: Math.max(1, halfGapBar * 2), height } break