Skip to content

Commit d79fe90

Browse files
authored
EC: fix last interval in edit size histogram (x-tools#590)
It currently wasn't initialised, which meant our += operation made (undefined + int) = NaN, which chart.js interpreted as 0, so that last interval was always empty. Bug: T411310
1 parent c4222f0 commit d79fe90

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

assets/js/editcounter.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ xtools.editcounter.setupMonthYearChart = function (id, datasets, labels, maxTota
304304
createchart(uselog?"logarithmic":"linear");
305305
});
306306
});
307-
307+
308308
};
309309

310310
/**
@@ -315,7 +315,7 @@ xtools.editcounter.setupMonthYearChart = function (id, datasets, labels, maxTota
315315
* @param {Array} barLabels i18n'd bar labels for additions, removals and same-size, in that order.
316316
*/
317317
xtools.editcounter.setupSizeHistogram = function (data, colors, barLabels) {
318-
let bars = 11;
318+
let bars = 12; // Counting the >10240 interval!
319319
// First sanitize input, to get array.
320320
let total = Object.keys(data).length;
321321
data.length = total;
@@ -339,14 +339,26 @@ xtools.editcounter.setupSizeHistogram = function (data, colors, barLabels) {
339339
datasetZero.data[0] += 1;
340340
} else {
341341
// That's the slice index
342-
let index = Math.ceil(Math.min(11, Math.max(0, Math.log(Math.abs(x)/10)/Math.log(2))));
342+
let index = Math.ceil(
343+
Math.min(
344+
bars-1,
345+
Math.max(
346+
0,
347+
Math.log(
348+
Math.abs(x)/10
349+
)
350+
/
351+
Math.log(2)
352+
)
353+
)
354+
);
343355
( x < 0 ? datasetNeg : datasetPos ).data[index] += ( x < 0 ? -1 : 1);
344356
}
345357
});
346358
// The labels for intervals
347-
let bounds = [0].concat(Array.from(new Array(bars), (_,i) => 10*2**i));
348-
let labels = Array.from(new Array(bars), (_,i) => (new Intl.NumberFormat(i18nLang)).formatRange(bounds[i], bounds[i+1]));
349-
labels.push(">"+bounds[bars].toLocaleString(i18nLang));
359+
let bounds = [0].concat(Array.from(new Array(bars-1), (_,i) => 10*2**i));
360+
let labels = Array.from(new Array(bars-1), (_,i) => (new Intl.NumberFormat(i18nLang)).formatRange(bounds[i], bounds[i+1]));
361+
labels.push(">"+bounds[bars-1].toLocaleString(i18nLang));
350362

351363
window['sizeHistogramChart'] = new Chart($("#sizechart-canvas"), {
352364
type: 'bar',

public/build/app.93b4ef2d.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

public/build/app.a7ec0e72.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/entrypoints.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"js": [
55
"/build/runtime.c217f8c4.js",
66
"/build/852.96913092.js",
7-
"/build/app.93b4ef2d.js"
7+
"/build/app.a7ec0e72.js"
88
],
99
"css": [
1010
"/build/app.7692d209.css"

public/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"build/app.css": "/build/app.7692d209.css",
3-
"build/app.js": "/build/app.93b4ef2d.js",
3+
"build/app.js": "/build/app.a7ec0e72.js",
44
"build/runtime.js": "/build/runtime.c217f8c4.js",
55
"build/852.96913092.js": "/build/852.96913092.js",
66
"build/images/VPS-badge.svg": "/build/images/VPS-badge.svg",

0 commit comments

Comments
 (0)