Example usage for org.jfree.chart.plot XYPlot removeAnnotation

List of usage examples for org.jfree.chart.plot XYPlot removeAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot removeAnnotation.

Prototype

public boolean removeAnnotation(XYAnnotation annotation) 

Source Link

Document

Removes an annotation from the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.att.aro.ui.view.diagnostictab.plot.AlarmPlot.java

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    if (analysis == null) {
        logger.info("analysis data is null");
    } else {//from w  ww .  j a  v a 2 s  .  c o  m
        alarmDataCollection.removeAllSeries();
        pointerAnnotation.clear();

        TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
        if (resultType.equals(TraceResultType.TRACE_FILE)) {
            logger.info("didn't get analysis trace data!");

        } else {
            // Remove old annotation from previous plots
            Iterator<XYPointerAnnotation> pointers = pointerAnnotation.iterator();
            while (pointers.hasNext()) {
                plot.removeAnnotation(pointers.next());
            }

            for (AlarmType eventType : AlarmType.values()) {
                XYIntervalSeries series = new XYIntervalSeries(eventType);
                seriesMap.put(eventType, series);
                alarmDataCollection.addSeries(series);
            }
            TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult()
                    .getTraceresult();
            List<AlarmInfo> alarmInfos = traceresult.getAlarmInfos();
            List<ScheduledAlarmInfo> pendingAlarms = getHasFiredAlarms(traceresult.getScheduledAlarms());
            Iterator<ScheduledAlarmInfo> iterPendingAlarms = pendingAlarms.iterator();
            double firedTime = 0;
            while (iterPendingAlarms.hasNext()) {
                ScheduledAlarmInfo scheduledEvent = iterPendingAlarms.next();
                AlarmType pendingAlarmType = scheduledEvent.getAlarmType();
                if (pendingAlarmType != null) {
                    firedTime = (scheduledEvent.getTimeStamp() - scheduledEvent.getRepeatInterval()) / 1000;
                    seriesMap.get(pendingAlarmType).add(firedTime, firedTime, firedTime, 1, 0.8, 1);
                    eventMapPending.put(firedTime, scheduledEvent);
                    // logger.fine("populateAlarmScheduledPlot type:\n" +
                    // pendingAlarmType
                    // + "\ntime " + scheduledEvent.getTimeStamp()
                    // + "\nrepeating " + firedTime);
                }
            }

            Iterator<AlarmInfo> iter = alarmInfos.iterator();
            while (iter.hasNext()) {
                AlarmInfo currEvent = iter.next();
                if (currEvent != null) {
                    AlarmType alarmType = currEvent.getAlarmType();
                    if (alarmType != null) {
                        firedTime = currEvent.getTimeStamp() / 1000;

                        /*
                         * Catching any alarms align to quanta as being
                         * inexactRepeating alarms
                         */
                        if ((currEvent.getTimestampElapsed() / 1000) % 900 < 1) {
                            seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.7);

                            // Adding an arrow to mark these
                            // inexactRepeating alarms
                            XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(alarmType.name(),
                                    firedTime, 0.6, 3.92699082D);
                            xypointerannotation.setBaseRadius(20D);
                            xypointerannotation.setTipRadius(1D);
                            pointerAnnotation.add(xypointerannotation);
                            plot.addAnnotation(xypointerannotation);

                            // logger.info("SetInexactRepeating alarm type: "
                            // + alarmType
                            // + " time " + firedTime
                            // + " epoch " + currEvent.getTimestampEpoch()
                            // + " elapsed:\n" +
                            // currEvent.getTimestampElapsed()/1000);
                        } else {
                            seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.5);
                        }
                        eventMap.put(firedTime, currEvent);
                    }
                }
            }
            XYItemRenderer renderer = plot.getRenderer();
            renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC_WAKEUP), Color.red);

            renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC), Color.pink);

            renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME_WAKEUP), Color.blue);

            renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME), Color.cyan);

            renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.UNKNOWN), Color.black);

            // Assign ToolTip to renderer
            renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
                @Override
                public String generateToolTip(XYDataset dataset, int series, int item) {
                    AlarmInfo info = eventMap.get(dataset.getX(series, item));
                    Date epochTime = new Date();
                    if (info != null) {

                        epochTime.setTime((long) info.getTimestampEpoch());

                        StringBuffer displayInfo = new StringBuffer(
                                ResourceBundleHelper.getMessageString("alarm.tooltip.prefix"));
                        displayInfo.append(MessageFormat.format(
                                ResourceBundleHelper.getMessageString("alarm.tooltip.content"),
                                info.getAlarmType(), info.getTimeStamp() / 1000, epochTime.toString()));
                        if ((info.getTimestampElapsed() / 1000) % 900 < 1) {
                            displayInfo.append(
                                    ResourceBundleHelper.getMessageString("alarm.tooltip.setInexactRepeating"));
                        }
                        displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix"));
                        return displayInfo.toString();
                    }
                    ScheduledAlarmInfo infoPending = eventMapPending.get(dataset.getX(series, item));
                    if (infoPending != null) {

                        epochTime.setTime(
                                (long) (infoPending.getTimestampEpoch() - infoPending.getRepeatInterval()));

                        StringBuffer displayInfo = new StringBuffer(
                                ResourceBundleHelper.getMessageString("alarm.tooltip.prefix"));
                        displayInfo.append(MessageFormat.format(
                                ResourceBundleHelper.getMessageString("alarm.tooltip.contentWithName"),
                                infoPending.getAlarmType(),
                                (infoPending.getTimeStamp() - infoPending.getRepeatInterval()) / 1000,
                                epochTime.toString(), infoPending.getApplication(),
                                infoPending.getRepeatInterval() / 1000));
                        displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix"));
                        return displayInfo.toString();
                    }
                    return null;
                }
            });

        }
    }
    plot.setDataset(alarmDataCollection);
    //      return plot;
}

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

