@sqlrooms/vega 0.29.0-rc.10 → 0.29.0-rc.11

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.
package/README.md CHANGED
@@ -75,7 +75,11 @@ import {
75
75
  createDefaultAiInstructions,
76
76
  createDefaultAiTools,
77
77
  } from '@sqlrooms/ai';
78
- import {createVegaChartTool} from '@sqlrooms/vega';
78
+ import {
79
+ createVegaChartTool,
80
+ VegaChartToolResult,
81
+ type VegaChartToolResultProps,
82
+ } from '@sqlrooms/vega';
79
83
 
80
84
  // inside your createRoomStore composer
81
85
  createAiSlice({
@@ -95,6 +99,41 @@ createAiSlice({
95
99
  - `editable`: whether users can edit SQL/spec in the chart UI
96
100
  - `editorMode`: which editors to render (`'none' | 'sql' | 'vega' | 'both'`)
97
101
 
102
+ ### AI chart result sizing
103
+
104
+ `VegaChartToolResult` retains its default 16:9 layout when no sizing props are
105
+ provided. Use `height="auto"` to opt into data-driven sizing for
106
+ category-dense horizontal bar charts:
107
+
108
+ ```tsx
109
+ const CategoryAwareChartResult = (props: VegaChartToolResultProps) => (
110
+ <VegaChartToolResult {...props} height="auto" />
111
+ );
112
+
113
+ createAiSlice({
114
+ toolRenderers: {
115
+ chart: CategoryAwareChartResult,
116
+ },
117
+ tools: {
118
+ chart: createVegaChartTool(),
119
+ },
120
+ });
121
+ ```
122
+
123
+ The automatic policy inspects the parsed Vega-Lite encoding and counts distinct
124
+ values in the loaded Arrow data. Horizontal bar charts with at least 12
125
+ categories use `clamp(280, 48 + categoryCount * 22, 800)` pixels; other charts
126
+ continue to use `aspectRatio` (16:9 by default). Transformed and concatenated
127
+ multi-view specs also use the aspect ratio because raw Arrow rows do not reflect
128
+ their rendered data or panel layout. A numeric `height` fixes the outer chart
129
+ viewport while preserving responsive width. Applications can also provide
130
+ `getHeight={({spec, arrowTable}) => ...}` for a custom sizing policy; returning
131
+ `'auto'` delegates to the built-in category-aware policy.
132
+
133
+ Sizing is based on loaded query data rather than an LLM-provided row count, so
134
+ it stays accurate when SQL results or application filters change. The Vega-Lite
135
+ spec remains responsible for visualization semantics, not React layout.
136
+
98
137
  ### LLM invocation / Zod schema fields
99
138
 
100
139
  At runtime, the tool call payload is validated by a Zod schema.
@@ -3,6 +3,7 @@ import { ReactNode } from 'react';
3
3
  import { EmbedOptions } from 'vega-embed';
4
4
  import { EditorMode } from './editor/types';
5
5
  import type { VegaChartToolOutput, VegaChartToolParameters } from './VegaChartTool';
6
+ import type { VegaChartHeight, VegaChartHeightResolver } from './chartSizing';
6
7
  export type VegaChartToolResultProps = ToolRendererProps<VegaChartToolOutput, VegaChartToolParameters> & {
7
8
  className?: string;
8
9
  options?: EmbedOptions;
@@ -11,10 +12,25 @@ export type VegaChartToolResultProps = ToolRendererProps<VegaChartToolOutput, Ve
11
12
  * @default 'both'
12
13
  */
13
14
  editorMode?: EditorMode;
15
+ /**
16
+ * Width-to-height ratio used when no fixed or automatic height is selected.
17
+ * @default 16/9
18
+ */
19
+ aspectRatio?: number;
20
+ /**
21
+ * Fixed outer chart height, or `'auto'` to opt into category-aware sizing.
22
+ * Automatic sizing falls back to the aspect ratio for ordinary charts.
23
+ */
24
+ height?: VegaChartHeight;
25
+ /**
26
+ * Optional application-specific height policy. Returning `'auto'` applies
27
+ * the built-in category-aware sizing policy.
28
+ */
29
+ getHeight?: VegaChartHeightResolver;
14
30
  };
15
31
  /**
16
32
  * Renders a chart tool call with visualization using Vega-Lite.
17
33
  * Shows read-only editors for inspecting spec and SQL.
18
34
  */
19
- export declare function VegaChartToolResult({ className, input, output, options, editorMode, }: VegaChartToolResultProps): ReactNode;
35
+ export declare function VegaChartToolResult({ className, input, output, options, editorMode, aspectRatio, height, getHeight, }: VegaChartToolResultProps): ReactNode;
20
36
  //# sourceMappingURL=VegaChartToolResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaChartToolResult.d.ts","sourceRoot":"","sources":["../src/VegaChartToolResult.tsx"],"names":[],"mappings":"AA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vB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,uBAAuB,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,SAAS,EACT,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAmB,EACnB,WAAoB,EACpB,MAAM,EACN,SAAS,GACV,EAAE,wBAAwB,GAAG,SAAS,CAmCtC"}
@@ -9,12 +9,12 @@ import { VegaLiteArrowChart } from './VegaLiteArrowChart';
9
9
  * Renders a chart tool call with visualization using Vega-Lite.
10
10
  * Shows read-only editors for inspecting spec and SQL.
11
11
  */
12
- export function VegaChartToolResult({ className, input, output, options, editorMode = 'both', }) {
12
+ export function VegaChartToolResult({ className, input, output, options, editorMode = 'both', aspectRatio = 16 / 9, height, getHeight, }) {
13
13
  const sqlQuery = output?.sqlQuery ?? '';
14
14
  const vegaLiteSpec = output?.vegaLiteSpec;
15
15
  if (!vegaLiteSpec) {
16
16
  return null;
17
17
  }
18
- return (_jsxs("div", { className: cn('flex max-w-full flex-col gap-2', className), children: [input?.reasoning && (_jsx("p", { className: "text-tiny text-muted-foreground", children: input.reasoning })), _jsx(VegaChartContainer, { spec: vegaLiteSpec, sqlQuery: sqlQuery, options: options, editable: false, children: _jsx("div", { className: "relative max-w-full overflow-x-auto", children: _jsx(VegaChartDisplay, { aspectRatio: 16 / 9, className: "pt-2", children: _jsxs(VegaLiteArrowChart.Actions, { className: "right-3", children: [_jsx(VegaExportAction, {}), _jsx(VegaEditAction, { editorMode: editorMode })] }) }) }) })] }));
18
+ return (_jsxs("div", { className: cn('flex max-w-full flex-col gap-2', className), children: [input?.reasoning && (_jsx("p", { className: "text-tiny text-muted-foreground", children: input.reasoning })), _jsx(VegaChartContainer, { spec: vegaLiteSpec, sqlQuery: sqlQuery, options: options, editable: false, children: _jsx("div", { className: "relative max-w-full overflow-x-auto", children: _jsx(VegaChartDisplay, { aspectRatio: aspectRatio, height: height, getHeight: getHeight, className: "pt-2", children: _jsxs(VegaLiteArrowChart.Actions, { className: "right-3", children: [_jsx(VegaExportAction, {}), _jsx(VegaEditAction, { editorMode: editorMode })] }) }) }) })] }));
19
19
  }
20
20
  //# sourceMappingURL=VegaChartToolResult.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaChartToolResult.js","sourceRoot":"","sources":["../src/VegaChartToolResult.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAIhC,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAexD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAU,GAAG,MAAM,GACM;IACzB,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,YAAY,GAAG,MAAM,EAAE,YAAwC,CAAC;IAEtE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,gCAAgC,EAAE,SAAS,CAAC,aAC5D,KAAK,EAAE,SAAS,IAAI,CACnB,YAAG,SAAS,EAAC,iCAAiC,YAAE,KAAK,CAAC,SAAS,GAAK,CACrE,EACD,KAAC,kBAAkB,IACjB,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,KAAK,YAEf,cAAK,SAAS,EAAC,qCAAqC,YAClD,KAAC,gBAAgB,IAAC,WAAW,EAAE,EAAE,GAAG,CAAC,EAAE,SAAS,EAAC,MAAM,YACrD,MAAC,kBAAkB,CAAC,OAAO,IAAC,SAAS,EAAC,SAAS,aAC7C,KAAC,gBAAgB,KAAG,EACpB,KAAC,cAAc,IAAC,UAAU,EAAE,UAAU,GAAI,IACf,GACZ,GACf,GACa,IACjB,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type {ToolRendererProps} from '@sqlrooms/ai-core';\nimport {cn} from '@sqlrooms/ui';\nimport {ReactNode} from 'react';\nimport {EmbedOptions, VisualizationSpec} from 'vega-embed';\nimport {EditorMode} from './editor/types';\nimport {VegaChartContainer} from './editor/VegaChartContainer';\nimport {VegaChartDisplay} from './editor/VegaChartDisplay';\nimport type {\n VegaChartToolOutput,\n VegaChartToolParameters,\n} from './VegaChartTool';\nimport {VegaEditAction} from './VegaEditAction';\nimport {VegaExportAction} from './VegaExportAction';\nimport {VegaLiteArrowChart} from './VegaLiteArrowChart';\n\nexport type VegaChartToolResultProps = ToolRendererProps<\n VegaChartToolOutput,\n VegaChartToolParameters\n> & {\n className?: string;\n options?: EmbedOptions;\n /**\n * Which editors to show when viewing\n * @default 'both'\n */\n editorMode?: EditorMode;\n};\n\n/**\n * Renders a chart tool call with visualization using Vega-Lite.\n * Shows read-only editors for inspecting spec and SQL.\n */\nexport function VegaChartToolResult({\n className,\n input,\n output,\n options,\n editorMode = 'both',\n}: VegaChartToolResultProps): ReactNode {\n const sqlQuery = output?.sqlQuery ?? '';\n const vegaLiteSpec = output?.vegaLiteSpec as VisualizationSpec | null;\n\n if (!vegaLiteSpec) {\n return null;\n }\n\n return (\n <div className={cn('flex max-w-full flex-col gap-2', className)}>\n {input?.reasoning && (\n <p className=\"text-tiny text-muted-foreground\">{input.reasoning}</p>\n )}\n <VegaChartContainer\n spec={vegaLiteSpec}\n sqlQuery={sqlQuery}\n options={options}\n editable={false}\n >\n <div className=\"relative max-w-full overflow-x-auto\">\n <VegaChartDisplay aspectRatio={16 / 9} className=\"pt-2\">\n <VegaLiteArrowChart.Actions className=\"right-3\">\n <VegaExportAction />\n <VegaEditAction editorMode={editorMode} />\n </VegaLiteArrowChart.Actions>\n </VegaChartDisplay>\n </div>\n </VegaChartContainer>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"VegaChartToolResult.js","sourceRoot":"","sources":["../src/VegaChartToolResult.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAIhC,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AA+BxD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAU,GAAG,MAAM,EACnB,WAAW,GAAG,EAAE,GAAG,CAAC,EACpB,MAAM,EACN,SAAS,GACgB;IACzB,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,YAAY,GAAG,MAAM,EAAE,YAAwC,CAAC;IAEtE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,gCAAgC,EAAE,SAAS,CAAC,aAC5D,KAAK,EAAE,SAAS,IAAI,CACnB,YAAG,SAAS,EAAC,iCAAiC,YAAE,KAAK,CAAC,SAAS,GAAK,CACrE,EACD,KAAC,kBAAkB,IACjB,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,KAAK,YAEf,cAAK,SAAS,EAAC,qCAAqC,YAClD,KAAC,gBAAgB,IACf,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,SAAS,EAAC,MAAM,YAEhB,MAAC,kBAAkB,CAAC,OAAO,IAAC,SAAS,EAAC,SAAS,aAC7C,KAAC,gBAAgB,KAAG,EACpB,KAAC,cAAc,IAAC,UAAU,EAAE,UAAU,GAAI,IACf,GACZ,GACf,GACa,IACjB,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type {ToolRendererProps} from '@sqlrooms/ai-core';\nimport {cn} from '@sqlrooms/ui';\nimport {ReactNode} from 'react';\nimport {EmbedOptions, VisualizationSpec} from 'vega-embed';\nimport {EditorMode} from './editor/types';\nimport {VegaChartContainer} from './editor/VegaChartContainer';\nimport {VegaChartDisplay} from './editor/VegaChartDisplay';\nimport type {\n VegaChartToolOutput,\n VegaChartToolParameters,\n} from './VegaChartTool';\nimport {VegaEditAction} from './VegaEditAction';\nimport {VegaExportAction} from './VegaExportAction';\nimport {VegaLiteArrowChart} from './VegaLiteArrowChart';\nimport type {VegaChartHeight, VegaChartHeightResolver} from './chartSizing';\n\nexport type VegaChartToolResultProps = ToolRendererProps<\n VegaChartToolOutput,\n VegaChartToolParameters\n> & {\n className?: string;\n options?: EmbedOptions;\n /**\n * Which editors to show when viewing\n * @default 'both'\n */\n editorMode?: EditorMode;\n /**\n * Width-to-height ratio used when no fixed or automatic height is selected.\n * @default 16/9\n */\n aspectRatio?: number;\n /**\n * Fixed outer chart height, or `'auto'` to opt into category-aware sizing.\n * Automatic sizing falls back to the aspect ratio for ordinary charts.\n */\n height?: VegaChartHeight;\n /**\n * Optional application-specific height policy. Returning `'auto'` applies\n * the built-in category-aware sizing policy.\n */\n getHeight?: VegaChartHeightResolver;\n};\n\n/**\n * Renders a chart tool call with visualization using Vega-Lite.\n * Shows read-only editors for inspecting spec and SQL.\n */\nexport function VegaChartToolResult({\n className,\n input,\n output,\n options,\n editorMode = 'both',\n aspectRatio = 16 / 9,\n height,\n getHeight,\n}: VegaChartToolResultProps): ReactNode {\n const sqlQuery = output?.sqlQuery ?? '';\n const vegaLiteSpec = output?.vegaLiteSpec as VisualizationSpec | null;\n\n if (!vegaLiteSpec) {\n return null;\n }\n\n return (\n <div className={cn('flex max-w-full flex-col gap-2', className)}>\n {input?.reasoning && (\n <p className=\"text-tiny text-muted-foreground\">{input.reasoning}</p>\n )}\n <VegaChartContainer\n spec={vegaLiteSpec}\n sqlQuery={sqlQuery}\n options={options}\n editable={false}\n >\n <div className=\"relative max-w-full overflow-x-auto\">\n <VegaChartDisplay\n aspectRatio={aspectRatio}\n height={height}\n getHeight={getHeight}\n className=\"pt-2\"\n >\n <VegaLiteArrowChart.Actions className=\"right-3\">\n <VegaExportAction />\n <VegaEditAction editorMode={editorMode} />\n </VegaLiteArrowChart.Actions>\n </VegaChartDisplay>\n </div>\n </VegaChartContainer>\n </div>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"VegaLiteArrowChart.d.ts","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAS3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACjC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;IACpC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,OAAO,CAAC,EAAE,YAAY,GACrB,YAAY,CAed;AA0HD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEH,CAAC"}
1
+ {"version":3,"file":"VegaLiteArrowChart.d.ts","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAS3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACjC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;IACpC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,OAAO,CAAC,EAAE,YAAY,GACrB,YAAY,CAed;AA8ID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEH,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ToolErrorMessage } from '@sqlrooms/ai-core';
3
3
  import { arrowTableToJson } from '@sqlrooms/duckdb';
4
- import { AspectRatio, cn, useAspectRatioDimensions, useTheme, } from '@sqlrooms/ui';
4
+ import { cn, useAspectRatioDimensions, useTheme } from '@sqlrooms/ui';
5
5
  import { safeJsonParse } from '@sqlrooms/utils';
6
6
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
7
7
  import { useVegaEmbed } from 'react-vega';
@@ -27,7 +27,11 @@ export function makeDefaultVegaLiteOptions(options) {
27
27
  ...options,
28
28
  };
29
29
  }
30
- const VegaLiteArrowChartBase = ({ className, aspectRatio = 16 / 9, spec, arrowTable, options: propsOptions, width = 'auto', height = 'auto', children, }) => {
30
+ const VegaLiteArrowChartBase = (props) => {
31
+ const { className, spec, arrowTable, options: propsOptions, width = 'auto', height = 'auto', children, } = props;
32
+ const aspectRatio = Object.hasOwn(props, 'aspectRatio')
33
+ ? props.aspectRatio
34
+ : 16 / 9;
31
35
  const { theme } = useTheme();
32
36
  const options = useMemo(() => makeDefaultVegaLiteOptions({
33
37
  config: {
@@ -81,7 +85,7 @@ const VegaLiteArrowChartBase = ({ className, aspectRatio = 16 / 9, spec, arrowTa
81
85
  containerRef,
82
86
  width,
83
87
  height,
84
- aspectRatio,
88
+ aspectRatio: height === 'auto' || width !== 'auto' ? aspectRatio : undefined,
85
89
  });
86
90
  const changeDimensions = useCallback((width, height) => {
87
91
  embed?.view.width(width).height(height).runAsync();
@@ -89,8 +93,15 @@ const VegaLiteArrowChartBase = ({ className, aspectRatio = 16 / 9, spec, arrowTa
89
93
  useEffect(() => {
90
94
  changeDimensions(dimensions.width, dimensions.height);
91
95
  }, [changeDimensions, dimensions.width, dimensions.height]);
92
- return (_jsx(VegaChartContextProvider, { value: { embed }, children: _jsxs("div", { ref: containerRef, className: cn('relative flex h-full w-full flex-col gap-2', className), children: [_jsx("div", { className: "peer relative", children: displayError ? (_jsx(ToolErrorMessage, { error: displayError, triggerLabel: "Chart rendering failed", title: "Chart error", align: "start", details: spec })) : (specWithData &&
93
- data && (_jsx(AspectRatio, { ratio: aspectRatio, className: "overflow-visible", asChild: true, children: _jsx("div", { ref: ref, className: "[&_svg]:overflow-visible" }) }))) }), children] }) }));
96
+ return (_jsx(VegaChartContextProvider, { value: { embed }, children: _jsxs("div", { className: cn('relative flex w-full flex-col gap-2', className), children: [_jsx("div", { className: cn('peer relative', height === 'auto' && aspectRatio === undefined && 'h-full'), children: displayError ? (_jsx(ToolErrorMessage, { error: displayError, triggerLabel: "Chart rendering failed", title: "Chart error", align: "start", details: spec })) : (specWithData &&
97
+ data && (_jsx("div", { ref: containerRef, style: {
98
+ ...(height === 'auto' && aspectRatio !== undefined
99
+ ? { aspectRatio }
100
+ : height !== 'auto'
101
+ ? { height }
102
+ : {}),
103
+ ...(width !== 'auto' ? { width } : {}),
104
+ }, className: cn('overflow-visible', width === 'auto' && 'w-full', height === 'auto' && aspectRatio === undefined && 'h-full'), children: _jsx("div", { ref: ref, className: "h-full w-full [&_svg]:overflow-visible" }) }))) }), children] }) }));
94
105
  };
95
106
  /**
96
107
  * Composable Vega-Lite chart component with support for custom actions.
@@ -1 +1 @@
1
- {"version":3,"file":"VegaLiteArrowChart.js","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,WAAW,EACX,EAAE,EACF,wBAAwB,EACxB,QAAQ,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACxE,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAGxC,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAC,UAAU,EAAC,MA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f,CACF,GACG,EACL,QAAQ,IACL,GACmB,CAC5B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE;IACtE;;OAEG;IACH,OAAO,EAAE,gBAAgB;IACzB;;OAEG;IACH,YAAY,EAAE,gBAAgB;IAC9B;;OAEG;IACH,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai-core';\nimport {arrowTableToJson} from '@sqlrooms/duckdb';\nimport {\n AspectRatio,\n cn,\n useAspectRatioDimensions,\n useTheme,\n} from '@sqlrooms/ui';\nimport {safeJsonParse} from '@sqlrooms/utils';\nimport * as arrow from 'apache-arrow';\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport {useVegaEmbed} from 'react-vega';\nimport {EmbedOptions, VisualizationSpec} from 'vega-embed';\nimport {Config} from 'vega-lite';\nimport {darkTheme} from './themes/darkTheme';\nimport {lightTheme} from './themes/lightTheme';\nimport {VegaChartActions} from './VegaChartActions';\nimport {VegaChartContextProvider} from './VegaChartContext';\nimport {VegaEditAction} from './VegaEditAction';\nimport {VegaExportAction} from './VegaExportAction';\n\nexport type VegaLiteArrowChartProps = {\n className?: string;\n width?: number | 'auto';\n height?: number | 'auto';\n aspectRatio?: number;\n spec: string | VisualizationSpec;\n options?: EmbedOptions;\n arrowTable: arrow.Table | undefined;\n /**\n * Children for composing actions and other elements.\n * Use VegaLiteArrowChart.Actions to add action buttons.\n *\n * @example\n * ```tsx\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\n children?: React.ReactNode;\n};\n\nexport function makeDefaultVegaLiteOptions(\n options?: EmbedOptions,\n): EmbedOptions {\n return {\n mode: 'vega-lite',\n renderer: 'svg',\n theme: undefined,\n tooltip: true,\n actions: false,\n padding: {\n top: 20,\n right: 10,\n bottom: 10,\n left: 10,\n },\n ...options,\n };\n}\n\nconst VegaLiteArrowChartBase: React.FC<VegaLiteArrowChartProps> = ({\n className,\n aspectRatio = 16 / 9,\n spec,\n arrowTable,\n options: propsOptions,\n width = 'auto',\n height = 'auto',\n children,\n}) => {\n const {theme} = useTheme();\n\n const options = useMemo(\n () =>\n makeDefaultVegaLiteOptions({\n config: {\n ...(theme === 'dark' ? darkTheme : lightTheme),\n ...(typeof propsOptions?.config === 'object'\n ? (propsOptions.config as Config)\n : {}),\n },\n\n ...propsOptions,\n }),\n [theme, propsOptions],\n );\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [chartError, setChartError] = useState<Error | null>(null);\n\n const data = useMemo(() => {\n if (!arrowTable) return null;\n return {values: arrowTableToJson(arrowTable)};\n }, [arrowTable]);\n\n const specWithData = useMemo(() => {\n const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;\n if (!parsed) {\n return null;\n }\n return {\n padding: 10,\n background: 'transparent',\n ...parsed,\n data: data,\n // Override the following props to ensure the chart is responsive\n width: 'container',\n height: 'container',\n autosize: {contains: 'padding'},\n } as VisualizationSpec;\n }, [spec, data]);\n const specError = specWithData\n ? null\n : new Error('Invalid Vega-Lite specification');\n const displayError = specError ?? chartError;\n\n // Reset chart error whenever spec or data changes\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setChartError(null);\n }, [spec, data]);\n\n const ref = useRef<HTMLDivElement>(null);\n const embed = useVegaEmbed({\n ref,\n spec: specWithData ?? '',\n onError: () => setChartError,\n options,\n });\n\n const dimensions = useAspectRatioDimensions({\n containerRef,\n width,\n height,\n aspectRatio,\n });\n const changeDimensions = useCallback(\n (width: number, height: number) => {\n embed?.view.width(width).height(height).runAsync();\n },\n [embed],\n );\n useEffect(() => {\n changeDimensions(dimensions.width, dimensions.height);\n }, [changeDimensions, dimensions.width, dimensions.height]);\n\n return (\n <VegaChartContextProvider value={{embed}}>\n <div\n ref={containerRef}\n className={cn('relative flex h-full w-full flex-col gap-2', className)}\n >\n <div className=\"peer relative\">\n {displayError ? (\n <ToolErrorMessage\n error={displayError}\n triggerLabel=\"Chart rendering failed\"\n title=\"Chart error\"\n align=\"start\"\n details={spec}\n />\n ) : (\n specWithData &&\n data && (\n <AspectRatio\n ratio={aspectRatio}\n className=\"overflow-visible\"\n asChild\n >\n <div ref={ref} className=\"[&_svg]:overflow-visible\" />\n </AspectRatio>\n )\n )}\n </div>\n {children}\n </div>\n </VegaChartContextProvider>\n );\n};\n\n/**\n * Composable Vega-Lite chart component with support for custom actions.\n *\n * @example\n * ```tsx\n * // Basic usage without actions (backwards compatible)\n * <VegaLiteArrowChart spec={spec} arrowTable={data} />\n *\n * // With export action\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n *\n * // Custom actions with separator\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction pngScale={3} />\n * <Separator orientation=\"vertical\" className=\"h-4\" />\n * <Button size=\"xs\" variant=\"ghost\" onClick={handleRefresh}>\n * <RefreshCw className=\"h-4 w-4\" />\n * </Button>\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\nexport const VegaLiteArrowChart = Object.assign(VegaLiteArrowChartBase, {\n /**\n * Container for action buttons, positioned as an overlay\n */\n Actions: VegaChartActions,\n /**\n * Built-in export action with PNG/SVG download\n */\n ExportAction: VegaExportAction,\n /**\n * Built-in edit action with spec/SQL editor popover\n */\n EditAction: VegaEditAction,\n});\n"]}
1
+ {"version":3,"file":"VegaLiteArrowChart.js","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAC,MA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;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE;IACtE;;OAEG;IACH,OAAO,EAAE,gBAAgB;IACzB;;OAEG;IACH,YAAY,EAAE,gBAAgB;IAC9B;;OAEG;IACH,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai-core';\nimport {arrowTableToJson} from '@sqlrooms/duckdb';\nimport {cn, useAspectRatioDimensions, useTheme} from '@sqlrooms/ui';\nimport {safeJsonParse} from '@sqlrooms/utils';\nimport * as arrow from 'apache-arrow';\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport {useVegaEmbed} from 'react-vega';\nimport {EmbedOptions, VisualizationSpec} from 'vega-embed';\nimport {Config} from 'vega-lite';\nimport {darkTheme} from './themes/darkTheme';\nimport {lightTheme} from './themes/lightTheme';\nimport {VegaChartActions} from './VegaChartActions';\nimport {VegaChartContextProvider} from './VegaChartContext';\nimport {VegaEditAction} from './VegaEditAction';\nimport {VegaExportAction} from './VegaExportAction';\n\nexport type VegaLiteArrowChartProps = {\n className?: string;\n width?: number | 'auto';\n height?: number | 'auto';\n aspectRatio?: number;\n spec: string | VisualizationSpec;\n options?: EmbedOptions;\n arrowTable: arrow.Table | undefined;\n /**\n * Children for composing actions and other elements.\n * Use VegaLiteArrowChart.Actions to add action buttons.\n *\n * @example\n * ```tsx\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\n children?: React.ReactNode;\n};\n\nexport function makeDefaultVegaLiteOptions(\n options?: EmbedOptions,\n): EmbedOptions {\n return {\n mode: 'vega-lite',\n renderer: 'svg',\n theme: undefined,\n tooltip: true,\n actions: false,\n padding: {\n top: 20,\n right: 10,\n bottom: 10,\n left: 10,\n },\n ...options,\n };\n}\n\nconst VegaLiteArrowChartBase: React.FC<VegaLiteArrowChartProps> = (props) => {\n const {\n className,\n spec,\n arrowTable,\n options: propsOptions,\n width = 'auto',\n height = 'auto',\n children,\n } = props;\n const aspectRatio = Object.hasOwn(props, 'aspectRatio')\n ? props.aspectRatio\n : 16 / 9;\n const {theme} = useTheme();\n\n const options = useMemo(\n () =>\n makeDefaultVegaLiteOptions({\n config: {\n ...(theme === 'dark' ? darkTheme : lightTheme),\n ...(typeof propsOptions?.config === 'object'\n ? (propsOptions.config as Config)\n : {}),\n },\n\n ...propsOptions,\n }),\n [theme, propsOptions],\n );\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [chartError, setChartError] = useState<Error | null>(null);\n\n const data = useMemo(() => {\n if (!arrowTable) return null;\n return {values: arrowTableToJson(arrowTable)};\n }, [arrowTable]);\n\n const specWithData = useMemo(() => {\n const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;\n if (!parsed) {\n return null;\n }\n return {\n padding: 10,\n background: 'transparent',\n ...parsed,\n data: data,\n // Override the following props to ensure the chart is responsive\n width: 'container',\n height: 'container',\n autosize: {contains: 'padding'},\n } as VisualizationSpec;\n }, [spec, data]);\n const specError = specWithData\n ? null\n : new Error('Invalid Vega-Lite specification');\n const displayError = specError ?? chartError;\n\n // Reset chart error whenever spec or data changes\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setChartError(null);\n }, [spec, data]);\n\n const ref = useRef<HTMLDivElement>(null);\n const embed = useVegaEmbed({\n ref,\n spec: specWithData ?? '',\n onError: () => setChartError,\n options,\n });\n\n const dimensions = useAspectRatioDimensions({\n containerRef,\n width,\n height,\n aspectRatio:\n height === 'auto' || width !== 'auto' ? aspectRatio : undefined,\n });\n const changeDimensions = useCallback(\n (width: number, height: number) => {\n embed?.view.width(width).height(height).runAsync();\n },\n [embed],\n );\n useEffect(() => {\n changeDimensions(dimensions.width, dimensions.height);\n }, [changeDimensions, dimensions.width, dimensions.height]);\n\n return (\n <VegaChartContextProvider value={{embed}}>\n <div className={cn('relative flex w-full flex-col gap-2', className)}>\n <div\n className={cn(\n 'peer relative',\n height === 'auto' && aspectRatio === undefined && 'h-full',\n )}\n >\n {displayError ? (\n <ToolErrorMessage\n error={displayError}\n triggerLabel=\"Chart rendering failed\"\n title=\"Chart error\"\n align=\"start\"\n details={spec}\n />\n ) : (\n specWithData &&\n data && (\n <div\n ref={containerRef}\n style={{\n ...(height === 'auto' && aspectRatio !== undefined\n ? {aspectRatio}\n : height !== 'auto'\n ? {height}\n : {}),\n ...(width !== 'auto' ? {width} : {}),\n }}\n className={cn(\n 'overflow-visible',\n width === 'auto' && 'w-full',\n height === 'auto' && aspectRatio === undefined && 'h-full',\n )}\n >\n <div\n ref={ref}\n className=\"h-full w-full [&_svg]:overflow-visible\"\n />\n </div>\n )\n )}\n </div>\n {children}\n </div>\n </VegaChartContextProvider>\n );\n};\n\n/**\n * Composable Vega-Lite chart component with support for custom actions.\n *\n * @example\n * ```tsx\n * // Basic usage without actions (backwards compatible)\n * <VegaLiteArrowChart spec={spec} arrowTable={data} />\n *\n * // With export action\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n *\n * // Custom actions with separator\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction pngScale={3} />\n * <Separator orientation=\"vertical\" className=\"h-4\" />\n * <Button size=\"xs\" variant=\"ghost\" onClick={handleRefresh}>\n * <RefreshCw className=\"h-4 w-4\" />\n * </Button>\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\nexport const VegaLiteArrowChart = Object.assign(VegaLiteArrowChartBase, {\n /**\n * Container for action buttons, positioned as an overlay\n */\n Actions: VegaChartActions,\n /**\n * Built-in export action with PNG/SVG download\n */\n ExportAction: VegaExportAction,\n /**\n * Built-in edit action with spec/SQL editor popover\n */\n EditAction: VegaEditAction,\n});\n"]}
@@ -0,0 +1,20 @@
1
+ import type * as arrow from 'apache-arrow';
2
+ import type { VisualizationSpec } from 'vega-embed';
3
+ /** Height behavior for a Vega chart result. */
4
+ export type VegaChartHeight = number | 'auto';
5
+ /** Data available when resolving the height of a rendered Vega chart. */
6
+ export interface VegaChartSizingContext {
7
+ /** The parsed, responsive Vega-Lite specification. */
8
+ spec: VisualizationSpec;
9
+ /** The data loaded for the chart, when available. */
10
+ arrowTable: arrow.Table | undefined;
11
+ }
12
+ /** Resolves a chart height from its parsed specification and loaded data. */
13
+ export type VegaChartHeightResolver = (context: VegaChartSizingContext) => VegaChartHeight;
14
+ /**
15
+ * Computes a taller height for category-dense horizontal bar charts.
16
+ *
17
+ * Returns `'auto'` for other chart shapes so they retain aspect-ratio sizing.
18
+ */
19
+ export declare function getCategoryAwareVegaChartHeight({ spec, arrowTable, }: VegaChartSizingContext): VegaChartHeight;
20
+ //# sourceMappingURL=chartSizing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartSizing.d.ts","sourceRoot":"","sources":["../src/chartSizing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAElD,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9C,yEAAyE;AACzE,MAAM,WAAW,sBAAsB;IACrC,sDAAsD;IACtD,IAAI,EAAE,iBAAiB,CAAC;IACxB,qDAAqD;IACrD,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;CACrC;AAED,6EAA6E;AAC7E,MAAM,MAAM,uBAAuB,GAAG,CACpC,OAAO,EAAE,sBAAsB,KAC5B,eAAe,CAAC;AA8GrB;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,EAC9C,IAAI,EACJ,UAAU,GACX,EAAE,sBAAsB,GAAG,eAAe,CAmB1C"}
@@ -0,0 +1,103 @@
1
+ const MIN_CATEGORY_COUNT = 12;
2
+ const MIN_AUTO_HEIGHT = 280;
3
+ const MAX_AUTO_HEIGHT = 800;
4
+ const CHART_VERTICAL_PADDING = 48;
5
+ const CATEGORY_ROW_HEIGHT = 22;
6
+ const MAX_MEANINGFUL_CATEGORY_COUNT = Math.ceil((MAX_AUTO_HEIGHT - CHART_VERTICAL_PADDING) / CATEGORY_ROW_HEIGHT);
7
+ /** Returns a JSON object value while excluding arrays and primitives. */
8
+ function asObject(value) {
9
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
10
+ ? value
11
+ : undefined;
12
+ }
13
+ /** Extracts the Vega-Lite mark type from string and object mark definitions. */
14
+ function getMarkType(spec) {
15
+ if (typeof spec.mark === 'string') {
16
+ return spec.mark;
17
+ }
18
+ return asObject(spec.mark)?.type;
19
+ }
20
+ /** Checks for data/layout semantics that raw-table sizing cannot reproduce. */
21
+ function hasUnsupportedAutoSizingStructure(spec) {
22
+ if (Array.isArray(spec.transform) && spec.transform.length > 0) {
23
+ return true;
24
+ }
25
+ for (const key of ['concat', 'hconcat', 'vconcat']) {
26
+ if (Array.isArray(spec[key]))
27
+ return true;
28
+ }
29
+ const layers = spec.layer;
30
+ if (Array.isArray(layers) &&
31
+ layers.some((layer) => hasUnsupportedAutoSizingStructure(asObject(layer) ?? {}))) {
32
+ return true;
33
+ }
34
+ const nestedSpec = asObject(spec.spec);
35
+ return nestedSpec ? hasUnsupportedAutoSizingStructure(nestedSpec) : false;
36
+ }
37
+ /** Finds the discrete y field of a horizontal bar unit in a nested spec. */
38
+ function getHorizontalBarCategoryField(spec, inheritedEncoding = {}) {
39
+ const encoding = { ...inheritedEncoding, ...asObject(spec.encoding) };
40
+ const x = asObject(encoding.x);
41
+ const y = asObject(encoding.y);
42
+ const isAggregate = typeof x?.aggregate === 'string';
43
+ const isQuantitativeX = x?.type === 'quantitative' || isAggregate;
44
+ const isDiscreteY = y?.type === 'nominal' ||
45
+ y?.type === 'ordinal' ||
46
+ (isAggregate && y?.type === undefined);
47
+ if (getMarkType(spec) === 'bar' &&
48
+ isQuantitativeX &&
49
+ isDiscreteY &&
50
+ typeof y?.field === 'string') {
51
+ return y.field;
52
+ }
53
+ for (const key of ['layer', 'concat', 'hconcat', 'vconcat']) {
54
+ const children = spec[key];
55
+ if (!Array.isArray(children))
56
+ continue;
57
+ for (const child of children) {
58
+ const field = getHorizontalBarCategoryField(asObject(child) ?? {}, encoding);
59
+ if (field)
60
+ return field;
61
+ }
62
+ }
63
+ const nestedSpec = asObject(spec.spec);
64
+ return nestedSpec
65
+ ? getHorizontalBarCategoryField(nestedSpec, encoding)
66
+ : undefined;
67
+ }
68
+ /** Counts distinct non-null field values up to the height saturation point. */
69
+ function countDistinctValues(table, field) {
70
+ const vector = table.getChild(field);
71
+ if (!vector)
72
+ return 0;
73
+ const values = new Set();
74
+ for (let index = 0; index < table.numRows; index += 1) {
75
+ const value = vector.get(index);
76
+ if (value !== null && value !== undefined) {
77
+ values.add(`${typeof value}:${String(value)}`);
78
+ if (values.size >= MAX_MEANINGFUL_CATEGORY_COUNT)
79
+ break;
80
+ }
81
+ }
82
+ return values.size;
83
+ }
84
+ /**
85
+ * Computes a taller height for category-dense horizontal bar charts.
86
+ *
87
+ * Returns `'auto'` for other chart shapes so they retain aspect-ratio sizing.
88
+ */
89
+ export function getCategoryAwareVegaChartHeight({ spec, arrowTable, }) {
90
+ if (!arrowTable)
91
+ return 'auto';
92
+ const specObject = asObject(spec) ?? {};
93
+ if (hasUnsupportedAutoSizingStructure(specObject))
94
+ return 'auto';
95
+ const categoryField = getHorizontalBarCategoryField(specObject);
96
+ if (!categoryField)
97
+ return 'auto';
98
+ const categoryCount = countDistinctValues(arrowTable, categoryField);
99
+ if (categoryCount < MIN_CATEGORY_COUNT)
100
+ return 'auto';
101
+ return Math.min(MAX_AUTO_HEIGHT, Math.max(MIN_AUTO_HEIGHT, CHART_VERTICAL_PADDING + categoryCount * CATEGORY_ROW_HEIGHT));
102
+ }
103
+ //# sourceMappingURL=chartSizing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartSizing.js","sourceRoot":"","sources":["../src/chartSizing.ts"],"names":[],"mappings":"AAmBA,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,6BAA6B,GAAG,IAAI,CAAC,IAAI,CAC7C,CAAC,eAAe,GAAG,sBAAsB,CAAC,GAAG,mBAAmB,CACjE,CAAC;AAIF,yEAAyE;AACzE,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAoB;QACvB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,gFAAgF;AAChF,SAAS,WAAW,CAAC,IAAgB;IACnC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAA0B,CAAC;AACzD,CAAC;AAED,+EAA+E;AAC/E,SAAS,iCAAiC,CAAC,IAAgB;IACzD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAU,EAAE,CAAC;QAC5D,IAAI,K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,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/C,IAAI,MAAM,CAAC,IAAI,IAAI,6BAA6B;gBAAE,MAAM;QAC1D,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,EAC9C,IAAI,EACJ,UAAU,GACa;IACvB,IAAI,CAAC,UAAU;QAAE,OAAO,MAAM,CAAC;IAE/B,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACxC,IAAI,iCAAiC,CAAC,UAAU,CAAC;QAAE,OAAO,MAAM,CAAC;IAEjE,MAAM,aAAa,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAChE,IAAI,CAAC,aAAa;QAAE,OAAO,MAAM,CAAC;IAElC,MAAM,aAAa,GAAG,mBAAmB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACrE,IAAI,aAAa,GAAG,kBAAkB;QAAE,OAAO,MAAM,CAAC;IAEtD,OAAO,IAAI,CAAC,GAAG,CACb,eAAe,EACf,IAAI,CAAC,GAAG,CACN,eAAe,EACf,sBAAsB,GAAG,aAAa,GAAG,mBAAmB,CAC7D,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type * as arrow from 'apache-arrow';\nimport type {VisualizationSpec} from 'vega-embed';\n\n/** Height behavior for a Vega chart result. */\nexport type VegaChartHeight = number | 'auto';\n\n/** Data available when resolving the height of a rendered Vega chart. */\nexport interface VegaChartSizingContext {\n /** The parsed, responsive Vega-Lite specification. */\n spec: VisualizationSpec;\n /** The data loaded for the chart, when available. */\n arrowTable: arrow.Table | undefined;\n}\n\n/** Resolves a chart height from its parsed specification and loaded data. */\nexport type VegaChartHeightResolver = (\n context: VegaChartSizingContext,\n) => VegaChartHeight;\n\nconst MIN_CATEGORY_COUNT = 12;\nconst MIN_AUTO_HEIGHT = 280;\nconst MAX_AUTO_HEIGHT = 800;\nconst CHART_VERTICAL_PADDING = 48;\nconst CATEGORY_ROW_HEIGHT = 22;\nconst MAX_MEANINGFUL_CATEGORY_COUNT = Math.ceil(\n (MAX_AUTO_HEIGHT - CHART_VERTICAL_PADDING) / CATEGORY_ROW_HEIGHT,\n);\n\ntype JsonObject = Record<string, unknown>;\n\n/** Returns a JSON object value while excluding arrays and primitives. */\nfunction asObject(value: unknown): JsonObject | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? (value as JsonObject)\n : undefined;\n}\n\n/** Extracts the Vega-Lite mark type from string and object mark definitions. */\nfunction getMarkType(spec: JsonObject): string | undefined {\n if (typeof spec.mark === 'string') {\n return spec.mark;\n }\n return asObject(spec.mark)?.type as string | undefined;\n}\n\n/** Checks for data/layout semantics that raw-table sizing cannot reproduce. */\nfunction hasUnsupportedAutoSizingStructure(spec: JsonObject): boolean {\n if (Array.isArray(spec.transform) && spec.transform.length > 0) {\n return true;\n }\n\n for (const key of ['concat', 'hconcat', 'vconcat'] as const) {\n if (Array.isArray(spec[key])) return true;\n }\n\n const layers = spec.layer;\n if (\n Array.isArray(layers) &&\n layers.some((layer) =>\n hasUnsupportedAutoSizingStructure(asObject(layer) ?? {}),\n )\n ) {\n return true;\n }\n\n const nestedSpec = asObject(spec.spec);\n return nestedSpec ? hasUnsupportedAutoSizingStructure(nestedSpec) : false;\n}\n\n/** Finds the discrete y field of a horizontal bar unit in a nested spec. */\nfunction getHorizontalBarCategoryField(\n spec: JsonObject,\n inheritedEncoding: JsonObject = {},\n): string | undefined {\n const encoding = {...inheritedEncoding, ...asObject(spec.encoding)};\n const x = asObject(encoding.x);\n const y = asObject(encoding.y);\n const isAggregate = typeof x?.aggregate === 'string';\n const isQuantitativeX = x?.type === 'quantitative' || isAggregate;\n const isDiscreteY =\n y?.type === 'nominal' ||\n y?.type === 'ordinal' ||\n (isAggregate && y?.type === undefined);\n\n if (\n getMarkType(spec) === 'bar' &&\n isQuantitativeX &&\n isDiscreteY &&\n typeof y?.field === 'string'\n ) {\n return y.field;\n }\n\n for (const key of ['layer', 'concat', 'hconcat', 'vconcat'] as const) {\n const children = spec[key];\n if (!Array.isArray(children)) continue;\n for (const child of children) {\n const field = getHorizontalBarCategoryField(\n asObject(child) ?? {},\n encoding,\n );\n if (field) return field;\n }\n }\n\n const nestedSpec = asObject(spec.spec);\n return nestedSpec\n ? getHorizontalBarCategoryField(nestedSpec, encoding)\n : undefined;\n}\n\n/** Counts distinct non-null field values up to the height saturation point. */\nfunction countDistinctValues(table: arrow.Table, field: string): number {\n const vector = table.getChild(field);\n if (!vector) return 0;\n\n const values = new Set<string>();\n for (let index = 0; index < table.numRows; index += 1) {\n const value = vector.get(index);\n if (value !== null && value !== undefined) {\n values.add(`${typeof value}:${String(value)}`);\n if (values.size >= MAX_MEANINGFUL_CATEGORY_COUNT) break;\n }\n }\n return values.size;\n}\n\n/**\n * Computes a taller height for category-dense horizontal bar charts.\n *\n * Returns `'auto'` for other chart shapes so they retain aspect-ratio sizing.\n */\nexport function getCategoryAwareVegaChartHeight({\n spec,\n arrowTable,\n}: VegaChartSizingContext): VegaChartHeight {\n if (!arrowTable) return 'auto';\n\n const specObject = asObject(spec) ?? {};\n if (hasUnsupportedAutoSizingStructure(specObject)) return 'auto';\n\n const categoryField = getHorizontalBarCategoryField(specObject);\n if (!categoryField) return 'auto';\n\n const categoryCount = countDistinctValues(arrowTable, categoryField);\n if (categoryCount < MIN_CATEGORY_COUNT) return 'auto';\n\n return Math.min(\n MAX_AUTO_HEIGHT,\n Math.max(\n MIN_AUTO_HEIGHT,\n CHART_VERTICAL_PADDING + categoryCount * CATEGORY_ROW_HEIGHT,\n ),\n );\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { VegaChartHeight, VegaChartHeightResolver } from '../chartSizing';
2
3
  export interface VegaChartDisplayProps {
3
4
  /**
4
5
  * Custom class name for the chart container
@@ -9,6 +10,14 @@ export interface VegaChartDisplayProps {
9
10
  * @default 16/9
10
11
  */
11
12
  aspectRatio?: number;
13
+ /**
14
+ * Fixed outer chart height, or `'auto'` for category-aware sizing.
15
+ */
16
+ height?: VegaChartHeight;
17
+ /**
18
+ * Optional height policy evaluated with the parsed spec and loaded data.
19
+ */
20
+ getHeight?: VegaChartHeightResolver;
12
21
  /**
13
22
  * Children passed through to VegaLiteArrowChart (e.g., action components)
14
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"VegaChartDisplay.d.ts","sourceRoot":"","sources":["../../src/editor/VegaChartDisplay.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAkE5D,CAAC"}
1
+ {"version":3,"file":"VegaChartDisplay.d.ts","sourceRoot":"","sources":["../../src/editor/VegaChartDisplay.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAC,eAAe,EAAE,uBAAuB,EAAC,MAAM,gBAAgB,CAAC;AAG7E,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,uBAAuB,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA6E5D,CAAC"}
@@ -2,7 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ToolErrorMessage } from '@sqlrooms/ai-core';
3
3
  import { useSql } from '@sqlrooms/duckdb';
4
4
  import { cn } from '@sqlrooms/ui';
5
+ import React from 'react';
5
6
  import { VegaLiteArrowChart } from '../VegaLiteArrowChart';
7
+ import { getCategoryAwareVegaChartHeight } from '../chartSizing';
6
8
  import { useVegaEditorContext } from './VegaEditorContext';
7
9
  /**
8
10
  * Chart display subcomponent for VegaLiteChart.Container.
@@ -19,7 +21,7 @@ import { useVegaEditorContext } from './VegaEditorContext';
19
21
  * </VegaLiteChart.Container>
20
22
  * ```
21
23
  */
22
- export const VegaChartDisplay = ({ className, aspectRatio = 16 / 9, children, }) => {
24
+ export const VegaChartDisplay = ({ className, aspectRatio = 16 / 9, height, getHeight, children, }) => {
23
25
  const { state, arrowTable, options } = useVegaEditorContext();
24
26
  // Use the applied SQL for chart rendering (updates when Apply is clicked)
25
27
  const sqlQuery = state.appliedSql;
@@ -33,6 +35,13 @@ export const VegaChartDisplay = ({ className, aspectRatio = 16 / 9, children, })
33
35
  // Use parsed spec for live preview, fall back to last valid spec if parse failed
34
36
  // This ensures the chart keeps rendering during typing even with invalid JSON
35
37
  const spec = state.parsedSpec ?? state.lastValidSpec;
38
+ const resolvedHeight = React.useMemo(() => {
39
+ const context = { spec, arrowTable: chartData };
40
+ const requestedHeight = getHeight?.(context) ?? height;
41
+ return requestedHeight === 'auto'
42
+ ? getCategoryAwareVegaChartHeight(context)
43
+ : requestedHeight;
44
+ }, [chartData, getHeight, height, spec]);
36
45
  // Show loading state
37
46
  if (sqlQuery && !arrowTable && sqlResult.isLoading) {
38
47
  return (_jsxs("div", { className: cn('text-muted-foreground flex items-center justify-center', className), children: [_jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600" }), _jsx("span", { className: "ml-2 text-sm", children: "Loading data..." })] }));
@@ -41,6 +50,6 @@ export const VegaChartDisplay = ({ className, aspectRatio = 16 / 9, children, })
41
50
  if (sqlQuery && !arrowTable && sqlResult.error) {
42
51
  return (_jsx("div", { className: className, children: _jsx(ToolErrorMessage, { error: sqlResult.error, triggerLabel: "SQL query failed", title: "Query error", align: "start", details: sqlQuery }) }));
43
52
  }
44
- return (_jsx("div", { className: cn('relative', className), children: _jsx(VegaLiteArrowChart, { className: "w-full", spec: spec, arrowTable: chartData, aspectRatio: aspectRatio, options: options, children: children }) }));
53
+ return (_jsx("div", { className: cn('relative', className), children: _jsx(VegaLiteArrowChart, { className: "w-full", spec: spec, arrowTable: chartData, aspectRatio: aspectRatio, height: resolvedHeight, options: options, children: children }) }));
45
54
  };
46
55
  //# sourceMappingURL=VegaChartDisplay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaChartDisplay.js","sourceRoot":"","sources":["../../src/editor/VegaChartDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAEhC,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAkBzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAChE,SAAS,EACT,WAAW,GAAG,EAAE,GAAG,CAAC,EACpB,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,EAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAE5D,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC;IAElC,gDAAgD;IAChD,MAAM,SAAS,GAAG,MAAM,CAAC;QACvB,KAAK,EAAE,QAAQ,IAAI,EAAE;QACrB,OAAO,EAAE,CAAC,CAAC,QAAQ,IAAI,CAAC,UAAU;KACnC,CAAC,CAAC;IAEH,wDAAwD;IACxD,MAAM,SAAS,GAAG,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC;IAE3D,iFAAiF;IACjF,8EAA8E;IAC9E,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,aAAa,CAAC;IAErD,qBAAqB;IACrB,IAAI,QAAQ,IAAI,CAAC,UAAU,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;QACnD,OAAO,CACL,eACE,SAAS,EAAE,EAAE,CACX,wDAAwD,EACxD,SAAS,CACV,aAED,cAAK,SAAS,EAAC,8EAA8E,GAAG,EAChG,eAAM,SAAS,EAAC,cAAc,gCAAuB,IACjD,CACP,CAAC;IACJ,CAAC;IAED,mBAAmB;IACnB,IAAI,QAAQ,IAAI,CAAC,UAAU,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;QAC/C,OAAO,CACL,cAAK,SAAS,EAAE,SAAS,YACvB,KAAC,gBAAgB,IACf,KAAK,EAAE,SAAS,CAAC,KAAK,EACtB,YAAY,EAAC,kBAAkB,EAC/B,KAAK,EAAC,aAAa,EACnB,KAAK,EAAC,OAAO,EACb,OAAO,EAAE,QAAQ,GACjB,GACE,CACP,CAAC;IACJ,CAAC;IAED,OAAO,CACL,cAAK,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,YACvC,KAAC,kBAAkB,IACjB,SAAS,EAAC,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,SAAS,EACrB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,YAEf,QAAQ,GACU,GACjB,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai-core';\nimport {useSql} from '@sqlrooms/duckdb';\nimport {cn} from '@sqlrooms/ui';\nimport React from 'react';\nimport {VegaLiteArrowChart} from '../VegaLiteArrowChart';\nimport {useVegaEditorContext} from './VegaEditorContext';\n\nexport interface VegaChartDisplayProps {\n /**\n * Custom class name for the chart container\n */\n className?: string;\n /**\n * Aspect ratio for the chart\n * @default 16/9\n */\n aspectRatio?: number;\n /**\n * Children passed through to VegaLiteArrowChart (e.g., action components)\n */\n children?: React.ReactNode;\n}\n\n/**\n * Chart display subcomponent for VegaLiteChart.Container.\n * Renders the Vega-Lite chart with data from SQL query or arrow table.\n *\n * Uses the parsed spec from the editor state for live preview during editing.\n *\n * Must be used within a VegaLiteChart.Container component.\n *\n * @example\n * ```tsx\n * <VegaLiteChart.Container spec={spec} sqlQuery={query}>\n * <VegaLiteChart.Chart />\n * </VegaLiteChart.Container>\n * ```\n */\nexport const VegaChartDisplay: React.FC<VegaChartDisplayProps> = ({\n className,\n aspectRatio = 16 / 9,\n children,\n}) => {\n const {state, arrowTable, options} = useVegaEditorContext();\n\n // Use the applied SQL for chart rendering (updates when Apply is clicked)\n const sqlQuery = state.appliedSql;\n\n // Fetch data from SQL if no arrowTable provided\n const sqlResult = useSql({\n query: sqlQuery || '',\n enabled: !!sqlQuery && !arrowTable,\n });\n\n // Use arrow table if provided, otherwise use SQL result\n const chartData = arrowTable ?? sqlResult.data?.arrowTable;\n\n // Use parsed spec for live preview, fall back to last valid spec if parse failed\n // This ensures the chart keeps rendering during typing even with invalid JSON\n const spec = state.parsedSpec ?? state.lastValidSpec;\n\n // Show loading state\n if (sqlQuery && !arrowTable && sqlResult.isLoading) {\n return (\n <div\n className={cn(\n 'text-muted-foreground flex items-center justify-center',\n className,\n )}\n >\n <div className=\"h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600\" />\n <span className=\"ml-2 text-sm\">Loading data...</span>\n </div>\n );\n }\n\n // Show error state\n if (sqlQuery && !arrowTable && sqlResult.error) {\n return (\n <div className={className}>\n <ToolErrorMessage\n error={sqlResult.error}\n triggerLabel=\"SQL query failed\"\n title=\"Query error\"\n align=\"start\"\n details={sqlQuery}\n />\n </div>\n );\n }\n\n return (\n <div className={cn('relative', className)}>\n <VegaLiteArrowChart\n className=\"w-full\"\n spec={spec}\n arrowTable={chartData}\n aspectRatio={aspectRatio}\n options={options}\n >\n {children}\n </VegaLiteArrowChart>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"VegaChartDisplay.js","sourceRoot":"","sources":["../../src/editor/VegaChartDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,+BAA+B,EAAC,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AA0BzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAChE,SAAS,EACT,WAAW,GAAG,EAAE,GAAG,CAAC,EACpB,MAAM,EACN,SAAS,EACT,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,EAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAE5D,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC;IAElC,gDAAgD;IAChD,MAAM,SAAS,GAAG,MAAM,CAAC;QACvB,KAAK,EAAE,QAAQ,IAAI,EAAE;QACrB,OAAO,EAAE,CAAC,CAAC,QAAQ,IAAI,CAAC,UAAU;KACnC,CAAC,CAAC;IAEH,wDAAwD;IACxD,MAAM,SAAS,GAAG,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC;IAE3D,iFAAiF;IACjF,8EAA8E;IAC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W,EACxB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,OAAO,YAEf,QAAQ,GACU,GACjB,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai-core';\nimport {useSql} from '@sqlrooms/duckdb';\nimport {cn} from '@sqlrooms/ui';\nimport React from 'react';\nimport {VegaLiteArrowChart} from '../VegaLiteArrowChart';\nimport {getCategoryAwareVegaChartHeight} from '../chartSizing';\nimport type {VegaChartHeight, VegaChartHeightResolver} from '../chartSizing';\nimport {useVegaEditorContext} from './VegaEditorContext';\n\nexport interface VegaChartDisplayProps {\n /**\n * Custom class name for the chart container\n */\n className?: string;\n /**\n * Aspect ratio for the chart\n * @default 16/9\n */\n aspectRatio?: number;\n /**\n * Fixed outer chart height, or `'auto'` for category-aware sizing.\n */\n height?: VegaChartHeight;\n /**\n * Optional height policy evaluated with the parsed spec and loaded data.\n */\n getHeight?: VegaChartHeightResolver;\n /**\n * Children passed through to VegaLiteArrowChart (e.g., action components)\n */\n children?: React.ReactNode;\n}\n\n/**\n * Chart display subcomponent for VegaLiteChart.Container.\n * Renders the Vega-Lite chart with data from SQL query or arrow table.\n *\n * Uses the parsed spec from the editor state for live preview during editing.\n *\n * Must be used within a VegaLiteChart.Container component.\n *\n * @example\n * ```tsx\n * <VegaLiteChart.Container spec={spec} sqlQuery={query}>\n * <VegaLiteChart.Chart />\n * </VegaLiteChart.Container>\n * ```\n */\nexport const VegaChartDisplay: React.FC<VegaChartDisplayProps> = ({\n className,\n aspectRatio = 16 / 9,\n height,\n getHeight,\n children,\n}) => {\n const {state, arrowTable, options} = useVegaEditorContext();\n\n // Use the applied SQL for chart rendering (updates when Apply is clicked)\n const sqlQuery = state.appliedSql;\n\n // Fetch data from SQL if no arrowTable provided\n const sqlResult = useSql({\n query: sqlQuery || '',\n enabled: !!sqlQuery && !arrowTable,\n });\n\n // Use arrow table if provided, otherwise use SQL result\n const chartData = arrowTable ?? sqlResult.data?.arrowTable;\n\n // Use parsed spec for live preview, fall back to last valid spec if parse failed\n // This ensures the chart keeps rendering during typing even with invalid JSON\n const spec = state.parsedSpec ?? state.lastValidSpec;\n\n const resolvedHeight = React.useMemo(() => {\n const context = {spec, arrowTable: chartData};\n const requestedHeight = getHeight?.(context) ?? height;\n return requestedHeight === 'auto'\n ? getCategoryAwareVegaChartHeight(context)\n : requestedHeight;\n }, [chartData, getHeight, height, spec]);\n\n // Show loading state\n if (sqlQuery && !arrowTable && sqlResult.isLoading) {\n return (\n <div\n className={cn(\n 'text-muted-foreground flex items-center justify-center',\n className,\n )}\n >\n <div className=\"h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600\" />\n <span className=\"ml-2 text-sm\">Loading data...</span>\n </div>\n );\n }\n\n // Show error state\n if (sqlQuery && !arrowTable && sqlResult.error) {\n return (\n <div className={className}>\n <ToolErrorMessage\n error={sqlResult.error}\n triggerLabel=\"SQL query failed\"\n title=\"Query error\"\n align=\"start\"\n details={sqlQuery}\n />\n </div>\n );\n }\n\n return (\n <div className={cn('relative', className)}>\n <VegaLiteArrowChart\n className=\"w-full\"\n spec={spec}\n arrowTable={chartData}\n aspectRatio={aspectRatio}\n height={resolvedHeight}\n options={options}\n >\n {children}\n </VegaLiteArrowChart>\n </div>\n );\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@
3
3
  * @packageDocumentation
4
4
  */
5
5
  export { VegaChartToolResult as VegaChartToolResult } from './VegaChartToolResult';
6
+ export type { VegaChartToolResultProps } from './VegaChartToolResult';
7
+ export { getCategoryAwareVegaChartHeight } from './chartSizing';
8
+ export type { VegaChartHeight, VegaChartHeightResolver, VegaChartSizingContext, } from './chartSizing';
6
9
  export type { VisualizationSpec } from 'vega-embed';
7
10
  export type { SignalListenerHandler, SignalValue } from 'vega';
8
11
  export { createVegaChartTool, createSqlValidator, VegaChartToolParameters, DEFAULT_VEGA_CHART_DESCRIPTION, } from './VegaChartTool';
@@ -1 +1 @@
1
- {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OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,4BAA4B,CAAC;AAGhE,YAAY,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAG9D,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import { VegaSpecEditorPanel } from './editor/VegaSpecEditorPanel';
10
10
  import { VegaSqlEditorPanel } from './editor/VegaSqlEditorPanel';
11
11
  import { VegaChartEditorActions } from './editor/VegaChartEditorActions';
12
12
  export { VegaChartToolResult as VegaChartToolResult } from './VegaChartToolResult';
13
+ export { getCategoryAwareVegaChartHeight } from './chartSizing';
13
14
  export { createVegaChartTool, createSqlValidator, VegaChartToolParameters, DEFAULT_VEGA_CHART_DESCRIPTION, } from './VegaChartTool';
14
15
  export { createChartImageForMarkdownTool, ChartImageForMarkdownToolParameters, } from './ChartImageForMarkdownTool';
15
16
  /**
package/dist/index.js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AM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,4BAA4B,CAAC;AAchE,0BAA0B;AAC1B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,mDAAmD;AACnD,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAGvD,2BAA2B;AAC3B,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nimport {VegaLiteSqlChart} from './VegaLiteSqlChart';\nimport {VegaLiteArrowChart} from './VegaLiteArrowChart';\nimport {VegaChartContainer} from './editor/VegaChartContainer';\nimport {VegaChartDisplay} from './editor/VegaChartDisplay';\nimport {VegaSpecEditorPanel} from './editor/VegaSpecEditorPanel';\nimport {VegaSqlEditorPanel} from './editor/VegaSqlEditorPanel';\nimport {VegaChartEditorActions} from './editor/VegaChartEditorActions';\nexport {VegaChartToolResult as VegaChartToolResult} from './VegaChartToolResult';\nexport type {VisualizationSpec} from 'vega-embed';\nexport type {SignalListenerHandler, SignalValue} from 'vega';\n\nexport {\n createVegaChartTool,\n createSqlValidator,\n VegaChartToolParameters,\n DEFAULT_VEGA_CHART_DESCRIPTION,\n} from './VegaChartTool';\n\nexport type {VegaChartToolOptions, VegaChartToolOutput} from './VegaChartTool';\nexport {\n createChartImageForMarkdownTool,\n ChartImageForMarkdownToolParameters,\n} from './ChartImageForMarkdownTool';\nexport type {\n ChartImageForMarkdownToolOutput,\n ChartImageForMarkdownToolParameters as ChartImageForMarkdownToolParametersType,\n} from './ChartImageForMarkdownTool';\n\n/**\n * Composable Vega-Lite chart component with editing capabilities.\n *\n * @example\n * ```tsx\n * // Compound component pattern\n * <VegaLiteChart.Container\n * spec={mySpec}\n * sqlQuery={myQuery}\n * editable={true}\n * onSpecChange={(spec) => saveSpec(spec)}\n * >\n * <VegaLiteChart.Chart />\n * <VegaLiteChart.SpecEditor />\n * <VegaLiteChart.SqlEditor />\n * <VegaLiteChart.Actions />\n * </VegaLiteChart.Container>\n *\n * // Simple usage (legacy)\n * <VegaLiteChart spec={mySpec} sqlQuery={myQuery} />\n * ```\n */\nexport const VegaLiteChart = Object.assign(VegaLiteSqlChart, {\n // Legacy chart components\n SqlChart: VegaLiteSqlChart,\n ArrowChart: VegaLiteArrowChart,\n // Compound editor components\n Container: VegaChartContainer,\n Chart: VegaChartDisplay,\n SpecEditor: VegaSpecEditorPanel,\n SqlEditor: VegaSqlEditorPanel,\n Actions: VegaChartEditorActions,\n});\n\n// Export editor components and hooks for advanced use\n/** @deprecated Use VegaCodeMirrorEditor instead */\nexport {VegaMonacoEditor} from './editor/VegaMonacoEditor';\nexport {VegaCodeMirrorEditor} from './editor/VegaCodeMirrorEditor';\nexport {useVegaChartEditor} from './editor/useVegaChartEditor';\nexport {useVegaEditorContext} from './editor/VegaEditorContext';\n\n// Export editor types\nexport type {\n EditorMode,\n OnSpecChange,\n OnSqlChange,\n UseVegaChartEditorOptions,\n UseVegaChartEditorReturn,\n VegaEditorActions,\n VegaEditorContextValue,\n VegaEditorState,\n} from './editor/types';\n\n// Export schema utilities\nexport {\n loadVegaLiteSchema,\n getCachedVegaLiteSchema,\n preloadVegaLiteSchema,\n} from './schema/vegaLiteSchema';\n\n// Export chart context and hook for custom actions\nexport {useVegaChartContext} from './VegaChartContext';\nexport type {VegaChartContextValue} from './VegaChartContext';\n\n// Export action components\nexport {VegaExportAction} from './VegaExportAction';\nexport type {VegaExportActionProps} from './VegaExportAction';\nexport {VegaEditAction} from './VegaEditAction';\nexport type {VegaEditActionProps} from './VegaEditAction';\nexport {VegaChartActions} from './VegaChartActions';\nexport type {VegaChartActionsProps} from './VegaChartActions';\n"]}
1
+ {"version":3,"file":"index.js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EAAC,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,4BAA4B,CAAC;AAchE,0BAA0B;AAC1B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,mDAAmD;AACnD,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAGvD,2BAA2B;AAC3B,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nimport {VegaLiteSqlChart} from './VegaLiteSqlChart';\nimport {VegaLiteArrowChart} from './VegaLiteArrowChart';\nimport {VegaChartContainer} from './editor/VegaChartContainer';\nimport {VegaChartDisplay} from './editor/VegaChartDisplay';\nimport {VegaSpecEditorPanel} from './editor/VegaSpecEditorPanel';\nimport {VegaSqlEditorPanel} from './editor/VegaSqlEditorPanel';\nimport {VegaChartEditorActions} from './editor/VegaChartEditorActions';\nexport {VegaChartToolResult as VegaChartToolResult} from './VegaChartToolResult';\nexport type {VegaChartToolResultProps} from './VegaChartToolResult';\nexport {getCategoryAwareVegaChartHeight} from './chartSizing';\nexport type {\n VegaChartHeight,\n VegaChartHeightResolver,\n VegaChartSizingContext,\n} from './chartSizing';\nexport type {VisualizationSpec} from 'vega-embed';\nexport type {SignalListenerHandler, SignalValue} from 'vega';\n\nexport {\n createVegaChartTool,\n createSqlValidator,\n VegaChartToolParameters,\n DEFAULT_VEGA_CHART_DESCRIPTION,\n} from './VegaChartTool';\n\nexport type {VegaChartToolOptions, VegaChartToolOutput} from './VegaChartTool';\nexport {\n createChartImageForMarkdownTool,\n ChartImageForMarkdownToolParameters,\n} from './ChartImageForMarkdownTool';\nexport type {\n ChartImageForMarkdownToolOutput,\n ChartImageForMarkdownToolParameters as ChartImageForMarkdownToolParametersType,\n} from './ChartImageForMarkdownTool';\n\n/**\n * Composable Vega-Lite chart component with editing capabilities.\n *\n * @example\n * ```tsx\n * // Compound component pattern\n * <VegaLiteChart.Container\n * spec={mySpec}\n * sqlQuery={myQuery}\n * editable={true}\n * onSpecChange={(spec) => saveSpec(spec)}\n * >\n * <VegaLiteChart.Chart />\n * <VegaLiteChart.SpecEditor />\n * <VegaLiteChart.SqlEditor />\n * <VegaLiteChart.Actions />\n * </VegaLiteChart.Container>\n *\n * // Simple usage (legacy)\n * <VegaLiteChart spec={mySpec} sqlQuery={myQuery} />\n * ```\n */\nexport const VegaLiteChart = Object.assign(VegaLiteSqlChart, {\n // Legacy chart components\n SqlChart: VegaLiteSqlChart,\n ArrowChart: VegaLiteArrowChart,\n // Compound editor components\n Container: VegaChartContainer,\n Chart: VegaChartDisplay,\n SpecEditor: VegaSpecEditorPanel,\n SqlEditor: VegaSqlEditorPanel,\n Actions: VegaChartEditorActions,\n});\n\n// Export editor components and hooks for advanced use\n/** @deprecated Use VegaCodeMirrorEditor instead */\nexport {VegaMonacoEditor} from './editor/VegaMonacoEditor';\nexport {VegaCodeMirrorEditor} from './editor/VegaCodeMirrorEditor';\nexport {useVegaChartEditor} from './editor/useVegaChartEditor';\nexport {useVegaEditorContext} from './editor/VegaEditorContext';\n\n// Export editor types\nexport type {\n EditorMode,\n OnSpecChange,\n OnSqlChange,\n UseVegaChartEditorOptions,\n UseVegaChartEditorReturn,\n VegaEditorActions,\n VegaEditorContextValue,\n VegaEditorState,\n} from './editor/types';\n\n// Export schema utilities\nexport {\n loadVegaLiteSchema,\n getCachedVegaLiteSchema,\n preloadVegaLiteSchema,\n} from './schema/vegaLiteSchema';\n\n// Export chart context and hook for custom actions\nexport {useVegaChartContext} from './VegaChartContext';\nexport type {VegaChartContextValue} from './VegaChartContext';\n\n// Export action components\nexport {VegaExportAction} from './VegaExportAction';\nexport type {VegaExportActionProps} from './VegaExportAction';\nexport {VegaEditAction} from './VegaEditAction';\nexport type {VegaEditActionProps} from './VegaEditAction';\nexport {VegaChartActions} from './VegaChartActions';\nexport type {VegaChartActionsProps} from './VegaChartActions';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlrooms/vega",
3
- "version": "0.29.0-rc.10",
3
+ "version": "0.29.0-rc.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/sqlrooms/sqlrooms.git"
@@ -19,18 +19,20 @@
19
19
  "build": "tsc",
20
20
  "dev": "tsc -w",
21
21
  "lint": "eslint .",
22
+ "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
23
+ "test:watch": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --watch",
22
24
  "typecheck": "tsc --noEmit",
23
25
  "typedoc": "typedoc"
24
26
  },
25
27
  "dependencies": {
26
- "@sqlrooms/ai-core": "0.29.0-rc.10",
27
- "@sqlrooms/codemirror": "0.29.0-rc.10",
28
- "@sqlrooms/documents": "0.29.0-rc.10",
29
- "@sqlrooms/duckdb": "0.29.0-rc.10",
30
- "@sqlrooms/monaco-editor": "0.29.0-rc.10",
31
- "@sqlrooms/sql-editor": "0.29.0-rc.10",
32
- "@sqlrooms/ui": "0.29.0-rc.10",
33
- "@sqlrooms/utils": "0.29.0-rc.10",
28
+ "@sqlrooms/ai-core": "0.29.0-rc.11",
29
+ "@sqlrooms/codemirror": "0.29.0-rc.11",
30
+ "@sqlrooms/documents": "0.29.0-rc.11",
31
+ "@sqlrooms/duckdb": "0.29.0-rc.11",
32
+ "@sqlrooms/monaco-editor": "0.29.0-rc.11",
33
+ "@sqlrooms/sql-editor": "0.29.0-rc.11",
34
+ "@sqlrooms/ui": "0.29.0-rc.11",
35
+ "@sqlrooms/utils": "0.29.0-rc.11",
34
36
  "ai": "^6.0.177",
35
37
  "lucide-react": "^0.556.0",
36
38
  "react-vega": "^8.0.0",
@@ -40,7 +42,10 @@
40
42
  "zod": "^4.1.8"
41
43
  },
42
44
  "devDependencies": {
43
- "@monaco-editor/react": "^4.7.0"
45
+ "@monaco-editor/react": "^4.7.0",
46
+ "@types/jest": "^30.0.0",
47
+ "jest": "^30.1.3",
48
+ "ts-jest": "^29.4.4"
44
49
  },
45
50
  "peerDependencies": {
46
51
  "apache-arrow": "17.0.0",
@@ -50,5 +55,5 @@
50
55
  "publishConfig": {
51
56
  "access": "public"
52
57
  },
53
- "gitHead": "dbcff5982d39cc07d0c1d0b1189795b19f1e8d87"
58
+ "gitHead": "e451e434c67f59d16a45493689f092af134b207c"
54
59
  }