[apps/shared] CurveView: change API to expose 'drawLabel' and

'drawLabelsAndGraduations'
This commit is contained in:
Émilie Feral
2020-01-07 16:28:20 +01:00
committed by Léa Saviot
parent 98c6f4ba47
commit dfd4811136
6 changed files with 17 additions and 36 deletions

View File

@@ -35,10 +35,10 @@ void ComplexGraphView::drawRect(KDContext * ctx, KDRect rect) const {
}, m_complex, nullptr, Palette::Red, false);
drawAxes(ctx, rect);
drawDot(ctx, rect, real, imag, KDColorBlack);
drawLabel(ctx, rect, Axis::Horizontal, real);
drawLabel(ctx, rect, Axis::Vertical, imag);
drawAxisLabel(ctx, rect, Axis::Horizontal, "Re", real > 0.0f);
drawAxisLabel(ctx, rect, Axis::Vertical, "Im", imag > 0.0f);
//drawLabel(ctx, rect, Axis::Horizontal, real);
//drawLabel(ctx, rect, Axis::Vertical, imag);
//drawAxisLabel(ctx, rect, Axis::Horizontal, "Re", real > 0.0f);
//drawAxisLabel(ctx, rect, Axis::Vertical, "Im", imag > 0.0f);
char buffer[k_labelBufferMaxSize];
PrintFloat::ConvertFloatToText<float>(
std::arg(*m_complex),

View File

@@ -18,7 +18,7 @@ void DistributionCurveView::drawRect(KDContext * ctx, KDRect rect) const {
float upperBound = m_calculation->upperBound();
ctx->fillRect(bounds(), k_backgroundColor);
drawAxis(ctx, rect, Axis::Horizontal);
drawLabels(ctx, rect, Axis::Horizontal, false, false, false, 0, k_backgroundColor);
drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, false, false, false, 0, k_backgroundColor);
if (m_distribution->type() == Distribution::Type::Normal) {
/* Special case for the normal distribution, which has always the same curve
* We indicate the pixels from and to which we color under the curve, not

View File

@@ -220,8 +220,8 @@ void CurveView::computeLabels(Axis axis) {
}
void CurveView::simpleDrawBothAxesLabels(KDContext * ctx, KDRect rect) const {
drawLabels(ctx, rect, Axis::Vertical, true);
drawLabels(ctx, rect, Axis::Horizontal, true);
drawLabelsAndGraduations(ctx, rect, Axis::Vertical, true);
drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, true);
}
void CurveView::drawGraduation(KDContext * ctx, KDRect rect, Axis axis, float grad) const {
@@ -242,7 +242,7 @@ void CurveView::drawGraduation(KDContext * ctx, KDRect rect, Axis axis, float gr
ctx->fillRect(graduation, KDColorBlack);
}
void CurveView::privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, float grad, const char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels, bool shiftOrigin, KDCoordinate viewHeight, KDColor backgroundColor) const {
void CurveView::privateDrawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad, const char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels, bool shiftOrigin, KDCoordinate viewHeight, KDColor backgroundColor) const {
KDCoordinate labelPosition = std::round(floatToPixel(axis, grad));
KDSize textSize = k_font->stringSize(label);
float xPosition = 0.0f;
@@ -287,31 +287,13 @@ void CurveView::privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, fl
}
}
void CurveView::drawAxisLabel(KDContext * ctx, KDRect rect, Axis axis, const char * label, bool minExtremityPosition) const {
void CurveView::drawLabel(KDContext * ctx, KDRect rect, Axis axis, float position, const char * label) const {
float verticalCoordinate = std::round(floatToPixel(Axis::Vertical, 0.0f));
float horizontalCoordinate = std::round(floatToPixel(Axis::Horizontal, 0.0f));
float position = minExtremityPosition ? min(axis) : max(axis);
position *= 0.9f;
privateDrawLabelOnly(ctx, rect, axis, position, label, verticalCoordinate, horizontalCoordinate);
privateDrawLabel(ctx, rect, axis, position, label, verticalCoordinate, horizontalCoordinate);
}
void CurveView::drawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad) const {
drawGraduation(ctx, rect, axis, grad);
float verticalCoordinate = std::round(floatToPixel(Axis::Vertical, 0.0f));
float horizontalCoordinate = std::round(floatToPixel(Axis::Horizontal, 0.0f));
char labelBuffer[k_labelBufferMaxSize];
PrintFloat::ConvertFloatToText<float>(
grad,
labelBuffer,
k_labelBufferMaxSize,
k_labelBufferMaxGlyphLength,
k_numberSignificantDigits,
Preferences::PrintFloatMode::Decimal);
privateDrawLabelOnly(ctx, rect, axis, grad, labelBuffer, verticalCoordinate, horizontalCoordinate);
}
void CurveView::drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin, bool graduationOnly, bool fixCoordinate, KDCoordinate fixedCoordinate, KDColor backgroundColor) const {
void CurveView::drawLabelsAndGraduations(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin, bool graduationOnly, bool fixCoordinate, KDCoordinate fixedCoordinate, KDColor backgroundColor) const {
int numberLabels = numberOfLabels(axis);
if (numberLabels <= 1) {
return;
@@ -380,7 +362,7 @@ void CurveView::drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOr
// Draw the labels
for (int i = minDrawnLabel; i < maxDrawnLabel; i++) {
privateDrawLabelOnly(ctx, rect, axis, labelValueAtIndex(axis, i), label(axis, i), verticalCoordinate, horizontalCoordinate, floatingLabels, shiftOrigin, viewHeight, backgroundColor);
privateDrawLabel(ctx, rect, axis, labelValueAtIndex(axis, i), label(axis, i), verticalCoordinate, horizontalCoordinate, floatingLabels, shiftOrigin, viewHeight, backgroundColor);
}
}

View File

@@ -75,9 +75,8 @@ protected:
bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound = INFINITY, float highlightUpperBound = -INFINITY) const;
void computeLabels(Axis axis);
void simpleDrawBothAxesLabels(KDContext * ctx, KDRect rect) const;
void drawAxisLabel(KDContext * ctx, KDRect rect, Axis axis, const char * label, bool minExtremityPosition) const;
void drawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad) const;
void drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin, bool graduationOnly = false, bool fixCoordinate = false, KDCoordinate fixedCoordinate = 0, KDColor backgroundColor = KDColorWhite) const;
void drawLabel(KDContext * ctx, KDRect rect, Axis axis, float position, const char * label) const;
void drawLabelsAndGraduations(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin, bool graduationOnly = false, bool fixCoordinate = false, KDCoordinate fixedCoordinate = 0, KDColor backgroundColor = KDColorWhite) const;
View * m_bannerView;
CurveViewCursor * m_curveViewCursor;
private:
@@ -88,7 +87,7 @@ private:
Min,
Max
};
void privateDrawLabelOnly(KDContext * ctx, KDRect rect, Axis axis, float grad, const char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels = FloatingPosition::None, bool shiftOrigin = false, KDCoordinate viewHeight = 0, KDColor backgroundColor = KDColorWhite) const;
void privateDrawLabel(KDContext * ctx, KDRect rect, Axis axis, float grad, const char * label, float verticalCoordinate, float horizontalCoordinate, FloatingPosition floatingLabels = FloatingPosition::None, bool shiftOrigin = false, KDCoordinate viewHeight = 0, KDColor backgroundColor = KDColorWhite) const;
void drawGridLines(KDContext * ctx, KDRect rect, Axis axis, float step, KDColor boldColor, KDColor lightColor) const;
/* The window bounds are deduced from the model bounds but also take into
account a margin (computed with k_marginFactor) */

View File

@@ -9,7 +9,7 @@ void BoxAxisView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, KDColorWhite);
KDRect lineRect = KDRect(0, k_axisMargin, bounds().width(), 1);
ctx->fillRect(lineRect, KDColorBlack);
drawLabels(ctx, rect, Axis::Horizontal, false, false, true, k_axisMargin);
drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, false, false, true, k_axisMargin);
}
char * BoxAxisView::label(Axis axis, int index) const {

View File

@@ -42,7 +42,7 @@ void HistogramView::drawRect(KDContext * ctx, KDRect rect) const {
m_controller->setCurrentDrawnSeries(m_series);
ctx->fillRect(rect, KDColorWhite);
drawAxis(ctx, rect, Axis::Horizontal);
drawLabels(ctx, rect, Axis::Horizontal, false, !m_displayLabels);
drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, false, !m_displayLabels);
/* We memoize the total size to avoid recomputing it in double precision at
* every call to EvaluateHistogramAtAbscissa() */
float totalSize = m_store->sumOfOccurrences(m_series);