@SuppressWarnings("unchecked")
public void redrawSelectedPlots() {

    if (syncedOption.getSyncWhat().isSync() && !getSelectionChanging()) {
        XYPlot xyplot = getChart().getXYPlot();

        //         curationControls.setSyncedState(true);

        Double yscale = (xyplot.getRangeAxis().getUpperBound() - xyplot.getRangeAxis().getLowerBound()) / 50;
        Double xscale = (xyplot.getDomainAxis().getUpperBound() - xyplot.getDomainAxis().getLowerBound()) / 50;

        Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3 },
                0);//from   w  w  w .  j a  va2  s.  c  o  m
        Paint paint = Color.RED;

        for (Annotation anno : (List<Annotation>) xyplot.getAnnotations()) {
            if (anno != intervalAnnotation && anno instanceof XYShapeAnnotation) {
                xyplot.removeAnnotation((XYShapeAnnotation) anno);
            }
        }

        for (Point2D point : selectedPoints) {
            double x = point.getX();
            double y = point.getY();

            double y1 = y - yscale;
            double y2 = y + yscale;
            double x1 = x - xscale;
            double x2 = x + xscale;

            Ellipse2D oval = new Ellipse2D.Double(x1, y1, x2 - x1, y2 - y1);

            XYShapeAnnotation lineanno0 = new XYShapeAnnotation(oval, stroke, paint);
            addRangeMarker(lineanno0);
        }
    }
    curationControls.updateButtons();
}

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
 * Creating Alarm triggered data for graph plot
 *//*from   w  w w . j a  v a  2 s  . c  o m*/
