derive-dashboards 0.6.0 → 0.7.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 (134) hide show
  1. package/dist/charts/kinds/area-marks.mjs +2 -1
  2. package/dist/charts/kinds/funnel-words.mjs +1 -1
  3. package/dist/charts/kinds/grid-marks.mjs +9 -4
  4. package/dist/charts/theme.d.mts +13 -13
  5. package/dist/charts/theme.mjs +17 -14
  6. package/dist/charts-react/Overlay.mjs +1 -0
  7. package/dist/charts-react/chart-unlayered.css +1 -107
  8. package/dist/charts-react/chart.css +1 -121
  9. package/dist/charts-react/tip-place.mjs +30 -15
  10. package/dist/core/document/display-comparisons.mjs +49 -0
  11. package/dist/core/document/display-validation.d.mts +12 -0
  12. package/dist/core/document/display-validation.mjs +56 -0
  13. package/dist/core/document/display.d.mts +6 -12
  14. package/dist/core/document/display.mjs +23 -48
  15. package/dist/core/engine/dialect.d.mts +2 -0
  16. package/dist/core/engine/index.mjs +1 -1
  17. package/dist/core/engine/levels.mjs +33 -1
  18. package/dist/core/engine/postgres.mjs +1 -0
  19. package/dist/core/engine/rank.mjs +1 -1
  20. package/dist/core/engine/reader.d.mts +4 -0
  21. package/dist/core/engine/sql-partition.mjs +45 -0
  22. package/dist/core/engine/sql-reads.mjs +4 -1
  23. package/dist/core/engine/statement.mjs +4 -4
  24. package/dist/core/engine/version.d.mts +1 -1
  25. package/dist/core/engine/version.mjs +1 -1
  26. package/dist/core/error/codes.d.mts +1 -1
  27. package/dist/core/error/codes.mjs +1 -1
  28. package/dist/core/index.d.mts +6 -5
  29. package/dist/core/index.mjs +8 -7
  30. package/dist/core/model/validate/fields.mjs +1 -1
  31. package/dist/core/query/drill/compose.d.mts +2 -0
  32. package/dist/core/query/drill/compose.mjs +1 -1
  33. package/dist/core/query/drill/synthetic.mjs +1 -1
  34. package/dist/core/query/drill/types.d.mts +7 -0
  35. package/dist/core/query/drill/types.mjs +3 -1
  36. package/dist/core/schema/answers.d.mts +1176 -362
  37. package/dist/core/schema/drill-answers.mjs +19 -1
  38. package/dist/core/schema/drill.d.mts +21 -6
  39. package/dist/core/schema/drill.mjs +7 -1
  40. package/dist/core/schema/tools.mjs +13 -0
  41. package/dist/core/time/index.d.mts +2 -2
  42. package/dist/core/time/text-time.d.mts +9 -2
  43. package/dist/core/time/text-time.mjs +18 -3
  44. package/dist/core/types/api.d.mts +1 -1
  45. package/dist/core/types/api.mjs +1 -1
  46. package/dist/core/types/drill-api.d.mts +22 -2
  47. package/dist/dashboard-documents.d.mts +8 -0
  48. package/dist/dashboard-documents.mjs +52 -0
  49. package/dist/drill-access.mjs +40 -3
  50. package/dist/drill-comparison.mjs +71 -0
  51. package/dist/drill-crumbs.mjs +21 -2
  52. package/dist/drill-group-seal.mjs +13 -0
  53. package/dist/drill-open.mjs +7 -1
  54. package/dist/drill-seal.mjs +4 -6
  55. package/dist/drill-views.mjs +5 -13
  56. package/dist/drill.mjs +28 -58
  57. package/dist/editing.mjs +1 -1
  58. package/dist/endpoints/drill.mjs +2 -3
  59. package/dist/endpoints/index.d.mts +20 -0
  60. package/dist/index.d.mts +2 -1
  61. package/dist/index.mjs +6 -27
  62. package/dist/llms.txt +1 -1
  63. package/dist/react/Cell.mjs +2 -2
  64. package/dist/react/DashboardList.mjs +3 -3
  65. package/dist/react/Editing.mjs +3 -3
  66. package/dist/react/Header.mjs +2 -2
  67. package/dist/react/History.mjs +3 -3
  68. package/dist/react/Parts.mjs +2 -2
  69. package/dist/react/RowBody.d.mts +2 -4
  70. package/dist/react/RowBody.mjs +14 -39
  71. package/dist/react/Tile.mjs +4 -5
  72. package/dist/react/builder/FilterEditor.mjs +2 -2
  73. package/dist/react/builder/Picker.mjs +3 -3
  74. package/dist/react/builder/RangeEditor.mjs +3 -3
  75. package/dist/react/builder/Time.mjs +3 -3
  76. package/dist/react/builder/Values.mjs +2 -2
  77. package/dist/react/builder/WidgetBuilder.mjs +2 -2
  78. package/dist/react/drill/Bars.mjs +34 -38
  79. package/dist/react/drill/Comparison.mjs +204 -0
  80. package/dist/react/drill/Controls.mjs +8 -12
  81. package/dist/react/drill/DrillDrawer.mjs +42 -0
  82. package/dist/react/drill/DrillPanel.mjs +61 -41
  83. package/dist/react/drill/Header.mjs +65 -35
  84. package/dist/react/drill/ItemLink.mjs +40 -0
  85. package/dist/react/drill/Items.d.mts +2 -1
  86. package/dist/react/drill/Items.mjs +126 -99
  87. package/dist/react/drill/ItemsBody.mjs +38 -0
  88. package/dist/react/drill/ItemsFoot.mjs +24 -19
  89. package/dist/react/drill/Notes.mjs +23 -13
  90. package/dist/react/drill/PanelBody.mjs +7 -25
  91. package/dist/react/drill/RecordRow.mjs +47 -0
  92. package/dist/react/drill/Trend.mjs +186 -0
  93. package/dist/react/drill/board.mjs +21 -11
  94. package/dist/react/drill/drawer-context.mjs +5 -0
  95. package/dist/react/drill/item-parts.mjs +53 -35
  96. package/dist/react/drill/item-type.d.mts +2 -2
  97. package/dist/react/drill/lazy.d.mts +1 -4
  98. package/dist/react/drill/lazy.mjs +29 -11
  99. package/dist/react/drill/panel-focus.mjs +18 -7
  100. package/dist/react/drill/props.d.mts +7 -1
  101. package/dist/react/drill/props.mjs +39 -8
  102. package/dist/react/drill/record-page.mjs +61 -0
  103. package/dist/react/drill/state.mjs +17 -2
  104. package/dist/react/drill/trend-touch.mjs +33 -0
  105. package/dist/react/drill/useDrill.d.mts +3 -3
  106. package/dist/react/drill/useDrill.mjs +35 -15
  107. package/dist/react/drill/words.d.mts +14 -0
  108. package/dist/react/drill/words.mjs +19 -7
  109. package/dist/react/english.d.mts +1 -0
  110. package/dist/react/english.mjs +1 -0
  111. package/dist/react/filters/chip.mjs +2 -2
  112. package/dist/react/filters/menu-search.mjs +5 -5
  113. package/dist/react/filters/menu.mjs +2 -2
  114. package/dist/react/filters/number.mjs +2 -2
  115. package/dist/react/filters/operator.mjs +2 -2
  116. package/dist/react/filters/phone.mjs +2 -2
  117. package/dist/react/filters/values.mjs +4 -4
  118. package/dist/react/format-time.d.mts +1 -0
  119. package/dist/react/format-time.mjs +39 -33
  120. package/dist/react/format.mjs +10 -1
  121. package/dist/react/renderers/list.mjs +8 -10
  122. package/dist/react/renderers/table-cells.mjs +38 -9
  123. package/dist/react/renderers/table-measure.mjs +2 -0
  124. package/dist/react/renderers/table-row.mjs +64 -7
  125. package/dist/react/renderers/table-sort.mjs +2 -8
  126. package/dist/react/renderers/table.mjs +16 -15
  127. package/dist/react/theme-unlayered.css +1 -3148
  128. package/dist/react/theme.css +1 -3150
  129. package/dist/recharts/parts.mjs +1 -1
  130. package/dist/skills/derive-dashboards/SKILL.md +4 -2
  131. package/dist/store/apply.mjs +2 -2
  132. package/dist/store/editor.mjs +2 -2
  133. package/dist/store/writer.mjs +2 -2
  134. package/package.json +1 -1
