/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown. */ public void testDrawWithNullInfo() { boolean success = false; try { float[][] data = createData(); ValueAxis domainAxis = new NumberAxis("X"); ValueAxis rangeAxis = new NumberAxis("Y"); FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { e.printStackTrace(); success = false; } assertTrue(success); }
/** * Experimental, fast scatter plot for faster processing * only possible for 2D datasets */ private JFreeChart createFastScatterPlot(XYDataset dataset) { final NumberAxis domainAxis = new NumberAxis("X"); domainAxis.setAutoRangeIncludesZero(false); final NumberAxis rangeAxis = new NumberAxis("Y"); rangeAxis.setAutoRangeIncludesZero(false); float[][] data = new float[2][dataset.getItemCount(0)]; for (int i = 0; i < dataset.getItemCount(0); i++) { data[0][i] = (float) dataset.getXValue(0, i); data[1][i] = (float) dataset.getYValue(0, i); } final FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis); final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot); // chart.setLegend(null); // force aliasing of the rendered content.. chart.getRenderingHints().put (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return chart; }
/** * Creates a new controller to handle plot shifts. * * @param chartPanel * The panel displaying the plot. */ public ChartPanelShiftController(ChartPanel chartPanel) { super(); this.chartPanel = chartPanel; // Check to see if plot is shiftable Plot plot = chartPanel.getChart().getPlot(); if ((plot instanceof XYPlot) || (plot instanceof FastScatterPlot)) { plotSupported = true; axesSwaped = isHorizontalPlot(plot); } }
/** * Returns the plot orientation. * * @return True = {@link org.jfree.chart.plot.PlotOrientation#VERTICAL VERTICAL}; False = * {@link org.jfree.chart.plot.PlotOrientation#HORIZONTAL HORIZONTAL} */ protected boolean isHorizontalPlot(Plot plot) { if (plot instanceof XYPlot) { return ((XYPlot) plot).getOrientation() == PlotOrientation.HORIZONTAL; } if (plot instanceof FastScatterPlot) { return ((FastScatterPlot) plot).getOrientation() == PlotOrientation.HORIZONTAL; } return false; }
/** * Returns a reference to the 'horizontal' value axis, if there is one. * * @param plot the plot. * * @return The axis. */ private ValueAxis getHorizontalValueAxis(Plot plot) { if (plot == null) { return null; } ValueAxis axis = null; if (plot instanceof CategoryPlot) { CategoryPlot cp = (CategoryPlot) plot; if (cp.getOrientation() == PlotOrientation.HORIZONTAL) { axis = cp.getRangeAxis(); } } if (plot instanceof XYPlot) { XYPlot xyp = (XYPlot) plot; if (xyp.getOrientation() == PlotOrientation.HORIZONTAL) { axis = xyp.getRangeAxis(); } else if (xyp.getOrientation() == PlotOrientation.VERTICAL) { axis = xyp.getDomainAxis(); } } if (plot instanceof FastScatterPlot) { FastScatterPlot fsp = (FastScatterPlot) plot; axis = fsp.getDomainAxis(); } return axis; }
/** * Returns a reference to the 'vertical' value axis, if there is one. * * @param plot the plot. * * @return The axis. */ private ValueAxis getVerticalValueAxis(Plot plot) { if (plot == null) { return null; } ValueAxis axis = null; if (plot instanceof CategoryPlot) { CategoryPlot cp = (CategoryPlot) plot; if (cp.getOrientation() == PlotOrientation.VERTICAL) { axis = cp.getRangeAxis(); } } if (plot instanceof XYPlot) { XYPlot xyp = (XYPlot) plot; if (xyp.getOrientation() == PlotOrientation.HORIZONTAL) { axis = xyp.getDomainAxis(); } else if (xyp.getOrientation() == PlotOrientation.VERTICAL) { axis = xyp.getRangeAxis(); } } if (plot instanceof FastScatterPlot) { FastScatterPlot fsp = (FastScatterPlot) plot; axis = fsp.getRangeAxis(); } return axis; }
/** * Applies the attributes of this theme to a {@link FastScatterPlot}. * * @param plot the plot ({@code null} not permitted). */ protected void applyToFastScatterPlot(FastScatterPlot plot) { plot.setDomainGridlinePaint(this.domainGridlinePaint); plot.setRangeGridlinePaint(this.rangeGridlinePaint); ValueAxis xAxis = plot.getDomainAxis(); if (xAxis != null) { applyToValueAxis(xAxis); } ValueAxis yAxis = plot.getRangeAxis(); if (yAxis != null) { applyToValueAxis(yAxis); } }
/** * Applies the attributes of this theme to a {@link FastScatterPlot}. * @param plot */ protected void applyToFastScatterPlot(FastScatterPlot plot) { plot.setDomainGridlinePaint(this.domainGridlinePaint); plot.setRangeGridlinePaint(this.rangeGridlinePaint); ValueAxis xAxis = plot.getDomainAxis(); if (xAxis != null) { applyToValueAxis(xAxis); } ValueAxis yAxis = plot.getRangeAxis(); if (yAxis != null) { applyToValueAxis(yAxis); } }
/** * Some tests for the data array equality in the equals() method. */ public void testEquals2() { FastScatterPlot plot1 = new FastScatterPlot(); FastScatterPlot plot2 = new FastScatterPlot(); assertTrue(plot1.equals(plot2)); assertTrue(plot2.equals(plot1)); float[][] a = new float[2][]; float[][] b = new float[2][]; plot1.setData(a); assertFalse(plot1.equals(plot2)); plot2.setData(b); assertTrue(plot1.equals(plot2)); a[0] = new float[6]; assertFalse(plot1.equals(plot2)); b[0] = new float[6]; assertTrue(plot1.equals(plot2)); a[0][0] = 1.0f; assertFalse(plot1.equals(plot2)); b[0][0] = 1.0f; assertTrue(plot1.equals(plot2)); a[0][1] = Float.NaN; assertFalse(plot1.equals(plot2)); b[0][1] = Float.NaN; assertTrue(plot1.equals(plot2)); a[0][2] = Float.POSITIVE_INFINITY; assertFalse(plot1.equals(plot2)); b[0][2] = Float.POSITIVE_INFINITY; assertTrue(plot1.equals(plot2)); a[0][3] = Float.NEGATIVE_INFINITY; assertFalse(plot1.equals(plot2)); b[0][3] = Float.NEGATIVE_INFINITY; assertTrue(plot1.equals(plot2)); }
/** * Creates a new controller to handle plot shifts. * @param chartPanel The panel displaying the plot. */ public ChartPanelShiftController(ChartPanel chartPanel) { super(); this.chartPanel = chartPanel; // Check to see if plot is shiftable Plot plot = chartPanel.getChart().getPlot(); if ((plot instanceof XYPlot) || (plot instanceof FastScatterPlot)) { plotSupported = true; axesSwaped = isHorizontalPlot(plot); } }
/** * Returns the plot orientation. * @return True = {@link org.jfree.chart.plot.PlotOrientation#VERTICAL VERTICAL}; * False = {@link org.jfree.chart.plot.PlotOrientation#HORIZONTAL HORIZONTAL} */ protected boolean isHorizontalPlot(Plot plot) { if (plot instanceof XYPlot) { return ((XYPlot) plot).getOrientation() == PlotOrientation.HORIZONTAL; } if (plot instanceof FastScatterPlot) { return ((FastScatterPlot) plot).getOrientation() == PlotOrientation.HORIZONTAL; } return false; }
/** * Test the equals() method. */ public void testEquals() { FastScatterPlot plot1 = new FastScatterPlot(); FastScatterPlot plot2 = new FastScatterPlot(); assertTrue(plot1.equals(plot2)); assertTrue(plot2.equals(plot1)); plot1.setPaint(Color.yellow); assertFalse(plot1.equals(plot2)); plot2.setPaint(Color.yellow); assertTrue(plot1.equals(plot2)); plot1.setDomainGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinesVisible(false); assertTrue(plot1.equals(plot2)); plot1.setDomainGridlinePaint(Color.red); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinePaint(Color.red); assertTrue(plot1.equals(plot2)); Stroke s = new BasicStroke(1.5f); plot1.setDomainGridlineStroke(s); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlineStroke(s); assertTrue(plot1.equals(plot2)); plot1.setRangeGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinesVisible(false); assertTrue(plot1.equals(plot2)); plot1.setRangeGridlinePaint(Color.red); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinePaint(Color.red); assertTrue(plot1.equals(plot2)); Stroke s2 = new BasicStroke(1.5f); plot1.setRangeGridlineStroke(s2); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlineStroke(s2); assertTrue(plot1.equals(plot2)); }
/** * Some checks for the equals() method. */ public void testEquals() { FastScatterPlot plot1 = new FastScatterPlot(); FastScatterPlot plot2 = new FastScatterPlot(); assertTrue(plot1.equals(plot2)); assertTrue(plot2.equals(plot1)); plot1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(plot1.equals(plot2)); plot1.setDomainGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinesVisible(false); assertTrue(plot1.equals(plot2)); plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow)); assertTrue(plot1.equals(plot2)); Stroke s = new BasicStroke(1.5f); plot1.setDomainGridlineStroke(s); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlineStroke(s); assertTrue(plot1.equals(plot2)); plot1.setRangeGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinesVisible(false); assertTrue(plot1.equals(plot2)); plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertTrue(plot1.equals(plot2)); Stroke s2 = new BasicStroke(1.5f); plot1.setRangeGridlineStroke(s2); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlineStroke(s2); assertTrue(plot1.equals(plot2)); }
/** * Applies the attributes of this theme to a plot. * * @param plot the plot (<code>null</code>). */ protected void applyToPlot(Plot plot) { ParamChecks.nullNotPermitted(plot, "plot"); if (plot.getDrawingSupplier() != null) { plot.setDrawingSupplier(getDrawingSupplier()); } if (plot.getBackgroundPaint() != null) { plot.setBackgroundPaint(this.plotBackgroundPaint); } plot.setOutlinePaint(this.plotOutlinePaint); // now handle specific plot types (and yes, I know this is some // really ugly code that has to be manually updated any time a new // plot type is added - I should have written something much cooler, // but I didn't and neither did anyone else). if (plot instanceof PiePlot) { applyToPiePlot((PiePlot) plot); } else if (plot instanceof MultiplePiePlot) { applyToMultiplePiePlot((MultiplePiePlot) plot); } else if (plot instanceof CategoryPlot) { applyToCategoryPlot((CategoryPlot) plot); } else if (plot instanceof XYPlot) { applyToXYPlot((XYPlot) plot); } else if (plot instanceof FastScatterPlot) { applyToFastScatterPlot((FastScatterPlot) plot); } else if (plot instanceof MeterPlot) { applyToMeterPlot((MeterPlot) plot); } else if (plot instanceof ThermometerPlot) { applyToThermometerPlot((ThermometerPlot) plot); } else if (plot instanceof SpiderWebPlot) { applyToSpiderWebPlot((SpiderWebPlot) plot); } else if (plot instanceof PolarPlot) { applyToPolarPlot((PolarPlot) plot); } }
/** * Applies the attributes of this theme to a plot. * * @param plot the plot ({@code null}). */ protected void applyToPlot(Plot plot) { Args.nullNotPermitted(plot, "plot"); if (plot.getDrawingSupplier() != null) { plot.setDrawingSupplier(getDrawingSupplier()); } if (plot.getBackgroundPaint() != null) { plot.setBackgroundPaint(this.plotBackgroundPaint); } plot.setOutlinePaint(this.plotOutlinePaint); // now handle specific plot types (and yes, I know this is some // really ugly code that has to be manually updated any time a new // plot type is added - I should have written something much cooler, // but I didn't and neither did anyone else). if (plot instanceof PiePlot) { applyToPiePlot((PiePlot) plot); } else if (plot instanceof MultiplePiePlot) { applyToMultiplePiePlot((MultiplePiePlot) plot); } else if (plot instanceof CategoryPlot) { applyToCategoryPlot((CategoryPlot) plot); } else if (plot instanceof XYPlot) { applyToXYPlot((XYPlot) plot); } else if (plot instanceof FastScatterPlot) { applyToFastScatterPlot((FastScatterPlot) plot); } else if (plot instanceof MeterPlot) { applyToMeterPlot((MeterPlot) plot); } else if (plot instanceof ThermometerPlot) { applyToThermometerPlot((ThermometerPlot) plot); } else if (plot instanceof SpiderWebPlot) { applyToSpiderWebPlot((SpiderWebPlot) plot); } else if (plot instanceof PolarPlot) { applyToPolarPlot((PolarPlot) plot); } }
/** * Applies the attributes of this theme to a plot. * * @param plot the plot (<code>null</code>). */ protected void applyToPlot(Plot plot) { if (plot == null) { throw new IllegalArgumentException("Null 'plot' argument."); } if (plot.getDrawingSupplier() != null) { plot.setDrawingSupplier(getDrawingSupplier()); } if (plot.getBackgroundPaint() != null) { plot.setBackgroundPaint(this.plotBackgroundPaint); } plot.setOutlinePaint(this.plotOutlinePaint); // now handle specific plot types (and yes, I know this is some // really ugly code that has to be manually updated any time a new // plot type is added - I should have written something much cooler, // but I didn't and neither did anyone else). if (plot instanceof PiePlot) { applyToPiePlot((PiePlot) plot); } else if (plot instanceof MultiplePiePlot) { applyToMultiplePiePlot((MultiplePiePlot) plot); } else if (plot instanceof CategoryPlot) { applyToCategoryPlot((CategoryPlot) plot); } else if (plot instanceof XYPlot) { applyToXYPlot((XYPlot) plot); } else if (plot instanceof FastScatterPlot) { applyToFastScatterPlot((FastScatterPlot) plot); } else if (plot instanceof MeterPlot) { applyToMeterPlot((MeterPlot) plot); } else if (plot instanceof ThermometerPlot) { applyToThermometerPlot((ThermometerPlot) plot); } else if (plot instanceof SpiderWebPlot) { applyToSpiderWebPlot((SpiderWebPlot) plot); } else if (plot instanceof PolarPlot) { applyToPolarPlot((PolarPlot) plot); } }
public static void main(String[] args) throws IOException { final File inputcsv = new File("/Volumes/SSD/training_latlng"); final List<double[]> data = new ArrayList<double[]>(10000000); // read in images final BufferedReader br = new BufferedReader(new FileReader(inputcsv)); String line; int i = 0; br.readLine(); while ((line = br.readLine()) != null) { final String[] parts = line.split(" "); final double longitude = Double.parseDouble(parts[2]); final double latitude = Double.parseDouble(parts[1]); data.add(new double[] { longitude, latitude }); if (longitude >= -0.1 && longitude < 0 && latitude > 50 && latitude < 54) System.out.println(parts[0] + " " + latitude + " " + longitude); // if (i++ % 10000 == 0) // System.out.println(i); } br.close(); System.out.println("Done reading"); final float[][] dataArr = new float[2][data.size()]; for (i = 0; i < data.size(); i++) { dataArr[0][i] = (float) data.get(i)[0]; dataArr[1][i] = (float) data.get(i)[1]; } final NumberAxis domainAxis = new NumberAxis("X"); domainAxis.setRange(-180, 180); final NumberAxis rangeAxis = new NumberAxis("Y"); rangeAxis.setRange(-90, 90); final FastScatterPlot plot = new FastScatterPlot(dataArr, domainAxis, rangeAxis); final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); final ApplicationFrame frame = new ApplicationFrame("Title"); frame.setContentPane(chartPanel); frame.pack(); frame.setVisible(true); }
/** * Some checks for the equals() method. */ public void testEquals() { FastScatterPlot plot1 = new FastScatterPlot(); FastScatterPlot plot2 = new FastScatterPlot(); assertTrue(plot1.equals(plot2)); assertTrue(plot2.equals(plot1)); plot1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)); assertTrue(plot1.equals(plot2)); plot1.setDomainGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinesVisible(false); assertTrue(plot1.equals(plot2)); plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow)); assertTrue(plot1.equals(plot2)); Stroke s = new BasicStroke(1.5f); plot1.setDomainGridlineStroke(s); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlineStroke(s); assertTrue(plot1.equals(plot2)); plot1.setRangeGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinesVisible(false); assertTrue(plot1.equals(plot2)); plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertTrue(plot1.equals(plot2)); Stroke s2 = new BasicStroke(1.5f); plot1.setRangeGridlineStroke(s2); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlineStroke(s2); assertTrue(plot1.equals(plot2)); plot1.setDomainPannable(true); assertFalse(plot1.equals(plot2)); plot2.setDomainPannable(true); assertTrue(plot1.equals(plot2)); plot1.setRangePannable(true); assertFalse(plot1.equals(plot2)); plot2.setRangePannable(true); assertTrue(plot1.equals(plot2)); }