@@ -29,6 +29,7 @@ import {
2929 DEFAULT_LASSO_COLOR ,
3030 DEFAULT_LASSO_MIN_DELAY ,
3131 DEFAULT_LASSO_MIN_DIST ,
32+ DEFAULT_LASSO_CLEAR_EVENT ,
3233 DEFAULT_SHOW_RECTICLE ,
3334 DEFAULT_RECTICLE_COLOR ,
3435 DEFAULT_POINT_OUTLINE_WIDTH ,
@@ -39,6 +40,9 @@ import {
3940 DEFAULT_VIEW ,
4041 DEFAULT_WIDTH ,
4142 FLOAT_BYTES ,
43+ LASSO_CLEAR_EVENTS ,
44+ LASSO_CLEAR_ON_DESELECT ,
45+ LASSO_CLEAR_ON_END ,
4246} from './constants' ;
4347
4448import {
@@ -50,6 +54,7 @@ import {
5054 isMultipleColors ,
5155 isPointInPolygon ,
5256 isString ,
57+ limit ,
5358 toRgba ,
5459 max ,
5560 min ,
@@ -96,6 +101,7 @@ const createScatterplot = (initialProperties = {}) => {
96101 lassoColor : initialLassoColor = DEFAULT_LASSO_COLOR ,
97102 lassoMinDelay : initialLassoMinDelay = DEFAULT_LASSO_MIN_DELAY ,
98103 lassoMinDist : initialLassoMinDist = DEFAULT_LASSO_MIN_DIST ,
104+ lassoClearEvent : initialLassoClearEvent = DEFAULT_LASSO_CLEAR_EVENT ,
99105 showRecticle : initialShowRecticle = DEFAULT_SHOW_RECTICLE ,
100106 recticleColor : initialRecticleColor = DEFAULT_RECTICLE_COLOR ,
101107 pointColor : initialPointColor = DEFAULT_COLOR_NORMAL ,
@@ -136,9 +142,9 @@ const createScatterplot = (initialProperties = {}) => {
136142 let lassoColor = toRgba ( initialLassoColor , true ) ;
137143 let lassoMinDelay = + initialLassoMinDelay ;
138144 let lassoMinDist = + initialLassoMinDist ;
145+ let lassoClearEvent = initialLassoClearEvent ;
139146 let lassoPos = [ ] ;
140147 let lassoPoints = [ ] ;
141- let lassoScatterPos = [ ] ;
142148 let lassoPrevMousePos ;
143149 let searchIndex ;
144150 let viewAspectRatio ;
@@ -259,19 +265,17 @@ const createScatterplot = (initialProperties = {}) => {
259265 const currMousePos = getMousePos ( ) ;
260266
261267 if ( ! lassoPrevMousePos ) {
262- const point = getMouseGlPos ( currMousePos ) ;
263- lassoPos = [ point [ 0 ] , point [ 1 ] ] ;
268+ const point = getScatterGlPos ( currMousePos ) ;
269+ lassoPos = [ ... point ] ;
264270 lassoPoints = [ point ] ;
265- lassoScatterPos = [ ...getScatterGlPos ( currMousePos ) ] ;
266271 lassoPrevMousePos = currMousePos ;
267272 } else {
268273 const d = dist ( ...currMousePos , ...lassoPrevMousePos ) ;
269274
270275 if ( d > lassoMinDist ) {
271- const point = getMouseGlPos ( currMousePos ) ;
272- lassoPos . push ( point [ 0 ] , point [ 1 ] ) ;
276+ const point = getScatterGlPos ( currMousePos ) ;
277+ lassoPos . push ( ... point ) ;
273278 lassoPoints . push ( point ) ;
274- lassoScatterPos . push ( ...getScatterGlPos ( currMousePos ) ) ;
275279 lassoPrevMousePos = currMousePos ;
276280 if ( lassoPos . length > 2 ) {
277281 lasso . setPoints ( lassoPos ) ;
@@ -296,7 +300,14 @@ const createScatterplot = (initialProperties = {}) => {
296300 return pointsInPolygon ;
297301 } ;
298302
303+ const lassoClear = ( ) => {
304+ lassoPos = [ ] ;
305+ lassoPoints = [ ] ;
306+ lasso . clear ( ) ;
307+ } ;
308+
299309 const deselect = ( { preventEvent = false } = { } ) => {
310+ if ( lassoClearEvent === LASSO_CLEAR_ON_DESELECT ) lassoClear ( ) ;
300311 if ( selection . length ) {
301312 if ( ! preventEvent ) pubSub . publish ( 'deselect' ) ;
302313 selection = [ ] ;
@@ -332,20 +343,17 @@ const createScatterplot = (initialProperties = {}) => {
332343 camera . config ( { isFixed : true } ) ;
333344 // Make sure we start a new lasso selection
334345 lassoPrevMousePos = undefined ;
335- lasso . clear ( ) ;
346+ lassoClear ( ) ;
336347 } ;
337348
338349 const lassoEnd = ( ) => {
339350 camera . config ( { isFixed : false } ) ;
340351 // const t0 = performance.now();
341- const pointsInLasso = findPointsInLasso ( lassoScatterPos ) ;
352+ const pointsInLasso = findPointsInLasso ( lassoPos ) ;
342353 // console.log(`found ${pointsInLasso.length} in ${performance.now() - t0} msec`);
343354 select ( pointsInLasso ) ;
344- lassoPos = [ ] ;
345- lassoPoints = [ ] ;
346- lassoScatterPos = [ ] ;
347355 lassoPrevMousePos = undefined ;
348- lasso . clear ( ) ;
356+ if ( lassoClearEvent === LASSO_CLEAR_ON_END ) lassoClear ( ) ;
349357 } ;
350358
351359 const mouseDownHandler = ( event ) => {
@@ -698,9 +706,12 @@ const createScatterplot = (initialProperties = {}) => {
698706 const drawPolygon2d = regl ( {
699707 vert : `
700708 precision mediump float;
709+ uniform mat4 projection;
710+ uniform mat4 model;
711+ uniform mat4 view;
701712 attribute vec2 position;
702713 void main () {
703- gl_Position = vec4(position, 0, 1);
714+ gl_Position = projection * view * model * vec4(position, 0, 1);
704715 }` ,
705716
706717 frag : `
@@ -727,6 +738,9 @@ const createScatterplot = (initialProperties = {}) => {
727738 } ,
728739
729740 uniforms : {
741+ projection : getProjection ,
742+ model : getModel ,
743+ view : getView ,
730744 color : ( ) => lassoColor ,
731745 } ,
732746
@@ -855,7 +869,11 @@ const createScatterplot = (initialProperties = {}) => {
855869
856870 if ( lassoPoints . length > 2 ) drawPolygon2d ( ) ;
857871
858- lasso . draw ( ) ;
872+ lasso . draw ( {
873+ projection : getProjection ( ) ,
874+ model : getModel ( ) ,
875+ view : getView ( ) ,
876+ } ) ;
859877
860878 // Publish camera change
861879 if ( isViewChanged ) pubSub . publish ( 'view' , camera . view ) ;
@@ -932,6 +950,13 @@ const createScatterplot = (initialProperties = {}) => {
932950 lassoMinDist = + newLassoMinDist ;
933951 } ;
934952
953+ const setLassoClearEvent = ( newLassoClearEvent ) => {
954+ lassoClearEvent = limit (
955+ LASSO_CLEAR_EVENTS ,
956+ lassoClearEvent
957+ ) ( newLassoClearEvent ) ;
958+ } ;
959+
935960 const setShowRecticle = ( newShowRecticle ) => {
936961 if ( newShowRecticle === null ) return ;
937962
@@ -975,6 +1000,7 @@ const createScatterplot = (initialProperties = {}) => {
9751000 if ( property === 'lassoColor' ) return lassoColor ;
9761001 if ( property === 'lassoMinDelay' ) return lassoMinDelay ;
9771002 if ( property === 'lassoMinDist' ) return lassoMinDist ;
1003+ if ( property === 'lassoClearEvent' ) return lassoClearEvent ;
9781004 if ( property === 'opacity' ) return opacity ;
9791005 if ( property === 'pointColor' )
9801006 return pointColors . length === 1 ? pointColors [ 0 ] : pointColors ;
@@ -1060,6 +1086,10 @@ const createScatterplot = (initialProperties = {}) => {
10601086 setLassoMinDist ( properties . lassoMinDist ) ;
10611087 }
10621088
1089+ if ( properties . lassoClearEvent !== undefined ) {
1090+ setLassoClearEvent ( properties . lassoClearEvent ) ;
1091+ }
1092+
10631093 if ( properties . showRecticle !== undefined ) {
10641094 setShowRecticle ( properties . showRecticle ) ;
10651095 }
0 commit comments