@@ -97,8 +97,6 @@ def __init__(
97
97
self .y_top = y_max
98
98
# y_top: The actual minimum value of the vertical scale, will be
99
99
# updated if autorange
100
- self ._x = x
101
- self ._y = y
102
100
self ._redraw = True # _redraw: redraw primitives
103
101
self ._last = [] # _last: last point of sparkline
104
102
@@ -127,7 +125,12 @@ def add_value(self, value: float, update: bool = True) -> None:
127
125
if (
128
126
len (self ._spark_list ) >= self ._max_items
129
127
): # if list is full, remove the first item
130
- self ._spark_list .pop (0 )
128
+ first = self ._spark_list .pop (0 )
129
+ # check if boundaries have to be updated
130
+ if self .y_min is None and first == self .y_bottom :
131
+ self .y_bottom = min (self ._spark_list )
132
+ if self .y_max is None and first == self .y_top :
133
+ self .y_top = max (self ._spark_list )
131
134
self ._redraw = True
132
135
self ._spark_list .append (value )
133
136
@@ -140,10 +143,6 @@ def add_value(self, value: float, update: bool = True) -> None:
140
143
self ._redraw = self ._redraw or value > self .y_top
141
144
self .y_top = value if not self .y_top else max (value , self .y_top )
142
145
143
- # Guard for y_top and y_bottom being the same
144
- if self .y_top == self .y_bottom :
145
- self .y_bottom *= 0.99
146
-
147
146
if update :
148
147
self .update ()
149
148
@@ -177,10 +176,15 @@ def _plotline(
177
176
value : float ,
178
177
) -> None :
179
178
180
- y_2 = int (self .height * (self .y_top - value ) / (self .y_top - self .y_bottom ))
181
- y_1 = int (
182
- self .height * (self .y_top - last_value ) / (self .y_top - self .y_bottom )
183
- )
179
+ # Guard for y_top and y_bottom being the same
180
+ if self .y_top == self .y_bottom :
181
+ y_2 = int (0.5 * self .height )
182
+ y_1 = int (0.5 * self .height )
183
+ else :
184
+ y_2 = int (self .height * (self .y_top - value ) / (self .y_top - self .y_bottom ))
185
+ y_1 = int (
186
+ self .height * (self .y_top - last_value ) / (self .y_top - self .y_bottom )
187
+ )
184
188
self .append (Line (x_1 , y_1 , x_2 , y_2 , self .color )) # plot the line
185
189
self ._last = [x_2 , value ]
186
190
0 commit comments