/** * Returns the tool tip generator for a series. * * @param series the series index (zero based). * * @return The generator (possibly <code>null</code>). */ public XYToolTipGenerator getSeriesToolTipGenerator(int series) { // return the generator for ALL series, if there is one... if (this.toolTipGenerator != null) { return this.toolTipGenerator; } // otherwise look up the generator table XYToolTipGenerator generator = (XYToolTipGenerator) this.toolTipGeneratorList.get(series); if (generator == null) { generator = this.baseToolTipGenerator; } return generator; }
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param area the entity area (if <code>null</code> a default will be used). * @param entityX the entity's center x-coordinate in user space. * @param entityY the entity's center y-coordinate in user space. * @param dataset the dataset. * @param series the series. * @param item the item. */ protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) { if (area == null) { area = new Ellipse2D.Double( entityX - this.defaultEntityRadius, entityY - this.defaultEntityRadius, this.defaultEntityRadius * 2, this.defaultEntityRadius * 2 ); } 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(area, dataset, series, item, tip, url); entities.addEntity(entity); }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: * AREA, SHAPES or AREA_AND_SHAPES. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use (<code>null</code> permitted). * @param urlGenerator the URL generator (<code>null</code> permitted). */ public XYStepAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == AREA) { this.plotArea = true; } else if (type == SHAPES) { this.plotShapes = true; } else if (type == AREA_AND_SHAPES) { this.plotArea = true; this.plotShapes = true; } this.showOutline = false; }
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param area the entity area (if <code>null</code> a default will be * used). * @param dataset the dataset. * @param series the series. * @param item the item. * @param entityX the entity's center x-coordinate in user space. * @param entityY the entity's center y-coordinate in user space. */ protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) { if (!getItemCreateEntity(series, item)) { return; } if (area == null) { area = new Ellipse2D.Double(entityX - this.defaultEntityRadius, entityY - this.defaultEntityRadius, this.defaultEntityRadius * 2, this.defaultEntityRadius * 2); } 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(area, dataset, series, item, tip, url); entities.add(entity); }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: * AREA, SHAPES or AREA_AND_SHAPES. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use * (<code>null</code> permitted). * @param urlGenerator the URL generator (<code>null</code> permitted). */ public XYStepAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setBaseToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == AREA) { this.plotArea = true; } else if (type == SHAPES) { this.shapesVisible = true; } else if (type == AREA_AND_SHAPES) { this.plotArea = true; this.shapesVisible = true; } this.showOutline = false; }
/** * Constructs a new renderer. * * @param labelGenerator the tool tip generator to use. <code>null</code> * is none. * @param urlGenerator the URL generator (null permitted). */ public XYAreaRenderer2(XYToolTipGenerator labelGenerator, XYURLGenerator urlGenerator) { super(); this.showOutline = false; setBaseToolTipGenerator(labelGenerator); setURLGenerator(urlGenerator); GeneralPath area = new GeneralPath(); area.moveTo(0.0f, -4.0f); area.lineTo(3.0f, -2.0f); area.lineTo(4.0f, 4.0f); area.lineTo(-4.0f, 4.0f); area.lineTo(-3.0f, -2.0f); area.closePath(); this.legendArea = area; }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: * AREA, SHAPES or AREA_AND_SHAPES. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use * (<code>null</code> permitted). * @param urlGenerator the URL generator (<code>null</code> permitted). */ public XYStepAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setBaseToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == AREA) { this.plotArea = true; } else if (type == SHAPES) { this.shapesVisible = true; } else if (type == AREA_AND_SHAPES) { this.plotArea = true; this.shapesVisible = true; } this.showOutline = false; this.stepPoint = 1.0; }
/** * Displays the info about the vertex including the error in each vertex nicely */ public void setToolTipRenderer(){ errorRenderer.setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int seriesIndex, int item) { XYSeriesCollection collection = (XYSeriesCollection)dataset; XYSeries series = collection.getSeries(seriesIndex); Number x = series.getX(item); Number y = series.getY(item); double error = ((PrismXYDataItem)series.getDataItem(item)).getError(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(String.format("<html><p style='color:#0000ff;'>Series: '%s'</p>", dataset.getSeriesKey(seriesIndex))); stringBuilder.append("X: " + (Math.round( x.doubleValue() * 10000.0 ) / 10000.0) + "<br>"); stringBuilder.append("Y: " + (Math.round( y.doubleValue() * 10000.0 ) / 10000.0) + " +/- " + (Math.round( error * 10000.0 ) / 10000.0) + "<br>"); stringBuilder.append("</html>"); return stringBuilder.toString(); } }); }
/** * Constructs a new renderer. To specify the type of renderer, use one of * the constants: {@link #SHAPES}, {@link #LINES} or * {@link #SHAPES_AND_LINES}. * * @param type the type of renderer. * @param toolTipGenerator the item label generator ({@code null} * permitted). * @param urlGenerator the URL generator. */ public StandardXYItemRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setDefaultToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if ((type & SHAPES) != 0) { this.baseShapesVisible = true; } if ((type & LINES) != 0) { this.plotLines = true; } if ((type & IMAGES) != 0) { this.plotImages = true; } if ((type & DISCONTINUOUS) != 0) { this.plotDiscontinuous = true; } this.seriesShapesFilled = new BooleanList(); this.baseShapesFilled = true; this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0); this.drawSeriesLineAsPath = false; }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: * AREA, SHAPES or AREA_AND_SHAPES. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use * ({@code null} permitted). * @param urlGenerator the URL generator ({@code null} permitted). */ public XYStepAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setDefaultToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == AREA) { this.plotArea = true; } else if (type == SHAPES) { this.shapesVisible = true; } else if (type == AREA_AND_SHAPES) { this.plotArea = true; this.shapesVisible = true; } this.showOutline = false; this.stepPoint = 1.0; }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: SHAPES, LINES or SHAPES_AND_LINES. * * @param type the type of renderer. * @param toolTipGenerator the item label generator (<code>null</code> permitted). * @param urlGenerator the URL generator. */ public StandardXYItemRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if ((type & SHAPES) != 0) { this.plotShapes = true; } if ((type & LINES) != 0) { this.plotLines = true; } if ((type & IMAGES) != 0) { this.plotImages = true; } if ((type & DISCONTINUOUS) != 0) { this.plotDiscontinuous = true; } //this.line = new Line2D.Double(0.0, 0.0, 0.0, 0.0); this.shapesFilled = null; this.seriesShapesFilled = new BooleanList(); this.defaultShapesFilled = Boolean.TRUE; }
/** * Creates a new renderer for candlestick charts. * <P> * Use -1 for the candle width if you prefer the width to be calculated automatically. * * @param candleWidth the candle width. * @param drawVolume a flag indicating whether or not volume bars should be drawn. * @param toolTipGenerator the tool tip generator. <code>null</code> is none. */ public CandlestickRenderer(double candleWidth, boolean drawVolume, XYToolTipGenerator toolTipGenerator) { super(); setToolTipGenerator(toolTipGenerator); this.candleWidth = candleWidth; this.drawVolume = drawVolume; this.upPaint = Color.green; this.downPaint = Color.red; }
/** * Constructs a new renderer. * * @param toolTipGenerator the item label generator. * @param urlGenerator the URL generator. */ public XYStepRenderer(XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: SHAPES, LINES, * SHAPES_AND_LINES, AREA or AREA_AND_SHAPES. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use. <code>null</code> is none. * @param urlGenerator the URL generator (null permitted). */ public XYAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == SHAPES) { this.plotShapes = true; } if (type == LINES) { this.plotLines = true; } if (type == SHAPES_AND_LINES) { this.plotShapes = true; this.plotLines = true; } if (type == AREA) { this.plotArea = true; } if (type == AREA_AND_SHAPES) { this.plotArea = true; this.plotShapes = true; } this.showOutline = false; }
/** * Constructs a new renderer. * <p> * To specify the type of renderer, use one of the constants: SHAPES, LINES, * SHAPES_AND_LINES, AREA or AREA_AND_SHAPES. * * @param labelGenerator the tool tip generator to use. <code>null</code> is none. * @param urlGenerator the URL generator (null permitted). */ public XYAreaRenderer2(XYToolTipGenerator labelGenerator, XYURLGenerator urlGenerator) { super(); this.plotArea = true; this.plotLines = false; this.plotShapes = false; this.showOutline = false; setToolTipGenerator(labelGenerator); setURLGenerator(urlGenerator); }
/** * Check that setting a tool tip generator for a series does override the * default generator. */ public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertTrue(tt2 == tt); }
/** * Constructs a new renderer. To specify the type of renderer, use one of * the constants: {@link #SHAPES}, {@link #LINES} or * {@link #SHAPES_AND_LINES}. * * @param type the type of renderer. * @param toolTipGenerator the item label generator (<code>null</code> * permitted). * @param urlGenerator the URL generator. */ public StandardXYItemRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if ((type & SHAPES) != 0) { this.baseShapesVisible = true; } if ((type & LINES) != 0) { this.plotLines = true; } if ((type & IMAGES) != 0) { this.plotImages = true; } if ((type & DISCONTINUOUS) != 0) { this.plotDiscontinuous = true; } this.shapesFilled = null; this.seriesShapesFilled = new BooleanList(); this.baseShapesFilled = true; this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0); this.drawSeriesLineAsPath = false; }
/** * Returns the tool tip generator for a data item. If, for some reason, * you want a different generator for individual items, you can override * this method. * * @param series the series index (zero based). * @param item the item index (zero based). * * @return The generator (possibly <code>null</code>). */ public XYToolTipGenerator getToolTipGenerator(int series, int item) { // return the generator for ALL series, if there is one... if (this.toolTipGenerator != null) { return this.toolTipGenerator; } // otherwise look up the generator table XYToolTipGenerator generator = (XYToolTipGenerator) this.toolTipGeneratorList.get(series); if (generator == null) { generator = this.baseToolTipGenerator; } return generator; }
/** * Constructs a new renderer. To specify the type of renderer, use one of * the constants: <code>SHAPES</code>, <code>LINES</code>, * <code>SHAPES_AND_LINES</code>, <code>AREA</code> or * <code>AREA_AND_SHAPES</code>. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use * (<code>null</code> permitted). * @param urlGenerator the URL generator (<code>null</code> permitted). */ public XYAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setBaseToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == SHAPES) { this.plotShapes = true; } if (type == LINES) { this.plotLines = true; } if (type == SHAPES_AND_LINES) { this.plotShapes = true; this.plotLines = true; } if (type == AREA) { this.plotArea = true; } if (type == AREA_AND_SHAPES) { this.plotArea = true; this.plotShapes = true; } this.showOutline = false; GeneralPath area = new GeneralPath(); area.moveTo(0.0f, -4.0f); area.lineTo(3.0f, -2.0f); area.lineTo(4.0f, 4.0f); area.lineTo(-4.0f, 4.0f); area.lineTo(-3.0f, -2.0f); area.closePath(); this.legendArea = area; }
/** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertTrue(tt2 == tt); }
/** * Constructs a new renderer. To specify the type of renderer, use one of * the constants: {@link #SHAPES}, {@link #LINES} or * {@link #SHAPES_AND_LINES}. * * @param type the type of renderer. * @param toolTipGenerator the item label generator (<code>null</code> * permitted). * @param urlGenerator the URL generator. */ public StandardXYItemRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setBaseToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if ((type & SHAPES) != 0) { this.baseShapesVisible = true; } if ((type & LINES) != 0) { this.plotLines = true; } if ((type & IMAGES) != 0) { this.plotImages = true; } if ((type & DISCONTINUOUS) != 0) { this.plotDiscontinuous = true; } this.shapesFilled = null; this.seriesShapesFilled = new BooleanList(); this.baseShapesFilled = true; this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0); this.drawSeriesLineAsPath = false; }
/** * Creates a renderer where the tooltip generator and the URL generator are * both <code>null</code>. */ protected AbstractXYItemRenderer() { super(); this.itemLabelGenerator = null; this.itemLabelGeneratorMap = new HashMap<Integer, XYItemLabelGenerator>(); this.toolTipGenerator = null; this.toolTipGeneratorMap = new HashMap<Integer, XYToolTipGenerator>(); this.urlGenerator = null; this.backgroundAnnotations = new java.util.ArrayList(); this.foregroundAnnotations = new java.util.ArrayList(); this.legendItemLabelGenerator = new StandardXYSeriesLabelGenerator( "{0}"); }
/** * Add custom tool tip for the Histogram to show more info */ public void addToolTip(){ ((ClusteredXYBarRenderer)plot.getRenderer()).setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int seriesIndex, int item) { XYIntervalSeriesCollection collection = (XYIntervalSeriesCollection)dataset; XYIntervalSeries series = collection.getSeries(seriesIndex); double minX = series.getXLowValue(item); double maxX = series.getXHighValue(item); double height = series.getYValue(item); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(String.format("<html><p style='color:#0000ff;'>Prop: '%s'</p>", dataset.getSeriesKey(seriesIndex))); stringBuilder.append("<table style=\"width:100%\">"); stringBuilder.append("<tr><td> Min range: </td><td>" + (Math.round( minX * 10000.0 ) / 10000.0) + "</td></tr>"); stringBuilder.append("<tr><td> Max range: </td><td>" + (Math.round( maxX * 10000.0 ) / 10000.0) + "</td></tr>"); stringBuilder.append("<tr><td> Number of states: </td><td>" + height + "</td></tr></table>"); stringBuilder.append("</html>"); return stringBuilder.toString(); } }); }
/** * Creates a new renderer for candlestick charts. * <P> * Use -1 for the candle width if you prefer the width to be calculated * automatically. * * @param candleWidth the candle width. * @param drawVolume a flag indicating whether or not volume bars should * be drawn. * @param toolTipGenerator the tool tip generator. <code>null</code> is * none. */ public CandlestickRenderer(double candleWidth, boolean drawVolume, XYToolTipGenerator toolTipGenerator) { super(); setBaseToolTipGenerator(toolTipGenerator); this.candleWidth = candleWidth; this.drawVolume = drawVolume; this.volumePaint = Color.gray; this.upPaint = Color.green; this.downPaint = Color.red; this.useOutlinePaint = false; // false preserves the old behaviour // prior to introducing this flag }
/** * Constructs a new renderer. To specify the type of renderer, use one of * the constants: <code>SHAPES</code>, <code>LINES</code>, * <code>SHAPES_AND_LINES</code>, <code>AREA</code> or * <code>AREA_AND_SHAPES</code>. * * @param type the type of renderer. * @param toolTipGenerator the tool tip generator to use * (<code>null</code> permitted). * @param urlGenerator the URL generator (<code>null</code> permitted). */ public XYAreaRenderer(int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { super(); setBaseToolTipGenerator(toolTipGenerator); setURLGenerator(urlGenerator); if (type == SHAPES) { this.plotShapes = true; } if (type == LINES) { this.plotLines = true; } if (type == SHAPES_AND_LINES) { this.plotShapes = true; this.plotLines = true; } if (type == AREA) { this.plotArea = true; } if (type == AREA_AND_SHAPES) { this.plotArea = true; this.plotShapes = true; } this.showOutline = false; GeneralPath area = new GeneralPath(); area.moveTo(0.0f, -4.0f); area.lineTo(3.0f, -2.0f); area.lineTo(4.0f, 4.0f); area.lineTo(-4.0f, 4.0f); area.lineTo(-3.0f, -2.0f); area.closePath(); this.legendArea = area; this.useFillPaint = false; this.gradientTransformer = new StandardGradientPaintTransformer(); }
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param area the entity area (if <code>null</code> a default will be * used). * @param dataset the dataset. * @param series the series. * @param item the item. * @param entityX the entity's center x-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * @param entityY the entity's center y-coordinate in user space (only * used if <code>area</code> is <code>null</code>). */ protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) { if (!getItemCreateEntity(series, item)) { return; } 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); } } 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); }