Introduce date histogram time base configuration to EditorConfig (#22344)

* Add `default` and `baseInterval` configuration ability to date histogram EditorConfig
* Change EditorConfig `warning` to `help`, show `help` below date histogram and histogram interval inputs
This commit is contained in:
Jen Huang 2018-09-07 12:38:31 -07:00 committed by GitHub
parent 44475231a6
commit 0ed2623ce3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 518 additions and 42 deletions

View file

@ -5,8 +5,9 @@
"license": "Apache-2.0",
"private": true,
"main": "target/index.js",
"typings": "target/index.d.ts",
"scripts": {
"build": "babel src --out-dir target",
"build": "babel src --out-dir target --copy-files",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},

29
packages/kbn-datemath/src/index.d.ts vendored Normal file
View file

@ -0,0 +1,29 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
declare module '@kbn/datemath' {
const dateMath: {
parse: any;
unitsMap: any;
units: string[];
unitsAsc: string[];
unitsDesc: string[];
};
export default dateMath;
}

View file

@ -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' }, // TODO: moment duration does not support quarter
y: { weight: 9, type: 'calendar' },
};
const units = Object.keys(unitsMap).sort((a, b) => unitsMap[b].weight - unitsMap[a].weight);
const unitsDesc = [...units];
const unitsAsc = [...units].reverse();
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),

View file

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "./target"
},
"include": [
"./src/**/*.ts"
]
}