Example usage for java.awt.geom GeneralPath GeneralPath

List of usage examples for java.awt.geom GeneralPath GeneralPath

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath GeneralPath.

Prototype

public GeneralPath() 

Source Link

Document

Constructs a new empty single precision GeneralPath object with a default winding rule of #WIND_NON_ZERO .

Usage

From source file:ro.nextreports.engine.chart.JFreeChartExporter.java

private JFreeChart createLineChart() throws QueryException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    String chartTitle = replaceParameters(chart.getTitle().getTitle());
    chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language));
    Object[] charts = new Object[chart.getYColumns().size()];
    List<String> legends = chart.getYColumnsLegends();
    boolean hasLegend = false;
    for (int i = 0; i < charts.length; i++) {
        String legend = "";
        try {//  w  w w .j  av a2 s . co m
            legend = replaceParameters(legends.get(i));
            legend = StringUtil.getI18nString(legend, I18nUtil.getLanguageByName(chart, language));
        } catch (IndexOutOfBoundsException ex) {
            // no legend set
        }
        if ((legend != null) && !"".equals(legend.trim())) {
            hasLegend = true;
        }
        XYSeries lineChart = new XYSeries(legend);
        charts[i] = lineChart;
        dataset.addSeries(lineChart);
    }

    String xLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    String yLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));

    JFreeChart jfreechart = ChartFactory.createXYLineChart(chartTitle, // Title
            replaceParameters(xLegend), // x-axis Label
            replaceParameters(yLegend), // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    // hide legend if necessary
    if (!hasLegend) {
        jfreechart.removeLegend();
    }

    // hide border
    jfreechart.setBorderVisible(false);

    // title
    setTitle(jfreechart);

    // charts colors & values 
    boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart();
    DecimalFormat decimalFormat;
    DecimalFormat percentageFormat;
    if (chart.getYTooltipPattern() == null) {
        decimalFormat = new DecimalFormat("#");
        percentageFormat = new DecimalFormat("0.00%");
    } else {
        decimalFormat = new DecimalFormat(chart.getYTooltipPattern());
        percentageFormat = decimalFormat;
    }
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    for (int i = 0; i < charts.length; i++) {
        plot.getRenderer().setSeriesPaint(i, chart.getForegrounds().get(i));
        if (showValues) {
            plot.getRenderer().setSeriesItemLabelsVisible(i, true);
            plot.getRenderer().setSeriesItemLabelGenerator(i,
                    new StandardXYItemLabelGenerator("{2}", decimalFormat, percentageFormat));
        }
    }

    if (showValues) {
        // increase a little bit the range axis to view all item label values over points
        plot.getRangeAxis().setUpperMargin(0.2);
    }

    // grid axis visibility & colors 
    if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) {
        plot.setDomainGridlinesVisible(false);
    } else {
        if (chart.getXGridColor() != null) {
            plot.setDomainGridlinePaint(chart.getXGridColor());
        } else {
            plot.setDomainGridlinePaint(Color.BLACK);
        }
    }
    if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) {
        plot.setRangeGridlinesVisible(false);
    } else {
        if (chart.getYGridColor() != null) {
            plot.setRangeGridlinePaint(chart.getYGridColor());
        } else {
            plot.setRangeGridlinePaint(Color.BLACK);
        }
    }

    // chart background
    plot.setBackgroundPaint(chart.getBackground());

    // labels color
    plot.getDomainAxis().setTickLabelPaint(chart.getXColor());
    plot.getRangeAxis().setTickLabelPaint(chart.getYColor());

    //legend color
    plot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor());
    plot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor());

    // legend font
    plot.getDomainAxis().setLabelFont(chart.getXLegend().getFont());
    plot.getRangeAxis().setLabelFont(chart.getYLegend().getFont());

    // hide labels
    if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) {
        plot.getDomainAxis().setTickLabelsVisible(false);
        plot.getDomainAxis().setTickMarksVisible(false);
    }
    if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) {
        plot.getRangeAxis().setTickLabelsVisible(false);
        plot.getRangeAxis().setTickMarksVisible(false);
    }

    // label orientation 
    if (chart.getXorientation() == Chart.VERTICAL) {
        plot.getDomainAxis().setVerticalTickLabels(true);
    }

    // labels fonts
    plot.getDomainAxis().setTickLabelFont(chart.getXLabelFont());
    plot.getRangeAxis().setTickLabelFont(chart.getYLabelFont());

    // point style
    Shape pointShape = null;
    byte style = chart.getType().getStyle();
    switch (style) {
    case ChartType.STYLE_LINE_DOT_SOLID:
    case ChartType.STYLE_LINE_DOT_HOLLOW:
        pointShape = new Ellipse2D.Float(-3.0f, -3.0f, 6.0f, 6.0f);
        break;
    case ChartType.STYLE_LINE_DOT_ANCHOR: // triangle
        GeneralPath s5 = new GeneralPath();
        s5.moveTo(0.0f, -3.0f);
        s5.lineTo(3.0f, 3.0f);
        s5.lineTo(-3.0f, 3.0f);
        s5.closePath();
        pointShape = s5;
        break;
    case ChartType.STYLE_LINE_DOT_BOW:
        GeneralPath s4 = new GeneralPath();
        s4.moveTo(-3.0f, -3.0f);
        s4.lineTo(3.0f, -3.0f);
        s4.lineTo(-3.0f, 3.0f);
        s4.lineTo(3.0f, 3.0f);
        s4.closePath();
        pointShape = s4;
        break;
    case ChartType.STYLE_LINE_DOT_STAR:
        pointShape = new Star(-3.0f, 0f).getShape();
        break;
    default:
        // no shape
        break;
    }

    if (pointShape != null) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setUseFillPaint(true);
        for (int i = 0; i < charts.length; i++) {
            renderer.setSeriesShapesVisible(i, true);
            if (style != ChartType.STYLE_LINE_DOT_SOLID) {
                renderer.setSeriesFillPaint(i, chart.getBackground());
            } else {
                renderer.setSeriesFillPaint(i, chart.getForegrounds().get(i));
            }
            renderer.setSeriesShape(i, pointShape);
        }
    }

    final HashMap<String, String> formatValues = createChart(plot.getRangeAxis(), charts);

    // in x axis does not contain number values , values are strings representing one unit 
    if (!integerXValue) {
        ((NumberAxis) plot.getDomainAxis()).setTickUnit(new NumberTickUnit(1));
        ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(new DecimalFormat() {
            @Override
            public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) {
                String s = formatValues.get(String.valueOf(Math.round(number)));
                if (s == null) {
                    s = "";
                }
                return result.append(s);
            }
        });
    }

    return jfreechart;

}

