use of org.jfree.chart.ChartRenderingInfo in project jfreechart-fx by jfree.
the class TooltipHandlerFX method getTooltipText.
/**
* Returns the tooltip text.
*
* @param canvas the canvas that is displaying the chart.
* @param x the x-coordinate of the mouse pointer.
* @param y the y-coordinate of the mouse pointer.
*
* @return String The tooltip text (possibly {@code null}).
*/
private String getTooltipText(ChartCanvas canvas, double x, double y) {
ChartRenderingInfo info = canvas.getRenderingInfo();
if (info == null) {
return null;
}
EntityCollection entities = info.getEntityCollection();
if (entities == null) {
return null;
}
ChartEntity entity = entities.getEntity(x, y);
if (entity == null) {
return null;
}
return entity.getToolTipText();
}
use of org.jfree.chart.ChartRenderingInfo in project jfreechart-fx by jfree.
the class ChartCanvas method draw.
/**
* Draws the content of the canvas and updates the
* {@code renderingInfo} attribute with the latest rendering
* information.
*/
public final void draw() {
GraphicsContext ctx = getGraphicsContext2D();
ctx.save();
double width = getWidth();
double height = getHeight();
if (width > 0 && height > 0) {
ctx.clearRect(0, 0, width, height);
this.info = new ChartRenderingInfo();
if (this.chart != null) {
this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info);
}
}
ctx.restore();
for (OverlayFX overlay : this.overlays) {
overlay.paintOverlay(g2, this);
}
this.anchor = null;
}
use of org.jfree.chart.ChartRenderingInfo in project hudson-2.x by hudson.
the class Graph method doMap.
/**
* Renders a clickable map.
*/
public void doMap(StaplerRequest req, StaplerResponse rsp) throws IOException {
if (req.checkIfModified(timestamp, rsp))
return;
String w = req.getParameter("width");
if (w == null)
w = String.valueOf(defaultW);
String h = req.getParameter("height");
if (h == null)
h = String.valueOf(defaultH);
ChartRenderingInfo info = new ChartRenderingInfo();
render(req, info);
rsp.setContentType("text/plain;charset=UTF-8");
rsp.getWriter().println(ChartUtilities.getImageMap("map", info));
}
use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.
the class ValueAxisTest method test3555275.
/**
* A test for bug 3555275 (where the fixed axis space is calculated
* incorrectly).
*/
@Test
public void test3555275() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setInsets(RectangleInsets.ZERO_INSETS);
plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
ValueAxis yAxis = plot.getRangeAxis();
yAxis.setFixedDimension(100.0);
BufferedImage image = new BufferedImage(500, 300, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
ChartRenderingInfo info = new ChartRenderingInfo();
chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
g2.dispose();
Rectangle2D rect = info.getPlotInfo().getDataArea();
double x = rect.getMinX();
assertEquals(100.0, x, 1.0);
}
use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.
the class MultiplePiePlot method draw.
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the state from the parent plot, if there is one.
* @param info collects info about the drawing.
*/
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
drawBackground(g2, area);
drawOutline(g2, area);
// check that there is some data to display...
if (DatasetUtilities.isEmptyOrNull(this.dataset)) {
drawNoDataMessage(g2, area);
return;
}
int pieCount;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
pieCount = this.dataset.getRowCount();
} else {
pieCount = this.dataset.getColumnCount();
}
// the columns variable is always >= rows
int displayCols = (int) Math.ceil(Math.sqrt(pieCount));
int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols);
// swap rows and columns to match plotArea shape
if (displayCols > displayRows && area.getWidth() < area.getHeight()) {
int temp = displayCols;
displayCols = displayRows;
displayRows = temp;
}
prefetchSectionPaints();
int x = (int) area.getX();
int y = (int) area.getY();
int width = ((int) area.getWidth()) / displayCols;
int height = ((int) area.getHeight()) / displayRows;
int row = 0;
int column = 0;
int diff = (displayRows * displayCols) - pieCount;
int xoffset = 0;
Rectangle rect = new Rectangle();
for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) {
rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height);
String title;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
title = this.dataset.getRowKey(pieIndex).toString();
} else {
title = this.dataset.getColumnKey(pieIndex).toString();
}
this.pieChart.setTitle(title);
PieDataset piedataset;
PieDataset dd = new CategoryToPieDataset(this.dataset, this.dataExtractOrder, pieIndex);
if (this.limit > 0.0) {
piedataset = DatasetUtilities.createConsolidatedPieDataset(dd, this.aggregatedItemsKey, this.limit);
} else {
piedataset = dd;
}
PiePlot piePlot = (PiePlot) this.pieChart.getPlot();
piePlot.setDataset(piedataset);
piePlot.setPieIndex(pieIndex);
// update the section colors to match the global colors...
for (int i = 0; i < piedataset.getItemCount(); i++) {
Comparable key = piedataset.getKey(i);
Paint p;
if (key.equals(this.aggregatedItemsKey)) {
p = this.aggregatedItemsPaint;
} else {
p = (Paint) this.sectionPaints.get(key);
}
piePlot.setSectionPaint(key, p);
}
ChartRenderingInfo subinfo = null;
if (info != null) {
subinfo = new ChartRenderingInfo();
}
this.pieChart.draw(g2, rect, subinfo);
if (info != null) {
assert subinfo != null;
info.getOwner().getEntityCollection().addAll(subinfo.getEntityCollection());
info.addSubplotInfo(subinfo.getPlotInfo());
}
++column;
if (column == displayCols) {
column = 0;
++row;
if (row == displayRows - 1 && diff != 0) {
xoffset = (diff * width) / 2;
}
}
}
}
Aggregations