new plotter

This commit is contained in:
Sergey Solovyev 2013-01-13 21:23:46 +04:00
parent 76719407db
commit f792e4c8ec
5 changed files with 35 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import jscl.math.Generic;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.core.R; import org.solovyev.android.calculator.core.R;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.CalculatorPlotter;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog; import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
@ -79,9 +80,8 @@ public enum CalculatorDisplayMenuItem implements LabeledMenuItem<CalculatorDispl
final Generic expression = data.getResult(); final Generic expression = data.getResult();
assert expression != null; assert expression != null;
Locator.getInstance().getPlotter().removeAllUnpinned(); final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
Locator.getInstance().getPlotter().addFunction(expression); plotter.plot(expression);
Locator.getInstance().getPlotter().plot();
} }
@Override @Override

View File

@ -123,6 +123,11 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
plotter.plot(); plotter.plot();
} }
@Override
public void plot(@NotNull Generic expression) {
plotter.plot(expression);
}
@Override @Override
public boolean is2dPlotPossible() { public boolean is2dPlotPossible() {
return plotter.is2dPlotPossible(); return plotter.is2dPlotPossible();

View File

@ -47,6 +47,7 @@ public interface CalculatorPlotter {
List<PlotFunction> getVisibleFunctions(); List<PlotFunction> getVisibleFunctions();
void plot(); void plot();
void plot(@NotNull Generic expression);
boolean is2dPlotPossible(); boolean is2dPlotPossible();

View File

@ -27,6 +27,8 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
@NotNull @NotNull
private final Calculator calculator; private final Calculator calculator;
private final PlotResourceManager plotResourceManager = new PlotResourceManager();
private boolean plot3d = false; private boolean plot3d = false;
private boolean plotImag = false; private boolean plotImag = false;
@ -71,12 +73,17 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
boolean realAdded = addFunction(new XyFunction(expression, xVariable, yVariable, false)); boolean realAdded = addFunction(new XyFunction(expression, xVariable, yVariable, false));
final PlotFunction imagPlotFunction = new PlotFunction(new XyFunction(expression, xVariable, yVariable, true)); final PlotFunction imagPlotFunction = newPlotFunction(new XyFunction(expression, xVariable, yVariable, true));
final boolean imagAdded = addFunction(plotImag ? imagPlotFunction : PlotFunction.invisible(imagPlotFunction)); final boolean imagAdded = addFunction(plotImag ? imagPlotFunction : PlotFunction.invisible(imagPlotFunction));
return imagAdded || realAdded; return imagAdded || realAdded;
} }
@NotNull
private PlotFunction newPlotFunction(@NotNull XyFunction xyFunction) {
return new PlotFunction(xyFunction);
}
@Override @Override
public boolean addFunction(@NotNull PlotFunction plotFunction) { public boolean addFunction(@NotNull PlotFunction plotFunction) {
synchronized (functions) { synchronized (functions) {
@ -119,7 +126,7 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
@Override @Override
public boolean addFunction(@NotNull XyFunction xyFunction) { public boolean addFunction(@NotNull XyFunction xyFunction) {
return addFunction(new PlotFunction(xyFunction)); return addFunction(newPlotFunction(xyFunction));
} }
@Override @Override
@ -258,6 +265,13 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
calculator.fireCalculatorEvent(CalculatorEventType.plot_graph, null); calculator.fireCalculatorEvent(CalculatorEventType.plot_graph, null);
} }
@Override
public void plot(@NotNull Generic expression) {
removeAllUnpinned();
addFunction(expression);
plot();
}
@Override @Override
public boolean is2dPlotPossible() { public boolean is2dPlotPossible() {
return arity < 2; return arity < 2;

View File

@ -0,0 +1,10 @@
package org.solovyev.android.calculator.plot;
/**
* User: serso
* Date: 1/13/13
* Time: 8:19 PM
*/
class PlotResourceManager {
}