Example usage for org.jfree.chart.plot IntervalMarker setEndValue

List of usage examples for org.jfree.chart.plot IntervalMarker setEndValue

Introduction

In this page you can find the example usage for org.jfree.chart.plot IntervalMarker setEndValue.

Prototype

public void setEndValue(double value) 

Source Link

Document

Sets the end value for the marker and sends a MarkerChangeEvent to all registered listeners.

Usage

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static Pair<String, XYSeriesCollection> adjustTime(XYSeriesCollection chartsCollection,
        Collection<IntervalMarker> markers) {
    int maxTime = 0;
    for (int i = 0; i < chartsCollection.getSeriesCount(); i++) {
        XYSeries series = chartsCollection.getSeries(i);
        for (int j = 0; j < series.getItemCount(); j++) {
            int x = series.getX(j).intValue();
            if (x > maxTime) {
                maxTime = x;/*  w  ww . j a  v  a  2  s  .c o  m*/
            }
        }
    }

    String type = "ms";
    int div = 1;

    if (maxTime > 10 * 60 * 1000) {
        div = 60 * 1000;
        type = "min";
    }

    if (maxTime > 30 * 1000) {
        div = 1000;
        type = "sec";
    }

    XYSeriesCollection result = new XYSeriesCollection();

    for (int i = 0; i < chartsCollection.getSeriesCount(); i++) {

        XYSeries old = chartsCollection.getSeries(i);
        XYSeries series = new XYSeries(old.getKey(), old.getAutoSort(), old.getAllowDuplicateXValues());
        for (int j = 0; j < old.getItemCount(); j++) {
            Number x = old.getX(j).doubleValue() / div;
            Number y = old.getY(j);
            series.add(x, y);
        }

        result.addSeries(series);
    }

    if (markers != null) {
        for (IntervalMarker marker : markers) {
            marker.setStartValue(marker.getStartValue() / div);
            marker.setEndValue(marker.getEndValue() / div);
        }
    }

    return Pair.of(type, result);
}

From source file:ch.algotrader.client.chart.ChartTab.java

