Skip to content

Commit df95459

Browse files
author
Jon Vegard Venås
committed
Fix missing distinction between different TransmissionModes in the "data"-menu by including the id field in parantheses. Also, improve the info-box.
1 parent 2497a0d commit df95459

11 files changed

Lines changed: 254 additions & 119 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Version 0.5.18 (2025-11-24)
44

5+
### Bugfix
6+
7+
* Fix missing distinction between different `TransmissionMode`s in the "data"-menu by including the `id` field in parantheses.
8+
59
### Enhancements
610

711
* 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.
@@ -16,6 +20,8 @@
1620
* 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).
1721
* Make the distance between two way connection linearly dependent on `Δh` instead of a fixed width based on `gui.vars[:two_way_sep_px]`.
1822
* Make the markersize (arrow heads for connections) linearly dependent on `Δh` instead of a fixed size based on `gui.vars[:markersize]`
23+
* Also expand `TransmissionMode`s in the info-box.
24+
* For the labeling, use square brackets around indices in the string construction.
1925

2026
## Version 0.5.17 (2025-11-19)
2127

docs/src/figures/EMI_geography.png

-228 Bytes
Loading
2.61 KB
Loading

ext/EMGExt/EMGExt.jl

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ Returns the `Transmission`s of a `SystemGeo` `system`.
2727
EMG.get_transmissions(system::EMGUI.SystemGeo) = EMGUI.get_connections(system)
2828

2929
"""
30-
get_modes(system::EMGUI.SystemGeo)
30+
EMG.modes(conn::EMGUI.Connection)
3131
32-
Get all transmission modes of a `SystemGeo` `system`.
32+
Returns an array of the transmission modes for a `Connection` `conn`.
3333
"""
34-
function get_modes(system::EMGUI.SystemGeo)
35-
transmission_modes = TransmissionMode[]
36-
for t get_transmissions(system)
37-
append!(transmission_modes, modes(t))
38-
end
39-
return transmission_modes
40-
end
34+
EMG.modes(conn::EMGUI.Connection) = EMG.modes(EMGUI.get_element(conn))
4135

4236
############################################################################################
4337
## From datastructures.jl
@@ -85,7 +79,7 @@ function EMGUI.get_plotables(system::EMGUI.SystemGeo)
8579
get_nodes(system),
8680
get_links(system),
8781
get_areas(system),
88-
get_modes(system),
82+
modes(get_transmissions(system)),
8983
)
9084
end
9185

@@ -194,4 +188,47 @@ end
194188
Map types to header symbols for saving results.
195189
"""
196190
EMGUI._type_to_header(::Type{<:TransmissionMode}) = :element
191+
192+
############################################################################################
193+
## From info_axis_utils.jl
194+
"""
195+
print_nested_structure!(
196+
element::Vector{<:TransmissionMode},
197+
io::IOBuffer,
198+
indent::Int64,
199+
vector_limit::Int64,
200+
show_the_n_last_elements::Int64,
201+
)
202+
203+
Appends the nested structure of element in a nice format to the `io` buffer for `element`.
204+
The parameter `indent` tracks the indentation level, the parameter `vector_limit` is used
205+
to truncate large vectors and `show_the_n_last_elements` specifies how many of the last elements to show.
206+
"""
207+
function EMGUI.print_nested_structure!(
208+
element::Vector{<:TransmissionMode},
209+
io::IOBuffer,
210+
indent::Int64,
211+
vector_limit::Int64,
212+
show_the_n_last_elements::Int64,
213+
)
214+
indent += 1
215+
indent_str::String = EMGUI.create_indent_string(indent)
216+
for (i, field1) enumerate(element)
217+
if i == vector_limit + 1
218+
println(io, indent_str, "...")
219+
continue
220+
end
221+
if i <= vector_limit || i > length(element) - show_the_n_last_elements
222+
type = typeof(field1)
223+
println(io, indent_str, i, " (", type, "):")
224+
EMGUI.print_nested_structure!(
225+
field1,
226+
io,
227+
indent,
228+
vector_limit,
229+
show_the_n_last_elements,
230+
)
231+
end
232+
end
233+
end
197234
end

src/utils_GUI/GUI_utils.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,22 +644,30 @@ function update_descriptive_names!(gui::GUI)
644644
end
645645

646646
"""
647-
select_data!(gui::GUI, name::String)
647+
select_data!(gui::GUI, name::String; selection::Vector = Any[])
648648
649-
Select the data with name `name` from the `available_data` menu.
649+
Select the data with name `name` from the `available_data` menu. If `selection` is provided,
650+
it is used to further specify which data to select.
650651
"""
651-
function select_data!(gui::GUI, name::String)
652+
function select_data!(gui::GUI, name::String; selection::Vector = Any[])
652653
# Fetch the available data menu object
653654
menu = get_menu(gui, :available_data)
654655

655-
# Fetch all menu options
656-
available_data = [get_name(x[2]) for x collect(menu.options[])]
656+
items = collect(menu.options[])
657657

658658
# Find menu number for data with name `name`
659-
i_selected = findfirst(x -> x == name, available_data)
659+
if isempty(selection)
660+
i_selected = findfirst(x -> get_name(x[2]) == name, items)
661+
else
662+
i_selected = findfirst(
663+
x -> get_name(x[2]) == name && issubset(selection, get_selection(x[2])),
664+
items,
665+
)
666+
end
660667

661668
# Select data
662669
menu.i_selected = i_selected
670+
return nothing
663671
end
664672

665673
"""

