From 1e6529a8acf199078e6276e8998f680e4806d776 Mon Sep 17 00:00:00 2001 From: Thomas Charlot Date: Tue, 9 Oct 2018 13:50:43 +0200 Subject: [PATCH] Add numeral custom format + update contributors. --- README.md | 12 +++++++----- package.json | 2 +- public/agg_types/formatter.html | 6 ++++++ public/agg_types/formula.js | 28 ++++++++++++++++++++++++---- public/decorators/response_writer.js | 2 +- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 305abd5..9c5def3 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,13 @@ If you find a bug or want to request a feature, please create a [GitHub Issue](h Datasweet Formula is built on [Javascript Expression Evaluator](https://silentmatt.com/javascript-expression-evaluator/) by Silent Matt. # Contributors -[
Gustavo Matheus](https://github.com/gmatheus) - -[
itamarm10](https://github.com/itamarm10) - - + + + + + + +

Gustavo Matheus

itamarm10

joeyJsonar
# License ``` diff --git a/package.json b/package.json index f3c42b9..3d71922 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasweet_formula", - "version": "1.1.0", + "version": "1.1.1", "description": "This Kibana plugin allows calculated metrics on any standard kibana visualizations.", "main": "index.js", "kibana": { diff --git a/public/agg_types/formatter.html b/public/agg_types/formatter.html index eeb7094..eeaeaaf 100644 --- a/public/agg_types/formatter.html +++ b/public/agg_types/formatter.html @@ -7,3 +7,9 @@ class="form-control"> +
+ +
+ +
+
diff --git a/public/agg_types/formula.js b/public/agg_types/formula.js index d929b03..b6c41f6 100644 --- a/public/agg_types/formula.js +++ b/public/agg_types/formula.js @@ -1,15 +1,16 @@ -import { map } from 'lodash'; +import { capitalize, map } from 'lodash'; import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type'; import * as prov from 'ui/registry/field_formats'; import formulaEditor from './formula.html'; import formatterEditor from './formatter.html'; - export function AggTypesMetricsFormulaProvider(Private) { const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider); const fieldFormats = prov.fieldFormats || Private(prov.RegistryFieldFormatsProvider); const defaultValue = null; - const formatters = map(['number', 'percent', 'boolean', 'bytes'], fieldFormats.getType); + const formatters = map(['number', 'percent', 'boolean', 'bytes', 'numeral'], f => { + return { id: f, title: capitalize(f) }; + }); return new MetricAggType({ name: 'datasweet_formula', @@ -30,11 +31,30 @@ export function AggTypesMetricsFormulaProvider(Private) { getFormatters: function () { return formatters; } + }, + { + name: 'numeralFormat' } ], getFormat: function (agg) { const formatterId = agg.params.formatter; - return formatterId ? fieldFormats.getInstance(formatterId) : fieldFormats.getDefaultInstance('number'); + + if (!formatterId) { + return fieldFormats.getDefaultInstance('number'); + } + + if (formatterId === 'numeral') { + const format = agg.params.numeralFormat; + if (!format) { + return fieldFormats.getDefaultInstance('number'); + } + + const FieldFormat = fieldFormats.getType('number'); + const f = new FieldFormat({ pattern: format }); + return f; + } + + return fieldFormats.getInstance(formatterId); }, getValue: function () { return defaultValue; diff --git a/public/decorators/response_writer.js b/public/decorators/response_writer.js index eccce4c..15e2c52 100644 --- a/public/decorators/response_writer.js +++ b/public/decorators/response_writer.js @@ -4,7 +4,7 @@ import { AggResponseFormulaProvider } from './lib/apply_formula'; import { TableTotalFormulaProvider } from './lib/apply_formula_total'; import { applyColumnGroups } from './lib/apply_column_groups'; -export function decorateTabbedAggResponseWriterProvider(Private) { +export function decorateTabbedAggResponseWriterProvider(Private) { const TabbedAggResponseWriter = prov.TabbedAggResponseWriter || Private(prov.TabbedAggResponseWriterProvider); const applyFormulas = Private(AggResponseFormulaProvider); const applyFormulaTotal = Private(TableTotalFormulaProvider);