}
/** Return an IntervalCategoryDataset for this model for the given category */
public IntervalCategoryDataset getIntervalCategoryDataset(String category) {
TaskSeriesCollection collection = new TaskSeriesCollection();
TaskSeries taskSeries = new TaskSeries("Targets");
// calculate the target description field widths, so they can be lined up in columns
int[] maxWidths = _calculateTargetDescriptionColumnWidths(_targets);
int totalWidth = 0;
for (int maxWidth : maxWidths) {
totalWidth += maxWidth;
}
// make the dataset
for (int i = 0; i < _targets.length; i++) {
if (_targets[i].getCategory().equals(category)) {
String name = _getTargetDescription(_targets[i], maxWidths, totalWidth);
Date[] times = _xDate[i];
double[] elevations = _yData[i];
Date[] xTimes = _findCrossingPoints(times, elevations);
if (xTimes.length == 2) {
// simple range
Task task = new Task(name, new SimpleTimePeriod(xTimes[0], xTimes[1]));
taskSeries.add(task);
} else {
// range is split and wraps around graph
Task task = new Task(name, new SimpleTimePeriod(xTimes[0], xTimes[xTimes.length - 1]));
int n = xTimes.length / 2;
for (int j = 0; j < n; j++) {
Task subtask = new Task(name, new SimpleTimePeriod(xTimes[j * 2], xTimes[j * 2 + 1]));
task.addSubtask(subtask);
}
taskSeries.add(task);
}
}
}
collection.add(taskSeries);
return collection;
}