Skip to content

Commit 2916089

Browse files
committed
[FIX] charts: small zoom is disabled
Task Description: This task aims to reduce issue coming from the zoom feature in two cases : 1. Make the slider looks "disabled" when there is only one data point 2. Don't zoom when the new min and max value are equals 3. The onMouseUp event is now resetting the displayed boundaries according to the chart boundaries, to stay consistant. Among all the changes, a new behavior has been added for the onMouseUp in the master chart, where the lowerBound and the upperBound are updated according to the real displayed boundaries of the detail chart computed by chartJs. This avoid having lots of different cases to recompute the boundaries one last time according to the type of chart and axis. Unfortunately, two tests are now unusable (checking the rounding of the boundaries when mouseUping) as chartJs is not fully used/mocked in the test, and then the boundaries are not correctly recomputed. Related task closes #7069 Task: 5058567 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent b0c2d66 commit 2916089

File tree

12 files changed

+307
-209
lines changed

12 files changed

+307
-209
lines changed

src/components/figures/chart/chartJs/zoomable_chart/zoomable_chart_store.ts

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import { SpreadsheetStore } from "../../../../../stores";
88
const TREND_LINE_AXES_IDS = [TREND_LINE_XAXIS_ID, MOVING_AVERAGE_TREND_LINE_XAXIS_ID] as const;
99
const ZOOMABLE_AXIS_IDS = ["x", ...TREND_LINE_AXES_IDS] as const;
1010
export type AxisId = (typeof ZOOMABLE_AXIS_IDS)[number];
11+
12+
export interface Boundaries {
13+
min: number;
14+
max: number;
15+
}
1116
export type AxesLimits = {
12-
[chartId: UID]: { [axisId in AxisId]?: { min: number; max: number } | undefined };
17+
[chartId: UID]: { [axisId in AxisId]?: Boundaries } & { x: Boundaries };
1318
};
19+
1420
export class ZoomableChartStore extends SpreadsheetStore {
1521
mutators = [
1622
"resetAxisLimits",
@@ -53,34 +59,21 @@ export class ZoomableChartStore extends SpreadsheetStore {
5359
return "noStateChange";
5460
}
5561

56-
resetAxisLimits(
57-
chartId: UID,
58-
limits: { [key: string]: { min: number; max: number } | undefined } | undefined
59-
) {
62+
resetAxisLimits(chartId: UID, limits: { [key: string]: Boundaries }) {
6063
for (const axisId of ZOOMABLE_AXIS_IDS) {
61-
if (limits?.[axisId]) {
62-
if (!this.originalAxisLimits[chartId]?.[axisId]) {
63-
this.originalAxisLimits[chartId] = {
64-
...this.originalAxisLimits[chartId],
65-
[axisId]: {},
66-
};
67-
}
68-
this.originalAxisLimits[chartId][axisId]!["min"] = limits[axisId].min;
69-
this.originalAxisLimits[chartId][axisId]!["max"] = limits[axisId].max;
70-
} else {
71-
if (this.originalAxisLimits[chartId]?.[axisId]) {
72-
delete this.originalAxisLimits[chartId][axisId];
73-
}
64+
if (limits[axisId]) {
65+
this.originalAxisLimits[chartId] = {
66+
...this.originalAxisLimits[chartId],
67+
[axisId]: { ...limits[axisId] },
68+
};
69+
} else if (this.originalAxisLimits[chartId]?.[axisId]) {
70+
delete this.originalAxisLimits[chartId][axisId];
7471
}
7572
}
7673
return "noStateChange";
7774
}
7875

79-
updateAxisLimits(chartId: UID, limits?: { min: number; max: number } | undefined) {
80-
if (limits === undefined) {
81-
delete this.currentAxesLimits[chartId];
82-
return "noStateChange";
83-
}
76+
updateAxisLimits(chartId: UID, limits: Boundaries) {
8477
let { min, max } = limits;
8578
if (min > max) {
8679
[min, max] = [max, min];
@@ -97,35 +90,25 @@ export class ZoomableChartStore extends SpreadsheetStore {
9790
* for the current trend line axes.
9891
*/
9992
updateTrendLineConfiguration(chartId: UID) {
100-
if (!this.originalAxisLimits[chartId]) {
93+
if (!this.originalAxisLimits[chartId]?.x || !this.currentAxesLimits[chartId]?.x) {
10194
return "noStateChange";
10295
}
10396
const chartLimits = this.originalAxisLimits[chartId].x;
104-
if (chartLimits === undefined) {
105-
return "noStateChange";
106-
}
10797
for (const axisId of TREND_LINE_AXES_IDS) {
10898
if (!this.originalAxisLimits[chartId][axisId]) {
10999
continue;
110100
}
111-
if (!this.currentAxesLimits[chartId]?.[axisId]) {
112-
this.currentAxesLimits[chartId] = {
113-
...this.currentAxesLimits[chartId],
114-
[axisId]: {},
115-
};
116-
}
117-
if (this.currentAxesLimits[chartId]?.x === undefined) {
118-
return "noStateChange";
119-
}
120101
const realRange = chartLimits.max - chartLimits.min;
121102
const trendingLimits = this.originalAxisLimits[chartId][axisId];
122-
const trendingRange = trendingLimits.max! - trendingLimits.min!;
103+
const trendingRange = trendingLimits.max - trendingLimits.min;
123104
const slope = trendingRange / realRange;
124-
const intercept = trendingLimits.min! - chartLimits.min * slope;
105+
const intercept = trendingLimits.min - chartLimits.min * slope;
125106
const newXMin = this.currentAxesLimits[chartId].x.min;
126107
const newXMax = this.currentAxesLimits[chartId].x.max;
127-
this.currentAxesLimits[chartId][axisId]!.min = newXMin * slope + intercept;
128-
this.currentAxesLimits[chartId][axisId]!.max = newXMax * slope + intercept;
108+
this.currentAxesLimits[chartId][axisId] = {
109+
min: newXMin * slope + intercept,
110+
max: newXMax * slope + intercept,
111+
};
129112
}
130113
return "noStateChange";
131114
}

0 commit comments

Comments
 (0)