[apps/*/curve_view] Use drawCartesianCurve specifically for drawing Cartesian curves

This commit is contained in:
Ruben Dashyan
2019-08-20 14:00:01 +02:00
committed by Léa Saviot
parent 7d689e22e4
commit fbee2d81e4
5 changed files with 10 additions and 5 deletions

View File

@@ -28,7 +28,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
ExpiringPointer<CartesianFunction> f = m_functionStore->modelForRecord(record);;
/* Draw function */
drawCurve(ctx, rect, [](float t, void * model, void * context) {
drawCartesianCurve(ctx, rect, [](float t, void * model, void * context) {
CartesianFunction * f = (CartesianFunction *)model;
Poincare::Context * c = (Poincare::Context *)context;
return f->evaluateAtAbscissa(t, c);
@@ -39,7 +39,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
float tangentParameter[2];
tangentParameter[0] = f->approximateDerivative(m_curveViewCursor->x(), context());
tangentParameter[1] = -tangentParameter[0]*m_curveViewCursor->x()+f->evaluateAtAbscissa(m_curveViewCursor->x(), context());
drawCurve(ctx, rect, [](float t, void * model, void * context) {
drawCartesianCurve(ctx, rect, [](float t, void * model, void * context) {
float * tangent = (float *)model;
return tangent[0]*t+tangent[1];
}, tangentParameter, nullptr, Palette::GreyVeryDark);

View File

@@ -25,7 +25,7 @@ void DistributionCurveView::drawRect(KDContext * ctx, KDRect rect) const {
return;
}
if (m_distribution->isContinuous()) {
drawCurve(ctx, rect, EvaluateAtAbscissa, m_distribution, nullptr, Palette::YellowDark, true, lowerBound, upperBound);
drawCartesianCurve(ctx, rect, EvaluateAtAbscissa, m_distribution, nullptr, Palette::YellowDark, true, lowerBound, upperBound);
} else {
drawHistogram(ctx, rect, EvaluateAtAbscissa, m_distribution, nullptr, 0, 1, false, Palette::GreyMiddle, Palette::YellowDark, lowerBound, upperBound+0.5f);
}
@@ -51,7 +51,7 @@ void DistributionCurveView::drawStandardNormal(KDContext * ctx, KDRect rect, flo
// Draw a centered reduced normal curve
NormalDistribution n;
constCastedThis->setCurveViewRange(&n);
drawCurve(ctx, rect, EvaluateAtAbscissa, &n, nullptr, Palette::YellowDark, true, colorLowerBound, colorUpperBound);
drawCartesianCurve(ctx, rect, EvaluateAtAbscissa, &n, nullptr, Palette::YellowDark, true, colorLowerBound, colorUpperBound);
// Put back the previous curve view range
constCastedThis->setCurveViewRange(previousRange);

View File

@@ -26,7 +26,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
if (!m_store->seriesIsEmpty(series)) {
KDColor color = Palette::DataColor[series];
Model * seriesModel = m_store->modelForSeries(series);
drawCurve(ctx, rect, [](float abscissa, void * model, void * context) {
drawCartesianCurve(ctx, rect, [](float abscissa, void * model, void * context) {
Model * regressionModel = static_cast<Model *>(model);
double * regressionCoefficients = static_cast<double *>(context);
return (float)regressionModel->evaluate(regressionCoefficients, abscissa);

View File

@@ -527,6 +527,10 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParamet
}
}
void CurveView::drawCartesianCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter yEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound) const {
drawCurve(ctx, rect, yEvaluation, model, context, color, colorUnderCurve, colorLowerBound, colorUpperBound);
}
void CurveView::drawHistogram(KDContext * ctx, KDRect rect, EvaluateModelWithParameter evaluation, void * model, void * context, float firstBarAbscissa, float barWidth,
bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound, float highlightUpperBound) const {
float rectMin = pixelToFloat(Axis::Horizontal, rect.left());

View File

@@ -63,6 +63,7 @@ protected:
void drawAxes(KDContext * ctx, KDRect rect) const;
void drawAxis(KDContext * ctx, KDRect rect, Axis axis) const;
void drawCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter evaluation, void * model, void * context, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
void drawCartesianCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter yEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
void drawHistogram(KDContext * ctx, KDRect rect, EvaluateModelWithParameter evaluation, void * model, void * context, float firstBarAbscissa, float barWidth,
bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound = INFINITY, float highlightUpperBound = -INFINITY) const;
void computeLabels(Axis axis);