Skip to content

Commit

Permalink
Merge pull request #229 from rgieseke/typescript-fixes-mouseevent
Browse files Browse the repository at this point in the history
Add type information for mousemove event
  • Loading branch information
mhkeller authored Aug 26, 2024
2 parents 3c0a9d8 + da3abbf commit fa94719
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/_components/QuadTree.html.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
let found = {};
let e = {};
/** @type {string} [x='x'] – The dimension to search across when moving the mouse left and right. */
/** @type {'x'|'y'} [x='x'] – The dimension to search across when moving the mouse left and right. */
export let x = 'x';
/** @type {string} [y='y'] – The dimension to search across when moving the mouse up and down. */
/** @type {'x'|'y'} [y='y'] – The dimension to search across when moving the mouse up and down. */
export let y = 'y';
/** @type {number|undefined} [searchRadius] – The number of pixels to search around the mouse's location. This is the third argument passed to [`quadtree.find`](https://github.com/d3/d3-quadtree#quadtree_find) and by default a value of `undefined` means an unlimited range. */
Expand All @@ -29,11 +29,12 @@
$: xGetter = x === 'x' ? $xGet : $yGet;
$: yGetter = y === 'y' ? $yGet : $xGet;
/** @param {MouseEvent} evt */
function findItem(evt) {
e = evt;
const xLayerKey = `layer${x.toUpperCase()}`;
const yLayerKey = `layer${y.toUpperCase()}`;
const xLayerKey = /** @type {'layerX'|'layerY'} */ (`layer${x.toUpperCase()}`);
const yLayerKey = /** @type {'layerX'|'layerY'}*/ (`layer${y.toUpperCase()}`);
found = finder.find(evt[xLayerKey], evt[yLayerKey], searchRadius) || {};
visible = Object.keys(found).length > 0;
Expand Down
9 changes: 5 additions & 4 deletions src/_components/QuadTree.percent-range.html.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
let found = {};
let e = {};
/** @type {string} [x='x'] - The dimension to search across when moving the mouse left and right. */
/** @type {'x'|'y'} [x='x'] - The dimension to search across when moving the mouse left and right. */
export let x = 'x';
/** @type {string} [y='y'] - The dimension to search across when moving the mouse up and down. */
/** @type {'x'|'y'} [y='y'] - The dimension to search across when moving the mouse up and down. */
export let y = 'y';
/** @type {number|undefined} [searchRadius] - The number of pixels to search around the mouse's location. This is the third argument passed to [`quadtree.find`](https://github.com/d3/d3-quadtree#quadtree_find) and by default a value of `undefined` means an unlimited range. */
Expand All @@ -29,11 +29,12 @@
$: xGetter = x === 'x' ? $xGet : $yGet;
$: yGetter = y === 'y' ? $yGet : $xGet;
/** @param {MouseEvent} evt*/
function findItem(evt) {
e = evt;
const xLayerKey = `layer${x.toUpperCase()}`;
const yLayerKey = `layer${y.toUpperCase()}`;
const xLayerKey = /** @type {'layerX'|'layerY'} */ (`layer${x.toUpperCase()}`);
const yLayerKey = /** @type {'layerX'|'layerY'}*/ (`layer${y.toUpperCase()}`);
const xLayerVal = (evt[xLayerKey] / (x === 'x' ? $width : $height)) * 100;
const yLayerVal = (evt[yLayerKey] / (y === 'y' ? $height : $width)) * 100;
Expand Down

0 comments on commit fa94719

Please sign in to comment.