acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_chart_6.py (3135B)

      1 class ExampleChart_6():
      2 
      3     def __init__(self):
      4         self.last_id = -1
      5         #
      6         # Show cursor on the clicked point
      7         #
      8 
      9         chart = lv.chart(lv.scr_act())
     10         chart.set_size(200, 150)
     11         chart.align(lv.ALIGN.CENTER, 0, -10)
     12 
     13         chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 5, True, 40)
     14         chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 10, 5, 10, 1, True, 30)
     15 
     16         chart.add_event_cb(self.event_cb, lv.EVENT.ALL, None)
     17         chart.refresh_ext_draw_size()
     18 
     19         self.cursor = chart.add_cursor(lv.palette_main(lv.PALETTE.BLUE), lv.DIR.LEFT | lv.DIR.BOTTOM)
     20 
     21         self.ser = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
     22 
     23         self.ser_p = []
     24         for i in range(10):
     25             self.ser_p.append(lv.rand(10,90))
     26         self.ser.y_points = self.ser_p
     27 
     28         newser = chart.get_series_next(None)
     29         # print("length of data points: ",len(newser.points))
     30         chart.set_zoom_x(500)
     31 
     32         label = lv.label(lv.scr_act())
     33         label.set_text("Click on a point")
     34         label.align_to(chart, lv.ALIGN.OUT_TOP_MID, 0, -5)
     35 
     36 
     37     def event_cb(self,e):
     38 
     39         code = e.get_code()
     40         chart = e.get_target()
     41 
     42         if code == lv.EVENT.VALUE_CHANGED:
     43             # print("last_id: ",self.last_id)
     44             self.last_id = chart.get_pressed_point()
     45             if self.last_id != lv.CHART_POINT.NONE:
     46                 p = lv.point_t()
     47                 chart.get_point_pos_by_id(self.ser, self.last_id, p)
     48                 chart.set_cursor_point(self.cursor, None, self.last_id)
     49 
     50         elif code == lv.EVENT.DRAW_PART_END:
     51             # print("EVENT.DRAW_PART_END")
     52             dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
     53             # if dsc.p1 and dsc.p2:
     54                 # print("p1, p2", dsc.p1,dsc.p2)
     55                 # print("p1.y, p2.y", dsc.p1.y, dsc.p2.y)
     56                 # print("last_id: ",self.last_id)
     57             if dsc.part == lv.PART.CURSOR and dsc.p1 and dsc.p2 and dsc.p1.y == dsc.p2.y and self.last_id >= 0:
     58 
     59                 v = self.ser_p[self.last_id]
     60 
     61                 # print("value: ",v)
     62                 value_txt = str(v)
     63                 size = lv.point_t()
     64                 lv.txt_get_size(size, value_txt, lv.font_default(), 0, 0, lv.COORD.MAX, lv.TEXT_FLAG.NONE)
     65 
     66                 a = lv.area_t()
     67                 a.y2 = dsc.p1.y - 5
     68                 a.y1 = a.y2 - size.y - 10
     69                 a.x1 = dsc.p1.x + 10
     70                 a.x2 = a.x1 + size.x + 10
     71 
     72                 draw_rect_dsc = lv.draw_rect_dsc_t()
     73                 draw_rect_dsc.init()
     74                 draw_rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)
     75                 draw_rect_dsc.radius = 3
     76 
     77                 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc)
     78 
     79                 draw_label_dsc = lv.draw_label_dsc_t()
     80                 draw_label_dsc.init()
     81                 draw_label_dsc.color = lv.color_white()
     82                 a.x1 += 5
     83                 a.x2 -= 5
     84                 a.y1 += 5
     85                 a.y2 -= 5
     86                 lv.draw_label(a, dsc.clip_area, draw_label_dsc, value_txt, None)
     87 
     88 example_chart_6 = ExampleChart_6()