Search in sources :

Example 1 with RectangleEdge

use of org.jfree.ui.RectangleEdge 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);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 2 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project tdq-studio-se by Talend.

the class ToolTipChartComposite method getTooltipAtPoint.

/**
 * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a
 * data point in a data set that lies inside a hotspot around that value.
 *
 * @param point The Java 2D point
 * @return A string for the data at the point or null if no data is found.
 */
protected String getTooltipAtPoint(Point point) {
    String result = null;
    Point2D translatedPoint = this.translateScreenToJava2D(point);
    Plot plot = this.getChart().getPlot();
    PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo();
    if (plot instanceof CombinedDomainXYPlot) {
        int index = info.getSubplotIndex(translatedPoint);
        if (index < 0) {
            index = 0;
        }
        plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index);
        info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index);
    }
    if (plot != null && plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        ValueAxis domainAxis = xyPlot.getDomainAxis();
        ValueAxis rangeAxis = xyPlot.getRangeAxis();
        // had to switch to SWT's rectangle here.
        Rectangle screenArea = this.scale(info.getDataArea());
        double hotspotSizeX = hotspontsize * this.getScaleX();
        double hotspotSizeY = hotspontsize * this.getScaleY();
        double x0 = point.getX();
        double y0 = point.getY();
        double x1 = x0 - hotspotSizeX;
        double y1 = y0 + hotspotSizeY;
        double x2 = x0 + hotspotSizeX;
        double y2 = y0 - hotspotSizeY;
        RectangleEdge xEdge = RectangleEdge.BOTTOM;
        RectangleEdge yEdge = RectangleEdge.LEFT;
        // Switch everything for horizontal charts
        if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) {
            hotspotSizeX = hotspontsize * this.getScaleY();
            hotspotSizeY = hotspontsize * this.getScaleX();
            x0 = point.getY();
            y0 = point.getX();
            x1 = x0 + hotspotSizeX;
            y1 = y0 - hotspotSizeY;
            x2 = x0 - hotspotSizeX;
            y2 = y0 + hotspotSizeY;
            xEdge = RectangleEdge.LEFT;
            yEdge = RectangleEdge.BOTTOM;
        }
        // OK, here we have to get ourselves back into AWT land...
        Rectangle2D r2d = new Rectangle2D.Double();
        r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height);
        double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge);
        double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge);
        double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge);
        double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge);
        double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge);
        int datasetCount = xyPlot.getDatasetCount();
        for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) {
            XYDataset dataset = xyPlot.getDataset(datasetIndex);
            int seriesCount = dataset.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = dataset.getItemCount(series);
                if (dataset instanceof OHLCDataset) {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item);
                        double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item);
                        // Check hi lo and swap if needed
                        if (yValueHi < yValueLo) {
                            double temp = yValueHi;
                            yValueHi = yValueLo;
                            yValueLo = temp;
                        }
                        // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the cursor 'y' value lies between the high and low (low < ty0 < high)
                            if (yValueLo < ty0 && ty0 < yValueHi) {
                                return hiLoTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                } else {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValue = dataset.getYValue(series, item);
                        // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2)
                            if (ty1 < yValue && yValue < ty2) {
                                return xyTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Plot(org.jfree.chart.plot.Plot) Rectangle(org.eclipse.swt.graphics.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) OHLCDataset(org.jfree.data.xy.OHLCDataset) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 3 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project ma-core-public by infiniteautomation.

the class XYCardinalSplineRenderer method drawPrimaryLineAsPath.

@Override
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    State s = (State) state;
    // update path to reflect latest point
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        this.points.add(new Point2D.Double(transX1, transY1));
    }
    // if this is the last item, draw the path ...
    if (item == s.getLastItemIndex()) {
        List<Point2D> pts = this.getCurvePoints();
        s.seriesPath.moveTo(pts.get(0).getX(), pts.get(0).getY());
        for (int i = 1; i < pts.size(); i++) {
            final Point2D p = pts.get(i);
            s.seriesPath.lineTo(p.getX(), p.getY());
        }
        // draw path
        drawFirstPassShape(g2, pass, series, item, s.seriesPath);
        this.points.clear();
    }
}
Also used : Point2D(java.awt.geom.Point2D) XYItemRendererState(org.jfree.chart.renderer.xy.XYItemRendererState) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 4 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class XYSmoothLineAndShapeRenderer method drawPrimaryLine.

