-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimeline.tcl
More file actions
287 lines (240 loc) · 11.5 KB
/
Copy pathtimeline.tcl
File metadata and controls
287 lines (240 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# Copyright (c) 2022-2024 Nicolas ROBERT.
# Distributed under MIT license. Please see LICENSE for details.
#
namespace eval ticklecharts {}
# timeline class, which provides functions like switching and playing
# between multiple ECharts options.
oo::class create ticklecharts::timeline {
variable _h ; # huddle
variable _data ; # list data value
variable _charts ; # list charts
variable _opts ; # list options timeline
variable _baseOption ; # list base options timeline
variable _options ; # list charts options timeline
variable _jschartvar ; # js variable chart
constructor {args} {
# Initializes a new timeline Class.
#
# args - Options described below.
#
# -theme - name theme see : theme.tcl
#
ticklecharts::setTheme $args ; # theme options
set _data {}
set _charts {}
set _opts {}
set _baseOption {}
set _options {}
}
}
oo::define ticklecharts::timeline {
method getType {} {
# Returns type.
return "timeline"
}
method charts {} {
# Gets list charts.
return $_charts
}
method baseOption {} {
# Gets list base options.
return $_baseOption
}
method track {} {
# Compares properties.
#
# Returns nothing
foreach chart [my charts] {
$chart track
}
return {}
}
method SetOptions {args} {
# options : https://echarts.apache.org/en/option.html#timeline
#
# args - Options described in proc ticklecharts::timelineOpts below.
#
# Returns nothing
if {[llength $args] % 2} {
error "wrong # args: [self] SetOptions \$args must have\
an even number of elements."
}
set _opts {}
lappend _opts "@L=timeline" [ticklecharts::timelineOpts $args]
return {}
}
method Add {chart args} {
# Add data dict to timeline options.
#
# Returns nothing
if {![llength $args]} {
error "wrong # args: 'timeline' arguments should not be equal\
to 0 for the 'Add' method."
}
if {[$chart getType] ni {chart chart3D gridlayout}} {
error "wrong # args: First argument for 'Add' method\
should be a 'chart', 'chart3D' or 'gridlayout' class."
}
lappend _data [ticklecharts::timelineItem $args]
lappend _charts $chart
return {}
}
method ToHuddle {} {
# Transform list to ehudlle.
#
# Returns nothing
# init ehuddle.
set _h [ticklecharts::ehuddle new]
# timeline data
set key [lindex $_opts 0]
set dataopts [lindex $_opts 1]
# Insert data to timeline options
lappend timeline_opts $key [linsert \
$dataopts end {*}[format "-data {{%s} list.o}" $_data] \
]
# Retrieves global option keys and deletes them.
set optsglob [ticklecharts::globalOptions {}]
set keysoptsglob [dict keys [ticklecharts::optsToEchartsHuddle [$optsglob get]]]
# Add keys from 'SetOptions' ticklecharts::chart* method
foreach class {"chart" "chart3D"} {
lappend infomethod [lindex [ticklecharts::classDef $class SetOptions] 1]
}
foreach linebody [split $infomethod "\n"] {
if {[string match {*@*} $linebody]} {
set keyopts [lindex $linebody 2]
set hType [string range $keyopts 0 2]
if {$hType in {@D= @L=}} {
lappend keysoptsglob $keyopts
}
}
}
# Gets the first chart.
set optschart [[lindex [my charts] 0] options]
# Removes keys global for 'baseOption'.
set _baseOption {}
foreach {key value} $optschart {
if {$key in $keysoptsglob} {
continue
}
lappend _baseOption $key $value
}
# Add 'timeline' options to huddle 'baseOption'.
foreach {key value} $timeline_opts {
set f [ticklecharts::optsToEchartsHuddle $value]
lappend _baseOption $key [list {*}$f]
}
# Add 'baseOption' key.
$_h append "@L=baseOption" $_baseOption
# Add all charts to 'option' key.
set _options {}
foreach chart [my charts] {
set option {}
foreach {key value} [$chart options] {
lappend option $key $value
}
$_h append "@D=options" $option
lappend _options $option
}
return {}
}
# Copy shared methods definition from 'ticklecharts::chart' class :
#
# Render - Export timeline html.
# toHTML - Export chart as HTML fragment.
# toJSON - Returns json timeline data.
# get - Gets huddle object.
# options - Gets chart(s) list options.
# ...
foreach method {Render toHTML toJSON get options} {
method $method {*}[ticklecharts::classDef "chart" $method]
}
# export of methods
export Add SetOptions Render
}
proc ticklecharts::timelineOpts {value} {
# timeline options.
#
# Returns dict options
setdef options -show -minversion 5 -validvalue {} -type bool -default "True"
setdef options -type -minversion 5 -validvalue formatTimelineType -type str -default "slider"
setdef options -axisType -minversion 5 -validvalue formatTimelineAxisType -type str -default "time"
setdef options -currentIndex -minversion 5 -validvalue {} -type num|null -default "nothing"
setdef options -autoPlay -minversion 5 -validvalue {} -type bool|null -default "nothing"
setdef options -rewind -minversion 5 -validvalue {} -type bool|null -default "nothing"
setdef options -loop -minversion 5 -validvalue {} -type bool -default "True"
setdef options -playInterval -minversion 5 -validvalue {} -type num -default 1000
setdef options -realtime -minversion 5 -validvalue {} -type bool -default "True"
setdef options -replaceMerge -minversion 5 -validvalue formatTimelineMerge -type str|list.s|null -default "nothing"
setdef options -controlPosition -minversion 5 -validvalue formatTimelinePosition -type str -default "left"
setdef options -width -minversion 5 -validvalue {} -type num|null -default "nothing"
setdef options -zlevel -minversion 5 -validvalue {} -type num|null -default "nothing"
setdef options -z -minversion 5 -validvalue {} -type num -default 2
setdef options -left -minversion 5 -validvalue formatLeft -type str|num|null -default "nothing"
setdef options -top -minversion 5 -validvalue formatTop -type str|num|null -default "nothing"
setdef options -right -minversion 5 -validvalue formatRight -type str|num|null -default "nothing"
setdef options -bottom -minversion 5 -validvalue formatBottom -type str|num|null -default "nothing"
setdef options -padding -minversion 5 -validvalue {} -type num|list.n -default 5
setdef options -orient -minversion 5 -validvalue formatOrient -type str -default "horizontal"
setdef options -inverse -minversion 5 -validvalue {} -type bool|null -default "nothing"
setdef options -itemSymbol -minversion 5 -validvalue formatItemSymbol -type str|null -default "emptyCircle"
setdef options -symbolSize -minversion 5 -validvalue {} -type num|list.n -default 10
setdef options -symbolRotate -minversion 5 -validvalue {} -type num|null -default "nothing"
setdef options -symbolKeepAspect -minversion 5 -validvalue {} -type bool|null -default "nothing"
setdef options -symbolOffset -minversion 5 -validvalue {} -type list.n|null -default "nothing"
setdef options -lineStyle -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::lineStyle $value]
setdef options -label -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::label $value]
setdef options -itemStyle -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::itemStyle $value]
setdef options -checkpointStyle -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::checkPointStyle $value]
setdef options -controlStyle -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::controlStyle $value]
setdef options -progress -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::progress $value]
setdef options -emphasis -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::emphasis $value]
#...
# remove key(s)...
set value [dict remove $value -lineStyle -label -itemStyle \
-checkpointStyle -controlStyle \
-progress -emphasis]
set options [merge $options $value]
return $options
}
proc ticklecharts::timelineItem {value} {
# timeline item options.
#
# Returns dict options
if {[llength $value] % 2} {
ticklecharts::errorEvenArgs
}
if {![dict exists $value -data]} {
error "wrong # args: Property '-data' not defined for\
'[ticklecharts::getLevelProperties [info level]]'"
}
set d [dict get $value -data]
if {![dict exists $d value]} {
ticklecharts::errorKeyArgs -data value
}
# Force string value for this key below.
set typeOf [ticklecharts::typeOf [dict get $d value]]
if {$typeOf ni {str str.e}} {
dict set d value [new estr [dict get $d value]]
}
setdef options value -minversion 5 -validvalue {} -type str|null -default "nothing"
setdef options symbol -minversion 5 -validvalue formatItemSymbol -type str|null -default "nothing"
setdef options symbolSize -minversion 5 -validvalue {} -type num|null -default "nothing"
setdef options tooltip -minversion 5 -validvalue {} -type dict|null -default [ticklecharts::tooltip $d]
# remove key(s)...
set d [dict remove $d tooltip]
set options [merge $options $d]
return [new edict $options]
}
proc ticklecharts::istimelineClass {value} {
# Check if value is timeline class.
#
# value - obj or string
#
# Returns true if 'value' is a timeline class,
# false otherwise.
return [expr {
[ticklecharts::isAObject $value] &&
[string match "*::timeline" [ticklecharts::typeOfClass $value]]
}
]
}