private void onS2CheckBoxClicked(boolean checked) { if (checked) { plot.addSeries(series2, formatter2); } else { plot.removeSeries(series2); } plot.redraw(); }
@SuppressWarnings("deprecation") public void drawGraph( XYPlot plot, List<Number> xseries, List<Number> yseries, String datatitle, String title) { // Log.d(SystemInfo.TIG, TAG + "::drawGraph()"); // set up data series plot.removeSeries(series); series = new SimpleXYSeries(xseries, yseries, datatitle); // create a formatter // TODO solve deprecation waring LineAndPointFormatter format = new LineAndPointFormatter( Color.rgb(0, 200, 0) // line color , Color.rgb(0, 100, 0) // point color , Color.rgb(150, 190, 150)); // fill color (optional) // add series1 and series2 to the XYPlot plot.addSeries(series, format); // Reduce the number of range labels plot.setTicksPerRangeLabel(3); plot.getBackgroundPaint().setAlpha(0); plot.getGraphWidget().getBackgroundPaint().setAlpha(0); plot.getGraphWidget().getGridBackgroundPaint().setAlpha(0); // TODO implement an on-the-fly refresh of the plot // this is just a small "stubbed" redraw for demonstration purposes plot.setDomainStepMode(XYStepMode.SUBDIVIDE); plot.setDomainStepValue(1); plot.setGridPadding(0, 5, 0, 5); plot.setDomainLabel("Time [s]"); if (title.equals(SystemInfo.DB_TABLENAME_BATTERY)) { plot.setTitle(SystemInfo.DB_TABLENAME_BATTERY); plot.setRangeLabel("[%]"); plot.setRangeBoundaries(0, 100, BoundaryMode.FIXED); } else if (title.equals(SystemInfo.DB_TABLENAME_WIFI)) { plot.setTitle(SystemInfo.DB_TABLENAME_WIFI); plot.setRangeLabel("[~mW]"); plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); } else if (title.equals(SystemInfo.DB_TABLENAME_THREEG)) { plot.setTitle(SystemInfo.DB_TABLENAME_THREEG); plot.setRangeLabel("[~mW]"); plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); } else if (title.equals(SystemInfo.DB_TABLENAME_BLUETOOTH)) { plot.setTitle(SystemInfo.DB_TABLENAME_BLUETOOTH); plot.setRangeLabel("[~mW]"); plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); // XXX scale } plot.redraw(); }
private void plotTemperatureHistory() { SensorHistory temperatureLongHistory = new SensorHistory( Environment.getExternalStorageDirectory().getPath() + "/Sensors/temperature.dat"); longHistoryPlot.setRangeLabel("Temperature (ºC)"); longHistoryPlot.getRangeLabelWidget().pack(); longHistorySeries.setModel(temperatureLongHistory, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); longHistoryPlot.redraw(); }
private void plotAltitudeHistory() { SensorHistory altitudeLongHistory = new SensorHistory( Environment.getExternalStorageDirectory().getPath() + "/Sensors/altitude.dat"); longHistoryPlot.setRangeLabel("Altitude (m)"); longHistoryPlot.getRangeLabelWidget().pack(); longHistorySeries.setModel(altitudeLongHistory, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); longHistoryPlot.redraw(); }
private void onPlotClicked(PointF point) { // make sure the point lies within the graph area. we use gridrect // because it accounts for margins and padding as well. if (plot.containsPoint(point.x, point.y)) { Number x = plot.getXVal(point); Number y = plot.getYVal(point); selection = null; double xDistance = 0; double yDistance = 0; // find the closest value to the selection: for (SeriesBundle<XYSeries, ? extends XYSeriesFormatter> sfPair : plot.getRegistry().getSeriesAndFormatterList()) { XYSeries series = sfPair.getSeries(); for (int i = 0; i < series.size(); i++) { Number thisX = series.getX(i); Number thisY = series.getY(i); if (thisX != null && thisY != null) { double thisXDistance = Region.measure(x, thisX).doubleValue(); double thisYDistance = Region.measure(y, thisY).doubleValue(); if (selection == null) { selection = new Pair<>(i, series); xDistance = thisXDistance; yDistance = thisYDistance; } else if (thisXDistance < xDistance) { selection = new Pair<>(i, series); xDistance = thisXDistance; yDistance = thisYDistance; } else if (thisXDistance == xDistance && thisYDistance < yDistance && thisY.doubleValue() >= y.doubleValue()) { selection = new Pair<>(i, series); xDistance = thisXDistance; yDistance = thisYDistance; } } } } } else { // if the press was outside the graph area, deselect: selection = null; } if (selection == null) { selectionWidget.setText(NO_SELECTION_TXT); } else { selectionWidget.setText( "Selected: " + selection.second.getTitle() + " Value: " + selection.second.getY(selection.first)); } plot.redraw(); }
private void updatePlot(SeriesSize seriesSize) { // Remove all current series from each plot plot.clear(); // Setup our Series with the selected number of elements series1 = new SimpleXYSeries( Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Us"); series2 = new SimpleXYSeries( Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Them"); plot.setDomainBoundaries(-1, series1.size(), BoundaryMode.FIXED); plot.setRangeUpperBoundary( SeriesUtils.minMax(series1, series2).getMaxY().doubleValue() + 1, BoundaryMode.FIXED); if (seriesSize != null) { switch (seriesSize) { case TEN: plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 2); break; case TWENTY: plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 4); break; case SIXTY: plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 6); break; } } // add a new series' to the xyplot: if (series1CheckBox.isChecked()) plot.addSeries(series1, formatter1); if (series2CheckBox.isChecked()) plot.addSeries(series2, formatter2); // Setup the BarRenderer with our selected options MyBarRenderer renderer = plot.getRenderer(MyBarRenderer.class); renderer.setBarOrientation((BarRenderer.BarOrientation) spRenderStyle.getSelectedItem()); final BarRenderer.BarGroupWidthMode barGroupWidthMode = (BarRenderer.BarGroupWidthMode) spWidthStyle.getSelectedItem(); renderer.setBarGroupWidth( barGroupWidthMode, barGroupWidthMode == BarRenderer.BarGroupWidthMode.FIXED_WIDTH ? sbFixedWidth.getProgress() : sbVariableWidth.getProgress()); if (BarRenderer.BarOrientation.STACKED.equals(spRenderStyle.getSelectedItem())) { plot.getInnerLimits().setMaxY(15); } else { plot.getInnerLimits().setMaxY(0); } plot.redraw(); }
@Override public void run() { try { while (true) { Log.d("graph", "foi"); if (wifi.isWifiEnabled()) { WifiInfo wifiINFO = wifi.getConnectionInfo(); Log.d("MyDebug", "" + wifiINFO.getIpAddress()); wifi.startScan(); List<ScanResult> sr = wifi.getScanResults(); for (WifiStrengthXYSeries s : hash.values()) { plot.removeSeries(s); } plot.removeMarkers(); for (ScanResult r : sr) { WifiStrengthXYSeries series = hash.get(r.SSID); if (series == null) { series = new WifiStrengthXYSeries( r.SSID, (r.frequency - 2407) / 5, r.level, ColorPool.getColor(hash.size()), ColorPool.getTransparentColor(hash.size())); hash.put(r.SSID, series); } else { series.setChannel((r.frequency - 2407) / 5); series.setStrength(r.level); series.update(); } plot.addSeries(series, series.getFormatter()); plot.addMarker( series.getMarker(activity.getResources().getConfiguration().orientation)); } plot.redraw(); } Thread.sleep(1000); } } catch (InterruptedException e) { for (WifiStrengthXYSeries s : hash.values()) { plot.removeSeries(s); } } }
public void onSensorChanged(SensorEvent event) { String valuesString = ""; int counter = 0; for (float value : event.values) { valuesString += String.format("%d) %f ", counter++, value); } valuesString += " , " + pressureHistory.size(); textViewPressure.setText(valuesString); double value = pressureSmoothingWin.push((double) event.values[0]); // Number[] series1Numbers = {event.values[0], event.values[1], // event.values[2]}; // get rid the oldest sample in history: if (pressureHistory.size() > HISTORY_SIZE) { pressureHistory.removeFirst(); } // add the latest history sample: pressureHistory.addLast(value); // event.values[0]); value = altitudeSmoothingWin.push((double) event.values[1]); if (altitudeHistory.size() > HISTORY_SIZE) { altitudeHistory.removeFirst(); } altitudeHistory.addLast(value); // event.values[0]); value = tempSmoothingWin.push((double) event.values[2]); if (tempHistory.size() > HISTORY_SIZE) { tempHistory.removeFirst(); } tempHistory.addLast(value); if (cooler++ % 2 == 0) return; // update the plot with the updated history Lists: if (sensorId == 0) { pressureHistorySeries.setModel(pressureHistory, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); preHistoryPlot.setRangeLabel("Pressure (hPa)"); } else if (sensorId == 1) { pressureHistorySeries.setModel(altitudeHistory, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); preHistoryPlot.setRangeLabel("Altitude (m)"); } else { pressureHistorySeries.setModel(tempHistory, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); preHistoryPlot.setRangeLabel("Temperature (ºC)"); } // redraw the Plots: preHistoryPlot.redraw(); }
public boolean onTouch(View arg0, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Start gesture firstFinger = new PointF(event.getX(), event.getY()); mode = ONE_FINGER_DRAG; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: // When the gesture ends, a thread is created to give inertia to the scrolling and zoom final Timer t = new Timer(); t.schedule( new TimerTask() { @Override public void run() { while (Math.abs(lastScrolling) > 1f || Math.abs(lastZooming - 1) > 1.01) { lastScrolling *= .8; // speed of scrolling damping scroll(lastScrolling); lastZooming += (1 - lastZooming) * .2; // speed of zooming damping zoom(lastZooming); graph.redraw(); } } }, 0); break; case MotionEvent.ACTION_MOVE: if (mode == ONE_FINGER_DRAG) { final PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); lastScrolling = oldFirstFinger.x - firstFinger.x; scroll(lastScrolling); lastZooming = (firstFinger.y - oldFirstFinger.y) / graph.getHeight(); if (lastZooming < 0) lastZooming = 1 / (1 - lastZooming); else lastZooming += 1; zoom(lastZooming); graph.redraw(); } break; } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.zoomscrollgraph); mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); mySimpleXYPlot.setOnTouchListener(this); // Plot layout configurations mySimpleXYPlot.getGraphWidget().setTicksPerRangeLabel(1); mySimpleXYPlot.getGraphWidget().setTicksPerDomainLabel(1); mySimpleXYPlot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##")); mySimpleXYPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("#####.##")); mySimpleXYPlot.getGraphWidget().setRangeLabelWidth(25); mySimpleXYPlot.setRangeLabel(""); mySimpleXYPlot.setDomainLabel(""); mySimpleXYPlot.disableAllMarkup(); // Creation of the series final Vector<Double> vector = new Vector<Double>(); for (double x = 0.0; x < Math.PI * 5; x += Math.PI / 20) { vector.add(x); vector.add(Math.sin(x)); } mySeries = new SimpleXYSeries(vector, ArrayFormat.Y_VALS_ONLY, "Series Name"); // colors: (line, vertex, fill) mySimpleXYPlot.addSeries( mySeries, LineAndPointRenderer.class, new LineAndPointFormatter( Color.rgb(0, 200, 0), Color.rgb(200, 0, 0), Color.argb(100, 0, 0, 100))); // Enact all changes mySimpleXYPlot.redraw(); // Set of internal variables for keeping track of the boundaries mySimpleXYPlot.calculateMinMaxVals(); m_viewPort = new Viewport(mySimpleXYPlot); }
@Override public boolean onTouch(View arg0, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Start gesture firstFinger = new PointF(event.getX(), event.getY()); mode = ONE_FINGER_DRAG; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: // When the gesture ends, a thread is created to give inertia to the scrolling and zoom final Timer t = new Timer(); t.schedule( new TimerTask() { @Override public void run() { while (Math.abs(lastScrolling) > 1f || Math.abs(lastZooming - 1) < 1.01) { lastScrolling *= .8; // speed of scrolling damping m_viewPort.scroll(lastScrolling); lastZooming += (1 - lastZooming) * .2; // speed of zooming damping m_viewPort.zoom(lastZooming); checkBoundaries(); try { mySimpleXYPlot.postRedraw(); } catch (final InterruptedException e) { e.printStackTrace(); } // the thread lives until the scrolling and zooming are imperceptible } } }, 0); case MotionEvent.ACTION_POINTER_DOWN: // second finger distBetweenFingers = spacing(event); // the distance check is done to avoid false alarms if (distBetweenFingers > 5f) mode = TWO_FINGERS_DRAG; break; case MotionEvent.ACTION_MOVE: if (mode == ONE_FINGER_DRAG) { final PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); lastScrolling = oldFirstFinger.x - firstFinger.x; m_viewPort.scroll(lastScrolling); lastZooming = (firstFinger.y - oldFirstFinger.y) / mySimpleXYPlot.getHeight(); if (lastZooming < 0) lastZooming = 1 / (1 - lastZooming); else lastZooming += 1; m_viewPort.zoom(lastZooming); checkBoundaries(); mySimpleXYPlot.redraw(); } // else if (mode == TWO_FINGERS_DRAG) { // final float oldDist = distBetweenFingers; // distBetweenFingers = spacing(event); // lastZooming = oldDist / distBetweenFingers; // m_viewPort.zoom(lastZooming); // checkBoundaries(); // mySimpleXYPlot.redraw(); // } break; } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.poincare); // Rellenar vector RR1 for (int i = 1; i < Representar.RR.size(); i++) { RR1.add(Representar.RR.get(i)); } // Rellenar vector RRaux for (int i = 0; i < Representar.RR.size() - 1; i++) { RRaux.add(Representar.RR.get(i)); Log.i("RRaux", String.valueOf(Representar.RR.get(i))); } // Declarar el Plot mySimpleXYPlot = (XYPlot) findViewById(R.id.plotPoincare); // Configurar el Plot XYSeries series1 = new SimpleXYSeries( RRaux, // Vector a representar en el eje X RR1, // Vector a representar en el eje Y "Poincaré"); // Etiqueta LineAndPointFormatter series1Format = new LineAndPointFormatter( Color.TRANSPARENT, // Color de la línea Color.rgb( Representar.color0, Representar.color1, Representar.color2), // Color de los puntos null); // Color de relleno // Propiedades para configurar el Plot mySimpleXYPlot.addSeries(series1, series1Format); mySimpleXYPlot.setTicksPerRangeLabel(4); mySimpleXYPlot.disableAllMarkup(); mySimpleXYPlot.getBackgroundPaint().setAlpha(0); mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setAlpha(0); mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setAlpha(0); // Redibujar el Plot mySimpleXYPlot.redraw(); // Configuración boundaries mySimpleXYPlot.calculateMinMaxVals(); // Cálculo del valor mínimo y máximo minXY = new PointF( mySimpleXYPlot.getCalculatedMinX().floatValue(), mySimpleXYPlot.getCalculatedMinY().floatValue()); maxXY = new PointF( mySimpleXYPlot.getCalculatedMaxX().floatValue(), mySimpleXYPlot.getCalculatedMaxY().floatValue()); mySimpleXYPlot.setScrollbarFadingEnabled(true); mySimpleXYPlot.setScrollContainer(true); mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getLegendWidget()); // Etiquetas vertical y horizontal mySimpleXYPlot.setRangeLabel("RR N+1"); mySimpleXYPlot.setDomainLabel("RR N"); mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getTitleWidget()); // Márgenes del Plot mySimpleXYPlot.setPlotMargins(10, 10, 10, 10); mySimpleXYPlot.setPlotPadding(10, 10, 10, 10); // Comienzo y fin del plot mySimpleXYPlot.setDomainBoundaries( mySimpleXYPlot.getCalculatedMinX().floatValue() - 10.0, mySimpleXYPlot.getCalculatedMaxX().floatValue() + 10.0, BoundaryMode.FIXED); mySimpleXYPlot.setRangeBoundaries( mySimpleXYPlot.getCalculatedMinY().floatValue() - 10.0, mySimpleXYPlot.getCalculatedMaxY().floatValue() + 10.0, BoundaryMode.FIXED); }
private void ShowPlot() { mySimpleXYPlot = (XYPlot) findViewById(R.id.chartPlot); mySimpleXYPlot.setTitle("Weight"); if (plotLine != null) mySimpleXYPlot.removeSeries(plotLine); mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK); mySimpleXYPlot .getGraphWidget() .getGridLinePaint() .setPathEffect(new DashPathEffect(new float[] {1, 1}, 1)); mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null); mySimpleXYPlot.getBorderPaint().setStrokeWidth(1); mySimpleXYPlot.getBorderPaint().setAntiAlias(false); mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE); mySimpleXYPlot.getGraphWidget().setPaddingRight(5); // Create a formatter to use for drawing a series using LineAndPointRenderer: LineAndPointFormatter series1Format = new LineAndPointFormatter( Color.rgb(0, 100, 0), // line color Color.rgb(0, 100, 0), // point color Color.rgb(100, 200, 0)); // fill color // setup our line fill paint to be a slightly transparent gradient: Paint lineFill = new Paint(); lineFill.setAlpha(200); lineFill.setShader( new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR)); LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.BLUE, Color.RED); formatter.setFillPaint(lineFill); plotLine = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(weights), "Weight over time"); mySimpleXYPlot.addSeries(plotLine, formatter); mySimpleXYPlot.redraw(); // draw a domain tick for each year: int min = DomainMin(); int max = DomainMax(); int domainStep = domainStep(min, max); mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, domainStep); // mySimpleXYPlot.setDomainBoundaries(min, max, BoundaryMode.AUTO); // customize our domain/range labels mySimpleXYPlot.setDomainLabel("Date"); mySimpleXYPlot.setRangeLabel("Weight"); Double minimum = FindMinimum(); Double maximum = FindMaximum(); Double stepSize = FindStep(maximum, minimum); mySimpleXYPlot.setRangeBoundaries(minimum, maximum, BoundaryMode.FIXED); mySimpleXYPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepSize); mySimpleXYPlot.setDomainValueFormat( new Format() { private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM"); @Override public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { // because our timestamps are in seconds and SimpleDateFormat expects milliseconds // we multiply our timestamp by 1000: long timestamp = ((Number) obj).longValue() * 1000; Date date = new Date(timestamp); return dateFormat.format(date, toAppendTo, pos); } @Override public Object parseObject(String source, ParsePosition pos) { return null; } }); // by default, AndroidPlot displays developer guides to aid in laying out your plot. // To get rid of them call disableAllMarkup(): mySimpleXYPlot.disableAllMarkup(); }
/** * DESCRIPTION: Sets the height of the plot view. * * @param height - the height in pixels. */ public void setHeight(int height) { ViewGroup.LayoutParams params = plot.getLayoutParams(); params.height = height; plot.setLayoutParams(params); plot.redraw(); }
/** DESCRIPTION: Clears the plot widget, then plots the data again. */ private void redrawPlot() { plot.clear(); drawPlot(); plot.redraw(); }