public XYPlot layerRaster(Collection<Spike> spikes,Layer lay) { // throw new UnsupportedOperationException("This is broken for now!"); // Add the data Iterator<Spike> itr=spikes.iterator(); XYSeries data=new XYSeries("Events"); for (int i=0; i<spikes.size(); i++) { Spike evt=itr.next(); if (evt.layer==lay.ixLayer) data.add((float)evt.time/1000,evt.addr); } XYDataset raster = new XYSeriesCollection(data); //SamplingXYLineAndShapeRenderer renderer = new SamplingXYLineAndShapeRenderer(false, true); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotWidth(2); renderer.setDotHeight(5); return new XYPlot(raster, null, new NumberAxis("Layer "+lay.ixLayer), renderer); }
/** * Check that the equals() method distinguishes all fields. */ public void testEquals() { XYDotRenderer r1 = new XYDotRenderer(); XYDotRenderer r2 = new XYDotRenderer(); assertEquals(r1, r2); r1.setDotWidth(11); assertFalse(r1.equals(r2)); r2.setDotWidth(11); assertTrue(r1.equals(r2)); r1.setDotHeight(12); assertFalse(r1.equals(r2)); r2.setDotHeight(12); assertTrue(r1.equals(r2)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { XYDotRenderer r1 = new XYDotRenderer(); XYDotRenderer r2 = new XYDotRenderer(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); r1.setDotHeight(12); r2.setDotHeight(12); assertTrue(r1.equals(r2)); h1 = r1.hashCode(); h2 = r2.hashCode(); assertEquals(h1, h2); }
/** * Check that the equals() method distinguishes all fields. */ public void testEquals() { XYDotRenderer r1 = new XYDotRenderer(); XYDotRenderer r2 = new XYDotRenderer(); assertEquals(r1, r2); r1.setDotWidth(11); assertFalse(r1.equals(r2)); r2.setDotWidth(11); assertTrue(r1.equals(r2)); r1.setDotHeight(12); assertFalse(r1.equals(r2)); r2.setDotHeight(12); assertTrue(r1.equals(r2)); r1.setLegendShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertFalse(r1.equals(r2)); r2.setLegendShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertTrue(r1.equals(r2)); }
/** Plot a list of events read from a file */ public static void plotEvents(Queue<Spike> evts) { Iterator<Spike> itr=evts.iterator(); XYSeries data=new XYSeries("Size"); for (int i=0; i<evts.size(); i++) { Spike ev=itr.next(); data.add((float)ev.time,ev.addr); } XYDataset raster = new XYSeriesCollection(data); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotWidth(2); renderer.setDotHeight(2); XYPlot subplot1 = new XYPlot(raster, null, new NumberAxis("address"), renderer); XYPlot subplot2 = new XYPlot(raster, null, new NumberAxis("address"), renderer); CombinedXYPlot plot = new CombinedXYPlot(new NumberAxis("Time"),new NumberAxis("Address")); plot.add(subplot1, 1); plot.add(subplot2, 1); JFreeChart chart= new JFreeChart("Raster",JFreeChart.DEFAULT_TITLE_FONT, plot,true); JFrame fr=new JFrame(); fr.getContentPane().add(new ChartPanel(chart)); fr.setSize(1200,1000); fr.setVisible(true); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { XYDotRenderer r1 = new XYDotRenderer(); XYDotRenderer r2 = new XYDotRenderer(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); }
public void removeSeries( String series ) { final XYSeriesCollection s = (XYSeriesCollection) ((XYPlot) getChart().getPlot()).getDataset(); final XYSeries xys = s.getSeries( series ); //If we remove a series, the series paints don't seem to get updated final XYDotRenderer renderer = (XYDotRenderer) ((XYPlot) getChart().getPlot()).getRenderer(); final int index = s.getSeriesIndex( xys.getKey() ); for (int i = index; i < s.getSeriesCount() - 1; i++) { renderer.setSeriesPaint( i, renderer.getSeriesPaint( i + 1 ) ); } s.removeSeries( xys ); }
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ public void testGetLegendItemSeriesIndex() { XYSeriesCollection d1 = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); XYSeries s2 = new XYSeries("S2"); s2.add(1.0, 1.1); d1.addSeries(s1); d1.addSeries(s2); XYSeriesCollection d2 = new XYSeriesCollection(); XYSeries s3 = new XYSeries("S3"); s3.add(1.0, 1.1); XYSeries s4 = new XYSeries("S4"); s4.add(1.0, 1.1); XYSeries s5 = new XYSeries("S5"); s5.add(1.0, 1.1); d2.addSeries(s3); d2.addSeries(s4); d2.addSeries(s5); XYDotRenderer r = new XYDotRenderer(); XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, d2); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("S5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
/** * Problem that the equals(...) method distinguishes all fields. */ public void testEquals() { XYDotRenderer r1 = new XYDotRenderer(); XYDotRenderer r2 = new XYDotRenderer(); assertEquals(r1, r2); }
/** * @return the pencil size for painting the markers */ public int getDotSize() { return ((XYDotRenderer) ((XYPlot) getChart().getPlot()).getRenderer()).getDotHeight(); }
public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel, String yLabel) { super(null, true); setBackground(Color.white); setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); xAxis = new NumberAxis(xLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); xyDataset = new DefaultXYZDataset(); int length = Math.min(xValues.length, yValues.length); double[][] data = new double[3][length]; System.arraycopy(xValues, 0, data[0], 0, length); System.arraycopy(yValues, 0, data[1], 0, length); System.arraycopy(colors, 0, data[2], 0, length); xyDataset.addSeries(SERIES_ID, data); XYDotRenderer renderer = new XYDotRenderer() { @Override public Paint getItemPaint(int row, int col) { double c = xyDataset.getZ(row, col).doubleValue(); return Color.getHSBColor((float) c, 1.0f, 1.0f); } }; renderer.setDotHeight(3); renderer.setDotWidth(3); plot = new XYPlot(xyDataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false); chart.setBackgroundPaint(Color.white); super.setChart(chart); }
/** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { XYDotRenderer r1 = new XYDotRenderer(); assertTrue(r1 instanceof PublicCloneable); }
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) { JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false); chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); chartPanel.setMouseZoomable(false); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.CENTER; gbl_chartPanel.insets = new Insets(3, 3, 3, 3); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 1; plotPanel.add(chartPanel, gbl_chartPanel); XYDotRenderer dotRenderer = new XYDotRenderer(); dotRenderer.setSeriesPaint(0, new Color(0, 51, 102)); dotRenderer.setDotHeight(3); dotRenderer.setDotWidth(3); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setLegendItemLabelGenerator( new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = 7593430826693873496L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection)dataset).getSeries(series); return xys.getDescription(); } } ); NumberAxis xAxis = new NumberAxis(xAxisName); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisName); yAxis.setAutoRangeIncludesZero(false); XYSeriesCollection scatterDataset = new XYSeriesCollection(runData); XYSeriesCollection lineDataset = new XYSeriesCollection(); trendData.setDescription(trendDataName); lineDataset.addSeries(trendData); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, xAxis); plot.setRangeAxis(0, yAxis); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); plot.setDataset(1, scatterDataset); plot.setRenderer(1, dotRenderer); plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); }
/** * Sets the pencil size for each marker. If set to a value > 1, * the MapCanvasComponent will colour more pixels around the the actual * marker, depending on the pencil size, to highlight the marker. * @param dotSize */ public void setDotSize( int dotSize ) { ((XYDotRenderer) ((XYPlot) getChart().getPlot()).getRenderer()).setDotHeight( dotSize ); ((XYDotRenderer) ((XYPlot) getChart().getPlot()).getRenderer()).setDotWidth( dotSize ); }