diff --git a/src/Chart.ts b/src/Chart.ts index 6f0056bb..6553984e 100644 --- a/src/Chart.ts +++ b/src/Chart.ts @@ -47,6 +47,7 @@ import { type PaneOptions, PANE_DEFAULT_HEIGHT, PaneIdConstants, PaneState, PANE import type AxisImp from './component/Axis' import { AxisPosition } from './component/Axis' +import type { YAxis } from './component/YAxis' import type { IndicatorFilter, Indicator, IndicatorCreate } from './component/Indicator' import type { OverlayFilter, Overlay, OverlayCreate } from './component/Overlay' @@ -54,7 +55,6 @@ import type { OverlayFilter, Overlay, OverlayCreate } from './component/Overlay' import { getIndicatorClass } from './extension/indicator/index' import Event from './Event' -import type { YAxis } from './component/YAxis' export enum DomPosition { Root = 'root', diff --git a/src/Store.ts b/src/Store.ts index b8182cdb..fb839276 100644 --- a/src/Store.ts +++ b/src/Store.ts @@ -1263,7 +1263,7 @@ export default class Store { this._overlays.get(paneId)?.push(overlay) } if (overlay.isStart()) { - overlay.onDrawStart?.(({ overlay })) + overlay.onDrawStart?.(({ overlay, chart: this._chart })) } return id } @@ -1345,7 +1345,7 @@ export default class Store { filterMap.forEach((overlays, paneId) => { const paneOverlays = this.getOverlaysByPaneId(paneId) overlays.forEach(overlay => { - overlay.onRemoved?.({ overlay }) + overlay.onRemoved?.({ overlay, chart: this._chart }) if (!updatePaneIds.includes(paneId)) { updatePaneIds.push(paneId) } @@ -1393,7 +1393,7 @@ export default class Store { if (overlay !== null) { sortFlag = true if (isFunction(overlay.onMouseLeave)) { - overlay.onMouseLeave({ overlay, figureKey, figureIndex, ...event }) + overlay.onMouseLeave({ chart: this._chart, overlay, figureKey, figureIndex, ...event }) ignoreUpdateFlag = true } } @@ -1401,7 +1401,7 @@ export default class Store { if (infoOverlay !== null) { sortFlag = true if (isFunction(infoOverlay.onMouseEnter)) { - infoOverlay.onMouseEnter({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) + infoOverlay.onMouseEnter({ chart: this._chart, overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) ignoreUpdateFlag = true } } @@ -1423,13 +1423,13 @@ export default class Store { const { paneId, overlay, figureType, figureKey, figureIndex } = this._clickOverlayInfo const infoOverlay = info.overlay if (!(infoOverlay?.isDrawing() ?? false)) { - infoOverlay?.onClick?.({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) + infoOverlay?.onClick?.({ chart: this._chart, overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) } if (overlay?.id !== infoOverlay?.id || figureType !== info.figureType || figureIndex !== info.figureIndex) { this._clickOverlayInfo = info if (overlay?.id !== infoOverlay?.id) { - overlay?.onDeselected?.({ overlay, figureKey, figureIndex, ...event }) - infoOverlay?.onSelected?.({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) + overlay?.onDeselected?.({ chart: this._chart, overlay, figureKey, figureIndex, ...event }) + infoOverlay?.onSelected?.({ chart: this._chart, overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) this._chart.updatePane(UpdateLevel.Overlay, info.paneId) if (paneId !== info.paneId) { this._chart.updatePane(UpdateLevel.Overlay, paneId) diff --git a/src/component/Axis.ts b/src/component/Axis.ts index bab54556..362e5b70 100644 --- a/src/component/Axis.ts +++ b/src/component/Axis.ts @@ -17,8 +17,7 @@ import type VisibleRange from '../common/VisibleRange' import type DrawPane from '../pane/DrawPane' import type Bounding from '../common/Bounding' -import type { KLineData } from '../common/Data' -import type { Indicator } from './Indicator' +import type { Chart } from '../Chart' export interface AxisTick { coord: number @@ -51,10 +50,8 @@ export interface AxisValueToValueParams { export type AxisValueToValueCallback = (value: number, params: AxisValueToValueParams) => number export interface AxisCreateRangeParams { + chart: Chart paneId: string - kLineDataList: KLineData[] - indicators: Indicator[] - dataVisibleRange: VisibleRange defaultRange: AxisRange } diff --git a/src/component/Indicator.ts b/src/component/Indicator.ts index 2ce3250a..d7abcb45 100644 --- a/src/component/Indicator.ts +++ b/src/component/Indicator.ts @@ -16,7 +16,6 @@ import type Nullable from '../common/Nullable' import type ExcludePickPartial from '../common/ExcludePickPartial' import type { KLineData } from '../common/Data' import type Bounding from '../common/Bounding' -import type VisibleRange from '../common/VisibleRange' import type BarSpace from '../common/BarSpace' import type Crosshair from '../common/Crosshair' import type { IndicatorStyle, IndicatorPolygonStyle, SmoothLineStyle, RectStyle, TextStyle, TooltipIconStyle, LineStyle, LineType, TooltipLegend } from '../common/Styles' @@ -31,6 +30,7 @@ import type { ArcAttrs } from '../extension/figure/arc' import type { RectAttrs } from '../extension/figure/rect' import type { TextAttrs } from '../extension/figure/text' import type { LoadDataType } from '../common/LoadDataCallback' +import type { Chart } from '../Chart' export enum IndicatorSeries { Normal = 'normal', @@ -90,12 +90,10 @@ export interface IndicatorTooltipData { } export interface IndicatorCreateTooltipDataSourceParams { - kLineDataList: KLineData[] + chart: Chart indicator: Indicator - visibleRange: VisibleRange bounding: Bounding crosshair: Crosshair - defaultStyles: IndicatorStyle xAxis: XAxis yAxis: YAxis } @@ -104,12 +102,9 @@ export type IndicatorCreateTooltipDataSourceCallback = (params: IndicatorCrea export interface IndicatorDrawParams { ctx: CanvasRenderingContext2D - kLineDataList: KLineData[] + chart: Chart indicator: Indicator - visibleRange: VisibleRange bounding: Bounding - barSpace: BarSpace - defaultStyles: IndicatorStyle xAxis: XAxis yAxis: YAxis } diff --git a/src/component/Overlay.ts b/src/component/Overlay.ts index a244e9f1..a2ad7669 100644 --- a/src/component/Overlay.ts +++ b/src/component/Overlay.ts @@ -18,8 +18,6 @@ import type ExcludePickPartial from '../common/ExcludePickPartial' import type Point from '../common/Point' import type Coordinate from '../common/Coordinate' import type Bounding from '../common/Bounding' -import type BarSpace from '../common/BarSpace' -import type Precision from '../common/Precision' import type { OverlayStyle } from '../common/Styles' import type { MouseTouchEvent } from '../common/SyntheticEvent' import { clone, isArray, isFunction, isNumber, isString, isValid, merge } from '../common/utils/typeChecks' @@ -27,7 +25,7 @@ import { clone, isArray, isFunction, isNumber, isString, isValid, merge } from ' import type { XAxis } from './XAxis' import type { YAxis } from './YAxis' import type ChartStore from '../Store' -import type { Options } from '../Options' +import type { Chart } from '../Chart' export enum OverlayMode { Normal = 'normal', @@ -67,21 +65,11 @@ export interface OverlayFigure { ignoreEvent?: boolean | OverlayFigureIgnoreEventType[] } -export interface OverlayPrecision extends Precision { - max: number - min: number - excludePriceVolumeMax: number - excludePriceVolumeMin: number - [key: string]: number -} - export interface OverlayCreateFiguresCallbackParams { - options: Options + chart: Chart overlay: Overlay coordinates: Coordinate[] bounding: Bounding - barSpace: BarSpace - precision: OverlayPrecision xAxis: Nullable yAxis: Nullable } @@ -90,6 +78,7 @@ export interface OverlayEvent extends Partial { figureKey?: string figureIndex?: number overlay: Overlay + chart: Chart } export type OverlayEventCallback = (event: OverlayEvent) => boolean diff --git a/src/component/YAxis.ts b/src/component/YAxis.ts index 21335d80..23ac7b4b 100644 --- a/src/component/YAxis.ts +++ b/src/component/YAxis.ts @@ -169,10 +169,8 @@ export default abstract class YAxisImp extends AxisImp implements YAxis { } const range = this.createRange({ + chart, paneId, - kLineDataList: chartStore.getDataList(), - dataVisibleRange: chartStore.getVisibleRange(), - indicators, defaultRange }) let realFrom = range.realFrom diff --git a/src/extension/overlay/fibonacciLine.ts b/src/extension/overlay/fibonacciLine.ts index 974c9208..9544e385 100644 --- a/src/extension/overlay/fibonacciLine.ts +++ b/src/extension/overlay/fibonacciLine.ts @@ -25,22 +25,31 @@ const fibonacciLine: OverlayTemplate = { needDefaultPointFigure: true, needDefaultXAxisFigure: true, needDefaultYAxisFigure: true, - createPointFigures: ({ coordinates, bounding, overlay, precision, options, yAxis }) => { + createPointFigures: ({ chart, coordinates, bounding, overlay, yAxis }) => { const points = overlay.points + if (coordinates.length > 0) { - const currentPrecision = (yAxis?.isInCandle() ?? true) ? precision.price : precision.excludePriceVolumeMax + let precision = 0 + if (yAxis?.isInCandle() ?? true) { + precision = chart.getPriceVolumePrecision().price + } else { + const indicators = chart.getIndicators({ paneId: overlay.paneId }).get(overlay.paneId) ?? [] + indicators.forEach(indicator => { + precision = Math.max(precision, indicator.precision) + }) + } const lines: LineAttrs[] = [] const texts: TextAttrs[] = [] const startX = 0 const endX = bounding.width if (coordinates.length > 1 && isNumber(points[0].value) && isNumber(points[1].value)) { - const { decimalFold, thousandsSeparator } = options + const { decimalFold, thousandsSeparator } = chart.getOptions() const percents = [1, 0.786, 0.618, 0.5, 0.382, 0.236, 0] const yDif = coordinates[0].y - coordinates[1].y const valueDif = points[0].value - points[1].value percents.forEach(percent => { const y = coordinates[1].y + yDif * percent - const value = decimalFold.format(thousandsSeparator.format(((points[1].value ?? 0) + valueDif * percent).toFixed(currentPrecision))) + const value = decimalFold.format(thousandsSeparator.format(((points[1].value ?? 0) + valueDif * percent).toFixed(precision))) lines.push({ coordinates: [{ x: startX, y }, { x: endX, y }] }) texts.push({ x: startX, diff --git a/src/extension/overlay/priceLine.ts b/src/extension/overlay/priceLine.ts index 6cdd7156..59a0b121 100644 --- a/src/extension/overlay/priceLine.ts +++ b/src/extension/overlay/priceLine.ts @@ -20,10 +20,18 @@ const priceLine: OverlayTemplate = { needDefaultPointFigure: true, needDefaultXAxisFigure: true, needDefaultYAxisFigure: true, - createPointFigures: ({ coordinates, bounding, precision, overlay, options, yAxis }) => { - const { decimalFold, thousandsSeparator } = options + createPointFigures: ({ chart, coordinates, bounding, overlay, yAxis }) => { + let precision = 0 + if (yAxis?.isInCandle() ?? true) { + precision = chart.getPriceVolumePrecision().price + } else { + const indicators = chart.getIndicators({ paneId: overlay.paneId }).get(overlay.paneId) ?? [] + indicators.forEach(indicator => { + precision = Math.max(precision, indicator.precision) + }) + } + const { decimalFold, thousandsSeparator } = chart.getOptions() const { value = 0 } = (overlay.points)[0] - const currentPrecision = (yAxis?.isInCandle() ?? true) ? precision.price : precision.excludePriceVolumeMax return [ { type: 'line', @@ -35,7 +43,7 @@ const priceLine: OverlayTemplate = { attrs: { x: coordinates[0].x, y: coordinates[0].y, - text: decimalFold.format(thousandsSeparator.format(value.toFixed(currentPrecision))), + text: decimalFold.format(thousandsSeparator.format(value.toFixed(precision))), baseline: 'bottom' } } diff --git a/src/extension/overlay/simpleTag.ts b/src/extension/overlay/simpleTag.ts index f599ee30..ebc922a0 100644 --- a/src/extension/overlay/simpleTag.ts +++ b/src/extension/overlay/simpleTag.ts @@ -38,7 +38,7 @@ const simpleTag: OverlayTemplate = { ignoreEvent: true } }, - createYAxisFigures: ({ overlay, coordinates, bounding, yAxis, precision }) => { + createYAxisFigures: ({ chart, overlay, coordinates, bounding, yAxis }) => { const isFromZero = yAxis?.isFromZero() ?? false let textAlign: CanvasTextAlign = 'left' let x = 0 @@ -58,7 +58,7 @@ const simpleTag: OverlayTemplate = { } } if (!isValid(text) && isNumber(overlay.points[0].value)) { - text = formatPrecision(overlay.points[0].value, precision.price) + text = formatPrecision(overlay.points[0].value, chart.getPriceVolumePrecision().price) } return { type: 'text', attrs: { x, y: coordinates[0].y, text, align: textAlign, baseline: 'middle' } } } diff --git a/src/extension/y-axis/percentage.ts b/src/extension/y-axis/percentage.ts index 22f2fd73..a2ffcac3 100644 --- a/src/extension/y-axis/percentage.ts +++ b/src/extension/y-axis/percentage.ts @@ -26,8 +26,10 @@ const percentage: AxisTemplate = { realValueToValue: (value, { range }) => { return (value - range.realFrom) / range.realRange * range.range + range.from }, - createRange: ({ defaultRange, dataVisibleRange, kLineDataList }) => { - const kLineData = kLineDataList[dataVisibleRange.from] + createRange: ({ chart, defaultRange }) => { + const kLineDataList = chart.getDataList() + const visibleRange = chart.getVisibleRange() + const kLineData = kLineDataList[visibleRange.from] if (isValid(kLineData)) { const { from, to, range } = defaultRange const realFrom = (defaultRange.from - kLineData.close) / kLineData.close * 100 diff --git a/src/view/IndicatorTooltipView.ts b/src/view/IndicatorTooltipView.ts index 1b88ca73..312f38b4 100644 --- a/src/view/IndicatorTooltipView.ts +++ b/src/view/IndicatorTooltipView.ts @@ -295,14 +295,12 @@ export default class IndicatorTooltipView extends View { if (isFunction(indicator.createTooltipDataSource)) { const widget = this.getWidget() const pane = widget.getPane() - const chartStore = pane.getChart().getChartStore() + const chart = pane.getChart() const { name: customName, calcParamsText: customCalcParamsText, legends: customLegends, icons: customIcons } = indicator.createTooltipDataSource({ - kLineDataList: dataList, + chart, indicator, - visibleRange: chartStore.getVisibleRange(), bounding: widget.getBounding(), crosshair, - defaultStyles: styles, xAxis: pane.getChart().getXAxisPane().getAxisComponent(), yAxis: pane.getAxisComponent() }) diff --git a/src/view/IndicatorView.ts b/src/view/IndicatorView.ts index 7c09fca9..52478150 100644 --- a/src/view/IndicatorView.ts +++ b/src/view/IndicatorView.ts @@ -68,7 +68,6 @@ export default class IndicatorView extends CandleBarView { const yAxis = pane.getAxisComponent() const chartStore = chart.getChartStore() const dataList = chartStore.getDataList() - const visibleRange = chartStore.getVisibleRange() const indicators = chartStore.getIndicatorsByPaneId(pane.getId()) const defaultStyles = chartStore.getOptions().styles.indicator ctx.save() @@ -84,12 +83,9 @@ export default class IndicatorView extends CandleBarView { ctx.save() isCover = indicator.draw({ ctx, - kLineDataList: dataList, + chart, indicator, - visibleRange, bounding, - barSpace: chartStore.getBarSpace(), - defaultStyles, xAxis, yAxis }) diff --git a/src/view/OverlayView.ts b/src/view/OverlayView.ts index 69c21b95..f63bf1f1 100644 --- a/src/view/OverlayView.ts +++ b/src/view/OverlayView.ts @@ -16,7 +16,6 @@ import type Nullable from '../common/Nullable' import type Coordinate from '../common/Coordinate' import type Point from '../common/Point' import type Bounding from '../common/Bounding' -import type BarSpace from '../common/BarSpace' import type { OverlayStyle } from '../common/Styles' import type { EventHandler, EventName, MouseTouchEvent, MouseTouchEventCallback } from '../common/SyntheticEvent' import { isBoolean, isNumber, isValid } from '../common/utils/typeChecks' @@ -26,7 +25,7 @@ import type { Options } from '../Options' import type { Axis } from '../component/Axis' import type { XAxis } from '../component/XAxis' import type { YAxis } from '../component/YAxis' -import type { OverlayPrecision, OverlayFigure, OverlayFigureIgnoreEventType, Overlay } from '../component/Overlay' +import type { OverlayFigure, OverlayFigureIgnoreEventType, Overlay } from '../component/Overlay' import type OverlayImp from '../component/Overlay' import { OVERLAY_FIGURE_KEY_PREFIX, OverlayMode, getAllOverlayFigureIgnoreEventTypes } from '../component/Overlay' @@ -40,6 +39,8 @@ import type DrawWidget from '../widget/DrawWidget' import type DrawPane from '../pane/DrawPane' import View from './View' +import type { Chart } from '../Chart' +import type Precision from '../common/Precision' export default class OverlayView extends View { constructor (widget: DrawWidget>) { @@ -50,7 +51,8 @@ export default class OverlayView extends View { private _initEvent (): void { const pane = this.getWidget().getPane() const paneId = pane.getId() - const chartStore = pane.getChart().getChartStore() + const chart = pane.getChart() + const chartStore = chart.getChartStore() this.registerEvent('mouseMoveEvent', (event: MouseTouchEvent) => { const progressOverlayInfo = chartStore.getProgressOverlayInfo() if (progressOverlayInfo !== null) { @@ -64,7 +66,7 @@ export default class OverlayView extends View { const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}` if (overlay.isDrawing() && progressOverlayPaneId === paneId) { overlay.eventMoveForDrawing(this._coordinateToPoint(overlay, event)) - overlay.onDrawing?.({ overlay, figureKey: key, figureIndex: index, ...event }) + overlay.onDrawing?.({ chart, overlay, figureKey: key, figureIndex: index, ...event }) } return this._figureMouseMoveEvent( overlay, @@ -96,11 +98,11 @@ export default class OverlayView extends View { const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}` if (overlay.isDrawing() && progressOverlayPaneId === paneId) { overlay.eventMoveForDrawing(this._coordinateToPoint(overlay, event)) - overlay.onDrawing?.({ overlay, figureKey: key, figureIndex: index, ...event }) + overlay.onDrawing?.({ chart, overlay, figureKey: key, figureIndex: index, ...event }) overlay.nextStep() if (!overlay.isDrawing()) { chartStore.progressOverlayComplete() - overlay.onDrawEnd?.({ overlay, figureKey: key, figureIndex: index, ...event }) + overlay.onDrawEnd?.({ chart, overlay, figureKey: key, figureIndex: index, ...event }) } } return this._figureMouseClickEvent( @@ -131,7 +133,7 @@ export default class OverlayView extends View { chartStore.progressOverlayComplete() const index = overlay.points.length - 1 const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}` - overlay.onDrawEnd?.({ overlay, figureKey: key, figureIndex: index, ...event }) + overlay.onDrawEnd?.({ chart, overlay, figureKey: key, figureIndex: index, ...event }) } } const index = overlay.points.length - 1 @@ -163,7 +165,7 @@ export default class OverlayView extends View { }).registerEvent('mouseUpEvent', (event: MouseTouchEvent) => { const { overlay, figureIndex, figureKey } = chartStore.getPressedOverlayInfo() if (overlay !== null) { - overlay.onPressedMoveEnd?.({ overlay, figureKey, figureIndex, ...event }) + overlay.onPressedMoveEnd?.({ chart, overlay, figureKey, figureIndex, ...event }) } chartStore.setPressedOverlayInfo({ paneId, @@ -178,7 +180,7 @@ export default class OverlayView extends View { const { overlay, figureType, figureIndex, figureKey } = chartStore.getPressedOverlayInfo() if (overlay !== null) { if (!overlay.lock) { - if (!(overlay.onPressedMoving?.({ overlay, figureIndex, figureKey, ...event }) ?? false)) { + if (!(overlay.onPressedMoving?.({ chart, overlay, figureIndex, figureKey, ...event }) ?? false)) { const point = this._coordinateToPoint(overlay, event) if (figureType === EventOverlayInfoFigureType.Point) { overlay.eventPressedPointMove(point, figureIndex) @@ -262,7 +264,7 @@ export default class OverlayView extends View { const pane = this.getWidget().getPane() const paneId = pane.getId() overlay.startPressedMove(this._coordinateToPoint(overlay, event)) - overlay.onPressedMoveStart?.({ overlay, figureIndex, figureKey, ...event }) + overlay.onPressedMoveStart?.({ chart: pane.getChart(), overlay, figureIndex, figureKey, ...event }) pane.getChart().getChartStore().setPressedOverlayInfo({ paneId, overlay, figureType, figureKey, figureIndex, attrsIndex }) return true } @@ -279,14 +281,14 @@ export default class OverlayView extends View { private _figureMouseDoubleClickEvent (overlay: OverlayImp, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { - overlay.onDoubleClick?.({ ...event, figureIndex, figureKey, overlay }) + overlay.onDoubleClick?.({ ...event, chart: this.getWidget().getPane().getChart(), figureIndex, figureKey, overlay }) return true } } private _figureMouseRightClickEvent (overlay: OverlayImp, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { - if (!(overlay.onRightClick?.({ overlay, figureIndex, figureKey, ...event }) ?? false)) { + if (!(overlay.onRightClick?.({ chart: this.getWidget().getPane().getChart(), overlay, figureIndex, figureKey, ...event }) ?? false)) { this.getWidget().getPane().getChart().getChartStore().removeOverlay(overlay) } return true @@ -390,32 +392,15 @@ export default class OverlayView extends View { const bounding = widget.getBounding() const chartStore = chart.getChartStore() const options = chartStore.getOptions() - const barSpace = chartStore.getBarSpace() const precision = chartStore.getPrecision() const hoverOverlayInfo = chartStore.getHoverOverlayInfo() const clickOverlayInfo = chartStore.getClickOverlayInfo() const overlays = this.getCompleteOverlays(chartStore, paneId) - const paneIndicators = chartStore.getIndicatorsByPaneId(paneId) - const overlayPrecision = paneIndicators.reduce((prev, indicator) => { - const precision = indicator.precision - prev[indicator.name] = precision - prev.max = Math.max(prev.max, precision) - prev.min = Math.min(prev.min, precision) - prev.excludePriceVolumeMax = Math.max(prev.excludePriceVolumeMax, precision) - prev.excludePriceVolumeMin = Math.min(prev.excludePriceVolumeMin, precision) - return prev - }, { - ...precision, - max: Math.max(precision.price, precision.volume), - min: Math.min(precision.price, precision.volume), - excludePriceVolumeMax: Number.MIN_SAFE_INTEGER, - excludePriceVolumeMin: Number.MAX_SAFE_INTEGER - }) overlays.forEach(overlay => { if (overlay.visible) { this._drawOverlay( - ctx, overlay, bounding, barSpace, - overlayPrecision, options, xAxis, yAxis, + ctx, overlay, bounding, + precision, options, xAxis, yAxis, hoverOverlayInfo, clickOverlayInfo, chartStore ) } @@ -426,8 +411,8 @@ export default class OverlayView extends View { if (isValid(overlay) && overlay.visible) { this._drawOverlay( - ctx, overlay, bounding, barSpace, - overlayPrecision, options, xAxis, yAxis, + ctx, overlay, bounding, + precision, options, xAxis, yAxis, hoverOverlayInfo, clickOverlayInfo, chartStore ) } @@ -438,8 +423,7 @@ export default class OverlayView extends View { ctx: CanvasRenderingContext2D, overlay: OverlayImp, bounding: Bounding, - barSpace: BarSpace, - precision: OverlayPrecision, + precision: Precision, options: Options, xAxis: Nullable, yAxis: Nullable, @@ -465,7 +449,7 @@ export default class OverlayView extends View { if (coordinates.length > 0) { const figures = new Array().concat( this.getFigures( - overlay, coordinates, bounding, barSpace, precision, options, xAxis, yAxis + chartStore.getChart(), overlay, coordinates, bounding, xAxis, yAxis ) ) this.drawFigures( @@ -520,16 +504,14 @@ export default class OverlayView extends View { } protected getFigures ( + chart: Chart, o: Overlay, coordinates: Coordinate[], bounding: Bounding, - barSpace: BarSpace, - precision: OverlayPrecision, - options: Options, xAxis: Nullable, yAxis: Nullable ): OverlayFigure | OverlayFigure[] { - return o.createPointFigures?.({ overlay: o, coordinates, bounding, barSpace, precision, options, xAxis, yAxis }) ?? [] + return o.createPointFigures?.({ chart, overlay: o, coordinates, bounding, xAxis, yAxis }) ?? [] } protected drawDefaultFigures ( @@ -537,7 +519,7 @@ export default class OverlayView extends View { overlay: OverlayImp, coordinates: Coordinate[], _bounding: Bounding, - _precision: OverlayPrecision, + _precision: Precision, options: Options, _xAxis: Nullable, _yAxis: Nullable, diff --git a/src/view/OverlayXAxisView.ts b/src/view/OverlayXAxisView.ts index ba04ed9c..6331600e 100644 --- a/src/view/OverlayXAxisView.ts +++ b/src/view/OverlayXAxisView.ts @@ -15,7 +15,6 @@ import type Nullable from '../common/Nullable' import type Coordinate from '../common/Coordinate' import type Bounding from '../common/Bounding' -import type BarSpace from '../common/BarSpace' import type Precision from '../common/Precision' import { isNumber } from '../common/utils/typeChecks' @@ -23,13 +22,14 @@ import { FormatDateType, type Options } from '../Options' import type { XAxis } from '../component/XAxis' import type { YAxis } from '../component/YAxis' -import type { OverlayPrecision, OverlayFigure, Overlay } from '../component/Overlay' +import type { OverlayFigure, Overlay } from '../component/Overlay' import type OverlayImp from '../component/Overlay' import type { EventOverlayInfo, ProgressOverlayInfo } from '../Store' import type ChartStore from '../Store' import OverlayYAxisView from './OverlayYAxisView' +import type { Chart } from '../Chart' export default class OverlayXAxisView extends OverlayYAxisView { override coordinateToPointTimestampDataIndexFlag (): boolean { @@ -79,15 +79,13 @@ export default class OverlayXAxisView extends OverlayYAxisView { } override getFigures ( + chart: Chart, o: Overlay, coordinates: Coordinate[], bounding: Bounding, - barSpace: BarSpace, - precision: OverlayPrecision, - options: Options, xAxis: Nullable, yAxis: Nullable ): OverlayFigure | OverlayFigure[] { - return o.createXAxisFigures?.({ overlay: o, coordinates, bounding, barSpace, precision, options, xAxis, yAxis }) ?? [] + return o.createXAxisFigures?.({ chart, overlay: o, coordinates, bounding, xAxis, yAxis }) ?? [] } } diff --git a/src/view/OverlayYAxisView.ts b/src/view/OverlayYAxisView.ts index fb5726ee..104072fa 100644 --- a/src/view/OverlayYAxisView.ts +++ b/src/view/OverlayYAxisView.ts @@ -15,21 +15,23 @@ import type Nullable from '../common/Nullable' import type Coordinate from '../common/Coordinate' import type Bounding from '../common/Bounding' -import type BarSpace from '../common/BarSpace' import type { Options } from '../Options' import { formatPrecision } from '../common/utils/format' import { isNumber } from '../common/utils/typeChecks' +import type Precision from '../common/Precision' import type { Axis } from '../component/Axis' import type { XAxis } from '../component/XAxis' import type { YAxis } from '../component/YAxis' -import type { OverlayPrecision, OverlayFigure, Overlay } from '../component/Overlay' +import type { OverlayFigure, Overlay } from '../component/Overlay' import type OverlayImp from '../component/Overlay' import type { EventOverlayInfo } from '../Store' import OverlayView from './OverlayView' +import type { Chart } from '../Chart' + export default class OverlayYAxisView extends OverlayView { override coordinateToPointTimestampDataIndexFlag (): boolean { return false @@ -40,7 +42,7 @@ export default class OverlayYAxisView extends OverlayVie overlay: OverlayImp, coordinates: Coordinate[], bounding: Bounding, - precision: OverlayPrecision, + precision: Precision, options: Options, xAxis: Nullable, yAxis: Nullable, @@ -59,7 +61,7 @@ export default class OverlayYAxisView extends OverlayVie overlay: Overlay, coordinates: Coordinate[], bounding: Bounding, - precision: OverlayPrecision, + precision: Precision, options: Options, _xAxis: Nullable, yAxis: Nullable, @@ -101,15 +103,13 @@ export default class OverlayYAxisView extends OverlayVie } override getFigures ( + chart: Chart, overlay: Overlay, coordinates: Coordinate[], bounding: Bounding, - barSpace: BarSpace, - precision: OverlayPrecision, - options: Options, xAxis: Nullable, yAxis: Nullable ): OverlayFigure | OverlayFigure[] { - return overlay.createYAxisFigures?.({ overlay, coordinates, bounding, barSpace, precision, options, xAxis, yAxis }) ?? [] + return overlay.createYAxisFigures?.({ chart, overlay, coordinates, bounding, xAxis, yAxis }) ?? [] } }