diff --git a/apps/graph/function_store.cpp b/apps/graph/function_store.cpp index ad389d7f1..d17b91dc5 100644 --- a/apps/graph/function_store.cpp +++ b/apps/graph/function_store.cpp @@ -80,7 +80,7 @@ int FunctionStore::numberOfFunctions() { int FunctionStore::numberOfActiveFunctions() { int result = 0; for (int i = 0; i < m_numberOfFunctions; i++) { - if (m_functions[i].isActive()) { + if (m_functions[i].layout() != nullptr && m_functions[i].isActive()) { result++; } } diff --git a/apps/graph/function_store.h b/apps/graph/function_store.h index a30cd1e1e..370fbbbfd 100644 --- a/apps/graph/function_store.h +++ b/apps/graph/function_store.h @@ -15,7 +15,9 @@ public: Function * addEmptyFunction(); void removeFunction(Function * f); int numberOfFunctions(); + // Functions can be undefined when they have a color and a name but no content int numberOfDefinedFunctions(); + // An active function must be defined to be counted int numberOfActiveFunctions(); static constexpr int k_maxNumberOfFunctions = 8; private: diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 8f2e15ff2..7f96e2183 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -166,21 +166,19 @@ KDCoordinate GraphView::floatToPixel(Axis axis, float f) const { void GraphView::drawFunction(KDContext * ctx, KDRect rect) const { KDColor workingBuffer[k_stampSize*k_stampSize]; - for (int i=0; inumberOfDefinedFunctions(); i++) { - Function * f = m_functionStore->definedFunctionAtIndex(i); - if (f->isActive()) { - float y = 0.0f; - float x = 0.0f; - for (KDCoordinate px = rect.x()-k_stampSize; pxevaluateAtAbscissa(x, m_evaluateContext); - KDCoordinate py = floatToPixel(Axis::Vertical, y); - stampAtLocation(px, py, f->color(), ctx, workingBuffer); - if (px > rect.x()-k_stampSize) { + for (int i=0; inumberOfActiveFunctions(); i++) { + Function * f = m_functionStore->activeFunctionAtIndex(i); + float y = 0.0f; + float x = 0.0f; + for (KDCoordinate px = rect.x()-k_stampSize; pxevaluateAtAbscissa(x, m_evaluateContext); + KDCoordinate py = floatToPixel(Axis::Vertical, y); + stampAtLocation(px, py, f->color(), ctx, workingBuffer); + if (px > rect.x()-k_stampSize) { jointDots(previousX, previousY, x, y, f, k_maxNumberOfIterations, ctx, workingBuffer); - } } } }