@gisce/ooui 2.2.1 → 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/dist/Graph/Graph.d.ts +2 -0
- package/dist/Graph/Graph.d.ts.map +1 -1
- package/dist/Graph/processor/graphProcessor.d.ts.map +1 -1
- package/dist/Graph/processor/timerangeHelper.d.ts +6 -3
- package/dist/Graph/processor/timerangeHelper.d.ts.map +1 -1
- package/dist/HTMLPreview.d.ts +5 -0
- package/dist/HTMLPreview.d.ts.map +1 -0
- package/dist/WidgetFactory.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/ooui.es.js +234 -215
- package/dist/ooui.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Graph/Graph.ts +8 -0
- package/src/Graph/processor/graphProcessor.ts +1 -0
- package/src/Graph/processor/timerangeHelper.ts +13 -2
- package/src/HTMLPreview.ts +5 -0
- package/src/WidgetFactory.ts +4 -0
- package/src/index.ts +2 -0
- package/src/spec/Graph.spec.ts +11 -0
- package/src/spec/WidgetFactory.spec.ts +8 -0
- package/src/spec/timerangeHelper.spec.ts +21 -0
package/package.json
CHANGED
package/src/Graph/Graph.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
130
|
+
iDate.add(interval, units);
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
}
|
package/src/WidgetFactory.ts
CHANGED
|
@@ -14,6 +14,7 @@ import Integer from "./Integer";
|
|
|
14
14
|
import Widget from "./Widget";
|
|
15
15
|
import Float from "./Float";
|
|
16
16
|
import FloatTime from "./FloatTime";
|
|
17
|
+
import HTMLPreview from "./HTMLPreview";
|
|
17
18
|
import ProgressBar from "./ProgressBar";
|
|
18
19
|
import Date from "./Date";
|
|
19
20
|
import DateTime from "./DateTime";
|
|
@@ -163,6 +164,9 @@ class WidgetFactory {
|
|
|
163
164
|
case "time":
|
|
164
165
|
this._widgetClass = Time;
|
|
165
166
|
break;
|
|
167
|
+
case "html_preview":
|
|
168
|
+
this._widgetClass = HTMLPreview;
|
|
169
|
+
break;
|
|
166
170
|
|
|
167
171
|
default:
|
|
168
172
|
break;
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,7 @@ import Switch from "./Switch";
|
|
|
48
48
|
import Steps from "./Steps";
|
|
49
49
|
import CodeEditor from "./CodeEditor";
|
|
50
50
|
import Time from "./Time";
|
|
51
|
+
import HTMLPreview from "./HTMLPreview";
|
|
51
52
|
|
|
52
53
|
import {
|
|
53
54
|
Graph,
|
|
@@ -80,6 +81,7 @@ export {
|
|
|
80
81
|
Integer,
|
|
81
82
|
Float,
|
|
82
83
|
FloatTime,
|
|
84
|
+
HTMLPreview,
|
|
83
85
|
Date,
|
|
84
86
|
DateTime,
|
|
85
87
|
Many2many,
|
package/src/spec/Graph.spec.ts
CHANGED
|
@@ -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
|
});
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
CodeEditor,
|
|
13
13
|
ButtonGroup,
|
|
14
14
|
Time,
|
|
15
|
+
HTMLPreview,
|
|
15
16
|
} from "..";
|
|
16
17
|
|
|
17
18
|
describe("A WidgetFactory", () => {
|
|
@@ -111,4 +112,11 @@ describe("A WidgetFactory", () => {
|
|
|
111
112
|
expect(widget).toBeInstanceOf(Time);
|
|
112
113
|
expect(widget.type).toBe("time");
|
|
113
114
|
});
|
|
115
|
+
it("should be able to HtmlPreview time type", () => {
|
|
116
|
+
const widgetFactory = new WidgetFactory();
|
|
117
|
+
const props = {};
|
|
118
|
+
const widget = widgetFactory.createWidget("html_preview", props);
|
|
119
|
+
expect(widget).toBeInstanceOf(HTMLPreview);
|
|
120
|
+
expect(widget.type).toBe("html_preview");
|
|
121
|
+
});
|
|
114
122
|
});
|
|
@@ -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", () => {
|