cabana: fix divde by zero for std::log10 (#27077)

fix divde by zero for std::log10
old-commit-hash: 2de2bab2864eeaea8104ac0cbb619c5c25b8b4d6
This commit is contained in:
Dean Lee
2023-01-26 02:59:05 +08:00
committed by GitHub
parent 88e3c87072
commit 455452a1b1
+3
View File
@@ -332,6 +332,9 @@ ChartView::ChartView(QWidget *parent) : QChartView(nullptr, parent) {
}
qreal ChartView::getYAsixLabelWidth() const {
if (axis_y->max() <= axis_y->min() || axis_y->tickCount() <= 1) {
return 0;
}
QFontMetrics fm(axis_y->labelsFont());
int n = qMax(int(-qFloor(std::log10((axis_y->max() - axis_y->min()) / (axis_y->tickCount() - 1)))), 0) + 1;
return qMax(fm.width(QString::number(axis_y->min(), 'f', n)), fm.width(QString::number(axis_y->max(), 'f', n))) + 20;