List of usage examples for org.jfree.chart.plot XYPlot getDomainAxisEdge
public RectangleEdge getDomainAxisEdge()
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * Translates mouse coordinates to chart coordinates (xy-axis) * //from ww w.j a va 2 s . c o m * @param myChart * @param mouseX * @param mouseY * @return Range as chart coordinates (never null) */ public static Point2D mouseXYToPlotXY(ChartViewer myChart, int mouseX, int mouseY) { XYPlot plot = null; // find plot as parent of axis ChartEntity entity = findChartEntity(myChart.getCanvas(), mouseX, mouseY); if (entity instanceof AxisEntity) { Axis a = ((AxisEntity) entity).getAxis(); if (a.getPlot() instanceof XYPlot) plot = (XYPlot) a.getPlot(); } ChartRenderingInfo info = myChart.getRenderingInfo(); int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY)); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); if (subplot != -1) dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea(); // find subplot or plot if (plot == null) plot = findXYSubplot(myChart.getChart(), info, mouseX, mouseY); // coordinates double cx = 0; double cy = 0; if (plot != null) { // find axis ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // parent? if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); domainAxis = pp.getDomainAxis(); domainAxisEdge = pp.getDomainAxisEdge(); } if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); rangeAxis = pp.getRangeAxis(); rangeAxisEdge = pp.getRangeAxisEdge(); } if (domainAxis != null) cx = domainAxis.java2DToValue(mouseX, dataArea, domainAxisEdge); if (rangeAxis != null) cy = rangeAxis.java2DToValue(mouseY, dataArea, rangeAxisEdge); } return new Point2D.Double(cx, cy); }
From source file:com.od.jtimeseries.ui.visualizer.chart.creator.EfficientXYLineAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items.//from w w w .ja v a2 s. c o m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } 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; } int transX0Int = (int) transX0; int transX1Int = (int) transX1; //make sure we store the max and min y for this x boolean isSameX = transX0Int == transX1Int; if (isSameX) { minY = Math.min(transY0, minY); minY = Math.min(transY1, minY); maxY = Math.max(transY0, maxY); maxY = Math.max(transY1, maxY); storedLine = true; } //if we have moved x, or this the last item in the series, draw if (!isSameX || isLastItem(dataset, series, item)) { Stroke s = getItemStroke(series, item); Paint p = getItemPaint(series, item); if (storedLine) { drawLine(state, g2, plot, transX0Int, minY, transX0Int, maxY, s, p); linesDrawn++; } drawLine(state, g2, plot, transX0Int, transY0, transX1Int, transY1, s, p); linesDrawn++; storedLine = false; minY = Integer.MAX_VALUE; maxY = Integer.MIN_VALUE; } // if ( isLastItem(dataset, series, item)) { // System.out.println("Lines drawn " + linesDrawn + "/" + dataset.getItemCount(series)); // } }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Sets the current {@link PlotConfiguration} for this dialog. * /*from w w w.jav a2 s.c o m*/ * @param plotConfig */ private void setPlotConfiguration(PlotConfiguration plotConfig) { if (plotConfig == null) { throw new IllegalArgumentException("plotConfig must not be null!"); } this.plotConfig = plotConfig; Vector<RangeAxisConfig> rangeConfigsVector = new Vector<RangeAxisConfig>(); String selectedItem = String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()); for (RangeAxisConfig config : this.plotConfig.getRangeAxisConfigs()) { rangeConfigsVector.add(config); } rangeAxisSelectionCombobox.setModel(new DefaultComboBoxModel(rangeConfigsVector)); // reselect the previously selected RangeAxisConfig (if it is still there) if (selectedItem != null) { for (int i = 0; i < rangeAxisSelectionCombobox.getItemCount(); i++) { if (String.valueOf(rangeAxisSelectionCombobox.getItemAt(i)).equals(selectedItem)) { rangeAxisSelectionCombobox.setSelectedIndex(i); break; } } } // calculate preselected x/y values if (mousePosition != null) { Rectangle2D plotArea = engine.getChartPanel().getScreenDataArea(); if (engine.getChartPanel().getChart().getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) engine.getChartPanel().getChart().getPlot(); // calculate x value double chartX = plot.getDomainAxis().java2DToValue(mousePosition.getX(), plotArea, plot.getDomainAxisEdge()); xField.setText(String.valueOf(chartX)); // calculate y value for (int i = 0; i < plot.getRangeAxisCount(); i++) { ValueAxis config = plot.getRangeAxis(i); if (config != null && config.getLabel() != null) { if (config.getLabel() .equals(String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()))) { double chartY = config.java2DToValue(mousePosition.getY(), plotArea, plot.getRangeAxisEdge()); yField.setText(String.valueOf(chartY)); } } } } } }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
private void updateToolTipLocation() { if (!toolTip.isVisible()) { return;//from w ww .j a v a 2s . c om } XYPlot plot = chart.getXYPlot(); Rectangle2D chartArea = cp.getScreenDataArea(); if (chartArea.getWidth() == 0) { // no idea why that happens return; } double vx = plot.getDomainAxis().valueToJava2D(this.toolTipValue, chartArea, plot.getDomainAxisEdge()); if (vx + toolTip.getWidth() > cp.getScreenDataArea().getMaxX()) { toolTip.setLocation((int) vx - toolTip.getWidth(), 10); } else { toolTip.setLocation((int) vx, 10); } }
From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java
/** * Draws the block representing the specified item. * /* w w w. j a va2s . c o m*/ * @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); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
/** * Decreases the range on the horizontal axis, centered about a Java2D x coordinate. * <P>/* w w w. ja v a2 s . c o m*/ * The range on the x axis is multiplied by zoomFactor * * @param x the x coordinate in Java2D space. * @param zoomFactor the zoomFactor < 1 == zoom in; else out. */ private void zoomHorizontal(double x, double zoomFactor) { JFreeChart chart = this.chartPanel.getChart(); ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); if (chart.getPlot() instanceof XYPlot) { XYPlot hvp = (XYPlot) chart.getPlot(); ValueAxis axis = hvp.getDomainAxis(); if (axis != null) { double anchorValue = axis.java2DToValue((float) x, info.getPlotInfo().getDataArea(), hvp.getDomainAxisEdge()); if (zoomFactor < 1.0) { axis.resizeRange(zoomFactor, anchorValue); } else if (zoomFactor > 1.0) { Range range = hvp.getDataRange(axis); adjustRange(axis, range, zoomFactor, anchorValue); } } } }
From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java
/** * Draws the visual representation of a single data item. * // ww w .j a va2 s . c o m * @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 (an {@link XYZDataset} 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(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) { PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double circleSize; circleSize = maxSize * (z / maxZ); circleSize = Math.abs(circleSize); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize); } 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)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }
From source file:com.ivli.roim.controls.ChartControl.java
@Override public void mouseDragged(MouseEvent e) { final XYPlot plot = getChart().getXYPlot(); if (null != iEntity) { moveTo(plot.getRangeAxis().java2DToValue(e.getY(), getChartRenderingInfo().getPlotInfo().getDataArea(), plot.getRangeAxisEdge())); }/*from w w w . java 2s .co m*/ if (null != iMarker) { double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(), plot.getDomainAxisEdge()); iMarker.setValue(domainX); } else super.mouseDragged(e); }
From source file:com.rapidminer.gui.plotter.charts.ColorizedShapeItemRenderer.java
/** * Draws the block representing the specified item. * //from w w w . j av a 2 s .c o m * @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); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.java
/** * 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 (an {@link XYZDataset} 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. */// w w w. j a va 2 s .c om 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) { final PlotOrientation orientation = plot.getOrientation(); // get the data point... final double x = dataset.getXValue(series, item); final double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { final XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double circleSize; circleSize = maxSize * (z / maxZ); circleSize = Math.abs(circleSize); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize); } 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)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // add an entity for the item... if (entities != null) { String tip = null; final XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }