@@ -43,19 +43,20 @@ def __init__(self, display, ul_x=1, ul_y=1, br_x=400, br_y=300,ax_color=WHITE, m
4343 self .max_y = max_y
4444 self .x_ticks_num = x_ticks_num
4545 self .y_ticks_num = y_ticks_num
46- # Load a small font
47- self .x_font_size = 8
48- self .y_font_size = 10
49- self .display .font = Font ('fonts/Small_Fonts8x10.c' , self .x_font_size , self .y_font_size ,char_spacing = 0 , line_spacing = 1 )
46+ # Choose defaut font here
47+ self .display .defaut_font = Font ('fonts/Small_Fonts8x10.c' , width = 8 , height = 10 ,start_letter = 32 , letter_count = 96 ,char_spacing = 1 , line_spacing = 2 )
48+ self .display .font = self .display .defaut_font
5049 # Define and draw plotting area (taking out space for the ticks and labels)
5150 self .tick_size = 3
52- self .top_margin = int (self .y_font_size / 2 )+ 1
51+ self .top_margin = int (self .display . font . height / 2 )+ 1
5352 self .bottom_margin = 12
5453 self .left_margin = 20
5554 self .x_origin = self .ul_x + self .left_margin
5655 self .x_range = self .br_x - self .x_origin
56+ self .x_origin += int (abs (self .x_range * (self .min_x / (self .max_x - self .min_x ))))
5757 self .y_origin = self .br_y - self .bottom_margin
5858 self .y_range = self .y_origin - self .top_margin - self .ul_y
59+ self .y_origin -= int (abs (self .y_range * (self .min_y / (self .max_y - self .min_y ))))
5960 self .display .draw_rect (self .ul_x + self .left_margin , self .ul_y + self .top_margin , self .br_x , self .br_y - self .bottom_margin ,self .ax_color )
6061 self .display .settextcolor (self .ax_color )
6162 # prepare for legend
@@ -79,19 +80,21 @@ def draw_axes_y(self):
7980 for i in range (self .y_ticks_num + 1 ):
8081 y_tick = self .br_y - self .bottom_margin - int (i * self .y_range / self .y_ticks_num )
8182 self .display .draw_fastHline (self .ul_x + self .left_margin ,self .ul_x + self .left_margin + self .tick_size ,y_tick ,self .ax_color )
82- self .display .settextcursor (self .ul_x , y_tick - int (self .y_font_size / 2 ))
83+ self .display .settextcursor (self .ul_x , y_tick - int (self .display . font . height / 2 ))
8384 y_tick_val = round (self .min_y + (i * (self .max_y - self .min_y )/ self .y_ticks_num ),2 )
8485 self .display .printh (str (y_tick_val ))
8586
8687 def draw_labels (self ):
88+ #Choose font for labels
89+ self .display .font = Font ('fonts/Small_Fonts9x11.c' , width = 9 , height = 11 , start_letter = 32 , letter_count = 96 ,char_spacing = 1 , line_spacing = 2 )
8790 x1_line = self .x_origin + 10
8891 for i in range (len (self .line_labels )):
89- y1_line = self .top_margin + self .ul_y + int (self .y_font_size / 2 )+ i * self .y_font_size + 1
92+ y1_line = self .top_margin + self .ul_y + int (self .display . font . width / 2 )+ i * self .display . font . height + 1
9093 self .display .draw_fastHline (x1_line ,x1_line + 10 ,y1_line ,self .line_colors [i ])
91- self .display .settextcursor (x1_line + 10 + 2 , y1_line - int (self .y_font_size / 2 ))
94+ self .display .settextcursor (x1_line + 10 + 4 , y1_line - int (self .display . font . height / 2 ))
9295 self .display .settextcolor (self .line_colors [i ])
9396 self .display .printh (self .line_labels [i ])
94-
97+ self . display . font = self . display . defaut_font
9598
9699class Line :
97100 """An x.y graph object (line) for the VGA 800x600 display.
@@ -159,6 +162,9 @@ def add_data_ns(self,x,y,draw_line=True):
159162 self .ploty0 = self .plot .y_origin - int ((y * self .plot .y_range / (self .plot .max_y - self .plot .min_y )))
160163 self .plot .display .draw_pix (self .plotx0 ,self .ploty0 ,self .color )
161164 self .is_first_point = False
165+ print ("first point" )
166+ print ("self.plotx0" ,self .plotx0 )
167+ print ("self.plot.x_origin" ,self .plot .x_origin )
162168 else :
163169 plotx = self .plot .x_origin + int ((x * self .plot .x_range / (self .plot .max_x - self .plot .min_x )))
164170 ploty = self .plot .y_origin - int ((y * self .plot .y_range / (self .plot .max_y - self .plot .min_y )))
0 commit comments