Skip to content

Commit 48ac585

Browse files
committed
smarter inference of what kind of spec is being passed, add warning
1 parent 62280bd commit 48ac585

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,42 @@ In your Idyll markup,
2626
2727
```
2828

29+
To use with a `vega` specification, set the mode to `vega` and do not pass the
30+
data as a separate parameter:
31+
32+
```
33+
[IdyllVegaLite mode:"vega" spec:`{
34+
...
35+
...
36+
}` /]
37+
```
38+
2939
See https://idyll-lang.github.io/examples/csv/ for example usage.
40+
41+
42+
## Troubleshooting
43+
44+
Depending on your environment, you may see errors when trying to compile an Idyll document
45+
that depends on this library. In this case, you can compile using the `compileLibs` option
46+
to apply all code transformations to the vega dependencies as well, which will make them
47+
compatible with the rest of the build system:
48+
49+
```
50+
$ idyll --compileLibs
51+
```
52+
53+
or specify in `package.json` with:
54+
55+
```
56+
"idyll": {
57+
"compileLibs": true
58+
}
59+
```
60+
61+
This option will cause the initial compile time to be slower, but after the first run
62+
the results are cached and so it should be quicker on subsequent compilation.
63+
64+
## Contributors
65+
66+
- Matthew Conlen (https://github.com/mathisonian)
67+
- Dan Marshall (https://github.com/danmarshall)

index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class IdyllVegaLite extends React.Component {
1414
}
1515
}
1616

17+
isVegaSpec() {
18+
return this.props.mode === 'vega' || (this.props.spec.$schema && this.props.spec.$schema.startsWith("https://vega.github.io/schema/vega/"))
19+
}
20+
1721
componentDidMount() {
1822
const { Handler } = require('vega-tooltip')
1923
this.setState({
@@ -25,8 +29,11 @@ class IdyllVegaLite extends React.Component {
2529
let adjustedSpec = spec;
2630

2731
let Runtime = VegaLite;
28-
if (this.props.mode === 'vega') {
32+
if (this.isVegaSpec()) {
2933
Runtime = Vega;
34+
if (!adjustedSpec.data) {
35+
console.warn('If passing a vega spec you must provide a data object in the spec.');
36+
}
3037
} else {
3138
//vega-lite spec. Modify the spec if data was passed.
3239
if (data) {

0 commit comments

Comments
 (0)