Search in sources :

Example 6 with XYToolTipGenerator

use of org.jfree.chart.labels.XYToolTipGenerator in project SIMVA-SoS by SESoS.

the class XYAreaRenderer2 method drawItem.

/**
 * 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.
 * @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.
 */
@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 crosshairState, int pass) {
    if (!getItemVisible(series, item)) {
        return;
    }
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
    int itemCount = dataset.getItemCount(series);
    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
    double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());
    double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
    GeneralPath hotspot = new GeneralPath();
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        moveTo(hotspot, transZero, ((transX0 + transX1) / 2.0));
        lineTo(hotspot, ((transY0 + transY1) / 2.0), ((transX0 + transX1) / 2.0));
        lineTo(hotspot, transY1, transX1);
        lineTo(hotspot, ((transY1 + transY2) / 2.0), ((transX1 + transX2) / 2.0));
        lineTo(hotspot, transZero, ((transX1 + transX2) / 2.0));
    } else {
        // vertical orientation
        moveTo(hotspot, ((transX0 + transX1) / 2.0), transZero);
        lineTo(hotspot, ((transX0 + transX1) / 2.0), ((transY0 + transY1) / 2.0));
        lineTo(hotspot, transX1, transY1);
        lineTo(hotspot, ((transX1 + transX2) / 2.0), ((transY1 + transY2) / 2.0));
        lineTo(hotspot, ((transX1 + transX2) / 2.0), transZero);
    }
    hotspot.closePath();
    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke stroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(stroke);
    // Check if the item is the last item for the series.
    // and number of items > 0.  We can't draw an area for a single point.
    g2.fill(hotspot);
    // draw an outline around the Area.
    if (isOutline()) {
        g2.setStroke(lookupSeriesOutlineStroke(series));
        g2.setPaint(lookupSeriesOutlinePaint(series));
        g2.draw(hotspot);
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != 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(hotspot, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) GeneralPath(java.awt.geom.GeneralPath) EntityCollection(org.jfree.chart.entity.EntityCollection) Paint(java.awt.Paint) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) Paint(java.awt.Paint)

Example 7 with XYToolTipGenerator

use of org.jfree.chart.labels.XYToolTipGenerator in project SIMVA-SoS by SESoS.

the class TimeSeriesChartTest method testSetSeriesToolTipGenerator.

/**
 * 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);
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) Test(org.junit.Test)

Example 8 with XYToolTipGenerator

use of org.jfree.chart.labels.XYToolTipGenerator in project SIMVA-SoS by SESoS.

the class XYAreaChartTest method testSetSeriesToolTipGenerator.

/**
 * 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);
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) Test(org.junit.Test)

Example 9 with XYToolTipGenerator

use of org.jfree.chart.labels.XYToolTipGenerator in project SIMVA-SoS by SESoS.

the class XYLineChartTest method testSetSeriesToolTipGenerator.

/**
 * 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);
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) Test(org.junit.Test)

Example 10 with XYToolTipGenerator

use of org.jfree.chart.labels.XYToolTipGenerator in project SIMVA-SoS by SESoS.

the class XYStepChartTest method testSetSeriesToolTipGenerator.

/**
 * 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);
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) Test(org.junit.Test)

Aggregations

XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)28 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)22 XYPlot (org.jfree.chart.plot.XYPlot)21 NumberAxis (org.jfree.chart.axis.NumberAxis)14 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)13 StandardXYURLGenerator (org.jfree.chart.urls.StandardXYURLGenerator)10 JFreeChart (org.jfree.chart.JFreeChart)8 DateAxis (org.jfree.chart.axis.DateAxis)8 Paint (java.awt.Paint)7 XYURLGenerator (org.jfree.chart.urls.XYURLGenerator)7 XYItemEntity (org.jfree.chart.entity.XYItemEntity)6 Test (org.junit.Test)6 SimpleDateFormat (java.text.SimpleDateFormat)5 ValueAxis (org.jfree.chart.axis.ValueAxis)5 XYStepAreaRenderer (org.jfree.chart.renderer.xy.XYStepAreaRenderer)5 XYDataset (org.jfree.data.xy.XYDataset)5 Color (java.awt.Color)4 Shape (java.awt.Shape)4 EntityCollection (org.jfree.chart.entity.EntityCollection)4 PlotOrientation (org.jfree.chart.plot.PlotOrientation)4