Skip to content

Commit 2ee7236

Browse files
committed
Remove scroll. Do not wrap setting new points with withRaf(). Update the camera on refresh. Add clear() for clearing points.
1 parent 0667bde commit 2ee7236

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import createDom2dCamera from '@flekschas/dom-2d-camera';
1+
import createDom2dCamera from 'dom-2d-camera';
22
import KDBush from 'kdbush';
33
import createPubSub from 'pub-sub-es';
44
import withThrottle from 'lodash-es/throttle';
@@ -95,7 +95,6 @@ const createScatterplot = ({
9595
let regl = initialRegl || createRegl(initialCanvas);
9696
let camera;
9797
let lasso;
98-
let scroll;
9998
let mouseDown = false;
10099
let mouseDownShift = false;
101100
let mouseDownPosition = [0, 0];
@@ -700,8 +699,7 @@ const createScatterplot = ({
700699
isInit = true;
701700
};
702701

703-
const draw = (newPoints, showRecticleOnce) => {
704-
if (newPoints) setPoints(newPoints);
702+
const draw = (showRecticleOnce = false) => {
705703
if (!isInit) return;
706704

707705
regl.clear({
@@ -731,6 +729,11 @@ const createScatterplot = ({
731729

732730
const drawRaf = withRaf(draw);
733731

732+
const publicDraw = (newPoints, showRecticleOnce = false) => {
733+
if (newPoints) setPoints(newPoints);
734+
drawRaf(showRecticleOnce);
735+
};
736+
734737
const withDraw = f => (...args) => {
735738
const out = f(...args);
736739
drawRaf();
@@ -795,6 +798,7 @@ const createScatterplot = ({
795798
*/
796799
const refresh = () => {
797800
regl.poll();
801+
camera.refresh();
798802
};
799803

800804
const get = property => {
@@ -915,6 +919,10 @@ const createScatterplot = ({
915919
drawRaf();
916920
};
917921

922+
const clear = () => {
923+
setPoints([]);
924+
};
925+
918926
const init = () => {
919927
updateViewAspectRatio();
920928
initCamera();
@@ -974,16 +982,16 @@ const createScatterplot = ({
974982
camera = undefined;
975983
regl = undefined;
976984
lasso.destroy();
977-
scroll.dispose();
978985
pubSub.clear();
979986
};
980987

981988
init(canvas);
982989

983990
return {
991+
clear: withDraw(clear),
984992
deselect,
985993
destroy,
986-
draw: drawRaf,
994+
draw: publicDraw,
987995
get,
988996
hover,
989997
refresh,

0 commit comments

Comments
 (0)