@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,91 @@
|
|
|
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{CanvasBoundsContainer
|
|
6
|
+
import { CanvasBoundsContainer, CanvasElement, isInVerticalBounds, } from '../canvas/canvas-bounds-container';
|
|
7
|
+
import { ChartBaseElement } from './chart-base-element';
|
|
8
|
+
import { DragNDropYComponent } from '../components/dran-n-drop_helper/drag-n-drop-y.component';
|
|
9
|
+
export const BASELINE_RESIZER_UUID = 'BASELINE_RESIZER';
|
|
10
|
+
/**
|
|
11
|
+
* Baseline separator for baseline chart
|
|
12
|
+
* Used to resize baseline area on chart.
|
|
13
|
+
*/
|
|
14
|
+
export class BaselineModel extends ChartBaseElement {
|
|
15
|
+
constructor(chartModel, chartPanComponent, canvasModel, canvasInputListener, config, canvasBoundContainer, cursorHandler) {
|
|
16
|
+
super();
|
|
17
|
+
this.chartModel = chartModel;
|
|
18
|
+
this.canvasModel = canvasModel;
|
|
19
|
+
this.canvasInputListener = canvasInputListener;
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.canvasBoundContainer = canvasBoundContainer;
|
|
22
|
+
this.cursorHandler = cursorHandler;
|
|
23
|
+
this.resizerBounds = { x: 0, y: 0, pageX: 0, pageY: 0, height: 0, width: 0 };
|
|
24
|
+
// the position of a baseline in percents relatively to chart height
|
|
25
|
+
this.baselineYPercents = 50;
|
|
26
|
+
this.ht = CanvasBoundsContainer.hitTestOf(this.resizerBounds, {
|
|
27
|
+
extensionY: this.config.components.paneResizer.dragZone,
|
|
28
|
+
});
|
|
29
|
+
this.dragTickCb = (dragInfo) => {
|
|
30
|
+
const { delta: yDelta } = dragInfo;
|
|
31
|
+
const chart = this.canvasBoundContainer.getBounds(CanvasElement.CHART);
|
|
32
|
+
const y = this.canvasInputListener.getCurrentPoint().y;
|
|
33
|
+
if (yDelta !== 0 && isInVerticalBounds(y, chart)) {
|
|
34
|
+
this.moveBaseLine(y);
|
|
35
|
+
this.canvasModel.fireDraw();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const dndHelper = new DragNDropYComponent(this.ht, {
|
|
39
|
+
onDragTick: this.dragTickCb,
|
|
40
|
+
}, canvasInputListener, chartPanComponent);
|
|
41
|
+
this.addChildEntity(dndHelper);
|
|
42
|
+
}
|
|
43
|
+
doActivate() {
|
|
44
|
+
super.doActivate();
|
|
45
|
+
this.addRxSubscription(this.canvasBoundContainer
|
|
46
|
+
.observeBoundsChanged(CanvasElement.CHART)
|
|
47
|
+
.subscribe(() => this.recalculateBounds()));
|
|
48
|
+
this.chartModel.chartTypeChanged.subscribe(type => {
|
|
49
|
+
if (type === 'baseline') {
|
|
50
|
+
this.cursorHandler.setCursorForBounds('BASELINE_RESIZER', this.resizerBounds, this.config.components.baseline.cursor, this.config.components.baseline.dragZone);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.cursorHandler.removeCursorForCanvasEl('BASELINE_RESIZER');
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Recalculates the bounds of the baseline resizer based on the current chart and y-axis bounds.
|
|
59
|
+
* @private
|
|
60
|
+
* @function
|
|
61
|
+
* @name recalculateBounds
|
|
62
|
+
* @memberof ClassName
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
recalculateBounds() {
|
|
66
|
+
const chart = this.canvasBoundContainer.getBounds(CanvasElement.CHART);
|
|
67
|
+
const yAxis = this.canvasBoundContainer.getBounds(CanvasElement.Y_AXIS);
|
|
68
|
+
this.resizerBounds.x = chart.x;
|
|
69
|
+
this.resizerBounds.width = chart.width + yAxis.width;
|
|
70
|
+
this.resizerBounds.height = this.config.components.baseline.height;
|
|
71
|
+
const relativeBaselineY = chart.y + chart.height * (this.baselineYPercents / 100);
|
|
72
|
+
this.resizerBounds.y = relativeBaselineY;
|
|
73
|
+
this.canvasBoundContainer.bounds[BASELINE_RESIZER_UUID] = this.resizerBounds;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Moves the baseline of the chart to the specified y coordinate.
|
|
77
|
+
* @param {number} y - The y coordinate to move the baseline to.
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
moveBaseLine(y) {
|
|
81
|
+
const chart = this.canvasBoundContainer.getBounds(CanvasElement.CHART);
|
|
82
|
+
this.baselineYPercents = ((y - chart.y) * 100) / chart.height;
|
|
83
|
+
this.resizerBounds.y = y;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* This method is called when the component is being deactivated.
|
|
87
|
+
* It calls the doDeactivate method of the parent class.
|
|
88
|
+
* @protected
|
|
89
|
+
*/
|
|
90
|
+
doDeactivate() {
|
|
91
|
+
super.doDeactivate();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -3,4 +3,73 @@
|
|
|
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
|
-
class
|
|
6
|
+
class CandleHoverImpl {
|
|
7
|
+
constructor(visualCandle, price, priceFormatter, toY) {
|
|
8
|
+
this.visualCandle = visualCandle;
|
|
9
|
+
this.price = price;
|
|
10
|
+
this.priceFormatter = priceFormatter;
|
|
11
|
+
this.toY = toY;
|
|
12
|
+
}
|
|
13
|
+
get high() {
|
|
14
|
+
return this.visualCandle.high;
|
|
15
|
+
}
|
|
16
|
+
get low() {
|
|
17
|
+
return this.visualCandle.low;
|
|
18
|
+
}
|
|
19
|
+
get open() {
|
|
20
|
+
return this.visualCandle.open;
|
|
21
|
+
}
|
|
22
|
+
get close() {
|
|
23
|
+
return this.visualCandle.close;
|
|
24
|
+
}
|
|
25
|
+
get volume() {
|
|
26
|
+
return this.visualCandle.candle.volume;
|
|
27
|
+
}
|
|
28
|
+
get openY() {
|
|
29
|
+
return this.toY(this.open);
|
|
30
|
+
}
|
|
31
|
+
get closeY() {
|
|
32
|
+
return this.toY(this.close);
|
|
33
|
+
}
|
|
34
|
+
get highY() {
|
|
35
|
+
return this.toY(this.high);
|
|
36
|
+
}
|
|
37
|
+
get lowY() {
|
|
38
|
+
return this.toY(this.low);
|
|
39
|
+
}
|
|
40
|
+
get openFormatted() {
|
|
41
|
+
return this.priceFormatter(this.open);
|
|
42
|
+
}
|
|
43
|
+
get closeFormatted() {
|
|
44
|
+
return this.priceFormatter(this.close);
|
|
45
|
+
}
|
|
46
|
+
get highFormatted() {
|
|
47
|
+
return this.priceFormatter(this.high);
|
|
48
|
+
}
|
|
49
|
+
get lowFormatted() {
|
|
50
|
+
return this.priceFormatter(this.low);
|
|
51
|
+
}
|
|
52
|
+
get closestOHLCY() {
|
|
53
|
+
return this.toY([this.close, this.open, this.high, this.low].sort((a, b) => Math.abs(a - this.price) - Math.abs(b - this.price))[0]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class CandleHoverProducerPart {
|
|
57
|
+
constructor(chartModel) {
|
|
58
|
+
this.chartModel = chartModel;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns a CandleHover object or undefined based on the provided BaseHover object.
|
|
62
|
+
* @param {BaseHover} hover - The BaseHover object containing the x and y coordinates.
|
|
63
|
+
* @returns {CandleHover | undefined} - The CandleHover object or undefined if mainSeriesCandle is falsy.
|
|
64
|
+
*/
|
|
65
|
+
getData(hover) {
|
|
66
|
+
const { x, y } = hover;
|
|
67
|
+
const candle = this.chartModel.candleFromX(x);
|
|
68
|
+
const idx = candle.idx || 0;
|
|
69
|
+
const mainSeriesCandle = this.chartModel.getVisualCandle(idx);
|
|
70
|
+
const price = this.chartModel.priceFromY(y);
|
|
71
|
+
const candleHover = mainSeriesCandle &&
|
|
72
|
+
new CandleHoverImpl(mainSeriesCandle, price, this.chartModel.pane.regularFormatter, this.chartModel.toY);
|
|
73
|
+
return candleHover;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -3,4 +3,48 @@
|
|
|
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
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Candles high low provider.
|
|
8
|
+
* @param candleSeriesModel
|
|
9
|
+
* @doc-tags viewport,scaling
|
|
10
|
+
*/
|
|
11
|
+
export const createCandleSeriesHighLowProvider = (candleSeriesModel) => {
|
|
12
|
+
return {
|
|
13
|
+
isHighLowActive: () => true,
|
|
14
|
+
calculateHighLow: (state) => {
|
|
15
|
+
const xStart = state ? state.xStart : candleSeriesModel.scale.xStart;
|
|
16
|
+
const xEnd = state ? state.xEnd : candleSeriesModel.scale.xEnd;
|
|
17
|
+
const { dataIdxStart, dataIdxEnd } = candleSeriesModel.calculateDataViewportIndexes(xStart, xEnd);
|
|
18
|
+
// +1 because dataIdxEnd candle should be included in the result
|
|
19
|
+
const visualCandles = candleSeriesModel.visualPoints.slice(dataIdxStart, dataIdxEnd + 1);
|
|
20
|
+
const highLowWithIndex = calculateCandlesHighLow(visualCandles);
|
|
21
|
+
// to calculate correct high low for percent scale
|
|
22
|
+
const baseLine = () => { var _a, _b; return (_b = (_a = candleSeriesModel.visualPoints[dataIdxStart]) === null || _a === void 0 ? void 0 : _a.close) !== null && _b !== void 0 ? _b : 1; };
|
|
23
|
+
return Object.assign(Object.assign({}, highLowWithIndex), { low: candleSeriesModel.view.toAxisUnits(highLowWithIndex.low, baseLine), high: candleSeriesModel.view.toAxisUnits(highLowWithIndex.high, baseLine) });
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Calculates the high and low values for given candles array.
|
|
29
|
+
* @param visualCandles
|
|
30
|
+
*/
|
|
31
|
+
export const calculateCandlesHighLow = (visualCandles) => {
|
|
32
|
+
const result = {
|
|
33
|
+
high: Number.MIN_SAFE_INTEGER,
|
|
34
|
+
low: Number.MAX_SAFE_INTEGER,
|
|
35
|
+
highIdx: 0,
|
|
36
|
+
lowIdx: 0,
|
|
37
|
+
};
|
|
38
|
+
for (let i = 0; i < visualCandles.length; i++) {
|
|
39
|
+
const candle = visualCandles[i];
|
|
40
|
+
if (candle.high > result.high) {
|
|
41
|
+
result.high = candle.high;
|
|
42
|
+
result.highIdx = i;
|
|
43
|
+
}
|
|
44
|
+
if (candle.low < result.low) {
|
|
45
|
+
result.low = candle.low;
|
|
46
|
+
result.lowIdx = i;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
@@ -34,13 +34,13 @@ export declare class CandleSeriesModel extends DataSeriesModel<Candle, VisualCan
|
|
|
34
34
|
get instrument(): ChartInstrument;
|
|
35
35
|
set instrument(instrument: ChartInstrument);
|
|
36
36
|
meanCandleWidth: Unit;
|
|
37
|
-
constructor(extentComponent: YExtentComponent, id: number, eventBus: EventBus,
|
|
37
|
+
constructor(extentComponent: YExtentComponent, id: number, eventBus: EventBus, scale: ScaleModel, instrument: ChartInstrument, candlesTransformersByChartType: Partial<Record<DataSeriesType, VisualCandleCalculator>>, candleWidthByChartType: Partial<Record<DataSeriesType, CandleWidthCalculator>>, colors?: CandleSeriesColors);
|
|
38
38
|
/**
|
|
39
39
|
* Recalculates data viewport indexes based on xStart and xEnd parameters or values from scaleModel.
|
|
40
40
|
* Calls superclass method for calculation, recalculates zipped high/low data points, and fires draw event.
|
|
41
41
|
*
|
|
42
|
-
* @param {number} [xStart=this.
|
|
43
|
-
* @param {number} [xEnd=this.
|
|
42
|
+
* @param {number} [xStart=this.scale.xStart] - Start index of visible data range.
|
|
43
|
+
* @param {number} [xEnd=this.scale.xEnd] - End index of visible data range.
|
|
44
44
|
* @returns {void}
|
|
45
45
|
*/
|
|
46
46
|
recalculateDataViewportIndexes(xStart?: number, xEnd?: number): void;
|
|
@@ -3,4 +3,248 @@
|
|
|
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 { Subject } from 'rxjs';
|
|
7
|
+
import { getDefaultConfig } from '../chart.config';
|
|
8
|
+
import { defaultCandleTransformer } from '../components/chart/candle-transformer.functions';
|
|
9
|
+
import { calculateCandleWidth } from '../components/chart/candle-width-calculator.functions';
|
|
10
|
+
import { lastOf } from '../utils/array.utils';
|
|
11
|
+
import { merge } from '../utils/merge.utils';
|
|
12
|
+
import { PriceIncrementsUtils } from '../utils/price-increments.utils';
|
|
13
|
+
import { calculateCandlesHighLow, createCandleSeriesHighLowProvider } from './candle-series-high-low.provider';
|
|
14
|
+
import { BASIC_CANDLE_WIDTH, nameDirection } from './candle.model';
|
|
15
|
+
import { DataSeriesModel } from './data-series.model';
|
|
16
|
+
import { getDefaultHighLowWithIndex } from './scale.model';
|
|
17
|
+
const DEFAULT_CANDLE_SERIES_CONFIG = getDefaultConfig().colors;
|
|
18
|
+
export class CandleSeriesModel extends DataSeriesModel {
|
|
19
|
+
get dataPoints() {
|
|
20
|
+
return super.dataPoints;
|
|
21
|
+
}
|
|
22
|
+
set dataPoints(points) {
|
|
23
|
+
super.dataPoints = points;
|
|
24
|
+
this.applyPriceMovement();
|
|
25
|
+
}
|
|
26
|
+
get instrument() {
|
|
27
|
+
return this._instrument;
|
|
28
|
+
}
|
|
29
|
+
set instrument(instrument) {
|
|
30
|
+
var _a;
|
|
31
|
+
this._instrument = instrument;
|
|
32
|
+
this.pricePrecisions = PriceIncrementsUtils.computePrecisions((_a = instrument.priceIncrements) !== null && _a !== void 0 ? _a : [0.01]);
|
|
33
|
+
}
|
|
34
|
+
constructor(extentComponent, id, eventBus, scale, instrument, candlesTransformersByChartType, candleWidthByChartType, colors = DEFAULT_CANDLE_SERIES_CONFIG) {
|
|
35
|
+
super(extentComponent, id);
|
|
36
|
+
this.eventBus = eventBus;
|
|
37
|
+
this.candlesTransformersByChartType = candlesTransformersByChartType;
|
|
38
|
+
this.candleWidthByChartType = candleWidthByChartType;
|
|
39
|
+
this.colors = colors;
|
|
40
|
+
// high low in absolute price values
|
|
41
|
+
this.zippedHighLow = getDefaultHighLowWithIndex();
|
|
42
|
+
this.lastPriceMovement = 'none';
|
|
43
|
+
this.lastVisualCandleChangedSubject = new Subject();
|
|
44
|
+
// start/end candle index in viewport
|
|
45
|
+
this.meanCandleWidth = BASIC_CANDLE_WIDTH;
|
|
46
|
+
this._instrument = instrument;
|
|
47
|
+
this.instrument = instrument;
|
|
48
|
+
this.highLowProvider = createCandleSeriesHighLowProvider(this);
|
|
49
|
+
this.scale = scale;
|
|
50
|
+
this.name = instrument.symbol;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Recalculates data viewport indexes based on xStart and xEnd parameters or values from scaleModel.
|
|
54
|
+
* Calls superclass method for calculation, recalculates zipped high/low data points, and fires draw event.
|
|
55
|
+
*
|
|
56
|
+
* @param {number} [xStart=this.scale.xStart] - Start index of visible data range.
|
|
57
|
+
* @param {number} [xEnd=this.scale.xEnd] - End index of visible data range.
|
|
58
|
+
* @returns {void}
|
|
59
|
+
*/
|
|
60
|
+
recalculateDataViewportIndexes(xStart = this.scale.xStart, xEnd = this.scale.xEnd) {
|
|
61
|
+
super.recalculateDataViewportIndexes(xStart, xEnd);
|
|
62
|
+
this.recalculateZippedHighLow();
|
|
63
|
+
this.eventBus.fireDraw();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Calculates the price movement of the last candle by comparing the open and close prices.
|
|
67
|
+
* Sets the lastPriceMovement property of the instance with the name of the direction of the price movement.
|
|
68
|
+
*
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*/
|
|
71
|
+
applyPriceMovement() {
|
|
72
|
+
const lastCandle = lastOf(this.dataPoints);
|
|
73
|
+
if (lastCandle) {
|
|
74
|
+
this.lastPriceMovement = nameDirection(lastCandle.open, lastCandle.close);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Should be called 1 time when candles are set / updated to chart.
|
|
79
|
+
*/
|
|
80
|
+
recalculateVisualPoints() {
|
|
81
|
+
super.recalculateVisualPoints();
|
|
82
|
+
this.recalculateMeanCandleWidth(this.visualPoints);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Used for optimization when we have to update only the last candle
|
|
86
|
+
* @doc-tags tricky
|
|
87
|
+
*/
|
|
88
|
+
// recalculateOnlyLastVisualCandle() {
|
|
89
|
+
// const prev = this.visualPointsFlat[this.visualPointsFlat.length - 2];
|
|
90
|
+
// const last = this.visualPointsFlat[this.visualPointsFlat.length - 1];
|
|
91
|
+
// if (last && prev) {
|
|
92
|
+
// const startX = this.visualPointsFlat[prev.idx ?? 0].startUnit;
|
|
93
|
+
// const updatedCandle = lastOf(this.toVisualCandles([prev, last], startX));
|
|
94
|
+
// if (updatedCandle) {
|
|
95
|
+
// this.visualCandleSource[this.visualCandleSource.length - 1] = updatedCandle;
|
|
96
|
+
// this.lastVisualCandleChangedSubject.next();
|
|
97
|
+
// this.eventBus.fire(EVENT_DRAW_LAST_CANDLE);
|
|
98
|
+
// }
|
|
99
|
+
// }
|
|
100
|
+
// }
|
|
101
|
+
/**
|
|
102
|
+
* Recalculates and returns the zipped high-low values for the visible data range.
|
|
103
|
+
* Uses the visualPoints, dataIdxStart, and dataIdxEnd properties of the instance to calculate high-low values.
|
|
104
|
+
*
|
|
105
|
+
* @returns {HighLowWithIndex} - An object containing the high-low values along with their corresponding indexes.
|
|
106
|
+
*/
|
|
107
|
+
recalculateZippedHighLow() {
|
|
108
|
+
return (this.zippedHighLow = calculateCandlesHighLow(this.visualPoints.slice(this.dataIdxStart, this.dataIdxEnd)));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Updates the current price and the last price movement.
|
|
112
|
+
* Compares the current price with the previous price, and sets the lastPriceMovement property accordingly.
|
|
113
|
+
*
|
|
114
|
+
* @param {number} currentPrice - The current price of the asset.
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
updateCurrentPrice(currentPrice) {
|
|
118
|
+
this.previousPrice = this.currentPrice || currentPrice;
|
|
119
|
+
this.currentPrice = currentPrice;
|
|
120
|
+
if (this.currentPrice !== this.previousPrice) {
|
|
121
|
+
this.lastPriceMovement = this.currentPrice > this.previousPrice ? 'up' : 'down';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Updates the colors used to render the candlestick series and recalculates the visual points.
|
|
126
|
+
* Merges the newConfig object with the existing colors object of the instance.
|
|
127
|
+
* Calls the recalculateVisualPoints method of the instance to update the visual points using the new color configuration.
|
|
128
|
+
*
|
|
129
|
+
* @param {PartialCandleSeriesColors} newConfig - The new color configuration to be merged with the existing colors object.
|
|
130
|
+
* @returns {void}
|
|
131
|
+
*/
|
|
132
|
+
updateCandleSeriesColors(newConfig) {
|
|
133
|
+
this.colors = merge(newConfig, this.colors);
|
|
134
|
+
this.recalculateVisualPoints();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns an observable that emits an event when the last visual candle changes.
|
|
138
|
+
* Returns the observable associated with the lastVisualCandleChangedSubject of the instance.
|
|
139
|
+
*
|
|
140
|
+
* @returns {Observable<void>} - An observable that emits an event when the last visual candle changes.
|
|
141
|
+
*/
|
|
142
|
+
observeLastVisualCandleChanged() {
|
|
143
|
+
return this.lastVisualCandleChangedSubject.asObservable();
|
|
144
|
+
}
|
|
145
|
+
doDeactivate() {
|
|
146
|
+
super.doDeactivate();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Transforms candles list into visual candles.
|
|
150
|
+
* NOTE: should be used only on FULL candles array, no single transformations, since candle coordinates depend on each other.
|
|
151
|
+
* OR provide startX :)
|
|
152
|
+
* @param candles
|
|
153
|
+
* @param startX
|
|
154
|
+
*/
|
|
155
|
+
toVisualPoints(candles, startX = 0) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
if (candles.length === 0) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const type = this.config.type;
|
|
161
|
+
const visualCandles = [];
|
|
162
|
+
let accumulatedWidth = startX;
|
|
163
|
+
const calculator = (_a = this.candleWidthByChartType[type]) !== null && _a !== void 0 ? _a : calculateCandleWidth;
|
|
164
|
+
for (let i = 0; i < candles.length; i++) {
|
|
165
|
+
const candle = candles[i];
|
|
166
|
+
const prevCandle = candles[i - 1];
|
|
167
|
+
const width = calculator(candle);
|
|
168
|
+
// x - middle of candle
|
|
169
|
+
const x = accumulatedWidth + width / 2;
|
|
170
|
+
const transformer = (_b = this.candlesTransformersByChartType[type]) !== null && _b !== void 0 ? _b : defaultCandleTransformer;
|
|
171
|
+
visualCandles.push(transformer(candle, { x, width, prevCandle, activeCandle: this.activeCandle }));
|
|
172
|
+
accumulatedWidth += width;
|
|
173
|
+
}
|
|
174
|
+
return visualCandles;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Recalculates the mean candle width using the given array of visual candles.
|
|
178
|
+
* Calculates the sum of widths of all visual candles and divides it by the total number of candles to get the mean candle width.
|
|
179
|
+
* Sets the meanCandleWidth property of the instance with the calculated value.
|
|
180
|
+
*
|
|
181
|
+
* @param {VisualCandle[]} visualCandles - An array of visual candles to be used for mean candle width calculation.
|
|
182
|
+
* @returns {void}
|
|
183
|
+
*/
|
|
184
|
+
recalculateMeanCandleWidth(visualCandles) {
|
|
185
|
+
if (visualCandles.length !== 0) {
|
|
186
|
+
this.meanCandleWidth = visualCandles.reduce((acc, cur) => acc + cur.width, 0) / visualCandles.length;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.meanCandleWidth = BASIC_CANDLE_WIDTH;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Sets the active candle for the chart and recalculates the visual points.
|
|
194
|
+
* Sets the activeCandle property of the instance with the provided candle parameter.
|
|
195
|
+
* Calls the recalculateVisualPoints method of the instance to recalculate the visual points using the new active candle.
|
|
196
|
+
*
|
|
197
|
+
* @param {Candle} candle - The candle to be set as active candle.
|
|
198
|
+
* @returns {void}
|
|
199
|
+
*/
|
|
200
|
+
setActiveCandle(candle) {
|
|
201
|
+
this.activeCandle = candle;
|
|
202
|
+
this.recalculateVisualPoints();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Clears all the data and visual elements from the chart.
|
|
206
|
+
* Sets the dataPoints property of the instance to an empty array.
|
|
207
|
+
* Calls the clearVisualCandles and clearPrices methods of the instance to clear the visual elements from the chart.
|
|
208
|
+
*
|
|
209
|
+
* @returns {void}
|
|
210
|
+
*/
|
|
211
|
+
clearData() {
|
|
212
|
+
this.dataPoints = [];
|
|
213
|
+
this.clearVisualCandles();
|
|
214
|
+
this.clearPrices();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Clears the price-related properties of the instance.
|
|
218
|
+
* Sets the previousPrice, currentPrice and lastPriceMovement properties of the instance to undefined, undefined, and 'none' respectively.
|
|
219
|
+
*
|
|
220
|
+
* @returns {void}
|
|
221
|
+
*/
|
|
222
|
+
clearPrices() {
|
|
223
|
+
this.previousPrice = undefined;
|
|
224
|
+
this.currentPrice = undefined;
|
|
225
|
+
this.lastPriceMovement = 'none';
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Clears the visualPoints property of the instance.
|
|
229
|
+
* Sets the visualPoints property of the instance to an empty array.
|
|
230
|
+
*
|
|
231
|
+
* @returns {void}
|
|
232
|
+
*/
|
|
233
|
+
clearVisualCandles() {
|
|
234
|
+
this.visualPoints = [];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Checks if the provided chart type is linked.
|
|
239
|
+
* @param {BarType} chartType - The type of chart to check.
|
|
240
|
+
* @returns {boolean} - Returns true if the chart type is linked, false otherwise.
|
|
241
|
+
*/
|
|
242
|
+
export function isLinked(chartType) {
|
|
243
|
+
switch (chartType) {
|
|
244
|
+
case 'line':
|
|
245
|
+
case 'area':
|
|
246
|
+
return true;
|
|
247
|
+
default:
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -3,4 +3,72 @@
|
|
|
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
|
-
|
|
6
|
+
// Has no specific rule, just any number to use in units calculation.
|
|
7
|
+
// 1 - because why not? Easy to debug.
|
|
8
|
+
export const BASIC_CANDLE_WIDTH = 1;
|
|
9
|
+
/**
|
|
10
|
+
* Provides the name of candle difference
|
|
11
|
+
* @param {Number} open
|
|
12
|
+
* @param {Number} close
|
|
13
|
+
* @returns {String}
|
|
14
|
+
*/
|
|
15
|
+
export function nameDirection(open, close) {
|
|
16
|
+
if (close === open) {
|
|
17
|
+
return 'none';
|
|
18
|
+
}
|
|
19
|
+
else if (close > open) {
|
|
20
|
+
return 'up';
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return 'down';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Provides the name of candle difference for hollow chart type
|
|
28
|
+
* @param {Number} open
|
|
29
|
+
* @param {Number} close
|
|
30
|
+
* @returns {String}
|
|
31
|
+
*/
|
|
32
|
+
export function hollowDirection(open, close) {
|
|
33
|
+
if (close > open) {
|
|
34
|
+
return 'up';
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return 'down';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new Candle object based on the provided base object, with the option to modify the prices.
|
|
42
|
+
* @param {Candle} base - The base object to copy.
|
|
43
|
+
* @param {number} idx - The index of the new Candle object.
|
|
44
|
+
* @param {boolean} pricesAsClose - If true, the high, low, and open prices will be set to the close price.
|
|
45
|
+
* @returns {Candle} A new Candle object with the same properties as the base object, with the option to modify the prices.
|
|
46
|
+
*/
|
|
47
|
+
export function copyCandle(base, idx, pricesAsClose = false) {
|
|
48
|
+
const { expansion, impVolatility, vwap, volume, timestamp } = base;
|
|
49
|
+
let hi = base.hi;
|
|
50
|
+
let lo = base.lo;
|
|
51
|
+
let open = base.open;
|
|
52
|
+
const close = base.close;
|
|
53
|
+
if (pricesAsClose) {
|
|
54
|
+
hi = close;
|
|
55
|
+
lo = close;
|
|
56
|
+
open = close;
|
|
57
|
+
}
|
|
58
|
+
let _idx = base.idx;
|
|
59
|
+
if (idx !== undefined) {
|
|
60
|
+
_idx = idx;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
hi,
|
|
64
|
+
lo,
|
|
65
|
+
open,
|
|
66
|
+
close,
|
|
67
|
+
timestamp,
|
|
68
|
+
volume,
|
|
69
|
+
expansion,
|
|
70
|
+
idx: _idx,
|
|
71
|
+
impVolatility,
|
|
72
|
+
vwap,
|
|
73
|
+
};
|
|
74
|
+
}
|