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

How to support signals in dl.template #33

Closed
arvind opened this issue May 28, 2015 · 2 comments
Closed

How to support signals in dl.template #33

arvind opened this issue May 28, 2015 · 2 comments

Comments

@arvind
Copy link
Member

arvind commented May 28, 2015

Right now, the function produced by dl.template.source take a single argument for the data object to parse the handlebars against. In Vega, signals are not namespaced, and I'm wondering how best we should support them with template. Some ideas:

  • Use dl.extend to pass dl.template an object containing both item.datum properties and signals.
  • Switch the dl.template function to take vargs, and iterate through them until the property is found.

I prefer the second option, as running dl.extend on every tuple every time an encoder is overly expensive.

In either case, I also need to know which signals are being used within a template expression, in order to compile the signal values and send them into the encoder. i.e., I need from dl.template a list of the handlebar strings used.

@jheer
Copy link
Member

jheer commented May 30, 2015

Collecting the properties accessed is straightforward, so that's not problem. The API I am thinking of is to pass a hash as an additional optional argument to source. If provided, the hash will be populated with all the accessed properties.

I agree that running dl.extend would be overkill. However, I'm reticent to add the varargs functionality as it will complicate the internal logic in ways I'd prefer to avoid.

An alternative might be to "wrap" the signals and datum in a shared object that you can reuse (no new object allocations): var ctx = {}; ctx.signals = signals; ctx.data = item.datum; template_fn(ctx).... Of course, you would only create ctx once. The complication is that the template variables will need to be updated with the correct access paths due to the name spacing.

In any case, how were you planning to differentiate data variable names from signal names? We must use some form of name spacing otherwise collisions might occur.

@arvind
Copy link
Member Author

arvind commented Jun 4, 2015

So, following up our discussion yesterday of handlebar syntax to support datum, group, parent composition and de-referencing, here are some ideas. Whatever syntax we settle on, the thing I need support for in datalib is finding/parsing properties within [ ].

dl.template.source("{{datum[signalA.foo]}}", "hello", props={})
props = { 'datum[signalA.foo]': 1 }; // should be {'datum': 1, 'signalA': 1}

Alright, so CSS doesn't have parent selectors but proposals have coalesced around two options: parent < child and :parent. I personally prefer the latter because it is difficult for me to parse the order/result of <. So, for dl.template support in Vega, I propose this:

{{signalA}}
{{datum.price}}
{{datum[:parent.A]}}
{{:group.width}}

And of course, they can be chained like so: :parent:parent.a or :group:group.width. Thoughts?

@arvind arvind closed this as completed Jun 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants