@devexperts/dxcharts-lite 2.4.1 → 2.4.2
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/dist/chart/bootstrap.js +3 -3
- package/dist/chart/chart.config.js +2 -2
- package/dist/chart/components/cross_tool/cross-tool.component.d.ts +1 -2
- package/dist/chart/components/cross_tool/cross-tool.component.js +3 -4
- package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.d.ts +1 -3
- package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.js +2 -3
- package/dist/chart/components/events/events.component.d.ts +1 -1
- package/dist/chart/components/events/events.component.js +2 -2
- package/dist/chart/components/events/events.drawer.d.ts +2 -3
- package/dist/chart/components/events/events.drawer.js +5 -5
- package/dist/chart/components/x_axis/x-axis-draw.functions.d.ts +1 -1
- package/dist/chart/components/x_axis/x-axis-draw.functions.js +9 -7
- package/dist/chart/components/x_axis/x-axis-labels.drawer.d.ts +1 -2
- package/dist/chart/components/x_axis/x-axis-labels.drawer.js +2 -3
- package/dist/chart/components/x_axis/x-axis.component.d.ts +1 -1
- package/dist/chart/components/x_axis/x-axis.component.js +2 -2
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.d.ts +1 -1
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.js +6 -5
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +2 -2
- package/dist/chart/components/y_axis/y-axis-labels.drawer.d.ts +1 -1
- package/dist/chart/components/y_axis/y-axis-labels.drawer.js +6 -4
- package/dist/chart/components/y_axis/y-axis-scale.handler.js +4 -2
- package/dist/chart/drawers/chart-background.drawer.js +2 -1
- package/dist/dxchart.min.js +4 -4
- package/package.json +1 -1
package/dist/chart/bootstrap.js
CHANGED
|
@@ -144,7 +144,7 @@ export default class ChartBootstrap {
|
|
|
144
144
|
this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries);
|
|
145
145
|
hitTestCanvasModel.addSubscriber(paneManager.hitTestController);
|
|
146
146
|
// X-axis component
|
|
147
|
-
this.xAxisComponent = new XAxisComponent(eventBus, config, mainCanvasModel, chartComponent, scaleModel, canvasBoundsContainer, canvasInputListener, chartResizeHandler, this.drawingManager, timeZoneModel, chartPanComponent, this.cursorHandler
|
|
147
|
+
this.xAxisComponent = new XAxisComponent(eventBus, config, mainCanvasModel, chartComponent, scaleModel, canvasBoundsContainer, canvasInputListener, chartResizeHandler, this.drawingManager, timeZoneModel, chartPanComponent, this.cursorHandler);
|
|
148
148
|
this.chartComponents.push(this.xAxisComponent);
|
|
149
149
|
this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);
|
|
150
150
|
const mainCanvasClearDrawer = new ClearCanvasDrawer(mainCanvasModel);
|
|
@@ -180,7 +180,7 @@ export default class ChartBootstrap {
|
|
|
180
180
|
this.chartComponents.push(mainChartGridComponent);
|
|
181
181
|
this.hoverProducer = new HoverProducerComponent(this.crossEventProducer, scaleModel, config, chartModel, canvasInputListener, this.canvasBoundsContainer, this.paneManager, timeZoneModel, formatterFactory);
|
|
182
182
|
this.chartComponents.push(this.hoverProducer);
|
|
183
|
-
this.crossToolComponent = new CrossToolComponent(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, this.crossEventProducer, this.hoverProducer
|
|
183
|
+
this.crossToolComponent = new CrossToolComponent(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, this.crossEventProducer, this.hoverProducer);
|
|
184
184
|
this.chartComponents.push(this.crossToolComponent);
|
|
185
185
|
// Snapshot component
|
|
186
186
|
const snapshotCanvasModel = createCanvasModel(eventBus, elements.snapshotCanvas, config, drawingManager, this.canvasModels, elements.chartResizer);
|
|
@@ -188,7 +188,7 @@ export default class ChartBootstrap {
|
|
|
188
188
|
this.snapshotComponent = snapshotComponent;
|
|
189
189
|
this.chartComponents.push(snapshotComponent);
|
|
190
190
|
// events
|
|
191
|
-
const eventsComponent = new EventsComponent(config, this.dynamicObjectsCanvasModel, hitTestCanvasModel, chartModel, canvasBoundsContainer, drawingManager, formatterFactory, this.cursorHandler
|
|
191
|
+
const eventsComponent = new EventsComponent(config, this.dynamicObjectsCanvasModel, hitTestCanvasModel, chartModel, canvasBoundsContainer, drawingManager, formatterFactory, this.cursorHandler);
|
|
192
192
|
this.eventsComponent = eventsComponent;
|
|
193
193
|
this.chartComponents.push(eventsComponent);
|
|
194
194
|
// Temporary solution - all in one place
|
|
@@ -459,7 +459,7 @@ export const getDefaultConfig = () => ({
|
|
|
459
459
|
},
|
|
460
460
|
],
|
|
461
461
|
yAxis: {
|
|
462
|
-
backgroundColor: '
|
|
462
|
+
backgroundColor: 'rgba(20,20,19,1)',
|
|
463
463
|
labelBoxColor: 'rgba(20,20,19,1)',
|
|
464
464
|
labelTextColor: 'rgba(128,128,128,1)',
|
|
465
465
|
labelInvertedTextColor: 'rgba(20,20,19,1)',
|
|
@@ -499,7 +499,7 @@ export const getDefaultConfig = () => ({
|
|
|
499
499
|
prevDayClose: { boxColor: 'rgba(107,96,86,1)', textColor: 'rgba(255,255,255,1)' },
|
|
500
500
|
},
|
|
501
501
|
xAxis: {
|
|
502
|
-
backgroundColor: '
|
|
502
|
+
backgroundColor: 'rgba(20,20,19,1)',
|
|
503
503
|
labelTextColor: 'rgba(128,128,128,1)',
|
|
504
504
|
},
|
|
505
505
|
navigationMap: {
|
|
@@ -23,10 +23,9 @@ export declare class CrossToolComponent extends ChartBaseElement {
|
|
|
23
23
|
private canvasBoundsContainer;
|
|
24
24
|
private drawingManager;
|
|
25
25
|
private paneManager;
|
|
26
|
-
private backgroundCanvasModel;
|
|
27
26
|
readonly model: CrossToolModel;
|
|
28
27
|
private readonly crossToolTypeDrawers;
|
|
29
|
-
constructor(config: FullChartConfig, crossToolCanvasModel: CanvasModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, paneManager: PaneManager, crossEventProducer: CrossEventProducerComponent, hoverProducer: HoverProducerComponent
|
|
28
|
+
constructor(config: FullChartConfig, crossToolCanvasModel: CanvasModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, paneManager: PaneManager, crossEventProducer: CrossEventProducerComponent, hoverProducer: HoverProducerComponent);
|
|
30
29
|
/**
|
|
31
30
|
* Registers default drawer types for the chart.
|
|
32
31
|
* @private
|
|
@@ -14,14 +14,13 @@ import { NoneDrawerType } from './types/none.drawer';
|
|
|
14
14
|
* Default bundled chart cross tool.
|
|
15
15
|
*/
|
|
16
16
|
export class CrossToolComponent extends ChartBaseElement {
|
|
17
|
-
constructor(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, crossEventProducer, hoverProducer
|
|
17
|
+
constructor(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, crossEventProducer, hoverProducer) {
|
|
18
18
|
super();
|
|
19
19
|
this.config = config;
|
|
20
20
|
this.crossToolCanvasModel = crossToolCanvasModel;
|
|
21
21
|
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
22
22
|
this.drawingManager = drawingManager;
|
|
23
23
|
this.paneManager = paneManager;
|
|
24
|
-
this.backgroundCanvasModel = backgroundCanvasModel;
|
|
25
24
|
this.crossToolTypeDrawers = {};
|
|
26
25
|
this.model = new CrossToolModel(config.components.crossTool, this.crossToolCanvasModel, crossEventProducer, hoverProducer);
|
|
27
26
|
this.addChildEntity(this.model);
|
|
@@ -42,8 +41,8 @@ export class CrossToolComponent extends ChartBaseElement {
|
|
|
42
41
|
* @returns {void}
|
|
43
42
|
*/
|
|
44
43
|
registerDefaultDrawerTypes() {
|
|
45
|
-
this.registerCrossToolTypeDrawer('cross-and-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager,
|
|
46
|
-
this.registerCrossToolTypeDrawer('just-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager,
|
|
44
|
+
this.registerCrossToolTypeDrawer('cross-and-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager, () => true));
|
|
45
|
+
this.registerCrossToolTypeDrawer('just-labels', new CrossAndLabelsDrawerType(this.config, this.canvasBoundsContainer, this.paneManager, () => true, true));
|
|
47
46
|
this.registerCrossToolTypeDrawer('none', new NoneDrawerType());
|
|
48
47
|
}
|
|
49
48
|
//#region public methods
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { CanvasBoundsContainer } from '../../../canvas/canvas-bounds-container';
|
|
7
7
|
import { FullChartConfig } from '../../../chart.config';
|
|
8
|
-
import { CanvasModel } from '../../../model/canvas.model';
|
|
9
8
|
import { PaneManager } from '../../pane/pane-manager.component';
|
|
10
9
|
import { CrossToolTypeDrawer } from '../cross-tool.drawer';
|
|
11
10
|
import { CrossToolHover } from '../cross-tool.model';
|
|
@@ -13,10 +12,9 @@ export declare class CrossAndLabelsDrawerType implements CrossToolTypeDrawer {
|
|
|
13
12
|
private config;
|
|
14
13
|
private canvasBoundsContainer;
|
|
15
14
|
private paneManager;
|
|
16
|
-
private backgroundCanvasModel;
|
|
17
15
|
private crossDrawPredicate;
|
|
18
16
|
private noLines?;
|
|
19
|
-
constructor(config: FullChartConfig, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager,
|
|
17
|
+
constructor(config: FullChartConfig, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager, crossDrawPredicate?: () => boolean, noLines?: boolean | undefined);
|
|
20
18
|
/**
|
|
21
19
|
* Draws a cross tool on a canvas context and its labels if the crossDrawPredicate is true.
|
|
22
20
|
* @param {CanvasRenderingContext2D} ctx - The canvas context to draw on.
|
|
@@ -7,11 +7,10 @@ import { CanvasElement } from '../../../canvas/canvas-bounds-container';
|
|
|
7
7
|
import { avoidAntialiasing, drawRoundedRect } from '../../../utils/canvas/canvas-drawing-functions.utils';
|
|
8
8
|
import { priceLabelDrawersMap } from '../../y_axis/price_labels/price-label.drawer';
|
|
9
9
|
export class CrossAndLabelsDrawerType {
|
|
10
|
-
constructor(config, canvasBoundsContainer, paneManager,
|
|
10
|
+
constructor(config, canvasBoundsContainer, paneManager, crossDrawPredicate = () => true, noLines) {
|
|
11
11
|
this.config = config;
|
|
12
12
|
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
13
13
|
this.paneManager = paneManager;
|
|
14
|
-
this.backgroundCanvasModel = backgroundCanvasModel;
|
|
15
14
|
this.crossDrawPredicate = crossDrawPredicate;
|
|
16
15
|
this.noLines = noLines;
|
|
17
16
|
}
|
|
@@ -138,7 +137,7 @@ export class CrossAndLabelsDrawerType {
|
|
|
138
137
|
paddingBottom: yLabelPadding === null || yLabelPadding === void 0 ? void 0 : yLabelPadding.bottom,
|
|
139
138
|
paddingEnd: yLabelPadding === null || yLabelPadding === void 0 ? void 0 : yLabelPadding.end,
|
|
140
139
|
paddingTop: yLabelPadding === null || yLabelPadding === void 0 ? void 0 : yLabelPadding.top,
|
|
141
|
-
}, extent.yAxis.state, this.config.colors.yAxis, true
|
|
140
|
+
}, extent.yAxis.state, this.config.colors.yAxis, true);
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
143
|
}
|
|
@@ -22,7 +22,7 @@ export declare class EventsComponent extends ChartBaseElement {
|
|
|
22
22
|
private formatterFactory;
|
|
23
23
|
eventsModel: EventsModel;
|
|
24
24
|
private eventsXAxisLabelFormatterProvider;
|
|
25
|
-
constructor(config: FullChartConfig, canvasModel: CanvasModel, hitTestCanvasModel: HitTestCanvasModel, chartModel: ChartModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, formatterFactory: DateTimeFormatterFactory, cursorHandler: CursorHandler
|
|
25
|
+
constructor(config: FullChartConfig, canvasModel: CanvasModel, hitTestCanvasModel: HitTestCanvasModel, chartModel: ChartModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, formatterFactory: DateTimeFormatterFactory, cursorHandler: CursorHandler);
|
|
26
26
|
/**
|
|
27
27
|
* Sets the new event list.
|
|
28
28
|
* @param events
|
|
@@ -11,7 +11,7 @@ import { EventsHitTestDrawer } from './events-hit-test.drawer';
|
|
|
11
11
|
import { EventsDrawer } from './events.drawer';
|
|
12
12
|
import { EventsModel } from './events.model';
|
|
13
13
|
export class EventsComponent extends ChartBaseElement {
|
|
14
|
-
constructor(config, canvasModel, hitTestCanvasModel, chartModel, canvasBoundsContainer, drawingManager, formatterFactory, cursorHandler
|
|
14
|
+
constructor(config, canvasModel, hitTestCanvasModel, chartModel, canvasBoundsContainer, drawingManager, formatterFactory, cursorHandler) {
|
|
15
15
|
super();
|
|
16
16
|
this.config = config;
|
|
17
17
|
this.canvasModel = canvasModel;
|
|
@@ -23,7 +23,7 @@ export class EventsComponent extends ChartBaseElement {
|
|
|
23
23
|
this.eventsModel = eventsModel;
|
|
24
24
|
this.addChildEntity(eventsModel);
|
|
25
25
|
hitTestCanvasModel.addSubscriber(eventsModel);
|
|
26
|
-
const eventsDrawer = new EventsDrawer(
|
|
26
|
+
const eventsDrawer = new EventsDrawer(canvasModel, chartModel, config, canvasBoundsContainer, eventsModel, this.eventsXAxisLabelFormatterProvider);
|
|
27
27
|
this.drawingManager.addDrawer(eventsDrawer, 'EVENTS');
|
|
28
28
|
const eventsHitTestDrawer = new EventsHitTestDrawer(hitTestCanvasModel, chartModel, config, canvasBoundsContainer, eventsModel);
|
|
29
29
|
this.drawingManager.addDrawerBefore(eventsHitTestDrawer, 'HIT_TEST_EVENTS', 'HIT_TEST_DRAWINGS');
|
|
@@ -12,7 +12,6 @@ import { DateTimeFormatter } from '../../model/date-time.formatter';
|
|
|
12
12
|
import { ChartModel } from '../chart/chart.model';
|
|
13
13
|
import { EconomicEvent, EventsModel, EventType, EventWithId } from './events.model';
|
|
14
14
|
export declare class EventsDrawer implements Drawer {
|
|
15
|
-
private backgroundCanvas;
|
|
16
15
|
private canvasModel;
|
|
17
16
|
private chartModel;
|
|
18
17
|
private config;
|
|
@@ -20,7 +19,7 @@ export declare class EventsDrawer implements Drawer {
|
|
|
20
19
|
private model;
|
|
21
20
|
private formatterProvider;
|
|
22
21
|
private customIcons;
|
|
23
|
-
constructor(
|
|
22
|
+
constructor(canvasModel: CanvasModel, chartModel: ChartModel, config: FullChartConfig, canvasBoundsContainer: CanvasBoundsContainer, model: EventsModel, formatterProvider: () => DateTimeFormatter);
|
|
24
23
|
/**
|
|
25
24
|
* Creates a custom icon for a given event type.
|
|
26
25
|
* @param {EventType} type - The type of the event.
|
|
@@ -67,7 +66,7 @@ export declare class EventsDrawer implements Drawer {
|
|
|
67
66
|
/**
|
|
68
67
|
* This function is responsible for drawing a label on the canvas at a given x coordinate. The label contains a formatted timestamp of a given event. The function takes two parameters: x, which is the x coordinate where the label will be drawn, and event, which is an object containing information about the event, including its timestamp and type.
|
|
69
68
|
* The function first gets the canvas context and the bounds of the x-axis. It then retrieves the font family, font height, and top padding from the configuration object. The y coordinate of the label is calculated based on the font height, top padding, and the y coordinate of the x-axis bounds. The font is set using the retrieved font family and font height.
|
|
70
|
-
* The timestamp of the event is formatted using a formatter provider function. The width of the label is calculated using the canvas context's measureText() method. The function then
|
|
69
|
+
* The timestamp of the event is formatted using a formatter provider function. The width of the label is calculated using the canvas context's measureText() method. The function then draws rectangle with xAxis background, to be on to hide the regular x-axis label that may overlap with the event label.
|
|
71
70
|
* Finally, the function sets the fill style of the canvas context to the color associated with the event type in the configuration object. The label text is then drawn on the canvas context at the calculated x and y coordinates.
|
|
72
71
|
*/
|
|
73
72
|
drawLabel(x: number, event: EventWithId): void;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import { CanvasElement } from '../../canvas/canvas-bounds-container';
|
|
7
|
-
import { redrawBackgroundArea } from '../../drawers/chart-background.drawer';
|
|
8
7
|
const eventsSizesDict = {
|
|
9
8
|
'rhombus-small': 4,
|
|
10
9
|
rhombus: 6,
|
|
@@ -12,8 +11,7 @@ const eventsSizesDict = {
|
|
|
12
11
|
};
|
|
13
12
|
const getIconHash = (type, state) => `${type}_${state}`;
|
|
14
13
|
export class EventsDrawer {
|
|
15
|
-
constructor(
|
|
16
|
-
this.backgroundCanvas = backgroundCanvas;
|
|
14
|
+
constructor(canvasModel, chartModel, config, canvasBoundsContainer, model, formatterProvider) {
|
|
17
15
|
this.canvasModel = canvasModel;
|
|
18
16
|
this.chartModel = chartModel;
|
|
19
17
|
this.config = config;
|
|
@@ -161,7 +159,7 @@ export class EventsDrawer {
|
|
|
161
159
|
/**
|
|
162
160
|
* This function is responsible for drawing a label on the canvas at a given x coordinate. The label contains a formatted timestamp of a given event. The function takes two parameters: x, which is the x coordinate where the label will be drawn, and event, which is an object containing information about the event, including its timestamp and type.
|
|
163
161
|
* The function first gets the canvas context and the bounds of the x-axis. It then retrieves the font family, font height, and top padding from the configuration object. The y coordinate of the label is calculated based on the font height, top padding, and the y coordinate of the x-axis bounds. The font is set using the retrieved font family and font height.
|
|
164
|
-
* The timestamp of the event is formatted using a formatter provider function. The width of the label is calculated using the canvas context's measureText() method. The function then
|
|
162
|
+
* The timestamp of the event is formatted using a formatter provider function. The width of the label is calculated using the canvas context's measureText() method. The function then draws rectangle with xAxis background, to be on to hide the regular x-axis label that may overlap with the event label.
|
|
165
163
|
* Finally, the function sets the fill style of the canvas context to the color associated with the event type in the configuration object. The label text is then drawn on the canvas context at the calculated x and y coordinates.
|
|
166
164
|
*/
|
|
167
165
|
drawLabel(x, event) {
|
|
@@ -176,7 +174,9 @@ export class EventsDrawer {
|
|
|
176
174
|
const labelText = this.formatterProvider()(event.timestamp);
|
|
177
175
|
const width = ctx.measureText(labelText).width;
|
|
178
176
|
// label can overlap with regular x-axis label, so we need to hide regular x-axis label
|
|
179
|
-
|
|
177
|
+
ctx.fillStyle = this.config.colors.xAxis.backgroundColor;
|
|
178
|
+
ctx.strokeStyle = this.config.colors.xAxis.backgroundColor;
|
|
179
|
+
ctx.fillRect(x - width / 2, xAxisBounds.y + 1, width, xAxisBounds.height - 1);
|
|
180
180
|
ctx.fillStyle = this.config.colors.events[event.type].color;
|
|
181
181
|
ctx.fillText(labelText, x - width / 2, y);
|
|
182
182
|
}
|
|
@@ -14,4 +14,4 @@ export type LabelAlign = 'start' | 'end' | 'middle';
|
|
|
14
14
|
* @param config
|
|
15
15
|
* @param label
|
|
16
16
|
*/
|
|
17
|
-
export declare function drawXAxisLabel(
|
|
17
|
+
export declare function drawXAxisLabel(ctx: CanvasRenderingContext2D, canvasBoundsContainer: CanvasBoundsContainer, config: FullChartConfig, label: XAxisLabel): void;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import { CanvasElement } from '../../canvas/canvas-bounds-container';
|
|
7
|
-
import { redrawBackgroundArea } from '../../drawers/chart-background.drawer';
|
|
8
7
|
const DEFAULT_X_LABEL_PADDING = { x: 4, y: 4 };
|
|
9
8
|
/**
|
|
10
9
|
* Draws the label on X axis.
|
|
@@ -13,12 +12,13 @@ const DEFAULT_X_LABEL_PADDING = { x: 4, y: 4 };
|
|
|
13
12
|
* @param config
|
|
14
13
|
* @param label
|
|
15
14
|
*/
|
|
16
|
-
export function drawXAxisLabel(
|
|
15
|
+
export function drawXAxisLabel(ctx, canvasBoundsContainer, config, label) {
|
|
17
16
|
var _a, _b;
|
|
18
17
|
const alignType = (_a = label.alignType) !== null && _a !== void 0 ? _a : 'middle';
|
|
19
18
|
const { fontSize, fontFamily, padding } = config.components.xAxis;
|
|
19
|
+
const xAxisColors = config.colors.xAxis;
|
|
20
20
|
const offsetTop = (_b = padding.top) !== null && _b !== void 0 ? _b : 0;
|
|
21
|
-
const
|
|
21
|
+
const xAxisBounds = canvasBoundsContainer.getBounds(CanvasElement.X_AXIS);
|
|
22
22
|
ctx.save();
|
|
23
23
|
ctx.font = `bold ${fontSize}px ${fontFamily}`;
|
|
24
24
|
const labelWidth = ctx.measureText(label.text).width;
|
|
@@ -38,17 +38,19 @@ export function drawXAxisLabel(backgroundCtx, ctx, canvasBoundsContainer, config
|
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
40
|
// label can overlap with regular x-axis label, so we need to hide regular x-axis label
|
|
41
|
-
|
|
41
|
+
ctx.fillStyle = xAxisColors.backgroundColor;
|
|
42
|
+
ctx.strokeStyle = xAxisColors.backgroundColor;
|
|
43
|
+
ctx.fillRect(boxStart, xAxisBounds.y, boxWidth, xAxisBounds.height);
|
|
42
44
|
if (alignType !== 'middle') {
|
|
43
45
|
ctx.strokeStyle = label.color;
|
|
44
46
|
ctx.beginPath();
|
|
45
|
-
ctx.moveTo(x,
|
|
46
|
-
ctx.lineTo(x,
|
|
47
|
+
ctx.moveTo(x, xAxisBounds.y);
|
|
48
|
+
ctx.lineTo(x, xAxisBounds.y + xAxisBounds.height);
|
|
47
49
|
ctx.stroke();
|
|
48
50
|
}
|
|
49
51
|
ctx.fillStyle = label.color;
|
|
50
52
|
const xTextPos = boxStart + DEFAULT_X_LABEL_PADDING.x;
|
|
51
|
-
const yTextPos =
|
|
53
|
+
const yTextPos = xAxisBounds.y + offsetTop + fontSize; // -2 for vertical adjustment
|
|
52
54
|
ctx.fillText(label.text, xTextPos, yTextPos);
|
|
53
55
|
ctx.restore();
|
|
54
56
|
}
|
|
@@ -13,12 +13,11 @@ import { FullChartConfig } from '../../chart.config';
|
|
|
13
13
|
* By default labels for drawings are drawn by this drawer.
|
|
14
14
|
*/
|
|
15
15
|
export declare class XAxisLabelsDrawer implements Drawer {
|
|
16
|
-
private backgroundCanvasModel;
|
|
17
16
|
private config;
|
|
18
17
|
private canvasModel;
|
|
19
18
|
private canvasBoundsContainer;
|
|
20
19
|
private xAxisLabelsModel;
|
|
21
|
-
constructor(
|
|
20
|
+
constructor(config: FullChartConfig, canvasModel: CanvasModel, canvasBoundsContainer: CanvasBoundsContainer, xAxisLabelsModel: XAxisLabelsModel);
|
|
22
21
|
/**
|
|
23
22
|
* Draws the X axis labels on the canvas.
|
|
24
23
|
* @function
|
|
@@ -12,8 +12,7 @@ import { fillRect } from '../../utils/canvas/canvas-drawing-functions.utils';
|
|
|
12
12
|
* By default labels for drawings are drawn by this drawer.
|
|
13
13
|
*/
|
|
14
14
|
export class XAxisLabelsDrawer {
|
|
15
|
-
constructor(
|
|
16
|
-
this.backgroundCanvasModel = backgroundCanvasModel;
|
|
15
|
+
constructor(config, canvasModel, canvasBoundsContainer, xAxisLabelsModel) {
|
|
17
16
|
this.config = config;
|
|
18
17
|
this.canvasModel = canvasModel;
|
|
19
18
|
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
@@ -30,7 +29,7 @@ export class XAxisLabelsDrawer {
|
|
|
30
29
|
const ctx = this.canvasModel.ctx;
|
|
31
30
|
this.drawHighlightedBackgroundBetweenLabels();
|
|
32
31
|
this.xAxisLabelsModel.labels.forEach(l => {
|
|
33
|
-
drawXAxisLabel(
|
|
32
|
+
drawXAxisLabel(ctx, this.canvasBoundsContainer, this.config, l);
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
// this is a very simple solution which matches 2 labels with same "subGroupId"
|
|
@@ -38,7 +38,7 @@ export declare class XAxisComponent extends ChartBaseElement {
|
|
|
38
38
|
xAxisLabelsGenerator: XAxisLabelsGenerator;
|
|
39
39
|
readonly xAxisLabelsModel: XAxisLabelsModel;
|
|
40
40
|
xAxisScaleHandler: XAxisScaleHandler;
|
|
41
|
-
constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, chartComponent: ChartComponent, scale: ScaleModel, canvasBoundsContainer: CanvasBoundsContainer, canvasInputListener: CanvasInputListenerComponent, chartResizeHandler: ChartResizeHandler, drawingManager: DrawingManager, timeZoneModel: TimeZoneModel, chartPanComponent: ChartPanComponent, cursorHandler: CursorHandler
|
|
41
|
+
constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, chartComponent: ChartComponent, scale: ScaleModel, canvasBoundsContainer: CanvasBoundsContainer, canvasInputListener: CanvasInputListenerComponent, chartResizeHandler: ChartResizeHandler, drawingManager: DrawingManager, timeZoneModel: TimeZoneModel, chartPanComponent: ChartPanComponent, cursorHandler: CursorHandler);
|
|
42
42
|
/**
|
|
43
43
|
* This method is used to activate the chart and update the labels if there is a new data set or equivolume type.
|
|
44
44
|
* It subscribes to the chart type change, candles set subject, candles updated subject, and time zone change to generate new labels.
|
|
@@ -20,7 +20,7 @@ import { availableBarTypes } from '../../chart.config';
|
|
|
20
20
|
* X-axis component, contains all x-axis calculation and rendering logic.
|
|
21
21
|
*/
|
|
22
22
|
export class XAxisComponent extends ChartBaseElement {
|
|
23
|
-
constructor(eventBus, config, canvasModel, chartComponent, scale, canvasBoundsContainer, canvasInputListener, chartResizeHandler, drawingManager, timeZoneModel, chartPanComponent, cursorHandler
|
|
23
|
+
constructor(eventBus, config, canvasModel, chartComponent, scale, canvasBoundsContainer, canvasInputListener, chartResizeHandler, drawingManager, timeZoneModel, chartPanComponent, cursorHandler) {
|
|
24
24
|
super();
|
|
25
25
|
this.eventBus = eventBus;
|
|
26
26
|
this.config = config;
|
|
@@ -36,7 +36,7 @@ export class XAxisComponent extends ChartBaseElement {
|
|
|
36
36
|
drawingManager.addDrawer(xAxisCompositeDrawer, 'X_AXIS');
|
|
37
37
|
this.xAxisDrawer = new XAxisTimeLabelsDrawer(config, canvasModel, scale, canvasBoundsContainer, () => this.xAxisLabelsGenerator.labels, () => config.components.xAxis.visible);
|
|
38
38
|
xAxisCompositeDrawer.addDrawer(this.xAxisDrawer);
|
|
39
|
-
this.xAxisLabelsDrawer = new XAxisLabelsDrawer(
|
|
39
|
+
this.xAxisLabelsDrawer = new XAxisLabelsDrawer(config, canvasModel, canvasBoundsContainer, this.xAxisLabelsModel);
|
|
40
40
|
xAxisCompositeDrawer.addDrawer(this.xAxisLabelsDrawer);
|
|
41
41
|
this.xAxisScaleHandler = new XAxisScaleHandler(scale, canvasInputListener, canvasBoundsContainer, chartPanComponent, this.chartComponent.chartModel);
|
|
42
42
|
this.addChildEntity(this.xAxisScaleHandler);
|
|
@@ -19,5 +19,5 @@ export declare const priceLabelDrawersMap: Record<YAxisVisualLabelType, LabelDra
|
|
|
19
19
|
* @param canvasBoundsContainer
|
|
20
20
|
* @param config
|
|
21
21
|
*/
|
|
22
|
-
export declare function drawLabel(ctx: CanvasRenderingContext2D, backgroundCtx: CanvasRenderingContext2D, bounds: Bounds, paneBounds: Bounds, visualLabel: VisualYAxisLabel, canvasBoundsContainer: CanvasBoundsContainer, config: YAxisConfig, colors: FullChartColors
|
|
22
|
+
export declare function drawLabel(ctx: CanvasRenderingContext2D, backgroundCtx: CanvasRenderingContext2D, bounds: Bounds, paneBounds: Bounds, visualLabel: VisualYAxisLabel, canvasBoundsContainer: CanvasBoundsContainer, config: YAxisConfig, colors: FullChartColors): void;
|
|
23
23
|
export {};
|
|
@@ -48,7 +48,7 @@ export function drawLabel(ctx, backgroundCtx, bounds, paneBounds, visualLabel, c
|
|
|
48
48
|
const drawLabel = priceLabelDrawersMap[appearanceType];
|
|
49
49
|
const showDescription = config.labels.descriptions;
|
|
50
50
|
const showLine = isLineVisible(bounds, labelY, labelBoxHeight);
|
|
51
|
-
const _drawDescription = () => showDescription && drawDescription(backgroundCtx, ctx, bounds, paneBounds, visualLabel, config
|
|
51
|
+
const _drawDescription = () => showDescription && drawDescription(backgroundCtx, ctx, bounds, paneBounds, visualLabel, config);
|
|
52
52
|
let lineXStart;
|
|
53
53
|
let lineXEnd;
|
|
54
54
|
// line should touch the label
|
|
@@ -65,7 +65,7 @@ export function drawLabel(ctx, backgroundCtx, bounds, paneBounds, visualLabel, c
|
|
|
65
65
|
}
|
|
66
66
|
const lineY = (_e = visualLabel.lineY) !== null && _e !== void 0 ? _e : visualLabel.y;
|
|
67
67
|
const _drawLine = () => showLine && avoidAntialiasing(ctx, () => drawLine(ctx, lineXStart, lineY, lineXEnd, lineY, 1));
|
|
68
|
-
const _drawLabel = () => drawLabel(ctx, bounds, text, centralY, visualLabel, config, colors, false
|
|
68
|
+
const _drawLabel = () => drawLabel(ctx, bounds, text, centralY, visualLabel, config, colors.yAxis, false);
|
|
69
69
|
const drawLineLabel = () => {
|
|
70
70
|
_drawLine();
|
|
71
71
|
_drawDescription();
|
|
@@ -80,9 +80,9 @@ export function drawLabel(ctx, backgroundCtx, bounds, paneBounds, visualLabel, c
|
|
|
80
80
|
_drawLabel();
|
|
81
81
|
};
|
|
82
82
|
const labelDrawerByMode = {
|
|
83
|
-
|
|
83
|
+
line: drawLineLabel,
|
|
84
84
|
'line-label': drawLineLabelLabel,
|
|
85
|
-
|
|
85
|
+
label: drawLabelLabel,
|
|
86
86
|
};
|
|
87
87
|
if (mode !== 'none' && checkLabelInBoundaries(centralY, bounds, labelBoxHeight)) {
|
|
88
88
|
labelDrawerByMode[mode]();
|
|
@@ -90,8 +90,9 @@ export function drawLabel(ctx, backgroundCtx, bounds, paneBounds, visualLabel, c
|
|
|
90
90
|
ctx.restore();
|
|
91
91
|
}
|
|
92
92
|
const isLineVisible = (bounds, labelY, labelBoxHeight) => labelY > bounds.y + labelBoxHeight / 2 && labelY < bounds.y + bounds.height - labelBoxHeight / 2;
|
|
93
|
-
function drawDescription(backgroundCtx, ctx, labelBounds, paneBounds, visualLabel,
|
|
93
|
+
function drawDescription(backgroundCtx, ctx, labelBounds, paneBounds, visualLabel, yAxisState) {
|
|
94
94
|
var _a, _b, _c;
|
|
95
|
+
const align = yAxisState.align || 'right';
|
|
95
96
|
const description = visualLabel.description;
|
|
96
97
|
if (!description || description.length === 0) {
|
|
97
98
|
return;
|
|
@@ -26,10 +26,10 @@ export class YAxisPriceLabelsDrawer {
|
|
|
26
26
|
orderedLabels.forEach(l => {
|
|
27
27
|
var _a;
|
|
28
28
|
const bounds = (_a = l.bounds) !== null && _a !== void 0 ? _a : yAxisBounds;
|
|
29
|
-
l.labels.forEach(vl => drawLabel(ctx, backgroundCtx, bounds, paneBounds, vl, this.canvasBoundsContainer, extent.yAxis.state, this.fullConfig.colors
|
|
29
|
+
l.labels.forEach(vl => drawLabel(ctx, backgroundCtx, bounds, paneBounds, vl, this.canvasBoundsContainer, extent.yAxis.state, this.fullConfig.colors));
|
|
30
30
|
});
|
|
31
31
|
// TODO I added this as a simple mechanism to add custom labels, we need to review it
|
|
32
|
-
Object.values(extent.yAxis.model.fancyLabelsModel.customLabels).forEach(l => drawLabel(ctx, backgroundCtx, yAxisBounds, paneBounds, l, this.canvasBoundsContainer, extent.yAxis.state, this.fullConfig.colors
|
|
32
|
+
Object.values(extent.yAxis.model.fancyLabelsModel.customLabels).forEach(l => drawLabel(ctx, backgroundCtx, yAxisBounds, paneBounds, l, this.canvasBoundsContainer, extent.yAxis.state, this.fullConfig.colors));
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -63,7 +63,7 @@ export declare function drawRectLabel(ctx: CanvasRenderingContext2D, bounds: Bou
|
|
|
63
63
|
* @param checkBoundaries
|
|
64
64
|
* @param backgroundCtx
|
|
65
65
|
*/
|
|
66
|
-
export declare function drawPlainLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: YAxisConfig, yAxisColors: FullChartColors['yAxis'], checkBoundaries?: boolean
|
|
66
|
+
export declare function drawPlainLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: YAxisConfig, yAxisColors: FullChartColors['yAxis'], checkBoundaries?: boolean): void;
|
|
67
67
|
/**
|
|
68
68
|
* Offset from the center of label to the top/bottom.
|
|
69
69
|
*
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import { getFontFromConfig } from '../../chart.config';
|
|
7
|
-
import { redrawBackgroundArea } from '../../drawers/chart-background.drawer';
|
|
8
7
|
import { drawPriceLabel, drawRoundedRect } from '../../utils/canvas/canvas-drawing-functions.utils';
|
|
9
8
|
import { calculateSymbolHeight, calculateTextWidth } from '../../utils/canvas/canvas-font-measure-tool.utils';
|
|
10
9
|
import { getLabelTextColorByBackgroundColor } from '../../utils/canvas/canvas-text-functions.utils';
|
|
@@ -120,11 +119,11 @@ export function drawRectLabel(ctx, bounds, text, centralY, config, yAxisState, y
|
|
|
120
119
|
* @param checkBoundaries
|
|
121
120
|
* @param backgroundCtx
|
|
122
121
|
*/
|
|
123
|
-
export function drawPlainLabel(ctx, bounds, text, centralY, config, yAxisState, yAxisColors, checkBoundaries = true
|
|
122
|
+
export function drawPlainLabel(ctx, bounds, text, centralY, config, yAxisState, yAxisColors, checkBoundaries = true) {
|
|
124
123
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
125
124
|
const align = yAxisState.align;
|
|
126
125
|
const textFont = (_a = config.textFont) !== null && _a !== void 0 ? _a : getFontFromConfig(yAxisState);
|
|
127
|
-
const bgColor =
|
|
126
|
+
const bgColor = yAxisColors.backgroundColor;
|
|
128
127
|
const textColor = (_b = config.textColor) !== null && _b !== void 0 ? _b : getLabelTextColorByBackgroundColor(bgColor, yAxisColors.labelTextColor, yAxisColors.labelInvertedTextColor);
|
|
129
128
|
const paddings = (_c = yAxisState.typeConfig.rectangle) === null || _c === void 0 ? void 0 : _c.paddings;
|
|
130
129
|
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;
|
|
@@ -149,7 +148,10 @@ export function drawPlainLabel(ctx, bounds, text, centralY, config, yAxisState,
|
|
|
149
148
|
const width = paddingStart !== undefined ? textWidth + paddingStart + paddingEnd : bounds.width - marginEnd;
|
|
150
149
|
const x = align === 'right' ? bounds.x + bounds.width - marginEnd - width : bounds.x + marginEnd;
|
|
151
150
|
const textX = align === 'right' ? bounds.x + bounds.width - textWidth - xTextOffset : xTextOffset;
|
|
152
|
-
|
|
151
|
+
// label can overlap with regular price y-axis label, so we need to hide regular y-axis label
|
|
152
|
+
ctx.fillStyle = bgColor;
|
|
153
|
+
ctx.strokeStyle = bgColor;
|
|
154
|
+
ctx.fillRect(x, labelBoxTopY, width, labelBoxHeight);
|
|
153
155
|
ctx.fillStyle = textColor;
|
|
154
156
|
ctx.fillText(text, textX, centralY + fontHeight / 2 - 1); // -1 for font height adjustment
|
|
155
157
|
ctx.restore();
|
|
@@ -53,8 +53,10 @@ export class YAxisScaleHandler extends ChartBaseElement {
|
|
|
53
53
|
const newYStart = this.lastYStart - delta;
|
|
54
54
|
const newYEnd = this.lastYEnd + delta;
|
|
55
55
|
this.autoScaleCallback(false);
|
|
56
|
-
this.
|
|
57
|
-
|
|
56
|
+
if (this.lastYStart !== newYStart || this.lastYEnd !== newYEnd) {
|
|
57
|
+
this.scale.setYScale(newYStart, newYEnd);
|
|
58
|
+
this.bus.fireDraw();
|
|
59
|
+
}
|
|
58
60
|
};
|
|
59
61
|
this.onYDragEnd = () => {
|
|
60
62
|
this.yAxisDragEndSubject.next();
|
|
@@ -19,7 +19,7 @@ export class BackgroundDrawer {
|
|
|
19
19
|
this.canvasModel.clear();
|
|
20
20
|
const ctx = this.canvasModel.ctx;
|
|
21
21
|
if (this.config.colors.chartAreaTheme.backgroundMode === 'gradient') {
|
|
22
|
-
const grd = ctx.createLinearGradient(0, 0, this.canvasModel.width, this.canvasModel.height);
|
|
22
|
+
const grd = ctx.createLinearGradient(0, 0 + this.canvasModel.height / 2, this.canvasModel.width, 0 + this.canvasModel.height / 2);
|
|
23
23
|
grd.addColorStop(0, this.config.colors.chartAreaTheme.backgroundGradientTopColor);
|
|
24
24
|
grd.addColorStop(1, this.config.colors.chartAreaTheme.backgroundGradientBottomColor);
|
|
25
25
|
ctx.fillStyle = grd;
|
|
@@ -38,6 +38,7 @@ export class BackgroundDrawer {
|
|
|
38
38
|
}
|
|
39
39
|
// this function in used in case when
|
|
40
40
|
// some entity can overlap with another chart entity, so we need to hide the another entity
|
|
41
|
+
// it has very (!!!) poor perfomance, use it carefully
|
|
41
42
|
export const redrawBackgroundArea = (backgroundCtx, ctx, x, y, width, height, opacity) => {
|
|
42
43
|
const dpr = getDPR();
|
|
43
44
|
const backgroundCoords = [x * dpr, y * dpr, width * dpr, height * dpr];
|