-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.py
1801 lines (1651 loc) · 52.8 KB
/
grid.py
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
#!/usr/bin/env python3
import re
import sys
import cairo
import gtk
## DataRange class
class DataRange:
## @var start
# start
## @var end
# end
## @var value
# value
def __init__(self, start=0, end=0, value=""):
"""! Initializer
@param self this object
@param start start
@param end end
@param value value
"""
self.start = start
self.end = end
self.value = value
## EventString class
class EventString:
## @var at
# at
## @var value
# value
def __init__(self, at=0, value=""):
"""! Initializer
@param self this object
@param at you
@param value value
"""
self.at = at
self.value = value
## EventFloat class
class EventFloat:
## @var at
# at
## @var value
# value
def __init__(self, at=0, value=0.0):
"""! Initializer
@param self this object
@param at you
@param value value
"""
self.at = at
self.value = value
## EventInt class
class EventInt:
## @var at
# at
## @var value
# value
def __init__(self, at=0, value=0.0):
"""! Initializer
@param self this object
@param at you
@param value value
"""
self.at = at
self.value = value
def ranges_cmp(a, b):
diff = a.start - b.start
if diff < 0:
return -1
elif diff > 0:
return +1
else:
return 0
def events_cmp(a, b):
diff = a.at - b.at
if diff < 0:
return -1
elif diff > 0:
return +1
else:
return 0
## TimelineDataRange
class TimelineDataRange:
## @var name
# name
## @var ranges
# ranges
def __init__(self, name=""):
"""! Initializer
@param self this object
@param name name
"""
self.name = name
self.ranges = []
return
def __search(self, key):
"""! Search
@param self this object
@param key key
@return index if found or -1 if not found
"""
l = 0
u = len(self.ranges) - 1
while l <= u:
i = int((l + u) / 2)
if key >= self.ranges[i].start and key <= self.ranges[i].end:
return i
elif key < self.ranges[i].start:
u = i - 1
else:
# key > self.ranges[i].end
l = i + 1
return -1
def add_range(self, range):
"""! Add range
@param self this object
@param range range
@return none
"""
self.ranges.append(range)
def get_all(self):
"""! Get all ranges
@param self this object
@return the ranges
"""
return self.ranges
def get_ranges(self, start, end):
"""! Get selected ranges
@param self this object
@param start range start
@param end range end
@return the range or and empty list
"""
s = self.__search(start)
e = self.__search(end)
if s == -1 and e == -1:
return []
elif s == -1:
return self.ranges[0 : e + 1]
elif e == -1:
return self.ranges[s : len(self.ranges)]
else:
return self.ranges[s : e + 1]
def get_ranges_bounds(self, start, end):
"""! Get ranges bounds
@param self this object
@param start range start
@param end range end
@return range
"""
s = self.__search(start)
e = self.__search(end)
if s == -1 and e == -1:
return (0, 0)
elif s == -1:
return (0, e + 1)
elif e == -1:
return (s, len(self.ranges))
else:
return (s, e + 1)
def sort(self):
"""! Sort ranges
@param self this object
@return none
"""
self.ranges.sort(ranges_cmp)
def get_bounds(self):
"""! Get bounds
@param self this object
@return the bounds
"""
if len(self.ranges) > 0:
lo = self.ranges[0].start
hi = self.ranges[len(self.ranges) - 1].end
return (lo, hi)
else:
return (0, 0)
## TimelineEvent class
class TimelineEvent:
## @var name
# name
## @var events
# events
def __init__(self, name=""):
"""! Get ranges bounds
@param self this object
@param name name
"""
self.name = name
self.events = []
def __search(self, key):
"""! Search function
@param self this object
@param key the key
@return event index
"""
l = 0
u = len(self.events) - 1
while l <= u:
i = int((l + u) / 2)
if key == self.events[i].at:
return i
elif key < self.events[i].at:
u = i - 1
else:
# key > self.events[i].at
l = i + 1
return l
def add_event(self, event):
"""! Add Event
@param self this object
@param event event to add
@return none
"""
self.events.append(event)
def get_events(self, start, end):
"""! Get Events
@param self this object
@param start starting event
@param end ending event
@return the events
"""
s = self.__search(start)
e = self.__search(end)
return self.events[s : e + 1]
def get_events_bounds(self, start, end):
"""! Get Events Bounds
@param self this object
@param start starting event
@param end ending event
@return event bounds
"""
s = self.__search(start)
e = self.__search(end)
return (s, e + 1)
def sort(self):
"""! Sort function
@param self this object
@return none
"""
self.events.sort(events_cmp)
def get_bounds(self):
"""! Get Bounds
@param self this object
@return the bounds
"""
if len(self.events) > 0:
lo = self.events[0].at
hi = self.events[-1].at
return (lo, hi)
else:
return (0, 0)
## Timeline class
class Timeline:
## @var name
# name
## @var ranges
# ranges
## @var event_str
# event string
## @var event_int
# event int
def __init__(self, name=""):
"""! Initializer
@param self this object
@param name name
"""
self.ranges = []
self.event_str = []
self.event_int = []
self.name = name
def get_range(self, name):
"""! Get range
@param self this object
@param name name
@return the range
"""
for range in self.ranges:
if range.name == name:
return range
timeline = TimelineDataRange(name)
self.ranges.append(timeline)
return timeline
def get_event_str(self, name):
"""! Get Event String
@param self this object
@param name name
@return the event string
"""
for event_str in self.event_str:
if event_str.name == name:
return event_str
timeline = TimelineEvent(name)
self.event_str.append(timeline)
return timeline
def get_event_int(self, name):
"""! Get Event Int
@param self this object
@param name name
@return eevent int
"""
for event_int in self.event_int:
if event_int.name == name:
return event_int
timeline = TimelineEvent(name)
self.event_int.append(timeline)
return timeline
def get_ranges(self):
"""! Get Ranges
@param self this object
@return the ranges
"""
return self.ranges
def get_events_str(self):
"""! Get Events string
@param self this object
@return event string
"""
return self.event_str
def get_events_int(self):
"""! Get Events int
@param self this object
@return evrnt int
"""
return self.event_int
def sort(self):
"""! Sort the ranges and events
@param self this object
@return none
"""
for range in self.ranges:
range.sort()
for event in self.event_int:
event.sort()
for event in self.event_str:
event.sort()
def get_bounds(self):
"""! Get Bounds
@param self this object
@return the bounds
"""
lo = 0
hi = 0
for range in self.ranges:
(range_lo, range_hi) = range.get_bounds()
if range_lo < lo:
lo = range_lo
if range_hi > hi:
hi = range_hi
for event_str in self.event_str:
(ev_lo, ev_hi) = event_str.get_bounds()
if ev_lo < lo:
lo = ev_lo
if ev_hi > hi:
hi = ev_hi
for event_int in self.event_int:
(ev_lo, ev_hi) = event_int.get_bounds()
if ev_lo < lo:
lo = ev_lo
if ev_hi > hi:
hi = ev_hi
return (lo, hi)
## Timelines class
class Timelines:
## @var timelines
# timelines
def __init__(self):
"""Initializer
@param self: this object
"""
self.timelines = []
def get(self, name):
"""! Get Timeline
@param self this object
@param name name
@return the timeline for the name
"""
for timeline in self.timelines:
if timeline.name == name:
return timeline
timeline = Timeline(name)
self.timelines.append(timeline)
return timeline
def get_all(self):
"""! Get All Timeline
@param self this object
@return all timelines
"""
return self.timelines
def sort(self):
"""! Sort the timelines
@param self this object
@return none
"""
for timeline in self.timelines:
timeline.sort()
def get_bounds(self):
"""! Get Bounds
@param self this object
@return the bounds for all timelines
"""
lo = 0
hi = 0
for timeline in self.timelines:
(t_lo, t_hi) = timeline.get_bounds()
if t_lo < lo:
lo = t_lo
if t_hi > hi:
hi = t_hi
return (lo, hi)
def get_all_range_values(self):
"""! Get All Ranges
@param self this object
@return the keys for all ranges
"""
range_values = {}
for timeline in self.timelines:
for ranges in timeline.get_ranges():
for ran in ranges.get_all():
range_values[ran.value] = 1
return range_values.keys()
## Color class
class Color:
## @var r
# red
## @var g
# green
## @var b
# blue
def __init__(self, r=0.0, g=0.0, b=0.0):
"""! Initializer
@param self: this object
@param r: red
@param g: green
@param b: blue
"""
self.r = r
self.g = g
self.b = b
def set(self, r, g, b):
"""! Set color
@param self: this object
@param r: red
@param g: green
@param b: blue
@return none
"""
self.r = r
self.g = g
self.b = b
## Colors class
class Colors:
## @var __colors
# colors
## @var default_colors
# default colors
## XXX add more
default_colors = [
Color(1, 0, 0),
Color(0, 1, 0),
Color(0, 0, 1),
Color(1, 1, 0),
Color(1, 0, 1),
Color(0, 1, 1),
]
def __init__(self):
"""! Initializer
@param self this object
"""
self.__colors = {}
def add(self, name, color):
"""! Add
@param self this object
@param name name of the color
@param color color value
@return none
"""
self.__colors[name] = color
def lookup(self, name):
"""! Lookup name
@param self this object
@param name name
@return named color
"""
if not self.__colors.has_key(name):
self.add(name, self.default_colors.pop())
return self.__colors.get(name)
## TopLegendRenderer class
class TopLegendRenderer:
## @var __padding
# padding
## @var __legends
# legends
## @var __colors
# colors
## @var __width
# width
## @var __height
# height
def __init__(self):
"""! Initializer
@param self this object
"""
self.__padding = 10
def set_padding(self, padding):
"""! Set padding
@param self this object
@param padding padding
@return none
"""
self.__padding = padding
def set_legends(self, legends, colors):
"""! Set padding
@param self this object
@param legends legends
@param colors colors
@return none
"""
self.__legends = legends
self.__colors = colors
def layout(self, width):
"""! Set padding
@param self this object
@param width width
@return none
"""
self.__width = width
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
ctx = cairo.Context(surface)
line_height = 0
total_height = self.__padding
line_used = self.__padding
for legend in self.__legends:
(t_width, t_height) = ctx.text_extents(legend)[2:4]
item_width = self.__padding + self.__padding + t_width + self.__padding
item_height = t_height + self.__padding
if item_height > line_height:
line_height = item_height
if line_used + item_width > self.__width:
line_used = self.__padding + item_width
total_height += line_height
else:
line_used += item_width
x = line_used - item_width
total_height += line_height
self.__height = total_height
def get_height(self):
"""! Set padding
@param self this object
@return height
"""
return self.__height
def draw(self, ctx):
"""! Set padding
@param self this object
@param ctx ctx
@return none
"""
i = 0
line_height = 0
total_height = self.__padding
line_used = self.__padding
for legend in self.__legends:
(t_width, t_height) = ctx.text_extents(legend)[2:4]
item_width = self.__padding + self.__padding + t_width + self.__padding
item_height = t_height + self.__padding
if item_height > line_height:
line_height = item_height
if line_used + item_width > self.__width:
line_used = self.__padding + item_width
total_height += line_height
else:
line_used += item_width
x = line_used - item_width
ctx.rectangle(x, total_height, self.__padding, self.__padding)
ctx.set_source_rgb(0, 0, 0)
ctx.set_line_width(2)
ctx.stroke_preserve()
ctx.set_source_rgb(self.__colors[i].r, self.__colors[i].g, self.__colors[i].b)
ctx.fill()
ctx.move_to(x + self.__padding * 2, total_height + t_height)
ctx.set_source_rgb(0, 0, 0)
ctx.show_text(legend)
i += 1
## TimelinesRenderer class
class TimelinesRenderer:
## @var padding
# padding
## @var timelines
# timelines
## @var colors
# colors
## @var start
# start
## @var end
# end
## @var left_width
# left width
## @var right_width
# right width
## @var max_text_height
# maximum text height
## @var width
# width
## @var height
# height
## @var grey_background
# grey background
def __init__(self):
"""! Initializer
@param self this object
"""
self.padding = 10
return
def get_height(self):
"""! Get Height
@param self this object
@return height
"""
return self.height
def set_timelines(self, timelines, colors):
"""! Set Timelines
@param self this object
@param timelines timelines
@param colors colors
@return none
"""
self.timelines = timelines
self.colors = colors
def set_render_range(self, start, end):
"""! Set Render Range
@param self this object
@param start start
@param end end
@return none
"""
self.start = start
self.end = end
def get_data_x_start(self):
"""! Get Data X Start
@param self: this object
@return X start
"""
return (
self.padding / 2 + self.left_width + self.padding + self.right_width + self.padding / 2
)
def layout(self, width):
"""! Get Data X Start
@param self this object
@param width width
@return none
"""
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
ctx = cairo.Context(surface)
max_text_height = ctx.text_extents(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789"
)[3]
left_width = 0
right_width = 0
left_n_lines = 0
range_n = 0
eventint_n = 0
eventstr_n = 0
for timeline in self.timelines.get_all():
left_n_lines += 1
t_width = ctx.text_extents(timeline.name)[2]
left_width = max(left_width, t_width)
for rang in timeline.get_ranges():
t_width = ctx.text_extents(rang.name)[2]
right_width = max(right_width, t_width)
range_n += 1
for events_int in timeline.get_events_int():
t_width = ctx.text_extents(events_int.name)[2]
right_width = max(right_width, t_width)
eventint_n += 1
for events_str in timeline.get_events_str():
t_width = ctx.text_extents(events_str.name)[2]
right_width = max(right_width, t_width)
eventstr_n += 1
left_height = left_n_lines * max_text_height + (left_n_lines - 1) * self.padding
right_n_lines = range_n + eventint_n + eventstr_n
right_height = (right_n_lines - 1) * self.padding + right_n_lines * max_text_height
right_data_height = (eventint_n + eventstr_n) * (max_text_height + 5) + range_n * 10
right_data_height += (right_n_lines - 1) * self.padding
height = max(left_height, right_height)
height = max(height, right_data_height)
self.left_width = left_width
self.right_width = right_width
self.max_text_height = max_text_height
self.width = width
self.height = height + self.padding
def draw_line(self, ctx, x, y, width, height):
"""! Draw Line
@param self this object
@param ctx ctx
@param x x
@param y y
@param width width
@param height height
@return none
"""
ctx.move_to(x, y)
ctx.rel_line_to(width, height)
ctx.close_path()
ctx.set_operator(cairo.OPERATOR_SOURCE)
ctx.set_line_width(1.0)
ctx.set_source_rgb(0, 0, 0)
ctx.stroke()
def draw_events(self, ctx, events, x, y, width, height):
"""! Draw Event
@param self this object
@param ctx ctx
@param events events
@param x x
@param y y
@param width width
@param height height
@return none
"""
if (self.grey_background % 2) == 0:
ctx.rectangle(x, y - self.padding / 2, width, height + self.padding)
ctx.set_source_rgb(0.9, 0.9, 0.9)
ctx.fill()
last_x_drawn = int(x)
(lo, hi) = events.get_events_bounds(self.start, self.end)
for event in events.events[lo:hi]:
real_x = int(x + (event.at - self.start) * width / (self.end - self.start))
if real_x > last_x_drawn + 2:
ctx.rectangle(real_x, y, 1, 1)
ctx.set_source_rgb(1, 0, 0)
ctx.stroke()
ctx.move_to(real_x, y + self.max_text_height)
ctx.set_source_rgb(0, 0, 0)
ctx.show_text(str(event.value))
last_x_drawn = real_x
self.grey_background += 1
def draw_ranges(self, ctx, ranges, x, y, width, height):
"""! Draw Ranges
@param self this object
@param ctx ctx
@param ranges ranges
@param x x
@param y y
@param width width
@param height height
@return none
"""
if (self.grey_background % 2) == 0:
ctx.rectangle(x, y - self.padding / 2, width, height + self.padding)
ctx.set_source_rgb(0.9, 0.9, 0.9)
ctx.fill()
last_x_drawn = int(x - 1)
(lo, hi) = ranges.get_ranges_bounds(self.start, self.end)
for data_range in ranges.ranges[lo:hi]:
s = max(data_range.start, self.start)
e = min(data_range.end, self.end)
x_start = int(x + (s - self.start) * width / (self.end - self.start))
x_end = int(x + (e - self.start) * width / (self.end - self.start))
if x_end > last_x_drawn:
ctx.rectangle(x_start, y, x_end - x_start, 10)
ctx.set_source_rgb(0, 0, 0)
ctx.stroke_preserve()
color = self.colors.lookup(data_range.value)
ctx.set_source_rgb(color.r, color.g, color.b)
ctx.fill()
last_x_drawn = x_end
self.grey_background += 1
def draw(self, ctx):
"""! Draw
@param self this object
@param ctx ctx
@return none
"""
timeline_top = 0
top_y = self.padding / 2
left_x_start = self.padding / 2
left_x_end = left_x_start + self.left_width
right_x_start = left_x_end + self.padding
right_x_end = right_x_start + self.right_width
data_x_start = right_x_end + self.padding / 2
data_x_end = self.width
data_width = data_x_end - data_x_start
cur_y = top_y
self.draw_line(ctx, 0, 0, self.width, 0)
self.grey_background = 1
for timeline in self.timelines.get_all():
(y_bearing, t_width, t_height) = ctx.text_extents(timeline.name)[1:4]
ctx.move_to(left_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
ctx.show_text(timeline.name)
for events_int in timeline.get_events_int():
(y_bearing, t_width, t_height) = ctx.text_extents(events_int.name)[1:4]
ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
ctx.show_text(events_int.name)
self.draw_events(
ctx, events_int, data_x_start, cur_y, data_width, self.max_text_height + 5
)
cur_y += self.max_text_height + 5 + self.padding
self.draw_line(
ctx,
right_x_start - self.padding / 2,
cur_y - self.padding / 2,
self.right_width + self.padding,
0,
)
for events_str in timeline.get_events_str():
(y_bearing, t_width, t_height) = ctx.text_extents(events_str.name)[1:4]
ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
ctx.show_text(events_str.name)
self.draw_events(
ctx, events_str, data_x_start, cur_y, data_width, self.max_text_height + 5
)
cur_y += self.max_text_height + 5 + self.padding
self.draw_line(
ctx,
right_x_start - self.padding / 2,
cur_y - self.padding / 2,
self.right_width + self.padding,
0,
)
for ranges in timeline.get_ranges():
(y_bearing, t_width, t_height) = ctx.text_extents(ranges.name)[1:4]
ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing))
ctx.show_text(ranges.name)
self.draw_ranges(ctx, ranges, data_x_start, cur_y, data_width, 10)
cur_y += self.max_text_height + self.padding
self.draw_line(
ctx,
right_x_start - self.padding / 2,
cur_y - self.padding / 2,
self.right_width + self.padding,
0,
)
self.draw_line(ctx, 0, cur_y - self.padding / 2, self.width, 0)
bot_y = cur_y - self.padding / 2
self.draw_line(ctx, left_x_end + self.padding / 2, 0, 0, bot_y)
self.draw_line(ctx, right_x_end + self.padding / 2, 0, 0, bot_y)
## ScaleRenderer class
class ScaleRenderer:
## @var __top
# top
## @var __lo
# lo
## @var __hi
# hi
## @var __delta
# delta
## @var __width
# width
## @var __height
# height
## @var max_text_height
# maximum text height
def __init__(self):
"""! Initializer
@param self this object
"""
self.__top = 0
return
def set_bounds(self, lo, hi):
"""! Set Bounds
@param self this object
@param lo lo
@param hi hi
@return none
"""
self.__lo = lo
self.__hi = hi
def get_position(self, x):
"""! Get Position
@param self this object
@param x x
@return real x
"""
real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo)
return real_x
def set_top(self):
"""! Set Top
@param self this object
@return none
"""
self.__top = 1
def set_bot(self):
"""! Set Bottom
@param self this object
@return none
"""
self.__top = 0
def layout(self, width):
"""! Layout
@param self this object
@param width width
@return none
"""
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
ctx = cairo.Context(surface)
# calculate scale delta
data_delta = self.__hi - self.__lo
closest = 1
while (closest * 10) < data_delta:
closest *= 10
if (data_delta / closest) == 0:
delta = closest
elif (data_delta / closest) == 1:
delta = closest / 10
else:
delta = closest
start = self.__lo - (self.__lo % delta) + delta
end = self.__hi - (self.__hi % delta)
self.__delta = delta
self.__width = width