2021-06-07 13:56:08 +02:00
|
|
|
class ExampleChart_6():
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
def __init__(self):
|
|
|
|
self.last_id = -1
|
|
|
|
#
|
|
|
|
# Show cursor on the clicked point
|
|
|
|
#
|
|
|
|
|
|
|
|
chart = lv.chart(lv.scr_act())
|
|
|
|
chart.set_size(200, 150)
|
|
|
|
chart.align(lv.ALIGN.CENTER, 0, -10)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 5, True, 40)
|
|
|
|
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 10, 5, 10, 1, True, 30)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2023-02-20 20:50:58 +01:00
|
|
|
chart.add_event(self.event_cb, lv.EVENT.ALL, None)
|
2021-06-07 13:56:08 +02:00
|
|
|
chart.refresh_ext_draw_size()
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
self.cursor = chart.add_cursor(lv.palette_main(lv.PALETTE.BLUE), lv.DIR.LEFT | lv.DIR.BOTTOM)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
self.ser = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
|
|
|
|
|
|
|
self.ser_p = []
|
|
|
|
for i in range(10):
|
|
|
|
self.ser_p.append(lv.rand(10,90))
|
2022-03-21 18:25:51 +08:00
|
|
|
self.ser.y_points = self.ser_p
|
2021-06-07 13:56:08 +02:00
|
|
|
|
|
|
|
newser = chart.get_series_next(None)
|
|
|
|
# print("length of data points: ",len(newser.points))
|
|
|
|
chart.set_zoom_x(500)
|
|
|
|
|
|
|
|
label = lv.label(lv.scr_act())
|
|
|
|
label.set_text("Click on a point")
|
|
|
|
label.align_to(chart, lv.ALIGN.OUT_TOP_MID, 0, -5)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
def event_cb(self,e):
|
|
|
|
|
|
|
|
code = e.get_code()
|
2023-02-20 20:50:58 +01:00
|
|
|
chart = e.get_target_obj()
|
2021-06-07 13:56:08 +02:00
|
|
|
|
|
|
|
if code == lv.EVENT.VALUE_CHANGED:
|
|
|
|
# print("last_id: ",self.last_id)
|
|
|
|
self.last_id = chart.get_pressed_point()
|
2022-07-30 18:10:56 +03:00
|
|
|
if self.last_id != lv.CHART_POINT_NONE:
|
2021-06-07 13:56:08 +02:00
|
|
|
p = lv.point_t()
|
|
|
|
chart.get_point_pos_by_id(self.ser, self.last_id, p)
|
|
|
|
chart.set_cursor_point(self.cursor, None, self.last_id)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
elif code == lv.EVENT.DRAW_PART_END:
|
|
|
|
# print("EVENT.DRAW_PART_END")
|
2021-06-30 00:03:07 +03:00
|
|
|
dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
|
2021-06-07 13:56:08 +02:00
|
|
|
# if dsc.p1 and dsc.p2:
|
|
|
|
# print("p1, p2", dsc.p1,dsc.p2)
|
|
|
|
# print("p1.y, p2.y", dsc.p1.y, dsc.p2.y)
|
|
|
|
# print("last_id: ",self.last_id)
|
|
|
|
if dsc.part == lv.PART.CURSOR and dsc.p1 and dsc.p2 and dsc.p1.y == dsc.p2.y and self.last_id >= 0:
|
|
|
|
|
2021-12-05 14:41:17 +01:00
|
|
|
v = self.ser_p[self.last_id]
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
# print("value: ",v)
|
|
|
|
value_txt = str(v)
|
|
|
|
size = lv.point_t()
|
|
|
|
lv.txt_get_size(size, value_txt, lv.font_default(), 0, 0, lv.COORD.MAX, lv.TEXT_FLAG.NONE)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
a = lv.area_t()
|
|
|
|
a.y2 = dsc.p1.y - 5
|
|
|
|
a.y1 = a.y2 - size.y - 10
|
2021-12-05 14:41:17 +01:00
|
|
|
a.x1 = dsc.p1.x + 10
|
|
|
|
a.x2 = a.x1 + size.x + 10
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
draw_rect_dsc = lv.draw_rect_dsc_t()
|
|
|
|
draw_rect_dsc.init()
|
|
|
|
draw_rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)
|
2021-12-05 14:41:17 +01:00
|
|
|
draw_rect_dsc.radius = 3
|
2023-03-10 21:44:12 +01:00
|
|
|
dsc.draw_ctx.rect(draw_rect_dsc,a)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
draw_label_dsc = lv.draw_label_dsc_t()
|
|
|
|
draw_label_dsc.init()
|
|
|
|
draw_label_dsc.color = lv.color_white()
|
|
|
|
a.x1 += 5
|
|
|
|
a.x2 -= 5
|
|
|
|
a.y1 += 5
|
|
|
|
a.y2 -= 5
|
2023-03-10 21:44:12 +01:00
|
|
|
dsc.draw_ctx.label(draw_label_dsc,a,value_txt,None)
|
2021-06-07 13:56:08 +02:00
|
|
|
|
|
|
|
example_chart_6 = ExampleChart_6()
|