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 pie chart data lables #1885

Open
wants to merge 20 commits into
base: xdmod11.0
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions classes/DataWarehouse/Visualization/AggregateChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,13 +983,20 @@ public function configure(
}
}
// Dont add data labels for all pie slices. Plotly will render all labels otherwise,
// which causes the margin on pie charts with many slices to break
// which causes the margin on pie charts with many slices to break.
// Show all labels on thumbnail plots because slices can be difficult to hover over
// due to size of plot.
$labelLimit = 12;
$labelsAllocated = 0;
$pieSum = array_sum($yValues);
for ($i = 0; $i < count($xValues); $i++) {
if ($isThumbnail || (($labelsAllocated < $labelLimit) && (($yValues[$i] / $pieSum) * 100) >= 2.0)) {
$text[] = '<b>' . $xValues[$i] . '</b><br>' . number_format($yValues[$i], $decimals, '.', ',');
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) {
$label = mb_substr($xValues[$i], 0, 40) . '...';
}
$text[] = '<b>' . $label . '</b><br>' . number_format($yValues[$i], $decimals, '.', ',');
$labelsAllocated++;
}
else {
Expand Down