@malloy-publisher/sdk 0.9.13 → 0.9.15

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 (148) hide show
  1. package/dist/RenderedResult-BClN_PG6.cjs.js +154 -0
  2. package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
  3. package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
  4. package/dist/ServerProvider-e2369oom.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +80 -79
  6. package/dist/builder/index.es.js +7430 -6548
  7. package/dist/client/api.d.ts +30 -6
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
  11. package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
  12. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  13. package/dist/components/Dashboard/index.d.ts +1 -1
  14. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  15. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
  18. package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
  19. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  20. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  21. package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
  22. package/dist/components/Report/Report.d.ts +7 -1
  23. package/dist/components/Report/ReportPage.d.ts +7 -0
  24. package/dist/components/Report/layoutRules.d.ts +45 -0
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  26. package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
  27. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  28. package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
  29. package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
  30. package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
  31. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  32. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  33. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  34. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  35. package/dist/components/ReportBuilder/document.d.ts +53 -5
  36. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  37. package/dist/components/ReportBuilder/placement.d.ts +75 -0
  38. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  39. package/dist/components/ReportBuilder/sortable.d.ts +3 -1
  40. package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
  41. package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
  42. package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
  43. package/dist/index.cjs.js +7 -7
  44. package/dist/index.es.js +3328 -3287
  45. package/dist/text/index.es.js +1 -1
  46. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  47. package/dist/theme/resolveTheme.d.ts +15 -0
  48. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
  49. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
  50. package/dist/utils/blankQuoted.d.ts +15 -0
  51. package/package.json +1 -1
  52. package/src/components/Dashboard/DashboardGrid.tsx +127 -10
  53. package/src/components/Dashboard/DashboardTile.tsx +11 -1
  54. package/src/components/Dashboard/DashboardView.tsx +63 -10
  55. package/src/components/Dashboard/TileCard.tsx +6 -0
  56. package/src/components/Dashboard/index.ts +1 -0
  57. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  58. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  59. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  60. package/src/components/Dashboard/useStuck.ts +76 -28
  61. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  62. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  63. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  64. package/src/components/RenderedResult/RenderedResult.tsx +21 -6
  65. package/src/components/RenderedResult/ResultContainer.tsx +60 -7
  66. package/src/components/RenderedResult/ResultPanel.tsx +21 -1
  67. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  68. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  69. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  70. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  71. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  72. package/src/components/RenderedResult/resultSizing.ts +65 -11
  73. package/src/components/Report/Report.spec.tsx +19 -0
  74. package/src/components/Report/Report.tsx +8 -1
  75. package/src/components/Report/ReportPage.tsx +13 -1
  76. package/src/components/Report/layoutRules.spec.ts +43 -3
  77. package/src/components/Report/layoutRules.ts +70 -0
  78. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  79. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  80. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  81. package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
  82. package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
  83. package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
  84. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  85. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  86. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  87. package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
  88. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  89. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  90. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  91. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  92. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  93. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
  94. package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
  95. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  96. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  97. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
  98. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  99. package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
  100. package/src/components/ReportBuilder/TileFrame.tsx +251 -6
  101. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  102. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  103. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  104. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  105. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  106. package/src/components/ReportBuilder/catalog.ts +90 -37
  107. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  108. package/src/components/ReportBuilder/chartLine.ts +80 -2
  109. package/src/components/ReportBuilder/controls.ts +4 -3
  110. package/src/components/ReportBuilder/document.ts +65 -7
  111. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  112. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  113. package/src/components/ReportBuilder/imports.ts +1 -1
  114. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  115. package/src/components/ReportBuilder/layout.ts +3 -0
  116. package/src/components/ReportBuilder/placement.spec.ts +193 -0
  117. package/src/components/ReportBuilder/placement.ts +250 -0
  118. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  119. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  120. package/src/components/ReportBuilder/preview.ts +203 -40
  121. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  122. package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
  123. package/src/components/ReportBuilder/readDocument.ts +194 -23
  124. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  125. package/src/components/ReportBuilder/sortable.tsx +4 -0
  126. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  127. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  128. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  129. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
  130. package/src/components/ReportBuilder/spliceDocument.ts +139 -52
  131. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  132. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  133. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  134. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  135. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  136. package/src/components/ReportBuilder/useTileHeight.ts +149 -0
  137. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  138. package/src/components/ReportBuilder/useTileResize.ts +16 -1
  139. package/src/components/given/FilterButton.spec.tsx +27 -11
  140. package/src/components/given/FilterButton.tsx +19 -6
  141. package/src/theme/resolveTheme.spec.ts +72 -1
  142. package/src/theme/resolveTheme.ts +43 -0
  143. package/src/utils/blankQuoted.spec.ts +50 -0
  144. package/src/utils/blankQuoted.ts +32 -0
  145. package/src/utils/malloyText.ts +2 -1
  146. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  147. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  148. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