@SuppressWarnings("unchecked")
public void updateData(ChartDataVO chartData) {

    resetAxis();//  ww w  . j  a v a  2 s.com

    // add/update indicators
    for (IndicatorVO indicator : chartData.getIndicators()) {

        RegularTimePeriod timePeriod = getRegularTimePeriod(indicator.getDateTime());
        TimeSeries series = this.indicators.get(indicator.getName());

        if (series != null) {
            series.addOrUpdate(timePeriod, indicator.getValue());
        }
    }

    // add/update bars
    for (BarVO bar : chartData.getBars()) {

        OHLCSeries series = this.bars.get(bar.getSecurityId());

        if (series != null) {

            // remove a value if it already exists
            RegularTimePeriod timePeriod = getRegularTimePeriod(bar.getDateTime());
            if (series.indexOf(timePeriod) >= 0) {
                series.remove(timePeriod);
            }
            series.add(timePeriod, bar.getOpen().doubleValue(), bar.getHigh().doubleValue(),
                    bar.getLow().doubleValue(), bar.getClose().doubleValue());
        }
    }

    // make all invisible since they might not currently have a value
    for (Marker marker : this.markers.values()) {
        marker.setAlpha(0);
    }

    // update markers
    for (MarkerVO markerVO : chartData.getMarkers()) {

        Marker marker = this.markers.get(markerVO.getName());
        Boolean selected = this.markersSelectionStatus.get(markerVO.getName());
        String name = marker.getLabel().split(":")[0];
        if (marker instanceof ValueMarker && markerVO instanceof ValueMarkerVO) {

            ValueMarker valueMarker = (ValueMarker) marker;
            ValueMarkerVO valueMarkerVO = (ValueMarkerVO) markerVO;
            valueMarker.setValue(valueMarkerVO.getValue());
            marker.setLabel(name + ": " + valueMarkerVO.getValue());
            marker.setAlpha(selected ? 1.0f : 0.0f);

        } else if (marker instanceof IntervalMarker && markerVO instanceof IntervalMarkerVO) {

            IntervalMarker intervalMarker = (IntervalMarker) marker;
            IntervalMarkerVO intervalMarkerVO = (IntervalMarkerVO) markerVO;
            intervalMarker.setStartValue(intervalMarkerVO.getStartValue());
            intervalMarker.setEndValue(intervalMarkerVO.getEndValue());
            marker.setLabel(
                    name + ": " + intervalMarkerVO.getStartValue() + " - " + intervalMarkerVO.getEndValue());
            marker.setAlpha(selected ? 0.5f : 0.0f);

        } else {
            throw new RuntimeException(marker.getClass() + " does not match " + markerVO.getClass());
        }
    }

    // update annotations
    for (AnnotationVO annotationVO : chartData.getAnnotations()) {

        AbstractXYAnnotation annotation;
        if (annotationVO instanceof PointerAnnotationVO) {

            PointerAnnotationVO pointerAnnotationVO = (PointerAnnotationVO) annotationVO;
            XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(pointerAnnotationVO.getText(),
                    pointerAnnotationVO.getDateTime().getTime(), pointerAnnotationVO.getValue(),
                    3.926990816987241D);
            pointerAnnotation.setTipRadius(0);
            pointerAnnotation.setBaseRadius(20);
            pointerAnnotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
            pointerAnnotation.setFont(new Font("SansSerif", 0, 9));
            pointerAnnotation.setToolTipText("<html>" + formatter.format(pointerAnnotationVO.getDateTime())
                    + "<br>" + pointerAnnotationVO.getValue() + "</html>");

            annotation = pointerAnnotation;

        } else if (annotationVO instanceof BoxAnnotationVO) {

            BoxAnnotationVO boxAnnotationVO = (BoxAnnotationVO) annotationVO;
            XYBoxAnnotation boxAnnotation = new XYBoxAnnotation(boxAnnotationVO.getStartDateTime().getTime(),
                    boxAnnotationVO.getStartValue(), boxAnnotationVO.getEndDateTime().getTime(),
                    boxAnnotationVO.getEndValue(), null, null, new java.awt.Color(0, 0, 0, 60));
            boxAnnotation.setToolTipText("<html>" + formatter.format(boxAnnotationVO.getStartDateTime()) + " - "
                    + formatter.format(boxAnnotationVO.getEndDateTime()) + "<br>"
                    + boxAnnotationVO.getStartValue() + " - " + boxAnnotationVO.getEndValue() + "</html>");

            annotation = boxAnnotation;
        } else {
            throw new RuntimeException("unkown annotation type" + annotationVO.getClass());
        }

        if (!getPlot().getAnnotations().contains(annotation)) {
            getPlot().addAnnotation(annotation);
        }
    }

    // update description
    for (Title title : (List<Title>) this.getChart().getSubtitles()) {
        if (title instanceof TextTitle) {
            TextTitle textTitle = ((TextTitle) title);
            if (chartData.getDescription() != null && !("".equals(chartData.getDescription()))) {
                textTitle.setText(chartData.getDescription());
                textTitle.setVisible(true);
            } else {
                textTitle.setVisible(false);
            }
        }
    }

    initAxis();
}

From source file:com.griddynamics.jagger.monitoring.reporting.SystemUnderTestPlotsGeneralProvider.java

public Map<String, List<MonitoringReporterData>> createTaskPlots() {
    log.info("BEGIN: Create general task plots");

    Map<String, List<MonitoringReporterData>> taskPlots = new LinkedHashMap<String, List<MonitoringReporterData>>();
    GeneralStatistics generalStatistics = getStatistics();

    Set<String> taskIds = generalStatistics.findTaskIds();
    Set<String> boxIdentifiers = generalStatistics.findBoxIdentifiers();
    Set<String> sutUrls = generalStatistics.findSutUrls();
    for (GroupKey groupName : plotGroups.getPlotGroups().keySet()) {
        log.info("    Create general task plots for group '{}'", groupName);

        if (showPlotsByGlobal) {
            log.info("        Create general global task plots");

            List<MonitoringReporterData> plots = new LinkedList<MonitoringReporterData>();
            XYSeriesCollection chartsCollection = new XYSeriesCollection();
            LinkedHashMap<String, IntervalMarker> markers = new LinkedHashMap<String, IntervalMarker>();
            for (MonitoringParameter parameterId : plotGroups.getPlotGroups().get(groupName)) {
                log.info("            Create general global task plots for parameter '{}'", parameterId);

                MonitoringParameterBean param = MonitoringParameterBean.copyOf(parameterId);
                if (generalStatistics.hasGlobalStatistics(param)) {
                    XYSeries values = new XYSeries(param.getDescription());
                    long timeShift = 0;
                    int taskNum = 0;
                    for (String taskId : taskIds) {
                        log.info("                Create general global task plots for task '{}'", taskId);

                        long maxTime = 0;
                        for (MonitoringStatistics monitoringStatistics : generalStatistics
                                .findGlobalStatistics(taskId, param)) {
                            long time = monitoringStatistics.getTime();
                            double t = timeShift + time;
                            values.add(t, monitoringStatistics.getAverageValue());

                            if (time > maxTime) {
                                maxTime = time;
                            }//w  w  w  .j ava 2  s.com

                            if (showNumbers) {
                                IntervalMarker marker = markers.get(taskId);
                                if (marker == null) {
                                    marker = new IntervalMarker(t, t);
                                    marker.setLabel(monitoringStatistics.getTaskData().getNumber().toString());
                                    marker.setAlpha((taskNum % 2 == 0) ? 0.2f : 0.4f);

                                    int mod = taskNum % 3;
                                    if (mod == 0) {
                                        marker.setLabelAnchor(RectangleAnchor.CENTER);
                                    } else if (mod == 1) {
                                        marker.setLabelAnchor(RectangleAnchor.TOP);
                                    } else if (mod == 2) {
                                        marker.setLabelAnchor(RectangleAnchor.BOTTOM);
                                    }

                                    marker.setLabelFont(
                                            marker.getLabelFont().deriveFont(10.0f).deriveFont(Font.BOLD));
                                    markers.put(taskId, marker);
                                } else {
                                    if (t < marker.getStartValue()) {
                                        marker.setStartValue(t);
                                    }
                                    if (t > marker.getEndValue()) {
                                        marker.setEndValue(t);
                                    }
                                }
                            }
                        }
                        timeShift += maxTime;
                        taskNum++;
                    }
                    if (values.isEmpty()) {
                        values.add(0, 0);
                    }
                    chartsCollection.addSeries(values);
                }
            }

            log.debug("group name \n{} \nparams {}]\n", groupName,
                    Lists.newArrayList(plotGroups.getPlotGroups().get(groupName)));

            Pair<String, XYSeriesCollection> pair = ChartHelper.adjustTime(chartsCollection, markers.values());

            chartsCollection = pair.getSecond();

            String name = groupName.getUpperName();

            if (chartsCollection.getSeriesCount() > 0) {
                JFreeChart chart = ChartHelper.createXYChart(null, chartsCollection,
                        "Time (" + pair.getFirst() + ")", groupName.getLeftName(), 0, 1,
                        ChartHelper.ColorTheme.LIGHT);

                XYPlot plot = (XYPlot) chart.getPlot();
                for (IntervalMarker marker : markers.values()) {
                    plot.addDomainMarker(marker);
                }

                MonitoringReporterData monitoringReporterData = new MonitoringReporterData();
                monitoringReporterData.setParameterName(name);
                monitoringReporterData.setTitle(name);
                monitoringReporterData.setPlot(new JCommonDrawableRenderer(chart));
                plots.add(monitoringReporterData);
            }

            if (!plots.isEmpty()) {
                taskPlots.put(name, plots);
            }
        }

        if (showPlotsByBox) {
            log.info("        Create general box task plots");

            for (String boxIdentifier : boxIdentifiers) {
                log.info("            Create general box task plots for box '{}'", boxIdentifier);

                List<MonitoringReporterData> plots = new LinkedList<MonitoringReporterData>();
                XYSeriesCollection chartsCollection = new XYSeriesCollection();
                LinkedHashMap<String, IntervalMarker> markers = new LinkedHashMap<String, IntervalMarker>();
                for (MonitoringParameter parameterId : plotGroups.getPlotGroups().get(groupName)) {
                    log.info("                Create general box task plots for parameter '{}'", parameterId);

                    MonitoringParameterBean param = MonitoringParameterBean.copyOf(parameterId);
                    if (generalStatistics.hasBoxStatistics(param, boxIdentifier)) {
                        XYSeries values = new XYSeries(param.getDescription());
                        long timeShift = 0;
                        int taskNum = 0;
                        for (String taskId : taskIds) {
                            log.info("                    Create general box task plots for task '{}'", taskId);

                            long maxTime = 0;
                            for (MonitoringStatistics monitoringStatistics : generalStatistics
                                    .findBoxStatistics(taskId, param, boxIdentifier)) {
                                long time = monitoringStatistics.getTime();
                                double t = timeShift + time;
                                values.add(t, monitoringStatistics.getAverageValue());

                                if (time > maxTime) {
                                    maxTime = time;
                                }

                                if (showNumbers) {
                                    IntervalMarker marker = markers.get(taskId);
                                    if (marker == null) {
                                        marker = new IntervalMarker(t, t);
                                        marker.setLabel(
                                                monitoringStatistics.getTaskData().getNumber().toString());
                                        marker.setAlpha((taskNum % 2 == 0) ? 0.2f : 0.4f);

                                        int mod = taskNum % 3;
                                        if (mod == 0) {
                                            marker.setLabelAnchor(RectangleAnchor.CENTER);
                                        } else if (mod == 1) {
                                            marker.setLabelAnchor(RectangleAnchor.TOP);
                                        } else if (mod == 2) {
                                            marker.setLabelAnchor(RectangleAnchor.BOTTOM);
                                        }

                                        marker.setLabelFont(
                                                marker.getLabelFont().deriveFont(10.0f).deriveFont(Font.BOLD));
                                        markers.put(taskId, marker);
                                    } else {
                                        if (t < marker.getStartValue()) {
                                            marker.setStartValue(t);
                                        }
                                        if (t > marker.getEndValue()) {
                                            marker.setEndValue(t);
                                        }
                                    }
                                }
                            }
                            timeShift += maxTime;
                            taskNum++;
                        }
                        if (values.isEmpty()) {
                            values.add(0, 0);
                        }
                        chartsCollection.addSeries(values);
                    }
                }

                log.debug("group name \n{} \nparams {}]\n", groupName,
                        Lists.newArrayList(plotGroups.getPlotGroups().get(groupName)));

                Pair<String, XYSeriesCollection> pair = ChartHelper.adjustTime(chartsCollection,
                        markers.values());

                chartsCollection = pair.getSecond();

                String name = groupName.getUpperName() + " on " + boxIdentifier;

                if (chartsCollection.getSeriesCount() > 0) {
                    JFreeChart chart = ChartHelper.createXYChart(null, chartsCollection,
                            "Time (" + pair.getFirst() + ")", groupName.getLeftName(), 0, 1,
                            ChartHelper.ColorTheme.LIGHT);

                    XYPlot plot = (XYPlot) chart.getPlot();
                    for (IntervalMarker marker : markers.values()) {
                        plot.addDomainMarker(marker);
                    }

                    MonitoringReporterData monitoringReporterData = new MonitoringReporterData();
                    monitoringReporterData.setParameterName(name);
                    monitoringReporterData.setTitle(name);
                    monitoringReporterData.setPlot(new JCommonDrawableRenderer(chart));
                    plots.add(monitoringReporterData);
                }

                if (!plots.isEmpty()) {
                    taskPlots.put(name, plots);
                }
            }
        }

        if (showPlotsBySuT) {
            log.info("        Create general sut task plots");

            for (String sutUrl : sutUrls) {
                log.info("            Create general sut task plots for sut '{}'", sutUrl);

                List<MonitoringReporterData> plots = new LinkedList<MonitoringReporterData>();
                XYSeriesCollection chartsCollection = new XYSeriesCollection();
                LinkedHashMap<String, IntervalMarker> markers = new LinkedHashMap<String, IntervalMarker>();
                for (MonitoringParameter parameterId : plotGroups.getPlotGroups().get(groupName)) {
                    log.info("                Create general sut task plots for parameter '{}'", parameterId);

                    MonitoringParameterBean param = MonitoringParameterBean.copyOf(parameterId);
                    if (generalStatistics.hasSutStatistics(param, sutUrl)) {
                        XYSeries values = new XYSeries(param.getDescription());
                        long timeShift = 0;
                        int taskNum = 0;
                        for (String taskId : taskIds) {
                            log.info("                    Create general sut task plots for task '{}'", taskId);

                            long maxTime = 0;
                            for (MonitoringStatistics monitoringStatistics : generalStatistics
                                    .findSutStatistics(taskId, param, sutUrl)) {
                                long time = monitoringStatistics.getTime();
                                double t = timeShift + time;
                                values.add(t, monitoringStatistics.getAverageValue());

                                if (time > maxTime) {
                                    maxTime = time;
                                }

                                if (showNumbers) {
                                    IntervalMarker marker = markers.get(taskId);
                                    if (marker == null) {
                                        marker = new IntervalMarker(t, t);
                                        marker.setLabel(
                                                monitoringStatistics.getTaskData().getNumber().toString());
                                        marker.setAlpha((taskNum % 2 == 0) ? 0.2f : 0.4f);

                                        int mod = taskNum % 3;
                                        if (mod == 0) {
                                            marker.setLabelAnchor(RectangleAnchor.CENTER);
                                        } else if (mod == 1) {
                                            marker.setLabelAnchor(RectangleAnchor.TOP);
                                        } else if (mod == 2) {
                                            marker.setLabelAnchor(RectangleAnchor.BOTTOM);
                                        }

                                        marker.setLabelFont(
                                                marker.getLabelFont().deriveFont(10.0f).deriveFont(Font.BOLD));
                                        markers.put(taskId, marker);
                                    } else {
                                        if (t < marker.getStartValue()) {
                                            marker.setStartValue(t);
                                        }
                                        if (t > marker.getEndValue()) {
                                            marker.setEndValue(t);
                                        }
                                    }
                                }
                            }
                            timeShift += maxTime;
                            taskNum++;
                        }
                        if (values.isEmpty()) {
                            values.add(0, 0);
                        }
                        chartsCollection.addSeries(values);
                    }
                }

                log.debug("group name \n{} \nparams {}]\n", groupName,
                        Lists.newArrayList(plotGroups.getPlotGroups().get(groupName)));

                Pair<String, XYSeriesCollection> pair = ChartHelper.adjustTime(chartsCollection,
                        markers.values());

                chartsCollection = pair.getSecond();

                String name = groupName.getUpperName() + " on " + sutUrl;

                if (chartsCollection.getSeriesCount() > 0) {
                    JFreeChart chart = ChartHelper.createXYChart(null, chartsCollection,
                            "Time (" + pair.getFirst() + ")", groupName.getLeftName(), 0, 1,
                            ChartHelper.ColorTheme.LIGHT);

                    XYPlot plot = (XYPlot) chart.getPlot();
                    for (IntervalMarker marker : markers.values()) {
                        plot.addDomainMarker(marker);
                    }

                    MonitoringReporterData monitoringReporterData = new MonitoringReporterData();
                    monitoringReporterData.setParameterName(name);
                    monitoringReporterData.setTitle(name);
                    monitoringReporterData.setPlot(new JCommonDrawableRenderer(chart));
                    plots.add(monitoringReporterData);
                }

                if (!plots.isEmpty()) {
                    taskPlots.put(name, plots);
                }
            }
        }
    }

    clearStatistics();

    log.info("END: Create general task plots");

    return taskPlots;
}