List of usage examples for org.jfree.data Range Range
public Range(double lower, double upper)
From source file:org.jfree.data.RangeTest.java
/** * A simple test for the scale() method. *//*from w w w .j a va 2 s. c om*/ @Test public void testScale() { Range r1 = new Range(0.0, 100.0); Range r2 = Range.scale(r1, 0.10); assertEquals(0.0, r2.getLowerBound(), 0.001); assertEquals(10.0, r2.getUpperBound(), 0.001); r1 = new Range(-10.0, 100.0); r2 = Range.scale(r1, 2.0); assertEquals(-20.0, r2.getLowerBound(), 0.001); assertEquals(200.0, r2.getUpperBound(), 0.001); // Scaling with a factor of 1 does not change the range r2 = Range.scale(r1, 1.0); assertEquals(r1, r2); try { Range.scale(null, 0.1); fail("Null value is accepted"); } catch (Exception e) { } try { Range.scale(r1, -0.5); fail("Negative factor accepted"); } catch (Exception e) { } }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java
/** * Some checks for the add() method.//from w w w .j a v a 2 s .c o m */ @Test public void testAddUpdatesCachedRange() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(item1, "R1", "C1"); // now overwrite this item with another BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList()); dataset.add(item2, "R1", "C1"); assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON); assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON); assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON); assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON); assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false)); }
From source file:org.jfree.data.statistics.DefaultStatisticalCategoryDatasetTest.java
/** * Some checks for the remove method./*from w w w .jav a 2 s .c o m*/ */ @Test public void testRemove() { DefaultStatisticalCategoryDataset data = new DefaultStatisticalCategoryDataset(); boolean pass = false; try { data.remove("R1", "R2"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); data.add(1.0, 0.5, "R1", "C1"); assertEquals(new Range(1.0, 1.0), data.getRangeBounds(false)); assertEquals(new Range(0.5, 1.5), data.getRangeBounds(true)); data.add(1.4, 0.2, "R2", "C1"); assertEquals(1.0, data.getRangeLowerBound(false), EPSILON); assertEquals(1.4, data.getRangeUpperBound(false), EPSILON); assertEquals(0.5, data.getRangeLowerBound(true), EPSILON); assertEquals(1.6, data.getRangeUpperBound(true), EPSILON); data.remove("R1", "C1"); assertEquals(1.4, data.getRangeLowerBound(false), EPSILON); assertEquals(1.4, data.getRangeUpperBound(false), EPSILON); assertEquals(1.2, data.getRangeLowerBound(true), EPSILON); assertEquals(1.6, data.getRangeUpperBound(true), EPSILON); }
From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java
/** * Returns the range of data values to be plotted along the axis. * * @param axis the axis./* w w w . j a v a2 s. com*/ * * @return The range. */ public Range getDataRange(ValueAxis axis) { if (series == null) { return new Range(0.0, 1.0); } boolean isDomainAxis = true; int index = -1; // is it a domain axis? int domainIndex = getDomainAxisIndex(axis); if (domainIndex >= 0) { isDomainAxis = true; index = domainIndex; } // or is it a range axis? int rangeIndex = getRangeAxisIndex(axis); if (rangeIndex >= 0) { isDomainAxis = false; index = rangeIndex; } if ((index < 0) || (index >= series.size())) { return new Range(0.0, 1.0); } double[][] data = (double[][]) series.get(index); if (isDomainAxis) { return calculateXDataRange(data); } return calculateYDataRange(data); }
From source file:com.rapidminer.gui.plotter.RangeablePlotterAdapter.java
@Override public void setAdditionalParameter(String key, String value) { super.setAdditionalParameter(key, value); if (key.startsWith(PARAMETER_PREFIX_RANGE_LIST)) { List<String[]> dimensionRangePairs = ParameterTypeList.transformString2List(value); for (String[] dimensionRangePair : dimensionRangePairs) { String[] rangeTupel = ParameterTypeTupel.transformString2Tupel(dimensionRangePair[1]); if (rangeTupel.length == 2) { try { Range range = new Range(Double.parseDouble(rangeTupel[0]), Double.parseDouble(rangeTupel[1])); nameRangeMap.put(PlotterAdapter.transformParameterName(dimensionRangePair[0]), range); updatePlotter();/*from ww w . jav a 2 s . com*/ } catch (NumberFormatException e) { } } } return; } }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapPlotPanel.java
private PortHeatMapPlotPanel(OMS_Collection history, ArrayList<IB_Vertex> includedNodes, EnumSet<IB_Depth> includedDepths) { super(new BorderLayout()); // creates the main chart panel, which creates the PortHeatMapDataSet // (so all the data has been initialized here, available for all subsequent actions) overallDimension = new java.awt.Dimension(900, 500); heatPanel = (ChartPanel) createHeatPanel(history, includedNodes, includedDepths); heatPanel.setPreferredSize(overallDimension); // add the vertical and horizontal crosshairs CrosshairOverlay overlay = new CrosshairOverlay(); TimeXhair = new Crosshair(0); TimeXhair.setPaint(TimeSliceColor); // vertical slice (single timestamp) for dataset1, SingleTimeChart plot 1, slider 2, etc PortXhair = new Crosshair(0); PortXhair.setPaint(PortSliceColor); // horizontal slice (single port) for dataset2, SinglePortChart, slider 1 overlay.addDomainCrosshair(TimeXhair); overlay.addRangeCrosshair(PortXhair); heatPanel.addOverlay(overlay);//from ww w . ja v a 2 s . co m TimeXhair.setLabelVisible(true); TimeXhair.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); TimeXhair.setLabelBackgroundPaint(new Color(255, 255, 0, 100)); PortXhair.setLabelVisible(true); PortXhair.setLabelBackgroundPaint(new Color(255, 255, 0, 100)); add(heatPanel); JPanel PortSliderPanel = new JPanel(new BorderLayout()); // all ports, single timestamp (right vertical plot) - uses TimeXhair and slider 2 from the horizontal panel (TimeSliderPanel) XYSeriesCollection dataset1 = new XYSeriesCollection(); SingleTimeChart = ChartFactory.createXYLineChart("Vertical Cross-section (all ports single timestamp)", PortAxisLabel, UtilizationAxisLabel, dataset1, PlotOrientation.HORIZONTAL, false, false, false); XYPlot plot1 = (XYPlot) SingleTimeChart.getPlot(); plot1.getDomainAxis().setLowerMargin(0.0); plot1.getDomainAxis().setUpperMargin(0.0); plot1.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot1.getRenderer().setSeriesPaint(0, TimeSliceColor); // this is the right ChartPanel SingleTimeChartPanel = new ChartPanel(SingleTimeChart); SingleTimeChartPanel.setMinimumDrawWidth(0); SingleTimeChartPanel.setMinimumDrawHeight(0); SingleTimeChartPanel.setPreferredSize(new Dimension(200, (int) (overallDimension.getWidth() / 3))); ((XYPlot) SingleTimeChart.getPlot()).getRangeAxis().setRange(new Range(0, 1)); ((XYPlot) SingleTimeChart.getPlot()).getDomainAxis().setRange(new Range(0, 1)); // this slider panel holds the slider and the Single Time Snapshot of all ports, on the right or EAST (for use with plot2) PortSlider = new JSlider(0, 1, 0); PortSlider.addChangeListener(this); PortSlider.setOrientation(JSlider.VERTICAL); PortSliderPanel.add(SingleTimeChartPanel); PortSliderPanel.add(PortSlider, BorderLayout.WEST); TimeSliderPanel = new JPanel(new BorderLayout()); // single port, all timestamps (lower horizontal plot) - uses PortXhair and slider 1 from the vertical panel (PortSliderPanel) XYSeriesCollection dataset2 = new XYSeriesCollection(); SinglePortChart = ChartFactory.createXYLineChart("Horizontal Cross-section (single port over time)", TimeAxisLabel, UtilizationAxisLabel, dataset2, PlotOrientation.VERTICAL, false, false, false); XYPlot plot2 = (XYPlot) SinglePortChart.getPlot(); plot2.getDomainAxis().setLowerMargin(0.0); plot2.getDomainAxis().setUpperMargin(0.0); plot2.getRenderer().setSeriesPaint(0, PortSliceColor); ChartPanel SinglePortChartPanel = new ChartPanel(SinglePortChart); SinglePortChartPanel.setMinimumDrawWidth(0); SinglePortChartPanel.setMinimumDrawHeight(0); SinglePortChartPanel.setPreferredSize(new Dimension(200, (int) (overallDimension.getHeight() / 3))); ((XYPlot) SinglePortChart.getPlot()).getRangeAxis().setRange(new Range(0, 1)); ((XYPlot) SinglePortChart.getPlot()).getDomainAxis().setRange(new Range(0, 1)); DepthPanel = new HeatMapDepthPanel(null); DepthPanel.setPreferredSize( new Dimension((int) (overallDimension.getWidth() / 4), (int) (overallDimension.getHeight() / 3))); TimeSliderPanel.add(DepthPanel, BorderLayout.EAST); // this slider panel holds the slider and the Single Port for all times, in the BOTTOM (for use with plot1) TimeSlider = new JSlider(0, 1, 0); TimeSlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 200)); TimeSlider.addChangeListener(this); TimeSliderPanel.add(SinglePortChartPanel); TimeSliderPanel.add(TimeSlider, BorderLayout.NORTH); add(PortSliderPanel, BorderLayout.EAST); add(TimeSliderPanel, BorderLayout.SOUTH); heatChart.setNotify(true); }
From source file:org.jfree.data.Range.java
/** * Returns a range that includes all the values in the specified * <code>range</code> AND the specified <code>value</code>. * * @param range the range (<code>null</code> permitted). * @param value the value that must be included. * * @return A range./*from www.j a va 2 s .c o m*/ * * @since 1.0.1 */ public static Range expandToInclude(Range range, double value) { if (range == null) { return new Range(value, value); } if (value < range.getLowerBound()) { return new Range(value, range.getUpperBound()); } else if (value > range.getUpperBound()) { return new Range(range.getLowerBound(), value); } else { return range; } }
From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java
@Override @OnAwt//from w ww.j a v a 2s .c om public void setRangeAxisRange(double lower, double upper) { this.rangeAxis = new Range(lower, upper); setAutoZoomRange(true); }
From source file:org.jfree.experimental.chart.annotations.XYTitleAnnotation.java
/** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly.//from w w w. ja v a2 s . c o m * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); Range xRange = domainAxis.getRange(); Range yRange = rangeAxis.getRange(); double anchorX = 0.0; double anchorY = 0.0; if (this.coordinateType == XYCoordinateType.RELATIVE) { anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); } else { anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); } float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } double maxW = dataArea.getWidth(); double maxH = dataArea.getHeight(); if (this.coordinateType == XYCoordinateType.RELATIVE) { if (this.maxWidth > 0.0) { maxW = maxW * this.maxWidth; } if (this.maxHeight > 0.0) { maxH = maxH * this.maxHeight; } } if (this.coordinateType == XYCoordinateType.DATA) { maxW = this.maxWidth; maxH = this.maxHeight; } RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH)); Size2D size = this.title.arrange(g2, rc); Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height); Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor); xx = xx - (float) anchorPoint.getX(); yy = yy - (float) anchorPoint.getY(); titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); BlockParams p = new BlockParams(); if (info != null) { if (info.getOwner().getEntityCollection() != null) { p.setGenerateEntities(true); } } Object result = this.title.draw(g2, titleRect, p); if (result instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) result; info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection()); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url); } }
From source file:org.jfree.data.RangeTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from ww w . j a va2s. c om*/ @Test public void testSerialization() { Range r1 = new Range(25.0, 133.42); Range r2 = (Range) TestUtilities.serialised(r1); assertEquals(r1, r2); }