@devexperts/dxcharts-lite 1.0.2 → 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.
- 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.d.ts +2 -2
- package/dist/chart/components/pane/pane-hit-test.controller.js +55 -1
- package/dist/chart/components/pane/pane-manager.component.d.ts +12 -6
- package/dist/chart/components/pane/pane-manager.component.js +149 -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.d.ts +4 -3
- package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.js +96 -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 +10 -17
- package/dist/chart/components/y_axis/y-axis.model.js +34 -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 +3 -2
- package/dist/chart/model/scale.model.js +316 -1
- package/dist/chart/model/scaling/auto-scale.model.d.ts +2 -4
- package/dist/chart/model/scaling/auto-scale.model.js +91 -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,21 @@
|
|
|
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 Color from 'color';
|
|
7
|
+
export const VOLUMES_COLOR_OPACITY = 0.3;
|
|
8
|
+
export const resolveColorForBar = (priceMovement, colors) => {
|
|
9
|
+
const color = colors.barTheme[`${priceMovement}Color`];
|
|
10
|
+
return Color(color).alpha(VOLUMES_COLOR_OPACITY).toString();
|
|
11
|
+
};
|
|
12
|
+
export const resolveColorUsingConfig = (priceMovement, colors) => {
|
|
13
|
+
const color = colors.volume[`${priceMovement}BarColor`];
|
|
14
|
+
return Color(color).alpha(VOLUMES_COLOR_OPACITY).toString();
|
|
15
|
+
};
|
|
16
|
+
export const resolveColorForLine = (priceMovement, colors) => {
|
|
17
|
+
const color = colors.lineTheme[`${priceMovement}Color`];
|
|
18
|
+
return Color(color).alpha(VOLUMES_COLOR_OPACITY).toString();
|
|
19
|
+
};
|
|
20
|
+
export const resolveColorForCandle = (priceMovement, colors) => {
|
|
21
|
+
const color = colors.candleTheme[`${priceMovement}Color`];
|
|
22
|
+
return Color(color).alpha(VOLUMES_COLOR_OPACITY).toString();
|
|
23
|
+
};
|
|
@@ -3,31 +3,30 @@
|
|
|
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 { BehaviorSubject } from 'rxjs';
|
|
6
7
|
import { CanvasBoundsContainer } from '../../canvas/canvas-bounds-container';
|
|
7
|
-
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
8
8
|
import { BarType, FullChartColors, FullChartConfig } from '../../chart.config';
|
|
9
|
-
import { CanvasModel } from '../../model/canvas.model';
|
|
10
9
|
import { DrawingManager } from '../../drawers/drawing-manager';
|
|
11
10
|
import { PriceMovement } from '../../model/candle-series.model';
|
|
11
|
+
import { CanvasModel } from '../../model/canvas.model';
|
|
12
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
12
13
|
import { ScaleModel } from '../../model/scale.model';
|
|
13
14
|
import { ChartComponent } from '../chart/chart.component';
|
|
15
|
+
import { DynamicObjectsComponent } from '../dynamic-objects/dynamic-objects.component';
|
|
14
16
|
import { PaneManager } from '../pane/pane-manager.component';
|
|
15
17
|
import { SeparateVolumesComponent } from './separate-volumes.component';
|
|
16
18
|
import { VolumesModel } from './volumes.model';
|
|
17
|
-
import { YAxisComponent } from '../y_axis/y-axis.component';
|
|
18
|
-
import { BehaviorSubject } from 'rxjs';
|
|
19
19
|
export type VolumeColorResolver = (priceMovement: PriceMovement, colors: FullChartColors) => string;
|
|
20
20
|
export declare class VolumesComponent extends ChartBaseElement {
|
|
21
21
|
private canvasModel;
|
|
22
22
|
private canvasBoundsContainer;
|
|
23
23
|
private config;
|
|
24
24
|
separateVolumes: SeparateVolumesComponent;
|
|
25
|
-
|
|
25
|
+
volumesColorByChartTypeMap: Partial<Record<BarType, VolumeColorResolver>>;
|
|
26
26
|
volumesModel: VolumesModel;
|
|
27
|
-
yAxisComponent: YAxisComponent;
|
|
28
27
|
volumeVisibilityChangedSubject: BehaviorSubject<boolean>;
|
|
29
28
|
volumeIsSeparateModeChangedSubject: BehaviorSubject<boolean>;
|
|
30
|
-
constructor(canvasModel: CanvasModel, chartComponent: ChartComponent,
|
|
29
|
+
constructor(canvasModel: CanvasModel, chartComponent: ChartComponent, scale: ScaleModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, config: FullChartConfig, paneManager: PaneManager, dynamicObjectsComponent: DynamicObjectsComponent);
|
|
31
30
|
/**
|
|
32
31
|
* Registers default volume color resolvers for candle, line and bar charts
|
|
33
32
|
* @private
|
|
@@ -3,4 +3,97 @@
|
|
|
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 { BehaviorSubject } from 'rxjs';
|
|
7
|
+
import { CHART_UUID } from '../../canvas/canvas-bounds-container';
|
|
8
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
9
|
+
import { SeparateVolumesComponent } from './separate-volumes.component';
|
|
10
|
+
import { resolveColorForBar, resolveColorForCandle, resolveColorForLine } from './volume-color-resolvers.functions';
|
|
11
|
+
import { VolumesDrawer } from './volumes.drawer';
|
|
12
|
+
import { VolumesModel } from './volumes.model';
|
|
13
|
+
export class VolumesComponent extends ChartBaseElement {
|
|
14
|
+
constructor(canvasModel, chartComponent, scale, canvasBoundsContainer, drawingManager, config, paneManager, dynamicObjectsComponent) {
|
|
15
|
+
super();
|
|
16
|
+
this.canvasModel = canvasModel;
|
|
17
|
+
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.volumesColorByChartTypeMap = {};
|
|
20
|
+
this.volumeVisibilityChangedSubject = new BehaviorSubject(false);
|
|
21
|
+
this.volumeIsSeparateModeChangedSubject = new BehaviorSubject(false);
|
|
22
|
+
const volumesModel = new VolumesModel(chartComponent, scale);
|
|
23
|
+
this.volumesModel = volumesModel;
|
|
24
|
+
this.addChildEntity(volumesModel);
|
|
25
|
+
this.separateVolumes = new SeparateVolumesComponent(chartComponent, drawingManager, config, volumesModel, paneManager);
|
|
26
|
+
const volumesDrawer = new VolumesDrawer(config, this.volumesModel, chartComponent.chartModel, () => { var _a, _b; return (this.config.components.volumes.showSeparately ? (_b = (_a = this.separateVolumes.pane) === null || _a === void 0 ? void 0 : _a.scale) !== null && _b !== void 0 ? _b : scale : scale); }, this.volumesColorByChartTypeMap, () => true);
|
|
27
|
+
dynamicObjectsComponent.model.addObject({ drawer: volumesDrawer, model: volumesModel }, CHART_UUID);
|
|
28
|
+
this.addChildEntity(this.separateVolumes);
|
|
29
|
+
this.registerDefaultVolumeColorResolvers();
|
|
30
|
+
this.volumeVisibilityChangedSubject.next(config.components.volumes.visible);
|
|
31
|
+
this.volumeIsSeparateModeChangedSubject.next(config.components.volumes.showSeparately);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers default volume color resolvers for candle, line and bar charts
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
registerDefaultVolumeColorResolvers() {
|
|
38
|
+
this.registerVolumeColorResolver('candle', resolveColorForCandle);
|
|
39
|
+
this.registerVolumeColorResolver('trend', resolveColorForCandle);
|
|
40
|
+
this.registerVolumeColorResolver('hollow', resolveColorForCandle);
|
|
41
|
+
this.registerVolumeColorResolver('line', resolveColorForLine);
|
|
42
|
+
this.registerVolumeColorResolver('bar', resolveColorForBar);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sets whether the volumes should be shown separately or not.
|
|
46
|
+
*
|
|
47
|
+
* @param {boolean} separate - A boolean value indicating whether the volumes should be shown separately or not.
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
setShowVolumesSeparatly(separate) {
|
|
51
|
+
if (this.config.components.volumes.showSeparately !== separate) {
|
|
52
|
+
this.config.components.volumes.showSeparately = separate;
|
|
53
|
+
if (separate) {
|
|
54
|
+
this.separateVolumes.activateSeparateVolumes();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.separateVolumes.deactiveSeparateVolumes();
|
|
58
|
+
}
|
|
59
|
+
this.volumeIsSeparateModeChangedSubject.next(separate);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* This method deactivates the current component by calling the superclass doDeactivate method and setting the visibility of the component to false.
|
|
64
|
+
* @returns {void}
|
|
65
|
+
*/
|
|
66
|
+
doDeactivate() {
|
|
67
|
+
super.doDeactivate();
|
|
68
|
+
this.setVisible(false);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* You can use this method to determine volumes' color for specified chart type.
|
|
72
|
+
* @param chartType
|
|
73
|
+
* @param resolver
|
|
74
|
+
*/
|
|
75
|
+
registerVolumeColorResolver(chartType, resolver) {
|
|
76
|
+
this.volumesColorByChartTypeMap[chartType] = resolver;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sets the visibility of the volumes component and updates the canvas accordingly.
|
|
80
|
+
* @param {boolean} visible - Whether the volumes component should be visible or not. Default is true.
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
setVisible(visible = true) {
|
|
84
|
+
this.config.components.volumes.visible = visible;
|
|
85
|
+
this.volumeVisibilityChangedSubject.next(visible);
|
|
86
|
+
if (this.config.components.volumes.showSeparately === true) {
|
|
87
|
+
if (visible) {
|
|
88
|
+
this.separateVolumes.activateSeparateVolumes();
|
|
89
|
+
this.volumeIsSeparateModeChangedSubject.next(true);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.separateVolumes.deactiveSeparateVolumes();
|
|
93
|
+
this.volumeIsSeparateModeChangedSubject.next(false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.canvasBoundsContainer.recalculatePanesHeightRatios();
|
|
97
|
+
this.canvasModel.fireDraw();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -5,21 +5,20 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { BarType, FullChartConfig } from '../../chart.config';
|
|
7
7
|
import { CanvasModel } from '../../model/canvas.model';
|
|
8
|
-
import { Drawer } from '../../drawers/drawing-manager';
|
|
9
8
|
import { ViewportModel } from '../../model/scaling/viewport.model';
|
|
10
9
|
import { ChartModel } from '../chart/chart.model';
|
|
10
|
+
import { DynamicModelDrawer } from '../dynamic-objects/dynamic-objects.drawer';
|
|
11
11
|
import { VolumeColorResolver } from './volumes.component';
|
|
12
12
|
import { VolumesModel } from './volumes.model';
|
|
13
|
-
export declare class VolumesDrawer implements
|
|
14
|
-
private canvasModel;
|
|
13
|
+
export declare class VolumesDrawer implements DynamicModelDrawer<VolumesModel> {
|
|
15
14
|
private config;
|
|
16
15
|
private volumesModel;
|
|
17
16
|
private chartModel;
|
|
18
|
-
|
|
17
|
+
getViewportModel: () => ViewportModel;
|
|
19
18
|
private volumesColorByChartTypeMap;
|
|
20
19
|
private drawPredicate;
|
|
21
20
|
private readonly volumeBarColors;
|
|
22
|
-
constructor(
|
|
21
|
+
constructor(config: FullChartConfig, volumesModel: VolumesModel, chartModel: ChartModel, getViewportModel: () => ViewportModel, volumesColorByChartTypeMap: Partial<Record<BarType, VolumeColorResolver>>, drawPredicate: () => boolean);
|
|
23
22
|
/**
|
|
24
23
|
* This function is used to calculate the colors for each volume bar. It is an optimization to avoid calculating the color for each volume, which can be expensive.
|
|
25
24
|
* @param {BarType} barType - The type of bar to calculate the color for.
|
|
@@ -33,7 +32,7 @@ export declare class VolumesDrawer implements Drawer {
|
|
|
33
32
|
* Restores the canvas context.
|
|
34
33
|
* @returns {void}
|
|
35
34
|
*/
|
|
36
|
-
draw(): void;
|
|
35
|
+
draw(canvasModel: CanvasModel): void;
|
|
37
36
|
/**
|
|
38
37
|
* Draws the last bar of the chart if the volumes component is visible.
|
|
39
38
|
* TODO: Rework the function.
|
|
@@ -62,10 +61,4 @@ export declare class VolumesDrawer implements Drawer {
|
|
|
62
61
|
* @returns {void}
|
|
63
62
|
*/
|
|
64
63
|
private drawVolume;
|
|
65
|
-
/**
|
|
66
|
-
* Returns an array of canvas ids.
|
|
67
|
-
*
|
|
68
|
-
* @returns {Array<string>} An array containing the canvas id.
|
|
69
|
-
*/
|
|
70
|
-
getCanvasIds(): Array<string>;
|
|
71
64
|
}
|
|
@@ -3,4 +3,143 @@
|
|
|
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{clipToBounds
|
|
6
|
+
import { clipToBounds } from '../../drawers/data-series.drawer';
|
|
7
|
+
import { unitToPixels } from '../../model/scaling/viewport.model';
|
|
8
|
+
import { flat } from '../../utils/array.utils';
|
|
9
|
+
import { ceilToDPR, floorToDPR } from '../../utils/device/device-pixel-ratio.utils';
|
|
10
|
+
import { resolveColorUsingConfig } from './volume-color-resolvers.functions';
|
|
11
|
+
// ratio of CHART bounds height which is for overlay volumes
|
|
12
|
+
const OVERLAY_VOLUME_TOTAL_HEIGHT_DIVISOR = 3;
|
|
13
|
+
export class VolumesDrawer {
|
|
14
|
+
constructor(config, volumesModel, chartModel, getViewportModel, volumesColorByChartTypeMap, drawPredicate) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.volumesModel = volumesModel;
|
|
17
|
+
this.chartModel = chartModel;
|
|
18
|
+
this.getViewportModel = getViewportModel;
|
|
19
|
+
this.volumesColorByChartTypeMap = volumesColorByChartTypeMap;
|
|
20
|
+
this.drawPredicate = drawPredicate;
|
|
21
|
+
this.volumeBarColors = {
|
|
22
|
+
down: '#FF00FF',
|
|
23
|
+
up: '#FF00FF',
|
|
24
|
+
none: '#FF00FF',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* This function is used to calculate the colors for each volume bar. It is an optimization to avoid calculating the color for each volume, which can be expensive.
|
|
29
|
+
* @param {BarType} barType - The type of bar to calculate the color for.
|
|
30
|
+
* @returns {void}
|
|
31
|
+
*/
|
|
32
|
+
calculateColors(barType) {
|
|
33
|
+
var _a;
|
|
34
|
+
const getVolumeBarColor = (_a = this.volumesColorByChartTypeMap[barType]) !== null && _a !== void 0 ? _a : resolveColorUsingConfig;
|
|
35
|
+
this.volumeBarColors['down'] = getVolumeBarColor('down', this.config.colors);
|
|
36
|
+
this.volumeBarColors['up'] = getVolumeBarColor('up', this.config.colors);
|
|
37
|
+
this.volumeBarColors['none'] = getVolumeBarColor('none', this.config.colors);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Draws the volumes on the chart canvas if the volumes are visible and the drawPredicate is true.
|
|
41
|
+
* Calculates the colors based on the chart type and saves the canvas context.
|
|
42
|
+
* Clips the canvas to the viewport bounds and draws the volumes.
|
|
43
|
+
* Restores the canvas context.
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
draw(canvasModel) {
|
|
47
|
+
if (this.config.components.volumes.visible && this.drawPredicate()) {
|
|
48
|
+
this.calculateColors(this.config.components.chart.type);
|
|
49
|
+
const ctx = canvasModel.ctx;
|
|
50
|
+
ctx.save();
|
|
51
|
+
const bounds = this.getViewportModel().getBounds();
|
|
52
|
+
clipToBounds(ctx, bounds);
|
|
53
|
+
this.drawVolumes(canvasModel);
|
|
54
|
+
ctx.restore();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Draws the last bar of the chart if the volumes component is visible.
|
|
59
|
+
* TODO: Rework the function.
|
|
60
|
+
*
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*/
|
|
63
|
+
drawLastBar() {
|
|
64
|
+
if (this.config.components.volumes.visible) {
|
|
65
|
+
// TODO rework
|
|
66
|
+
// this.calculateColors(this.config.components.chart.type);
|
|
67
|
+
// const ctx = this.canvasModel.ctx;
|
|
68
|
+
// const lastVolume = lastOf(this.volumes.data);
|
|
69
|
+
// if (lastVolume) {
|
|
70
|
+
// ctx.fillStyle = this.volumeBarColors[lastVolume.direction];
|
|
71
|
+
// const { width, height, x, y } = lastVolume;
|
|
72
|
+
// ctx.fillRect(x, y, width, height);
|
|
73
|
+
// }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Draws volumes on the chart based on the data provided by the volumesModel and chartModel.
|
|
78
|
+
* If the volumeMax is 0, the function will return without drawing anything.
|
|
79
|
+
* The function loops through all the candles in the viewport and calculates the x, y, width and height of each volume bar.
|
|
80
|
+
* If the config.components.volumes.showSeparately is true, the function will draw each volume bar separately.
|
|
81
|
+
* Otherwise, it will calculate the zoomY based on the volumeMax and the fullVHeight, and draw all the volume bars together.
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
drawVolumes(canvasModel) {
|
|
85
|
+
const volumeMax = this.volumesModel.volumeMax.getValue();
|
|
86
|
+
if (volumeMax === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const candles = flat(this.chartModel.mainCandleSeries
|
|
90
|
+
// TODO volumes drawer should be a part of data series drawer
|
|
91
|
+
.getSeriesInViewport(this.chartModel.scale.xStart - 1, this.chartModel.scale.xEnd + 1));
|
|
92
|
+
const viewportModel = this.getViewportModel();
|
|
93
|
+
candles.forEach((vCandle, idx) => {
|
|
94
|
+
if (vCandle.candle.volume) {
|
|
95
|
+
const bounds = viewportModel.getBounds();
|
|
96
|
+
const fullVHeight = bounds.height;
|
|
97
|
+
const nextX = candles[idx + 1] !== undefined
|
|
98
|
+
? floorToDPR(viewportModel.toX(candles[idx + 1].startUnit))
|
|
99
|
+
: undefined;
|
|
100
|
+
const x = floorToDPR(viewportModel.toX(vCandle.startUnit));
|
|
101
|
+
const width = nextX !== undefined ? nextX - x : floorToDPR(unitToPixels(vCandle.width, viewportModel.zoomX));
|
|
102
|
+
if (this.config.components.volumes.showSeparately) {
|
|
103
|
+
const y = floorToDPR(viewportModel.toY(vCandle.candle.volume));
|
|
104
|
+
const height = floorToDPR(viewportModel.toY(0)) - y;
|
|
105
|
+
this.drawVolume(canvasModel, vCandle, x, y, width, height);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const zoomY = volumeMax / (fullVHeight / OVERLAY_VOLUME_TOTAL_HEIGHT_DIVISOR);
|
|
109
|
+
const height = Math.max(unitToPixels(vCandle.candle.volume, zoomY), 2);
|
|
110
|
+
const y = floorToDPR(bounds.y + fullVHeight - height);
|
|
111
|
+
this.drawVolume(canvasModel, vCandle, x, y, width, height);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Draws a volume bar on the canvas.
|
|
118
|
+
*
|
|
119
|
+
* @private
|
|
120
|
+
* @param {VisualCandle} vCandle - The visual candle object.
|
|
121
|
+
* @param {Pixel} x - The x coordinate of the top-left corner of the volume bar.
|
|
122
|
+
* @param {Pixel} y - The y coordinate of the top-left corner of the volume bar.
|
|
123
|
+
* @param {Pixel} width - The width of the volume bar.
|
|
124
|
+
* @param {Pixel} height - The height of the volume bar.
|
|
125
|
+
* @returns {void}
|
|
126
|
+
*/
|
|
127
|
+
drawVolume(canvasModel, vCandle, x, y, width, height) {
|
|
128
|
+
const ctx = canvasModel.ctx;
|
|
129
|
+
const yStart = y;
|
|
130
|
+
const yEnd = y + height;
|
|
131
|
+
const direction = vCandle.name;
|
|
132
|
+
ctx.fillStyle = this.volumeBarColors[direction];
|
|
133
|
+
ctx.strokeStyle = this.volumeBarColors[direction];
|
|
134
|
+
if (width === 0) {
|
|
135
|
+
// just draw a vertical line
|
|
136
|
+
ctx.beginPath();
|
|
137
|
+
ctx.moveTo(x, yStart);
|
|
138
|
+
ctx.lineTo(x, ceilToDPR(yEnd));
|
|
139
|
+
ctx.stroke();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
ctx.fillRect(x, y, width, ceilToDPR(height));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -3,4 +3,34 @@
|
|
|
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
|
-
const
|
|
6
|
+
const DEFAULT_PRECISION = 5;
|
|
7
|
+
const MIN_VALUE = 0.0000000001;
|
|
8
|
+
const TRAILLING_ZEROES_REGEXP = /\.?0+$/;
|
|
9
|
+
const TRAILLING_FRACTION_WITH_ZEROES_REGEXP = /(\.[1-9]*)0+$/;
|
|
10
|
+
export const volumeFormatter = (value) => {
|
|
11
|
+
const formatValue = (value, amountToCut) => {
|
|
12
|
+
const rounder = Math.pow(10, DEFAULT_PRECISION);
|
|
13
|
+
const roundedValue = Math.round(value * rounder) / rounder;
|
|
14
|
+
if (roundedValue < 1 && roundedValue >= MIN_VALUE) {
|
|
15
|
+
return roundedValue
|
|
16
|
+
.toFixed(DEFAULT_PRECISION)
|
|
17
|
+
.replace(TRAILLING_ZEROES_REGEXP, '')
|
|
18
|
+
.replace(TRAILLING_FRACTION_WITH_ZEROES_REGEXP, '');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return (roundedValue + '').replace(TRAILLING_FRACTION_WITH_ZEROES_REGEXP, '') + (amountToCut || '');
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
if (Math.abs(value) > 999999999) {
|
|
25
|
+
value = Math.round(value / 1000000) * 1000000;
|
|
26
|
+
return formatValue(value / 1000000000, 'B');
|
|
27
|
+
}
|
|
28
|
+
if (Math.abs(value) > 999999) {
|
|
29
|
+
value = 1000 * Math.round(value / 1000);
|
|
30
|
+
return formatValue(value / 1000000, 'M');
|
|
31
|
+
}
|
|
32
|
+
if (Math.abs(value) > 9999) {
|
|
33
|
+
return formatValue(value / 1000, 'K');
|
|
34
|
+
}
|
|
35
|
+
return formatValue(value);
|
|
36
|
+
};
|
|
@@ -10,10 +10,10 @@ import { HighLowProvider } from '../../model/scaling/auto-scale.model';
|
|
|
10
10
|
import { ChartComponent } from '../chart/chart.component';
|
|
11
11
|
export declare class VolumesModel extends ChartBaseElement {
|
|
12
12
|
private chartComponent;
|
|
13
|
-
private
|
|
13
|
+
private scale;
|
|
14
14
|
volumeMax: BehaviorSubject<number>;
|
|
15
15
|
highLowProvider: HighLowProvider;
|
|
16
|
-
constructor(chartComponent: ChartComponent,
|
|
16
|
+
constructor(chartComponent: ChartComponent, scale: ScaleModel);
|
|
17
17
|
protected doActivate(): void;
|
|
18
18
|
/**
|
|
19
19
|
* Used for optimization when we have to update only the last candle
|
|
@@ -3,4 +3,46 @@
|
|
|
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{BehaviorSubject
|
|
6
|
+
import { BehaviorSubject, merge } from 'rxjs';
|
|
7
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
8
|
+
import { firstOf, maxMin } from '../../utils/array.utils';
|
|
9
|
+
const volumeMaxMinFn = maxMin(candle => candle.candle.volume);
|
|
10
|
+
export class VolumesModel extends ChartBaseElement {
|
|
11
|
+
constructor(chartComponent, scale) {
|
|
12
|
+
super();
|
|
13
|
+
this.chartComponent = chartComponent;
|
|
14
|
+
this.scale = scale;
|
|
15
|
+
// max volume in all data series
|
|
16
|
+
this.volumeMax = new BehaviorSubject(0);
|
|
17
|
+
this.highLowProvider = {
|
|
18
|
+
calculateHighLow: () => ({ high: this.volumeMax.getValue(), low: 0 }),
|
|
19
|
+
isHighLowActive: () => true,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
doActivate() {
|
|
23
|
+
super.doActivate();
|
|
24
|
+
this.addRxSubscription(merge(this.chartComponent.chartModel.observeCandlesChanged(), this.scale.xChanged).subscribe(() => this.updateVolumeMax()));
|
|
25
|
+
this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries
|
|
26
|
+
.observeLastVisualCandleChanged()
|
|
27
|
+
.subscribe(() => this.recalculateLastVisualVolume()));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Used for optimization when we have to update only the last candle
|
|
31
|
+
* Doesn't work for line chart types
|
|
32
|
+
* @doc-tags tricky
|
|
33
|
+
*/
|
|
34
|
+
recalculateLastVisualVolume() {
|
|
35
|
+
// TODO rework, move this logic to drawer
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Updates the maximum volume value of the chart.
|
|
39
|
+
* @function
|
|
40
|
+
* @name updateVolumeMax
|
|
41
|
+
* @memberof ChartComponent
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
updateVolumeMax() {
|
|
45
|
+
var _a;
|
|
46
|
+
this.volumeMax.next((_a = firstOf(volumeMaxMinFn(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat()))) !== null && _a !== void 0 ? _a : 0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -3,4 +3,106 @@
|
|
|
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{CHART_UUID
|
|
6
|
+
import { CHART_UUID, CanvasElement } from '../../canvas/canvas-bounds-container';
|
|
7
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
8
|
+
import { merge } from '../../utils/merge.utils';
|
|
9
|
+
import { WaterMarkDrawer } from './water-mark.drawer';
|
|
10
|
+
export class WaterMarkComponent extends ChartBaseElement {
|
|
11
|
+
constructor(paneManager, chartModel, eventBus, config, canvasBoundsContainer, canvasModel, drawingManager) {
|
|
12
|
+
super();
|
|
13
|
+
this.paneManager = paneManager;
|
|
14
|
+
this.chartModel = chartModel;
|
|
15
|
+
this.eventBus = eventBus;
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.canvasModel = canvasModel;
|
|
18
|
+
this.waterMarkConfig = this.config.components.waterMark;
|
|
19
|
+
this.waterMarkData = this.getWaterMarkData();
|
|
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.paneAddedSubject).subscribe((bounds) => {
|
|
22
|
+
this.waterMarkConfig = this.recalculateTextSize(bounds.width, bounds.height);
|
|
23
|
+
}));
|
|
24
|
+
this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(() => {
|
|
25
|
+
this.waterMarkData = this.getWaterMarkData();
|
|
26
|
+
}));
|
|
27
|
+
drawingManager.addDrawerAfter(this.waterMarkDrawer, 'WATERMARK', 'DYNAMIC_OBJECTS');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets the visibility of the watermark component.
|
|
31
|
+
*
|
|
32
|
+
* @param {boolean} visible - A boolean indicating whether the watermark should be visible or not.
|
|
33
|
+
* @returns {void}
|
|
34
|
+
*/
|
|
35
|
+
setWaterMarkVisible(visible) {
|
|
36
|
+
if (this.config.components && this.config.components.waterMark) {
|
|
37
|
+
this.config.components.waterMark.visible = visible;
|
|
38
|
+
this.canvasModel.fireDraw();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Sets the watermark data to be used in the canvas.
|
|
43
|
+
* @param {WaterMarkData} watermarkData - The data to be used as watermark.
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
setWaterMarkData(watermarkData) {
|
|
47
|
+
this.waterMarkData = watermarkData;
|
|
48
|
+
this.canvasModel.fireDraw();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the water mark data object if it exists, otherwise returns an empty object.
|
|
52
|
+
* @returns {WaterMarkData} The water mark data object.
|
|
53
|
+
*/
|
|
54
|
+
getWaterMarkData() {
|
|
55
|
+
return this.waterMarkData || {};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the watermark configuration for the chart.
|
|
59
|
+
* @param {WaterMarkConfig} watermarkConfig - The configuration object for the watermark.
|
|
60
|
+
* @returns {void}
|
|
61
|
+
|
|
62
|
+
*/
|
|
63
|
+
setWaterMarkConfig(watermarkConfig) {
|
|
64
|
+
if (!watermarkConfig || !this.config.components) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!this.config.components.waterMark) {
|
|
68
|
+
this.config.components.waterMark = JSON.parse(JSON.stringify(watermarkConfig));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const newWatermark = {};
|
|
72
|
+
merge(newWatermark, watermarkConfig);
|
|
73
|
+
merge(newWatermark, this.config.components.waterMark);
|
|
74
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
75
|
+
this.config.components.waterMark = newWatermark;
|
|
76
|
+
}
|
|
77
|
+
this.canvasModel.fireDraw();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sets the logo image to be used as a watermark.
|
|
81
|
+
* @param {CanvasImageSource} img - The image to be used as a watermark.
|
|
82
|
+
*/
|
|
83
|
+
setLogoImage(img) {
|
|
84
|
+
this.waterMarkDrawer.setLogoImage(img);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Recalculates the watermark text size based on the chart's width and height.
|
|
88
|
+
* @param {number} chartWidth - The width of the chart.
|
|
89
|
+
* @param {number} chartHeight - The height of the chart.
|
|
90
|
+
* @returns {Object} - An object containing the updated watermark font sizes.
|
|
91
|
+
*/
|
|
92
|
+
recalculateTextSize(chartWidth, chartHeight) {
|
|
93
|
+
const defaultScreenWidth = 1920;
|
|
94
|
+
const defaultScreenHeight = 1080;
|
|
95
|
+
// this function is used to make logarithmic dependency between screen size and watermark size
|
|
96
|
+
const fun = (x) => (0.15 * Math.log(x)) / Math.log(1.5) + 1;
|
|
97
|
+
const textSizeRatioHorizontal = fun(chartWidth / defaultScreenWidth);
|
|
98
|
+
const textSizeRatioVertical = fun(chartHeight / defaultScreenHeight);
|
|
99
|
+
const textSizeRatio = Math.min(textSizeRatioHorizontal, textSizeRatioVertical);
|
|
100
|
+
const textRatio = textSizeRatio >= 0 ? textSizeRatio : 0;
|
|
101
|
+
const updatedProps = {
|
|
102
|
+
firstRowFontSize: Math.round(this.config.components.waterMark.firstRowFontSize * textRatio),
|
|
103
|
+
secondRowFontSize: Math.round(this.config.components.waterMark.secondRowFontSize * textRatio),
|
|
104
|
+
thirdRowFontSize: Math.round(this.config.components.waterMark.thirdRowFontSize * textRatio),
|
|
105
|
+
};
|
|
106
|
+
return Object.assign(Object.assign({}, this.config.components.waterMark), updatedProps);
|
|
107
|
+
}
|
|
108
|
+
}
|