JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

map dependency tree of Plots' attributes #1149

Open mkborregaard opened 7 years ago

mkborregaard commented 7 years ago

Many attributes in Plot objects depend on each other: x affects axis[:extrema], background_color affects foreground_color affects most other colors, etc. It would be nice to map these depedencies (also to put in the docs). In particular, it would make for much faster updating of Plot objects, where you'd push a change, say a new series (e.g. by calling plot!) or a different background color, and then the rest of the plot would update accordingly, but only updating those attributes that were affected by the change. This is inspired by @SimonDanisch 's ideas in Makie but @tbreloff also talked about this idea a number of times in the past.

mkborregaard commented 7 years ago

I could do this by pen and paper by looking over the code, but I guess some of the hackers in this organisation could find a way to lift it from the code?

piever commented 7 years ago

It's a nice idea! I was thinking along these lines as well after the slack chat with @SimonDanisch. I have two questions regarding future plans and one remark:

Question 1: Do we also intend to support changing an attribute that only affects one series? i.e. should it, for example, be allowed to change the line color of the 3rd series? As of now, I don't think that's possible and I wonder whether it should be or if it's just bad practice to build a plot like that.

Question 2: Do we want to distinguish, when updating the attributes, whether one attribute was computed automatically or given by the user? For example, if I give explicit axis[:extrema] and then modify x, I probably don't want my axis[:extrema] to be overwritten.

Remark: As of know, solving this issue would still not allow a fully efficient update of the plot, as the backends only implement one monolithic display function that computes everything. For this proposal to work, the backend code would need to be much more modular, which I think should be taken care of during the Plots.jl reorganization, I'll try to post a more lengthy discussion of this tomorrow in the Plots reorg issue.

mkborregaard commented 7 years ago

Question 1: I think it would normally be bad practice, but I don't see why we couldn't support it. In fact it is supported now:

p = plot(rand(10,2))
p[1][2][:linecolor] = colorant"red"
p

skaermbillede 2017-10-11 kl 09 17 56

Question 2: Yes.

Remark: great!

piever commented 7 years ago

I see, but also on Question 1 we need to be careful, as here there is the opposite problem: now we don't update any attribute, so for example:

p = plot(rand(10,2))
p[1][2][:seriescolor] = colorant"red"
p

doesn't do anything, as the :linecolor attribute doesn't get changed.

mkborregaard commented 7 years ago

Exactly, that's the purpose of mapping the dependency tree :-)

SimonDanisch commented 7 years ago

Question 2:

For example, if I give explicit axis[:extrema] and then modify x, I probably don't want my axis[:extrema] to be overwritten.

That's my intuition as well. Actually i have it implemented in GLVisualize like this forever. It also has some other advantages:

1) It's the easiest to implement 2) It also gives the user a way to un-link attributes 3) User can link to other attributes/ link differently

This relies a bit on the assumption, that it's easy for users to build those links themselves - which should be true :)

Remark: couldn't agree more!