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:
@@ -353,7 +353,7 @@
|
|||||||
if (!labels[key] || !labels[key].values) { continue; }
|
if (!labels[key] || !labels[key].values) { continue; }
|
||||||
const values = Object.keys(labels[key].values)
|
const values = Object.keys(labels[key].values)
|
||||||
.map(v => parseInt(v, 10));
|
.map(v => parseInt(v, 10));
|
||||||
values.sort();
|
values.sort((a, b) => a - b);
|
||||||
if (!values.length) { continue; }
|
if (!values.length) { continue; }
|
||||||
extremes[key] = {min: values[0], max: values[values.length - 1]};
|
extremes[key] = {min: values[0], max: values[values.length - 1]};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -566,11 +566,18 @@ limitations under the License.
|
|||||||
assert.deepEqual(computeSpy.lastCall.returnValue,
|
assert.deepEqual(computeSpy.lastCall.returnValue,
|
||||||
{'my-label': {min: -12, max: -12}});
|
{'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 = {
|
element.labels = {
|
||||||
'my-label': {values: {'-12': {}}},
|
'my-label': {values: {'-12': {}}},
|
||||||
'other-label': {values: {'-1': {}, ' 0': {}, '+1': {}}},
|
'other-label': {values: {'-1': {}, ' 0': {}, '+1': {}}},
|
||||||
};
|
};
|
||||||
assert.equal(computeSpy.callCount, 6);
|
assert.equal(computeSpy.callCount, 7);
|
||||||
assert.deepEqual(computeSpy.lastCall.returnValue, {
|
assert.deepEqual(computeSpy.lastCall.returnValue, {
|
||||||
'my-label': {min: -12, max: -12},
|
'my-label': {min: -12, max: -12},
|
||||||
'other-label': {min: -1, max: 1},
|
'other-label': {min: -1, max: 1},
|
||||||
|
|||||||
Reference in New Issue
Block a user