Skip to content

Commit 2e14ac9

Browse files
author
Jon Vegard Venås
authored
Fix bugs for large cases (#34)
* Fix square_intersection function * Use Float32 instead of Number/Real/Float64 for coordinate related computations in topo (also Point2f instead of Tuple and Vector). Remove redundant notify_component and observables (use the @lift macro instead). * Add missing tests for show-function on the types AbstractSystem and ProcInvData * Improve performance of updates to ax_info and other misc improvements * Fix bug that made nodes/areas disappear when plotting too many objects (max z_level is 10000) * Run tests on Julia version 1.11 due to incompatibility with version 1.12
1 parent b134ddf commit 2e14ac9

16 files changed

Lines changed: 433 additions & 467 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
# Since EnergyModelsGUI doesn't have binary dependencies,
1717
# only test on a subset of possible platforms.
1818
include:
19-
- version: '1' # The latest point-release (Linux)
19+
- version: '1.11' # The latest point-release (Linux)
2020
os: ubuntu-latest
2121
arch: x64
22-
#- version: '1' # The latest point-release (Windows)
22+
#- version: '1.11' # The latest point-release (Windows)
2323
# os: windows-latest
2424
# arch: x64
2525
- version: 'lts' # lts

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- uses: julia-actions/setup-julia@latest
1414
with:
15-
version: '1'
15+
version: '1.11'
1616
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils
1717
- name: Install dependencies
1818
shell: julia --color=yes --project=docs/ {0}

NEWS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Release notes
22

3+
## Version 0.5.17 (2025-11-09)
4+
5+
### Bugfix
6+
7+
* Fix bug that made nodes/areas disappear when plotting too many objects (max z_level is 10000).
8+
* Fix square_intersection function.
9+
10+
### Enhancements
11+
12+
* Use `Float32` instead of `Number`/`Real`/`Float64` for coordinate related computations in topo (also `Point2f` instead of `Tuple` and `Vector`).
13+
* Remove redundant `notify_component` function and `Observable`s (use the `@lift` macro instead).
14+
* Improve performance of updates to `ax_info`.
15+
* Add missing tests for show-function on the types `AbstractSystem` and `ProcInvData`, and improve code structure.
16+
317
## Version 0.5.16 (2025-09-24)
418

519
### Enhancement

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "EnergyModelsGUI"
22
uuid = "737a7361-d3b7-40e9-b1ac-59bee4c5ea2d"
33
authors = ["Jon Vegard Venås <JonVegard.Venas@sintef.no>", "Magnus Askeland <Magnus.Askeland@sintef.no>", "Shweta Tiwari <Shweta.Tiwari@sintef.no>"]
4-
version = "0.5.16"
4+
version = "0.5.17"
55

66
[deps]
77
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
@@ -17,6 +17,7 @@ GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
1717
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
1818
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1919
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
20+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
2021
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
2122
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2223
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
@@ -47,6 +48,7 @@ GeoJSON = "0.8"
4748
GeoMakie = "=0.7.12"
4849
HTTP = "1.10"
4950
ImageMagick = "1.3"
51+
IntervalSets = "<0.7.12"
5052
JuMP = "1.22"
5153
Pkg = "1.9"
5254
PrettyTables = "2.3"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Visualization of the results after simulations will be added at a later stage.
1212

1313
The EnergyModelsGUI package has taken inspiration from the source code of [ModelingToolkitDesigner](https://github.com/bradcarman/ModelingToolkitDesigner.jl) as a starting point for development.
1414

15+
> [!WARNING]
16+
> EnergyModelsGUI.jl currently does not support Julia verison 1.12 due to a breaking change in GLMakie. It is assumed that this issue will resolve soon in the future.
17+
1518
## Usage
1619

1720
If you already have constructed a `case` in EMX you can view this case with

src/datastructures.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ energy system designs in Julia.
119119
- **`components::Vector{EnergySystemDesign}`** is the components of the system, stored
120120
as an array of EnergySystemDesign objects.
121121
- **`connections::Vector{Connection}`** are the connections between system parts.
122-
- **`xy::Observable{Tuple{Real,Real}}`** are the coordinates of the system, observed for
123-
changes.
122+
- **`xy::Observable{<:Point2f}`** are the coordinates of the system, observed for changes.
124123
- **`icon::String`** is the optional (path to) icons associated with the system, stored as
125124
a string.
126125
- **`color::Observable{Symbol}`** is the color of the system, observed for changes and
@@ -138,7 +137,7 @@ mutable struct EnergySystemDesign <: AbstractGUIObj
138137
id_to_icon_map::Dict
139138
components::Vector{EnergySystemDesign}
140139
connections::Vector
141-
xy::Observable{Tuple{Real,Real}}
140+
xy::Observable{<:Point2f}
142141
icon::String
143142
color::Observable{Symbol}
144143
wall::Observable{Symbol}
@@ -152,7 +151,7 @@ function EnergySystemDesign(
152151
id_to_icon_map::Dict,
153152
components::Vector{EnergySystemDesign},
154153
connections::Vector,
155-
xy::Observable{Tuple{Real,Real}},
154+
xy::Observable{<:Point2f},
156155
icon::String,
157156
color::Observable{Symbol},
158157
wall::Observable{Symbol},

src/setup_GUI.jl

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ function GUI(
7979
# Set variables
8080
vars::Dict{Symbol,Any} = Dict(
8181
:title => Observable("top_level"),
82-
:Δh => 0.05, # Sidelength of main box
82+
:Δh => Observable(0.05f0), # Sidelength of main box
8383
:coarse_coast_lines => coarse_coast_lines,
8484
:Δh_px => 50, # Pixel size of a box for nodes
8585
:markersize => 15, # Marker size for arrows in connections
86-
:boundary_add => 0.2, # Relative to the xlim/ylim-dimensions, expand the axis
86+
:boundary_add => 0.2f0, # Relative to the xlim/ylim-dimensions, expand the axis
8787
:line_sep_px => 2, # Separation (in px) between lines for connections
8888
:connection_linewidth => 2, # line width of connection lines
8989
:ax_aspect_ratio => 1.0, # Aspect ratio for the topology plotting area
9090
:fontsize => fontsize, # General font size (in px)
9191
:linewidth => 1.2, # Width of the line around boxes
9292
:parent_scaling => 1.1, # Scale for enlargement of boxes around main boxes for nodes for parent systems
93-
:icon_scale => 0.9, # scale icons w.r.t. the surrounding box in fraction of Δh
93+
:icon_scale => 0.9f0, # scale icons w.r.t. the surrounding box in fraction of Δh
9494
:two_way_sep_px => 10, # No pixels between set of lines for nodes having connections both ways
9595
:selection_color => :green2, # Colors for box boundaries when selection objects
9696
:investment_lineStyle => Linestyle([1.0, 1.5, 2.0, 2.5] .* 5), # linestyle for investment connections and box boundaries for nodes
@@ -134,16 +134,16 @@ function GUI(
134134
vars[:hide_topo_ax_decorations] = hide_topo_ax_decorations
135135
vars[:expand_all] = expand_all
136136

137-
vars[:xlimits] = Vector{Float64}([0.0, 1.0])
138-
vars[:ylimits] = Vector{Float64}([0.0, 1.0])
137+
vars[:xlimits] = Vector{Float32}([0.0f0, 1.0f0])
138+
vars[:ylimits] = Vector{Float32}([0.0f0, 1.0f0])
139139

140-
vars[:topo_title_loc_x] = Observable(0.0)
141-
vars[:topo_title_loc_y] = Observable(0.0)
140+
vars[:topo_title_loc_x] = Observable(0.0f0)
141+
vars[:topo_title_loc_y] = Observable(0.0f0)
142142

143143
# Create iterables for plotting objects in layers (z-direction) such that nodes are
144144
# neatly placed on top of each other and lines are beneath nodes
145-
vars[:z_translate_lines] = 1000
146-
vars[:z_translate_components] = 5000
145+
vars[:z_translate_lines] = 10.0f0
146+
vars[:z_translate_components] = 50.0f0
147147

148148
vars[:selected_systems] = []
149149

@@ -162,10 +162,12 @@ function GUI(
162162
"\tholding x while scrolling over plots will zoom in/out in the x-direction.\n",
163163
"\tholding y while scrolling over plots will zoom in/out in the y-direction.\n\n",
164164
"Left-clicking a component will put information about this component here.\n\n",
165-
"Clicking a plot below enables you to pin this plot (hitting the `pin\n\
166-
current plot` button) for comparison with other plots.\n",
165+
"Clicking a plot below enables you to pin this plot (hitting the `pin\n",
166+
"current plot` button) for comparison with other plots.\n",
167167
"Use the `Delete` button to unpin a selected plot.",
168168
)
169+
vars[:info_text] = Observable(vars[:default_text])
170+
vars[:summary_text] = Observable("No model results")
169171
vars[:dragging] = Ref(false)
170172
vars[:ctrl_is_pressed] = Ref(false)
171173

@@ -410,8 +412,8 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
410412
# Add text at the top left of the axis domain (to print information of the selected/hovered node/connection)
411413
text!(
412414
ax_info,
413-
vars[:default_text];
414-
position = (0.01, 0.99),
415+
vars[:info_text];
416+
position = (0.01f0, 0.99f0),
415417
align = (:left, :top),
416418
fontsize = vars[:fontsize],
417419
)
@@ -428,8 +430,8 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
428430
# Add text at the top left of the axis domain (to print information of the selected/hovered node/connection)
429431
text!(
430432
ax_summary,
431-
"No model results";
432-
position = (0.01, 0.99),
433+
vars[:summary_text];
434+
position = (0.01f0, 0.99f0),
433435
align = (:left, :top),
434436
fontsize = vars[:fontsize],
435437
)
@@ -467,7 +469,7 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
467469
expand_all_toggle = Makie.Toggle(gridlayout_taskbar[1, 8]; active = vars[:expand_all])
468470

469471
# Add the following to add flexibility
470-
Makie.Label(gridlayout_taskbar[1, 9], ""; tellwidth = false)
472+
Makie.Label(gridlayout_taskbar[1, 9], " "; tellwidth = false)
471473

472474
# Add buttons related to the ax_results object (where the optimization results are plotted)
473475
Makie.Label(
@@ -539,11 +541,14 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
539541
justification = :right,
540542
)
541543
available_data_menu = Makie.Menu(
542-
gridlayout_results_taskbar2[1, 2]; halign = :left, fontsize = vars[:fontsize],
544+
gridlayout_results_taskbar2[1, 2];
545+
options = zip(["no options"], [nothing]),
546+
halign = :left,
547+
fontsize = vars[:fontsize],
543548
)
544549

545550
# Add the following to add flexibility
546-
Makie.Label(gridlayout_results_taskbar3[1, 1], ""; tellwidth = false)
551+
Makie.Label(gridlayout_results_taskbar3[1, 1], " "; tellwidth = false)
547552

548553
reset_view_results_button = Makie.Button(
549554
gridlayout_results_taskbar3[1, 2]; label = "reset view",
@@ -626,7 +631,7 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
626631

627632
# Ensure that menus are on top
628633
for menu values(menus)
629-
translate!(menu.blockscene, 0, 0, vars[:z_translate_components] + 2000)
634+
translate!(menu.blockscene, 0.0f0, 0.0f0, vars[:z_translate_components] + 2000.0f0)
630635
end
631636

632637
# Collect all toggles into a dictionary
@@ -638,14 +643,19 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
638643
)
639644

640645
# Update the title of the figure
641-
vars[:topo_title_obj] = text!(
646+
topo_title_obj = text!(
642647
ax,
643648
vars[:topo_title_loc_x],
644649
vars[:topo_title_loc_y];
645650
text = vars[:title],
646651
fontsize = vars[:fontsize],
647652
)
648-
Makie.translate!(vars[:topo_title_obj], 0, 0, vars[:z_translate_components] + 999)
653+
Makie.translate!(
654+
topo_title_obj,
655+
0.0f0,
656+
0.0f0,
657+
vars[:z_translate_components] + 999.0f0,
658+
)
649659

650660
return fig, buttons, menus, toggles, axes, legends
651661
end

src/setup_topology.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ the function initializes the `EnergySystemDesign`.
1111
- **`design_path::String=""`** is a file path or identifier related to the design.
1212
- **`id_to_color_map::Dict`** is a dictionary of resources and their assigned colors.
1313
- **`id_to_icon_map::Dict`** is a dictionary of nodes and their assigned icons.
14-
- **`x::Real=0.0`** is the initial x-coordinate of the system.
15-
- **`y::Real=0.0`** is the initial y-coordinate of the system.
14+
- **`x::Float32=0.0f0`** is the initial x-coordinate of the system.
15+
- **`y::Float32=0.0f0`** is the initial y-coordinate of the system.
1616
- **`icon::String=""`** is the optional (path to) icons associated with the system, stored as
1717
a string.
1818
- **`parent::Union{Symbol, Nothing}=nothing`** is a parent reference or indicator.
@@ -27,8 +27,8 @@ function EnergySystemDesign(
2727
design_path::String = "",
2828
id_to_color_map::Dict = Dict(),
2929
id_to_icon_map::Dict = Dict(),
30-
x::Real = 0.0,
31-
y::Real = 0.0,
30+
x::Float32 = 0.0f0,
31+
y::Float32 = 0.0f0,
3232
icon::String = "",
3333
)
3434
# Create the path to the file where existing design is stored (if any)
@@ -53,7 +53,7 @@ function EnergySystemDesign(
5353

5454
# Create an observable for the coordinate xy that can be inherited as the coordinate
5555
# parent_xy
56-
xy::Observable{Tuple{Real,Real}} = Observable((x, y))
56+
xy::Observable{Point2f} = Observable(Point2f(x, y))
5757

5858
# Create an iterator for the current system
5959
elements = get_children(system)
@@ -73,23 +73,22 @@ function EnergySystemDesign(
7373

7474
# Extract x and y coordinates from file, or from structure or add defaults
7575
if haskey(system_info, "x") && haskey(system_info, "y")
76-
x = system_info["x"]
77-
y = system_info["y"]
76+
x = Float32(system_info["x"])
77+
y = Float32(system_info["y"])
7878
elseif isa(system, SystemGeo)
7979
if hasproperty(element, :lon) && hasproperty(element, :lat)
8080
# assigning longitude and latitude
81-
x = element.lon
82-
y = element.lat
81+
x = Float32(element.lon)
82+
y = Float32(element.lat)
8383
else
8484
@error "Missing lon and/or lat coordinates"
8585
end
8686
else
8787
if element == get_ref_element(system)
88-
x = parent_x
89-
y = parent_y
88+
x, y = parent_x, parent_y
9089
else # place nodes in a circle around the parents availability node
9190
x, y = place_nodes_in_circle(
92-
nodes_count, current_node, 1, parent_x, parent_y,
91+
nodes_count, current_node, 1.0f0, parent_x, parent_y,
9392
)
9493
current_node += 1
9594
end

src/utils_GUI/GUI_utils.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ function toggle_selection_color!(gui::GUI, selection::Connection, selected::Bool
1515
plots = selection.plots
1616
if selected
1717
for plot plots
18-
for plot_sub plot[]
18+
for plot_sub plot
1919
plot_sub.color = get_selection_color(gui)
2020
end
2121
end
2222
else
2323
colors::Vector{RGB} = selection.colors
2424
no_colors::Int64 = length(colors)
2525
for plot plots
26-
for (i, plot_sub) enumerate(plot[])
26+
for (i, plot_sub) enumerate(plot)
2727
plot_sub.color = colors[((i-1)%no_colors)+1]
2828
end
2929
end
@@ -399,7 +399,8 @@ function initialize_available_data!(gui)
399399
investment_overview *= "Investment overview (CAPEX):\n"
400400
investment_overview *= inv_overview_components
401401
end
402-
get_ax(gui, :summary).scene.plots[1][1][] = investment_overview
402+
summary_text = get_var(gui, :summary_text)
403+
summary_text[] = investment_overview
403404
else
404405
if !isempty(model)
405406
@warn "Total quantities were not computed as model does not contain a feasible solution"

0 commit comments

Comments
 (0)