@@ -26,7 +26,8 @@ function bandNodes(bands, look) {
26
26
  part: "band",
27
27
  ...look.keys[s] === void 0 ? {} : { key: look.keys[s] },
28
28
  d: bandPath(edges.top, edges.bottom, look.curve),
29
- fill: paintAt(look.paints, s)
29
+ fill: paintAt(look.paints, s),
30
+ opacity: MARK.areaFill
30
31
  }, {
31
32
  kind: "path",
32
33
  part: "edge",
@@ -11,7 +11,7 @@ function stopOf(step, slot, at) {
11
11
  const words = wordsOf(at.env).funnel;
12
12
  const share = flow.share[slot] ?? null;
13
13
  const rate = flow.rate[slot] ?? null;
14
- const aside = [...share === null || slot === 0 ? [] : [words.ofFirstStep(at.percent(share))], ...rate === null ? [] : [words.ofStepBefore(at.percent(rate))]].join(", ");
14
+ const aside = [...share === null || slot === 0 ? [] : [words.ofFirstStep(at.percent(share))], ...rate === null || slot === 1 ? [] : [words.ofStepBefore(at.percent(rate))]].join(", ");
15
15
  const items = step.value === null ? [] : [{
16
16
  key: "value",
17
17
  label: at.measure.label,
@@ -11,6 +11,8 @@ const OVER = LINE.tick / 2;
11
11
  * hue, so the ink a cell's number is written in reads on every cell, in a light and a dark theme.
12
12
  */
13
13
  const PALEST = .08;
14
+ const DEEPEST_WITH_TEXT = .51;
15
+ const DEEPEST_WITHOUT_TEXT = .85;
14
16
  /**
15
17
  * The columns' names over the cells: every one when they fit side by side, else the first at
16
18
  * the left and the last at the right, each cut to its half, so no two ever touch.
@@ -103,10 +105,13 @@ const emptyNodes = (layout) => layout.empty.map(({ key, box }) => ({
103
105
  /** A cell's colour: the grid's one hue, whatever its value. What its stop's swatch wears too. */
104
106
  const colorOf = (cell, at) => at.mixed && cell.value < 0 ? at.negative : at.own;
105
107
  /** How a cell is filled: its colour, as strong as its value is high. */
106
- const shadeOf = (cell, at) => ({
107
- fill: colorOf(cell, at),
108
- opacity: PALEST + .62 * at.shade(cell.value)
109
- });
108
+ function shadeOf(cell, at) {
109
+ const deepest = at.layout.numbers ? DEEPEST_WITH_TEXT : DEEPEST_WITHOUT_TEXT;
110
+ return {
111
+ fill: colorOf(cell, at),
112
+ opacity: PALEST + (deepest - PALEST) * at.shade(cell.value)
113
+ };
114
+ }
110
115
  /**
111
116
  * A cell: its shade, and its number when the cells' numbers are written. They are written in
112
117
  * every cell or in none, so a cell with no number is never taken for a cell with no value.
@@ -17,17 +17,17 @@ export declare const THEMES: {
17
17
  readonly light: {
18
18
  readonly "--dd-surface": "#ffffff";
19
19
  readonly "--dd-ink": "#18181b";
20
- readonly "--dd-muted": "#71717a";
20
+ readonly "--dd-muted": "#626571";
21
21
  readonly "--dd-line": "#e4e4e7";
22
22
  readonly "--dd-other": "#737380";
23
23
  readonly "--dd-good": "#15803d";
24
24
  readonly "--dd-danger": "#b91c1c";
25
- readonly "--dd-series-1": "#0074d6";
26
- readonly "--dd-series-2": "#ac3700";
27
- readonly "--dd-series-3": "#007c55";
28
- readonly "--dd-series-4": "#734219";
29
- readonly "--dd-series-5": "#ce397c";
30
- readonly "--dd-series-6": "#714fad";
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";
31
31
  };
32
32
  readonly dark: {
33
33
  readonly "--dd-surface": "#18181b";
@@ -37,11 +37,11 @@ export declare const THEMES: {
37
37
  readonly "--dd-other": "#93939e";
38
38
  readonly "--dd-good": "#4ade80";
39
39
  readonly "--dd-danger": "#f87171";
40
- readonly "--dd-series-1": "#3987e5";
41
- readonly "--dd-series-2": "#f07544";
42
- readonly "--dd-series-3": "#199e70";
43
- readonly "--dd-series-4": "#c98500";
44
- readonly "--dd-series-5": "#ec406a";
45
- readonly "--dd-series-6": "#a885d7";
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";
46
46
  };
47
47
  };
@@ -13,15 +13,17 @@ const PALETTE = 6;
13
13
  const TEXT = {
14
14
  name: {
15
15
  size: 12,
16
+ weight: 500,
16
17
  fill: INK
17
18
  },
18
19
  value: {
19
20
  size: 12,
20
- weight: 500,
21
+ weight: 600,
21
22
  fill: INK
22
23
  },
23
24
  tick: {
24
25
  size: 11,
26
+ weight: 500,
25
27
  fill: MUTED
26
28
  },
27
29
  title: {
@@ -73,6 +75,7 @@ const MARK = {
73
75
  hollow: 2,
74
76
  zero: .4,
75
77
  faint: .88,
78
+ areaFill: .85,
76
79
  partialFill: .55,
77
80
  wash: .2,
78
81
  dash: "4 4",
@@ -205,17 +208,17 @@ const THEMES = {
205
208
  light: {
206
209
  "--dd-surface": "#ffffff",
207
210
  "--dd-ink": "#18181b",
208
- "--dd-muted": "#71717a",
211
+ "--dd-muted": "#626571",
209
212
  "--dd-line": "#e4e4e7",
210
213
  "--dd-other": "#737380",
211
214
  "--dd-good": "#15803d",
212
215
  "--dd-danger": "#b91c1c",
213
- "--dd-series-1": "#0074d6",
214
- "--dd-series-2": "#ac3700",
215
- "--dd-series-3": "#007c55",
216
- "--dd-series-4": "#734219",
217
- "--dd-series-5": "#ce397c",
218
- "--dd-series-6": "#714fad"
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"
219
222
  },
220
223
  dark: {
221
224
  "--dd-surface": "#18181b",
@@ -225,12 +228,12 @@ const THEMES = {
225
228
  "--dd-other": "#93939e",
226
229
  "--dd-good": "#4ade80",
227
230
  "--dd-danger": "#f87171",
228
- "--dd-series-1": "#3987e5",
229
- "--dd-series-2": "#f07544",
230
- "--dd-series-3": "#199e70",
231
- "--dd-series-4": "#c98500",
232
- "--dd-series-5": "#ec406a",
233
- "--dd-series-6": "#a885d7"
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"
234
237
  }
235
238
  };
236
239
  export { INK, LINE, MARK, MUTED, OTHER, PALETTE, RULE, SPACE, SURFACE, TEXT, THEMES, ownPaint, paintAt, paintsOf, roundedEnd, seriesPaint, signPaint };
@@ -123,6 +123,7 @@ function Tip({ scene, stop, pointer, hint, chosen, noValue, more }) {
123
123
  return /* @__PURE__ */ jsxs("div", {
124
124
  ref,
125
125
  className: "dd-c-tip",
126
+ "data-single": stop.items.length === 1 || void 0,
126
127
  "aria-hidden": "true",
127
128
  style: TIP,
128
129
  children: [
@@ -1,107 +1 @@
1
- /* derive-dashboards/charts-react/chart.css without its cascade layer. */
2
- /*
3
- * The theme's ring for what opens (`[data-drill]:focus-visible`), which does not reach a
4
- * chart's box: the box takes focus to move through its stops, whether or not anything opens.
5
- */
6
- .dd-chart:focus-visible {
7
- border-radius: var(--dd-radius);
8
- outline: 2px solid var(--dd-accent);
9
- outline-offset: 2px;
10
- }
11
- /* Over the picture, the pointer cursor while the value under the pointer opens. */
12
- .dd-chart[data-opens="true"] > .dd-c-stage {
13
- cursor: pointer;
14
- }
15
- .dd-c-stage > .dd-chart-picture > svg {
16
- display: block;
17
- overflow: visible;
18
- }
19
-
20
- .dd-c-tip {
21
- display: grid;
22
- grid-template-columns: auto minmax(3ch, 1fr) minmax(0, auto);
23
- row-gap: 3px;
24
- align-items: center;
25
- box-sizing: border-box;
26
- min-width: min(132px, 100%);
27
- max-width: min(304px, 100%);
28
- max-height: 100%;
29
- overflow: auto;
30
- padding: 8px 11px 9px;
31
- background: var(--dd-surface);
32
- color: var(--dd-ink);
33
- border: 1px solid var(--dd-line);
34
- border-radius: var(--dd-radius);
35
- box-shadow:
36
- 0 1px 2px rgb(0 0 0 / 0.06),
37
- 0 8px 24px -6px rgb(0 0 0 / 0.18);
38
- font-family: var(--dd-font, system-ui, sans-serif);
39
- font-size: 12px;
40
- line-height: 16px;
41
- font-variant-numeric: tabular-nums;
42
- white-space: normal;
43
- overflow-wrap: anywhere;
44
- z-index: 2;
45
- }
46
- /* A long name breaks over lines inside the tooltip: it is never drawn past the tooltip's edge. */
47
- .dd-c-tip-title {
48
- grid-column: 1 / -1;
49
- margin-bottom: 3px;
50
- font-weight: 600;
51
- white-space: normal;
52
- overflow-wrap: anywhere;
53
- }
54
- .dd-c-tip-note {
55
- margin-left: 6px;
56
- color: var(--dd-muted);
57
- font-weight: 400;
58
- }
59
- .dd-c-tip-row {
60
- display: contents;
61
- }
62
- .dd-c-swatch {
63
- grid-column: 1;
64
- margin-right: 7px;
65
- width: 8px;
66
- height: 8px;
67
- border-radius: 2px;
68
- }
69
- .dd-c-tip-label {
70
- grid-column: 2;
71
- overflow: hidden;
72
- white-space: nowrap;
73
- text-overflow: ellipsis;
74
- color: var(--dd-muted);
75
- }
76
- /* The value a click or Enter opens: the one nearest the pointer, or chosen by the keyboard. */
77
- .dd-c-tip-row[data-chosen] .dd-c-tip-label {
78
- color: var(--dd-ink);
79
- text-decoration: underline;
80
- }
81
- .dd-c-tip-value {
82
- grid-column: 3;
83
- padding-left: 14px;
84
- font-weight: 600;
85
- text-align: right;
86
- }
87
- .dd-c-tip-aside {
88
- grid-column: 2 / -1;
89
- padding-left: 8px;
90
- color: var(--dd-muted);
91
- text-align: right;
92
- }
93
- /* A stop with no value (a gap): the word for it under the title. */
94
- .dd-c-tip-empty {
95
- grid-column: 1 / -1;
96
- color: var(--dd-muted);
97
- }
98
- /* Under the values a short box has room for: how many more the stop has. */
99
- .dd-c-tip-more {
100
- grid-column: 1 / -1;
101
- color: var(--dd-muted);
102
- }
103
- .dd-c-tip-hint {
104
- grid-column: 1 / -1;
105
- margin-top: 4px;
106
- color: var(--dd-muted);
107
- }
1
+ .dd-chart:focus-visible{border-radius:var(--dd-radius);outline:2px solid var(--dd-accent);outline-offset:2px}.dd-chart[data-opens=true]>.dd-c-stage{cursor:pointer}.dd-c-stage>.dd-chart-picture>svg{display:block;overflow:visible}.dd-c-tip{display:grid;grid-template-columns:auto minmax(0,1fr) minmax(0,auto);row-gap:4px;align-items:center;box-sizing:border-box;min-width:min(146px,100%);max-width:min(304px,100%);max-height:100%;overflow:auto;padding:9px 12px;background:var(--dd-surface);color:var(--dd-ink);border:1px solid var(--dd-line);border-radius:var(--dd-tooltip-radius, 5px);box-shadow:0 1px 2px rgb(0 0 0 / 0.06),0 5px 14px -4px rgb(0 0 0 / 0.16);font-family:var(--dd-font, system-ui, sans-serif);font-size:12px;line-height:16px;font-variant-numeric:tabular-nums;white-space:normal;overflow-wrap:anywhere;z-index:2}.dd-c-tip-title{grid-column:1 / -1;margin-bottom:3px;font-weight:600;white-space:normal;overflow-wrap:anywhere}.dd-c-tip-note{margin-left:6px;color:var(--dd-muted);font-weight:400}.dd-c-tip-row{display:contents}.dd-c-swatch{grid-column:1;margin-right:7px;width:8px;height:8px;border-radius:2px}.dd-c-tip-label{grid-column:2;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--dd-muted)}.dd-c-tip-row[data-chosen] .dd-c-tip-label{color:var(--dd-ink);font-weight:600}.dd-c-tip-value{grid-column:3;padding-left:14px;font-weight:600;text-align:right}.dd-c-tip-aside{grid-column:1 / -1;color:var(--dd-muted);text-align:start}.dd-c-tip[data-single] .dd-c-tip-title{grid-column:1 / 3;grid-row:1;margin:0}.dd-c-tip[data-single] .dd-c-tip-value{grid-row:1;font-size:13px}.dd-c-tip[data-single] .dd-c-swatch,.dd-c-tip[data-single] .dd-c-tip-label{grid-row:2}.dd-c-tip[data-single] .dd-c-tip-label{grid-column:2 / -1;white-space:normal}.dd-c-tip-empty{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-more{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-hint{grid-column:1 / -1;margin-top:2px;padding-top:5px;border-top:1px solid var(--dd-line-soft, var(--dd-line));color:var(--dd-muted)}
@@ -1,121 +1 @@
1
- /*
2
- * The chart's look around the picture: the focus ring and the tooltip. The host includes this
3
- * file once (`import "derive-dashboards/charts-react/chart.css"`); nothing imports it on its
4
- * own. A chart wears the theme's names for the same jobs (`theme.css`): its box is `dd-chart`,
5
- * marked `data-drillable="true"` when some value of it opens, as the theme marks a chart, and
6
- * `data-opens="true"` while the value under the pointer or the keyboard opens; its
7
- * picture is `dd-chart-picture`; its note is `dd-chart-note`, inside the box under the picture;
8
- * its table is `dd-sr-only`. So a host styles a chart once, whichever kit draws it (a rule on
9
- * `.dd-chart .dd-chart-note` reaches the note here too), and the light and the dark theme both
10
- * apply.
11
- * Its rules sit in the theme's layer, so a host overrides them as it overrides the theme.
12
- */
13
-
14
- @layer derive-dashboards {
15
- /*
16
- * The theme's ring for what opens (`[data-drill]:focus-visible`), which does not reach a
17
- * chart's box: the box takes focus to move through its stops, whether or not anything opens.
18
- */
19
- .dd-chart:focus-visible {
20
- border-radius: var(--dd-radius);
21
- outline: 2px solid var(--dd-accent);
22
- outline-offset: 2px;
23
- }
24
- /* Over the picture, the pointer cursor while the value under the pointer opens. */
25
- .dd-chart[data-opens="true"] > .dd-c-stage {
26
- cursor: pointer;
27
- }
28
- .dd-c-stage > .dd-chart-picture > svg {
29
- display: block;
30
- overflow: visible;
31
- }
32
-
33
- .dd-c-tip {
34
- display: grid;
35
- grid-template-columns: auto minmax(3ch, 1fr) minmax(0, auto);
36
- row-gap: 3px;
37
- align-items: center;
38
- box-sizing: border-box;
39
- min-width: min(132px, 100%);
40
- max-width: min(304px, 100%);
41
- max-height: 100%;
42
- overflow: auto;
43
- padding: 8px 11px 9px;
44
- background: var(--dd-surface);
45
- color: var(--dd-ink);
46
- border: 1px solid var(--dd-line);
47
- border-radius: var(--dd-radius);
48
- box-shadow:
49
- 0 1px 2px rgb(0 0 0 / 0.06),
50
- 0 8px 24px -6px rgb(0 0 0 / 0.18);
51
- font-family: var(--dd-font, system-ui, sans-serif);
52
- font-size: 12px;
53
- line-height: 16px;
54
- font-variant-numeric: tabular-nums;
55
- white-space: normal;
56
- overflow-wrap: anywhere;
57
- z-index: 2;
58
- }
59
- /* A long name breaks over lines inside the tooltip: it is never drawn past the tooltip's edge. */
60
- .dd-c-tip-title {
61
- grid-column: 1 / -1;
62
- margin-bottom: 3px;
63
- font-weight: 600;
64
- white-space: normal;
65
- overflow-wrap: anywhere;
66
- }
67
- .dd-c-tip-note {
68
- margin-left: 6px;
69
- color: var(--dd-muted);
70
- font-weight: 400;
71
- }
72
- .dd-c-tip-row {
73
- display: contents;
74
- }
75
- .dd-c-swatch {
76
- grid-column: 1;
77
- margin-right: 7px;
78
- width: 8px;
79
- height: 8px;
80
- border-radius: 2px;
81
- }
82
- .dd-c-tip-label {
83
- grid-column: 2;
84
- overflow: hidden;
85
- white-space: nowrap;
86
- text-overflow: ellipsis;
87
- color: var(--dd-muted);
88
- }
89
- /* The value a click or Enter opens: the one nearest the pointer, or chosen by the keyboard. */
90
- .dd-c-tip-row[data-chosen] .dd-c-tip-label {
91
- color: var(--dd-ink);
92
- text-decoration: underline;
93
- }
94
- .dd-c-tip-value {
95
- grid-column: 3;
96
- padding-left: 14px;
97
- font-weight: 600;
98
- text-align: right;
99
- }
100
- .dd-c-tip-aside {
101
- grid-column: 2 / -1;
102
- padding-left: 8px;
103
- color: var(--dd-muted);
104
- text-align: right;
105
- }
106
- /* A stop with no value (a gap): the word for it under the title. */
107
- .dd-c-tip-empty {
108
- grid-column: 1 / -1;
109
- color: var(--dd-muted);
110
- }
111
- /* Under the values a short box has room for: how many more the stop has. */
112
- .dd-c-tip-more {
113
- grid-column: 1 / -1;
114
- color: var(--dd-muted);
115
- }
116
- .dd-c-tip-hint {
117
- grid-column: 1 / -1;
118
- margin-top: 4px;
119
- color: var(--dd-muted);
120
- }
121
- }
1
+ @layer derive-dashboards{.dd-chart:focus-visible{border-radius:var(--dd-radius);outline:2px solid var(--dd-accent);outline-offset:2px}.dd-chart[data-opens=true]>.dd-c-stage{cursor:pointer}.dd-c-stage>.dd-chart-picture>svg{display:block;overflow:visible}.dd-c-tip{display:grid;grid-template-columns:auto minmax(0,1fr) minmax(0,auto);row-gap:4px;align-items:center;box-sizing:border-box;min-width:min(146px,100%);max-width:min(304px,100%);max-height:100%;overflow:auto;padding:9px 12px;background:var(--dd-surface);color:var(--dd-ink);border:1px solid var(--dd-line);border-radius:var(--dd-tooltip-radius, 5px);box-shadow:0 1px 2px rgb(0 0 0 / 0.06),0 5px 14px -4px rgb(0 0 0 / 0.16);font-family:var(--dd-font, system-ui, sans-serif);font-size:12px;line-height:16px;font-variant-numeric:tabular-nums;white-space:normal;overflow-wrap:anywhere;z-index:2}.dd-c-tip-title{grid-column:1 / -1;margin-bottom:3px;font-weight:600;white-space:normal;overflow-wrap:anywhere}.dd-c-tip-note{margin-left:6px;color:var(--dd-muted);font-weight:400}.dd-c-tip-row{display:contents}.dd-c-swatch{grid-column:1;margin-right:7px;width:8px;height:8px;border-radius:2px}.dd-c-tip-label{grid-column:2;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--dd-muted)}.dd-c-tip-row[data-chosen] .dd-c-tip-label{color:var(--dd-ink);font-weight:600}.dd-c-tip-value{grid-column:3;padding-left:14px;font-weight:600;text-align:right}.dd-c-tip-aside{grid-column:1 / -1;color:var(--dd-muted);text-align:start}.dd-c-tip[data-single] .dd-c-tip-title{grid-column:1 / 3;grid-row:1;margin:0}.dd-c-tip[data-single] .dd-c-tip-value{grid-row:1;font-size:13px}.dd-c-tip[data-single] .dd-c-swatch,.dd-c-tip[data-single] .dd-c-tip-label{grid-row:2}.dd-c-tip[data-single] .dd-c-tip-label{grid-column:2 / -1;white-space:normal}.dd-c-tip-empty{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-more{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-hint{grid-column:1 / -1;margin-top:2px;padding-top:5px;border-top:1px solid var(--dd-line-soft, var(--dd-line));color:var(--dd-muted)}}
@@ -29,17 +29,28 @@ function anchorOf(hover, stop, pointer) {
29
29
  };
30
30
  }
31
31
  /** The room between a stop and its tooltip, in pixels. */
32
- const GAP = 12;
32
+ const GAP = 20;
33
33
  /** The room between a row and the tooltip over or under it. */
34
- const UNDER = 4;
34
+ const UNDER = 10;
35
35
  /** A number kept between two ends; the low end wins when they cross. */
36
36
  const within = (value, low, high) => Math.max(low, Math.min(value, high));
37
37
  /** Beside the anchor: to its right, or to its left when it would cross the right edge. */
38
38
  function beside(anchor, tip, box) {
39
+ const top = anchor.y - tip.height / 2;
39
40
  const right = anchor.x + GAP;
41
+ if (right + tip.width <= box.width) return {
42
+ left: right,
43
+ top
44
+ };
45
+ const left = anchor.x - tip.width - GAP;
46
+ if (left >= 0) return {
47
+ left,
48
+ top
49
+ };
50
+ const above = anchor.y - tip.height - UNDER;
40
51
  return {
41
- left: right + tip.width > box.width ? anchor.x - GAP - tip.width : right,
42
- top: anchor.y - tip.height / 2
52
+ left: anchor.x - tip.width / 2,
53
+ top: above >= 0 ? above : anchor.y + UNDER
43
54
  };
44
55
  }
45
56
  /** The tops a tooltip on a row's line may take: centred on it, hanging from it, standing on it. */
@@ -49,8 +60,8 @@ const linesOf = (anchor, row, tip) => [
49
60
  row.bottom - tip.height
50
61
  ];
51
62
  /**
52
- * On the row's own line, right of the pointer and clear of the reach of every row it lies over;
53
- * undefined when the box has no room there. Centred on the row first; else hanging down from
63
+ * On the row's own line, clear of the pointer and the reach of every row it lies over;
64
+ * null when the box has no room there. Centred on the row first; else hanging down from
54
65
  * it or standing up on it, whichever passes the shorter bars beside it.
55
66
  */
56
67
  function onLine(anchor, row, tip, box) {
@@ -59,18 +70,22 @@ function onLine(anchor, row, tip, box) {
59
70
  end: anchor.x
60
71
  }];
61
72
  const high = box.width - tip.width;
62
- const found = linesOf(anchor, row, tip).map((wanted) => {
73
+ for (const wanted of linesOf(anchor, row, tip)) {
63
74
  const top = within(wanted, 0, box.height - tip.height);
64
75
  const over = rows.filter((r) => r.bottom > top && r.top < top + tip.height);
65
- return {
66
- top,
67
- low: Math.max(0, ...over.map((r) => r.end)) + GAP
76
+ const low = Math.max(0, ...over.map((r) => r.end)) + GAP;
77
+ const right = Math.max(low, anchor.x + GAP);
78
+ if (right <= high) return {
79
+ left: right,
80
+ top
68
81
  };
69
- }).find((place) => place.low <= high);
70
- return found === void 0 ? found : {
71
- left: within(anchor.x + GAP, found.low, high),
72
- top: found.top
73
- };
82
+ const left = Math.min(high, anchor.x - GAP - tip.width);
83
+ if (left >= low) return {
84
+ left,
85
+ top
86
+ };
87
+ }
88
+ return null;
74
89
  }
75
90
  /** Over the row, or under it when there is no room over it; centred on the anchor. */
76
91
  function offRow(row, anchor, tip) {
@@ -0,0 +1,49 @@
1
+ import { resolveDimension } from "../model/member.mjs";
2
+ import { nearest } from "../model/validate/fields.mjs";
3
+ import { drillMembers, drillableMembers } from "../query/drill/fields.mjs";
4
+ // src/document/display-comparisons.ts
5
+ function fieldReason(model, source, field, choices) {
6
+ const dimension = resolveDimension(model, source, field)?.dimension;
7
+ if (dimension) {
8
+ if (dimension.sensitive === true || dimension.hidden === true || dimension.drill === false) return "This dimension is excluded from drill-downs.";
9
+ if (dimension.kind === "time") return "Time fields belong in the Over time view.";
10
+ if (drillableMembers(model, source, () => true).includes(field)) return "Add the field to the source’s drill.prefer list to enable it.";
11
+ }
12
+ const near = choices.find((id) => id === `${source}.${field}`) ?? nearest(field, choices);
13
+ return near === void 0 ? "" : `Did you mean "${near}"?`;
14
+ }
15
+ /** Only the host registering its own model receives suggested model members. */
16
+ function authorHint(model, source, field, groups) {
17
+ const { fixed, choices } = groups;
18
+ return [fixed.has(field) ? "The table already groups by it." : fieldReason(model, source, field, choices), choices.length > 0 ? `Available fields: ${choices.join(", ")}.` : "The model offers no other breakdown fields."].filter(Boolean).join(" ");
19
+ }
20
+ /** A row's sealed selection fixes its grouping fields. Its comparison needs another breakdown field. */
21
+ function comparisonIssues(query, comparisons, model, options) {
22
+ const { path, author } = options;
23
+ const groups = query?.dimensions ?? [];
24
+ if (!query || groups.length === 0) return [{
25
+ code: "DISPLAY_INVALID",
26
+ path,
27
+ message: "A table with comparisons needs a grouping dimension in its main query."
28
+ }];
29
+ const offered = drillMembers(model, query.source, () => true);
30
+ const fixed = new Set(groups.map((group) => group.member));
31
+ const choices = offered.filter((field) => !fixed.has(field));
32
+ return Object.entries(comparisons).flatMap(([key, fields]) => fields.flatMap((field, index) => {
33
+ if (choices.includes(field)) return [];
34
+ const hint = author ? authorHint(model, query.source, field, {
35
+ fixed,
36
+ choices
37
+ }) : "Open Breakdown on this source to see the fields available to you.";
38
+ return {
39
+ code: "DISPLAY_INVALID",
40
+ path: [
41
+ ...path,
42
+ key,
43
+ index
44
+ ],
45
+ message: `The comparison for "${key}" cannot group by "${field}". ${hint}`
46
+ };
47
+ }));
48
+ }
49
+ export { comparisonIssues };
@@ -0,0 +1,12 @@
1
+ import { Model } from "../model/types.mjs";
2
+ import { Issue } from "../types/primitives.mjs";
3
+ import { Doc } from "./types.mjs";
4
+ /** Check each widget's options. A host with a model also checks the drill fields its rows can open. */
5
+ export declare function documentDisplayIssues(doc: Doc, model?: Model): Issue[];
6
+ /**
7
+ * What an edit did wrong to a display: each option of the wrong type that the edit set or
8
+ * changed, at `widgets.<id>.display.<option>`. Only what the edit touched is checked: an option
9
+ * stored before options were typed stays as it is, so it never blocks an edit of something
10
+ * else, and replaying a draft's own commands never refuses one that was accepted.
11
+ */
12
+ export declare function editedDisplayIssues(before: Doc, after: Doc, model?: Model): Issue[];
@@ -0,0 +1,56 @@
1
+ import { canonical } from "../value/canonical.mjs";
2
+ import { displayIssues, displayOf, isRecord } from "./display.mjs";
3
+ import { comparisonIssues } from "./display-comparisons.mjs";
4
+ import { displayEntryIssues } from "./display-entries.mjs";
5
+ // src/document/display-validation.ts
6
+ /**
7
+ * What is wrong with one widget's display: each option of the wrong type for its kind, and
8
+ * each option that names a value its query does not have (`displayEntryIssues`).
9
+ */
10
+ function widgetDisplayIssues(widget, path, model, author = false) {
11
+ const issues = [...displayIssues(widget.kind, widget.display, path), ...displayEntryIssues(widget, path)];
12
+ if (!model || widget.kind !== "table") return issues;
13
+ const { comparisons } = displayOf("table", widget.display);
14
+ if (!comparisons || Object.keys(comparisons).length === 0) return issues;
15
+ return [...issues, ...comparisonIssues(widget.queries["main"], comparisons, model, {
16
+ path: [...path, "comparisons"],
17
+ author
18
+ })];
19
+ }
20
+ /** Check each widget's options. A host with a model also checks the drill fields its rows can open. */
21
+ function documentDisplayIssues(doc, model) {
22
+ return Object.entries(doc.widgets).flatMap(([id, widget]) => widgetDisplayIssues(widget, [
23
+ "widgets",
24
+ id,
25
+ "display"
26
+ ], model, true));
27
+ }
28
+ /** An option as an object holds it: none when it has no such option, which is not the same as holding null. */
29
+ const held = (display, option) => Object.hasOwn(display, option) ? { is: display[option] ?? null } : null;
30
+ /**
31
+ * What an edit did wrong to a display: each option of the wrong type that the edit set or
32
+ * changed, at `widgets.<id>.display.<option>`. Only what the edit touched is checked: an option
33
+ * stored before options were typed stays as it is, so it never blocks an edit of something
34
+ * else, and replaying a draft's own commands never refuses one that was accepted.
35
+ */
36
+ function editedDisplayIssues(before, after, model) {
37
+ return Object.entries(after.widgets).flatMap(([id, widget]) => {
38
+ const prior = before.widgets[id];
39
+ if (prior === widget) return [];
40
+ const path = [
41
+ "widgets",
42
+ id,
43
+ "display"
44
+ ];
45
+ const was = prior?.display;
46
+ const old = isRecord(was) ? was : {};
47
+ const now = widget.display;
48
+ const previous = prior ? widgetDisplayIssues(prior, path, model) : [];
49
+ return widgetDisplayIssues(widget, path, model).filter((found) => {
50
+ const option = String(found.path[path.length] ?? "display");
51
+ const [set, had] = isRecord(now) ? [held(now, option), held(old, option)] : [now, was];
52
+ return canonical(set ?? null) !== canonical(had ?? null) || option === "comparisons" && !previous.some((issue) => canonical(issue.path) === canonical(found.path));
53
+ });
54
+ });
55
+ }
56
+ export { documentDisplayIssues, editedDisplayIssues };
@@ -1,6 +1,8 @@
1
1
  import { Issue } from "../types/primitives.mjs";
2
- import { Doc } from "./types.mjs";
3
- type ValueOf<T> = T extends "boolean" ? boolean : T extends "text" ? string : T extends "texts" ? readonly string[] : Readonly<Record<string, string>>;
2
+ /** The first field groups the selected row; the second optionally groups its children. */
3
+ type DistinctPair<First extends string, All extends string = First> = First extends unknown ? readonly [First, Exclude<All, First>] : never;
4
+ export type ComparisonFields<Field extends string = string> = readonly [Field] | (string extends Field ? readonly [Field, Field] : DistinctPair<Field>);
5
+ type ValueOf<T, Field extends string = string> = T extends "comparisons" ? Readonly<Record<string, ComparisonFields<Field>>> : T extends "boolean" ? boolean : T extends "text" ? string : T extends "texts" ? readonly string[] : Readonly<Record<string, string>>;
4
6
  /** Options every widget takes. */
5
7
  declare const SHARED: {
6
8
  readonly keepDateRange: "boolean";
@@ -18,6 +20,7 @@ export declare const DISPLAY_OPTIONS: {
18
20
  readonly bars: "texts";
19
21
  readonly heat: "texts";
20
22
  readonly compact: "boolean";
23
+ readonly comparisons: "comparisons";
21
24
  readonly keepDateRange: "boolean";
22
25
  readonly empty: "text";
23
26
  };
@@ -67,14 +70,12 @@ export declare const DISPLAY_HELP: Readonly<Record<string, string>>;
67
70
  /** A kind of widget the library draws. A host's own kind is not here: its options are its own. */
68
71
  export type DisplayKind = keyof typeof DISPLAY_OPTIONS;
69
72
  /** The options a kind of widget reads, each of its type. */
70
- export type DisplayOf<K extends DisplayKind> = { readonly [P in keyof (typeof DISPLAY_OPTIONS)[K]]?: ValueOf<(typeof DISPLAY_OPTIONS)[K][P]>; };
73
+ export type DisplayOf<K extends DisplayKind, Field extends string = string> = { readonly [P in keyof (typeof DISPLAY_OPTIONS)[K]]?: ValueOf<(typeof DISPLAY_OPTIONS)[K][P], Field>; };
71
74
  /**
72
75
  * What is wrong with a widget's display for its kind: each option of the wrong type, at its
73
76
  * path. None for a kind the library does not draw, and none for an option it does not know.
74
77
  */
75
78
  export declare function displayIssues(kind: string, display: unknown, path?: Issue["path"]): Issue[];
76
- /** Every widget of a document whose display does not fit its kind or its query, at `widgets.<id>.display`. */
77
- export declare function documentDisplayIssues(doc: Doc): Issue[];
78
79
  /**
79
80
  * A widget's options as its kind reads them: each option it knows, when it is of its type. A
80
81
  * stored option of the wrong type (written before options were checked, or by hand) is left
@@ -82,13 +83,6 @@ export declare function documentDisplayIssues(doc: Doc): Issue[];
82
83
  * colours that are text are kept.
83
84
  */
84
85
  export declare function displayOf<K extends DisplayKind>(kind: K, display: unknown): DisplayOf<K>;
85
- /**
86
- * What an edit did wrong to a display: each option of the wrong type that the edit set or
87
- * changed, at `widgets.<id>.display.<option>`. Only what the edit touched is checked: an option
88
- * stored before options were typed stays as it is, so it never blocks an edit of something
89
- * else, and replaying a draft's own commands never refuses one that was accepted.
90
- */
91
- export declare function editedDisplayIssues(before: Doc, after: Doc): Issue[];
92
86
  /** The options every widget takes, whatever draws it. */
93
87
  export type SharedDisplay = { readonly [P in keyof typeof SHARED]?: ValueOf<(typeof SHARED)[P]>; };
94
88
  /** The options every widget takes, whatever draws it: `keepDateRange` and `empty`, and no option of any one kind. */