@devexperts/dxcharts-lite 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import { CanvasAnimation } from './animation/canvas-animation';
8
8
  import { CHART_UUID, CanvasBoundsContainer, CanvasElement } from './canvas/canvas-bounds-container';
9
9
  import { CursorHandler } from './canvas/cursor.handler';
10
10
  import { createDefaultLayoutTemplate, extractElements } from './canvas/layout-creator';
11
- import { mergeWithDefaultConfig } from './chart.config';
11
+ import { mergeWithDefaultConfig, } from './chart.config';
12
12
  import { ChartBaseModel } from './components/chart/chart-base.model';
13
13
  import { ChartComponent } from './components/chart/chart.component';
14
14
  import { ChartModel } from './components/chart/chart.model';
@@ -170,7 +170,7 @@ export default class ChartBootstrap {
170
170
  this.initYAxisDrawer(yAxisLabelsCanvasModel);
171
171
  this.yAxisComponent = mainPane.mainExtent.yAxis;
172
172
  // default labels provider
173
- const lastCandleLabelsProvider = new LastCandleLabelsProvider(this.chartModel, this.config, this.chartModel.lastCandleLabelsByChartType, this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));
173
+ const lastCandleLabelsProvider = new LastCandleLabelsProvider(this.chartModel, this.config, mainPane.mainExtent.yAxis.state, this.chartModel.lastCandleLabelsByChartType, this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));
174
174
  this.yAxisComponent.registerYAxisLabelsProvider(lastCandleLabelsProvider, LabelsGroups.MAIN);
175
175
  this.volumesComponent = new VolumesComponent(this.dynamicObjectsCanvasModel, chartComponent, scaleModel, canvasBoundsContainer, drawingManager, config, paneManager, this.dynamicObjects);
176
176
  this.chartComponents.push(this.volumesComponent);
@@ -8,10 +8,10 @@ import { DataSeriesModel, DataSeriesPoint, VisualSeriesPoint } from '../../model
8
8
  import { HitTestSubscriber } from '../../model/hit-test-canvas.model';
9
9
  import { PaneComponent } from './pane.component';
