List of usage examples for java.awt.geom Rectangle2D getCenterY
public double getCenterY()
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start, final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke, final float arrowSize) { final double startx = start.getCenterX(); final double starty = start.getCenterY(); final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty); if (arrowPoint != null) { gfx.setStroke(arrowStroke);/* w w w. j a v a2s . c o m*/ double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty); final double arrowAngle = Math.PI / 12.0d; final double x1 = arrowSize * Math.cos(angle - arrowAngle); final double y1 = arrowSize * Math.sin(angle - arrowAngle); final double x2 = arrowSize * Math.cos(angle + arrowAngle); final double y2 = arrowSize * Math.sin(angle + arrowAngle); final double cx = (arrowSize / 2.0f) * Math.cos(angle); final double cy = (arrowSize / 2.0f) * Math.sin(angle); final GeneralPath polygon = new GeneralPath(); polygon.moveTo(arrowPoint.getX(), arrowPoint.getY()); polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1); polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2); polygon.closePath(); gfx.fill(polygon); gfx.setStroke(lineStroke); gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx), (int) (arrowPoint.getY() + cy)); } }
From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java
private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar, PlotOrientation orientation) {//from ww w . j a va 2 s . c o m Point2D result = null; double offset = getItemLabelAnchorOffset(); double x0 = bar.getX() - offset; double x1 = bar.getX(); double x2 = bar.getX() + offset; double x3 = bar.getCenterX(); double x4 = bar.getMaxX() - offset; double x5 = bar.getMaxX(); double x6 = bar.getMaxX() + offset; double y0 = bar.getMaxY() + offset; double y1 = bar.getMaxY(); double y2 = bar.getMaxY() - offset; double y3 = bar.getCenterY(); double y4 = bar.getMinY() + offset; double y5 = bar.getMinY(); double y6 = bar.getMinY() - offset; if (anchor == ItemLabelAnchor.CENTER) { result = new Point2D.Double(x3, y3); } else if (anchor == ItemLabelAnchor.INSIDE1) { result = new Point2D.Double(x4, y4); } else if (anchor == ItemLabelAnchor.INSIDE2) { result = new Point2D.Double(x4, y4); } else if (anchor == ItemLabelAnchor.INSIDE3) { result = new Point2D.Double(x4, y3); } else if (anchor == ItemLabelAnchor.INSIDE4) { result = new Point2D.Double(x4, y2); } else if (anchor == ItemLabelAnchor.INSIDE5) { result = new Point2D.Double(x4, y2); } else if (anchor == ItemLabelAnchor.INSIDE6) { result = new Point2D.Double(x3, y2); } else if (anchor == ItemLabelAnchor.INSIDE7) { result = new Point2D.Double(x2, y2); } else if (anchor == ItemLabelAnchor.INSIDE8) { result = new Point2D.Double(x2, y2); } else if (anchor == ItemLabelAnchor.INSIDE9) { result = new Point2D.Double(x2, y3); } else if (anchor == ItemLabelAnchor.INSIDE10) { result = new Point2D.Double(x2, y4); } else if (anchor == ItemLabelAnchor.INSIDE11) { result = new Point2D.Double(x2, y4); } else if (anchor == ItemLabelAnchor.INSIDE12) { result = new Point2D.Double(x3, y4); } else if (anchor == ItemLabelAnchor.OUTSIDE1) { result = new Point2D.Double(x5, y6); } else if (anchor == ItemLabelAnchor.OUTSIDE2) { result = new Point2D.Double(x6, y5); } else if (anchor == ItemLabelAnchor.OUTSIDE3) { result = new Point2D.Double(x6, y3); } else if (anchor == ItemLabelAnchor.OUTSIDE4) { result = new Point2D.Double(x6, y1); } else if (anchor == ItemLabelAnchor.OUTSIDE5) { result = new Point2D.Double(x5, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE6) { result = new Point2D.Double(x3, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE7) { result = new Point2D.Double(x1, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE8) { result = new Point2D.Double(x0, y1); } else if (anchor == ItemLabelAnchor.OUTSIDE9) { result = new Point2D.Double(x0, y3); } else if (anchor == ItemLabelAnchor.OUTSIDE10) { result = new Point2D.Double(x0, y5); } else if (anchor == ItemLabelAnchor.OUTSIDE11) { result = new Point2D.Double(x1, y6); } else if (anchor == ItemLabelAnchor.OUTSIDE12) { result = new Point2D.Double(x3, y6); } return result; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Handles an action event./*from w w w . j a va 2 s . c om*/ * * @param evt * the event. */ public void actionPerformed(final ActionEvent evt) { try { final String acmd = evt.getActionCommand(); if (acmd.equals(ACTION_CMD_ZOOM_BOX)) { setPanMode(false); } else if (acmd.equals(ACTION_CMD_PAN)) { setPanMode(true); } else if (acmd.equals(ACTION_CMD_ZOOM_IN)) { final ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); final Rectangle2D rect = info.getPlotInfo().getDataArea(); zoomBoth(rect.getCenterX(), rect.getCenterY(), ZOOM_FACTOR); } else if (acmd.equals(ACTION_CMD_ZOOM_OUT)) { final ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); final Rectangle2D rect = info.getPlotInfo().getDataArea(); zoomBoth(rect.getCenterX(), rect.getCenterY(), 1 / ZOOM_FACTOR); } else if (acmd.equals(ACTION_CMD_ZOOM_TO_FIT)) { // X-axis (has no fixed borders) // this.chartPanel.autoRangeHorizontal(); // Y-Axes) (autoRangeVertical // not useful because of fixed borders final Plot plot = this.chartPanel.getChart().getPlot(); if (plot instanceof ValueAxisPlot) { final XYPlot vvPlot = (XYPlot) plot; ValueAxis axis = vvPlot.getRangeAxis(); if (axis != null) { axis.setLowerBound(this.primYMinMax[0]); axis.setUpperBound(this.primYMinMax[1]); } if (plot instanceof XYPlot) { final XYPlot xyPlot = (XYPlot) plot; axis = xyPlot.getRangeAxis(1); if (axis != null) { axis.setLowerBound(this.secondYMinMax[0]); axis.setUpperBound(this.secondYMinMax[1]); } } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.rapidminer.gui.plotter.charts.BubbleChartPlotter.java
@Override public void updatePlotter() { final DataTable dataTable = getDataTable(); prepareData();/*from w w w . j a v a2 s. c om*/ JFreeChart chart = ChartFactory.createBubbleChart(null, // chart title null, // domain axis label null, // range axis label xyzDataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0 && axis[BUBBLE_SIZE_AXIS] >= 0) { if (nominal) { int size = xyzDataSet.getSeriesCount(); chart = ChartFactory.createBubbleChart(null, // chart title null, // domain axis label null, // range axis label xyzDataSet, // data PlotOrientation.VERTICAL, // orientation colorColumn >= 0 && size < 100 ? true : false, // include legend true, // tooltips false // URLs ); // renderer settings XYBubbleRenderer renderer = (XYBubbleRenderer) chart.getXYPlot().getRenderer(); renderer.setBaseOutlinePaint(Color.BLACK); if (size > 1) { for (int i = 0; i < size; i++) { renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1))); renderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 7, 7)); } } else { renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d)); renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7)); } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label xyzDataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); // renderer settings ColorizedBubbleRenderer renderer = new ColorizedBubbleRenderer(this.colors); renderer.setBaseOutlinePaint(Color.BLACK); chart.getXYPlot().setRenderer(renderer); // legend settings chart.addLegend(new LegendTitle(renderer) { private static final long serialVersionUID = 1288380309936848376L; @Override public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params) { if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn) || dataTable.isDateTime(colorColumn)) { drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7), dataTable, colorColumn, minColor, maxColor); return new BlockResult(); } else { final String minColorString = Tools.formatNumber(minColor); final String maxColorString = Tools.formatNumber(maxColor); drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90), (int) (area.getCenterY() + 7), dataTable.getColumnName(colorColumn), minColorString, maxColorString); return new BlockResult(); } } @Override public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) { draw(g2, area, null); } }); } } // GENERAL CHART SETTINGS // set the background colors for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getPlot().setForegroundAlpha(0.7f); XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (axis[X_AXIS] >= 0) { if (dataTable.isNominal(axis[X_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[X_AXIS], i); } plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values)); } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { if (logScales[X_AXIS]) { LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setDomainAxis(domainAxis); } else { plot.setDomainAxis(new NumberAxis(dataTable.getColumnName(axis[X_AXIS]))); } } Range range = getRangeForDimension(axis[X_AXIS]); if (range != null) { plot.getDomainAxis().setRange(range, true, false); } else { plot.getDomainAxis().setAutoRange(true); } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } // range axis if (axis[Y_AXIS] >= 0) { if (dataTable.isNominal(axis[Y_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[Y_AXIS], i); } plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values)); } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) { DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setRangeAxis(rangeAxis); } else { plot.setRangeAxis(new NumberAxis(dataTable.getColumnName(axis[Y_AXIS]))); } Range range = getRangeForDimension(axis[Y_AXIS]); if (range != null) { plot.getRangeAxis().setRange(range, true, false); } else { plot.getRangeAxis().setAutoRange(true); } } plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); AbstractChartPanel panel = getPlotterPanel(); // Chart Panel Settings if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
/** * Draws the label for one radar axis./*from w w w .ja v a 2 s. com*/ * * @param g2 The graphics device. * @param chartArea The area for the radar chart. * @param data The data for the plot. * @param axis The axis (zero-based index). * @param startAngle The starting angle. */ protected void drawLabel(Graphics2D g2, Rectangle2D chartArea, String label, int axis, double labelX, double labelY) { // handle label drawing... FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D labelBounds = this.axisLabelFont.getStringBounds(label, frc); LineMetrics lm = this.axisLabelFont.getLineMetrics(label, frc); double ascent = lm.getAscent(); if (labelX == chartArea.getCenterX()) labelX -= labelBounds.getWidth() / 2; else if (labelX < chartArea.getCenterX()) labelX -= labelBounds.getWidth(); if (labelY > chartArea.getCenterY()) labelY += ascent; g2.setPaint(this.axisLabelPaint); g2.setFont(this.axisLabelFont); g2.drawString(label, (float) labelX, (float) labelY); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void zoom(Rectangle2D selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D( new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = getChartRenderingInfo().getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) { double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight(); double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight(); Plot p = getChart().getPlot();// w w w .jav a 2s . c o m if (p instanceof LinkAndBrushPlot) { PlotOrientation orientation = null; if (p instanceof XYPlot) { XYPlot xyPlot = (XYPlot) p; orientation = xyPlot.getOrientation(); } if (p instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) p; orientation = categoryPlot.getOrientation(); } // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = p.isNotify(); p.setNotify(false); LinkAndBrushPlot LABPlot = (LinkAndBrushPlot) p; List<Pair<Integer, Range>> zoomedDomainAxisRanges = new LinkedList<Pair<Integer, Range>>(); List<Pair<Integer, Range>> zoomedRangeAxisRanges = new LinkedList<Pair<Integer, Range>>(); if (orientation == PlotOrientation.HORIZONTAL) { zoomedDomainAxisRanges .addAll(LABPlot.calculateDomainAxesZoom(vLower, vUpper, zoomOnLinkAndBrushSelection)); zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(hLower, hUpper, plotInfo, selectOrigin, zoomOnLinkAndBrushSelection)); } else { zoomedDomainAxisRanges .addAll(LABPlot.calculateDomainAxesZoom(hLower, hUpper, zoomOnLinkAndBrushSelection)); zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(vLower, vUpper, plotInfo, selectOrigin, zoomOnLinkAndBrushSelection)); } p.setNotify(savedNotify); if (zoomOnLinkAndBrushSelection) { informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.ZOOM_IN, zoomedDomainAxisRanges, zoomedRangeAxisRanges)); } else { informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.SELECTION, zoomedDomainAxisRanges, zoomedRangeAxisRanges)); } } else { super.zoom(selection); } } }
From source file:edu.cuny.cat.ui.ClockPanel.java
@Override public void setup(final ParameterDatabase parameters, final Parameter base) { clock = GameController.getInstance().getClock(); dataset = new DefaultValueDataset(); meterplot = new MyMeterPlot(dataset) { /**/* w w w . j av a 2 s . co m*/ * */ private static final long serialVersionUID = 1L; @Override protected void drawValueLabel(final Graphics2D g2, final Rectangle2D area) { g2.setFont(getValueFont()); g2.setPaint(getValuePaint()); String valueStr = "No value"; if (dataset != null) { final Number n = dataset.getValue(); if (n != null) { if (n.intValue() == 0) { valueStr = "to start"; } else if (n.intValue() == clock.getGameLen() * clock.getDayLen()) { valueStr = "done"; } else { valueStr = "day " + (n.intValue() / clock.getDayLen()) + ", round " + (n.intValue() % clock.getDayLen()); } } } final float x = (float) area.getCenterX(); final float y = (float) area.getCenterY() + MeterPlot.DEFAULT_CIRCLE_SIZE; TextUtilities.drawAlignedString(valueStr, g2, x, y, TextAnchor.TOP_CENTER); } }; meterplot.setRange(new Range(0, clock.getDayLen() * clock.getGameLen())); meterplot.setNeedlePaint( parameters.getColorWithDefault(base.push(ClockPanel.P_NEEDLE), null, Color.darkGray)); meterplot.setDialBackgroundPaint(new Color(0, 255, 0, 64)); meterplot.setDialOutlinePaint(Color.gray); meterplot.setDialShape(DialShape.CHORD); meterplot.setMeterAngle(parameters.getIntWithDefault(base.push(ClockPanel.P_ANGLE), null, 260)); meterplot.setTickLabelsVisible(true); meterplot.setTickLabelFont(new Font("Dialog", 1, 10)); meterplot.setTickLabelPaint(Color.darkGray); meterplot.setTickSize(clock.getDayLen()); meterplot.setTickPaint(Color.lightGray); meterplot.setValuePaint(Color.black); meterplot.setValueFont(new Font("Dialog", 1, 14)); meterplot.setUnits(""); meterplot.setTickLabelFormat(new NumberFormat() { /** * */ private static final long serialVersionUID = 1L; @Override public StringBuffer format(final double number, final StringBuffer toAppendTo, final FieldPosition pos) { return format((long) number, toAppendTo, pos); } @Override public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) { if (number % clock.getDayLen() == 0) { toAppendTo.append(String.valueOf(number / clock.getDayLen())); } return toAppendTo; } @Override public Number parse(final String source, final ParsePosition parsePosition) { return null; } }); final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, meterplot, false); final ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(parameters.getIntWithDefault(base.push(ClockPanel.P_WIDTH), null, 200), parameters.getIntWithDefault(base.push(ClockPanel.P_HEIGHT), null, 200))); add(panel, BorderLayout.CENTER); initIterationLabel(); initScoreReport(); }
From source file:com.rapidminer.gui.plotter.charts.Abstract2DChartPlotter.java
@Override public void updatePlotter() { prepareData();/*w w w. j ava2 s . c om*/ JFreeChart chart; if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0) { if (nominal) { int size = dataSet.getSeriesCount(); chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation colorColumn >= 0 && size < 100 ? true : false, // include legend true, // tooltips false // URLs ); // renderer settings try { chart.getXYPlot().setRenderer(getItemRenderer(nominal, size, this.minColor, this.maxColor)); } catch (Exception e) { // do nothing } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); LabelBlock title = new LabelBlock(getDataTable().getColumnName(colorColumn), new Font("SansSerif", Font.BOLD, 12)); title.setPadding(0, 5, 5, 5); wrapper.add(title, RectangleEdge.LEFT); BlockContainer items = legend.getItemContainer(); wrapper.add(items, RectangleEdge.RIGHT); legend.setWrapper(wrapper); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); // renderer settings try { chart.getXYPlot().setRenderer(getItemRenderer(nominal, -1, minColor, maxColor)); } catch (Exception e) { // do nothing } LegendTitle legendTitle = new LegendTitle(chart.getXYPlot().getRenderer()) { private static final long serialVersionUID = 1288380309936848376L; @Override public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params) { if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn) || dataTable.isDateTime(colorColumn)) { drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7), dataTable, colorColumn, minColor, maxColor); return new BlockResult(); } else { final String minColorString = Tools.formatNumber(minColor); final String maxColorString = Tools.formatNumber(maxColor); drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 75), (int) (area.getCenterY() + 7), getDataTable().getColumnName(colorColumn), minColorString, maxColorString); return new BlockResult(); } } @Override public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) { draw(g2, area, null); } }; BlockContainer wrapper = new BlockContainer(new BorderArrangement()); LabelBlock title = new LabelBlock(getDataTable().getColumnName(colorColumn), new Font("SansSerif", Font.BOLD, 12)); title.setPadding(0, 5, 5, 5); wrapper.add(title, RectangleEdge.LEFT); BlockContainer items = legendTitle.getItemContainer(); wrapper.add(items, RectangleEdge.RIGHT); legendTitle.setWrapper(wrapper); chart.addLegend(legendTitle); } } else { chart = ChartFactory.createScatterPlot(null, // chart title null, // domain axis label null, // range axis label dataSet, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // URLs ); } // GENERAL CHART SETTINGS // set the background colors for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(false); // general plot settings XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (axis[X_AXIS] >= 0) { if (dataTable.isNominal(axis[X_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[X_AXIS], i); } plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values)); } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { if (logScales[X_AXIS]) { LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setDomainAxis(domainAxis); } else { NumberAxis domainAxis = new NumberAxis(dataTable.getColumnName(axis[X_AXIS])); domainAxis.setAutoRangeStickyZero(false); domainAxis.setAutoRangeIncludesZero(false); plot.setDomainAxis(domainAxis); } } } if (axis[X_AXIS] >= 0) { Range range = getRangeForDimension(axis[X_AXIS]); if (range != null) { plot.getDomainAxis().setRange(range, true, false); } else { plot.getDomainAxis().setAutoRange(true); } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } // range axis if (axis[Y_AXIS] >= 0) { if (dataTable.isNominal(axis[Y_AXIS])) { String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(axis[Y_AXIS], i); } plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values)); } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) { DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setTimeZone(Tools.getPreferredTimeZone()); plot.setRangeAxis(rangeAxis); } else { if (logScales[Y_AXIS]) { LogAxis rangeAxis = new LogAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); plot.setRangeAxis(rangeAxis); } else { NumberAxis rangeAxis = new NumberAxis(dataTable.getColumnName(axis[Y_AXIS])); rangeAxis.setAutoRangeStickyZero(false); rangeAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(rangeAxis); } } } plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); if (axis[Y_AXIS] >= 0) { Range range = getRangeForDimension(axis[Y_AXIS]); if (range != null) { plot.getRangeAxis().setRange(range, true, false); } else { plot.getRangeAxis().setAutoRange(true); } } // Chart Panel Settings AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); // react to mouse clicks panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { if (e.getTrigger().getClickCount() > 1) { if (e.getEntity() instanceof XYItemEntity) { XYItemEntity entity = (XYItemEntity) e.getEntity(); if (entity != null) { String id = idMap.get(new SeriesAndItem(entity.getSeriesIndex(), entity.getItem())); if (id != null) { ObjectVisualizer visualizer = ObjectVisualizerService .getVisualizerForObject(dataTable); visualizer.startVisualization(id); } } } } } @Override public void chartMouseMoved(ChartMouseEvent e) { } }); } else { panel.setChart(chart); } // tooltips class CustomXYToolTipGenerator implements XYToolTipGenerator { public CustomXYToolTipGenerator() { } private String formatValue(int axis, double value) { if (dataTable.isNominal(axis)) { // TODO add mapping of value to nominal value return Tools.formatIntegerIfPossible(value); } else if (dataTable.isNumerical(axis)) { return Tools.formatIntegerIfPossible(value); } else if (dataTable.isDate(axis)) { return Tools.createDateAndFormat(value); } else if (dataTable.isTime(axis)) { return Tools.createTimeAndFormat(value); } else if (dataTable.isDateTime(axis)) { return Tools.createDateTimeAndFormat(value); } return "?"; } @Override public String generateToolTip(XYDataset dataset, int row, int column) { String id = idMap.get(new SeriesAndItem(row, column)); if (id != null) { return "<html><b>Id: " + id + "</b> (" + dataset.getSeriesKey(row) + ", " + formatValue(axis[X_AXIS], dataset.getXValue(row, column)) + ", " + formatValue(axis[Y_AXIS], dataset.getYValue(row, column)) + ")</html>"; } else { return "<html>(" + dataset.getSeriesKey(row) + ", " + formatValue(axis[X_AXIS], dataset.getXValue(row, column)) + ", " + formatValue(axis[Y_AXIS], dataset.getYValue(row, column)) + ")</html>"; } } } for (int i = 0; i < dataSet.getSeriesCount(); i++) { plot.getRenderer().setSeriesToolTipGenerator(i, new CustomXYToolTipGenerator()); } }
From source file:net.sf.maltcms.chromaui.charts.renderer.XYNoBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device./*from ww w . j av a2 s . c om*/ * @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) { // return; double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { z = ((XYZDataset) dataset).getZValue(series, item); if (entityThreshold != Double.NaN && z < entityThreshold) { return; } } //} Paint p = getPaintScale().getPaint(z); // if(p.equals(getPaintScale().getPaint(getPaintScale().getLowerBound()))) { // return; // } // double xx0 = domainAxis.valueToJava2D(x + xOffset, dataArea, // plot.getDomainAxisEdge()); // double yy0 = rangeAxis.valueToJava2D(y + yOffset, dataArea, // plot.getRangeAxisEdge()); // double xx1 = domainAxis.valueToJava2D(x + blockWidth // + xOffset, dataArea, plot.getDomainAxisEdge()); // double yy1 = rangeAxis.valueToJava2D(y + blockHeight // + yOffset, dataArea, plot.getRangeAxisEdge()); double xx0 = domainAxis.valueToJava2D(x - getBlockWidth() / 2, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y - getBlockHeight() / 2, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + getBlockWidth() / 2, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + getBlockHeight() / 2, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { if (dataArea.contains(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1))) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { return; } } else { if (dataArea.contains(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy0 - yy1))) { block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy0 - yy1)); } else { return; } } g2.setPaint(p); g2.fill(block); g2.setStroke(new BasicStroke(1.0f)); g2.draw(block); EntityCollection entities = state.getEntityCollection(); // System.out.println("Entity collection is of type: "+entities.getClass()); if (entities != null) { //System.out.println("Adding entity"); addEntity(entities, block, dataset, series, item, block.getCenterX(), block.getCenterY()); } }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialPointer.java
/** * Draws the pointer./*w w w . ja v a2 s . c o m*/ * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view. */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setStroke(new BasicStroke(1.0f)); Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius()); Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius()); double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale); DialScale scale = plot.getScaleForDataset(this.getDatasetIndex()); double angle = scale.valueToAngle(value); Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN); Point2D pt1 = arc1.getEndPoint(); Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN); Point2D pt2 = arc2.getStartPoint(); Point2D pt3 = arc2.getEndPoint(); Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN); Point2D pt4 = arc3.getStartPoint(); GeneralPath gp = new GeneralPath(); gp.moveTo((float) pt1.getX(), (float) pt1.getY()); gp.lineTo((float) pt2.getX(), (float) pt2.getY()); gp.lineTo((float) pt4.getX(), (float) pt4.getY()); gp.lineTo((float) pt3.getX(), (float) pt3.getY()); gp.closePath(); g2.setPaint(this.fillPaint); g2.fill(gp); g2.setPaint(this.getOutlinePaint()); Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY()); // g2.draw(line); line.setLine(pt2, pt3); g2.draw(line); line.setLine(pt3, pt1); g2.draw(line); line.setLine(pt2, pt1); g2.draw(line); line.setLine(pt2, pt4); g2.draw(line); line.setLine(pt3, pt4); g2.draw(line); }