Skip to content

Commit

Permalink
fixing node color options
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonpbarrows committed May 25, 2023
1 parent 4c4f72a commit a718da6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerSystemsMaps"
uuid = "e146f72c-d4f8-45d3-b3ca-12a16cb68a38"
authors = ["cbarrows <[email protected]>"]
version = "0.1.3"
version = "0.1.4"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand All @@ -20,6 +20,6 @@ Graphs = "1.4"
MetaGraphs = "0.7"
NetworkLayout = "0.4"
Plots = "1"
PowerSystems = "1, 2"
PowerSystems = "2"
Shapefile = "0.7, 0.8"
julia = "^1.6"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Pkg; Pkg.add("PowerSystemsMaps")

```julia
using PowerSystems
using PowerSystemsMaps
using PowerSystemsMaps
PSM = PowerSystemsMaps
PSM.Plots.plotlyjs() # load the PlotlyJS backend

Expand Down Expand Up @@ -53,6 +53,6 @@ p = plot_net!(
shownodelegend = true,
size = (1500,800),
buffer = 0.4e4
)
)

```
43 changes: 38 additions & 5 deletions src/plot_network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ end

function color_nodes!(g, sys, color_by::Type{T}) where {T <: AggregationTopology}
# Generate n maximally distinguishable colors in LCHab space.
areas = get_components(color_by, sys)
accessor = get_aggregation_topology_accessor(color_by)
agg_top = get_components(color_by, sys)
buses = get_components(Bus, sys)
area_colors = Dict(
zip(
get_name.(areas),
Colors.distinguishable_colors(length(areas), Colors.colorant"blue"),
get_name.(agg_top),
Colors.distinguishable_colors(length(agg_top), Colors.colorant"blue"),
),
)
node_colors = getindex.(Ref(area_colors), get_name.(get_area.(buses)))
node_colors = getindex.(Ref(area_colors), get_name.(accessor.(buses)))
color_nodes!(g, sys, node_colors)
set_prop!(g, :group, get_name.(get_area.(buses)))
set_prop!(g, :group, get_name.(accessor.(buses)))
end

function color_nodes!(g, sys, color_by)
Expand Down Expand Up @@ -135,6 +136,38 @@ function make_graph(sys::PowerSystems.System; kwargs...)
return g
end



function plot_lines!(p, sys, line_width)
components = collect(get_components(Branch, sys))
fr_lat_lon = get_ext.(get_from.(get_arc.(components)))
to_lat_lon = get_ext.(get_to.(get_arc.(components)))
fr_xy = [PSM.lonlat_to_webmercator((PSM.get_longitude(p), PSM.get_latitude(p))) for p in fr_lat_lon]
to_xy = [PSM.lonlat_to_webmercator((PSM.get_longitude(p), PSM.get_latitude(p))) for p in to_lat_lon]

xy = []
groups = []
labels = []
for (i, c) in enumerate(components)
push!(xy, [fr_xy[i][1] fr_xy[i][2]; to_xy[i][1] to_xy[i][2]; NaN NaN])
for _ in 1:3
push!(groups, get_base_voltage(get_from(get_arc(c))))
push!(labels, get_name(c))
end
end
xy = vcat(xy...)

p = plot!(
p,
xy[:,1], xy[:,2];
linewidth = line_width,
hover = labels,
group = groups,
legend = true
)
return p
end

"""
plot a network from a graph
Expand Down

0 comments on commit a718da6

Please sign in to comment.