From bb9d6f403849e88776c06c339e999aecfa0539b3 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sun, 13 Jan 2013 21:38:49 +0400 Subject: [PATCH] new plotter --- .../plot/CalculatorPlotterImpl.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java b/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java index 74bba028..19478641 100644 --- a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java @@ -71,9 +71,12 @@ public class CalculatorPlotterImpl implements CalculatorPlotter { yVariable = null; } - boolean realAdded = addFunction(new XyFunction(expression, xVariable, yVariable, false)); - + final PlotFunction realPlotFunction = newPlotFunction(new XyFunction(expression, xVariable, yVariable, false)); final PlotFunction imagPlotFunction = newPlotFunction(new XyFunction(expression, xVariable, yVariable, true)); + + removeAllUnpinnedExcept(realPlotFunction, imagPlotFunction); + + final boolean realAdded = addFunction(realPlotFunction); final boolean imagAdded = addFunction(plotImag ? imagPlotFunction : PlotFunction.invisible(imagPlotFunction)); return imagAdded || realAdded; @@ -97,6 +100,37 @@ public class CalculatorPlotterImpl implements CalculatorPlotter { } } + + private boolean removeAllUnpinnedExcept(@NotNull final PlotFunction... exceptFunctions) { + synchronized (functions) { + + boolean changed = Iterables.removeIf(functions, new Predicate() { + @Override + public boolean apply(@Nullable PlotFunction function) { + if ( function != null && !function.isPinned() ) { + + for (PlotFunction exceptFunction : exceptFunctions) { + if ( exceptFunction.equals(function) ) { + return false; + } + } + + return true; + } else { + return false; + } + } + }); + + if (changed) { + onFunctionsChanged(); + } + + return changed; + } + } + + @Override public void removeAllUnpinned() { synchronized (functions) { @@ -267,7 +301,6 @@ public class CalculatorPlotterImpl implements CalculatorPlotter { @Override public void plot(@NotNull Generic expression) { - removeAllUnpinned(); addFunction(expression); plot(); }