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 jscl.NumeralBase;
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.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.ExpressionFunction;
import org.solovyev.android.plotter.Plotter;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
public class DisplayFragment extends BaseFragment implements View.OnClickListener,
MenuItem.OnMenuItemClickListener {
@ -80,10 +86,16 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene
@Inject
SharedPreferences preferences;
@Inject
ErrorReporter errorReporter;
@Inject
Display display;
@Inject
ActivityLauncher launcher;
@Inject
Bus bus;
@Inject
Plotter plotter;
@Inject
Calculator calculator;
public DisplayFragment() {
@ -134,7 +146,8 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene
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);
}
}
@ -204,7 +217,19 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene
return true;
case R.string.c_plot:
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;
default:

View File

@ -9,7 +9,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import butterknife.Bind;
import jscl.math.function.CustomFunction;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent;
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.Plotter;
import org.solovyev.android.plotter.meshes.MeshSpec;
import java.util.ArrayList;
import java.util.List;
import uz.shift.colorpicker.LineColorPicker;
import uz.shift.colorpicker.OnColorChangedListener;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import butterknife.Bind;
import jscl.math.function.Constant;
import jscl.math.function.CustomFunction;
import uz.shift.colorpicker.LineColorPicker;
import uz.shift.colorpicker.OnColorChangedListener;
import java.util.ArrayList;
import java.util.List;
public class PlotEditFunctionFragment extends BaseFunctionFragment
implements SeekBar.OnSeekBarChangeListener {
@ -157,9 +153,6 @@ public class PlotEditFunctionFragment extends BaseFunctionFragment
protected boolean applyData(@Nonnull CppFunction function) {
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 =
new ExpressionFunction(function.toJsclBuilder().create(), false);
final PlotFunction plotFunction = PlotFunction.create(expressionFunction,