Skip to content

Commit 2497a0d

Browse files
author
Jon Vegard Venås
authored
Enhancing connections with simplified plotting (#40)
Added two new options to the `GUI` constructor: `simplified_connection_plotting` (default `false`) for controlling connection visualization detail, and `simplify_all_levels` (default `false`) for applying simplification across hierarchical levels. Also, made the distance between two way connection linearly dependent on `Δh` instead of a fixed width based on `gui.vars[:two_way_sep_px]` and made the markersize (arrow heads for connections) linearly dependent on `Δh` instead of a fixed size based on `gui.vars[:markersize]`
1 parent c948366 commit 2497a0d

File tree

15 files changed

+381
-123
lines changed

15 files changed

+381
-123
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# Release notes
22

3-
## Unversioned updates
3+
## Version 0.5.18 (2025-11-24)
44

55
### Enhancements
66

77
* Added the option `pre_plot_sub_components` to the `GUI`-constructor to skip preplotting hidden sub components of an area (the option is by default `true`). The components of an `Area` are then plotted on demand (on the `open` functionality). This greatly enhances performance for large cases.
88
* Improved general performance.
9+
* Added two new options to the `GUI` constructor: `simplified_connection_plotting` (default `false`) for controlling connection visualization detail, and `simplify_all_levels` (default `false`) for applying simplification across hierarchical levels.
910

1011
### Adjustments
1112

1213
* Adjusted the calculation of `Connection` plots.
1314
* Added the field `visible` to `EnergySystemDesign` and `Connection` on which plots can directly rely on for visibility
1415
* Adjust behaviour of `Base.show` on the types `EnergySystemDesign`, `Connection` and `AbstractSystem` to correspond to `Base.show` of their corresponding `AbstractElement`.
1516
* Change tests of toggling of colors to be based on a new case having more transmission modes (the case in the new `test/EMI_geography_2.jl` file).
17+
* Make the distance between two way connection linearly dependent on `Δh` instead of a fixed width based on `gui.vars[:two_way_sep_px]`.
18+
* Make the markersize (arrow heads for connections) linearly dependent on `Δh` instead of a fixed size based on `gui.vars[:markersize]`
1619

1720
## Version 0.5.17 (2025-11-19)
1821

docs/generate_images.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import EnergyModelsGUI:
99
get_component,
1010
get_selected_systems,
1111
get_name,
12+
get_toggle,
13+
pick_component!,
1214
update!,
1315
toggle_selection_color!,
1416
select_data!
@@ -77,7 +79,7 @@ function create_EMI_geography_images()
7779
solution_summary(m)
7880

7981
# Set folder where visualization info is saved and retrieved
80-
design_path = joinpath(@__DIR__, "design", "EMI", "geography")
82+
design_path = joinpath(docsdir, "design", "EMI", "geography")
8183

8284
# Run the GUI
8385
gui = GUI(
@@ -90,7 +92,7 @@ function create_EMI_geography_images()
9092
)
9193

9294
# Create examples.png image
93-
path_to_results = joinpath(@__DIR__, "src", "figures")
95+
path_to_results = joinpath(docsdir, "src", "figures")
9496
get_vars(gui)[:path_to_results] = path_to_results
9597
get_menu(gui, :axes).selection[] = "All"
9698
get_menu(gui, :export_type).selection[] = "png"
@@ -105,9 +107,8 @@ function create_EMI_geography_images()
105107

106108
# Create EMI_geography.png image
107109
oslo_area = get_component(get_root_design(gui), 1)
108-
push!(get_selected_systems(gui), oslo_area) # Manually add to :selected_systems
110+
pick_component!(gui, oslo_area, :topo)
109111
update!(gui)
110-
toggle_selection_color!(gui, oslo_area, true)
111112
select_data!(gui, "area_exchange")
112113
notify(export_button.clicks)
113114
mv(
@@ -119,11 +120,8 @@ function create_EMI_geography_images()
119120
# Create EMI_geography_Oslo.png image
120121
notify(open_button.clicks)
121122
sub_component = get_component(oslo_area, 5) # fetch node id 5 in Oslo area
122-
selected_systems = get_selected_systems(gui)
123-
empty!(selected_systems)
124-
push!(selected_systems, sub_component) # Manually add to :selected_systems
123+
pick_component!(gui, sub_component, :topo)
125124
update!(gui)
126-
toggle_selection_color!(gui, sub_component, true)
127125
select_data!(gui, "cap_add")
128126
notify(export_button.clicks)
129127
mv(

docs/make.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ const EMB = EnergyModelsBase
77
const EMGUI = EnergyModelsGUI
88

99
# Copy the NEWS.md file
10-
news = "docs/src/manual/NEWS.md"
10+
pkg_dir = pkgdir(EnergyModelsGUI)
11+
docsdir = joinpath(pkg_dir, "docs")
12+
news = joinpath(docsdir, "src", "manual", "NEWS.md")
1113
if isfile(news)
1214
rm(news)
1315
end
14-
cp("NEWS.md", news)
16+
cp(joinpath(pkg_dir, "NEWS.md"), news)
1517

1618
ENV["EMX_TEST"] = true # Set flag for example scripts to check if they are run as part CI
17-
include("generate_images.jl")
19+
include(joinpath(docsdir, "generate_images.jl"))
1820

1921
DocMeta.setdocmeta!(
2022
EnergyModelsGUI, :DocTestSetup, :(using EnergyModelsGUI); recursive = true,

docs/src/figures/EMI_geography.png

1.47 KB
Loading
-189 Bytes
Loading

ext/EMGExt/EMGExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Get the line style for an Transmission `transmission` based on its properties.
166166
"""
167167
function EMGUI.get_linestyle(gui::GUI, transmission::Transmission)
168168
return [
169-
EMI.has_investment(m) ? EMGUI.get_var(gui, :investment_lineStyle) : :solid for
169+
EMI.has_investment(m) ? EMGUI.get_var(gui, :investment_linestyle) : :solid for
170170
m modes(transmission)
171171
]
172172
end

src/datastructures.jl

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
AbstractGUIObj
33
4-
Supertype for EnergyModelsGUI objects representing `Node`s/`Link`s/`Area`s/`Transmission`s.
4+
Supertype for `EnergyModelsGUI` objects representing `Node`s/`Link`s/`Area`s/`Transmission`s.
55
"""
66
abstract type AbstractGUIObj end
77

@@ -15,14 +15,14 @@ struct NothingDesign <: AbstractGUIObj end
1515
"""
1616
AbstractSystem
1717
18-
Supertype for EnergyModelsGUI objects representing a sub system of a Case.
18+
Supertype for `EnergyModelsGUI` objects representing a sub system of a `Case`.
1919
"""
2020
abstract type AbstractSystem <: AbstractCase end
2121

2222
"""
2323
NothingElement <: AbstractElement
2424
25-
Type for representing an empty Element (the "nothing" element).
25+
Type for representing an empty `AbstractElement` (the "nothing" element).
2626
"""
2727
struct NothingElement <: AbstractElement end
2828

@@ -139,6 +139,8 @@ energy system designs in Julia.
139139
- **`inv_data::ProcInvData`** stores processed investment data.
140140
- **`plots::Vector{Makie.AbstractPlot}`** is a vector with all Makie object associated with
141141
this object.
142+
- **`simplified::Observable{Bool}`** indicates whether the system uses a simplified
143+
representation of its plotted connections, observed for changes.
142144
"""
143145
mutable struct EnergySystemDesign <: AbstractGUIObj
144146
system::AbstractSystem
@@ -155,6 +157,7 @@ mutable struct EnergySystemDesign <: AbstractGUIObj
155157
visible::Observable{Bool}
156158
inv_data::ProcInvData
157159
plots::Vector{Makie.AbstractPlot}
160+
simplified::Observable{Bool}
158161
end
159162
function EnergySystemDesign(
160163
system::AbstractSystem,
@@ -184,7 +187,8 @@ function EnergySystemDesign(
184187
file,
185188
visible,
186189
ProcInvData(),
187-
Any[],
190+
Makie.AbstractPlot[],
191+
Observable(false),
188192
)
189193
end
190194

@@ -201,30 +205,42 @@ Mutable type for providing a flexible data structure for connections between
201205
- **`to::EnergySystemDesign`** is the `EnergySystemDesign` to which the connection is
202206
linked to.
203207
- **`connection::AbstractElement`** is the EMX connection structure.
208+
- **`parent::EnergySystemDesign`** is the parent EnergySystemDesign of the connection.
204209
- **`colors::Vector{RGBA{Float32}}`** is the associated colors of the connection.
205-
- **`visible::Observable{Bool}`** indicates whether the system is visible, observed for changes.
206210
- **`inv_data::ProcInvData`** stores processed investment data.
207-
- **`plots::Vector{Makie.AbstractPlot}`** is a vector with all Makie object associated with
208-
this object.
211+
- **`regular_plots::Vector{Makie.AbstractPlot}`** is a vector with
212+
all regular plots associated with the connection.
213+
- **`simplified_plots::Vector{Makie.AbstractPlot}`** is a vector with
214+
all simplified plots associated with the connection.
209215
"""
210216
mutable struct Connection <: AbstractGUIObj
211217
from::EnergySystemDesign
212218
to::EnergySystemDesign
213219
connection::AbstractElement
220+
parent::EnergySystemDesign
214221
colors::Vector{RGBA{Float32}}
215-
visible::Observable{Bool}
216222
inv_data::ProcInvData
217-
plots::Vector{Makie.AbstractPlot}
223+
regular_plots::Vector{Makie.AbstractPlot}
224+
simplified_plots::Vector{Makie.AbstractPlot}
218225
end
219226
function Connection(
220227
from::EnergySystemDesign,
221228
to::EnergySystemDesign,
222229
connection::AbstractElement,
230+
parent::EnergySystemDesign,
223231
id_to_color_map::Dict{Any,Any},
224-
visible::Observable{Bool},
225232
)
226233
colors::Vector{RGBA{Float32}} = get_resource_colors(connection, id_to_color_map)
227-
return Connection(from, to, connection, colors, visible, ProcInvData(), Any[])
234+
return Connection(
235+
from,
236+
to,
237+
connection,
238+
parent,
239+
colors,
240+
ProcInvData(),
241+
Makie.AbstractPlot[],
242+
Makie.AbstractPlot[],
243+
)
228244
end
229245

230246
"""
@@ -446,13 +462,6 @@ Returns the `system` field of a `EnergySystemDesign` `design`.
446462
"""
447463
get_system(design::EnergySystemDesign) = design.system
448464

449-
"""
450-
get_parent(design::EnergySystemDesign)
451-
452-
Returns the `parent` field of a `EnergySystemDesign` `design`.
453-
"""
454-
get_parent(design::EnergySystemDesign) = design.parent
455-
456465
"""
457466
get_element(design::EnergySystemDesign)
458467
@@ -535,10 +544,24 @@ EMB.get_time_struct(design::EnergySystemDesign) = EMB.get_time_struct(get_system
535544
"""
536545
get_ref_element(design::EnergySystemDesign)
537546
538-
Returns the `ref_element` field of a `EnergySystemDesign` `design`.
547+
Returns the `ref_element` field in the `system` field of a `EnergySystemDesign` `design`.
539548
"""
540549
get_ref_element(design::EnergySystemDesign) = get_ref_element(get_system(design))
541550

551+
"""
552+
get_plots(design::EnergySystemDesign)
553+
554+
Returns the `plots` field of a `EnergySystemDesign` `design`.
555+
"""
556+
get_plots(design::EnergySystemDesign) = design.plots
557+
558+
"""
559+
get_simplified(design::EnergySystemDesign)
560+
561+
Returns the `simplified` field of a `EnergySystemDesign` `design`.
562+
"""
563+
get_simplified(design::EnergySystemDesign) = design.simplified
564+
542565
"""
543566
get_from(conn::Connection)
544567
@@ -567,6 +590,43 @@ Returns the `colors` field of a `Connection` `conn`.
567590
"""
568591
get_colors(conn::Connection) = conn.colors
569592

593+
"""
594+
get_regular_plots(conn::Connection)
595+
596+
Returns the `regular_plots` field of a `Connection` `conn`.
597+
"""
598+
get_regular_plots(conn::Connection) = conn.regular_plots
599+
600+
"""
601+
get_simplified_plots(conn::Connection)
602+
603+
Returns the `simplified_plots` field of a `Connection` `conn`.
604+
"""
605+
get_simplified_plots(conn::Connection) = conn.simplified_plots
606+
607+
"""
608+
get_simplified(conn::Connection)
609+
610+
Returns the `simplified` field of the parent `EnergySystemDesign` of a `Connection` `conn`.
611+
"""
612+
get_simplified(conn::Connection) = get_simplified(get_parent(conn))
613+
614+
"""
615+
get_plots(conn::Connection)
616+
617+
Returns the active `plots` field of a `Connection` `conn`.
618+
"""
619+
get_plots(conn::Connection) =
620+
get_simplified(conn)[] ? get_simplified_plots(conn) : get_regular_plots(conn)
621+
622+
"""
623+
get_plots(conn::Connection, simplified::Bool)
624+
625+
Returns the `plots` field of a `Connection` `conn` based on the `simplified` flag.
626+
"""
627+
get_plots(conn::Connection, simplified::Bool) =
628+
simplified ? get_simplified_plots(conn) : get_regular_plots(conn)
629+
570630
"""
571631
get_inv_times(data::ProcInvData)
572632
get_inv_times(design::AbstractGUIObj)
@@ -602,18 +662,18 @@ Returns the `inv_data` field of a `AbstractGUIObj` `obj`.
602662
get_inv_data(obj::AbstractGUIObj) = obj.inv_data
603663

604664
"""
605-
get_plots(obj::AbstractGUIObj)
665+
get_visible(obj::AbstractGUIObj)
606666
607-
Returns the `plots` field of a `AbstractGUIObj` `obj`.
667+
Returns the `visible` field of a `AbstractGUIObj` `obj`.
608668
"""
609-
get_plots(obj::AbstractGUIObj) = obj.plots
669+
get_visible(obj::AbstractGUIObj) = obj.visible
610670

611671
"""
612-
get_visible(obj::AbstractGUIObj)
672+
get_parent(obj::AbstractGUIObj)
613673
614-
Returns the `visible` field of a `AbstractGUIObj` `obj`.
674+
Returns the `parent` field of a `AbstractGUIObj` `obj`.
615675
"""
616-
get_visible(obj::AbstractGUIObj) = obj.visible
676+
get_parent(obj::AbstractGUIObj) = obj.parent
617677

618678
"""
619679
get_fig(gui::GUI)

src/setup_GUI.jl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ to the old EnergyModelsX `case` dictionary.
4646
sub-components of areas in the topology design. Setting this to `false` greatly
4747
enhances performance for large cases, as the components of an `Area` are then
4848
plotted on demand (on the `open` functionality).
49+
- **`simplified_connection_plotting::Bool=false`** toggles whether or not to use a
50+
simplified representation of the connections with a single line for each connection
51+
(instead of multiple lines for multiple transmission modes) in the topology design.
52+
- **`simplify_all_levels::Bool=false`** toggles whether or not to use simplified connection
53+
plotting for all hierarchical levels.
4954
5055
!!! warning "Reading model results from CSV-files"
5156
Reading model results from a directory (*i.e.*, `model::String` implying that the results
@@ -77,6 +82,8 @@ function GUI(
7782
enable_data_inspector::Bool = true,
7883
use_geomakie::Bool = true,
7984
pre_plot_sub_components::Bool = true,
85+
simplified_connection_plotting::Bool = false,
86+
simplify_all_levels::Bool = false,
8087
)
8188
# Generate the system topology:
8289
@info raw"Setting up the topology design structure"
@@ -98,7 +105,6 @@ function GUI(
98105
:Δh => Observable(0.05f0), # Sidelength of main box
99106
:coarse_coast_lines => coarse_coast_lines,
100107
:Δh_px => 50, # Pixel size of a box for nodes
101-
:markersize => 15, # Marker size for arrows in connections
102108
:boundary_add => 0.2f0, # Relative to the xlim/ylim-dimensions, expand the axis
103109
:line_sep_px => 2, # Separation (in px) between lines for connections
104110
:connection_linewidth => 2, # line width of connection lines
@@ -107,9 +113,8 @@ function GUI(
107113
:linewidth => 1.2, # Width of the line around boxes
108114
:parent_scaling => 1.1, # Scale for enlargement of boxes around main boxes for nodes for parent systems
109115
:icon_scale => 0.9f0, # scale icons w.r.t. the surrounding box in fraction of Δh
110-
:two_way_sep_px => 10, # No pixels between set of lines for nodes having connections both ways
111116
:selection_color => GREEN2, # Colors for box boundaries when selection objects
112-
:investment_lineStyle => Linestyle([1.0, 1.5, 2.0, 2.5] .* 5), # linestyle for investment connections and box boundaries for nodes
117+
:investment_linestyle => Linestyle([1.0, 1.5, 2.0, 2.5] .* 5), # linestyle for investment connections and box boundaries for nodes
113118
:path_to_results => path_to_results, # Path to the location where axes[:results] can be exported
114119
:plotted_data => [],
115120
:periods_labels => periods_labels,
@@ -122,6 +127,9 @@ function GUI(
122127
:tol => tol,
123128
:use_geomakie => use_geomakie,
124129
:pre_plot_sub_components => pre_plot_sub_components,
130+
:simplified_connection_plotting => simplified_connection_plotting,
131+
:simplify_all_levels => simplify_all_levels,
132+
:marker_to_box_ratio => 0.4, # Ratio between marker size and `Node` box size
125133
:autolimits => Dict(
126134
:results_op => true,
127135
:results_sc => true,
@@ -501,9 +509,20 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
501509
justification = :right,
502510
)
503511
expand_all_toggle = Makie.Toggle(gridlayout_taskbar[1, 8]; active = vars[:expand_all])
512+
Makie.Label(
513+
gridlayout_taskbar[1, 9],
514+
"Simplified:";
515+
halign = :right,
516+
fontsize = vars[:fontsize],
517+
justification = :right,
518+
)
519+
simplified_toggle = Makie.Toggle(
520+
gridlayout_taskbar[1, 10];
521+
active = vars[:simplified_connection_plotting],
522+
)
504523

505524
# Add the following to add flexibility
506-
Makie.Label(gridlayout_taskbar[1, 9], " "; tellwidth = false)
525+
Makie.Label(gridlayout_taskbar[1, 11], " "; tellwidth = false)
507526

508527
# Add buttons related to the ax_results object (where the optimization results are plotted)
509528
Makie.Label(
@@ -664,7 +683,8 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
664683
)
665684

666685
# Collect all toggles into a dictionary
667-
toggles::Dict{Symbol,Makie.Toggle} = Dict(:expand_all => expand_all_toggle)
686+
toggles::Dict{Symbol,Makie.Toggle} =
687+
Dict(:expand_all => expand_all_toggle, :simplified => simplified_toggle)
668688

669689
# Collect all axes into a dictionary
670690
axes::Dict{Symbol,Makie.Block} = Dict(

0 commit comments

Comments
 (0)