Skip to content

Instantly share code, notes, and snippets.

@ijlyttle
Last active December 13, 2018 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijlyttle/98e622c958d5ebec1d62ee7d2dee1216 to your computer and use it in GitHub Desktop.
Save ijlyttle/98e622c958d5ebec1d62ee7d2dee1216 to your computer and use it in GitHub Desktop.
vega-view changeset works as expected
license: mit
height: 500
scrolling: yes
border: yes

In this case, I have used the changeset insert() method with new tuples, and the remove() method with vega.truthy; things work as I expect. However, in another case, I used remove() with the existing tuple; it does not work.

<!DOCTYPE html>
<html>
<head>
<!-- uploaded using vegawidget -->
<script src="https://cdn.jsdelivr.net/npm/vega@4"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@3.0.0-rc10"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
</head>
<body>
<div id="chart"></div>
<script type="text/javascript">
const spec = "spec.json";
const opt = {"defaultStyle":true,"renderer":"canvas"};
vegaEmbed('#chart', spec, opt).then(result => {
// access view as result.view
let changeset = vega.changeset()
.insert([{a: "b", b: 2}, {a: "c", b: 3}])
.remove(vega.truthy);
result.view.change("source", changeset).run();
}).catch(console.error);
</script>
</body>
</html>
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"datasets": {
"source": [
{
"a": "a",
"b": 1
}
]
},
"data": {
"name": "source"
},
"mark": "bar",
"encoding": {
"x": {
"field": "a",
"type": "ordinal"
},
"y": {
"field": "b",
"type": "quantitative"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment