use of org.jfree.chart.entity.EntityCollection in project processdash by dtuma.
the class TooltipLineXYLineAndShapeRenderer method drawPrimaryLine.
@Override
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
super.drawPrimaryLine(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea);
EntityCollection entities = state.getEntityCollection();
if (entities != null && item > 0) {
Shape tooltipArea = getTooltipArea(state.workingLine, series);
addEntity(entities, tooltipArea, dataset, series, item, 0, 0);
}
}
use of org.jfree.chart.entity.EntityCollection in project processdash by dtuma.
the class CGIChartBase method writeImageHtml.
private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException {
String tooltip = getParameter("tooltip");
if (!StringUtils.hasValue(tooltip))
tooltip = resources.getHTML("More_Detail_Here_Instruction");
String href = getParameter("href");
if (StringUtils.hasValue(href)) {
// create a copy of the entity collection, and place an entity for
// the entire chart at the beginning of the list. This will
// make it appear last in the image map (which is important,
// because browsers process the image map areas in the order that
// they appear; having the entire chart area listed first would
// obscure all of the other image map areas).
EntityCollection entities = new StandardEntityCollection();
entities.add(new ChartEntity(info.getChartArea(), tooltip, href));
if (info.getEntityCollection() != null)
entities.addAll(info.getEntityCollection());
// area in the chart.
for (Iterator i = entities.iterator(); i.hasNext(); ) {
ChartEntity ce = (ChartEntity) i.next();
// image map anyway, so they don't need to be adjusted
if (ce.getToolTipText() == null && ce.getURLText() == null)
continue;
// for other entities, add a tooltip and a URL as needed.
if (!StringUtils.hasValue(ce.getToolTipText()))
ce.setToolTipText(tooltip);
if (!StringUtils.hasValue(ce.getURLText()))
ce.setURLText(href);
}
// install our modified version of the entity collection into
// the chart info object, so it will be used when generating
// the image map later.
info.setEntityCollection(entities);
}
// write the image tag
out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID + "\" usemap=\"#IMG" + imgID + '"');
// have a URL we're pointing to. Turn that border off.
if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
out.write(" border=\"0\"");
// starting with the prefix "img", and copy them into the tag.
for (Iterator i = parameters.entrySet().iterator(); i.hasNext(); ) {
Map.Entry e = (Map.Entry) i.next();
String attrName = (String) e.getKey();
if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) {
out.write(" " + attrName.substring(3) + "=\"");
out.write(HTMLUtils.escapeEntities(e.getValue().toString()));
out.write('"');
}
}
out.write(">");
// finally, write the image map. Note that we have to strip line
// break characters from the resulting HTML, otherwise firefox seems
// to decide that the <map> tag actually takes up space on the page
String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip), new StandardURLTagFragmentGenerator());
for (int i = 0; i < imageMapHtml.length(); i++) {
char c = imageMapHtml.charAt(i);
if (c != '\r' && c != '\n')
out.write(c);
}
out.flush();
}
use of org.jfree.chart.entity.EntityCollection in project tdq-studio-se by Talend.
the class HideSeriesGanttRenderer method drawTask.
/**
* Draws a single task.
*
* @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);
}
}
}
use of org.jfree.chart.entity.EntityCollection in project processdash by dtuma.
the class RangeXYItemRenderer method drawItem.
/** Draws the visual representation of a single data item.
*/
@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 crosshairInfo, int pass) {
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
Shape entityArea = null;
Paint paint = getItemPaint(series, item);
Stroke seriesStroke = getItemStroke(series, item);
g2.setPaint(paint);
g2.setStroke(seriesStroke);
// get the data point...
Number x1n = dataset.getX(series, item);
Number y1n = dataset.getY(series, item);
if (y1n == null || x1n == null) {
return;
}
double x1 = x1n.doubleValue();
double y1 = y1n.doubleValue();
final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
PlotOrientation orientation = plot.getOrientation();
if (item > 0) {
// get the previous data point...
Number x0n = dataset.getX(series, item - 1);
Number y0n = dataset.getY(series, item - 1);
if (y0n != null && x0n != null) {
double x0 = x0n.doubleValue();
double y0 = y0n.doubleValue();
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
// only draw if we have good values
if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
return;
}
if (orientation == PlotOrientation.HORIZONTAL) {
line.setLine(transY0, transX0, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
line.setLine(transX0, transY0, transX1, transY1);
}
if (y1n instanceof RangeInfo) {
RangeInfo y1r = (RangeInfo) y1n;
double transY1low = rangeAxis.valueToJava2D(y1r.getRangeLowerBound(false), dataArea, yAxisLocation);
double transY1high = rangeAxis.valueToJava2D(y1r.getRangeUpperBound(false), dataArea, yAxisLocation);
drawItemRangeGradient(g2, line, paint, seriesStroke, transX1, transY1low, transX1, transY1high);
} else if (x1n instanceof RangeInfo) {
RangeInfo x1r = (RangeInfo) x1n;
double transX1low = domainAxis.valueToJava2D(x1r.getRangeLowerBound(false), dataArea, xAxisLocation);
double transX1high = domainAxis.valueToJava2D(x1r.getRangeUpperBound(false), dataArea, xAxisLocation);
drawItemRangeGradient(g2, line, paint, seriesStroke, transX1low, transY1, transX1high, transY1);
} else if (line.intersects(dataArea)) {
g2.draw(line);
}
}
} else if (dataset.getItemCount(series) == 1) {
Shape shape = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
}
if (shape.intersects(dataArea)) {
if (getItemShapeFilled(series, item)) {
g2.fill(shape);
} else {
g2.draw(shape);
}
}
entityArea = shape;
}
if (entities != null && (dataArea.contains(transX1, transY1) || entityArea != null)) {
addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
}
}
use of org.jfree.chart.entity.EntityCollection in project processdash by dtuma.
the class StandardDiscItemRenderer method drawItem.
public void drawItem(Graphics2D g2, DiscItemRendererState state, Rectangle2D dataArea, Ellipse2D discLocation, PlotRenderingInfo info, DiscPlot plot, PieDataset dataset, int item) {
Ellipse2D shape = plot.getDiscDistributor().getDiscLocation(item);
if (shape == null)
return;
Comparable key = dataset.getKey(item);
Paint discPaint = lookupDiscPaint(key, true);
drawDisc(g2, shape, discPaint, item);
drawLabel(g2, plot, dataset, shape, key, discPaint);
drawOutline(g2, shape, key);
if (info != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
String tip = null;
if (plot.getToolTipGenerator() != null) {
tip = plot.getToolTipGenerator().generateToolTip(dataset, key);
}
String url = null;
if (plot.getUrlGenerator() != null) {
url = plot.getUrlGenerator().generateURL(dataset, key, item);
}
DiscItemEntity entity = new DiscItemEntity(shape, dataset, item, key, tip, url);
entities.add(entity);
}
}
}
Aggregations