@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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/caption.d.ts +68 -0
  4. package/dist/caption.js +118 -0
  5. package/dist/csv.d.ts +22 -0
  6. package/dist/csv.js +95 -0
  7. package/dist/fixtures.d.ts +58 -0
  8. package/dist/fixtures.js +1 -0
  9. package/dist/format.d.ts +6 -0
  10. package/dist/format.js +39 -0
  11. package/dist/generated/palette.d.ts +4 -0
  12. package/dist/generated/palette.js +23 -0
  13. package/dist/generated/statistics.d.ts +6 -0
  14. package/dist/generated/statistics.js +217 -0
  15. package/dist/index.d.ts +13 -0
  16. package/dist/index.js +8 -0
  17. package/dist/measure.d.ts +7 -0
  18. package/dist/measure.js +14 -0
  19. package/dist/palette.d.ts +11 -0
  20. package/dist/palette.js +19 -0
  21. package/dist/parse.d.ts +3 -0
  22. package/dist/parse.js +82 -0
  23. package/dist/payload.d.ts +81 -0
  24. package/dist/payload.js +1 -0
  25. package/dist/view.d.ts +58 -0
  26. package/dist/view.js +243 -0
  27. package/fixtures/README.md +13 -0
  28. package/fixtures/aggregate-empty.json +85 -0
  29. package/fixtures/aggregate-fills-empty-buckets.json +118 -0
  30. package/fixtures/aggregate-has-more-others-count.json +103 -0
  31. package/fixtures/aggregate-incomplete-with-probe-day.json +108 -0
  32. package/fixtures/aggregate-jobs-by-resource.json +66 -0
  33. package/fixtures/aggregate-marks-resources-that-stop.json +125 -0
  34. package/fixtures/aggregate-no-fill-for-average.json +115 -0
  35. package/fixtures/aggregate-no-fill-incomplete-buckets.json +110 -0
  36. package/fixtures/aggregate-no-fill-when-bucket-filtered.json +114 -0
  37. package/fixtures/aggregate-no-fill-when-more.json +110 -0
  38. package/fixtures/aggregate-no-fill-with-offset.json +110 -0
  39. package/fixtures/aggregate-nominal-not-reordered.json +107 -0
  40. package/fixtures/aggregate-offset-page.json +103 -0
  41. package/fixtures/aggregate-ordered-bucket-order.json +116 -0
  42. package/fixtures/aggregate-probe-reaches-end.json +108 -0
  43. package/fixtures/aggregate-unknown-bucket-last.json +115 -0
  44. package/fixtures/aggregate-unordered.json +103 -0
  45. package/fixtures/average-leaves-gaps.json +125 -0
  46. package/fixtures/calendar-december-into-january.json +113 -0
  47. package/fixtures/calendar-range-ends-at-month-end.json +108 -0
  48. package/fixtures/cpu-hours-by-resource-incomplete.json +125 -0
  49. package/fixtures/early-end-average-by-resource-not-filled.json +147 -0
  50. package/fixtures/early-end-average-other-dimension.json +144 -0
  51. package/fixtures/early-end-daily-by-queue.json +180 -0
  52. package/fixtures/early-end-daily-series-stops.json +139 -0
  53. package/fixtures/early-end-day-inside-last-period.json +147 -0
  54. package/fixtures/early-end-fill-stops-at-last-day.json +145 -0
  55. package/fixtures/early-end-fills-to-resource-last-day.json +149 -0
  56. package/fixtures/early-end-other-dimension-never-filled.json +145 -0
  57. package/fixtures/early-end-probe-window-too-short.json +144 -0
  58. package/fixtures/early-end-resource-retired.json +144 -0
  59. package/fixtures/early-end-several-resources.json +205 -0
  60. package/fixtures/early-end-without-probe.json +140 -0
  61. package/fixtures/label-stripped-from-description.json +95 -0
  62. package/fixtures/no-series-values.json +86 -0
  63. package/fixtures/partial-last-day.json +119 -0
  64. package/fixtures/partial-last-month.json +122 -0
  65. package/fixtures/probe-day-after-range.json +113 -0
  66. package/fixtures/probe-day-inside-last-month.json +113 -0
  67. package/fixtures/probe-day-last-day-of-period.json +113 -0
  68. package/fixtures/rank-prefixes-on-series.json +130 -0
  69. package/fixtures/series-ended-before-probe-day.json +188 -0
  70. package/fixtures/timeseries-complete-last-period.json +113 -0
  71. package/fixtures/timeseries-month-gaps.json +121 -0
  72. package/package.json +28 -4
  73. package/rules/README.md +29 -0
  74. package/rules/palette.json +4 -0
  75. package/rules/statistics.json +217 -0
  76. package/schema/chart-payload.v1.json +320 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Connect.CI contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # @connectci/xdmod-charts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The shared XDMoD chart contract used by ACCESS chat and Open OnDemand's ood-agent: a JSON Schema (`schema/chart-payload.v1.json`), the `ChartPayload` TypeScript types, and `parsePayload`, which validates an untrusted payload and returns it typed or `null`.
