@malloy-publisher/sdk 0.9.14 → 0.9.16

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 (164) hide show
  1. package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
  2. package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
  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 +7732 -6717
  7. package/dist/builder-entry.d.ts +1 -1
  8. package/dist/client/api.d.ts +31 -7
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
  12. package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
  13. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  14. package/dist/components/Dashboard/index.d.ts +1 -1
  15. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  16. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  17. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  18. package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
  19. package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
  20. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  21. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  22. package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
  23. package/dist/components/Report/Report.d.ts +7 -1
  24. package/dist/components/Report/ReportPage.d.ts +7 -0
  25. package/dist/components/Report/layoutRules.d.ts +45 -0
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  27. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
  29. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  30. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  31. package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
  32. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  33. package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
  34. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  35. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  36. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  37. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  38. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  39. package/dist/components/ReportBuilder/document.d.ts +53 -5
  40. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  41. package/dist/components/ReportBuilder/placement.d.ts +121 -0
  42. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  43. package/dist/components/ReportBuilder/sortable.d.ts +12 -1
  44. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  45. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  46. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  47. package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
  48. package/dist/index.cjs.js +7 -7
  49. package/dist/index.es.js +3349 -3307
  50. package/dist/text/index.es.js +1 -1
  51. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  52. package/dist/theme/classes.d.ts +1 -1
  53. package/dist/theme/resolveTheme.d.ts +15 -0
  54. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
  55. package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
  56. package/dist/utils/blankQuoted.d.ts +15 -0
  57. package/package.json +1 -1
  58. package/src/builder-entry.ts +1 -0
  59. package/src/components/Dashboard/DashboardGrid.tsx +129 -10
  60. package/src/components/Dashboard/DashboardTile.tsx +15 -1
  61. package/src/components/Dashboard/DashboardView.tsx +64 -10
  62. package/src/components/Dashboard/TileCard.tsx +6 -0
  63. package/src/components/Dashboard/index.ts +1 -0
  64. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  65. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  66. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  67. package/src/components/Dashboard/useStuck.ts +76 -28
  68. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  69. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  70. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  71. package/src/components/RenderedResult/RenderedResult.tsx +39 -6
  72. package/src/components/RenderedResult/ResultContainer.tsx +99 -10
  73. package/src/components/RenderedResult/ResultPanel.tsx +25 -1
  74. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  75. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  76. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  77. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  78. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  79. package/src/components/RenderedResult/resultSizing.ts +71 -11
  80. package/src/components/Report/Report.spec.tsx +19 -0
  81. package/src/components/Report/Report.tsx +8 -1
  82. package/src/components/Report/ReportPage.tsx +13 -1
  83. package/src/components/Report/layoutRules.spec.ts +43 -3
  84. package/src/components/Report/layoutRules.ts +70 -0
  85. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  86. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  87. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  88. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  89. package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
  90. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
  91. package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
  92. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  93. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  94. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  95. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  96. package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
  97. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  98. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  99. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  100. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  101. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  102. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
  103. package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
  104. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  105. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  106. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  107. package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
  108. package/src/components/ReportBuilder/TileFrame.tsx +366 -170
  109. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  110. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  111. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  112. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  113. package/src/components/ReportBuilder/builderControls.ts +34 -0
  114. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  115. package/src/components/ReportBuilder/catalog.ts +90 -37
  116. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  117. package/src/components/ReportBuilder/chartLine.ts +80 -2
  118. package/src/components/ReportBuilder/controls.ts +4 -3
  119. package/src/components/ReportBuilder/document.ts +65 -7
  120. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  121. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  122. package/src/components/ReportBuilder/imports.ts +1 -1
  123. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  124. package/src/components/ReportBuilder/layout.ts +3 -0
  125. package/src/components/ReportBuilder/placement.spec.ts +401 -0
  126. package/src/components/ReportBuilder/placement.ts +416 -0
  127. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  128. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  129. package/src/components/ReportBuilder/preview.ts +203 -40
  130. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  131. package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
  132. package/src/components/ReportBuilder/readDocument.ts +197 -29
  133. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  134. package/src/components/ReportBuilder/sortable.tsx +30 -2
  135. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  136. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  137. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  138. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
  139. package/src/components/ReportBuilder/spliceDocument.ts +139 -91
  140. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  141. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  142. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  143. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  144. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  145. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  146. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  147. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  148. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  149. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  150. package/src/components/given/FilterButton.spec.tsx +27 -11
  151. package/src/components/given/FilterButton.tsx +19 -6
  152. package/src/theme/classes.ts +1 -1
  153. package/src/theme/resolveTheme.spec.ts +72 -1
  154. package/src/theme/resolveTheme.ts +43 -0
  155. package/src/utils/blankQuoted.spec.ts +50 -0
  156. package/src/utils/blankQuoted.ts +32 -0
  157. package/src/utils/malloyText.ts +2 -1
  158. package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
  159. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  160. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  161. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
  162. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
  163. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  164. package/src/components/ReportBuilder/useTileResize.ts +0 -133
@@ -3,7 +3,8 @@
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
5
  import type { CompiledModel } from "../../client";
6
- import { buildCatalog } from "./catalog";
6
+ import { chartShapeGap } from "../RenderedResult/chartShapeProblem";
7
+ import { buildCatalog, documentViewsOf } from "./catalog";
7
8
 
