Skip to content

Commit 05c9dff

Browse files
committed
Minor readability improvement by moving cleanup into single method
1 parent a91a325 commit 05c9dff

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

public/js/module.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,22 @@
5757
_this.currentCursor = null;
5858
}
5959

60-
_this.renderCharts();
60+
// Remove leftover eventhandlers and uPlot instances
61+
_this.plots.forEach((plot, element) => {
62+
plot.destroy();
63+
});
64+
// Then, reset the existing plots map for the new rendering
65+
_this.plots = new Map();
66+
67+
// Get the elements we going to render the charts in
68+
const lineCharts = document.querySelectorAll(CHART_CLASS);
69+
70+
// Check if the elements exist, just to be safe
71+
if (lineCharts.length < 1) {
72+
return;
73+
}
74+
75+
_this.renderCharts(lineCharts);
6176
}
6277

6378
/**
@@ -198,7 +213,7 @@
198213
/**
199214
* renderCharts creates the canvas objects given the provided datasets.
200215
*/
201-
renderCharts()
216+
renderCharts(lineCharts)
202217
{
203218
// Get the colors from these sneaky little HTML elements
204219
const axesColor = $('div.axes-color').css('background-color');
@@ -208,24 +223,11 @@
208223
// These are the shared options for all charts
209224
const baseOpts = this.getChartBaseOptions();
210225

211-
// Remove leftover eventhandlers and uPlot instances
212-
this.plots.forEach((plot, element) => {
213-
plot.destroy();
214-
});
215-
// Then, reset the existing plots map for the new rendering
216-
this.plots = new Map();
217-
218-
// Get the elements we going to render the charts in
219-
const lineCharts = document.querySelectorAll(CHART_CLASS);
220-
221-
// Check if the elements exist, just to be safe
222-
if (lineCharts.length < 1) {
223-
return;
224-
}
225-
226226
this.icinga.logger.debug('perfdatagraphs', 'start renderCharts');
227227

228228
for (let elem of lineCharts) {
229+
this.icinga.logger.debug('perfdatagraphs', 'rendering for', elem);
230+
229231
const dataset = JSON.parse(elem.getAttribute('data-perfdata'));
230232

231233
// The size can vary from chart to chart for example when

0 commit comments

Comments
 (0)