derive-dashboards 0.7.0 → 0.8.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 (49) hide show
  1. package/README.md +1 -1
  2. package/dist/charts/kinds/area-marks.mjs +20 -19
  3. package/dist/charts/kinds/grid-marks.mjs +8 -10
  4. package/dist/charts/kinds/grid-words.mjs +1 -1
  5. package/dist/charts/kinds/grid.d.mts +1 -1
  6. package/dist/charts/kinds/grid.mjs +3 -2
  7. package/dist/charts/marks/axes.mjs +2 -1
  8. package/dist/charts/marks/x-axis.mjs +3 -2
  9. package/dist/charts/scene/types.d.mts +1 -1
  10. package/dist/charts/theme.d.mts +25 -25
  11. package/dist/charts/theme.mjs +35 -27
  12. package/dist/charts-react/plan-grid.mjs +1 -1
  13. package/dist/core/document/display.d.mts +1 -0
  14. package/dist/core/document/display.mjs +3 -1
  15. package/dist/core/engine/version.d.mts +1 -1
  16. package/dist/core/engine/version.mjs +1 -1
  17. package/dist/core/time/bucket.d.mts +2 -1
  18. package/dist/core/time/bucket.mjs +6 -2
  19. package/dist/core/time/zone.d.mts +6 -1
  20. package/dist/core/time/zone.mjs +11 -2
  21. package/dist/llms.txt +1 -1
  22. package/dist/react/Canvas.mjs +7 -7
  23. package/dist/react/Dashboard.d.mts +6 -0
  24. package/dist/react/Dashboard.mjs +1 -0
  25. package/dist/react/Header.mjs +21 -17
  26. package/dist/react/builder/Time.mjs +1 -1
  27. package/dist/react/builder/words.d.mts +2 -1
  28. package/dist/react/builder/words.mjs +1 -1
  29. package/dist/react/columns.mjs +9 -1
  30. package/dist/react/drill/board.mjs +1 -0
  31. package/dist/react/drill/props.d.mts +2 -1
  32. package/dist/react/drill/props.mjs +8 -5
  33. package/dist/react/english.mjs +6 -6
  34. package/dist/react/format.d.mts +1 -1
  35. package/dist/react/format.mjs +25 -6
  36. package/dist/react/headline.d.mts +9 -0
  37. package/dist/react/headline.mjs +51 -0
  38. package/dist/react/index.d.mts +3 -2
  39. package/dist/react/index.mjs +4 -3
  40. package/dist/react/messages.d.mts +1 -0
  41. package/dist/react/place.mjs +4 -2
  42. package/dist/react/renderers/index.mjs +31 -8
  43. package/dist/react/theme-unlayered.css +1 -1
  44. package/dist/react/theme.css +1 -1
  45. package/dist/recharts/bar.mjs +2 -2
  46. package/dist/recharts/line.mjs +2 -2
  47. package/dist/recharts/parts.mjs +3 -1
  48. package/dist/skills/derive-dashboards/SKILL.md +3 -2
  49. package/package.json +1 -1
package/README.md CHANGED
@@ -37,7 +37,7 @@ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`exam
37
37
  | `derive-dashboards` | `deriveDashboards(options)`: a fetch handler for every endpoint, a Postgres source and store for any driver, the result cache, the query log, `createTables`, and the store contract suite (`/testing`). |
38
38
  | `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, the filter bar (`FilterBar`, with chips, a Filter menu, a phone sheet and `filterRules` for your own), `Tile`, the built-in tiles (`NumberTile`, `TableTile` with a viewer's sort, bars and shading), a tile's answer as CSV (`downloadCsv`, `csvOf`, `exportRows`), drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
39
39
  | `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts, each mark a drill (install `recharts` to use them; any other chart library plugs into `renderers`). |
40
- | `derive-dashboards/charts-react` | The package's own charts as tiles (`CHARTS_RENDERERS`): line, bar, area, small multiples, heat grid and funnel, each with a tooltip, keyboard steps, a table for screen readers and drill, and `Chart` to draw one yourself. Include `chart.css`. |
40
+ | `derive-dashboards/charts-react` | The package's own charts as tiles (`CHARTS_RENDERERS`): line, bar, area, small multiples, heatmap and funnel, each with a tooltip, keyboard steps, a table for screen readers and drill, and `Chart` to draw one yourself. Include `chart.css`. |
41
41
  | `derive-dashboards/charts` | The charts as plain functions, with no React: data in, a picture out as SVG (`lineChart`, `barChart`, `areaChart`, `gridChart`, `funnelChart` and more, and `renderSvg`). |
42
42
  | `derive-dashboards/mcp` | Two tools for the MCP server you already run (`addDashboardTools`): `dashboards_query` to ask and read, `dashboards_api` for everything else. See [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md). |
43
43
  | `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `doctor`, `check`, `generate`, `create-tables`. |
@@ -1,6 +1,6 @@
1
1
  import { running, starting } from "../data/buckets.mjs";
2
2
  import { stacked } from "../layout/stack.mjs";
3
- import { MUTED, SURFACE } from "../scene/paint.mjs";
3
+ import { MUTED } from "../scene/paint.mjs";
4
4
  import { bandPath, broken, linePath } from "../marks/lines.mjs";
5
5
  import { thinnedBand } from "../marks/thin.mjs";
6
6
  import { MARK, paintAt } from "../theme.mjs";
@@ -16,26 +16,27 @@ function bandsOf(spans, frame) {
16
16
  bottoms: edge((span) => span.from)
17
17
  };
18
18
  }
