From c1e99618553faa3d3f70285f953325bdcd558e6f Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 29 Sep 2023 12:55:25 +0300 Subject: [PATCH 1/2] fix: volumes object is always persists in dynamic objects --- .../components/volumes/volumes.component.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/chart/components/volumes/volumes.component.ts b/src/chart/components/volumes/volumes.component.ts index 503541b9..d9d7e4be 100644 --- a/src/chart/components/volumes/volumes.component.ts +++ b/src/chart/components/volumes/volumes.component.ts @@ -23,8 +23,10 @@ export type VolumeColorResolver = (priceMovement: PriceMovement, colors: FullCha export class VolumesComponent extends ChartBaseElement { separateVolumes: SeparateVolumesComponent; + dynamicObjectsComponent: DynamicObjectsComponent; public volumesColorByChartTypeMap: Partial> = {}; volumesModel: VolumesModel; + volumesDrawer: VolumesDrawer public volumeVisibilityChangedSubject = new BehaviorSubject(false); public volumeIsSeparateModeChangedSubject = new BehaviorSubject(false); @@ -49,7 +51,8 @@ export class VolumesComponent extends ChartBaseElement { volumesModel, paneManager, ); - const volumesDrawer = new VolumesDrawer( + this.dynamicObjectsComponent = dynamicObjectsComponent; + this.volumesDrawer = new VolumesDrawer( config, this.volumesModel, chartComponent.chartModel, @@ -57,12 +60,7 @@ export class VolumesComponent extends ChartBaseElement { this.volumesColorByChartTypeMap, () => true, ); - dynamicObjectsComponent.model.addObject({ - id: volumesModel.id, - paneId: CHART_UUID, - drawer: volumesDrawer, - model: volumesModel, - }); + config.components.volumes.visible && this.addVolumesToDynamicObjects(); this.addChildEntity(this.separateVolumes); this.registerDefaultVolumeColorResolvers(); this.volumeVisibilityChangedSubject.next(config.components.volumes.visible); @@ -124,7 +122,9 @@ export class VolumesComponent extends ChartBaseElement { public setVisible(visible = true) { this.config.components.volumes.visible = visible; this.volumeVisibilityChangedSubject.next(visible); - if (this.config.components.volumes.showSeparately === true) { + visible ? + this.addVolumesToDynamicObjects() : this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id); + if (this.config.components.volumes.showSeparately) { if (visible) { this.separateVolumes.activateSeparateVolumes(); this.volumeIsSeparateModeChangedSubject.next(true); @@ -136,4 +136,13 @@ export class VolumesComponent extends ChartBaseElement { this.canvasBoundsContainer.recalculatePanesHeightRatios(); this.canvasModel.fireDraw(); } + + private addVolumesToDynamicObjects() { + this.dynamicObjectsComponent.model.addObject({ + id: this.volumesModel.id, + paneId: this.config.components.volumes.showSeparately ? this.volumesModel.id : CHART_UUID, + drawer: this.volumesDrawer, + model: this.volumesModel, + }); + } } From 94b406b6684a34a87129dff025873198ec73af7e Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Wed, 4 Oct 2023 10:36:07 +0300 Subject: [PATCH 2/2] fix: volumes object is always persists in dynamic objects --- src/chart/components/volumes/volumes.component.ts | 10 ++++------ src/chart/components/volumes/volumes.model.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/chart/components/volumes/volumes.component.ts b/src/chart/components/volumes/volumes.component.ts index d9d7e4be..bf81cdee 100644 --- a/src/chart/components/volumes/volumes.component.ts +++ b/src/chart/components/volumes/volumes.component.ts @@ -17,16 +17,15 @@ import { PaneManager } from '../pane/pane-manager.component'; import { SeparateVolumesComponent } from './separate-volumes.component'; import { resolveColorForBar, resolveColorForCandle, resolveColorForLine } from './volume-color-resolvers.functions'; import { VolumesDrawer } from './volumes.drawer'; -import { VolumesModel } from './volumes.model'; +import { VOLUMES_UUID, VolumesModel } from './volumes.model'; export type VolumeColorResolver = (priceMovement: PriceMovement, colors: FullChartColors) => string; export class VolumesComponent extends ChartBaseElement { separateVolumes: SeparateVolumesComponent; - dynamicObjectsComponent: DynamicObjectsComponent; public volumesColorByChartTypeMap: Partial> = {}; volumesModel: VolumesModel; - volumesDrawer: VolumesDrawer + private readonly volumesDrawer: VolumesDrawer; public volumeVisibilityChangedSubject = new BehaviorSubject(false); public volumeIsSeparateModeChangedSubject = new BehaviorSubject(false); @@ -38,7 +37,7 @@ export class VolumesComponent extends ChartBaseElement { drawingManager: DrawingManager, private config: FullChartConfig, paneManager: PaneManager, - dynamicObjectsComponent: DynamicObjectsComponent, + private dynamicObjectsComponent: DynamicObjectsComponent, ) { super(); const volumesModel = new VolumesModel(chartComponent, scale); @@ -51,7 +50,6 @@ export class VolumesComponent extends ChartBaseElement { volumesModel, paneManager, ); - this.dynamicObjectsComponent = dynamicObjectsComponent; this.volumesDrawer = new VolumesDrawer( config, this.volumesModel, @@ -140,7 +138,7 @@ export class VolumesComponent extends ChartBaseElement { private addVolumesToDynamicObjects() { this.dynamicObjectsComponent.model.addObject({ id: this.volumesModel.id, - paneId: this.config.components.volumes.showSeparately ? this.volumesModel.id : CHART_UUID, + paneId: this.config.components.volumes.showSeparately ? VOLUMES_UUID : CHART_UUID, drawer: this.volumesDrawer, model: this.volumesModel, }); diff --git a/src/chart/components/volumes/volumes.model.ts b/src/chart/components/volumes/volumes.model.ts index 0fed4aa2..2e2238ab 100644 --- a/src/chart/components/volumes/volumes.model.ts +++ b/src/chart/components/volumes/volumes.model.ts @@ -14,7 +14,7 @@ import { firstOf, maxMin } from '../../utils/array.utils'; const volumeMaxMinFn = maxMin(candle => candle.candle.volume); -const VOLUMES_UUID = 'volumes'; +export const VOLUMES_UUID = 'volumes'; export class VolumesModel extends ChartBaseElement { public readonly id = VOLUMES_UUID; // max volume in all data series