From source file:userinterface.graph.PrismErrorRenderer.java

/**
 * Draws the visual representation for one data item.
 *
 * @param g2  the graphics output target.
 * @param state  the renderer state.//from w  w  w  .  j a  v a2 s .c o  m
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index
 * @author Muhammad Omer Saeed.
 */

@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 (!drawError) {
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
        return;
    }

    switch (currentMethod) {

    case PrismErrorRenderer.ERRORBARS:

        if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) {

            synchronized (dataset) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;

                PlotOrientation orientation = plot.getOrientation();
                // draw the error bar for the y-interval
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                double y0 = it.getYValue() + it.getError();
                double y1 = it.getYValue() - it.getError();
                double x = collection.getXValue(series, item);

                RectangleEdge edge = plot.getRangeAxisEdge();
                double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
                double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
                double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
                Line2D line;
                Line2D cap1;
                Line2D cap2;
                double adj = this.capLength / 2.0;
                if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(xx, yy0, xx, yy1);
                    cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
                    cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
                } else { // PlotOrientation.HORIZONTAL
                    line = new Line2D.Double(yy0, xx, yy1, xx);
                    cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
                    cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
                }

                g2.setPaint(getItemPaint(series, item));

                if (this.errorStroke != null) {
                    g2.setStroke(this.errorStroke);
                } else {
                    g2.setStroke(getItemStroke(series, item));
                }
                g2.draw(line);
                g2.draw(cap1);
                g2.draw(cap2);
            }

        }

        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);

        break;

    case PrismErrorRenderer.ERRORDEVIATION:

        synchronized (dataset) {
            // do nothing if item is not visible
            if (!getItemVisible(series, item)) {
                return;
            }

            // first pass draws the shading
            if (pass == 0) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                State drState = (State) state;

                double x = collection.getXValue(series, item);
                double yLow = it.getYValue() - it.getError();
                double yHigh = it.getYValue() + it.getError();

                RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
                RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

                double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
                double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    drState.lowerCoordinates.add(new double[] { yyLow, xx });
                    drState.upperCoordinates.add(new double[] { yyHigh, xx });
                } else if (orientation == PlotOrientation.VERTICAL) {
                    drState.lowerCoordinates.add(new double[] { xx, yyLow });
                    drState.upperCoordinates.add(new double[] { xx, yyHigh });
                }

                if (item == (dataset.getItemCount(series) - 1)) {
                    // last item in series, draw the lot...
                    // set up the alpha-transparency...
                    Composite originalComposite = g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha));
                    g2.setPaint(getItemPaint(series, item));
                    GeneralPath area = new GeneralPath();
                    double[] coords = (double[]) drState.lowerCoordinates.get(0);
                    area.moveTo((float) coords[0], (float) coords[1]);
                    for (int i = 1; i < drState.lowerCoordinates.size(); i++) {
                        coords = (double[]) drState.lowerCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    int count = drState.upperCoordinates.size();
                    coords = (double[]) drState.upperCoordinates.get(count - 1);
                    area.lineTo((float) coords[0], (float) coords[1]);
                    for (int i = count - 2; i >= 0; i--) {
                        coords = (double[]) drState.upperCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    area.closePath();
                    g2.fill(area);
                    g2.setComposite(originalComposite);

                    drState.lowerCoordinates.clear();
                    drState.upperCoordinates.clear();
                }
            }
            if (isLinePass(pass)) {

                // the following code handles the line for the y-values...it's
                // all done by code in the super class
                if (item == 0) {
                    State s = (State) state;
                    s.seriesPath.reset();
                    s.setLastPointGood(false);
                }

                if (getItemLineVisible(series, item)) {
                    drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis,
                            dataArea);
                }
            }

            // second pass adds shapes where the items are ..
            else if (isItemPass(pass)) {

                // setup for collecting optional entity info...
                EntityCollection entities = null;
                if (info != null) {
                    entities = info.getOwner().getEntityCollection();
                }

                drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis,
                        crosshairState, entities);
            }

        }

        break;
    default:
        return;
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private static GeneralPath createAreaShape() {
    GeneralPath areaShape = new GeneralPath();
    areaShape.moveTo(0, 0);/*w w w.j a v a  2 s  .  c  o m*/
    areaShape.lineTo(0, -5);
    areaShape.lineTo(5, -10);
    areaShape.lineTo(10, -5);
    areaShape.lineTo(15, -7);
    areaShape.lineTo(15, 0);

    areaShape.closePath();
    return areaShape;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private static GeneralPath createBarShape() {
    GeneralPath barShape = new GeneralPath();
    barShape.moveTo(0, 0);/*from   w ww  .  j  a  v a2s  .c om*/
    barShape.lineTo(0, -5);
    barShape.lineTo(5, -5);
    barShape.lineTo(5, 0);
    barShape.lineTo(5, -15);
    barShape.lineTo(10, -15);
    barShape.lineTo(10, 0);
    barShape.lineTo(10, -10);
    barShape.lineTo(15, -10);
    barShape.lineTo(15, 0);
    barShape.closePath();
    return barShape;
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawArrow(SVGGraphics2D g2d, GeomPoint start, GeomPoint end, float thickness, float alpha,
        Color linecoler, Color fillColor) {

    if (start.equals(end))
        return;//from   w  w w  . j  a v  a 2 s.  c o  m

    //      (double edgeControlPosition, double edgeControlSize,
    //            double headLength, double headWidth, double shaftControlPosition,
    //            double shaftControlSize, float shaftPosition, double shaftThickness)
    ArrowStyle arrowStyle = new ArrowStyle(0.5, 0.5, thickness * 5, thickness * 5, 0.5, 0.5, 0, thickness);

    GeomPoint fullVect = end.subtract(start);
    double halfWidth = (arrowStyle.headWidth != -1) ? arrowStyle.headWidth / 2 : arrowStyle.headLength / 2;

    //Figure out the line start/end points
    GeomPoint startNorm = new GeomPoint();
    startNorm.setLocation(fullVect.getY(), -fullVect.getX());
    startNorm.normalize(arrowStyle.shaftThickness / 2);
    GeomPoint start1 = start.add(startNorm);
    GeomPoint start2 = start.subtract(startNorm);
    GeomPoint end1 = end.add(startNorm);
    GeomPoint end2 = end.subtract(startNorm);

    //log.debug("startNorm: "+startNorm.toString());
    //log.debug("start1: "+start1.toString());
    //log.debug("start2: "+start2.toString());
    //log.debug("end1: "+end1.toString());
    //log.debug("end2: "+end2.toString());

    //figure out where the arrow head starts
    GeomPoint headPnt = fullVect.clone();
    //log.debug("headPnt 1: "+headPnt.toString());
    //log.debug("headPnt.length 1: "+headPnt.length());
    //log.debug("arrowStyle.headLength 1: "+arrowStyle.headLength);
    headPnt.normalize(headPnt.length() - arrowStyle.headLength);
    //log.debug("headPnt 2: "+headPnt.toString());
    headPnt = headPnt.add(start);
    //log.debug("headPnt 3: "+headPnt.toString());

    //calculate the arrowhead corners
    GeomPoint headPntNorm = startNorm.clone();
    //log.debug("headPntNorm ^^: "+headPntNorm.toString());
    //log.debug("halfWidth ^^: "+halfWidth);
    headPntNorm.normalize(halfWidth);
    //log.debug("headPntNorm: "+headPntNorm.toString());
    GeomPoint edge1 = headPnt.add(headPntNorm);
    GeomPoint edge2 = headPnt.subtract(headPntNorm);

    //log.debug("edge1: "+edge1.toString());
    //log.debug("edge2: "+edge2.toString());

    //Figure out where the arrow connects the the shaft, then calc the intersections
    GeomPoint shaftCenter = GeomPoint.interpolate(end, headPnt, arrowStyle.shaftPosition);
    //log.debug("end"+end.toString());
    //log.debug("headPnt: "+headPnt.toString());
    //log.debug("arrowStyle.shaftPosition: "+arrowStyle.shaftPosition);
    //log.debug("shaftCenter: "+shaftCenter);
    //log.debug("edge1: "+edge1);
    //shaftCenter.setLocation(185.857864376269, 185.857864376269);
    GeomPoint inter1 = GeomPoint.getLineIntersection(start1, end1, shaftCenter, edge1);
    GeomPoint inter2 = GeomPoint.getLineIntersection(start2, end2, shaftCenter, edge2);

    //log.debug("inter1: "+inter1.toString());
    //log.debug("inter2: "+inter2.toString());

    //Figure out the control points
    GeomPoint edgeCenter = GeomPoint.interpolate(end, headPnt, (float) arrowStyle.edgeControlPosition);
    GeomPoint edgeNorm = startNorm.clone();
    edgeNorm.normalize(halfWidth * arrowStyle.edgeControlSize);
    //log.debug("halfWidth*arrowStyle.edgeControlSize: "+(halfWidth*arrowStyle.edgeControlSize));
    //log.debug("edgeNorm: "+edgeNorm.toString());
    GeomPoint edgeCntrl1 = edgeCenter.add(edgeNorm);
    GeomPoint edgeCntrl2 = edgeCenter.subtract(edgeNorm);

    //log.debug("edgeCntrl1: "+edgeCntrl1.toString());
    //log.debug("edgeCntrl2: "+edgeCntrl2.toString());

    g2d.setPaint(new Color(255, 0, 0));

    //      graphics.moveTo(start1.x,start1.y);
    //      graphics.lineTo(inter1.x,inter1.y);
    //      graphics.lineTo(edge1.x,edge1.y);
    //      graphics.curveTo(edgeCntrl1.x,edgeCntrl1.y,end.x,end.y);
    //      graphics.curveTo(edgeCntrl2.x,edgeCntrl2.y,edge2.x,edge2.y);
    //      graphics.lineTo(inter2.x,inter2.y);
    //      graphics.lineTo(start2.x,start2.y);
    //      graphics.lineTo(start1.x,start1.y);

    //      log.debug("moveTo"+start1.x+","+start1.y);
    //      log.debug("lineTo"+inter1.x+","+inter1.y);
    //      log.debug("lineTo"+edge1.x+","+edge1.y);
    //      log.debug("quadTo"+edgeCntrl1.x+","+edgeCntrl1.y+","+end.x+","+end.y);
    //      log.debug("quadTo"+edgeCntrl2.x+","+edgeCntrl2.y+","+edge2.x+","+edge2.y);
    //      log.debug("lineTo"+inter2.x+","+inter2.y);
    //      log.debug("lineTo"+start2.x+","+start2.y);
    //      log.debug("lineTo"+start1.x+","+start1.y);

    GeneralPath graphics = new GeneralPath();
    graphics.moveTo(start1.x, start1.y);
    graphics.lineTo(inter1.x, inter1.y);
    graphics.lineTo(edge1.x, edge1.y);
    graphics.quadTo(edgeCntrl1.x, edgeCntrl1.y, end.x, end.y);
    graphics.quadTo(edgeCntrl2.x, edgeCntrl2.y, edge2.x, edge2.y);
    graphics.lineTo(inter2.x, inter2.y);
    graphics.lineTo(start2.x, start2.y);
    graphics.lineTo(start1.x, start1.y);
    graphics.closePath();

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));
    g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    if (linecoler != null) {
        g2d.setPaint(linecoler);
        g2d.draw(graphics);
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fill(graphics);
    }

}

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private VisualPeakAnnotation generateOutline(IChromatogramDescriptor chromatogram,
        IPeakAnnotationDescriptor peakDescr, ADataset1D<IChromatogram1D, IScan> dataset, int seriesIndex) {
    boolean baselineAvailable = false;
    if (!(Double.isNaN(peakDescr.getBaselineStartIntensity())
            && Double.isNaN(peakDescr.getBaselineStopIntensity())
            && Double.isNaN(peakDescr.getBaselineStartTime())
            && Double.isNaN(peakDescr.getBaselineStopTime()))) {
        Logger.getLogger(getClass().getName()).warning("Using baseline for peak outline");
        baselineAvailable = true;/*w  w  w. j  a  v  a 2 s  . com*/
    }
    double sat = peakDescr.getApexTime();
    double peakStartTime = peakDescr.getStartTime();
    double peakStopTime = peakDescr.getStopTime();
    if (Double.isNaN(peakStartTime) || Double.isNaN(peakStopTime)) {
        return null;
    }
    int scan = chromatogram.getChromatogram().getIndexFor(sat);
    int startIdx = chromatogram.getChromatogram().getIndexFor(peakStartTime);
    int stopIdx = chromatogram.getChromatogram().getIndexFor(peakStopTime);
    double peakStartValue = peakDescr.getStartIntensity();
    double peakStopValue = peakDescr.getStopIntensity();
    double blStartTime, blStopTime, blStartVal, blStopVal;
    if (baselineAvailable) {
        blStartTime = peakDescr.getBaselineStartTime();
        blStopTime = peakDescr.getBaselineStopTime();
        blStartVal = peakDescr.getBaselineStartIntensity();
        blStopVal = peakDescr.getBaselineStopIntensity();
    } else {
        blStartTime = peakStartTime;
        blStopTime = peakStopTime;
        //FIXME baseline is not correctly shown
        if (Double.isNaN(peakDescr.getStartIntensity()) || Double.isNaN(peakDescr.getStopIntensity())) {
            blStartVal = dataset.getYValue(seriesIndex, startIdx);
            blStopVal = dataset.getYValue(seriesIndex, stopIdx);
        } else {
            blStartVal = dataset.getYValue(seriesIndex, startIdx);
            blStopVal = dataset.getYValue(seriesIndex, stopIdx);
        }
    }
    peakStartValue = dataset.getYValue(seriesIndex, startIdx);
    peakStopValue = dataset.getYValue(seriesIndex, stopIdx);
    double peakApexValue = dataset.getYValue(seriesIndex, scan);

    GeneralPath gp = new GeneralPath();
    gp.moveTo(blStartTime, dataset.getYValue(seriesIndex, startIdx) + blStartVal);
    gp.lineTo(peakStartTime, peakStartValue);
    for (int j = startIdx + 1; j <= stopIdx; j++) {
        gp.lineTo(dataset.getXValue(seriesIndex, j), dataset.getYValue(seriesIndex, j));
    }
    gp.lineTo(blStopTime, dataset.getYValue(seriesIndex, stopIdx) + blStopVal);
    gp.closePath();
    Logger.getLogger(getClass().getName()).log(Level.WARNING,
            "Generating peak outline: ({0};{1})({2};{3}" + ")" + "({4};{5})",
            new Object[] { peakStartTime, peakStartValue, sat, peakApexValue, peakStopTime, peakStopValue });
    VisualPeakAnnotation vpa = new VisualPeakAnnotation(gp,
            new Point2D.Double(sat, Math.min(peakStartValue, Math.min(peakApexValue, peakStopValue))),
            PeakAnnotationType.OUTLINE);//generate(peakStartTime, peakStartValue, sat, peakApexValue, peakStopTime, peakStopValue);
    return vpa;
}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Initialises the renderer./*  w  w  w.  j  a  v a 2 s  . co  m*/
 * <P>
 * This method will be called before the first item is rendered, giving the
 * renderer an opportunity to initialise any state information it wants to
 * maintain.  The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the dataset.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The renderer state.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset,
        PlotRenderingInfo info) {

    State state = new State(info, sampleDataset, plot, dataset, dataArea, shapeSize, lineWidth);
    state.series2Sample = new BitSet(dataset.getSeriesCount());
    for (int series = 0; series < dataset.getSeriesCount(); series++) {
        if ((getItemVisible(series, 0) && getItemShapeVisible(series, 0)) || getItemCreateEntity(series, 0)) {
            state.series2Sample.set(series);
        }
    }
    double dpi = 72;
    //        Integer dpiVal = (Integer) g2.getRenderingHint(HintKey.DPI);
    //        if (dpiVal != null) {
    //            dpi = dpiVal.intValue();
    //        }
    state.seriesPath = new GeneralPath();
    state.intervalPath = new GeneralPath();
    state.findVisiblePointsInDataset(plot, dataset);
    //state.dX = 72.0 / dpi;
    return state;
}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java

