List of usage examples for org.jfree.chart.plot IntervalMarker getStartValue
public double getStartValue()
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;/*from ww w . j a va2s . 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
private void initAxis() { DateAxis domainAxis = (DateAxis) getPlot().getDomainAxis(); // configure the Date Axis (if startTime & endTime is set) if (this.chartDefinition.getStartTime() != null && this.chartDefinition.getEndTime() != null && !this.chartDefinition.getStartTime().equals(this.chartDefinition.getEndTime())) { // creat the SegmentedTimeline long startTime = this.chartDefinition.getStartTime().getTime(); long endTime = this.chartDefinition.getEndTime().getTime(); if (endTime == -3600000) { // adjust 00:00 endTime += 86400000;/*w ww . j a v a 2 s. c o m*/ } long segmentSize = 60 * 1000; // minute int segmentsIncluded = (int) (endTime - startTime) / (60 * 1000); int segmentsExcluded = 24 * 60 - segmentsIncluded; SegmentedTimeline timeline = new SegmentedTimeline(segmentSize, segmentsIncluded, segmentsExcluded); Date fromDate = domainAxis.getMinimumDate(); Date toDate = domainAxis.getMaximumDate(); long fromTime = fromDate.getTime(); long toTime = toDate.getTime(); // get year/month/day from fromTime and hour/minute from diagrm.startTime Date truncatedDate = DateUtils.truncate(fromDate, Calendar.DAY_OF_MONTH); Calendar truncatedCalendar = DateUtils.toCalendar(truncatedDate); Calendar startCalendar = DateUtils.toCalendar(this.chartDefinition.getStartTime()); truncatedCalendar.set(Calendar.HOUR_OF_DAY, startCalendar.get(Calendar.HOUR_OF_DAY)); truncatedCalendar.set(Calendar.MINUTE, startCalendar.get(Calendar.MINUTE)); timeline.setStartTime(truncatedCalendar.getTimeInMillis()); timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); timeline.addBaseTimelineExclusions(fromTime, toTime); timeline.setAdjustForDaylightSaving(true); domainAxis.setTimeline(timeline); } // make sure the markers are within the rangeAxis ValueAxis rangeAxis = getPlot().getRangeAxis(); for (Marker marker : this.markers.values()) { if (marker instanceof ValueMarker) { ValueMarker valueMarker = (ValueMarker) marker; if (marker.getAlpha() > 0 && valueMarker.getValue() != 0.0) { if (valueMarker.getValue() < rangeAxis.getLowerBound()) { rangeAxis.setLowerBound(valueMarker.getValue()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } if (valueMarker.getValue() > rangeAxis.getUpperBound()) { rangeAxis.setUpperBound(valueMarker.getValue()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } } } else { IntervalMarker intervalMarker = (IntervalMarker) marker; if (marker.getAlpha() > 0 && intervalMarker.getStartValue() != 0.0) { if (intervalMarker.getStartValue() < rangeAxis.getLowerBound()) { rangeAxis.setLowerBound(intervalMarker.getStartValue()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } if (intervalMarker.getEndValue() > rangeAxis.getUpperBound()) { rangeAxis.setUpperBound(intervalMarker.getEndValue()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } } } } }
From source file:com.sciaps.view.SpectrometerStackPanel.java
@Override public void doAddMarker(IntervalMarker marker) { plot_.addDomainMarker(marker);//from w ww . ja va 2 s . c o m if (xySeriesCollection_.getSeriesCount() > 0 && plotSettingPanel_.getMarkerAutoZoom()) { plot_.getDomainAxis().setAutoRange(true); plot_.getRangeAxis().setAutoRange(true); plot_.getDomainAxis().setLowerBound(marker.getStartValue() - 3); plot_.getDomainAxis().setUpperBound(marker.getEndValue() + 3); } }
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; }/*from w w w .ja v a2s. c om*/ 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; }