Skip to content

Commit ae4783d

Browse files
committed
Perf: Fix slow selectAll and deselectAll highcharts controller methods
1 parent b1601b5 commit ae4783d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

app/javascript/controllers/highchart_controller.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ export default class extends Controller {
1818

1919
deselectAll() {
2020
this.chart.series.forEach((s) => {
21-
s.hide();
21+
// Change series visibility to hidden (first param) without redrawing (second param)
22+
s.setVisible(false, false);
2223
})
24+
// Redraw chart only once at the end for performance reasons.
25+
this.chart.redraw();
2326
}
2427

2528
selectAll() {
2629
this.chart.series.forEach((s) => {
27-
s.show();
30+
// Change series visibility to visible (first param) without redrawing (second param)
31+
s.setVisible(true, false);
2832
})
33+
// Redraw chart only once at the end for performance reasons.
34+
this.chart.redraw();
2935
}
3036

3137
}

app/views/shared/_highcharts.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div data-controller="highchart" data-highchart-config-value="<%= config %>">
22
<div data-highchart-target="chart"></div>
3-
<div>
3+
<div class="pl-3">
44
<button type="button" class="btn btn-sm btn-secondary" data-action="click->highchart#selectAll">Select All</button>
55
<button type="button" class="btn btn-sm btn-info" data-action="click->highchart#deselectAll">Deselect All</button>
66
</div>

0 commit comments

Comments
 (0)