Changeset 423
- Timestamp:
- 07/27/2011 04:28:20 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SHX/trunk/sandbox/traceplotter.py
r422 r423 20 20 # space for time-scale 21 21 TIMESCALE = 40 22 # offset for time string 23 TIMESCALE_OFFSET_TEXT = 8 24 # length of minor/major ticks 25 TIMESCALE_TICKS_MINOR = 3 26 TIMESCALE_TICKS_MAJOR = 7 22 27 23 28 class Traces(object): … … 689 694 690 695 if self.traceOrder in [0, 1]: 691 PARTS = 5. 692 w = width - MARGIN-STATION_INFO 693 y = height - TIMESCALE + 10 694 sx = STATION_INFO 695 canvas.DrawLine(sx, y, w+STATION_INFO, y) 696 697 chunk = w / PARTS 698 chunk2 = chunk / 5. 699 chunk_t = (end - start) / PARTS 700 for i in range(int(PARTS)): 701 if isinstance(start, UTCDateTime): 702 timecode = start + i*chunk_t 703 txt = timecode.strftime("%H:%M:%S.") + \ 704 str(timecode.microsecond//1000) 705 else: 706 txt = str(start + i*chunk_t) 707 708 tw, _, _, _ = canvas.GetFullTextExtent(txt) 709 x = sx+i*chunk 710 canvas.DrawText(txt, x-tw/2, y+8) 711 canvas.DrawLine(x, y, x, y+7) 712 for j in range(1,5): 713 canvas.DrawLine(x+j*chunk2, y, x+j*chunk2, y+3) 696 PARTS = 5. # axis split into X parts 697 length = width - MARGIN - STATION_INFO # pixel length of time axis 698 fixpos = height - TIMESCALE + 10 # here: y coordinate 699 varpos_start = STATION_INFO # here: x start 714 700 elif self.traceOrder in [2, 3]: 715 701 PARTS = 4. 716 h = height - MARGIN - STATION_INFO717 x = width - TIMESCALE + 10702 length = height - MARGIN - STATION_INFO 703 fixpos = width - TIMESCALE + 10 # here: x coordinate 718 704 if self.traceOrder == 2: 719 sy = MARGIN705 varpos_start = MARGIN # here: y start 720 706 elif self.traceOrder == 3: 721 sy = STATION_INFO 722 canvas.DrawLine(x, sy, x, sy+h) 723 724 chunk = h / PARTS 725 chunk2 = chunk / 5. 726 chunk_t = (end - start) / PARTS 727 728 for i in range(int(PARTS)): 729 if isinstance(start, UTCDateTime): 730 timecode = start + i*chunk_t 731 txt = timecode.strftime("%H:%M:%S.") + \ 732 str(timecode.microsecond//1000) 733 else: 734 txt = str(start + i*chunk_t) 735 736 tw, _, _, _ = canvas.GetFullTextExtent(txt) 707 varpos_start = STATION_INFO 708 709 chunk = length / PARTS 710 chunk2 = chunk / 5. 711 chunk_t = (end - start) / PARTS 712 713 if self.traceOrder in [0, 1]: 714 canvas.DrawLine(varpos_start, fixpos, length + varpos_start, fixpos) 715 elif self.traceOrder in [2, 3]: 716 canvas.DrawLine(fixpos, varpos_start, fixpos, varpos_start + length) 717 718 for i in range(int(PARTS)): 719 if isinstance(start, UTCDateTime): 720 timecode = start + i*chunk_t 721 txt = timecode.strftime("%H:%M:%S.") + \ 722 str(timecode.microsecond//1000) 723 else: 724 txt = str(start + i*chunk_t) 725 726 tw = canvas.GetFullTextExtent(txt)[0] 727 728 if self.traceOrder in [0, 1]: 729 varpos_current = varpos_start + i * chunk 730 # time string 731 canvas.DrawText(txt, varpos_current - tw / 2, 732 fixpos + TIMESCALE_OFFSET_TEXT) 733 # major tick 734 canvas.DrawLine(varpos_current, fixpos, 735 varpos_current, fixpos + TIMESCALE_TICKS_MAJOR) 736 # minor ticks 737 for j in range(1, 5): 738 canvas.DrawLine( 739 varpos_current + j * chunk2, 740 fixpos, 741 varpos_current + j * chunk2, 742 fixpos + TIMESCALE_TICKS_MINOR 743 ) 744 elif self.traceOrder in [2, 3]: 737 745 if self.traceOrder == 2: 738 y = sy + (PARTS-i) * chunk746 varpos_current = varpos_start + (PARTS - i) * chunk 739 747 elif self.traceOrder == 3: 740 y = sy + i * chunk 741 canvas.DrawRotatedText(txt, x+8, y+tw/2, 90) 742 canvas.DrawLine(x, y, x+7, y) 748 varpos_current = varpos_start + i * chunk 749 canvas.DrawRotatedText(txt, fixpos + TIMESCALE_OFFSET_TEXT, 750 varpos_current + tw / 2, 90) 751 canvas.DrawLine(fixpos, varpos_current, 752 fixpos + TIMESCALE_TICKS_MAJOR, varpos_current) 743 753 for j in range(1, 5): 744 754 if self.traceOrder == 2: 745 755 j -= 5 746 canvas.DrawLine(x, y+j*chunk2, x+3, y+j*chunk2) 756 canvas.DrawLine( 757 fixpos, 758 varpos_current + j * chunk2, 759 fixpos + TIMESCALE_TICKS_MINOR, 760 varpos_current + j * chunk2 761 ) 747 762 748 763 # make it visible
Note: See TracChangeset
for help on using the changeset viewer.