Skip to content

Commit

Permalink
Observe series visibility in ClusteredXYBarRenderer (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfree committed Nov 14, 2020
1 parent 46cb5de commit 7d7ead4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ History
-------

##### Version 1.5.2 (not yet released)
- observe series visibility flag in `ClusteredXYBarRenderer` ([#89](https:/jfree/jfreechart/issues/89));
- apply rendering hints to overlays ([#187](https:/jfree/jfreechart/issues/187));
- don't draw disabled outlines on crosshair labels ([#189](https:/jfree/jfreechart/pull/189));
- ensure label offsets are used in `CrosshairOverlay` ([#190](https:/jfree/jfreechart/pull/190));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,22 @@
* ---------------------------
* ClusteredXYBarRenderer.java
* ---------------------------
* (C) Copyright 2003-2016, by Paolo Cova and Contributors.
* (C) Copyright 2003-2020, by Paolo Cova and Contributors.
*
* Original Author: Paolo Cova;
* Contributor(s): David Gilbert (for Object Refinery Limited);
* Christian W. Zuckschwerdt;
* Matthias Rose;
*
* Changes
* -------
* 24-Jan-2003 : Version 1, contributed by Paolo Cova (DG);
* 25-Mar-2003 : Implemented Serializable (DG);
* 01-May-2003 : Modified drawItem() method signature (DG);
* 30-Jul-2003 : Modified entity constructor (CZ);
* 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
* 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
* 07-Oct-2003 : Added renderer state (DG);
* 03-Nov-2003 : In draw method added state parameter and y==null value
* handling (MR);
* 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
* 15-Jul-2004 : Switched getX() with getXValue() and getY() with
* getYValue() (DG);
* 01-Oct-2004 : Fixed bug where 'drawBarOutline' flag is ignored (DG);
* 16-May-2005 : Fixed to used outline stroke for bar outlines. Removed some
* redundant code with the result that the renderer now respects
* the 'base' setting from the super-class. Added an equals()
* method (DG);
* 19-May-2005 : Added minimal item label implementation - needs improving (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 11-Dec-2006 : Added support for GradientPaint (DG);
* 12-Jun-2007 : Added override to findDomainBounds() to handle cluster offset,
* fixed rendering to handle inverted axes, and simplified
* entity generation code (DG);
* 24-Jun-2008 : Added new barPainter mechanism (DG);
* 03-Jul-2013 : Use ParamChecks (DG);
*
*/

package org.jfree.chart.renderer.xy;

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 @@ -155,8 +129,7 @@ public Range findDomainBounds(XYDataset dataset) {
// need to handle cluster centering as a special case
if (this.centerBarAtStartValue) {
return findDomainBoundsWithOffset((IntervalXYDataset) dataset);
}
else {
} else {
return super.findDomainBounds(dataset);
}
}
Expand Down Expand Up @@ -192,8 +165,7 @@ protected Range findDomainBoundsWithOffset(IntervalXYDataset dataset) {

if (minimum > maximum) {
return null;
}
else {
} else {
return new Range(minimum, maximum);
}
}
Expand Down Expand Up @@ -227,15 +199,18 @@ public void drawItem(Graphics2D g2, XYItemRendererState state,
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;
double y1;
if (getUseYInterval()) {
y0 = intervalDataset.getStartYValue(series, item);
y1 = intervalDataset.getEndYValue(series, item);
}
else {
} else {
y0 = getBase();
y1 = intervalDataset.getYValue(series, item);
}
Expand Down Expand Up @@ -271,21 +246,28 @@ 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;
double ry = Math.min(barY0, barY1);
double rh = Math.abs(barY1 - barY0);
bar = new Rectangle2D.Double(rx, ry, rw, rh);
}
else if (orientation == PlotOrientation.VERTICAL) {
double barX0 = baseX + (seriesBarWidth * series);
} else if (orientation == PlotOrientation.VERTICAL) {
double barX0 = baseX + (seriesBarWidth * visibleSeriesIndex);
double barX1 = barX0 + seriesBarWidth;
double rx = Math.min(barX0, barX1);
double rw = Math.abs(barX1 - barX0);
Expand All @@ -301,16 +283,13 @@ else if (orientation == PlotOrientation.VERTICAL) {
if (orientation == PlotOrientation.HORIZONTAL) {
if (positive && inverted || !positive && !inverted) {
barBase = RectangleEdge.RIGHT;
}
else {
} else {
barBase = RectangleEdge.LEFT;
}
}
else {
} else {
if (positive && !inverted || !positive && inverted) {
barBase = RectangleEdge.BOTTOM;
}
else {
} else {
barBase = RectangleEdge.TOP;
}
}
Expand Down

0 comments on commit 7d7ead4

Please sign in to comment.