19
- /** The bands, each with a hair of surface along its upper edge to part it from the next. */
19
+ /**
20
+ * The bands, each a tint, then their upper edges over all of them, each in its band's own
21
+ * colour: drawn last, no edge lies under the tint of the band above it.
22
+ */
20
23
  function bandNodes(bands, look) {
21
24
  const gapped = (points) => broken(points, look.buckets);
22
- return bands.tops.flatMap((top, s) => {
23
- const edges = thinnedBand(gapped(top), gapped(bands.bottoms[s] ?? []));
24
- return [{
25
- kind: "path",
26
- part: "band",
27
- ...look.keys[s] === void 0 ? {} : { key: look.keys[s] },
28
- d: bandPath(edges.top, edges.bottom, look.curve),
29
- fill: paintAt(look.paints, s),
30
- opacity: MARK.areaFill
31
- }, {
32
- kind: "path",
33
- part: "edge",
34
- d: linePath(edges.top, look.curve),
35
- stroke: look.dense ? paintAt(look.paints, s) : SURFACE,
36
- strokeWidth: MARK.hair
37
- }];
38
- });
25
+ const drawn = bands.tops.map((top, s) => thinnedBand(gapped(top), gapped(bands.bottoms[s] ?? [])));
26
+ return [...drawn.map((edges, s) => ({
27
+ kind: "path",
28
+ part: "band",
29
+ ...look.keys[s] === void 0 ? {} : { key: look.keys[s] },
30
+ d: bandPath(edges.top, edges.bottom, look.curve),
31
+ fill: paintAt(look.paints, s),
32
+ opacity: MARK.areaFill
33
+ })), ...drawn.map((edges, s) => ({
34
+ kind: "path",
35
+ part: "edge",
36
+ d: linePath(edges.top, look.curve),
37
+ stroke: paintAt(look.paints, s),
38
+ strokeWidth: look.dense ? MARK.hair : MARK.context
39
+ }))];
39
40
  }
40
41
  /**
41
42
  * How far past the plot a clip of the bands reaches, across (twice that up and down): past the
@@ -7,13 +7,6 @@ import { rowName } from "./row-marks.mjs";
7
7
  /** How far over the cells the middle of their columns' names sits: half a line of them. */
8
8
  const OVER = LINE.tick / 2;
9
9
  /**
10
- * How strong the hue is in the palest and the deepest cell. The deepest stops short of the full
11
- * hue, so the ink a cell's number is written in reads on every cell, in a light and a dark theme.
12
- */
13
- const PALEST = .08;
14
- const DEEPEST_WITH_TEXT = .51;
15
- const DEEPEST_WITHOUT_TEXT = .85;
16
- /**
17
10
  * The columns' names over the cells: every one when they fit side by side, else the first at
18
11
  * the left and the last at the right, each cut to its half, so no two ever touch.
19
12
  */
@@ -104,12 +97,17 @@ const emptyNodes = (layout) => layout.empty.map(({ key, box }) => ({
104
97
  }));
105
98
  /** A cell's colour: the grid's one hue, whatever its value. What its stop's swatch wears too. */
106
99
  const colorOf = (cell, at) => at.mixed && cell.value < 0 ? at.negative : at.own;
107
- /** How a cell is filled: its colour, as strong as its value is high. */
100
+ /**
101
+ * How a cell is filled: its colour, as strong as its value is high. A cell with its number on
102
+ * it stops short of the full hue, so the ink reads on every cell in a light and a dark theme,
103
+ * which the palette law holds it to.
104
+ */
108
105
  function shadeOf(cell, at) {
109
- const deepest = at.layout.numbers ? DEEPEST_WITH_TEXT : DEEPEST_WITHOUT_TEXT;
106
+ const deepest = at.layout.numbers ? at.deepest : MARK.deepestBare;
107
+ const opacity = MARK.palest + (deepest - MARK.palest) * at.shade(cell.value);
110
108
  return {
111
109
  fill: colorOf(cell, at),
112
- opacity: PALEST + (deepest - PALEST) * at.shade(cell.value)
110
+ opacity
113
111
  };
114
112
  }
