1 | # This program is under CECILL_B licence. See footer for details. |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | # GRAPH CREATION |
---|
7 | |
---|
8 | proc graph_create { args } { |
---|
9 | set mandatory_arguments { path_father address } |
---|
10 | |
---|
11 | # Initializes the widget |
---|
12 | initWidget |
---|
13 | |
---|
14 | set widgetInfo($address-status) 1 |
---|
15 | set widgetInfo($address-message) "" |
---|
16 | set widgetInfo($address-accepted_keys) {"name" "xtitle" "ytitle" "color" "type"} |
---|
17 | |
---|
18 | ttk::frame $win |
---|
19 | eval $widgetInfo(packme-$win) |
---|
20 | |
---|
21 | set title [dTree_getAttribute $XMLtree $full_address_XML "title"] |
---|
22 | ttk::label $win.lb -text "$title" |
---|
23 | ttk::frame $win.t |
---|
24 | |
---|
25 | pack $win.lb -side top -pady 3 |
---|
26 | pack $win.t -side top -pady {0 5} |
---|
27 | |
---|
28 | set size_v [expr { (0.6)*$widgetInfo(guiSmallWidgetWidth)}] |
---|
29 | set size_h [expr { (1)*$widgetInfo(guiSmallWidgetWidth)}] |
---|
30 | set size [split [dTree_tryGetAttribute $XMLtree $full_address_XML_clean "size" "1;1" ] ";"] |
---|
31 | set size_h [expr {int([lindex $size 1]*1.*$size_h)}] |
---|
32 | set size_v [expr {int([lindex $size 1]*1.*$size_v)}] |
---|
33 | |
---|
34 | set widgetInfo($address-width) $size_h |
---|
35 | set widgetInfo($address-height) $size_v |
---|
36 | set widgetInfo($address-widthcanvas) $size_h |
---|
37 | set widgetInfo($address-heightcanvas) $size_v |
---|
38 | |
---|
39 | |
---|
40 | # graph part |
---|
41 | canvas $win.t.can -yscrollcommand [list $win.t.sby set] -xscrollcommand [list $win.t.sbx set] -width $size_h -height $size_v |
---|
42 | ttk::scrollbar $win.t.sby -orient vertical -command [list $win.t.can yview] |
---|
43 | ttk::scrollbar $win.t.sbx -orient horizontal -command [list $win.t.can xview] |
---|
44 | |
---|
45 | grid $win.t.can -row 1 -column 0 -sticky news |
---|
46 | grid $win.t.sby -row 1 -column 1 -sticky ns |
---|
47 | grid $win.t.sbx -row 2 -column 0 -sticky ew |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | # controls part |
---|
52 | ttk::frame $win.c |
---|
53 | pack $win.c -side top -fill x |
---|
54 | # export csv |
---|
55 | ttk::button $win.c.csv -image icon_clipboard -command [subst { |
---|
56 | clipboard clear |
---|
57 | clipboard append \[graph_var_to_csv $win $address\] |
---|
58 | success "Content of graph copied into clipboard in CSV format." |
---|
59 | }] |
---|
60 | balloon $win.c.csv "Export CSV to clipboard" |
---|
61 | pack $win.c.csv -side left |
---|
62 | |
---|
63 | # export xmgrace |
---|
64 | ttk::button $win.c.xmgr -image icon_graph -command [subst { |
---|
65 | clipboard clear |
---|
66 | clipboard append \[graph_var_to_xmgrace_project $win $address\] |
---|
67 | log "Try to open graph into XMGR" |
---|
68 | }] |
---|
69 | balloon $win.c.xmgr "Open in XMGRACE" |
---|
70 | pack $win.c.xmgr -side left |
---|
71 | |
---|
72 | |
---|
73 | # message label |
---|
74 | ttk::label $win.c.message -textvariable widgetInfo($address-message) |
---|
75 | pack $win.c.message -side left |
---|
76 | |
---|
77 | #add the check/refresh procedure to the bindings of the variable |
---|
78 | |
---|
79 | append widgetInfo($address-refresh) [ subst { graph_refresh $win $address}] |
---|
80 | append widgetInfo($address-check) [subst { graph_check $win $address}] |
---|
81 | finishWidget |
---|
82 | |
---|
83 | #trick? |
---|
84 | bind $win.t.can <ButtonPress-1> {+; focus %W} |
---|
85 | |
---|
86 | bind $win.t.can <Motion> [subst {graph_showlocation $win $address}] |
---|
87 | |
---|
88 | # zoom binding |
---|
89 | #bind $win.t.can <KeyPress-x> [ subst {graph_zoom $address $win 0.8 1.0}] |
---|
90 | #bind $win.t.can <KeyPress-X> [ subst {graph_zoom $address $win 1.2 1.0}] |
---|
91 | #bind $win.t.can <KeyPress-y> [ subst {graph_zoom $address $win 1.0 0.8}] |
---|
92 | #bind $win.t.can <KeyPress-Y> [ subst {graph_zoom $address $win 1.0 1.2}] |
---|
93 | bind $win.t.can <KeyPress-z> [ subst {graph_zoom $address $win 0.8 0.8}] |
---|
94 | bind $win.t.can <KeyPress-Z> [ subst {graph_zoom $address $win 1.2 1.2}] |
---|
95 | |
---|
96 | # ctrl move |
---|
97 | bind $win.t.can <Control-Motion> [ subst {graph_move $win $address %x %y }] |
---|
98 | |
---|
99 | graph_scrollupdate $win $address 1.0 1.0 |
---|
100 | |
---|
101 | # clean the widget callBack on dstruction |
---|
102 | bind $win <Destroy> [ subst {widget_destroy $win $address}] |
---|
103 | |
---|
104 | return $win |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | proc graph_refresh {win address} { |
---|
109 | global widgetInfo |
---|
110 | #$win.t.can create rect 0 0 $widgetInfo($address-widthcanvas) $widgetInfo($address-heightcanvas) -fill white -tags "xscalable yscalable" |
---|
111 | |
---|
112 | $win.t.can delete all |
---|
113 | |
---|
114 | set xmin 1000000000 |
---|
115 | set xmax -1000000000 |
---|
116 | set ymin 1000000000 |
---|
117 | set ymax -1000000000 |
---|
118 | set xtitle "" |
---|
119 | set ytitle "" |
---|
120 | |
---|
121 | # first pass, to get bounds |
---|
122 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
123 | set ds_name [graph_parsecontent $address $dataset name] |
---|
124 | set ds_xtitle [graph_parsecontent $address $dataset xtitle] |
---|
125 | set ds_ytitle [graph_parsecontent $address $dataset ytitle] |
---|
126 | set ds_color [graph_parsecontent $address $dataset color] |
---|
127 | set ds_type [graph_parsecontent $address $dataset type] |
---|
128 | set dsraw [graph_parsecontent $address $dataset raw] |
---|
129 | set ds_length [graph_parsecontent $address $dataset length] |
---|
130 | |
---|
131 | if {$ds_length <= 1} { |
---|
132 | set msg_err "Void datased in graph $address" |
---|
133 | warning $msg_err |
---|
134 | return |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | lappend xtitle $ds_xtitle |
---|
139 | lappend ytitle $ds_ytitle |
---|
140 | |
---|
141 | for {set i 1} {$i <= $ds_length} {incr i} { |
---|
142 | set x [lindex $dsraw [expr {2*$i-2}]] |
---|
143 | set y [lindex $dsraw [expr {2*$i-1}]] |
---|
144 | if {$x>$xmax} {set xmax $x} |
---|
145 | if {$x<$xmin} {set xmin $x} |
---|
146 | if {$y>$ymax} {set ymax $y} |
---|
147 | if {$y<$ymin} {set ymin $y} |
---|
148 | } |
---|
149 | |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | set xtitle [join [lsort -unique $xtitle] ", "] |
---|
154 | set ytitle [join [lsort -unique $ytitle] ", "] |
---|
155 | |
---|
156 | if {$ymin == $ymax} { |
---|
157 | set ymin [expr {$ymin-1.0}] |
---|
158 | set ymax [expr {$ymax+1.0}] |
---|
159 | } |
---|
160 | if {$xmin == $xmax} { |
---|
161 | set xmin [expr {$xmin-1.0}] |
---|
162 | set xmax [expr {$xmax+1.0}] |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | # initialize bounds and scaling |
---|
167 | set widgetInfo($address-xmin) $xmin |
---|
168 | set widgetInfo($address-xmax) $xmax |
---|
169 | set widgetInfo($address-ymin) $ymin |
---|
170 | set widgetInfo($address-ymax) $ymax |
---|
171 | |
---|
172 | set widgetInfo($address-xscale) [expr {0.75 *$widgetInfo($address-widthcanvas) /($widgetInfo($address-xmax)-$widgetInfo($address-xmin))}] |
---|
173 | set widgetInfo($address-yscale) [expr {0.75*$widgetInfo($address-heightcanvas)/($widgetInfo($address-ymax)-$widgetInfo($address-ymin))}] |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | # draw frame an midlines |
---|
179 | set xmin_pix [graph_pix_x $address $xmin] |
---|
180 | set xmax_pix [graph_pix_x $address $xmax] |
---|
181 | set ymin_pix [graph_pix_y $address $ymin] |
---|
182 | set ymax_pix [graph_pix_y $address $ymax] |
---|
183 | set xzero_pix [graph_pix_x $address 0.0] |
---|
184 | set yzero_pix [graph_pix_y $address 0.0] |
---|
185 | |
---|
186 | |
---|
187 | # draw zero axis if any |
---|
188 | if {[expr {$xmin*$xmax}] < 0} { |
---|
189 | $win.t.can create line $xzero_pix $ymin_pix $xzero_pix $ymax_pix -width 2 -fill black -tags "xscalable yscalable axis" |
---|
190 | } |
---|
191 | if {[expr {$ymin*$ymax}] < 0} { |
---|
192 | $win.t.can create line $xmin_pix $yzero_pix $xmax_pix $yzero_pix -width 2 -fill black -tags "xscalable yscalable axis" |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | #$win.t.can create text $xmax_pix $ymin_pix -text "$xmax, $ymin" -anchor "se" -tags "xscalable yscalable" |
---|
197 | #$win.t.can create text $xmin_pix $ymax_pix -text "$xmin, $ymax" -anchor "nw" -tags "xscalable yscalable" |
---|
198 | foreach frac {0 0.2 0.4 0.6 0.8 1.0 } { |
---|
199 | set xfrac [expr {$frac * $xmin + (1.-$frac)*$xmax}] |
---|
200 | set yfrac [expr {$frac * $ymin + (1.-$frac)*$ymax}] |
---|
201 | set xfrac_pix [graph_pix_x $address $xfrac] |
---|
202 | set yfrac_pix [graph_pix_y $address $yfrac] |
---|
203 | $win.t.can create line $xfrac_pix $ymin_pix $xfrac_pix $ymax_pix -fill grey80 -tags "xscalable yscalable axis" |
---|
204 | canvas_text_vector $win.t.can $xfrac_pix $ymin_pix [format %.4g $xfrac] nw 11 45 black "xscalable yscalable axis" |
---|
205 | $win.t.can create line $xmin_pix $yfrac_pix $xmax_pix $yfrac_pix -fill grey80 -tags "xscalable yscalable axis" |
---|
206 | canvas_text_vector $win.t.can $xmin_pix $yfrac_pix [format %.4g $yfrac] sw 11 45 black "xscalable yscalable axis" |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | set xtit [expr {0.5 * $xmin + 0.5*$xmax}] |
---|
211 | set ytit [expr {0.5 * $ymin + 0.5*$ymax}] |
---|
212 | set xtit_pix [graph_pix_x $address $xtit] |
---|
213 | set ytit_pix [graph_pix_y $address $ytit] |
---|
214 | #canvas_text_vector $win.t.can $xtit_pix $ymin_pix "$xtitle" nw 11 45 black "xscalable yscalable axis" |
---|
215 | #canvas_text_vector $win.t.can $xmin_pix $ytit_pix "$ytitle" sw 11 45 black "xscalable yscalable axis" |
---|
216 | |
---|
217 | canvas_text_vector $win.t.can $xmax_pix $ymin_pix "$xtitle" sw 11 -90 black "xscalable yscalable axis" |
---|
218 | canvas_text_vector $win.t.can $xmin_pix $ymax_pix "$ytitle" se 11 0 black "xscalable yscalable axis" |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | # second pass pass, to draw |
---|
223 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
224 | |
---|
225 | set ds_name [graph_parsecontent $address $dataset name] |
---|
226 | set ds_tag [string map {" " "_"} $ds_name] |
---|
227 | set ds_xtitle [graph_parsecontent $address $dataset xtitle] |
---|
228 | set ds_ytitle [graph_parsecontent $address $dataset ytitle] |
---|
229 | set ds_color [graph_parsecontent $address $dataset color] |
---|
230 | set ds_type [graph_parsecontent $address $dataset type] |
---|
231 | set dsraw [graph_parsecontent $address $dataset raw] |
---|
232 | set ds_length [graph_parsecontent $address $dataset length] |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | set ds_rawpix "" |
---|
237 | |
---|
238 | set tags "xscalable yscalable $ds_tag" |
---|
239 | |
---|
240 | for {set i 1} {$i <= $ds_length} {incr i} { |
---|
241 | set shade [expr {1.0*($ds_length-$i)/($ds_length-1)}] |
---|
242 | set x [lindex $dsraw [expr {2*$i-2}]] |
---|
243 | set y [lindex $dsraw [expr {2*$i-1}]] |
---|
244 | set xpix [graph_pix_x $address $x] |
---|
245 | set ypix [graph_pix_y $address $y] |
---|
246 | |
---|
247 | |
---|
248 | # Symbols |
---|
249 | if {"circle" in $ds_type} { |
---|
250 | set h 5 |
---|
251 | $win.t.can create oval [expr {$xpix-$h}] [expr {$ypix-$h}] [expr {$xpix+$h}] [expr {$ypix+$h}] -fill [shadeColor $ds_color $shade] -width 0 -tags $tags -activewidth 3 |
---|
252 | set h 5 |
---|
253 | $win.t.can create oval [expr {$xpix-$h}] [expr {$ypix-$h}] [expr {$xpix+$h}] [expr {$ypix+$h}] -outline $ds_color -tags $tags -activewidth 3 |
---|
254 | } |
---|
255 | if {"square" in $ds_type} { |
---|
256 | set h 5 |
---|
257 | $win.t.can create rectangle [expr {$xpix-$h}] [expr {$ypix-$h}] [expr {$xpix+$h}] [expr {$ypix+$h}] -fill [shadeColor $ds_color $shade] -width 0 -tags $tags -activewidth 3 |
---|
258 | set h 5 |
---|
259 | $win.t.can create rectangle [expr {$xpix-$h}] [expr {$ypix-$h}] [expr {$xpix+$h}] [expr {$ypix+$h}] -outline $ds_color -tags $tags -activewidth 3 |
---|
260 | |
---|
261 | } |
---|
262 | if {"triangle" in $ds_type} { |
---|
263 | set h 5 |
---|
264 | $win.t.can create polygon [expr {$xpix-$h}] [expr {$ypix-$h}] [expr {$xpix+$h}] [expr {$ypix-$h}] [expr {$xpix}] [expr {$ypix+$h}] -fill [shadeColor $ds_color $shade] -width 0 -tags $tags -activewidth 3 |
---|
265 | set h 5 |
---|
266 | $win.t.can create line [expr {$xpix-$h}] [expr {$ypix-$h}] [expr {$xpix+$h}] [expr {$ypix-$h}] [expr {$xpix}] [expr {$ypix+$h}] [expr {$xpix-$h}] [expr {$ypix-$h}] -fill $ds_color -tags $tags -activewidth 3 |
---|
267 | |
---|
268 | } |
---|
269 | if {"diamond" in $ds_type} { |
---|
270 | set h 5 |
---|
271 | $win.t.can create polygon $xpix [expr {$ypix-$h}] [expr {$xpix+$h}] $ypix $xpix [expr {$ypix+$h}] [expr {$xpix-$h}] $ypix -fill [shadeColor $ds_color $shade] -width 0 -tags $tags -activewidth 3 |
---|
272 | set h 5 |
---|
273 | $win.t.can create line $xpix [expr {$ypix-$h}] [expr {$xpix+$h}] $ypix $xpix [expr {$ypix+$h}] [expr {$xpix-$h}] $ypix $xpix [expr {$ypix-$h}] -fill $ds_color -tags $tags -activewidth 3 |
---|
274 | |
---|
275 | } |
---|
276 | # line to zero |
---|
277 | if {"toy0" in $ds_type} { |
---|
278 | $win.t.can create line [expr {$xpix}] [expr {$yzero_pix}] [expr {$xpix}] [expr {$ypix}] -fill $ds_color -tags $tags -activewidth 3 |
---|
279 | } |
---|
280 | |
---|
281 | # labels |
---|
282 | if {"lblall" in $ds_type} { |
---|
283 | canvas_text_vector $win.t.can $xpix $ypix "$x, $y" se 9 45 $ds_color $tags |
---|
284 | } |
---|
285 | |
---|
286 | # line |
---|
287 | if { "line" in $ds_type} { |
---|
288 | lappend ds_rawpix $xpix $ypix |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | #last label |
---|
293 | if {"lbllast" in $ds_type} { |
---|
294 | canvas_text_vector $win.t.can $xpix $ypix "$x, $y" se 9 45 $ds_color $tags |
---|
295 | } |
---|
296 | |
---|
297 | # line |
---|
298 | if {"line" in $ds_type} { |
---|
299 | $win.t.can create line $ds_rawpix -fill $ds_color -width 2 -activewidth 3 -tags $tags |
---|
300 | } |
---|
301 | |
---|
302 | $win.t.can bind $ds_tag <Enter> [subst { |
---|
303 | set widgetInfo($address-message) "Dataset : $ds_name" |
---|
304 | }] |
---|
305 | $win.t.can bind $ds_tag <Leave> [subst {set widgetInfo($address-message) ""}] |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | } |
---|
310 | |
---|
311 | $win.t.can lower "axis" |
---|
312 | |
---|
313 | $win.t.can configure -scrollregion [ $win.t.can bbox all] |
---|
314 | |
---|
315 | smartpacker_update_visibility $win $address |
---|
316 | |
---|
317 | #canvas_makegif $win.t.can "$widgetInfo($address-name).gif" |
---|
318 | |
---|
319 | } |
---|
320 | |
---|
321 | |
---|
322 | proc graph_parsecontent {address curve_data arg} { |
---|
323 | global widgetInfo |
---|
324 | |
---|
325 | set ds [split $curve_data ";"] |
---|
326 | set dsi(name) "no name" |
---|
327 | set dsi(xtitle) "no xtitle" |
---|
328 | set dsi(ytitle) "no ytitle" |
---|
329 | set dsi(color) "black" |
---|
330 | set dsi(type) "circle_line" |
---|
331 | set dsi(raw) "" |
---|
332 | foreach item $ds { |
---|
333 | if {[string match "*=*" $item] == 1} { |
---|
334 | set key [lindex [split $item "="] 0] |
---|
335 | set value [lindex [split $item "="] 1] |
---|
336 | if {$key in $widgetInfo($address-accepted_keys)} { |
---|
337 | set dsi($key) $value |
---|
338 | } else { |
---|
339 | debug "Graph key $key not recognized among $widgetInfo($address-accepted_keys)" |
---|
340 | } |
---|
341 | } else { |
---|
342 | if {[string is double $item]} { |
---|
343 | lappend dsi(raw) $item |
---|
344 | } { |
---|
345 | log "Warning : graph $address ; item $item not understood" |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | set dsi(type) [split $dsi(type) "_"] |
---|
350 | set dsi(length) [expr {0.5*[llength $dsi(raw)]}] |
---|
351 | return $dsi($arg) |
---|
352 | } |
---|
353 | |
---|
354 | proc graph_pix_x { address x } { |
---|
355 | global widgetInfo |
---|
356 | set xpix [expr {($x -$widgetInfo($address-xmin)) * $widgetInfo($address-xscale)}] |
---|
357 | return $xpix |
---|
358 | } |
---|
359 | proc graph_pix_y { address y} { |
---|
360 | global widgetInfo |
---|
361 | set ypix [expr {($widgetInfo($address-ymax) -$y) * $widgetInfo($address-yscale)}] |
---|
362 | return $ypix |
---|
363 | |
---|
364 | } |
---|
365 | proc graph_pix_realx { address xpix} { |
---|
366 | global widgetInfo |
---|
367 | set x [expr {$widgetInfo($address-xmin) + $xpix/$widgetInfo($address-xscale)}] |
---|
368 | return $x |
---|
369 | } |
---|
370 | proc graph_pix_realy { address ypix} { |
---|
371 | global widgetInfo |
---|
372 | set y [expr {$widgetInfo($address-ymax) - $ypix/$widgetInfo($address-yscale)}] |
---|
373 | return $y |
---|
374 | } |
---|
375 | |
---|
376 | proc graph_showlocation {win address} { |
---|
377 | global widgetInfo |
---|
378 | $win.t.can delete "pointer" |
---|
379 | set x [$win.t.can canvasx [expr {[winfo pointerx $win.t.can] - [winfo rootx $win.t.can]}]] |
---|
380 | set y [$win.t.can canvasy [expr {[winfo pointery $win.t.can] - [winfo rooty $win.t.can]}]] |
---|
381 | set realx [graph_pix_realx $address $x ] |
---|
382 | set realy [graph_pix_realy $address $y ] |
---|
383 | set widgetInfo($address-position) "[format %+.4f $realx]\n[format %+.4f $realy]" |
---|
384 | canvas_text_highlighted $win.t.can $x $y $widgetInfo($address-position) "pointer" |
---|
385 | } |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | proc graph_scrollupdate { win address xzoom yzoom} { |
---|
390 | global widgetInfo |
---|
391 | set width $widgetInfo($address-width) |
---|
392 | set height $widgetInfo($address-height) |
---|
393 | set widthcanvas $widgetInfo($address-widthcanvas) |
---|
394 | set heightcanvas $widgetInfo($address-heightcanvas) |
---|
395 | |
---|
396 | set widthcanvas [expr $widthcanvas*$xzoom ] |
---|
397 | set heightcanvas [expr $heightcanvas*$yzoom ] |
---|
398 | |
---|
399 | set widgetInfo($address-widthcanvas) $widthcanvas |
---|
400 | set widgetInfo($address-heightcanvas) $heightcanvas |
---|
401 | |
---|
402 | set scroll_factor_x [expr 1.0/$width*(1.0-$width*1.0/$widthcanvas)] |
---|
403 | if { $width > $widthcanvas} { set scroll_factor_x 0} |
---|
404 | set widgetInfo($address-scroll_factor_x) $scroll_factor_x |
---|
405 | set scroll_factor_y [expr 1.0/$height*(1.0-$height*1.0/$heightcanvas)] |
---|
406 | if { $height > $heightcanvas} { set scroll_factor_y 0} |
---|
407 | set widgetInfo($address-scroll_factor_y) $scroll_factor_y |
---|
408 | |
---|
409 | } |
---|
410 | |
---|
411 | # to move the canvases using Control_move binding |
---|
412 | proc graph_zoom { address win xzoom yzoom} { |
---|
413 | global widgetInfo |
---|
414 | set y0 0 |
---|
415 | set x0 0 |
---|
416 | $win.t.can scale xscalable $x0 $y0 $xzoom 1 |
---|
417 | $win.t.can scale yscalable $x0 $y0 1 $yzoom |
---|
418 | |
---|
419 | set widgetInfo($address-xscale) [expr {$widgetInfo($address-xscale) * $xzoom} ] |
---|
420 | set widgetInfo($address-yscale) [expr {$widgetInfo($address-yscale) * $yzoom} ] |
---|
421 | |
---|
422 | $win.t.can configure -scrollregion [ $win.t.can bbox all] |
---|
423 | graph_scrollupdate $win $address $xzoom $yzoom |
---|
424 | |
---|
425 | } |
---|
426 | |
---|
427 | |
---|
428 | proc graph_var_to_csv {win address} { |
---|
429 | global widgetInfo |
---|
430 | # first pass, to get bounds |
---|
431 | set maxrow 0 |
---|
432 | set col 0 |
---|
433 | set colp1 1 |
---|
434 | |
---|
435 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
436 | |
---|
437 | set ds_name [graph_parsecontent $address $dataset name] |
---|
438 | set ds_xtitle [graph_parsecontent $address $dataset xtitle] |
---|
439 | set ds_ytitle [graph_parsecontent $address $dataset ytitle] |
---|
440 | set dsraw [graph_parsecontent $address $dataset raw] |
---|
441 | set ds_length [graph_parsecontent $address $dataset length] |
---|
442 | |
---|
443 | |
---|
444 | set csv_data(0-$col) $ds_name |
---|
445 | set csv_data(1-$col) $ds_xtitle |
---|
446 | set csv_data(1-$colp1) $ds_ytitle |
---|
447 | set row 2 |
---|
448 | foreach {x y} $dsraw { |
---|
449 | set csv_data($row-$col) $x |
---|
450 | set csv_data($row-$colp1) $y |
---|
451 | incr row |
---|
452 | } |
---|
453 | |
---|
454 | incr col 2 |
---|
455 | incr colp1 2 |
---|
456 | set maxrow [expr {max($row,$maxrow)}] |
---|
457 | |
---|
458 | } |
---|
459 | set result "" |
---|
460 | |
---|
461 | set cell_list [array names csv_data] |
---|
462 | for {set r 0 } {$r < $maxrow } {incr r} { |
---|
463 | set line "" |
---|
464 | for {set c 0 } {$c < $colp1 } {incr c} { |
---|
465 | set cell "$r-$c" |
---|
466 | if {$cell in $cell_list} { |
---|
467 | lappend line $csv_data($cell) |
---|
468 | } else { |
---|
469 | lappend line {} |
---|
470 | } |
---|
471 | } |
---|
472 | set result "$result [join $line ";" ] \n" |
---|
473 | } |
---|
474 | |
---|
475 | array unset csv_data |
---|
476 | return $result |
---|
477 | } |
---|
478 | |
---|
479 | |
---|
480 | proc graph_var_to_xmgrace_project {win address} { |
---|
481 | global widgetInfo |
---|
482 | |
---|
483 | set result "" |
---|
484 | lappend result "# Grace project file" |
---|
485 | lappend result "# " |
---|
486 | lappend result "@with g0" |
---|
487 | lappend result "@ legend on" |
---|
488 | |
---|
489 | |
---|
490 | # first loop to setup the graphs |
---|
491 | set ds_id 0 |
---|
492 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
493 | set ds_name [graph_parsecontent $address $dataset name] |
---|
494 | set ds_xtitle [graph_parsecontent $address $dataset xtitle] |
---|
495 | set ds_ytitle [graph_parsecontent $address $dataset ytitle] |
---|
496 | set ds_color [graph_parsecontent $address $dataset color] |
---|
497 | set ds_type [graph_parsecontent $address $dataset type] |
---|
498 | |
---|
499 | # convert color |
---|
500 | set xm_col 1 |
---|
501 | switch $ds_color { |
---|
502 | "black" { |
---|
503 | set xm_col 1 |
---|
504 | } |
---|
505 | "red" { |
---|
506 | set xm_col 2 |
---|
507 | } |
---|
508 | "blue" { |
---|
509 | set xm_col 4 |
---|
510 | } |
---|
511 | "green4" { |
---|
512 | set xm_col 15 |
---|
513 | } |
---|
514 | } |
---|
515 | # convert symbol |
---|
516 | set xm_sym 0 |
---|
517 | if {"circle" in $ds_type} {set xm_sym 1} |
---|
518 | if {"square" in $ds_type} {set xm_sym 2} |
---|
519 | if {"triangle" in $ds_type} {set xm_sym 6} |
---|
520 | if {"diamond" in $ds_type} {set xm_sym 3} |
---|
521 | |
---|
522 | lappend result "@ xaxis label \"$ds_xtitle\"" |
---|
523 | lappend result "@ yaxis label \"$ds_ytitle\"" |
---|
524 | lappend result "@ s$ds_id symbol $xm_sym" |
---|
525 | lappend result "@ s$ds_id symbol color $xm_col" |
---|
526 | lappend result "@ s$ds_id symbol fill color $xm_col" |
---|
527 | lappend result "@ s$ds_id symbol fill pattern 8" |
---|
528 | lappend result "@ s$ds_id line color $xm_col" |
---|
529 | lappend result "@ s$ds_id baseline off" |
---|
530 | lappend result "@ s$ds_id dropline off" |
---|
531 | lappend result "@ s$ds_id legend \"$ds_name\"" |
---|
532 | |
---|
533 | incr ds_id |
---|
534 | } |
---|
535 | |
---|
536 | # second loop to fill the data |
---|
537 | set ds_id 0 |
---|
538 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
539 | set dsraw [graph_parsecontent $address $dataset raw] |
---|
540 | lappend result "@target G0.S$ds_id" |
---|
541 | lappend result "@type xy" |
---|
542 | foreach {x y} $dsraw { |
---|
543 | lappend result "$x $y" |
---|
544 | } |
---|
545 | lappend result "&" |
---|
546 | incr ds_id |
---|
547 | } |
---|
548 | |
---|
549 | |
---|
550 | set result [join $result "\n"] |
---|
551 | array unset xmgr_data |
---|
552 | set xmgracefile [open "./tmp.agr" w+] |
---|
553 | puts $xmgracefile $result |
---|
554 | close $xmgracefile |
---|
555 | exec_script "xmgrace ./tmp.agr" |
---|
556 | return |
---|
557 | } |
---|
558 | |
---|
559 | |
---|
560 | # to move the canvases using Control_move binding |
---|
561 | proc graph_move { win address x y} { |
---|
562 | global widgetInfo |
---|
563 | set xv [expr $x * $widgetInfo($address-scroll_factor_x)] |
---|
564 | set yv [expr $y * $widgetInfo($address-scroll_factor_y)] |
---|
565 | $win.t.can xview moveto $xv |
---|
566 | $win.t.can yview moveto $yv |
---|
567 | } |
---|
568 | |
---|
569 | |
---|
570 | proc graph_check {win address} { |
---|
571 | global widgetInfo |
---|
572 | |
---|
573 | } |
---|
574 | |
---|
575 | |
---|
576 | |
---|
577 | # Copyright CERFACS 2014 |
---|
578 | # |
---|
579 | # antoine.dauptain@cerfacs.fr |
---|
580 | # |
---|
581 | # This software is a computer program whose purpose is to ensure technology |
---|
582 | # transfer between academia and industry. |
---|
583 | # |
---|
584 | # This software is governed by the CeCILL-B license under French law and |
---|
585 | # abiding by the rules of distribution of free software. You can use, |
---|
586 | # modify and/ or redistribute the software under the terms of the CeCILL-B |
---|
587 | # license as circulated by CEA, CNRS and INRIA at the following URL |
---|
588 | # "http://www.cecill.info". |
---|
589 | # |
---|
590 | # As a counterpart to the access to the source code and rights to copy, |
---|
591 | # modify and redistribute granted by the license, users are provided only |
---|
592 | # with a limited warranty and the software's author, the holder of the |
---|
593 | # economic rights, and the successive licensors have only limited |
---|
594 | # liability. |
---|
595 | # |
---|
596 | # In this respect, the user's attention is drawn to the risks associated |
---|
597 | # with loading, using, modifying and/or developing or reproducing the |
---|
598 | # software by the user in light of its specific status of free software, |
---|
599 | # that may mean that it is complicated to manipulate, and that also |
---|
600 | # therefore means that it is reserved for developers and experienced |
---|
601 | # professionals having in-depth computer knowledge. Users are therefore |
---|
602 | # encouraged to load and test the software's suitability as regards their |
---|
603 | # requirements in conditions enabling the security of their systems and/or |
---|
604 | # data to be ensured and, more generally, to use and operate it in the |
---|
605 | # same conditions as regards security. |
---|
606 | # |
---|
607 | # The fact that you are presently reading this means that you have had |
---|
608 | # knowledge of the CeCILL-B license and that you accept its terms. |
---|