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

Fix crosshair position for a single data point in line chart #1726

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rita-morozova
Copy link
Contributor

@rita-morozova rita-morozova commented Sep 19, 2024

What does this implement/fix?

When rendering a line chart with single data points per series, the crosshair was not aligned with the actual data points. This misalignment was caused by the animation logic. I am adding a condition to bypass the animation logic if all series have only one data point. Animating a single point or very sparse data does not provide any additional visual benefit to the user.

Does this close any currently open issues?

Related https://github.com/Shopify/core-issues/issues/71927

What do the changes look like?

Before After
Screenshot 2024-09-18 at 2 46 26 PM Screenshot 2024-09-18 at 2 46 54 PM
Screenshot 2024-09-18 at 2 46 05 PM Screenshot 2024-09-18 at 2 47 35 PM

Storybook link

Storybook

  • Make sure the crosshair is positioned correctly
  • Test other line charts and make sure nothing is broken

Before merging

  • Check your changes on a variety of browsers and devices.

  • Update the Changelog's Unreleased section with your changes.

  • Update relevant documentation, tests, and Storybook.

  • Make sure you're exporting any new shared Components, Types and Utilities from the top level index file of the package

Copy link

github-actions bot commented Sep 19, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
polaris-viz-core-cjs 61.41 KB (0%) 1.3 s (0%) 864 ms (+7.81% 🔺) 2.1 s
polaris-viz-cjs 215.79 KB (+0.01% 🔺) 4.4 s (+0.01% 🔺) 1.8 s (+8.04% 🔺) 6.1 s
polaris-viz-esm 176.63 KB (+0.01% 🔺) 3.6 s (+0.01% 🔺) 1.5 s (+10.63% 🔺) 5 s
polaris-viz-css 4.72 KB (0%) 95 ms (0%) 439 ms (+78.71% 🔺) 534 ms
polaris-viz-esnext 182.28 KB (+0.01% 🔺) 3.7 s (+0.01% 🔺) 1.3 s (+6.74% 🔺) 5 s

@@ -70,6 +70,15 @@ export function PointsAndCrosshair({
}
const offset = isCrosshair ? selectedTheme.crossHair.width / 2 : 0;

const allSingleDataPoints = data.every(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think using .some instead so we're not always checking the entire data set would be better, or not worth the optimization?

const allSingleDataPoints = data.some(
  (series) => series.data.length !== 1,
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@envex I misread the comment in the first place 😆 updated here

Copy link
Collaborator

@envex envex left a comment

Choose a reason for hiding this comment

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

Approving, just one comment about the loop

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.

2 participants