private static void populateAlarmPlot(XYPlot plot, TraceData.Analysis analysis) {

    final XYIntervalSeriesCollection alarmDataCollection = new XYIntervalSeriesCollection();
    if (analysis != null) {

        // Remove old annotation from previous plots
        Iterator<XYPointerAnnotation> pointers = pointerAnnotation.iterator();
        while (pointers.hasNext()) {
            plot.removeAnnotation(pointers.next());
        }
        pointerAnnotation.clear();

        final Map<AlarmType, XYIntervalSeries> seriesMap = new EnumMap<AlarmType, XYIntervalSeries>(
                AlarmType.class);
        for (AlarmType eventType : AlarmType.values()) {
            XYIntervalSeries series = new XYIntervalSeries(eventType);
            seriesMap.put(eventType, series);
            alarmDataCollection.addSeries(series);
        }
        final List<AlarmInfo> alarmInfos = analysis.getAlarmInfos();
        final Map<Double, AlarmInfo> eventMap = new HashMap<Double, AlarmInfo>();
        final Map<Double, ScheduledAlarmInfo> eventMapPending = new HashMap<Double, ScheduledAlarmInfo>();
        List<ScheduledAlarmInfo> pendingAlarms = getHasFiredAlarms(analysis.getScheduledAlarms());
        Iterator<ScheduledAlarmInfo> iterPendingAlarms = pendingAlarms.iterator();
        double firedTime = 0;
        while (iterPendingAlarms.hasNext()) {
            ScheduledAlarmInfo scheduledEvent = iterPendingAlarms.next();
            AlarmType pendingAlarmType = scheduledEvent.getAlarmType();
            if (pendingAlarmType != null) {
                firedTime = (scheduledEvent.getTimeStamp() - scheduledEvent.getRepeatInterval()) / 1000;
                seriesMap.get(pendingAlarmType).add(firedTime, firedTime, firedTime, 1, 0.8, 1);
                eventMapPending.put(firedTime, scheduledEvent);
                logger.fine("populateAlarmScheduledPlot type:\n" + pendingAlarmType + "\ntime "
                        + scheduledEvent.getTimeStamp() + "\nrepeating " + firedTime);
            }
        }

        Iterator<AlarmInfo> iter = alarmInfos.iterator();
        while (iter.hasNext()) {
            AlarmInfo currEvent = iter.next();
            if (currEvent != null) {
                AlarmType alarmType = currEvent.getAlarmType();
                if (alarmType != null) {
                    firedTime = currEvent.getTimeStamp() / 1000;

                    /*
                     * Catching any alarms align to quanta as being
                     * inexactRepeating alarms
                     */
                    if ((currEvent.getTimestampElapsed() / 1000) % 900 < 1) {
                        seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.7);

                        // Adding an arrow to mark these inexactRepeating alarms
                        XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(alarmType.name(),
                                firedTime, 0.6, 3.92699082D);
                        xypointerannotation.setBaseRadius(20D);
                        xypointerannotation.setTipRadius(1D);
                        pointerAnnotation.add(xypointerannotation);
                        plot.addAnnotation(xypointerannotation);

                        logger.info("SetInexactRepeating alarm type: " + alarmType + " time " + firedTime
                                + " epoch " + currEvent.getTimestampEpoch() + " elapsed:\n"
                                + currEvent.getTimestampElapsed() / 1000);
                    } else {
                        seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.5);
                    }
                    eventMap.put(firedTime, currEvent);
                }
            }
        }
        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC_WAKEUP), Color.red);

        renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC), Color.pink);

        renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME_WAKEUP), Color.blue);

        renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME), Color.cyan);

        renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.UNKNOWN), Color.black);

        // Assign ToolTip to renderer
        renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {
                AlarmInfo info = eventMap.get(dataset.getX(series, item));
                Date epochTime = new Date();
                if (info != null) {

                    epochTime.setTime((long) info.getTimestampEpoch());

                    StringBuffer displayInfo = new StringBuffer(rb.getString("alarm.tooltip.prefix"));
                    displayInfo.append(MessageFormat.format(rb.getString("alarm.tooltip.content"),
                            info.getAlarmType(), info.getTimeStamp() / 1000, epochTime.toString()));
                    if ((info.getTimestampElapsed() / 1000) % 900 < 1) {
                        displayInfo.append(rb.getString("alarm.tooltip.setInexactRepeating"));
                    }
                    displayInfo.append(rb.getString("alarm.tooltip.suffix"));
                    return displayInfo.toString();
                }
                ScheduledAlarmInfo infoPending = eventMapPending.get(dataset.getX(series, item));
                if (infoPending != null) {

                    epochTime.setTime(
                            (long) (infoPending.getTimestampEpoch() - infoPending.getRepeatInterval()));

                    StringBuffer displayInfo = new StringBuffer(rb.getString("alarm.tooltip.prefix"));
                    displayInfo.append(MessageFormat.format(rb.getString("alarm.tooltip.contentWithName"),
                            infoPending.getAlarmType(),
                            (infoPending.getTimeStamp() - infoPending.getRepeatInterval()) / 1000,
                            epochTime.toString(), infoPending.getApplication(),
                            infoPending.getRepeatInterval() / 1000));
                    displayInfo.append(rb.getString("alarm.tooltip.suffix"));
                    return displayInfo.toString();
                }
                return null;
            }
        });

    }

    plot.setDataset(alarmDataCollection);
}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * A demonstration application showing a candlestick chart.
 * /*from ww w . ja v a  2  s  . co m*/
 * @param title
 *            the frame title.
 * @param strategyData
 *            StrategyData
 */