src/utils_GUI/info_axis_utils.jl

Lines changed: 134 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Expandable::Type = Union{
2+
Vector,
3+
Dict,
4+
EMB.Node,
5+
Resource,
6+
Link,
7+
TimeStructure,
8+
Data,
9+
AbstractInvData,
10+
Investment,
11+
LifetimeMode,
12+
TimeProfile,
13+
}
114
"""
215
update_info_box!(gui::GUI, element)
316
@@ -10,114 +23,148 @@ function update_info_box!(gui::GUI, element)
1023
return nothing
1124
end
1225
io = IOBuffer()
13-
print_nested_structure!(
14-
element,
15-
io;
16-
vector_limit = 5,
17-
show_the_n_last_elements = 1,
18-
)
26+
type = typeof(element)
27+
if isa(element, Dict) || isa(element, Vector)
28+
println(io, type)
29+
else
30+
println(io, element, " (", type, ")")
31+
end
32+
print_nested_structure!(element, io, 0, 5, 1)
1933
info_text[] = String(take!(io))
2034
end
2135

36+
"""
37+
create_indent_string(indent::Int64)
38+
39+
Create an indentation string based on the `indent` level.
40+
"""
41+
create_indent_string(indent::Int64) = " "^indent
42+
2243
"""
2344
print_nested_structure!(
2445
element,
25-
io::IOBuffer;
26-
indent::Int64=0,
27-
vector_limit::Int64=typemax(Int64),
46+
io::IOBuffer,
47+
indent::Int64,
48+
vector_limit::Int64,
49+
show_the_n_last_elements::Int64,
2850
)
2951
30-
Appends the nested structure of element in a nice format to the io buffer. The
31-
parameter `vector_limit` is used to truncate large vectors.
52+
Appends the nested structure of element in a nice format to the `io` buffer for `element`.
53+
The parameter `indent` tracks the indentation level, the parameter `vector_limit` is used
54+
to truncate large vectors and `show_the_n_last_elements` specifies how many of the last elements to show.
3255
"""
3356
function print_nested_structure!(
34-
element,
35-
io::IOBuffer;
36-
indent::Int64 = 0,
37-
vector_limit::Int64 = typemax(Int64),
38-
show_the_n_last_elements::Int64 = 3,
57+
element::Any,
58+
io::IOBuffer,
59+
indent::Int64,
60+
vector_limit::Int64,
61+
show_the_n_last_elements::Int64,
3962
)
40-
if indent == 0
41-
type = typeof(element)
42-
if isa(element, Dict) || isa(element, Vector)
43-
println(io, type)
63+
indent += 1
64+
indent_str::String = create_indent_string(indent)
65+
for field1 fieldnames(typeof(element))
66+
value1 = getfield(element, field1)
67+
if isa(value1, Expandable)
68+
println(io, indent_str, field1, " (", typeof(value1), "):")
69+
print_nested_structure!(
70+
value1,
71+
io,
72+
indent,
73+
vector_limit,
74+
show_the_n_last_elements,
75+
)
4476
else
45-
println(io, element, " (", type, ")")
77+
if isa(value1, OperationalProfile) &&
78+
!isa(value1, FixedProfile) &&
79+
length(value1.vals) > vector_limit
80+
# Truncate large vectors
81+
println(io, indent_str, field1, ": ", typeof(value1))
82+
else
83+
println(io, indent_str, field1, ": ", value1)
84+
end
4685
end
4786
end
87+
return nothing
88+
end
89+
function print_nested_structure!(
90+
element::Dict,
91+
io::IOBuffer,
92+
indent::Int64,
93+
vector_limit::Int64,
94+
show_the_n_last_elements::Int64,
95+
)
4896
indent += 1
49-
indent_str::String = " "^indent
50-
expandable::Union = Union{
51-
Vector,
52-
Dict,
53-
EMB.Node,
54-
Resource,
55-
Link,
56-
TimeStructure,
57-
Data,
58-
AbstractInvData,
59-
Investment,
60-
LifetimeMode,
61-
TimeProfile,
62-
}
63-
if isa(element, Vector)
64-
if eltype(element) <: expandable
65-
for (i, field1) enumerate(element)
66-
if i == vector_limit + 1
67-
println(io, indent_str, "...")
68-
continue
69-
end
70-
if i <= vector_limit || i > length(element) - show_the_n_last_elements
71-
type = typeof(field1)
72-
if isa(field1, expandable)
73-
println(io, indent_str, i, " (", type, "):")
74-
print_nested_structure!(field1, io; indent, vector_limit)
75-
else
76-
println(io, indent_str, i, ": ", type, "(", field1, ")")
77-
end
78-
end
79-
end
97+
indent_str::String = create_indent_string(indent)
98+
for field1 keys(element)
99+
if isa(element[field1], Expandable)
100+
println(io, indent_str, field1, " (", typeof(element[field1]), "):")
101+
print_nested_structure!(
102+
element[field1],
103+
io,
104+
indent,
105+
vector_limit,
106+
show_the_n_last_elements,
107+
)
80108
else
81-
print(io, indent_str, "[")
82-
for (i, field1) enumerate(element)
83-
if i == vector_limit + 1
84-
print(io, " ... ")
85-
continue
86-
end
87-
if i <= vector_limit || i > length(element) - show_the_n_last_elements
88-
print(io, field1)
89-
if i != length(element)
90-
print(io, ", ")
91-
end
92-
end
93-
end
94-
println(io, "]")
109+
println(io, indent_str, field1, " => ", element[field1])
110+
end
111+
end
112+
end
113+
function print_nested_structure!(
114+
element::Vector{T},
115+
io::IOBuffer,
116+
indent::Int64,
117+
vector_limit::Int64,
118+
show_the_n_last_elements::Int64,
119+
) where {T<:Expandable}
120+
indent += 1
121+
indent_str::String = create_indent_string(indent)
122+
for (i, field1) enumerate(element)
123+
if i == vector_limit + 1
124+
println(io, indent_str, "...")
125+
continue
95126
end
96-
elseif isa(element, Dict)
97-
for field1 keys(element)
98-
if isa(element[field1], expandable)
99-
println(io, indent_str, field1, " (", typeof(element[field1]), "):")
100-
print_nested_structure!(element[field1], io; indent, vector_limit)
127+
if i <= vector_limit || i > length(element) - show_the_n_last_elements
128+
type = typeof(field1)
129+
if isa(field1, Expandable)
130+
println(io, indent_str, i, " (", type, "):")
131+
print_nested_structure!(
132+
field1,
133+
io,
134+
indent,
135+
vector_limit,
136+
show_the_n_last_elements,
137+
)
101138
else
102-
println(io, indent_str, field1, " => ", element[field1])
139+
println(io, indent_str, i, ": ", type, "(", field1, ")")
103140
end
104141
end
105-
else
106-
for field1 fieldnames(typeof(element))
107-
value1 = getfield(element, field1)
108-
if isa(value1, expandable)
109-
println(io, indent_str, field1, " (", typeof(value1), "):")
110-
print_nested_structure!(value1, io; indent, vector_limit)
111-
else
112-
if isa(value1, OperationalProfile) &&
113-
!isa(value1, FixedProfile) &&
114-
length(value1.vals) > vector_limit
115-
# Truncate large vectors
116-
println(io, indent_str, field1, ": ", typeof(value1))
117-
else
118-
println(io, indent_str, field1, ": ", value1)
119-
end
142+
end
143+
return nothing
144+
end
145+
function print_nested_structure!(
146+
element::Vector{T},
147+
io::IOBuffer,
148+
indent::Int64,
149+
vector_limit::Int64,
150+
show_the_n_last_elements::Int64,
151+
) where {T}
152+
indent += 1
153+
indent_str::String = create_indent_string(indent)
154+
print(io, indent_str, "[")
155+
156+
for (i, field1) enumerate(element)
157+
if i == vector_limit + 1
158+
print(io, " ... ")
159+
continue
160+
end
161+
if i <= vector_limit || i > length(element) - show_the_n_last_elements
162+
print(io, field1)
163+
if i != length(element)
164+
print(io, ", ")
120165
end
121166
end
122167
end
168+
println(io, "]")
169+
return nothing
123170
end

0 commit comments

Comments
 (0)