115
113
  /**
@@ -59,7 +59,7 @@ function highestOf(data, measure) {
59
59
  function describeGrid(data, at) {
60
60
  const cells = data.rows.flatMap((_row, r) => data.columns.map((_column, c) => data.values[r]?.[c] ?? null));
61
61
  return summary([
62
- `Grid of ${at.measure.label}`,
62
+ `Heatmap of ${at.measure.label}`,
63
63
  shownOf(data.rows.length, at.shown, "row"),
64
64
  counted(data.columns.length, "column")
65
65
  ], [
@@ -17,6 +17,6 @@ export type GridOptions = Header & {
17
17
  /** The palette place of the grid's one colour. */
18
18
  slot?: number;
19
19
  };
20
- /** A heat grid of one measure by two fields. */
20
+ /** A heatmap of one measure by two fields. */
21
21
  export declare function gridChart(given: GridData, options: GridOptions, env: Env): Scene;
22
22
  export type { GridData };
@@ -1,5 +1,5 @@
1
1
  import { bare, headerNodes } from "../layout/frame.mjs";
2
- import { seriesPaint } from "../theme.mjs";
2
+ import { MARK, seriesPaint } from "../theme.mjs";
3
3
  import { rowsMore } from "./row-marks.mjs";
4
4
  import { cleaned, colorsOf } from "./grid-data.mjs";
5
5
  import { layoutOf } from "./grid-layout.mjs";
@@ -8,7 +8,7 @@ import { fitTimeGrid } from "./grid-time.mjs";
8
8
  import { describeGrid, matrixOf, stopsOf } from "./grid-words.mjs";
9
9
  import { hasRoom } from "./row-chart.mjs";
10
10
  // src/kinds/grid.ts
11
- /** A heat grid of one measure by two fields. */
11
+ /** A heatmap of one measure by two fields. */
12
12
  function gridChart(given, options, env) {
13
13
  const clean = cleaned(given);
14
14
  const data = options.time === void 0 ? clean : fitTimeGrid(clean, options.time, env);
@@ -27,6 +27,7 @@ function gridChart(given, options, env) {
27
27
  ...colorsOf(data, options.range, options.diverging),
28
28
  negative: seriesPaint((options.slot ?? 0) + 1),
29
29
  own: seriesPaint(options.slot ?? 0),
30
+ deepest: (options.slot ?? 0) === 0 ? MARK.deepest : MARK.deepestAny,
30
31
  env
31
32
  };
32
33
  return {
@@ -44,7 +44,8 @@ function valueGrid(axis, at) {
44
44
  x2: plot.x + plot.width,
45
45
  y1: place(one.value),
46
46
  y2: place(one.value),
47
- stroke: RULE
47
+ stroke: RULE,
48
+ opacity: MARK.grid
48
49
  }, ...written.has(one) ? [{
49
50
  kind: "text",
50
51
  part: "tick",
@@ -1,5 +1,5 @@
1
1
  import { RULE } from "../scene/paint.mjs";
2
- import { TEXT } from "../theme.mjs";
2
+ import { MARK, TEXT } from "../theme.mjs";
3
3
  import { tickTexts, tickUnder, writtenOf } from "./axes.mjs";
4
4
  // src/marks/x-axis.ts
5
5
  /** The ticks whose numbers are written, left to right, by the rule of every value axis (`writtenOf`). */
@@ -26,7 +26,8 @@ function xGrid(axis, at) {
26
26
  x2: place(value),
27
27
  y1: plot.y,
28
28
  y2: plot.y + plot.height,
29
- stroke: RULE
29
+ stroke: RULE,
30
+ opacity: MARK.grid
30
31
  })), ...writtenTicks(axis, at).map((tick) => tickUnder(tick, plot))];
31
32
  }
32
33
  export { xGrid };
@@ -158,7 +158,7 @@ export type Hover = {
158
158
  rows: readonly HoverColumn[];
159
159
  columns: readonly HoverColumn[];
160
160
  heading?: string;
161
- /** All cells are stops in row order, including empty cells (a navigable heat grid). */
161
+ /** All cells are stops in row order, including empty cells (a navigable heatmap). */
162
162
  rowMajor?: boolean;
163
163
  };
164
164
  };
@@ -16,32 +16,32 @@ export declare function paintsOf(things: readonly Toned[], own?: Paint): Paint[]
16
16
  export declare const THEMES: {
17
17
  readonly light: {
18
18
  readonly "--dd-surface": "#ffffff";
19
- readonly "--dd-ink": "#18181b";
20
- readonly "--dd-muted": "#626571";
21
- readonly "--dd-line": "#e4e4e7";
22
- readonly "--dd-other": "#737380";
23
- readonly "--dd-good": "#15803d";
24
- readonly "--dd-danger": "#b91c1c";
25
- readonly "--dd-series-1": "#4c6ba7";
26
- readonly "--dd-series-2": "#a3664c";
27
- readonly "--dd-series-3": "#2d5b51";
28
- readonly "--dd-series-4": "#675522";
29
- readonly "--dd-series-5": "#946379";
30
- readonly "--dd-series-6": "#6e5b86";
19
+ readonly "--dd-ink": "#111620";
20
+ readonly "--dd-muted": "#646974";
21
+ readonly "--dd-line": "#e2e4e8";
22
+ readonly "--dd-other": "#737984";
23
+ readonly "--dd-good": "#19793f";
24
+ readonly "--dd-danger": "#c0282d";
25
+ readonly "--dd-series-1": "#1d5fd3";
26
+ readonly "--dd-series-2": "#eb6834";
27
+ readonly "--dd-series-3": "#1da766";
28
+ readonly "--dd-series-4": "#8986fa";
29
+ readonly "--dd-series-5": "#ee58c0";
30
+ readonly "--dd-series-6": "#33477f";
31
31
  };
32
32
  readonly dark: {
33
- readonly "--dd-surface": "#18181b";
34
- readonly "--dd-ink": "#fafafa";
35
- readonly "--dd-muted": "#a1a1aa";
36
- readonly "--dd-line": "#27272a";
37
- readonly "--dd-other": "#93939e";
38
- readonly "--dd-good": "#4ade80";
39
- readonly "--dd-danger": "#f87171";
40
- readonly "--dd-series-1": "#91bcf5";
41
- readonly "--dd-series-2": "#d0947b";
42
- readonly "--dd-series-3": "#6ea59b";
43
- readonly "--dd-series-4": "#d9c68e";
44
- readonly "--dd-series-5": "#e8aeca";
45
- readonly "--dd-series-6": "#ae9dc9";
33
+ readonly "--dd-surface": "#13151b";
34
+ readonly "--dd-ink": "#eef0f4";
35
+ readonly "--dd-muted": "#969ba6";
36
+ readonly "--dd-line": "#262a32";
37
+ readonly "--dd-other": "#7b818d";
38
+ readonly "--dd-good": "#4fd487";
39
+ readonly "--dd-danger": "#f47c7c";
40
+ readonly "--dd-series-1": "#5589f2";
41
+ readonly "--dd-series-2": "#eb6834";
42
+ readonly "--dd-series-3": "#1baf7a";
43
+ readonly "--dd-series-4": "#b7a1f7";
44
+ readonly "--dd-series-5": "#ea8dcc";
45
+ readonly "--dd-series-6": "#d5dcf7";
46
46
  };
47
47
  };
@@ -61,7 +61,10 @@ const LINE = {
61
61
  * value is drawn at (a column's height, a cell's side), so a value is never drawn as nothing; the surface ring that parts a
62
62
  * dot from what is under it, and a hollow dot's own stroke; how strong the zero line is; how
63
63
  * faint a mark that is not the point is drawn (a period still running, a comparison), and how
64
- * strong a partial fill and a background wash are; and the dashes: of a line the data is read against, of a
64
+ * strong a band's tint, a partial fill and a background wash are; how strong the hue is in a
65
+ * gridline is beside a border in the same colour, so a host's heavy border leaves a plot quiet; how strong the hue is in a
66
+ * heat grid's palest cell and its deepest (with its number on it, in the palette's first two
67
+ * colours and in any of them, and with no number); and the dashes: of a line the data is read against, of a
65
68
  * marked moment (finer, since it marks a time and not a value), of the comparison period's
66
69
  * line, and of a step into or out of a period that is not whole.
67
70
  */
