Skip to content

Commit 208cfa7

Browse files
Keelaro1dxcity
authored and
dxcity
committed
Pull request #5500: Feature/DXCF-5864 change price scale scales color along with background
Merge in DXCHARTS/dxchart5 from feature/DXCF-5864-change-price-scale-scales-color-along-with-background to master * commit 'a2cce13abf69dd3397f9ecd33a5c1f017a2497e5': [DXCF-5864] Change price scale/scales color along with background // init [DXCF-5864] Change price scale/scales color along with background [DXCF-5864] Change price scale/scales color along with background // init [DXCF-5864] Change price scale/scales color along with background // init GitOrigin-RevId: e73f6355a54e6ba1b9bfa74024a0cb2d01a995e8
1 parent 03db53e commit 208cfa7

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/chart/chart.config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export const getDefaultConfig = (): FullChartConfig => ({
112112
barCapSize: 1,
113113
},
114114
maxYAxisScalesAmount: 10,
115+
applyBackgroundToAxes: {
116+
x: true,
117+
y: true,
118+
},
115119
sortCandles: defaultSortCandles,
116120
},
117121
yAxis: {
@@ -1000,6 +1004,13 @@ export interface ChartConfigComponentsChart {
10001004
* The maximum amount of Y axis scales on a single chart
10011005
*/
10021006
maxYAxisScalesAmount: number;
1007+
/**
1008+
* Background color will be also applied to the chart axes
1009+
*/
1010+
applyBackgroundToAxes: {
1011+
x: boolean;
1012+
y: boolean;
1013+
};
10031014
// optional because backward compability
10041015
sortCandles?: (candles: Candle[]) => Candle[];
10051016
}

src/chart/components/chart/chart.component.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
2+
* Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited
33
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
44
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
@@ -317,6 +317,18 @@ export class ChartComponent extends ChartBaseElement {
317317
this.canvasModel.fireDraw();
318318
}
319319

320+
/**
321+
* Sets the options for the background color applying to the chart axes
322+
* @param {Object} options - options for both axes
323+
* @param {boolean} options.x - should the background color apply to the x axis
324+
* @param {boolean} options.y - should the background color apply to the y axis
325+
* @returns {void}
326+
*/
327+
public setApplyBackgroundToAxes(options: { x: boolean; y: boolean }) {
328+
this.config.components.chart.applyBackgroundToAxes = { ...options };
329+
this.chartModel.bus.fireDraw();
330+
}
331+
320332
/**
321333
* Used to set the main series to chart.
322334
* @param series

src/chart/components/x_axis/x-axis-time-labels.drawer.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
2+
* Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited
33
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
44
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
@@ -42,7 +42,10 @@ export class XAxisTimeLabelsDrawer implements Drawer {
4242
ctx.font = font;
4343
ctx.fillStyle = xAxisColors.backgroundColor;
4444
const bounds = this.canvasBoundsContainer.getBounds(CanvasElement.X_AXIS);
45-
ctx.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
45+
// draw axis background rect if the background color is not used
46+
if (!this.config.components.chart.applyBackgroundToAxes.x) {
47+
ctx.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
48+
}
4649

4750
const color = this.config.colors.xAxis.labelTextColor;
4851
const labels = this.labelsProvider();

src/chart/components/y_axis/y-axis.drawer.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
2+
* Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited
33
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
44
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
@@ -51,9 +51,11 @@ export class YAxisDrawer implements Drawer {
5151
const bounds: Bounds = yAxisComponent.getBounds();
5252
const ctx = this.canvasModel.ctx;
5353

54-
// draw axis background rect animation
55-
ctx.fillStyle = this.getBackgroundColor();
56-
ctx.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
54+
// draw axis background rect if the background color is not used
55+
if (!this.fullConfig.components.chart.applyBackgroundToAxes.y) {
56+
ctx.fillStyle = this.getBackgroundColor();
57+
ctx.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
58+
}
5759

5860
const font = getFontFromConfig(yAxisComponent.state);
5961
const fontHeight = calculateSymbolHeight(font, ctx);

0 commit comments

Comments
 (0)