The following works, but it doesn't seem right (see live demo):
vg.parse.spec(spec, function(chart) {
var view = chart({
el: "#graph"
});
view.update();
view.update({
props: "hover",
items: view._model._scene.items[0].items[0].items[1] // <- ugly and brittle!
});
});
What's the right way of doing this?
Vega is making good progress and this is one of the features they've talked about in their forum. However, right now, what you're doing is the only way to get to a scene item.
For proof, see advice from jheer (main author of vega): https://groups.google.com/forum/#!topic/vega-js/r4aUahV-RwI (last post there shows an example of traversing the scene the same way you do).
One small difference is you can use view.model().scene() instead of view._model._scene. But right now those do the same thing, it's just you don't have to use variables that are actively telling you not to use them :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With