Search in sources :

Example 1 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity in project adempiere by adempiere.

the class VChart method chartMouseClicked.

@Override
public void chartMouseClicked(ChartMouseEvent event) {
    if ((event.getEntity() != null) && (event.getTrigger().getClickCount() > 1)) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        try {
            ChartEntity entity = event.getEntity();
            String key = null;
            String seriesName = null;
            if (entity instanceof CategoryItemEntity) {
                CategoryItemEntity item = ((CategoryItemEntity) entity);
                Comparable<?> colKey = item.getColumnKey();
                Comparable<?> rowKey = item.getRowKey();
                if (colKey != null && rowKey != null) {
                    key = colKey.toString();
                    seriesName = rowKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (entity instanceof XYItemEntity) {
                XYItemEntity item = ((XYItemEntity) entity);
                if (item.getDataset() instanceof TimeSeriesCollection) {
                    TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
                    TimeSeries series = data.getSeries(item.getSeriesIndex());
                    TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
                    seriesName = series.getKey().toString();
                    key = dataitem.getPeriod().toString();
                }
            }
            if (key == null)
                return;
            MQuery query = chartModel.getQuery(seriesName == null ? key : seriesName + "__" + key);
            if (query != null)
                AEnv.zoom(query);
        } finally {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    }
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) MQuery(org.compiere.model.MQuery) ChartEntity(org.jfree.chart.entity.ChartEntity) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 2 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity in project adempiere by adempiere.

the class WChartEditor method render.

private void render(JFreeChart chart) {
    ChartRenderingInfo info = new ChartRenderingInfo();
    int width = 400;
    int height = chartModel.getWinHeight();
    BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();
        Panel panel = getComponent();
        myImage.setContent(image);
        if (panel.getPanelchildren() != null) {
            panel.getPanelchildren().getChildren().clear();
            panel.getPanelchildren().appendChild(myImage);
        } else {
            Panelchildren pc = new Panelchildren();
            panel.appendChild(pc);
            pc.appendChild(myImage);
        }
        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) {
            ChartEntity entity = (ChartEntity) it.next();
            String key = null;
            String seriesName = null;
            if (entity instanceof CategoryItemEntity) {
                CategoryItemEntity item = ((CategoryItemEntity) entity);
                Comparable<?> colKey = item.getColumnKey();
                Comparable<?> rowKey = item.getRowKey();
                if (colKey != null && rowKey != null) {
                    key = colKey.toString();
                    seriesName = rowKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (entity instanceof XYItemEntity) {
                XYItemEntity item = ((XYItemEntity) entity);
                if (item.getDataset() instanceof TimeSeriesCollection) {
                    TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
                    TimeSeries series = data.getSeries(item.getSeriesIndex());
                    TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
                    seriesName = series.getKey().toString();
                    key = dataitem.getPeriod().toString();
                }
            }
            if (key == null)
                continue;
            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG__" + seriesName + "__" + key);
            count++;
        }
        myImage.addEventListener(Events.ON_CLICK, new EventListener() {

            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    String[] strs = areaId.split("__");
                    if (strs.length == 3) {
                        chartMouseClicked(strs[2], strs[1]);
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) Panelchildren(org.zkoss.zul.Panelchildren) BufferedImage(java.awt.image.BufferedImage) XYItemEntity(org.jfree.chart.entity.XYItemEntity) Panel(org.zkoss.zul.Panel) Area(org.zkoss.zul.Area) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) AImage(org.zkoss.image.AImage) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) Event(org.zkoss.zk.ui.event.Event) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) ChartEntity(org.jfree.chart.entity.ChartEntity) EventListener(org.zkoss.zk.ui.event.EventListener) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity) Imagemap(org.zkoss.zul.Imagemap)

Example 3 with XYItemEntity

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

the class XYSeriesCollectionChartComponent 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) ((XYSeriesCollection) xyItemEntity.getDataset()).getSeriesKey(seriesIndex);
                        String encodedVal = URLEncoder.encode(xySeriesKey, LocaleHelper.getSystemEncoding());
                        String drillURL = TemplateUtil.applyTemplate(urlTemplate, paramName, encodedVal);
                        String itemValueStr = ((XYSeriesCollection) 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 4 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity in project SIMVA-SoS by SESoS.

the class XYDifferenceRenderer method drawItemPass1.

/**
 * Draws the visual representation of a single data item, second pass.  In
 * the second pass, the renderer draws the lines and shapes for the
 * individual points in the two series.
 *
 * @param x_graphics  the graphics device.
 * @param x_dataArea  the area within which the data is being drawn.
 * @param x_info  collects information about the drawing.
 * @param x_plot  the plot (can be used to obtain standard color
 *         information etc).
 * @param x_domainAxis  the domain (horizontal) axis.
 * @param x_rangeAxis  the range (vertical) axis.
 * @param x_dataset  the dataset.
 * @param x_series  the series index (zero-based).
 * @param x_item  the item index (zero-based).
 * @param x_crosshairState  crosshair information for the plot
 *                          (<code>null</code> permitted).
 */
protected void drawItemPass1(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) {
    Shape l_entityArea = null;
    EntityCollection l_entities = null;
    if (null != x_info) {
        l_entities = x_info.getOwner().getEntityCollection();
    }
    Paint l_seriesPaint = getItemPaint(x_series, x_item);
    Stroke l_seriesStroke = getItemStroke(x_series, x_item);
    x_graphics.setPaint(l_seriesPaint);
    x_graphics.setStroke(l_seriesStroke);
    PlotOrientation l_orientation = x_plot.getOrientation();
    RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
    RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
    double l_x0 = x_dataset.getXValue(x_series, x_item);
    double l_y0 = x_dataset.getYValue(x_series, x_item);
    double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation);
    double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation);
    if (getShapesVisible()) {
        Shape l_shape = getItemShape(x_series, x_item);
        if (l_orientation == PlotOrientation.HORIZONTAL) {
            l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_y1, l_x1);
        } else {
            l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_x1, l_y1);
        }
        if (l_shape.intersects(x_dataArea)) {
            x_graphics.setPaint(getItemPaint(x_series, x_item));
            x_graphics.fill(l_shape);
        }
        l_entityArea = l_shape;
    }
    // add an entity for the item...
    if (null != l_entities) {
        if (null == l_entityArea) {
            l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4);
        }
        String l_tip = null;
        XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item);
        if (null != l_tipGenerator) {
            l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item);
        }
        String l_url = null;
        XYURLGenerator l_urlGenerator = getURLGenerator();
        if (null != l_urlGenerator) {
            l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item);
        }
        XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url);
        l_entities.add(l_entity);
    }
    // draw the item label if there is one...
    if (isItemLabelVisible(x_series, x_item)) {
        drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, l_x1, l_y1, (l_y1 < 0.0));
    }
    int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis);
    int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis);
    updateCrosshairValues(x_crosshairState, l_x0, l_y0, l_domainAxisIndex, l_rangeAxisIndex, l_x1, l_y1, l_orientation);
    if (0 == x_item) {
        return;
    }
    double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation);
    double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation);
    Line2D l_line = null;
    if (PlotOrientation.HORIZONTAL == l_orientation) {
        l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
    } else if (PlotOrientation.VERTICAL == l_orientation) {
        l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
    }
    if ((null != l_line) && l_line.intersects(x_dataArea)) {
        x_graphics.setPaint(getItemPaint(x_series, x_item));
        x_graphics.setStroke(getItemStroke(x_series, x_item));
        x_graphics.draw(l_line);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) XYItemEntity(org.jfree.chart.entity.XYItemEntity) EntityCollection(org.jfree.chart.entity.EntityCollection) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 5 with XYItemEntity

use of org.jfree.chart.entity.XYItemEntity 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)

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