@@ -75,7 +78,12 @@ const MARK = {
75
78
  hollow: 2,
76
79
  zero: .4,
77
80
  faint: .88,
78
- areaFill: .85,
81
+ areaFill: .3,
82
+ grid: .6,
83
+ palest: .08,
84
+ deepest: .72,
85
+ deepestAny: .44,
86
+ deepestBare: .9,
79
87
  partialFill: .55,
80
88
  wash: .2,
81
89
  dash: "4 4",
@@ -207,33 +215,33 @@ function placesOf(things, all) {
207
215
  const THEMES = {
208
216
  light: {
209
217
  "--dd-surface": "#ffffff",
210
- "--dd-ink": "#18181b",
211
- "--dd-muted": "#626571",
212
- "--dd-line": "#e4e4e7",
213
- "--dd-other": "#737380",
214
- "--dd-good": "#15803d",
215
- "--dd-danger": "#b91c1c",
216
- "--dd-series-1": "#4c6ba7",
217
- "--dd-series-2": "#a3664c",
218
- "--dd-series-3": "#2d5b51",
219
- "--dd-series-4": "#675522",
220
- "--dd-series-5": "#946379",
221
- "--dd-series-6": "#6e5b86"
218
+ "--dd-ink": "#111620",
219
+ "--dd-muted": "#646974",
220
+ "--dd-line": "#e2e4e8",
221
+ "--dd-other": "#737984",
222
+ "--dd-good": "#19793f",
223
+ "--dd-danger": "#c0282d",
224
+ "--dd-series-1": "#1d5fd3",
225
+ "--dd-series-2": "#eb6834",
226
+ "--dd-series-3": "#1da766",
227
+ "--dd-series-4": "#8986fa",
228
+ "--dd-series-5": "#ee58c0",
229
+ "--dd-series-6": "#33477f"
222
230
  },
223
231
  dark: {
224
- "--dd-surface": "#18181b",
225
- "--dd-ink": "#fafafa",
226
- "--dd-muted": "#a1a1aa",
227
- "--dd-line": "#27272a",
228
- "--dd-other": "#93939e",
229
- "--dd-good": "#4ade80",
230
- "--dd-danger": "#f87171",
231
- "--dd-series-1": "#91bcf5",
232
- "--dd-series-2": "#d0947b",
233
- "--dd-series-3": "#6ea59b",
234
- "--dd-series-4": "#d9c68e",
235
- "--dd-series-5": "#e8aeca",
236
- "--dd-series-6": "#ae9dc9"
232
+ "--dd-surface": "#13151b",
233
+ "--dd-ink": "#eef0f4",
234
+ "--dd-muted": "#969ba6",
235
+ "--dd-line": "#262a32",
236
+ "--dd-other": "#7b818d",
237
+ "--dd-good": "#4fd487",
238
+ "--dd-danger": "#f47c7c",
239
+ "--dd-series-1": "#5589f2",
240
+ "--dd-series-2": "#eb6834",
241
+ "--dd-series-3": "#1baf7a",
242
+ "--dd-series-4": "#b7a1f7",
243
+ "--dd-series-5": "#ea8dcc",
244
+ "--dd-series-6": "#d5dcf7"
237
245
  }
238
246
  };
239
247
  export { INK, LINE, MARK, MUTED, OTHER, PALETTE, RULE, SPACE, SURFACE, TEXT, THEMES, ownPaint, paintAt, paintsOf, roundedEnd, seriesPaint, signPaint };
@@ -86,7 +86,7 @@ function byRows(drawn, from) {
86
86
  function rowTitleOf(props, timed) {
87
87
  return props.answer.columns.filter((c) => roleOf(c) === "time" || roleOf(c) === "dimension")[timed ? 1 : 0]?.label;
88
88
  }
89
- /** A heat grid of the answer's first value by its two fields. None for an answer with no value. */
89
+ /** A heatmap of the answer's first value by its two fields. None for an answer with no value. */
90
90
  function gridPlan(props, drawn, from) {
91
91
  const [first] = drawn.series;
92
92
  if (first === void 0) return void 0;
@@ -13,6 +13,7 @@ export declare const DISPLAY_OPTIONS: {
13
13
  readonly number: {
14
14
  readonly value: "text";
15
15
  readonly secondary: "text";
16
+ readonly full: "boolean";
16
17
  readonly keepDateRange: "boolean";
17
18
  readonly empty: "text";
18
19
  };
@@ -13,7 +13,8 @@ const DISPLAY_OPTIONS = {
13
13
  number: {
14
14
  ...SHARED,
15
15
  value: "text",
16
- secondary: "text"
16
+ secondary: "text",
17
+ full: "boolean"
17
18
  },
18
19
  table: {
19
20
  ...SHARED,
@@ -52,6 +53,7 @@ const DISPLAY_HELP = {
52
53
  empty: "What the tile says when its answer has no rows.",
53
54
  value: "The query entry a number tile shows large. Without it: a calc when the query has one, else its first value.",
54
55
  secondary: "A query entry a number tile shows as a second, smaller figure under the number, beside its label.",
56
+ full: "Write a number tile's large value in full, where an amount of a thousand or more is otherwise rounded to whole units.",
55
57
  bars: "Query entries drawn with a bar in each cell, as long as the value is beside the column's largest.",
56
58
  heat: "Query entries whose cells are shaded by their value, darker for more.",
57
59
  comparisons: "For a value of the first grouping column, name the drill field for its comparison table and optionally the field to expand each group by.",
@@ -5,4 +5,4 @@
5
5
  * older code, or in an older shape, is never read. `test/engine-version.test.ts` checks it
6
6
  * against the files and prints the new value when they change.
7
7
  */
8
- export declare const ENGINE_VERSION = "f390ec5ebe464f91";
8
+ export declare const ENGINE_VERSION = "200e411586e1bf61";
@@ -6,5 +6,5 @@
6
6
  * older code, or in an older shape, is never read. `test/engine-version.test.ts` checks it
7
7
  * against the files and prints the new value when they change.
8
8
  */
9
- const ENGINE_VERSION = "f390ec5ebe464f91";
9
+ const ENGINE_VERSION = "200e411586e1bf61";
10
10
  export { ENGINE_VERSION };
@@ -2,7 +2,8 @@ import { Calendar, Grain } from "../query/types.mjs";
2
2
  import { Micros } from "./instant.mjs";
3
3
  /**
4
4
  * The first instant of the bucket an instant falls in, in the calendar's zone. A day bucket
5
- * starts at the day's first instant, so it lasts 23 or 25 hours across a clock change.
5
+ * starts at the day's first instant (`startOfDate`), so it lasts 23 or 25 hours across a clock
6
+ * change, and every instant is in exactly one.
6
7
  */
7
8
  export declare function bucketStart(instant: Micros, grain: Grain, calendar: Calendar): Micros;
8
9
  /**
@@ -53,12 +53,16 @@ function nextHour(start, zone) {
53
53
  }
54
54
  /**
55
55
  * The first instant of the bucket an instant falls in, in the calendar's zone. A day bucket
56
- * starts at the day's first instant, so it lasts 23 or 25 hours across a clock change.
56
+ * starts at the day's first instant (`startOfDate`), so it lasts 23 or 25 hours across a clock
57
+ * change, and every instant is in exactly one.
57
58
  */
58
59
  function bucketStart(instant, grain, calendar) {
59
60
  const zone = calendar.timezone;
60
61
  if (grain === "hour") return hourStart(instant, zone);
61
- return startOfDate(startDate(zonedAt(instant, zone).toPlainDate(), grain, calendar), zone);
62
+ const date = zonedAt(instant, zone).toPlainDate();
63
+ const start = startOfDate(startDate(date, grain, calendar), zone);
64
+ if (start <= instant) return start;
65
+ return startOfDate(startDate(date.subtract({ days: 1 }), grain, calendar), zone);
62
66
  }
63
67
  /**
64
68
  * The first instant after a bucket start that begins another bucket. An hour is a real hour,
@@ -12,7 +12,12 @@ export type NaiveRule = {
12
12
  * rule excludes it. In a gap, shift_forward moves it later by the gap's length, as Postgres does.
13
13
  */
14
14
  export declare function resolveNaive(time: Temporal.PlainDateTime, rule: NaiveRule): Micros | null;
15
- /** The first instant of a calendar day in a zone: usually midnight, later on a day that skips it. */
15
+ /**
16
+ * The first instant of a calendar day in a zone: usually midnight, later on a day that skips
17
+ * it. Where the clocks fall back across midnight, midnight comes twice with the end of the day
18
+ * before in between: the day starts at the later one, so no two days overlap. Where both
19
+ * midnights are the day's own (clocks set back from 01:00), it starts at the first.
20
+ */
16
21
  export declare function startOfDate(date: Temporal.PlainDate, zone: string): Micros;
17
22
  /** One stretch of time with a single UTC offset, in minutes east of UTC. */
18
23
  export type OffsetSegment = {
@@ -11,9 +11,18 @@ function resolveNaive(time, rule) {
11
11
  if (earlier.toPlainDateTime().equals(time)) return rule.ambiguous === "exclude" ? null : microsOf(rule.ambiguous === "earlier" ? earlier : later);
12
12
  return rule.nonexistent === "exclude" ? null : microsOf(later);
13
13
  }
14
- /** The first instant of a calendar day in a zone: usually midnight, later on a day that skips it. */
14
+ /**
15
+ * The first instant of a calendar day in a zone: usually midnight, later on a day that skips
16
+ * it. Where the clocks fall back across midnight, midnight comes twice with the end of the day
17
+ * before in between: the day starts at the later one, so no two days overlap. Where both
18
+ * midnights are the day's own (clocks set back from 01:00), it starts at the first.
19
+ */
15
20
  function startOfDate(date, zone) {
16
- return microsOf(date.toZonedDateTime(zone));
21
+ const first = date.toZonedDateTime(zone);
22
+ const again = date.toPlainDateTime().toZonedDateTime(zone, { disambiguation: "later" });
23
+ if (again.epochNanoseconds <= first.epochNanoseconds) return microsOf(first);
24
+ const before = again.subtract({ microseconds: 1 }).toPlainDate();
25
+ return microsOf(before.equals(date) ? first : again);
17
26
  }
18
27
  function offsetMinutes(at) {
19
28
  return at.offsetNanoseconds / 6e10;
package/dist/llms.txt CHANGED
@@ -9,7 +9,7 @@ Install skill for coding agents: `npx skills add derive-to/dashboards --skill de
9
9
  - [Quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md): install, describe your data, mount the handler, show a dashboard, drill in.
10
10
  - [Concepts](https://github.com/derive-to/dashboards/blob/main/docs/concepts.md): the model, measures, joins, tenancy and row policies, access, documents, drill-in.
11
11
  - [Filters](https://github.com/derive-to/dashboards/blob/main/docs/filters.md): the built-in filter bar, theming, options, words, the shadcn copy, custom bars.
12
- - [React](https://github.com/derive-to/dashboards/blob/main/docs/react.md): provider, Dashboard, editing UI, URL state, drill parts, widget builder; the tiles and their `display` options (a number's `value` and `secondary`, a table's `bars`, `heat`, `compact` and `comparisons` for grouped drill-down, a list's lines); plain SVG functions in `derive-dashboards/charts`, the two chart kits and what each kind draws (`CHARTS_RENDERERS` from `derive-dashboards/charts-react`: line, bar, area, small multiples, heat grid, funnel; a bar's `against`, an area's `share`, small multiples' `ownScales`); a table a viewer sorts; a tile's answer as CSV (`csv={false}` turns the button off, `downloadCsv` and `csvOf` for your own). Use `drill.compare` on a row in a custom renderer. Catch `DashboardDocumentError` for invalid code dashboards. Translate drill labels with `messages.drillMetricTotal`, `drillCompareGroup`, `drillGroupedBy`, `drillRecordPages` and `drillTrendWindow`.
12
+ - [React](https://github.com/derive-to/dashboards/blob/main/docs/react.md): provider, Dashboard (`tiles="sheet"` or `"cards"`), editing UI, URL state, drill parts, widget builder; the tiles and their `display` options (a number's `value`, `secondary` and `full`, with `formatHeadline` for a tile of your own, a table's `bars`, `heat`, `compact` and `comparisons` for grouped drill-down, a list's lines); plain SVG functions in `derive-dashboards/charts`, the two chart kits and what each kind draws (`CHARTS_RENDERERS` from `derive-dashboards/charts-react`: line, bar, area, small multiples, heatmap, funnel; a bar's `against`, an area's `share`, small multiples' `ownScales`); a table a viewer sorts; a tile's answer as CSV (`csv={false}` turns the button off, `downloadCsv` and `csvOf` for your own). Use `drill.compare` on a row in a custom renderer. Catch `DashboardDocumentError` for invalid code dashboards. Translate drill labels with `messages.drillMetricTotal`, `drillCompareGroup`, `drillGroupedBy`, `drillRecordPages` and `drillTrendWindow`.
13
13
  - [CLI](https://github.com/derive-to/dashboards/blob/main/docs/cli.md): init, check, generate, create-tables, add, importing from dbt or Cube.
14
14
  - [Endpoints](https://github.com/derive-to/dashboards/blob/main/docs/endpoints.md): every handler endpoint, its body and answer.
15
15
  - [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md): tools that let agents query and edit dashboards as themselves.
@@ -59,7 +59,7 @@ function Filters({ board, doc }) {
59
59
  timezone: doc.scope.timezone ?? answeredZone(board.tiles.results)
60
60
  });
61
61
  }
62
- /** The span most tiles cover, said once under the filters; the tiles that cover it leave it out. */
62
+ /** The span most tiles cover, said once over the grid; the tiles that cover it leave it out. */
63
63
  function DashboardSpan({ results }) {
64
64
  const shared = sharedSpan(results);
65
65
  const one = [...results.values()].find((result) => spanKey(result) === shared);
@@ -68,7 +68,7 @@ function DashboardSpan({ results }) {
68
68
  children: /* @__PURE__ */ jsx(Span, { result: one })
69
69
  });
70
70
  }
71
- /** The canvas: header, tabs, filters, and the grid with its marks. */
71
+ /** The canvas: the header with the filters in it, the tabs, and the grid with its marks. */
72
72
  function Canvas(props) {
73
73
  const { board, shown } = props;
74
74
  const { edit, panels, view } = board;
@@ -86,7 +86,11 @@ function Canvas(props) {
86
86
  historyOpen: panels.panel === "history",
87
87
  onAdd: add,
88
88
  onHistory: panels.toggleHistory,
89
- link: () => linkTo(view.current, props.dashboard.linkFor)
89
+ link: () => linkTo(view.current, props.dashboard.linkFor),
90
+ filters: /* @__PURE__ */ jsx(Filters, {
91
+ board,
92
+ doc: shown.doc
93
+ })
90
94
  }),
91
95
  /* @__PURE__ */ jsx(Dropped, { names: view.dropped }),
92
96
  /* @__PURE__ */ jsx(Tabs, {
@@ -94,10 +98,6 @@ function Canvas(props) {
94
98
  current: shown.tab,
95
99
  onSelect: view.setTab
96
100
  }),
97
- /* @__PURE__ */ jsx(Filters, {
98
- board,
99
- doc: shown.doc
100
- }),
101
101
  /* @__PURE__ */ jsx(DashboardSpan, { results: board.tiles.results }),
102
102
  edit.draft === void 0 || !emptyTab(shown) ? null : /* @__PURE__ */ jsx(EmptyTab, { onAdd: add }),
103
103
  /* @__PURE__ */ jsx(Grid, {
@@ -28,6 +28,12 @@ export type DashboardProps = {
28
28
  linkDropped?: readonly string[];
29
29
  /** The link Share copies for a view; by default, this page's address with the view in it. */
30
30
  linkFor?: (view: ViewState) => string;
31
+ /**
32
+ * How tiles sit when the dashboard is read: "sheet" (the default) joins them as one ruled
33
+ * sheet, sharing hairline rules; "cards" keeps each a card of its own, with room between.
34
+ * While editing they are always cards, with room to drag into.
35
+ */
36
+ tiles?: "sheet" | "cards";
31
37
  } & DashboardEvents & DashboardDrillProps;
32
38
  /**
33
39
  * One dashboard. Everything drawn in it, the builder's preview too, shares one book of series
@@ -102,6 +102,7 @@ function Board(props) {
102
102
  id: props.id,
103
103
  board,
104
104
  drill: props,
105
+ tiles: props.tiles ?? "sheet",
105
106
  children: [/* @__PURE__ */ jsxs("div", {
106
107
  className: "dd-board",
107
108
  children: [
@@ -17,6 +17,7 @@ function Title({ doc, edit, isNew }) {
17
17
  }, [isNew, editing]);
18
18
  if (!editing) return /* @__PURE__ */ jsx("h2", {
19
19
  className: "dd-title",
20
+ title: doc.meta.title,
20
21
  children: doc.meta.title
21
22
  });
22
23
  const save = () => {
@@ -89,23 +90,26 @@ function Header(props) {
89
90
  edit,
90
91
  isNew: props.unpublished === true
91
92
  }), /* @__PURE__ */ jsxs("div", {
92
- className: "dd-header-actions",
93
- children: [
94
- props.unpublished === true || editing ? null : /* @__PURE__ */ jsx(ShareButton, { link: props.link }),
95
- editing || version === 0 ? null : /* @__PURE__ */ jsx("button", {
96
- type: "button",
97
- className: "dd-button dd-quiet",
98
- "aria-expanded": props.historyOpen,
99
- onClick: props.onHistory,
100
- children: messages.history
101
- }),
102
- /* @__PURE__ */ jsx(EditButton, {
103
- edit,
104
- canEdit,
105
- waiting,
106
- onAdd: props.onAdd
107
- })
108
- ]
93
+ className: "dd-header-controls",
94
+ children: [props.filters, /* @__PURE__ */ jsxs("div", {
95
+ className: "dd-header-actions",
96
+ children: [
97
+ props.unpublished === true || editing ? null : /* @__PURE__ */ jsx(ShareButton, { link: props.link }),
98
+ editing || version === 0 ? null : /* @__PURE__ */ jsx("button", {
99
+ type: "button",
100
+ className: "dd-button dd-quiet",
101
+ "aria-expanded": props.historyOpen,
102
+ onClick: props.onHistory,
103
+ children: messages.history
104
+ }),
105
+ /* @__PURE__ */ jsx(EditButton, {
106
+ edit,
107
+ canEdit,
108
+ waiting,
109
+ onAdd: props.onAdd
110
+ })
111
+ ]
112
+ })]
109
113
  })]
110
114
  }), doc.meta.description === void 0 ? null : /* @__PURE__ */ jsx("p", {
111
115
  className: "dd-description",
@@ -146,7 +146,7 @@ function GrainSelect({ b, time }) {
146
146
  }, g))
147
147
  });
148
148
  }
149
- /** Over time: the time field, no breakdown or a grain, the range, and any comparison. */
149
+ /** Over time: the time field, the whole period or a time grain, the range, and any comparison. */
150
150
  function TimeSection({ b }) {
151
151
  const { messages, locale } = useDashboards();
152
152
  const time = b.state.query?.time;
@@ -6,7 +6,7 @@ export type RangeUnit = Exclude<Grain, "hour">;
6
6
  export type BuilderMessages = {
7
7
  /** The chip that opens the custom range editor. */
8
8
  customRange: string;
9
- /** The names of the time row's two selects: how time splits, and which days it covers. */
9
+ /** Label for the date field used to group and filter the query. */
10
10
  timeField: string;
11
11
  /** A quick range's short name on its button: "7D", "12M". */
12
12
  shortRange: (r: {
@@ -16,6 +16,7 @@ export type BuilderMessages = {
16
16
  /** The labels of a fixed range's first and last day. */
17
17
  fromDay: string;
18
18
  toDay: string;
19
+ /** Label for choosing the time grain, such as day or week. */
19
20
  breakdown: string;
20
21
  timeRange: string;
21
22
  /** A range that moves with today: "Last 6 months". */
@@ -21,7 +21,7 @@ const ENGLISH_BUILDER = {
21
21
  shortRange: (r) => `${String(r.last)}${r.unit.charAt(0).toUpperCase()}`,
22
22
  fromDay: "From",
23
23
  toDay: "To",
24
- breakdown: "Breakdown",
24
+ breakdown: "Group dates by",
25
25
  timeRange: "Range",
26
26
  rolling: "Rolling",
27
27
  betweenDates: "Between dates",