diff --git a/src/fixtures/vislib/mock_data/date_histogram/_columns.js b/src/fixtures/vislib/mock_data/date_histogram/_columns.js index 60166ba592684..b5b14c279b40e 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_columns.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_columns.js @@ -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 }; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_rows.js b/src/fixtures/vislib/mock_data/date_histogram/_rows.js index b9b6df6c0916a..98609d8ffbcd3 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_rows.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_rows.js @@ -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 }; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_rows_series_with_holes.js b/src/fixtures/vislib/mock_data/date_histogram/_rows_series_with_holes.js index 144ab06ee9ce0..4ca631c7fc497 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_rows_series_with_holes.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_rows_series_with_holes.js @@ -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, + ], }; diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series.js b/src/fixtures/vislib/mock_data/date_histogram/_series.js index b26c687c6c86e..13e2ab7b7fb1a 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_series.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_series.js @@ -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); }, diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series_monthly_interval.js b/src/fixtures/vislib/mock_data/date_histogram/_series_monthly_interval.js index 791b072f2cd03..6b7c574ab5551 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_series_monthly_interval.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_series_monthly_interval.js @@ -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); }, diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js b/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js index 15d08b1b0ac7f..ff5cd05b2f2d4 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_series_neg.js @@ -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); }, diff --git a/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js b/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js index f85bb2b042d6f..06d9b31dc6b57 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_series_pos_neg.js @@ -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); }, diff --git a/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js b/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js index 8c77336f997b7..5208c7e996cd8 100644 --- a/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js +++ b/src/fixtures/vislib/mock_data/date_histogram/_stacked_series.js @@ -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); }, diff --git a/src/fixtures/vislib/mock_data/filters/_columns.js b/src/fixtures/vislib/mock_data/filters/_columns.js index 372a887a4a45b..041fad2ed15b9 100644 --- a/src/fixtures/vislib/mock_data/filters/_columns.js +++ b/src/fixtures/vislib/mock_data/filters/_columns.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/filters/_series.js b/src/fixtures/vislib/mock_data/filters/_series.js index 6b07dc1ec7a51..2a2d14d59b67e 100644 --- a/src/fixtures/vislib/mock_data/filters/_series.js +++ b/src/fixtures/vislib/mock_data/filters/_series.js @@ -24,6 +24,7 @@ export default { } ], 'hits': 171454, + 'xAxisOrderedValues': ['css', 'html', 'png'], 'xAxisFormatter': function (val) { if (_.isObject(val)) { return JSON.stringify(val); diff --git a/src/fixtures/vislib/mock_data/histogram/_columns.js b/src/fixtures/vislib/mock_data/histogram/_columns.js index 422e2b56d4c05..96d2cfd174579 100644 --- a/src/fixtures/vislib/mock_data/histogram/_columns.js +++ b/src/fixtures/vislib/mock_data/histogram/_columns.js @@ -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 }; diff --git a/src/fixtures/vislib/mock_data/histogram/_rows.js b/src/fixtures/vislib/mock_data/histogram/_rows.js index 8a9a08db2c29f..27050030ebdfd 100644 --- a/src/fixtures/vislib/mock_data/histogram/_rows.js +++ b/src/fixtures/vislib/mock_data/histogram/_rows.js @@ -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 }; diff --git a/src/fixtures/vislib/mock_data/histogram/_series.js b/src/fixtures/vislib/mock_data/histogram/_series.js index 90995a00a11ef..5c7554db2060d 100644 --- a/src/fixtures/vislib/mock_data/histogram/_series.js +++ b/src/fixtures/vislib/mock_data/histogram/_series.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js b/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js index 45b6c0e72f483..b05e258133963 100644 --- a/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js +++ b/src/fixtures/vislib/mock_data/not_enough_data/_one_point.js @@ -16,6 +16,7 @@ export default { } ], 'hits': 274, + 'xAxisOrderedValues': ['_all'], 'xAxisFormatter': function (val) { if (_.isObject(val)) { return JSON.stringify(val); diff --git a/src/fixtures/vislib/mock_data/range/_columns.js b/src/fixtures/vislib/mock_data/range/_columns.js index d75f80d8fcec8..d6f3fc4361f32 100644 --- a/src/fixtures/vislib/mock_data/range/_columns.js +++ b/src/fixtures/vislib/mock_data/range/_columns.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/range/_rows.js b/src/fixtures/vislib/mock_data/range/_rows.js index 35a938851b130..b420565b1c96b 100644 --- a/src/fixtures/vislib/mock_data/range/_rows.js +++ b/src/fixtures/vislib/mock_data/range/_rows.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/range/_series.js b/src/fixtures/vislib/mock_data/range/_series.js index 34454bbb2020b..2ac35efadc8f2 100644 --- a/src/fixtures/vislib/mock_data/range/_series.js +++ b/src/fixtures/vislib/mock_data/range/_series.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/significant_terms/_columns.js b/src/fixtures/vislib/mock_data/significant_terms/_columns.js index feae108fb558d..5b1e29ac0d54a 100644 --- a/src/fixtures/vislib/mock_data/significant_terms/_columns.js +++ b/src/fixtures/vislib/mock_data/significant_terms/_columns.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/significant_terms/_rows.js b/src/fixtures/vislib/mock_data/significant_terms/_rows.js index 43c0ec2f0d48d..147eb691eb67b 100644 --- a/src/fixtures/vislib/mock_data/significant_terms/_rows.js +++ b/src/fixtures/vislib/mock_data/significant_terms/_rows.js @@ -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); diff --git a/src/fixtures/vislib/mock_data/stacked/_stacked.js b/src/fixtures/vislib/mock_data/stacked/_stacked.js index 37410f393b3a0..228a22ed534d5 100644 --- a/src/fixtures/vislib/mock_data/stacked/_stacked.js +++ b/src/fixtures/vislib/mock_data/stacked/_stacked.js @@ -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', diff --git a/src/fixtures/vislib/mock_data/terms/_columns.js b/src/fixtures/vislib/mock_data/terms/_columns.js index fdcaf9987351d..4683640725f2a 100644 --- a/src/fixtures/vislib/mock_data/terms/_columns.js +++ b/src/fixtures/vislib/mock_data/terms/_columns.js @@ -141,5 +141,6 @@ export default { } } ], + 'xAxisOrderedValues': ['jpg', 'css', 'png', 'gif', 'php'], 'hits': 171462 }; diff --git a/src/fixtures/vislib/mock_data/terms/_rows.js b/src/fixtures/vislib/mock_data/terms/_rows.js index 7564258ddee8a..2b4ee83eca44c 100644 --- a/src/fixtures/vislib/mock_data/terms/_rows.js +++ b/src/fixtures/vislib/mock_data/terms/_rows.js @@ -95,5 +95,6 @@ export default { } } ], + 'xAxisOrderedValues': ['jpg', 'css', 'png', 'gif', 'php'], 'hits': 171458 }; diff --git a/src/fixtures/vislib/mock_data/terms/_series.js b/src/fixtures/vislib/mock_data/terms/_series.js index 90db8af86fa57..f717012d430cf 100644 --- a/src/fixtures/vislib/mock_data/terms/_series.js +++ b/src/fixtures/vislib/mock_data/terms/_series.js @@ -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': [ { diff --git a/src/fixtures/vislib/mock_data/terms/_seriesMultiple.js b/src/fixtures/vislib/mock_data/terms/_seriesMultiple.js index 026404bd7f359..6319daf456661 100644 --- a/src/fixtures/vislib/mock_data/terms/_seriesMultiple.js +++ b/src/fixtures/vislib/mock_data/terms/_seriesMultiple.js @@ -1,6 +1,7 @@ import _ from 'lodash'; export default { + 'xAxisOrderedValues': ['_all'], 'yAxisLabel': 'Count', 'zAxisLabel': 'machine.os.raw: Descending', 'yScale': null, diff --git a/src/ui/public/agg_response/point_series/__tests__/_fake_x_aspect.js b/src/ui/public/agg_response/point_series/__tests__/_fake_x_aspect.js index 3b6ac3b31d9e6..1bb030f3638bb 100644 --- a/src/ui/public/agg_response/point_series/__tests__/_fake_x_aspect.js +++ b/src/ui/public/agg_response/point_series/__tests__/_fake_x_aspect.js @@ -40,5 +40,6 @@ describe('makeFakeXAspect', function () { .and.to.have.property('title', 'All docs') .and.to.have.property('hasNoDsl', true); + expect(aspect.params).to.have.property('defaultValue', '_all'); }); }); diff --git a/src/ui/public/agg_response/point_series/__tests__/_init_x_axis.js b/src/ui/public/agg_response/point_series/__tests__/_init_x_axis.js index 43872dba8af54..b0ec05dfe9bb4 100644 --- a/src/ui/public/agg_response/point_series/__tests__/_init_x_axis.js +++ b/src/ui/public/agg_response/point_series/__tests__/_init_x_axis.js @@ -25,41 +25,58 @@ describe('initXAxis', function () { const field = {}; const indexPattern = {}; + let chart; + let table; - const baseChart = { - aspects: { - x: { - aggConfig: { - fieldFormatter: _.constant({}), - write: _.constant({ params: {} }), - aggConfigs: {}, - getIndexPattern: () => { - return indexPattern; + beforeEach(function () { + chart = { + aspects: { + x: { + aggConfig: { + fieldFormatter: _.constant({}), + write: _.constant({ params: {} }), + aggConfigs: {}, + getIndexPattern: () => { + return indexPattern; + }, + type: {} }, - type: {} - }, - title: 'label' + title: 'label', + params: { + defaultValue: '_all', + }, + i: 0, + } } - } - }; + }; + + 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('xAxisFormatter', chart.aspects.x.aggConfig.fieldFormatter()); }); it('makes the chart ordered if the agg is ordered', function () { - const chart = _.cloneDeep(baseChart); chart.aspects.x.aggConfig.type.ordered = true; chart.aspects.x.aggConfig.params = { field: field }; chart.aspects.x.aggConfig.aggConfigs.indexPattern = indexPattern; - initXAxis(chart); + initXAxis(chart, table); expect(chart) .to.have.property('xAxisLabel', 'label') .and.have.property('xAxisFormatter', chart.aspects.x.aggConfig.fieldFormatter()) @@ -72,8 +89,44 @@ describe('initXAxis', function () { .and.not.have.property('interval'); }); + 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.i = -1; + chart.aspects.x.params.defaultValue = '_all'; + 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.aggConfig.type.ordered = true; chart.aspects.x.aggConfig.write = _.constant({ params: { interval: 10 } }); chart.aspects.x.aggConfig.params = { @@ -81,7 +134,7 @@ describe('initXAxis', function () { }; chart.aspects.x.aggConfig.aggConfigs.indexPattern = indexPattern; - initXAxis(chart); + initXAxis(chart, table); expect(chart) .to.have.property('xAxisLabel', 'label') .and.have.property('xAxisFormatter', chart.aspects.x.aggConfig.fieldFormatter()) diff --git a/src/ui/public/agg_response/point_series/_fake_x_aspect.js b/src/ui/public/agg_response/point_series/_fake_x_aspect.js index dbea0d4f7bc9b..64070a7d0d089 100644 --- a/src/ui/public/agg_response/point_series/_fake_x_aspect.js +++ b/src/ui/public/agg_response/point_series/_fake_x_aspect.js @@ -40,5 +40,8 @@ export function makeFakeXAspect() { i: -1, aggConfig: fake, title: fake.makeLabel(), + params: { + defaultValue: '_all', + }, }; } diff --git a/src/ui/public/agg_response/point_series/_init_x_axis.js b/src/ui/public/agg_response/point_series/_init_x_axis.js index 2a37bbd151987..637516ba42e6d 100644 --- a/src/ui/public/agg_response/point_series/_init_x_axis.js +++ b/src/ui/public/agg_response/point_series/_init_x_axis.js @@ -17,11 +17,15 @@ * under the License. */ +import { uniq } from 'lodash'; -export function initXAxis(chart) { +export function initXAxis(chart, table) { const x = chart.aspects.x; chart.xAxisFormatter = x.aggConfig ? x.aggConfig.fieldFormatter() : String; chart.xAxisLabel = x.title; + chart.xAxisOrderedValues = x.i === -1 + ? [x.params.defaultValue] + : uniq(table.rows.map(r => r[x.i])); if (!x.aggConfig || !x.aggConfig.type.ordered) return; diff --git a/src/ui/public/agg_response/point_series/point_series.js b/src/ui/public/agg_response/point_series/point_series.js index 10cbd4726034e..9c2054a7b6335 100644 --- a/src/ui/public/agg_response/point_series/point_series.js +++ b/src/ui/public/agg_response/point_series/point_series.js @@ -34,7 +34,7 @@ export function AggResponsePointSeriesProvider(Private) { chart.tooltipFormatter = tooltipFormatter; - initXAxis(chart); + initXAxis(chart, table); initYAxis(chart); const datedX = aspects.x.aggConfig.type.ordered && aspects.x.aggConfig.type.ordered.date; diff --git a/src/ui/public/vislib/__tests__/components/zero_injection.js b/src/ui/public/vislib/__tests__/components/zero_injection.js index abadb47e74ad4..8cf0a2bdfa553 100644 --- a/src/ui/public/vislib/__tests__/components/zero_injection.js +++ b/src/ui/public/vislib/__tests__/components/zero_injection.js @@ -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); diff --git a/src/ui/public/vislib/__tests__/lib/x_axis.js b/src/ui/public/vislib/__tests__/lib/x_axis.js index ca8c64039aa7a..d55259132a794 100644 --- a/src/ui/public/vislib/__tests__/lib/x_axis.js +++ b/src/ui/public/vislib/__tests__/lib/x_axis.js @@ -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', diff --git a/src/ui/public/vislib/__tests__/visualizations/chart.js b/src/ui/public/vislib/__tests__/visualizations/chart.js index cf6dea67a09cf..5a9cbc0494213 100644 --- a/src/ui/public/vislib/__tests__/visualizations/chart.js +++ b/src/ui/public/vislib/__tests__/visualizations/chart.js @@ -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: [ diff --git a/src/ui/public/vislib/components/zero_injection/uniq_keys.js b/src/ui/public/vislib/components/zero_injection/uniq_keys.js index fa2a3c0cf2ac0..58f1124f2b774 100644 --- a/src/ui/public/vislib/components/zero_injection/uniq_keys.js +++ b/src/ui/public/vislib/components/zero_injection/uniq_keys.js @@ -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; + const initXValue = (key, index) => { + uniqueXValues.set(key, { + index, + isDate, + isOrdered, + isNumber: isNumber(key), + sum: 0, + }); + }; - if (prev) { - i = Math.min(i, prev.index); - sum += prev.sum; - } + // 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, { - index: i, - isDate: isDate, - isOrdered: isOrdered, - isNumber: _.isNumber(key), - sum: sum + ...prev, + sum: prev.sum + d.y, }); }); diff --git a/src/ui/public/vislib/lib/types/point_series.js b/src/ui/public/vislib/lib/types/point_series.js index 36df39d39d183..1edddbd0f223d 100644 --- a/src/ui/public/vislib/lib/types/point_series.js +++ b/src/ui/public/vislib/lib/types/point_series.js @@ -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.aggId === 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); }) }; };