WISPO-POP / PowerPlots.jl

Functions plot PowerModels networks
BSD 3-Clause "New" or "Revised" License
22 stars 2 forks source link

how to pass in user parameters (size, color, etc.) #15

Closed bryanluu closed 3 years ago

bryanluu commented 3 years ago

Implement a way to pass user parameters to the plot

bryanluu commented 3 years ago

Lines 302-325 of utils.jl and 340-343 of graphs.jl seem relevant.

Basically a lot of Julia Metaprogramming stuff to replace aliases with keywords

bryanluu commented 3 years ago

Added new file src/core/utils.jl that demonstrates the use of aliases. Next need to figure out what the aliases and attributes to use are.

noahrhodes commented 3 years ago

Here are some ideas of what the parameters names could be (not the aliases though)

* = gen, bus, branch, etc ...

*_color *_size *_label (the hover information) *_min, *_max (for color gradients) *_type (line types for branches, outline type for nodes?)

There are some features that might be tricky to implement like a gradient based on a value like power generated relative to the capacity.

These are just some basic ideas to start a list. Please add anything else that you can think of below!

bryanluu commented 3 years ago

I'm confused by your formatting, what exactly does the * mean? Do you mean like it could be any variable? I guess a lot of this depends on how you pass attributes to VegaLite

From what I can tell, you call a macro which takes an expression, so it looks like we would need to do a bit more Metaprogramming to convert the plotattributes into a form we can pass to Vegalite

noahrhodes commented 3 years ago

sorry for the confusion. Essentially, I'm trying to discuss what the supported arguments for the plot function are going to be. The * is to make shorthand list instead of listing gen_color, bus_color, and branch_color etc. This is separate from what the potential aliases would be, like maybe [substation_color, bc] as aliases for bus_color.

This also might be a misunderstanding on my end about what the aliases/attributes are doing. As I understand if you passed in something like plot(data; bc=:blue) would be re-parsed as plot(data, bus_color=:blue). But the individual keyword arguments need to be defined for what it is possible to modify in the plot.

bryanluu commented 3 years ago

Yes pretty much as you said, the code I wrote will replace any keywords that are aliases with the correct attribute and place them in a dictionary plotattributes. I think you can simple define it as an empty dictionary then call the functions convert_to_attributes!(plotattributes, kwargs), then the @process_aliases macro, then remove_aliases! function, as in src/core/utils.jl in parameters branch. You define default attributes as keyword arguments, and a variable-number of keyword arguments at the end as kwargs... (see the test function at the end of src/core/utils.jl).

I think the issue now is figuring out how do we want to use this plotattributes dictionary and pass it into the plot. Looking through the plot_vega method, it's not clear to me how color is specified for example besides using some weird syntax and passing it into the macro. That's why I said we might need to do some more Metaprogramming (i.e. construct Expr objects to pass back into the @vlplot macro).

bryanluu commented 3 years ago

I committed some changes, now you just need to call one macro to create the correct plot_attributes dictionary:

function plot_vega(case; stuff=nothing, kwargs...)
    @prepare_plot_attributes(kwargs)

    #do stuff
end

The default attributes and their aliases are defined in src/core/options.jl. You just need to figure out what you want as attributes and define them :)

noahrhodes commented 3 years ago

closed via #22

noahrhodes commented 3 years ago

Supported named colors for Vega are named colors: https://www.w3schools.com/colors/colors_names.asp