Guarded cases when min and max values of charts are equal.

This commit is contained in:
23rd 2023-10-09 17:59:59 +03:00 committed by John Preston
parent a79e025151
commit 79662dffa4
3 changed files with 16 additions and 3 deletions

View File

@ -80,6 +80,13 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
}
result.measure();
}
if (result.maxValue == result.minValue) {
if (result.minValue) {
result.minValue = 0;
} else {
result.maxValue = 1;
}
}
{
const auto subchart = root.value(u"subchart"_q).toObject();

View File

@ -256,6 +256,10 @@ AbstractChartView::HeightLimits LinearChartView::heightLimits(
maxValueFull = std::max(int(l.maxValue * r), maxValueFull);
minValueFull = std::min(int(l.minValue * r), minValueFull);
}
if (maxValue == minValue) {
maxValue = chartData.maxValue;
minValue = chartData.minValue;
}
return {
.full = Limits{ float64(minValueFull), float64(maxValueFull) },
.ranged = Limits{ float64(minValue), float64(maxValue) },

View File

@ -167,9 +167,11 @@ AbstractChartView::HeightLimits StackChartView::heightLimits(
_cachedHeightLimits.ySum);
_cachedHeightLimits.full = { 0., float64(maxValueFull) };
}
const auto max = _cachedHeightLimits.ySumSegmentTree.rMaxQ(
xIndices.min,
xIndices.max);
const auto max = std::max(
_cachedHeightLimits.ySumSegmentTree.rMaxQ(
xIndices.min,
xIndices.max),
1);
return {
.full = _cachedHeightLimits.full,
.ranged = { 0., float64(max) },