List of usage examples for org.jfree.chart.entity EntityCollection add
public void add(ChartEntity entity);
From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java
/** * Draws the tasks/subtasks for one item. * //from w ww .j ava 2 s. co m * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) { int count = dataset.getSubIntervalCount(row, column); if (count == 0 && getItemVisible(row, column)) { drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column); } for (int subinterval = 0; subinterval < count; subinterval++) { RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // value 0 Number value0 = dataset.getStartValue(row, column, subinterval); if (value0 == null) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // value 1 Number value1 = dataset.getEndValue(row, column, subinterval); if (value1 == null) { return; } double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (translatedValue1 < translatedValue0) { double temp = translatedValue1; translatedValue1 = translatedValue0; translatedValue0 = temp; } double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row, column); double rectLength = Math.abs(translatedValue1 - translatedValue0); double rectBreadth = state.getBarWidth(); // DRAW THE BARS... Rectangle2D bar = null; if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth); } else if (plot.getOrientation() == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(rectStart, translatedValue0, rectBreadth, rectLength); } Rectangle2D completeBar = null; Rectangle2D incompleteBar = null; Number percent = dataset.getPercentComplete(row, column, subinterval); double start = getStartPercent(); double end = getEndPercent(); if (percent != null) { double p = percent.doubleValue(); if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { completeBar = new Rectangle2D.Double(translatedValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start)); incompleteBar = new Rectangle2D.Double(translatedValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start)); } else if (plot.getOrientation() == PlotOrientation.VERTICAL) { completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, translatedValue0 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p); incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, translatedValue0, rectBreadth * (end - start), rectLength * (1 - p)); } } Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (getToolTipGenerator(row, column) != null) { tip = getToolTipGenerator(row, column).generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } } }
From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java
/** * Draws a single task.//from w w w .j a v a 2 s. co m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // Y0 Number value0 = dataset.getEndValue(row, column); if (value0 == null) { return; } double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // Y1 Number value1 = dataset.getStartValue(row, column); if (value1 == null) { return; } double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; Number tempNum = value1; value1 = value0; value0 = tempNum; } // count the number of non-null values int totalBars = countNonNullValues(dataset, column); if (totalBars == 0) { return; } // count non-null values up to but not including the current value int priorBars = countPriorNonNullValues(dataset, column, row); // double rectStart = calculateBarW0(plot, orientation, dataArea, // domainAxis, state, row, column); // double rectBreadth = state.getBarWidth(); double rectBreadth = (domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())) / totalBars; double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) + rectBreadth * priorBars; double rectLength = Math.abs(java2dValue1 - java2dValue0); Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth); } else if (orientation == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength); } Rectangle2D completeBar = null; Rectangle2D incompleteBar = null; Number percent = dataset.getPercentComplete(row, column); double start = getStartPercent(); double end = getEndPercent(); if (percent != null) { double p = percent.doubleValue(); if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start)); incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start)); } else if (plot.getOrientation() == PlotOrientation.VERTICAL) { completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p); incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p)); } } Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } // draw the outline... if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, false); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:org.mwc.debrief.sensorfusion.views.FusionPlotRenderer.java
/** note: this method has been generated to correct the mistaken JFreeChart * implementation that breaks whtn in PlotOrientation.Horizontal. *//*from ww w. j a va 2s .c o m*/ protected void addEntity(final EntityCollection entities, final Shape area, final XYDataset dataset, final int series, final int item, final double entityX, final double entityY) { if (!getItemCreateEntity(series, item)) { return; } Shape hotspot = area; if (hotspot == null) { final double r = getDefaultEntityRadius(); final double w = r * 2; // NOTE: the JFreeChart problem is in the next line, it tries // to switch the X & Y when in horizontal mode, but the X and Y // values have already been transposed. hotspot = new Ellipse2D.Double(entityX - r, entityY - r, w, w); } 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(hotspot, dataset, series, item, tip, url); entities.add(entity); }
From source file:umontreal.iro.lecuyer.charts.EmpiricalRenderer.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 axis.//from w w w . j a v a 2 s .co m * @param rangeAxis the range 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. */ 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; PlotOrientation orientation = plot.getOrientation(); java.awt.Paint seriesPaint = getItemPaint(series, item); java.awt.Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(seriesPaint); g2.setStroke(seriesStroke); double x0 = dataset.getXValue(series, item); double y0 = dataset.getYValue(series, item); if (java.lang.Double.isNaN(y0)) return; org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double x1 = 0, y1 = 0; if (item < dataset.getItemCount(series) - 1) { x1 = dataset.getXValue(series, item + 1); y1 = dataset.getYValue(series, item + 1); } else { x1 = dataArea.getMaxX(); y1 = dataArea.getMaxY(); } boolean useFillPaint = getUseFillPaint(); ; boolean drawOutlines = getDrawOutlines(); if (!java.lang.Double.isNaN(y0)) { double transX1; double transY1; if (item < dataset.getItemCount(series) - 1) { transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); } else { transX1 = x1; transY1 = y1; } Line2D line = state.workingLine; if (orientation == PlotOrientation.HORIZONTAL) { line.setLine(transY0, transX0, transY0, transX1); g2.draw(line); } else if (orientation == PlotOrientation.VERTICAL) { line.setLine(transX0, transY0, transX1, transY0); g2.draw(line); } } if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0); else if (orientation == PlotOrientation.VERTICAL) shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0); if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (useFillPaint) g2.setPaint(getItemFillPaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.fill(shape); } if (drawOutlines) { if (getUseOutlinePaint()) g2.setPaint(getItemOutlinePaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } if (isItemLabelVisible(series, item)) { double xx = transX0; double yy = transY0; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY0; yy = transX0; } drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0, orientation); if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { int r = getDefaultEntityRadius(); java.awt.Shape shape = orientation != PlotOrientation.VERTICAL ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r, transX0 - (double) r, 2 * r, 2 * r))) : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r, transY0 - (double) r, 2 * r, 2 * r))); if (shape != 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(shape, dataset, series, item, tip, url); entities.add(entity); } } } }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.renderer.HierarchicalBarRenderer.java
/** * Draws the bar for one item in the dataset. * * @param g2/* ww w . j a v a 2 s . com*/ * the graphics device. * @param state * the renderer state. * @param dataArea * the plot area. * @param plot * the plot. * @param domainAxis * the domain (category) axis. * @param rangeAxis * the range (value) axis. * @param data * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = data.getValue(row, column); if (dataValue == null) { return; } // BAR X double rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); int seriesCount = this.getRowCount(); // BAR Y double value = dataValue.doubleValue(); double base = 0.0; double lclip = this.getLowerClip(); double uclip = this.getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = this.getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge edge = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); double rectY = Math.min(transY2, transY1); double rectWidth = state.getBarWidth(); double rectHeight = Math.abs(transY2 - transY1); // draw the bar... double shift = 0.0; rectWidth = 0.0; double widthFactor = 1.0; double seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - ((seriesCount - 1 - row) * shift * 2)), rectHeight); double rrX; double rrY; double rrW; double rrH; if (row == 0) { @SuppressWarnings("unchecked") Iterator it = this.datasetTree[column].getDescendants(); int numElement = -1; while (it.hasNext()) { try { Element elt = (Element) it.next(); numElement++; String name = elt.getAttributeValue("name"); dataValue = Double.valueOf(elt.getAttributeValue("avg")); // System.out.println("["+column+"] "+name+" \t--> // "+dataValue); // BAR X rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); seriesCount = this.getRowCount(); // BAR Y value = dataValue.doubleValue(); base = 0.0; lclip = this.getLowerClip(); uclip = this.getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = this.getLowerClip(); if (value >= uclip) { value = uclip; } } edge = plot.getRangeAxisEdge(); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); rectY = Math.min(transY2, transY1); rectWidth = state.getBarWidth(); rectHeight = Math.abs(transY2 - transY1); // draw the bar... shift = 0.0; rectWidth = 0.0; widthFactor = 1.0; seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } rrX = (rectX + ((seriesCount - 1 - row) * shift)); rrY = rectY; rrW = (rectWidth - ((seriesCount - 1 - row) * shift * 2)); rrH = rectHeight; // IMPORTANT NOTE : // dev attribute is used to save width of the element // min attribute is used to save X position of the element // max attribute is used to save the number of child already // managed if (numElement == 0) { elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); elt.setAttribute("max", "0"); } else { Element parent = elt.getParentElement(); // System.out.println(" Parent // "+parent.getAttributeValue("name") // + " rrX/rrW/child -> " // + parent.getAttributeValue("min")+"/" // + parent.getAttributeValue("dev")+"/" // + parent.getAttributeValue("max") ); double pW = Double.valueOf(parent.getAttributeValue("dev")); double pX = Double.valueOf(parent.getAttributeValue("min")); int numChild = Integer.valueOf(parent.getAttributeValue("max")); rrW = pW / parent.getChildren().size(); rrX = pX + (rrW * numChild); rrX += HierarchicalBarRenderer.INCLUSION_MARGIN; rrW -= (HierarchicalBarRenderer.INCLUSION_MARGIN * 2); elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); parent.setAttribute("max", "" + (numChild + 1)); } RoundRectangle2D rbar = new RoundRectangle2D.Double(rrX, rrY, rrW, rrH, HierarchicalBarRenderer.CORNER, HierarchicalBarRenderer.CORNER); Rectangle2D childSumLine = null; double childSum = Double.valueOf(elt.getAttributeValue("sum")); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(childSum, dataArea, edge); rectY = Math.min(transY2, transY1); childSum = (childSum / dataValue.doubleValue()) * rrH; if ((childSum < rrH) && (childSum > 0) && ((childSum / rrH) < 0.95)) { childSumLine = new Rectangle2D.Double(rrX, rectY, rrW, 1); } Paint itemPaint = this.getItemPaintFromName(name, this.series, column); GradientPaintTransformer t = this.getGradientPaintTransformer(); if ((t != null) && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); Color c = g2.getColor(); g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), this.alpha)); g2.fill(rbar); g2.setColor(Color.DARK_GRAY); if (childSumLine != null) { g2.fill(childSumLine); } // draw the outline... if (this.isDrawBarOutline() && (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD)) { Stroke stroke = this.getItemOutlineStroke(row, column); Paint paint = this.getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(rbar); } } } catch (ClassCastException e) { continue; } } } // //////////////////////////// // draw the item labels if there are any... double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge); CategoryItemLabelGenerator generator = this.getItemLabelGenerator(row, column); if ((generator != null) && this.isItemLabelVisible(row, column)) { this.drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = this.getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(data, row, column); } String url = null; if (this.getItemURLGenerator(row, column) != null) { url = this.getItemURLGenerator(row, column).generateURL(data, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, data, row, data.getColumnKey(column), column); entities.add(entity); } } }
From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a horizontal orientation.//www.j a va 2s . c om * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot 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 row the row index (zero-based). * @param column the column index (zero-based). */ public void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = Math.abs(categoryEnd - categoryStart); double yy = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; yy = yy + offset + (row * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than // the category width double offset = (categoryWidth - state.getBarWidth()) / 2; yy = yy + offset; } Paint p = getItemPaint(row, column); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Number xQ1 = bawDataset.getQ1Value(row, column); Number xQ3 = bawDataset.getQ3Value(row, column); Number xMax = bawDataset.getMaxRegularValue(row, column); Number xMin = bawDataset.getMinRegularValue(row, column); Shape box = null; if (xQ1 != null && xQ3 != null && xMax != null && xMin != null) { double xxQ1 = rangeAxis.valueToJava2D(xQ1.doubleValue(), dataArea, location); double xxQ3 = rangeAxis.valueToJava2D(xQ3.doubleValue(), dataArea, location); double xxMax = rangeAxis.valueToJava2D(xMax.doubleValue(), dataArea, location); double xxMin = rangeAxis.valueToJava2D(xMin.doubleValue(), dataArea, location); double yymid = yy + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxMax, yymid, xxQ3, yymid)); g2.draw(new Line2D.Double(xxMax, yy, xxMax, yy + state.getBarWidth())); // draw the lower shadow... g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid)); g2.draw(new Line2D.Double(xxMin, yy, xxMin, yy + state.getBarWidth())); // draw the box... box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), state.getBarWidth()); if (this.fillBox) { g2.fill(box); } g2.draw(box); } g2.setPaint(this.artifactPaint); double aRadius = 0; // average radius // draw mean - SPECIAL AIMS REQUIREMENT... Number xMean = bawDataset.getMeanValue(row, column); if (xMean != null) { double xxMean = rangeAxis.valueToJava2D(xMean.doubleValue(), dataArea, location); aRadius = state.getBarWidth() / 4; Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxMean - aRadius, yy + aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } // draw median... Number xMedian = bawDataset.getMedianValue(row, column); if (xMedian != null) { double xxMedian = rangeAxis.valueToJava2D(xMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + state.getBarWidth())); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(box, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.BoxAndWhiskerCoinPlotRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a vertical orientation./*from w w w .ja v a2s . c om*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot 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 row the row index (zero-based). * @param column the column index (zero-based). */ public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; xx = xx + offset + (row * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than the // category width double offset = (categoryWidth - state.getBarWidth()) / 2; xx = xx + offset; } double yyAverage = 0.0; double yyOutlier; // bar colors are determined by the Paint p obtained here in a rotational //manner (from a Color array). By switching the column and raw values, //you can get a different color pattern for the bar: In the method //getItemPaint(), only the first argument counts for the color. The original //code Paint p = getItemPaint(row, column); is commented out for a difference. Paint p = null; if (this.getPlotColor() != null) { p = PaintUtilities.stringToColor(getPlotColor()); // coin plot should all be one color } else { p = getItemPaint(row, column); } // Paint p = PaintUtilities.stringToColor("red"); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = plot.getRangeAxisEdge(); Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); Shape box = null; if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) { double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location); double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location); double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location); double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location); double xxmid = xx + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower shadow... g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin)); // draw the body... box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3)); if (getFillBox()) { g2.fill(box); } g2.draw(box); } g2.setPaint(getArtifactPaint()); if (this.isDisplayMean()) { // draw mean - SPECIAL AIMS REQUIREMENT... Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); aRadius = state.getBarWidth() / 4; Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } } if (this.isDisplayMedian()) { // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } } // draw yOutliers... double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius; double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius; g2.setPaint(p); if (this.isDisplayCoinCloud()) { //draw coin clouds drawCoinCloud(g2, state, dataArea, location, rangeAxis, xx, row, column, bawDataset); } //caIntegrator: oRadius is the radius of the outlier circles. It was used to be 3. // draw outliers double oRadius = state.getBarWidth() / this.outlierRadiusDenominator; // outlier radius List outliers = new ArrayList(); OutlierListCollection outlierListCollection = new OutlierListCollection(); List yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { double outlier = ((Number) yOutliers.get(i)).doubleValue(); Number minOutlier = bawDataset.getMinOutlier(row, column); Number maxOutlier = bawDataset.getMaxOutlier(row, column); Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); if (outlier > maxOutlier.doubleValue()) { outlierListCollection.setHighFarOut(true); } else if (outlier < minOutlier.doubleValue()) { outlierListCollection.setLowFarOut(true); } else if (outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } else if (outlier < minRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } Collections.sort(outliers); } //display farouts as JFreeChart Implemetation if (!displayAllOutliers) { // Process outliers. Each outlier is either added to the // appropriate outlier list or a new outlier list is made for (int i = 0; i < yOutliers.size(); i++) { Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); double outlier = ((Number) yOutliers.get(i)).doubleValue(); if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } } for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); outlierListCollection.add(outlier); } for (Iterator iterator = outlierListCollection.iterator(); iterator.hasNext();) { OutlierList list = (OutlierList) iterator.next(); Outlier outlier = list.getAveragedOutlier(); Point2D point = outlier.getPoint(); if (list.isMultiple()) { drawMultipleEllipse(point, state.getBarWidth(), oRadius, g2); } else { drawEllipse(point, oRadius, g2); } } // draw farout indicators if (outlierListCollection.isHighFarOut()) { drawHighFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, maxAxisValue); } if (outlierListCollection.isLowFarOut()) { drawLowFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, minAxisValue); } } else { for (int i = 0; i < yOutliers.size(); i++) { Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); double outlier = ((Number) yOutliers.get(i)).doubleValue(); if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } } Collections.sort(outliers); for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); drawEllipse(point, oRadius, g2); } } } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(box, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:net.sf.maltcms.chromaui.charts.renderer.XYNoBlockRenderer.java
@Override protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) { if (!getItemCreateEntity(series, item)) { return;// ww w .j ava2s .com } Shape hotspot = area; if (hotspot == null) { double r = getDefaultEntityRadius(); double w = r * 2; if (getPlot().getOrientation() == PlotOrientation.VERTICAL) { hotspot = new Ellipse2D.Double(entityX - r, entityY - r, w, w); } else { hotspot = new Ellipse2D.Double(entityY - r, entityX - r, w, w); } } else if (hotspot.getBounds2D().getWidth() < 5.0 || hotspot.getBounds2D().getHeight() < 5.0) { if (getPlot().getOrientation() == PlotOrientation.VERTICAL) { hotspot = new Rectangle2D.Double(entityX - 2.5, entityY - 2.5, 5, 5); } else { hotspot = new Rectangle2D.Double(entityY - 2.5, entityX - 2.5, 5, 5); } } 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(hotspot, dataset, series, item, tip, url); entities.add(entity); }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawYIntervalPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; 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) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); }// w w w .jav a 2 s. c o m IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); 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(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null && line != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:com.att.aro.main.PacketPlots.java
/** * The utility method that creates the packet plots from a packet series map *///from w ww. j a va2 s . c o m private XYPlot createPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; 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) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); 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(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }