|
1 | | -import createDom2dCamera from '@flekschas/dom-2d-camera'; |
| 1 | +import createDom2dCamera from 'dom-2d-camera'; |
2 | 2 | import KDBush from 'kdbush'; |
3 | 3 | import createPubSub from 'pub-sub-es'; |
4 | 4 | import withThrottle from 'lodash-es/throttle'; |
@@ -95,7 +95,6 @@ const createScatterplot = ({ |
95 | 95 | let regl = initialRegl || createRegl(initialCanvas); |
96 | 96 | let camera; |
97 | 97 | let lasso; |
98 | | - let scroll; |
99 | 98 | let mouseDown = false; |
100 | 99 | let mouseDownShift = false; |
101 | 100 | let mouseDownPosition = [0, 0]; |
@@ -700,8 +699,7 @@ const createScatterplot = ({ |
700 | 699 | isInit = true; |
701 | 700 | }; |
702 | 701 |
|
703 | | - const draw = (newPoints, showRecticleOnce) => { |
704 | | - if (newPoints) setPoints(newPoints); |
| 702 | + const draw = (showRecticleOnce = false) => { |
705 | 703 | if (!isInit) return; |
706 | 704 |
|
707 | 705 | regl.clear({ |
@@ -731,6 +729,11 @@ const createScatterplot = ({ |
731 | 729 |
|
732 | 730 | const drawRaf = withRaf(draw); |
733 | 731 |
|
| 732 | + const publicDraw = (newPoints, showRecticleOnce = false) => { |
| 733 | + if (newPoints) setPoints(newPoints); |
| 734 | + drawRaf(showRecticleOnce); |
| 735 | + }; |
| 736 | + |
734 | 737 | const withDraw = f => (...args) => { |
735 | 738 | const out = f(...args); |
736 | 739 | drawRaf(); |
@@ -795,6 +798,7 @@ const createScatterplot = ({ |
795 | 798 | */ |
796 | 799 | const refresh = () => { |
797 | 800 | regl.poll(); |
| 801 | + camera.refresh(); |
798 | 802 | }; |
799 | 803 |
|
800 | 804 | const get = property => { |
@@ -915,6 +919,10 @@ const createScatterplot = ({ |
915 | 919 | drawRaf(); |
916 | 920 | }; |
917 | 921 |
|
| 922 | + const clear = () => { |
| 923 | + setPoints([]); |
| 924 | + }; |
| 925 | + |
918 | 926 | const init = () => { |
919 | 927 | updateViewAspectRatio(); |
920 | 928 | initCamera(); |
@@ -974,16 +982,16 @@ const createScatterplot = ({ |
974 | 982 | camera = undefined; |
975 | 983 | regl = undefined; |
976 | 984 | lasso.destroy(); |
977 | | - scroll.dispose(); |
978 | 985 | pubSub.clear(); |
979 | 986 | }; |
980 | 987 |
|
981 | 988 | init(canvas); |
982 | 989 |
|
983 | 990 | return { |
| 991 | + clear: withDraw(clear), |
984 | 992 | deselect, |
985 | 993 | destroy, |
986 | | - draw: drawRaf, |
| 994 | + draw: publicDraw, |
987 | 995 | get, |
988 | 996 | hover, |
989 | 997 | refresh, |
|
0 commit comments