Quellcode durchsuchen

changed grid interval

subDesTagesMitExtraKaese vor 3 Jahren
Ursprung
Commit
cb00eb5653
1 geänderte Dateien mit 10 neuen und 2 gelöschten Zeilen
  1. 10 2
      raspberry-pi/gui/graph.py

+ 10 - 2
raspberry-pi/gui/graph.py

@@ -5,7 +5,7 @@ from PIL import Image, ImageDraw, ImageTk, ImageFont
 
 
 class Graph(tk.Canvas):
-  def __init__(self, root, scale=(-100, 550), **kwargs):
+  def __init__(self, root, scale=(-50, 450), **kwargs):
     self.root = root
     tk.Canvas.__init__(self, root, **kwargs)
     self.image = self.create_image(0, 0, image=None, anchor='nw')
@@ -34,12 +34,20 @@ class Graph(tk.Canvas):
     axes = self.pointToCoord((0, 0))
     draw.line([(0, axes[1]), (self.width, axes[1])], (60,127,127), self.lineWidth)
     draw.line([(axes[0], 0), (axes[0], self.height)], (60,127,127), self.lineWidth)
-    for p in range(self.scale[0], self.scale[1], 10**int(math.log10(self.scale[1]-self.scale[0]))):
+
+    step  = 10**int(math.log10(self.scale[1]-self.scale[0]))
+    begin = math.floor(self.scale[0] / step) * step
+    end   = math.ceil(self.scale[1] / step) * step
+    halfStep = int(step / 2)
+    for p in range(begin, end, halfStep):
       tickPosX = self.pointToCoord((p, 0))
       tickPosY = self.pointToCoord((0, p))
       #draw grid
       draw.line([(tickPosX[0], self.height), (tickPosX[0], 0)], (60,127,60), 1)
       draw.line([(self.width, tickPosY[1]), (0, tickPosY[1])], (60,127,60), 1)
+    for p in range(begin, end, step):
+      tickPosX = self.pointToCoord((p, 0))
+      tickPosY = self.pointToCoord((0, p))
       # draw ticks
       draw.line([(tickPosX[0], tickPosX[1]+self.lineWidth*3), (tickPosX[0], tickPosX[1]-self.lineWidth*3)], (60,127,100), int(self.lineWidth/2))
       draw.line([(tickPosY[0]+self.lineWidth*3, tickPosY[1]), (tickPosY[0]-self.lineWidth*3, tickPosY[1])], (60,127,100), int(self.lineWidth/2))