@@ -445,42 +445,52 @@ def _draw_vline(self, x1, y1, y2, colidx):
445
445
446
446
# def _clear_plot_bitmap(self): ### woz here
447
447
448
- # This is almost always going to be quicker
449
- # than the slow _clear_plot_bitmap implemented on 5.0.0
450
- def _undraw_bitmap (self ):
451
- if not self ._plot_dirty :
452
- return
448
+ def _redraw_all_col_idx (self , col_idx_list ):
453
449
x_cols = min (self ._data_values , self ._plot_width )
454
450
wrapMode = self ._mode == "wrap"
455
451
if wrapMode :
456
452
x_data_idx = (self ._data_idx - self ._x_pos ) % self ._data_size
457
453
else :
458
454
x_data_idx = (self ._data_idx - x_cols ) % self ._data_size
459
455
460
- colidx = self .TRANSPARENT_IDX
461
456
for ch_idx in range (self ._channels ):
457
+ col_idx = col_idx_list [ch_idx ]
462
458
data_idx = x_data_idx
463
459
for x_pos in range (x_cols ):
464
460
# "jump" the gap in the circular buffer for wrap mode
465
461
if wrapMode and x_pos == self ._x_pos :
466
462
data_idx = (data_idx + self ._data_size - self ._plot_width ) % self ._data_size
467
- # TODO - inhibit line drawing in BOTH VERSIONS
463
+ # ideally this should inhibit lines between wrapped data
468
464
469
465
y_pos = self ._data_y_pos [ch_idx ][data_idx ]
470
466
if self ._style == "lines" and x_pos != 0 :
471
467
# Python supports negative array index
472
468
prev_y_pos = self ._data_y_pos [ch_idx ][data_idx - 1 ]
473
- self ._draw_vline (x_pos , prev_y_pos , y_pos , colidx )
469
+ self ._draw_vline (x_pos , prev_y_pos , y_pos , col_idx )
474
470
else :
475
471
if 0 <= y_pos <= self ._plot_height_m1 :
476
- self ._displayio_plot [x_pos , y_pos ] = colidx
472
+ self ._displayio_plot [x_pos , y_pos ] = col_idx
477
473
data_idx += 1
478
474
if data_idx >= self ._data_size :
479
475
data_idx = 0
480
476
477
+ # This is almost always going to be quicker
478
+ # than the slow _clear_plot_bitmap implemented on 5.0.0 displayio
479
+ def _undraw_bitmap (self ):
480
+ if not self ._plot_dirty :
481
+ return
482
+
483
+ self ._redraw_all_col_idx ([self .TRANSPARENT_IDX ] * self ._channels )
481
484
self ._plot_dirty = False
482
485
486
+
487
+ def _redraw_all (self ):
488
+ self ._redraw_all_col_idx (self ._channel_colidx )
489
+ self ._plot_dirty = True
490
+
491
+
483
492
def _undraw_column (self , x_pos , data_idx ):
493
+ """Undraw a single column at x_pos based on data from data_idx."""
484
494
colidx = self .TRANSPARENT_IDX
485
495
for ch_idx in range (self ._channels ):
486
496
y_pos = self ._data_y_pos [ch_idx ][data_idx ]
@@ -492,47 +502,10 @@ def _undraw_column(self, x_pos, data_idx):
492
502
if 0 <= y_pos <= self ._plot_height_m1 :
493
503
self ._displayio_plot [x_pos , y_pos ] = colidx
494
504
495
- # TODO - This is a cut and paste from _undraw_bitmap()
496
- # TODO - This is a cut and paste from _undraw_bitmap()
497
- # TODO - This is a cut and paste from _undraw_bitmap()
498
- # TODO - This is a cut and paste from _undraw_bitmap()
499
-
500
- # TODO - time to clean this up and review _data_redraw()
501
- def _data_redraw_all (self ):
502
- x_cols = min (self ._data_values , self ._plot_width )
503
- wrapMode = self ._mode == "wrap"
504
- if wrapMode :
505
- x_data_idx = (self ._data_idx - self ._x_pos ) % self ._data_size
506
- else :
507
- x_data_idx = (self ._data_idx - x_cols ) % self ._data_size
508
-
509
- for ch_idx in range (self ._channels ):
510
- colidx = self ._channel_colidx [ch_idx ]
511
- data_idx = x_data_idx
512
- for x_pos in range (x_cols ):
513
- # "jump" the gap in the circular buffer for wrap mode
514
- if wrapMode and x_pos == self ._x_pos :
515
- data_idx = (data_idx + self ._data_size - self ._plot_width ) % self ._data_size
516
- # TODO - inhibit line drawing in BOTH VERSIONS
517
-
518
- y_pos = self ._data_y_pos [ch_idx ][data_idx ]
519
- if self ._style == "lines" and x_pos != 0 :
520
- # Python supports negative array index
521
- prev_y_pos = self ._data_y_pos [ch_idx ][data_idx - 1 ]
522
- self ._draw_vline (x_pos , prev_y_pos , y_pos , colidx )
523
- else :
524
- if 0 <= y_pos <= self ._plot_height_m1 :
525
- self ._displayio_plot [x_pos , y_pos ] = colidx
526
- data_idx += 1
527
- if data_idx >= self ._data_size :
528
- data_idx = 0
529
-
530
- self ._plot_dirty = True
531
-
532
- # TODO - very similar code to _undraw_bitmap although that is now
533
- # more sophisticated as it support wrap mode
534
- def _data_redraw (self , x1 , x2 , x1_data_idx ):
535
- """Redraw data from x1 to x2 inclusive."""
505
+ # very similar code to _undraw_bitmap although that is now
506
+ # more sophisticated as it supports wrap mode
507
+ def _redraw_for_scroll (self , x1 , x2 , x1_data_idx ):
508
+ """Redraw data from x1 to x2 inclusive for scroll mode only."""
536
509
for ch_idx in range (self ._channels ):
537
510
colidx = self ._channel_colidx [ch_idx ]
538
511
data_idx = x1_data_idx
@@ -703,8 +676,9 @@ def data_add(self, values):
703
676
sc_data_idx = ((data_idx + self ._scroll_px - self ._plot_width )
704
677
% self ._data_size )
705
678
self ._data_values -= self ._scroll_px
706
- self ._data_redraw (0 , self ._plot_width - 1 - self ._scroll_px ,
707
- sc_data_idx )
679
+ self ._redraw_for_scroll (0 ,
680
+ self ._plot_width - 1 - self ._scroll_px ,
681
+ sc_data_idx )
708
682
x_pos = self ._plot_width - self ._scroll_px
709
683
710
684
elif self ._scale_mode == "pixel" :
@@ -768,7 +742,7 @@ def _change_y_range(self, new_plot_min, new_plot_max, redraw_plot=True):
768
742
self ._undraw_bitmap ()
769
743
self ._recalc_y_pos () ## calculates new y positions
770
744
if redraw_plot :
771
- self ._data_redraw_all ()
745
+ self ._redraw_all ()
772
746
773
747
@property
774
748
def title (self ):
0 commit comments