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

EES-5067 add ref lines between data points on major axis #4757

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

amyb-hiveit
Copy link
Collaborator

Adds the ability to position reference lines between data points on the major axis on vertical bar charts (they can't be added on other types of chart).

Recharts doesn't allow reference lines to be positioned like this: "If the specified x-axis is a category axis, the value of x must be one of the categorys (sic), otherwise no line will be drawn" (https://recharts.org/en-US/api/ReferenceLine), so I've had to be a bit 'creative':

  • the reference line is added to the major axis configuration
  • when the chart is rendered it:
    • moves the line to the minor axis, so the line is rendered horizontally between the two points
    • in CustomReferenceLineLabel it draws a new line perpendicular to the existing one, using the viewbox, chart height and margin to calculate its position
    • hides the existing line by setting its stroke to none

Screenshot 2024-04-16 102419

Screenshot 2024-04-16 104600

Copy link
Collaborator

@sambiramairelogic sambiramairelogic left a comment

Choose a reason for hiding this comment

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

Nice job! I wouldn't have even thought this was possible tbh...

I did notice a few improvements we could make to the validation in the configuration form, but nothing worth addressing in this PR. It's currently possible to add two identical reference lines, which render on top of each other, or to enter 0 as the label pixel width (or indeed something stupid like 100,000). Also, it's possible to get it into a state where it gives validation errors but doesn't say why:
image

But also the problems are immediately obvious in the preview, and easily editable. Also we're never going to be able to create something totally foolproof with this sort of tool anyway, so the users are always going to be able to ask for something silly.

@amyb-hiveit amyb-hiveit merged commit f1e1898 into master Apr 16, 2024
7 checks passed
@amyb-hiveit amyb-hiveit deleted the EES-5067 branch April 16, 2024 12:34
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.

None yet

2 participants