From 7d4f948e049ba2112a792619e1efbc424311e06a Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Mon, 1 Mar 2021 13:12:07 -0600 Subject: [PATCH 1/6] fix endzones in xy charts --- src/plugins/vis_type_xy/public/utils/domain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_type_xy/public/utils/domain.ts b/src/plugins/vis_type_xy/public/utils/domain.ts index a59b2fd20cb5a..6c01e97d678d1 100644 --- a/src/plugins/vis_type_xy/public/utils/domain.ts +++ b/src/plugins/vis_type_xy/public/utils/domain.ts @@ -21,7 +21,7 @@ export const getXDomain = (params: Aspect['params']): DomainRange => { const minInterval = (params as DateHistogramParams | HistogramParams)?.interval ?? undefined; if ((params as DateHistogramParams).date) { - const bounds = getTimefilter().getActiveBounds(); + const bounds = getTimefilter().getBounds(); if (bounds) { return { From 52b7290605fbffe26c4632bffd79684971852e3b Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Tue, 2 Mar 2021 11:17:18 -0600 Subject: [PATCH 2/6] manually enable time filter for date histograms --- src/plugins/vis_type_xy/public/to_ast.ts | 4 ++++ src/plugins/vis_type_xy/public/utils/domain.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/vis_type_xy/public/to_ast.ts b/src/plugins/vis_type_xy/public/to_ast.ts index 7f990b01c2d07..825e5cf14dd70 100644 --- a/src/plugins/vis_type_xy/public/to_ast.ts +++ b/src/plugins/vis_type_xy/public/to_ast.ts @@ -16,6 +16,7 @@ import { DateHistogramParams, Dimensions, HistogramParams, VisParams } from './t import { visName, VisTypeXyExpressionFunctionDefinition } from './xy_vis_fn'; import { XyVisType } from '../common'; import { getEsaggsFn } from './to_ast_esaggs'; +import { getTimefilter } from './services'; export const toExpressionAst: VisToExpressionAst = async (vis, params) => { const schemas = getVisSchemas(vis, params); @@ -32,6 +33,8 @@ export const toExpressionAst: VisToExpressionAst = async (vis, params const responseAggs = vis.data.aggs?.getResponseAggs().filter(({ enabled }) => enabled) ?? []; if (dimensions.x) { + getTimefilter().disableTimeRangeSelector(); + const xAgg = responseAggs[dimensions.x.accessor] as any; if (xAgg.type.name === BUCKET_TYPES.DATE_HISTOGRAM) { (dimensions.x.params as DateHistogramParams).date = true; @@ -42,6 +45,7 @@ export const toExpressionAst: VisToExpressionAst = async (vis, params .duration(esValue, esUnit) .asMilliseconds(); (dimensions.x.params as DateHistogramParams).format = xAgg.buckets.getScaledDateFormat(); + getTimefilter().enableTimeRangeSelector(); } else if (xAgg.type.name === BUCKET_TYPES.HISTOGRAM) { const intervalParam = xAgg.type.paramByName('interval'); const output = { params: {} as any }; diff --git a/src/plugins/vis_type_xy/public/utils/domain.ts b/src/plugins/vis_type_xy/public/utils/domain.ts index 6c01e97d678d1..a59b2fd20cb5a 100644 --- a/src/plugins/vis_type_xy/public/utils/domain.ts +++ b/src/plugins/vis_type_xy/public/utils/domain.ts @@ -21,7 +21,7 @@ export const getXDomain = (params: Aspect['params']): DomainRange => { const minInterval = (params as DateHistogramParams | HistogramParams)?.interval ?? undefined; if ((params as DateHistogramParams).date) { - const bounds = getTimefilter().getBounds(); + const bounds = getTimefilter().getActiveBounds(); if (bounds) { return { From 32dc89c211ee3524237356f3621dd0fcb999e67f Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Tue, 2 Mar 2021 11:20:43 -0600 Subject: [PATCH 3/6] remove disable method --- src/plugins/vis_type_xy/public/to_ast.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/vis_type_xy/public/to_ast.ts b/src/plugins/vis_type_xy/public/to_ast.ts index 825e5cf14dd70..781dab3dcf3c0 100644 --- a/src/plugins/vis_type_xy/public/to_ast.ts +++ b/src/plugins/vis_type_xy/public/to_ast.ts @@ -33,8 +33,6 @@ export const toExpressionAst: VisToExpressionAst = async (vis, params const responseAggs = vis.data.aggs?.getResponseAggs().filter(({ enabled }) => enabled) ?? []; if (dimensions.x) { - getTimefilter().disableTimeRangeSelector(); - const xAgg = responseAggs[dimensions.x.accessor] as any; if (xAgg.type.name === BUCKET_TYPES.DATE_HISTOGRAM) { (dimensions.x.params as DateHistogramParams).date = true; From 12f6752ef5c1a281e768d0fca740449e785de3d7 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Tue, 2 Mar 2021 13:57:05 -0600 Subject: [PATCH 4/6] fix bounds to use xaggs bounds not from timefilter --- src/plugins/vis_type_xy/public/plugin.ts | 2 -- src/plugins/vis_type_xy/public/services.ts | 4 ---- src/plugins/vis_type_xy/public/to_ast.ts | 11 ++++++++-- .../vis_type_xy/public/utils/domain.ts | 20 +++++++++---------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/plugins/vis_type_xy/public/plugin.ts b/src/plugins/vis_type_xy/public/plugin.ts index 75a2f4fb6895c..d414da8f6dc97 100644 --- a/src/plugins/vis_type_xy/public/plugin.ts +++ b/src/plugins/vis_type_xy/public/plugin.ts @@ -18,7 +18,6 @@ import { setDataActions, setFormatService, setThemeService, - setTimefilter, setUISettings, setDocLinks, setPalettesService, @@ -80,7 +79,6 @@ export class VisTypeXyPlugin public start(core: CoreStart, { data }: VisTypeXyPluginStartDependencies) { setFormatService(data.fieldFormats); setDataActions(data.actions); - setTimefilter(data.query.timefilter.timefilter); setDocLinks(core.docLinks); return {}; diff --git a/src/plugins/vis_type_xy/public/services.ts b/src/plugins/vis_type_xy/public/services.ts index 3f6a344091d76..b5dd6152605dc 100644 --- a/src/plugins/vis_type_xy/public/services.ts +++ b/src/plugins/vis_type_xy/public/services.ts @@ -24,10 +24,6 @@ export const [getFormatService, setFormatService] = createGetterSetter< DataPublicPluginStart['fieldFormats'] >('xy data.fieldFormats'); -export const [getTimefilter, setTimefilter] = createGetterSetter< - DataPublicPluginStart['query']['timefilter']['timefilter'] ->('xy data.query.timefilter.timefilter'); - export const [getThemeService, setThemeService] = createGetterSetter( 'xy charts.theme' ); diff --git a/src/plugins/vis_type_xy/public/to_ast.ts b/src/plugins/vis_type_xy/public/to_ast.ts index 781dab3dcf3c0..84331af3a5329 100644 --- a/src/plugins/vis_type_xy/public/to_ast.ts +++ b/src/plugins/vis_type_xy/public/to_ast.ts @@ -16,7 +16,7 @@ import { DateHistogramParams, Dimensions, HistogramParams, VisParams } from './t import { visName, VisTypeXyExpressionFunctionDefinition } from './xy_vis_fn'; import { XyVisType } from '../common'; import { getEsaggsFn } from './to_ast_esaggs'; -import { getTimefilter } from './services'; +import { TimeRangeBounds } from '../../data/common'; export const toExpressionAst: VisToExpressionAst = async (vis, params) => { const schemas = getVisSchemas(vis, params); @@ -43,7 +43,14 @@ export const toExpressionAst: VisToExpressionAst = async (vis, params .duration(esValue, esUnit) .asMilliseconds(); (dimensions.x.params as DateHistogramParams).format = xAgg.buckets.getScaledDateFormat(); - getTimefilter().enableTimeRangeSelector(); + const bounds = xAgg.buckets.getBounds() as TimeRangeBounds | undefined; + + if (bounds && bounds?.min && bounds?.max) { + (dimensions.x.params as DateHistogramParams).bounds = { + min: bounds.min.valueOf(), + max: bounds.max.valueOf(), + }; + } } else if (xAgg.type.name === BUCKET_TYPES.HISTOGRAM) { const intervalParam = xAgg.type.paramByName('interval'); const output = { params: {} as any }; diff --git a/src/plugins/vis_type_xy/public/utils/domain.ts b/src/plugins/vis_type_xy/public/utils/domain.ts index a59b2fd20cb5a..322ffc087766c 100644 --- a/src/plugins/vis_type_xy/public/utils/domain.ts +++ b/src/plugins/vis_type_xy/public/utils/domain.ts @@ -14,22 +14,20 @@ import { DomainRange } from '@elastic/charts'; import { getAdjustedInterval } from '../../../charts/public'; import { Datatable } from '../../../expressions/public'; -import { getTimefilter } from '../services'; import { Aspect, DateHistogramParams, HistogramParams } from '../types'; export const getXDomain = (params: Aspect['params']): DomainRange => { const minInterval = (params as DateHistogramParams | HistogramParams)?.interval ?? undefined; + const bounds = (params as DateHistogramParams).date + ? (params as DateHistogramParams).bounds + : null; - if ((params as DateHistogramParams).date) { - const bounds = getTimefilter().getActiveBounds(); - - if (bounds) { - return { - min: bounds.min ? bounds.min.valueOf() : undefined, - max: bounds.max ? bounds.max.valueOf() : undefined, - minInterval, - }; - } + if (bounds) { + return { + min: bounds.min as number, + max: bounds.max as number, + minInterval, + }; } return { From 9381a7bf38959232e4ca4aef2b8a21e54240afec Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 3 Mar 2021 13:13:30 -0600 Subject: [PATCH 5/6] fix failing functional test --- test/functional/apps/visualize/_area_chart.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/functional/apps/visualize/_area_chart.ts b/test/functional/apps/visualize/_area_chart.ts index 9b8abc7ae60a8..05fbdc2e0c283 100644 --- a/test/functional/apps/visualize/_area_chart.ts +++ b/test/functional/apps/visualize/_area_chart.ts @@ -96,14 +96,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('should show correct chart', async function () { const xAxisLabels = await PageObjects.visChart.getExpectedValue( ['2015-09-20 00:00', '2015-09-21 00:00', '2015-09-22 00:00', '2015-09-23 00:00'], - [ - '2015-09-20 00:00', - '2015-09-20 12:00', - '2015-09-21 00:00', - '2015-09-21 12:00', - '2015-09-22 00:00', - '2015-09-22 12:00', - ] + ['2015-09-19 12:00', '2015-09-20 12:00', '2015-09-21 12:00', '2015-09-22 12:00'] ); const yAxisLabels = await PageObjects.visChart.getExpectedValue( ['0', '200', '400', '600', '800', '1,000', '1,200', '1,400', '1,600'], From 542b2ca40413522ce24fb9fefa948b2b61713d32 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 3 Mar 2021 16:11:09 -0600 Subject: [PATCH 6/6] fix failing functional tests --- .../functional/apps/visualize/_point_series_options.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/functional/apps/visualize/_point_series_options.ts b/test/functional/apps/visualize/_point_series_options.ts index 09f9694ea9474..ac641fb554b0b 100644 --- a/test/functional/apps/visualize/_point_series_options.ts +++ b/test/functional/apps/visualize/_point_series_options.ts @@ -269,7 +269,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('should show round labels in default timezone', async function () { const expectedLabels = await PageObjects.visChart.getExpectedValue( ['2015-09-20 00:00', '2015-09-21 00:00', '2015-09-22 00:00'], - ['2015-09-20 00:00', '2015-09-20 18:00', '2015-09-21 12:00', '2015-09-22 06:00'] + ['2015-09-19 12:00', '2015-09-20 12:00', '2015-09-21 12:00', '2015-09-22 12:00'] ); await initChart(); const labels = await PageObjects.visChart.getXAxisLabels(); @@ -279,7 +279,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('should show round labels in different timezone', async function () { const expectedLabels = await PageObjects.visChart.getExpectedValue( ['2015-09-20 00:00', '2015-09-21 00:00', '2015-09-22 00:00'], - ['2015-09-19 18:00', '2015-09-20 12:00', '2015-09-21 06:00', '2015-09-22 00:00'] + [ + '2015-09-19 12:00', + '2015-09-20 06:00', + '2015-09-21 00:00', + '2015-09-21 18:00', + '2015-09-22 12:00', + ] ); await kibanaServer.uiSettings.update({ 'dateFormat:tz': 'America/Phoenix' });