Skip to main content

How to select an item programmatically in 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?

Solved

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


Comments

Popular posts from this blog

Strcpy Segmentation Fault C

I am learning some new things and get stuck on a simple strcpy operation. I don't understand why first time when I print works but second time it doesn't. #include #include #include int main() { char *name; char *altname; name=(char *)malloc(60*sizeof(char)); name="Hello World!"; altname=name; printf("%s \n", altname); altname=NULL; strcpy(altname,name); printf("%s \n", altname); return 1; } Solved You need to allocate memory for altname : #include #include #include int main() { char *name; char *altname; name=(char *)malloc(60*sizeof(char)); name="Hello World!"; altname=name; printf("%s \n", altname); altname=NULL; // allocate memory, so strcpy has space to write on ;) altname=(char *)malloc(60*sizeof(char)); strcpy(altname,name); printf("%s \n", altname); return 1; } The problems star...