Skip to content

Commit

Permalink
Merge pull request #89 from hchriste/clusteredbar-visible-series
Browse files Browse the repository at this point in the history
Update ClusteredXYBarRenderer to account for visibility of series
  • Loading branch information
jfree committed Nov 14, 2020
2 parents ec31284 + e0720ac commit 42261ea
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.EntityCollection;
Expand Down Expand Up @@ -222,11 +224,15 @@ protected Range findDomainBoundsWithOffset(IntervalXYDataset dataset) {
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
public void drawItem(Graphics2D g2, XYItemRendererState state,
Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
int series, int item, CrosshairState crosshairState, int pass) {

if (!getItemVisible(series, item)) {
return;
}

IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

double y0;
Expand Down Expand Up @@ -271,12 +277,21 @@ public void drawItem(Graphics2D g2, XYItemRendererState state,

PlotOrientation orientation = plot.getOrientation();

int numSeries = dataset.getSeriesCount();

List<Integer> visibleSeries = new ArrayList<Integer>();
for (int i = 0; i < dataset.getSeriesCount(); i++) {
if (isSeriesVisible(i)) {
visibleSeries.add(i);
}
}

int numSeries = visibleSeries.size();
double seriesBarWidth = intervalW / numSeries; // may be negative
int visibleSeriesIndex = visibleSeries.indexOf(series);

Rectangle2D bar = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double barY0 = baseX + (seriesBarWidth * series);
double barY0 = baseX + (seriesBarWidth * visibleSeriesIndex);
double barY1 = barY0 + seriesBarWidth;
double rx = Math.min(yy0, yy1);
double rw = intervalH;
Expand All @@ -285,7 +300,7 @@ public void drawItem(Graphics2D g2, XYItemRendererState state,
bar = new Rectangle2D.Double(rx, ry, rw, rh);
}
else if (orientation == PlotOrientation.VERTICAL) {
double barX0 = baseX + (seriesBarWidth * series);
double barX0 = baseX + (seriesBarWidth * visibleSeriesIndex);
double barX1 = barX0 + seriesBarWidth;
double rx = Math.min(barX0, barX1);
double rw = Math.abs(barX1 - barX0);
Expand Down Expand Up @@ -316,7 +331,7 @@ else if (orientation == PlotOrientation.VERTICAL) {
}
if (pass == 0 && getShadowsVisible()) {
getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase,
!getUseYInterval());
!getUseYInterval());
}
if (pass == 1) {
getBarPainter().paintBar(g2, this, series, item, bar, barBase);
Expand Down

0 comments on commit 42261ea

Please sign in to comment.