Fix computing label extremes

The array of potential label values is sorted alphabetically when you
just call .sort(), so -1 was "smaller" than -2.

Bug: Issue 11782
Change-Id: I1c1aac0129d0bb59714a1a3c0ea845acbae54bcc
(cherry picked from commit 6e26a4b2c5)
This commit is contained in:
Ben Rohlfs
2019-10-23 22:49:47 +02:00
committed by Paladox none
parent f504e927f4
commit 54b4873eb4
2 changed files with 9 additions and 2 deletions

View File

@@ -353,7 +353,7 @@
if (!labels[key] || !labels[key].values) { continue; }
const values = Object.keys(labels[key].values)
.map(v => parseInt(v, 10));
values.sort();
values.sort((a, b) => a - b);
if (!values.length) { continue; }
extremes[key] = {min: values[0], max: values[values.length - 1]};
}

View File

@@ -566,11 +566,18 @@ limitations under the License.
assert.deepEqual(computeSpy.lastCall.returnValue,
{'my-label': {min: -12, max: -12}});
element.labels = {
'my-label': {values: {'-2': {}, '-1': {}, '0': {}, '+1': {}, '+2': {}}},
};
assert.equal(computeSpy.callCount, 6);
assert.deepEqual(computeSpy.lastCall.returnValue,
{'my-label': {min: -2, max: 2}});
element.labels = {
'my-label': {values: {'-12': {}}},
'other-label': {values: {'-1': {}, ' 0': {}, '+1': {}}},
};
assert.equal(computeSpy.callCount, 6);
assert.equal(computeSpy.callCount, 7);
assert.deepEqual(computeSpy.lastCall.returnValue, {
'my-label': {min: -12, max: -12},
'other-label': {min: -1, max: 1},