/**
 * Draws the item (first pass). This method draws the lines
 * connecting the items.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @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 pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 */
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
    if (item == 0) {
        return;
    }
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }
    double x0 = dataset.getXValue(series, item - 1);
    double y0 = dataset.getYValue(series, item - 1);
    if (Double.isNaN(y0) || Double.isNaN(x0)) {
        return;
    }
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    // only draw if we have good values
    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
        return;
    }
    Point2D.Double point0 = new Point2D.Double();
    Point2D.Double point1 = new Point2D.Double();
    Point2D.Double point2 = new Point2D.Double();
    Point2D.Double point3 = new Point2D.Double();
    if (item == 1) {
        point0 = null;
    } else {
        point0.x = domainAxis.valueToJava2D(dataset.getXValue(series, item - 2), dataArea, xAxisLocation);
        point0.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item - 2), dataArea, yAxisLocation);
    }
    point1.x = transX0;
    point1.y = transY0;
    point2.x = transX1;
    point2.y = transY1;
    if ((item + 1) == dataset.getItemCount(series)) {
        point3 = null;
    } else {
        point3.x = domainAxis.valueToJava2D(dataset.getXValue(series, item + 1), dataArea, xAxisLocation);
        point3.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item + 1), dataArea, yAxisLocation);
    }
    int steps = ((int) ((point2.x - point1.x) / 0.2) < 30) ? (int) ((point2.x - point1.x) / 0.2) : 30;
    Point2D.Double[] points = getBezierCurve(point0, point1, point2, point3, 1, steps);
    for (int i = 1; i < points.length; i++) {
        transX0 = points[i - 1].x;
        transY0 = points[i - 1].y;
        transX1 = points[i].x;
        transY1 = points[i].y;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            state.workingLine.setLine(transY0, transX0, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            state.workingLine.setLine(transX0, transY0, transX1, transY1);
        }
        if (state.workingLine.intersects(dataArea)) {
            drawFirstPassShape(g2, pass, series, item, state.workingLine);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Point2D(java.awt.geom.Point2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 5 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class CategoryLineAnnotation method draw.

/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
    CategoryDataset dataset = plot.getDataset();
    int catIndex1 = dataset.getColumnIndex(this.category1);
    int catIndex2 = dataset.getColumnIndex(this.category2);
    int catCount = dataset.getColumnCount();
    double lineX1 = 0.0f;
    double lineY1 = 0.0f;
    double lineX2 = 0.0f;
    double lineY2 = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        lineY1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge);
        lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineY2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge);
        lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.VERTICAL) {
        lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge);
        lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge);
        lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    }
    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

RectangleEdge (org.jfree.ui.RectangleEdge)98 Rectangle2D (java.awt.geom.Rectangle2D)52 PlotOrientation (org.jfree.chart.plot.PlotOrientation)49 Paint (java.awt.Paint)48 EntityCollection (org.jfree.chart.entity.EntityCollection)40 Stroke (java.awt.Stroke)23 Shape (java.awt.Shape)19 Line2D (java.awt.geom.Line2D)18 ValueAxis (org.jfree.chart.axis.ValueAxis)16 AxisSpace (org.jfree.chart.axis.AxisSpace)15 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)13 Point2D (java.awt.geom.Point2D)11 GeneralPath (java.awt.geom.GeneralPath)9 GradientPaint (java.awt.GradientPaint)8 Ellipse2D (java.awt.geom.Ellipse2D)7 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 RectangleInsets (org.jfree.ui.RectangleInsets)7 BasicStroke (java.awt.BasicStroke)6 AxisState (org.jfree.chart.axis.AxisState)6 CrosshairState (org.jfree.chart.plot.CrosshairState)5