From 80f60d7c7180f58d9f1981d9de3a24d0ec8cac73 Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Tue, 10 Dec 2024 11:02:58 +0000 Subject: [PATCH] Pull request #5379: Feature/DXCF-5566 new web multiple scales implement right click menu for additional multiple scales Merge in DXCHARTS/dxchart5 from feature/DXCF-5566-new-web-multiple-scales-implement-right-click-menu-for-additional-multiple-scales to master * commit 'ba42fb3152e74f902d3fb8892b7485e5a9634715': [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // fix data series align when moved to another pane [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init [DXCF-5566] [Web] Multiple scales - implement right-click menu for additional (multiple) scales // init GitOrigin-RevId: 31927af313e831f0506190e32d54045cad6c0625 --- .../components/pane/pane-manager.component.ts | 7 ++++- .../price_labels/y-axis-labels.model.ts | 8 +++++- .../components/y_axis/y-axis-scale.handler.ts | 5 ++++ src/chart/model/data-series.model.ts | 26 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/chart/components/pane/pane-manager.component.ts b/src/chart/components/pane/pane-manager.component.ts index 585db44..45953e5 100644 --- a/src/chart/components/pane/pane-manager.component.ts +++ b/src/chart/components/pane/pane-manager.component.ts @@ -314,7 +314,12 @@ export class PaneManager extends ChartBaseElement { if (extent) { pane.moveDataSeriesToExistingExtentComponent(dataSeries, initialPane, initialExtent, extent); } else { - pane.moveDataSeriesToNewExtentComponent(dataSeries, initialPane, initialExtent); + pane.moveDataSeriesToNewExtentComponent( + dataSeries, + initialPane, + initialExtent, + initialExtent.yAxis.state.align, + ); } initialPane.yExtentComponents.length === 0 && this.removePane(initialPane.uuid); } diff --git a/src/chart/components/y_axis/price_labels/y-axis-labels.model.ts b/src/chart/components/y_axis/price_labels/y-axis-labels.model.ts index 9bb85e7..d9bb519 100644 --- a/src/chart/components/y_axis/price_labels/y-axis-labels.model.ts +++ b/src/chart/components/y_axis/price_labels/y-axis-labels.model.ts @@ -69,7 +69,12 @@ export class FancyYAxisLabelsModel extends ChartBaseElement { * an easier way to manage custom y-axis labels, than y-axis labels providers, but doesn't support overlapping avoidance */ public readonly customLabels: Record = {}; - private labelsProviders: Record> = {}; + private _labelsProviders: Record> = {}; + + get labelsProviders(): Record> { + return this._labelsProviders; + } + private labelsPositionRecalculatedSubject: Subject = new Subject(); private animFrameId = `anim_cache_${uuid()}`; @@ -276,4 +281,5 @@ export class FancyYAxisLabelsModel extends ChartBaseElement { */ export interface YAxisLabelsProvider { readonly getUnorderedLabels: () => LabelGroup[]; + yAxisBoundsProvider?: () => Bounds; } diff --git a/src/chart/components/y_axis/y-axis-scale.handler.ts b/src/chart/components/y_axis/y-axis-scale.handler.ts index 8f68d2e..b789828 100644 --- a/src/chart/components/y_axis/y-axis-scale.handler.ts +++ b/src/chart/components/y_axis/y-axis-scale.handler.ts @@ -1,3 +1,8 @@ +/* + * Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited + * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ /* * Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. diff --git a/src/chart/model/data-series.model.ts b/src/chart/model/data-series.model.ts index c18341a..d9b38a8 100644 --- a/src/chart/model/data-series.model.ts +++ b/src/chart/model/data-series.model.ts @@ -5,6 +5,7 @@ */ import { YExtentComponent } from '../components/pane/extent/y-extent-component'; import { DataSeriesYAxisLabelsProvider } from '../components/y_axis/price_labels/data-series-y-axis-labels.provider'; +import { LabelsGroups } from '../components/y_axis/price_labels/y-axis-labels.model'; import { binarySearch, create2DArray, lastOf, slice2DArray } from '../utils/array.utils'; import { floorToDPR } from '../utils/device/device-pixel-ratio.utils'; import { MathUtils } from '../utils/math.utils'; @@ -151,6 +152,7 @@ export class DataSeriesModel< this.addRxSubscription( this.scale.scaleInversedSubject.subscribe(() => { this.recalculateVisualPoints(); + this.extentComponent.dynamicObjectsCanvasModel.fireDraw(); }), ); } @@ -185,6 +187,7 @@ export class DataSeriesModel< * @param extent */ public moveToExtent(extent: YExtentComponent) { + const prevExtent = { ...this.extentComponent }; this.extentComponent.removeDataSeries(this); this.extentComponent = extent; this.scale = extent.scale; @@ -196,6 +199,29 @@ export class DataSeriesModel< ); this.yAxisLabelProvider.yAxisBoundsProvider = extent.getYAxisBounds; this.yAxisLabelProvider.axisState = extent.yAxis?.state; + // move data series labels + const prevExtentMainLabels = prevExtent.yAxis.model.fancyLabelsModel.labelsProviders[LabelsGroups.MAIN]; + const dataSeriesLabelsId = + prevExtentMainLabels && Object.keys(prevExtentMainLabels).find(p => this.parentId && p === this.parentId); + const currentMainLabels = this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[LabelsGroups.MAIN]; + if (dataSeriesLabelsId) { + const labelsProvider = prevExtentMainLabels[dataSeriesLabelsId]; + labelsProvider.yAxisBoundsProvider = extent.getYAxisBounds; + // main group is not created yet (new extent without labels) or main group exists but no data series labels so far + if (!currentMainLabels || (currentMainLabels && !currentMainLabels[dataSeriesLabelsId])) { + // create new data series labels group on the new extent + this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider( + LabelsGroups.MAIN, + labelsProvider, + dataSeriesLabelsId, + ); + // remove labels from previous extent + prevExtent.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider( + LabelsGroups.MAIN, + dataSeriesLabelsId, + ); + } + } // shut down old subscriptions this.deactivate(); // and apply new ones (with updated scaleModel)