List of usage examples for org.jfree.data.xy XYDataItem getX
public Number getX()
From source file:org.jfree.data.xy.XYSeries.java
/** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the (x, y) item (<code>null</code> not permitted). * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all * registered listeners./*from w w w. j a v a2s . c om*/ */ public void add(XYDataItem item, boolean notify) { if (item == null) { throw new IllegalArgumentException("Null 'item' argument."); } if (this.autoSort) { int index = Collections.binarySearch(this.data, item); if (index < 0) { this.data.add(-index - 1, item); } else { if (this.allowDuplicateXValues) { // need to make sure we are adding *after* any duplicates int size = this.data.size(); while (index < size && item.compareTo(this.data.get(index)) == 0) { index++; } if (index < this.data.size()) { this.data.add(index, item); } else { this.data.add(item); } } else { throw new SeriesException("X-value already exists."); } } } else { if (!this.allowDuplicateXValues) { // can't allow duplicate values, so we need to check whether // there is an item with the given x-value already int index = indexOf(item.getX()); if (index >= 0) { throw new SeriesException("X-value already exists."); } } this.data.add(item); } if (getItemCount() > this.maximumItemCount) { this.data.remove(0); } if (notify) { fireSeriesChanged(); } }
From source file:org.jfree.data.xy.XYSeries.java
/** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the (x, y) item (<code>null</code> not permitted). * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners./*from w w w . j a v a2 s. c o m*/ */ public void add(XYDataItem item, boolean notify) { ParamChecks.nullNotPermitted(item, "item"); item = (XYDataItem) item.clone(); if (this.autoSort) { int index = Collections.binarySearch(this.data, item); if (index < 0) { this.data.add(-index - 1, item); } else { if (this.allowDuplicateXValues) { // need to make sure we are adding *after* any duplicates int size = this.data.size(); while (index < size && item.compareTo(this.data.get(index)) == 0) { index++; } if (index < this.data.size()) { this.data.add(index, item); } else { this.data.add(item); } } else { throw new SeriesException("X-value already exists."); } } } else { if (!this.allowDuplicateXValues) { // can't allow duplicate values, so we need to check whether // there is an item with the given x-value already int index = indexOf(item.getX()); if (index >= 0) { throw new SeriesException("X-value already exists."); } } this.data.add(item); } updateBoundsForAddedItem(item); if (getItemCount() > this.maximumItemCount) { XYDataItem removed = (XYDataItem) this.data.remove(0); updateBoundsForRemovedItem(removed); } if (notify) { fireSeriesChanged(); } }
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 . j a va 2 s .com*/ * @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
protected void createChartInPanelDaughterTasksOnly(XYPlot xyp) { XYSeries coloredDataset = transitionOnPlot.getCurrentDaughter().getGraphData(); Paint daughterColor = Utils.paleColor((Color) transitionOnPlot.getCurrentDaughter().getGraphColor()); ArrayList<XYLineAnnotation> coloredDaughters = new ArrayList<XYLineAnnotation>(); //Trace calculated elution curves over data spikes if (transitionOnPlot.getElutionCurves() != null && !transitionOnPlot.getElutionCurves().isEmpty()) { MRMDaughter curDaughter = transitionOnPlot.getCurrentDaughter(); ElutionCurveStrategy ecs = transitionOnPlot.getElutionCurves().get(curDaughter); //Is current daughter rejected? Boolean accepted = (Boolean) ((PeaksTableModel) peaksTable.getModel()).data[curDaughter .getElutionDataTableRow()][peaksData.Accept.colno]; if (accepted == null || !accepted) { xyp.setBackgroundPaint(new Color(255, 230, 230)); }//from w w w .j av a 2s . c o m List<ElutionCurve> ecl = ecs.getDaughterCurves(); if (ecl != null) { for (ElutionCurve e : ecl) { List<Line2D.Double> ll2dd = e.getSegments(); for (Line2D.Double l2dd : ll2dd) { xyp.addAnnotation(Utils.line2Annotation(l2dd, new BasicStroke(2.0f), ecs.isBestDaughterCurve(e) ? Color.BLACK : Color.LIGHT_GRAY)); } } } } // If there is a valid "current" daughter draw the spikes in the daughter's color // as annotations (sensu JFree) if (coloredDataset != null) { int nOfPoints = coloredDataset.getItemCount(); for (int i = 0; i < (nOfPoints - 1); i++) { XYDataItem p1 = coloredDataset.getDataItem(i); XYDataItem p2 = coloredDataset.getDataItem(i + 1); coloredDaughters.add(new XYLineAnnotation(p1.getX().doubleValue(), p1.getY().doubleValue(), p2.getX().doubleValue(), p2.getY().doubleValue(), new BasicStroke(1.5f), transitionOnPlot.getCurrentDaughter().getGraphColor()) // new XYLineAnnotation(p1.getX().doubleValue(),p1.getY().doubleValue(),p2.getX().doubleValue(),p2.getY().doubleValue(),new BasicStroke(1.5f),daughterColor) ); } } if (_traceAllFragments) { for (MRMDaughter d : transitionOnPlot.getDaughters().values()) { if (d == transitionOnPlot.getCurrentDaughter()) continue; XYSeries curXYSeries = d.getContinDaughterData(); if (curXYSeries == null || curXYSeries.getItemCount() == 0) continue; if (d.getBestElutionCurve() == null) continue; int nOfPoints = curXYSeries.getItemCount(); for (int i = 0; i < (nOfPoints - 1); i++) { XYDataItem p1 = curXYSeries.getDataItem(i); XYDataItem p2 = curXYSeries.getDataItem(i + 1); coloredDaughters.add( // new XYLineAnnotation(p1.getX().doubleValue(),p1.getY().doubleValue(),p2.getX().doubleValue(),p2.getY().doubleValue(),new BasicStroke(1f),Utils.paleColor((Color)d.getGraphColor())) new XYLineAnnotation(p1.getX().doubleValue(), p1.getY().doubleValue(), p2.getX().doubleValue(), p2.getY().doubleValue(), new BasicStroke(1f), d.getGraphColor())); } } } if (coloredDaughters != null) { for (XYLineAnnotation xyla : coloredDaughters) { xyp.addAnnotation(xyla); } } coloredDaughters.clear(); //Display L or H label in upper left hand corner Range xRange = xyp.getDomainAxis().getRange(); Range yRange = xyp.getRangeAxis().getRange(); XYTextAnnotation lab = new XYTextAnnotation( (String) ((PeaksTableModel) peaksTable.getModel()).data[transitionOnPlot.getCurrentDaughter() .getElutionDataTableRow()][peaksData.Label.colno], xRange.getUpperBound() - (0.05 * xRange.getLength()), yRange.getUpperBound() - (0.05 * yRange.getLength())); lab.setFont(lab.getFont().deriveFont(Font.BOLD, 40.0F)); xyp.addAnnotation(lab); XYTextAnnotation midMarker = new XYTextAnnotation("\u25BC", ((MRMTransition) transitionOnPlot).getCalcXatMaxYAllDaughters(), ((MRMTransition) transitionOnPlot).getCalcMaxYAllDaughters()); midMarker.setPaint(Color.RED); midMarker.setFont(midMarker.getFont().deriveFont(Font.BOLD, 20F)); XYTextAnnotation midMarkerOutline = new XYTextAnnotation("\u25BC", ((MRMTransition) transitionOnPlot).getCalcXatMaxYAllDaughters(), ((MRMTransition) transitionOnPlot).getCalcMaxYAllDaughters()); midMarkerOutline.setPaint(Color.BLACK); midMarkerOutline.setFont(midMarker.getFont().deriveFont(Font.BOLD, 23F)); xyp.addAnnotation(midMarkerOutline); xyp.addAnnotation(midMarker); }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIComponent.java
/*********************************************************************************************** * Update the existing Chart referenced by the DAO, by applying the specified datasets, * using all existing channel selections and range selections. * This implementation ASSUMES a ChannelSelector is present. * * @param dao//from w w w .j ava2s. c om * @param datasettype * @param primarydataset * @param secondarydatasets * @param displaylimit * @param domainstartpoint * @param domainendpoint * @param channelselector * @param debug */ public void updateChartForSelection(final ObservatoryInstrumentDAOInterface dao, final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final int displaylimit, final int domainstartpoint, final int domainendpoint, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final String SOURCE = "ChartUIComponent.updateChartForSelection() "; if ((dao != null) && (dao.getChartUI() != null) && (dao.getChartUI().getChartPanel() != null) && (dao.getChartUI().getChartPanel().getChart() != null) && (dao.getChartUI().getChartPanel().getChart().getXYPlot() != null) && (datasettype != null) && (primarydataset != null) && (secondarydatasets != null) && (channelselector != null)) { final XYDataset xyNewPrimaryDataset; final List<XYDataset> listNewSecondaryDatasets; final List<XYDataset> listParentSecondaryDatasetForSeries; final Iterator iterOriginalSecondaryDatasets; final Calendar calObservatory; // Either find the Current Observatory calendar, or provide a default calObservatory = ObservatoryInstrumentHelper.getCurrentObservatoryCalendar(REGISTRY.getFramework(), dao, debug); // 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(); 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); } } } // 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; // ToDo Make this work for ChannelSelector NULL, get channel count from primary and secondaries? Set mode to X1? if ((collectionPrimary.getSeriesCount() > 0) && (collectionPrimary.getSeries() != null) && (channelselector.getChannelSelectionModes() != null)) { LOGGER.debug(debug, SOURCE + "XY domainstartpoint=" + domainstartpoint + " domainendpoint=" + domainendpoint); ChartHelper.dumpXYDataset(debug, calObservatory, collectionPrimary, 4, SOURCE + "XYSeriesCollection --> Original Dataset"); // Find which channels and data range to use this time round for (int intChannelIndex = 0; intChannelIndex < channelselector.getChannelSelectionModes() .size(); intChannelIndex++) { final ChannelSelectionMode selectionMode; selectionMode = channelselector.getChannelSelectionModes().get(intChannelIndex); if (!ChannelSelectionMode.OFF.equals(selectionMode)) { final XYSeries seriesOriginalData; // We needed to know about the secondary datasets in order to get the correct index seriesOriginalData = (XYSeries) ChartHelper.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()); if (listOriginalDataItems.size() > 0) { // Map the slider values to data indexes intStartIndex = ChartHelper.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 = ChartHelper.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 + "]"); // Copy over only the selected range from the Slider for (int intDataIndex = intStartIndex; intDataIndex < intEndIndex; 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); } // 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 ChartHelper.createDummyXYSeriesDataItemAtOrigin() seriesChangedData.add(new XYDataItem(0, 0)); } // 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 ((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 ChartHelper.addSecondarySeries(datasettype, listParentSecondaryDatasetForSeries, seriesChangedData, intChannelIndex - collectionPrimary.getSeriesCount()); } } else { LOGGER.warn(SOURCE + "OriginalData XYSeries unexpectedly NULL"); } } else { // There are no data! Do nothing... LOGGER.warn(SOURCE + "There are no data, so do nothing"); } } } LOGGER.debug(debug, SOURCE + "Update the data shown on existing Chart"); // The outputs are xyNewPrimaryDataset and listNewSecondaryDatasets // This Chart does not use secondary datasets (yet) // Dump the (partial) contents of each Series in the new XYdataset ChartHelper.dumpXYDataset(debug, calObservatory, xyNewPrimaryDataset, 4, SOURCE + "XYSeriesCollection --> setDataset"); dao.getChartUI().getChartPanel().getChart().getXYPlot().setDataset(INDEX_DATA, xyNewPrimaryDataset); } else { LOGGER.error(SOURCE + " The XYSeriesCollection does not have any XYSeries"); } } else if ((datasettype.getName().equals(DatasetType.TIMESTAMPED.getName())) && (primarydataset instanceof TimeSeriesCollection)) { final TimeSeriesCollection collectionPrimary; LOGGER.debug(debug, SOURCE + "TIMESTAMPED domainstartpoint=" + domainstartpoint + " domainendpoint=" + domainendpoint); // 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) && (channelselector.getChannelSelectionModes() != null)) { ChartHelper.dumpXYDataset(debug, calObservatory, collectionPrimary, 4, SOURCE + "TimeSeriesCollection PrimaryDataset --> Original Dataset"); // Find which channels and data range to use this time round for (int intChannelIndex = 0; intChannelIndex < channelselector.getChannelSelectionModes() .size(); intChannelIndex++) { final ChannelSelectionMode selectionMode; selectionMode = channelselector.getChannelSelectionModes().get(intChannelIndex); if (!ChannelSelectionMode.OFF.equals(selectionMode)) { final TimeSeries seriesOriginalData; // We needed to know about the secondary datasets in order to get the correct index seriesOriginalData = (TimeSeries) ChartHelper.getSeriesForIndex(datasettype, primarydataset, secondarydatasets, intChannelIndex, debug); if (seriesOriginalData != null) { final List listOriginalDataItems; final TimeSeries seriesChangedData; listOriginalDataItems = seriesOriginalData.getItems(); // Prepare a new Series for the changed data, with the same Key seriesChangedData = new TimeSeries(seriesOriginalData.getKey().toString(), seriesOriginalData.getTimePeriodClass()); if (listOriginalDataItems.size() > 0) { int intStartIndex; int intEndIndex; // Map the slider values to data indexes intStartIndex = ChartHelper.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 = ChartHelper.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 LOGGER.debug(debug, SOURCE + "Set EndIndex = StartIndex = 0"); intStartIndex = 0; intEndIndex = 0; } else if (intEndIndex <= intStartIndex) { LOGGER.debug(debug, SOURCE + "Correcting EndIndex less than StartIndex"); intEndIndex = intStartIndex + 1; } LOGGER.debug(debug, SOURCE + "before copy of selected series subset [channel=" + intChannelIndex + "] [start_index=" + intStartIndex + "] [end_index=" + intEndIndex + "]"); // Copy over only the selected range from the Slider for (int intDataIndex = intStartIndex; intDataIndex < intEndIndex; 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(ChartHelper.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 ChartHelper.addSecondarySeries(datasettype, listParentSecondaryDatasetForSeries, seriesChangedData, intChannelIndex - collectionPrimary.getSeriesCount()); } } else { // There are no data! Do nothing... LOGGER.warn(SOURCE + "There are no data, so do nothing [channel.index=" + intChannelIndex + "]"); } } else { LOGGER.warn(SOURCE + "OriginalData TimeSeries unexpectedly NULL [channel.index=" + intChannelIndex + "]"); } } else { LOGGER.debug(debug, SOURCE + "Channel is OFF [channel.index=" + intChannelIndex + "]"); } } LOGGER.debug(debug, SOURCE + "Update the data shown on existing Chart"); // The outputs are xyNewPrimaryDataset and listNewSecondaryDatasets // This Chart superclass does not use secondary datasets (yet) // Dump the (partial) contents of each Series in the new XYdataset ChartHelper.dumpXYDataset(debug, calObservatory, xyNewPrimaryDataset, 4, SOURCE + "TimeSeriesCollection NewPrimaryDataset --> setDataset"); dao.getChartUI().getChartPanel().getChart().getXYPlot().setDataset(INDEX_DATA, xyNewPrimaryDataset); } else { LOGGER.error(SOURCE + " The TimeSeriesCollection does not have any TimeSeries"); } } else { LOGGER.error(SOURCE + " The Dataset is of an invalid type"); } } else { LOGGER.debug(debug, SOURCE + " Unable to change the Chart - invalid parameters"); } }