Skip to content

Commit

Permalink
Add onPointerMove method
Browse files Browse the repository at this point in the history
  • Loading branch information
vasturiano committed Oct 27, 2023
1 parent a5387fe commit 0456a76
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ HilbertChart({ configOptions })(<domElement>)
| <b>enableZoom</b>([<i>boolean</i>]) | Getter/setter for whether to enable zoom/pan interaction in the chart. | `true` |
| <b>onRangeClick</b>(<i>fn</i>) | Callback function for range clicks. The range object is included as single argument `onRangeClick(range)`. | - |
| <b>onRangeHover</b>(<i>fn</i>) | Callback function for range mouse over events. The range object (or `null` if hovering out) is included as single argument `onRangeHover(range)`. | - |
| <b>onPointerMove</b>(<i>fn</i>) | Callback function for pointer move events over the hilbert canvas. The hilbert curve value directly under the mouse pointer is included as argument, as well as the event object itself. `onPointerMove(value, event)`. | - |
| <b>onZoom</b>(<i>fn</i>) | Callback function for zoom/pan events. The current zoom transform is included as single argument `onZoom({ k, x, y })`. Note that `onZoom` is triggered by user interaction as well as programmatic zooming/panning with `focusOn()`. | - |
| <b>onZoomEnd</b>(<i>fn</i>) | Callback function for 'end' of zoom/pan events. The current zoom transform is included as single argument `onZoomEnd({ k, x, y })`. Note that `onZoomEnd` is triggered by user interaction as well as programmatic zooming/panning with `focusOn()`. | - |

Expand Down
10 changes: 8 additions & 2 deletions src/hilbert.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default Kapsule({
enableZoom: { default: true, triggerUpdate: false },
onRangeClick: { triggerUpdate: false },
onRangeHover: { triggerUpdate: false },
onPointerMove: { triggerUpdate: false },
onZoom: { triggerUpdate: false },
onZoomEnd: { triggerUpdate: false }
},
Expand Down Expand Up @@ -326,7 +327,7 @@ export default Kapsule({
const offset = getOffset(d3El.node());
const pointerPos = { x: ev.pageX - offset.left, y: ev.pageY - offset.top };

if (state.showValTooltip) {
if (state.showValTooltip || state.onPointerMove) {
const c = coords.slice();
if (state.useCanvas) {
// Need to consider zoom on canvas
Expand All @@ -336,9 +337,14 @@ export default Kapsule({
c[1] -= zoomTransform.y;
c[1] /= zoomTransform.k;
}
valTooltip.text(state.valFormatter(state.hilbert.getValAtXY(...c)))

const val = state.hilbert.getValAtXY(...c);

state.showValTooltip && valTooltip.text(state.valFormatter(val))
.style('left', `${pointerPos.x}px`)
.style('top', `${pointerPos.y}px`);

state.onPointerMove && state.onPointerMove(val, ev);
}
if (state.showRangeTooltip) {
rangeTooltip
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface HilbertChartGenericInstance<ChainableInstance> {

onRangeClick(cb: (range: Range) => void): ChainableInstance;
onRangeHover(cb: (range: Range | null) => void): ChainableInstance;

onPointerMove(cb: (value: number, event: MouseEvent) => void): ChainableInstance;
onZoom(callback: (transform: {k: number, x: number, y: number}) => void): ChainableInstance;
onZoomEnd(callback: (transform: {k: number, x: number, y: number}) => void): ChainableInstance;
}
Expand Down

0 comments on commit 0456a76

Please sign in to comment.