@connectci/xdmod-charts 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/caption.d.ts +68 -0
- package/dist/caption.js +118 -0
- package/dist/csv.d.ts +22 -0
- package/dist/csv.js +95 -0
- package/dist/fixtures.d.ts +58 -0
- package/dist/fixtures.js +1 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +39 -0
- package/dist/generated/palette.d.ts +4 -0
- package/dist/generated/palette.js +23 -0
- package/dist/generated/statistics.d.ts +6 -0
- package/dist/generated/statistics.js +217 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/measure.d.ts +7 -0
- package/dist/measure.js +14 -0
- package/dist/palette.d.ts +11 -0
- package/dist/palette.js +19 -0
- package/dist/parse.d.ts +3 -0
- package/dist/parse.js +82 -0
- package/dist/payload.d.ts +81 -0
- package/dist/payload.js +1 -0
- package/dist/view.d.ts +58 -0
- package/dist/view.js +243 -0
- package/fixtures/README.md +13 -0
- package/fixtures/aggregate-empty.json +85 -0
- package/fixtures/aggregate-fills-empty-buckets.json +118 -0
- package/fixtures/aggregate-has-more-others-count.json +103 -0
- package/fixtures/aggregate-incomplete-with-probe-day.json +108 -0
- package/fixtures/aggregate-jobs-by-resource.json +66 -0
- package/fixtures/aggregate-marks-resources-that-stop.json +125 -0
- package/fixtures/aggregate-no-fill-for-average.json +115 -0
- package/fixtures/aggregate-no-fill-incomplete-buckets.json +110 -0
- package/fixtures/aggregate-no-fill-when-bucket-filtered.json +114 -0
- package/fixtures/aggregate-no-fill-when-more.json +110 -0
- package/fixtures/aggregate-no-fill-with-offset.json +110 -0
- package/fixtures/aggregate-nominal-not-reordered.json +107 -0
- package/fixtures/aggregate-offset-page.json +103 -0
- package/fixtures/aggregate-ordered-bucket-order.json +116 -0
- package/fixtures/aggregate-probe-reaches-end.json +108 -0
- package/fixtures/aggregate-unknown-bucket-last.json +115 -0
- package/fixtures/aggregate-unordered.json +103 -0
- package/fixtures/average-leaves-gaps.json +125 -0
- package/fixtures/calendar-december-into-january.json +113 -0
- package/fixtures/calendar-range-ends-at-month-end.json +108 -0
- package/fixtures/cpu-hours-by-resource-incomplete.json +125 -0
- package/fixtures/early-end-average-by-resource-not-filled.json +147 -0
- package/fixtures/early-end-average-other-dimension.json +144 -0
- package/fixtures/early-end-daily-by-queue.json +180 -0
- package/fixtures/early-end-daily-series-stops.json +139 -0
- package/fixtures/early-end-day-inside-last-period.json +147 -0
- package/fixtures/early-end-fill-stops-at-last-day.json +145 -0
- package/fixtures/early-end-fills-to-resource-last-day.json +149 -0
- package/fixtures/early-end-other-dimension-never-filled.json +145 -0
- package/fixtures/early-end-probe-window-too-short.json +144 -0
- package/fixtures/early-end-resource-retired.json +144 -0
- package/fixtures/early-end-several-resources.json +205 -0
- package/fixtures/early-end-without-probe.json +140 -0
- package/fixtures/label-stripped-from-description.json +95 -0
- package/fixtures/no-series-values.json +86 -0
- package/fixtures/partial-last-day.json +119 -0
- package/fixtures/partial-last-month.json +122 -0
- package/fixtures/probe-day-after-range.json +113 -0
- package/fixtures/probe-day-inside-last-month.json +113 -0
- package/fixtures/probe-day-last-day-of-period.json +113 -0
- package/fixtures/rank-prefixes-on-series.json +130 -0
- package/fixtures/series-ended-before-probe-day.json +188 -0
- package/fixtures/timeseries-complete-last-period.json +113 -0
- package/fixtures/timeseries-month-gaps.json +121 -0
- package/package.json +28 -4
- package/rules/README.md +29 -0
- package/rules/palette.json +4 -0
- package/rules/statistics.json +217 -0
- package/schema/chart-payload.v1.json +320 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
export const STATISTICS = {
|
|
2
|
+
"job_count": {
|
|
3
|
+
"kind": "total",
|
|
4
|
+
"unit": "jobs",
|
|
5
|
+
"additive": true
|
|
6
|
+
},
|
|
7
|
+
"started_job_count": {
|
|
8
|
+
"kind": "total",
|
|
9
|
+
"unit": "jobs",
|
|
10
|
+
"additive": true
|
|
11
|
+
},
|
|
12
|
+
"submitted_job_count": {
|
|
13
|
+
"kind": "total",
|
|
14
|
+
"unit": "jobs",
|
|
15
|
+
"additive": true
|
|
16
|
+
},
|
|
17
|
+
"total_cpu_hours": {
|
|
18
|
+
"kind": "total",
|
|
19
|
+
"unit": "core-hours",
|
|
20
|
+
"additive": true
|
|
21
|
+
},
|
|
22
|
+
"total_node_hours": {
|
|
23
|
+
"kind": "total",
|
|
24
|
+
"unit": "node-hours",
|
|
25
|
+
"additive": true
|
|
26
|
+
},
|
|
27
|
+
"total_gpu_hours": {
|
|
28
|
+
"kind": "total",
|
|
29
|
+
"unit": "GPU-hours",
|
|
30
|
+
"additive": true
|
|
31
|
+
},
|
|
32
|
+
"total_wallduration_hours": {
|
|
33
|
+
"kind": "total",
|
|
34
|
+
"unit": "hours",
|
|
35
|
+
"additive": true
|
|
36
|
+
},
|
|
37
|
+
"total_waitduration_hours": {
|
|
38
|
+
"kind": "total",
|
|
39
|
+
"unit": "hours",
|
|
40
|
+
"additive": true
|
|
41
|
+
},
|
|
42
|
+
"used_su": {
|
|
43
|
+
"kind": "total",
|
|
44
|
+
"unit": "SUs",
|
|
45
|
+
"additive": true
|
|
46
|
+
},
|
|
47
|
+
"used_ace": {
|
|
48
|
+
"kind": "total",
|
|
49
|
+
"unit": "ACCESS credits",
|
|
50
|
+
"additive": true
|
|
51
|
+
},
|
|
52
|
+
"cloud_num_sessions_ended": {
|
|
53
|
+
"kind": "total",
|
|
54
|
+
"unit": "sessions",
|
|
55
|
+
"additive": true
|
|
56
|
+
},
|
|
57
|
+
"cloud_num_sessions_started": {
|
|
58
|
+
"kind": "total",
|
|
59
|
+
"unit": "sessions",
|
|
60
|
+
"additive": true
|
|
61
|
+
},
|
|
62
|
+
"cloud_wall_time": {
|
|
63
|
+
"kind": "total",
|
|
64
|
+
"unit": "hours",
|
|
65
|
+
"additive": true
|
|
66
|
+
},
|
|
67
|
+
"cloud_core_time": {
|
|
68
|
+
"kind": "total",
|
|
69
|
+
"unit": "core-hours",
|
|
70
|
+
"additive": true
|
|
71
|
+
},
|
|
72
|
+
"allocated_nu": {
|
|
73
|
+
"kind": "total",
|
|
74
|
+
"unit": "NUs",
|
|
75
|
+
"additive": false
|
|
76
|
+
},
|
|
77
|
+
"allocated_raw_su": {
|
|
78
|
+
"kind": "total",
|
|
79
|
+
"unit": "SUs",
|
|
80
|
+
"additive": false
|
|
81
|
+
},
|
|
82
|
+
"allocated_su": {
|
|
83
|
+
"kind": "total",
|
|
84
|
+
"unit": "SUs",
|
|
85
|
+
"additive": false
|
|
86
|
+
},
|
|
87
|
+
"allocated_ace": {
|
|
88
|
+
"kind": "total",
|
|
89
|
+
"unit": "ACCESS credits",
|
|
90
|
+
"additive": false
|
|
91
|
+
},
|
|
92
|
+
"cloud_num_sessions_running": {
|
|
93
|
+
"kind": "total",
|
|
94
|
+
"unit": "sessions",
|
|
95
|
+
"additive": false
|
|
96
|
+
},
|
|
97
|
+
"wall_time": {
|
|
98
|
+
"kind": "total",
|
|
99
|
+
"unit": "hours",
|
|
100
|
+
"additive": false
|
|
101
|
+
},
|
|
102
|
+
"wait_time": {
|
|
103
|
+
"kind": "total",
|
|
104
|
+
"unit": "hours",
|
|
105
|
+
"additive": false
|
|
106
|
+
},
|
|
107
|
+
"gpu_time": {
|
|
108
|
+
"kind": "total",
|
|
109
|
+
"unit": "hours",
|
|
110
|
+
"additive": false
|
|
111
|
+
},
|
|
112
|
+
"requested_wall_time": {
|
|
113
|
+
"kind": "total",
|
|
114
|
+
"unit": "hours",
|
|
115
|
+
"additive": false
|
|
116
|
+
},
|
|
117
|
+
"cpu_time_user": {
|
|
118
|
+
"kind": "total",
|
|
119
|
+
"unit": "hours",
|
|
120
|
+
"additive": false
|
|
121
|
+
},
|
|
122
|
+
"cpu_time_system": {
|
|
123
|
+
"kind": "total",
|
|
124
|
+
"unit": "hours",
|
|
125
|
+
"additive": false
|
|
126
|
+
},
|
|
127
|
+
"cpu_time_idle": {
|
|
128
|
+
"kind": "total",
|
|
129
|
+
"unit": "hours",
|
|
130
|
+
"additive": false
|
|
131
|
+
},
|
|
132
|
+
"allocated_cpu_core_hours": {
|
|
133
|
+
"kind": "total",
|
|
134
|
+
"unit": "core-hours",
|
|
135
|
+
"additive": false
|
|
136
|
+
},
|
|
137
|
+
"allocated_gpu_hours": {
|
|
138
|
+
"kind": "total",
|
|
139
|
+
"unit": "GPU-hours",
|
|
140
|
+
"additive": false
|
|
141
|
+
},
|
|
142
|
+
"allocated_cpu_node_hours": {
|
|
143
|
+
"kind": "total",
|
|
144
|
+
"unit": "node-hours",
|
|
145
|
+
"additive": false
|
|
146
|
+
},
|
|
147
|
+
"allocated_gpu_node_hours": {
|
|
148
|
+
"kind": "total",
|
|
149
|
+
"unit": "node-hours",
|
|
150
|
+
"additive": false
|
|
151
|
+
},
|
|
152
|
+
"ace_total": {
|
|
153
|
+
"kind": "total",
|
|
154
|
+
"unit": "ACCESS credits",
|
|
155
|
+
"additive": false
|
|
156
|
+
},
|
|
157
|
+
"ace_allocated": {
|
|
158
|
+
"kind": "total",
|
|
159
|
+
"unit": "ACCESS credits",
|
|
160
|
+
"additive": false
|
|
161
|
+
},
|
|
162
|
+
"total_avg_number_of_cpu_cores": {
|
|
163
|
+
"kind": "average",
|
|
164
|
+
"unit": "cores",
|
|
165
|
+
"additive": false
|
|
166
|
+
},
|
|
167
|
+
"total_avg_number_of_gpus": {
|
|
168
|
+
"kind": "average",
|
|
169
|
+
"unit": "GPUs",
|
|
170
|
+
"additive": false
|
|
171
|
+
},
|
|
172
|
+
"total_avg_number_of_cpu_nodes": {
|
|
173
|
+
"kind": "average",
|
|
174
|
+
"unit": "nodes",
|
|
175
|
+
"additive": false
|
|
176
|
+
},
|
|
177
|
+
"total_avg_number_of_gpu_nodes": {
|
|
178
|
+
"kind": "average",
|
|
179
|
+
"unit": "nodes",
|
|
180
|
+
"additive": false
|
|
181
|
+
},
|
|
182
|
+
"allocated_avg_number_of_cpu_cores": {
|
|
183
|
+
"kind": "average",
|
|
184
|
+
"unit": "cores",
|
|
185
|
+
"additive": false
|
|
186
|
+
},
|
|
187
|
+
"allocated_avg_number_of_gpus": {
|
|
188
|
+
"kind": "average",
|
|
189
|
+
"unit": "GPUs",
|
|
190
|
+
"additive": false
|
|
191
|
+
},
|
|
192
|
+
"allocated_avg_number_of_cpu_nodes": {
|
|
193
|
+
"kind": "average",
|
|
194
|
+
"unit": "nodes",
|
|
195
|
+
"additive": false
|
|
196
|
+
},
|
|
197
|
+
"allocated_avg_number_of_gpu_nodes": {
|
|
198
|
+
"kind": "average",
|
|
199
|
+
"unit": "nodes",
|
|
200
|
+
"additive": false
|
|
201
|
+
},
|
|
202
|
+
"avg_waitduration_hours": {
|
|
203
|
+
"kind": "average",
|
|
204
|
+
"unit": "hours",
|
|
205
|
+
"additive": false
|
|
206
|
+
},
|
|
207
|
+
"avg_wallduration_hours": {
|
|
208
|
+
"kind": "average",
|
|
209
|
+
"unit": "hours",
|
|
210
|
+
"additive": false
|
|
211
|
+
},
|
|
212
|
+
"avg_processors": {
|
|
213
|
+
"kind": "average",
|
|
214
|
+
"unit": "cores",
|
|
215
|
+
"additive": false
|
|
216
|
+
}
|
|
217
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { ChartPayload, Unit, MeasureKind, DataEndSource, Warning } from "./payload.js";
|
|
2
|
+
export { parsePayload } from "./parse.js";
|
|
3
|
+
export { STATISTICS } from "./generated/statistics.js";
|
|
4
|
+
export type { Statistic } from "./generated/statistics.js";
|
|
5
|
+
export { measureKind } from "./measure.js";
|
|
6
|
+
export type { BuilderInput, ChartFixture } from "./fixtures.js";
|
|
7
|
+
export { toView, isChartWorthy, chartSummary, dimensionLabel, BUILT_IN_WARNINGS, DIMENSION_LABELS, DIMENSION_NOUNS } from "./view.js";
|
|
8
|
+
export type { ChartView, ViewOptions } from "./view.js";
|
|
9
|
+
export { captionLines } from "./caption.js";
|
|
10
|
+
export type { CaptionFacts, EarlyEnd } from "./caption.js";
|
|
11
|
+
export { formatDay, formatPeriod, parseDay } from "./format.js";
|
|
12
|
+
export { chartCsv, chartFileName, csvCell, csvRow, periods, periodContaining, shownCount } from "./csv.js";
|
|
13
|
+
export { PALETTE, MAX_SERIES, colorFor } from "./palette.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { parsePayload } from "./parse.js";
|
|
2
|
+
export { STATISTICS } from "./generated/statistics.js";
|
|
3
|
+
export { measureKind } from "./measure.js";
|
|
4
|
+
export { toView, isChartWorthy, chartSummary, dimensionLabel, BUILT_IN_WARNINGS, DIMENSION_LABELS, DIMENSION_NOUNS } from "./view.js";
|
|
5
|
+
export { captionLines } from "./caption.js";
|
|
6
|
+
export { formatDay, formatPeriod, parseDay } from "./format.js";
|
|
7
|
+
export { chartCsv, chartFileName, csvCell, csvRow, periods, periodContaining, shownCount } from "./csv.js";
|
|
8
|
+
export { PALETTE, MAX_SERIES, colorFor } from "./palette.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MeasureKind } from "./payload.js";
|
|
2
|
+
/**
|
|
3
|
+
* A statistic's kind: the table in rules/statistics.json first. For an id not
|
|
4
|
+
* listed, the documented fallback: a `total_` prefix or `_count` suffix is a
|
|
5
|
+
* total, anything else an average.
|
|
6
|
+
*/
|
|
7
|
+
export declare function measureKind(statistic: string): MeasureKind;
|
package/dist/measure.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { STATISTICS } from "./generated/statistics.js";
|
|
2
|
+
/**
|
|
3
|
+
* A statistic's kind: the table in rules/statistics.json first. For an id not
|
|
4
|
+
* listed, the documented fallback: a `total_` prefix or `_count` suffix is a
|
|
5
|
+
* total, anything else an average.
|
|
6
|
+
*/
|
|
7
|
+
export function measureKind(statistic) {
|
|
8
|
+
const listed = STATISTICS[statistic];
|
|
9
|
+
if (listed)
|
|
10
|
+
return listed.kind;
|
|
11
|
+
if (statistic.startsWith("total_") || statistic.endsWith("_count"))
|
|
12
|
+
return "total";
|
|
13
|
+
return "average";
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PALETTE } from "./generated/palette.js";
|
|
2
|
+
export { PALETTE };
|
|
3
|
+
/** The most series a timeseries chart draws: one palette slot each. */
|
|
4
|
+
export declare const MAX_SERIES: number;
|
|
5
|
+
/**
|
|
6
|
+
* The colour for a series, by name. Names are sorted (stable, locale-independent
|
|
7
|
+
* of the input order) and slot i goes to the i-th, so reordering the input
|
|
8
|
+
* never changes a name's colour and no two names in `names` share a slot
|
|
9
|
+
* while there are at most MAX_SERIES of them.
|
|
10
|
+
*/
|
|
11
|
+
export declare function colorFor(name: string, names: string[], mode?: "light" | "dark"): string;
|
package/dist/palette.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PALETTE } from "./generated/palette.js";
|
|
2
|
+
export { PALETTE };
|
|
3
|
+
/** The most series a timeseries chart draws: one palette slot each. */
|
|
4
|
+
export const MAX_SERIES = PALETTE.light.length;
|
|
5
|
+
/**
|
|
6
|
+
* The colour for a series, by name. Names are sorted (stable, locale-independent
|
|
7
|
+
* of the input order) and slot i goes to the i-th, so reordering the input
|
|
8
|
+
* never changes a name's colour and no two names in `names` share a slot
|
|
9
|
+
* while there are at most MAX_SERIES of them.
|
|
10
|
+
*/
|
|
11
|
+
export function colorFor(name, names, mode = "light") {
|
|
12
|
+
const colors = PALETTE[mode];
|
|
13
|
+
const sorted = [...new Set(names)].sort(byName);
|
|
14
|
+
const i = sorted.indexOf(name);
|
|
15
|
+
return colors[(i < 0 ? 0 : i) % colors.length];
|
|
16
|
+
}
|
|
17
|
+
function byName(a, b) {
|
|
18
|
+
return a.localeCompare(b, "en") || (a < b ? -1 : a > b ? 1 : 0);
|
|
19
|
+
}
|
package/dist/parse.d.ts
ADDED
package/dist/parse.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const isRecord = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
2
|
+
const isString = (v) => typeof v === "string";
|
|
3
|
+
const isValue = (v) => v === null || (typeof v === "number" && Number.isFinite(v));
|
|
4
|
+
const isOptionalString = (v) => v === undefined || isString(v);
|
|
5
|
+
const isNullableString = (v) => v === undefined || v === null || isString(v);
|
|
6
|
+
const isPeriod = (v) => isRecord(v) && isString(v.start) && isString(v.end);
|
|
7
|
+
const isList = (v, check) => Array.isArray(v) && v.every(check);
|
|
8
|
+
const UNITS = new Set(["Day", "Week", "Month", "Quarter", "Year"]);
|
|
9
|
+
const isSource = (v) => v === undefined || v === "resource" || v === "series";
|
|
10
|
+
const isPrecision = (v) => v === undefined || v === "day" || v === "period";
|
|
11
|
+
const isCount = (v) => v === undefined || v === null || (typeof v === "number" && Number.isInteger(v) && v >= 0);
|
|
12
|
+
const isPoint = (p) => isRecord(p) && isString(p.start) && isValue(p.value);
|
|
13
|
+
const isSeries = (s) => isRecord(s) &&
|
|
14
|
+
isString(s.name) &&
|
|
15
|
+
isList(s.points, isPoint) &&
|
|
16
|
+
isOptionalString(s.data_through) &&
|
|
17
|
+
isPrecision(s.data_through_precision) &&
|
|
18
|
+
isSource(s.data_through_source);
|
|
19
|
+
const isCategory = (c) => isRecord(c) &&
|
|
20
|
+
isString(c.name) &&
|
|
21
|
+
isValue(c.value) &&
|
|
22
|
+
isOptionalString(c.data_through) &&
|
|
23
|
+
isSource(c.data_through_source);
|
|
24
|
+
const isWarning = (w) => isRecord(w) && isString(w.code) && isString(w.text);
|
|
25
|
+
/** The payload typed, or null when it isn't a valid v1 chart payload. Unknown fields are ignored. */
|
|
26
|
+
export function parsePayload(raw) {
|
|
27
|
+
if (!isRecord(raw) || raw.version !== 1)
|
|
28
|
+
return null;
|
|
29
|
+
const { measure, dimension, filters } = raw;
|
|
30
|
+
if (!isString(raw.realm) ||
|
|
31
|
+
!isString(raw.statistic) ||
|
|
32
|
+
!isString(raw.group_by) ||
|
|
33
|
+
(raw.dataset_type !== "timeseries" && raw.dataset_type !== "aggregate") ||
|
|
34
|
+
!isPeriod(raw.requested) ||
|
|
35
|
+
!isPeriod(raw.counted) ||
|
|
36
|
+
typeof raw.last_period_incomplete !== "boolean" ||
|
|
37
|
+
typeof raw.has_more !== "boolean" ||
|
|
38
|
+
raw.source !== "XDMoD" ||
|
|
39
|
+
!isString(raw.retrieved)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (raw.unit !== undefined && !(isString(raw.unit) && UNITS.has(raw.unit)))
|
|
43
|
+
return null;
|
|
44
|
+
if (!isRecord(measure) ||
|
|
45
|
+
!isString(measure.label) ||
|
|
46
|
+
!isString(measure.description) ||
|
|
47
|
+
(measure.kind !== "total" && measure.kind !== "average") ||
|
|
48
|
+
(measure.missing !== "zero" && measure.missing !== "gap") ||
|
|
49
|
+
!isOptionalString(measure.unit)) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (!isRecord(dimension) || !isString(dimension.name) || typeof dimension.ordered !== "boolean") {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!isRecord(filters) || !isList(filters.notes, isString))
|
|
56
|
+
return null;
|
|
57
|
+
if (raw.time_basis !== undefined && !(isRecord(raw.time_basis) && isString(raw.time_basis.zone))) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (raw.warnings !== undefined && !isList(raw.warnings, isWarning))
|
|
61
|
+
return null;
|
|
62
|
+
if (raw.instance !== undefined &&
|
|
63
|
+
!(isRecord(raw.instance) && isString(raw.instance.name) && isString(raw.instance.url) && raw.instance.url.startsWith("https:"))) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (!isNullableString(raw.link) || !isNullableString(raw.data_through))
|
|
67
|
+
return null;
|
|
68
|
+
if (raw.data_through_precision !== null && !isPrecision(raw.data_through_precision))
|
|
69
|
+
return null;
|
|
70
|
+
if (!isCount(raw.others_count) || !isCount(raw.offset))
|
|
71
|
+
return null;
|
|
72
|
+
if (raw.ranked_by !== undefined && raw.ranked_by !== "value")
|
|
73
|
+
return null;
|
|
74
|
+
if (raw.last_data_period_partial !== undefined && typeof raw.last_data_period_partial !== "boolean") {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (raw.series !== undefined && !isList(raw.series, isSeries))
|
|
78
|
+
return null;
|
|
79
|
+
if (raw.categories !== undefined && !isList(raw.categories, isCategory))
|
|
80
|
+
return null;
|
|
81
|
+
return raw;
|
|
82
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type Unit = "Day" | "Week" | "Month" | "Quarter" | "Year";
|
|
2
|
+
export type MeasureKind = "total" | "average";
|
|
3
|
+
export type DataEndSource = "resource" | "series";
|
|
4
|
+
export type Warning = {
|
|
5
|
+
code: string;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export interface ChartPayload {
|
|
9
|
+
version: 1;
|
|
10
|
+
realm: string;
|
|
11
|
+
statistic: string;
|
|
12
|
+
group_by: string;
|
|
13
|
+
dataset_type: "timeseries" | "aggregate";
|
|
14
|
+
unit?: Unit;
|
|
15
|
+
requested: {
|
|
16
|
+
start: string;
|
|
17
|
+
end: string;
|
|
18
|
+
};
|
|
19
|
+
counted: {
|
|
20
|
+
start: string;
|
|
21
|
+
end: string;
|
|
22
|
+
};
|
|
23
|
+
last_period_incomplete: boolean;
|
|
24
|
+
measure: {
|
|
25
|
+
label: string;
|
|
26
|
+
description: string;
|
|
27
|
+
kind: MeasureKind;
|
|
28
|
+
missing: "zero" | "gap";
|
|
29
|
+
unit?: string;
|
|
30
|
+
};
|
|
31
|
+
dimension: {
|
|
32
|
+
name: string;
|
|
33
|
+
ordered: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** What the chart was filtered to, one note per filter value; empty when unfiltered. */
|
|
36
|
+
filters: {
|
|
37
|
+
notes: string[];
|
|
38
|
+
};
|
|
39
|
+
/** The zone the periods are in. */
|
|
40
|
+
time_basis?: {
|
|
41
|
+
zone: string;
|
|
42
|
+
};
|
|
43
|
+
warnings?: Warning[];
|
|
44
|
+
/** The XDMoD instance the data came from. */
|
|
45
|
+
instance?: {
|
|
46
|
+
name: string;
|
|
47
|
+
url: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A series' data_through is set only when its values stop before the chart's:
|
|
51
|
+
* the start of its last period with a value ("period"), or a last day ("day").
|
|
52
|
+
*/
|
|
53
|
+
series?: {
|
|
54
|
+
name: string;
|
|
55
|
+
points: {
|
|
56
|
+
start: string;
|
|
57
|
+
value: number | null;
|
|
58
|
+
}[];
|
|
59
|
+
data_through?: string;
|
|
60
|
+
data_through_precision?: "day" | "period";
|
|
61
|
+
data_through_source?: DataEndSource;
|
|
62
|
+
}[];
|
|
63
|
+
categories?: {
|
|
64
|
+
name: string;
|
|
65
|
+
value: number | null;
|
|
66
|
+
data_through?: string;
|
|
67
|
+
data_through_source?: DataEndSource;
|
|
68
|
+
}[];
|
|
69
|
+
/** How many top-ranked series or categories XDMoD skipped before these. Absent in older payloads. */
|
|
70
|
+
offset?: number;
|
|
71
|
+
data_through?: string | null;
|
|
72
|
+
data_through_precision?: "day" | "period" | null;
|
|
73
|
+
others_count?: number | null;
|
|
74
|
+
last_data_period_partial?: boolean;
|
|
75
|
+
has_more: boolean;
|
|
76
|
+
ranked_by?: "value";
|
|
77
|
+
/** Null when the public portal can't open this chart. */
|
|
78
|
+
link?: string | null;
|
|
79
|
+
source: "XDMoD";
|
|
80
|
+
retrieved: string;
|
|
81
|
+
}
|
package/dist/payload.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/view.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ChartPayload, Warning } from "./payload.js";
|
|
2
|
+
import type { CaptionFacts } from "./caption.js";
|
|
3
|
+
type Value = number | null;
|
|
4
|
+
export type ChartView = {
|
|
5
|
+
kind: "line" | "bar-ranked" | "bar-ordered";
|
|
6
|
+
title: string;
|
|
7
|
+
/** What the bars are, readable: "Resource", "Field of science". */
|
|
8
|
+
dimension: string;
|
|
9
|
+
/** `color` is the light-mode colour, `darkColor` the dark-mode one. */
|
|
10
|
+
series: {
|
|
11
|
+
name: string;
|
|
12
|
+
color: string;
|
|
13
|
+
darkColor: string;
|
|
14
|
+
points: {
|
|
15
|
+
start: string;
|
|
16
|
+
value: Value;
|
|
17
|
+
}[];
|
|
18
|
+
}[];
|
|
19
|
+
bars: {
|
|
20
|
+
name: string;
|
|
21
|
+
color: string;
|
|
22
|
+
darkColor: string;
|
|
23
|
+
value: Value;
|
|
24
|
+
}[];
|
|
25
|
+
caption: CaptionFacts;
|
|
26
|
+
/** What a screen reader hears for the drawing; the table view holds the values. */
|
|
27
|
+
summary: string;
|
|
28
|
+
/** An https link into XDMoD, or null when there is none to offer. */
|
|
29
|
+
link: string | null;
|
|
30
|
+
/** The XDMoD instance the data came from, when the payload or caller names one. */
|
|
31
|
+
instance: {
|
|
32
|
+
name: string;
|
|
33
|
+
url: string;
|
|
34
|
+
} | null;
|
|
35
|
+
};
|
|
36
|
+
export type ViewOptions = {
|
|
37
|
+
/** Overrides the payload's instance. */
|
|
38
|
+
instance?: {
|
|
39
|
+
name: string;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
/** The viewer's time zone; a differing time_basis.zone adds a caption line. */
|
|
43
|
+
viewerZone?: string;
|
|
44
|
+
};
|
|
45
|
+
/** The warnings used only when the payload has no `warnings` field. */
|
|
46
|
+
export declare const BUILT_IN_WARNINGS: readonly Warning[];
|
|
47
|
+
export declare function isChartWorthy(chart: ChartPayload): boolean;
|
|
48
|
+
export declare const DIMENSION_LABELS: Record<string, string>;
|
|
49
|
+
export declare const DIMENSION_NOUNS: Record<string, string>;
|
|
50
|
+
/** A readable column name for an XDMoD dimension id. */
|
|
51
|
+
export declare function dimensionLabel(name: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* What a screen reader hears for the drawing, in place of its tick labels.
|
|
54
|
+
* The table view holds the values themselves.
|
|
55
|
+
*/
|
|
56
|
+
export declare function chartSummary(view: Pick<ChartView, "kind" | "title" | "dimension" | "series" | "bars" | "caption">): string;
|
|
57
|
+
export declare function toView(chart: ChartPayload, options?: ViewOptions): ChartView;
|
|
58
|
+
export {};
|