@devexperts/dxcharts-lite 1.0.2 → 2.0.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 +2 -2
- package/dist/chart/animation/canvas-animation.js +134 -1
- package/dist/chart/animation/types/animation.js +43 -1
- package/dist/chart/animation/types/color-alpha-animation.d.ts +1 -1
- package/dist/chart/animation/types/color-alpha-animation.js +60 -1
- package/dist/chart/animation/types/color-transition-animation.d.ts +1 -1
- package/dist/chart/animation/types/color-transition-animation.js +86 -1
- package/dist/chart/animation/types/viewport-movement-animation.js +63 -1
- package/dist/chart/animation/viewport-model-animation.js +20 -1
- package/dist/chart/bootstrap.d.ts +51 -48
- package/dist/chart/bootstrap.js +449 -1
- package/dist/chart/canvas/canvas-bounds-container.d.ts +0 -5
- package/dist/chart/canvas/canvas-bounds-container.js +815 -1
- package/dist/chart/canvas/canvas-chart-html.js +16 -18
- package/dist/chart/canvas/chart-elements.d.ts +1 -4
- package/dist/chart/canvas/chart-elements.js +22 -1
- package/dist/chart/canvas/cursor.handler.js +122 -1
- package/dist/chart/canvas/layout-creator.js +34 -1
- package/dist/chart/canvas/y-axis-bounds.container.d.ts +2 -2
- package/dist/chart/canvas/y-axis-bounds.container.js +67 -1
- package/dist/chart/chart-container.js +1 -1
- package/dist/chart/chart.config.d.ts +4 -5
- package/dist/chart/chart.config.js +645 -1
- package/dist/chart/chart.d.ts +62 -0
- package/dist/chart/chart.js +106 -0
- package/dist/chart/components/chart/basic-scale.d.ts +2 -2
- package/dist/chart/components/chart/basic-scale.js +31 -1
- package/dist/chart/components/chart/candle-transformer.functions.js +15 -1
- package/dist/chart/components/chart/candle-width-calculator.functions.js +2 -1
- package/dist/chart/components/chart/candle.functions.js +44 -1
- package/dist/chart/components/chart/chart-area-pan.handler.d.ts +3 -3
- package/dist/chart/components/chart/chart-area-pan.handler.js +197 -1
- package/dist/chart/components/chart/chart-base.model.js +66 -1
- package/dist/chart/components/chart/chart.component.d.ts +7 -3
- package/dist/chart/components/chart/chart.component.js +408 -1
- package/dist/chart/components/chart/chart.model.d.ts +4 -11
- package/dist/chart/components/chart/chart.model.js +954 -1
- package/dist/chart/components/chart/data-series.high-low-provider.js +34 -1
- package/dist/chart/components/chart/fake-candles.js +97 -1
- package/dist/chart/components/chart/price.formatter.js +35 -1
- package/dist/chart/components/chart/secondary-chart-colors-pool.js +68 -1
- package/dist/chart/components/cross_tool/cross-tool.component.js +85 -1
- package/dist/chart/components/cross_tool/cross-tool.drawer.js +32 -1
- package/dist/chart/components/cross_tool/cross-tool.model.js +107 -1
- package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.js +137 -1
- package/dist/chart/components/cross_tool/types/none.drawer.js +3 -1
- package/dist/chart/components/dran-n-drop_helper/drag-n-drop-x.component.js +28 -1
- package/dist/chart/components/dran-n-drop_helper/drag-n-drop-y.component.js +24 -1
- package/dist/chart/components/dran-n-drop_helper/drag-n-drop.component.js +53 -1
- package/dist/chart/components/dynamic-objects/dynamic-objects.component.d.ts +13 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.component.js +20 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.drawer.d.ts +18 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.drawer.js +23 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.model.d.ts +63 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.model.js +136 -0
- package/dist/chart/components/events/events-hit-test.drawer.js +63 -1
- package/dist/chart/components/events/events.component.js +61 -1
- package/dist/chart/components/events/events.drawer.js +195 -1
- package/dist/chart/components/events/events.model.js +69 -1
- package/dist/chart/components/grid/grid.component.d.ts +2 -2
- package/dist/chart/components/grid/grid.component.js +31 -1
- package/dist/chart/components/grid/grid.drawer.d.ts +4 -3
- package/dist/chart/components/grid/grid.drawer.js +106 -1
- package/dist/chart/components/high_low/high-low.component.js +12 -1
- package/dist/chart/components/high_low/high-low.drawer.js +126 -1
- package/dist/chart/components/highlights/highlights.component.js +46 -1
- package/dist/chart/components/highlights/highlights.drawer.js +154 -1
- package/dist/chart/components/highlights/highlights.model.js +75 -1
- package/dist/chart/components/labels_generator/numeric-axis-labels.generator.d.ts +1 -1
- package/dist/chart/components/labels_generator/numeric-axis-labels.generator.js +199 -1
- package/dist/chart/components/navigation_map/navigation-map-move.handler.d.ts +2 -2
- package/dist/chart/components/navigation_map/navigation-map-move.handler.js +108 -1
- package/dist/chart/components/navigation_map/navigation-map.component.js +112 -1
- package/dist/chart/components/navigation_map/navigation-map.drawer.js +244 -1
- package/dist/chart/components/navigation_map/navigation-map.model.js +33 -2
- package/dist/chart/components/pan/chart-pan.component.d.ts +2 -2
- package/dist/chart/components/pan/chart-pan.component.js +51 -1
- package/dist/chart/components/pane/extent/y-extent-component.d.ts +12 -18
- package/dist/chart/components/pane/extent/y-extent-component.js +120 -1
- package/dist/chart/components/pane/pane-hit-test.controller.js +55 -1
- package/dist/chart/components/pane/pane-manager.component.d.ts +10 -5
- package/dist/chart/components/pane/pane-manager.component.js +148 -1
- package/dist/chart/components/pane/pane.component.d.ts +16 -32
- package/dist/chart/components/pane/pane.component.js +278 -1
- package/dist/chart/components/resizer/bar-resizer.component.js +139 -1
- package/dist/chart/components/resizer/bar-resizer.drawer.js +46 -1
- package/dist/chart/components/snapshot/snapshot.component.js +48 -1
- package/dist/chart/components/volumes/separate-volumes.component.d.ts +6 -10
- package/dist/chart/components/volumes/separate-volumes.component.js +63 -1
- package/dist/chart/components/volumes/volume-color-resolvers.functions.js +18 -1
- package/dist/chart/components/volumes/volumes.component.d.ts +6 -7
- package/dist/chart/components/volumes/volumes.component.js +94 -1
- package/dist/chart/components/volumes/volumes.drawer.d.ts +5 -12
- package/dist/chart/components/volumes/volumes.drawer.js +140 -1
- package/dist/chart/components/volumes/volumes.formatter.js +31 -1
- package/dist/chart/components/volumes/volumes.model.d.ts +2 -2
- package/dist/chart/components/volumes/volumes.model.js +43 -1
- package/dist/chart/components/watermark/water-mark.component.js +103 -1
- package/dist/chart/components/watermark/water-mark.drawer.js +187 -1
- package/dist/chart/components/x_axis/numeric-x-axis-labels.generator.js +27 -1
- package/dist/chart/components/x_axis/time/parser/time-formats-matchers.functions.js +187 -1
- package/dist/chart/components/x_axis/time/parser/time-formats-parser.functions.js +76 -1
- package/dist/chart/components/x_axis/time/parser/time-formats-validators.functions.js +79 -1
- package/dist/chart/components/x_axis/time/parser/time-formats.model.js +14 -1
- package/dist/chart/components/x_axis/time/x-axis-weights.functions.d.ts +1 -1
- package/dist/chart/components/x_axis/time/x-axis-weights.functions.js +143 -1
- package/dist/chart/components/x_axis/time/x-axis-weights.generator.js +73 -1
- package/dist/chart/components/x_axis/x-axis-draw.functions.js +49 -1
- package/dist/chart/components/x_axis/x-axis-labels.drawer.js +70 -1
- package/dist/chart/components/x_axis/x-axis-labels.generator.d.ts +2 -2
- package/dist/chart/components/x_axis/x-axis-labels.generator.js +332 -1
- package/dist/chart/components/x_axis/x-axis-labels.model.js +35 -1
- package/dist/chart/components/x_axis/x-axis-scale.handler.d.ts +2 -2
- package/dist/chart/components/x_axis/x-axis-scale.handler.js +60 -1
- package/dist/chart/components/x_axis/x-axis-time-labels.drawer.js +82 -1
- package/dist/chart/components/x_axis/x-axis.component.d.ts +2 -2
- package/dist/chart/components/x_axis/x-axis.component.js +119 -1
- package/dist/chart/components/y_axis/label-color.functions.js +53 -1
- package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.d.ts +4 -4
- package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.js +33 -1
- package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.d.ts +3 -3
- package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.js +67 -1
- package/dist/chart/components/y_axis/price_labels/labels-positions-calculator.js +56 -1
- package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.js +95 -1
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.d.ts +2 -2
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.js +119 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.d.ts +9 -8
- package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.js +201 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.d.ts +6 -7
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +58 -1
- package/dist/chart/components/y_axis/y-axis-base-labels.model.d.ts +6 -4
- package/dist/chart/components/y_axis/y-axis-base-labels.model.js +47 -1
- package/dist/chart/components/y_axis/y-axis-labels.drawer.d.ts +4 -4
- package/dist/chart/components/y_axis/y-axis-labels.drawer.js +161 -1
- package/dist/chart/components/y_axis/y-axis-scale.handler.d.ts +2 -2
- package/dist/chart/components/y_axis/y-axis-scale.handler.js +72 -1
- package/dist/chart/components/y_axis/y-axis.component.d.ts +32 -41
- package/dist/chart/components/y_axis/y-axis.component.js +220 -1
- package/dist/chart/components/y_axis/y-axis.drawer.d.ts +9 -12
- package/dist/chart/components/y_axis/y-axis.drawer.js +96 -1
- package/dist/chart/components/y_axis/y-axis.model.d.ts +9 -17
- package/dist/chart/components/y_axis/y-axis.model.js +33 -1
- package/dist/chart/drawers/chart-background.drawer.js +69 -1
- package/dist/chart/drawers/chart-type-drawers/area.drawer.js +69 -1
- package/dist/chart/drawers/chart-type-drawers/bar.drawer.js +57 -1
- package/dist/chart/drawers/chart-type-drawers/baseline.drawer.js +84 -1
- package/dist/chart/drawers/chart-type-drawers/candle.drawer.js +162 -1
- package/dist/chart/drawers/chart-type-drawers/histogram.drawer.js +57 -1
- package/dist/chart/drawers/chart-type-drawers/line.drawer.js +38 -1
- package/dist/chart/drawers/chart-type-drawers/scatter-plot.drawer.js +19 -1
- package/dist/chart/drawers/clear-canvas.drawer.js +14 -1
- package/dist/chart/drawers/composite.drawer.js +67 -1
- package/dist/chart/drawers/data-series-drawers/candle-series-wrapper.js +50 -1
- package/dist/chart/drawers/data-series-drawers/color-candle.drawer.js +35 -1
- package/dist/chart/drawers/data-series-drawers/data-series-drawers.utils.js +16 -1
- package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.js +106 -1
- package/dist/chart/drawers/data-series-drawers/histogram.drawer.js +23 -1
- package/dist/chart/drawers/data-series-drawers/linear.drawer.js +19 -1
- package/dist/chart/drawers/data-series-drawers/points.drawer.js +19 -1
- package/dist/chart/drawers/data-series-drawers/rectangular-tool.drawer.js +7 -1
- package/dist/chart/drawers/data-series-drawers/text.drawer.js +25 -1
- package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.js +35 -1
- package/dist/chart/drawers/data-series-drawers/triangle.drawer.js +22 -1
- package/dist/chart/drawers/data-series.drawer.d.ts +5 -7
- package/dist/chart/drawers/data-series.drawer.js +56 -1
- package/dist/chart/drawers/drawing-manager.d.ts +1 -1
- package/dist/chart/drawers/drawing-manager.js +177 -1
- package/dist/chart/drawers/ht-data-series.drawer.js +37 -1
- package/dist/chart/events/event-bus.js +73 -1
- package/dist/chart/events/events.js +3 -1
- package/dist/chart/inputhandlers/candle-tap.handler.js +46 -1
- package/dist/chart/inputhandlers/chart-resize.handler.js +98 -1
- package/dist/chart/inputhandlers/cross-event-producer.component.js +67 -1
- package/dist/chart/inputhandlers/hover-producer.component.d.ts +2 -2
- package/dist/chart/inputhandlers/hover-producer.component.js +228 -1
- package/dist/chart/inputhandlers/main-canvas-touch.handler.d.ts +2 -2
- package/dist/chart/inputhandlers/main-canvas-touch.handler.js +80 -1
- package/dist/chart/inputlisteners/canvas-input-listener.component.js +629 -1
- package/dist/chart/model/baseline.model.js +88 -1
- package/dist/chart/model/bounds.model.js +1 -1
- package/dist/chart/model/candle-hover.js +70 -1
- package/dist/chart/model/candle-series-high-low.provider.js +45 -1
- package/dist/chart/model/candle-series.model.d.ts +3 -3
- package/dist/chart/model/candle-series.model.js +245 -1
- package/dist/chart/model/candle.model.js +69 -1
- package/dist/chart/model/canvas.model.js +228 -1
- package/dist/chart/model/chart-base-element.js +129 -1
- package/dist/chart/model/compare-series-hover.js +25 -1
- package/dist/chart/model/data-series-view.d.ts +5 -5
- package/dist/chart/model/data-series-view.js +111 -1
- package/dist/chart/model/data-series.config.js +14 -1
- package/dist/chart/model/data-series.model.d.ts +4 -4
- package/dist/chart/model/data-series.model.js +281 -1
- package/dist/chart/model/date-time.formatter.js +151 -1
- package/dist/chart/model/hit-test-canvas.model.d.ts +1 -1
- package/dist/chart/model/hit-test-canvas.model.js +256 -1
- package/dist/chart/model/main-candle-series.model.d.ts +1 -1
- package/dist/chart/model/main-candle-series.model.js +29 -1
- package/dist/chart/model/scale.model.d.ts +2 -1
- package/dist/chart/model/scale.model.js +316 -1
- package/dist/chart/model/scaling/auto-scale.model.js +97 -1
- package/dist/chart/model/scaling/constrait.functions.js +61 -1
- package/dist/chart/model/scaling/lock-ratio.model.js +17 -1
- package/dist/chart/model/scaling/move-chart.functions.js +22 -1
- package/dist/chart/model/scaling/viewport.model.d.ts +2 -2
- package/dist/chart/model/scaling/viewport.model.js +279 -1
- package/dist/chart/model/scaling/x-zooming.functions.js +35 -1
- package/dist/chart/model/time-zone.model.js +109 -1
- package/dist/chart/model/visual-candle.js +134 -1
- package/dist/chart/utils/__tests__/array.utils.test.js +135 -1
- package/dist/chart/utils/__tests__/math.utils.test.js +14 -1
- package/dist/chart/utils/__tests__/object.utils.test.js +11 -1
- package/dist/chart/utils/__tests__/priceIncrementsUtils.test.js +29 -1
- package/dist/chart/utils/array.utils.d.ts +1 -1
- package/dist/chart/utils/array.utils.js +269 -1
- package/dist/chart/utils/auto-period-detector.utils.js +39 -1
- package/dist/chart/utils/candles-generator-ts.utils.js +20 -1
- package/dist/chart/utils/candles-generator.utils.js +161 -1
- package/dist/chart/utils/candles.utils.js +42 -1
- package/dist/chart/utils/canvas/canvas-drawing-functions.utils.js +144 -1
- package/dist/chart/utils/canvas/canvas-font-measure-tool.utils.js +51 -1
- package/dist/chart/utils/canvas/canvas-text-functions.utils.js +156 -1
- package/dist/chart/utils/color.utils.js +31 -1
- package/dist/chart/utils/device/browser.utils.js +10 -1
- package/dist/chart/utils/device/device-detector.utils.js +24 -1
- package/dist/chart/utils/device/device-pixel-ratio.utils.js +21 -1
- package/dist/chart/utils/device/touchpad.utils.js +91 -1
- package/dist/chart/utils/dom.utils.js +15 -1
- package/dist/chart/utils/function.utils.js +16 -1
- package/dist/chart/utils/linkedList.utils.d.ts +28 -0
- package/dist/chart/utils/linkedList.utils.js +138 -0
- package/dist/chart/utils/math.utils.js +115 -1
- package/dist/chart/utils/merge.utils.js +56 -1
- package/dist/chart/utils/object.utils.js +43 -1
- package/dist/chart/utils/performance/animation-frame-cache.utils.js +77 -0
- package/dist/chart/utils/{perfomance → performance}/debounce.utils.js +7 -1
- package/dist/chart/utils/performance/memoize.utils.js +74 -0
- package/dist/chart/utils/performance/request-animation-frame-throttle.utils.js +43 -0
- package/dist/chart/utils/performance/throttle.utils.js +26 -0
- package/dist/chart/utils/price-increments.utils.d.ts +1 -0
- package/dist/chart/utils/price-increments.utils.js +127 -1
- package/dist/chart/utils/uuid.utils.js +4 -1
- package/dist/dxchart.min.js +9 -12
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -1
- package/package.json +4 -4
- package/dist/chart/utils/perfomance/animation-frame-cache.utils.js +0 -6
- package/dist/chart/utils/perfomance/memoize.utils.js +0 -6
- package/dist/chart/utils/perfomance/request-animation-frame-throttle.utils.js +0 -6
- package/dist/chart/utils/perfomance/throttle.utils.js +0 -6
- /package/dist/chart/utils/{perfomance → performance}/animation-frame-cache.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/debounce.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/memoize.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/request-animation-frame-throttle.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/throttle.utils.d.ts +0 -0
|
@@ -3,4 +3,122 @@
|
|
|
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
|
|
6
|
+
import { merge } from 'rxjs';
|
|
7
|
+
import { distinctUntilChanged, map, throttleTime, filter } from 'rxjs/operators';
|
|
8
|
+
import { CanvasElement } from '../../canvas/canvas-bounds-container';
|
|
9
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
10
|
+
import { CompositeDrawer } from '../../drawers/composite.drawer';
|
|
11
|
+
import { XAxisLabelsDrawer } from './x-axis-labels.drawer';
|
|
12
|
+
import { XAxisTimeLabelsGenerator } from './x-axis-labels.generator';
|
|
13
|
+
import { XAxisLabelsModel } from './x-axis-labels.model';
|
|
14
|
+
import { XAxisScaleHandler } from './x-axis-scale.handler';
|
|
15
|
+
import { XAxisTimeLabelsDrawer } from './x-axis-time-labels.drawer';
|
|
16
|
+
import { lastOf } from '../../utils/array.utils';
|
|
17
|
+
import { notEmpty } from '../../utils/function.utils';
|
|
18
|
+
import { availableBarTypes } from '../../chart.config';
|
|
19
|
+
/**
|
|
20
|
+
* X-axis component, contains all x-axis calculation and rendering logic.
|
|
21
|
+
*/
|
|
22
|
+
export class XAxisComponent extends ChartBaseElement {
|
|
23
|
+
constructor(eventBus, config, canvasModel, chartComponent, scale, canvasBoundsContainer, canvasInputListener, chartResizeHandler, drawingManager, timeZoneModel, chartPanComponent, cursorHandler, backgroundCanvasModel) {
|
|
24
|
+
super();
|
|
25
|
+
this.eventBus = eventBus;
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.canvasModel = canvasModel;
|
|
28
|
+
this.chartComponent = chartComponent;
|
|
29
|
+
this.scale = scale;
|
|
30
|
+
this.chartResizeHandler = chartResizeHandler;
|
|
31
|
+
this.timeZoneModel = timeZoneModel;
|
|
32
|
+
const xAxisLabelsGenerator = new XAxisTimeLabelsGenerator(eventBus, config, chartComponent.chartModel, scale, timeZoneModel, this.canvasModel);
|
|
33
|
+
this.xAxisLabelsGenerator = xAxisLabelsGenerator;
|
|
34
|
+
this.xAxisLabelsModel = new XAxisLabelsModel(eventBus, []);
|
|
35
|
+
const xAxisCompositeDrawer = new CompositeDrawer();
|
|
36
|
+
drawingManager.addDrawer(xAxisCompositeDrawer, 'X_AXIS');
|
|
37
|
+
this.xAxisDrawer = new XAxisTimeLabelsDrawer(config, canvasModel, scale, canvasBoundsContainer, () => this.xAxisLabelsGenerator.labels, () => config.components.xAxis.visible);
|
|
38
|
+
xAxisCompositeDrawer.addDrawer(this.xAxisDrawer);
|
|
39
|
+
this.xAxisLabelsDrawer = new XAxisLabelsDrawer(backgroundCanvasModel, config, canvasModel, canvasBoundsContainer, this.xAxisLabelsModel);
|
|
40
|
+
xAxisCompositeDrawer.addDrawer(this.xAxisLabelsDrawer);
|
|
41
|
+
this.xAxisScaleHandler = new XAxisScaleHandler(scale, canvasInputListener, canvasBoundsContainer, chartPanComponent, this.chartComponent.chartModel);
|
|
42
|
+
this.addChildEntity(this.xAxisScaleHandler);
|
|
43
|
+
cursorHandler.setCursorForCanvasEl(CanvasElement.X_AXIS, config.components.xAxis.cursor);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* This method is used to activate the chart and update the labels if there is a new data set or equivolume type.
|
|
47
|
+
* It subscribes to the chart type change, candles set subject, candles updated subject, and time zone change to generate new labels.
|
|
48
|
+
* It also subscribes to the x-axis scale change and canvas resize to recalculate the labels.
|
|
49
|
+
* @protected
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/
|
|
52
|
+
doActivate() {
|
|
53
|
+
super.doActivate();
|
|
54
|
+
// do update labels if new data set
|
|
55
|
+
this.addRxSubscription(merge(this.chartComponent.chartModel.candlesSetSubject, this.timeZoneModel.observeTimeZoneChanged()).subscribe(() => {
|
|
56
|
+
this.xAxisLabelsGenerator.generateLabels();
|
|
57
|
+
}));
|
|
58
|
+
this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject
|
|
59
|
+
.pipe(filter(({ preparedCandles }) => preparedCandles.length !== 0), map(({ preparedCandles }) => {
|
|
60
|
+
return this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0, preparedCandles.length);
|
|
61
|
+
}))
|
|
62
|
+
.subscribe(newCandles => {
|
|
63
|
+
//@ts-ignore
|
|
64
|
+
if (availableBarTypes.includes(this.config.components.chart.type)) {
|
|
65
|
+
this.xAxisLabelsGenerator.updateHistoryLabels &&
|
|
66
|
+
this.xAxisLabelsGenerator.updateHistoryLabels(newCandles);
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
this.addRxSubscription(merge(this.scale.xChanged, this.chartResizeHandler.canvasResized)
|
|
70
|
+
.pipe(throttleTime(50, undefined, { trailing: true, leading: true }))
|
|
71
|
+
.subscribe(() => {
|
|
72
|
+
this.xAxisLabelsGenerator.recalculateLabels();
|
|
73
|
+
}));
|
|
74
|
+
this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject
|
|
75
|
+
.pipe(map(() => lastOf(this.chartComponent.chartModel.mainCandleSeries.visualPoints)), distinctUntilChanged((a, b) => { var _a, _b; return ((_a = a === null || a === void 0 ? void 0 : a.candle) === null || _a === void 0 ? void 0 : _a.timestamp) === ((_b = b === null || b === void 0 ? void 0 : b.candle) === null || _b === void 0 ? void 0 : _b.timestamp); }), filter(notEmpty))
|
|
76
|
+
.subscribe(x => {
|
|
77
|
+
this.xAxisLabelsGenerator.updateLastLabel && this.xAxisLabelsGenerator.updateLastLabel(x);
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the xAxisDrawer object.
|
|
82
|
+
*
|
|
83
|
+
* @returns {Object} The xAxisDrawer object.
|
|
84
|
+
*/
|
|
85
|
+
getDrawer() {
|
|
86
|
+
return this.xAxisDrawer;
|
|
87
|
+
}
|
|
88
|
+
//#region public methods
|
|
89
|
+
/**
|
|
90
|
+
* You can add a custom labels provider for additional labels on XAxis (like for drawings)
|
|
91
|
+
* @param provider
|
|
92
|
+
*/
|
|
93
|
+
registerXAxisLabelsProvider(provider) {
|
|
94
|
+
this.xAxisLabelsModel.labelProviders.push(provider);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Controls visibility of the x-axis
|
|
98
|
+
*/
|
|
99
|
+
setVisible(isVisible) {
|
|
100
|
+
var _a;
|
|
101
|
+
if ((_a = this.config.components) === null || _a === void 0 ? void 0 : _a.xAxis) {
|
|
102
|
+
this.config.components.xAxis.visible = isVisible;
|
|
103
|
+
this.eventBus.fireDraw();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set new config for x labels formatting
|
|
108
|
+
*/
|
|
109
|
+
setFormatsForLabelsConfig(newFormatsByWeightMap) {
|
|
110
|
+
if (this.xAxisLabelsGenerator instanceof XAxisTimeLabelsGenerator) {
|
|
111
|
+
this.xAxisLabelsGenerator.setFormatsForLabelsConfig(newFormatsByWeightMap);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.error('Format config for x-axis is not available');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* If visible, when you can see the x-axis on the chart
|
|
119
|
+
*/
|
|
120
|
+
isVisible() {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
return (_b = (_a = this.config.components) === null || _a === void 0 ? void 0 : _a.xAxis.visible) !== null && _b !== void 0 ? _b : false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -3,4 +3,56 @@
|
|
|
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
|
-
export const DEFAULT_LABEL_COLOR=
|
|
6
|
+
export const DEFAULT_LABEL_COLOR = '#FF00FF';
|
|
7
|
+
export const getPrimaryLabelTextColor = (lastPriceMovement, colors) => {
|
|
8
|
+
if (lastPriceMovement === 'down') {
|
|
9
|
+
return colors.lastPrice.textNegative;
|
|
10
|
+
}
|
|
11
|
+
else if (lastPriceMovement === 'up') {
|
|
12
|
+
return colors.lastPrice.textPositive;
|
|
13
|
+
}
|
|
14
|
+
else if (lastPriceMovement === 'none') {
|
|
15
|
+
return colors.lastPrice.textSelected;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return colors.lastPrice.textSelected;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const resolveColorForBar = (priceMovement, colors) => {
|
|
22
|
+
const resolvedColor = colors.barTheme[`${priceMovement}Color`];
|
|
23
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
24
|
+
};
|
|
25
|
+
export const resolveColorForLine = (priceMovement, colors) => {
|
|
26
|
+
const resolvedColor = colors.lineTheme[`${priceMovement}Color`];
|
|
27
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
28
|
+
};
|
|
29
|
+
export const resolveColorForCandle = (priceMovement, colors) => {
|
|
30
|
+
const resolvedColor = colors.candleTheme[`${priceMovement}Color`];
|
|
31
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
32
|
+
};
|
|
33
|
+
export const resolveColorForArea = (priceMovement, colors) => {
|
|
34
|
+
const resolvedColor = colors.areaTheme.lineColor;
|
|
35
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
36
|
+
};
|
|
37
|
+
export const resolveColorForScatterPlot = (priceMovement, colors) => {
|
|
38
|
+
const resolvedColor = colors.scatterPlot.mainColor;
|
|
39
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
40
|
+
};
|
|
41
|
+
export const resolveColorForHistogram = (priceMovement, colors) => {
|
|
42
|
+
const resolvedColor = colors.histogram[`${priceMovement}Cap`];
|
|
43
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
44
|
+
};
|
|
45
|
+
export const resolveColorForBaseLine = (priceMovement, colors) => {
|
|
46
|
+
const resolvedColor = priceMovement === 'up'
|
|
47
|
+
? colors.baseLineTheme.upperSectionStrokeColor
|
|
48
|
+
: colors.baseLineTheme.lowerSectionStrokeColor;
|
|
49
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
50
|
+
};
|
|
51
|
+
export const resolveColorForTrendAndHollow = (priceMovement, colors) => {
|
|
52
|
+
const resolvedColor = colors.candleTheme[`${priceMovement}WickColor`];
|
|
53
|
+
return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR;
|
|
54
|
+
};
|
|
55
|
+
export const resolveDefaultColorForLabel = () => {
|
|
56
|
+
console.warn('Fallback for label default color');
|
|
57
|
+
return DEFAULT_LABEL_COLOR;
|
|
58
|
+
};
|
|
@@ -3,15 +3,15 @@
|
|
|
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 {
|
|
7
|
-
import { NumericAxisLabelsGenerator, PriceAxisType } from '../labels_generator/numeric-axis-labels.generator';
|
|
6
|
+
import { DataSeriesModel } from '../../model/data-series.model';
|
|
8
7
|
import { ViewportModel } from '../../model/scaling/viewport.model';
|
|
8
|
+
import { NumericAxisLabelsGenerator, PriceAxisType } from '../labels_generator/numeric-axis-labels.generator';
|
|
9
9
|
/**
|
|
10
10
|
* Y axis labels generator for prices. Respects price increment from instrument.
|
|
11
11
|
*/
|
|
12
12
|
export declare class NumericYAxisLabelsGenerator extends NumericAxisLabelsGenerator {
|
|
13
|
-
private
|
|
14
|
-
constructor(increment: number | null,
|
|
13
|
+
private dataSeriesProvider;
|
|
14
|
+
constructor(increment: number | null, dataSeriesProvider: () => DataSeriesModel | undefined, viewportModel: ViewportModel, valueFormatter: (value: number) => string, axisTypeProvider?: () => PriceAxisType, singleLabelHeightPixels?: number);
|
|
15
15
|
getLargestLabel(): string;
|
|
16
16
|
/**
|
|
17
17
|
* Calculates the increment to be used on the chart axis based on the length of the value and the instrument's price increments.
|
|
@@ -3,4 +3,36 @@
|
|
|
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{
|
|
6
|
+
import { lastOf } from '../../utils/array.utils';
|
|
7
|
+
import { precisionsToIncrement } from '../../utils/price-increments.utils';
|
|
8
|
+
import { NumericAxisLabelsGenerator } from '../labels_generator/numeric-axis-labels.generator';
|
|
9
|
+
/**
|
|
10
|
+
* Y axis labels generator for prices. Respects price increment from instrument.
|
|
11
|
+
*/
|
|
12
|
+
export class NumericYAxisLabelsGenerator extends NumericAxisLabelsGenerator {
|
|
13
|
+
constructor(increment, dataSeriesProvider, viewportModel, valueFormatter, axisTypeProvider = () => 'regular', singleLabelHeightPixels = 23) {
|
|
14
|
+
super(increment, () => [viewportModel.yStart, viewportModel.yEnd], () => viewportModel.getBounds().height, valueFormatter, false, axisTypeProvider, () => { var _a, _b; return (_b = (_a = dataSeriesProvider()) === null || _a === void 0 ? void 0 : _a.getBaseline()) !== null && _b !== void 0 ? _b : 1; }, undefined, singleLabelHeightPixels);
|
|
15
|
+
this.dataSeriesProvider = dataSeriesProvider;
|
|
16
|
+
}
|
|
17
|
+
getLargestLabel() {
|
|
18
|
+
var _a;
|
|
19
|
+
return ((_a = this.labelsCache.getLastCachedValue()) !== null && _a !== void 0 ? _a : []).reduce((maxLengthText, label) => (label.text.length > maxLengthText.length ? label.text : maxLengthText), '');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Calculates the increment to be used on the chart axis based on the length of the value and the instrument's price increments.
|
|
23
|
+
* @param {number} valueLength - The length of the value.
|
|
24
|
+
* @returns {number} - The calculated increment.
|
|
25
|
+
*/
|
|
26
|
+
calculateIncrement(valueLength) {
|
|
27
|
+
var _a;
|
|
28
|
+
const dataSeries = this.dataSeriesProvider();
|
|
29
|
+
if (dataSeries) {
|
|
30
|
+
const lastCandle = lastOf(dataSeries.dataPoints);
|
|
31
|
+
const priceIncrementBasis = (_a = lastCandle === null || lastCandle === void 0 ? void 0 : lastCandle.close) !== null && _a !== void 0 ? _a : 0;
|
|
32
|
+
const increment = precisionsToIncrement(priceIncrementBasis, dataSeries.pricePrecisions);
|
|
33
|
+
return this.adjustIncrementOnAxisType(increment);
|
|
34
|
+
}
|
|
35
|
+
// auto-generated increment
|
|
36
|
+
return super.calculateIncrement(valueLength);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
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 {
|
|
6
|
+
import { YAxisConfig } from '../../../chart.config';
|
|
7
7
|
import { BoundsProvider } from '../../../model/bounds.model';
|
|
8
8
|
import { DataSeriesConfig } from '../../../model/data-series.config';
|
|
9
9
|
import { DataSeriesModel } from '../../../model/data-series.model';
|
|
@@ -12,8 +12,8 @@ export declare class DataSeriesYAxisLabelsProvider implements YAxisLabelsProvide
|
|
|
12
12
|
private series;
|
|
13
13
|
private config;
|
|
14
14
|
yAxisBoundsProvider: BoundsProvider;
|
|
15
|
-
axisState?:
|
|
16
|
-
constructor(series: DataSeriesModel, config: DataSeriesConfig, yAxisBoundsProvider: BoundsProvider, axisState?:
|
|
15
|
+
axisState?: YAxisConfig | undefined;
|
|
16
|
+
constructor(series: DataSeriesModel, config: DataSeriesConfig, yAxisBoundsProvider: BoundsProvider, axisState?: YAxisConfig | undefined);
|
|
17
17
|
/**
|
|
18
18
|
* Returns an array of LabelGroup objects that contain VisualYAxisLabel objects.
|
|
19
19
|
* The labels are unordered and are based on the last data series point or the last visual series point, depending on the configuration.
|
|
@@ -3,4 +3,70 @@
|
|
|
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{DEFAULT_DATA_SERIES_PAINT_CONFIG
|
|
6
|
+
import { DEFAULT_DATA_SERIES_PAINT_CONFIG } from '../../../model/data-series.config';
|
|
7
|
+
import { getLabelTextColorByBackgroundColor } from '../../../utils/canvas/canvas-text-functions.utils';
|
|
8
|
+
export class DataSeriesYAxisLabelsProvider {
|
|
9
|
+
constructor(series, config, yAxisBoundsProvider, axisState) {
|
|
10
|
+
this.series = series;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.yAxisBoundsProvider = yAxisBoundsProvider;
|
|
13
|
+
this.axisState = axisState;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns an array of LabelGroup objects that contain VisualYAxisLabel objects.
|
|
17
|
+
* The labels are unordered and are based on the last data series point or the last visual series point, depending on the configuration.
|
|
18
|
+
* The labels are formatted using the series value formatter.
|
|
19
|
+
* The label appearance type and draw configuration are also based on the configuration.
|
|
20
|
+
* @returns {LabelGroup[]} An array of LabelGroup objects that contain VisualYAxisLabel objects.
|
|
21
|
+
*/
|
|
22
|
+
getUnorderedLabels() {
|
|
23
|
+
const visible = this.config.visible;
|
|
24
|
+
if (visible) {
|
|
25
|
+
const getLastPointForLabel = this.config.labelLastValue === 'series'
|
|
26
|
+
? this.series.getLastDataSeriesPoint
|
|
27
|
+
: this.series.getLastVisualSeriesPoint;
|
|
28
|
+
const bounds = this.yAxisBoundsProvider();
|
|
29
|
+
const mode = this.config.labelMode;
|
|
30
|
+
const appearanceType = this.config.labelAppearanceType;
|
|
31
|
+
const lastPoint = getLastPointForLabel();
|
|
32
|
+
if (lastPoint !== undefined) {
|
|
33
|
+
const lastPointY = this.series.view.toY(lastPoint.close);
|
|
34
|
+
if (isFinite(lastPointY)) {
|
|
35
|
+
const label = this.series.valueFormatter(lastPoint.close);
|
|
36
|
+
const drawConfig = this.getLabelDrawConfig();
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
labels: [
|
|
40
|
+
Object.assign({ y: lastPointY, description: this.series.name, mode, labelType: appearanceType, labelText: label }, drawConfig),
|
|
41
|
+
],
|
|
42
|
+
axisState: this.axisState,
|
|
43
|
+
bounds,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the `config` object from the `series` object and then retrieves the `paintConfig` object from the `config` object.
|
|
53
|
+
* If `paintConfig` is null or undefined, it uses the `DEFAULT_DATA_SERIES_PAINT_CONFIG`. It then retrieves the `bgColor`
|
|
54
|
+
* from the `paintConfig` object and calculates the `textColor` based on the `bgColor` using the `getLabelTextColorByBackgroundColor` function.
|
|
55
|
+
* Finally, it returns an object with `textColor`, `bgColor`, `paddingBottom`, `paddingEnd`, and `paddingTop` properties.
|
|
56
|
+
* @returns {YAxisLabelDrawConfig}
|
|
57
|
+
*/
|
|
58
|
+
getLabelDrawConfig() {
|
|
59
|
+
var _a;
|
|
60
|
+
const config = this.series.config;
|
|
61
|
+
const paintConfig = (_a = config.paintConfig[0]) !== null && _a !== void 0 ? _a : DEFAULT_DATA_SERIES_PAINT_CONFIG;
|
|
62
|
+
const bgColor = paintConfig.color;
|
|
63
|
+
const textColor = getLabelTextColorByBackgroundColor(bgColor, 'white', 'black');
|
|
64
|
+
return {
|
|
65
|
+
textColor,
|
|
66
|
+
bgColor,
|
|
67
|
+
paddingBottom: config.labelPaddingBottom,
|
|
68
|
+
paddingEnd: config.labelPaddingEnd,
|
|
69
|
+
paddingTop: config.labelPaddingTop,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -3,4 +3,59 @@
|
|
|
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{notEmpty
|
|
6
|
+
import { notEmpty } from '../../../utils/function.utils';
|
|
7
|
+
/**
|
|
8
|
+
* Calculates the Y coordinates for the labels of a chart based on the provided points and label height.
|
|
9
|
+
* @param {PositionAndWeight[]} points - An array of objects containing the position and weight of each point.
|
|
10
|
+
* @param {number} labelHeight - The height of the label.
|
|
11
|
+
* @returns {number[]} An array of Y coordinates for the labels.
|
|
12
|
+
* @doc-tags tricky
|
|
13
|
+
*/
|
|
14
|
+
export function calcLabelsYCoordinates(points, labelHeight) {
|
|
15
|
+
if (points.filter(it => it !== null).length <= 1) {
|
|
16
|
+
return points.map(p => p.y);
|
|
17
|
+
}
|
|
18
|
+
const adjustedLabelHeight = labelHeight - 2; // -2 to remove paddings between labels
|
|
19
|
+
const formattedCoordinates = points
|
|
20
|
+
.map((point, index) => toLabel(point, index, adjustedLabelHeight))
|
|
21
|
+
.filter(notEmpty)
|
|
22
|
+
.sort(sortLabels); // sort labels in ascending order, top -> down
|
|
23
|
+
const newCoordinates = new Array(formattedCoordinates.length);
|
|
24
|
+
formattedCoordinates.forEach((current, idx) => {
|
|
25
|
+
if (current === null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const next = formattedCoordinates[idx + 1];
|
|
29
|
+
if (next && next.top < current.bottom) {
|
|
30
|
+
/**
|
|
31
|
+
* adjust padding if weight diff is 1, used for countdown label padding
|
|
32
|
+
* @doc-tags tricky
|
|
33
|
+
*/
|
|
34
|
+
const paddingAdjust = next.labelWeight - current.labelWeight === 1 ? 2 : 0;
|
|
35
|
+
const delta = current.bottom - next.top + paddingAdjust;
|
|
36
|
+
next.top += delta;
|
|
37
|
+
next.bottom += delta;
|
|
38
|
+
}
|
|
39
|
+
newCoordinates[current.actualIndex] = (current.top + current.bottom) / 2;
|
|
40
|
+
});
|
|
41
|
+
return newCoordinates;
|
|
42
|
+
}
|
|
43
|
+
const toLabel = (point, index, labelHeight) => point
|
|
44
|
+
? {
|
|
45
|
+
top: point.y - labelHeight / 2,
|
|
46
|
+
bottom: point.y + labelHeight / 2,
|
|
47
|
+
labelWeight: point.weight,
|
|
48
|
+
actualIndex: index,
|
|
49
|
+
}
|
|
50
|
+
: null;
|
|
51
|
+
const sortLabels = (a, b) => {
|
|
52
|
+
const aVal = a.top;
|
|
53
|
+
const bVal = b.top;
|
|
54
|
+
if (aVal > bVal) {
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
if (aVal < bVal || (aVal === bVal && a.labelWeight < b.labelWeight)) {
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
};
|
|
@@ -3,4 +3,98 @@
|
|
|
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{getPrimaryLabelTextColor
|
|
6
|
+
import { getPrimaryLabelTextColor } from '../label-color.functions';
|
|
7
|
+
import { lastOf } from '../../../utils/array.utils';
|
|
8
|
+
import { getLabelTextColorByBackgroundColor } from '../../../utils/canvas/canvas-text-functions.utils';
|
|
9
|
+
export class LastCandleLabelsProvider {
|
|
10
|
+
constructor(chartModel, config, lastCandleLabelsByChartType, resolveLabelColorFn) {
|
|
11
|
+
this.chartModel = chartModel;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.lastCandleLabelsByChartType = lastCandleLabelsByChartType;
|
|
14
|
+
this.resolveLabelColorFn = resolveLabelColorFn;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns an array of LabelGroup objects that contain the labels for the yAxis of the chart.
|
|
18
|
+
* @returns {LabelGroup[]} An array of LabelGroup objects that contain the labels for the yAxis of the chart.
|
|
19
|
+
*/
|
|
20
|
+
getUnorderedLabels() {
|
|
21
|
+
const collectedLabels = [];
|
|
22
|
+
const visible = this.config.components.yAxis.labels.settings.lastPrice.mode !== 'none';
|
|
23
|
+
if (visible) {
|
|
24
|
+
// main candle series
|
|
25
|
+
const yAxisVisualLabel = this.getYAxisVisualLabel(this.chartModel.mainCandleSeries);
|
|
26
|
+
const mainCandleSeriesVisualLabel = yAxisVisualLabel
|
|
27
|
+
? Object.assign(Object.assign({}, yAxisVisualLabel), this.getLabelDrawConfig(this.chartModel.mainCandleSeries, true)) : yAxisVisualLabel;
|
|
28
|
+
if (mainCandleSeriesVisualLabel) {
|
|
29
|
+
const mainCandleSeriesLabels = { labels: [mainCandleSeriesVisualLabel] };
|
|
30
|
+
const handler = this.lastCandleLabelsByChartType[this.config.components.chart.type];
|
|
31
|
+
handler === null || handler === void 0 ? void 0 : handler(mainCandleSeriesLabels, this.chartModel.mainCandleSeries);
|
|
32
|
+
collectedLabels.push(mainCandleSeriesLabels);
|
|
33
|
+
}
|
|
34
|
+
// compare candle series
|
|
35
|
+
this.chartModel.candleSeries.forEach((series, index) => {
|
|
36
|
+
if (index === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const yAxisVisualLabel = this.getYAxisVisualLabel(series);
|
|
40
|
+
const secondarySeriesVisualLabel = yAxisVisualLabel
|
|
41
|
+
? Object.assign(Object.assign({}, yAxisVisualLabel), this.getLabelDrawConfig(series, false)) : yAxisVisualLabel;
|
|
42
|
+
if (secondarySeriesVisualLabel) {
|
|
43
|
+
const secondarySeriesLabel = {
|
|
44
|
+
labels: [secondarySeriesVisualLabel],
|
|
45
|
+
};
|
|
46
|
+
const handler = this.lastCandleLabelsByChartType[series.config.type];
|
|
47
|
+
handler === null || handler === void 0 ? void 0 : handler(secondarySeriesLabel, this.chartModel.mainCandleSeries);
|
|
48
|
+
collectedLabels.push(secondarySeriesLabel);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return collectedLabels;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the visual label for the Y axis of a candle series.
|
|
56
|
+
* @param {CandleSeriesModel} series - The candle series model.
|
|
57
|
+
* @returns {Omit<VisualYAxisLabel, 'bgColor'> | null} - The visual label for the Y axis or null if there is no data.
|
|
58
|
+
*/
|
|
59
|
+
getYAxisVisualLabel(series) {
|
|
60
|
+
const lastCandle = lastOf(series.dataPoints);
|
|
61
|
+
if (lastCandle) {
|
|
62
|
+
const y = series.view.toY(lastCandle.close);
|
|
63
|
+
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;
|
|
66
|
+
return {
|
|
67
|
+
y,
|
|
68
|
+
labelWeight: 0,
|
|
69
|
+
labelText: this.chartModel.pane.valueFormatter(lastCandle.close, series),
|
|
70
|
+
mode,
|
|
71
|
+
labelType: appearanceType,
|
|
72
|
+
description: series.instrument.symbol,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns the configuration object for drawing the label of the Y-axis.
|
|
80
|
+
* @param {CandleSeriesModel} series - The series model for which the label configuration is to be returned.
|
|
81
|
+
* @param {boolean} primary - A boolean value indicating whether the label is primary or not.
|
|
82
|
+
* @returns {YAxisLabelDrawConfig} - The configuration object for drawing the label of the Y-axis.
|
|
83
|
+
*/
|
|
84
|
+
getLabelDrawConfig(series, primary) {
|
|
85
|
+
const colors = series.colors.labels;
|
|
86
|
+
const getLabelBoxColor = this.resolveLabelColorFn(series.config.type);
|
|
87
|
+
const { rectLabelTextColor, rectLabelInvertedTextColor } = this.chartModel.config.colors.yAxis;
|
|
88
|
+
let boxColor = '#FFFFFF';
|
|
89
|
+
let textColor = '#FFFFFF';
|
|
90
|
+
if (colors) {
|
|
91
|
+
boxColor = getLabelBoxColor(series.lastPriceMovement, series.colors);
|
|
92
|
+
textColor = primary ? getPrimaryLabelTextColor(series.lastPriceMovement, colors) : rectLabelTextColor;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
bgColor: boxColor,
|
|
96
|
+
textColor: getLabelTextColorByBackgroundColor(boxColor, textColor, rectLabelInvertedTextColor),
|
|
97
|
+
rounded: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
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 { CanvasBoundsContainer } from '../../../canvas/canvas-bounds-container';
|
|
7
|
-
import {
|
|
7
|
+
import { YAxisConfig, FullChartColors, YAxisLabelAppearanceType } from '../../../chart.config';
|
|
8
8
|
import { Bounds } from '../../../model/bounds.model';
|
|
9
9
|
import { drawBadgeLabel, drawPlainLabel, drawRectLabel } from '../y-axis-labels.drawer';
|
|
10
10
|
import { VisualYAxisLabel, YAxisVisualLabelType } from './y-axis-labels.model';
|
|
@@ -19,5 +19,5 @@ export declare const priceLabelDrawersMap: Record<YAxisVisualLabelType, LabelDra
|
|
|
19
19
|
* @param canvasBoundsContainer
|
|
20
20
|
* @param config
|
|
21
21
|
*/
|
|
22
|
-
export declare function drawLabel(ctx: CanvasRenderingContext2D, backgroundCtx: CanvasRenderingContext2D, bounds: Bounds, paneBounds: Bounds, visualLabel: VisualYAxisLabel, canvasBoundsContainer: CanvasBoundsContainer, config:
|
|
22
|
+
export declare function drawLabel(ctx: CanvasRenderingContext2D, backgroundCtx: CanvasRenderingContext2D, bounds: Bounds, paneBounds: Bounds, visualLabel: VisualYAxisLabel, canvasBoundsContainer: CanvasBoundsContainer, config: YAxisConfig, colors: FullChartColors['yAxis']): void;
|
|
23
23
|
export {};
|