[apps/graph/graph] Resolve edge cases in the cursor and range

initialisation

Change-Id: I2685d0bcf93b7bcce9c0ac1b01057f9c9c06ca1f
This commit is contained in:
Émilie Feral
2017-01-27 15:41:40 +01:00
parent 7ca7bb2ebc
commit b8dd0d991d
3 changed files with 19 additions and 5 deletions

View File

@@ -40,7 +40,6 @@ void CurveView::selectMainView(bool mainViewSelected) {
if (m_mainViewSelected != mainViewSelected) {
m_mainViewSelected = mainViewSelected;
reload();
layoutSubviews();
}
}
@@ -391,7 +390,7 @@ void CurveView::layoutSubviews() {
KDCoordinate xCursorPixelPosition = roundf(floatToPixel(Axis::Horizontal, m_curveViewCursor->x()));
KDCoordinate yCursorPixelPosition = roundf(floatToPixel(Axis::Vertical, m_curveViewCursor->y()));
KDRect cursorFrame(xCursorPixelPosition - k_cursorSize/2, yCursorPixelPosition - k_cursorSize/2, k_cursorSize, k_cursorSize);
if (!m_mainViewSelected) {
if (!m_mainViewSelected || isnan(m_curveViewCursor->x()) || isnan(m_curveViewCursor->y())) {
cursorFrame = KDRectZero;
}
m_cursorView->setFrame(cursorFrame);

View File

@@ -80,6 +80,16 @@ bool GraphController::didChangeRange(InteractiveCurveViewRange * interactiveCurv
min = min - 1;
max = max + 1;
}
if (min == FLT_MAX && max == -FLT_MAX) {
min = -1.0f;
max = 1.0f;
}
if (min == FLT_MAX) {
min = max-1.0f;
}
if (max == -FLT_MAX) {
max = min+1.0f;
}
m_graphRange.setYMin(min);
m_graphRange.setYMax(max);
return true;
@@ -132,9 +142,13 @@ void GraphController::initRangeParameters() {
void GraphController::initCursorParameters() {
float x = (m_graphRange.xMin()+m_graphRange.xMax())/2.0f;
m_indexFunctionSelectedByCursor = 0;
Function * firstFunction = m_functionStore->activeFunctionAtIndex(0);
App * graphApp = (Graph::App *)app();
float y = firstFunction->evaluateAtAbscissa(x, graphApp->localContext());
int functionIndex = 0;
float y = 0;
do {
Function * firstFunction = m_functionStore->activeFunctionAtIndex(functionIndex++);
y = firstFunction->evaluateAtAbscissa(x, graphApp->localContext());
} while (isnan(y) && functionIndex < m_functionStore->numberOfActiveFunctions());
m_cursor.moveTo(x, y);
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
}

View File

@@ -93,10 +93,12 @@ bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) {
}
void InteractiveCurveViewController::didBecomeFirstResponder() {
curveView()->selectMainView(true);
uint32_t newModelVersion = modelVersion();
if (m_modelVersion != newModelVersion) {
m_modelVersion = newModelVersion;
initRangeParameters();
initCursorParameters();
}
uint32_t newRangeVersion = rangeVersion();
if (m_rangeVersion != newRangeVersion) {
@@ -104,7 +106,6 @@ void InteractiveCurveViewController::didBecomeFirstResponder() {
initCursorParameters();
}
headerViewController()->setSelectedButton(-1);
curveView()->selectMainView(true);
// Reload graph view
curveView()->reload();
reloadBannerView();