diff --git a/src/ui/public/agg_table/__tests__/_table.js b/src/ui/public/agg_table/__tests__/_table.js index 7369f6ba9907a..18954f36e5f92 100644 --- a/src/ui/public/agg_table/__tests__/_table.js +++ b/src/ui/public/agg_table/__tests__/_table.js @@ -164,7 +164,7 @@ describe('AggTable Directive', function () { it('as min', function () { totalsRowTest('min', [ '', - 'September 28th 2014, 00:00:00.000', + '2014-09-28', '9,283', 'September 28th 2014, 00:00:00.000', '1', @@ -174,7 +174,7 @@ describe('AggTable Directive', function () { it('as max', function () { totalsRowTest('max', [ '', - 'October 3rd 2014, 00:00:00.000', + '2014-10-03', '220,943', 'October 3rd 2014, 00:00:00.000', '239', diff --git a/src/ui/public/agg_types/buckets/date_histogram.js b/src/ui/public/agg_types/buckets/date_histogram.js index 8ae5401bfef53..4f13f1b2a9a74 100644 --- a/src/ui/public/agg_types/buckets/date_histogram.js +++ b/src/ui/public/agg_types/buckets/date_histogram.js @@ -62,6 +62,9 @@ export function AggTypesBucketsDateHistogramProvider(timefilter, config, Private } }; }, + getFormat: function (agg) { + return agg.buckets.getScaledDateFormatter(); + }, params: [ { name: 'field', diff --git a/src/ui/public/time_buckets/time_buckets.js b/src/ui/public/time_buckets/time_buckets.js index 83a725000790a..e6420a83ca5fb 100644 --- a/src/ui/public/time_buckets/time_buckets.js +++ b/src/ui/public/time_buckets/time_buckets.js @@ -3,10 +3,13 @@ import moment from 'moment'; import { parseInterval } from 'ui/utils/parse_interval'; import { TimeBucketsCalcAutoIntervalProvider } from 'ui/time_buckets/calc_auto_interval'; import { TimeBucketsCalcEsIntervalProvider } from 'ui/time_buckets/calc_es_interval'; +import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; export function TimeBucketsProvider(Private, timefilter, config) { const calcAuto = Private(TimeBucketsCalcAutoIntervalProvider); const calcEsInterval = Private(TimeBucketsCalcEsIntervalProvider); + const fieldFormats = Private(RegistryFieldFormatsProvider); + const getConfig = (...args) => config.get(...args); function isValidMoment(m) { return m && ('isValid' in m) && m.isValid(); @@ -274,6 +277,13 @@ export function TimeBucketsProvider(Private, timefilter, config) { return config.get('dateFormat'); }; + TimeBuckets.prototype.getScaledDateFormatter = function () { + const DateFieldFormat = fieldFormats.getType('date'); + return new DateFieldFormat({ + pattern: this.getScaledDateFormat() + }, getConfig); + }; + TimeBuckets.__cached__ = function (self) { let cache = {}; diff --git a/src/ui/public/vis/__tests__/_agg_config.js b/src/ui/public/vis/__tests__/_agg_config.js index ecfd4fdb25a72..f0a21d8d952ca 100644 --- a/src/ui/public/vis/__tests__/_agg_config.js +++ b/src/ui/public/vis/__tests__/_agg_config.js @@ -414,21 +414,9 @@ describe('AggConfig', function () { }); }); - describe('#fieldFormatter', function () { - it('returns the fields format unless the agg type has a custom getFormat handler', function () { - let vis = new Vis(indexPattern, { - type: 'histogram', - aggs: [ - { - type: 'date_histogram', - schema: 'segment', - params: { field: '@timestamp' } - } - ] - }); - expect(vis.aggs[0].fieldFormatter()).to.be(vis.aggs[0].getField().format.getConverterFor()); - - vis = new Vis(indexPattern, { + describe('#fieldFormatter - custom getFormat handler', function () { + it('returns formatter from getFormat handler', function () { + const vis = new Vis(indexPattern, { type: 'metric', aggs: [ { @@ -440,53 +428,43 @@ describe('AggConfig', function () { }); expect(vis.aggs[0].fieldFormatter()).to.be(fieldFormat.getDefaultInstance('number').getConverterFor()); }); + }); - it('returns the string format if the field does not have a format', function () { - const vis = new Vis(indexPattern, { - type: 'histogram', - aggs: [ - { - type: 'date_histogram', - schema: 'segment', - params: { field: '@timestamp' } - } - ] - }); + describe('#fieldFormatter - no custom getFormat handler', function () { + + const visStateAggWithoutCustomGetFormat = { + type: 'table', + aggs: [ + { + type: 'terms', + schema: 'bucket', + params: { field: 'bytes' } + } + ] + }; + let vis; + + beforeEach(function () { + vis = new Vis(indexPattern, visStateAggWithoutCustomGetFormat); + }); + it('returns the field\'s formatter', function () { + expect(vis.aggs[0].fieldFormatter()).to.be(vis.aggs[0].getField().format.getConverterFor()); + }); + + it('returns the string format if the field does not have a format', function () { const agg = vis.aggs[0]; - agg.params.field = { type: 'date', format: null }; + agg.params.field = { type: 'number', format: null }; expect(agg.fieldFormatter()).to.be(fieldFormat.getDefaultInstance('string').getConverterFor()); }); it('returns the string format if their is no field', function () { - const vis = new Vis(indexPattern, { - type: 'histogram', - aggs: [ - { - type: 'date_histogram', - schema: 'segment', - params: { field: '@timestamp' } - } - ] - }); - const agg = vis.aggs[0]; delete agg.params.field; expect(agg.fieldFormatter()).to.be(fieldFormat.getDefaultInstance('string').getConverterFor()); }); it('returns the html converter if "html" is passed in', function () { - const vis = new Vis(indexPattern, { - type: 'histogram', - aggs: [ - { - type: 'avg', - schema: 'metric', - params: { field: 'bytes' } - } - ] - }); - const field = indexPattern.fields.byName.bytes; expect(vis.aggs[0].fieldFormatter('html')).to.be(field.format.getConverterFor('html')); }); diff --git a/test/functional/apps/visualize/_area_chart.js b/test/functional/apps/visualize/_area_chart.js index 4e6eb25274bf5..d4fc8b33b1e92 100644 --- a/test/functional/apps/visualize/_area_chart.js +++ b/test/functional/apps/visualize/_area_chart.js @@ -141,30 +141,30 @@ export default function ({ getService, getPageObjects }) { }); it('should show correct data', function () { - const expectedTableData = [ 'September 20th 2015, 00:00:00.000', '37', - 'September 20th 2015, 03:00:00.000', '202', - 'September 20th 2015, 06:00:00.000', '740', - 'September 20th 2015, 09:00:00.000', '1,437', - 'September 20th 2015, 12:00:00.000', '1,371', - 'September 20th 2015, 15:00:00.000', '751', - 'September 20th 2015, 18:00:00.000', '188', - 'September 20th 2015, 21:00:00.000', '31', - 'September 21st 2015, 00:00:00.000', '42', - 'September 21st 2015, 03:00:00.000', '202', - 'September 21st 2015, 06:00:00.000', '683', - 'September 21st 2015, 09:00:00.000', '1,361', - 'September 21st 2015, 12:00:00.000', '1,415', - 'September 21st 2015, 15:00:00.000', '707', - 'September 21st 2015, 18:00:00.000', '177', - 'September 21st 2015, 21:00:00.000', '27', - 'September 22nd 2015, 00:00:00.000', '32', - 'September 22nd 2015, 03:00:00.000', '175', - 'September 22nd 2015, 06:00:00.000', '707', - 'September 22nd 2015, 09:00:00.000', '1,408', - 'September 22nd 2015, 12:00:00.000', '1,355', - 'September 22nd 2015, 15:00:00.000', '726', - 'September 22nd 2015, 18:00:00.000', '201', - 'September 22nd 2015, 21:00:00.000', '29' + const expectedTableData = [ '2015-09-20 00:00', '37', + '2015-09-20 03:00', '202', + '2015-09-20 06:00', '740', + '2015-09-20 09:00', '1,437', + '2015-09-20 12:00', '1,371', + '2015-09-20 15:00', '751', + '2015-09-20 18:00', '188', + '2015-09-20 21:00', '31', + '2015-09-21 00:00', '42', + '2015-09-21 03:00', '202', + '2015-09-21 06:00', '683', + '2015-09-21 09:00', '1,361', + '2015-09-21 12:00', '1,415', + '2015-09-21 15:00', '707', + '2015-09-21 18:00', '177', + '2015-09-21 21:00', '27', + '2015-09-22 00:00', '32', + '2015-09-22 03:00', '175', + '2015-09-22 06:00', '707', + '2015-09-22 09:00', '1,408', + '2015-09-22 12:00', '1,355', + '2015-09-22 15:00', '726', + '2015-09-22 18:00', '201', + '2015-09-22 21:00', '29' ]; return PageObjects.visualize.collapseChart() diff --git a/test/functional/apps/visualize/_heatmap_chart.js b/test/functional/apps/visualize/_heatmap_chart.js index 93508932319bd..f7aae6f9061d5 100644 --- a/test/functional/apps/visualize/_heatmap_chart.js +++ b/test/functional/apps/visualize/_heatmap_chart.js @@ -94,16 +94,16 @@ export default function ({ getService, getPageObjects }) { it('should show correct data', function () { // this is only the first page of the tabular data. - const expectedChartData = [ 'September 20th 2015, 00:00:00.000', '37', - 'September 20th 2015, 03:00:00.000', '202', - 'September 20th 2015, 06:00:00.000', '740', - 'September 20th 2015, 09:00:00.000', '1,437', - 'September 20th 2015, 12:00:00.000', '1,371', - 'September 20th 2015, 15:00:00.000', '751', - 'September 20th 2015, 18:00:00.000', '188', - 'September 20th 2015, 21:00:00.000', '31', - 'September 21st 2015, 00:00:00.000', '42', - 'September 21st 2015, 03:00:00.000', '202' + const expectedChartData = [ '2015-09-20 00:00', '37', + '2015-09-20 03:00', '202', + '2015-09-20 06:00', '740', + '2015-09-20 09:00', '1,437', + '2015-09-20 12:00', '1,371', + '2015-09-20 15:00', '751', + '2015-09-20 18:00', '188', + '2015-09-20 21:00', '31', + '2015-09-21 00:00', '42', + '2015-09-21 03:00', '202' ]; return PageObjects.visualize.collapseChart() diff --git a/test/functional/apps/visualize/_vertical_bar_chart.js b/test/functional/apps/visualize/_vertical_bar_chart.js index 218f352ca1652..3b952c6e1e540 100644 --- a/test/functional/apps/visualize/_vertical_bar_chart.js +++ b/test/functional/apps/visualize/_vertical_bar_chart.js @@ -93,16 +93,16 @@ export default function ({ getService, getPageObjects }) { it('should show correct data', function () { // this is only the first page of the tabular data. - const expectedChartData = [ 'September 20th 2015, 00:00:00.000', '37', - 'September 20th 2015, 03:00:00.000', '202', - 'September 20th 2015, 06:00:00.000', '740', - 'September 20th 2015, 09:00:00.000', '1,437', - 'September 20th 2015, 12:00:00.000', '1,371', - 'September 20th 2015, 15:00:00.000', '751', - 'September 20th 2015, 18:00:00.000', '188', - 'September 20th 2015, 21:00:00.000', '31', - 'September 21st 2015, 00:00:00.000', '42', - 'September 21st 2015, 03:00:00.000', '202' + const expectedChartData = [ '2015-09-20 00:00', '37', + '2015-09-20 03:00', '202', + '2015-09-20 06:00', '740', + '2015-09-20 09:00', '1,437', + '2015-09-20 12:00', '1,371', + '2015-09-20 15:00', '751', + '2015-09-20 18:00', '188', + '2015-09-20 21:00', '31', + '2015-09-21 00:00', '42', + '2015-09-21 03:00', '202' ]; return PageObjects.visualize.collapseChart()