-
-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper way to iterate over datasets in XYPlot? #201
Comments
Usually I wrap such kind of multiple dataset charts in a class with a dataset-fields. I suppose it's a bad practice to obtain data that already stored in dataset, in your way datasets are just rendered UI |
Yeah, I have a set of tools for formatting and operating on XYPlots generically , so I have to rely on the XYPlot being able to report what datasets are available. It hadn't been a problem until I ran into the situation I described where I don't have "consecutive" dataset indices. |
Good point. I've added methods to XYPlot and CategoryPlot to return unmodifiable maps of the datasets and renderers. |
Thanks, David. We probably need similar methods for the domainAxes and rangeAxes maps (and any other index-based maps there may be). |
Methods for the axis maps are added now too. |
Another thing I noticed was in StandardChartTheme.applyToXYPlot and applytoCategoryPlot, there is iteration over the domain and range axes as well as the renderers that should probably use the new map methods rather than getting a count and getXXX(index). |
Also in XYPlot.drawDomainMarkers and drawRangeMarkers, there's an And also iteration over domainAxes in panDomainAxes and panRangeAxes in XYPlot, CombinedDomainXYPlot, and CombinedRangeXYPlot that should iterate over the axes maps. There may be more of these types of changes, but these are the ones I had previously identified. |
I have noticed that datasets are stored in a map by index in XYPlot. However, there is no exposed way of iterating over the datasets other than getDataset(int index). The rub is that getDatasetCount() returns the number of datasets in the map, not the maximum index value.
I have plots that have optional datasets, so there may be gaps in the indices. For instance: datasets={0=BaseDataset, 2=Dataset2}. There is no dataset with index=1. When you try to iterate over the available datasets in a generic way, there's no way to know what dataset indices are actually available for the plot:
for (int i=0; i<plot.getDatasetCount(); i++) { // plot.getDatasetCount() = 2
XYDataset d = plot.getDataset(i); // i will be 0 and 1, so you never get dataset 2.
}
To properly obtain all a plot's datasets when you don't know what the indices may be, should getDatasetCount() return the maximum value of the datasets map's keySet()? Or other methods provided to return, say, an unmodifiable collection of the datasets map's values()? Internally to XYPlot, this is how iteration is done: for (XYDataset dataset: this.datasets.values()) { ... }
The same issue applies to the other maps by index in XYPlot: getRendererCount(), getDomainAxisCount(), getRangeAxisCount()
The text was updated successfully, but these errors were encountered: