From 9b1c7243ff3a8a13af1f091c4a71a4252ecce776 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Wed, 28 Apr 2021 17:36:43 +0200 Subject: [PATCH] [TSVB] reduce formatter creation number --- .../components/last_value_mode_indicator.tsx | 4 +--- .../lib/create_interval_based_formatter.ts | 6 ++++-- .../components/lib/get_fixed_offset.ts | 15 --------------- .../components/vis_types/timeseries/vis.js | 10 +++++----- 4 files changed, 10 insertions(+), 25 deletions(-) delete mode 100644 src/plugins/vis_type_timeseries/public/application/components/lib/get_fixed_offset.ts diff --git a/src/plugins/vis_type_timeseries/public/application/components/last_value_mode_indicator.tsx b/src/plugins/vis_type_timeseries/public/application/components/last_value_mode_indicator.tsx index acc6c974bcfd1..12ffe72135288 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/last_value_mode_indicator.tsx +++ b/src/plugins/vis_type_timeseries/public/application/components/last_value_mode_indicator.tsx @@ -12,7 +12,6 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFlexItem, EuiToolTip, EuiFlexGroup, EuiBadge } from '@elastic/eui'; import { getUISettings } from '../../services'; import { convertIntervalIntoUnit, isAutoInterval, isGteInterval } from './lib/get_interval'; -import { getFixedOffset } from './lib/get_fixed_offset'; import { createIntervalBasedFormatter } from './lib/create_interval_based_formatter'; import { PanelData } from '../../../common/types'; @@ -47,8 +46,7 @@ export const LastValueModeIndicator = ({ panelInterval, scaledDataFormat, dateFormat, - ignoreDaylightTime, - getFixedOffset() + ignoreDaylightTime ); const lastBucketDate = formatter(seriesData[seriesData.length - 1][0]); const formattedPanelInterval = diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/create_interval_based_formatter.ts b/src/plugins/vis_type_timeseries/public/application/components/lib/create_interval_based_formatter.ts index ee4033861f483..53a1d1be0d45d 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/lib/create_interval_based_formatter.ts +++ b/src/plugins/vis_type_timeseries/public/application/components/lib/create_interval_based_formatter.ts @@ -8,6 +8,8 @@ import moment from 'moment'; +const JANUARY_MOMENT_CONFIG = { M: 0, d: 1 }; + function getFormat(interval: number, rules: string[][] = []) { for (let i = rules.length - 1; i >= 0; i--) { const rule = rules[i]; @@ -21,9 +23,9 @@ export function createIntervalBasedFormatter( interval: number, rules: string[][], dateFormat: string, - ignoreDaylightTime: boolean, - fixedOffset: number + ignoreDaylightTime: boolean ) { + const fixedOffset = moment(JANUARY_MOMENT_CONFIG).utcOffset(); return (val: moment.MomentInput): string => { const momentVal = moment(val); if (ignoreDaylightTime) { diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/get_fixed_offset.ts b/src/plugins/vis_type_timeseries/public/application/components/lib/get_fixed_offset.ts deleted file mode 100644 index 9aa6ca27044b9..0000000000000 --- a/src/plugins/vis_type_timeseries/public/application/components/lib/get_fixed_offset.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import moment from 'moment'; - -const JANUARY_MOMENT_CONFIG = { M: 0, d: 1 }; - -export const getFixedOffset = () => { - return moment(JANUARY_MOMENT_CONFIG).utcOffset(); -}; diff --git a/src/plugins/vis_type_timeseries/public/application/components/vis_types/timeseries/vis.js b/src/plugins/vis_type_timeseries/public/application/components/vis_types/timeseries/vis.js index 0338014a8a192..0766019b814eb 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/vis_types/timeseries/vis.js +++ b/src/plugins/vis_type_timeseries/public/application/components/vis_types/timeseries/vis.js @@ -19,7 +19,6 @@ import { MarkdownSimple } from '../../../../../../../plugins/kibana_react/public import { replaceVars } from '../../lib/replace_vars'; import { getAxisLabelString } from '../../lib/get_axis_label_string'; import { getInterval } from '../../lib/get_interval'; -import { getFixedOffset } from '../../lib/get_fixed_offset'; import { createIntervalBasedFormatter } from '../../lib/create_interval_based_formatter'; import { STACKED_OPTIONS } from '../../../visualizations/constants'; import { getCoreStart } from '../../../../services'; @@ -35,15 +34,16 @@ class TimeseriesVisualization extends Component { scaledDataFormat = this.props.getConfig('dateFormat:scaled'); dateFormat = this.props.getConfig('dateFormat'); - xAxisFormatter = (interval) => (val) => { + xAxisFormatter = (interval) => { const formatter = createIntervalBasedFormatter( interval, this.scaledDataFormat, this.dateFormat, - Boolean(this.props.model.ignore_daylight_time), - getFixedOffset() + Boolean(this.props.model.ignore_daylight_time) ); - return formatter(val); + return (val) => { + return formatter(val); + }; }; yAxisStackedByPercentFormatter = (val) => {