From 43e8b2bdda530b0caca4ce2aa854e096523fc7db Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Thu, 28 Sep 2023 15:08:39 +0300 Subject: [PATCH 1/3] enhancement: refactor-dataseries-and-dynamic-objects-ids --- src/chart/components/chart/chart.component.ts | 4 +++- .../components/dynamic-objects/dynamic-objects.model.ts | 5 +++-- src/chart/components/pane/extent/y-extent-component.ts | 3 ++- src/chart/components/pane/pane-hit-test.controller.ts | 4 ++-- src/chart/components/volumes/volumes.component.ts | 1 + src/chart/drawers/ht-data-series.drawer.ts | 2 +- src/chart/model/candle-series.model.ts | 2 +- src/chart/model/compare-series-hover.ts | 2 +- src/chart/model/data-series.model.ts | 4 +++- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/chart/components/chart/chart.component.ts b/src/chart/components/chart/chart.component.ts index d126da56..9c9327c5 100644 --- a/src/chart/components/chart/chart.component.ts +++ b/src/chart/components/chart/chart.component.ts @@ -134,6 +134,7 @@ export class ChartComponent extends ChartBaseElement { super.doActivate(); // TODO hack, main data series is created before doActivate, so we need to add it manually this.dynamicObjects.model.addObject({ + htId: this.chartModel.mainCandleSeries.htId, id: this.chartModel.mainCandleSeries.id, paneId: this.chartModel.mainCandleSeries.extentComponent.paneUUID, model: this.chartModel.mainCandleSeries, @@ -142,6 +143,7 @@ export class ChartComponent extends ChartBaseElement { this.addRxSubscription( this.paneManager.dataSeriesAddedSubject.subscribe(series => { this.dynamicObjects.model.addObject({ + htId: series.htId, id: series.id, paneId: series.extentComponent.paneUUID, model: series, @@ -151,7 +153,7 @@ export class ChartComponent extends ChartBaseElement { ); this.addRxSubscription( this.paneManager.dataSeriesRemovedSubject.subscribe(series => { - this.dynamicObjects.model.removeObject(series.id); + this.dynamicObjects.model.removeObject(series.htId); }), ); } diff --git a/src/chart/components/dynamic-objects/dynamic-objects.model.ts b/src/chart/components/dynamic-objects/dynamic-objects.model.ts index b87ec958..33f33e59 100644 --- a/src/chart/components/dynamic-objects/dynamic-objects.model.ts +++ b/src/chart/components/dynamic-objects/dynamic-objects.model.ts @@ -4,9 +4,10 @@ import { LinkedList, ListNode } from '../../utils/linkedList.utils'; import { DynamicModelDrawer } from './dynamic-objects.drawer'; export type PaneId = string; -type DynamicObjectId = string | number; +export type DynamicObjectId = string | number; export interface DynamicObject { + readonly htId: DynamicObjectId; readonly id: DynamicObjectId; readonly drawer: DynamicModelDrawer; readonly paneId: PaneId; @@ -57,7 +58,7 @@ export class DynamicObjectsModel extends ChartBaseElement { objects[paneId] = paneList; } paneList.insertAtEnd(obj); - this.modelIdToObjectMap.set(obj.id, obj); + this.modelIdToObjectMap.set(obj.id ?? obj.htId, obj); this.setDynamicObjects(objects); } diff --git a/src/chart/components/pane/extent/y-extent-component.ts b/src/chart/components/pane/extent/y-extent-component.ts index e33ddea9..50f0a6d5 100644 --- a/src/chart/components/pane/extent/y-extent-component.ts +++ b/src/chart/components/pane/extent/y-extent-component.ts @@ -16,6 +16,7 @@ import { import { ScaleModel } from '../../../model/scale.model'; import { HighLowProvider, mergeHighLow } from '../../../model/scaling/auto-scale.model'; import { Pixel, Price, Unit } from '../../../model/scaling/viewport.model'; +import { uuid } from '../../../utils/uuid.utils'; import { ChartBaseModel } from '../../chart/chart-base.model'; import { createYExtentFormatters } from '../../chart/price.formatter'; import { DragNDropYComponent } from '../../dran-n-drop_helper/drag-n-drop-y.component'; @@ -98,7 +99,7 @@ export class YExtentComponent extends ChartBaseElement { * @returns {DataSeriesModel} - The newly created DataSeriesModel object. */ public createDataSeries(): DataSeriesModel { - const series = new DataSeriesModel(this, this.hitTestController.getNewDataSeriesHitTestId()); + const series = new DataSeriesModel(this, this.hitTestController.getNewDataSeriesHitTestId(), uuid()); series.toVisualPoints = this.toVisualPoints; return series; } diff --git a/src/chart/components/pane/pane-hit-test.controller.ts b/src/chart/components/pane/pane-hit-test.controller.ts index b607243a..6e3daee4 100644 --- a/src/chart/components/pane/pane-hit-test.controller.ts +++ b/src/chart/components/pane/pane-hit-test.controller.ts @@ -38,7 +38,7 @@ export class PaneHitTestController implements HitTestSubscriber * @returns {DataSeriesModel | undefined} - The data series with the given ID, or undefined if it does not exist. */ public lookup(id: number): DataSeriesModel | undefined { - const result = this.allDataSeries.find(d => d.id === id); + const result = this.allDataSeries.find(d => d.htId === id); return result; } @@ -48,7 +48,7 @@ export class PaneHitTestController implements HitTestSubscriber * @returns {void} */ onHover(model: DataSeriesModel | null): void { - this.allDataSeries.forEach(d => (d.hovered = d.id === model?.id)); + this.allDataSeries.forEach(d => (d.hovered = d.htId === model?.htId)); this.canvasModel.fireDraw(); } diff --git a/src/chart/components/volumes/volumes.component.ts b/src/chart/components/volumes/volumes.component.ts index 503541b9..227bb0e4 100644 --- a/src/chart/components/volumes/volumes.component.ts +++ b/src/chart/components/volumes/volumes.component.ts @@ -58,6 +58,7 @@ export class VolumesComponent extends ChartBaseElement { () => true, ); dynamicObjectsComponent.model.addObject({ + htId: volumesModel.id, id: volumesModel.id, paneId: CHART_UUID, drawer: volumesDrawer, diff --git a/src/chart/drawers/ht-data-series.drawer.ts b/src/chart/drawers/ht-data-series.drawer.ts index cc4e2ef6..0fa11d9a 100644 --- a/src/chart/drawers/ht-data-series.drawer.ts +++ b/src/chart/drawers/ht-data-series.drawer.ts @@ -35,7 +35,7 @@ export class HTDataSeriesDrawer implements Drawer { const drawer = this.seriesDrawers[paintTool]; if (drawer) { const drawConfig: ChartDrawerConfig = { - singleColor: this.canvasModel.idToColor(series.id), + singleColor: this.canvasModel.idToColor(series.htId), forceBold: 7, }; // +- 1 to correctly draw points which are partly inside bounds diff --git a/src/chart/model/candle-series.model.ts b/src/chart/model/candle-series.model.ts index 090beff6..43cb6d46 100644 --- a/src/chart/model/candle-series.model.ts +++ b/src/chart/model/candle-series.model.ts @@ -72,7 +72,7 @@ export class CandleSeriesModel extends DataSeriesModel { private readonly candleWidthByChartType: Partial>, public colors: CandleSeriesColors = DEFAULT_CANDLE_SERIES_CONFIG, ) { - super(extentComponent, id); + super(extentComponent, id, id); this._instrument = instrument; this.instrument = instrument; this.highLowProvider = createCandleSeriesHighLowProvider(this); diff --git a/src/chart/model/compare-series-hover.ts b/src/chart/model/compare-series-hover.ts index 508c0748..351028e5 100644 --- a/src/chart/model/compare-series-hover.ts +++ b/src/chart/model/compare-series-hover.ts @@ -31,7 +31,7 @@ export class CompareSeriesHoverProducerPart implements HoverProducerPart = cloneUnsafe(DEFAULT_DATA_SERIES_CONFIG), ) { super(); From 63de931a10b43c210187343ab8fb96db0d37e13c Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Thu, 28 Sep 2023 15:16:02 +0300 Subject: [PATCH 2/3] enhancement: refactor-dataseries-and-dynamic-objects-ids --- src/chart/components/chart/chart.component.ts | 2 -- src/chart/components/dynamic-objects/dynamic-objects.model.ts | 3 +-- src/chart/components/volumes/volumes.component.ts | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/chart/components/chart/chart.component.ts b/src/chart/components/chart/chart.component.ts index 9c9327c5..a29377a9 100644 --- a/src/chart/components/chart/chart.component.ts +++ b/src/chart/components/chart/chart.component.ts @@ -134,7 +134,6 @@ export class ChartComponent extends ChartBaseElement { super.doActivate(); // TODO hack, main data series is created before doActivate, so we need to add it manually this.dynamicObjects.model.addObject({ - htId: this.chartModel.mainCandleSeries.htId, id: this.chartModel.mainCandleSeries.id, paneId: this.chartModel.mainCandleSeries.extentComponent.paneUUID, model: this.chartModel.mainCandleSeries, @@ -143,7 +142,6 @@ export class ChartComponent extends ChartBaseElement { this.addRxSubscription( this.paneManager.dataSeriesAddedSubject.subscribe(series => { this.dynamicObjects.model.addObject({ - htId: series.htId, id: series.id, paneId: series.extentComponent.paneUUID, model: series, diff --git a/src/chart/components/dynamic-objects/dynamic-objects.model.ts b/src/chart/components/dynamic-objects/dynamic-objects.model.ts index 33f33e59..9f05bc21 100644 --- a/src/chart/components/dynamic-objects/dynamic-objects.model.ts +++ b/src/chart/components/dynamic-objects/dynamic-objects.model.ts @@ -7,7 +7,6 @@ export type PaneId = string; export type DynamicObjectId = string | number; export interface DynamicObject { - readonly htId: DynamicObjectId; readonly id: DynamicObjectId; readonly drawer: DynamicModelDrawer; readonly paneId: PaneId; @@ -58,7 +57,7 @@ export class DynamicObjectsModel extends ChartBaseElement { objects[paneId] = paneList; } paneList.insertAtEnd(obj); - this.modelIdToObjectMap.set(obj.id ?? obj.htId, obj); + this.modelIdToObjectMap.set(obj.id, obj); this.setDynamicObjects(objects); } diff --git a/src/chart/components/volumes/volumes.component.ts b/src/chart/components/volumes/volumes.component.ts index 227bb0e4..503541b9 100644 --- a/src/chart/components/volumes/volumes.component.ts +++ b/src/chart/components/volumes/volumes.component.ts @@ -58,7 +58,6 @@ export class VolumesComponent extends ChartBaseElement { () => true, ); dynamicObjectsComponent.model.addObject({ - htId: volumesModel.id, id: volumesModel.id, paneId: CHART_UUID, drawer: volumesDrawer, From ba832c2e30f8335f3bc18e55cd6a3ea538785be1 Mon Sep 17 00:00:00 2001 From: Denis Travin Date: Fri, 29 Sep 2023 17:01:13 +0500 Subject: [PATCH 3/3] feat!: updated the mental model of id and htid for DataSeriesModel --- src/chart/components/chart/chart.component.ts | 2 +- src/chart/components/chart/chart.model.ts | 5 ++++- src/chart/components/pane/extent/y-extent-component.ts | 2 +- src/chart/model/candle-series.model.ts | 5 +++-- src/chart/model/compare-series-hover.ts | 6 ++++-- src/chart/model/data-series.model.ts | 3 +-- src/chart/model/main-candle-series.model.ts | 4 +++- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/chart/components/chart/chart.component.ts b/src/chart/components/chart/chart.component.ts index a29377a9..d126da56 100644 --- a/src/chart/components/chart/chart.component.ts +++ b/src/chart/components/chart/chart.component.ts @@ -151,7 +151,7 @@ export class ChartComponent extends ChartBaseElement { ); this.addRxSubscription( this.paneManager.dataSeriesRemovedSubject.subscribe(series => { - this.dynamicObjects.model.removeObject(series.htId); + this.dynamicObjects.model.removeObject(series.id); }), ); } diff --git a/src/chart/components/chart/chart.model.ts b/src/chart/components/chart/chart.model.ts index 70ce937b..0d29f9ac 100755 --- a/src/chart/components/chart/chart.model.ts +++ b/src/chart/components/chart/chart.model.ts @@ -38,6 +38,7 @@ import { ChartBaseModel } from './chart-base.model'; import { CandleSeries, ChartInstrument, PartialCandle } from './chart.component'; import { fakeCandle } from './fake-candles'; import { SecondaryChartColorsPool } from './secondary-chart-colors-pool'; +import { uuid } from '../../utils/uuid.utils'; export type VisualCandleCalculator = ( candle: Candle, @@ -93,6 +94,7 @@ export class ChartModel extends ChartBaseElement { const candleSeries = new MainCandleSeriesModel( this.chartBaseModel, this.paneManager.panes[CHART_UUID].mainExtent, + uuid(), this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, @@ -435,6 +437,7 @@ export class ChartModel extends ChartBaseElement { private createCandleSeriesModel(instrument: ChartInstrument, colors?: CandleSeriesColors): CandleSeriesModel { const candleSeries = new CandleSeriesModel( this.paneManager.panes[CHART_UUID].mainExtent, + uuid(), this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, @@ -620,7 +623,7 @@ export class ChartModel extends ChartBaseElement { // lineX is the middle of candle - it's correct return this.scale.toX(visualCandle.centerUnit); } - + /** * Transforms X coordinate (relative to canvas element) to Candle object. * If extrapolate = false, then it takes leftmost/rightmost existing candle diff --git a/src/chart/components/pane/extent/y-extent-component.ts b/src/chart/components/pane/extent/y-extent-component.ts index 50f0a6d5..cdaa554c 100644 --- a/src/chart/components/pane/extent/y-extent-component.ts +++ b/src/chart/components/pane/extent/y-extent-component.ts @@ -99,7 +99,7 @@ export class YExtentComponent extends ChartBaseElement { * @returns {DataSeriesModel} - The newly created DataSeriesModel object. */ public createDataSeries(): DataSeriesModel { - const series = new DataSeriesModel(this, this.hitTestController.getNewDataSeriesHitTestId(), uuid()); + const series = new DataSeriesModel(this, uuid(), this.hitTestController.getNewDataSeriesHitTestId()); series.toVisualPoints = this.toVisualPoints; return series; } diff --git a/src/chart/model/candle-series.model.ts b/src/chart/model/candle-series.model.ts index 43cb6d46..3f35e117 100644 --- a/src/chart/model/candle-series.model.ts +++ b/src/chart/model/candle-series.model.ts @@ -64,7 +64,8 @@ export class CandleSeriesModel extends DataSeriesModel { constructor( extentComponent: YExtentComponent, - id: number, + id: string, + htId: number, private eventBus: EventBus, scale: ScaleModel, instrument: ChartInstrument, @@ -72,7 +73,7 @@ export class CandleSeriesModel extends DataSeriesModel { private readonly candleWidthByChartType: Partial>, public colors: CandleSeriesColors = DEFAULT_CANDLE_SERIES_CONFIG, ) { - super(extentComponent, id, id); + super(extentComponent, id, htId); this._instrument = instrument; this.instrument = instrument; this.highLowProvider = createCandleSeriesHighLowProvider(this); diff --git a/src/chart/model/compare-series-hover.ts b/src/chart/model/compare-series-hover.ts index 351028e5..babd3881 100644 --- a/src/chart/model/compare-series-hover.ts +++ b/src/chart/model/compare-series-hover.ts @@ -9,7 +9,8 @@ import { BaseHover, HoverProducerPart } from '../inputhandlers/hover-producer.co export interface CompareSeriesHover { instrument: string; price: string; - id: number; + id: string; + htId: number; } export class CompareSeriesHoverProducerPart implements HoverProducerPart { @@ -31,7 +32,8 @@ export class CompareSeriesHoverProducerPart implements HoverProducerPart = cloneUnsafe(DEFAULT_DATA_SERIES_CONFIG), ) { super(); diff --git a/src/chart/model/main-candle-series.model.ts b/src/chart/model/main-candle-series.model.ts index dcddcdbe..89839b25 100644 --- a/src/chart/model/main-candle-series.model.ts +++ b/src/chart/model/main-candle-series.model.ts @@ -21,7 +21,8 @@ export class MainCandleSeriesModel extends CandleSeriesModel { constructor( private readonly baseModel: ChartBaseModel<'candle'>, extentComponent: YExtentComponent, - id: number, + id: string, + htId: number, eventBus: EventBus, scale: ScaleModel, instrument: ChartInstrument, @@ -32,6 +33,7 @@ export class MainCandleSeriesModel extends CandleSeriesModel { super( extentComponent, id, + htId, eventBus, scale, instrument,