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

Remove boilerplate from API #92

Merged
merged 2 commits into from
May 19, 2016
Merged

Remove boilerplate from API #92

merged 2 commits into from
May 19, 2016

Conversation

jakevdp
Copy link
Collaborator

@jakevdp jakevdp commented May 19, 2016

This is a tiny change in the top-level API that makes for less boilerplate. Using the scatterplot example, the current API looks like this:

Layer(data).encode(
    X('Horsepower'),
    Y('Miles_per_Gallon'),
    Color('Origin'),
    Size('Weight_in_lbs')
).point()

You can also use keywords, e.g.

Layer(data).encode(
    x=X('Horsepower'),
    y=Y('Miles_per_Gallon'),
    color=Color('Origin'),
    size=Size('Weight_in_lbs')
).point()

With this PR, there is a (to my mind) more intuitive way to do this:

Layer(data).encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
    size='Weight_in_lbs'
).point()

The string arguments are converted automatically to the appropriate object. Note that this works only in the encode() function, not deeper within the object hierarchy.

What do you think?

@ellisonbg
Copy link
Collaborator

Nice, do the shorthands work in the strings?

@jakevdp
Copy link
Collaborator Author

jakevdp commented May 19, 2016

Yes – x='foo' is exactly equivalent to x=X('foo')

@jakevdp
Copy link
Collaborator Author

jakevdp commented May 19, 2016

We might also think about allowing this kind of shortcut deeper down, though that would be a bit trickier.

@ellisonbg
Copy link
Collaborator

Looks good, merging.

@ellisonbg ellisonbg merged commit d8c1a19 into vega:master May 19, 2016
@jakevdp jakevdp deleted the cleaner-api branch May 23, 2016 16:09
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

Successfully merging this pull request may close these issues.

None yet

2 participants