-
Notifications
You must be signed in to change notification settings - Fork 215
pool option for tip marks #2382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
2ef64ff
4745cce
7da78e3
edbcdc2
44a6981
8e7f034
0174b94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import {isArray} from "../options.js"; | |
| import {applyFrameAnchor} from "../style.js"; | ||
|
|
||
| const states = new WeakMap(); | ||
| const frames = new WeakMap(); | ||
|
|
||
| function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...options} = {}) { | ||
| maxRadius = +maxRadius; | ||
|
|
@@ -29,7 +30,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op | |
| // Isolate state per-pointer, per-plot; if the pointer is reused by | ||
| // multiple marks, they will share the same state (e.g., sticky modality). | ||
| let state = states.get(svg); | ||
| if (!state) states.set(svg, (state = {sticky: false, roots: [], renders: []})); | ||
| if (!state) states.set(svg, (state = {sticky: false, roots: [], renders: [], pool: new Map()})); | ||
Fil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // This serves as a unique identifier of the rendered mark per-plot; it is | ||
| // used to record the currently-rendered elements (state.roots) so that we | ||
|
|
@@ -71,32 +72,26 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op | |
| let i; // currently focused index | ||
| let g; // currently rendered mark | ||
| let s; // currently rendered stickiness | ||
| let f; // current animation frame | ||
|
|
||
| // When faceting, if more than one pointer would be visible, only show | ||
| // this one if it is the closest. We defer rendering using an animation | ||
| // frame to allow all pointer events to be received before deciding which | ||
| // mark to render; although when hiding, we render immediately. | ||
| // When pooling or faceting, if more than one pointer would be visible, | ||
| // only show the closest. We defer rendering using an animation frame to | ||
| // allow all pointer events to be received before deciding which mark to | ||
| // render; although when hiding, we render immediately. | ||
| const pool = this.pool ? state.pool : faceted ? facetState : null; | ||
Fil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| function update(ii, ri) { | ||
| if (faceted) { | ||
| if (f) f = cancelAnimationFrame(f); | ||
| if (ii == null) facetState.delete(index.fi); | ||
| else { | ||
| facetState.set(index.fi, ri); | ||
| f = requestAnimationFrame(() => { | ||
| f = null; | ||
| for (const [fi, r] of facetState) { | ||
| if (r < ri || (r === ri && fi < index.fi)) { | ||
| ii = null; | ||
| break; | ||
| } | ||
| } | ||
| render(ii); | ||
| }); | ||
| return; | ||
| } | ||
| } | ||
| render(ii); | ||
| if (ii == null) render(ii); | ||
| if (!pool) return void render(ii); | ||
| pool.set(render, {ii, ri, render}); | ||
| if (frames.has(pool)) cancelAnimationFrame(frames.get(pool)); | ||
| frames.set( | ||
| pool, | ||
| requestAnimationFrame(() => { | ||
| frames.delete(pool); | ||
|
||
| let best = null; | ||
| for (const [, c] of pool) if (!best || c.ri < best.ri) best = c; | ||
| for (const [, c] of pool) c.render(c === best ? c.ii : null); | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| function render(ii) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment on these maps saying what they store? It’s especially hard without types and the names are not obvious. Sometimes I use the convention thingByKey to name maps, if it helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And the pool map too.)