8
9
  /**
9
10
  * `sourceInfos` as the compiler wrote it (modelDefToModelInfo on a DuckDB source with a measure `n`
@@ -48,3 +49,138 @@ describe("buildCatalog, aggregate-only views, from real compiler output", () =>
48
49
  );
49
50
  });
50
51
  });
52
+
53
+ describe("documentViewsOf, the views a report file declares itself", () => {
54
+ it("gives each view its shape, from the file's own compiled model", () => {
55
+ const views = documentViewsOf(MODEL).get("s");
56
+ expect(views?.get("kpi")).toEqual({
57
+ name: "kpi",
58
+ aggregateOnly: true,
59
+ shape: { groupBys: 0, totals: 1 },
60
+ });
61
+ expect(views?.get("by_calc_n")?.shape).toEqual({
62
+ groupBys: 1,
63
+ totals: 1,
64
+ });
65
+ // A nest is neither an x-axis field nor a total.
66
+ expect(views?.get("nst")?.shape).toEqual({ groupBys: 1, totals: 0 });
67
+ });
68
+
69
+ // A pick negates the chart its view declares. Without it, a bar picked on
70
+ // a `# line_chart` view wrote `# -viz bar_chart` and the renderer was asked
71
+ // for both charts at once, and drew an error.
72
+ it("carries the chart and doc line each view declares, as the catalog does", () => {
73
+ const withNotes = {
74
+ ...MODEL,
75
+ sources: [
76
+ {
77
+ name: "s",
78
+ views: [
79
+ {
80
+ name: "by_calc_n",
81
+ annotations: [
82
+ "#(doc) Orders by month\n",
83
+ "# line_chart\n",
84
+ ],
85
+ },
86
+ { name: "kpi" },
87
+ ],
88
+ },
89
+ ],
90
+ } as unknown as CompiledModel;
91
+ const views = documentViewsOf(withNotes).get("s");
92
+ expect(views?.get("by_calc_n")).toEqual({
93
+ name: "by_calc_n",
94
+ description: "Orders by month",
95
+ chart: "line_chart",
96
+ shape: { groupBys: 1, totals: 1 },
97
+ });
98
+ expect(views?.get("kpi")?.chart).toBeUndefined();
99
+ expect(views?.get("by_calc_n")).toEqual(
100
+ buildCatalog([withNotes]).sources[0].views.find(
101
+ (v) => v.name === "by_calc_n",
102
+ ),
103
+ );
104
+ });
105
+ });
106
+
107
+ describe("buildCatalog, combo-chart views", () => {
108
+ // Columns as the compiler annotates them: an aggregate carries
109
+ // `calculation` in its `#(malloy)` note, a group-by does not.
110
+ const column = (name: string, aggregate: boolean, array = false) => ({
111
+ kind: "dimension",
112
+ name,
113
+ type: array
114
+ ? {
115
+ kind: "array_type",
116
+ element_type: { kind: "record_type", fields: [] },
117
+ }
118
+ : { kind: "number_type" },
119
+ annotations: [
120
+ {
121
+ value: `#(malloy) ${aggregate ? "calculation " : ""}drill_expression { kind = field_reference name = ${name} }\n`,
122
+ },
123
+ ],
124
+ });
125
+ const view = (name: string, columns: unknown[]) => ({
126
+ kind: "view",
127
+ name,
128
+ schema: { fields: columns },
129
+ });
130
+ const VIEWS = [
131
+ view("by_month", [
132
+ column("month", false),
133
+ column("orders", true),
134
+ column("revenue", true),
135
+ ]),
136
+ view("one_total", [column("month", false), column("orders", true)]),
137
+ view("three_totals", [
138
+ column("month", false),
139
+ column("a", true),
140
+ column("b", true),
141
+ column("c", true),
142
+ ]),
143
+ view("totals_only", [column("a", true), column("b", true)]),
144
+ view("nested_only", [
145
+ column("rows", false, true),
146
+ column("a", true),
147
+ column("b", true),
148
+ ]),
149
+ ];
150
+ const COMBO = {
151
+ ...MODEL,
152
+ sources: [{ name: "s", views: VIEWS.map((v) => ({ name: v.name })) }],
153
+ sourceInfos: [JSON.stringify({ name: "s", schema: { fields: VIEWS } })],
154
+ } as unknown as CompiledModel;
155
+
156
+ it("counts each view's group-bys and totals, a nest being neither", () => {
157
+ const [source] = buildCatalog([COMBO]).sources;
158
+ expect(
159
+ Object.fromEntries(source.views.map((v) => [v.name, v.shape])),
160
+ ).toEqual({
161
+ by_month: { groupBys: 1, totals: 2 },
162
+ one_total: { groupBys: 1, totals: 1 },
163
+ three_totals: { groupBys: 1, totals: 3 },
164
+ totals_only: { groupBys: 0, totals: 2 },
165
+ nested_only: { groupBys: 0, totals: 2 },
166
+ });
167
+ });
168
+
169
+ it("gives only a view with a group by and exactly two totals the shape a bare # combo_chart draws", () => {
170
+ const [source] = buildCatalog([COMBO]).sources;
171
+ expect(
172
+ Object.fromEntries(
173
+ source.views.map((v) => [
174
+ v.name,
175
+ v.shape && chartShapeGap("combo_chart", v.shape),
176
+ ]),
177
+ ),
178
+ ).toEqual({
179
+ by_month: undefined,
180
+ one_total: "combo_totals",
181
+ three_totals: "combo_totals",
182
+ totals_only: "no_x_axis",
183
+ nested_only: "no_x_axis",
184
+ });
185
+ });
186
+ });
@@ -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. */