Merge "[apps/sequence] Draw term sum in graph view"

This commit is contained in:
Émilie Feral
2017-03-03 10:55:56 +01:00
committed by Gerrit
4 changed files with 58 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ void GraphController::viewWillAppear() {
m_view.setVerticalCursor(false);
m_view.setCursorView(&m_cursorView);
m_view.setBannerView(&m_bannerView);
m_view.setHighlight(-1.0f, -1.0f);
FunctionGraphController::viewWillAppear();
}

View File

@@ -8,7 +8,11 @@ GraphView::GraphView(SequenceStore * sequenceStore, InteractiveCurveViewRange *
CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
FunctionGraphView(graphRange, cursor, bannerView, cursorView),
m_sequenceStore(sequenceStore),
m_verticalCursor(false)
m_verticalCursor(false),
m_highlightedDotStart(-1),
m_highlightedDotEnd(-1),
m_highlightColor(false),
m_selectedSequence(nullptr)
{
}
@@ -24,6 +28,14 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
continue;
}
drawDot(ctx, rect, x, y, s->color());
if (x >= m_highlightedDotStart && x <= m_highlightedDotEnd && s == m_selectedSequence) {
KDColor color = m_highlightColor ? s->color() : KDColorBlack;
if (y >= 0.0f) {
drawSegment(ctx, rect, Axis::Vertical, x, 0.0f, y, color, 1);
} else {
drawSegment(ctx, rect, Axis::Vertical, x, y, 0.0f, color, 1);
}
}
}
}
}
@@ -32,6 +44,36 @@ void GraphView::setVerticalCursor(bool verticalCursor) {
m_verticalCursor = verticalCursor;
}
void GraphView::reload() {
FunctionGraphView::reload();
markRectAsDirty(bounds());
}
void GraphView::selectSequence(Sequence * sequence) {
if (m_selectedSequence != sequence) {
reload();
m_selectedSequence = sequence;
reload();
}
}
void GraphView::setHighlight(int start, int end) {
if (m_highlightedDotStart != start || m_highlightedDotEnd != end) {
reload();
m_highlightedDotStart = start;
m_highlightedDotEnd = end;
reload();
}
}
void GraphView::setHighlightColor(bool highlightColor) {
if (m_highlightColor != highlightColor) {
reload();
m_highlightColor = highlightColor;
reload();
}
}
float GraphView::evaluateModelWithParameter(Model * curve, float abscissa) const {
Sequence * s = (Sequence *)curve;
return s->evaluateAtAbscissa(abscissa, context());

View File

@@ -12,11 +12,19 @@ public:
Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, View * cursorView);
void drawRect(KDContext * ctx, KDRect rect) const override;
void setVerticalCursor(bool verticalCursor);
void reload() override;
void selectSequence(Sequence * sequence);
void setHighlight(int start, int end);
void setHighlightColor(bool highlightColor);
private:
float evaluateModelWithParameter(Model * expression, float abscissa) const override;
KDSize cursorSize() override;
SequenceStore * m_sequenceStore;
bool m_verticalCursor;
int m_highlightedDotStart;
int m_highlightedDotEnd;
bool m_highlightColor;
Sequence * m_selectedSequence;
};
}

View File

@@ -39,6 +39,8 @@ void TermSumController::viewWillAppear() {
m_contentView.graphView()->setCursorView(&m_cursorView);
m_contentView.graphView()->setBannerView(nullptr);
m_contentView.graphView()->selectMainView(true);
m_contentView.graphView()->setHighlightColor(false);
m_contentView.graphView()->setHighlight(-1.0f,-1.0f);
m_contentView.graphView()->reload();
m_contentView.layoutSubviews();
@@ -101,6 +103,8 @@ bool TermSumController::handleEvent(Ion::Events::Event event) {
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
float sum = m_sequence->sumOfTermsBetweenAbscissa(m_startSum, m_endSum, myApp->localContext());
Complex::convertFloatToText(sum, buffer+2, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_contentView.graphView()->setHighlightColor(true);
m_contentView.graphView()->selectMainView(false);
m_contentView.legendView()->setLegendText(buffer);
}
return false;
@@ -121,6 +125,7 @@ bool TermSumController::moveCursorHorizontallyToPosition(int position) {
m_contentView.legendView()->setSumSubscript(m_cursor->x());
}
if (m_step == 1) {
m_contentView.graphView()->setHighlight(m_startSum, m_cursor->x());
m_contentView.legendView()->setSumSuperscript(m_startSum, m_cursor->x());
}
m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
@@ -128,6 +133,7 @@ bool TermSumController::moveCursorHorizontallyToPosition(int position) {
}
void TermSumController::setSequence(Sequence * sequence) {
m_contentView.graphView()->selectSequence(sequence);
m_sequence = sequence;
}