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

Improvements to data labels #103

Merged
merged 6 commits into from
Feb 17, 2025
Merged

Conversation

helenb
Copy link
Contributor

@helenb helenb commented Feb 14, 2025

What is the context of this PR?

  • Previously our custom code to move data labels inside the bars of a bar chart, if the bar chart was wide enough, was only for the situation where the bar was 50px or wider. This does a more accurate test to check the actual width of the data label, and compare it to the width of the bar.
  • Also declares functions more consistently with fat arrows

How to review

  • Create a bar chart visualisation with varied bar widths.
  • Tick 'show value labels' in the styling options
  • Observe if the data labels are inside or outside the bars

Follow-up Actions

List any follow-up actions (if applicable), like needed documentation updates or additional testing.

    - Create a macro that could be repurposed by the design system
    - Tidy up and refactor all the JavaScript
    - Don't include the annotations in the chart config from the back-end, and instead build this in the JavaScript to create the arrows
    - Fix missing annotations JS
… or outside the bar, and a bit of tidying up of function declarations
@helenb helenb requested a review from a team as a code owner February 14, 2025 12:45
Copy link

@nimasmi nimasmi left a comment

Choose a reason for hiding this comment

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

Thanks Helen. The code looks good. I haven't time to user-test this, sorry.

(this.chartType === 'bar' &&
this.useStackedLayout === false &&
this.apiConfig.series.length > 2) ||
this.useStackedLayout === true;
Copy link

Choose a reason for hiding this comment

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

Question: Are stacked and clustered the only two possibilities? And useStackedLayout === false == clustered?

Copy link
Contributor Author

@helenb helenb Feb 17, 2025

Choose a reason for hiding this comment

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

Could be a simple bar without being stacked or clustered, or could be a clustered bar chart with 2 series - in either of those cases hideDataLabels would be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For stacked layouts we always want to hide data labels.

this.postLoadDataLabels(event);
if (!hideDataLabels) {
this.postLoadDataLabels(event);
}
Copy link

Choose a reason for hiding this comment

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

Question: Previously were we calling postLoadDataLabels for any bar, even if we'd set series.dataLabels.enabled to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously we hid them for clustered bar charts with more than 2 series - this updates to hide them for stacked bar charts too.

Comment on lines +147 to +149
const labelWidth = point.dataLabel && point.dataLabel.absoluteBox.width;
// Move the data labels inside the bar if the bar is wider than the label
if (point.shapeArgs.height > labelWidth) {
Copy link

Choose a reason for hiding this comment

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

Praise: Gotcha. Much better. Good change.

@helenb helenb merged commit 432ba38 into feature/datavis Feb 17, 2025
@helenb helenb deleted the fix/data-labels-stacked-chart branch February 17, 2025 08:41
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