@devexperts/dxcharts-lite 2.0.2 → 2.2.0
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.
- package/README.md +1 -1
- package/dist/chart/__tests__/chart.test.d.ts +6 -0
- package/dist/chart/__tests__/chart.test.js +51 -0
- package/dist/chart/__tests__/env.d.ts +5 -0
- package/dist/chart/__tests__/env.js +28 -0
- package/dist/chart/bootstrap.js +2 -2
- package/dist/chart/chart.config.d.ts +4 -1
- package/dist/chart/chart.config.js +1 -1
- package/dist/chart/components/chart/chart-base.model.d.ts +1 -1
- package/dist/chart/components/chart/chart.component.js +13 -3
- package/dist/chart/components/chart/chart.model.d.ts +2 -2
- package/dist/chart/components/chart/chart.model.js +9 -7
- package/dist/chart/components/cross_tool/cross-tool.component.d.ts +2 -1
- package/dist/chart/components/cross_tool/cross-tool.component.js +4 -3
- package/dist/chart/components/cross_tool/cross-tool.model.js +1 -0
- package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.d.ts +3 -1
- package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.js +3 -2
- package/dist/chart/components/dynamic-objects/dynamic-objects.component.js +1 -1
- package/dist/chart/components/dynamic-objects/dynamic-objects.model.d.ts +30 -10
- package/dist/chart/components/dynamic-objects/dynamic-objects.model.js +119 -57
- package/dist/chart/components/grid/grid.drawer.js +3 -1
- package/dist/chart/components/pane/extent/y-extent-component.js +2 -1
- package/dist/chart/components/pane/pane-hit-test.controller.js +2 -2
- package/dist/chart/components/volumes/volumes.component.d.ts +3 -0
- package/dist/chart/components/volumes/volumes.component.js +21 -4
- package/dist/chart/components/volumes/volumes.model.d.ts +2 -0
- package/dist/chart/components/volumes/volumes.model.js +2 -0
- package/dist/chart/components/x_axis/x-axis.component.js +2 -2
- package/dist/chart/components/y_axis/label-color.functions.d.ts +2 -1
- package/dist/chart/components/y_axis/label-color.functions.js +17 -0
- package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.d.ts +2 -2
- package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.js +27 -25
- package/dist/chart/components/y_axis/price_labels/labels-positions-calculator.js +24 -13
- package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.d.ts +3 -3
- package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.js +58 -40
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.d.ts +3 -3
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +15 -13
- package/dist/chart/components/y_axis/y-axis-scale.handler.js +1 -1
- package/dist/chart/components/y_axis/y-axis.component.d.ts +2 -1
- package/dist/chart/components/y_axis/y-axis.component.js +6 -2
- package/dist/chart/drawers/ht-data-series.drawer.js +1 -1
- package/dist/chart/inputhandlers/cross-event-producer.component.js +2 -1
- package/dist/chart/inputhandlers/hover-producer.component.d.ts +1 -1
- package/dist/chart/inputhandlers/hover-producer.component.js +8 -8
- package/dist/chart/inputlisteners/canvas-input-listener.component.d.ts +12 -5
- package/dist/chart/inputlisteners/canvas-input-listener.component.js +74 -62
- package/dist/chart/model/candle-series.model.d.ts +1 -1
- package/dist/chart/model/candle-series.model.js +2 -2
- package/dist/chart/model/compare-series-hover.d.ts +2 -1
- package/dist/chart/model/compare-series-hover.js +1 -0
- package/dist/chart/model/data-series.model.d.ts +3 -2
- package/dist/chart/model/data-series.model.js +2 -1
- package/dist/chart/model/main-candle-series.model.d.ts +1 -1
- package/dist/chart/model/main-candle-series.model.js +2 -2
- package/dist/chart/model/scale.model.d.ts +2 -0
- package/dist/chart/model/scale.model.js +11 -2
- package/dist/chart/utils/dom.utils.d.ts +7 -0
- package/dist/chart/utils/dom.utils.js +12 -0
- package/dist/chart/utils/linkedList.utils.d.ts +3 -3
- package/dist/chart/utils/linkedList.utils.js +55 -57
- package/dist/dxchart.min.js +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -8
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<img src="https://img.shields.io/static/v1?label=PRs&message=Welcome&color=blue" alt="PRs: Welcome" />
|
|
24
24
|
</a>
|
|
25
25
|
<a href="https://devexperts.com/dxcharts-demo/?lang=en">
|
|
26
|
-
<img src="https://img.shields.io/static/v1?label=Latest%20version&message=2.0
|
|
26
|
+
<img src="https://img.shields.io/static/v1?label=Latest%20version&message=2.2.0&color=blue" alt="Version" />
|
|
27
27
|
</a>
|
|
28
28
|
</p>
|
|
29
29
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
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
|
+
*/
|
|
6
|
+
import './env';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
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
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
import './env';
|
|
16
|
+
import { createChart } from '../../index';
|
|
17
|
+
import { generateCandlesDataTS } from '../utils/candles-generator-ts.utils';
|
|
18
|
+
describe('chart', () => {
|
|
19
|
+
const candles = generateCandlesDataTS({ quantity: 50 });
|
|
20
|
+
it.each([
|
|
21
|
+
['zero -> non-zero candles', [[], candles]],
|
|
22
|
+
['prepend candles', [candles.slice(10), candles.slice(0, 10)]],
|
|
23
|
+
['prepend with a gap', [candles.slice(0, 10), candles.slice(20, 30)]],
|
|
24
|
+
['prepend with overlap', [candles.slice(10), candles.slice(0, 20)]],
|
|
25
|
+
['prepend with full overlap', [candles.slice(10), candles]],
|
|
26
|
+
['only update existing candles', [candles, candles.slice(10, 20)]],
|
|
27
|
+
['update all candles', [candles, candles]],
|
|
28
|
+
['append candles', [candles.slice(0, 10), candles.slice(10)]],
|
|
29
|
+
['append candles with a gap', [candles.slice(0, 10), candles.slice(20)]],
|
|
30
|
+
['append candles with overlap', [candles.slice(0, 20), candles.slice(10)]],
|
|
31
|
+
['append candles with full overlap', [candles.slice(0, 20), candles]],
|
|
32
|
+
['prepend and append', [candles.slice(10, 20), candles.slice(0, 30)]],
|
|
33
|
+
[
|
|
34
|
+
"fill in the gap (won't work but should not error)",
|
|
35
|
+
[candles.slice(0, 10), candles.slice(11, 20), candles.slice(10, 11)],
|
|
36
|
+
],
|
|
37
|
+
])('should update candles in various scenarios: %s', (scenario, updates) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const div = document.createElement('div');
|
|
39
|
+
const chart = createChart(div);
|
|
40
|
+
updates.forEach((update, i) => {
|
|
41
|
+
if (i === 0) {
|
|
42
|
+
chart.setData({ candles: update });
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
chart.updateData({ candles: update });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// wait for async tasks to complete successfully
|
|
49
|
+
yield new Promise(done => setTimeout(done, 100));
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
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
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
/* @see https://jestjs.io/docs/29.4/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom */
|
|
8
|
+
Object.defineProperty(window, 'matchMedia', {
|
|
9
|
+
writable: true,
|
|
10
|
+
value: jest.fn().mockImplementation(query => ({
|
|
11
|
+
matches: false,
|
|
12
|
+
media: query,
|
|
13
|
+
onchange: null,
|
|
14
|
+
addListener: jest.fn(),
|
|
15
|
+
removeListener: jest.fn(),
|
|
16
|
+
addEventListener: jest.fn(),
|
|
17
|
+
removeEventListener: jest.fn(),
|
|
18
|
+
dispatchEvent: jest.fn(),
|
|
19
|
+
})),
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(window, 'ResizeObserver', {
|
|
22
|
+
writable: true,
|
|
23
|
+
value: jest.fn().mockImplementation(() => ({
|
|
24
|
+
observe: jest.fn(),
|
|
25
|
+
unobserve: jest.fn(),
|
|
26
|
+
disconnect: jest.fn(),
|
|
27
|
+
})),
|
|
28
|
+
});
|
package/dist/chart/bootstrap.js
CHANGED
|
@@ -179,7 +179,7 @@ export default class ChartBootstrap {
|
|
|
179
179
|
this.chartComponents.push(mainChartGridComponent);
|
|
180
180
|
this.hoverProducer = new HoverProducerComponent(this.crossEventProducer, scaleModel, config, chartModel, canvasInputListener, this.canvasBoundsContainer, this.paneManager, timeZoneModel, formatterFactory);
|
|
181
181
|
this.chartComponents.push(this.hoverProducer);
|
|
182
|
-
this.crossToolComponent = new CrossToolComponent(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, this.crossEventProducer, this.hoverProducer);
|
|
182
|
+
this.crossToolComponent = new CrossToolComponent(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, this.crossEventProducer, this.hoverProducer, this.backgroundCanvasModel);
|
|
183
183
|
this.chartComponents.push(this.crossToolComponent);
|
|
184
184
|
// Snapshot component
|
|
185
185
|
const snapshotCanvasModel = createCanvasModel(eventBus, elements.snapshotCanvas, config, drawingManager, this.canvasModels, elements.chartResizer);
|
|
@@ -203,7 +203,7 @@ export default class ChartBootstrap {
|
|
|
203
203
|
this.drawingManager.addDrawer(yAxisCompositeDrawer, 'Y_AXIS');
|
|
204
204
|
const yAxisDrawer = new YAxisDrawer(this.config, yAxisLabelsCanvasModel, this.paneManager);
|
|
205
205
|
yAxisCompositeDrawer.addDrawer(yAxisDrawer);
|
|
206
|
-
const yAxisLabelsDrawer = new YAxisPriceLabelsDrawer(yAxisLabelsCanvasModel, this.backgroundCanvasModel, this.canvasBoundsContainer, this.config
|
|
206
|
+
const yAxisLabelsDrawer = new YAxisPriceLabelsDrawer(yAxisLabelsCanvasModel, this.backgroundCanvasModel, this.canvasBoundsContainer, this.config, this.paneManager);
|
|
207
207
|
yAxisCompositeDrawer.addDrawer(yAxisLabelsDrawer);
|
|
208
208
|
}
|
|
209
209
|
// TODO remove chartModel dependency, put period to global config somewhere
|
|
@@ -106,7 +106,6 @@ export interface FullChartColors {
|
|
|
106
106
|
};
|
|
107
107
|
yAxis: {
|
|
108
108
|
backgroundColor: string;
|
|
109
|
-
backgroundHoverColor: string;
|
|
110
109
|
zeroPercentLine: string;
|
|
111
110
|
labelTextColor: string;
|
|
112
111
|
labelInvertedTextColor: string;
|
|
@@ -246,6 +245,10 @@ export interface ChartScale {
|
|
|
246
245
|
* Adjust x viewport when y-axis width is changed, so x zoom remains the same
|
|
247
246
|
*/
|
|
248
247
|
keepZoomXOnYAxisChange: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Disable all scale process animations
|
|
250
|
+
*/
|
|
251
|
+
disableAnimations: boolean;
|
|
249
252
|
}
|
|
250
253
|
export interface AutoScaleDisableOnDrag {
|
|
251
254
|
enabled: boolean;
|
|
@@ -43,6 +43,7 @@ export const getDefaultConfig = () => ({
|
|
|
43
43
|
inverse: false,
|
|
44
44
|
zoomSensitivity: 0.25,
|
|
45
45
|
defaultViewportItems: 100,
|
|
46
|
+
disableAnimations: false
|
|
46
47
|
},
|
|
47
48
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
48
49
|
components: {
|
|
@@ -455,7 +456,6 @@ export const getDefaultConfig = () => ({
|
|
|
455
456
|
],
|
|
456
457
|
yAxis: {
|
|
457
458
|
backgroundColor: 'transparent',
|
|
458
|
-
backgroundHoverColor: 'rgba(20,20,19,1)',
|
|
459
459
|
labelBoxColor: 'rgba(20,20,19,1)',
|
|
460
460
|
labelTextColor: 'rgba(128,128,128,1)',
|
|
461
461
|
labelInvertedTextColor: 'rgba(20,20,19,1)',
|
|
@@ -13,7 +13,7 @@ type DataPoint<T extends BaseType> = T extends 'candle' ? Candle : DataSeriesPoi
|
|
|
13
13
|
type VisualPoint<T extends BaseType> = T extends 'candle' ? VisualCandle : VisualSeriesPoint;
|
|
14
14
|
export interface PrependedCandlesData {
|
|
15
15
|
prependedCandlesWidth: number;
|
|
16
|
-
|
|
16
|
+
prependedCandles: Candle[];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* This model is an abstraction which describes manipulations tied to the main data series.
|
|
@@ -87,12 +87,22 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
87
87
|
doActivate() {
|
|
88
88
|
super.doActivate();
|
|
89
89
|
// TODO hack, main data series is created before doActivate, so we need to add it manually
|
|
90
|
-
this.dynamicObjects.model.addObject({
|
|
90
|
+
this.dynamicObjects.model.addObject({
|
|
91
|
+
id: this.chartModel.mainCandleSeries.id,
|
|
92
|
+
paneId: this.chartModel.mainCandleSeries.extentComponent.paneUUID,
|
|
93
|
+
model: this.chartModel.mainCandleSeries,
|
|
94
|
+
drawer: this.dataSeriesDrawer,
|
|
95
|
+
});
|
|
91
96
|
this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(series => {
|
|
92
|
-
this.dynamicObjects.model.addObject({
|
|
97
|
+
this.dynamicObjects.model.addObject({
|
|
98
|
+
id: series.id,
|
|
99
|
+
paneId: series.extentComponent.paneUUID,
|
|
100
|
+
model: series,
|
|
101
|
+
drawer: this.dataSeriesDrawer,
|
|
102
|
+
});
|
|
93
103
|
}));
|
|
94
104
|
this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(series => {
|
|
95
|
-
this.dynamicObjects.model.removeObject(series
|
|
105
|
+
this.dynamicObjects.model.removeObject(series.id);
|
|
96
106
|
}));
|
|
97
107
|
}
|
|
98
108
|
/**
|
|
@@ -440,8 +440,8 @@ export declare class ChartModel extends ChartBaseElement {
|
|
|
440
440
|
removeCandleByIdx(idx: number, instrumentSymbol?: string): void;
|
|
441
441
|
}
|
|
442
442
|
export interface UpdateCandlesResult {
|
|
443
|
-
prepended:
|
|
444
|
-
appended?:
|
|
443
|
+
prepended: Candle[];
|
|
444
|
+
appended?: Candle[];
|
|
445
445
|
candles: Candle[];
|
|
446
446
|
}
|
|
447
447
|
export type TimeFrameRange = [number, number];
|
|
@@ -24,6 +24,7 @@ import { deleteCandlesIndex, prepareCandle, reindexCandles } from './candle.func
|
|
|
24
24
|
import { ChartInstrument } from './chart.component';
|
|
25
25
|
import { fakeCandle } from './fake-candles';
|
|
26
26
|
import { SecondaryChartColorsPool } from './secondary-chart-colors-pool';
|
|
27
|
+
import { uuid } from '../../utils/uuid.utils';
|
|
27
28
|
export class ChartModel extends ChartBaseElement {
|
|
28
29
|
get mainCandleSeries() {
|
|
29
30
|
return this.candleSeries[0];
|
|
@@ -62,7 +63,7 @@ export class ChartModel extends ChartBaseElement {
|
|
|
62
63
|
};
|
|
63
64
|
this.chartTypeChanged.next(this.config.components.chart.type);
|
|
64
65
|
this.secondaryChartColors = new SecondaryChartColorsPool(this.config);
|
|
65
|
-
const candleSeries = new MainCandleSeriesModel(this.chartBaseModel, this.paneManager.panes[CHART_UUID].mainExtent, this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, new ChartInstrument(), this.candlesTransformersByChartType, this.candleWidthByChartType, Object.assign({}, this.config.colors));
|
|
66
|
+
const candleSeries = new MainCandleSeriesModel(this.chartBaseModel, this.paneManager.panes[CHART_UUID].mainExtent, uuid(), this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, new ChartInstrument(), this.candlesTransformersByChartType, this.candleWidthByChartType, Object.assign({}, this.config.colors));
|
|
66
67
|
candleSeries.config.type = this.config.components.chart.type;
|
|
67
68
|
this.candleSeries.push(candleSeries);
|
|
68
69
|
scale.addXConstraint((_, state) => candleEdgesConstrait(state, this.mainCandleSeries.visualPoints, this.config.components.chart.minCandlesOffset, scale.getBounds()));
|
|
@@ -302,12 +303,12 @@ export class ChartModel extends ChartBaseElement {
|
|
|
302
303
|
});
|
|
303
304
|
// caclulate offset width for prepanded candles
|
|
304
305
|
const prependedCandlesWidth = this.chartBaseModel.mainVisualPoints
|
|
305
|
-
.slice(0, updateResult.prepended)
|
|
306
|
+
.slice(0, updateResult.prepended.length)
|
|
306
307
|
.reduce((acc, cur) => acc + cur.width, 0);
|
|
307
308
|
this.scale.moveXStart(this.scale.xStart + prependedCandlesWidth);
|
|
308
309
|
this.candlesPrependSubject.next({
|
|
309
310
|
prependedCandlesWidth,
|
|
310
|
-
|
|
311
|
+
prependedCandles: updateResult.prepended,
|
|
311
312
|
});
|
|
312
313
|
this.chartBaseModel.recalculatePeriod();
|
|
313
314
|
this.candlesUpdatedSubject.next();
|
|
@@ -346,7 +347,7 @@ export class ChartModel extends ChartBaseElement {
|
|
|
346
347
|
* @returns {CandleSeriesModel} - The newly created CandleSeriesModel object.
|
|
347
348
|
*/
|
|
348
349
|
createCandleSeriesModel(instrument, colors) {
|
|
349
|
-
const candleSeries = new CandleSeriesModel(this.paneManager.panes[CHART_UUID].mainExtent, this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, instrument, this.candlesTransformersByChartType, this.candleWidthByChartType, colors);
|
|
350
|
+
const candleSeries = new CandleSeriesModel(this.paneManager.panes[CHART_UUID].mainExtent, uuid(), this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, instrument, this.candlesTransformersByChartType, this.candleWidthByChartType, colors);
|
|
350
351
|
candleSeries.config.type = 'line';
|
|
351
352
|
this.candleSeries.push(candleSeries);
|
|
352
353
|
return candleSeries;
|
|
@@ -798,6 +799,7 @@ export class ChartModel extends ChartBaseElement {
|
|
|
798
799
|
});
|
|
799
800
|
if (lastCandle) {
|
|
800
801
|
series.updateCurrentPrice(lastCandle.close);
|
|
802
|
+
this.paneManager.yExtents.forEach(ext => ext.yAxis.updateOrderedLabels(true));
|
|
801
803
|
}
|
|
802
804
|
if (isInView && lastCandle && candles.length === 1) {
|
|
803
805
|
// can apply some optimization
|
|
@@ -890,7 +892,7 @@ export class ChartModel extends ChartBaseElement {
|
|
|
890
892
|
}
|
|
891
893
|
});
|
|
892
894
|
return {
|
|
893
|
-
prepended: prepend
|
|
895
|
+
prepended: prepend,
|
|
894
896
|
candles: [...prepend, ...targetCopy],
|
|
895
897
|
};
|
|
896
898
|
}
|
|
@@ -972,8 +974,8 @@ const updateCandles = (target, update) => {
|
|
|
972
974
|
}
|
|
973
975
|
});
|
|
974
976
|
return {
|
|
975
|
-
prepended: prepend
|
|
976
|
-
appended: append
|
|
977
|
+
prepended: prepend,
|
|
978
|
+
appended: append,
|
|
977
979
|
candles: [...prepend, ...targetCopy, ...append],
|
|
978
980
|
};
|
|
979
981
|
};
|
|
@@ -23,9 +23,10 @@ export declare class CrossToolComponent extends ChartBaseElement {
|
|
|
23
23
|
private canvasBoundsContainer;
|
|
24
24
|
private drawingManager;
|
|
25
25
|
private paneManager;
|
|
26
|
+
private backgroundCanvasModel;
|
|
26
27
|
readonly model: CrossToolModel;
|
|
27
28
|
private readonly crossToolTypeDrawers;
|
|
28
|
-
constructor(config: FullChartConfig, crossToolCanvasModel: CanvasModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, paneManager: PaneManager, crossEventProducer: CrossEventProducerComponent, hoverProducer: HoverProducerComponent);
|
|
29
|
+
constructor(config: FullChartConfig, crossToolCanvasModel: CanvasModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, paneManager: PaneManager, crossEventProducer: CrossEventProducerComponent, hoverProducer: HoverProducerComponent, backgroundCanvasModel: CanvasModel);
|
|
29
30
|
/**
|
|
30
31
|
* Registers default drawer types for the chart.
|
|
31
32
|
* @private
|
|
@@ -14,13 +14,14 @@ import { NoneDrawerType } from './types/none.drawer';
|
|
|
14
14
|
* Default bundled chart cross tool.
|
|
15
15
|
*/
|
|
16
16
|
export class CrossToolComponent extends ChartBaseElement {
|
|
17
|
-
constructor(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, crossEventProducer, hoverProducer) {
|
|
17
|
+
constructor(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, crossEventProducer, hoverProducer, backgroundCanvasModel) {
|
|
18
18
|
super();
|
|
19
19
|
this.config = config;
|
|
20
20
|
this.crossToolCanvasModel = crossToolCanvasModel;
|
|
21
21
|
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
22
22
|
this.drawingManager = drawingManager;
|
|
23
23
|
this.paneManager = paneManager;
|
|
24
|
+
this.backgroundCanvasModel = backgroundCanvasModel;
|
|
24
25
|
this.crossToolTypeDrawers = {};
|
|
25
26
|
this.model = new CrossToolModel(config.components.crossTool, this.crossToolCanvasModel, crossEventProducer, hoverProducer);
|
|
26
27
|
this.addChildEntity(this.model);
|
|
@@ -41,8 +42,8 @@ export class CrossToolComponent extends ChartBaseElement {
|
|
|
41
42
|
* @returns {void}
|
|
42
43
|
*/
|
|
43
44
|
registerDefaultDrawerTypes() {
|
|
44
|
-
this.registerCrossToolTypeDrawer('cross-and-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager, () => true));
|
|
45
|
-
this.registerCrossToolTypeDrawer('just-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager, () => true, true));
|
|
45
|
+
this.registerCrossToolTypeDrawer('cross-and-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager, this.backgroundCanvasModel, () => true));
|
|
46
|
+
this.registerCrossToolTypeDrawer('just-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager, this.backgroundCanvasModel, () => true, true));
|
|
46
47
|
this.registerCrossToolTypeDrawer('none', new NoneDrawerType());
|
|
47
48
|
}
|
|
48
49
|
//#region public methods
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { CanvasBoundsContainer } from '../../../canvas/canvas-bounds-container';
|
|
7
7
|
import { FullChartConfig } from '../../../chart.config';
|
|
8
|
+
import { CanvasModel } from '../../../model/canvas.model';
|
|
8
9
|
import { PaneManager } from '../../pane/pane-manager.component';
|
|
9
10
|
import { CrossToolTypeDrawer } from '../cross-tool.drawer';
|
|
10
11
|
import { CrossToolHover } from '../cross-tool.model';
|
|
@@ -12,9 +13,10 @@ export declare class CrossAndLabelsDrawerType implements CrossToolTypeDrawer {
|
|
|
12
13
|
private config;
|
|
13
14
|
private canvasBoundsContainer;
|
|
14
15
|
private paneManager;
|
|
16
|
+
private backgroundCanvasModel;
|
|
15
17
|
private crossDrawPredicate;
|
|
16
18
|
private noLines?;
|
|
17
|
-
constructor(config: FullChartConfig, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager, crossDrawPredicate?: () => boolean, noLines?: boolean | undefined);
|
|
19
|
+
constructor(config: FullChartConfig, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager, backgroundCanvasModel: CanvasModel, crossDrawPredicate?: () => boolean, noLines?: boolean | undefined);
|
|
18
20
|
/**
|
|
19
21
|
* Draws a cross tool on a canvas context and its labels if the crossDrawPredicate is true.
|
|
20
22
|
* @param {CanvasRenderingContext2D} ctx - The canvas context to draw on.
|
|
@@ -7,10 +7,11 @@ import { CanvasElement } from '../../../canvas/canvas-bounds-container';
|
|
|
7
7
|
import { avoidAntialiasing, drawRoundedRect } from '../../../utils/canvas/canvas-drawing-functions.utils';
|
|
8
8
|
import { priceLabelDrawersMap } from '../../y_axis/price_labels/price-label.drawer';
|
|
9
9
|
export class CrossAndLabelsDrawerType {
|
|
10
|
-
constructor(config, canvasBoundsContainer, paneManager, crossDrawPredicate = () => true, noLines) {
|
|
10
|
+
constructor(config, canvasBoundsContainer, paneManager, backgroundCanvasModel, crossDrawPredicate = () => true, noLines) {
|
|
11
11
|
this.config = config;
|
|
12
12
|
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
13
13
|
this.paneManager = paneManager;
|
|
14
|
+
this.backgroundCanvasModel = backgroundCanvasModel;
|
|
14
15
|
this.crossDrawPredicate = crossDrawPredicate;
|
|
15
16
|
this.noLines = noLines;
|
|
16
17
|
}
|
|
@@ -135,7 +136,7 @@ export class CrossAndLabelsDrawerType {
|
|
|
135
136
|
paddingBottom: yLabelPadding === null || yLabelPadding === void 0 ? void 0 : yLabelPadding.bottom,
|
|
136
137
|
paddingEnd: yLabelPadding === null || yLabelPadding === void 0 ? void 0 : yLabelPadding.end,
|
|
137
138
|
paddingTop: yLabelPadding === null || yLabelPadding === void 0 ? void 0 : yLabelPadding.top,
|
|
138
|
-
}, extent.yAxis.state, this.config.colors.yAxis, true);
|
|
139
|
+
}, extent.yAxis.state, this.config.colors.yAxis, true, this.backgroundCanvasModel.ctx);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
}
|
|
@@ -10,7 +10,7 @@ export class DynamicObjectsComponent extends ChartBaseElement {
|
|
|
10
10
|
constructor(canvasModel, drawingManager) {
|
|
11
11
|
super();
|
|
12
12
|
// model
|
|
13
|
-
const dynamicObjectsModel = new DynamicObjectsModel();
|
|
13
|
+
const dynamicObjectsModel = new DynamicObjectsModel(canvasModel);
|
|
14
14
|
this.model = dynamicObjectsModel;
|
|
15
15
|
this.addChildEntity(dynamicObjectsModel);
|
|
16
16
|
// drawer
|
|
@@ -4,53 +4,73 @@
|
|
|
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
6
|
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
7
|
-
import { LinkedList
|
|
7
|
+
import { LinkedList } from '../../utils/linkedList.utils';
|
|
8
8
|
import { DynamicModelDrawer } from './dynamic-objects.drawer';
|
|
9
|
+
import { CanvasModel } from '../../model/canvas.model';
|
|
9
10
|
export type PaneId = string;
|
|
11
|
+
export type DynamicObjectId = string | number;
|
|
10
12
|
export interface DynamicObject<T = unknown> {
|
|
13
|
+
readonly id: DynamicObjectId;
|
|
11
14
|
readonly drawer: DynamicModelDrawer<T>;
|
|
12
|
-
readonly
|
|
15
|
+
readonly paneId: PaneId;
|
|
16
|
+
readonly model?: T;
|
|
13
17
|
}
|
|
14
18
|
export declare class DynamicObjectsModel extends ChartBaseElement {
|
|
19
|
+
private canvasModel;
|
|
15
20
|
private _objects;
|
|
16
|
-
private
|
|
17
|
-
constructor();
|
|
21
|
+
private modelIdToObjectMap;
|
|
22
|
+
constructor(canvasModel: CanvasModel);
|
|
23
|
+
/**
|
|
24
|
+
* @returns the `DynamicObject` itself and pane `LinkedList` where the object is stored.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
private getObjectInfoById;
|
|
28
|
+
/**
|
|
29
|
+
* @returns `DynamicObject` position in associated pane `LinkedList`
|
|
30
|
+
* @returns `-1` if an object was not found
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
getObjectPosition(id: DynamicObjectId): number;
|
|
18
34
|
/**
|
|
19
35
|
* Adds an object from outside chart-core into model
|
|
20
36
|
* @param obj
|
|
21
37
|
* @param paneId
|
|
22
38
|
*/
|
|
23
|
-
addObject(obj: DynamicObject
|
|
39
|
+
addObject(obj: DynamicObject): void;
|
|
24
40
|
/**
|
|
25
41
|
* Removes an object from model
|
|
26
42
|
* @param model
|
|
27
43
|
* @param paneId
|
|
28
44
|
*/
|
|
29
|
-
removeObject(
|
|
45
|
+
removeObject(id: DynamicObjectId): void;
|
|
46
|
+
/**
|
|
47
|
+
* Moves the object inside the associated LinkedList to the specified position
|
|
48
|
+
*/
|
|
49
|
+
moveToPosition(id: DynamicObjectId, position: number): void;
|
|
30
50
|
/**
|
|
31
51
|
* Moves the object inside the drawing order so it's being drawn before the other elements
|
|
32
52
|
* @param paneId
|
|
33
53
|
* @param listNode
|
|
34
54
|
*/
|
|
35
|
-
bringToFront(
|
|
55
|
+
bringToFront(id: DynamicObjectId): void;
|
|
36
56
|
/**
|
|
37
57
|
* Moves the object inside the drawing order so it's being drawn after the other elements
|
|
38
58
|
* @param paneId
|
|
39
59
|
* @param listNode
|
|
40
60
|
*/
|
|
41
|
-
bringToBack(
|
|
61
|
+
bringToBack(id: DynamicObjectId): void;
|
|
42
62
|
/**
|
|
43
63
|
* Moves the object inside the drawing order so it's being drawn one layer ahead
|
|
44
64
|
* @param obj
|
|
45
65
|
* @param paneId
|
|
46
66
|
*/
|
|
47
|
-
moveForward(
|
|
67
|
+
moveForward(id: DynamicObjectId): void;
|
|
48
68
|
/**
|
|
49
69
|
* Moves the object inside the drawing order so it's being drawn one layer closer to the back
|
|
50
70
|
* @param obj
|
|
51
71
|
* @param paneId
|
|
52
72
|
*/
|
|
53
|
-
moveBackwards(
|
|
73
|
+
moveBackwards(id: DynamicObjectId): void;
|
|
54
74
|
/**
|
|
55
75
|
* Getter for the objects
|
|
56
76
|
*/
|