Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select an item programmatically in vega?

Tags:

vega

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?

like image 910
Gabriel Florit Avatar asked Nov 29 '25 09:11

Gabriel Florit


1 Answers

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 :)

like image 129
Milimetric Avatar answered Dec 02 '25 03:12

Milimetric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!