diff --git a/apps/calculation/additional_outputs/complex_graph_cell.h b/apps/calculation/additional_outputs/complex_graph_cell.h index 7c57b92c8..82c8dd6f9 100644 --- a/apps/calculation/additional_outputs/complex_graph_cell.h +++ b/apps/calculation/additional_outputs/complex_graph_cell.h @@ -14,6 +14,8 @@ private: char * label(Axis axis, int index) const override { return (axis == Axis::Horizontal ? (char *)m_xLabels[index] : (char *)m_yLabels[index]); } + // '-' + significant digits + ".E-" + 2 digits (the represented dot is a float, so it is bounded by 1E38 and 1E-38 + size_t labelMaxGlyphLengthSize() const override { return 1 + Poincare::Preferences::VeryShortNumberOfSignificantDigits + 3 + 2; } char m_xLabels[k_maxNumberOfXLabels][k_labelBufferMaxSize]; char m_yLabels[k_maxNumberOfYLabels][k_labelBufferMaxSize]; ComplexModel * m_complex; diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index caa04acd7..89d8be428 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -177,12 +177,12 @@ void CurveView::computeLabels(Axis axis) { int axisLabelsCount = numberOfLabels(axis); for (int i = 0; i < axisLabelsCount; i++) { float labelValue = labelValueAtIndex(axis, i); - /* Label cannot hold more than k_labelBufferMaxSize characters to prevent + /* Label cannot hold more than k_labelBufferMaxGlyphLength characters to prevent * them from overprinting one another.*/ - int labelMaxGlyphLength = k_labelBufferMaxGlyphLength; + int labelMaxGlyphLength = labelMaxGlyphLengthSize(); if (axis == Axis::Horizontal) { float pixelsPerLabel = maxFloat(0.0f, ((float)Ion::Display::Width)/((float)axisLabelsCount) - k_labelMargin); - labelMaxGlyphLength = minInt(k_labelBufferMaxGlyphLength, pixelsPerLabel/k_font->glyphSize().width()); + labelMaxGlyphLength = minInt(labelMaxGlyphLengthSize(), pixelsPerLabel/k_font->glyphSize().width()); } if (labelValue < step && labelValue > -step) { @@ -849,7 +849,7 @@ void CurveView::computeHorizontalExtremaLabels(bool increaseNumberOfSignificantD labelValueAtIndex(axis, i), label(axis, i), k_labelBufferMaxSize, - k_labelBufferMaxGlyphLength, + labelMaxGlyphLengthSize(), increaseNumberOfSignificantDigits ? k_bigNumberSignificantDigits : k_numberSignificantDigits, Preferences::PrintFloatMode::Decimal); } diff --git a/apps/shared/curve_view.h b/apps/shared/curve_view.h index c0312bae2..1d86abe31 100644 --- a/apps/shared/curve_view.h +++ b/apps/shared/curve_view.h @@ -96,6 +96,7 @@ private: float max(Axis axis) const; float gridUnit(Axis axis) const; virtual char * label(Axis axis, int index) const = 0; + virtual size_t labelMaxGlyphLengthSize() const { return k_labelBufferMaxGlyphLength; } int numberOfLabels(Axis axis) const; /* Recursively join two dots (dichotomy). The method stops when the * maxNumberOfRecursion in reached. */