Skip to content

Commit

Permalink
Add numeral custom format + update contributors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Charlot committed Oct 9, 2018
1 parent 539ebda commit 1e6529a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[<img src="https://avatars0.githubusercontent.com/u/16384428?s=100&v=4" width="100"/><br /><sub><b>Gustavo Matheus</b></sub>](https://github.com/gmatheus)

[<img src="https://avatars0.githubusercontent.com/u/41620871?s=100&v=4" width="100"/><br /><sub><b>itamarm10</b></sub>](https://github.com/itamarm10)


<table>
<tr>
<td align="center"><a href="https://github.com/gmatheus"><img src="https://avatars0.githubusercontent.com/u/16384428?s=100&v=4" width="100" /><br><sub><b>Gustavo Matheus</b></a></td>
<td align="center"><a href="https://github.com/itamarm10"><img src="https://avatars0.githubusercontent.com/u/41620871?s=100&v=4" width="100"/><br /><sub><b>itamarm10</b></sub></a></td>
<td align="center"><a href="https://github.com/joeyJsonar"><img src="https://avatars0.githubusercontent.com/u/33907626?s=100&v=4" width="100"/><br /><sub><b>joeyJsonar</b></sub></a></td>
</tr>
</table>

# License
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 6 additions & 0 deletions public/agg_types/formatter.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
class="form-control">
</select>
</div>
<div class="form-group" ng-show="agg.params.formatter === 'numeral'">
<label>Numeral format</label>
<div>
<input type="text" ng-model="agg.params.numeralFormat" class="form-control" />
</div>
</div>
28 changes: 24 additions & 4 deletions public/agg_types/formula.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion public/decorators/response_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1e6529a

Please sign in to comment.