@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,164 @@
|
|
|
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 { getFontFromConfig } from '../../chart.config';
|
|
7
|
+
import { redrawBackgroundArea } from '../../drawers/chart-background.drawer';
|
|
8
|
+
import { drawPriceLabel, drawRoundedRect } from '../../utils/canvas/canvas-drawing-functions.utils';
|
|
9
|
+
import { calculateSymbolHeight, calculateTextWidth } from '../../utils/canvas/canvas-font-measure-tool.utils';
|
|
10
|
+
import { getLabelTextColorByBackgroundColor } from '../../utils/canvas/canvas-text-functions.utils';
|
|
11
|
+
import { round } from '../../utils/math.utils';
|
|
12
|
+
export const DEFAULT_PRICE_LABEL_PADDING = 4;
|
|
13
|
+
/**
|
|
14
|
+
* Draws badge label on Y axis with provided parameters.
|
|
15
|
+
* @param ctx - canvas 2D context to draw on
|
|
16
|
+
* @param bounds - bounds of Y axis
|
|
17
|
+
* @param text - text to draw
|
|
18
|
+
* @param centralY - y
|
|
19
|
+
* @param config - label styles config
|
|
20
|
+
* @param align
|
|
21
|
+
* @param yAxisState
|
|
22
|
+
*/
|
|
23
|
+
export function drawBadgeLabel(ctx, bounds, text, centralY, config, yAxisState, yAxisColors, drawOutside = false) {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
25
|
+
const align = yAxisState.align;
|
|
26
|
+
const textFont = (_a = config.textFont) !== null && _a !== void 0 ? _a : getFontFromConfig(yAxisState);
|
|
27
|
+
const bgColor = config.bgColor;
|
|
28
|
+
const textColor = (_b = config.textColor) !== null && _b !== void 0 ? _b : getLabelTextColorByBackgroundColor(bgColor, yAxisColors.labelTextColor, yAxisColors.labelInvertedTextColor);
|
|
29
|
+
const paddingTop = (_c = config.paddingTop) !== null && _c !== void 0 ? _c : DEFAULT_PRICE_LABEL_PADDING;
|
|
30
|
+
const paddingBottom = (_d = config.paddingBottom) !== null && _d !== void 0 ? _d : DEFAULT_PRICE_LABEL_PADDING;
|
|
31
|
+
const paddingEnd = (_e = config.paddingEnd) !== null && _e !== void 0 ? _e : DEFAULT_PRICE_LABEL_PADDING;
|
|
32
|
+
const halfFontHeight = round(calculateSymbolHeight(textFont, ctx) / 2);
|
|
33
|
+
const labelBoxTopY = centralY - halfFontHeight - paddingTop;
|
|
34
|
+
const labelBoxBottomY = centralY + halfFontHeight + paddingBottom;
|
|
35
|
+
const labelBoxHeight = labelBoxBottomY - labelBoxTopY;
|
|
36
|
+
// do not draw, if label is out of bounds
|
|
37
|
+
if ((centralY < bounds.y + labelBoxHeight / 2 || centralY > bounds.y + bounds.height - labelBoxHeight / 2) &&
|
|
38
|
+
!drawOutside) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
ctx.save();
|
|
42
|
+
ctx.fillStyle = bgColor;
|
|
43
|
+
ctx.strokeStyle = bgColor;
|
|
44
|
+
const labelForeWidth = round(bounds.width / 6);
|
|
45
|
+
const x1 = align === 'right' ? bounds.x : bounds.x + bounds.width;
|
|
46
|
+
const x2 = align === 'right' ? x1 + labelForeWidth : x1 - labelForeWidth;
|
|
47
|
+
const xTextOffset = yAxisState.labelBoxMargin.end;
|
|
48
|
+
const marginEnd = xTextOffset - paddingEnd;
|
|
49
|
+
// main body label width, without triangle
|
|
50
|
+
const width = bounds.width - labelForeWidth - marginEnd;
|
|
51
|
+
drawPriceLabel(ctx, x2, labelBoxTopY, x1, labelBoxTopY + round(labelBoxHeight / 2), x2, labelBoxTopY + labelBoxHeight, width, (_g = (_f = yAxisState.typeConfig.badge) === null || _f === void 0 ? void 0 : _f.rounded) !== null && _g !== void 0 ? _g : false, align);
|
|
52
|
+
ctx.fillStyle = textColor;
|
|
53
|
+
ctx.font = textFont;
|
|
54
|
+
const textX = align === 'right'
|
|
55
|
+
? bounds.x + bounds.width - calculateTextWidth(text, ctx, textFont) - xTextOffset
|
|
56
|
+
: bounds.x + xTextOffset;
|
|
57
|
+
ctx.fillText(text, textX, centralY + halfFontHeight - 1); // -1 for font height adjustment
|
|
58
|
+
ctx.restore();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Draws rectangle label on Y axis with provided parameters.
|
|
62
|
+
* @param ctx - canvas 2D context to draw on
|
|
63
|
+
* @param bounds - bounds of Y axis
|
|
64
|
+
* @param text - text to draw
|
|
65
|
+
* @param centralY - y
|
|
66
|
+
* @param config - label styles config
|
|
67
|
+
* @param align
|
|
68
|
+
* @param yAxisState
|
|
69
|
+
*/
|
|
70
|
+
export function drawRectLabel(ctx, bounds, text, centralY, config, yAxisState, yAxisColors, drawOutside = false) {
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
72
|
+
const align = yAxisState.align;
|
|
73
|
+
const textFont = (_a = config.textFont) !== null && _a !== void 0 ? _a : getFontFromConfig(yAxisState);
|
|
74
|
+
const bgColor = config.bgColor;
|
|
75
|
+
const textColor = (_b = config.textColor) !== null && _b !== void 0 ? _b : getLabelTextColorByBackgroundColor(bgColor, yAxisColors.labelTextColor, yAxisColors.labelInvertedTextColor);
|
|
76
|
+
const paddings = (_c = yAxisState.typeConfig.rectangle) === null || _c === void 0 ? void 0 : _c.paddings;
|
|
77
|
+
const paddingTop = (_e = (_d = config.paddingTop) !== null && _d !== void 0 ? _d : paddings === null || paddings === void 0 ? void 0 : paddings.top) !== null && _e !== void 0 ? _e : DEFAULT_PRICE_LABEL_PADDING;
|
|
78
|
+
const paddingBottom = (_g = (_f = config.paddingBottom) !== null && _f !== void 0 ? _f : paddings === null || paddings === void 0 ? void 0 : paddings.bottom) !== null && _g !== void 0 ? _g : DEFAULT_PRICE_LABEL_PADDING;
|
|
79
|
+
const paddingEnd = (_j = (_h = config.paddingEnd) !== null && _h !== void 0 ? _h : paddings === null || paddings === void 0 ? void 0 : paddings.end) !== null && _j !== void 0 ? _j : DEFAULT_PRICE_LABEL_PADDING;
|
|
80
|
+
const paddingStart = config.paddingStart;
|
|
81
|
+
const fontHeight = calculateSymbolHeight(textFont, ctx);
|
|
82
|
+
const labelBoxTopY = centralY - fontHeight / 2 - paddingTop;
|
|
83
|
+
const labelBoxBottomY = centralY + fontHeight / 2 + paddingBottom;
|
|
84
|
+
const labelBoxHeight = labelBoxBottomY - labelBoxTopY;
|
|
85
|
+
const rounded = (_k = config.rounded) !== null && _k !== void 0 ? _k : (_l = yAxisState.typeConfig.rectangle) === null || _l === void 0 ? void 0 : _l.rounded;
|
|
86
|
+
// do not draw, if label is out of bounds
|
|
87
|
+
if ((centralY < bounds.y + labelBoxHeight / 2 || centralY > bounds.y + bounds.height - labelBoxHeight / 2) &&
|
|
88
|
+
!drawOutside) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
ctx.save();
|
|
92
|
+
ctx.fillStyle = bgColor;
|
|
93
|
+
ctx.strokeStyle = bgColor;
|
|
94
|
+
const xTextOffset = yAxisState.labelBoxMargin.end;
|
|
95
|
+
ctx.font = textFont;
|
|
96
|
+
const textWidth = calculateTextWidth(text, ctx, textFont);
|
|
97
|
+
const marginEnd = xTextOffset - paddingEnd;
|
|
98
|
+
const width = paddingStart !== undefined ? textWidth + paddingStart + paddingEnd : bounds.width - marginEnd;
|
|
99
|
+
const x = align === 'right' ? bounds.x + bounds.width - marginEnd - width : bounds.x + marginEnd;
|
|
100
|
+
const textX = align === 'right' ? bounds.x + bounds.width - textWidth - xTextOffset : xTextOffset;
|
|
101
|
+
if (rounded) {
|
|
102
|
+
drawRoundedRect(ctx, x, labelBoxTopY, width, labelBoxHeight, 4, true);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
ctx.fillRect(x, labelBoxTopY, width, labelBoxHeight);
|
|
106
|
+
}
|
|
107
|
+
ctx.fillStyle = textColor;
|
|
108
|
+
ctx.fillText(text, textX, centralY + fontHeight / 2 - 1); // -1 for font height adjustment
|
|
109
|
+
ctx.restore();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Draws rectangle label on Y axis with provided parameters but with transparent background.
|
|
113
|
+
* @param ctx - canvas 2D context to draw on
|
|
114
|
+
* @param bounds - bounds of Y axis
|
|
115
|
+
* @param text - text to draw
|
|
116
|
+
* @param centralY - y
|
|
117
|
+
* @param config - label styles config
|
|
118
|
+
* @param align
|
|
119
|
+
* @param yAxisState
|
|
120
|
+
*/
|
|
121
|
+
export function drawPlainLabel(ctx, bounds, text, centralY, config, yAxisState, yAxisColors, drawOutside = false, backgroundCtx) {
|
|
122
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
123
|
+
const align = yAxisState.align;
|
|
124
|
+
const textFont = (_a = config.textFont) !== null && _a !== void 0 ? _a : getFontFromConfig(yAxisState);
|
|
125
|
+
const bgColor = config.bgColor;
|
|
126
|
+
const textColor = (_b = config.textColor) !== null && _b !== void 0 ? _b : getLabelTextColorByBackgroundColor(bgColor, yAxisColors.labelTextColor, yAxisColors.labelInvertedTextColor);
|
|
127
|
+
const paddings = (_c = yAxisState.typeConfig.rectangle) === null || _c === void 0 ? void 0 : _c.paddings;
|
|
128
|
+
const paddingTop = (_e = (_d = config.paddingTop) !== null && _d !== void 0 ? _d : paddings === null || paddings === void 0 ? void 0 : paddings.top) !== null && _e !== void 0 ? _e : DEFAULT_PRICE_LABEL_PADDING;
|
|
129
|
+
const paddingBottom = (_g = (_f = config.paddingBottom) !== null && _f !== void 0 ? _f : paddings === null || paddings === void 0 ? void 0 : paddings.bottom) !== null && _g !== void 0 ? _g : DEFAULT_PRICE_LABEL_PADDING;
|
|
130
|
+
const paddingEnd = (_j = (_h = config.paddingEnd) !== null && _h !== void 0 ? _h : paddings === null || paddings === void 0 ? void 0 : paddings.end) !== null && _j !== void 0 ? _j : DEFAULT_PRICE_LABEL_PADDING;
|
|
131
|
+
const paddingStart = config.paddingStart;
|
|
132
|
+
const fontHeight = calculateSymbolHeight(textFont, ctx);
|
|
133
|
+
const labelBoxTopY = centralY - fontHeight / 2 - paddingTop;
|
|
134
|
+
const labelBoxBottomY = centralY + fontHeight / 2 + paddingBottom;
|
|
135
|
+
const labelBoxHeight = labelBoxBottomY - labelBoxTopY;
|
|
136
|
+
// do not draw, if label is out of bounds
|
|
137
|
+
if ((centralY < bounds.y + labelBoxHeight / 2 || centralY > bounds.y + bounds.height - labelBoxHeight / 2) &&
|
|
138
|
+
!drawOutside) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
ctx.save();
|
|
142
|
+
ctx.fillStyle = bgColor;
|
|
143
|
+
ctx.strokeStyle = bgColor;
|
|
144
|
+
const xTextOffset = yAxisState.labelBoxMargin.end;
|
|
145
|
+
ctx.font = textFont;
|
|
146
|
+
const textWidth = calculateTextWidth(text, ctx, textFont);
|
|
147
|
+
const marginEnd = xTextOffset - paddingEnd;
|
|
148
|
+
const width = paddingStart !== undefined ? textWidth + paddingStart + paddingEnd : bounds.width - marginEnd;
|
|
149
|
+
const x = align === 'right' ? bounds.x + bounds.width - marginEnd - width : bounds.x + marginEnd;
|
|
150
|
+
const textX = align === 'right' ? bounds.x + bounds.width - textWidth - xTextOffset : xTextOffset;
|
|
151
|
+
backgroundCtx && redrawBackgroundArea(backgroundCtx, ctx, x, labelBoxTopY, width, labelBoxHeight);
|
|
152
|
+
ctx.fillStyle = textColor;
|
|
153
|
+
ctx.fillText(text, textX, centralY + fontHeight / 2 - 1); // -1 for font height adjustment
|
|
154
|
+
ctx.restore();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Offset from the center of label to the top/bottom.
|
|
158
|
+
*
|
|
159
|
+
* @param font Label font
|
|
160
|
+
* @param ctx Drawing context
|
|
161
|
+
* @param paddingTop - extra padding from top
|
|
162
|
+
*/
|
|
163
|
+
export function getLabelYOffset(font, ctx, paddingTop = DEFAULT_PRICE_LABEL_PADDING) {
|
|
164
|
+
const fontHeight = calculateSymbolHeight(font, ctx);
|
|
165
|
+
return fontHeight / 2 + paddingTop;
|
|
166
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Subject } from 'rxjs';
|
|
7
7
|
import { CanvasBoundsContainer, HitBoundsTest } from '../../canvas/canvas-bounds-container';
|
|
8
|
-
import {
|
|
8
|
+
import { YAxisConfig } from '../../chart.config';
|
|
9
9
|
import EventBus from '../../events/event-bus';
|
|
10
10
|
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
11
11
|
import { CanvasInputListenerComponent } from '../../inputlisteners/canvas-input-listener.component';
|
|
@@ -25,7 +25,7 @@ export declare class YAxisScaleHandler extends ChartBaseElement {
|
|
|
25
25
|
lastYEnd: Unit;
|
|
26
26
|
lastYHeight: Unit;
|
|
27
27
|
lastYPxHeight: Pixel;
|
|
28
|
-
constructor(bus: EventBus, config:
|
|
28
|
+
constructor(bus: EventBus, config: YAxisConfig, chartPanComponent: ChartPanComponent, viewportModel: ViewportModel, canvasInputListener: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, hitTest: HitBoundsTest, autoScaleCallback: (auto: boolean) => void);
|
|
29
29
|
private onYDragStart;
|
|
30
30
|
private onYDragTick;
|
|
31
31
|
private onYDragEnd;
|
|
@@ -3,4 +3,75 @@
|
|
|
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 { CanvasElement } from '../../canvas/canvas-bounds-container';
|
|
8
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
9
|
+
import { DragNDropYComponent } from '../dran-n-drop_helper/drag-n-drop-y.component';
|
|
10
|
+
// if you drag full Y height from top to bottom - you will have x3 zoom, and vice-versa
|
|
11
|
+
const FULL_Y_HEIGHT_ZOOM_FACTOR = 10;
|
|
12
|
+
/**
|
|
13
|
+
* Handles the mouse drag on Y axis - to zoom the viewport vertically.
|
|
14
|
+
* @doc-tags scaling,zoom,viewport
|
|
15
|
+
*/
|
|
16
|
+
export class YAxisScaleHandler extends ChartBaseElement {
|
|
17
|
+
constructor(bus, config, chartPanComponent, viewportModel, canvasInputListener, canvasBoundsContainer, hitTest, autoScaleCallback) {
|
|
18
|
+
super();
|
|
19
|
+
this.bus = bus;
|
|
20
|
+
this.viewportModel = viewportModel;
|
|
21
|
+
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
22
|
+
this.autoScaleCallback = autoScaleCallback;
|
|
23
|
+
this.yAxisDragEndSubject = new Subject();
|
|
24
|
+
this.lastYStart = 0;
|
|
25
|
+
this.lastYEnd = 0;
|
|
26
|
+
this.lastYHeight = 0;
|
|
27
|
+
this.lastYPxHeight = 0;
|
|
28
|
+
this.onYDragStart = () => {
|
|
29
|
+
this.lastYStart = this.viewportModel.yStart;
|
|
30
|
+
this.lastYEnd = this.viewportModel.yEnd;
|
|
31
|
+
this.lastYHeight = this.viewportModel.yEnd - this.viewportModel.yStart;
|
|
32
|
+
this.lastYPxHeight = this.canvasBoundsContainer.getBounds(CanvasElement.Y_AXIS).height;
|
|
33
|
+
};
|
|
34
|
+
this.onYDragTick = (dragInfo) => {
|
|
35
|
+
const { delta: absoluteYDelta } = dragInfo;
|
|
36
|
+
// 1/3..3
|
|
37
|
+
let zoomYMult;
|
|
38
|
+
if (absoluteYDelta < 0) {
|
|
39
|
+
// 1/3..1
|
|
40
|
+
zoomYMult = 1 / (1 + (-absoluteYDelta / this.lastYPxHeight) * (FULL_Y_HEIGHT_ZOOM_FACTOR - 1));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// 1..3
|
|
44
|
+
zoomYMult = 1 + (absoluteYDelta / this.lastYPxHeight) * (FULL_Y_HEIGHT_ZOOM_FACTOR - 1);
|
|
45
|
+
}
|
|
46
|
+
const newYHeight = this.lastYHeight * zoomYMult;
|
|
47
|
+
const delta = (newYHeight - this.lastYHeight) / 2;
|
|
48
|
+
const newYStart = this.lastYStart - delta;
|
|
49
|
+
const newYEnd = this.lastYEnd + delta;
|
|
50
|
+
this.autoScaleCallback(false);
|
|
51
|
+
this.viewportModel.setYScale(newYStart, newYEnd);
|
|
52
|
+
this.bus.fireDraw();
|
|
53
|
+
};
|
|
54
|
+
this.onYDragEnd = () => {
|
|
55
|
+
this.yAxisDragEndSubject.next();
|
|
56
|
+
};
|
|
57
|
+
// drag to Y-scale and double click to auto scale
|
|
58
|
+
if (config.customScale) {
|
|
59
|
+
const dragPredicate = () => config.type !== 'percent';
|
|
60
|
+
const dragNDropYComponent = new DragNDropYComponent(hitTest, {
|
|
61
|
+
onDragTick: callIfPredicateTrue(this.onYDragTick, dragPredicate),
|
|
62
|
+
onDragStart: callIfPredicateTrue(this.onYDragStart, dragPredicate),
|
|
63
|
+
onDragEnd: callIfPredicateTrue(this.onYDragEnd, dragPredicate),
|
|
64
|
+
}, canvasInputListener, chartPanComponent, {
|
|
65
|
+
disableChartPanning: false,
|
|
66
|
+
});
|
|
67
|
+
this.addChildEntity(dragNDropYComponent);
|
|
68
|
+
if (config.customScaleDblClick) {
|
|
69
|
+
canvasInputListener.observeDbClick(hitTest).subscribe(() => {
|
|
70
|
+
autoScaleCallback(true);
|
|
71
|
+
this.bus.fireDraw();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const callIfPredicateTrue = (fun, predicate) => (...args) => predicate() && fun(...args);
|
|
@@ -6,64 +6,68 @@
|
|
|
6
6
|
import { Subject } from 'rxjs';
|
|
7
7
|
import { CanvasBoundsContainer } from '../../canvas/canvas-bounds-container';
|
|
8
8
|
import { CursorHandler } from '../../canvas/cursor.handler';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { DrawingManager } from '../../drawers/drawing-manager';
|
|
9
|
+
import { YAxisWidthContributor } from '../../canvas/y-axis-bounds.container';
|
|
10
|
+
import { BarType, FullChartColors, FullChartConfig, YAxisAlign, YAxisConfig, YAxisLabelAppearanceType, YAxisLabelMode, YAxisLabelType } from '../../chart.config';
|
|
12
11
|
import EventBus from '../../events/event-bus';
|
|
13
12
|
import { CanvasInputListenerComponent } from '../../inputlisteners/canvas-input-listener.component';
|
|
14
13
|
import { PriceMovement } from '../../model/candle-series.model';
|
|
15
14
|
import { CanvasModel } from '../../model/canvas.model';
|
|
16
15
|
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
17
16
|
import { DataSeriesType } from '../../model/data-series.config';
|
|
17
|
+
import { DataSeriesModel } from '../../model/data-series.model';
|
|
18
18
|
import { ScaleModel } from '../../model/scale.model';
|
|
19
|
-
import { ChartModel } from '../chart/chart.model';
|
|
20
19
|
import { PriceAxisType } from '../labels_generator/numeric-axis-labels.generator';
|
|
21
20
|
import { ChartPanComponent } from '../pan/chart-pan.component';
|
|
22
|
-
import { PaneManager } from '../pane/pane-manager.component';
|
|
23
21
|
import { VisualYAxisLabel, YAxisLabelsProvider } from './price_labels/y-axis-labels.model';
|
|
24
22
|
import { YAxisScaleHandler } from './y-axis-scale.handler';
|
|
25
23
|
import { YAxisModel } from './y-axis.model';
|
|
26
|
-
import { YAxisWidthContributor } from '../../canvas/y-axis-bounds.container';
|
|
27
24
|
export type LabelColorResolver = (priceMovement: PriceMovement, colors: FullChartColors) => string;
|
|
28
25
|
/**
|
|
29
26
|
* Y axis component. Contains all Y axis related logic.
|
|
30
27
|
*/
|
|
31
28
|
export declare class YAxisComponent extends ChartBaseElement {
|
|
32
29
|
private eventBus;
|
|
33
|
-
private config;
|
|
34
30
|
private canvasModel;
|
|
35
|
-
|
|
36
|
-
private backgroundCanvasModel;
|
|
37
|
-
private chartModel;
|
|
38
|
-
private scaleModel;
|
|
31
|
+
scale: ScaleModel;
|
|
39
32
|
private canvasBoundsContainer;
|
|
40
|
-
private
|
|
33
|
+
private cursors;
|
|
34
|
+
paneUUID: string;
|
|
35
|
+
extentIdx: number;
|
|
36
|
+
private labelsColorByChartTypeMap;
|
|
41
37
|
yAxisScaleHandler: YAxisScaleHandler;
|
|
42
|
-
|
|
38
|
+
model: YAxisModel;
|
|
43
39
|
axisTypeSetSubject: Subject<PriceAxisType>;
|
|
44
|
-
readonly state:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
readonly state: YAxisConfig;
|
|
41
|
+
constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, chartPanComponent: ChartPanComponent, cursors: CursorHandler, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, paneUUID: string, extentIdx: number);
|
|
42
|
+
/**
|
|
43
|
+
* Registers default label color resolvers for different chart types.
|
|
44
|
+
* @private
|
|
45
|
+
* @function
|
|
46
|
+
* @name registerDefaultLabelColorResolver
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
private registerDefaultLabelColorResolvers;
|
|
50
|
+
protected doActivate(): void;
|
|
48
51
|
private updateCursor;
|
|
49
52
|
/**
|
|
50
53
|
* Updates labels visual appearance on canvas
|
|
51
54
|
*/
|
|
52
55
|
updateOrderedLabels(adjustYAxisWidth?: boolean): void;
|
|
53
56
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
57
|
+
* Registers a label color resolver for a specific chart type.
|
|
58
|
+
*
|
|
59
|
+
* @param {BarType} chartType - The type of chart for which the label color resolver is being registered.
|
|
60
|
+
* @param {LabelColorResolver} resolver - The function that will be used to resolve the color of the labels for the specified chart type.
|
|
56
61
|
* @returns {void}
|
|
57
62
|
*/
|
|
58
|
-
|
|
63
|
+
registerLabelColorResolver(chartType: BarType, resolver: LabelColorResolver): void;
|
|
59
64
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
* @function
|
|
63
|
-
*
|
|
64
|
-
* @returns {void}
|
|
65
|
+
* Returns a function that resolves the color for a label based on the type of data series.
|
|
66
|
+
* @param {DataSeriesType} candlesType - The type of data series.
|
|
67
|
+
* @returns {Function} - A function that resolves the color for a label.
|
|
68
|
+
* If there is no color mapping for the given data series type, it returns the default color resolver function.
|
|
65
69
|
*/
|
|
66
|
-
|
|
70
|
+
getLabelsColorResolver(candlesType: DataSeriesType): LabelColorResolver;
|
|
67
71
|
/**
|
|
68
72
|
* You can add a custom labels provider for additional labels on YAxis (like for drawings, symbol last price, studies, etc..)
|
|
69
73
|
* @param groupName - a group in which labels position recalculation algorithm will be applied, usually it's subchart name
|
|
@@ -82,6 +86,7 @@ export declare class YAxisComponent extends ChartBaseElement {
|
|
|
82
86
|
* @param name
|
|
83
87
|
*/
|
|
84
88
|
deleteSimpleYAxisLabel(name: string): void;
|
|
89
|
+
getAxisType(): PriceAxisType;
|
|
85
90
|
/**
|
|
86
91
|
* Unregister a Y axis labels provider from the specified group.
|
|
87
92
|
* @param {string} groupName - The name of the group from which to unregister the provider. Defaults to LabelsGroups.MAIN.
|
|
@@ -89,6 +94,7 @@ export declare class YAxisComponent extends ChartBaseElement {
|
|
|
89
94
|
* @returns {string} - The ID of the unregistered provider.
|
|
90
95
|
*/
|
|
91
96
|
unregisterYAxisLabelsProvider(groupName: string | undefined, id: string): string;
|
|
97
|
+
getBounds(): import("../../model/bounds.model").Bounds;
|
|
92
98
|
/**
|
|
93
99
|
* If custom pane has y-axis it has to register width contributor to correctly calculate overall y-axis width.
|
|
94
100
|
* @param contributor
|
|
@@ -140,19 +146,4 @@ export declare class YAxisComponent extends ChartBaseElement {
|
|
|
140
146
|
* @returns {void}
|
|
141
147
|
*/
|
|
142
148
|
changeLabelsDescriptionVisibility(descVisibility: boolean): void;
|
|
143
|
-
/**
|
|
144
|
-
* Registers a label color resolver for a specific chart type.
|
|
145
|
-
*
|
|
146
|
-
* @param {BarType} chartType - The type of chart for which the label color resolver is being registered.
|
|
147
|
-
* @param {LabelColorResolver} resolver - The function that will be used to resolve the color of the labels for the specified chart type.
|
|
148
|
-
* @returns {void}
|
|
149
|
-
*/
|
|
150
|
-
registerLabelColorResolver(chartType: BarType, resolver: LabelColorResolver): void;
|
|
151
|
-
/**
|
|
152
|
-
* Returns a function that resolves the color for a label based on the type of data series.
|
|
153
|
-
* @param {DataSeriesType} candlesType - The type of data series.
|
|
154
|
-
* @returns {Function} - A function that resolves the color for a label.
|
|
155
|
-
* If there is no color mapping for the given data series type, it returns the default color resolver function.
|
|
156
|
-
*/
|
|
157
|
-
getLabelsColorResolver(candlesType: DataSeriesType): LabelColorResolver;
|
|
158
149
|
}
|
|
@@ -3,4 +3,223 @@
|
|
|
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 { CanvasElement } from '../../canvas/canvas-bounds-container';
|
|
8
|
+
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
9
|
+
import { cloneUnsafe } from '../../utils/object.utils';
|
|
10
|
+
import { uuid } from '../../utils/uuid.utils';
|
|
11
|
+
import { resolveColorForArea, resolveColorForBar, resolveColorForBaseLine, resolveColorForCandle, resolveColorForHistogram, resolveColorForLine, resolveColorForScatterPlot, resolveColorForTrendAndHollow, resolveDefaultColorForLabel } from './label-color.functions';
|
|
12
|
+
import { LabelsGroups } from './price_labels/y-axis-labels.model';
|
|
13
|
+
import { YAxisScaleHandler } from './y-axis-scale.handler';
|
|
14
|
+
import { YAxisModel } from './y-axis.model';
|
|
15
|
+
/**
|
|
16
|
+
* Y axis component. Contains all Y axis related logic.
|
|
17
|
+
*/
|
|
18
|
+
export class YAxisComponent extends ChartBaseElement {
|
|
19
|
+
constructor(eventBus, config, canvasModel, scale, canvasInputListeners, canvasBoundsContainer, chartPanComponent, cursors, valueFormatter, dataSeriesProvider, paneUUID, extentIdx) {
|
|
20
|
+
super();
|
|
21
|
+
this.eventBus = eventBus;
|
|
22
|
+
this.canvasModel = canvasModel;
|
|
23
|
+
this.scale = scale;
|
|
24
|
+
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
25
|
+
this.cursors = cursors;
|
|
26
|
+
this.paneUUID = paneUUID;
|
|
27
|
+
this.extentIdx = extentIdx;
|
|
28
|
+
this.labelsColorByChartTypeMap = {};
|
|
29
|
+
this.axisTypeSetSubject = new Subject();
|
|
30
|
+
this.state = cloneUnsafe(config.components.yAxis);
|
|
31
|
+
//#region init yAxisScaleHandler
|
|
32
|
+
this.yAxisScaleHandler = new YAxisScaleHandler(eventBus, this.state, chartPanComponent, scale, canvasInputListeners, canvasBoundsContainer, canvasBoundsContainer.getBoundsHitTest(CanvasElement.PANE_UUID_Y_AXIS(paneUUID, extentIdx)), auto => scale.autoScale(auto));
|
|
33
|
+
this.addChildEntity(this.yAxisScaleHandler);
|
|
34
|
+
//#endregion
|
|
35
|
+
this.model = new YAxisModel(this.paneUUID, eventBus, this.state, canvasBoundsContainer, canvasModel, scale, valueFormatter, dataSeriesProvider, extentIdx);
|
|
36
|
+
this.addChildEntity(this.model);
|
|
37
|
+
this.updateCursor();
|
|
38
|
+
this.registerDefaultLabelColorResolvers();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Registers default label color resolvers for different chart types.
|
|
42
|
+
* @private
|
|
43
|
+
* @function
|
|
44
|
+
* @name registerDefaultLabelColorResolver
|
|
45
|
+
* @returns {void}
|
|
46
|
+
*/
|
|
47
|
+
registerDefaultLabelColorResolvers() {
|
|
48
|
+
this.registerLabelColorResolver('candle', resolveColorForCandle);
|
|
49
|
+
this.registerLabelColorResolver('bar', resolveColorForBar);
|
|
50
|
+
this.registerLabelColorResolver('line', resolveColorForLine);
|
|
51
|
+
this.registerLabelColorResolver('area', resolveColorForArea);
|
|
52
|
+
this.registerLabelColorResolver('scatterPlot', resolveColorForScatterPlot);
|
|
53
|
+
this.registerLabelColorResolver('histogram', resolveColorForHistogram);
|
|
54
|
+
this.registerLabelColorResolver('baseline', resolveColorForBaseLine);
|
|
55
|
+
this.registerLabelColorResolver('trend', resolveColorForTrendAndHollow);
|
|
56
|
+
this.registerLabelColorResolver('hollow', resolveColorForTrendAndHollow);
|
|
57
|
+
}
|
|
58
|
+
doActivate() {
|
|
59
|
+
this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(() => this.state.type === 'percent' && this.scale.haltAnimation()));
|
|
60
|
+
}
|
|
61
|
+
updateCursor() {
|
|
62
|
+
if (this.state.type === 'percent') {
|
|
63
|
+
this.cursors.setCursorForCanvasEl(CanvasElement.PANE_UUID_Y_AXIS(this.paneUUID, this.extentIdx), this.state.resizeDisabledCursor);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.cursors.setCursorForCanvasEl(CanvasElement.PANE_UUID_Y_AXIS(this.paneUUID, this.extentIdx), this.state.cursor);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Updates labels visual appearance on canvas
|
|
71
|
+
*/
|
|
72
|
+
updateOrderedLabels(adjustYAxisWidth = false) {
|
|
73
|
+
this.model.fancyLabelsModel.updateLabels(adjustYAxisWidth);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Registers a label color resolver for a specific chart type.
|
|
77
|
+
*
|
|
78
|
+
* @param {BarType} chartType - The type of chart for which the label color resolver is being registered.
|
|
79
|
+
* @param {LabelColorResolver} resolver - The function that will be used to resolve the color of the labels for the specified chart type.
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
registerLabelColorResolver(chartType, resolver) {
|
|
83
|
+
this.labelsColorByChartTypeMap[chartType] = resolver;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns a function that resolves the color for a label based on the type of data series.
|
|
87
|
+
* @param {DataSeriesType} candlesType - The type of data series.
|
|
88
|
+
* @returns {Function} - A function that resolves the color for a label.
|
|
89
|
+
* If there is no color mapping for the given data series type, it returns the default color resolver function.
|
|
90
|
+
*/
|
|
91
|
+
getLabelsColorResolver(candlesType) {
|
|
92
|
+
var _a;
|
|
93
|
+
return (_a = this.labelsColorByChartTypeMap[candlesType]) !== null && _a !== void 0 ? _a : resolveDefaultColorForLabel;
|
|
94
|
+
}
|
|
95
|
+
//#region public methods
|
|
96
|
+
/**
|
|
97
|
+
* You can add a custom labels provider for additional labels on YAxis (like for drawings, symbol last price, studies, etc..)
|
|
98
|
+
* @param groupName - a group in which labels position recalculation algorithm will be applied, usually it's subchart name
|
|
99
|
+
* @param provider
|
|
100
|
+
* @param id
|
|
101
|
+
*/
|
|
102
|
+
registerYAxisLabelsProvider(provider, groupName = LabelsGroups.MAIN, id = uuid()) {
|
|
103
|
+
this.model.fancyLabelsModel.registerYAxisLabelsProvider(groupName, provider, id);
|
|
104
|
+
return id;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* An easier way to manage custom y-axis labels, than y-axis labels providers.
|
|
108
|
+
* However, overlapping avoidance is not supported
|
|
109
|
+
* @param name
|
|
110
|
+
* @param label
|
|
111
|
+
*/
|
|
112
|
+
addSimpleYAxisLabel(name, label) {
|
|
113
|
+
this.model.fancyLabelsModel.customLabels[name] = label;
|
|
114
|
+
this.canvasModel.fireDraw();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @param name
|
|
118
|
+
*/
|
|
119
|
+
deleteSimpleYAxisLabel(name) {
|
|
120
|
+
delete this.model.fancyLabelsModel.customLabels[name];
|
|
121
|
+
this.canvasModel.fireDraw();
|
|
122
|
+
}
|
|
123
|
+
getAxisType() {
|
|
124
|
+
return this.state.type;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Unregister a Y axis labels provider from the specified group.
|
|
128
|
+
* @param {string} groupName - The name of the group from which to unregister the provider. Defaults to LabelsGroups.MAIN.
|
|
129
|
+
* @param {string} id - The ID of the provider to unregister.
|
|
130
|
+
* @returns {string} - The ID of the unregistered provider.
|
|
131
|
+
*/
|
|
132
|
+
unregisterYAxisLabelsProvider(groupName = LabelsGroups.MAIN, id) {
|
|
133
|
+
this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(groupName, id);
|
|
134
|
+
return id;
|
|
135
|
+
}
|
|
136
|
+
getBounds() {
|
|
137
|
+
return this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID_Y_AXIS(this.paneUUID, this.extentIdx));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* If custom pane has y-axis it has to register width contributor to correctly calculate overall y-axis width.
|
|
141
|
+
* @param contributor
|
|
142
|
+
*/
|
|
143
|
+
registerYAxisWidthContributor(contributor) {
|
|
144
|
+
this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(contributor);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Sets the type of axis: percent, regular or logarithmic.
|
|
148
|
+
* @param type - the type of axis
|
|
149
|
+
*/
|
|
150
|
+
setAxisType(type) {
|
|
151
|
+
if (type !== this.state.type) {
|
|
152
|
+
this.state.type = type;
|
|
153
|
+
this.axisTypeSetSubject.next(type);
|
|
154
|
+
this.scale.autoScale(true);
|
|
155
|
+
this.model.fancyLabelsModel.updateLabels(true);
|
|
156
|
+
this.updateCursor();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Change YAxis position to left or to right
|
|
161
|
+
* @param align
|
|
162
|
+
*/
|
|
163
|
+
setYAxisAlign(align) {
|
|
164
|
+
this.state.align = align;
|
|
165
|
+
this.canvasBoundsContainer.updateYAxisWidths();
|
|
166
|
+
this.eventBus.fireDraw();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Controls visibility of the y-axis
|
|
170
|
+
*/
|
|
171
|
+
setVisible(isVisible) {
|
|
172
|
+
this.state.visible = isVisible;
|
|
173
|
+
this.eventBus.fireDraw();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* If visible, when you can see the y-axis on the chart
|
|
177
|
+
*/
|
|
178
|
+
isVisible() {
|
|
179
|
+
return this.state.visible;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Controls lockPriceToBarRatio of the y-axis
|
|
183
|
+
*/
|
|
184
|
+
setLockPriceToBarRatio(value = false) {
|
|
185
|
+
this.scale.setLockPriceToBarRatio(value);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Changes the visual type of particular label.
|
|
189
|
+
* @param type - label type
|
|
190
|
+
* @param mode - visual mode
|
|
191
|
+
*/
|
|
192
|
+
changeLabelMode(type, mode) {
|
|
193
|
+
this.state.labels.settings[type].mode = mode;
|
|
194
|
+
this.model.fancyLabelsModel.updateLabels();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Changes the visual type of particular label.
|
|
198
|
+
* @param type - label type
|
|
199
|
+
* @param mode - visual mode
|
|
200
|
+
*/
|
|
201
|
+
changeLabelAppearance(type, mode) {
|
|
202
|
+
this.state.labels.settings[type].type = mode;
|
|
203
|
+
this.model.fancyLabelsModel.updateLabels();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Sets the inverse price scale mode. Inverts Y axis vertically.
|
|
207
|
+
* Inversion also works for candles, drawings and overlay studies.
|
|
208
|
+
* @param inverse - true or false
|
|
209
|
+
*/
|
|
210
|
+
togglePriceScaleInverse(inverse) {
|
|
211
|
+
this.scale.state.inverse = inverse;
|
|
212
|
+
this.scale.inverseY = inverse;
|
|
213
|
+
this.scale.scaleInversedSubject.next(inverse);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Changes the visibility of the labels' descriptions.
|
|
217
|
+
* @param {boolean} descVisibility - A boolean value indicating whether the descriptions should be visible or not.
|
|
218
|
+
* @returns {void}
|
|
219
|
+
*/
|
|
220
|
+
changeLabelsDescriptionVisibility(descVisibility) {
|
|
221
|
+
this.state.labels.descriptions = descVisibility;
|
|
222
|
+
// recalculating labels is not needed, so just redraw YAxis
|
|
223
|
+
this.canvasModel.fireDraw();
|
|
224
|
+
}
|
|
225
|
+
}
|