public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) {

    this.strategyData = strategyData;
    this.setLayout(new BorderLayout());
    // Used to mark the current price
    stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0);
    valueMarker = new ValueMarker(0.00, Color.black, stroke);

    this.chart = createChart(this.strategyData, title, tradingday);

    BlockContainer container = new BlockContainer(new BorderArrangement());
    container.add(titleLegend1, RectangleEdge.LEFT);
    container.add(titleLegend2, RectangleEdge.RIGHT);
    container.add(new EmptyBlock(2000, 0));
    CompositeTitle legends = new CompositeTitle(container);
    legends.setPosition(RectangleEdge.BOTTOM);
    this.chart.addSubtitle(legends);

    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true, true);
    chartPanel.setRefreshBuffer(true);
    chartPanel.setDoubleBuffered(true);
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseMoved(ChartMouseEvent e) {
        }

        public void chartMouseClicked(final ChartMouseEvent e) {
            CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot();
            @SuppressWarnings("unchecked")
            List<XYPlot> subplots = combinedXYplot.getSubplots();
            if (e.getTrigger().getClickCount() == 2) {
                double xItem = 0;
                double yItem = 0;
                if (e.getEntity() instanceof XYItemEntity) {
                    XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity());
                    xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                    yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                } else {
                    PlotEntity plotEntity = ((PlotEntity) e.getEntity());
                    XYPlot plot = (XYPlot) plotEntity.getPlot();
                    xItem = plot.getDomainCrosshairValue();
                    yItem = plot.getRangeCrosshairValue();
                }

                for (XYPlot xyplot : subplots) {

                    double x = xyplot.getDomainCrosshairValue();
                    double y = xyplot.getRangeCrosshairValue();

                    /*
                     * If the cross hair is from a right-hand y axis we need
                     * to convert this to a left-hand y axis.
                     */
                    String rightAxisName = ", Price: ";
                    double rangeLowerLeft = 0;
                    double rangeUpperLeft = 0;
                    double rangeLowerRight = 0;
                    double rangeUpperRight = 0;
                    double yRightLocation = 0;
                    for (int index = 0; index < xyplot.getRangeAxisCount(); index++) {
                        AxisLocation axisLocation = xyplot.getRangeAxisLocation(index);
                        Range range = xyplot.getRangeAxis(index).getRange();

                        if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT)
                                || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) {
                            rangeLowerLeft = range.getLowerBound();
                            rangeUpperLeft = range.getUpperBound();
                            rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": ";
                        }
                        if (y >= range.getLowerBound() && y <= range.getUpperBound()
                                && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT)
                                        || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) {
                            rangeUpperRight = range.getUpperBound();
                            rangeLowerRight = range.getLowerBound();
                        }
                    }
                    if ((rangeUpperRight - rangeLowerRight) > 0) {
                        yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft)
                                * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight)));
                    } else {
                        yRightLocation = y;
                    }

                    String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName
                            + new Money(y);
                    if (x == xItem && y == yItem) {
                        titleLegend1.setText(text);
                        if (null == clickCrossHairs) {
                            clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation);
                            clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT);
                            xyplot.addAnnotation(clickCrossHairs);
                        } else {
                            clickCrossHairs.setText(text);
                            clickCrossHairs.setX(x);
                            clickCrossHairs.setY(yRightLocation);
                        }
                    }
                }
            } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) {
                for (XYPlot xyplot : subplots) {
                    if (xyplot.removeAnnotation(clickCrossHairs)) {
                        clickCrossHairs = null;
                        titleLegend1.setText(" Time: 0, Price :0.0");
                        break;
                    }
                }
            }
        }
    });
    this.add(chartPanel, null);
    this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this);
}