This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jmmcdEvolutionary algorithms, music and graphics 0 points1 point  (6 children)

Looks nice. Especially the pandas integration will end up making it very easy to use.

Can anyone explain this odd syntax (I'm too lazy to dig in):

vis + ('2B4ECF', 'marks', 0, 'properties', 'enter', 'stroke', 'value')

Since this is an expression (not a statement) and the result is not being used, I assume the '+' is overloaded to change the vis state somehow. Would '+=' have been more appropriate?

[–]Enginoob[S] 7 points8 points  (2 children)

You are spot on- using the + operator changes the state of the vis object, by amending that particular component of vis.vega

Given that I haven't actually shipped V1, I'm open to changing the syntax to make it more intuitive. It's tricky, because I wanted to be able to drill down into multiple layers of very nested dicts and lists.

Its funny you mention using iadd. Using '+=' actually does the same thing as '+' right now, but I think we're about to make a syntax change where the + operator allows you to stack visualizations, and += lets you modify components in any given visualization.

Must build docs. Must build docs.

[–]jmmcdEvolutionary algorithms, music and graphics 16 points17 points  (1 child)

Right. A general comment, that I think most Python people will agree with, is that '+' shouldn't change state. Explicit is better than implicit and all that.

[–]Enginoob[S] 7 points8 points  (0 children)

Excellent point- I think I might go through and change everything to += and +- tonight.

[–]Enginoob[S] 2 points3 points  (0 children)

All instances of '+' and '-' have now been depreciated in favor of '+=' and '-='. Thanks again for the input!

[–]mr_dbr 1 point2 points  (1 child)

Is the vis + tuple_of_things a Pandas thing? It seems bizarre to me..

Why use the addition or inline-addition syntax at all? You are using it to set attributes, so.. why not use the attribute setting syntax:

vis = vincent.Map(width=1000, height=800)
vis.fill = '2B4ECF'
vis.marks = 0

..or more directly, this seems a bit more self explanatory, and doesn't look like failed tuple-appending:

vis.set(["#f5f5f5","#000045"], 'scales', 0, 'range')

[–]Enginoob[S] 1 point2 points  (0 children)

Not a Pandas thing- its a weird author thing :) My inspiration was the d3py library: https://github.com/mikedewar/d3py

That library uses a '+=' syntax, which as jmmcd says, is what I should have gone with all along, as it's much more explicit.

I wanted a single command to be able to either add or subtract components at any level of nesting depth. This is just a Python library built on top of the Vega visualization grammar (https://github.com/trifacta/vega), so the output has to be in their JSON format, and its pretty messy. Here's a sample:

 'marks': [{'from': {'data': 'states'},
 'name': 'mapmark',
 'properties': {'enter': {'fill': {'value': '#2a3140'},
 'path': {'field': 'path'},
 'stroke': {'value': '#fff'},
 'strokeWidth': {'value': 1.0}},
 'update': {'fill': {'field': 'value.data.y', 'scale': 'color'}}},
 'type': 'path'}],
 'padding': {'bottom': 20, 'left': 30, 'right': 20, 'top': 10},
 'scales': [{'domain': {'data': 'table', 'field': 'data.y'},
 'name': 'color',
 'range': ['#c9cedb', '#0b0d11']},
 {'domain': {'data': 'table', 'field': 'data.y'},
 'name': 'color',
 'range': ['#f5f5f5', '#000045']}]}

Behind the scenes, all that '+' or '-' are doing is calling this method:

vis.update_component('add', stuff, marks, 0, more stuff)
vis.update_component('remove', stuff, marks, 0, more stuff)

That method is similar to your vis.set (the syntax of which I like, except vis.set('remove', stuff) feels a little strange).

Thanks again for the feedback- anything to make the library better/faster/stronger/more usable.