Skip to content
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

Update ClusteredXYBarRenderer to account for visibility of series #89

Merged
merged 2 commits into from
Nov 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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