Closed bryanluu closed 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
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.
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!
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
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.
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).
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 :)
closed via #22
Supported named colors for Vega are named colors: https://www.w3schools.com/colors/colors_names.asp
Implement a way to pass user parameters to the plot