@@ -20,8 +20,8 @@ import {
2020 DEFAULT_POINT_SIZE ,
2121 DEFAULT_POINT_SIZE_SELECTED ,
2222 DEFAULT_WIDTH ,
23- LASSO_MIN_DELAY ,
24- LASSO_MIN_DIST ,
23+ DEFAULT_LASSO_MIN_DELAY ,
24+ DEFAULT_LASSO_MIN_DIST ,
2525} from '../src/constants' ;
2626
2727import {
@@ -502,33 +502,69 @@ test('set({ opacity })', async (t) => {
502502 ) ;
503503} ) ;
504504
505- test ( 'set({ lassoColor })' , async ( t ) => {
505+ test ( 'set({ lassoColor, lassoMinDist, lassoMinDelay })' , async ( t ) => {
506506 const scatterplot = createScatterplot ( { canvas : createCanvas ( ) } ) ;
507507
508- // Check default lasso color
508+ // Check default lasso color, min distance, and min delay
509509 t . equal (
510510 scatterplot . get ( 'lassoColor' ) ,
511511 DEFAULT_LASSO_COLOR ,
512512 `lassoColor should be set to ${ DEFAULT_LASSO_COLOR } `
513513 ) ;
514+ t . equal (
515+ scatterplot . get ( 'lassoMinDist' ) ,
516+ DEFAULT_LASSO_MIN_DIST ,
517+ `lassoMinDist should be set to ${ DEFAULT_LASSO_MIN_DIST } `
518+ ) ;
519+ t . equal (
520+ scatterplot . get ( 'lassoMinDelay' ) ,
521+ DEFAULT_LASSO_MIN_DELAY ,
522+ `lassoMinDelay should be set to ${ DEFAULT_LASSO_MIN_DELAY } `
523+ ) ;
514524
515525 const lassoColor = [ 1 , 0 , 0 , 1 ] ;
526+ const lassoMinDist = 10 ;
527+ const lassoMinDelay = 150 ;
516528
517- scatterplot . set ( { lassoColor } ) ;
529+ scatterplot . set ( { lassoColor, lassoMinDist , lassoMinDelay } ) ;
518530
519531 t . equal (
520532 scatterplot . get ( 'lassoColor' ) ,
521533 lassoColor ,
522534 `lassoColor should be set to ${ lassoColor } `
523535 ) ;
536+ t . equal (
537+ scatterplot . get ( 'lassoMinDist' ) ,
538+ lassoMinDist ,
539+ `lassoMinDist should be set to ${ lassoMinDist } `
540+ ) ;
541+ t . equal (
542+ scatterplot . get ( 'lassoMinDelay' ) ,
543+ lassoMinDelay ,
544+ `lassoMinDelay should be set to ${ lassoMinDelay } `
545+ ) ;
524546
525- scatterplot . set ( { lassoColor : null } ) ;
547+ scatterplot . set ( {
548+ lassoColor : null ,
549+ lassoMinDist : null ,
550+ lassoMinDelay : null ,
551+ } ) ;
526552
527553 t . equal (
528554 scatterplot . get ( 'lassoColor' ) ,
529555 lassoColor ,
530556 'lassoColor should not be nullifyable'
531557 ) ;
558+ t . equal (
559+ scatterplot . get ( 'lassoMinDist' ) ,
560+ lassoMinDist ,
561+ 'lassoMinDist should not be nullifyable'
562+ ) ;
563+ t . equal (
564+ scatterplot . get ( 'lassoMinDelay' ) ,
565+ lassoMinDelay ,
566+ 'lassoMinDelay should not be nullifyable'
567+ ) ;
532568} ) ;
533569
534570test ( 'set({ pointOutlineWidth })' , async ( t ) => {
@@ -696,10 +732,10 @@ test('draw(), clear(), publish("select")', async (t) => {
696732 t . equal ( selectedPoints . length , 0 , 'should have deselected one point' ) ;
697733
698734 // Test that mousedown + mousemove + click is not interpreted as a click when
699- // the cursor moved more than `LASSO_MIN_DIST ` in between mousedown and
735+ // the cursor moved more than `DEFAULT_LASSO_MIN_DIST ` in between mousedown and
700736 // mouseup
701737 canvas . dispatchEvent (
702- createMouseEvent ( 'mousedown' , hdim - LASSO_MIN_DIST , hdim )
738+ createMouseEvent ( 'mousedown' , hdim - DEFAULT_LASSO_MIN_DIST , hdim )
703739 ) ;
704740 canvas . dispatchEvent ( createMouseEvent ( 'click' , hdim , hdim ) ) ;
705741
@@ -763,7 +799,7 @@ test('lasso selection with publish("select")', async (t) => {
763799
764800 await asyncForEach ( mousePositions , async ( mousePosition ) => {
765801 window . dispatchEvent ( createMouseEvent ( 'mousemove' , ...mousePosition ) ) ;
766- await wait ( LASSO_MIN_DELAY + 5 ) ;
802+ await wait ( DEFAULT_LASSO_MIN_DELAY + 5 ) ;
767803 } ) ;
768804
769805 window . dispatchEvent ( createMouseEvent ( 'mouseup' ) ) ;
@@ -846,3 +882,66 @@ test('point hover with publish("pointover") and publish("pointout")', async (t)
846882// 'should have published the translated view'
847883// );
848884// });
885+
886+ /* ----------------------------- Other Methods ------------------------------ */
887+
888+ test ( 'select()' , async ( t ) => {
889+ const scatterplot = createScatterplot ( { canvas : createCanvas ( ) } ) ;
890+
891+ const points = [
892+ [ 0 , 0 ] ,
893+ [ 1 , 1 ] ,
894+ [ 1 , - 1 ] ,
895+ [ - 1 , - 1 ] ,
896+ [ - 1 , 1 ] ,
897+ ] ;
898+ scatterplot . draw ( points ) ;
899+
900+ // TODO: fix this!
901+ await wait ( 250 ) ;
902+
903+ let selectedPoints = [ ] ;
904+ const selectHandler = ( { points : newSelectedPoints } ) => {
905+ selectedPoints = [ ...newSelectedPoints ] ;
906+ } ;
907+ const deselectHandler = ( ) => {
908+ selectedPoints = [ ] ;
909+ } ;
910+ scatterplot . subscribe ( 'select' , selectHandler ) ;
911+ scatterplot . subscribe ( 'deselect' , deselectHandler ) ;
912+
913+ scatterplot . select ( [ 0 , 2 , 4 ] ) ;
914+
915+ await wait ( 0 ) ;
916+
917+ t . ok (
918+ flatArrayEqual ( [ 0 , 2 , 4 ] , selectedPoints ) ,
919+ 'should have selected point 0, 2, and 4'
920+ ) ;
921+
922+ scatterplot . deselect ( ) ;
923+
924+ await wait ( 0 ) ;
925+
926+ t . equal ( selectedPoints . length , 0 , 'should have deselected all points' ) ;
927+
928+ scatterplot . select ( [ 0 , 2 , 4 ] , { preventEvent : true } ) ;
929+
930+ await wait ( 0 ) ;
931+
932+ t . equal (
933+ selectedPoints . length ,
934+ 0 ,
935+ 'should have silently selected three points'
936+ ) ;
937+
938+ scatterplot . select ( [ 0 , 2 , 4 ] ) ;
939+ scatterplot . deselect ( { preventEvent : true } ) ;
940+
941+ await wait ( 0 ) ;
942+
943+ t . ok (
944+ flatArrayEqual ( [ 0 , 2 , 4 ] , selectedPoints ) ,
945+ 'should have silently deselected points'
946+ ) ;
947+ } ) ;
0 commit comments