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))
2034end
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"""
3356function 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
123170end
0 commit comments