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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
|
#
# tkextlib/tcllib/plotchart.rb
# by Hidetoshi NAGAI ([email protected])
#
# * Part of tcllib extension
# * Simple plotting and charting package
#
# (The following is the original description of the library.)
#
# Plotchart is a Tcl-only package that focuses on the easy creation of
# xy-plots, barcharts and other common types of graphical presentations.
# The emphasis is on ease of use, rather than flexibility. The procedures
# that create a plot use the entire canvas window, making the layout of the
# plot completely automatic.
#
# This results in the creation of an xy-plot in, say, ten lines of code:
# --------------------------------------------------------------------
# package require Plotchart
#
# canvas .c -background white -width 400 -height 200
# pack .c -fill both
#
# #
# # Create the plot with its x- and y-axes
# #
# set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
#
# foreach {x y} {0.0 32.0 10.0 50.0 25.0 60.0 78.0 11.0 } {
# $s plot series1 $x $y
# }
#
# $s title "Data series"
# --------------------------------------------------------------------
#
# A drawback of the package might be that it does not do any data management.
# So if the canvas that holds the plot is to be resized, the whole plot must
# be redrawn. The advantage, though, is that it offers a number of plot and
# chart types:
#
# * XY-plots like the one shown above with any number of data series.
# * Stripcharts, a kind of XY-plots where the horizontal axis is adjusted
# automatically. The result is a kind of sliding window on the data
# series.
# * Polar plots, where the coordinates are polar instead of cartesian.
# * Isometric plots, where the scale of the coordinates in the two
# directions is always the same, i.e. a circle in world coordinates
# appears as a circle on the screen.
# You can zoom in and out, as well as pan with these plots (Note: this
# works best if no axes are drawn, the zooming and panning routines do
# not distinguish the axes), using the mouse buttons with the control
# key and the arrow keys with the control key.
# * Piecharts, with automatic scaling to indicate the proportions.
# * Barcharts, with either vertical or horizontal bars, stacked bars or
# bars side by side.
# * Timecharts, where bars indicate a time period and milestones or other
# important moments in time are represented by triangles.
# * 3D plots (both for displaying surfaces and 3D bars)
#
require 'tk'
require 'tkextlib/tcllib.rb'
# TkPackage.require('Plotchart', '0.9')
# TkPackage.require('Plotchart', '1.1')
TkPackage.require('Plotchart')
module Tk
module Tcllib
module Plotchart
PACKAGE_NAME = 'Plotchart'.freeze
def self.package_name
PACKAGE_NAME
end
def self.package_version
begin
TkPackage.require('Plotchart')
rescue
''
end
end
end
end
end
module Tk::Tcllib::Plotchart
extend TkCore
############################
def self.view_port(w, *args) # args := pxmin, pymin, pxmax, pymax
tk_call_without_enc('::Plotchart::viewPort', w.path, *(args.flatten))
end
def self.world_coordinates(w, *args) # args := xmin, ymin, xmax, ymax
tk_call_without_enc('::Plotchart::worldCoordinates',
w.path, *(args.flatten))
end
def self.world_3D_coordinates(w, *args)
# args := xmin, ymin, zmin, xmax, ymax, zmax
tk_call_without_enc('::Plotchart::world3DCoordinates',
w.path, *(args.flatten))
end
def self.coords_to_pixel(w, x, y)
list(tk_call_without_enc('::Plotchart::coordsToPixel', w.path, x, y))
end
def self.coords_3D_to_pixel(w, x, y, z)
list(tk_call_without_enc('::Plotchart::coords3DToPixel', w.path, x, y, z))
end
def self.polar_coordinates(w, radmax)
tk_call_without_enc('::Plotchart::polarCoordinates', w.path, radmax)
end
def self.polar_to_pixel(w, rad, phi)
list(tk_call_without_enc('::Plotchart::polarToPixel', w.path, rad, phi))
end
def self.pixel_to_coords(w, x, y)
list(tk_call_without_enc('::Plotchart::coordsToPixel', w.path, x, y))
end
def self.determine_scale(w, xmax, ymax)
tk_call_without_enc('::Plotchart::determineScale', w.path, xmax, ymax)
end
def self.set_zoom_pan(w)
tk_call_without_enc('::Plotchart::setZoomPan', w.path)
end
############################
module ChartMethod
include TkCore
def title(str)
tk_call_without_enc(@chart, 'title', _get_eval_enc_str(str))
self
end
def save_plot(filename)
tk_call_without_enc(@chart, 'saveplot', filename)
self
end
def xtext(str)
tk_call_without_enc(@chart, 'xtext', _get_eval_enc_str(str))
self
end
def ytext(str)
tk_call_without_enc(@chart, 'ytext', _get_eval_enc_str(str))
self
end
def xconfig(key, value=None)
if key.kind_of?(Hash)
tk_call_without_enc(@chart, 'xconfig', *hash_kv(key, true))
else
tk_call_without_enc(@chart, 'xconfig',
"-#{key}", _get_eval_enc_str(value))
end
self
end
def yconfig(key, value=None)
if key.kind_of?(Hash)
tk_call_without_enc(@chart, 'yconfig', *hash_kv(key, true))
else
tk_call_without_enc(@chart, 'yconfig',
"-#{key}", _get_eval_enc_str(value))
end
self
end
############################
def view_port(*args) # args := pxmin, pymin, pxmax, pymax
tk_call_without_enc('::Plotchart::viewPort', @path, *(args.flatten))
self
end
def world_coordinates(*args) # args := xmin, ymin, xmax, ymax
tk_call_without_enc('::Plotchart::worldCoordinates',
@path, *(args.flatten))
self
end
def world_3D_coordinates(*args)
# args := xmin, ymin, zmin, xmax, ymax, zmax
tk_call_without_enc('::Plotchart::world3DCoordinates',
@path, *(args.flatten))
self
end
def coords_to_pixel(x, y)
list(tk_call_without_enc('::Plotchart::coordsToPixel', @path, x, y))
end
def coords_3D_to_pixel(x, y, z)
list(tk_call_without_enc('::Plotchart::coords3DToPixel', @path, x, y, z))
end
def polar_coordinates(radmax)
tk_call_without_enc('::Plotchart::polarCoordinates', @path, radmax)
self
end
def polar_to_pixel(rad, phi)
list(tk_call_without_enc('::Plotchart::polarToPixel', @path, rad, phi))
end
def pixel_to_coords(x, y)
list(tk_call_without_enc('::Plotchart::coordsToPixel', @path, x, y))
end
def determine_scale(xmax, ymax)
tk_call_without_enc('::Plotchart::determineScale', @path, xmax, ymax)
self
end
def set_zoom_pan()
tk_call_without_enc('::Plotchart::setZoomPan', @path)
self
end
end
############################
class XYPlot < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createXYPlot'.freeze
].freeze
def initialize(*args) # args := ([parent,] xaxis, yaxis [, keys])
# xaxis := Array of [minimum, maximum, stepsize]
# yaxis := Array of [minimum, maximum, stepsize]
if args[0].kind_of?(Array)
@xaxis = args.shift
@yaxis = args.shift
super(*args) # create canvas widget
else
parent = args.shift
@xaxis = args.shift
@yaxis = args.shift
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
array2tk_list(@xaxis), array2tk_list(@yaxis))
end
private :_create_chart
def __destroy_hook__
Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
end
def plot(series, x, y)
tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(series), x, y)
self
end
def contourlines(xcrd, ycrd, vals, clss=None)
xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
vals = array2tk_list(vals) if vals.kind_of?(Array)
clss = array2tk_list(clss) if clss.kind_of?(Array)
tk_call_without_enc(@chart, 'contourlines', xcrd, ycrd, vals, clss)
self
end
def contourfill(xcrd, ycrd, vals, klasses=None)
xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
vals = array2tk_list(vals) if vals.kind_of?(Array)
clss = array2tk_list(clss) if clss.kind_of?(Array)
tk_call_without_enc(@chart, 'contourfill', xcrd, ycrd, vals, clss)
self
end
def contourbox(xcrd, ycrd, vals, klasses=None)
xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
vals = array2tk_list(vals) if vals.kind_of?(Array)
clss = array2tk_list(clss) if clss.kind_of?(Array)
tk_call_without_enc(@chart, 'contourbox', xcrd, ycrd, vals, clss)
self
end
def color_map(colors)
colors = array2tk_list(colors) if colors.kind_of?(Array)
tk_call_without_enc(@chart, 'colorMap', colors)
self
end
def grid_cells(xcrd, ycrd)
xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
tk_call_without_enc(@chart, 'grid', xcrd, ycrd)
self
end
def dataconfig(series, key, value=None)
if key.kind_of?(Hash)
tk_call_without_enc(@chart, 'dataconfig', series, *hash_kv(key, true))
else
tk_call_without_enc(@chart, 'dataconfig', series,
"-#{key}", _get_eval_enc_str(value))
end
end
end
############################
class Stripchart < XYPlot
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createStripchart'.freeze
].freeze
end
############################
class PolarPlot < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createPolarplot'.freeze
].freeze
def initialize(*args) # args := ([parent,] radius_data [, keys])
# radius_data := Array of [maximum_radius, stepsize]
if args[0].kind_of?(Array)
@radius_data = args.shift
super(*args) # create canvas widget
else
parent = args.shift
@radius_data = args.shift
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
array2tk_list(@radius_data))
end
private :_create_chart
def __destroy_hook__
Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
end
def plot(series, radius, angle)
tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(series),
radius, angle)
self
end
def dataconfig(series, key, value=None)
if key.kind_of?(Hash)
tk_call_without_enc(@chart, 'dataconfig', series, *hash_kv(key, true))
else
tk_call_without_enc(@chart, 'dataconfig', series,
"-#{key}", _get_eval_enc_str(value))
end
end
end
Polarplot = PolarPlot
############################
class IsometricPlot < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createIsometricPlot'.freeze
].freeze
def initialize(*args) # args := ([parent,] xaxis, yaxis, [, step] [, keys])
# xaxis := Array of [minimum, maximum]
# yaxis := Array of [minimum, maximum]
# step := Float of stepsize | "noaxes" | :noaxes
if args[0].kind_of?(Array)
@xaxis = args.shift
@yaxis = args.shift
if args[0].kind_of?(Hash)
@stepsize = :noaxes
else
@stepsize = args.shift
end
super(*args) # create canvas widget
else
parent = args.shift
@xaxis = args.shift
@yaxis = args.shift
if args[0].kind_of?(Hash)
@stepsize = :noaxes
else
@stepsize = args.shift
end
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
array2tk_list(@xaxis), array2tk_list(@yaxis),
@stepsize)
end
private :_create_chart
def plot(type, *args)
self.__send__("plot_#{type.to_s.tr('-', '_')}", *args)
end
def plot_rectangle(*args) # args := x1, y1, x2, y2, color
tk_call_without_enc(@chart, 'plot', 'rectangle', *(args.flatten))
self
end
def plot_filled_rectangle(*args) # args := x1, y1, x2, y2, color
tk_call_without_enc(@chart, 'plot', 'filled-rectangle', *(args.flatten))
self
end
def plot_circle(*args) # args := xc, yc, radius, color
tk_call_without_enc(@chart, 'plot', 'circle', *(args.flatten))
self
end
def plot_filled_circle(*args) # args := xc, yc, radius, color
tk_call_without_enc(@chart, 'plot', 'filled-circle', *(args.flatten))
self
end
end
Isometricplot = IsometricPlot
############################
class Plot3D < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::create3DPlot'.freeze
].freeze
def initialize(*args) # args := ([parent,] xaxis, yaxis, zaxis [, keys])
# xaxis := Array of [minimum, maximum, stepsize]
# yaxis := Array of [minimum, maximum, stepsize]
# zaxis := Array of [minimum, maximum, stepsize]
if args[0].kind_of?(Array)
@xaxis = args.shift
@yaxis = args.shift
@zaxis = args.shift
super(*args) # create canvas widget
else
parent = args.shift
@xaxis = args.shift
@yaxis = args.shift
@zaxis = args.shift
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
array2tk_list(@xaxis),
array2tk_list(@yaxis),
array2tk_list(@zaxis))
end
private :_create_chart
def plot_function(cmd=Proc.new)
Tk.ip_eval("proc #{@path}_#{@chart} {x y} {#{install_cmd(cmd)} $x $y}")
tk_call_without_enc(@chart, 'plotfunc', "#{@path}_#{@chart}")
self
end
def plot_funcont(conts, cmd=Proc.new)
conts = array2tk_list(conts) if conts.kind_of?(Array)
Tk.ip_eval("proc #{@path}_#{@chart} {x y} {#{install_cmd(cmd)} $x $y}")
tk_call_without_enc(@chart, 'plotfuncont', "#{@path}_#{@chart}", conts)
self
end
def grid_size(nxcells, nycells)
tk_call_without_enc(@chart, 'gridsize', nxcells, nycells)
self
end
def plot_data(dat)
# dat has to be provided as a 2 level array.
# 1st level contains rows, drawn in y-direction,
# and each row is an array whose elements are drawn in x-direction,
# for the columns.
tk_call_without_enc(@chart, 'plotdata', dat)
self
end
def colour(fill, border)
# configure the colours to use for polygon borders and inner area
tk_call_without_enc(@chart, 'colour', fill, border)
self
end
alias colours colour
alias colors colour
alias color colour
end
############################
class Piechart < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createPiechart'.freeze
].freeze
def initialize(*args) # args := ([parent] [, keys])
if args[0].kind_of?(Tk::Canvas)
parent = args.shift
@path = parent.path
else
super(*args) # create canvas widget
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path)
end
private :_create_chart
def plot(*dat) # argument is a list of [label, value]
tk_call_without_enc(@chart, 'plot', dat.flatten)
self
end
end
############################
class Barchart < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createBarchart'.freeze
].freeze
def initialize(*args)
# args := ([parent,] xlabels, ylabels [, series] [, keys])
# xlabels, ylabels := labels | axis ( depend on normal or horizontal )
# labels := Array of [label, label, ...]
# (It determines the number of bars that will be plotted per series.)
# axis := Array of [minimum, maximum, stepsize]
# series := Integer number of data series | 'stacked' | :stacked
if args[0].kind_of?(Array)
@xlabels = args.shift
@ylabels = args.shift
if args[0].kind_of?(Hash)
@series_size = :stacked
else
@series_size = args.shift
end
super(*args) # create canvas widget
else
parent = args.shift
@xlabels = args.shift
@ylabels = args.shift
if args[0].kind_of?(Hash)
@series_size = :stacked
else
@series_size = args.shift
end
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
array2tk_list(@xlabels), array2tk_list(@ylabels),
@series_size)
end
private :_create_chart
def __destroy_hook__
Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path)
end
def plot(series, dat, col=None)
tk_call_without_enc(@chart, 'plot', series, dat, col)
self
end
def colours(*cols)
# set the colours to be used
tk_call_without_enc(@chart, 'colours', *cols)
self
end
alias colour colours
alias colors colours
alias color colours
end
############################
class HorizontalBarchart < Barchart
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createHorizontalBarchart'.freeze
].freeze
end
############################
class Timechart < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createTimechart'.freeze
].freeze
def initialize(*args)
# args := ([parent,] time_begin, time_end, items [, keys])
# time_begin := String of time format (e.g. "1 january 2004")
# time_end := String of time format (e.g. "1 january 2004")
# items := Expected/maximum number of items
# ( This determines the vertical spacing. )
if args[0].kind_of?(String)
@time_begin = args.shift
@time_end = args.shift
@items = args.shift
super(*args) # create canvas widget
else
parent = args.shift
@time_begin = args.shift
@time_end = args.shift
@items = args.shift
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
@time_begin, @time_end, @items)
end
private :_create_chart
def period(txt, time_begin, time_end, col=None)
tk_call_without_enc(@chart, 'period', txt, time_begin, time_end, col)
self
end
def milestone(txt, time, col=None)
tk_call_without_enc(@chart, 'milestone', txt, time, col)
self
end
def vertline(txt, time)
tk_call_without_enc(@chart, 'vertline', txt, time)
self
end
end
############################
class Gnattchart < Tk::Canvas
include ChartMethod
TkCommandNames = [
'canvas'.freeze,
'::Plotchart::createGnattchart'.freeze
].freeze
def initialize(*args)
# args := ([parent,] time_begin, time_end, items [, text_width] [, keys])
# time_begin := String of time format (e.g. "1 january 2004")
# time_end := String of time format (e.g. "1 january 2004")
# items := Expected/maximum number of items
# ( This determines the vertical spacing. )
if args[0].kind_of?(String)
@time_begin = args.shift
@time_end = args.shift
@items = args.shift
if args[0].kind_of?(Fixnum)
@text_width = args.shift
else
@text_width = None
end
super(*args) # create canvas widget
else
parent = args.shift
@time_begin = args.shift
@time_end = args.shift
@items = args.shift
if args[0].kind_of?(Fixnum)
@text_width = args.shift
else
@text_width = None
end
if parent.kind_of?(Tk::Canvas)
@path = parent.path
else
super(parent, *args) # create canvas widget
end
end
@chart = _create_chart
end
def _create_chart
p self.class::TkCommandNames[1] if $DEBUG
tk_call_without_enc(self.class::TkCommandNames[1], @path,
@time_begin, @time_end, @items, @text_width)
end
private :_create_chart
def task(txt, time_begin, time_end, completed=0.0)
list(tk_call_without_enc(@chart, 'task', txt, time_begin, time_end,
completed)).collect!{|id|
TkcItem.id2obj(self, id)
}
end
def milestone(txt, time, col=None)
tk_call_without_enc(@chart, 'milestone', txt, time, col)
self
end
def vertline(txt, time)
tk_call_without_enc(@chart, 'vertline', txt, time)
self
end
def connect(from_task, to_task)
from_task = array2tk_list(from_task) if from_task.kind_of?(Array)
to_task = array2tk_list(to_task) if to_task.kind_of?(Array)
tk_call_without_enc(@chart, 'connect', from_task, to_task)
self
end
def summary(txt, tasks)
tasks = array2tk_list(tasks) if tasks.kind_of?(Array)
tk_call_without_enc(@chart, 'summary', tasks)
self
end
def color_of_part(keyword, newcolor)
tk_call_without_enc(@chart, 'color', keyword, newcolor)
self
end
def font_of_part(keyword, newfont)
tk_call_without_enc(@chart, 'font', keyword, newfont)
self
end
end
############################
class PlotSeries < TkObject
SeriesID_TBL = TkCore::INTERP.create_table
Series_ID = ['series'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ SeriesID_TBL.clear }
def self.id2obj(chart, id)
path = chart.path
return id unless SeriesID_TBL[path]
SeriesID_TBL[path][id]? SeriesID_TBL[path][id]: id
end
def initialize(chart, keys=nil)
@parent = @chart_obj = chart
@ppath = @chart_obj.path
@path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_)
# SeriesID_TBL[@id] = self
SeriesID_TBL[@ppath] = {} unless SeriesID_TBL[@ppath]
SeriesID_TBL[@ppath][@id] = self
Series_ID[1].succ!
dataconfig(keys) if keys.kind_of?(Hash)
end
def plot(*args)
@chart_obj.plot(@series, *args)
end
def dataconfig(key, value=None)
@chart_obj.dataconfig(@series, key, value)
end
end
end
|