18
18
from circuitpython_uplot .uplot import Uplot
19
19
except ImportError :
20
20
pass
21
- import math
21
+ from math import sin , cos , ceil
22
22
from displayio import Palette
23
23
from bitmaptools import draw_line
24
24
from vectorio import Rectangle , Polygon
@@ -76,13 +76,12 @@ def __init__(
76
76
y_max = max_value
77
77
78
78
self ._y = [i * plot .scale for i in y ]
79
+
79
80
self ._bar_space = int (bar_space / plot .scale )
80
- self ._graphx = plot .scale * int (
81
+ self ._graphx = plot .scale * ceil (
81
82
abs (plot ._newxmax - plot ._newxmin ) / (len (x ) + 4 )
82
83
)
83
- self ._graphy = plot .scale * int (
84
- abs (plot ._newymax - plot ._newymin ) / (y_max + 2 )
85
- )
84
+ self ._graphy = plot .scale * (abs (plot ._newymax - plot ._newymin ) / (y_max + 2 ))
86
85
87
86
self ._new_min = int (plot .transform (0 , y_max , y_max , 0 , 0 ))
88
87
self ._new_max = int (plot .transform (0 , y_max , y_max , 0 , y_max ))
@@ -131,16 +130,16 @@ def __init__(
131
130
xstart + (i * self ._graphx ),
132
131
plot ._newymin ,
133
132
self ._graphx ,
134
- self ._graphy * y [i ],
133
+ ceil ( self ._graphy * y [i ]) ,
135
134
plot ._index_colorused ,
136
135
)
137
136
delta = 20
138
- rx = int (delta * math . cos (- 0.5 ))
139
- ry = int (delta * math . sin (- 0.5 ))
137
+ rx = int (delta * cos (- 0.5 ))
138
+ ry = int (delta * sin (- 0.5 ))
140
139
x0 = xstart + (i * self ._graphx )
141
- y0 = plot ._newymin - self ._graphy * y [i ]
140
+ y0 = ceil ( plot ._newymin - self ._graphy * y [i ])
142
141
x1 = xstart + (i * self ._graphx ) + self ._graphx
143
- y1 = plot ._newymin - self ._graphy * y [i ]
142
+ y1 = ceil ( plot ._newymin - self ._graphy * y [i ])
144
143
145
144
draw_line (
146
145
plot ._plotbitmap , x0 , y0 , x0 - rx , y0 + ry , plot ._index_colorused
@@ -182,7 +181,7 @@ def _create_bars(self, xstart: int, indice: int):
182
181
Rectangle (
183
182
pixel_shader = self ._color_palette ,
184
183
width = self ._graphx ,
185
- height = self ._graphy * self ._y [indice ],
184
+ height = ceil ( self ._graphy * self ._y [indice ]) ,
186
185
x = xstart + (indice * self ._graphx ),
187
186
y = int (
188
187
self ._plot_obj ._newymin
@@ -195,8 +194,8 @@ def _create_bars(self, xstart: int, indice: int):
195
194
196
195
def _create_projections (self , xstart : int , indice : int , color_lenght : int ):
197
196
delta = 20
198
- rx = int (delta * math . cos (- 0.5 ))
199
- ry = int (delta * math . sin (- 0.5 ))
197
+ rx = int (delta * cos (- 0.5 ))
198
+ ry = int (delta * sin (- 0.5 ))
200
199
points = [
201
200
(0 , 0 ),
202
201
(self ._graphx , 0 ),
@@ -213,22 +212,22 @@ def _create_projections(self, xstart: int, indice: int, color_lenght: int):
213
212
pixel_shader = self ._color_palette ,
214
213
points = points ,
215
214
x = xstart + (indice * self ._graphx ),
216
- y = self ._plot_obj ._newymin - self ._graphy * self ._y [indice ],
215
+ y = ceil ( self ._plot_obj ._newymin - self ._graphy * self ._y [indice ]) ,
217
216
color_index = self ._color_index + color_lenght ,
218
217
)
219
218
)
220
219
points = [
221
220
(0 , 0 ),
222
221
(0 - rx , 0 + ry ),
223
- (0 - rx , self ._graphy * self ._y [indice ]),
224
- (0 , self ._graphy * self ._y [indice ]),
222
+ (0 - rx , ceil ( self ._graphy * self ._y [indice ]) ),
223
+ (0 , ceil ( self ._graphy * self ._y [indice ]) ),
225
224
]
226
225
self ._plot_obj .append (
227
226
Polygon (
228
227
pixel_shader = self ._color_palette ,
229
228
points = points ,
230
229
x = xstart + (indice * self ._graphx ),
231
- y = self ._plot_obj ._newymin - self ._graphy * self ._y [indice ],
230
+ y = ceil ( self ._plot_obj ._newymin - self ._graphy * self ._y [indice ]) ,
232
231
color_index = self ._color_index + color_lenght ,
233
232
)
234
233
)
@@ -239,6 +238,7 @@ def _draw_rectangle(
239
238
"""
240
239
Helper function to draw bins rectangles
241
240
"""
241
+
242
242
draw_line (plot ._plotbitmap , x , y , x + width , y , color )
243
243
draw_line (plot ._plotbitmap , x , y , x , y - height , color )
244
244
draw_line (plot ._plotbitmap , x + width , y , x + width , y - height , color )
@@ -255,7 +255,7 @@ def update_values(self, values: list = None):
255
255
if values is None :
256
256
raise ValueError ("You must provide a list of values" )
257
257
for i , element in enumerate (self ._bars ):
258
- height = self ._graphy * values [i ]
258
+ height = ceil ( self ._graphy * values [i ])
259
259
y = int (
260
260
self ._plot_obj ._newymin
261
261
- self ._graphy * values [i ] / self ._plot_obj .scale
0 commit comments