Skip to content

Commit

Permalink
Add onZoom callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vasturiano committed Oct 20, 2023
1 parent 20ab101 commit 9be0ee3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ HilbertChart({ configOptions })(<domElement>)
| <b>rangeTooltipContent</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object tooltip content accessor function or attribute. Supports plain text or HTML content. | `<label>: <start> - <end>` |
| <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>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()`. | - |

[npm-img]: https://img.shields.io/npm/v/hilbert-chart
[npm-url]: https://npmjs.org/package/hilbert-chart
Expand Down
9 changes: 7 additions & 2 deletions src/hilbert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default Kapsule({
showRangeTooltip: { default: true, triggerUpdate: false },
rangeTooltipContent: { triggerUpdate: false },
onRangeClick: { triggerUpdate: false },
onRangeHover: { triggerUpdate: false }
onRangeHover: { triggerUpdate: false },
onZoom: { triggerUpdate: false },
onZoomEnd: { triggerUpdate: false }
},

methods: {
Expand Down Expand Up @@ -207,7 +209,10 @@ export default Kapsule({
state.skipRelayout = true;
requestAnimationFrame(state._rerender);
}
});

state.onZoom && state.onZoom({ ...zoomTransform });
})
.on('end', ev => state.onZoomEnd && state.onZoomEnd({ ...ev.transform }));

let hilbertCanvas;
if (!useCanvas) { // svg mode
Expand Down
3 changes: 3 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export interface HilbertChartGenericInstance<ChainableInstance> {

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

onZoom(callback: (transform: {k: number, x: number, y: number}) => void): ChainableInstance;
onZoomEnd(callback: (transform: {k: number, x: number, y: number}) => void): ChainableInstance;
}

export type HilbertChartInstance = HilbertChartGenericInstance<HilbertChartInstance>;
Expand Down

0 comments on commit 9be0ee3

Please sign in to comment.