Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any sample to show how to use the data attribute as function ? #185

Open
chabrof opened this issue Apr 28, 2020 · 3 comments
Open
Labels

Comments

@chabrof
Copy link

chabrof commented Apr 28, 2020

Is there any sample to show how to use the data attribute as function ?

Are we expected to use instance of the Vega View in this particular function in order to make some "insert" or "remove" ? If yes, we can unfortunately not access the Vega main instance to use the advanced "Changeset" features (in order to modify one datum for example).

var barData = {
  table: function(dataset){
    vegaView.remove('table', dataset) // remove all
    vegaView.insert('table', otherDataset) // set a new dataset
    // no modify function on vegaView... no access to Vega main instance
    // no need to return anything
    vegaView.run()
  }
};

Thank you very much

@chabrof
Copy link
Author

chabrof commented Apr 30, 2020

In fact, I found the way to access Vega. Vega is in fact not an instance and I can simply import it at the top of the script, and use the "changeset" features.

But I am still curious about a sample of function for data attribute.

Thanks

@kristw kristw changed the title data Attribute as a function Is there any sample to show how to use the data attribute as function ? Jul 20, 2020
@jamesacklin
Copy link

jamesacklin commented Sep 27, 2020

I think I have a working example of this. I am passing in the spec via a prop (established in state), calling some function (in this case, an async fetch), and then merging the response into spec, which effectively uses it as inline data. The Vega component is smart enough to re-render when it sees a spec change, so I think this method may be somewhat extensible.

https://github.com/jamesacklin/react-vega-playground

@cpbotha
Copy link

cpbotha commented Mar 19, 2022

@nerveharp Thank you very much for that example!

I'm having a super hard time getting react-vega 7.4.x to render fetched (via RTKQ) data via the data prop, instead of merging with the spec.

This is why I'm wondering why you went via the merged spec, instead of using the data prop. Could you elaborate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants