List of usage examples for org.jfree.chart.plot CategoryPlot getRangeAxisEdge
public RectangleEdge getRangeAxisEdge()
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param chartPanel// w w w .ja v a2 s . co m * @param category * @param y * @return */ public static AffineTransform getModelToViewTransformCategory(ChartPanel chartPanel, int category, double y) { double zoomX = chartPanel.getScaleX(); double zoomY = chartPanel.getScaleY(); Insets insets = chartPanel.getInsets(); AffineTransform at = getTranslateInstance(insets.left, insets.top); at.concatenate(getScaleInstance(zoomX, zoomY)); Plot plot = chartPanel.getChart().getPlot(); if (plot instanceof CategoryPlot) { CategoryPlot xyp = (CategoryPlot) plot; CategoryDataset cds = xyp.getDataset(); RectangleEdge xAxisLocation = xyp.getDomainAxisEdge(); RectangleEdge yAxisLocation = xyp.getRangeAxisEdge(); PlotOrientation orientation = xyp.getOrientation(); Comparable<?> categoryKey = cds.getColumnKey(category); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double transX = xyp.getDomainAxis().getCategoryMiddle(categoryKey, cds.getColumnKeys(), dataArea, xAxisLocation); double transY = xyp.getRangeAxis().valueToJava2D(y, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { double tmp = transX; transX = transY; transY = tmp; } at.concatenate(getTranslateInstance(transX, transY)); return at; } throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass()); }
From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
private RectangleEdge drawRectangles(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, ValueAxis rangeAxis, int row, int column, BoxAndWhiskerCategoryDataset bawDataset, double xx) { 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;/* w ww. j av a 2 s . c o m*/ 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); } return location; }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java
/** * Add the action listener to the graph. *//*from www . j av a 2 s. c o m*/ private void setAction() { gui.pnlGraph.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(final ChartMouseEvent e) { if (e.getEntity() instanceof PlotEntity) { Point2D p = gui.pnlGraph.translateScreenToJava2D(e.getTrigger().getPoint()); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); CategoryAxis catAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); double chartY = rangeAxis.java2DToValue(p.getX(), plotArea, rangeAxisEdge); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int categoryCount = categories.getColumnCount(); for (int i = 0; i < categoryCount; i++) { double catStart = catAxis.getCategoryStart(i, categoryCount, plotArea, domainAxisEdge); double catEnd = catAxis.getCategoryEnd(i, categoryCount, plotArea, domainAxisEdge); if (e.getTrigger().getY() >= catStart && e.getTrigger().getY() < catEnd) { new EditAvailabilityController(gui.function, gui.function.getWorkers().get(i), new Day(new Date((long) chartY)), parent); } } } else { CategoryItemEntity item = (CategoryItemEntity) e.getEntity(); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); DateAxis dateAxis = (DateAxis) plot.getRangeAxis(); double d = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX(), plotArea, rangeAxisEdge); double d2 = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX() + e.getEntity().getArea().getBounds2D().getWidth(), plotArea, rangeAxisEdge); Date startDate = new Date((long) d); Date endDate = new Date((long) d2); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int workerIndex = categories.getColumnIndex(item.getColumnKey()); Worker worker = gui.function.getWorkers().get(workerIndex); Set<Availability> found = CalendarService.getAllWorkerAvailability(worker.getId(), startDate, endDate); Availability foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { found = CalendarService.getProjectAvailability(startDate, endDate); foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { JOptionPane.showMessageDialog( new JFrame(LocalizedStrings.getGeneralStrings().warning()), LocalizedStrings.getErrorMessages().availabilityCanNotBeChanged()); } } } } @Override public void chartMouseMoved(final ChartMouseEvent arg0) { } }); /** * ActionListener */ gui.btnNext.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.increment(); } }); /** * ActionListener */ gui.btnPrev.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.decrement(); } }); for (int i = 0; i < gui.buttons.length; i++) { addButtonListener(i); } /** * ActionListener */ gui.btnManualAv.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { gui.function.setManualAv(true); } else { gui.function.setManualAv(false); } } }); }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
private double calculateItemYPoint(CategoryPlot plot, ValueAxis rangeAxis, Rectangle2D dataArea, double value) { return rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); }
From source file:org.jfree.chart.demo.GanttRenderer2.java
protected void drawTask(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, GanttCategoryDataset ganttcategorydataset, int i, int j) { PlotOrientation plotorientation = categoryplot.getOrientation(); org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); Number number = ganttcategorydataset.getEndValue(i, j); if (number == null) return;/*from w ww . ja v a 2 s. c o m*/ double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge); Number number1 = ganttcategorydataset.getStartValue(i, j); if (number1 == null) return; double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge); if (d1 < d) { double d2 = d1; d1 = d; d = d2; Number number2 = number1; number1 = number; number = number2; } int k = countNonNullValues(ganttcategorydataset, j); if (k == 0) return; int l = countPriorNonNullValues(ganttcategorydataset, j, i); double d3 = (categoryaxis.getCategoryEnd(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()) - categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge())) / (double) k; double d4 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()) + d3 * (double) l; double d5 = Math.abs(d1 - d); java.awt.geom.Rectangle2D.Double double1 = null; if (plotorientation == PlotOrientation.HORIZONTAL) double1 = new java.awt.geom.Rectangle2D.Double(d, d4, d5, d3); else if (plotorientation == PlotOrientation.VERTICAL) double1 = new java.awt.geom.Rectangle2D.Double(d4, d1, d3, d5); java.awt.geom.Rectangle2D.Double double2 = null; java.awt.geom.Rectangle2D.Double double3 = null; Number number3 = ganttcategorydataset.getPercentComplete(i, j); double d6 = getStartPercent(); double d7 = getEndPercent(); if (number3 != null) { double d8 = number3.doubleValue(); if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) { double2 = new java.awt.geom.Rectangle2D.Double(d, d4 + d6 * d3, d5 * d8, d3 * (d7 - d6)); double3 = new java.awt.geom.Rectangle2D.Double(d + d5 * d8, d4 + d6 * d3, d5 * (1.0D - d8), d3 * (d7 - d6)); } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) { double2 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1 + d5 * (1.0D - d8), d3 * (d7 - d6), d5 * d8); double3 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1, d3 * (d7 - d6), d5 * (1.0D - d8)); } } Paint paint = getItemPaint(i, j); graphics2d.setPaint(paint); graphics2d.fill(double1); if (double2 != null) { graphics2d.setPaint(getCompletePaint()); graphics2d.fill(double2); } if (double3 != null) { graphics2d.setPaint(getIncompletePaint()); graphics2d.fill(double3); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { java.awt.Stroke stroke = getItemOutlineStroke(i, j); Paint paint1 = getItemOutlinePaint(i, j); if (stroke != null && paint1 != null) { graphics2d.setStroke(stroke); graphics2d.setPaint(paint1); graphics2d.draw(double1); } } org.jfree.chart.labels.CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j); if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j)) drawItemLabel(graphics2d, ganttcategorydataset, i, j, categoryplot, categoryitemlabelgenerator, double1, false); if (categoryitemrendererstate.getInfo() != null) { EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection != null) { String s = null; CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j); if (categorytooltipgenerator != null) s = categorytooltipgenerator.generateToolTip(ganttcategorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset, ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } } }
From source file:org.operamasks.faces.render.graph.CurveAndShapeRenderer.java
private void drawSeriesCurve(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int series) { // do nothing if item is not visible if (!(getItemVisible(series, 0) && (getItemLineVisible(series, 0) || drawArea))) { return;// w w w . ja v a 2 s . c o m } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getColumnCount(); double[][] points = new double[itemCount][2]; int count = 0; // get data points for (int i = 0; i < itemCount; i++) { Number value = dataset.getValue(series, i); if (value != null) { points[count][0] = domainAxis.getCategoryMiddle(i, itemCount, dataArea, xAxisLocation); points[count][1] = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, yAxisLocation); count++; } } if (count < 2) { return; } // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getSeriesPaint(series); Stroke stroke = getSeriesStroke(series); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } if (getItemLineVisible(series, 0)) { g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); } }
From source file:org.ietr.preesm.mapper.ui.MyGanttRenderer.java
/** * Draws the tasks/subtasks for one item. * // w w w . j a v a2 s .com * @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). */ @Override 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) { 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... RoundRectangle2D bar = null; bar = new RoundRectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth, 10.0, 10.0); /* Paint seriesPaint = */getItemPaint(row, column); if (((TaskSeriesCollection) dataset).getSeriesCount() > 0) if (((TaskSeriesCollection) dataset).getSeries(0).getItemCount() > column) if (((TaskSeriesCollection) dataset).getSeries(0).get(column).getSubtaskCount() > subinterval) { g2.setPaint(getRandomBrightColor(((TaskSeriesCollection) dataset).getSeries(0).get(column) .getSubtask(subinterval).getDescription())); } g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // Displaying the tooltip inside the bar if enough space is // available if (getToolTipGenerator(row, column) != null) { // Getting the string to display String tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column); // Truncting the string if it is too long String subtip = ""; if (rectLength > 0) { double percent = (g2.getFontMetrics().getStringBounds(tip, g2).getWidth() + 10) / rectLength; if (percent > 1.0) { subtip = tip.substring(0, (int) (tip.length() / percent)); } else if (percent > 0) { subtip = tip; } // Setting font and color Font font = new Font("Garamond", Font.BOLD, 12); g2.setFont(font); g2.setColor(Color.WHITE); // Testing width and displaying if (!subtip.isEmpty()) { g2.drawString(subtip, (int) translatedValue0 + 5, (int) rectStart + g2.getFontMetrics().getHeight()); } } } // 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, subinterval, 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, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } } }
From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java
/** * Draws a single task.//w w w. j ava2 s . c om * * @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.jfree.chart.demo.GanttRenderer2.java
protected void drawTasks(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, GanttCategoryDataset ganttcategorydataset, int i, int j) { int k = ganttcategorydataset.getSubIntervalCount(i, j); if (k == 0)// w w w .j ava 2s . c om drawTask(graphics2d, categoryitemrendererstate, rectangle2d, categoryplot, categoryaxis, valueaxis, ganttcategorydataset, i, j); for (int l = 0; l < k; l++) { org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); Number number = ganttcategorydataset.getStartValue(i, j, l); if (number == null) return; double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge); Number number1 = ganttcategorydataset.getEndValue(i, j, l); if (number1 == null) return; double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge); if (d1 < d) { double d2 = d1; d1 = d; d = d2; } double d3 = calculateBarW0(categoryplot, categoryplot.getOrientation(), rectangle2d, categoryaxis, categoryitemrendererstate, i, j); double d4 = Math.abs(d1 - d); double d5 = categoryitemrendererstate.getBarWidth(); java.awt.geom.Rectangle2D.Double double1 = null; if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) double1 = new java.awt.geom.Rectangle2D.Double(d, d3, d4, d5); else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) double1 = new java.awt.geom.Rectangle2D.Double(d3, d, d5, d4); java.awt.geom.Rectangle2D.Double double2 = null; java.awt.geom.Rectangle2D.Double double3 = null; Number number2 = ganttcategorydataset.getPercentComplete(i, j, l); double d6 = getStartPercent(); double d7 = getEndPercent(); if (number2 != null) { double d8 = number2.doubleValue(); if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) { double2 = new java.awt.geom.Rectangle2D.Double(d, d3 + d6 * d5, d4 * d8, d5 * (d7 - d6)); double3 = new java.awt.geom.Rectangle2D.Double(d + d4 * d8, d3 + d6 * d5, d4 * (1.0D - d8), d5 * (d7 - d6)); } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) { double2 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d + d4 * (1.0D - d8), d5 * (d7 - d6), d4 * d8); double3 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d, d5 * (d7 - d6), d4 * (1.0D - d8)); } } Paint paint = getItemPaint(i, j); graphics2d.setPaint(paint); graphics2d.fill(double1); if (double2 != null) { graphics2d.setPaint(getCompletePaint()); graphics2d.fill(double2); } if (double3 != null) { graphics2d.setPaint(getIncompletePaint()); graphics2d.fill(double3); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { graphics2d.setStroke(getItemStroke(i, j)); graphics2d.setPaint(getItemOutlinePaint(i, j)); graphics2d.draw(double1); } if (categoryitemrendererstate.getInfo() == null) continue; EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection == null) continue; String s = null; if (getToolTipGenerator(i, j) != null) s = getToolTipGenerator(i, j).generateToolTip(ganttcategorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset, ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } }
From source file:edu.cuny.jfree.chart.renderer.category.IntervalListBarRenderer.java
/** * Draws a single interval.//from w w w . j av a 2s . c om * * @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 drawInterval(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final DefaultIntervalListCategoryDataset dataset, final int row, final int column) { final int seriesCount = getRowCount(); final int categoryCount = getColumnCount(); final PlotOrientation orientation = plot.getOrientation(); double rectX = 0.0; double rectY = 0.0; final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final List list = dataset.getList(row, column); if (list == null) { return; } Interval interval = null; for (int i = 0; i < list.size(); i++) { interval = (Interval) list.get(i); if (!interval.isMeaningful()) { continue; } // Y0 double java2dValue0 = rangeAxis.valueToJava2D(interval.low, dataArea, rangeAxisLocation); // Y1 double java2dValue1 = rangeAxis.valueToJava2D(interval.high, dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { final double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; } // BAR WIDTH double rectWidth = state.getBarWidth(); // BAR HEIGHT double rectHeight = Math.abs(java2dValue1 - java2dValue0); if (orientation == PlotOrientation.HORIZONTAL) { // BAR Y rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); if (seriesCount > 1) { final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + row * (state.getBarWidth() + seriesGap); } else { rectY = rectY + row * state.getBarWidth(); } rectX = java2dValue0; rectHeight = state.getBarWidth(); rectWidth = Math.abs(java2dValue1 - java2dValue0); } else if (orientation == PlotOrientation.VERTICAL) { // BAR X rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); if (seriesCount > 1) { final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectX = rectX + row * (state.getBarWidth() + seriesGap); } else { rectX = rectX + row * state.getBarWidth(); } rectY = java2dValue0; } final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); // draw the outline... if (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD) { final Stroke stroke = getItemOutlineStroke(row, column); final Paint paint = getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } final 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) { final EntityCollection entities = state.getInfo().getOwner().getEntityCollection(); if (entities != null) { String tip = null; final 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); } final CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } } }