diff --git a/src/component/Indicator.ts b/src/component/Indicator.ts index da1d4b5b6..73418a6b4 100644 --- a/src/component/Indicator.ts +++ b/src/component/Indicator.ts @@ -49,7 +49,10 @@ export interface IndicatorFigureCallbackBrother { export type IndicatorFigureAttrsCallbackCoordinate = IndicatorFigureCallbackBrother & { x: number }> +export type IndicatorFigureAttrsCallbackData = IndicatorFigureCallbackBrother + export interface IndicatorFigureAttrsCallbackParams { + data: IndicatorFigureAttrsCallbackData> coordinate: IndicatorFigureAttrsCallbackCoordinate bounding: Bounding barSpace: BarSpace diff --git a/src/view/IndicatorView.ts b/src/view/IndicatorView.ts index 7193eea6f..773624809 100644 --- a/src/view/IndicatorView.ts +++ b/src/view/IndicatorView.ts @@ -106,30 +106,31 @@ 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, figureIndex: number) => { - if (isValid(currentIndicatorData[figure.key])) { + eachFigures(dataList, indicator, dataIndex, defaultStyles, (figure: IndicatorFigure, figureStyles: IndicatorFigureStyle) => { + 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, @@ -147,7 +148,7 @@ export default class IndicatorView extends CandleBarView { const baseValue = figure.baseValue ?? yAxis.getRange().from 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 +160,7 @@ export default class IndicatorView extends CandleBarView { attrs = { x: x - halfGapBar, y, - width: gapBar, + width: Math.max(1, halfGapBar * 2), height } break