@sqlrooms/vega 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/dist/hooks/useChartDimensions.d.ts +0 -50
- package/dist/hooks/useChartDimensions.d.ts.map +0 -1
- package/dist/hooks/useChartDimensions.js +0 -47
- package/dist/hooks/useChartDimensions.js.map +0 -1
- package/dist/vega-lite-chart.d.ts +0 -16
- package/dist/vega-lite-chart.d.ts.map +0 -1
- package/dist/vega-lite-chart.js +0 -38
- package/dist/vega-lite-chart.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/vega",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sqlrooms/duckdb": "0.
|
|
23
|
-
"@sqlrooms/ui": "0.
|
|
24
|
-
"@sqlrooms/utils": "0.
|
|
22
|
+
"@sqlrooms/duckdb": "0.6.0",
|
|
23
|
+
"@sqlrooms/ui": "0.6.0",
|
|
24
|
+
"@sqlrooms/utils": "0.6.0",
|
|
25
25
|
"react-vega": "^7.6.0",
|
|
26
26
|
"vega": "^5.31.0",
|
|
27
27
|
"vega-lite": "^5.23.0"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"lint": "eslint .",
|
|
37
37
|
"typedoc": "typedoc"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "f46dfe6b5d135e1a039b49b3ba71cda7150eab0f"
|
|
40
40
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the dimensions of a chart
|
|
3
|
-
* @interface ChartDimensions
|
|
4
|
-
* @property {number} width - The width of the chart in pixels
|
|
5
|
-
* @property {number} height - The height of the chart in pixels
|
|
6
|
-
*/
|
|
7
|
-
export interface ChartDimensions {
|
|
8
|
-
width: number;
|
|
9
|
-
height: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Props for the useChartDimensions hook
|
|
13
|
-
* @interface UseChartDimensionsProps
|
|
14
|
-
* @property {number | 'auto'} width - The explicitly provided width, or 'auto' for container-based width
|
|
15
|
-
* @property {number | 'auto'} height - The explicitly provided height, or 'auto' for aspect ratio-based height
|
|
16
|
-
* @property {number} aspectRatio - The desired width-to-height ratio when dimensions are auto-calculated
|
|
17
|
-
* @property {React.RefObject<HTMLElement>} containerRef - Reference to the container element
|
|
18
|
-
*/
|
|
19
|
-
export interface UseChartDimensionsProps {
|
|
20
|
-
width: number | 'auto';
|
|
21
|
-
height: number | 'auto';
|
|
22
|
-
aspectRatio: number;
|
|
23
|
-
containerRef: React.RefObject<HTMLElement>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A hook that calculates chart dimensions based on provided values and container size
|
|
27
|
-
*
|
|
28
|
-
* This hook handles various combinations of width/height specifications:
|
|
29
|
-
* - If both width and height are provided, uses those exact dimensions
|
|
30
|
-
* - If only width is provided, calculates height using the aspect ratio
|
|
31
|
-
* - If only height is provided, calculates width using the aspect ratio
|
|
32
|
-
* - If both are 'auto', uses container width and calculates height using the aspect ratio
|
|
33
|
-
*
|
|
34
|
-
* @param {UseChartDimensionsProps} props - The input parameters for dimension calculation
|
|
35
|
-
* @returns {ChartDimensions} The calculated width and height
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```tsx
|
|
39
|
-
* const containerRef = useRef<HTMLDivElement>(null);
|
|
40
|
-
* const {width, height} = useChartDimensions({
|
|
41
|
-
* width: 'auto',
|
|
42
|
-
* height: 'auto',
|
|
43
|
-
* aspectRatio: 16/9,
|
|
44
|
-
* containerRef
|
|
45
|
-
* });
|
|
46
|
-
* // Returns dimensions based on container size
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare function useChartDimensions({ width, height, aspectRatio, containerRef, }: UseChartDimensionsProps): ChartDimensions;
|
|
50
|
-
//# sourceMappingURL=useChartDimensions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useChartDimensions.d.ts","sourceRoot":"","sources":["../../src/hooks/useChartDimensions.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,WAAW,EACX,YAAY,GACb,EAAE,uBAAuB,GAAG,eAAe,CAoB3C"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useResizeObserver } from 'usehooks-ts';
|
|
3
|
-
/**
|
|
4
|
-
* A hook that calculates chart dimensions based on provided values and container size
|
|
5
|
-
*
|
|
6
|
-
* This hook handles various combinations of width/height specifications:
|
|
7
|
-
* - If both width and height are provided, uses those exact dimensions
|
|
8
|
-
* - If only width is provided, calculates height using the aspect ratio
|
|
9
|
-
* - If only height is provided, calculates width using the aspect ratio
|
|
10
|
-
* - If both are 'auto', uses container width and calculates height using the aspect ratio
|
|
11
|
-
*
|
|
12
|
-
* @param {UseChartDimensionsProps} props - The input parameters for dimension calculation
|
|
13
|
-
* @returns {ChartDimensions} The calculated width and height
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const containerRef = useRef<HTMLDivElement>(null);
|
|
18
|
-
* const {width, height} = useChartDimensions({
|
|
19
|
-
* width: 'auto',
|
|
20
|
-
* height: 'auto',
|
|
21
|
-
* aspectRatio: 16/9,
|
|
22
|
-
* containerRef
|
|
23
|
-
* });
|
|
24
|
-
* // Returns dimensions based on container size
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function useChartDimensions({ width, height, aspectRatio, containerRef, }) {
|
|
28
|
-
const { width: containerWidth = 0 } = useResizeObserver({
|
|
29
|
-
ref: containerRef,
|
|
30
|
-
box: 'border-box',
|
|
31
|
-
});
|
|
32
|
-
return useMemo(() => {
|
|
33
|
-
if (width !== 'auto' && height !== 'auto') {
|
|
34
|
-
return { width, height };
|
|
35
|
-
}
|
|
36
|
-
if (width !== 'auto') {
|
|
37
|
-
return { width, height: width / aspectRatio };
|
|
38
|
-
}
|
|
39
|
-
if (height !== 'auto') {
|
|
40
|
-
return { width: height * aspectRatio, height };
|
|
41
|
-
}
|
|
42
|
-
const finalWidth = containerWidth;
|
|
43
|
-
const finalHeight = finalWidth / aspectRatio;
|
|
44
|
-
return { width: finalWidth, height: finalHeight };
|
|
45
|
-
}, [containerWidth, aspectRatio, width, height]);
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=useChartDimensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useChartDimensions.js","sourceRoot":"","sources":["../../src/hooks/useChartDimensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AA4B9C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,WAAW,EACX,YAAY,GACY;IACxB,MAAM,EAAC,KAAK,EAAE,cAAc,GAAG,CAAC,EAAC,GAAG,iBAAiB,CAAC;QACpD,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,YAAY;KAClB,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,KAAK,KAAK,MAAM,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YAC1C,OAAO,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC;QACzB,CAAC;QACD,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YACrB,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,WAAW,EAAC,CAAC;QAC9C,CAAC;QACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,EAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,MAAM,EAAC,CAAC;QAC/C,CAAC;QACD,MAAM,UAAU,GAAG,cAAc,CAAC;QAClC,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;QAC7C,OAAO,EAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAC,CAAC;IAClD,CAAC,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { VisualizationSpec } from 'react-vega';
|
|
2
|
-
/**
|
|
3
|
-
* A component that renders a Vega-Lite chart.
|
|
4
|
-
* @see Vega Lite Chart - https://vega.github.io/vega-lite/
|
|
5
|
-
* @param props - The props for the component.
|
|
6
|
-
* @returns The component.
|
|
7
|
-
* @example
|
|
8
|
-
* <VegaLiteChart sqlQuery="SELECT * FROM my_table" spec={spec} />
|
|
9
|
-
*/
|
|
10
|
-
export declare const VegaLiteChart: React.FC<{
|
|
11
|
-
width?: number;
|
|
12
|
-
height?: number;
|
|
13
|
-
sqlQuery: string;
|
|
14
|
-
spec: string | VisualizationSpec;
|
|
15
|
-
}>;
|
|
16
|
-
//# sourceMappingURL=vega-lite-chart.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vega-lite-chart.d.ts","sourceRoot":"","sources":["../src/vega-lite-chart.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAW,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAIvD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;CAClC,CAyBA,CAAC"}
|
package/dist/vega-lite-chart.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { safeJsonParse } from '@sqlrooms/utils';
|
|
3
|
-
import { arrowTableToJson, useDuckDb } from '@sqlrooms/duckdb';
|
|
4
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
5
|
-
import { VegaLite } from 'react-vega';
|
|
6
|
-
const DATA_NAME = 'queryResult';
|
|
7
|
-
/**
|
|
8
|
-
* A component that renders a Vega-Lite chart.
|
|
9
|
-
* @see Vega Lite Chart - https://vega.github.io/vega-lite/
|
|
10
|
-
* @param props - The props for the component.
|
|
11
|
-
* @returns The component.
|
|
12
|
-
* @example
|
|
13
|
-
* <VegaLiteChart sqlQuery="SELECT * FROM my_table" spec={spec} />
|
|
14
|
-
*/
|
|
15
|
-
export const VegaLiteChart = ({ width, height, sqlQuery, spec }) => {
|
|
16
|
-
const { conn } = useDuckDb();
|
|
17
|
-
const [data, setData] = useState();
|
|
18
|
-
const refinedSpec = useMemo(() => {
|
|
19
|
-
const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;
|
|
20
|
-
if (!parsed)
|
|
21
|
-
return null;
|
|
22
|
-
return {
|
|
23
|
-
...parsed,
|
|
24
|
-
data: { name: DATA_NAME },
|
|
25
|
-
};
|
|
26
|
-
}, [spec]);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
const fetchData = async () => {
|
|
29
|
-
const result = await conn.query(sqlQuery);
|
|
30
|
-
setData({ [DATA_NAME]: arrowTableToJson(result) });
|
|
31
|
-
};
|
|
32
|
-
fetchData();
|
|
33
|
-
}, [sqlQuery, conn]);
|
|
34
|
-
if (!refinedSpec || !data)
|
|
35
|
-
return null;
|
|
36
|
-
return (_jsx("div", { className: "w-full flex flex-col gap-2 overflow-hidden", children: _jsx(VegaLite, { spec: refinedSpec, data: data, width: width, height: height }) }));
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=vega-lite-chart.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vega-lite-chart.js","sourceRoot":"","sources":["../src/vega-lite-chart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAEvD,MAAM,SAAS,GAAG,aAAa,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAKrB,CAAC,EAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAC,EAAE,EAAE;IACvC,MAAM,EAAC,IAAI,EAAC,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,EAA2B,CAAC;IAC5D,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE;QAC/B,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrE,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACzB,OAAO;YACL,GAAG,MAAM;YACT,IAAI,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC;SACH,CAAC;IACzB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACX,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;YAC3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC1C,OAAO,CAAC,EAAC,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAC,CAAC,CAAC;QACnD,CAAC,CAAC;QACF,SAAS,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAErB,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvC,OAAO,CACL,cAAK,SAAS,EAAC,4CAA4C,YACzD,KAAC,QAAQ,IAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAI,GACrE,CACP,CAAC;AACJ,CAAC,CAAC"}
|