Skip to content

Commit

Permalink
Apply rendering hints to overlay drawing - fixes bug #187
Browse files Browse the repository at this point in the history
  • Loading branch information
jfree committed Nov 10, 2020
1 parent 532e3ab commit 39cca04
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ History
-------

##### Version 1.5.2 (not yet released)
- update French translations (https://github.com/jfree/jfreechart/pull/186);
- fix "Save_as" entries in localisation files (https://github.com/jfree/jfreechart/pull/184).
- apply rendering hints to overlays (bug #187);
- update French translations (PR #186);
- fix "Save_as" entries in localisation files (PR #184).

##### Version 1.5.1 (29 October 2020)
- add DeviationStepRenderer (PR #173)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jfree/chart/ChartPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,7 @@ else if (drawHeight > this.maximumDrawHeight) {

// zap the buffer onto the panel...
g2.drawImage(this.chartBuffer, insets.left, insets.top, (int) available.getWidth(), (int) available.getHeight(), this);
g2.addRenderingHints(this.chart.getRenderingHints()); // bug#187

} else { // redrawing the chart every time...
AffineTransform saved = g2.getTransform();
Expand Down
51 changes: 24 additions & 27 deletions src/main/java/org/jfree/chart/panel/CrosshairOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
* (C) Copyright 2000-2020, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
Expand All @@ -27,7 +27,7 @@
* ---------------------
* CrosshairOverlay.java
* ---------------------
* (C) Copyright 2011-2017, by Object Refinery Limited.
* (C) Copyright 2011-2020, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): John Matthews;
Expand Down Expand Up @@ -88,16 +88,16 @@ public class CrosshairOverlay extends AbstractOverlay implements Overlay,
private List<Crosshair> yCrosshairs;

/**
* Default constructor.
* Creates a new overlay that initially contains no crosshairs.
*/
public CrosshairOverlay() {
super();
this.xCrosshairs = new java.util.ArrayList<Crosshair>();
this.yCrosshairs = new java.util.ArrayList<Crosshair>();
this.xCrosshairs = new ArrayList<>();
this.yCrosshairs = new ArrayList<>();
}

/**
* Adds a crosshair against the domain axis and sends an
* Adds a crosshair against the domain axis (x-axis) and sends an
* {@link OverlayChangeEvent} to all registered listeners.
*
* @param crosshair the crosshair ({@code null} not permitted).
Expand Down Expand Up @@ -130,14 +130,14 @@ public void removeDomainCrosshair(Crosshair crosshair) {

/**
* Clears all the domain crosshairs from the overlay and sends an
* {@link OverlayChangeEvent} to all registered listeners.
* {@link OverlayChangeEvent} to all registered listeners (unless there
* were no crosshairs to begin with).
*/
public void clearDomainCrosshairs() {
if (this.xCrosshairs.isEmpty()) {
return; // nothing to do
return; // nothing to do - avoids firing change event
}
List<Crosshair> crosshairs = getDomainCrosshairs();
for (Crosshair c : crosshairs) {
for (Crosshair c : getDomainCrosshairs()) {
this.xCrosshairs.remove(c);
c.removePropertyChangeListener(this);
}
Expand All @@ -150,7 +150,7 @@ public void clearDomainCrosshairs() {
* @return A list of crosshairs.
*/
public List<Crosshair> getDomainCrosshairs() {
return new ArrayList<Crosshair>(this.xCrosshairs);
return new ArrayList<>(this.xCrosshairs);
}

/**
Expand Down Expand Up @@ -184,14 +184,14 @@ public void removeRangeCrosshair(Crosshair crosshair) {

/**
* Clears all the range crosshairs from the overlay and sends an
* {@link OverlayChangeEvent} to all registered listeners.
* {@link OverlayChangeEvent} to all registered listeners (unless there
* were no crosshairs to begin with).
*/
public void clearRangeCrosshairs() {
if (this.yCrosshairs.isEmpty()) {
return; // nothing to do
return; // nothing to do - avoids change notification
}
List<Crosshair> crosshairs = getRangeCrosshairs();
for (Crosshair c : crosshairs) {
for (Crosshair c : getRangeCrosshairs()) {
this.yCrosshairs.remove(c);
c.removePropertyChangeListener(this);
}
Expand All @@ -204,7 +204,7 @@ public void clearRangeCrosshairs() {
* @return A list of crosshairs.
*/
public List<Crosshair> getRangeCrosshairs() {
return new ArrayList<Crosshair>(this.yCrosshairs);
return new ArrayList<>(this.yCrosshairs);
}

/**
Expand All @@ -219,7 +219,10 @@ public void propertyChange(PropertyChangeEvent e) {
}

/**
* Paints the crosshairs in the layer.
* Renders the crosshairs in the overlay on top of the chart that has just
* been rendered in the specified {@code chartPanel}. This method is
* called by the JFreeChart framework, you won't normally call it from
* user code.
*
* @param g2 the graphics target.
* @param chartPanel the chart panel.
Expand All @@ -233,32 +236,26 @@ public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
XYPlot plot = (XYPlot) chart.getPlot();
ValueAxis xAxis = plot.getDomainAxis();
RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
Iterator<Crosshair> iterator = this.xCrosshairs.iterator();
while (iterator.hasNext()) {
Crosshair ch = iterator.next();
for (Crosshair ch : this.xCrosshairs) {
if (ch.isVisible()) {
double x = ch.getValue();
double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
drawVerticalCrosshair(g2, dataArea, xx, ch);
}
else {
} else {
drawHorizontalCrosshair(g2, dataArea, xx, ch);
}
}
}
ValueAxis yAxis = plot.getRangeAxis();
RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
iterator = this.yCrosshairs.iterator();
while (iterator.hasNext()) {
Crosshair ch = iterator.next();
for (Crosshair ch : this.yCrosshairs) {
if (ch.isVisible()) {
double y = ch.getValue();
double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
drawHorizontalCrosshair(g2, dataArea, yy, ch);
}
else {
} else {
drawVerticalCrosshair(g2, dataArea, yy, ch);
}
}
Expand Down

0 comments on commit 39cca04

Please sign in to comment.