4
+
5
+ Version policy: the payload stays `version: 1`. Changes only add optional fields. Enumerated fields are closed, so a client that meets a value it doesn't know shows no chart, and it ignores fields it doesn't know.
6
+
7
+ Consumers pin a git tag. Each tagged commit contains the built `dist/`, so installs need no build step. Nothing is published to npm or PyPI.
@@ -0,0 +1,68 @@
1
+ import type { Warning } from "./payload.js";
2
+ /** A series or bar whose data stops before the rest of the chart's. */
3
+ export type EarlyEnd = {
4
+ name: string;
5
+ through: string;
6
+ /** "day": the last day with data. "period": the start of the last period with data. */
7
+ precision: "day" | "period";
8
+ /** "resource": XDMoD has no data from that resource after it. "series": nothing recorded, reason unknown. */
9
+ source: "resource" | "series";
10
+ };
11
+ export type CaptionFacts = {
12
+ measure: string;
13
+ definition: string;
14
+ counted: {
15
+ start: string;
16
+ end: string;
17
+ };
18
+ /** Where XDMoD's data stops, when it says. */
19
+ dataThrough?: string;
20
+ /** "day" (the default): dataThrough is the last day with data. "period": only the start of the last period with data. */
21
+ dataThroughPrecision?: "day" | "period";
22
+ /** The counted range has periods after the dataThrough one, all empty. */
23
+ noDataAfter?: boolean;
24
+ /** The data_through period, when XDMoD's data likely covers only part of it. */
25
+ partialPeriod?: string;
26
+ unit?: string;
27
+ filters: string[];
28
+ /** One line when the chart's days are counted in a zone other than the viewer's. */
29
+ zoneNote?: string;
30
+ /** More series or bars than the chart draws. */
31
+ hasMore: boolean;
32
+ /** How many there are in all, when known. */
33
+ total?: number;
34
+ /** How many top-ranked ones come before the first shown. */
35
+ offset?: number;
36
+ /** Shown series or bars whose data stops before the chart's. */
37
+ earlyEnds?: EarlyEnd[];
38
+ /** What they are, plural: "resources", "fields of science", "groups". */
39
+ groupNoun?: string;
40
+ /** The dimension is ordered buckets (job size), not a ranking. */
41
+ ordered?: boolean;
42
+ incomplete: boolean;
43
+ warnings: Warning[];
44
+ /** The XDMoD instance's name when the payload names one, else "XDMoD". */
45
+ source: string;
46
+ retrieved: string;
47
+ };
48
+ /**
49
+ * Where XDMoD's data stops, as far as the caption can honestly say. A day
50
+ * is said when it's before the counted end. A period start is not a day the
51
+ * data stops (the period may be full), so it's said only as "no data after"
52
+ * that period, and only when later periods in the range are empty.
53
+ */
54
+ export declare function dataEnd(caption: CaptionFacts): {
55
+ day: string;
56
+ } | {
57
+ period: string;
58
+ } | null;
59
+ /** Which ranks a chart past the top shows: "4 to 8". */
60
+ export declare function rankRange(caption: CaptionFacts, shown: number): string | null;
61
+ /** When an early end is, at the precision it's known. */
62
+ export declare function earlyEndWhen(end: EarlyEnd, unit?: string): string;
63
+ /**
64
+ * The caption under a chart, one line per fact, in reading order. Every
65
+ * renderer draws these, so they all say the same thing. `shown` is how many
66
+ * series or bars the chart draws.
67
+ */
68
+ export declare function captionLines(caption: CaptionFacts, shown: number): string[];
@@ -0,0 +1,118 @@
1
+ import { formatDay, formatPeriod } from "./format.js";
2
+ /**
3
+ * Where XDMoD's data stops, as far as the caption can honestly say. A day
4
+ * is said when it's before the counted end. A period start is not a day the
5
+ * data stops (the period may be full), so it's said only as "no data after"
6
+ * that period, and only when later periods in the range are empty.
7
+ */
8
+ export function dataEnd(caption) {
9
+ const through = caption.dataThrough;
10
+ if (!through)
11
+ return null;
12
+ if ((caption.dataThroughPrecision ?? "day") === "day") {
13
+ return through < caption.counted.end ? { day: through } : null;
14
+ }
15
+ return caption.noDataAfter ? { period: formatPeriod(through, caption.unit) } : null;
16
+ }
17
+ /** Which ranks a chart past the top shows: "4 to 8". */
18
+ export function rankRange(caption, shown) {
19
+ const offset = caption.offset ?? 0;
20
+ return offset > 0 && shown > 0 ? `${offset + 1} to ${offset + shown}` : null;
21
+ }
22
+ /** How many of how many the chart shows, or null when it shows them all. */
23
+ function shownLine(caption, shown) {
24
+ const ranks = rankRange(caption, shown);
25
+ if (ranks) {
26
+ const offset = caption.offset ?? 0;
27
+ // XDMoD pages an ordered dimension in bucket order, not by value.
28
+ if (caption.ordered) {
29
+ const of = caption.total === undefined ? "" : ` of ${caption.total}`;
30
+ return `Showing buckets ${ranks}${of}, leaving out the first ${offset}.`;
31
+ }
32
+ if (caption.total !== undefined) {
33
+ return `Showing ranks ${ranks} of ${caption.total} ${caption.groupNoun ?? "groups"}, not the top ${offset}.`;
34
+ }
35
+ return `Showing ranks ${ranks}, not the top ${offset}${caption.hasMore ? "; XDMoD has more" : ""}.`;
36
+ }
37
+ if (!caption.hasMore)
38
+ return null;
39
+ if (caption.total === undefined) {
40
+ return `Showing the top ${shown}; XDMoD has more.`;
41
+ }
42
+ return caption.ordered
43
+ ? `Showing ${shown} of ${caption.total} buckets.`
44
+ : `Showing the top ${shown} of ${caption.total} ${caption.groupNoun ?? "groups"}.`;
45
+ }
46
+ /** When an early end is, at the precision it's known. */
47
+ export function earlyEndWhen(end, unit) {
48
+ return end.precision === "day" ? formatDay(end.through) : formatPeriod(end.through, unit);
49
+ }
50
+ const MAX_LISTED_NAMES = 6;
51
+ /** "A", "A and B", "A, B and C", past six "A, B, C, D, E, F and 2 more". */
52
+ function listNames(names) {
53
+ if (names.length > MAX_LISTED_NAMES) {
54
+ return `${names.slice(0, MAX_LISTED_NAMES).join(", ")} and ${names.length - MAX_LISTED_NAMES} more`;
55
+ }
56
+ return names.length < 2
57
+ ? names.join("")
58
+ : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
59
+ }
60
+ /** The early ends as one sentence, worded only as strongly as is known, names that stop on the same date together. */
61
+ function earlyEndsLine(ends, unit) {
62
+ const groups = new Map();
63
+ for (const end of ends) {
64
+ const when = earlyEndWhen(end, unit);
65
+ const key = `${end.source}|${when}`;
66
+ const group = groups.get(key) ?? { source: end.source, when, names: [] };
67
+ group.names.push(end.name);
68
+ groups.set(key, group);
69
+ }
70
+ const text = [...groups.values()]
71
+ .map((g) => g.source === "resource"
72
+ ? `XDMoD has no data from ${listNames(g.names)} after ${g.when}`
73
+ : `nothing is recorded for ${listNames(g.names)} after ${g.when}`)
74
+ .join("; ");
75
+ return `${text[0].toUpperCase()}${text.slice(1)}.`;
76
+ }
77
+ /**
78
+ * The caption under a chart, one line per fact, in reading order. Every
79
+ * renderer draws these, so they all say the same thing. `shown` is how many
80
+ * series or bars the chart draws.
81
+ */
82
+ export function captionLines(caption, shown) {
83
+ const range = `${formatDay(caption.counted.start)} to ${formatDay(caption.counted.end)}`;
84
+ const lines = [`${caption.measure}: ${caption.definition}`];
85
+ // Right under the definition, which reads as ACCESS-wide.
86
+ if (caption.filters.length > 0) {
87
+ lines.push(`Filtered to ${caption.filters.join("; ")}`);
88
+ }
89
+ lines.push(caption.unit ? `${range}, by ${caption.unit.toLowerCase()}` : range);
90
+ if (caption.zoneNote)
91
+ lines.push(caption.zoneNote);
92
+ // XDMoD's public data often stops weeks before the range does.
93
+ const end = dataEnd(caption);
94
+ if (end) {
95
+ const lead = "day" in end
96
+ ? `XDMoD has data through ${formatDay(end.day)}`
97
+ : `XDMoD has no data after ${end.period}`;
98
+ lines.push(caption.partialPeriod
99
+ ? `${lead}, so ${formatPeriod(caption.partialPeriod, caption.unit)} may be partial.`
100
+ : `${lead}.`);
101
+ }
102
+ if (caption.earlyEnds?.length) {
103
+ lines.push(earlyEndsLine(caption.earlyEnds, caption.unit));
104
+ }
105
+ const showing = shownLine(caption, shown);
106
+ if (showing)
107
+ lines.push(showing);
108
+ // A partial period already says the end isn't settled.
109
+ if (caption.incomplete && !caption.partialPeriod) {
110
+ lines.push(caption.unit
111
+ ? "The last period is still in progress."
112
+ : "The range runs to today, so it's still in progress.");
113
+ }
114
+ for (const warning of caption.warnings)
115
+ lines.push(warning.text);
116
+ lines.push(`Source: ${caption.source}, retrieved ${formatDay(caption.retrieved)}`);
117
+ return lines;
118
+ }
package/dist/csv.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { ChartView } from "./view.js";
2
+ /** How many series or bars a view draws. */
3
+ export declare function shownCount(view: ChartView): number;
4
+ /** One CSV cell: quoted when it holds a comma, quote or line break. */
5
+ export declare function csvCell(value: string | number | null): string;
6
+ export declare const csvRow: (cells: (string | number | null)[]) => string;
7
+ /**
8
+ * The chart's numbers as CSV: what was counted first, so the file still
9
+ * makes sense on its own, then one row per period or bar. Missing values are
10
+ * empty cells.
11
+ */
12
+ export declare function chartCsv(view: ChartView): string;
13
+ /** The periods of a line chart, from its longest series. XDMoD gives every series the same periods. */
14
+ export declare function periods(view: ChartView): string[];
15
+ /**
16
+ * The index of the period that contains `day`: the last one starting on or
17
+ * before it. data_through can fall mid-period (Oct 19 in a monthly chart), so
18
+ * an exact match on period starts would miss it. -1 if `day` is before the first period.
19
+ */
20
+ export declare function periodContaining(starts: string[], day: string): number;
21
+ /** A file name (no extension) from the measure and the counted range. */
22
+ export declare function chartFileName(view: ChartView): string;
package/dist/csv.js ADDED
@@ -0,0 +1,95 @@
1
+ import { dataEnd, earlyEndWhen, rankRange } from "./caption.js";
2
+ import { formatPeriod } from "./format.js";
3
+ /** How many series or bars a view draws. */
4
+ export function shownCount(view) {
5
+ return view.kind === "line" ? view.series.length : view.bars.length;
6
+ }
7
+ /** One CSV cell: quoted when it holds a comma, quote or line break. */
8
+ export function csvCell(value) {
9
+ if (value === null)
10
+ return "";
11
+ // A spreadsheet runs a text cell that starts like a formula; names come
12
+ // from XDMoD, so they're kept as text. Numbers stay numbers.
13
+ const text = typeof value === "string" && /^[=+\-@\t\r]/.test(value) ? `'${value}` : String(value);
14
+ return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
15
+ }
16
+ export const csvRow = (cells) => cells.map(csvCell).join(",");
17
+ /**
18
+ * The chart's numbers as CSV: what was counted first, so the file still
19
+ * makes sense on its own, then one row per period or bar. Missing values are
20
+ * empty cells.
21
+ */
22
+ export function chartCsv(view) {
23
+ const { caption } = view;
24
+ const end = dataEnd(caption);
25
+ const ranks = rankRange(caption, shownCount(view));
26
+ const rows = [
27
+ ["Measure", caption.measure],
28
+ ["Counted", `${caption.counted.start} to ${caption.counted.end}`],
29
+ ...(end
30
+ ? [("day" in end ? ["Data through", end.day] : ["No data after", end.period])]
31
+ : []),
32
+ ...(caption.partialPeriod
33
+ ? [["Partial period", formatPeriod(caption.partialPeriod, caption.unit)]]
34
+ : []),
35
+ ...(caption.earlyEnds ?? []).map((e) => [
36
+ e.source === "resource"
37
+ ? `No data after (${e.name})`
38
+ : `Nothing recorded after (${e.name})`,
39
+ e.precision === "day" ? e.through : earlyEndWhen(e, caption.unit),
40
+ ]),
41
+ ["Filters", caption.filters.length ? caption.filters.join("; ") : "None"],
42
+ ...(ranks
43
+ ? [(caption.ordered ? ["Buckets", ranks] : ["Ranks", `${ranks} by value`])]
44
+ : []),
45
+ ["Retrieved", caption.retrieved],
46
+ ["Source", caption.source],
47
+ ...(view.link ? [["XDMoD link", view.link]] : []),
48
+ ];
49
+ const lines = rows.map(csvRow);
50
+ lines.push("");
51
+ if (view.kind === "line") {
52
+ lines.push(csvRow(["Period", ...view.series.map((s) => s.name)]));
53
+ for (const [i, start] of periods(view).entries()) {
54
+ lines.push(csvRow([start, ...view.series.map((s) => s.points[i]?.value ?? null)]));
55
+ }
56
+ }
57
+ else {
58
+ lines.push(csvRow([view.dimension, caption.measure]));
59
+ for (const bar of view.bars)
60
+ lines.push(csvRow([bar.name, bar.value]));
61
+ }
62
+ return lines.join("\n");
63
+ }
64
+ /** The periods of a line chart, from its longest series. XDMoD gives every series the same periods. */
65
+ export function periods(view) {
66
+ let longest = [];
67
+ for (const s of view.series) {
68
+ if (s.points.length > longest.length)
69
+ longest = s.points.map((p) => p.start);
70
+ }
71
+ return longest;
72
+ }
73
+ /**
74
+ * The index of the period that contains `day`: the last one starting on or
75
+ * before it. data_through can fall mid-period (Oct 19 in a monthly chart), so
76
+ * an exact match on period starts would miss it. -1 if `day` is before the first period.
77
+ */
78
+ export function periodContaining(starts, day) {
79
+ const target = day.slice(0, 10);
80
+ let found = -1;
81
+ starts.forEach((start, i) => {
82
+ if (start.slice(0, 10) <= target)
83
+ found = i;
84
+ });
85
+ return found;
86
+ }
87
+ /** A file name (no extension) from the measure and the counted range. */
88
+ export function chartFileName(view) {
89
+ const slug = view.caption.measure
90
+ .toLowerCase()
91
+ .replace(/[^a-z0-9]+/g, "-")
92
+ .replace(/^-|-$/g, "");
93
+ const { start, end } = view.caption.counted;
94
+ return `xdmod-${slug}-${start}-to-${end}`;
95
+ }
@@ -0,0 +1,58 @@
1
+ import type { ChartPayload, Unit } from "./payload.js";
2
+ /**
3
+ * Everything a producer's pure builder is given: XDMoD's answers already fetched, no I/O left.
4
+ * `series` and `categories` are post-trim: the adapter (not the builder) drops gap-connector
5
+ * traces, "All N Others" entries and series with no values, applies the limit, and derives
6
+ * `has_more` and `others_count`, as access-mcp's trimToLimit does. `request.limit` is informational.
7
+ */
8
+ export interface BuilderInput {
9
+ request: {
10
+ realm: string;
11
+ statistic: string;
12
+ group_by: string;
13
+ dataset_type: "timeseries" | "aggregate";
14
+ start_date: string;
15
+ end_date: string;
16
+ unit?: Unit;
17
+ filters_notes: string[];
18
+ /** True when the request filters the group_by dimension itself. */
19
+ dimension_filtered: boolean;
20
+ offset: number;
21
+ limit: number;
22
+ };
23
+ label: string;
24
+ /** XDMoD's description as sent (HTML allowed). */
25
+ description: string;
26
+ /** The current date, YYYY-MM-DD, in the producer's clock. */
27
+ today: string;
28
+ series?: {
29
+ name: string;
30
+ values: Record<string, number>;
31
+ }[];
32
+ categories?: {
33
+ name: string;
34
+ value: number | null;
35
+ }[];
36
+ others_count: number | null;
37
+ has_more: boolean;
38
+ dimension_order?: string[];
39
+ dimension_complete?: boolean;
40
+ latest_data_day: string | null;
41
+ resource_days: {
42
+ since: string;
43
+ days: Record<string, string>;
44
+ } | null;
45
+ link: string | null;
46
+ time_zone: string | null;
47
+ instance: {
48
+ name: string;
49
+ url: string;
50
+ } | null;
51
+ }
52
+ /** One file in fixtures/: the builder input and the payload every listed producer must produce. */
53
+ export type ChartFixture = {
54
+ description: string;
55
+ producers: ("ts" | "py")[];
56
+ input: BuilderInput;
57
+ expected: ChartPayload;
58
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /** A UTC date, so "2026-08-01" stays Aug 1 wherever the reader is. */
2
+ export declare function parseDay(iso: string): Date | null;
3
+ /** "2026-08-01" as "Aug 1, 2026". Anything else comes back unchanged. */
4
+ export declare function formatDay(iso: string): string;
5
+ /** A period's start date, named at the chart's unit: "Aug 2026", "Q3 2026", "Week of Nov 2, 2026". */
6
+ export declare function formatPeriod(start: string, unit?: string): string;
package/dist/format.js ADDED
@@ -0,0 +1,39 @@
1
+ const DAY = /^(\d{4})-(\d{2})-(\d{2})/;
2
+ /** A UTC date, so "2026-08-01" stays Aug 1 wherever the reader is. */
3
+ export function parseDay(iso) {
4
+ const m = DAY.exec(iso);
5
+ if (!m)
6
+ return null;
7
+ return new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
8
+ }
9
+ /** "2026-08-01" as "Aug 1, 2026". Anything else comes back unchanged. */
10
+ export function formatDay(iso) {
11
+ const day = parseDay(iso);
12
+ if (!day)
13
+ return iso;
14
+ return day.toLocaleDateString("en-US", {
15
+ month: "short",
16
+ day: "numeric",
17
+ year: "numeric",
18
+ timeZone: "UTC",
19
+ });
20
+ }
21
+ /** A period's start date, named at the chart's unit: "Aug 2026", "Q3 2026", "Week of Nov 2, 2026". */
22
+ export function formatPeriod(start, unit) {
23
+ const day = parseDay(start);
24
+ if (!day)
25
+ return start;
26
+ const year = day.getUTCFullYear();
27
+ switch (unit) {
28
+ case "Year":
29
+ return String(year);
30
+ case "Quarter":
31
+ return `Q${Math.floor(day.getUTCMonth() / 3) + 1} ${year}`;
32
+ case "Month":
33
+ return day.toLocaleDateString("en-US", { month: "short", year: "numeric", timeZone: "UTC" });
34
+ case "Week":
35
+ return `Week of ${formatDay(start)}`;
36
+ default:
37
+ return formatDay(start);
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ export declare const PALETTE: {
2
+ light: readonly string[];
3
+ dark: readonly string[];
4
+ };
@@ -0,0 +1,23 @@
1
+ // Generated by scripts/gen.mjs from rules/*.json. Do not edit.
2
+ export const PALETTE = {
3
+ "light": [
4
+ "#2a78d6",
5
+ "#eb6834",
6
+ "#1baf7a",
7
+ "#eda100",
8
+ "#e87ba4",
9
+ "#008300",
10
+ "#6250d6",
11
+ "#e34948"
12
+ ],
13
+ "dark": [
14
+ "#3987e5",
15
+ "#d95926",
16
+ "#199e70",
17
+ "#c98500",
18
+ "#d55181",
19
+ "#0ca30c",
20
+ "#9085e9",
21
+ "#e66767"
22
+ ]
23
+ };
@@ -0,0 +1,6 @@
1
+ export type Statistic = {
2
+ kind: "total" | "average";
3
+ unit: string;
4
+ additive: boolean;
5
+ };
6
+ export declare const STATISTICS: Record<string, Statistic>;