jfree/jfreechart-fse — pull request #24 by amishwins (2013-10-27 17:29:27+00:00)
Title: Fix bug 1109 - Color of a zero-value middle bar in a Waterfall chart 

This pull request fixes the bug as described in http://sourceforge.net/p/jfreechart/bugs/1109/. The issue was that in the WaterfallBarRenderer class, a middle column having a value of 0 would be rendered using the wrong Paint object for the series. When viewing a JPEG image of the chart, it was evident that the color of the zero-value bar was the same as the last bar. My colleague Dimitri and I added steps in the bug report to show how to reproduce the issue.

The source of the issue was method "drawItem(...)" in class WaterfallBarRenderer. For middle columns, the valDiff variable was verified. If less than 0, then it was colored using the negative bar paint object; if greater than 0, it was colored using the positive bar paint object; otherwise (exactly zero-value), it was colored using the last bar paint object.

In order to fix this issue, we refactored out a (package private) method called "getSeriesPaintObject" which takes in the column number, the category count number, and the value difference for the column. This enabled us to isolate the change, and to build some unit tests to verify our assumption. Essentially, the logic is now as follows:

1) The first column gets the color from "getFirstBarPaint()"
2) The last column gets the color from "getLastBarPaint()"
3) Middle columns get the color depending on the value difference. If negative, "getNegativeBarPaint()" is called. If positive (and zero), "getPositiveBarPaint()" is called.

This pull request contains the changes to the "WaterfallBarRenderer" class, and the addition of a new test in "WaterfallBarRendererTest" which verifies the cases mentioned above. .