derive-dashboards 0.1.1 → 0.3.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 (202) hide show
  1. package/README.md +5 -3
  2. package/dist/cache.mjs +2 -1
  3. package/dist/cli/add.mjs +130 -0
  4. package/dist/cli/cli.mjs +14 -12
  5. package/dist/cli/config.mjs +12 -1
  6. package/dist/cli/doctor.mjs +162 -0
  7. package/dist/cli/init.mjs +3 -2
  8. package/dist/cli/json.mjs +21 -0
  9. package/dist/cli/layers.mjs +33 -0
  10. package/dist/core/document/display.d.mts +63 -0
  11. package/dist/core/document/display.mjs +139 -0
  12. package/dist/core/document/layout.mjs +1 -1
  13. package/dist/core/document/view-layout.d.mts +14 -0
  14. package/dist/core/document/view-layout.mjs +157 -0
  15. package/dist/core/engine/filter.mjs +2 -2
  16. package/dist/core/engine/leaf.mjs +9 -4
  17. package/dist/core/engine/members.mjs +1 -1
  18. package/dist/core/engine/version.d.mts +5 -4
  19. package/dist/core/engine/version.mjs +5 -4
  20. package/dist/core/error/codes.d.mts +4 -1
  21. package/dist/core/error/codes.mjs +4 -1
  22. package/dist/core/index.d.mts +12 -8
  23. package/dist/core/index.mjs +11 -7
  24. package/dist/core/model/member.mjs +5 -2
  25. package/dist/core/model/types.d.mts +13 -13
  26. package/dist/core/model/validate/drill.mjs +6 -15
  27. package/dist/core/model/validate/fields.mjs +130 -0
  28. package/dist/core/model/validate/index.mjs +11 -3
  29. package/dist/core/model/validate/known-members.mjs +133 -0
  30. package/dist/core/model/validate/known-nested.mjs +85 -0
  31. package/dist/core/model/validate/known.mjs +94 -0
  32. package/dist/core/model/validate/members.mjs +7 -4
  33. package/dist/core/model/validate/source.mjs +8 -1
  34. package/dist/core/policy/bind-query.d.mts +12 -0
  35. package/dist/core/policy/bind-query.mjs +53 -0
  36. package/dist/core/query/alias.mjs +11 -1
  37. package/dist/core/query/drill/selection.d.mts +7 -2
  38. package/dist/core/query/drill/selection.mjs +18 -15
  39. package/dist/core/query/filter.d.mts +6 -0
  40. package/dist/core/query/picks.d.mts +8 -2
  41. package/dist/core/query/picks.mjs +11 -4
  42. package/dist/core/query/segments.mjs +2 -1
  43. package/dist/core/result/columns.d.mts +10 -1
  44. package/dist/core/result/columns.mjs +27 -5
  45. package/dist/core/result/time-axis.d.mts +23 -0
  46. package/dist/core/result/time-axis.mjs +72 -0
  47. package/dist/core/result/types.d.mts +36 -1
  48. package/dist/core/schema/aliases.d.mts +7 -0
  49. package/dist/core/schema/aliases.mjs +77 -0
  50. package/dist/core/schema/answer-parts.mjs +23 -1
  51. package/dist/core/schema/answers.d.mts +204 -0
  52. package/dist/core/schema/answers.mjs +2 -0
  53. package/dist/core/schema/index.d.mts +3 -2
  54. package/dist/core/schema/index.mjs +3 -2
  55. package/dist/core/schema/query.d.mts +81 -0
  56. package/dist/core/schema/query.mjs +9 -5
  57. package/dist/core/schema/tools.d.mts +2 -0
  58. package/dist/core/schema/tools.mjs +27 -1
  59. package/dist/core/time/bucket.mjs +8 -2
  60. package/dist/core/types/api.d.mts +7 -1
  61. package/dist/core/types/api.mjs +1 -1
  62. package/dist/dashboards.mjs +4 -0
  63. package/dist/drill-change.mjs +1 -1
  64. package/dist/drill-seal.mjs +1 -0
  65. package/dist/editing.mjs +2 -2
  66. package/dist/endpoints/dashboards.mjs +17 -2
  67. package/dist/endpoints/index.d.mts +15 -2
  68. package/dist/endpoints/meta.mjs +10 -1
  69. package/dist/execute.mjs +32 -17
  70. package/dist/handler.mjs +5 -1
  71. package/dist/index.mjs +6 -1
  72. package/dist/llms.txt +22 -0
  73. package/dist/mcp/format.mjs +42 -8
  74. package/dist/mcp/query.mjs +34 -4
  75. package/dist/postgres-store.mjs +1 -0
  76. package/dist/react/Canvas.mjs +28 -5
  77. package/dist/react/Cell.mjs +2 -1
  78. package/dist/react/Dashboard.d.mts +4 -0
  79. package/dist/react/Dashboard.mjs +27 -4
  80. package/dist/react/DashboardList.mjs +22 -22
  81. package/dist/react/DashboardListRow.mjs +49 -0
  82. package/dist/react/Discard.mjs +5 -2
  83. package/dist/react/Editing.mjs +19 -5
  84. package/dist/react/FilterBar.d.mts +7 -9
  85. package/dist/react/Grid.mjs +7 -19
  86. package/dist/react/Header.mjs +1 -1
  87. package/dist/react/History.mjs +5 -0
  88. package/dist/react/ReadFailed.mjs +23 -0
  89. package/dist/react/Spaces.mjs +15 -1
  90. package/dist/react/Tile.d.mts +2 -0
  91. package/dist/react/Tile.mjs +45 -10
  92. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  93. package/dist/react/arrange-steps.mjs +16 -13
  94. package/dist/react/arrange.mjs +10 -3
  95. package/dist/react/builder/Calcs.mjs +35 -11
  96. package/dist/react/builder/FilterEditor.mjs +196 -0
  97. package/dist/react/builder/Filters.mjs +172 -116
  98. package/dist/react/builder/Formula.mjs +82 -0
  99. package/dist/react/builder/Groups.mjs +1 -0
  100. package/dist/react/builder/Preview.mjs +1 -1
  101. package/dist/react/builder/RangeEditor.mjs +184 -0
  102. package/dist/react/builder/Sections.mjs +41 -6
  103. package/dist/react/builder/Time.mjs +138 -60
  104. package/dist/react/builder/Values.mjs +85 -0
  105. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  106. package/dist/react/builder/base.d.mts +5 -0
  107. package/dist/react/builder/base.mjs +33 -8
  108. package/dist/react/builder/calc.mjs +15 -1
  109. package/dist/react/builder/escape.d.mts +1 -0
  110. package/dist/react/builder/escape.mjs +62 -0
  111. package/dist/react/builder/filter-tree.d.mts +9 -0
  112. package/dist/react/builder/filter-tree.mjs +186 -0
  113. package/dist/react/builder/formula-parse.d.mts +18 -0
  114. package/dist/react/builder/formula-parse.mjs +136 -0
  115. package/dist/react/builder/labels.d.mts +1 -1
  116. package/dist/react/builder/state.d.mts +2 -1
  117. package/dist/react/builder/state.mjs +23 -37
  118. package/dist/react/builder/useBuilder.d.mts +12 -1
  119. package/dist/react/builder/useBuilder.mjs +6 -3
  120. package/dist/react/builder/words.d.mts +59 -0
  121. package/dist/react/builder/words.mjs +73 -0
  122. package/dist/react/context.d.mts +15 -1
  123. package/dist/react/context.mjs +9 -3
  124. package/dist/react/drill/Bars.mjs +2 -2
  125. package/dist/react/drill/props.mjs +2 -1
  126. package/dist/react/drill/useDrill.d.mts +1 -1
  127. package/dist/react/drill/words.d.mts +3 -0
  128. package/dist/react/drill/words.mjs +2 -0
  129. package/dist/react/english.mjs +20 -5
  130. package/dist/react/filters/bar.d.mts +12 -0
  131. package/dist/react/filters/bar.mjs +135 -0
  132. package/dist/react/filters/calendar.mjs +193 -0
  133. package/dist/react/filters/chip.mjs +174 -0
  134. package/dist/react/filters/context.d.mts +22 -0
  135. package/dist/react/filters/context.mjs +78 -0
  136. package/dist/react/filters/dates.mjs +89 -0
  137. package/dist/react/filters/days.d.mts +36 -0
  138. package/dist/react/filters/days.mjs +87 -0
  139. package/dist/react/filters/field-step.mjs +81 -0
  140. package/dist/react/filters/hooks.d.mts +34 -0
  141. package/dist/react/filters/hooks.mjs +94 -0
  142. package/dist/react/filters/listbox.mjs +131 -0
  143. package/dist/react/filters/logic.d.mts +59 -0
  144. package/dist/react/filters/logic.mjs +109 -0
  145. package/dist/react/filters/menu-search.mjs +211 -0
  146. package/dist/react/filters/menu.mjs +85 -0
  147. package/dist/react/filters/number.mjs +127 -0
  148. package/dist/react/filters/numbers.d.mts +47 -0
  149. package/dist/react/filters/numbers.mjs +151 -0
  150. package/dist/react/filters/operator.mjs +104 -0
  151. package/dist/react/filters/phone.mjs +104 -0
  152. package/dist/react/filters/popover.d.mts +19 -0
  153. package/dist/react/filters/popover.mjs +153 -0
  154. package/dist/react/filters/rules.d.mts +8 -0
  155. package/dist/react/filters/rules.mjs +55 -0
  156. package/dist/react/filters/sheet.mjs +196 -0
  157. package/dist/react/filters/state.mjs +132 -0
  158. package/dist/react/filters/suggest.d.mts +47 -0
  159. package/dist/react/filters/suggest.mjs +97 -0
  160. package/dist/react/filters/values.mjs +166 -0
  161. package/dist/react/filters/words.d.mts +81 -0
  162. package/dist/react/filters/words.mjs +73 -0
  163. package/dist/react/format.mjs +11 -4
  164. package/dist/react/index.d.mts +15 -6
  165. package/dist/react/index.mjs +10 -4
  166. package/dist/react/messages.d.mts +34 -2
  167. package/dist/react/place.mjs +7 -3
  168. package/dist/react/renderers/index.d.mts +3 -21
  169. package/dist/react/renderers/index.mjs +68 -6
  170. package/dist/react/renderers/list.d.mts +2 -1
  171. package/dist/react/renderers/list.mjs +9 -12
  172. package/dist/react/renderers/props.d.mts +26 -0
  173. package/dist/react/scope.d.mts +4 -0
  174. package/dist/react/scope.mjs +19 -2
  175. package/dist/react/series-slots.d.mts +37 -0
  176. package/dist/react/series-slots.mjs +71 -0
  177. package/dist/react/series.d.mts +39 -9
  178. package/dist/react/series.mjs +144 -47
  179. package/dist/react/theme.css +930 -19
  180. package/dist/react/useBoard.d.mts +2 -0
  181. package/dist/react/useDashboard.d.mts +3 -0
  182. package/dist/react/useDashboard.mjs +6 -0
  183. package/dist/react/view-grid.mjs +16 -0
  184. package/dist/recharts/axes.mjs +28 -0
  185. package/dist/recharts/axis.mjs +84 -0
  186. package/dist/recharts/bar.d.mts +7 -0
  187. package/dist/recharts/bar.mjs +141 -0
  188. package/dist/recharts/charts.d.mts +4 -5
  189. package/dist/recharts/charts.mjs +2 -208
  190. package/dist/recharts/index.d.mts +3 -1
  191. package/dist/recharts/index.mjs +4 -1
  192. package/dist/recharts/line.d.mts +2 -0
  193. package/dist/recharts/line.mjs +112 -0
  194. package/dist/recharts/marks.mjs +47 -18
  195. package/dist/recharts/parts.mjs +103 -0
  196. package/dist/recharts/table.mjs +71 -0
  197. package/dist/records-read.mjs +1 -1
  198. package/dist/registry/filter-bar.json +26 -0
  199. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  200. package/dist/store/apply.mjs +3 -1
  201. package/package.json +6 -2
  202. package/dist/react/FilterBar.mjs +0 -119