10
10
  export declare class PaneHitTestController implements HitTestSubscriber<DataSeriesModel> {
11
- private readonly paneComponents;
11
+ private readonly panes;
12
12
  private canvasModel;
13
13
  private dataSeriesIdCounter;
14
- constructor(paneComponents: Record<string, PaneComponent>, canvasModel: CanvasModel);
14
+ constructor(panes: Record<string, PaneComponent>, canvasModel: CanvasModel);
15
15
  getNewDataSeriesHitTestId: () => number;
16
16
  /**
17
17
  * Returns an array with two numbers representing the range of IDs for data series.
@@ -6,8 +6,8 @@
6
6
  import { HIT_TEST_ID_RANGE } from '../../model/hit-test-canvas.model';
7
7
  import { flatMap } from '../../utils/array.utils';
8
8
  export class PaneHitTestController {
9
- constructor(paneComponents, canvasModel) {
10
- this.paneComponents = paneComponents;
9
+ constructor(panes, canvasModel) {
10
+ this.panes = panes;
11
11
  this.canvasModel = canvasModel;
12
12
  // used in hit test for creating series
13
13
  this.dataSeriesIdCounter = HIT_TEST_ID_RANGE.DATA_SERIES[0];
@@ -23,7 +23,7 @@ export class PaneHitTestController {
23
23
  return HIT_TEST_ID_RANGE.DATA_SERIES;
24
24
  }
25
25
  get allDataSeries() {
26
- return flatMap(flatMap(Object.values(this.paneComponents), c => c.yExtentComponents), p => Array.from(p.dataSeries));
26
+ return flatMap(flatMap(Object.values(this.panes), c => c.yExtentComponents), p => Array.from(p.dataSeries));
27
27
  }
28
28
  /**
29
29
  * Looks up a data series by its ID.
@@ -51,10 +51,10 @@ export class PaneHitTestController {
51
51
  this.handleYExtentDragEnd();
52
52
  }
53
53
  handleYExtentDragStart(model) {
54
- Object.values(this.paneComponents).forEach(p => p.yExtentComponents.forEach(y => y.dragNDrop.deactivate()));
54
+ Object.values(this.panes).forEach(p => p.yExtentComponents.forEach(y => y.dragNDrop.deactivate()));
55
55
  model.extentComponent.dragNDrop.activate();
56
56
  }
57
57
  handleYExtentDragEnd() {
58
- Object.values(this.paneComponents).forEach(p => p.yExtentComponents.forEach(y => y.dragNDrop.activate()));
58
+ Object.values(this.panes).forEach(p => p.yExtentComponents.forEach(y => y.dragNDrop.activate()));
59
59
  }
60
60
  }
@@ -39,7 +39,8 @@ export declare class PaneManager extends ChartBaseElement {
39
39
  private mainCanvasModel;
40
40
  private yAxisLabelsCanvasModel;
41
41
  panes: Record<string, PaneComponent>;
42
- panesChangedSubject: Subject<Record<string, PaneComponent>>;
42
+ paneRemovedSubject: Subject<PaneComponent>;
43
+ paneAddedSubject: Subject<Record<string, PaneComponent>>;
43
44
  hitTestController: PaneHitTestController;
44
45
  dataSeriesAddedSubject: Subject<DataSeriesModel>;
45
46
  dataSeriesRemovedSubject: Subject<DataSeriesModel>;
@@ -38,7 +38,8 @@ export class PaneManager extends ChartBaseElement {
38
38
  this.mainCanvasModel = mainCanvasModel;
39
39
  this.yAxisLabelsCanvasModel = yAxisLabelsCanvasModel;
40
40
  this.panes = {};
41
- this.panesChangedSubject = new Subject();
41
+ this.paneRemovedSubject = new Subject();
42
+ this.paneAddedSubject = new Subject();
42
43
  this.dataSeriesAddedSubject = new Subject();
43
44
  this.dataSeriesRemovedSubject = new Subject();
44
45
  this.hitTestController = new PaneHitTestController(this.panes, this.dynamicObjectsCanvasModel);
@@ -104,7 +105,7 @@ export class PaneManager extends ChartBaseElement {
104
105
  paneComponent.activate();
105
106
  this.recalculateState();
106
107
  paneComponent.mainExtent.scale.autoScale(true);
107
- this.panesChangedSubject.next(this.panes);
108
+ this.paneAddedSubject.next(this.panes);
108
109
  return paneComponent;
109
110
  }
110
111
  /**
@@ -114,11 +115,11 @@ export class PaneManager extends ChartBaseElement {
114
115
  removePane(uuid) {
115
116
  const pane = this.panes[uuid];
116
117
  if (pane !== undefined) {
118
+ this.paneRemovedSubject.next(pane);
117
119
  pane.disable();
118
120
  pane.yExtentComponents.forEach(yExtentComponent => yExtentComponent.disable());
119
121
  delete this.panes[uuid];
120
122
  this.recalculateState();
121
- this.panesChangedSubject.next(this.panes);
122
123
  }
123
124
  }
124
125
  /**
@@ -18,7 +18,7 @@ export class WaterMarkComponent extends ChartBaseElement {
18
18
  this.waterMarkConfig = this.config.components.waterMark;
19
19
  this.waterMarkData = this.getWaterMarkData();
20
20
  this.waterMarkDrawer = new WaterMarkDrawer(this.config, canvasBoundsContainer, canvasModel, () => this.waterMarkConfig, () => this.waterMarkData);
21
- this.addRxSubscription(merge(canvasBoundsContainer.observeBoundsChanged(CanvasElement.PANE_UUID(CHART_UUID)), this.paneManager.panesChangedSubject).subscribe((bounds) => {
21
+ this.addRxSubscription(merge(canvasBoundsContainer.observeBoundsChanged(CanvasElement.PANE_UUID(CHART_UUID)), this.paneManager.paneAddedSubject).subscribe((bounds) => {
22
22
  this.waterMarkConfig = this.recalculateTextSize(bounds.width, bounds.height);
23
23
  }));
24
24
  this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(() => {
@@ -3,17 +3,18 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- import { FullChartConfig } from '../../../chart.config';
6
+ import { FullChartConfig, YAxisConfig } from '../../../chart.config';
7
7
  import { DataSeriesType } from '../../../model/data-series.config';
8
8
  import { ChartModel, LastCandleLabelHandler } from '../../chart/chart.model';
9
9
  import { LabelGroup, YAxisLabelsProvider } from './y-axis-labels.model';
10
10
  import { LabelColorResolver } from '../y-axis.component';
11
11
  export declare class LastCandleLabelsProvider implements YAxisLabelsProvider {
12
12
  private chartModel;
13
- private config;
13
+ private fullConfig;
14
+ private yAxisConfig;
14
15
  private lastCandleLabelsByChartType;
15
16
  private resolveLabelColorFn;
16
- constructor(chartModel: ChartModel, config: FullChartConfig, lastCandleLabelsByChartType: Partial<Record<DataSeriesType, LastCandleLabelHandler>>, resolveLabelColorFn: (chartType: DataSeriesType) => LabelColorResolver);
17
+ constructor(chartModel: ChartModel, fullConfig: FullChartConfig, yAxisConfig: YAxisConfig, lastCandleLabelsByChartType: Partial<Record<DataSeriesType, LastCandleLabelHandler>>, resolveLabelColorFn: (chartType: DataSeriesType) => LabelColorResolver);
17
18
  /**
18
19
  * Returns an array of LabelGroup objects that contain the labels for the yAxis of the chart.
19
20
  * @returns {LabelGroup[]} An array of LabelGroup objects that contain the labels for the yAxis of the chart.
@@ -7,9 +7,10 @@ import { getPrimaryLabelTextColor } from '../label-color.functions';
7
7
  import { lastOf } from '../../../utils/array.utils';
8
8
  import { getLabelTextColorByBackgroundColor } from '../../../utils/canvas/canvas-text-functions.utils';
9
9
  export class LastCandleLabelsProvider {
10
- constructor(chartModel, config, lastCandleLabelsByChartType, resolveLabelColorFn) {
10
+ constructor(chartModel, fullConfig, yAxisConfig, lastCandleLabelsByChartType, resolveLabelColorFn) {
11
11
  this.chartModel = chartModel;
12
- this.config = config;
12
+ this.fullConfig = fullConfig;
13
+ this.yAxisConfig = yAxisConfig;
13
14
  this.lastCandleLabelsByChartType = lastCandleLabelsByChartType;
14
15
  this.resolveLabelColorFn = resolveLabelColorFn;
15
16
  }
@@ -19,7 +20,7 @@ export class LastCandleLabelsProvider {
19
20
  */
20
21
  getUnorderedLabels() {
21
22
  const collectedLabels = [];
22
- const visible = this.config.components.yAxis.labels.settings.lastPrice.mode !== 'none';
23
+ const visible = this.yAxisConfig.labels.settings.lastPrice.mode !== 'none';
23
24
  if (visible) {
24
25
  // main candle series
25
26
  const yAxisVisualLabel = this.getYAxisVisualLabel(this.chartModel.mainCandleSeries);
@@ -27,7 +28,7 @@ export class LastCandleLabelsProvider {
27
28
  ? Object.assign(Object.assign({}, yAxisVisualLabel), this.getLabelDrawConfig(this.chartModel.mainCandleSeries, true)) : yAxisVisualLabel;
28
29
  if (mainCandleSeriesVisualLabel) {
29
30
  const mainCandleSeriesLabels = { labels: [mainCandleSeriesVisualLabel] };
30
- const handler = this.lastCandleLabelsByChartType[this.config.components.chart.type];
31
+ const handler = this.lastCandleLabelsByChartType[this.fullConfig.components.chart.type];
31
32
  handler === null || handler === void 0 ? void 0 : handler(mainCandleSeriesLabels, this.chartModel.mainCandleSeries);
32
33
  collectedLabels.push(mainCandleSeriesLabels);
33
34
  }
@@ -61,8 +62,8 @@ export class LastCandleLabelsProvider {
61
62
  if (lastCandle) {
62
63
  const y = series.view.toY(lastCandle.close);
63
64
  if (isFinite(y)) {
64
- const mode = this.config.components.yAxis.labels.settings.lastPrice.mode;
65
- const appearanceType = this.config.components.yAxis.labels.settings.lastPrice.type;
65
+ const mode = this.yAxisConfig.labels.settings.lastPrice.mode;
66
+ const appearanceType = this.yAxisConfig.labels.settings.lastPrice.type;
66
67
  return {
67
68
  y,
68
69
  labelWeight: 0,
@@ -17,6 +17,7 @@ export declare class YAxisModel extends ChartBaseElement {
17
17
  private paneUUID;
18
18
  private state;
19
19
  private canvasBoundsContainer;
20
+ private extentIdx;
20
21
  labelsGenerator: NumericYAxisLabelsGenerator;
21
22
  baseLabelsModel: YAxisBaseLabelsModel;
22
23
  fancyLabelsModel: FancyYAxisLabelsModel;
@@ -13,6 +13,7 @@ export class YAxisModel extends ChartBaseElement {
13
13
  this.paneUUID = paneUUID;
14
14
  this.state = state;
15
15
  this.canvasBoundsContainer = canvasBoundsContainer;
16
+ this.extentIdx = extentIdx;
16
17
  this.labelsGenerator = new NumericYAxisLabelsGenerator(null, dataSeriesProvider, scale, valueFormatter, () => this.state.type, state.labelHeight);
17
18
  this.baseLabelsModel = new YAxisBaseLabelsModel(scale, this.labelsGenerator, this.canvasBoundsContainer, paneUUID, extentIdx);
18
19
  this.addChildEntity(this.baseLabelsModel);
@@ -28,7 +29,7 @@ export class YAxisModel extends ChartBaseElement {
28
29
  .concat(this.fancyLabelsModel.orderedLabels.flatMap(l => l.labels).map(l => l.labelText))
29
30
  .reduce((maxLengthText, label) => (label.length > maxLengthText.length ? label : maxLengthText), '');
30
31
  },
31
- getYAxisIndex: () => 0,
32
+ getYAxisIndex: () => this.extentIdx,
32
33
  getYAxisState: () => this.state,
33
34
  getPaneUUID: () => this.paneUUID,
34
35
  };
@@ -50,7 +50,7 @@ export declare class ScaleModel extends ViewportModel {
50
50
  constructor(config: FullChartConfig, getBounds: BoundsProvider, canvasAnimation: CanvasAnimation);
51
51
  /**
52
52
  * The method adds a new "constraint" to the existing list of x-axis constraints for charting.
53
- * The "constrait" is expected to be an object containing information about the constraints, such as the minimum and maximum values for the x-axis.
53
+ * The "constraint" is expected to be an object containing information about the constraints, such as the minimum and maximum values for the x-axis.
54
54
  * @param constraint
55
55
  */
56
56
  addXConstraint(constraint: Constraints): void;
@@ -53,7 +53,7 @@ export class ScaleModel extends ViewportModel {
53
53
  }
54
54
  /**
55
55
  * The method adds a new "constraint" to the existing list of x-axis constraints for charting.
56
- * The "constrait" is expected to be an object containing information about the constraints, such as the minimum and maximum values for the x-axis.
56
+ * The "constraint" is expected to be an object containing information about the constraints, such as the minimum and maximum values for the x-axis.
57
57
  * @param constraint
58
58
  */
59
59
  addXConstraint(constraint) {
@@ -112,7 +112,7 @@ export class ScaleModel extends ViewportModel {
112
112
  lockedYEndViewportCalculator(constrainedState, this.zoomXYRatio);
113
113
  }
114
114
  if (this.state.auto) {
115
- this.autoScaleModel.setAutoAndRecalculateState(constrainedState, true);
115
+ this.autoScaleModel.doAutoYScale(constrainedState);
116
116
  }
117
117
  if (forceNoAnimation) {
118
118
  this.apply(constrainedState);
@@ -133,14 +133,14 @@ export class ScaleModel extends ViewportModel {
133
133
  const initialState = this.export();
134
134
  super.setXScale(xStart, xEnd, false);
135
135
  const state = this.export();
136
- const constraitedState = this.scalePostProcessor(initialState, state);
136
+ const constrainedState = this.scalePostProcessor(initialState, state);
137
137
  if (this.state.lockPriceToBarRatio) {
138
- lockedYEndViewportCalculator(constraitedState, this.zoomXYRatio);
138
+ lockedYEndViewportCalculator(constrainedState, this.zoomXYRatio);
139
139
  }
140
140
  if (this.state.auto) {
141
- this.autoScaleModel.setAutoAndRecalculateState(constraitedState, true);
141
+ this.autoScaleModel.doAutoYScale(constrainedState);
142
142
  }
143
- this.apply(constraitedState);
143
+ this.apply(constrainedState);
144
144
  }
145
145
  /**
146
146
  * Moves both xStart and xEnd without changing the viewport width (zoom).
@@ -153,12 +153,12 @@ export class ScaleModel extends ViewportModel {
153
153
  // always stop the animations
154
154
  this.haltAnimation();
155
155
  moveXStart(state, xStart);
156
- // there we need only candles constrait
157
- const constraitedState = this.scalePostProcessor(initialStateCopy, state);
156
+ // there we need only candles constraint
157
+ const constrainedState = this.scalePostProcessor(initialStateCopy, state);
158
158
  if (this.state.auto) {
159
- this.autoScaleModel.setAutoAndRecalculateState(constraitedState, true);
159
+ this.autoScaleModel.doAutoYScale(constrainedState);
160
160
  }
161
- this.apply(constraitedState);
161
+ this.apply(constrainedState);
162
162
  }
163
163
  /**
164
164
  * Moves both yStart and yEnd without changing the viewport height (zoom).
@@ -184,7 +184,7 @@ export class ScaleModel extends ViewportModel {
184
184
  // dont auto-scale if animation, otherwise - forced or config
185
185
  if ((!this.isViewportAnimationInProgress() && this.state.auto) || forceApply) {
186
186
  const state = this.export();
187
- this.autoScaleModel.setAutoAndRecalculateState(state, true);
187
+ this.autoScaleModel.doAutoYScale(state);
188
188
  if (!compareStates(state, this.export())) {
189
189
  this.apply(state);
190
190
  }
@@ -29,9 +29,8 @@ type HighLowPostProcessor = (highLow: HighLow) => HighLow;
29
29
  */
30
30
  export declare class AutoScaleViewportSubModel {
31
31
  private delegate;
32
- auto: boolean;
33
32
  highLowProviders: Record<string, HighLowProvider>;
34
- highLowPostPorcessor: Record<string, HighLowPostProcessor>;
33
+ highLowPostProcessor: Record<string, HighLowPostProcessor>;
35
34
  constructor(delegate: ViewportModel, highLowProviders?: Record<string, HighLowProvider>);
36
35
  /**
37
36
  * Sets a HighLowProvider for a given name.
@@ -55,10 +54,9 @@ export declare class AutoScaleViewportSubModel {
55
54
  /**
56
55
  * Sets the auto and recalculates the state of the viewport model.
57
56
  * @param {ViewportModelState} state - The state of the viewport model.
58
- * @param {boolean} auto - The auto value to set.
59
57
  * @returns {void}
60
58
  */
61
- setAutoAndRecalculateState(state: ViewportModelState, auto: boolean): void;
59
+ doAutoYScale(state: ViewportModelState): void;
62
60
  }
63
61
  /**
64
62
  * Y auto-scale viewport transformer. Calculates highLow for all chart visuals and recalculates the Y scale.
@@ -11,10 +11,8 @@
11
11
  export class AutoScaleViewportSubModel {
12
12
  constructor(delegate, highLowProviders) {
13
13
  this.delegate = delegate;
14
- // local state, used for pane X dragging
15
- this.auto = true;
16
14
  // post processors can apply some changes to high low before applying it
17
- this.highLowPostPorcessor = {};
15
+ this.highLowPostProcessor = {};
18
16
  this.highLowProviders = highLowProviders !== null && highLowProviders !== void 0 ? highLowProviders : {};
19
17
  }
20
18
  /**
@@ -40,19 +38,15 @@ export class AutoScaleViewportSubModel {
40
38
  * @returns {void}
41
39
  */
42
40
  setHighLowPostProcessor(name, processor) {
43
- this.highLowPostPorcessor[name] = processor;
41
+ this.highLowPostProcessor[name] = processor;
44
42
  }
45
43
  /**
46
44
  * Sets the auto and recalculates the state of the viewport model.
47
45
  * @param {ViewportModelState} state - The state of the viewport model.
48
- * @param {boolean} auto - The auto value to set.
49
46
  * @returns {void}
50
47
  */
51
- setAutoAndRecalculateState(state, auto) {
52
- this.auto = auto;
53
- if (auto) {
54
- autoScaleYViewportTransformer(this.delegate, state, Object.values(this.highLowProviders), Object.values(this.highLowPostPorcessor));
55
- }
48
+ doAutoYScale(state) {
49
+ autoScaleYViewportTransformer(this.delegate, state, Object.values(this.highLowProviders), Object.values(this.highLowPostProcessor));
56
50
  }
57
51
  }
58
52
  /**