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 divide by zero error in cloud visualisation #20386

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion plugins/CoreVisualizations/Visualizations/Cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Piwik\Plugins\CoreVisualizations\Visualizations;

use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugin\Visualization;

/**
Expand Down Expand Up @@ -194,7 +195,7 @@ private function getPercentage($popularity, $maxValue)
return 0;
}

$percent = ($popularity / $maxValue) * 100;
$percent = Piwik::getQuotientSafe($popularity, $maxValue, 4) * 100;
Copy link
Member

Choose a reason for hiding this comment

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

This actually changes the resulting precision of the number.
Also it actually only covers the real problem why the calculation fails. I'll add a comment to the original issue around that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking here is that the percent is being used to decide the size of the words in the cloud visualization, the original unsafe division wasn't applying a precision and four digit precision should be enough accuracy to differentiate between words.

It looks like this is too simplistic an approach and would be better fixed in #19940 - I'll close this PR as it was only intended as a possible quick fix.


return $percent;
}
Expand Down