public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int seriesIndex, int itemIndex, CrosshairState crosshairState, int pass) { PhetHistogramSeries series = ((PhetHistogramDataset)dataset).getSeries( seriesIndex ); if ( series.getNumberOfObservations() == 0 ) { return; } super.drawItem( g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, seriesIndex, itemIndex, crosshairState, pass ); }
@Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { setSeriesShape(series, shape, false); setSeriesStroke(series, stroke, false); if (seriesPaint != null && series < seriesPaint.length) { setSeriesPaint(series, seriesPaint[series], false); } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
public void drawFunctions(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, CrosshairState crosshairState) { if (fillMode == ExcitationFillMode.MIN_MAX) { fillMinMax(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset); } else if (fillMode == ExcitationFillMode.MIN_MAX_EXC) { fillMinMaxExc(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset); } super.drawFunctions(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, crosshairState); }
public void fillMinMaxExc(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset) { if (dataset.getSeriesCount() < 3) return; if (maxFillPaint != null) { fillSeries(2, maxFillPaint, g2, state, dataArea, plot, domainAxis, rangeAxis, dataset); } if (excFillPaint != null) { fillSeries(0, excFillPaint, g2, state, dataArea, plot, domainAxis, rangeAxis, dataset); } if (minFillPaint != null) { fillSeries(1, minFillPaint, g2, state, dataArea, plot, domainAxis, rangeAxis, dataset); } }
private void drawDashedLine( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item ) { // Axis (model) coordinates final double minPosition = domainAxis.getLowerBound(); final double maxPosition = domainAxis.getUpperBound(); final double E0 = dataset.getYValue( series, item ); // the average total energy // Java2D (screen) coordinates RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final double minX = domainAxis.valueToJava2D( minPosition, dataArea, domainAxisLocation ); final double maxX = domainAxis.valueToJava2D( maxPosition, dataArea, domainAxisLocation ); final double averageY = rangeAxis.valueToJava2D( E0, dataArea, rangeAxisLocation ); g2.setPaint( getSeriesPaint( series ) ); g2.setStroke( QTConstants.TOTAL_ENERGY_DASHED_STROKE ); _path.reset(); _path.moveTo( (float)minX, (float)averageY ); _path.lineTo( (float)maxX, (float)averageY ); g2.draw( _path ); }
/** * Draws a horizontal line at each energy value. */ public void drawItem( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass ) { if ( !getItemVisible( series, item ) ) { return; } // Model coordinates to draw a horizontal line at the specified energy... final double minPosition = domainAxis.getLowerBound(); final double maxPosition = domainAxis.getUpperBound(); final double energy = dataset.getYValue( series, item ); // Translate the points to screen coordinates... RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double minX = domainAxis.valueToJava2D( minPosition, dataArea, xAxisLocation ); final double maxX = domainAxis.valueToJava2D( maxPosition, dataArea, xAxisLocation ); final double y = rangeAxis.valueToJava2D( energy, dataArea, yAxisLocation ); // Draw the line... g2.setPaint( getSeriesPaint( series ) ); g2.setStroke( getSeriesStroke( series ) ); _path.reset(); _path.moveTo( (float)minX, (float)y ); _path.lineTo( (float)maxX, (float)y ); g2.draw( _path ); }
@Override public void drawItem( Graphics2D arg0, XYItemRendererState arg1, Rectangle2D arg2, PlotRenderingInfo arg3, XYPlot arg4, ValueAxis arg5, ValueAxis arg6, XYDataset arg7, int arg8, int arg9, CrosshairState arg10, int arg11 ) { if (itemIndex == null || itemIndex == arg9) { super.drawItem( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 ); } }
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (isTransparent) g2.setComposite(alphaComp); super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { g2.setComposite(makeComposite(transparency)); super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { g2.setComposite(makeComposite(transparency)); super.drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea); }
@Override public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataSet, final int series, final int item, final CrosshairState crosshairState, final int pass) { g2.setComposite(makeComposite(OPACITY)); super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataSet, series, item, crosshairState, pass); }
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (series > 0) { g2.setComposite(alphaComp); } else if (series == 0) { g2.setComposite(alphaCompOriginal); } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) { // Set transparency g2.setComposite(alpha); return super.initialise(g2, dataArea, plot, dataset, info); }
public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (series == 0) g2.setComposite(pointAlpha); else g2.setComposite(selectionAlpha); super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
@Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setSeriesShape(series, new DefaultCaret(), false); //Enter, Exit double y = dataset.getYValue(series, item); int side = ((TradeDataset) dataset).get(item).getSide().sign; if (Double.isNaN(y) || y <= 0) { setSeriesPaint(series, null, false); setSeriesStroke(series, null, false); setSeriesShape(series, null, false); } else { setSeriesPaint(series, side * (series == 0 ? 1 : -1) > 0 ? Main.longColor : Main.shortColor, false); setSeriesStroke(series, Main.defaultStoke, false); setSeriesShape(series, series == 0 ? Main.enterShape : Main.exitShape, false); } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
@Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; double yOpen = highLowData.getOpenValue(series, item); double yClose = highLowData.getCloseValue(series, item); if (yClose > yOpen) { setSeriesPaint(series, upPaint, false); } else if (yClose < yOpen) { setSeriesPaint(series, downPaint, false); } else { setSeriesPaint(series, flatPaint, false); } } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
private void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double x0, double y0, double x1, double y1, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); boolean visible; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } visible = LineUtilities.clipLine(state.workingLine, dataArea); if (visible) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } }
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); // The complete area chart is drawn when drawItem() is called for the last // item // so we need to draw all of the item labels after the last item so they'll // be // visible if they overlap the area chart. int itemCount = dataset.getItemCount(series); if (getPlotArea() && item > 0 && item == (itemCount - 1)) { // this is the last item so draw the item labels PlotOrientation orientation = plot.getOrientation(); for (int i = 0; i < itemCount; i++) { if (isItemLabelVisible(series, i)) { double xValue = dataset.getXValue(series, i); double yValue = dataset.getYValue(series, i); if (Double.isNaN(yValue)) { yValue = 0.0; } double transXValue = domainAxis.valueToJava2D(xValue, dataArea, plot.getDomainAxisEdge()); double transYValue = rangeAxis.valueToJava2D(yValue, dataArea, plot.getRangeAxisEdge()); double xx = transXValue; double yy = transYValue; if (orientation == PlotOrientation.HORIZONTAL) { xx = transYValue; yy = transXValue; } drawItemLabel(g2, orientation, dataset, series, i, xx, yy, (yValue < 0.0)); } } } }
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); // draw the item label if there is one... if (isItemLabelVisible(series, item)) { // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); double xx = transX1; double yy = transY1; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } }
/** * Selects a single point. * * @param xx the x coordinate in Java 2D space. * @param yy the y coordinate in Java 2D space. * @param dataArea the data area. * @param source the rendering source (can be used to locate the * appropriate selection state). * * @since 1.2.0 */ public void select(double xx, double yy, Rectangle2D dataArea, RenderingSource source) { int datasetCount = this.datasets.size(); for (int d = 0; d < datasetCount; d++) { XYDataset dataset = (XYDataset) this.datasets.get(d); if (dataset == null) { continue; } XYDatasetSelectionState state = findSelectionStateForDataset( dataset, source); if (state == null) { continue; } Graphics2D g2 = source.createGraphics2D(); XYItemRenderer renderer = getRendererForDataset(dataset); XYItemRendererState rs = renderer.initialise( source.createGraphics2D(), dataArea, this, dataset, null); int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { int itemCount = dataset.getItemCount(s); for (int i = 0; i < itemCount; i++) { // TODO: we should probably ask the renderer to specify // whether or not the item is contained in the path if (renderer.hitTest(xx, yy, g2, dataArea, this, getDomainAxisForDataset(d), getRangeAxisForDataset(d), dataset, s, i, rs, false)) { state.setSelected(s, i, !state.isSelected(s, i)); } } } } }
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { FunctionRenderer renderer = (FunctionRenderer)getRenderer(index); XYDataset dataset = getDataset(index); ValueAxis xAxis = getDomainAxisForDataset(index); ValueAxis yAxis = getRangeAxisForDataset(index); XYItemRendererState state = renderer.initialise(g2, dataArea, this, dataset, info); renderer.drawFunctions(g2, state, dataArea, this, xAxis, yAxis, dataset, crosshairState); return true; }
/** * Draws the visual representation of a single data item. * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information * etc). * @param domainAxis * the domain (horizontal) axis. * @param rangeAxis * the range (vertical) axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot (<code>null</code> * permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.97d; RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double transDomain = 0.0; double transRange = 0.0; double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1; transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); transDomain = Math.abs(transDomain); transRange = Math.abs(transRange); RoundRectangle2D.Double rect = new RoundRectangle2D.Double(transX - (transDomain / 2.0), transY - (transRange / 2.0), transDomain, transRange, 10, 10); g2.setPaint(this.getItemPaint(series, item)); g2.fill(rect); g2.setStroke(new BasicStroke(1.0f)); g2.setPaint(Color.LIGHT_GRAY); g2.draw(rect); this.updateCrosshairValues(crosshairState, x, y, transX, transY, orientation); }
/** * Draws the block representing the specified item. * * @param g2 * the graphics device. * @param state * the state. * @param dataArea * the data area. * @param info * the plot rendering info. * @param plot * the plot. * @param domainAxis * the x-axis. * @param rangeAxis * the y-axis. * @param dataset * the dataset. * @param series * the series index. * @param item * the item index. * @param crosshairState * the crosshair state. * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double colorValue = ((XYZDataset) dataset).getZValue(series, item); double normalized = (colorValue - minColor) / (maxColor - minColor); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { g2.setPaint(colorProvider.getPointColor(normalized)); g2.fill(shape); if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } }
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double dx = 0.0; double dy = 0.0; if (dataset instanceof VectorXYDataset) { dx = ((VectorXYDataset) dataset).getDeltaXValue(series, item); dy = ((VectorXYDataset) dataset).getDeltaYValue(series, item); } double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge()); Line2D line; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { line = new Line2D.Double(yy0, xx0, yy1, xx1); } else { line = new Line2D.Double(xx0, yy0, xx1, yy1); } g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemStroke(series, item)); g2.draw(line); // calculate the arrow head and draw it... double dxx = (xx1 - xx0); double dyy = (yy1 - yy0); double bx = xx0 + (1.0 - this.baseLength) * dxx; double by = yy0 + (1.0 - this.baseLength) * dyy; double cx = xx0 + (1.0 - this.headLength) * dxx; double cy = yy0 + (1.0 - this.headLength) * dyy; double angle = 0.0; if (dxx != 0.0) { angle = Math.PI / 2.0 - Math.atan(dyy / dxx); } double deltaX = 2.0 * Math.cos(angle); double deltaY = 2.0 * Math.sin(angle); double leftx = cx + deltaX; double lefty = cy - deltaY; double rightx = cx - deltaX; double righty = cy + deltaY; GeneralPath p = new GeneralPath(); p.moveTo((float) xx1, (float) yy1); p.lineTo((float) rightx, (float) righty); p.lineTo((float) bx, (float) by); p.lineTo((float) leftx, (float) lefty); p.closePath(); g2.draw(p); }
@Override public void drawItem(Graphics2D gd, XYItemRendererState xyirs, Rectangle2D rd, PlotRenderingInfo pri, XYPlot xyplot, ValueAxis va, ValueAxis va1, XYDataset xyd, int i, int i1, CrosshairState cs, int i2) { Shape hotspot = defaultShape; EntityCollection entities = null; if (pri != null) { entities = pri.getOwner().getEntityCollection(); } double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); double transX = va.valueToJava2D(x, rd, xyplot.getDomainAxisEdge()); double transY = va1.valueToJava2D(y, rd, xyplot.getRangeAxisEdge()); Shape myshape = defaultShape; PlotOrientation orientation = xyplot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { myshape = ShapeUtilities.createTranslatedShape(myshape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { myshape = ShapeUtilities.createTranslatedShape(myshape, transX, transY); } if (zRange == null) { this.determineZRange(); } Color pointColor; if (zRange[0] == zRange[1]) { pointColor = Color.BLUE; } else { pointColor = PlotSettings.INSTANCE.getColor(zRange[0], zRange[1], this.data.getZValue(0, i1)); } gd.setPaint(pointColor); gd.fill(myshape); gd.setPaint(pointColor); gd.setStroke(this.getItemOutlineStroke(i, i1)); gd.draw(myshape); if (entities != null) { addEntity(entities, hotspot, xyd, i, i1, transX, transY); } }
/** * Draws the proper representation of total energy, * as described in the javadoc for this class. */ public void drawItem( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass ) { // Do all rendering based on the first data point. if ( item != 0 ) { return; } // Initialized? if ( _wavePacket == null || _potentialEnergy == null ) { return; } // Visible? if ( !getItemVisible( series, item ) ) { return; } // Enabled antialiasing g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR ); // Java 1.5 workaround // Axis (model) coordinates final double packetCenter = _wavePacket.getCenter(); final double E0 = dataset.getYValue( series, item ); // average total energy final double V0 = _potentialEnergy.getEnergyAt( packetCenter ); // potential energy at wave packet's initial center // Determine which representation to use for total energy if ( E0 <= V0 ) { drawDashedLine( g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item ); } else if ( _potentialEnergy.isInWell( packetCenter ) ) { drawBandAndEigenstates( g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item ); } else { drawBand( g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item ); } }
private void drawBand( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item ) { // Wave packet properties (model coordinates) final double packetCenter = _wavePacket.getCenter(); final double packetWidth = _wavePacket.getWidth(); // Axis (model) coordinates final double minPosition = domainAxis.getLowerBound(); final double maxPosition = domainAxis.getUpperBound(); final double E0 = dataset.getYValue( series, item ); // the average total energy final double V0 = _potentialEnergy.getEnergyAt( packetCenter ); final double k0 = Math.sqrt( ( 2 * MASS * ( E0 - V0 ) ) / ( HBAR * HBAR ) ); final double term1 = ( 2 * HBAR / packetWidth ) * Math.sqrt( 2 * ( E0 - V0 ) / MASS ); final double term2 = ( 2 * HBAR * HBAR ) / ( MASS * packetWidth * packetWidth ); final double maxE = E0 + term1 + term2; // min total energy double minE = E0 - term1 + term2; // max total energy if ( k0 * packetWidth <= 2 ) { minE = V0; } // Java2D (screen) coordinates RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final double minX = domainAxis.valueToJava2D( minPosition, dataArea, domainAxisLocation ); final double maxX = domainAxis.valueToJava2D( maxPosition, dataArea, domainAxisLocation ); final double minY = rangeAxis.valueToJava2D( maxE, dataArea, rangeAxisLocation ); // +y is down! final double maxY = rangeAxis.valueToJava2D( minE, dataArea, rangeAxisLocation ); // +y is down! final double averageY = rangeAxis.valueToJava2D( E0, dataArea, rangeAxisLocation ); final double width = Math.max( maxX - minX, 1 ); final double topHeight = Math.max( averageY - minY, 1 ); final double bottomHeight = Math.max( maxY - averageY, 1 ); // Draw a band... { Shape topShape = new Rectangle2D.Double( minX, minY, width, topHeight + 1 ); Shape bottomShape = new Rectangle2D.Double( minX, averageY, width, bottomHeight ); // Take care that the gradients aren't zero pixels high! That will crash the JVM. Paint topPaint = new GradientPaint( (float) minX, (float) minY, _edgeColor, (float) minX, (float) ( minY + topHeight ), _centerColor ); Paint bottomPaint = new GradientPaint( (float) minX, (float) averageY, _centerColor, (float) minX, (float) ( averageY + bottomHeight ), _edgeColor ); g2.setPaint( topPaint ); g2.fill( topShape ); g2.setPaint( bottomPaint ); g2.fill( bottomShape ); } // Draw a line for the average total energy... { Paint paint = darkenColor( getSeriesPaint( series ) ); g2.setPaint( paint ); g2.setStroke( QTConstants.AVERAGE_TOTAL_ENERGY_STROKE ); _path.reset(); _path.moveTo( (float)minX, (float)averageY ); _path.lineTo( (float)maxX, (float)averageY ); g2.draw( _path ); } }
/** * Draws an item in the dataset. * <p> * The dataset consists of interleaved magnitude and phase values * (in that order). When drawing a magnitude/phase pair (M1,P1), * we look ahead at the next pair (M2,P2). M1 and M2 are used to * construct a 4-sided polygon, which is filled using a color * based on P1. (P2 is ignored.) The color is created by performing * and HSV-to-RGB conversion using P1 as the hue component. */ public void drawItem( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass ) { // draw only if visible... if ( !getItemVisible( series, item ) ) { return; } // every other item is a phase angle... if ( item % 2 == 1 ) { return; } // there is no corresponding polygon for the last 2 items... if ( item == dataset.getItemCount( series ) - 2 ) { return; } // get 2 adjacent data points and phase... double x1 = dataset.getXValue( series, item ); double y1 = dataset.getYValue( series, item ); double x2 = dataset.getXValue( series, item + 2 ); double y2 = dataset.getYValue( series, item + 2 ); double phase = dataset.getYValue( series, item + 1 ); // translate the points to screen coordinates... RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); double tx1 = domainAxis.valueToJava2D( x1, dataArea, xAxisLocation ); double tx2 = domainAxis.valueToJava2D( x2, dataArea, xAxisLocation ); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double ty0 = rangeAxis.valueToJava2D( 0, dataArea, yAxisLocation ); double ty1 = rangeAxis.valueToJava2D( y1, dataArea, yAxisLocation ); double ty2 = rangeAxis.valueToJava2D( y2, dataArea, yAxisLocation ); // Enable antialiasing... g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); // determine the color that corresponds to the phase... Color color = phaseToRGB( phase ); g2.setPaint( color ); // fill the area under the curve between the two data points... // // (tx1,ty1) +--------+ (tx2,ty2) // | | // | | // | | // (tx1,ty0) +--------+ (tx2, ty0) // _polygonPath.reset(); _polygonPath.moveTo( (float) tx1, (float) ty0 ); _polygonPath.lineTo( (float) tx1, (float) ty1 ); _polygonPath.lineTo( (float) tx2, (float) ty2 ); _polygonPath.lineTo( (float) tx2, (float) ty0 ); _polygonPath.closePath(); g2.fill( _polygonPath ); }
/** * Draws an item in the dataset. * <p> * The dataset consists of interleaved magnitude and phase values * (in that order). When drawing a magnitude/phase pair (M1,P1), * we look ahead at the next pair (M2,P2). M1 and M2 are used to * construct a 4-sided polygon, which is filled using a color * based on P1. (P2 is ignored.) The color is created by performing * an HSV-to-RGB conversion using P1 as the hue component. */ public void drawItem( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass ) { // draw only if visible... if ( !getItemVisible( series, item ) ) { return; } // every other item is a phase angle... if ( item % 2 == 1 ) { return; } // there is no corresponding polygon for the last 2 items... if ( item == dataset.getItemCount( series ) - 2 ) { return; } // get 2 adjacent data points and phase... double x1 = dataset.getXValue( series, item ); double y1 = dataset.getYValue( series, item ); double x2 = dataset.getXValue( series, item + 2 ); double y2 = dataset.getYValue( series, item + 2 ); double phase = dataset.getYValue( series, item + 1 ); // translate the points to screen coordinates... RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); double tx1 = domainAxis.valueToJava2D( x1, dataArea, xAxisLocation ); double tx2 = domainAxis.valueToJava2D( x2, dataArea, xAxisLocation ); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double ty0 = rangeAxis.valueToJava2D( 0, dataArea, yAxisLocation ); double ty1 = rangeAxis.valueToJava2D( y1, dataArea, yAxisLocation ); double ty2 = rangeAxis.valueToJava2D( y2, dataArea, yAxisLocation ); // Enable antialiasing... g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); // determine the color that corresponds to the phase... Color color = phaseToRGB( phase ); g2.setPaint( color ); // fill the area under the curve between the two data points... // // (tx1,ty1) +--------+ (tx2,ty2) // | | // | | // | | // (tx1,ty0) +--------+ (tx2, ty0) // _polygonPath.reset(); _polygonPath.moveTo( (float) tx1, (float) ty0 ); _polygonPath.lineTo( (float) tx1, (float) ty1 ); _polygonPath.lineTo( (float) tx2, (float) ty2 ); _polygonPath.lineTo( (float) tx2, (float) ty0 ); _polygonPath.closePath(); g2.fill( _polygonPath ); }
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain (horizontal) axis. * @param rangeAxis the range (vertical) axis. * @param dataset the dataset (a {@link edu.ucla.stat.SOCR.motionchart.MotionDataSet} is expected). * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (!(dataset instanceof MotionDataSet)) { throw new IllegalArgumentException("The dataset must be of type MotionDataSet."); } // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); Ellipse2D.Double shape = (Ellipse2D.Double)getItemShape(series, item); if (shape.getWidth() != 0 && shape.getHeight() != 0) { Ellipse2D.Double circle = translateShape(shape, plot, dataArea); g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { currCircle = circle; if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterX(), circle.getCenterY(), false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterY(), circle.getCenterX(), false); } } // add an entity if this info is being collected EntityCollection entities; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, shape.getCenterX(), shape.getCenterY(), domainAxisIndex, rangeAxisIndex, circle.getCenterX(), circle.getCenterY(), orientation); } }
@Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { TimeSeriesCollection timeDataSet = (TimeSeriesCollection)dataset; // get the x value for the series/item. double x = timeDataSet.getX(series, item).doubleValue(); // get the min/max of the range axis double yMin = rangeAxis.getLowerBound(); double yMax = rangeAxis.getUpperBound(); RectangleEdge domainEdge = plot.getDomainAxisEdge(); RectangleEdge rangeEdge = plot.getRangeAxisEdge(); // convert the coordinates to java2d. double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge); double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge); double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge); // get the paint information for the series/item Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); }
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double colorValue = ((XYZDataset)dataset).getZValue(series, item); double normalized = (colorValue - minColor) / (maxColor - minColor); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { g2.setPaint(colorProvider.getPointColor(normalized)); g2.fill(shape); if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } }
/** * Initialises and returns a state object that can be passed to each * invocation of the {@link #drawItem} method. * * @param g2 the graphics target. * @param dataArea the data area. * @param plot the plot. * @param dataset the dataset. * @param info the plot rendering info. * * @return A newly initialised state object. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) { State state = new State(info); state.seriesPath = new GeneralPath(); state.setProcessVisibleItemsOnly(false); return state; }
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { g2.setComposite(makeComposite(transparency)); super.drawPrimaryLine(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea); }
/** * Initialises the renderer. * <P> * This method will be called before the first item is rendered, giving the renderer an opportunity to initialise * any state information it wants to maintain. The renderer can do nothing if it chooses. * * @param g2 * the graphics device. * @param dataArea * the area inside the axes. * @param plot * the plot. * @param data * the data. * @param info * an optional info collection object to return data back to the caller. * * @return The renderer state. */ @Override public XYItemRendererState initialise(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot, final XYDataset data, final PlotRenderingInfo info) { final State state = new State(info); state.seriesPath = new GeneralPath(); state.seriesIndex = -1; return state; }
/** * Initialises the renderer and returns a state object that should be passed * to all subsequent calls to the drawItem() method. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param plot the plot. * @param data the data. * @param info an optional info collection object to return data back to the * caller. * * @return A state object for use by the renderer. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info) { AreaRendererState state = new AreaRendererState(info); return state; }