@@ -1,95 +1,192 @@
1
1
  import { formatCell, plotValue } from "./format.mjs";
2
2
  import { ENGLISH } from "./english.mjs";
3
- import { isMark } from "derive-dashboards/core";
3
+ import { seriesSlots } from "./series-slots.mjs";
4
+ import { isMark, roleOf } from "derive-dashboards/core";
4
5
  // src/series.ts
5
- const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
6
+ const isValue = (c) => roleOf(c) === "measure" || roleOf(c) === "calc";
6
7
  /** The series key a dimension's Other draws as. */
7
8
  const OTHER_KEY = "other";
8
9
  const isAll = (cell) => isMark(cell) && cell.mark === "all";
10
+ /** What a value is read against: two columns share an axis only when this is equal. */
11
+ const scaleOf = (c) => JSON.stringify([
12
+ c.unit ?? null,
13
+ c.format ?? null,
14
+ c.fraction ?? null
15
+ ]);
9
16
  /**
10
- * Chart data from an answer. The first non-value column is the x axis (the time bucket when
11
- * there is one). With a second key column, the first value is split into one series per
12
- * value of it, and Other in that column is one more series; otherwise every value column is
13
- * its own series. Other on the x axis is one more point; totals are not drawn.
17
+ * Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
18
+ * when there is one) and, after it, what splits the series; value columns are what is drawn.
19
+ * With split keys, the first value (the first calc, when there are calcs) becomes one series per
20
+ * combination of the keys ("Design · High"), Other one more. Without, every value is a series.
21
+ * Values in a second unit are read on a right axis; a third unit, or more values than a split can
22
+ * draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
23
+ * keyed by raw values, so two that read alike stay apart. Totals are not drawn.
24
+ *
25
+ * `slots` is the dashboard's book of palette places, so a value has one colour on every tile;
26
+ * left out, the chart keeps a book of its own.
14
27
  */
15
- function toSeries(answer, format = {}) {
28
+ function toSeries(answer, format = {}, slots) {
16
29
  const at = /* @__PURE__ */ new Map();
17
- const drawn = drawSeries(answer, format, (point, key, row) => {
30
+ const shape = shapeOf(answer, format, slots ?? seriesSlots(), (point, key, row) => {
18
31
  at.set(`${String(point)}|${key}`, row);
19
32
  });
33
+ const { xs, ...drawn } = drawSeries(answer, shape);
20
34
  return {
21
35
  ...drawn,
36
+ ...bucketsOf(answer, shape.keys, xs),
22
37
  rowAt: (point, key) => {
23
38
  const index = typeof point === "number" ? point : drawn.points.indexOf(point);
24
39
  return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
25
40
  }
26
41
  };
27
42
  }
28
- function drawSeries(answer, format, seen) {
29
- const keyCount = answer.columns.filter((c) => !isValue(c)).length;
30
- const all = answer.columns.slice(keyCount);
31
- const calcs = all.filter((c) => c.id.startsWith("c"));
32
- const values = calcs.length > 0 ? calcs : all;
33
- const rows = answer.rows.map((row, index) => ({
34
- row,
35
- index
36
- })).filter(({ row }) => !row.some((cell) => isAll(cell)));
43
+ /** Each point's time bucket, when the x axis is the answer's time column. */
44
+ function bucketsOf(answer, keys, xs) {
45
+ const x = answer.columns[keys[0] ?? -1];
46
+ if (answer.time === void 0 || x === void 0 || roleOf(x) !== "time") return {};
47
+ const named = new Map(answer.time.buckets.map((b) => [b.label, b]));
48
+ return { buckets: xs.map((cell) => typeof cell === "string" ? named.get(cell) : void 0) };
49
+ }
50
+ /** The values to draw: calcs when there are any (what the widget was built to see), else measures. */
51
+ function valuesOf(columns) {
52
+ const all = columns.filter((c) => isValue(c));
53
+ const calcs = all.filter((c) => roleOf(c) === "calc");
54
+ return calcs.length > 0 ? calcs : all;
55
+ }
56
+ /** How an answer is read into a chart: its key columns, how a key reads, and the book of slots. */
57
+ function shapeOf(answer, format, slots, seen) {
58
+ const keys = answer.columns.flatMap((c, i) => isValue(c) ? [] : [i]);
37
59
  const keyText = (cell, column) => {
38
60
  if (cell !== null && cell !== "") return formatCell(cell, column, format);
39
61
  const words = format.messages ?? ENGLISH;
40
62
  return column === void 0 ? words.empty : words.drillNone(column.label);
41
63
  };
42
- const xOf = (row) => keyText(row[0] ?? null, answer.columns[0]);
43
- if (keyCount < 2) {
44
- const series = values.map((column) => ({
45
- key: column.id,
46
- label: column.label,
47
- column
48
- }));
64
+ return {
65
+ answer,
66
+ keys,
67
+ keyText,
68
+ seen,
69
+ slots
70
+ };
71
+ }
72
+ function drawSeries(answer, shape) {
73
+ const values = valuesOf(answer.columns);
74
+ const rows = answer.rows.map((row, index) => ({
75
+ row,
76
+ index
77
+ })).filter(({ row }) => !row.some((cell) => isAll(cell)));
78
+ return shape.keys.length < 2 ? plainSeries(rows, values, shape) : splitSeries(rows, values, shape);
79
+ }
80
+ /** The x label of a row, from its first key. */
81
+ const xOf = (shape, row) => {
82
+ const at = shape.keys[0];
83
+ return at === void 0 ? "" : shape.keyText(row[at] ?? null, shape.answer.columns[at]);
84
+ };
85
+ /** One series per value: the first unit on the left axis, a second on the right, a third not drawn. */
86
+ function plainSeries(rows, values, shape) {
87
+ const scales = [...new Set(values.map((c) => scaleOf(c)))];
88
+ const side = (c) => scales.indexOf(scaleOf(c));
89
+ const drawn = values.filter((c) => side(c) < 2);
90
+ const series = drawn.map((column, slot) => ({
91
+ key: column.id,
92
+ label: column.label,
93
+ column,
94
+ axis: side(column) === 0 ? "left" : "right",
95
+ slot
96
+ }));
97
+ const points = rows.map(({ row, index }, i) => {
98
+ shape.seen(i, "*", index);
99
+ const cells = drawn.map((c) => [c.id, plotValue(row[shape.answer.columns.indexOf(c)] ?? null)]);
49
100
  return {
50
- points: rows.map(({ row, index }, i) => {
51
- seen(i, "*", index);
52
- return {
53
- x: keyCount === 0 ? "" : xOf(row),
54
- ...Object.fromEntries(values.map((c) => [c.id, plotValue(row[answer.columns.indexOf(c)] ?? null)]))
55
- };
56
- }),
57
- series,
58
- split: false
101
+ x: xOf(shape, row),
102
+ "#": i,
103
+ ...Object.fromEntries(cells)
59
104
  };
60
- }
61
- const first = values[0];
105
+ });
106
+ const xs = rows.map(({ row }) => row[shape.keys[0] ?? -1] ?? null);
107
+ return {
108
+ points,
109
+ series,
110
+ split: false,
111
+ notDrawn: values.filter((c) => side(c) >= 2),
112
+ xs
113
+ };
114
+ }
115
+ /** One value split into a series per combination of the keys after the first; other values are not drawn. */
116
+ function splitSeries(rows, values, shape) {
117
+ const [first, ...rest] = values;
62
118
  if (first === void 0) return {
63
119
  points: [],
64
120
  series: [],
65
- split: true
121
+ split: true,
122
+ notDrawn: [],
123
+ xs: []
66
124
  };
125
+ const { answer, keys, keyText } = shape;
126
+ const valueAt = answer.columns.indexOf(first);
67
127
  const byX = /* @__PURE__ */ new Map();
128
+ const xs = [];
68
129
  const names = /* @__PURE__ */ new Map();
69
130
  for (const { row, index } of rows) {
70
- const split = row[1] ?? null;
71
- const key = isMark(split) ? split.mark : `s${JSON.stringify(split)}`;
72
- names.set(key, keyText(split, answer.columns[1]));
73
- const point = byX.get(xOf(row)) ?? { x: xOf(row) };
74
- point[key] = plotValue(row[keyCount] ?? null);
75
- byX.set(xOf(row), point);
76
- seen([...byX.keys()].indexOf(xOf(row)), key, index);
131
+ const cells = keys.slice(1).map((i) => row[i] ?? null);
132
+ const key = splitKey(cells);
133
+ const label = cells.map((cell, i) => keyText(cell, answer.columns[keys[i + 1] ?? -1]));
134
+ names.set(key, {
135
+ label: label.join(" · "),
136
+ cells
137
+ });
138
+ const x = row[keys[0] ?? 0] ?? null;
139
+ const xKey = JSON.stringify(x);
140
+ if (!byX.has(xKey)) xs.push(x);
141
+ const point = byX.get(xKey) ?? {
142
+ x: xOf(shape, row),
143
+ "#": byX.size
144
+ };
145
+ point[key] = plotValue(row[valueAt] ?? null);
146
+ byX.set(xKey, point);
147
+ shape.seen(Number(point["#"]), key, index);
77
148
  }
78
- const series = [...names].map(([key, label]) => ({
149
+ const by = keys.slice(1).flatMap((i) => answer.columns[i] ?? []);
150
+ const series = [...names].map(([key, { label, cells }]) => ({
79
151
  key,
80
152
  label,
81
- column: first
153
+ column: first,
154
+ axis: "left",
155
+ ...key === "other" ? {} : { slot: shape.slots.of({
156
+ by,
157
+ key,
158
+ cells
159
+ }) }
82
160
  })).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
83
161
  return {
84
162
  points: [...byX.values()],
85
163
  series,
86
- split: true
164
+ split: true,
165
+ notDrawn: rest,
166
+ xs
87
167
  };
88
168
  }
169
+ /** A series' key from its split cells: Other stays "other", any value is its raw JSON. */
170
+ function splitKey(cells) {
171
+ const [only] = cells;
172
+ if (cells.length === 1 && only !== void 0 && isMark(only)) return only.mark;
173
+ return `s${JSON.stringify(cells.length === 1 ? only ?? null : cells)}`;
174
+ }
89
175
  /**
90
176
  * The row of the answer behind a point of any chart kit's series, by the point's place (or the
91
177
  * point) and the series key; undefined for a point no row stands behind. Pass it to
92
178
  * `drill.open(row, series.column.id)` to open what is behind the point.
93
179
  */
94
180
  const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
95
- export { OTHER_KEY, rowAt, toSeries };
181
+ /**
182
+ * Whether the answer's last time bucket is still running: the range ends before the bucket
183
+ * does, as this week does on its Monday. Its value is not final, so a chart marks it rather
184
+ * than draw it as a fall. The server says so (`answer.time`), by the engine's own calendar.
185
+ */
186
+ function lastBucketOpen(answer) {
187
+ const at = answer.columns.findIndex((c) => roleOf(c) === "time");
188
+ const last = answer.rows.findLast((row) => typeof row[at] === "string")?.[at];
189
+ const bucket = answer.time?.buckets.find((b) => b.label === last);
190
+ return bucket?.partial === "end" || bucket?.partial === "both";
191
+ }
192
+ export { OTHER_KEY, lastBucketOpen, rowAt, toSeries };