private void createGlyphsAndAddToPlot(XYPlot plot, double xScale, double yScale) {
    XYShapeAnnotation glyph;//from  www  .  java  2s . c om
    Shape glyphShape = null;
    Color glyphColor;

    //double glyphSize = 8.0;   //pixels

    double glyphIncrementX = (glyphSize * xScale) / 2.0;
    double glyphIncrementY = (glyphSize * yScale) / 2.0;
    float gi_x = (float) glyphIncrementX;
    float gi_y = (float) glyphIncrementY;

    PatientData pd;

    double x, y;
    Double mriPctChange = null;
    for (ISPYPlotPoint corrPoint : dataPoints) {

        x = corrPoint.getX();
        y = corrPoint.getY();

        mriPctChange = corrPoint.getMRITumorPctChange();

        if (mriPctChange == null) {
            //data is missing
            Rectangle2D.Double rect = new Rectangle2D.Double();
            //rect.setFrameFromCenter(x,y, x+1.25,y+1.25);
            rect.setFrameFromCenter(x, y, x + glyphIncrementX, y + glyphIncrementY);
            glyphShape = rect;
        } else if (mriPctChange <= -30.0) {

            //tumor shrank by more than 30% (down arrow)
            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;

            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf - gi_x, yf + gi_y);
            gp.lineTo(xf + gi_x, yf + gi_y);
            gp.closePath();
            glyphShape = gp;
        } else if (mriPctChange > 0.0) {
            //tumor size increased (up arrow)

            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;
            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf + gi_x, yf - gi_y);
            gp.lineTo(xf - gi_x, yf - gi_y);
            gp.closePath();
            glyphShape = gp;

            //            Ellipse2D.Double circle = new Ellipse2D.Double();
            //            circle.setFrameFromCenter(x,y, x+2, y+2);

        } else if ((mriPctChange > -30.0) && (mriPctChange <= 0.0)) {
            //no change or reduction in tumor size but less than 30% reduction
            Ellipse2D.Double circle = new Ellipse2D.Double();
            //circle.setFrameFromCenter(x,y,x+1.25,y+1.25);
            circle.setFrameFromCenter(x, y, x + gi_x, y + gi_y);
            glyphShape = circle;

        }

        //glyphColor = Color.BLUE; 
        //later can set color based on 
        glyphColor = getColorForDataPoint(corrPoint);

        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);

        String tooltip = corrPoint.getTag();

        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }

}

