jupyter / declarativewidgets

[RETIRED] Jupyter Declarative Widget Extension
http://jupyter.org/declarativewidgets/docs.html
Other
120 stars 38 forks source link

Dynamically update format for viz-col? #508

Closed MattKravetz closed 8 years ago

MattKravetz commented 8 years ago

I can't seem to figure out a way to dynamically update the value of "format" being passed to urth-viz-col.

I am creating a dashboard where users can interact with a number of survey questions that are listed in an urth-viz-table. When the user selects a row in the table, an urth-viz-bar widget is generated for the corresponding survey question. Since the survey questions are denominated in different units ($, %, etc.), I would like some way of programmatically defining the format used by urth-viz-col. My current approach works, but it is not dynamic (i.e., the format does not update until the cell is re-ran). Is it possible to have this behavior?

Here is the code for the offending cell:

%%html
<template is="urth-core-bind" channel="val">
    <template is='dom-if' if='{{selfSel}}'>
        <urth-core-function id='chartFunc'
            ref='prepare_for_chart'
            arg-question="{{selfSel.Question}}"
            result="{{selfData}}"
            auto></urth-core-function>
        <urth-core-function id="refreshFormFunc"
            ref="refresh_format"
            arg-question="{{selfSel.Question}}"
            result="{{form}}"
            auto></urth-core-function>
        <urth-viz-bar datarows="{{selfData.data}}" columns="{{selfData.columns}}">
            <template is='dom-repeat' items="{{n_cols}}">
                    <urth-viz-col index="{{item}}" format="{{form}}" type="numeric"></urth-viz-col>
            </template>
        </urth-viz-bar>
    </template>
</template>

Apologies if this is an improper use of this forum - I'm new to GitHub and this project, so I'm not quite sure if this qualifies as an "issue" or if I'm just missing something. Any help would be greatly appreciated!

peller commented 8 years ago

Definitely an issue. Both urth-viz-table and urth-viz-chart need to respond to changes to existing urth-viz-col tags, also insertion and removal of tags.

peller commented 8 years ago

@aluu317

peller commented 8 years ago

We can do what urth-core-query does: use observeNodes to watch for additions deletions and put select= on content to filter out urth-viz-col elements

https://github.com/jupyter-incubator/declarativewidgets/blob/master/elements/urth-core-dataframe/urth-core-query-group.html#L96

and fire an event from the children when properties change

https://github.com/jupyter-incubator/declarativewidgets/blob/master/elements/urth-core-dataframe/urth-core-query-agg.html#L80