Skip to content

Commit eedb134

Browse files
committed
[DRAFT]
from perf doc : https://github.com/chartjs/Chart.js/blob/b9c01414bac867310d192da676c78e8e269f7d8b/docs/general/performance.md?plain=1 PARSING: we can optimize by removing parsing, if we send date in the valid format and ordered, we can set parsing to false and save some time following the doc: https://www.chartjs.org/docs/latest/samples/bar/stacked-groups.html and testing with (array of object (x, y) instead of array of int) testing at odoo with parsing = false, there is a small problem, i'm still looking why the count is not well displayed (fyi, it's well computed as you can see in the y axis) Data normalization when parsing, i used unique and sorted data, so it should work with normalized: true Decimation (https://github.com/chartjs/Chart.js/blob/b9c01414bac867310d192da676c78e8e269f7d8b/docs/configuration/decimation.md) can't be acheived as our labels are not linear or time, we use stages (string) Disable Animations for large data i'm also wondering if we disable the view for large data. it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide. it was crushing, and sometimes loaded in 160 seconds, now it's done in around ~ 70 seconds, but as you can see it's not readable at all I also found an open issue on github, and someone tried to solve it  https://github.com/chartjs/Chart.js/pull/11836 it's still not approved i will need to test on  a staging env (real data) to be coherent.
1 parent 1affba5 commit eedb134

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

addons/web/static/lib/Chart/Chart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8125,7 +8125,7 @@
81258125
getDatasetMeta(datasetIndex) {
81268126
const dataset = this.data.datasets[datasetIndex];
81278127
const metasets = this._metasets;
8128-
let meta = metasets.filter((x)=>x && x._dataset === dataset).pop();
8128+
let meta = metasets[datasetIndex];
81298129
if (!meta) {
81308130
meta = {
81318131
type: null,
@@ -8141,7 +8141,7 @@
81418141
_parsed: [],
81428142
_sorted: false
81438143
};
8144-
metasets.push(meta);
8144+
metasets[datasetIndex] = meta;
81458145
}
81468146
return meta;
81478147
}

addons/web/static/src/views/graph/graph_model.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ export class GraphModel extends Model {
299299
(_, index) => labelsToKeepIndexes[index]
300300
);
301301
}
302+
} else if (mode === "bar") {
303+
for (const dataset of datasets) {
304+
dataset.data = dataset.data.map((value, index) => ({ x: index, y: value }));
305+
}
302306
}
303307

304308
return { datasets, labels };

addons/web/static/src/views/graph/graph_renderer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,9 @@ export class GraphRenderer extends Component {
773773
onResize: () => {
774774
this.resizeChart(options);
775775
},
776-
animation: this.getAnimationOptions(),
776+
animation: false, // this.getAnimationOptions(),
777+
parsing: false,
778+
normalized: true,
777779
};
778780
if (!disableLinking && mode !== "line") {
779781
options.onClick = this.onGraphClicked.bind(this);
@@ -838,7 +840,9 @@ export class GraphRenderer extends Component {
838840
}
839841
if (this.canvasRef.el) {
840842
const config = this.getChartConfig();
843+
console.time("chart");
841844
this.chart = new Chart(this.canvasRef.el, config);
845+
console.timeEnd("chart");
842846
}
843847
}
844848

0 commit comments

Comments
 (0)