فهرست منبع

ensure only most recent data displayed on graph and data is not cut off

Daniel Sheffield 2 سال پیش
والد
کامیت
f6f572813a
2فایلهای تغییر یافته به همراه13 افزوده شده و 10 حذف شده
  1. 2 5
      app/activities/TransactionEditor.py
  2. 11 5
      app/widgets.py

+ 2 - 5
app/activities/TransactionEditor.py

@@ -144,10 +144,7 @@ class TransactionEditor(FocusWidget):
           float(x) for x in df[['avg','min','max']].iloc[0]
         ]
         self.rating.update_rating(_avg, _min, _max, unit, price=price, quantity=quantity)
-        df = df.sort_values('ts_raw', ascending=True)
-        #print(df)
-        #input()
-        # need to sort by ts and take last 45 items
+        df = df.sort_values('ts_raw', ascending=True).truncate(after=self.graph._canvas_width-1)
         self.graph.set_data(
             df[['ts_raw','$/unit']].apply(
                 lambda x, axis=None: (
@@ -275,7 +272,7 @@ class TransactionEditor(FocusWidget):
               lambda x: _widgets[x] if x is not None else Divider(),
               bottom_pane
             )),
-            (self.graph.width, Pile([
+            (self.graph.total_width, Pile([
               LineBox(
                 AttrMap(components['badge'], 'badge'),
                 title="Current Price", title_align='left',

+ 11 - 5
app/widgets.py

@@ -305,8 +305,12 @@ class FlowBarGraphWithVScale(urwid.Columns):
     ignore_focus = True
     
     @property
-    def width(self):
-        return self._width
+    def total_width(self):
+        return self._total_width
+
+    @property
+    def canvas_width(self):
+        return self._canvas_width
     
     @property
     def height(self):
@@ -334,12 +338,14 @@ class FlowBarGraphWithVScale(urwid.Columns):
         ], top)
     
     def __init__(self, cols, rows, attr, *args, hatt=None, **kwargs):
-        self._width = cols
+        self._total_width = cols
         assert cols > 6
+        self._vscale_width = 6
+        self._canvas_width = cols - 6
         self.graph = FlowBarGraph(rows, attr, hatt=hatt)
         self.graph_vscale = FlowGraphVScale(self.graph, [], 0)
         super().__init__([
-            (6, self.graph_vscale),
-            (cols-6, self.graph)
+            (self._vscale_width, self.graph_vscale),
+            (self._canvas_width, self.graph)
         ], *args, **kwargs)