From 776a162b2dd927dd21315ce6b6e9bd0654d21e5a Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Wed, 5 Dec 2012 14:08:02 +0400 Subject: [PATCH] change --- .../plot/CalculatorPlotFragment.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFragment.java index 95cf64d0..cbb0996b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFragment.java @@ -24,6 +24,7 @@ import jscl.math.Generic; import jscl.math.function.Constant; import jscl.text.ParseException; import org.achartengine.chart.XYChart; +import org.achartengine.model.XYMultipleSeriesDataset; import org.achartengine.model.XYSeries; import org.achartengine.renderer.XYMultipleSeriesRenderer; import org.achartengine.tools.PanListener; @@ -323,37 +324,40 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul plotExecutor.execute(new Runnable() { @Override public void run() { - final XYMultipleSeriesRenderer dr = chart.getRenderer(); + final XYMultipleSeriesRenderer dr = chart.getRenderer(); - final MyXYSeries realSeries = (MyXYSeries) chart.getDataset().getSeriesAt(0); + final XYMultipleSeriesDataset dataset = chart.getDataset(); + if (dataset != null && dr != null) { + final MyXYSeries realSeries = (MyXYSeries) dataset.getSeriesAt(0); - final MyXYSeries imagSeries; - if (chart.getDataset().getSeriesCount() > 1) { - imagSeries = (MyXYSeries) chart.getDataset().getSeriesAt(1); - } else { - imagSeries = new MyXYSeries(PlotUtils.getImagFunctionName(variable), PlotUtils.DEFAULT_NUMBER_OF_STEPS * 2); - } - - try { - if (dr != null) { - if (PlotUtils.addXY(dr.getXAxisMin(), dr.getXAxisMax(), expression, variable, realSeries, imagSeries, true, PlotUtils.DEFAULT_NUMBER_OF_STEPS)) { - if (chart.getDataset().getSeriesCount() <= 1) { - chart.getDataset().addSeries(imagSeries); - chart.getRenderer().addSeriesRenderer(PlotUtils.createImagRenderer(imagLineColor.getColor())); - } + if (realSeries != null) { + final MyXYSeries imagSeries; + if (dataset.getSeriesCount() > 1) { + imagSeries = (MyXYSeries) dataset.getSeriesAt(1); + } else { + imagSeries = new MyXYSeries(PlotUtils.getImagFunctionName(variable), PlotUtils.DEFAULT_NUMBER_OF_STEPS * 2); } - } - } catch (ArithmeticException e) { - PlotUtils.handleArithmeticException(e, CalculatorPlotFragment.this); - } - uiHandler.post(new Runnable() { - @Override - public void run() { - graphicalView.repaint(); - } - }); - } + try { + if (PlotUtils.addXY(dr.getXAxisMin(), dr.getXAxisMax(), expression, variable, realSeries, imagSeries, true, PlotUtils.DEFAULT_NUMBER_OF_STEPS)) { + if (dataset.getSeriesCount() <= 1) { + dataset.addSeries(imagSeries); + dr.addSeriesRenderer(PlotUtils.createImagRenderer(imagLineColor.getColor())); + } + } + } catch (ArithmeticException e) { + PlotUtils.handleArithmeticException(e, CalculatorPlotFragment.this); + } + + uiHandler.post(new Runnable() { + @Override + public void run() { + graphicalView.repaint(); + } + }); + } + } + } }); } }