Skip to content

Commit a98fd71

Browse files
artskardxcity
authored andcommitted
Pull request #6344: [DXCF-6648] [Web] Volume - Issues for volume after save layout
Merge in DXCHARTS/dxchart5 from bugfix/DXCF-6648-web-volume-issues-for-volume-after-save-layout to master Squashed commit of the following: commit 39d0919abdc9cf1b002e23f73c43702489e8889e Author: dxcity <dxcity@bots.devexperts.com> Date: Fri Feb 6 09:26:28 2026 +0000 CI: update snapshots commit ea288c433d4cde8827406245c567779abd1d198c Author: Vladislav Poddubskii <vpoddubskii@devexperts.com> Date: Fri Feb 6 10:32:30 2026 +0300 [DXCF-6648] [Web] Volume - Issues for volume after save layout GitOrigin-RevId: c7450258712bd4f6a1c841d79999f54a4b7876e7
1 parent e7284df commit a98fd71

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/chart/components/volumes/volumes.drawer.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,22 @@ export class VolumesDrawer implements DynamicModelDrawer<VolumesModel> {
9999
if (volumeMax === 0) {
100100
return;
101101
}
102+
const viewportModel = this.getViewportModel();
103+
if (!viewportModel.isViewportValid()) {
104+
return;
105+
}
102106
const candles = flat(
103107
this.chartModel.mainCandleSeries
104108
// TODO volumes drawer should be a part of data series drawer
105109
.getSeriesInViewport(this.chartModel.scale.xStart - 1, this.chartModel.scale.xEnd + 1),
106110
);
107-
const viewportModel = this.getViewportModel();
108111
candles.forEach((vCandle, idx) => {
109112
if (vCandle.candle.volume) {
110113
const bounds = viewportModel.getBounds();
111114
const fullVHeight = bounds.height;
115+
if (fullVHeight <= 0) {
116+
return;
117+
}
112118
const nextX =
113119
candles[idx + 1] !== undefined
114120
? floorToDPR(viewportModel.toX(candles[idx + 1].startUnit))
@@ -121,8 +127,16 @@ export class VolumesDrawer implements DynamicModelDrawer<VolumesModel> {
121127
const height = ceilToDPR(viewportModel.toY(0)) - y;
122128
this.drawVolume(canvasModel, vCandle, x, y, width, height);
123129
} else {
124-
const zoomY = volumeMax / (fullVHeight / OVERLAY_VOLUME_TOTAL_HEIGHT_DIVISOR);
125-
const height = Math.max(ceilToDPR(unitToPixels(vCandle.candle.volume, zoomY)), 2);
130+
const volumeHeightDivisor = fullVHeight / OVERLAY_VOLUME_TOTAL_HEIGHT_DIVISOR;
131+
if (volumeHeightDivisor <= 0) {
132+
return;
133+
}
134+
const zoomY = volumeMax / volumeHeightDivisor;
135+
if (!isFinite(zoomY) || zoomY <= 0) {
136+
return;
137+
}
138+
const calculatedHeight = Math.max(ceilToDPR(unitToPixels(vCandle.candle.volume, zoomY)), 2);
139+
const height = Math.min(calculatedHeight, fullVHeight);
126140
const y = floorToDPR(bounds.y + fullVHeight - height);
127141
this.drawVolume(canvasModel, vCandle, x, y, width, height);
128142
}

src/chart/components/volumes/volumes.model.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ export class VolumesModel extends ChartBaseElement {
5858
* @returns {void}
5959
*/
6060
updateVolumeMax() {
61-
this.volumeMax.next(
62-
firstOf(volumeMaxMinFn(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())) ?? 0,
61+
// Use the same parameters as in drawer to ensure volumeMax is calculated from the same candles that will be drawn
62+
const candles = this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport(
63+
this.scale.xStart - 1,
64+
this.scale.xEnd + 1,
6365
);
66+
this.volumeMax.next(firstOf(volumeMaxMinFn(candles.flat())) ?? 0);
6467
}
6568
}

0 commit comments

Comments
 (0)