/
component.rb
2218 lines (2014 loc) · 59.8 KB
/
component.rb
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# tkextlib/blt/component.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module PlotComponent
include TkItemConfigMethod
module OptKeys
def __item_font_optkeys(id)
['font', 'tickfont', 'titlefont']
end
private :__item_font_optkeys
def __item_numstrval_optkeys(id)
['xoffset', 'yoffset']
end
private :__item_numstrval_optkeys
def __item_boolval_optkeys(id)
['hide', 'under', 'descending', 'logscale', 'loose', 'showticks',
'titlealternate', 'scalesymbols', 'minor', 'raised',
'center', 'decoration', 'landscape', 'maxpect']
end
private :__item_boolval_optkeys
def __item_strval_optkeys(id)
['text', 'label', 'limits', 'title',
'show', 'file', 'maskdata', 'maskfile',
'color', 'titlecolor', 'fill', 'outline', 'offdash']
end
private :__item_strval_optkeys
def __item_listval_optkeys(id)
['bindtags']
end
private :__item_listval_optkeys
def __item_numlistval_optkeys(id)
['dashes', 'majorticks', 'minorticks']
end
private :__item_numlistval_optkeys
def __item_tkvariable_optkeys(id)
['variable', 'textvariable', 'colormap', 'fontmap']
end
private :__item_tkvariable_optkeys
end
include OptKeys
def __item_cget_cmd(id)
if id.kind_of?(Array)
# id := [ type, name ]
[self.path, id[0], 'cget', id[1]]
else
[self.path, id, 'cget']
end
end
private :__item_cget_cmd
def __item_config_cmd(id)
if id.kind_of?(Array)
# id := [ type, name, ... ]
type, *names = id
[self.path, type, 'configure'].concat(names)
else
[self.path, id, 'configure']
end
end
private :__item_config_cmd
def __item_pathname(id)
if id.kind_of?(Array)
id = tagid(id[1])
end
[self.path, id].join(';')
end
private :__item_pathname
def axis_cget_tkstring(id, option)
ret = itemcget_tkstring(['axis', tagid(id)], option)
end
def axis_cget(id, option)
ret = itemcget(['axis', tagid(id)], option)
end
def axis_cget_strict(id, option)
ret = itemcget_strict(['axis', tagid(id)], option)
end
def axis_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
value = None
slot = _symbolkey2str(slot)
if cmd = slot.delete('command')
slot['command'] = proc{|w, tick|
cmd.call(TkComm.window(w), TkComm.num_or_str(tick))
}
end
else
value = slot
slot = args.pop
if slot == :command || slot == 'command'
cmd = value
value = proc{|w, tick|
cmd.call(TkComm.window(w), TkComm.num_or_str(tick))
}
end
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('axis')
itemconfigure(id_list, slot, value)
end
def axis_configinfo(id, slot=nil)
itemconfiginfo(['axis', tagid(id)], slot)
end
def current_axis_configinfo(id, slot=nil)
current_itemconfiginfo(['axis', tagid(id)], slot)
end
def crosshairs_cget_tkstring(option)
itemcget_tkstring('crosshairs', option)
end
def crosshairs_cget(option)
itemcget('crosshairs', option)
end
def crosshairs_cget_strict(option)
itemcget_strict('crosshairs', option)
end
def crosshairs_configure(slot, value=None)
itemconfigure('crosshairs', slot, value)
end
def crosshairs_configinfo(slot=nil)
itemconfiginfo('crosshairs', slot)
end
def current_crosshairs_configinfo(slot=nil)
current_itemconfiginfo('crosshairs', slot)
end
def element_cget_tkstring(id, option)
itemcget_tkstring(['element', tagid(id)], option)
end
def element_cget(id, option)
itemcget(['element', tagid(id)], option)
end
def element_cget_strict(id, option)
itemcget_strict(['element', tagid(id)], option)
end
def element_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('element')
itemconfigure(id_list, slot, value)
end
def element_configinfo(id, slot=nil)
itemconfiginfo(['element', tagid(id)], slot)
end
def current_element_configinfo(id, slot=nil)
current_itemconfiginfo(['element', tagid(id)], slot)
end
def bar_cget_tkstring(id, option)
itemcget_tkstring(['bar', tagid(id)], option)
end
def bar_cget(id, option)
itemcget(['bar', tagid(id)], option)
end
def bar_cget_strict(id, option)
itemcget_strict(['bar', tagid(id)], option)
end
def bar_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('bar')
itemconfigure(id_list, slot, value)
end
def bar_configinfo(id, slot=nil)
itemconfiginfo(['bar', tagid(id)], slot)
end
def current_bar_configinfo(id, slot=nil)
current_itemconfiginfo(['bar', tagid(id)], slot)
end
def line_cget_tkstring(id, option)
itemcget_tkstring(['line', tagid(id)], option)
end
def line_cget(id, option)
itemcget(['line', tagid(id)], option)
end
def line_cget_strict(id, option)
itemcget_strict(['line', tagid(id)], option)
end
def line_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('line')
itemconfigure(id_list, slot, value)
end
def line_configinfo(id, slot=nil)
itemconfiginfo(['line', tagid(id)], slot)
end
def current_line_configinfo(id, slot=nil)
current_itemconfiginfo(['line', tagid(id)], slot)
end
def gridline_cget_tkstring(option)
itemcget_tkstring('grid', option)
end
def gridline_cget(option)
itemcget('grid', option)
end
def gridline_cget_strict(option)
itemcget_strict('grid', option)
end
def gridline_configure(slot, value=None)
itemconfigure('grid', slot, value)
end
def gridline_configinfo(slot=nil)
itemconfiginfo('grid', slot)
end
def current_gridline_configinfo(slot=nil)
current_itemconfiginfo('grid', slot)
end
def legend_cget_tkstring(option)
itemcget_tkstring('legend', option)
end
def legend_cget(option)
itemcget('legend', option)
end
def legend_cget_strict(option)
itemcget_strict('legend', option)
end
def legend_configure(slot, value=None)
itemconfigure('legend', slot, value)
end
def legend_configinfo(slot=nil)
itemconfiginfo('legend', slot)
end
def current_legend_configinfo(slot=nil)
current_itemconfiginfo('legend', slot)
end
def pen_cget_tkstring(id, option)
itemcget_tkstring(['pen', tagid(id)], option)
end
def pen_cget(id, option)
itemcget(['pen', tagid(id)], option)
end
def pen_cget_strict(id, option)
itemcget_strict(['pen', tagid(id)], option)
end
def pen_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('pen')
itemconfigure(id_list, slot, value)
end
def pen_configinfo(id, slot=nil)
itemconfiginfo(['pen', tagid(id)], slot)
end
def current_pen_configinfo(id, slot=nil)
current_itemconfiginfo(['pen', tagid(id)], slot)
end
def postscript_cget_tkstring(option)
itemcget_tkstring('postscript', option)
end
def postscript_cget(option)
itemcget('postscript', option)
end
def postscript_cget_strict(option)
itemcget_strict('postscript', option)
end
def postscript_configure(slot, value=None)
itemconfigure('postscript', slot, value)
end
def postscript_configinfo(slot=nil)
itemconfiginfo('postscript', slot)
end
def current_postscript_configinfo(slot=nil)
current_itemconfiginfo('postscript', slot)
end
def marker_cget_tkstring(id, option)
itemcget_tkstring(['marker', tagid(id)], option)
end
def marker_cget(id, option)
itemcget(['marker', tagid(id)], option)
end
def marker_cget_strict(id, option)
itemcget_strict(['marker', tagid(id)], option)
end
def marker_configure(*args)
slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('marker')
itemconfigure(id_list, slot, value)
end
def marker_configinfo(id, slot=nil)
itemconfiginfo(['marker', tagid(id)], slot)
end
def current_marker_configinfo(id, slot=nil)
current_itemconfiginfo(['marker', tagid(id)], slot)
end
alias __itemcget_tkstring itemcget_tkstring
alias __itemcget itemcget
alias __itemcget_strict itemcget_strict
alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo
private :__itemcget_tkstring, :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo
def itemcget_tkstring(tagOrId, option)
__itemcget_tkstring(tagid(tagOrId), option)
end
def itemcget_strict(tagOrId, option)
ret = __itemcget(tagid(tagOrId), option)
if option == 'bindtags' || option == :bindtags
ret.collect{|tag| TkBindTag.id2obj(tag)}
else
ret
end
end
def itemcget(tagOrId, option)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
itemcget_strict(tagOrId, option)
else
begin
itemcget_strict(tagOrId, option)
rescue => e
begin
if current_itemconfiginfo(tagOrId).has_key?(option.to_s)
# error on known option
fail e
else
# unknown option
nil
end
rescue
fail e # tag error
end
end
end
end
def itemconfiginfo(tagOrId, slot = nil)
ret = __itemconfiginfo(tagid(tagOrId), slot)
if TkComm::GET_CONFIGINFO_AS_ARRAY
if slot
if slot == 'bindtags' || slot == :bindtags
ret[-2] = ret[-2].collect{|tag| TkBindTag.id2obj(tag)}
ret[-1] = ret[-1].collect{|tag| TkBindTag.id2obj(tag)}
end
else
if (inf = ret.assoc('bindtags'))
inf[-2] = inf[-2].collect{|tag| TkBindTag.id2obj(tag)}
inf[-1] = inf[-1].collect{|tag| TkBindTag.id2obj(tag)}
end
end
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
if (inf = ret['bindtags'])
inf[-2] = inf[-2].collect{|tag| TkBindTag.id2obj(tag)}
inf[-1] = inf[-1].collect{|tag| TkBindTag.id2obj(tag)}
ret['bindtags'] = inf
end
end
ret
end
def current_itemconfiginfo(tagOrId, slot = nil)
ret = __current_itemconfiginfo(tagid(tagOrId), slot)
if (val = ret['bindtags'])
ret['bindtags'] = val.collect{|tag| TkBindTag.id2obj(tag)}
end
ret
end
private :itemcget_tkstring, :itemcget, :itemcget_strict
private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################
class Axis < TkObject
(OBJ_ID = ['blt_chart_axis'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
AxisID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
AxisID_TBL.mutex.synchronize{ AxisID_TBL.clear }
}
def self.id2obj(chart, id)
cpath = chart.path
AxisID_TBL.mutex.synchronize{
return id unless AxisID_TBL[cpath]
AxisID_TBL[cpath][id]? AxisID_TBL[cpath][id]: id
}
end
def self.new(chart, axis=nil, keys={})
if axis.kind_of?(Hash)
keys = axis
axis = nil
end
if keys
keys = _symbolkey2str(keys)
not_create = keys.delete('without_creating')
else
not_create = false
end
obj = nil
AxisID_TBL.mutex.synchronize{
chart_path = chart.path
AxisID_TBL[chart_path] ||= {}
if axis && AxisID_TBL[chart_path][axis]
obj = AxisID_TBL[chart_path][axis]
else
(obj = self.allocate).instance_eval{
if axis
@axis = @id = axis.to_s
else
OBJ_ID.mutex.synchronize{
@axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
Axis::AxisID_TBL[@cpath][@axis] = self
unless not_create
tk_call(@chart, 'axis', 'create', @axis, keys)
return obj
end
}
end
}
obj.configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, axis=nil, keys={})
# dummy:: not called by 'new' method
if axis.kind_of?(Hash)
keys = axis
axis = nil
end
if axis
@axis = @id = axis.to_s
else
OBJ_ID.mutex.synchronize{
@axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
# Axis::AxisID_TBL[@cpath][@axis] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.axis_create(@axis, keys)
tk_call(@chart, 'axis', 'create', @axis, keys)
end
end
def id
@id
end
def to_eval
@id
end
def cget_tkstring(option)
@chart.axis_cget_tkstring(@id, option)
end
def cget(option)
@chart.axis_cget(@id, option)
end
def cget_strict(option)
@chart.axis_cget_strict(@id, option)
end
def configure(key, value=None)
@chart.axis_configure(@id, key, value)
self
end
def configinfo(key=nil)
@chart.axis_configinfo(@id, key)
end
def current_configinfo(key=nil)
@chart.current_axis_configinfo(@id, key)
end
def command(cmd=nil, &b)
if cmd
configure('command', cmd)
elsif b
configure('command', Proc.new(&b))
else
cget('command')
end
end
def delete
@chart.axis_delete(@id)
self
end
def invtransform(val)
@chart.axis_invtransform(@id, val)
end
def limits
@chart.axis_limits(@id)
end
def name
@axis
end
def transform(val)
@chart.axis_transform(@id, val)
end
def view
@chart.axis_view(@id)
self
end
def use(name=None) # if @id == xaxis | x2axis | yaxis | y2axis
@chart.axis_use(@id, name)
end
def use_as(axis) # axis := xaxis | x2axis | yaxis | y2axis
@chart.axis_use(axis, @id)
end
end
#################
class Crosshairs < TkObject
CrosshairsID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
CrosshairsID_TBL.mutex.synchronize{ CrosshairsID_TBL.clear }
}
def self.new(chart, keys={})
obj = nil
CrosshairsID_TBL.mutex.synchronize{
unless (obj = CrosshairsID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'crosshairs'
Crosshairs::CrosshairsID_TBL[@cpath] = self
}
end
}
chart.crosshair_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
# Crosshairs::CrosshairsID_TBL[@cpath] = self
@chart.crosshair_configure(keys) unless keys.empty?
@path = @id = 'crosshairs'
end
def id
@id
end
def to_eval
@id
end
def cget_tkstring(option)
@chart.crosshair_cget_tkstring(option)
end
def cget(option)
@chart.crosshair_cget(option)
end
def cget_strict(option)
@chart.crosshair_cget_strict(option)
end
def configure(key, value=None)
@chart.crosshair_configure(key, value)
self
end
def configinfo(key=nil)
@chart.crosshair_configinfo(key)
end
def current_configinfo(key=nil)
@chart.current_crosshair_configinfo(key)
end
def off
@chart.crosshair_off
self
end
def on
@chart.crosshair_on
self
end
def toggle
@chart.crosshair_toggle
self
end
end
#################
class Element < TkObject
extend Tk
extend TkItemFontOptkeys
extend TkItemConfigOptkeys
extend Tk::BLT::PlotComponent::OptKeys
ElementTypeName = 'element'
ElementTypeToClass = { ElementTypeName=>self }
ElementID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
ElementID_TBL.mutex.synchronize{ ElementID_TBL.clear }
}
(OBJ_ID = ['blt_chart_element'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def Element.type2class(type)
ElementTypeToClass[type]
end
def Element.id2obj(chart, id)
cpath = chart.path
ElementID_TBL.mutex.synchronize{
return id unless ElementID_TBL[cpath]
ElementID_TBL[cpath][id]? ElementID_TBL[cpath][id]: id
}
end
def self.new(chart, element=nil, keys={})
if element.kind_of?(Hash)
keys = element
element = nil
end
if keys
keys = _symbolkey2str(keys)
not_create = keys.delete('without_creating')
else
not_create = false
end
obj = nil
ElementID_TBL.mutex.synchronize{
chart_path = chart.path
ElementID_TBL[chart_path] ||= {}
if element && ElementID_TBL[chart_path][element]
obj = ElementID_TBL[chart_path][element]
else
(obj = self.allocate).instance_eval{
if element
@element = @id = element.to_s
else
OBJ_ID.mutex.synchronize{
@element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
@typename = self.class::ElementTypeName
Element::ElementID_TBL[@cpath][@element] = self
unless not_create
tk_call(@chart, @typename, 'create', @element, keys)
return obj
end
}
end
}
obj.configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, element=nil, keys={})
# dummy:: not called by 'new' method
if element.kind_of?(Hash)
keys = element
element = nil
end
if element
@element = @id = element.to_s
else
OBJ_ID.mutex.synchronize{
@element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
@typename = self.class::ElementTypeName
# Element::ElementID_TBL[@cpath][@element] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.element_create(@element, keys)
tk_call(@chart, @typename, 'create', @element, keys)
end
end
def id
@id
end
def to_eval
@id
end
def cget_tkstring(option)
# @chart.element_cget(@id, option)
@chart.__send__(@typename + '_cget_tkstring', @id, option)
end
def cget(option)
# @chart.element_cget(@id, option)
@chart.__send__(@typename + '_cget', @id, option)
end
def cget_strict(option)
@chart.__send__(@typename + '_cget_strict', @id, option)
end
def configure(key, value=None)
# @chart.element_configure(@id, key, value)
@chart.__send__(@typename + '_configure', @id, key, value)
self
end
def configinfo(key=nil)
# @chart.element_configinfo(@id, key)
@chart.__send__(@typename + '_configinfo', @id, key)
end
def current_configinfo(key=nil)
# @chart.current_element_configinfo(@id, key)
@chart.__send__('current_' << @typename << '_configinfo', @id, key)
end
def activate(*args)
@chart.element_activate(@id, *args)
end
def closest(x, y, var, keys={})
# @chart.element_closest(x, y, var, @id, keys)
@chart.__send__(@typename + '_closest', x, y, var, @id, keys)
end
def deactivate
@chart.element_deactivate(@id)
self
end
def delete
@chart.element_delete(@id)
self
end
def exist?
@chart.element_exist?(@id)
end
def name
@element
end
def type
@chart.element_type(@id)
end
end
class Bar < Element
ElementTypeName = 'bar'.freeze
ElementTypeToClass[ElementTypeName] = self
end
class Line < Element
ElementTypeName = 'line'.freeze
ElementTypeToClass[ElementTypeName] = self
end
#################
class GridLine < TkObject
GridLineID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
GridLineID_TBL.mutex.synchronize{ GridLineID_TBL.clear }
}
def self.new(chart, keys={})
obj = nil
GridLineID_TBL.mutex.synchronize{
unless (obj = GridLineID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'grid'
GridLine::GridLineID_TBL[@cpath] = self
}
end
}
chart.gridline_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
# GridLine::GridLineID_TBL[@cpath] = self
@chart.gridline_configure(keys) unless keys.empty?
@path = @id = 'grid'
end
def id
@id
end
def to_eval
@id
end
def cget_tkstring(option)
@chart.gridline_cget_tkstring(option)
end
def cget(option)
@chart.gridline_cget(option)
end
def cget_strict(option)
@chart.gridline_cget_strict(option)
end
def configure(key, value=None)
@chart.gridline_configure(key, value)
self
end
def configinfo(key=nil)
@chart.gridline_configinfo(key)
end
def current_configinfo(key=nil)
@chart.current_gridline_configinfo(key)
end
def off
@chart.gridline_off
self
end
def on
@chart.gridline_on
self
end
def toggle
@chart.gridline_toggle
self
end
end
#################
class Legend < TkObject
LegendID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
LegendID_TBL.mutex.synchronize{ LegendID_TBL.clear }
}
def self.new(chart, keys={})
obj = nil
LegenedID_TBL.mutex.synchronize{
unless (obj = LegenedID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'crosshairs'
Legend::LegenedID_TBL[@cpath] = self
}
end
}
chart.legend_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
# Legend::LegendID_TBL[@cpath] = self
@chart.legend_configure(keys) unless keys.empty?
@path = @id = 'legend'
end
def id
@id
end
def to_eval
@id
end
def cget_tkstring(option)
@chart.legend_cget_tkstring(option)
end
def cget(option)
@chart.legend_cget(option)
end
def cget_strict(option)
@chart.legend_cget_strict(option)
end
def configure(key, value=None)
@chart.legend_configure(key, value)
self
end
def configinfo(key=nil)
@chart.legend_configinfo(key)
end
def current_configinfo(key=nil)
@chart.current_legend_configinfo(key)
end
def activate(*args)
@chart.legend_activate(*args)
end
def deactivate(*args)
@chart.legend_deactivate(*args)
end
def get(pos, y=nil)
@chart.legend_get(pos, y)
end
end
#################
class Pen < TkObject
(OBJ_ID = ['blt_chart_pen'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
PenID_TBL = TkCore::INTERP.create_table