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_4.py (2055B)
1 def event_cb(e): 2 code = e.get_code() 3 chart = e.get_target() 4 5 if code == lv.EVENT.VALUE_CHANGED: 6 chart.invalidate() 7 8 if code == lv.EVENT.REFR_EXT_DRAW_SIZE: 9 e.set_ext_draw_size(20) 10 11 elif code == lv.EVENT.DRAW_POST_END: 12 id = lv.chart.get_pressed_point(chart) 13 if id == lv.CHART_POINT.NONE: 14 return 15 # print("Selected point ", id) 16 for i in range(len(series)): 17 p = lv.point_t() 18 chart.get_point_pos_by_id(series[i], id, p) 19 value = series_points[i][id] 20 buf = lv.SYMBOL.DUMMY + "$" + str(value) 21 22 draw_rect_dsc = lv.draw_rect_dsc_t() 23 draw_rect_dsc.init() 24 draw_rect_dsc.bg_color = lv.color_black() 25 draw_rect_dsc.bg_opa = lv.OPA._50 26 draw_rect_dsc.radius = 3 27 draw_rect_dsc.bg_img_src = buf 28 draw_rect_dsc.bg_img_recolor = lv.color_white() 29 30 a = lv.area_t() 31 coords = lv.area_t() 32 chart.get_coords(coords) 33 a.x1 = coords.x1 + p.x - 20 34 a.x2 = coords.x1 + p.x + 20 35 a.y1 = coords.y1 + p.y - 30 36 a.y2 = coords.y1 + p.y - 10 37 38 clip_area = lv.area_t.__cast__(e.get_param()) 39 lv.draw_rect(a, clip_area, draw_rect_dsc) 40 41 elif code == lv.EVENT.RELEASED: 42 chart.invalidate() 43 44 # 45 # Add ticks and labels to the axis and demonstrate scrolling 46 # 47 48 # Create a chart 49 chart = lv.chart(lv.scr_act()) 50 chart.set_size(200, 150) 51 chart.center() 52 53 chart.add_event_cb(event_cb, lv.EVENT.ALL, None) 54 chart.refresh_ext_draw_size() 55 56 # Zoom in a little in X 57 chart.set_zoom_x(800) 58 59 # Add two data series 60 ser1 = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y) 61 ser2 = chart.add_series(lv.palette_main(lv.PALETTE.GREEN), lv.chart.AXIS.PRIMARY_Y) 62 63 ser1_p = [] 64 ser2_p = [] 65 for i in range(10): 66 ser1_p.append(lv.rand(60,90)) 67 ser2_p.append(lv.rand(10,40)) 68 ser1.y_points = ser1_p 69 ser2.y_points = ser2_p 70 71 series = [ser1,ser2] 72 series_points=[ser1_p,ser2_p] 73