@perses-dev/core 0.36.2 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,3 +14,11 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ Object.defineProperty(exports, "isTimeSeriesValueTuple", {
18
+ enumerable: true,
19
+ get: ()=>isTimeSeriesValueTuple
20
+ });
21
+ function isTimeSeriesValueTuple(data) {
22
+ if (data.length !== 2) return false;
23
+ return true;
24
+ }
@@ -61,21 +61,56 @@ function getCommonTimeScale(seriesData) {
61
61
  let timeRange = undefined;
62
62
  const steps = [];
63
63
  for (const data of seriesData){
64
- if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
65
- // Keep track of query steps so we can calculate a common one for the graph
66
- steps.push(data.stepMs);
67
- // If we don't have an overall time range yet, just start with this one
68
- if (timeRange === undefined) {
69
- timeRange = data.timeRange;
70
- continue;
71
- }
72
- // Otherwise, see if this query has a start or end outside of the current
73
- // time range
74
- if (data.timeRange.start < timeRange.start) {
75
- timeRange.start = data.timeRange.start;
76
- }
77
- if (data.timeRange.end > timeRange.end) {
78
- timeRange.end = data.timeRange.end;
64
+ if (data && 'timeRange' in data) {
65
+ if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
66
+ // Keep track of query steps so we can calculate a common one for the graph
67
+ steps.push(data.stepMs);
68
+ // If we don't have an overall time range yet, just start with this one
69
+ if (timeRange === undefined) {
70
+ timeRange = data.timeRange;
71
+ continue;
72
+ }
73
+ // Otherwise, see if this query has a start or end outside of the current
74
+ // time range
75
+ if (data.timeRange.start < timeRange.start) {
76
+ timeRange.start = data.timeRange.start;
77
+ }
78
+ if (data.timeRange.end > timeRange.end) {
79
+ timeRange.end = data.timeRange.end;
80
+ }
81
+ } else if (data && 'values' in data) {
82
+ for(let i = 0; i < data.values.length; i++){
83
+ const values = data.values[i];
84
+ if (values === undefined) {
85
+ continue;
86
+ }
87
+ const [timestamp] = values;
88
+ const start = new Date(timestamp);
89
+ const end = new Date(timestamp);
90
+ if (timeRange === undefined) {
91
+ timeRange = {
92
+ start,
93
+ end
94
+ };
95
+ continue;
96
+ }
97
+ if (start < timeRange.start) {
98
+ timeRange.start = start;
99
+ }
100
+ if (end > timeRange.end) {
101
+ timeRange.end = end;
102
+ }
103
+ }
104
+ if (timeRange === undefined) return undefined;
105
+ const startMs = timeRange.start.valueOf();
106
+ const endMs = timeRange.end.valueOf();
107
+ const rangeMs = endMs - startMs;
108
+ return {
109
+ startMs,
110
+ endMs,
111
+ rangeMs,
112
+ stepMs: MIN_STEP_INTERVAL_MS
113
+ };
79
114
  }
80
115
  }
81
116
  if (timeRange === undefined) return undefined;
@@ -88,11 +123,13 @@ function getCommonTimeScale(seriesData) {
88
123
  const calculatedStepMs = (0, _mathjs.gcd)(...steps);
89
124
  stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
90
125
  }
91
- const startMs = timeRange.start.valueOf();
92
- const endMs = timeRange.end.valueOf();
126
+ const startMs1 = timeRange.start.valueOf();
127
+ const endMs1 = timeRange.end.valueOf();
128
+ const rangeMs1 = endMs1 - startMs1;
93
129
  return {
94
- startMs,
95
- endMs,
96
- stepMs
130
+ startMs: startMs1,
131
+ endMs: endMs1,
132
+ stepMs,
133
+ rangeMs: rangeMs1
97
134
  };
98
135
  }
@@ -5,6 +5,7 @@ export interface TimeScale {
5
5
  startMs: number;
6
6
  endMs: number;
7
7
  stepMs: number;
8
+ rangeMs: number;
8
9
  }
9
10
  export interface TimeSeriesData {
10
11
  timeRange?: AbsoluteTimeRange;
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/model/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,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C;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice } from './notice';\nimport { AbsoluteTimeRange } from './time';\nimport { Labels, TimeSeriesValueTuple } from './time-series-queries';\n\nexport interface TimeScale {\n startMs: number;\n endMs: number;\n stepMs: number;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n metadata?: TimeSeriesMetadata;\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n labels?: Labels;\n}\n\nexport interface TimeSeriesMetadata {\n notices?: Notice[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA0BC"}
1
+ {"version":3,"sources":["../../src/model/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice } from './notice';\nimport { AbsoluteTimeRange } from './time';\nimport { Labels, TimeSeriesValueTuple } from './time-series-queries';\n\nexport interface TimeScale {\n startMs: number;\n endMs: number;\n stepMs: number;\n rangeMs: number;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n metadata?: TimeSeriesMetadata;\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n labels?: Labels;\n}\n\nexport interface TimeSeriesMetadata {\n notices?: Notice[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA2BC"}
@@ -3,5 +3,6 @@ import { QueryDefinition } from './query';
3
3
  import { UnixTimeMs } from './time';
4
4
  export declare type TimeSeriesQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TimeSeriesQuery', PluginSpec>;
5
5
  export declare type TimeSeriesValueTuple = [timestamp: UnixTimeMs, value: number | null];
6
+ export declare function isTimeSeriesValueTuple(data: TimeSeriesValueTuple): data is TimeSeriesValueTuple;
6
7
  export declare type Labels = Record<string, string>;
7
8
  //# sourceMappingURL=time-series-queries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,oBAAY,yBAAyB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;AAEjH,oBAAY,oBAAoB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;AAEjF,oBAAY,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,oBAAY,yBAAyB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;AAEjH,oBAAY,oBAAoB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;AAEjF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,IAAI,oBAAoB,CAG/F;AAED,oBAAY,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -10,6 +10,9 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export { };
13
+ export function isTimeSeriesValueTuple(data) {
14
+ if (data.length !== 2) return false;
15
+ return true;
16
+ }
14
17
 
15
18
  //# sourceMappingURL=time-series-queries.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec } from './definitions';\nimport { QueryDefinition } from './query';\nimport { UnixTimeMs } from './time';\n\nexport type TimeSeriesQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TimeSeriesQuery', PluginSpec>;\n\nexport type TimeSeriesValueTuple = [timestamp: UnixTimeMs, value: number | null];\n\nexport type Labels = Record<string, string>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAQ4C"}
1
+ {"version":3,"sources":["../../src/model/time-series-queries.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec } from './definitions';\nimport { QueryDefinition } from './query';\nimport { UnixTimeMs } from './time';\n\nexport type TimeSeriesQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'TimeSeriesQuery', PluginSpec>;\n\nexport type TimeSeriesValueTuple = [timestamp: UnixTimeMs, value: number | null];\n\nexport function isTimeSeriesValueTuple(data: TimeSeriesValueTuple): data is TimeSeriesValueTuple {\n if (data.length !== 2) return false;\n return true;\n}\n\nexport type Labels = Record<string, string>;\n"],"names":["isTimeSeriesValueTuple","data","length"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAUjC,OAAO,SAASA,sBAAsB,CAACC,IAA0B,EAAgC;IAC/F,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACpC,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -16,5 +16,5 @@ export declare function getYValues(series: TimeSeries, timeScale: TimeScale): Ar
16
16
  * the x axis (i.e. start/end dates and a step that is divisible into all of
17
17
  * the queries' steps).
18
18
  */
19
- export declare function getCommonTimeScale(seriesData: Array<TimeSeriesData | undefined>): TimeScale | undefined;
19
+ export declare function getCommonTimeScale(seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>): TimeScale | undefined;
20
20
  //# sourceMappingURL=time-series-data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGpF,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,CAQzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAuBzF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,CAyCvG"}
1
+ {"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGpF,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,CAQzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAuBzF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,GACzE,SAAS,GAAG,SAAS,CAgFvB"}
@@ -56,21 +56,56 @@ export const MIN_STEP_INTERVAL_MS = 10;
56
56
  let timeRange = undefined;
57
57
  const steps = [];
58
58
  for (const data of seriesData){
59
- if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
60
- // Keep track of query steps so we can calculate a common one for the graph
61
- steps.push(data.stepMs);
62
- // If we don't have an overall time range yet, just start with this one
63
- if (timeRange === undefined) {
64
- timeRange = data.timeRange;
65
- continue;
66
- }
67
- // Otherwise, see if this query has a start or end outside of the current
68
- // time range
69
- if (data.timeRange.start < timeRange.start) {
70
- timeRange.start = data.timeRange.start;
71
- }
72
- if (data.timeRange.end > timeRange.end) {
73
- timeRange.end = data.timeRange.end;
59
+ if (data && 'timeRange' in data) {
60
+ if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
61
+ // Keep track of query steps so we can calculate a common one for the graph
62
+ steps.push(data.stepMs);
63
+ // If we don't have an overall time range yet, just start with this one
64
+ if (timeRange === undefined) {
65
+ timeRange = data.timeRange;
66
+ continue;
67
+ }
68
+ // Otherwise, see if this query has a start or end outside of the current
69
+ // time range
70
+ if (data.timeRange.start < timeRange.start) {
71
+ timeRange.start = data.timeRange.start;
72
+ }
73
+ if (data.timeRange.end > timeRange.end) {
74
+ timeRange.end = data.timeRange.end;
75
+ }
76
+ } else if (data && 'values' in data) {
77
+ for(let i = 0; i < data.values.length; i++){
78
+ const values = data.values[i];
79
+ if (values === undefined) {
80
+ continue;
81
+ }
82
+ const [timestamp] = values;
83
+ const start = new Date(timestamp);
84
+ const end = new Date(timestamp);
85
+ if (timeRange === undefined) {
86
+ timeRange = {
87
+ start,
88
+ end
89
+ };
90
+ continue;
91
+ }
92
+ if (start < timeRange.start) {
93
+ timeRange.start = start;
94
+ }
95
+ if (end > timeRange.end) {
96
+ timeRange.end = end;
97
+ }
98
+ }
99
+ if (timeRange === undefined) return undefined;
100
+ const startMs = timeRange.start.valueOf();
101
+ const endMs = timeRange.end.valueOf();
102
+ const rangeMs = endMs - startMs;
103
+ return {
104
+ startMs,
105
+ endMs,
106
+ rangeMs,
107
+ stepMs: MIN_STEP_INTERVAL_MS
108
+ };
74
109
  }
75
110
  }
76
111
  if (timeRange === undefined) return undefined;
@@ -83,12 +118,14 @@ export const MIN_STEP_INTERVAL_MS = 10;
83
118
  const calculatedStepMs = gcd(...steps);
84
119
  stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
85
120
  }
86
- const startMs = timeRange.start.valueOf();
87
- const endMs = timeRange.end.valueOf();
121
+ const startMs1 = timeRange.start.valueOf();
122
+ const endMs1 = timeRange.end.valueOf();
123
+ const rangeMs1 = endMs1 - startMs1;
88
124
  return {
89
- startMs,
90
- endMs,
91
- stepMs
125
+ startMs: startMs1,
126
+ endMs: endMs1,
127
+ stepMs,
128
+ rangeMs: rangeMs1
92
129
  };
93
130
  }
94
131
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData } from '../model';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a common time scale (see `getCommonTimeScale`), generates an array of\n * timestamp values in ms for the x axis of a graph.\n */\nexport function getXValues(timeScale: TimeScale): number[] {\n const xValues: number[] = [];\n let timestamp = timeScale.startMs;\n while (timestamp <= timeScale.endMs) {\n xValues.push(timestamp);\n timestamp += timeScale.stepMs;\n }\n return xValues;\n}\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * gets the values for the y axis of a graph, filling in any timestamps that are\n * missing from the time series data with `null` values.\n */\nexport function getYValues(series: TimeSeries, timeScale: TimeScale): Array<number | null> {\n let timestamp = timeScale.startMs;\n\n const yValues: Array<number | null> = [];\n for (const valueTuple of series.values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n yValues.push(valueTuple[1]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n return yValues;\n}\n\n/**\n * Given a list of running queries, calculates a common time scale for use on\n * the x axis (i.e. start/end dates and a step that is divisible into all of\n * the queries' steps).\n */\nexport function getCommonTimeScale(seriesData: Array<TimeSeriesData | undefined>): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n for (const data of seriesData) {\n if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;\n\n // Keep track of query steps so we can calculate a common one for the graph\n steps.push(data.stepMs);\n\n // If we don't have an overall time range yet, just start with this one\n if (timeRange === undefined) {\n timeRange = data.timeRange;\n continue;\n }\n\n // Otherwise, see if this query has a start or end outside of the current\n // time range\n if (data.timeRange.start < timeRange.start) {\n timeRange.start = data.timeRange.start;\n }\n if (data.timeRange.end > timeRange.end) {\n timeRange.end = data.timeRange.end;\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n // Use the greatest common divisor of all step values as the overall step\n // for the x axis (or if only one query, just use that query's step value)\n let stepMs: number;\n if (steps.length === 1) {\n stepMs = steps[0] as number;\n } else {\n const calculatedStepMs = gcd(...steps);\n stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;\n }\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n\n return { startMs, endMs, stepMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getXValues","timeScale","xValues","timestamp","startMs","endMs","push","stepMs","getYValues","series","yValues","valueTuple","values","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end","length","calculatedStepMs","valueOf"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,GAAG,QAAQ,UAAU,CAAC;AAE/B,OAAO,MAAMC,oBAAoB,GAAG,EAAE,CAAC;AAEvC;;;CAGC,GACD,OAAO,SAASC,UAAU,CAACC,SAAoB,EAAY;IACzD,MAAMC,OAAO,GAAa,EAAE,AAAC;IAC7B,IAAIC,SAAS,GAAGF,SAAS,CAACG,OAAO,AAAC;IAClC,MAAOD,SAAS,I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A2E;QAC3EC,KAAK,CAACX,IAAI,CAACY,IAAI,CAACX,MAAM,CAAC,CAAC;QAExB,uEAAuE;QACvE,IAAIQ,SAAS,KAAKC,SAAS,EAAE;YAC3BD,SAAS,GAAGG,IAAI,CAACH,SAAS,CAAC;YAC3B,SAAS;QACX,CAAC;QAED,yEAAyE;QACzE,aAAa;QACb,IAAIG,IAAI,CAACH,SAAS,CAACI,KAAK,GAAGJ,SAAS,CAACI,KAAK,EAAE;YAC1CJ,SAAS,CAACI,KAAK,GAAGD,IAAI,CAACH,SAAS,CAACI,KAAK,CAAC;QACzC,CAAC;QACD,IAAID,IAAI,CAACH,SAAS,CAACK,GAAG,GAAGL,SAAS,CAACK,GAAG,EAAE;YACtCL,SAAS,CAACK,GAAG,GAAGF,IAAI,CAACH,SAAS,CAACK,GAAG,CAAC;QACrC,CAAC;IACH,CAAC;IAED,IAAIL,SAAS,KAAKC,SAAS,EAAE,OAAOA,SAAS,CAAC;IAE9C,yEAAyE;IACzE,0EAA0E;IAC1E,IAAIT,MAAM,AAAQ,AAAC;IACnB,IAAIU,KAAK,CAACI,MAAM,KAAK,CAAC,EAAE;QACtBd,MAAM,GAAGU,KAAK,CAAC,CAAC,CAAC,AAAU,CAAC;IAC9B,OAAO;QACL,MAAMK,gBAAgB,GAAGxB,GAAG,IAAImB,KAAK,CAAC,AAAC;QACvCV,MAAM,GAAGe,gBAAgB,GAAGvB,oBAAoB,GAAGA,oBAAoB,GAAGuB,gBAAgB,CAAC;IAC7F,CAAC;IAED,MAAMlB,OAAO,GAAGW,SAAS,CAACI,KAAK,CAACI,OAAO,EAAE,AAAC;IAC1C,MAAMlB,KAAK,GAAGU,SAAS,CAACK,GAAG,CAACG,OAAO,EAAE,AAAC;IAEtC,OAAO;QAAEnB,OAAO;QAAEC,KAAK;QAAEE,MAAM;KAAE,CAAC;AACpC,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData } from '../model';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a common time scale (see `getCommonTimeScale`), generates an array of\n * timestamp values in ms for the x axis of a graph.\n */\nexport function getXValues(timeScale: TimeScale): number[] {\n const xValues: number[] = [];\n let timestamp = timeScale.startMs;\n while (timestamp <= timeScale.endMs) {\n xValues.push(timestamp);\n timestamp += timeScale.stepMs;\n }\n return xValues;\n}\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * gets the values for the y axis of a graph, filling in any timestamps that are\n * missing from the time series data with `null` values.\n */\nexport function getYValues(series: TimeSeries, timeScale: TimeScale): Array<number | null> {\n let timestamp = timeScale.startMs;\n\n const yValues: Array<number | null> = [];\n for (const valueTuple of series.values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n yValues.push(valueTuple[1]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n return yValues;\n}\n\n/**\n * Given a list of running queries, calculates a common time scale for use on\n * the x axis (i.e. start/end dates and a step that is divisible into all of\n * the queries' steps).\n */\nexport function getCommonTimeScale(\n seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>\n): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n\n for (const data of seriesData) {\n if (data && 'timeRange' in data) {\n if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;\n\n // Keep track of query steps so we can calculate a common one for the graph\n steps.push(data.stepMs);\n\n // If we don't have an overall time range yet, just start with this one\n if (timeRange === undefined) {\n timeRange = data.timeRange;\n continue;\n }\n\n // Otherwise, see if this query has a start or end outside of the current\n // time range\n if (data.timeRange.start < timeRange.start) {\n timeRange.start = data.timeRange.start;\n }\n if (data.timeRange.end > timeRange.end) {\n timeRange.end = data.timeRange.end;\n }\n } else if (data && 'values' in data) {\n for (let i = 0; i < data.values.length; i++) {\n const values = data.values[i];\n if (values === undefined) {\n continue;\n }\n\n const [timestamp] = values;\n const start = new Date(timestamp);\n const end = new Date(timestamp);\n\n if (timeRange === undefined) {\n timeRange = {\n start,\n end,\n };\n continue;\n }\n\n if (start < timeRange.start) {\n timeRange.start = start;\n }\n\n if (end > timeRange.end) {\n timeRange.end = end;\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, rangeMs, stepMs: MIN_STEP_INTERVAL_MS };\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n // Use the greatest common divisor of all step values as the overall step\n // for the x axis (or if only one query, just use that query's step value)\n let stepMs: number;\n if (steps.length === 1) {\n stepMs = steps[0] as number;\n } else {\n const calculatedStepMs = gcd(...steps);\n stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;\n }\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, stepMs, rangeMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getXValues","timeScale","xValues","timestamp","startMs","endMs","push","stepMs","getYValues","series","yValues","valueTuple","values","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end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CAAC,CAAC,CAAC,AAAU,CAAC;IAC9B,OAAO;QACL,MAAMS,gBAAgB,GAAG5B,GAAG,IAAImB,KAAK,CAAC,AAAC;QACvCV,MAAM,GAAGmB,gBAAgB,GAAG3B,oBAAoB,GAAGA,oBAAoB,GAAG2B,gBAAgB,CAAC;IAC7F,CAAC;IAED,MAAMtB,QAAO,GAAGW,SAAS,CAACI,KAAK,CAACK,OAAO,EAAE,AAAC;IAC1C,MAAMnB,MAAK,GAAGU,SAAS,CAACK,GAAG,CAACI,OAAO,EAAE,AAAC;IACtC,MAAMC,QAAO,GAAGpB,MAAK,GAAGD,QAAO,AAAC;IAEhC,OAAO;QAAEA,OAAO,EAAPA,QAAO;QAAEC,KAAK,EAALA,MAAK;QAAEE,MAAM;QAAEkB,OAAO,EAAPA,QAAO;KAAE,CAAC;AAC7C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/core",
3
- "version": "0.36.2",
3
+ "version": "0.37.0",
4
4
  "description": "Core functionality consumed by both the Perses UI and plugins",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",