private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solution) { XYPlot plot = new XYPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem); plot.setDataset(0, problem); plot.setRenderer(0, problemRenderer); XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments); plot.setDataset(1, shipments); plot.setRenderer(1, shipmentsRenderer); if (solution != null) { XYItemRenderer solutionRenderer = getRouteRenderer(solution); plot.setDataset(2, solution); plot.setRenderer(2, solutionRenderer); } NumberAxis xAxis = new NumberAxis(); NumberAxis yAxis = new NumberAxis(); if (boundingBox == null) { xAxis.setRangeWithMargins(getDomainRange(problem)); yAxis.setRangeWithMargins(getRange(problem)); } else { xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX)); yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY)); } plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); return plot; }
/** * Slides the axis range by the specified percentage. * * @param percent the percentage. * * @since 1.0.13 */ public void pan(double percent) { Range r = getRange(); double length = range.getLength(); double adj = length * percent; double lower = r.getLowerBound() + adj; double upper = r.getUpperBound() + adj; setRange(lower, upper); }
/** * Centers the axis range about the specified value and sends an * {@link AxisChangeEvent} to all registered listeners. * * @param value the center value. */ public void centerRange(double value) { double central = this.range.getCentralValue(); Range adjusted = new Range(this.range.getLowerBound() + value - central, this.range.getUpperBound() + value - central); setRange(adjusted); }
/** * Translates a data value to an angle on the dial. * * @param value the value. * * @return The angle on the dial. */ public double valueToAngle(double value) { value = value - this.range.getLowerBound(); double baseAngle = 180 + ((this.meterAngle - 180) / 2); return baseAngle - ((value / this.range.getLength()) * this.meterAngle); }
/** * Constructs a new range that is based on another {@link Range}. The * other range does not have to be a {@link DateRange}. If it is not, the * upper and lower bounds are evaluated as milliseconds since midnight * GMT, 1-Jan-1970. * * @param other the other range ({@code null} not permitted). */ public DateRange(Range other) { this(other.getLowerBound(), other.getUpperBound()); }
insets.trim(area); area.setRect(area.getX() + 4, area.getY() + 4, area.getWidth() - 8, area.getHeight() - 8); meterH = 2 * min; Rectangle2D meterArea = new Rectangle2D.Double(meterX, meterY, meterW, meterH); Rectangle2D.Double originalArea = new Rectangle2D.Double( meterArea.getX() - 4, meterArea.getY() - 4, meterArea.getWidth() + 8, meterArea.getHeight() + 8); double dataMin = this.range.getLowerBound(); double dataMax = this.range.getUpperBound(); Shape savedClip = g2.getClip(); g2.clip(originalArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); drawValueLabel(g2, meterArea); if (this.range.contains(value)) { g2.setPaint(this.needlePaint); g2.setStroke(new BasicStroke(2.0f));
Rectangle2D target = (Rectangle2D) area.clone(); target = trimMargin(target); if (this.backgroundPaint != null) { g2.setPaint(this.backgroundPaint); g2.fill(target); double base = this.axis.getLowerBound(); double increment = this.axis.getRange().getLength() / this.subdivisions; Rectangle2D r = new Rectangle2D.Double(); g2.setPaint(this.stripOutlinePaint); g2.setStroke(this.stripOutlineStroke); g2.draw(new Rectangle2D.Double(target.getMinX(), target.getMaxY() - this.stripWidth, target.getWidth(), this.stripWidth)); g2.setPaint(this.stripOutlinePaint); g2.setStroke(this.stripOutlineStroke); g2.draw(new Rectangle2D.Double(target.getMinX(), target.getMinY(), target.getWidth(), this.stripWidth));
plotState); if (isAdvanceLineVisible()) { double xx = valueToJava2D(getRange().getUpperBound(), dataArea, edge); Line2D mark = null; g2.setStroke(getAdvanceLineStroke()); g2.setPaint(getAdvanceLinePaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor, xx, cursor + dataArea.getWidth(), xx); mark = new Line2D.Double(cursor - dataArea.getWidth(), xx, cursor, xx); mark = new Line2D.Double(xx, cursor + dataArea.getHeight(), xx, cursor); cursor - dataArea.getHeight()); g2.draw(mark);
boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D tmpDataArea = (Rectangle2D) dataArea.clone(); double h = tmpDataArea.getHeight(); double w = tmpDataArea.getWidth(); double xLength = getDomainAxis().getRange().getLength(); double yLength = getRangeAxis().getRange().getLength(); double unitRatio = yLength / xLength; colorBarArea, this.colorBarLocation); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
/** * Returns the content size for the title. * * @param g2 the graphics device. * @param widthRange the width range. * @param heightRange the height range. * * @return The content size. */ @Override protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) { g2.setFont(getFont()); FontMetrics fm = g2.getFontMetrics(getFont()); Rectangle2D bounds = TextUtils.getTextBounds(getText(), g2, fm); if (bounds.getWidth() <= widthRange.getUpperBound() && bounds.getHeight() <= heightRange.getUpperBound()) { return new Size2D(bounds.getWidth(), bounds.getHeight()); } else { return new Size2D(0.0, 0.0); } }
IntervalMarker marker = (IntervalMarker) iterator.next(); double start = Math.max( marker.getStartValue(), this.axis.getRange().getLowerBound() ); double end = Math.min( marker.getEndValue(), this.axis.getRange().getUpperBound() ); double s = this.axis.valueToJava2D( end, dataArea, RectangleEdge.BOTTOM ); Rectangle2D r = new Rectangle2D.Double( s, y + this.topOuterGap, e - s, h - this.topOuterGap - this.bottomOuterGap ); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, marker.getAlpha()) ); g2.setPaint(marker.getPaint()); g2.fill(r); g2.setPaint(marker.getOutlinePaint());
dataArea, plot.getDomainAxisEdge()); double highVal, lowVal; if ((meanValue.doubleValue() + valueDelta) > rangeAxis.getRange().getUpperBound()) { highVal = rangeAxis.valueToJava2D( rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation); < rangeAxis.getRange().getLowerBound()) { lowVal = rangeAxis.valueToJava2D( rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation); g2.setPaint(this.errorIndicatorPaint); g2.setPaint(getItemPaint(row, column)); g2.setStroke(this.errorIndicatorStroke); g2.setStroke(getItemOutlineStroke(row, column)); line = new Line2D.Double(y0, x0, y1, x1); line = new Line2D.Double(x0, y0, x1, y1); g2.setPaint(getItemPaint(row, column));
FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); if (isVerticalTickLabels()) { ol = fm.getMaxAdvance(); float xx = (float) valueToJava2D(getRange().getUpperBound(), dataArea, edge); Line2D mark = null; g2.setStroke(getTickMarkStroke()); g2.setPaint(getTickMarkPaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx); mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx); mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
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, anchorY; if (this.coordinateType == XYCoordinateType.RELATIVE) { anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); double maxW = dataArea.getWidth(); double maxH = dataArea.getHeight(); if (this.coordinateType == XYCoordinateType.RELATIVE) { if (this.maxWidth > 0.0) { new Range(0, maxW), new Range(0, maxH));
/** * Converts a length in data coordinates into the corresponding length in * Java2D coordinates. * * @param length the length. * @param area the plot area. * @param edge the edge along which the axis lies. * * @return The length in Java2D coordinates. */ public double lengthToJava2D(double length, Rectangle2D area, RectangleEdge edge) { double axisLength = 0.0; if (this.displayEnd > this.displayStart) { axisLength = this.displayEnd - this.displayStart; } else { axisLength = (this.fixedRange.getUpperBound() - this.displayStart) + (this.displayEnd - this.fixedRange.getLowerBound()); } double areaLength = 0.0; if (RectangleEdge.isLeftOrRight(edge)) { areaLength = area.getHeight(); } else { areaLength = area.getWidth(); } return (length / axisLength) * areaLength; }
double axisMin = calculateLog(range.getLowerBound()); double axisMax = calculateLog(range.getUpperBound()); value = calculateLog(value); double max = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { min = area.getX(); max = area.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { max = area.getMinY(); min = area.getMaxY();
FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc); result += lm.getHeight(); FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); String lowerStr, upperStr; NumberFormat formatter = getNumberFormatOverride();
double axisMin = range.getLowerBound(); double axisMax = range.getUpperBound(); min = area.getX(); max = area.getMaxX(); min = area.getMaxY(); max = area.getY();
FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc); result += lm.getHeight(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2);
/** * Selects a tick unit when the axis is displayed horizontally. * * @param g2 the graphics device. * @param drawArea the drawing area. * @param dataArea the data area. * @param edge the side of the rectangle on which the axis is displayed. */ protected void selectHorizontalAutoTickUnit(Graphics2D g2, Rectangle2D drawArea, Rectangle2D dataArea, RectangleEdge edge) { double tickLabelWidth = estimateMaximumTickLabelWidth(g2, getTickUnit()); // Compute number of labels double n = getRange().getLength() * tickLabelWidth / dataArea.getWidth(); setTickUnit( (NumberTickUnit) getStandardTickUnits().getCeilingTickUnit(n), false, false); }