Skip to content

Fix pie chart data lables#1885

Merged
aestoltm merged 22 commits intoubccr:xdmod11.0from
aestoltm:plotly_pie_chart_margin
Jan 2, 2025
Merged

Fix pie chart data lables#1885
aestoltm merged 22 commits intoubccr:xdmod11.0from
aestoltm:plotly_pie_chart_margin

Conversation

@aestoltm
Copy link
Copy Markdown
Contributor

@aestoltm aestoltm commented Jul 15, 2024

Risk: LOW
Severity: MEDIUM (heavily affects readability of some pie charts)

Description

These changes fix the pie chart margin for when very long data labels are showing.

Also discovered that pie chart margin for some of the interactive charts have clipping with the data labels. This fix is non-trivial and will require some more effort in a separate PR. This is because the margin for pie charts may need to be re-worked entirely due to interactions with the subtitle, and different legend locations.

Motivation and Context

Pie charts with long data labels were barely visible

Tests performed

Tested on xdmod-dev

Checklist:

  • The pull request description is suitable for a Changelog entry
  • The milestone is set correctly on the pull request
  • The appropriate labels have been added to the pull request

@aestoltm aestoltm requested review from connersaeli and jpwhite4 July 15, 2024 18:20
@aestoltm aestoltm added this to the 11.0.1 milestone Oct 2, 2024
@aestoltm aestoltm modified the milestones: 11.0.1, 11.0.2 Oct 4, 2024
@aestoltm aestoltm changed the base branch from main to xdmod11.0 November 22, 2024 19:00
@aestoltm aestoltm added the bug Bugfixes label Dec 3, 2024
@aestoltm aestoltm changed the title Fix exported pie chart margin Fix pie chart data lables Dec 17, 2024
if ($isThumbnail || ($labelsAllocated < $labelLimit && (($yValues[$i] / $pieSum) * 100) >= 2.0)) {
$label = $xValues[$i];
// Truncate long data labels to improve visibility.
if (strlen($xValues[$i]) >= 70) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (strlen($xValues[$i]) >= 70) {
if (mb_strlen($label) >= 70) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also why only keep 40 characters but have the threshold set to 70 bytes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if 69 characters fits then why not have:

if (mb_strlen($label) >= LABLE_TRUNCATE_LEN) {
   $label = mb_substr($label, 0, LABLE_TRUNCATE_LEN - 3) . '...';
}

where LABLE_TRUNCATE_LEN would be set to something sensible (presumably between 40 and 70).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why I had those set so differently. Should be addressed now.

@aestoltm aestoltm requested a review from jpwhite4 January 2, 2025 21:04
@aestoltm aestoltm merged commit 18c0fb4 into ubccr:xdmod11.0 Jan 2, 2025
@aestoltm aestoltm deleted the plotly_pie_chart_margin branch January 2, 2025 21:33
aaronweeden pushed a commit to aaronweeden/xdmod that referenced this pull request Feb 10, 2025
* Truncate long data labels for pie charts to improve the visibility of the plot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bugfixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants