Skip to content
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

Add type information for mousemove event #229

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 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,12 +29,13 @@
$: 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()}`);
console.log(evt.x, evt.y);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to remove this log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooop, sory! Thanks for the merge!

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