Skip to content

Conversation

@gka
Copy link
Contributor

@gka gka commented Sep 9, 2025

resolves #183

Event handling improvements:

  • In events.ts, improved the calculation of event coordinates by:
    • Using clientX/clientY instead of layerX/layerY for more accurate positioning.
    • Correctly finding the facet container and adjusting for plot margins.
    • Ensuring compatibility with faceted plots and different event types.

Scale inversion logic:

  • Enhanced the invertScale function for band scales to compute the correct domain value based on the event's position within the plot, leading to more accurate data mapping from pointer events.

@netlify
Copy link

netlify bot commented Sep 9, 2025

Deploy Preview for svelteplot ready!

Name Link
🔨 Latest commit 036d10a
🔍 Latest deploy log https://app.netlify.com/projects/svelteplot/deploys/68c08d4b5c930500074ee478
😎 Deploy Preview https://deploy-preview-186--svelteplot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link

github-actions bot commented Sep 9, 2025

📦 Preview package for this PR is published!

Version: 0.4.2-pr-186.0

Install it with:

npm install svelteplot@pr-186
# or install the specific version
npm install svelteplot@0.4.2-pr-186.0

This comment was marked as outdated.

@github-actions
Copy link

github-actions bot commented Sep 9, 2025

📦 Preview package for this PR is published!

Version: 0.4.2-pr-186.1

Install it with:

npm install svelteplot@pr-186
# or install the specific version
npm install svelteplot@0.4.2-pr-186.1

@gka gka requested a review from Copilot September 9, 2025 20:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes event coordinate calculations for pointer events by switching from layerX/layerY to clientX/clientY and improving scale inversion logic for band scales. The changes ensure more accurate data mapping from pointer events, particularly in faceted plots.

Key changes:

  • Enhanced event coordinate calculation using client coordinates and proper facet container detection
  • Improved band scale inversion to handle positioning within the scale range correctly
  • Refactored import statements to use more specific type imports

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/lib/marks/helpers/events.ts Enhanced event coordinate calculation and band scale inversion logic
src/lib/marks/helpers/RectPath.svelte Refactored imports to use more specific type imports

Comment on lines +99 to +100
origEvent.clientX - facetRect.left + (options.marginLeft ?? 0);
const relativeY = origEvent.clientY - facetRect.top + (options.marginTop ?? 0);
Copy link

Copilot AI Sep 9, 2025

Choose a reason for hiding this comment

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

The margin calculations appear incorrect. When converting from client coordinates to plot coordinates, margins should be subtracted, not added. This would place events at incorrect positions within the plot area.

Copilot uses AI. Check for mistakes.
const extent = range[1] - range[0];
const posInRange = (position - range[0]) * Math.sign(extent);
const index = Math.floor(posInRange / eachBand);
return domain[index];
Copy link

Copilot AI Sep 9, 2025

Choose a reason for hiding this comment

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

Array access without bounds checking could cause runtime errors. If the calculated index is negative or exceeds the domain length, this will return undefined unexpectedly. Add bounds checking: return index >= 0 && index < domain.length ? domain[index] : undefined;

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Sep 9, 2025

📦 Preview package for this PR is published!

Version: 0.4.2-pr-186.2

Install it with:

npm install svelteplot@pr-186
# or install the specific version
npm install svelteplot@0.4.2-pr-186.2

@github-actions
Copy link

github-actions bot commented Sep 9, 2025

📦 Preview package for this PR is published!

Version: 0.4.2-pr-186.3

Install it with:

npm install svelteplot@pr-186
# or install the specific version
npm install svelteplot@0.4.2-pr-186.3

@gka gka merged commit 020481b into main Sep 9, 2025
8 checks passed
@gka gka deleted the fix/event-pointer-pos branch September 9, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] BarX calls its onclick handler with wrong [dataX, dataY]

2 participants