mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Preserve x-axis order in vislib. (#31533)
This commit is contained in:
parent
ae72315cf2
commit
e69d94b345
34 changed files with 605 additions and 136 deletions
|
@ -263,5 +263,38 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': [
|
||||
1415826600000,
|
||||
1415826630000,
|
||||
1415826660000,
|
||||
1415826690000,
|
||||
1415826720000,
|
||||
1415826750000,
|
||||
1415826780000,
|
||||
1415826810000,
|
||||
1415826840000,
|
||||
1415826870000,
|
||||
1415826900000,
|
||||
1415826930000,
|
||||
1415826960000,
|
||||
1415826990000,
|
||||
1415827020000,
|
||||
1415827050000,
|
||||
1415827080000,
|
||||
1415827110000,
|
||||
1415827140000,
|
||||
1415827170000,
|
||||
1415827200000,
|
||||
1415827230000,
|
||||
1415827260000,
|
||||
1415827290000,
|
||||
1415827320000,
|
||||
1415827350000,
|
||||
1415827380000,
|
||||
1415827410000,
|
||||
1415827440000,
|
||||
1415827470000,
|
||||
1415827500000,
|
||||
],
|
||||
'hits': 225
|
||||
};
|
||||
|
|
|
@ -1641,5 +1641,38 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': [
|
||||
1415826240000,
|
||||
1415826270000,
|
||||
1415826300000,
|
||||
1415826330000,
|
||||
1415826360000,
|
||||
1415826390000,
|
||||
1415826420000,
|
||||
1415826450000,
|
||||
1415826480000,
|
||||
1415826510000,
|
||||
1415826540000,
|
||||
1415826570000,
|
||||
1415826600000,
|
||||
1415826630000,
|
||||
1415826660000,
|
||||
1415826690000,
|
||||
1415826720000,
|
||||
1415826750000,
|
||||
1415826780000,
|
||||
1415826810000,
|
||||
1415826840000,
|
||||
1415826870000,
|
||||
1415826900000,
|
||||
1415826930000,
|
||||
1415826960000,
|
||||
1415826990000,
|
||||
1415827020000,
|
||||
1415827050000,
|
||||
1415827080000,
|
||||
1415827110000,
|
||||
1415827140000,
|
||||
],
|
||||
'hits': 236
|
||||
};
|
||||
|
|
|
@ -99,5 +99,25 @@ export const rowsSeriesWithHoles = {
|
|||
return d;
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
'xAxisOrderedValues': [
|
||||
1411761450000,
|
||||
1411761510000,
|
||||
1411761540000,
|
||||
1411761840000,
|
||||
1411761870000,
|
||||
1411761900000,
|
||||
1411761930000,
|
||||
1411761960000,
|
||||
1411761990000,
|
||||
1411762020000,
|
||||
1411762050000,
|
||||
1411762080000,
|
||||
1411762110000,
|
||||
1411762140000,
|
||||
1411762170000,
|
||||
1411762200000,
|
||||
1411762320000,
|
||||
1411762350000,
|
||||
],
|
||||
};
|
||||
|
|
|
@ -142,6 +142,39 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 533,
|
||||
'xAxisOrderedValues': [
|
||||
1411761450000,
|
||||
1411761480000,
|
||||
1411761510000,
|
||||
1411761540000,
|
||||
1411761570000,
|
||||
1411761600000,
|
||||
1411761630000,
|
||||
1411761660000,
|
||||
1411761690000,
|
||||
1411761720000,
|
||||
1411761750000,
|
||||
1411761780000,
|
||||
1411761810000,
|
||||
1411761840000,
|
||||
1411761870000,
|
||||
1411761900000,
|
||||
1411761930000,
|
||||
1411761960000,
|
||||
1411761990000,
|
||||
1411762020000,
|
||||
1411762050000,
|
||||
1411762080000,
|
||||
1411762110000,
|
||||
1411762140000,
|
||||
1411762170000,
|
||||
1411762200000,
|
||||
1411762230000,
|
||||
1411762260000,
|
||||
1411762290000,
|
||||
1411762320000,
|
||||
1411762350000,
|
||||
],
|
||||
'xAxisFormatter': function (thing) {
|
||||
return moment(thing);
|
||||
},
|
||||
|
|
|
@ -66,6 +66,20 @@ export const seriesMonthlyInterval = {
|
|||
}
|
||||
],
|
||||
'hits': 533,
|
||||
'xAxisOrderedValues': [
|
||||
1451631600000,
|
||||
1454310000000,
|
||||
1456815600000,
|
||||
1459490400000,
|
||||
1462082400000,
|
||||
1464760800000,
|
||||
1467352800000,
|
||||
1470031200000,
|
||||
1472709600000,
|
||||
1475301600000,
|
||||
1477980000000,
|
||||
1480575600000,
|
||||
],
|
||||
'xAxisFormatter': function (thing) {
|
||||
return moment(thing);
|
||||
},
|
||||
|
|
|
@ -142,6 +142,39 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 533,
|
||||
'xAxisOrderedValues': [
|
||||
1411761450000,
|
||||
1411761480000,
|
||||
1411761510000,
|
||||
1411761540000,
|
||||
1411761570000,
|
||||
1411761600000,
|
||||
1411761630000,
|
||||
1411761660000,
|
||||
1411761690000,
|
||||
1411761720000,
|
||||
1411761750000,
|
||||
1411761780000,
|
||||
1411761810000,
|
||||
1411761840000,
|
||||
1411761870000,
|
||||
1411761900000,
|
||||
1411761930000,
|
||||
1411761960000,
|
||||
1411761990000,
|
||||
1411762020000,
|
||||
1411762050000,
|
||||
1411762080000,
|
||||
1411762110000,
|
||||
1411762140000,
|
||||
1411762170000,
|
||||
1411762200000,
|
||||
1411762230000,
|
||||
1411762260000,
|
||||
1411762290000,
|
||||
1411762320000,
|
||||
1411762350000,
|
||||
],
|
||||
'xAxisFormatter': function (thing) {
|
||||
return moment(thing);
|
||||
},
|
||||
|
|
|
@ -142,6 +142,39 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 533,
|
||||
'xAxisOrderedValues': [
|
||||
1411761450000,
|
||||
1411761480000,
|
||||
1411761510000,
|
||||
1411761540000,
|
||||
1411761570000,
|
||||
1411761600000,
|
||||
1411761630000,
|
||||
1411761660000,
|
||||
1411761690000,
|
||||
1411761720000,
|
||||
1411761750000,
|
||||
1411761780000,
|
||||
1411761810000,
|
||||
1411761840000,
|
||||
1411761870000,
|
||||
1411761900000,
|
||||
1411761930000,
|
||||
1411761960000,
|
||||
1411761990000,
|
||||
1411762020000,
|
||||
1411762050000,
|
||||
1411762080000,
|
||||
1411762110000,
|
||||
1411762140000,
|
||||
1411762170000,
|
||||
1411762200000,
|
||||
1411762230000,
|
||||
1411762260000,
|
||||
1411762290000,
|
||||
1411762320000,
|
||||
1411762350000,
|
||||
],
|
||||
'xAxisFormatter': function (thing) {
|
||||
return moment(thing);
|
||||
},
|
||||
|
|
|
@ -1474,6 +1474,80 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 108970,
|
||||
'xAxisOrderedValues': [
|
||||
1413543600000,
|
||||
1413544200000,
|
||||
1413544800000,
|
||||
1413545400000,
|
||||
1413546000000,
|
||||
1413546600000,
|
||||
1413547200000,
|
||||
1413547800000,
|
||||
1413548400000,
|
||||
1413549000000,
|
||||
1413549600000,
|
||||
1413550200000,
|
||||
1413550800000,
|
||||
1413551400000,
|
||||
1413552000000,
|
||||
1413552600000,
|
||||
1413553200000,
|
||||
1413553800000,
|
||||
1413554400000,
|
||||
1413555000000,
|
||||
1413555600000,
|
||||
1413556200000,
|
||||
1413556800000,
|
||||
1413557400000,
|
||||
1413558000000,
|
||||
1413558600000,
|
||||
1413559200000,
|
||||
1413559800000,
|
||||
1413560400000,
|
||||
1413561000000,
|
||||
1413561600000,
|
||||
1413562200000,
|
||||
1413562800000,
|
||||
1413563400000,
|
||||
1413564000000,
|
||||
1413564600000,
|
||||
1413565200000,
|
||||
1413565800000,
|
||||
1413566400000,
|
||||
1413567000000,
|
||||
1413567600000,
|
||||
1413568200000,
|
||||
1413568800000,
|
||||
1413569400000,
|
||||
1413570000000,
|
||||
1413570600000,
|
||||
1413571200000,
|
||||
1413571800000,
|
||||
1413572400000,
|
||||
1413573600000,
|
||||
1413574200000,
|
||||
1413574800000,
|
||||
1413575400000,
|
||||
1413576000000,
|
||||
1413576600000,
|
||||
1413577200000,
|
||||
1413577800000,
|
||||
1413578400000,
|
||||
1413579000000,
|
||||
1413579600000,
|
||||
1413580200000,
|
||||
1413580800000,
|
||||
1413581400000,
|
||||
1413582000000,
|
||||
1413582600000,
|
||||
1413583200000,
|
||||
1413583800000,
|
||||
1413584400000,
|
||||
1413585000000,
|
||||
1413585600000,
|
||||
1413586200000,
|
||||
1413586800000,
|
||||
],
|
||||
'xAxisFormatter': function (thing) {
|
||||
return moment(thing);
|
||||
},
|
||||
|
|
|
@ -21,6 +21,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['css', 'png'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -55,6 +56,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['css', 'png'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -89,6 +91,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['css', 'png'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -24,6 +24,7 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 171454,
|
||||
'xAxisOrderedValues': ['css', 'html', 'png'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -345,5 +345,24 @@ export default {
|
|||
}
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': [
|
||||
2147483600,
|
||||
3221225400,
|
||||
4294967200,
|
||||
5368709100,
|
||||
6442450900,
|
||||
7516192700,
|
||||
8589934500,
|
||||
10737418200,
|
||||
11811160000,
|
||||
12884901800,
|
||||
13958643700,
|
||||
15032385500,
|
||||
16106127300,
|
||||
18253611000,
|
||||
19327352800,
|
||||
20401094600,
|
||||
21474836400,
|
||||
],
|
||||
'hits': 40
|
||||
};
|
||||
|
|
|
@ -186,5 +186,27 @@ export default {
|
|||
}
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': [
|
||||
2147483600,
|
||||
3221225400,
|
||||
4294967200,
|
||||
5368709100,
|
||||
6442450900,
|
||||
7516192700,
|
||||
8589934500,
|
||||
9663676400,
|
||||
10737418200,
|
||||
11811160000,
|
||||
12884901800,
|
||||
13958643700,
|
||||
15032385500,
|
||||
16106127300,
|
||||
17179869100,
|
||||
18253611000,
|
||||
19327352800,
|
||||
20401094600,
|
||||
21474836400,
|
||||
32212254700,
|
||||
],
|
||||
'hits': 51
|
||||
};
|
||||
|
|
|
@ -87,6 +87,26 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 71,
|
||||
'xAxisOrderedValues': [
|
||||
3221225400,
|
||||
4294967200,
|
||||
5368709100,
|
||||
6442450900,
|
||||
7516192700,
|
||||
9663676400,
|
||||
10737418200,
|
||||
11811160000,
|
||||
12884901800,
|
||||
13958643700,
|
||||
15032385500,
|
||||
16106127300,
|
||||
17179869100,
|
||||
18253611000,
|
||||
19327352800,
|
||||
20401094600,
|
||||
21474836400,
|
||||
32212254700,
|
||||
],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -16,6 +16,7 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 274,
|
||||
'xAxisOrderedValues': ['_all'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -44,6 +44,7 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 171499,
|
||||
'xAxisOrderedValues': ['0.0-1000.0', '1000.0-2000.0'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -70,6 +70,7 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 171501,
|
||||
'xAxisOrderedValues': ['0.0-1000.0', '1000.0-2000.0'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -20,6 +20,7 @@ export default {
|
|||
}
|
||||
],
|
||||
'hits': 171500,
|
||||
'xAxisOrderedValues': ['0.0-1000.0', '1000.0-2000.0'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -33,6 +33,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -79,6 +80,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -125,6 +127,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -171,6 +174,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -217,6 +221,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -33,6 +33,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -79,6 +80,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -125,6 +127,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -171,6 +174,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
@ -217,6 +221,7 @@ export default {
|
|||
]
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['success', 'info', 'security', 'error', 'warning'],
|
||||
'xAxisFormatter': function (val) {
|
||||
if (_.isObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
|
|
|
@ -10,6 +10,69 @@ export default {
|
|||
'max': 1416852140336
|
||||
},
|
||||
'yAxisLabel': 'Count of documents',
|
||||
'xAxisOrderedValues': [
|
||||
1416850320000,
|
||||
1416850350000,
|
||||
1416850380000,
|
||||
1416850410000,
|
||||
1416850440000,
|
||||
1416850470000,
|
||||
1416850500000,
|
||||
1416850530000,
|
||||
1416850560000,
|
||||
1416850590000,
|
||||
1416850620000,
|
||||
1416850650000,
|
||||
1416850680000,
|
||||
1416850710000,
|
||||
1416850740000,
|
||||
1416850770000,
|
||||
1416850800000,
|
||||
1416850830000,
|
||||
1416850860000,
|
||||
1416850890000,
|
||||
1416850920000,
|
||||
1416850950000,
|
||||
1416850980000,
|
||||
1416851010000,
|
||||
1416851040000,
|
||||
1416851070000,
|
||||
1416851100000,
|
||||
1416851130000,
|
||||
1416851160000,
|
||||
1416851190000,
|
||||
1416851220000,
|
||||
1416851250000,
|
||||
1416851280000,
|
||||
1416851310000,
|
||||
1416851340000,
|
||||
1416851370000,
|
||||
1416851400000,
|
||||
1416851430000,
|
||||
1416851460000,
|
||||
1416851490000,
|
||||
1416851520000,
|
||||
1416851550000,
|
||||
1416851580000,
|
||||
1416851610000,
|
||||
1416851640000,
|
||||
1416851670000,
|
||||
1416851700000,
|
||||
1416851730000,
|
||||
1416851760000,
|
||||
1416851790000,
|
||||
1416851820000,
|
||||
1416851850000,
|
||||
1416851880000,
|
||||
1416851910000,
|
||||
1416851940000,
|
||||
1416851970000,
|
||||
1416852000000,
|
||||
1416852030000,
|
||||
1416852060000,
|
||||
1416852090000,
|
||||
1416852120000,
|
||||
],
|
||||
'series': [
|
||||
{
|
||||
'label': 'jpg',
|
||||
|
|
|
@ -141,5 +141,6 @@ export default {
|
|||
}
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['jpg', 'css', 'png', 'gif', 'php'],
|
||||
'hits': 171462
|
||||
};
|
||||
|
|
|
@ -95,5 +95,6 @@ export default {
|
|||
}
|
||||
}
|
||||
],
|
||||
'xAxisOrderedValues': ['jpg', 'css', 'png', 'gif', 'php'],
|
||||
'hits': 171458
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@ import _ from 'lodash';
|
|||
export default {
|
||||
'label': '',
|
||||
'xAxisLabel': 'Top 5 extension',
|
||||
'xAxisOrderedValues': ['jpg', 'css', 'png', 'gif', 'php'],
|
||||
'yAxisLabel': 'Count of documents',
|
||||
'series': [
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
export default {
|
||||
'xAxisOrderedValues': ['_all'],
|
||||
'yAxisLabel': 'Count',
|
||||
'zAxisLabel': 'machine.os.raw: Descending',
|
||||
'yScale': null,
|
||||
|
|
|
@ -31,5 +31,6 @@ describe('makeFakeXAspect', function () {
|
|||
.and.have.property('format')
|
||||
.and.have.property('params');
|
||||
|
||||
expect(aspect.params).to.have.property('defaultValue', '_all');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,46 +17,98 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import expect from 'expect.js';
|
||||
import { initXAxis } from '../_init_x_axis';
|
||||
import { makeFakeXAspect } from '../_fake_x_aspect';
|
||||
|
||||
describe('initXAxis', function () {
|
||||
let chart;
|
||||
let table;
|
||||
|
||||
const baseChart = {
|
||||
aspects: {
|
||||
x: [{
|
||||
format: {},
|
||||
title: 'label',
|
||||
params: {}
|
||||
}]
|
||||
}
|
||||
};
|
||||
beforeEach(function () {
|
||||
chart = {
|
||||
aspects: {
|
||||
x: [{
|
||||
...makeFakeXAspect(),
|
||||
accessor: 0,
|
||||
title: 'label',
|
||||
}],
|
||||
}
|
||||
};
|
||||
|
||||
table = {
|
||||
columns: [{ id: '0' }],
|
||||
rows: [
|
||||
{ '0': 'hello' },
|
||||
{ '0': 'world' },
|
||||
{ '0': 'foo' },
|
||||
{ '0': 'bar' },
|
||||
{ '0': 'baz' },
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
it('sets the xAxisFormatter if the agg is not ordered', function () {
|
||||
const chart = _.cloneDeep(baseChart);
|
||||
initXAxis(chart);
|
||||
initXAxis(chart, table);
|
||||
expect(chart)
|
||||
.to.have.property('xAxisLabel', 'label')
|
||||
.and.have.property('xAxisFormat', chart.aspects.x[0].format);
|
||||
});
|
||||
|
||||
it('makes the chart ordered if the agg is ordered', function () {
|
||||
const chart = _.cloneDeep(baseChart);
|
||||
chart.aspects.x[0].params.date = true;
|
||||
|
||||
initXAxis(chart);
|
||||
initXAxis(chart, table);
|
||||
expect(chart)
|
||||
.to.have.property('xAxisLabel', 'label')
|
||||
.and.have.property('xAxisFormat', chart.aspects.x[0].format)
|
||||
.and.have.property('ordered');
|
||||
});
|
||||
|
||||
describe('xAxisOrderedValues', function () {
|
||||
it('sets the xAxisOrderedValues property', function () {
|
||||
initXAxis(chart, table);
|
||||
expect(chart).to.have.property('xAxisOrderedValues');
|
||||
});
|
||||
|
||||
it('returns a list of values, preserving the table order', function () {
|
||||
initXAxis(chart, table);
|
||||
expect(chart.xAxisOrderedValues).to.eql(['hello', 'world', 'foo', 'bar', 'baz']);
|
||||
});
|
||||
|
||||
it('only returns unique values', function () {
|
||||
table = {
|
||||
columns: [{ id: '0' }],
|
||||
rows: [
|
||||
{ '0': 'hello' },
|
||||
{ '0': 'world' },
|
||||
{ '0': 'hello' },
|
||||
{ '0': 'world' },
|
||||
{ '0': 'foo' },
|
||||
{ '0': 'bar' },
|
||||
{ '0': 'baz' },
|
||||
{ '0': 'hello' },
|
||||
],
|
||||
};
|
||||
initXAxis(chart, table);
|
||||
expect(chart.xAxisOrderedValues).to.eql(['hello', 'world', 'foo', 'bar', 'baz']);
|
||||
});
|
||||
|
||||
it('returns the defaultValue if using fake x aspect', function () {
|
||||
chart = {
|
||||
aspects: {
|
||||
x: [makeFakeXAspect()],
|
||||
}
|
||||
};
|
||||
initXAxis(chart, table);
|
||||
expect(chart.xAxisOrderedValues).to.eql(['_all']);
|
||||
});
|
||||
});
|
||||
|
||||
it('reads the interval param from the x agg', function () {
|
||||
const chart = _.cloneDeep(baseChart);
|
||||
chart.aspects.x[0].params.date = true;
|
||||
chart.aspects.x[0].params.interval = 10;
|
||||
initXAxis(chart);
|
||||
initXAxis(chart, table);
|
||||
expect(chart)
|
||||
.to.have.property('xAxisLabel', 'label')
|
||||
.and.have.property('xAxisFormat', chart.aspects.x[0].format)
|
||||
|
|
|
@ -20,13 +20,14 @@
|
|||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
export function makeFakeXAspect() {
|
||||
|
||||
return {
|
||||
accessor: -1,
|
||||
title: i18n.translate('common.ui.aggResponse.allDocsTitle', {
|
||||
defaultMessage: 'All docs'
|
||||
}),
|
||||
params: {},
|
||||
params: {
|
||||
defaultValue: '_all',
|
||||
},
|
||||
format: {}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,9 +17,13 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { uniq } from 'lodash';
|
||||
|
||||
export function initXAxis(chart) {
|
||||
export function initXAxis(chart, table) {
|
||||
const x = chart.aspects.x[0];
|
||||
chart.xAxisOrderedValues = x.accessor === -1
|
||||
? [x.params.defaultValue]
|
||||
: uniq(table.rows.map(r => r[x.accessor]));
|
||||
chart.xAxisFormat = x.format;
|
||||
chart.xAxisLabel = x.title;
|
||||
if (x.params.date) {
|
||||
|
|
|
@ -28,10 +28,9 @@ export const buildPointSeriesData = (table, dimensions) => {
|
|||
aspects: getAspects(table, dimensions),
|
||||
};
|
||||
|
||||
initXAxis(chart);
|
||||
initXAxis(chart, table);
|
||||
initYAxis(chart);
|
||||
|
||||
|
||||
if (chart.aspects.x[0].params.date) {
|
||||
orderedDateAxis(chart);
|
||||
}
|
||||
|
|
|
@ -29,32 +29,16 @@ import { VislibComponentsZeroInjectionZeroFilledArrayProvider } from '../../comp
|
|||
import { VislibComponentsZeroInjectionZeroFillDataArrayProvider } from '../../components/zero_injection/zero_fill_data_array';
|
||||
|
||||
describe('Vislib Zero Injection Module Test Suite', function () {
|
||||
const dateHistogramRows = [
|
||||
{
|
||||
'label': 'html',
|
||||
'values': [
|
||||
{ 'x': 1418410560000, 'y': 2 },
|
||||
{ 'x': 1418410620000, 'y': 4 },
|
||||
{ 'x': 1418410680000, 'y': 1 },
|
||||
{ 'x': 1418410740000, 'y': 5 },
|
||||
{ 'x': 1418410800000, 'y': 2 },
|
||||
{ 'x': 1418410860000, 'y': 3 },
|
||||
{ 'x': 1418410920000, 'y': 2 }
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'css',
|
||||
'values': [
|
||||
{ 'x': 1418410560000, 'y': 1 },
|
||||
{ 'x': 1418410620000, 'y': 3 },
|
||||
{ 'x': 1418410680000, 'y': 1 },
|
||||
{ 'x': 1418410740000, 'y': 4 },
|
||||
{ 'x': 1418410800000, 'y': 2 }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const dateHistogramRowsObj = {
|
||||
xAxisOrderedValues: [
|
||||
1418410560000,
|
||||
1418410620000,
|
||||
1418410680000,
|
||||
1418410740000,
|
||||
1418410800000,
|
||||
1418410860000,
|
||||
1418410920000,
|
||||
],
|
||||
series: [
|
||||
{
|
||||
'label': 'html',
|
||||
|
@ -80,22 +64,10 @@ describe('Vislib Zero Injection Module Test Suite', function () {
|
|||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
const seriesData = [
|
||||
{
|
||||
label: '200',
|
||||
values: [
|
||||
{ x: 'v1', y: 234 },
|
||||
{ x: 'v2', y: 34 },
|
||||
{ x: 'v3', y: 834 },
|
||||
{ x: 'v4', y: 1234 },
|
||||
{ x: 'v5', y: 4 }
|
||||
]
|
||||
}
|
||||
];
|
||||
const dateHistogramRows = dateHistogramRowsObj.series;
|
||||
|
||||
const seriesDataObj = {
|
||||
xAxisOrderedValues: ['v1', 'v2', 'v3', 'v4', 'v5'],
|
||||
series: [
|
||||
{
|
||||
label: '200',
|
||||
|
@ -109,35 +81,10 @@ describe('Vislib Zero Injection Module Test Suite', function () {
|
|||
}
|
||||
]
|
||||
};
|
||||
|
||||
const multiSeriesData = [
|
||||
{
|
||||
label: '200',
|
||||
values: [
|
||||
{ x: '1', y: 234 },
|
||||
{ x: '2', y: 34 },
|
||||
{ x: '3', y: 834 },
|
||||
{ x: '4', y: 1234 },
|
||||
{ x: '5', y: 4 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '404',
|
||||
values: [
|
||||
{ x: '1', y: 1234 },
|
||||
{ x: '3', y: 234 },
|
||||
{ x: '5', y: 34 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '503',
|
||||
values: [
|
||||
{ x: '3', y: 834 }
|
||||
]
|
||||
}
|
||||
];
|
||||
const seriesData = seriesDataObj.series;
|
||||
|
||||
const multiSeriesDataObj = {
|
||||
xAxisOrderedValues: ['1', '2', '3', '4', '5'],
|
||||
series: [
|
||||
{
|
||||
label: '200',
|
||||
|
@ -165,35 +112,10 @@ describe('Vislib Zero Injection Module Test Suite', function () {
|
|||
}
|
||||
]
|
||||
};
|
||||
|
||||
const multiSeriesNumberedData = [
|
||||
{
|
||||
label: '200',
|
||||
values: [
|
||||
{ x: 1, y: 234 },
|
||||
{ x: 2, y: 34 },
|
||||
{ x: 3, y: 834 },
|
||||
{ x: 4, y: 1234 },
|
||||
{ x: 5, y: 4 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '404',
|
||||
values: [
|
||||
{ x: 1, y: 1234 },
|
||||
{ x: 3, y: 234 },
|
||||
{ x: 5, y: 34 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '503',
|
||||
values: [
|
||||
{ x: 3, y: 834 }
|
||||
]
|
||||
}
|
||||
];
|
||||
const multiSeriesData = multiSeriesDataObj.series;
|
||||
|
||||
const multiSeriesNumberedDataObj = {
|
||||
xAxisOrderedValues: [1, 2, 3, 4, 5],
|
||||
series: [
|
||||
{
|
||||
label: '200',
|
||||
|
@ -221,6 +143,7 @@ describe('Vislib Zero Injection Module Test Suite', function () {
|
|||
}
|
||||
]
|
||||
};
|
||||
const multiSeriesNumberedData = multiSeriesNumberedDataObj.series;
|
||||
|
||||
const emptyObject = {};
|
||||
const str = 'string';
|
||||
|
@ -320,6 +243,37 @@ describe('Vislib Zero Injection Module Test Suite', function () {
|
|||
expect(numberedResults[4]).to.be(5);
|
||||
});
|
||||
|
||||
it('should return an array of values that preserve the index from xAxisOrderedValues', function () {
|
||||
const data = {
|
||||
xAxisOrderedValues: ['1', '2', '3', '4', '5'],
|
||||
series: [
|
||||
{
|
||||
label: '200',
|
||||
values: [
|
||||
{ x: '2', y: 34 },
|
||||
{ x: '4', y: 1234 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '404',
|
||||
values: [
|
||||
{ x: '1', y: 1234 },
|
||||
{ x: '3', y: 234 },
|
||||
{ x: '5', y: 34 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '503',
|
||||
values: [
|
||||
{ x: '3', y: 834 }
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
const result = orderXValues(data);
|
||||
expect(result).to.eql(['1', '2', '3', '4', '5']);
|
||||
});
|
||||
|
||||
it('should return an array of values ordered by their sum when orderBucketsBySum is true', function () {
|
||||
const orderBucketsBySum = true;
|
||||
results = orderXValues(multiSeriesDataObj, orderBucketsBySum);
|
||||
|
|
|
@ -41,6 +41,18 @@ describe('Vislib xAxis Class Test Suite', function () {
|
|||
max: 1408734982458,
|
||||
min: 1408734082458
|
||||
},
|
||||
xAxisOrderedValues: [
|
||||
1408734060000,
|
||||
1408734090000,
|
||||
1408734120000,
|
||||
1408734150000,
|
||||
1408734180000,
|
||||
1408734210000,
|
||||
1408734240000,
|
||||
1408734270000,
|
||||
1408734300000,
|
||||
1408734330000,
|
||||
],
|
||||
series: [
|
||||
{
|
||||
label: 'Count',
|
||||
|
|
|
@ -41,6 +41,18 @@ describe('Vislib _chart Test Suite', function () {
|
|||
max: 1408734982458,
|
||||
min: 1408734082458
|
||||
},
|
||||
xAxisOrderedValues: [
|
||||
1408734060000,
|
||||
1408734090000,
|
||||
1408734120000,
|
||||
1408734150000,
|
||||
1408734180000,
|
||||
1408734210000,
|
||||
1408734240000,
|
||||
1408734270000,
|
||||
1408734300000,
|
||||
1408734330000,
|
||||
],
|
||||
series: [
|
||||
{
|
||||
values: [
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import { isObject, isNumber } from 'lodash';
|
||||
import { VislibComponentsZeroInjectionFlattenDataProvider } from './flatten_data';
|
||||
|
||||
export function VislibComponentsZeroInjectionUniqKeysProvider(Private) {
|
||||
|
@ -32,7 +32,7 @@ export function VislibComponentsZeroInjectionUniqKeysProvider(Private) {
|
|||
*/
|
||||
|
||||
return function (obj) {
|
||||
if (!_.isObject(obj)) {
|
||||
if (!isObject(obj)) {
|
||||
throw new TypeError('UniqueXValuesUtilService expects an object');
|
||||
}
|
||||
|
||||
|
@ -46,30 +46,45 @@ export function VislibComponentsZeroInjectionUniqKeysProvider(Private) {
|
|||
charts = [obj];
|
||||
}
|
||||
|
||||
const isDate = charts.every(function (chart) {
|
||||
const isDate = charts.every(chart => {
|
||||
return chart.ordered && chart.ordered.date;
|
||||
});
|
||||
|
||||
const isOrdered = charts.every(function (chart) {
|
||||
const isOrdered = charts.every(chart => {
|
||||
return chart.ordered;
|
||||
});
|
||||
|
||||
flattenedData.forEach(function (d, i) {
|
||||
const key = d.x;
|
||||
const prev = uniqueXValues.get(key);
|
||||
let sum = d.y;
|
||||
|
||||
if (prev) {
|
||||
i = Math.min(i, prev.index);
|
||||
sum += prev.sum;
|
||||
}
|
||||
|
||||
const initXValue = (key, index) => {
|
||||
uniqueXValues.set(key, {
|
||||
index: i,
|
||||
isDate: isDate,
|
||||
isOrdered: isOrdered,
|
||||
isNumber: _.isNumber(key),
|
||||
sum: sum
|
||||
index,
|
||||
isDate,
|
||||
isOrdered,
|
||||
isNumber: isNumber(key),
|
||||
sum: 0,
|
||||
});
|
||||
};
|
||||
|
||||
// Populate `uniqueXValues` with the preserved x key order from the
|
||||
// original tabified data. `flattenedData` only contains the first
|
||||
// non-zero values in each series, and therefore is not guaranteed
|
||||
// to match the order that came back from ES.
|
||||
if (obj.xAxisOrderedValues) {
|
||||
obj.xAxisOrderedValues.forEach(initXValue);
|
||||
}
|
||||
|
||||
// Generate a sum for each value
|
||||
flattenedData.forEach(d => {
|
||||
const key = d.x;
|
||||
let prev = uniqueXValues.get(key);
|
||||
if (!prev) {
|
||||
// Value doesn't exist in xAxisOrderedValues, so we create it
|
||||
// and index it at the end.
|
||||
initXValue(key, uniqueXValues.size);
|
||||
prev = uniqueXValues.get(key);
|
||||
}
|
||||
uniqueXValues.set(key, {
|
||||
...prev,
|
||||
sum: prev.sum + d.y,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import _ from 'lodash';
|
|||
|
||||
export function VislibTypesPointSeries() {
|
||||
|
||||
const createSerieFromParams = (cfg, seri) => {
|
||||
const createSeriesFromParams = (cfg, seri) => {
|
||||
const matchingSeriesParams = cfg.seriesParams ? cfg.seriesParams.find(seriConfig => {
|
||||
return seri.id === seriConfig.data.id;
|
||||
}) : null;
|
||||
|
@ -55,7 +55,7 @@ export function VislibTypesPointSeries() {
|
|||
type: 'point_series',
|
||||
addTimeMarker: cfg.addTimeMarker,
|
||||
series: _.map(series, (seri) => {
|
||||
return createSerieFromParams(cfg, seri);
|
||||
return createSeriesFromParams(cfg, seri);
|
||||
})
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue