Search in sources :

Example 16 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity in project pentaho-platform by pentaho.

the class XYZSeriesCollectionChartComponent method populateInfo.

private void populateInfo(final ChartRenderingInfo info) {
    if (urlTemplate == null) {
        return;
    }
    Iterator iter = info.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity entity = (ChartEntity) iter.next();
        if (entity instanceof XYItemEntity) {
            if (urlTemplate != null) {
                XYItemEntity xyItemEntity = (XYItemEntity) entity;
                if (paramName == null) {
                    xyItemEntity.setURLText(urlTemplate);
                } else {
                    try {
                        int seriesIndex = xyItemEntity.getSeriesIndex();
                        int itemIndex = xyItemEntity.getItem();
                        String xySeriesKey = (String) ((XYZSeriesCollectionChartDefinition) xyItemEntity.getDataset()).getSeriesKey(seriesIndex);
                        String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding());
                        String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal);
                        String itemValueStr = ((XYZSeriesCollectionChartDefinition) xyItemEntity.getDataset()).getX(seriesIndex, itemIndex).toString();
                        encodedVal = URLEncoder.encode(itemValueStr, LocaleHelper.getSystemEncoding());
                        if (seriesName == null) {
                            // $NON-NLS-1$
                            drillURL = TemplateUtil.applyTemplate(drillURL, "SERIES", encodedVal);
                        } else {
                            drillURL = TemplateUtil.applyTemplate(drillURL, seriesName, encodedVal);
                        }
                        xyItemEntity.setURLText(drillURL);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) Iterator(java.util.Iterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChartEntity(org.jfree.chart.entity.ChartEntity)

Example 17 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity in project pentaho-platform by pentaho.

the class BubbleRenderer 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 (horizontal) axis.
 * @param rangeAxis
 *          the range (vertical) axis.
 * @param dataset
 *          the dataset (an {@link XYZDataset} is expected).
 * @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(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) {
    PlotOrientation orientation = plot.getOrientation();
    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);
        double circleSize;
        circleSize = maxSize * (z / maxZ);
        circleSize = Math.abs(circleSize);
        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);
        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }
        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        // add an entity for the item...
        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(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }
        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);
    }
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) PlotOrientation(org.jfree.chart.plot.PlotOrientation) EntityCollection(org.jfree.chart.entity.EntityCollection) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) XYZDataset(org.jfree.data.xy.XYZDataset) Ellipse2D(java.awt.geom.Ellipse2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 18 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity in project mafscaling by vimsh.

the class MafChartPanel method mousePressed.

public void mousePressed(MouseEvent e) {
    chartPanel.requestFocusInWindow();
    Insets insets = chartPanel.getInsets();
    int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX());
    int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY());
    ChartEntity entity = chartPanel.getChartRenderingInfo().getEntityCollection().getEntity(x, y);
    if (entity == null || !(entity instanceof XYItemEntity))
        return;
    IsMovable = true;
    chartPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    xyItemEntity = (XYItemEntity) entity;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
    Point2D p = chartPanel.translateScreenToJava2D(e.getPoint());
    initialMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge());
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) Insets(java.awt.Insets) XYPlot(org.jfree.chart.plot.XYPlot) Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) ChartEntity(org.jfree.chart.entity.ChartEntity) Cursor(java.awt.Cursor)

Aggregations

XYItemEntity (org.jfree.chart.entity.XYItemEntity)18 ChartEntity (org.jfree.chart.entity.ChartEntity)12 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)6 ChartMouseListener (org.jfree.chart.ChartMouseListener)6 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)6 BasicStroke (java.awt.BasicStroke)5 Color (java.awt.Color)5 GridBagLayout (java.awt.GridBagLayout)5 JLabel (javax.swing.JLabel)5 ChartPanel (org.jfree.chart.ChartPanel)5 CrosshairOverlay (org.jfree.chart.panel.CrosshairOverlay)5 Crosshair (org.jfree.chart.plot.Crosshair)5 XYDataset (org.jfree.data.xy.XYDataset)5 Shape (java.awt.Shape)4 JPanel (javax.swing.JPanel)4 EntityCollection (org.jfree.chart.entity.EntityCollection)4 PlotOrientation (org.jfree.chart.plot.PlotOrientation)4 Paint (java.awt.Paint)3 Stroke (java.awt.Stroke)3 Ellipse2D (java.awt.geom.Ellipse2D)3