@sqlrooms/vega 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
A package that provides Vega-Lite visualization components for the SQLRooms framework, allowing you to create interactive data visualizations directly from SQL queries.
|
|
2
|
+
|
|
3
|
+
## About Vega-Lite
|
|
4
|
+
|
|
5
|
+
[Vega-Lite](https://vega.github.io/vega-lite/) is a high-level grammar of interactive graphics. It provides a concise, declarative JSON syntax to create an expressive range of visualizations for data analysis and presentation.
|
|
6
|
+
|
|
7
|
+
Vega-Lite specifications describe visualizations as encoding mappings from data to properties of graphical marks (e.g., points or bars). The Vega-Lite compiler automatically produces visualization components including axes, legends, and scales. This approach allows for concise specifications while giving users control to customize various parts of a visualization.
|
|
8
|
+
|
|
9
|
+
This package integrates Vega-Lite with SQLRooms, allowing you to easily create data visualizations directly from SQL queries.
|
|
10
|
+
|
|
11
|
+
## Components
|
|
12
|
+
|
|
13
|
+
### VegaLiteChart
|
|
14
|
+
|
|
15
|
+
A React component that renders a Vega-Lite chart with SQL data and responsive sizing.
|
|
16
|
+
|
|
17
|
+
#### Features
|
|
18
|
+
|
|
19
|
+
- **SQL-Powered**: Directly use SQL queries to fetch data for your visualizations
|
|
20
|
+
- **Responsive Design**: Multiple sizing options to fit any layout
|
|
21
|
+
- **Aspect Ratio Control**: Maintain visual consistency with customizable aspect ratios
|
|
22
|
+
- **Integration with DuckDB**: Seamlessly works with the SQLRooms DuckDB integration
|
|
23
|
+
|
|
24
|
+
#### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @sqlrooms/vega
|
|
28
|
+
# or
|
|
29
|
+
yarn add @sqlrooms/vega
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Usage
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import {VegaLiteChart} from '@sqlrooms/vega';
|
|
36
|
+
|
|
37
|
+
// Basic usage
|
|
38
|
+
function MyChart() {
|
|
39
|
+
return (
|
|
40
|
+
<VegaLiteChart
|
|
41
|
+
sqlQuery="SELECT category, count(*) as count FROM sales GROUP BY category"
|
|
42
|
+
spec={{
|
|
43
|
+
mark: 'bar',
|
|
44
|
+
encoding: {
|
|
45
|
+
x: {field: 'category', type: 'nominal'},
|
|
46
|
+
y: {field: 'count', type: 'quantitative'},
|
|
47
|
+
},
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Props
|
|
55
|
+
|
|
56
|
+
| Prop | Type | Default | Description |
|
|
57
|
+
| ------------- | ----------------------------- | ----------- | --------------------------------------------------------------------- |
|
|
58
|
+
| `sqlQuery` | `string` | (required) | The SQL query to fetch data for the chart |
|
|
59
|
+
| `spec` | `string \| VisualizationSpec` | (required) | The Vega-Lite specification for the chart |
|
|
60
|
+
| `width` | `number \| 'auto'` | `'auto'` | The chart width in pixels, or 'auto' to use container width |
|
|
61
|
+
| `height` | `number \| 'auto'` | `'auto'` | The chart height in pixels, or 'auto' to calculate from aspect ratio |
|
|
62
|
+
| `aspectRatio` | `number` | `3/2` | The desired width-to-height ratio when dimensions are auto-calculated |
|
|
63
|
+
| `className` | `string` | `undefined` | Additional CSS classes to apply to the container |
|
|
64
|
+
|
|
65
|
+
#### Sizing Options
|
|
66
|
+
|
|
67
|
+
The chart can be sized in multiple ways:
|
|
68
|
+
|
|
69
|
+
- **Fixed dimensions**: Provide both width and height as numbers
|
|
70
|
+
- **Fixed width, proportional height**: Provide width as number, height as 'auto'
|
|
71
|
+
- **Fixed height, proportional width**: Provide height as number, width as 'auto'
|
|
72
|
+
- **Fully responsive**: Leave both as 'auto' (default), chart will fill container while maintaining aspect ratio
|
|
73
|
+
|
|
74
|
+
#### Examples
|
|
75
|
+
|
|
76
|
+
**Fixed size chart:**
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
<VegaLiteChart
|
|
80
|
+
width={600}
|
|
81
|
+
height={400}
|
|
82
|
+
sqlQuery="SELECT category, count(*) as count FROM sales GROUP BY category"
|
|
83
|
+
spec={{
|
|
84
|
+
mark: 'bar',
|
|
85
|
+
encoding: {
|
|
86
|
+
x: {field: 'category', type: 'nominal'},
|
|
87
|
+
y: {field: 'count', type: 'quantitative'},
|
|
88
|
+
},
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Responsive chart with 16:9 aspect ratio:**
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<VegaLiteChart
|
|
97
|
+
className="max-w-[600px]"
|
|
98
|
+
aspectRatio={16 / 9}
|
|
99
|
+
sqlQuery="SELECT date, value FROM metrics"
|
|
100
|
+
spec={{
|
|
101
|
+
mark: 'line',
|
|
102
|
+
encoding: {
|
|
103
|
+
x: {field: 'date', type: 'temporal'},
|
|
104
|
+
y: {field: 'value', type: 'quantitative'},
|
|
105
|
+
},
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Dependencies
|
|
111
|
+
|
|
112
|
+
This package depends on:
|
|
113
|
+
|
|
114
|
+
- `@sqlrooms/duckdb` - For SQL query execution
|
|
115
|
+
- `@sqlrooms/ui` - For UI utilities
|
|
116
|
+
- `@sqlrooms/utils` - For utility functions
|
|
117
|
+
- `react-vega` - For rendering Vega-Lite visualizations
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\nexport {VegaLiteChart} from './VegaLiteChart';\nexport type {VisualizationSpec} from 'react-vega';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/vega",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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.7.0",
|
|
23
|
+
"@sqlrooms/ui": "0.7.0",
|
|
24
|
+
"@sqlrooms/utils": "0.7.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": "8be65f051c588d3a963f721322429657913b6c63"
|
|
40
40
|
}
|