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

Feature/improved point label position (redux of #2045) #2047

Conversation

brochington
Copy link
Contributor

Currently tooltips (labels) of point data have the possibility of overlapping the actual point area. This PR is an attempt to provide a more calculated offset based on the area of the point.

redux of this PR

@finos finos deleted a comment from finos-cla-bot bot Dec 13, 2022
Copy link
Member

@texodus texodus left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I really like the approach taken here and I think it looks good with bubble charts. The spacing between the text and bubble edge in this mode is made very consistent and looks great!

Old:
Screenshot 2022-12-28 at 10 50 14 AM
New:
Screenshot 2022-12-28 at 10 50 25 AM

However, subjectively I find this 45deg angle offset less readable generally than the x-offset version in the old charts, especially without bubbling the next can get lost when the scatter area is crowded.

Old:
Screenshot 2022-12-28 at 10 54 42 AM
New:
Screenshot 2022-12-28 at 10 54 56 AM

I propose we keep the radius calculation for the x-offset, but remove the 45deg angle (e.g. LABEL_COSINE is 1 and no y-offset is applied). This will get us consistent spacing on the x-axis without the (IMO) confusing label placement when data is clustered.

I've done this change in #2067, which I've also rebased onto master and removed the "cargo.lock" commits. Please prefer rebase to git merge master and be sure to squash commits for open Perspective PRs - for a project of this size and regression coverage, it is of great help to have as clean a change history as possible.

@@ -12,6 +12,9 @@ import { groupFromKey } from "./seriesKey";
import { fromDomain } from "./seriesSymbols";
import { toValue } from "../tooltip/selectionData";

const LABEL_PADDING = 5;
Copy link
Member

Choose a reason for hiding this comment

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

Global const is better than magic numbers but we can also read these values from CSS variables if we want - these are cached when the plugin is first rendered so the stylesheet is not queried on every render. See plugin.js for examples.


context.fillText(value, offset, 4);
let magnitude = 10;
Copy link
Member

Choose a reason for hiding this comment

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

... and we should do them all :)

// r = sqrt(A / pi)
const radius = Math.sqrt(
(scale_factor * size(d.size)) / Math.PI
);
Copy link
Member

Choose a reason for hiding this comment

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

This was news to me - I had assumed that the .size() method meant radius, but according to the docs you are indeed correct, this is actually area!

@texodus texodus closed this Dec 28, 2022
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