@@ -1,8 +1,11 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { parseTag } from "@malloydata/malloy-tag";
5
4
  import type { CompiledModel } from "../../client";
5
+ import {
6
+ columnCounts,
7
+ type ResultField,
8
+ } from "../RenderedResult/chartShapeProblem";
6
9
  import { exportedSources } from "../DocumentCreate/exportedSources";
7
10
  import { CHART_TAGS } from "./chartLine";
8
11
  import { chartOf, docOf } from "./viewAnnotations";
@@ -40,6 +43,14 @@ export interface CatalogView {
40
43
  chart?: string;
41
44
  /** Every output column is an aggregate, which is the only shape `big_value` renders. Absent when the model did not say. */
42
45
  aggregateOnly?: boolean;
46
+ /** How many of its output columns are group-bys and how many are totals, when the model said: what decides which charts can draw it. */
47
+ shape?: ViewShape;
48
+ }
49
+
50
+ /** A view's output columns by role: a group-by is a field a chart can put on its x axis, a total one it can put on its y axis. */
51
+ export interface ViewShape {
52
+ groupBys: number;
53
+ totals: number;
43
54
  }
44
55
 
45
56
  export interface CatalogSource {
@@ -64,6 +75,13 @@ export interface CatalogSource {
64
75
 
65
76
  export interface PackageCatalog {
66
77
  sources: CatalogSource[];
78
+ /**
79
+ * The views the report file itself declares, by source then view, from the
80
+ * file's own compiled model: an inline `view: kpis is { aggregate: … }` is
81
+ * in no other model, so without these the builder could not tell which
82
+ * charts such a tile can take. Absent until that model has answered.
83
+ */
84
+ documentViews?: Map<string, Map<string, CatalogView>>;
67
85
  }
68
86
 
69
87
  /**
@@ -134,37 +152,83 @@ function parsedSourceInfos(model: CompiledModel): ParsedSourceInfo[] {
134
152
  return infos;
135
153
  }
136
154
 
137
- /** An aggregate output column has `calculation` as a top-level property of its `#(malloy)` note; a group-by or nested one does not. */
138
- const isAggregateColumn = (field: Record<string, unknown>) =>
139
- ((field["annotations"] as Array<{ value?: string }> | undefined) ?? []).some(
140
- (note) => {
141
- const text = note.value ?? "";
142
- return (
143
- text.startsWith("#(malloy)") &&
144
- parseTag(text.slice("#(malloy)".length)).tag?.has("calculation") ===
145
- true
146
- );
147
- },
148
- );
149
-
150
- /** Per source, the views whose every output column is an aggregate. */
151
- function aggregateViewsOf(model: CompiledModel): Map<string, Set<string>> {
152
- const bySource = new Map<string, Set<string>>();
155
+ /** Per source, per view: the shape of its output, and whether every column is a total. Columns are read by the result panel's own rule (`columnCounts`). */
156
+ function viewShapesOf(
157
+ model: CompiledModel,
158
+ ): Map<string, Map<string, Omit<CatalogView, "name">>> {
159
+ const bySource = new Map<string, Map<string, Omit<CatalogView, "name">>>();
153
160
  for (const info of parsedSourceInfos(model)) {
154
- const names = new Set<string>();
161
+ const views = new Map<string, Omit<CatalogView, "name">>();
155
162
  for (const field of info.schema?.fields ?? []) {
156
163
  if (field["kind"] !== "view" || typeof field["name"] !== "string")
157
164
  continue;
158
165
  const columns = (field["schema"] as { fields?: unknown } | undefined)
159
- ?.fields as Array<Record<string, unknown>> | undefined;
160
- if (columns && columns.length > 0 && columns.every(isAggregateColumn))
161
- names.add(field["name"]);
166
+ ?.fields as ResultField[] | undefined;
167
+ if (!columns || columns.length === 0) continue;
168
+ const { groupBys, totals } = columnCounts(columns);
169
+ views.set(field["name"], {
170
+ shape: { groupBys, totals },
171
+ ...(totals === columns.length ? { aggregateOnly: true } : {}),
172
+ });
162
173
  }
163
- bySource.set(info.name, names);
174
+ bySource.set(info.name, views);
164
175
  }
165
176
  return bySource;
166
177
  }
167
178
 
179
+ type ModelSource = NonNullable<CompiledModel["sources"]>[number];
180
+ type ModelView = NonNullable<ModelSource["views"]>[number];
181
+
182
+ /** One view of a model's source as the catalog lists it: its doc line, the chart it declares, and its shape. */
183
+ function catalogViewOf(
184
+ view: ModelView & { name: string },
185
+ shape: Omit<CatalogView, "name"> | undefined,
186
+ ): CatalogView {
187
+ const description = docOf(view.annotations);
188
+ const chart = chartOf(view.annotations);
189
+ return {
190
+ name: view.name,
191
+ ...(description ? { description } : {}),
192
+ ...(chart ? { chart } : {}),
193
+ ...shape,
194
+ };
195
+ }
196
+
197
+ const namedViews = (source: ModelSource) =>
198
+ (source.views ?? []).filter(
199
+ (view): view is ModelView & { name: string } =>
200
+ typeof view.name === "string",
201
+ );
202
+
203
+ /**
204
+ * The views a report file declares, from its own compiled model, keyed by
205
+ * source then view. The file's sources extend the package's, so its model
206
+ * lists their views too; only the ones under the file's own source names are
207
+ * the file's, and those are what a tile in it names. Each carries the chart
208
+ * its view declares, as a catalog view does: a pick negates that tag, and
209
+ * without it a `# line_chart` view picked as a bar would ask for both.
210
+ */
211
+ export function documentViewsOf(
212
+ model: CompiledModel,
213
+ ): Map<string, Map<string, CatalogView>> {
214
+ const shapes = viewShapesOf(model);
215
+ const out = new Map<string, Map<string, CatalogView>>();
216
+ for (const source of model.sources ?? []) {
217
+ if (!source.name) continue;
218
+ const own = shapes.get(source.name);
219
+ out.set(
220
+ source.name,
221
+ new Map(
222
+ namedViews(source).map((view) => [
223
+ view.name,
224
+ catalogViewOf(view, own?.get(view.name)),
225
+ ]),
226
+ ),
227
+ );
228
+ }
229
+ return out;
230
+ }
231
+
168
232
  /**
169
233
  * The fields a filter on `source` may name: its dimensions, joins included as
170
234
  * paths. Measures are not filterable with `where:` and are left out. Undefined
@@ -227,7 +291,7 @@ export function buildCatalog(
227
291
  const modelPath = pathOf(model);
228
292
  if (isReportModel(modelPath, reportPaths)) continue;
229
293
  const fields = fieldsOf(model);
230
- const aggregates = aggregateViewsOf(model);
294
+ const shapes = viewShapesOf(model);
231
295
 
232
296
  for (const source of model.sources ?? []) {
233
297
  const name = source.name;
@@ -250,20 +314,9 @@ export function buildCatalog(
250
314
  ...(docOf(source.annotations)
251
315
  ? { description: docOf(source.annotations) as string }
252
316
  : {}),
253
- views: (source.views ?? [])
254
- .filter((view) => typeof view.name === "string")
255
- .map((view) => ({
256
- name: view.name as string,
257
- ...(docOf(view.annotations)
258
- ? { description: docOf(view.annotations) as string }
259
- : {}),
260
- ...(chartOf(view.annotations)
261
- ? { chart: chartOf(view.annotations) as string }
262
- : {}),
263
- ...(aggregates.get(name)?.has(view.name as string)
264
- ? { aggregateOnly: true }
265
- : {}),
266
- })),
317
+ views: namedViews(source).map((view) =>
318
+ catalogViewOf(view, shapes.get(name)?.get(view.name)),
319
+ ),
267
320
  givens,
268
321
  fields: fields.get(name) ?? [],
269
322
  });
@@ -10,8 +10,26 @@ import {
10
10
  isChartPick,
11
11
  mentionsChartTag,
12
12
  parseChartLine,
13
+ seriesColorFrom,
14
+ seriesColorLine,
15
+ seriesColorOf,
13
16
  } from "./chartLine";
14
17
 
18
+ describe("seriesColorFrom", () => {
19
+ // A host theme's series, as the swatches offer them: only what a colour
20
+ // line can hold and read back.
21
+ it("writes a theme colour as #rrggbb, widening #abc and refusing what it cannot write", () => {
22
+ expect(seriesColorFrom("#1F6AA8")).toBe("#1f6aa8");
23
+ expect(seriesColorFrom("#AbC")).toBe("#aabbcc");
24
+ expect(seriesColorFrom("rebeccapurple")).toBeUndefined();
25
+ expect(seriesColorFrom("rgb(1, 2, 3)")).toBeUndefined();
26
+ for (const color of ["#1F6AA8", "#AbC"])
27
+ expect(
28
+ seriesColorOf(seriesColorLine(seriesColorFrom(color) as string)),
29
+ ).toBe(seriesColorFrom(color));
30
+ });
31
+ });
32
+
15
33
  describe("parseChartLine", () => {
16
34
  it("recognizes a bare pick, negations, and the writer's own lines", () => {
17
35
  expect(parseChartLine("# line_chart")).toEqual({
@@ -64,16 +82,25 @@ describe("mentionsChartTag", () => {
64
82
  describe("chartLineText", () => {
65
83
  it("negates every other chart tag and viz, in a fixed order", () => {
66
84
  expect(chartLineText("line_chart")).toBe(
67
- "# -bar_chart -big_value -scatter_chart -shape_map -segment_map -viz line_chart",
85
+ "# -bar_chart -big_value -scatter_chart -shape_map -segment_map -combo_chart -viz line_chart",
68
86
  );
69
87
  expect(chartLineText("bar_chart")).toBe(
70
- "# -line_chart -big_value -scatter_chart -shape_map -segment_map -viz bar_chart",
88
+ "# -line_chart -big_value -scatter_chart -shape_map -segment_map -combo_chart -viz bar_chart",
89
+ );
90
+ });
91
+
92
+ it("writes a combo chart, bars and a line on two axes, like any other pick", () => {
93
+ expect(chartLineText("combo_chart")).toBe(
94
+ "# -line_chart -bar_chart -big_value -scatter_chart -shape_map -segment_map -viz combo_chart",
95
+ );
96
+ expect(chartLineText("combo_chart", ["bar_chart"])).toBe(
97
+ "# -bar_chart -viz combo_chart",
71
98
  );
72
99
  });
73
100
 
74
101
  it("writes -viz on the no-chart line, which keeps a viz= view from rendering a chart", () => {
75
102
  expect(chartLineText("none")).toBe(
76
- "# -line_chart -bar_chart -big_value -scatter_chart -shape_map -segment_map -viz",
103
+ "# -line_chart -bar_chart -big_value -scatter_chart -shape_map -segment_map -combo_chart -viz",
77
104
  );
78
105
  });
79
106
 
@@ -81,12 +108,19 @@ describe("chartLineText", () => {
81
108
  expect(chartLineText("line_chart", ["bar_chart"])).toBe(
82
109
  "# -bar_chart -viz line_chart",
83
110
  );
84
- expect(chartLineText("none", ["bar_chart"])).toBe("# -bar_chart -viz");
85
111
  expect(chartLineText("bar_chart", ["bar_chart"])).toBe(
86
112
  "# -viz bar_chart",
87
113
  );
88
114
  expect(chartLineText("line_chart", [])).toBe("# -viz line_chart");
89
- expect(chartLineText("none", [])).toBe("# -viz");
115
+ });
116
+
117
+ // A view of totals draws as big numbers with no tag (the KPI promotion
118
+ // adds one), so Table takes `big_value` off whatever the view carries.
119
+ it("always takes big_value off for Table", () => {
120
+ expect(chartLineText("none", ["bar_chart"])).toBe(
121
+ "# -bar_chart -big_value -viz",
122
+ );
123
+ expect(chartLineText("none", [])).toBe("# -big_value -viz");
90
124
  });
91
125
 
92
126
  it("reads a narrowed line back as the same state", () => {
@@ -112,9 +146,11 @@ describe("chartLineText through the tag parser", () => {
112
146
  "scatter_chart",
113
147
  "shape_map",
114
148
  "segment_map",
149
+ "combo_chart",
115
150
  ] as const;
116
151
  const BASES = [
117
152
  "# bar_chart",
153
+ "# combo_chart",
118
154
  "# line_chart",
119
155
  "# viz=line",
120
156
  "# big_value",
@@ -167,6 +203,7 @@ describe("chartStateOf", () => {
167
203
  expect(chartStateOf(["# line_chart", "# -viz"])).toBe("custom");
168
204
  expect(chartStateOf(["# sparkline"])).toBe("custom");
169
205
  expect(chartStateOf(["# bar_chart"])).toBe("bar_chart");
206
+ expect(chartStateOf(["# combo_chart"])).toBe("combo_chart");
170
207
  });
171
208
  });
172
209
 
@@ -6,6 +6,8 @@
6
6
  * Pure text, with no Malloy import, so both writers and the main entry can reach it.
7
7
  */
8
8
 
9
+ import { blankQuoted } from "../../utils/blankQuoted";
10
+
9
11
  /** The renderer's chart tags, as they are spelled in a model. */
10
12
  export const CHART_TAGS = [
11
13
  "bar_chart",
@@ -15,6 +17,7 @@ export const CHART_TAGS = [
15
17
  "segment_map",
16
18
  "big_value",
17
19
  "sparkline",
20
+ "combo_chart",
18
21
  ];
19
22
 
20
23
  /** The tags the renderer has a plugin for, in the order a line negates them. */
@@ -25,6 +28,8 @@ const PLUGIN_TAGS = [
25
28
  "scatter_chart",
26
29
  "shape_map",
27
30
  "segment_map",
31
+ // Last, so the lines written before the renderer had it keep their order.
32
+ "combo_chart",
28
33
  ] as const;
29
34
 
30
35
  export type ChartPick = (typeof PLUGIN_TAGS)[number];
@@ -70,16 +75,42 @@ export function parseChartLine(line: string): ChartLineParts | undefined {
70
75
  export function mentionsChartTag(line: string): boolean {
71
76
  const trimmed = line.trim();
72
77
  if (!/^#[ \t]/.test(trimmed) || parseChartLine(trimmed)) return false;
73
- const unquoted = trimmed.replace(/"(?:[^"\\]|\\.)*"/g, '""');
78
+ const unquoted = blankQuoted(trimmed);
74
79
  return (unquoted.match(/[A-Za-z_]+/g) ?? []).some((word) =>
75
80
  LINE_NAMES.has(word),
76
81
  );
77
82
  }
78
83
 
84
+ /**
85
+ * The line that previews "Default" on a tile whose saved body may carry
86
+ * a chart line of its own: the chart tags taken off, and nothing put on.
87
+ * Unlike Table's line it does not negate `viz`, so it is not a choice of
88
+ * rendering: what the view's own shape gives is what draws.
89
+ *
90
+ * `big_value` is left alone. A one-row view of totals draws as big numbers
91
+ * with no tag at all (see `promoteMeasureRowToKpis`), which is what "From the
92
+ * view" must show; measured, a `# big_value` after a `# -big_value` in the
93
+ * same result does not bring the cards back, and the tile drew a one-row
94
+ * table. Big value can only have been picked on such a view, so keeping it
95
+ * changes nothing that Default would otherwise show.
96
+ */
97
+ export function chartResetLine(): string {
98
+ return [
99
+ "#",
100
+ ...PLUGIN_TAGS.filter((tag) => tag !== "big_value").map(
101
+ (tag) => `-${tag}`,
102
+ ),
103
+ ].join(" ");
104
+ }
105
+
79
106
  /**
80
107
  * The line for a pick. Given the chart tags the view carries it negates only those; without them
81
108
  * (the catalog does not know the view) it negates every other chart tag. `-viz` stays either way,
82
109
  * since the catalog does not report a `viz=` tag.
110
+ *
111
+ * Table also negates `big_value` always. A one-row view of totals draws as big numbers with no
112
+ * tag of its own (`promoteMeasureRowToKpis` puts `# big_value` ahead of the view's lines), so
113
+ * "the view carries none" is not "nothing to take off": only a `-big_value` after it draws a table.
83
114
  */
84
115
  export function chartLineText(
85
116
  chart: ChartPick | "none",
@@ -87,7 +118,10 @@ export function chartLineText(
87
118
  ): string {
88
119
  const negated = PLUGIN_TAGS.filter(
89
120
  (tag) =>
90
- tag !== chart && (carried === undefined || carried.includes(tag)),
121
+ tag !== chart &&
122
+ (carried === undefined ||
123
+ carried.includes(tag) ||
124
+ (chart === "none" && tag === "big_value")),
91
125
  ).map((tag) => `-${tag}`);
92
126
  return ["#", ...negated, "-viz", ...(chart === "none" ? [] : [chart])].join(
93
127
  " ",
@@ -116,6 +150,50 @@ export function chartStateOfTagLines(lines: string[]): ChartState | undefined {
116
150
  return ours.length === 0 ? undefined : chartStateOf(ours);
117
151
  }
118
152
 
153
+ /**
154
+ * The one colour line a builder writes above a tile: its chart's first series
155
+ * colour, as the per-chart theme annotation the renderer already reads
156
+ * (`# theme.palette.series=["#1f6aa8"]`). One colour only, so a line with a
157
+ * whole palette is the author's and never rewritten.
158
+ */
159
+ const SERIES_COLOR_LINE =
160
+ /^#[ \t]*theme\.palette\.series[ \t]*=[ \t]*\[[ \t]*"(#[0-9A-Fa-f]{6})"[ \t]*\][ \t]*$/;
161
+
162
+ /** The colour a builder-written colour line sets, or undefined for any other line. */
163
+ export function seriesColorOf(line: string): string | undefined {
164
+ return SERIES_COLOR_LINE.exec(line.trim())?.[1]?.toLowerCase();
165
+ }
166
+
167
+ /** The colour line for a tile's chart colour. */
168
+ export const seriesColorLine = (color: string): string =>
169
+ `# theme.palette.series=["${color.toLowerCase()}"]`;
170
+
171
+ /**
172
+ * The line that takes a saved colour line off, for a preview of a tile set
173
+ * back to the theme's colours. The tag parser deletes just that path, so any
174
+ * other `theme.*` setting on the view stays.
175
+ */
176
+ export const seriesColorResetLine = "# -theme.palette.series";
177
+
178
+ /** Whether a colour is one the builder writes: `#rrggbb`. */
179
+ export const isSeriesColor = (value: string): boolean =>
180
+ /^#[0-9A-Fa-f]{6}$/.test(value);
181
+
182
+ /**
183
+ * A theme colour as the builder writes it (`#rrggbb`, lower case), or
184
+ * undefined for one it cannot write. A host theme may spell its series `#abc`,
185
+ * which is widened; a named colour or `rgb()` is not offered, since a line
186
+ * holding one would not read back (`seriesColorOf`).
187
+ */
188
+ export function seriesColorFrom(value: string): string | undefined {
189
+ const text = value.trim().toLowerCase();
190
+ if (isSeriesColor(text)) return text;
191
+ const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(text);
192
+ return short
193
+ ? `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}`
194
+ : undefined;
195
+ }
196
+
119
197
  /** The lines of `lines` that are about the chart, recognized or not: what a "custom" state is made of. */
120
198
  export const chartLinesOf = (lines: string[]): string[] =>
121
199
  lines.filter((line) => parseChartLine(line) || mentionsChartTag(line));
@@ -3,6 +3,7 @@
3
3
 
4
4
  import {
5
5
  isQueryTile,
6
+ isReadOnlyTile,
6
7
  type DashboardDocument,
7
8
  type DashboardTile,
8
9
  type LocalGiven,
@@ -320,13 +321,13 @@ export interface MappingRow {
320
321
  * `inline` tile's own first stage — `TreeStage.wheres` in `malloyTree`, which
321
322
  * is the parse tree's answer rather than a depth count. Both forms are
322
323
  * declarations this file owns and the reader reads back. An `inherited` tile is declared on the
323
- * model's source, which the builder never writes, so it is the one kind this
324
- * excludes, and so is an `opaque` one: its body has no single block a binding
324
+ * model's source, which the builder never writes, so it is excluded, as is a
325
+ * named `query` tile, and so is an `opaque` one: its body has no single block a binding
325
326
  * belongs in, which the reader can see before a save is ever attempted.
326
327
  */
327
328
  export const canBind = (tile: DashboardTile): tile is QueryTile =>
328
329
  isQueryTile(tile) &&
329
- tile.declaration.kind !== "inherited" &&
330
+ !isReadOnlyTile(tile) &&
330
331
  tile.declaration.kind !== "opaque";
331
332
 
332
333
  /** The mapping a control has NOW, one row per tile, for the dialog to open on. */
@@ -95,7 +95,7 @@ export interface DashboardDrill {
95
95
  /**
96
96
  * Where a tile's view is declared, and therefore what the builder may edit.
97
97
  *
98
- * Four forms, all of them found in dashboards that ship in this repository, and
98
+ * Five forms, all of them found in dashboards that ship in this repository, and
99
99
  * the distinction decides which affordances a tile gets:
100
100
  *
101
101
  * - `reference` — `view: revenue_trend is sales_by_month` in this file. Fully
@@ -117,12 +117,19 @@ export interface DashboardDrill {
117
117
  * tile is `orders -> by_brand` against an imported source. Nothing about it is
118
118
  * editable here, because its tags live on the model's own view and the builder
119
119
  * does not write model files. Read and shown, not changed.
120
+ * - `query` — the entry names a query rather than a view: `tiles=["by_carrier"]`
121
+ * over a `query: by_carrier is flights -> { … }`, in this file or the model.
122
+ * The tile runs `run: by_carrier`, exactly as the reader does, and has no
123
+ * `source` of its own. Like `inherited` it is read and shown, and moved or
124
+ * removed in the list, but not changed: its tags sit on a `query:` statement
125
+ * the writer does not locate, and its body may be anything a query can be.
120
126
  */
121
127
  export type TileDeclaration =
122
128
  | { kind: "reference"; from: string }
123
129
  | { kind: "inline" }
124
130
  | { kind: "opaque"; why: string }
125
- | { kind: "inherited" };
131
+ | { kind: "inherited" }
132
+ | { kind: "query" };
126
133
 
127
134
  /** A tile that runs a view: a view shown on the page, plus how it is presented. */
128
135
  export interface QueryTile {
@@ -138,9 +145,10 @@ export interface QueryTile {
138
145
  /**
139
146
  * The source it reads, by NAME — an index would break on reorder. May name a
140
147
  * source this file declares in {@link DashboardDocument.sources}, or one it
141
- * merely imports.
148
+ * merely imports. Absent on a tile that names a query (`declaration.kind`
149
+ * `"query"`), whose source is whatever the query's own definition reads.
142
150
  */
143
- source: string;
151
+ source?: string;
144
152
  declaration: TileDeclaration;
145
153
  /**
146
154
  * Given bindings: a `+ { where: … }` refinement on a `reference` tile, or a
@@ -166,15 +174,39 @@ export interface QueryTile {
166
174
  chartLines?: string[];
167
175
  /** The chart tags the tile's view carries, when the catalog knows them: the writer negates only these. Never read from a file. */
168
176
  chartCarried?: string[];
177
+ /**
178
+ * Where the tile sits: its entry's `colspan` and `break` in `tiles=[…]`,
179
+ * or else its view's `# colspan` and `# break`. The writer puts a changed
180
+ * layout on the entry, which every tile has, and takes the view's two tags
181
+ * off a view this file declares, so the layout has one home.
182
+ */
169
183
  colspan?: number;
170
184
  break?: boolean;
185
+ /** `rowspan=N` on its entry: the grid rows it is tall. Only the entry carries it. */
186
+ rowspan?: number;
187
+ /** `row=N` and `col=N` on its entry: where it sits on a placed report, counted from 1. */
188
+ row?: number;
189
+ col?: number;
171
190
  borderless?: boolean;
191
+ /**
192
+ * The chart's colour, `#rrggbb`: its first series colour, written as the
193
+ * per-chart theme line `# theme.palette.series=["#…"]` the renderer reads.
194
+ * Absent, the chart takes the theme's own series.
195
+ */
196
+ color?: string;
197
+ /**
198
+ * The tile's own tags set `theme.palette.series` in a line the builder did
199
+ * not write: a list of two or more colours, or any other spelling. Read from
200
+ * the file, never written. The preview keeps that line when the tile is on
201
+ * Theme, where it otherwise takes a saved builder colour off.
202
+ */
203
+ ownPalette?: true;
172
204
  }
173
205
 
174
206
  /**
175
207
  * A markdown tile: prose between the query tiles, written as a `##|(markdown) <name>` block
176
- * and listed in `tiles=[…]` as `<name> { kind=text }`. Its width and row break live on that
177
- * list entry, since a block has no tags.
208
+ * and listed in `tiles=[…]` as `<name> { kind=text }`. Its layout lives on that list entry,
209
+ * as every tile's does.
178
210
  */
179
211
  export interface TextTile {
180
212
  kind: "text";
@@ -183,6 +215,9 @@ export interface TextTile {
183
215
  markdown: string;
184
216
  colspan?: number;
185
217
  break?: boolean;
218
+ rowspan?: number;
219
+ row?: number;
220
+ col?: number;
186
221
  }
187
222
 
188
223
  export type DashboardTile = QueryTile | TextTile;
@@ -227,9 +262,32 @@ export interface DashboardSource {
227
262
  scopedBy?: string[];
228
263
  }
229
264
 
265
+ /**
266
+ * What a query tile runs, as its `tiles=[…]` entry names it: `source -> view`,
267
+ * or a query's bare name. The one spelling every preview, served-tile lookup
268
+ * and new list entry derives from.
269
+ */
270
+ export const tileExpression = (tile: QueryTile): string =>
271
+ tile.declaration.kind === "query"
272
+ ? tile.name
273
+ : `${tile.source} -> ${tile.name}`;
274
+
275
+ /**
276
+ * Whether the builder can write nothing about this tile but its place in the
277
+ * list: declared on the model's view (`inherited`), or a named query, whose
278
+ * tags are on a `query:` statement the writer does not edit.
279
+ */
280
+ export const isReadOnlyTile = (tile: QueryTile): boolean =>
281
+ tile.declaration.kind === "inherited" || tile.declaration.kind === "query";
282
+
230
283
  /** A tile's identity across a reorder: what the grid keys on, a drag names and the writer matches. */
231
284
  export const tileKey = (tile: DashboardTile) =>
232
- isTextTile(tile) ? `text.${tile.name}` : `${tile.source}.${tile.name}`;
285
+ isTextTile(tile)
286
+ ? `text.${tile.name}`
287
+ : tile.declaration.kind === "query"
288
+ ? // `query` is a Malloy keyword, so no source can carry this prefix.
289
+ `query.${tile.name}`
290
+ : `${tile.source}.${tile.name}`;
233
291
 
234
292
  /** `dimension: <name> is <expression>` in the dashboard's own extension. */
235
293
  export interface DashboardDimension {
@@ -57,7 +57,7 @@ describe("a dashboard with an explicit, empty tile list", () => {
57
57
  colspan: 6,
58
58
  });
59
59
  });
60
- expect(out).toContain('tiles=["one_tiles -> vx_tile"]');
60
+ expect(out).toContain('tiles=["one_tiles -> vx_tile" { colspan=6 }]');
61
61
  const back = await openDocument(out);
62
62
  expect(back.tiles.map(tileKey)).toEqual(["one_tiles.vx_tile"]);
63
63
  });