Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TSVB] Adds ignore DST switch for timeseries #98484

Merged
merged 11 commits into from
May 5, 2021
1 change: 1 addition & 0 deletions src/plugins/vis_type_timeseries/common/vis_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export const panel = schema.object({
background_color_rules: schema.maybe(schema.arrayOf(backgroundColorRulesItems)),
drilldown_url: stringOptional,
drop_last_bucket: numberIntegerOptional,
ignore_daylight_time: schema.boolean(),
filter: schema.maybe(queryObject),
gauge_color_rules: schema.maybe(schema.arrayOf(gaugeColorRulesItems)),
gauge_width: schema.nullable(schema.oneOf([stringOptionalNullable, numberOptional])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface LastValueModeIndicatorProps {
seriesData?: PanelData['data'];
panelInterval: number;
modelInterval: string;
ignoreDaylightTime: boolean;
}

const lastValueLabel = i18n.translate('visTypeTimeseries.lastValueModeIndicator.lastValue', {
Expand All @@ -29,6 +30,7 @@ export const LastValueModeIndicator = ({
seriesData,
panelInterval,
modelInterval,
ignoreDaylightTime,
}: LastValueModeIndicatorProps) => {
if (!seriesData?.length) return <EuiBadge>{lastValueLabel}</EuiBadge>;

Expand All @@ -40,7 +42,12 @@ export const LastValueModeIndicator = ({
return interval && `${interval.unitValue}${interval.unitString}`;
};

const formatter = createIntervalBasedFormatter(panelInterval, scaledDataFormat, dateFormat);
const formatter = createIntervalBasedFormatter(
panelInterval,
scaledDataFormat,
dateFormat,
ignoreDaylightTime
);
const lastBucketDate = formatter(seriesData[seriesData.length - 1][0]);
const formattedPanelInterval =
(isAutoInterval(modelInterval) || isGteInterval(modelInterval)) && getFormattedPanelInterval();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -20,9 +22,15 @@ function getFormat(interval: number, rules: string[][] = []) {
export function createIntervalBasedFormatter(
interval: number,
rules: string[][],
dateFormat: string
dateFormat: string,
ignoreDaylightTime: boolean
) {
return (val: moment.MomentInput): string => {
return moment(val).format(getFormat(interval, rules) ?? dateFormat);
const fixedOffset = moment(JANUARY_MOMENT_CONFIG).utcOffset();
return (val: moment.MomentInput) => {
const momentVal = moment(val);
if (ignoreDaylightTime) {
momentVal.utcOffset(fixedOffset);
}
return momentVal.format(getFormat(interval, rules) ?? dateFormat);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class TimeseriesPanelConfig extends Component<
legend_position: 'right',
show_grid: 1,
tooltip_mode: 'show_all',
ignore_daylight_time: false,
};
const model = { ...defaults, ...this.props.model };
const { selectedTab } = this.state;
Expand Down Expand Up @@ -227,6 +228,22 @@ export class TimeseriesPanelConfig extends Component<
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFormRow
label={i18n.translate(
'visTypeTimeseries.timeseries.optionsTab.ignoreDaylightTimeLabel',
{
defaultMessage: 'Ignore daylight time?',
}
)}
>
<YesNo
value={model.ignore_daylight_time}
name="ignore_daylight_time"
onChange={this.props.onChange}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function SeriesConfigQueryBarWithIgnoreGlobalFilter({
const htmlId = htmlIdGenerator();
const yesNoOption = (
<YesNo
disabled={Boolean(panel.ignore_global_filter)}
disabled={panel.ignore_global_filter}
value={model.ignore_global_filter}
name="ignore_global_filter"
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function TimeseriesVisualization({
`${isVisSeriesData(visData) ? model.id : 'series[0]'}.series[0].data`,
undefined
)}
ignoreDaylightTime={model.ignore_daylight_time}
panelInterval={getInterval(visData, model)}
modelInterval={model.interval ?? AUTO_INTERVAL}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ 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
this.dateFormat,
this.props.model.ignore_daylight_time
);
return formatter(val);
return (val) => formatter(val);
};

yAxisStackedByPercentFormatter = (val) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TimeseriesVisParams } from '../../types';

interface YesNoProps<ParamName extends keyof TimeseriesVisParams> {
name: ParamName;
value: TimeseriesVisParams[ParamName];
value: boolean | number | undefined;
disabled?: boolean;
'data-test-subj'?: string;
onChange: (partialModel: Partial<TimeseriesVisParams>) => void;
Expand Down