From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java

/**
 * Initialises the renderer./*from w  w  w  .  j  a  v a  2 s .  c  o m*/
 * <P>
 * This method will be called before the first item is rendered, giving the renderer an opportunity to initialise
 * any state information it wants to maintain. The renderer can do nothing if it chooses.
 *
 * @param g2
 *            the graphics device.
 * @param dataArea
 *            the area inside the axes.
 * @param plot
 *            the plot.
 * @param data
 *            the data.
 * @param info
 *            an optional info collection object to return data back to the caller.
 *
 * @return The renderer state.
 */
@Override
public XYItemRendererState initialise(final Graphics2D g2, final Rectangle2D dataArea, final XYPlot plot,
        final XYDataset data, final PlotRenderingInfo info) {

    final State state = new State(info);
    state.seriesPath = new GeneralPath();
    state.seriesIndex = -1;
    return state;

}

From source file:edu.dlnu.liuwenpeng.render.XYLineAndShapeRenderer.java

/**    
* Initialises the renderer.    /*  w  w  w .  ja v  a  2s.c  o m*/
* <P>    
* This method will be called before the first item is rendered, giving the    
* renderer an opportunity to initialise any state information it wants to    
* maintain.  The renderer can do nothing if it chooses.    
*    
* @param g2  the graphics device.    
* @param dataArea  the area inside the axes.    
* @param plot  the plot.    
* @param data  the data.    
* @param info  an optional info collection object to return data back to    
*              the caller.    
*    
* @return The renderer state.    
*/
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data,
        PlotRenderingInfo info) {

    State state = new State(info);
    state.seriesPath = new GeneralPath();
    return state;

}