react-vega icon indicating copy to clipboard operation
react-vega copied to clipboard

Feature request: set signals from props

Open tehsenaus opened this issue 7 years ago • 5 comments

It would be useful to be able to set signal values from props, before the first draw.

Currently I'm doing this in onNewView, which isn't too efficient as I have to draw the vega plot twice.

tehsenaus avatar Mar 23 '18 19:03 tehsenaus

I'm very much interested in this functionality as well.

metasoarous avatar Jul 16 '18 21:07 metasoarous

Thanks for suggesting. I'm trying to define the expected behavior before making any change. Would the signal get passed again if the spec change and the chart has to re-initialized?

kristw avatar Jul 27 '18 22:07 kristw

Hmm... having trouble seeing through all the implications here without having a deeper understanding of the state-model. Could you flesh out some of the implications one way or the other?

metasoarous avatar Jul 29 '18 20:07 metasoarous

Any update on this? The behavior I am imagining is that the signal prop only updates (if we are talking about initial values of signals here) when the view is initialized / react-vega component is re-rendered for a spec-change. @tehsenaus the way I am doing this without re-drawing the viz as of right now is setting fields in the data prop with the value of the signal I'd like to initialize, and setting the those signals in the spec like

{
    "name": "my_signal",
    "update": "data(\"my_signal_data\")[0].data"
},

Of course this only works if you are able to set their initial values through update as opposed to value, though a solution to problems dealing with initializing signal values with an expression seems to be in the works.

eharkins avatar Oct 31 '18 20:10 eharkins

On second thought, I think a better default behavior is to have the signals update as the signal props change, not just on initialization. The feature that the Vega folks are working on (linked in my previous comment) will still allow the initialization of signals through an expression, but this would be a useful feature in order to allow signals to be set (on init and update) through react props.

eharkins avatar Nov 01 '18 23:11 eharkins