List of usage examples for org.jfree.data.general AbstractSeriesDataset getSeriesCount
@Override public abstract int getSeriesCount();
From source file:org.mwc.cmap.xyplot.views.XYPlotView.java
@SuppressWarnings("deprecation") private void fillThePlot(final String title, final String units, final formattingOperation theFormatter, final AbstractSeriesDataset dataset) { final StepControl _theStepper = null; // the working variables we rely on later _thePlotArea = null;//from ww w . j ava 2s. co m ValueAxis xAxis = null; XYToolTipGenerator tooltipGenerator = null; // the y axis is common to hi & lo res. Format it here final NumberAxis yAxis = new NumberAxis(units); final Font tickFont = new Font("SansSerif", Font.PLAIN, 14); Font labelFont = new Font("SansSerif", Font.PLAIN, 16); yAxis.setLabelFont(labelFont); yAxis.setTickLabelFont(tickFont); // hmm, see if we are in hi-res mode. If we are, don't use a formatted // y-axis, just use the plain long microseconds // value if (HiResDate.inHiResProcessingMode()) { // final SimpleDateFormat _secFormat = new SimpleDateFormat("ss"); // ok, simple enough for us... final NumberAxis nAxis = new NumberAxis("time (secs.micros)") { /** * */ private static final long serialVersionUID = 1L; // public String getTickLabel(double currentTickValue) // { // long time = (long) currentTickValue; // Date dtg = new HiResDate(0, time).getDate(); // String res = _secFormat.format(dtg) + "." // + DebriefFormatDateTime.formatMicros(new HiResDate(0, time)); // return res; // } }; nAxis.setAutoRangeIncludesZero(false); xAxis = nAxis; // just show the raw data values tooltipGenerator = new StandardXYToolTipGenerator(); } else { // create a date-formatting axis final DateAxis dAxis = new RelativeDateAxis(); dAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits()); xAxis = dAxis; // also create the date-knowledgable tooltip writer tooltipGenerator = new DatedToolTipGenerator(); } xAxis.setTickLabelFont(tickFont); xAxis.setLabelFont(labelFont); // create the special stepper plot final ColourStandardXYItemRenderer theRenderer = new ColourStandardXYItemRenderer(tooltipGenerator, null, null); _thePlot = new StepperXYPlot(null, (RelativeDateAxis) xAxis, yAxis, _theStepper, theRenderer); theRenderer.setPlot(_thePlot); theRenderer.setStroke(new BasicStroke(3.0f)); _thePlot.setRangeGridlineStroke(new BasicStroke(1f)); _thePlot.setDomainGridlineStroke(new BasicStroke(1f)); _thePlot.setRangeGridlinePaint(Color.LIGHT_GRAY); xAxis.setTickMarkStroke(new BasicStroke(1f)); yAxis.setTickMarkStroke(new BasicStroke(1f)); _thePlot.setOutlineStroke(new BasicStroke(2f)); // loop through the datasets, setting the color of each series to the first // color in that series if (dataset instanceof TimeSeriesCollection) { Color seriesCol = null; final TimeSeriesCollection tsc = (TimeSeriesCollection) dataset; for (int i = 0; i < dataset.getSeriesCount(); i++) { final TimeSeries ts = tsc.getSeries(i); if (ts.getItemCount() > 0) { final TimeSeriesDataItem dataItem = ts.getDataItem(0); if (dataItem instanceof ColouredDataItem) { final ColouredDataItem cd = (ColouredDataItem) dataItem; seriesCol = cd.getColor(); _thePlot.getRenderer().setSeriesPaint(i, seriesCol); } } } } // apply any formatting for this choice if (theFormatter != null) { theFormatter.format(_thePlot); } boolean createLegend = dataset.getSeriesCount() > 1; _thePlotArea = new NewFormattedJFreeChart(title, null, _thePlot, createLegend, _theStepper); // set the color of the area surrounding the plot // - naah, don't bother. leave it in the application background color. _thePlotArea.setBackgroundPaint(Color.white); // //////////////////////////////////////////////// // put the holder into one of our special items // //////////////////////////////////////////////// _chartInPanel = new StepperChartPanel(_thePlotArea, true, _theStepper); // ok - we need to fire time-changes to the chart setupFiringChangesToChart(); // format the chart _chartInPanel.setName(title); _chartInPanel.setMouseZoomable(true, true); // and insert into the composite _plotControl.setChart(_thePlotArea); // get the cross hairs ready _thePlot.setDomainCrosshairVisible(true); _thePlot.setRangeCrosshairVisible(true); _thePlot.setDomainCrosshairPaint(Color.GRAY); _thePlot.setRangeCrosshairPaint(Color.GRAY); _thePlot.setDomainCrosshairStroke(new BasicStroke(2)); _thePlot.setRangeCrosshairStroke(new BasicStroke(2)); // and the plot object to display the cross hair value _crosshairValueText = new XYTextAnnotation(" ", 0, 0); _crosshairValueText.setTextAnchor(TextAnchor.TOP_LEFT); _crosshairValueText.setFont(new Font("SansSerif", Font.BOLD, 15)); _crosshairValueText.setPaint(Color.black); _crosshairValueText.setBackgroundPaint(Color.white); _thePlot.addAnnotation(_crosshairValueText); _thePlotArea.addChangeListener(new ChartChangeListener() { @Override public void chartChanged(ChartChangeEvent event) { if (_showSymbols.isShowSymbols() != _thePlotArea.isShowSymbols()) { _showSymbols.updateAction(); } } }); _showSymbols.updateAction(); _thePlotArea.addProgressListener(new ChartProgressListener() { public void chartProgress(final ChartProgressEvent cpe) { if (cpe.getType() != ChartProgressEvent.DRAWING_FINISHED) return; // double-check our label is still in the right place final double xVal = _thePlot.getRangeAxis().getUpperBound(); final double yVal = _thePlot.getDomainAxis().getLowerBound(); boolean annotChanged = false; if (_crosshairValueText.getX() != yVal) { _crosshairValueText.setX(yVal); annotChanged = true; } if (_crosshairValueText.getY() != xVal) { _crosshairValueText.setY(xVal); annotChanged = true; } // and write the text final String numA = MWC.Utilities.TextFormatting.GeneralFormat .formatOneDecimalPlace(_thePlot.getRangeCrosshairValue()); final Date newDate = new Date((long) _thePlot.getDomainCrosshairValue()); final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss"); _df.setTimeZone(TimeZone.getTimeZone("GMT")); final String dateVal = _df.format(newDate); final String theMessage = " [" + dateVal + "," + numA + "]"; if (!theMessage.equals(_crosshairValueText.getText())) { _crosshairValueText.setText(theMessage); annotChanged = true; } if (annotChanged) { _plotControl.getChart().setNotify(true); } } }); // //////////////////////////////////////////////////// // put the time series into the plot // //////////////////////////////////////////////////// _thePlot.setDataset((XYDataset) dataset); }
From source file:Debrief.Tools.FilterOperations.ShowTimeVariablePlot3.java
/** * Collate the data points to plot/*from w ww . j a v a 2 s . c o m*/ * * @param primaryTrack * the primary track * @param myOperation * the calculation we're making * @param theTracks * the selected set of tracks * @param start_time * the start time selected * @param end_time * the end time selected * @param provider * the provider of the time offset used when plotting time-zero data * @return the dataset to plot * @see toteCalculation#isWrappableData * @see toteCalculation#calculate(Watchable primary,Watchable * secondary,HiResDate thisTime) * @see Debrief.Tools.FilterOperations.ShowTimeVariablePlot3.CalculationHolder#isARelativeCalculation * @see WatchableList#getItemsBetween(HiResDate start,HiResDate end) * @see TimeSeriesCollection#addSeries(BasicTimeSeries series) */ public static AbstractSeriesDataset getDataSeries(final WatchableList primaryTrack, final CalculationHolder myOperation, final Vector<WatchableList> theTracks, final HiResDate start_time, final HiResDate end_time, final ColouredDataItem.OffsetProvider provider) { final toteCalculation theCalculation = myOperation._theCalc; AbstractSeriesDataset theSeriesCollection = null; // ok, now collate the data VersatileSeriesAdder theAdder = null; // sort out the adder for what we're doing if (HiResDate.inHiResProcessingMode()) { theSeriesCollection = new TimeSeriesCollection(); theAdder = new VersatileSeriesAdder() { public void add(final Series thisSeries, final HiResDate theTime, final double data, final Color thisColor, final boolean connectToPrevious, final ColouredDataItem.OffsetProvider provider1) { // HI-RES NOT DONE - FixedMillisecond should be converted // some-how to // FixedMicroSecond final TimeSeriesDataItem newItem = new ColouredDataItem( new FixedMillisecond((long) (theTime.getMicros() / 1000d)), data, thisColor, connectToPrevious, provider1); // To change body of implemented methods use File | Settings // | File // Templates. final TimeSeries theSeries = (TimeSeries) thisSeries; theSeries.add(newItem); } public void addSeries(final AbstractSeriesDataset collection, final Series thisSeries, final Color defaultColor) { final TimeSeriesCollection coll = (TimeSeriesCollection) collection; coll.addSeries((TimeSeries) thisSeries); } }; } else { theSeriesCollection = new TimeSeriesCollection(); // right, just working with normal dates theAdder = new VersatileSeriesAdder() { public void add(final Series thisSeries, final HiResDate theTime, final double data, final Color thisColor, final boolean connectToPrevious, final ColouredDataItem.OffsetProvider provider1) { // HI-RES NOT DONE - FixedMillisecond should be converted // some-how to // FixedMicroSecond final ColouredDataItem newItem = new ColouredDataItem( new FixedMillisecond(theTime.getDate().getTime()), data, thisColor, connectToPrevious, provider1); // To change body of implemented methods use File | Settings // | File // Templates. final TimeSeries theSeries = (TimeSeries) thisSeries; theSeries.add(newItem); } public void addSeries(final AbstractSeriesDataset collection, final Series thisSeries, final Color defaultColor) { final TimeSeriesCollection coll = (TimeSeriesCollection) collection; coll.addSeries((TimeSeries) thisSeries); } }; } // calculate the data variables for our tracks final Enumeration<WatchableList> iter = theTracks.elements(); while (iter.hasMoreElements()) { final WatchableList thisSecondaryTrack = (WatchableList) iter.nextElement(); // is this a relative calculation? if (myOperation.isARelativeCalculation()) { // yes, but we don't bother with the primary track, see if this // is it if (thisSecondaryTrack == primaryTrack) { // just double check that we have primary data final Collection<Editable> ss = thisSecondaryTrack.getItemsBetween(start_time, end_time); if (ss == null) { Application.logError2(ToolParent.WARNING, "Insufficient points found in primary track." + "\nPlease check coverage of time controller bars", null); return null; } // drop out, and wait for the next cycle continue; } } // //////////////////////////////////////////////////// // step through the track // final Collection<Editable> ss = thisSecondaryTrack.getItemsBetween(start_time, end_time); // indicator for whether we join this data point to the previous one boolean connectToPrevious = false; // have we found any?. Hey, listen here. The "getItemsBetween" // method may return data items, but we may still not be able to do the calc // (such as if we have "NaN" for depth). So we still do a sanity check // at the end of this method to stop us adding empty data series to the collection. if (ss == null) { Application.logError2(ToolParent.WARNING, "Insufficient points found in primary track." + "\nPlease check coverage of time controller bars", null); return null; } else { // remember the default color for this series Color seriesColor; // ok, now collate the data Series thisSeries = null; // sort out the adder for what we're doing if (HiResDate.inHiResProcessingMode()) { thisSeries = new XYSeries(thisSecondaryTrack.getName()); } else { thisSeries = new TimeSeries(thisSecondaryTrack.getName()); } seriesColor = thisSecondaryTrack.getColor(); // split into separate processing here, depending on where we're // looking // at a relative calculation if (myOperation.isARelativeCalculation()) { // yes, it is a relative calculation. // Find out if it's a special case (where we don't have time // data) if (thisSecondaryTrack.getStartDTG() == null) { // do we have any primary data to fall back on (to // decide the times // for // data points) if (primaryTrack.getStartDTG() == null) { // //////////////////////////////////////////////// // CASE 1 - neither track has time data, relative // calc // //////////////////////////////////////////////// // so, we don't have primary or secondary data. // produce data // values at the start and end of the track // produce data points at the primary track // locations final Iterator<Editable> it = ss.iterator(); final Watchable theSecondaryPoint = (Watchable) it.next(); // get an iterator for the primary track final Collection<Editable> primaryPoints = primaryTrack.getItemsBetween(start_time, end_time); // do we have any primary data in this period if (primaryPoints != null) { final Iterator<Editable> throughPrimary = primaryPoints.iterator(); final Watchable thisPrimary = (Watchable) throughPrimary.next(); // ok, create the series with it's two points in produceTwoPointDataSeries(theCalculation, thisPrimary, theSecondaryPoint, thisSeries, start_time, end_time, provider, theAdder); } } else { // //////////////////////////////////////////////// // CASE 2 - secondary track has time data, relative // calc // //////////////////////////////////////////////// // so, we do have time data for the secondary track, // but not on // the primary track // therefore we produce data points at the primary // track locations final Watchable[] theSecondaryPoints = thisSecondaryTrack.getNearestTo(start_time); final Watchable theSecondaryPoint = theSecondaryPoints[0]; final Color thisColor = theSecondaryPoint.getColor(); // get an iterator for the primary track final Collection<Editable> primaryPoints = primaryTrack.getItemsBetween(start_time, end_time); if (primaryPoints != null) { final Iterator<Editable> throughPrimary = primaryPoints.iterator(); while (throughPrimary.hasNext()) { final Watchable thisPrimary = (Watchable) throughPrimary.next(); final HiResDate currentTime = thisPrimary.getTime(); // and add the new data point (if we have // to) connectToPrevious = createDataPoint(theCalculation, thisPrimary, theSecondaryPoint, currentTime, connectToPrevious, thisColor, thisSeries, provider, theAdder); } // stepping through the primary track } // whether we have primary points } } else // whether we have DTG data { // //////////////////////////////////////////////// // CASE 3 - both tracks have time data, relative calc // //////////////////////////////////////////////// // yes, we do have DTG data for this track - hooray! // ok, step through the list final Iterator<Editable> it = ss.iterator(); // remember the last point - used to check if we're // passing through // zero degs double lastSecondaryValue = Double.NaN; // we we're // using NaN but // it // was failing the equality // test HiResDate lastTime = null; throughThisTrack: while (it.hasNext()) { final Watchable thisSecondary = (Watchable) it.next(); final Color thisColor = thisSecondary.getColor(); // what's the current time? final HiResDate currentTime = thisSecondary.getTime(); // is this fix visible? if (thisSecondary.getVisible()) { // the point on the primary track we work with Watchable thisPrimary = null; // find the fix on the primary track which is // nearest in // time to this one (if we need to) Watchable[] nearList; // temp switch on interpolation Boolean oldInterp = null; if (primaryTrack instanceof ISecondaryTrack) { final ISecondaryTrack tw = (ISecondaryTrack) primaryTrack; oldInterp = tw.getInterpolatePoints(); tw.setInterpolatePoints(true); } // find it's nearest point on the primary track nearList = primaryTrack.getNearestTo(currentTime); // and restore the interpolate points setting if (oldInterp != null) { final ISecondaryTrack tw = (ISecondaryTrack) primaryTrack; tw.setInterpolatePoints(oldInterp.booleanValue()); } // yes. right, we only perform a calc if we have // primary data // for this point if (nearList.length == 0) { // remember that the next point doesn't // connect to it's // previous one // since we want to show the gap represented // by this datum connectToPrevious = false; // drop out, and wait for the next cycle continue throughThisTrack; } else { thisPrimary = nearList[0]; } // //////////////////////////////////////////////// // NOW PUT IN BIT TO WRAP THROUGH ZERO WHERE // APPLICABLE // //////////////////////////////////////////////// // produce the new calculated value final double thisVal = theCalculation.calculate(thisSecondary, thisPrimary, currentTime); // SPECIAL HANDLING - do we need to check if // this data passes // through 360 degs? if (theCalculation.isWrappableData()) { // add extra points, if we need to connectToPrevious = insertWrappingPoints(theCalculation, lastSecondaryValue, thisVal, lastTime, currentTime, thisColor, thisSeries, connectToPrevious, provider, theAdder, myOperation._clipMax); } // //////////////////////////////////////////////// // THANK YOU, WE'RE PLEASED TO RETURN YOU TO // YOUR NORMAL PROGRAM // //////////////////////////////////////////////// // and add the new data point (if we have to) connectToPrevious = createDataPoint(theCalculation, thisPrimary, thisSecondary, currentTime, connectToPrevious, thisColor, thisSeries, provider, theAdder); lastSecondaryValue = thisVal; lastTime = currentTime; } // whether this point is visible } // stepping through this track } // whether we have DTG data } else { // so, this is an absolute calculation - we don't need to // worry about // the primry // track // do we have time data for this secondary track? if (thisSecondaryTrack.getStartDTG() == null) { // //////////////////////////////////////////////// // CASE 4 - no time data, non-relative calculation // //////////////////////////////////////////////// // it's ok. It we don't have time related data for this // point we // just create // data points for it at the start & end of the track // ok, create the series with it's two points in // ok, step through the list final Iterator<Editable> it = ss.iterator(); final Watchable thisSecondary = (Watchable) it.next(); // and produceTwoPointDataSeries(theCalculation, null, thisSecondary, thisSeries, start_time, end_time, provider, theAdder); } else { // //////////////////////////////////////////////// // CASE 5 - with time data, non-relative calculation // //////////////////////////////////////////////// // ok, step through the list final Iterator<Editable> it = ss.iterator(); // remember the last point - used to check if we're // passing through // zero degs double lastSecondaryValue = Double.NaN; // we we're // using NaN but // it // was failing the equality // test HiResDate lastTime = null; while (it.hasNext()) { final Watchable thisSecondary = (Watchable) it.next(); // / get the colour final Color thisColor = thisSecondary.getColor(); // what's the time of this data point? final HiResDate currentTime = thisSecondary.getTime(); // produce the new calculated value final double thisVal = theCalculation.calculate(thisSecondary, null, currentTime); // SPECIAL HANDLING - do we need to check if this // data passes // through 360 degs? if (theCalculation.isWrappableData()) { // add extra points, if we need to connectToPrevious = insertWrappingPoints(theCalculation, lastSecondaryValue, thisVal, lastTime, currentTime, thisColor, thisSeries, connectToPrevious, provider, theAdder, myOperation._clipMax); } // is this fix visible? if (thisSecondary.getVisible()) { // the point on the primary track we work with final Watchable thisPrimary = null; // and add the new data point (if we have to) connectToPrevious = createDataPoint(theCalculation, thisPrimary, thisSecondary, currentTime, connectToPrevious, thisColor, thisSeries, provider, theAdder); lastSecondaryValue = thisVal; lastTime = new HiResDate(currentTime); } // whether this point is visible } // stepping through this secondary collection } // whether there was time-related data for this track } // whether this was a relative calculation // if the series if empty, set it to null, rather than create // one of // empty length if (thisSeries instanceof XYSeries) { final XYSeries ser = (XYSeries) thisSeries; if (ser.getItemCount() == 0) thisSeries = null; } else if (thisSeries instanceof TimeSeries) { final TimeSeries ser = (TimeSeries) thisSeries; if (ser.getItemCount() == 0) thisSeries = null; } // did we find anything? if (thisSeries != null) { theAdder.addSeries(theSeriesCollection, thisSeries, seriesColor); } } // if this collection actually had data } // looping through the tracks if (theSeriesCollection.getSeriesCount() == 0) theSeriesCollection = null; return theSeriesCollection; }