diff --git a/src/plugins/vis_type_timeseries/common/types/vis_data.ts b/src/plugins/vis_type_timeseries/common/types/vis_data.ts index 15755a5bb668a..fb3e0db82f188 100644 --- a/src/plugins/vis_type_timeseries/common/types/vis_data.ts +++ b/src/plugins/vis_type_timeseries/common/types/vis_data.ts @@ -46,7 +46,7 @@ export interface PanelData { error?: string; } -export type PanelDataArray = [number | undefined, number | string | null]; +export type PanelDataArray = [number | undefined | string, number | string | null]; export interface Annotation { key: number; diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/get_interval.ts b/src/plugins/vis_type_timeseries/public/application/components/lib/get_interval.ts index 082a3978f29ed..4b232af299a19 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/lib/get_interval.ts +++ b/src/plugins/vis_type_timeseries/public/application/components/lib/get_interval.ts @@ -77,8 +77,12 @@ export const getInterval = (visData: TimeseriesVisData, model: TimeseriesVisPara ) as PanelData[]; return series.reduce((currentInterval, item) => { - if (item.data.length > 1) { - const seriesInterval = item.data[1][0]! - item.data[0][0]!; + if ( + item.data.length > 1 && + typeof item.data[1][0] === 'number' && + typeof item.data[0][0] === 'number' + ) { + const seriesInterval = item.data[1][0] - item.data[0][0]; if (!currentInterval || seriesInterval < currentInterval) return seriesInterval; } return currentInterval; diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/get_splits.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/get_splits.ts index 68af9d7bad970..6e33d8ab07a42 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/get_splits.ts +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/get_splits.ts @@ -27,7 +27,14 @@ interface SplittedData { color: string; meta: TMeta; timeseries: { - buckets: Array & { key: string }>; + buckets: [ + { + [s: string]: { + // should be typed + values: Record; + }; + } & { key: string | number } + ]; }; } diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/map_empty_to_zero.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/map_empty_to_zero.ts index 8b04251411134..a035d566d130e 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/map_empty_to_zero.ts +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/map_empty_to_zero.ts @@ -10,15 +10,16 @@ import { getAggValue } from './get_agg_value'; import { METRIC_TYPES } from '../../../../../data/common'; import type { Metric } from '../../../../common/types'; +import type { PanelDataArray } from '../../../../common/types/vis_data'; export const mapEmptyToZero = ( metric: Metric, buckets: Array< { - key: number; + key: number | string; } & Record > -) => { +): PanelDataArray[] => { // Metric types where an empty set equals `zero` const isSettableToZero = [ METRIC_TYPES.COUNT, diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/timestamp.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/timestamp.ts index 4388de43667dd..7374b483aeec8 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/timestamp.ts +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/timestamp.ts @@ -38,7 +38,7 @@ export function getLastSeriesTimestamp(seriesGroup: Array if (lastValue) { const [dataLastTimestamp] = lastValue; - if (typeof dataLastTimestamp !== 'undefined') { + if (typeof dataLastTimestamp === 'number') { lastTimestamp = Math.max(dataLastTimestamp, lastTimestamp ?? dataLastTimestamp); } } diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile.ts index 4004501c2e015..6514267ee0ec3 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile.ts +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile.ts @@ -12,7 +12,7 @@ import { toPercentileNumber } from '../../../../../common/to_percentile_number'; import { METRIC_TYPES } from '../../../../../common/enums'; import type { TableResponseProcessorsFunction } from './types'; -import { PanelDataArray } from '../../../../../common/types/vis_data'; +import type { PanelDataArray } from '../../../../../common/types/vis_data'; export const percentile: TableResponseProcessorsFunction = ({ bucket, @@ -36,7 +36,7 @@ export const percentile: TableResponseProcessorsFunction = ({ const lastPercentile = last(metric.percentiles)?.value ?? 0; const percentileKey = toPercentileNumber(lastPercentile); const data = split.timeseries.buckets.map((b) => [ - Number(b.key), + b.key, b[metric.id].values[percentileKey], ]) as PanelDataArray[]; diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile_rank.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile_rank.ts index 0e1d4effe4c2f..73e177e21e756 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile_rank.ts +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/percentile_rank.ts @@ -12,7 +12,7 @@ import { toPercentileNumber } from '../../../../../common/to_percentile_number'; import { METRIC_TYPES } from '../../../../../common/enums'; import type { TableResponseProcessorsFunction } from './types'; -import { PanelDataArray } from '../../../../../common/types/vis_data'; +import type { PanelDataArray } from '../../../../../common/types/vis_data'; export const percentileRank: TableResponseProcessorsFunction = ({ bucket, @@ -37,7 +37,7 @@ export const percentileRank: TableResponseProcessorsFunction = ({ const lastPercentileNumber = toPercentileNumber(lastRankValue); const data = split.timeseries.buckets.map((b) => [ - Number(b.key), + b.key, getAggValue(b, { ...metric, value: lastPercentileNumber, diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/std_sibling.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/std_sibling.ts index b08bee7558b81..414108291a24f 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/std_sibling.ts +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/response_processors/table/std_sibling.ts @@ -26,7 +26,7 @@ export const stdSibling: TableResponseProcessorsFunction = ({ const fakeResp = { aggregations: bucket }; (await getSplits(fakeResp, panel, series, meta, extractFields)).forEach((split) => { const data: PanelDataArray[] = split.timeseries.buckets.map((b) => { - return [Number(b.key), getSiblingAggValue(split, metric)]; + return [b.key, getSiblingAggValue(split, metric)]; }); results.push({