gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Add CPTBarPlot method to calculate a plot range the encloses the entire bars #338

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Copied from issue 337:

- also, when one wants to adjust the plot ranges accordingly, I would suggest 
the bar plots should show the full range from the base to the maximum of the 
tips (or from the minimum of the base if they vary) and horizontally take the 
bar width into account (e.g. a bar plot with bars at 0, 1 and 2 and bar width 
0.7 should have range from -0.35 to 2.35 instead of from 0 to 2) so that the 
plot fits completely in the plot area

For example in CPTBarPlot
-(CPTPlotRange *)plotRangeForField:(NSUInteger)fieldEnum {

    CPTPlotRange *range = [super plotRangeForField:fieldEnum];

    if (fieldEnum == CPTBarPlotFieldBarTip) {
        if (self.barBasesVary) {
            // handle varying bases
        }
        else {
            range.length = CPTDecimalAdd(CPTDecimalSubtract(range.location, self.baseValue), range.length);
            range.location = self.baseValue;
        }
    }
    else if (fieldEnum == CPTBarPlotFieldBarLocation) {
        range.location = CPTDecimalSubtract(range.location, CPTDecimalDivide(self.barWidth, CPTDecimalFromInt(2)));
        range.length = CPTDecimalAdd(range.length, self.barWidth);
    }

    return range;
}

Original issue reported on code.google.com by eskr...@mac.com on 3 Oct 2011 at 1:34

GoogleCodeExporter commented 9 years ago
I don't think changing the behavior of -plotRangeForField: for only one plot 
type is a good idea. It might be helpful to have a different method that 
performs this function added to CPTBarPlot only. The caller could use it to 
compute new ranges for the plot space or any other purpose.

Things to keep in mind:
1. Plot ranges can have a negative length.

2. This method should also account for the barOffset property that moves the 
bars off their normal center point.

3. Bar widths and offsets can be specified in view coordinates or data 
coordinates. The range calculations must account for both cases.

Original comment by eskr...@mac.com on 3 Oct 2011 at 1:43

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 6 May 2012 at 12:23

GoogleCodeExporter commented 9 years ago
This issue was closed by revision be7926c11da4.

Original comment by eskr...@mac.com on 22 May 2012 at 1:33