List of usage examples for org.jfree.data Range contains
public boolean contains(double value)
true
if the range contains the specified value and false
otherwise. From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java
/** * /* w w w . j a va2 s.c om*/ */ public static JXPanel buildMDSViewFromDataSet(final Instances instances, final MDSResult mdsResult, final int maxInstances, final Listener<Instances> listener, final String... attrNameToUseAsPointTitle) throws Exception { final XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createScatterPlot("", // title "X", "Y", // axis labels dataset, // dataset PlotOrientation.VERTICAL, attrNameToUseAsPointTitle.length == 0, // legend? true, // tooltips? yes false // URLs? no ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setBackgroundPaint(Color.WHITE); xyPlot.getDomainAxis().setTickLabelsVisible(false); xyPlot.getRangeAxis().setTickLabelsVisible(false); //FIXME : should be different for Shih if (!mdsResult.isNormalized()) { String stress = FormatterUtil.DECIMAL_FORMAT .format(ClassicMDS.getKruskalStressFromMDSResult(mdsResult)); chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ",Stress=" + stress + ")" : "MDS(Stress=" + stress + ")"); } else { chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ")" : "MDS"); } final SimpleMatrix coordinates = mdsResult.getCoordinates(); buildFilteredSeries(mdsResult, xyPlot, attrNameToUseAsPointTitle); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("MDS Projection")); chartPanel.setBackground(Color.WHITE); final JButton selectionButton = new JButton("Select data"); selectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final org.jfree.data.Range XDomainRange = xyPlot.getDomainAxis().getRange(); final org.jfree.data.Range YDomainRange = xyPlot.getRangeAxis().getRange(); final Instances cInstances = mdsResult.getCollapsedInstances(); final Instances selectedInstances = new Instances(cInstances, 0); List<Instances> clusters = null; if (mdsResult.getCInstances().isCollapsed()) { clusters = mdsResult.getCInstances().getCentroidMap().getClusters(); } for (int i = 0; i < cInstances.numInstances(); i++) { final Instance centroid = instances.instance(i); if (XDomainRange.contains(coordinates.get(i, 0)) && YDomainRange.contains(coordinates.get(i, 1))) { if (mdsResult.getCInstances().isCollapsed()) { if (clusters != null) { final Instances elementsOfCluster = clusters.get(i); final int nbElements = elementsOfCluster.numInstances(); for (int k = 0; k < nbElements; k++) { selectedInstances.add(elementsOfCluster.get(k)); } } } else { selectedInstances.add(centroid); } } } if (listener != null) { listener.onAction(selectedInstances); } } }); final JXPanel allPanel = new JXPanel(); allPanel.setLayout(new BorderLayout()); allPanel.add(chartPanel, BorderLayout.CENTER); final JXPanel southPanel = new JXPanel(); southPanel.add(selectionButton); allPanel.add(southPanel, BorderLayout.SOUTH); return allPanel; }
From source file:org.jfree.data.RangeTest.java
/** * Simple tests for the contains() method. *//*from ww w. j a va 2 s .c om*/ @Test public void testContains() { Range r1 = new Range(0.0, 1.0); assertFalse(r1.contains(Double.NaN)); assertFalse(r1.contains(Double.NEGATIVE_INFINITY)); assertFalse(r1.contains(-1.0)); assertTrue(r1.contains(0.0)); assertTrue(r1.contains(0.5)); assertTrue(r1.contains(1.0)); assertFalse(r1.contains(2.0)); assertFalse(r1.contains(Double.POSITIVE_INFINITY)); }
From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java
private void drawRangeGridLine(Graphics2D g2, Rectangle2D dataArea, double value) { Range range = rangeAxis.getRange(); if (!range.contains(value)) { return;/*from w w w . j a va 2s . co m*/ } Line2D line = null; double v = rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); }
From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java
private void drawDomainGridLine(Graphics2D g2, Rectangle2D dataArea, double value) { Range range = domainAxis.getRange(); if (!range.contains(value)) { return;/*from ww w. j a v a2s . c o m*/ } Line2D line = null; double v = domainAxis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); }
From source file:org.jfree.experimental.chart.axis.LogAxis.java
/** * Returns a list of ticks for an axis at the top or bottom of the chart. * /* www . j ava 2 s. c o m*/ * @param g2 the graphics device. * @param dataArea the data area. * @param edge the edge. * * @return A list of ticks. */ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); double start = Math.floor(calculateLog(getLowerBound())); double end = Math.ceil(calculateLog(getUpperBound())); double current = start; while (current <= end) { double v = calculateValue(current); if (range.contains(v)) { ticks.add(new NumberTick(new Double(v), createTickLabel(v), TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < this.minorTickCount; i++) { double minorV = v + i * ((next - v) / this.minorTickCount); if (range.contains(minorV)) { ticks.add( new NumberTick(new Double(minorV), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); } } current = current + this.tickUnit.getSize(); } return ticks; }
From source file:org.jfree.experimental.chart.axis.LogAxis.java
/** * Returns a list of ticks for an axis at the left or right of the chart. * //from w w w .j a v a2s . com * @param g2 the graphics device. * @param dataArea the data area. * @param edge the edge. * * @return A list of ticks. */ protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); double start = Math.floor(calculateLog(getLowerBound())); double end = Math.ceil(calculateLog(getUpperBound())); double current = start; while (current <= end) { double v = calculateValue(current); if (range.contains(v)) { ticks.add(new NumberTick(new Double(v), createTickLabel(v), TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < this.minorTickCount; i++) { double minorV = v + i * ((next - v) / this.minorTickCount); if (range.contains(minorV)) { ticks.add(new NumberTick(new Double(minorV), "", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); } } current = current + this.tickUnit.getSize(); } return ticks; }
From source file:userinterface.graph.PrismLogarithmicAxis.java
/** * Returns a list of ticks for an axis at the top or bottom of the chart. * /*from w w w .j a va 2 s . co m*/ * @param g2 the graphics device. * @param dataArea the data area. * @param edge the edge. * * @return A list of ticks. */ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); double start = Math.floor(calculateLog(getLowerBound())); double end = Math.ceil(calculateLog(getUpperBound())); double current = start; while (current <= end) { double v = calculateValue(current); if (range.contains(v)) { ticks.add(new NumberTick(new Double(v), createTickLabel(v), TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < this.minorTickCount; i++) { double minorV = v + i * ((next - v) / this.minorTickCount); if (range.contains(minorV)) { ticks.add( new NumberTick(new Double(minorV), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); } } current = current + this.tickUnit.getSize(); } return ticks; }
From source file:userinterface.graph.PrismLogarithmicAxis.java
/** * Returns a list of ticks for an axis at the left or right of the chart. * /*from w ww. jav a2s . com*/ * @param g2 the graphics device. * @param dataArea the data area. * @param edge the edge. * * @return A list of ticks. */ protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); double start = Math.floor(calculateLog(getLowerBound())); double end = Math.ceil(calculateLog(getUpperBound())); double current = start; while (current <= end) { double v = calculateValue(current); if (range.contains(v)) { ticks.add(new NumberTick(new Double(v), createTickLabel(v), TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < this.minorTickCount; i++) { double minorV = v + i * ((next - v) / this.minorTickCount); if (range.contains(minorV)) { ticks.add(new NumberTick(new Double(minorV), "", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); } } current = current + this.tickUnit.getSize(); } return ticks; }
From source file:de.laures.cewolf.jfree.ThermometerPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device./*from w w w . ja v a 2s.c o m*/ * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { RoundRectangle2D outerStem = new RoundRectangle2D.Double(); RoundRectangle2D innerStem = new RoundRectangle2D.Double(); RoundRectangle2D mercuryStem = new RoundRectangle2D.Double(); Ellipse2D outerBulb = new Ellipse2D.Double(); Ellipse2D innerBulb = new Ellipse2D.Double(); String temp = null; FontMetrics metrics = null; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); // adjust for padding... Rectangle2D interior = (Rectangle2D) area.clone(); this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); int stemTop = (int) (interior.getMinY() + getBulbRadius()); int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop); outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter()); outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2); innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); innerThermometer.add(tempArea); if ((this.dataset != null) && (this.dataset.getValue() != null)) { double current = this.dataset.getValue().doubleValue(); double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); int i = getColumnDiameter() - getGap() * 2; // already calculated int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); if (k < (getGap() + interior.getMinY())) { k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } Area mercury = new Area(innerBulb); if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } g2.setPaint(getCurrentPaint()); g2.fill(mercury); // draw range indicators... if (this.subrangeIndicatorsVisible) { g2.setStroke(this.subrangeIndicatorStroke); Range range = this.rangeAxis.getRange(); // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[NORMAL]); g2.draw(line); } // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[WARNING]); g2.draw(line); } // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[CRITICAL]); g2.draw(line); } } // draw the axis... if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null); break; case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null); break; } } // draw text value on screen g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); metrics = g2.getFontMetrics(); switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap()); break; default: } /***/ } g2.setPaint(this.thermometerPaint); g2.setFont(this.valueFont); // draw units indicator metrics = g2.getFontMetrics(); int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20)); } // draw thermometer outline g2.setStroke(this.thermometerStroke); g2.draw(outerThermometer); g2.draw(innerThermometer); drawOutline(g2, area); }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of z-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range.//w ww . j a va2 s. co m * * @param dataset the dataset ({@code null} not permitted). * @param visibleSeriesKeys the visible series keys ({@code null} not * permitted). * @param xRange the x-range ({@code null} not permitted). * @param includeInterval a flag that determines whether or not the * z-interval for the dataset is included (this only applies if the * dataset has an interval, which is currently not supported). * * @return The y-range (possibly {@code null}). */ public static Range iterateToFindZBounds(XYZDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); Args.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double z = dataset.getZValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(z)) { minimum = Math.min(minimum, z); maximum = Math.max(maximum, z); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }