List of usage examples for org.jfree.data.xy XYDataItem getY
public Number getY()
From source file:gda.plots.TurboXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself./*from w ww . j ava2s .c om*/ * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @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 (_item > 0) return; SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); try { int x0 = -1; // the x position in pixels of the previous point int y0 = -1; // the y position in pixels of the previous point int x1 = -1; // the x position in pixels of the current point int y1 = -1; // the y position in pixels of the current point int xmin = (int) dataArea.getMinX(); int xmax = (int) dataArea.getMaxX(); int ymin = (int) dataArea.getMinY(); int ymax = (int) dataArea.getMaxY(); GeneralPath path = null; /* * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear * maths */ double xl = 0., mx = Double.NaN, cx = 0.; if (domainAxis instanceof SimpleNumberAxis) { xl = domainAxis.getRange().getLowerBound(); mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl); cx = xmin; } double yl = 0., my = Double.NaN, cy = 0.; if (rangeAxis instanceof SimpleNumberAxis) { yl = rangeAxis.getRange().getLowerBound(); my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl); cy = ymax; } List<XYDataItem> list = sxys.getData(); boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my); Paint paint = sxys.getPaint(); Stroke stroke = sxys.getStroke(); Paint paint_symbol = sxys.getSymbolPaint(); Stroke stroke_symbol = new BasicStroke(); drawLines = sxys.isDrawLines(); boolean filled = sxys.getFilled(); Shape shape = sxys.getSymbol(); boolean drawMarkers = sxys.isDrawMarkers() & shape != null; int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */ if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) { Rectangle shapeBoundingBox = shape.getBounds(); tooltipThresholdCounts = (int) dataArea.getWidth() / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold); } java.util.Vector<ddouble> markerPositions = null; Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } boolean prevLineAdded = false; // In case the iterator does not work then use the TODO comment iterator use and why not always // comment variables synchronized (list) { Iterator<XYDataItem> iter = list.iterator(); /* * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The * variable addThis determines if the current point is to be added to the path If previous line was * added that the current must be even if off the screen - but in this case the flag prevLineAdded is * set false so that the next does not have to be added. */ for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) { XYDataItem dataitem = iter.next(); double x = dataitem.getX().doubleValue(); double y = dataitem.getY().doubleValue(); x = xValueTransformer.transformValue(x); x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation) : (int) ((x - xl) * mx + cx); y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) : (int) ((y - yl) * my + cy); boolean addThis = true; if (item == 0) { x0 = x1; y0 = y1; if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) { addThis = false; } } else { if (x1 == x0 && y1 == y0) { addThis = false; } if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin) || (y1 > ymax && y0 > ymax)) { if (prevLineAdded) { path = addPointToLine(path, orientation, x1, y1); } addThis = false; } } if (addThis) { /* * If the current point is to be added then ensure previous one is as well to prevent lines * not crossing the edge of the screen */ if (!prevLineAdded) { path = addPointToLine(path, orientation, x0, y0); } path = addPointToLine(path, orientation, x1, y1); prevLineAdded = true; } prevLineAdded = addThis; if (addThis && drawMarkers) { if (markerPositions == null) { markerPositions = new java.util.Vector<ddouble>(); } markerPositions.add(new ddouble(item, x1, y1)); if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) { drawMarkers = false; markerPositions = null; } } } if (path != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(path); } if (markerPositions != null) { if (drawMarkers) { g2.setPaint(paint_symbol); g2.setStroke(stroke_symbol); for (ddouble dd : markerPositions) { Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y); if (filled) { g2.fill(shape_item); } else { g2.draw(shape_item); } entityArea = shape_item; // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y); } } g2.setPaint(paint); g2.setStroke(stroke); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.owasp.benchmark.score.report.ScatterVulns.java
private JFreeChart display(String title, int height, String category, Set<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // averages/*from ww w . j ava 2 s. c o m*/ ArrayList<Double> averageFalseRates = new ArrayList<Double>(); ArrayList<Double> averageTrueRates = new ArrayList<Double>(); int commercialToolCount = 0; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (Report toolReport : toolResults) { if (!toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } } for (Report toolReport : toolResults) { if (toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); if (!BenchmarkScore.showAveOnlyMode) { series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } commercialToolCount++; averageFalseRates.add(overallResult.falsePositiveRate); averageTrueRates.add(overallResult.truePositiveRate); } } for (double d : averageFalseRates) { afr += d; } afr = afr / averageFalseRates.size(); for (double d : averageTrueRates) { atr += d; } atr = atr / averageTrueRates.size(); if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) { series.add(afr * 100, atr * 100); } dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); initializePlot(xyplot); makeDataLabels(category, toolResults, xyplot); makeLegend(category, toolResults, 103, 100.5, dataset, xyplot); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:com.bwc.ora.models.Lrp.java
public static XYSeries findMaximums(XYSeries lrpSeries, String title) { XYSeries lrpMaxPoints = new XYSeries(title); XYDataItem leftPeakPoint = new XYDataItem(0, 0); int leftPeakPointIndex = 0; XYDataItem rightPeakPoint = new XYDataItem(0, 0); boolean first = true; int index = -1; List<XYDataItem> pointList = (List<XYDataItem>) lrpSeries.getItems(); for (XYDataItem point : pointList) { index++;// w w w. j a v a2 s . c om if (first) { leftPeakPoint = point; leftPeakPointIndex = index; first = false; continue; } if (leftPeakPoint.getYValue() < point.getYValue()) { leftPeakPoint = point; leftPeakPointIndex = index; rightPeakPoint = point; } else if (leftPeakPoint.getYValue() == point.getYValue()) { rightPeakPoint = point; } else { //determine if we are coming down off of a peak by looking two points behind the current point if (leftPeakPointIndex > 0) { XYDataItem prev = pointList.get(leftPeakPointIndex - 1); //if two points back has a Y value that is less than or equal to the left peak point //then we have found the end of the peak and we can process as such if (prev.getYValue() <= leftPeakPoint.getYValue()) { double peakx = rightPeakPoint.getXValue() - ((rightPeakPoint.getXValue() - leftPeakPoint.getXValue()) / 2D); lrpMaxPoints.add(peakx, leftPeakPoint.getY()); } } leftPeakPoint = point; leftPeakPointIndex = index; rightPeakPoint = point; } } return lrpMaxPoints; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java
protected TableXYDataset convertToTable(final XYSeriesCollection xyDataset) { final ExtCategoryTableXYDataset tableXYDataset = new ExtCategoryTableXYDataset(); final int count = xyDataset.getSeriesCount(); for (int i = 0; i < count; i++) { final XYSeries timeSeries = xyDataset.getSeries(i); final Comparable key = timeSeries.getKey(); final int itemCount = timeSeries.getItemCount(); for (int ic = 0; ic < itemCount; ic++) { final XYDataItem seriesDataItem = timeSeries.getDataItem(ic); tableXYDataset.add(seriesDataItem.getX(), seriesDataItem.getY(), key, false); }/*from w w w . j a v a 2 s . c o m*/ } return tableXYDataset; }
From source file:org.jfree.data.xy.XYSeries.java
/** * Updates the cached values for the minimum and maximum data values. * * @param item the item added (<code>null</code> not permitted). * * @since 1.0.13// ww w. j av a2 s . com */ private void updateBoundsForAddedItem(XYDataItem item) { double x = item.getXValue(); this.minX = minIgnoreNaN(this.minX, x); this.maxX = maxIgnoreNaN(this.maxX, x); if (item.getY() != null) { double y = item.getYValue(); this.minY = minIgnoreNaN(this.minY, y); this.maxY = maxIgnoreNaN(this.maxY, y); } }
From source file:org.jfree.data.xy.XYSeries.java
/** * Updates the cached values for the minimum and maximum data values on * the basis that the specified item has just been removed. * * @param item the item added (<code>null</code> not permitted). * * @since 1.0.13/* w w w . jav a 2 s. c o m*/ */ private void updateBoundsForRemovedItem(XYDataItem item) { boolean itemContributesToXBounds = false; boolean itemContributesToYBounds = false; double x = item.getXValue(); if (!Double.isNaN(x)) { if (x <= this.minX || x >= this.maxX) { itemContributesToXBounds = true; } } if (item.getY() != null) { double y = item.getYValue(); if (!Double.isNaN(y)) { if (y <= this.minY || y >= this.maxY) { itemContributesToYBounds = true; } } } if (itemContributesToYBounds) { findBoundsByIteration(); } else if (itemContributesToXBounds) { if (getAutoSort()) { this.minX = getX(0).doubleValue(); this.maxX = getX(getItemCount() - 1).doubleValue(); } else { findBoundsByIteration(); } } }
From source file:org.jfree.data.xy.XYSeries.java
/** * Adds or updates an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the data item (<code>null</code> not permitted). * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten./*from www. j a va 2s . c om*/ * * @since 1.0.14 */ public XYDataItem addOrUpdate(XYDataItem item) { ParamChecks.nullNotPermitted(item, "item"); if (this.allowDuplicateXValues) { add(item); return null; } // if we get to here, we know that duplicate X values are not permitted XYDataItem overwritten = null; int index = indexOf(item.getX()); if (index >= 0) { XYDataItem existing = (XYDataItem) this.data.get(index); overwritten = (XYDataItem) existing.clone(); // figure out if we need to iterate through all the y-values boolean iterate = false; double oldY = existing.getYValue(); if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } existing.setY(item.getY()); if (iterate) { findBoundsByIteration(); } else if (item.getY() != null) { double yy = item.getY().doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } } else { // if the series is sorted, the negative index is a result from // Collections.binarySearch() and tells us where to insert the // new item...otherwise it will be just -1 and we should just // append the value to the list... item = (XYDataItem) item.clone(); if (this.autoSort) { this.data.add(-index - 1, item); } else { this.data.add(item); } updateBoundsForAddedItem(item); // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { XYDataItem removed = (XYDataItem) this.data.remove(0); updateBoundsForRemovedItem(removed); } } fireSeriesChanged(); return overwritten; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java
/*********************************************************************************************** * Create a new Chart to show only those channels which are selected. * This must work even if the ChannelSelector is NULL. * * @param chartui//from ww w .jav a2 s. c o m * @param dao * @param datasettype * @param primarydataset * @param secondarydatasets * @param updatetype * @param isrefreshable * @param isclickrefresh * @param displaylimit * @param domainstartpoint * @param domainendpoint * @param channelselector * @param debug * * @return JFreeChart */ private static JFreeChart createChartForSelection(final ChartUIComponentPlugin chartui, final ObservatoryInstrumentDAOInterface dao, final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final boolean isrefreshable, final boolean isclickrefresh, final int displaylimit, final int domainstartpoint, final int domainendpoint, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final String SOURCE = "ChartHelper.createChartForSelection() "; final JFreeChart jFreeChart; LOGGER.debug(debug, SOURCE); if ((datasettype != null) && (primarydataset != null) && (secondarydatasets != null) && (updatetype != null)) { final XYDataset xyNewPrimaryDataset; final List<XYDataset> listNewSecondaryDatasets; final List<XYDataset> listParentSecondaryDatasetForSeries; final Iterator iterOriginalSecondaryDatasets; final Calendar calObservatory; // Create a list of NewSecondaryDatasets for display // Add an appropriate *empty* new dataset for every one existing in the secondary set // and record the parent new Dataset for each Series in each original Dataset // So much complexity just to handle the very few cases of secondary datasets... listNewSecondaryDatasets = new ArrayList<XYDataset>(10); listParentSecondaryDatasetForSeries = new ArrayList<XYDataset>(10); iterOriginalSecondaryDatasets = secondarydatasets.iterator(); // Either find the Current Observatory calendar, or provide a default calObservatory = ObservatoryInstrumentHelper.getCurrentObservatoryCalendar(REGISTRY.getFramework(), dao, debug); while (iterOriginalSecondaryDatasets.hasNext()) { final XYDataset xyDatasetOriginal; xyDatasetOriginal = (XYDataset) iterOriginalSecondaryDatasets.next(); if ((xyDatasetOriginal != null) && (xyDatasetOriginal.getSeriesCount() > 0)) { final XYDataset xyDatasetNew; // Create an empty Dataset to correspond with the original if (datasettype.getName().equals(DatasetType.XY.getName())) { xyDatasetNew = new XYSeriesCollection(); listNewSecondaryDatasets.add(xyDatasetNew); } else if (datasettype.getName().equals(DatasetType.TIMESTAMPED.getName())) { xyDatasetNew = new TimeSeriesCollection(calObservatory.getTimeZone()); listNewSecondaryDatasets.add(xyDatasetNew); } else { xyDatasetNew = new XYSeriesCollection(); listNewSecondaryDatasets.add(xyDatasetNew); } // Record the *same* parent Dataset for each Series in each original Secondary Dataset // This creates a List in channel order, but with references to Datasets not Series for (int i = 0; i < xyDatasetOriginal.getSeriesCount(); i++) { listParentSecondaryDatasetForSeries.add(xyDatasetNew); } } } LOGGER.debug(debug, SOURCE + "Check the DatasetType"); // Confirm the DatasetType if ((datasettype.getName().equals(DatasetType.XY.getName())) && (primarydataset instanceof XYSeriesCollection)) { final XYSeriesCollection collectionPrimary; // Prepare a new XYSeriesCollection for display xyNewPrimaryDataset = new XYSeriesCollection(); // There should be a collection of <channelcount> XYSeries in the Primary Dataset // but there may also be some in the Secondary Datasets collectionPrimary = (XYSeriesCollection) primarydataset; if ((collectionPrimary.getSeriesCount() > 0) && (collectionPrimary.getSeries() != null)) { final int intChannelCount; if (channelselector != null) { channelselector.debugSelector(debug, SOURCE); if ((channelselector.getChannelSelectionModes() != null) && (channelselector.showChannels())) { intChannelCount = channelselector.getChannelSelectionModes().size(); LOGGER.debug(debug, SOURCE + "[channelcount.channelselector=" + intChannelCount + "]"); } else if (dao != null) { intChannelCount = dao.getRawDataChannelCount(); LOGGER.debug(debug, SOURCE + "[channelcount.dao.raw=" + intChannelCount + "] (has channelselector?)"); } else { intChannelCount = collectionPrimary.getSeriesCount(); LOGGER.debug(debug, SOURCE + "[channelcount.primary.series=" + intChannelCount + "]"); } } else if (dao != null) { intChannelCount = dao.getRawDataChannelCount(); LOGGER.debug(debug, SOURCE + "[channelcount.dao.raw" + intChannelCount + "] (no channelselector)"); } else { // This should never happen! intChannelCount = collectionPrimary.getSeriesCount(); LOGGER.debug(debug, SOURCE + "[channelcount.primary.series" + intChannelCount + "] (last resort)"); } LOGGER.debug(debug, SOURCE + DatasetType.XY.getName() + " [domain.start.point=" + domainstartpoint + "] [domain.end.point=" + domainendpoint + "] [channelcount.inferred=" + intChannelCount + "]"); // Find which channels to use this time round for (int intChannelIndex = 0; intChannelIndex < intChannelCount; intChannelIndex++) { final ChannelSelectionMode selectionMode; // Use the ChannelSelectionMode if we can if ((channelselector != null) && (channelselector.getChannelSelectionModes() != null) && (channelselector.showChannels())) { selectionMode = channelselector.getChannelSelectionModes().get(intChannelIndex); } else { // If there is no ChannelSelector then we can safely assume the Channel is ON selectionMode = ChannelSelectionMode.X1; } if (!ChannelSelectionMode.OFF.equals(selectionMode)) { final XYSeries seriesOriginalData; seriesOriginalData = (XYSeries) getSeriesForIndex(datasettype, primarydataset, secondarydatasets, intChannelIndex, debug); if (seriesOriginalData != null) { final XYSeries seriesChangedData; final List listOriginalDataItems; int intStartIndex; int intEndIndex; listOriginalDataItems = seriesOriginalData.getItems(); // Prepare a new Series for the changed data, with the same Key seriesChangedData = new XYSeries(seriesOriginalData.getKey()); // Map the slider values to data indexes intStartIndex = transformDomainSliderValueToSeriesIndex( ChartUIComponentPlugin.DOMAIN_SLIDER_MINIMUM, ChartUIComponentPlugin.DOMAIN_SLIDER_MAXIMUM, domainstartpoint, DatasetDomainUIComponentInterface.INDEX_LEFT, collectionPrimary.getDomainLowerBound(true), collectionPrimary.getDomainUpperBound(true), DatasetType.XY, calObservatory, seriesOriginalData, debug); intEndIndex = transformDomainSliderValueToSeriesIndex( ChartUIComponentPlugin.DOMAIN_SLIDER_MINIMUM, ChartUIComponentPlugin.DOMAIN_SLIDER_MAXIMUM, domainendpoint, DatasetDomainUIComponentInterface.INDEX_RIGHT, collectionPrimary.getDomainLowerBound(true), collectionPrimary.getDomainUpperBound(true), DatasetType.XY, calObservatory, seriesOriginalData, debug); if ((intStartIndex == -1) || (intEndIndex == -1)) { // If either index is returned as -1, then there's nothing to do... // ...so stop the for() loop intStartIndex = 0; intEndIndex = 0; } else if (intEndIndex <= intStartIndex) { intEndIndex = intStartIndex + 1; } LOGGER.debug(debug, SOURCE + "before copy of selected series subset [channel=" + intChannelIndex + "] [index.start=" + intStartIndex + "] [index.end=" + intEndIndex + "] [show.ticks=" + ((intEndIndex - intStartIndex) <= 25) + "]"); // Copy over only the selected range from the Slider for (int intDataIndex = intStartIndex; ((intDataIndex < intEndIndex) && (listOriginalDataItems.size() > 0)); intDataIndex++) { final XYDataItem dataOriginalItem; final XYDataItem dataChangedItem; dataOriginalItem = (XYDataItem) listOriginalDataItems.get(intDataIndex); if (!ChannelSelectionMode.X1.equals(selectionMode)) { // Change each value of the series according to the multiplier dataChangedItem = new XYDataItem(dataOriginalItem.getX(), dataOriginalItem.getY().doubleValue() * selectionMode.getMultiplier()); } else { // Just use the whole series unaltered for gain of X1 dataChangedItem = new XYDataItem(dataOriginalItem.getX(), dataOriginalItem.getY()); } seriesChangedData.add(dataChangedItem); } // Place the changed series in the correct collection // to correspond with the original // Did we collect any data for this Series? // If not, place a dummy point at the origin of the *visible* chart if (seriesChangedData.getItemCount() == 0) { // TODO seriesChangedData.add(new XYDataItem(0, 0)); } if (intChannelIndex < collectionPrimary.getSeriesCount()) { // Simply add the changed Primary series to the PrimaryDataset collection ((XYSeriesCollection) xyNewPrimaryDataset).addSeries(seriesChangedData); } else { // It must be a secondary dataset // Add the changed Secondary series to the parent SecondaryDataset // given by the *secondary* channel index addSecondarySeries(datasettype, listParentSecondaryDatasetForSeries, seriesChangedData, intChannelIndex - collectionPrimary.getSeriesCount()); } } else { LOGGER.warn(SOURCE + "OriginalData XYSeries unexpectedly NULL"); } } } // Dump the (partial) contents of each Series in the composite XYdataset dumpXYDataset(debug, calObservatory, xyNewPrimaryDataset, 4, SOURCE + "XYSeriesCollection --> createCustomisedChart() xyNewPrimaryDataset"); jFreeChart = chartui.createCustomisedChart(datasettype, xyNewPrimaryDataset, listNewSecondaryDatasets, updatetype, displaylimit, channelselector, debug); } else { LOGGER.error(SOURCE + " The XYSeriesCollection does not have any XYSeries"); jFreeChart = null; } } else if ((datasettype.getName().equals(DatasetType.TIMESTAMPED.getName())) && (primarydataset instanceof TimeSeriesCollection)) { final TimeSeriesCollection collectionPrimary; // Prepare a new TimeSeriesCollection for display xyNewPrimaryDataset = new TimeSeriesCollection(calObservatory.getTimeZone()); // There should be a collection of <channelcount> TimeSeries in the Primary Dataset // but there may also be some in the Secondary Datasets collectionPrimary = (TimeSeriesCollection) primarydataset; if ((collectionPrimary.getSeriesCount() > 0) && (collectionPrimary.getSeries() != null)) { final int intChannelCount; if (channelselector != null) { channelselector.debugSelector(debug, SOURCE); if ((channelselector.getChannelSelectionModes() != null) && (channelselector.showChannels())) { intChannelCount = channelselector.getChannelSelectionModes().size(); LOGGER.debug(debug, SOURCE + "[channelcount.channelselector=" + intChannelCount + "]"); } else if (dao != null) { intChannelCount = dao.getRawDataChannelCount(); LOGGER.debug(debug, SOURCE + "[channelcount.dao.raw=" + intChannelCount + "] (has channelselector)"); } else { intChannelCount = collectionPrimary.getSeriesCount(); LOGGER.debug(debug, SOURCE + "[channelcount.primary.series=" + intChannelCount + "]"); } } else if (dao != null) { intChannelCount = dao.getRawDataChannelCount(); LOGGER.debug(debug, SOURCE + "[channelcount.dao.raw=" + intChannelCount + "] (no channelselector)"); } else { // This should never happen! intChannelCount = collectionPrimary.getSeriesCount(); LOGGER.debug(debug, SOURCE + "[channelcount.primary.series=" + intChannelCount + "] (last resort)"); } LOGGER.debug(debug, SOURCE + DatasetType.TIMESTAMPED.getName() + " [domain.startpoint=" + domainstartpoint + "] [domain.endpoint=" + domainendpoint + "] [domain.lowerbound=" + (long) collectionPrimary.getDomainLowerBound(true) + "] [domain.upperbound=" + (long) collectionPrimary.getDomainUpperBound(true) + "] [channelcount.inferred=" + intChannelCount + "]"); // Find which channels to use this time round for (int intChannelIndex = 0; intChannelIndex < intChannelCount; intChannelIndex++) { final ChannelSelectionMode selectionMode; // Use the ChannelSelectionMode if we can if ((channelselector != null) && (channelselector.getChannelSelectionModes() != null) && (channelselector.showChannels())) { selectionMode = channelselector.getChannelSelectionModes().get(intChannelIndex); } else { // If there is no ChannelSelector then we can safely assume the Channel is ON selectionMode = ChannelSelectionMode.X1; } if (!ChannelSelectionMode.OFF.equals(selectionMode)) { final TimeSeries seriesOriginalData; seriesOriginalData = (TimeSeries) getSeriesForIndex(datasettype, primarydataset, secondarydatasets, intChannelIndex, debug); if (seriesOriginalData != null) { final TimeSeries seriesChangedData; final List listOriginalDataItems; int intStartIndex; int intEndIndex; listOriginalDataItems = seriesOriginalData.getItems(); // Prepare a new Series for the changed data, with the same Key seriesChangedData = new TimeSeries(seriesOriginalData.getKey().toString(), seriesOriginalData.getTimePeriodClass()); // Map the slider values to data indexes intStartIndex = transformDomainSliderValueToSeriesIndex( ChartUIComponentPlugin.DOMAIN_SLIDER_MINIMUM, ChartUIComponentPlugin.DOMAIN_SLIDER_MAXIMUM, domainstartpoint, DatasetDomainUIComponentInterface.INDEX_LEFT, collectionPrimary.getDomainLowerBound(true), collectionPrimary.getDomainUpperBound(true), DatasetType.TIMESTAMPED, calObservatory, seriesOriginalData, debug); intEndIndex = transformDomainSliderValueToSeriesIndex( ChartUIComponentPlugin.DOMAIN_SLIDER_MINIMUM, ChartUIComponentPlugin.DOMAIN_SLIDER_MAXIMUM, domainendpoint, DatasetDomainUIComponentInterface.INDEX_RIGHT, collectionPrimary.getDomainLowerBound(true), collectionPrimary.getDomainUpperBound(true), DatasetType.TIMESTAMPED, calObservatory, seriesOriginalData, debug); if ((intStartIndex == -1) || (intEndIndex == -1)) { // If either index is returned as -1, then there's nothing to do... // ...so stop the for() loop intStartIndex = 0; intEndIndex = 0; } else if (intEndIndex <= intStartIndex) { intEndIndex = intStartIndex + 1; } LOGGER.debug(debug, SOURCE + "before copy of selected series subset [channel=" + intChannelIndex + "] [index.start=" + intStartIndex + "] [index.end=" + intEndIndex + "] [item.count=" + listOriginalDataItems.size() + "]"); // Copy over only the selected range from the Slider for (int intDataIndex = intStartIndex; ((intDataIndex < intEndIndex) && (intDataIndex < listOriginalDataItems.size())); intDataIndex++) { final TimeSeriesDataItem dataOriginalItem; final TimeSeriesDataItem dataChangedItem; dataOriginalItem = (TimeSeriesDataItem) listOriginalDataItems.get(intDataIndex); if (!ChannelSelectionMode.X1.equals(selectionMode)) { // Change each value of the series according to the multiplier dataChangedItem = new TimeSeriesDataItem(dataOriginalItem.getPeriod(), dataOriginalItem.getValue().doubleValue() * selectionMode.getMultiplier()); } else { // Just use the whole series unaltered for gain of X1 dataChangedItem = new TimeSeriesDataItem(dataOriginalItem.getPeriod(), dataOriginalItem.getValue().doubleValue()); } seriesChangedData.add(dataChangedItem); } // Did we collect any data for this Series? // If not, place a dummy point at the origin of the *visible* chart if (seriesChangedData.getItemCount() == 0) { seriesChangedData.add(createDummyTimeSeriesDataItemAtOrigin(collectionPrimary, seriesOriginalData, domainstartpoint, debug)); } // Place the changed series in the correct collection // to correspond with the original if (intChannelIndex < collectionPrimary.getSeriesCount()) { // Simply add the changed Primary series to the PrimaryDataset collection ((TimeSeriesCollection) xyNewPrimaryDataset).addSeries(seriesChangedData); } else { // It must be a secondary dataset // Add the changed Secondary series to the parent SecondaryDataset // given by the *secondary* channel index addSecondarySeries(datasettype, listParentSecondaryDatasetForSeries, seriesChangedData, intChannelIndex - collectionPrimary.getSeriesCount()); } } else { LOGGER.warn(SOURCE + "OriginalData TimeSeries unexpectedly NULL"); } } } // Dump the (partial) contents of each Series in the composite XYdataset dumpXYDataset(debug, calObservatory, xyNewPrimaryDataset, 4, SOURCE + "TimeSeriesCollection --> createCustomisedChart() xyNewPrimaryDataset"); jFreeChart = chartui.createCustomisedChart(datasettype, xyNewPrimaryDataset, listNewSecondaryDatasets, updatetype, displaylimit, channelselector, debug); } else { LOGGER.error(SOURCE + " The TimeSeriesCollection does not have any TimeSeries"); jFreeChart = null; } } else { LOGGER.error(SOURCE + " The Dataset is of an invalid type"); jFreeChart = null; } } else { LOGGER.debug(debug, SOURCE + " Unable to change the Chart - invalid parameters"); jFreeChart = null; } return (jFreeChart); }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
public boolean precursorChromatogramEmpty(MRMTransition parent) { if (parent == null) return true; XYSeries pData;//from www . j av a 2 s .c om if ((pData = parent.getGraphData()) == null) return true; for (Object xydio : pData.getItems()) { XYDataItem xydi = (XYDataItem) xydio; if (xydi.getY().doubleValue() != 0.0) return false; } return true; }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
private int indexOfMaxY(XYSeries s) { double _maxy = -10000000000.0; int retVal = -1; for (int i = 0; i < s.getItemCount(); i++) { XYDataItem xydi = s.getDataItem(i); if (_maxy < xydi.getY().doubleValue()) { _maxy = xydi.getY().doubleValue(); retVal = i;/* w w w. ja v a 2 s. c o m*/ } } return retVal; }