List of usage examples for org.jfree.data.xy XYSeriesCollection getSeries
public List getSeries()
From source file:org.spantus.exp.segment.draw.AbstractGraphGenerator.java
public JFreeChart getChart(ComparisionResult result) { CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time")); plot.setGap(10.0);/*from w ww.j a va 2s. c o m*/ plot.setOrientation(PlotOrientation.VERTICAL); XYSeriesCollection[] seriesArr = createSeries(result); for (XYSeriesCollection series : seriesArr) { XYSeriesCollection data = series; StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.BLACK); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setLabel(((XYSeries) series.getSeries().get(0)).getDescription()); rangeAxis.setAutoRange(true); XYPlot subplot = new XYPlot(data, null, rangeAxis, renderer); plot.add(subplot); } String name = result.getName() == null ? "Segmentation" : "Segmentation: " + result.getName(); JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, true); return chart; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * Set all the charts with the generated XYSeriesCollections. * * @param nCols/*from w ww.j a va 2 s . co m*/ */ private void setTrackChartsWithCollections(int nCols) { int length = GuiUtils.getAvailableColors().length; List<PlateCondition> plateConditionList = singleCellMainController.getPlateConditionList(); for (int i = 0; i < plateConditionList.size(); i++) { XYSeriesCollection collection = cellTracksData.get(i); int numberTracks = collection.getSeries().size(); String title = numberTracks + " tracks" + " - " + plateConditionList.get(i); // create a chart for each plate condition JFreeChart coordinatesChart = ChartFactory.createXYLineChart(title, "x (m)", "y (m)", collection, PlotOrientation.VERTICAL, false, true, false); // and a new chart panel as well ChartPanel coordinatesChartPanel = new ChartPanel(null); coordinatesChartPanel.setOpaque(false); // compute the constraints GridBagConstraints tempBagConstraints = GuiUtils.getTempBagConstraints(plateConditionList.size(), i, nCols); analysisPanel.getTrackPlotParentPanel().add(coordinatesChartPanel, tempBagConstraints); JFreeChartUtils.setupTrackChart(coordinatesChart); TrackXYLineAndShapeRenderer trackXYLineAndShapeRenderer = new TrackXYLineAndShapeRenderer(true, false, false, null, -1, 2, false); trackXYLineAndShapeRenderer.setChosenColor(GuiUtils.getAvailableColors()[i % length]); coordinatesChart.getXYPlot().setRenderer(trackXYLineAndShapeRenderer); coordinatesChartPanel.setChart(coordinatesChart); // add the chart panels to the list cellTracksChartPanels.add(coordinatesChartPanel); analysisPanel.getTrackPlotParentPanel().revalidate(); analysisPanel.getTrackPlotParentPanel().repaint(); } }
From source file:edu.fullerton.viewerplugin.SpectrumPlot.java
private void findSmallest(XYSeriesCollection mtds) { double minx = Double.MAX_VALUE; double miny = Double.MAX_VALUE; for (Iterator it = mtds.getSeries().iterator(); it.hasNext();) { XYSeries ds = (XYSeries) it.next(); for (int item = 1; item < ds.getItemCount() - 1; item++) { double x = ds.getX(item).doubleValue(); double y = ds.getY(item).doubleValue(); minx = Math.min(minx, x); miny = Math.min(miny, y); }/*from ww w.j a va2s. com*/ } smallestX = minx; smallestY = 1e-40; double t; for (int e = 40; e > -40; e--) { t = Math.pow(10., e); if (miny >= t) { smallestY = t; break; } } }
From source file:fr.amap.lidar.amapvox.chart.VoxelsToChart.java
public JFreeChart[] getVegetationProfileCharts(LayerReference reference, float maxPAD) { boolean inverseRangeAxis; inverseRangeAxis = !(reference == LayerReference.FROM_ABOVE_GROUND); int quadratNumber = getQuadratNumber(split, length); JFreeChart[] charts = new JFreeChart[quadratNumber]; for (int i = 0; i < quadratNumber; i++) { XYSeriesCollection dataset = new XYSeriesCollection(); for (VoxelFileChart voxelFile : voxelFiles) { int[] indices = getIndiceRange(voxelFile, i); XYSeries serie = createVegetationProfileSerie(voxelFile.reader, voxelFile.label, indices[0], indices[1], reference, maxPAD); dataset.addSeries(serie);/*from w ww. ja v a 2s . c o m*/ } List<XYSeries> series = dataset.getSeries(); double correlationValue = Double.NaN; if (series.size() == 2) { XYSeries firstSerie = series.get(0); XYSeries secondSerie = series.get(1); Map<Double, Double[]> valuesMap = new HashMap<>(); for (int j = 0; j < firstSerie.getItemCount(); j++) { Double[] value = new Double[] { firstSerie.getDataItem(j).getXValue(), Double.NaN }; valuesMap.put(firstSerie.getDataItem(j).getYValue(), value); } for (int j = 0; j < secondSerie.getItemCount(); j++) { Double[] value = valuesMap.get(Double.valueOf(secondSerie.getDataItem(j).getYValue())); if (value == null) { valuesMap.put(secondSerie.getDataItem(j).getYValue(), new Double[] { Double.NaN, secondSerie.getDataItem(j).getXValue() }); } else if (Double.isNaN(value[1])) { value[1] = secondSerie.getDataItem(j).getXValue(); valuesMap.put(secondSerie.getDataItem(j).getYValue(), value); } } List<Double> firstList = new ArrayList<>(); List<Double> secondList = new ArrayList<>(); Iterator<Map.Entry<Double, Double[]>> iterator = valuesMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Double, Double[]> next = iterator.next(); Double[] value = next.getValue(); if (!Double.isNaN(value[0]) && !Double.isNaN(value[1])) { firstList.add(value[0]); secondList.add(value[1]); } } double[] firstArray = new double[firstList.size()]; double[] secondArray = new double[secondList.size()]; for (int j = 0; j < firstList.size(); j++) { firstArray[j] = firstList.get(j); secondArray[j] = secondList.get(j); } PearsonsCorrelation correlation = new PearsonsCorrelation(); correlationValue = correlation.correlation(firstArray, secondArray); } charts[i] = createChart("Vegetation profile" + " - quadrat " + (i + 1), dataset, "PAD", reference.getLabel()); if (!Double.isNaN(correlationValue)) { charts[i].addSubtitle( new TextTitle("R2 = " + (Math.round(Math.pow(correlationValue, 2) * 100)) / 100.0)); } ((XYPlot) charts[i].getPlot()).getRangeAxis().setInverted(inverseRangeAxis); } //set quadrats ranges double minX = 0; double maxX = 0; double minY = 0; double maxY = 0; int id = 0; for (JFreeChart chart : charts) { XYPlot plot = (XYPlot) chart.getPlot(); Range rangeOfRangeAxis = plot.getDataRange(plot.getRangeAxis()); Range rangeOfDomainAxis = plot.getDataRange(plot.getDomainAxis()); double currentMinY = rangeOfRangeAxis.getLowerBound(); double currentMaxY = rangeOfRangeAxis.getUpperBound(); double currentMinX = rangeOfDomainAxis.getLowerBound(); double currentMaxX = rangeOfDomainAxis.getUpperBound(); if (id == 0) { minX = currentMinX; maxX = currentMaxX; minY = currentMinY; maxY = currentMaxY; } else { if (currentMinX < minX) { minX = currentMinX; } if (currentMaxX > maxX) { maxX = currentMaxX; } if (currentMinY < minY) { minY = currentMinY; } if (currentMaxY > maxY) { maxY = currentMaxY; } } id++; } for (JFreeChart chart : charts) { XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setRange(minX, maxX); plot.getRangeAxis().setRange(minY, maxY); } return charts; }
From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java
/** * @param os response output stream/* w w w . ja v a 2s.c o m*/ * @param mvr MeanVarianceRelation object to plot * @return true if mvr data points were plotted */ private boolean writeMeanVariance(OutputStream os, MeanVarianceRelation mvr, Double size) throws Exception { // if number of datapoints > THRESHOLD then alpha = TRANSLUCENT, else alpha = OPAQUE final int THRESHOLD = 1000; final int TRANSLUCENT = 50; final int OPAQUE = 255; // Set maximum plot range to Y_MAX + YRANGE * OFFSET to leave some extra white space final double OFFSET_FACTOR = 0.05f; // set the final image size to be the minimum of MAX_IMAGE_SIZE_PX or size final int MAX_IMAGE_SIZE_PX = 5; if (mvr == null) { return false; } // get data points XYSeriesCollection collection = this.getMeanVariance(mvr); if (collection.getSeries().size() == 0) { return false; } ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart chart = ChartFactory.createScatterPlot("", "mean (log2)", "variance (log2)", collection, PlotOrientation.VERTICAL, false, false, false); // adjust colors and shapes XYRegressionRenderer renderer = new XYRegressionRenderer(); renderer.setBasePaint(Color.white); XYSeries series = collection.getSeries(0); int alpha = series.getItemCount() > THRESHOLD ? TRANSLUCENT : OPAQUE; renderer.setSeriesPaint(0, new Color(0, 0, 0, alpha)); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesStroke(1, new BasicStroke(1)); renderer.setSeriesShape(0, new Ellipse2D.Double(4, 4, 4, 4)); renderer.setSeriesShapesFilled(0, false); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, false); XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); // adjust the chart domain and ranges double yRange = series.getMaxY() - series.getMinY(); double xRange = series.getMaxX() - series.getMinX(); if (xRange < 0) { log.warn("Min X was greater than Max X: Max=" + series.getMaxY() + " Min= " + series.getMinY()); return false; } double ybuffer = (yRange) * OFFSET_FACTOR; double xbuffer = (xRange) * OFFSET_FACTOR; double newYMin = series.getMinY() - ybuffer; double newYMax = series.getMaxY() + ybuffer; double newXMin = series.getMinX() - xbuffer; double newXMax = series.getMaxX() + xbuffer; ValueAxis yAxis = new NumberAxis("Variance"); yAxis.setRange(newYMin, newYMax); ValueAxis xAxis = new NumberAxis("Mean"); xAxis.setRange(newXMin, newXMax); chart.getXYPlot().setRangeAxis(yAxis); chart.getXYPlot().setDomainAxis(xAxis); int finalSize = (int) Math.min( MAX_IMAGE_SIZE_PX * ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX, size * ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX); ChartUtilities.writeChartAsPNG(os, chart, finalSize, finalSize); return true; }
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/* w w w. j a v a 2 s .co 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:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java
/** * Creates panel.//from w ww.ja va 2s . c o m */ private void createPanel() { setLayout(new BorderLayout()); // CENTER: chart ChartPanel chartPanel = new ChartPanel(createChart()); // no context menu chartPanel.setPopupMenu(null); // not zoomable chartPanel.setMouseZoomable(false); add(chartPanel, BorderLayout.CENTER); // LINE_END: series table JPanel tablePanel = new JPanel(new GridBagLayout()); String[] columnNames = { messages.getString("ModelExecutionChartPanel.Table.ColumnNames.ExtraAxis"), messages.getString("ModelExecutionChartPanel.Table.ColumnNames.LevelNode") }; final MyTableModel tableModel = new MyTableModel(columnNames, xySeriesArray.length); for (int i = 0; i < xySeriesArray.length; i++) { tableModel.addEntry((String) xySeriesArray[i].getKey()); } JTable table = new JTable(tableModel); table.setRowSelectionAllowed(false); JScrollPane tableScrollPane = new JScrollPane(table); int width = (int) Math.min(300, table.getPreferredSize().getWidth()); int height = (int) Math.min(200, table.getPreferredSize().getHeight()); tableScrollPane.getViewport().setPreferredSize(new Dimension(width, height)); tableScrollPane.setMaximumSize(tableScrollPane.getViewport().getPreferredSize()); axesButton = new JButton(messages.getString("ModelExecutionChartPanel.AxesButton.Text")); axesButton.setToolTipText(messages.getString("ModelExecutionChartPanel.AxesButton.ToolTipText")); axesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // create XYSeriesCollections (and renderer) XYSeriesCollection standardData = new XYSeriesCollection(); XYLineAndShapeRenderer standardRenderer = new XYLineAndShapeRenderer(true, false); LinkedList<XYSeriesCollection> extraDataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> extraRendererList = new LinkedList<XYLineAndShapeRenderer>(); for (int i = 0; i < tableModel.getRowCount(); i++) { if (tableModel.getValueAt(i, 0).equals(Boolean.FALSE)) { standardData.addSeries(xySeriesArray[i]); standardRenderer.setSeriesPaint(standardData.getSeriesCount() - 1, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } else { // extra axis XYSeriesCollection extraData = new XYSeriesCollection(); extraData.addSeries(xySeriesArray[i]); extraDataList.add(extraData); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); extraRendererList.add(renderer); renderer.setSeriesPaint(0, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } } LinkedList<XYSeriesCollection> dataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> rendererList = new LinkedList<XYLineAndShapeRenderer>(); if (!standardData.getSeries().isEmpty()) { dataList.add(standardData); rendererList.add(standardRenderer); } for (XYSeriesCollection data : extraDataList) { dataList.add(data); } for (XYLineAndShapeRenderer renderer : extraRendererList) { rendererList.add(renderer); } // creates axes LinkedList<NumberAxis> axesList = new LinkedList<NumberAxis>(); if (!standardData.getSeries().isEmpty()) { NumberAxis axis = new NumberAxis(messages.getString("ModelExecutionChartPanel.Value")); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } for (XYSeriesCollection data : extraDataList) { NumberAxis axis = new NumberAxis((String) data.getSeries(0).getKey()); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } // store data and axes in plot XYPlot plot = chart.getXYPlot(); plot.clearRangeAxes(); plot.setRangeAxes(axesList.toArray(new NumberAxis[0])); for (int i = 0; i < plot.getDatasetCount(); i++) { plot.setDataset(i, null); } int datasetIndex = 0; Iterator<XYSeriesCollection> datasetIterator = dataList.iterator(); Iterator<XYLineAndShapeRenderer> rendererIterator = rendererList.iterator(); while (datasetIterator.hasNext()) { plot.setDataset(datasetIndex, datasetIterator.next()); plot.setRenderer(datasetIndex, rendererIterator.next()); datasetIndex++; } for (int i = 0; i < plot.getDatasetCount(); i++) { plot.mapDatasetToRangeAxis(i, i); } } }); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 0; c.insets = new Insets(0, 0, 10, 0); tablePanel.add(tableScrollPane, c); c.gridx = 0; c.gridy = 1; tablePanel.add(axesButton, c); add(tablePanel, BorderLayout.LINE_END); // PAGE_END: number of rounds and execution button JPanel commandPanel = new JPanel(); commandPanel.add(new JLabel(messages.getString("ModelExecutionChartPanel.NumberRounds"))); final JTextField numberRoundsField = new JTextField("1", 5); numberRoundsField.addFocusListener(this); commandPanel.add(numberRoundsField); executionButton = new JButton(messages.getString("ModelExecutionChartPanel.ExecutionButton.Text")); executionButton.setToolTipText(messages.getString("ModelExecutionChartPanel.ExecutionButton.ToolTipText")); executionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int numberRounds = 0; boolean correctNumber = false; try { numberRounds = integerNumberFormatter.parse(numberRoundsField.getText()).intValue(); } catch (ParseException parseExcep) { // do nothing } if (numberRounds >= 1) { correctNumber = true; } if (correctNumber) { ModelExecutionThread executionThread = new ModelExecutionThread(numberRounds); executionThread.start(); } else { JOptionPane.showMessageDialog(null, messages.getString("ModelExecutionChartPanel.Error.Message"), messages.getString("ModelExecutionChartPanel.Error.Title"), JOptionPane.ERROR_MESSAGE); } } }); commandPanel.add(executionButton); add(commandPanel, BorderLayout.PAGE_END); }
From source file:jspritTest.util.Plotter.java
private LegendTitle createLegend(final Collection<VehicleRoute> routes, final XYSeriesCollection shipments, final XYPlot plot) { LegendItemSource lis = new LegendItemSource() { public LegendItemCollection getLegendItems() { LegendItemCollection lic = new LegendItemCollection(); LegendItem vehLoc = new LegendItem("vehLoc", Color.RED); vehLoc.setShape(ELLIPSE);/* w ww .j a v a 2 s. c om*/ vehLoc.setShapeVisible(true); lic.add(vehLoc); if (containsServiceAct) { LegendItem item = new LegendItem("service", Color.BLUE); item.setShape(ELLIPSE); item.setShapeVisible(true); lic.add(item); } if (containsPickupAct) { LegendItem item = new LegendItem("pickup", Color.GREEN); item.setShape(ELLIPSE); item.setShapeVisible(true); lic.add(item); } if (containsDeliveryAct) { LegendItem item = new LegendItem("delivery", Color.BLUE); item.setShape(ELLIPSE); item.setShapeVisible(true); lic.add(item); } if (routes != null) { LegendItem item = new LegendItem("firstActivity", Color.BLACK); Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f); item.setShape(upTriangle); item.setOutlinePaint(Color.BLACK); item.setLine(upTriangle); item.setLinePaint(Color.BLACK); item.setShapeVisible(true); lic.add(item); } if (!shipments.getSeries().isEmpty()) { lic.add(plot.getRenderer(1).getLegendItem(1, 0)); } if (routes != null) { lic.addAll(plot.getRenderer(2).getLegendItems()); } return lic; } }; LegendTitle legend = new LegendTitle(lis); legend.setPosition(RectangleEdge.BOTTOM); return legend; }
From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java
private LegendTitle createLegend(final Collection<VehicleRoute> routes, final XYSeriesCollection shipments, final XYPlot plot) { LegendItemSource lis = new LegendItemSource() { @Override/* ww w .jav a 2 s.co m*/ public LegendItemCollection getLegendItems() { LegendItemCollection lic = new LegendItemCollection(); LegendItem vehLoc = new LegendItem("vehLoc", Color.RED); vehLoc.setShape(ELLIPSE); vehLoc.setShapeVisible(true); lic.add(vehLoc); if (containsServiceAct) { LegendItem item = new LegendItem("service", Color.BLUE); item.setShape(ELLIPSE); item.setShapeVisible(true); lic.add(item); } if (containsPickupAct) { LegendItem item = new LegendItem("pickup", Color.GREEN); item.setShape(ELLIPSE); item.setShapeVisible(true); lic.add(item); } if (containsDeliveryAct) { LegendItem item = new LegendItem("delivery", Color.BLUE); item.setShape(ELLIPSE); item.setShapeVisible(true); lic.add(item); } if (routes != null) { LegendItem item = new LegendItem("firstActivity", Color.BLACK); Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f); item.setShape(upTriangle); item.setOutlinePaint(Color.BLACK); item.setLine(upTriangle); item.setLinePaint(Color.BLACK); item.setShapeVisible(true); lic.add(item); } if (!shipments.getSeries().isEmpty()) { lic.add(plot.getRenderer(1).getLegendItem(1, 0)); } if (routes != null) { lic.addAll(plot.getRenderer(2).getLegendItems()); } return lic; } }; LegendTitle legend = new LegendTitle(lis); legend.setPosition(RectangleEdge.BOTTOM); return legend; }
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/* w w w . j ava2 s. co m*/ * @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"); } }