From 045973502f210bd92c060c0ac0cb136d64777106 Mon Sep 17 00:00:00 2001 From: liihuu Date: Sat, 8 Jun 2024 00:12:34 +0800 Subject: [PATCH] refactor: refactor overlay module --- src/Chart.ts | 4 +- src/component/Indicator.ts | 5 - src/component/Overlay.ts | 411 +++++++++-------------------------- src/store/IndicatorStore.ts | 2 +- src/store/OverlayStore.ts | 177 +++++---------- src/view/OverlayView.ts | 111 +++++----- src/view/OverlayXAxisView.ts | 14 +- src/view/OverlayYAxisView.ts | 10 +- 8 files changed, 230 insertions(+), 504 deletions(-) diff --git a/src/Chart.ts b/src/Chart.ts index 3041716e0..b336ed30d 100644 --- a/src/Chart.ts +++ b/src/Chart.ts @@ -712,7 +712,7 @@ export default class ChartImp implements Chart { createIndicator (value: string | IndicatorCreate, isStack?: boolean, paneOptions?: Nullable, callback?: () => void): Nullable { const indicator = isString(value) ? { name: value } : value - if (getIndicatorClass(indicator.name as string) === null) { + if (getIndicatorClass(indicator.name) === null) { logWarn('createIndicator', 'value', 'indicator not supported, you may need to use registerIndicator to add one!!!') return null } @@ -820,7 +820,7 @@ export default class ChartImp implements Chart { } getOverlayById (id: string): Nullable { - return this._chartStore.getOverlayStore().getInstanceById(id) + return this._chartStore.getOverlayStore().getInstanceById(id)?.getOverlay() ?? null } overrideOverlay (override: Partial): void { diff --git a/src/component/Indicator.ts b/src/component/Indicator.ts index 28b916198..48e6e9dad 100644 --- a/src/component/Indicator.ts +++ b/src/component/Indicator.ts @@ -218,11 +218,6 @@ export interface Indicator { * Calculation result */ result: D[] - - /** - * Others - */ - [key: string]: any } export type IndicatorTemplate = ExcludePickPartial, 'result'>, 'name' | 'calc'> diff --git a/src/component/Overlay.ts b/src/component/Overlay.ts index 20b85b806..ce1a14054 100644 --- a/src/component/Overlay.ts +++ b/src/component/Overlay.ts @@ -22,7 +22,7 @@ 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, isNumber, isString, merge } from '../common/utils/typeChecks' +import { clone, isArray, isFunction, isNumber, isString, merge } from '../common/utils/typeChecks' import type TimeScaleStore from '../store/TimeScaleStore' @@ -282,10 +282,11 @@ export interface Overlay { } export type OverlayTemplate = ExcludePickPartial, 'name'> -export type OverlayCreate = ExcludePickPartial, 'name'> + +export type OverlayCreate = ExcludePickPartial, 'name'> export type OverlayRemove = Partial> export type OverlayInnerConstructor = new () => OverlayImp -export type OverlayConstructor = new () => Overlay +export type OverlayConstructor = new () => ({ getOverlay: () => Overlay }) const OVERLAY_DRAW_STEP_START = 1 const OVERLAY_DRAW_STEP_FINISHED = -1 @@ -294,339 +295,133 @@ export const OVERLAY_ID_PREFIX = 'overlay_' export const OVERLAY_FIGURE_KEY_PREFIX = 'overlay_figure_' -export const OVERLAY_ACTIVE_Z_LEVEL = Number.MAX_SAFE_INTEGER - -export default abstract class OverlayImp implements Overlay { - id: string - groupId: string - paneId: string - name: string - totalStep: number - currentStep: number = OVERLAY_DRAW_STEP_START - needDefaultPointFigure: boolean - needDefaultXAxisFigure: boolean - needDefaultYAxisFigure: boolean - lock: boolean - visible: boolean - zLevel: number - mode: OverlayMode - modeSensitivity: number - points: Array> = [] - extendData: any - styles: Nullable> - createPointFigures: Nullable - createXAxisFigures: Nullable - createYAxisFigures: Nullable - performEventPressedMove: Nullable<(params: OverlayPerformEventParams) => void> - performEventMoveForDrawing: Nullable<(params: OverlayPerformEventParams) => void> - onDrawStart: Nullable - onDrawing: Nullable - onDrawEnd: Nullable - onClick: Nullable - onDoubleClick: Nullable - onRightClick: Nullable - onPressedMoveStart: Nullable - onPressedMoving: Nullable - onPressedMoveEnd: Nullable - onMouseEnter: Nullable - onMouseLeave: Nullable - onRemoved: Nullable - onSelected: Nullable - onDeselected: Nullable +export default class OverlayImp { + private _prevOverlay: Overlay + + private readonly _overlay: Overlay = { + id: '', + groupId: '', + paneId: '', + name: '', + totalStep: 1, + currentStep: OVERLAY_DRAW_STEP_START, + needDefaultPointFigure: false, + needDefaultXAxisFigure: false, + needDefaultYAxisFigure: false, + lock: false, + visible: true, + zLevel: 0, + mode: OverlayMode.Normal, + modeSensitivity: 8, + points: [], + extendData: null, + styles: {}, + createPointFigures: null, + createXAxisFigures: null, + createYAxisFigures: null, + performEventPressedMove: null, + performEventMoveForDrawing: null, + onDrawStart: null, + onDrawing: null, + onDrawEnd: null, + onClick: null, + onDoubleClick: null, + onRightClick: null, + onPressedMoveStart: null, + onPressedMoving: null, + onPressedMoveEnd: null, + onMouseEnter: null, + onMouseLeave: null, + onRemoved: null, + onSelected: null, + onDeselected: null + } private _prevPressedPoint: Nullable> = null private _prevPressedPoints: Array> = [] constructor (overlay: OverlayTemplate) { - const { - mode, modeSensitivity, extendData, styles, - name, totalStep, lock, visible, zLevel, - needDefaultPointFigure, needDefaultXAxisFigure, needDefaultYAxisFigure, - createPointFigures, createXAxisFigures, createYAxisFigures, - performEventPressedMove, performEventMoveForDrawing, - onDrawStart, onDrawing, onDrawEnd, - onClick, onDoubleClick, onRightClick, - onPressedMoveStart, onPressedMoving, onPressedMoveEnd, - onMouseEnter, onMouseLeave, onRemoved, - onSelected, onDeselected - } = overlay - this.name = name - this.totalStep = (!isNumber(totalStep) || totalStep < 2) ? 1 : totalStep - this.lock = lock ?? false - this.visible = visible ?? true - this.zLevel = zLevel ?? 0 - this.needDefaultPointFigure = needDefaultPointFigure ?? false - this.needDefaultXAxisFigure = needDefaultXAxisFigure ?? false - this.needDefaultYAxisFigure = needDefaultYAxisFigure ?? false - this.mode = mode ?? OverlayMode.Normal - this.modeSensitivity = modeSensitivity ?? 8 - this.extendData = extendData - this.styles = clone(styles ?? {}) - this.createPointFigures = createPointFigures ?? null - this.createXAxisFigures = createXAxisFigures ?? null - this.createYAxisFigures = createYAxisFigures ?? null - this.performEventPressedMove = performEventPressedMove ?? null - this.performEventMoveForDrawing = performEventMoveForDrawing ?? null - this.onDrawStart = onDrawStart ?? null - this.onDrawing = onDrawing ?? null - this.onDrawEnd = onDrawEnd ?? null - this.onClick = onClick ?? null - this.onDoubleClick = onDoubleClick ?? null - this.onRightClick = onRightClick ?? null - this.onPressedMoveStart = onPressedMoveStart ?? null - this.onPressedMoving = onPressedMoving ?? null - this.onPressedMoveEnd = onPressedMoveEnd ?? null - this.onMouseEnter = onMouseEnter ?? null - this.onMouseLeave = onMouseLeave ?? null - this.onRemoved = onRemoved ?? null - this.onSelected = onSelected ?? null - this.onDeselected = onDeselected ?? null + this.override(overlay) } - setId (id: string): boolean { - if (!isString(this.id)) { - this.id = id - return true - } - return false + getOverlay (): Overlay { + return this._overlay } - setGroupId (groupId: string): boolean { - if (!isString(this.groupId)) { - this.groupId = groupId - return true + override (overlay: Partial): void { + this._prevOverlay = clone(this._overlay) + const id = this._overlay.id + merge(this._overlay, overlay) + if (isString(id)) { + this._overlay.id = id } - return false - } - - setPaneId (paneId: string): void { - this.paneId = paneId - } - - setExtendData (extendData: any): boolean { - if (extendData !== this.extendData) { - this.extendData = extendData - return true - } - return false - } - - setStyles (styles: DeepPartial): boolean { - merge(this.styles, styles) - return true - } - - setPoints (points: Array>): boolean { - if (points.length > 0) { + if (isArray(overlay.points) && overlay.points.length > 0) { let repeatTotalStep: number - this.points = [...points] - if (points.length >= this.totalStep - 1) { - this.currentStep = OVERLAY_DRAW_STEP_FINISHED - repeatTotalStep = this.totalStep - 1 + this._overlay.points = [...overlay.points] + if (overlay.points.length >= this._overlay.totalStep - 1) { + this._overlay.currentStep = OVERLAY_DRAW_STEP_FINISHED + repeatTotalStep = this._overlay.totalStep - 1 } else { - this.currentStep = points.length + 1 - repeatTotalStep = points.length + this._overlay.currentStep = overlay.points.length + 1 + repeatTotalStep = overlay.points.length } // Prevent wrong drawing due to wrong points - if (this.performEventMoveForDrawing !== null) { + if (isFunction(this._overlay.performEventMoveForDrawing)) { for (let i = 0; i < repeatTotalStep; i++) { - this.performEventMoveForDrawing({ + this._overlay.performEventMoveForDrawing({ currentStep: i + 2, - mode: this.mode, - points: this.points, + mode: this._overlay.mode, + points: this._overlay.points, performPointIndex: i, - performPoint: this.points[i] + performPoint: this._overlay.points[i] }) } } - if (this.currentStep === OVERLAY_DRAW_STEP_FINISHED && this.performEventPressedMove !== null) { - this.performEventPressedMove({ - currentStep: this.currentStep, - mode: this.mode, - points: this.points, - performPointIndex: this.points.length - 1, - performPoint: this.points[this.points.length - 1] + if (this._overlay.currentStep === OVERLAY_DRAW_STEP_FINISHED && isFunction(this._overlay.performEventPressedMove)) { + this._overlay.performEventPressedMove({ + currentStep: this._overlay.currentStep, + mode: this._overlay.mode, + points: this._overlay.points, + performPointIndex: this._overlay.points.length - 1, + performPoint: this._overlay.points[this._overlay.points.length - 1] }) } - return true } - return false } - setLock (lock: boolean): boolean { - if (this.lock !== lock) { - this.lock = lock - return true - } - return false - } + shouldUpdate (): { draw: boolean, sort: boolean } { + const sort = this._prevOverlay.zLevel !== this._overlay.zLevel + const draw = sort || + JSON.stringify(this._prevOverlay) !== JSON.stringify(this._overlay.points) || + this._prevOverlay.visible !== this._overlay.visible || + this._prevOverlay.extendData !== this._overlay.extendData || + this._prevOverlay.styles !== this._overlay.styles - setVisible (visible: boolean): boolean { - if (this.visible !== visible) { - this.visible = visible - return true - } - return false - } - - setZLevel (zLevel: number): boolean { - if (this.zLevel !== zLevel) { - this.zLevel = zLevel - return true - } - return false - } - - setMode (mode: OverlayMode): boolean { - if (this.mode !== mode) { - this.mode = mode - return true - } - return false - } - - setModeSensitivity (modeSensitivity: number): boolean { - if (this.modeSensitivity !== modeSensitivity) { - this.modeSensitivity = modeSensitivity - return true - } - return false - } - - setOnDrawStartCallback (callback: Nullable): boolean { - if (this.onDrawStart !== callback) { - this.onDrawStart = callback - return true - } - return false - } - - setOnDrawingCallback (callback: Nullable): boolean { - if (this.onDrawing !== callback) { - this.onDrawing = callback - return true - } - return false - } - - setOnDrawEndCallback (callback: Nullable): boolean { - if (this.onDrawEnd !== callback) { - this.onDrawEnd = callback - return true - } - return false - } - - setOnClickCallback (callback: Nullable): boolean { - if (this.onClick !== callback) { - this.onClick = callback - return true - } - return false - } - - setOnDoubleClickCallback (callback: Nullable): boolean { - if (this.onDoubleClick !== callback) { - this.onDoubleClick = callback - return true - } - return false - } - - setOnRightClickCallback (callback: Nullable): boolean { - if (this.onRightClick !== callback) { - this.onRightClick = callback - return true - } - return false - } - - setOnPressedMoveStartCallback (callback: Nullable): boolean { - if (this.onPressedMoveStart !== callback) { - this.onPressedMoveStart = callback - return true - } - return false - } - - setOnPressedMovingCallback (callback: Nullable): boolean { - if (this.onPressedMoving !== callback) { - this.onPressedMoving = callback - return true - } - return false - } - - setOnPressedMoveEndCallback (callback: Nullable): boolean { - if (this.onPressedMoveEnd !== callback) { - this.onPressedMoveEnd = callback - return true - } - return false - } - - setOnMouseEnterCallback (callback: Nullable): boolean { - if (this.onMouseEnter !== callback) { - this.onMouseEnter = callback - return true - } - return false - } - - setOnMouseLeaveCallback (callback: Nullable): boolean { - if (this.onMouseLeave !== callback) { - this.onMouseLeave = callback - return true - } - return false - } - - setOnRemovedCallback (callback: Nullable): boolean { - if (this.onRemoved !== callback) { - this.onRemoved = callback - return true - } - return false - } - - setOnSelectedCallback (callback: Nullable): boolean { - if (this.onSelected !== callback) { - this.onSelected = callback - return true - } - return false - } - - setOnDeselectedCallback (callback: Nullable): boolean { - if (this.onDeselected !== callback) { - this.onDeselected = callback - return true - } - return false + return { sort, draw } } nextStep (): void { - if (this.currentStep === this.totalStep - 1) { - this.currentStep = OVERLAY_DRAW_STEP_FINISHED + if (this._overlay.currentStep === this._overlay.totalStep - 1) { + this._overlay.currentStep = OVERLAY_DRAW_STEP_FINISHED } else { - this.currentStep++ + this._overlay.currentStep++ } } forceComplete (): void { - this.currentStep = OVERLAY_DRAW_STEP_FINISHED + this._overlay.currentStep = OVERLAY_DRAW_STEP_FINISHED } isDrawing (): boolean { - return this.currentStep !== OVERLAY_DRAW_STEP_FINISHED + return this._overlay.currentStep !== OVERLAY_DRAW_STEP_FINISHED } isStart (): boolean { - return this.currentStep === OVERLAY_DRAW_STEP_START + return this._overlay.currentStep === OVERLAY_DRAW_STEP_START } eventMoveForDrawing (point: Partial): void { - const pointIndex = this.currentStep - 1 + const pointIndex = this._overlay.currentStep - 1 const newPoint: Partial = {} if (isNumber(point.timestamp)) { newPoint.timestamp = point.timestamp @@ -637,11 +432,11 @@ export default abstract class OverlayImp implements Overlay { if (isNumber(point.value)) { newPoint.value = point.value } - this.points[pointIndex] = newPoint - this.performEventMoveForDrawing?.({ - currentStep: this.currentStep, - mode: this.mode, - points: this.points, + this._overlay.points[pointIndex] = newPoint + this._overlay.performEventMoveForDrawing?.({ + currentStep: this._overlay.currentStep, + mode: this._overlay.mode, + points: this._overlay.points, performPointIndex: pointIndex, performPoint: newPoint }) @@ -649,24 +444,24 @@ export default abstract class OverlayImp implements Overlay { eventPressedPointMove (point: Partial, pointIndex: number): void { if (isNumber(point.dataIndex)) { - this.points[pointIndex].dataIndex = point.dataIndex - this.points[pointIndex].timestamp = point.timestamp + this._overlay.points[pointIndex].dataIndex = point.dataIndex + this._overlay.points[pointIndex].timestamp = point.timestamp } if (isNumber(point.value)) { - this.points[pointIndex].value = point.value + this._overlay.points[pointIndex].value = point.value } - this.performEventPressedMove?.({ - currentStep: this.currentStep, - points: this.points, - mode: this.mode, + this._overlay.performEventPressedMove?.({ + currentStep: this._overlay.currentStep, + points: this._overlay.points, + mode: this._overlay.mode, performPointIndex: pointIndex, - performPoint: this.points[pointIndex] + performPoint: this._overlay.points[pointIndex] }) } startPressedMove (point: Partial): void { this._prevPressedPoint = { ...point } - this._prevPressedPoints = clone(this.points) + this._prevPressedPoints = clone(this._overlay.points) } eventPressedOtherMove (point: Partial, timeScaleStore: TimeScaleStore): void { @@ -679,7 +474,7 @@ export default abstract class OverlayImp implements Overlay { if (isNumber(point.value) && isNumber(this._prevPressedPoint.value)) { difValue = point.value - this._prevPressedPoint.value } - this.points = this._prevPressedPoints.map(p => { + this._overlay.points = this._prevPressedPoints.map(p => { if (isNumber(p.timestamp)) { p.dataIndex = timeScaleStore.timestampToDataIndex(p.timestamp) } diff --git a/src/store/IndicatorStore.ts b/src/store/IndicatorStore.ts index 9d8b5820c..61965708f 100644 --- a/src/store/IndicatorStore.ts +++ b/src/store/IndicatorStore.ts @@ -52,7 +52,7 @@ export default class IndicatorStore { if (!isValid(paneInstances)) { paneInstances = [] } - const IndicatorClazz = getIndicatorClass(name as string)! + const IndicatorClazz = getIndicatorClass(name)! const instance = new IndicatorClazz() this.synchronizeSeriesPrecision(instance) diff --git a/src/store/OverlayStore.ts b/src/store/OverlayStore.ts index 360922c04..b7ebc6560 100644 --- a/src/store/OverlayStore.ts +++ b/src/store/OverlayStore.ts @@ -15,13 +15,12 @@ import type Nullable from '../common/Nullable' import { UpdateLevel } from '../common/Updater' import { type MouseTouchEvent } from '../common/SyntheticEvent' -import { isFunction, isValid, isString, isBoolean, isNumber, isArray } from '../common/utils/typeChecks' +import { isFunction, isValid, isString, isBoolean } from '../common/utils/typeChecks' import { createId } from '../common/utils/id' import { LoadDataType } from '../common/LoadDataCallback' -import { type OverlayCreate, type OverlayRemove } from '../component/Overlay' import type OverlayImp from '../component/Overlay' -import { OVERLAY_ID_PREFIX, OVERLAY_ACTIVE_Z_LEVEL } from '../component/Overlay' +import { type OverlayCreate, type OverlayRemove, OVERLAY_ID_PREFIX } from '../component/Overlay' import { getOverlayInnerClass } from '../extension/overlay/index' @@ -98,104 +97,16 @@ export default class OverlayStore { this._chartStore = chartStore } - private _overrideInstance (instance: OverlayImp, overlay: Partial): [boolean, boolean] { - const { - id, groupId, points, styles, lock, visible, - zLevel, mode, modeSensitivity, extendData, - onDrawStart, onDrawing, - onDrawEnd, onClick, onDoubleClick, onRightClick, - onPressedMoveStart, onPressedMoving, onPressedMoveEnd, - onMouseEnter, onMouseLeave, - onRemoved, onSelected, onDeselected - } = overlay - let updateFlag = false - let sortFlag = false - if (isString(id)) { - instance.setId(id) - } - if (isString(groupId)) { - instance.setGroupId(groupId) - } - if (isArray(points) && instance.setPoints(points)) { - updateFlag = true - } - if (isValid(styles) && instance.setStyles(styles)) { - updateFlag = true - } - if (isBoolean(lock)) { - instance.setLock(lock) - } - if (isBoolean(visible) && instance.setVisible(visible)) { - updateFlag = true - } - if (isNumber(zLevel) && instance.setZLevel(zLevel)) { - updateFlag = true - sortFlag = true - } - if (isValid(mode)) { - instance.setMode(mode) - } - if (isNumber(modeSensitivity)) { - instance.setModeSensitivity(modeSensitivity) - } - if (extendData !== undefined && instance.setExtendData(extendData)) { - updateFlag = true - } - if (onDrawStart !== undefined) { - instance.setOnDrawStartCallback(onDrawStart) - } - if (onDrawing !== undefined) { - instance.setOnDrawingCallback(onDrawing) - } - if (onDrawEnd !== undefined) { - instance.setOnDrawEndCallback(onDrawEnd) - } - if (onClick !== undefined) { - instance.setOnClickCallback(onClick) - } - if (onDoubleClick !== undefined) { - instance.setOnDoubleClickCallback(onDoubleClick) - } - if (onRightClick !== undefined) { - instance.setOnRightClickCallback(onRightClick) - } - if (onPressedMoveStart !== undefined) { - instance.setOnPressedMoveStartCallback(onPressedMoveStart) - } - if (onPressedMoving !== undefined) { - instance.setOnPressedMovingCallback(onPressedMoving) - } - if (onPressedMoveEnd !== undefined) { - instance.setOnPressedMoveEndCallback(onPressedMoveEnd) - } - if (onMouseEnter !== undefined) { - instance.setOnMouseEnterCallback(onMouseEnter) - } - if (onMouseLeave !== undefined) { - instance.setOnMouseLeaveCallback(onMouseLeave) - } - if (onRemoved !== undefined) { - instance.setOnRemovedCallback(onRemoved) - } - if (onSelected !== undefined) { - instance.setOnSelectedCallback(onSelected) - } - if (onDeselected !== undefined) { - instance.setOnDeselectedCallback(onDeselected) - } - return [updateFlag, sortFlag] - } - getInstanceById (id: string): Nullable { for (const entry of this._instances) { const paneShapes = entry[1] - const overlay = paneShapes.find(s => s.id === id) + const overlay = paneShapes.find(s => s.getOverlay().id === id) if (isValid(overlay)) { return overlay } } if (this._progressInstanceInfo !== null) { - if (this._progressInstanceInfo.instance.id === id) { + if (this._progressInstanceInfo.instance.getOverlay().id === id) { return this._progressInstanceInfo.instance } } @@ -204,10 +115,10 @@ export default class OverlayStore { private _sort (paneId?: string): void { if (isString(paneId)) { - this._instances.get(paneId)?.sort((o1, o2) => o1.zLevel - o2.zLevel) + this._instances.get(paneId)?.sort((o1, o2) => o1.getOverlay().zLevel - o2.getOverlay().zLevel) } else { this._instances.forEach(paneInstances => { - paneInstances.sort((o1, o2) => o1.zLevel - o2.zLevel) + paneInstances.sort((o1, o2) => o1.getOverlay().zLevel - o2.getOverlay().zLevel) }) } } @@ -219,11 +130,12 @@ export default class OverlayStore { const OverlayClazz = getOverlayInnerClass(overlay.name) if (OverlayClazz !== null) { const instance = new OverlayClazz() - instance.setPaneId(paneId) + instance.override({ paneId }) const groupId = overlay.groupId ?? id overlay.id = id + overlay.paneId = paneId overlay.groupId = groupId - this._overrideInstance(instance, overlay) + instance.override(overlay) if (instance.isDrawing()) { this._progressInstanceInfo = { paneId, instance, appointPaneFlag } } else { @@ -233,7 +145,8 @@ export default class OverlayStore { this._instances.get(paneId)?.push(instance) } if (instance.isStart()) { - instance.onDrawStart?.(({ overlay: instance })) + const o = instance.getOverlay() + o.onDrawStart?.(({ overlay: o })) } return id } @@ -273,7 +186,7 @@ export default class OverlayStore { this._progressInstanceInfo.appointPaneFlag = appointPaneFlag } this._progressInstanceInfo.paneId = paneId - this._progressInstanceInfo.instance.setPaneId(paneId) + this._progressInstanceInfo.instance.override({ paneId }) } } @@ -294,11 +207,13 @@ export default class OverlayStore { let sortFlag = false const setFlag: (instance: OverlayImp) => void = (instance: OverlayImp) => { - const flags = this._overrideInstance(instance, overlay) - if (flags[0]) { + instance.override(overlay) + const { sort, draw } = instance.shouldUpdate() + + if (draw) { updateFlag = true } - if (flags[1]) { + if (sort) { sortFlag = true } } @@ -313,9 +228,10 @@ export default class OverlayStore { const groupIdValid = isString(groupId) this._instances.forEach(paneInstances => { paneInstances.forEach(instance => { + const o = instance.getOverlay() if ( - (nameValid && instance.name === name) || - (groupIdValid && instance.groupId === groupId) || + (nameValid && o.name === name) || + (groupIdValid && o.groupId === groupId) || (!nameValid && !groupIdValid) ) { setFlag(instance) @@ -324,9 +240,10 @@ export default class OverlayStore { }) if (this._progressInstanceInfo !== null) { const progressInstance = this._progressInstanceInfo.instance + const o = progressInstance.getOverlay() if ( - (nameValid && progressInstance.name === name) || - (groupIdValid && progressInstance.groupId === groupId) || + (nameValid && o.name === name) || + (groupIdValid && o.groupId === groupId) || (!nameValid && !groupIdValid) ) { setFlag(progressInstance) @@ -343,18 +260,19 @@ export default class OverlayStore { removeInstance (overlayRemove?: OverlayRemove): void { const match: ((remove: OverlayRemove, overlay: OverlayImp) => boolean) = (remove: OverlayRemove, overlay: OverlayImp) => { + const o = overlay.getOverlay() if (isString(remove.id)) { - if (overlay.id !== remove.id) { + if (o.id !== remove.id) { return false } } else { if (isString(remove.groupId)) { - if (overlay.groupId !== remove.groupId) { + if (o.groupId !== remove.groupId) { return false } } else { if (isString(remove.name)) { - if (overlay.name !== remove.name) { + if (o.name !== remove.name) { return false } } @@ -372,7 +290,8 @@ export default class OverlayStore { (overlayRemoveValid && match(overlayRemove, instance)) ) { updatePaneIds.push(this._progressInstanceInfo.paneId) - instance.onRemoved?.({ overlay: instance }) + const o = instance.getOverlay() + o.onRemoved?.({ overlay: o }) this._progressInstanceInfo = null } } @@ -385,7 +304,8 @@ export default class OverlayStore { if (!updatePaneIds.includes(entry[0])) { updatePaneIds.push(entry[0]) } - instance.onRemoved?.({ overlay: instance }) + const o = instance.getOverlay() + o.onRemoved?.({ overlay: o }) return false } return true @@ -399,7 +319,8 @@ export default class OverlayStore { this._instances.forEach((paneInstances, paneId) => { updatePaneIds.push(paneId) paneInstances.forEach(instance => { - instance.onRemoved?.({ overlay: instance }) + const o = instance.getOverlay() + o.onRemoved?.({ overlay: o }) }) }) this._instances.clear() @@ -425,7 +346,8 @@ export default class OverlayStore { if (dataChangeLength > 0) { const dataList = this._chartStore.getDataList() this._instances.forEach(overlays => { - overlays.forEach(o => { + overlays.forEach(overlay => { + const o = overlay.getOverlay() const points = o.points points.forEach(point => { if (!isValid(point.timestamp) && isValid(point.dataIndex)) { @@ -443,28 +365,29 @@ export default class OverlayStore { setHoverInstanceInfo (info: EventOverlayInfo, event: MouseTouchEvent): void { const { instance, figureType, figureKey, figureIndex } = this._hoverInstanceInfo + const overlay = instance?.getOverlay() + const infoOverlay = info.instance?.getOverlay() if ( - instance?.id !== info.instance?.id || + overlay?.id !== infoOverlay?.id || figureType !== info.figureType || figureIndex !== info.figureIndex ) { this._hoverInstanceInfo = info - if (instance?.id !== info.instance?.id) { + if (overlay?.id !== infoOverlay?.id) { let ignoreUpdateFlag = false let sortFlag = false if (instance !== null) { sortFlag = true - if (isFunction(instance.onMouseLeave)) { - instance.onMouseLeave({ overlay: instance, figureKey, figureIndex, ...event }) + if (isFunction(overlay?.onMouseLeave)) { + overlay?.onMouseLeave({ overlay, figureKey, figureIndex, ...event }) ignoreUpdateFlag = true } } - if (info.instance !== null) { + if (infoOverlay !== null) { sortFlag = true - info.instance.setZLevel(OVERLAY_ACTIVE_Z_LEVEL) - if (isFunction(info.instance.onMouseEnter)) { - info.instance.onMouseEnter({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) + if (isFunction(infoOverlay?.onMouseEnter)) { + infoOverlay?.onMouseEnter({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) ignoreUpdateFlag = true } } @@ -484,14 +407,16 @@ export default class OverlayStore { setClickInstanceInfo (info: EventOverlayInfo, event: MouseTouchEvent): void { const { paneId, instance, figureType, figureKey, figureIndex } = this._clickInstanceInfo + const overlay = instance?.getOverlay() + const infoOverlay = info.instance?.getOverlay() if (!(info.instance?.isDrawing() ?? false)) { - info.instance?.onClick?.({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) + infoOverlay?.onClick?.({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) } - if (instance?.id !== info.instance?.id || figureType !== info.figureType || figureIndex !== info.figureIndex) { + if (overlay?.id !== infoOverlay?.id || figureType !== info.figureType || figureIndex !== info.figureIndex) { this._clickInstanceInfo = info - if (instance?.id !== info.instance?.id) { - instance?.onDeselected?.({ overlay: instance, figureKey, figureIndex, ...event }) - info.instance?.onSelected?.({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) + if (overlay?.id !== infoOverlay?.id) { + overlay?.onDeselected?.({ overlay, figureKey, figureIndex, ...event }) + infoOverlay?.onSelected?.({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event }) const chart = this._chartStore.getChart() chart.updatePane(UpdateLevel.Overlay, info.paneId) if (paneId !== info.paneId) { diff --git a/src/view/OverlayView.ts b/src/view/OverlayView.ts index 9953e964a..abed83c1a 100644 --- a/src/view/OverlayView.ts +++ b/src/view/OverlayView.ts @@ -26,8 +26,8 @@ import { type CustomApi } from '../Options' import type Axis from '../component/Axis' import type XAxis from '../component/XAxis' import type YAxis from '../component/YAxis' -import { type OverlayPrecision, type OverlayFigure, type OverlayFigureIgnoreEventType } from '../component/Overlay' -import type Overlay from '../component/Overlay' +import { type OverlayPrecision, type OverlayFigure, type OverlayFigureIgnoreEventType, type Overlay } from '../component/Overlay' +import type OverlayImp from '../component/Overlay' import { OVERLAY_FIGURE_KEY_PREFIX, OverlayMode, getAllOverlayFigureIgnoreEventTypes } from '../component/Overlay' import { type ProgressOverlayInfo, type EventOverlayInfo } from '../store/OverlayStore' @@ -61,11 +61,12 @@ export default class OverlayView extends View { overlayStore.updateProgressInstanceInfo(paneId) progressInstancePaneId = paneId } - const index = overlay.points.length - 1 + const o = overlay.getOverlay() + const index = o.points.length - 1 const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}` if (overlay.isDrawing() && progressInstancePaneId === paneId) { - overlay.eventMoveForDrawing(this._coordinateToPoint(progressInstanceInfo.instance, event)) - overlay.onDrawing?.({ overlay, figureKey: key, figureIndex: index, ...event }) + overlay.eventMoveForDrawing(this._coordinateToPoint(progressInstanceInfo.instance.getOverlay(), event)) + o.onDrawing?.({ overlay: o, figureKey: key, figureIndex: index, ...event }) } return this._figureMouseMoveEvent( overlay, @@ -88,15 +89,16 @@ export default class OverlayView extends View { overlayStore.updateProgressInstanceInfo(paneId, true) progressInstancePaneId = paneId } - const index = overlay.points.length - 1 + const o = overlay.getOverlay() + const index = o.points.length - 1 const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}` if (overlay.isDrawing() && progressInstancePaneId === paneId) { - overlay.eventMoveForDrawing(this._coordinateToPoint(overlay, event)) - overlay.onDrawing?.({ overlay, figureKey: key, figureIndex: index, ...event }) + overlay.eventMoveForDrawing(this._coordinateToPoint(o, event)) + o.onDrawing?.({ overlay: o, figureKey: key, figureIndex: index, ...event }) overlay.nextStep() if (!overlay.isDrawing()) { overlayStore.progressInstanceComplete() - overlay.onDrawEnd?.({ overlay, figureKey: key, figureIndex: index, ...event }) + o.onDrawEnd?.({ overlay: o, figureKey: key, figureIndex: index, ...event }) } } return this._figureMouseClickEvent( @@ -116,16 +118,17 @@ export default class OverlayView extends View { if (progressInstanceInfo !== null) { const overlay = progressInstanceInfo.instance const progressInstancePaneId = progressInstanceInfo.paneId + const o = overlay.getOverlay() if (overlay.isDrawing() && progressInstancePaneId === paneId) { overlay.forceComplete() if (!overlay.isDrawing()) { overlayStore.progressInstanceComplete() - const index = overlay.points.length - 1 + const index = o.points.length - 1 const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}` - overlay.onDrawEnd?.({ overlay, figureKey: key, figureIndex: index, ...event }) + o.onDrawEnd?.({ overlay: o, figureKey: key, figureIndex: index, ...event }) } } - const index = overlay.points.length - 1 + const index = o.points.length - 1 return this._figureMouseClickEvent( overlay, EventOverlayInfoFigureType.Point, @@ -140,7 +143,7 @@ export default class OverlayView extends View { if (progressInstanceInfo !== null) { const overlay = progressInstanceInfo.instance if (overlay.isDrawing()) { - const index = overlay.points.length - 1 + const index = overlay.getOverlay().points.length - 1 return this._figureMouseRightClickEvent( overlay, EventOverlayInfoFigureType.Point, @@ -154,7 +157,8 @@ export default class OverlayView extends View { }).registerEvent('mouseUpEvent', (event: MouseTouchEvent) => { const { instance, figureIndex, figureKey } = overlayStore.getPressedInstanceInfo() if (instance !== null) { - instance.onPressedMoveEnd?.({ overlay: instance, figureKey, figureIndex, ...event }) + const o = instance.getOverlay() + o.onPressedMoveEnd?.({ overlay: o, figureKey, figureIndex, ...event }) } overlayStore.setPressedInstanceInfo({ paneId, instance: null, figureType: EventOverlayInfoFigureType.None, figureKey: '', figureIndex: -1, attrsIndex: -1 @@ -163,9 +167,10 @@ export default class OverlayView extends View { }).registerEvent('pressedMouseMoveEvent', (event: MouseTouchEvent) => { const { instance, figureType, figureIndex, figureKey } = overlayStore.getPressedInstanceInfo() if (instance !== null) { - if (!instance.lock) { - if (!(instance.onPressedMoving?.({ overlay: instance, figureIndex, figureKey, ...event }) ?? false)) { - const point = this._coordinateToPoint(instance, event) + const o = instance.getOverlay() + if (!o.lock) { + if (!(o.onPressedMoving?.({ overlay: o, figureIndex, figureKey, ...event }) ?? false)) { + const point = this._coordinateToPoint(o, event) if (figureType === EventOverlayInfoFigureType.Point) { instance.eventPressedPointMove(point, figureIndex) } else { @@ -180,7 +185,7 @@ export default class OverlayView extends View { } private _createFigureEvents ( - overlay: Overlay, + overlay: OverlayImp, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, @@ -233,7 +238,7 @@ export default class OverlayView extends View { return eventHandler } - private _figureMouseMoveEvent (overlay: Overlay, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, attrsIndex: number): MouseTouchEventCallback { + private _figureMouseMoveEvent (overlay: OverlayImp, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { const pane = this.getWidget().getPane() const overlayStore = pane.getChart().getChartStore().getOverlayStore() @@ -244,19 +249,20 @@ export default class OverlayView extends View { } } - private _figureMouseDownEvent (overlay: Overlay, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, attrsIndex: number): MouseTouchEventCallback { + private _figureMouseDownEvent (overlay: OverlayImp, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { const pane = this.getWidget().getPane() const paneId = pane.getId() const overlayStore = pane.getChart().getChartStore().getOverlayStore() - overlay.startPressedMove(this._coordinateToPoint(overlay, event)) - overlay.onPressedMoveStart?.({ overlay, figureIndex, figureKey, ...event }) + const o = overlay.getOverlay() + overlay.startPressedMove(this._coordinateToPoint(o, event)) + o.onPressedMoveStart?.({ overlay: o, figureIndex, figureKey, ...event }) overlayStore.setPressedInstanceInfo({ paneId, instance: overlay, figureType, figureKey, figureIndex, attrsIndex }) return true } } - private _figureMouseClickEvent (overlay: Overlay, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, attrsIndex: number): MouseTouchEventCallback { + private _figureMouseClickEvent (overlay: OverlayImp, figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { const pane = this.getWidget().getPane() const paneId = pane.getId() @@ -266,25 +272,27 @@ export default class OverlayView extends View { } } - private _figureMouseDoubleClickEvent (overlay: Overlay, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback { + private _figureMouseDoubleClickEvent (overlay: OverlayImp, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { - overlay.onDoubleClick?.({ ...event, figureIndex, figureKey, overlay }) + const o = overlay.getOverlay() + o.onDoubleClick?.({ ...event, figureIndex, figureKey, overlay: o }) return true } } - private _figureMouseRightClickEvent (overlay: Overlay, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback { + private _figureMouseRightClickEvent (overlay: OverlayImp, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback { return (event: MouseTouchEvent) => { - if (!(overlay.onRightClick?.({ overlay, figureIndex, figureKey, ...event }) ?? false)) { + const o = overlay.getOverlay() + if (!(o.onRightClick?.({ overlay: o, figureIndex, figureKey, ...event }) ?? false)) { const pane = this.getWidget().getPane() const overlayStore = pane.getChart().getChartStore().getOverlayStore() - overlayStore.removeInstance(overlay) + overlayStore.removeInstance(o) } return true } } - private _coordinateToPoint (overlay: Overlay, coordinate: Coordinate): Partial { + private _coordinateToPoint (o: Overlay, coordinate: Coordinate): Partial { const point: Partial = {} const pane = this.getWidget().getPane() const chart = pane.getChart() @@ -300,12 +308,12 @@ export default class OverlayView extends View { if (this.coordinateToPointValueFlag()) { const yAxis = pane.getAxisComponent() let value = yAxis.convertFromPixel(coordinate.y) - if (overlay.mode !== OverlayMode.Normal && paneId === PaneIdConstants.CANDLE && isNumber(point.dataIndex)) { + if (o.mode !== OverlayMode.Normal && paneId === PaneIdConstants.CANDLE && isNumber(point.dataIndex)) { const kLineData = timeScaleStore.getDataByDataIndex(point.dataIndex) if (kLineData !== null) { - const modeSensitivity = overlay.modeSensitivity + const modeSensitivity = o.modeSensitivity if (value > kLineData.high) { - if (overlay.mode === OverlayMode.WeakMagnet) { + if (o.mode === OverlayMode.WeakMagnet) { const highY = yAxis.convertToPixel(kLineData.high) const buffValue = yAxis.convertFromPixel(highY - modeSensitivity) if (value < buffValue) { @@ -315,7 +323,7 @@ export default class OverlayView extends View { value = kLineData.high } } else if (value < kLineData.low) { - if (overlay.mode === OverlayMode.WeakMagnet) { + if (o.mode === OverlayMode.WeakMagnet) { const lowY = yAxis.convertToPixel(kLineData.low) const buffValue = yAxis.convertFromPixel(lowY - modeSensitivity) if (value > buffValue) { @@ -410,7 +418,7 @@ export default class OverlayView extends View { excludePriceVolumeMin: Number.MAX_SAFE_INTEGER }) overlays.forEach(overlay => { - if (overlay.visible) { + if (overlay.getOverlay().visible) { this._drawOverlay( ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, @@ -423,7 +431,7 @@ export default class OverlayView extends View { if (progressInstanceInfo !== null) { const overlay = this.getProgressOverlay(progressInstanceInfo, paneId) // eslint-disable-next-line @typescript-eslint/prefer-optional-chain - if (overlay !== null && overlay.visible) { + if (isValid(overlay) && overlay.getOverlay().visible) { this._drawOverlay( ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, @@ -436,7 +444,7 @@ export default class OverlayView extends View { private _drawOverlay ( ctx: CanvasRenderingContext2D, - overlay: Overlay, + overlay: OverlayImp, bounding: Bounding, barSpace: BarSpace, precision: OverlayPrecision, @@ -451,7 +459,8 @@ export default class OverlayView extends View { clickInstanceInfo: EventOverlayInfo, timeScaleStore: TimeScaleStore ): void { - const { points } = overlay + const o = overlay.getOverlay() + const { points } = o const coordinates = points.map(point => { let dataIndex = point.dataIndex if (isNumber(point.timestamp)) { @@ -469,7 +478,7 @@ export default class OverlayView extends View { if (coordinates.length > 0) { const figures = new Array().concat( this.getFigures( - overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis + o, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis ) ) this.drawFigures( @@ -497,14 +506,15 @@ export default class OverlayView extends View { ) } - protected drawFigures (ctx: CanvasRenderingContext2D, overlay: Overlay, figures: OverlayFigure[], defaultStyles: OverlayStyle): void { + protected drawFigures (ctx: CanvasRenderingContext2D, overlay: OverlayImp, figures: OverlayFigure[], defaultStyles: OverlayStyle): void { + const o = overlay.getOverlay() figures.forEach((figure, figureIndex) => { const { type, styles, attrs, ignoreEvent } = figure // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const attrsArray = [].concat(attrs) attrsArray.forEach((ats, attrsIndex) => { const events = this._createFigureEvents(overlay, EventOverlayInfoFigureType.Other, figure.key ?? '', figureIndex, attrsIndex, ignoreEvent) - const ss = { ...defaultStyles[type], ...overlay.styles?.[type], ...styles } + const ss = { ...defaultStyles[type], ...o.styles?.[type], ...styles } this.createFigure({ name: type, attrs: ats, styles: ss }, events)?.draw(ctx) @@ -512,11 +522,11 @@ export default class OverlayView extends View { }) } - protected getCompleteOverlays (overlayStore: OverlayStore, paneId: string): Overlay[] { + protected getCompleteOverlays (overlayStore: OverlayStore, paneId: string): OverlayImp[] { return overlayStore.getInstances(paneId) } - protected getProgressOverlay (info: ProgressOverlayInfo, paneId: string): Nullable { + protected getProgressOverlay (info: ProgressOverlayInfo, paneId: string): Nullable { if (info.paneId === paneId) { return info.instance } @@ -524,7 +534,7 @@ export default class OverlayView extends View { } protected getFigures ( - overlay: Overlay, + o: Overlay, coordinates: Coordinate[], bounding: Bounding, barSpace: BarSpace, @@ -536,12 +546,12 @@ export default class OverlayView extends View { xAxis: Nullable, yAxis: Nullable ): OverlayFigure | OverlayFigure[] { - return overlay.createPointFigures?.({ overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis }) ?? [] + return o.createPointFigures?.({ overlay: o, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis }) ?? [] } protected drawDefaultFigures ( ctx: CanvasRenderingContext2D, - overlay: Overlay, + overlay: OverlayImp, coordinates: Coordinate[], _bounding: Bounding, _precision: OverlayPrecision, @@ -555,12 +565,13 @@ export default class OverlayView extends View { hoverInstanceInfo: EventOverlayInfo, clickInstanceInfo: EventOverlayInfo ): void { - if (overlay.needDefaultPointFigure) { + const o = overlay.getOverlay() + if (o.needDefaultPointFigure) { if ( - (hoverInstanceInfo.instance?.id === overlay.id && hoverInstanceInfo.figureType !== EventOverlayInfoFigureType.None) || - (clickInstanceInfo.instance?.id === overlay.id && clickInstanceInfo.figureType !== EventOverlayInfoFigureType.None) + (hoverInstanceInfo.instance?.getOverlay().id === o.id && hoverInstanceInfo.figureType !== EventOverlayInfoFigureType.None) || + (clickInstanceInfo.instance?.getOverlay().id === o.id && clickInstanceInfo.figureType !== EventOverlayInfoFigureType.None) ) { - const styles = overlay.styles + const styles = o.styles const pointStyles = { ...defaultStyles.point, ...styles?.point } coordinates.forEach(({ x, y }, index) => { let radius = pointStyles.radius @@ -568,7 +579,7 @@ export default class OverlayView extends View { let borderColor = pointStyles.borderColor let borderSize = pointStyles.borderSize if ( - hoverInstanceInfo.instance?.id === overlay.id && + hoverInstanceInfo.instance?.getOverlay().id === o.id && hoverInstanceInfo.figureType === EventOverlayInfoFigureType.Point && hoverInstanceInfo.figureIndex === index ) { diff --git a/src/view/OverlayXAxisView.ts b/src/view/OverlayXAxisView.ts index 0e7b20709..ef6599dad 100644 --- a/src/view/OverlayXAxisView.ts +++ b/src/view/OverlayXAxisView.ts @@ -24,8 +24,8 @@ import { type CustomApi, FormatDateType } from '../Options' import type XAxis from '../component/XAxis' import type YAxis from '../component/YAxis' -import { type OverlayPrecision, type OverlayFigure } from '../component/Overlay' -import type Overlay from '../component/Overlay' +import { type OverlayPrecision, type OverlayFigure, type Overlay } from '../component/Overlay' +import type OverlayImp from '../component/Overlay' import { type EventOverlayInfo, type ProgressOverlayInfo } from '../store/OverlayStore' import type OverlayStore from '../store/OverlayStore' @@ -41,11 +41,11 @@ export default class OverlayXAxisView extends OverlayYAxisView { return false } - override getCompleteOverlays (overlayStore: OverlayStore): Overlay[] { + override getCompleteOverlays (overlayStore: OverlayStore): OverlayImp[] { return overlayStore.getInstances() } - override getProgressOverlay (info: ProgressOverlayInfo): Overlay { + override getProgressOverlay (info: ProgressOverlayInfo): OverlayImp { return info.instance } @@ -63,7 +63,7 @@ export default class OverlayXAxisView extends OverlayYAxisView { clickInstanceInfo: EventOverlayInfo ): OverlayFigure[] { const figures: OverlayFigure[] = [] - if (overlay.needDefaultXAxisFigure && overlay.id === clickInstanceInfo.instance?.id) { + if (overlay.needDefaultXAxisFigure && overlay.id === clickInstanceInfo.instance?.getOverlay().id) { let leftX = Number.MAX_SAFE_INTEGER let rightX = Number.MIN_SAFE_INTEGER coordinates.forEach((coordinate, index) => { @@ -83,7 +83,7 @@ export default class OverlayXAxisView extends OverlayYAxisView { } override getFigures ( - overlay: Overlay, + o: Overlay, coordinates: Coordinate[], bounding: Bounding, barSpace: BarSpace, @@ -95,6 +95,6 @@ export default class OverlayXAxisView extends OverlayYAxisView { xAxis: Nullable, yAxis: Nullable ): OverlayFigure | OverlayFigure[] { - return overlay.createXAxisFigures?.({ overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis }) ?? [] + return o.createXAxisFigures?.({ overlay: o, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis }) ?? [] } } diff --git a/src/view/OverlayYAxisView.ts b/src/view/OverlayYAxisView.ts index ee7636a91..56b8cf266 100644 --- a/src/view/OverlayYAxisView.ts +++ b/src/view/OverlayYAxisView.ts @@ -24,8 +24,8 @@ import { isNumber } from '../common/utils/typeChecks' import type Axis from '../component/Axis' import type XAxis from '../component/XAxis' import type YAxis from '../component/YAxis' -import { type OverlayPrecision, type OverlayFigure } from '../component/Overlay' -import type Overlay from '../component/Overlay' +import { type OverlayPrecision, type OverlayFigure, type Overlay } from '../component/Overlay' +import type OverlayImp from '../component/Overlay' import { type EventOverlayInfo } from '../store/OverlayStore' @@ -38,7 +38,7 @@ export default class OverlayYAxisView extends OverlayVie override drawDefaultFigures ( ctx: CanvasRenderingContext2D, - overlay: Overlay, + overlay: OverlayImp, coordinates: Coordinate[], bounding: Bounding, precision: OverlayPrecision, @@ -55,7 +55,7 @@ export default class OverlayYAxisView extends OverlayVie this.drawFigures( ctx, overlay, - this.getDefaultFigures(overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, xAxis, yAxis, clickInstanceInfo), + this.getDefaultFigures(overlay.getOverlay(), coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, xAxis, yAxis, clickInstanceInfo), defaultStyles ) } @@ -76,7 +76,7 @@ export default class OverlayYAxisView extends OverlayVie const figures: OverlayFigure[] = [] if ( overlay.needDefaultYAxisFigure && - overlay.id === clickInstanceInfo.instance?.id && + overlay.id === clickInstanceInfo.instance?.getOverlay().id && clickInstanceInfo.paneId === this.getWidget().getPane().getId() ) { let topY = Number.MAX_SAFE_INTEGER