@gisce/ooui 2.3.0 → 2.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
@@ -18,8 +18,16 @@ export class Graph {
18
18
  return this._timerange;
19
19
  }
20
20
 
21
+ _interval: number = 1;
22
+ get interval(): number {
23
+ return this._interval;
24
+ }
25
+
21
26
  constructor(element: ParsedNode) {
22
27
  this._string = element.attributes.string || null;
23
28
  this._timerange = element.attributes.timerange || null;
29
+ if (element.attributes.interval) {
30
+ this._interval = parseInt(element.attributes.interval);
31
+ }
24
32
  }
25
33
  }
@@ -167,6 +167,7 @@ export const processGraphData = ({
167
167
  finalData = processTimerangeData({
168
168
  values: finalData,
169
169
  timerange: ooui.timerange,
170
+ interval: ooui.interval,
170
171
  });
171
172
  } else if (ooui.type == "pie") {
172
173
  finalData = adjustedUninformedData.sort((a, b) => b.value - a.value);
@@ -4,9 +4,11 @@ import { getValueForOperator } from "./graphProcessor";
4
4
  export function processTimerangeData({
5
5
  values,
6
6
  timerange,
7
+ interval = 1,
7
8
  }: {
8
9
  values: any[];
9
10
  timerange: string;
11
+ interval?: number;
10
12
  }) {
11
13
  const combinedValues = combineValuesForTimerange({
12
14
  values,
@@ -17,6 +19,7 @@ export function processTimerangeData({
17
19
  const filledValues = fillGapsInTimerangeData({
18
20
  values: combinedValues,
19
21
  timerange,
22
+ interval,
20
23
  });
21
24
 
22
25
  return filledValues;
@@ -25,9 +28,11 @@ export function processTimerangeData({
25
28
  export function fillGapsInTimerangeData({
26
29
  values,
27
30
  timerange,
31
+ interval = 1,
28
32
  }: {
29
33
  values: any[];
30
34
  timerange: string;
35
+ interval?: number;
31
36
  }) {
32
37
  let finalValues: any[] = [];
33
38
  const uniqueValues: Record<string, any> = getUniqueValuesGroupedBy({
@@ -56,6 +61,7 @@ export function fillGapsInTimerangeData({
56
61
  const missingDates = getMissingConsecutiveDates({
57
62
  dates: [date, nextDate],
58
63
  timerange,
64
+ interval,
59
65
  });
60
66
  finalValues = finalValues.concat(
61
67
  missingDates.map((stringDate) => {
@@ -86,9 +92,11 @@ export function fillGapsInTimerangeData({
86
92
  export function getMissingConsecutiveDates({
87
93
  dates,
88
94
  timerange,
95
+ interval = 1,
89
96
  }: {
90
97
  dates: string[];
91
98
  timerange: string;
99
+ interval?: number;
92
100
  }) {
93
101
  const missingDates: string[] = [];
94
102
  const units = `${timerange}s` as any;
@@ -111,12 +119,15 @@ export function getMissingConsecutiveDates({
111
119
  const date2 = sortedDates[i + 1];
112
120
 
113
121
  if (!checkDatesConsecutive([date1, date2], units)) {
114
- const iDate = moment(date1, getFormatForUnits(units)).add(1, units);
122
+ const iDate = moment(date1, getFormatForUnits(units)).add(
123
+ interval,
124
+ units,
125
+ );
115
126
  const fDate = moment(date2, getFormatForUnits(units));
116
127
 
117
128
  while (iDate.isBefore(fDate)) {
118
129
  missingDates.push(iDate.format(getFormatForUnits(units)));
119
- iDate.add(1, units);
130
+ iDate.add(interval, units);
120
131
  }
121
132
  }
122
133
  }
@@ -66,4 +66,15 @@ describe("A Graph", () => {
66
66
  const graph = parseGraph(xml) as GraphChart;
67
67
  expect(graph.timerange).toBe("day");
68
68
  });
69
+ it("should parse a graph with interval parameter", () => {
70
+ const xml = `<?xml version="1.0"?>
71
+ <graph type="line" timerange="minute" interval="5">
72
+ <field name="data_alta" axis="x"/>
73
+ <field name="data_alta" operator="count" axis="y"/>
74
+ </graph>
75
+ `;
76
+
77
+ const graph = parseGraph(xml) as GraphChart;
78
+ expect(graph.interval).toBe(5);
79
+ });
69
80
  });
@@ -569,6 +569,27 @@ describe("a timerangeHelper", () => {
569
569
  expect(missingDates.length).toBe(1);
570
570
  expect(missingDates[0]).toBe("2022-01");
571
571
  });
572
+ it("should allow to pass an interval to get missing dates", () => {
573
+ const dates = ["2024-01-01 00:00", "2024-01-01 01:00"];
574
+ const missingDates = getMissingConsecutiveDates({
575
+ dates,
576
+ timerange: "minute",
577
+ interval: 5,
578
+ });
579
+ expect(missingDates).toEqual([
580
+ "2024-01-01 00:05",
581
+ "2024-01-01 00:10",
582
+ "2024-01-01 00:15",
583
+ "2024-01-01 00:20",
584
+ "2024-01-01 00:25",
585
+ "2024-01-01 00:30",
586
+ "2024-01-01 00:35",
587
+ "2024-01-01 00:40",
588
+ "2024-01-01 00:45",
589
+ "2024-01-01 00:50",
590
+ "2024-01-01 00:55",
591
+ ]);
592
+ });
572
593
  });
573
594
  describe("in fillGapsInTimerangeData function", () => {
574
595
  it("should fill gaps in data for hour grouping", () => {