Plot from display

This commit is contained in:
serso 2016-02-27 00:26:53 +01:00
parent c602e552c7
commit 4070de7693
2 changed files with 33 additions and 15 deletions

View File

@ -37,11 +37,17 @@ import butterknife.ButterKnife;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import jscl.NumeralBase; import jscl.NumeralBase;
import jscl.math.Generic; import jscl.math.Generic;
import jscl.math.function.Constant;
import jscl.math.function.CustomFunction;
import org.solovyev.android.calculator.converter.ConverterFragment; import org.solovyev.android.calculator.converter.ConverterFragment;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.ExpressionFunction;
import org.solovyev.android.plotter.Plotter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
public class DisplayFragment extends BaseFragment implements View.OnClickListener, public class DisplayFragment extends BaseFragment implements View.OnClickListener,
MenuItem.OnMenuItemClickListener { MenuItem.OnMenuItemClickListener {
@ -80,10 +86,16 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene
@Inject @Inject
SharedPreferences preferences; SharedPreferences preferences;
@Inject @Inject
ErrorReporter errorReporter;
@Inject
Display display; Display display;
@Inject @Inject
ActivityLauncher launcher;
@Inject
Bus bus; Bus bus;
@Inject @Inject
Plotter plotter;
@Inject
Calculator calculator; Calculator calculator;
public DisplayFragment() { public DisplayFragment() {
@ -134,7 +146,8 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene
addMenu(menu, R.string.c_convert, this); addMenu(menu, R.string.c_convert, this);
} }
} }
if (Locator.getInstance().getPlotter().isPlotPossibleFor(result)) { final int parameters = CalculatorUtils.getNotSystemConstants(result).size();
if (parameters >= 0 && parameters <= 2) {
addMenu(menu, R.string.c_plot, this); addMenu(menu, R.string.c_plot, this);
} }
} }
@ -204,7 +217,19 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene
return true; return true;
case R.string.c_plot: case R.string.c_plot:
if (result != null) { if (result != null) {
Locator.getInstance().getPlotter().plot(result); try {
final List<String> parameters = new ArrayList<>();
for (Constant parameter : CalculatorUtils.getNotSystemConstants(result)) {
parameters.add(parameter.getName());
}
new CustomFunction.Builder().setParameterNames(parameters).setContent(state.text).create();
final CustomFunction f = new CustomFunction.Builder().setName("").setParameterNames(parameters).setContent(result.toString()).create();
final ExpressionFunction ef = new ExpressionFunction(f, false);
plotter.add(ef);
launcher.showPlotter();
} catch (RuntimeException e) {
errorReporter.onException(e);
}
} }
return true; return true;
default: default:

View File

@ -9,7 +9,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import butterknife.Bind;
import jscl.math.function.CustomFunction;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent; import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
@ -20,18 +21,13 @@ import org.solovyev.android.plotter.PlotFunction;
import org.solovyev.android.plotter.PlotIconView; import org.solovyev.android.plotter.PlotIconView;
import org.solovyev.android.plotter.Plotter; import org.solovyev.android.plotter.Plotter;
import org.solovyev.android.plotter.meshes.MeshSpec; import org.solovyev.android.plotter.meshes.MeshSpec;
import uz.shift.colorpicker.LineColorPicker;
import java.util.ArrayList; import uz.shift.colorpicker.OnColorChangedListener;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import butterknife.Bind; import java.util.List;
import jscl.math.function.Constant;
import jscl.math.function.CustomFunction;
import uz.shift.colorpicker.LineColorPicker;
import uz.shift.colorpicker.OnColorChangedListener;
public class PlotEditFunctionFragment extends BaseFunctionFragment public class PlotEditFunctionFragment extends BaseFunctionFragment
implements SeekBar.OnSeekBarChangeListener { implements SeekBar.OnSeekBarChangeListener {
@ -157,9 +153,6 @@ public class PlotEditFunctionFragment extends BaseFunctionFragment
protected boolean applyData(@Nonnull CppFunction function) { protected boolean applyData(@Nonnull CppFunction function) {
try { try {
final List<String> parameters = function.getParameters();
final Constant x = parameters.size() > 0 ? new Constant(parameters.get(0)) : null;
final Constant y = parameters.size() > 1 ? new Constant(parameters.get(1)) : null;
final ExpressionFunction expressionFunction = final ExpressionFunction expressionFunction =
new ExpressionFunction(function.toJsclBuilder().create(), false); new ExpressionFunction(function.toJsclBuilder().create(), false);
final PlotFunction plotFunction = PlotFunction.create(expressionFunction, final PlotFunction plotFunction = PlotFunction.create(expressionFunction,