From 7823369cae4bc2146b796df1d97c840c6df0316c Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 21 Aug 2018 22:31:26 -0700 Subject: [PATCH 1/7] Add `default` and `baseInterval` configuration ability to date histogram EditorConfig --- packages/kbn-datemath/src/index.js | 18 ++- .../agg_types/buckets/date_histogram.js | 5 + .../agg_types/controls/time_interval.html | 3 +- .../public/utils/__tests__/parse_interval.js | 141 +++++++++++------- src/ui/public/utils/parse_interval.js | 29 ++++ src/ui/public/validate_date_interval.js | 20 ++- .../__tests__/lib/least_common_interval.ts | 96 ++++++++++++ .../editors/config/editor_config_providers.ts | 43 +++++- src/ui/public/vis/editors/config/types.ts | 11 +- .../public/vis/editors/default/agg_params.js | 19 ++- .../public/vis/lib/least_common_interval.ts | 78 ++++++++++ 11 files changed, 399 insertions(+), 64 deletions(-) create mode 100644 src/ui/public/vis/__tests__/lib/least_common_interval.ts create mode 100644 src/ui/public/vis/lib/least_common_interval.ts diff --git a/packages/kbn-datemath/src/index.js b/packages/kbn-datemath/src/index.js index 17d91a530fdb38..f82a4324662700 100644 --- a/packages/kbn-datemath/src/index.js +++ b/packages/kbn-datemath/src/index.js @@ -19,9 +19,20 @@ import moment from 'moment'; -const units = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms']; -const unitsDesc = units; -const unitsAsc = [...unitsDesc].reverse(); +const unitsMap = { + ms: { weight: 1, type: 'fixed', base: 1 }, + s: { weight: 2, type: 'fixed', base: 1000 }, + m: { weight: 3, type: 'mixed', base: 1000 * 60 }, + h: { weight: 4, type: 'mixed', base: 1000 * 60 * 60 }, + d: { weight: 5, type: 'mixed', base: 1000 * 60 * 60 * 24 }, + w: { weight: 6, type: 'calendar' }, + M: { weight: 7, type: 'calendar' }, + q: { weight: 8, type: 'calendar' }, + y: { weight: 9, type: 'calendar' }, +}; +const units = Object.keys(unitsMap); +const unitsDesc = [...units].reverse(); +const unitsAsc = [...units]; const isDate = d => Object.prototype.toString.call(d) === '[object Date]'; @@ -142,6 +153,7 @@ function parseDateMath(mathString, time, roundUp) { export default { parse: parse, + unitsMap: Object.freeze(unitsMap), units: Object.freeze(units), unitsAsc: Object.freeze(unitsAsc), unitsDesc: Object.freeze(unitsDesc), diff --git a/src/ui/public/agg_types/buckets/date_histogram.js b/src/ui/public/agg_types/buckets/date_histogram.js index c9c26689f3d539..c80afd6d38851c 100644 --- a/src/ui/public/agg_types/buckets/date_histogram.js +++ b/src/ui/public/agg_types/buckets/date_histogram.js @@ -147,6 +147,11 @@ export const dateHistogramBucketAgg = new BucketAggType({ return isDefaultTimezone ? detectedTimezone || tzOffset : config.get('dateFormat:tz'); }, }, + { + name: 'intervalBase', + default: undefined, + write: _.noop + }, { name: 'customInterval', default: '2h', diff --git a/src/ui/public/agg_types/controls/time_interval.html b/src/ui/public/agg_types/controls/time_interval.html index 1da3e3ddcd39be..4c5ae05dafa914 100644 --- a/src/ui/public/agg_types/controls/time_interval.html +++ b/src/ui/public/agg_types/controls/time_interval.html @@ -9,6 +9,7 @@ > +
+ {{editorConfig.interval.help}} +
diff --git a/src/ui/public/agg_types/controls/time_interval.html b/src/ui/public/agg_types/controls/time_interval.html index 4c5ae05dafa914..4a980f39c727c5 100644 --- a/src/ui/public/agg_types/controls/time_interval.html +++ b/src/ui/public/agg_types/controls/time_interval.html @@ -9,7 +9,7 @@ >