kaiserfarrell / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

scaleToFitPlots: does not take into account bar widths and offsets #464

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a graph with multiple bar plots, and assign a bar offset to them so 
that they don't overlap (the first one can have offset 0)
2. Adjust plot space range with scaleToFitPlots:

What is the expected output? 

I see all of the bars fitting in the graph

What do you see instead?

The first bar is cut in half. The last bar of the first bar plot is as well. 
The last bars of the rest of the plots are outside of the graph

What version of the product are you using? On what operating system?

1.0 (revison 1409) on iOS 5.1 and iOS 6.0

I have fixed this on my working copy, please advise how to submit the patch

Original issue reported on code.google.com by victor.j...@gmail.com on 23 Oct 2012 at 8:29

GoogleCodeExporter commented 8 years ago
here's the diff in case you can use it right away:

diff -r c4b3ac52ecc8 framework/Source/CPTXYPlotSpace.m
--- a/framework/Source/CPTXYPlotSpace.m Wed Oct 03 20:47:35 2012 -0400
+++ b/framework/Source/CPTXYPlotSpace.m Tue Oct 23 15:45:50 2012 +0200
@@ -6,6 +6,7 @@
 #import "CPTGraphHostingView.h"
 #import "CPTMutablePlotRange.h"
 #import "CPTPlot.h"
+#import "CPTBarPlot.h"
 #import "CPTPlotArea.h"
 #import "CPTPlotArea.h"
 #import "CPTPlotAreaFrame.h"
@@ -354,6 +355,15 @@
     for ( CPTPlot *plot in plots ) {
         CPTPlotRange *currentXRange = [plot plotRangeForCoordinate:CPTCoordinateX];
         CPTPlotRange *currentYRange = [plot plotRangeForCoordinate:CPTCoordinateY];
+
+        if ([plot isKindOfClass:[CPTBarPlot class]]) {
+            if (((CPTBarPlot *)plot).barsAreHorizontal) {
+                currentYRange = [(CPTBarPlot *)plot plotRangeEnclosingBars];
+            } else {
+                currentXRange = [(CPTBarPlot *)plot plotRangeEnclosingBars];
+            }
+        }
+
         if ( !unionXRange ) {
             unionXRange = [currentXRange mutableCopy];
         }

Original comment by victor.j...@gmail.com on 23 Oct 2012 at 2:06

GoogleCodeExporter commented 8 years ago
This behavior was intentional. See my comment on issue 338: 
http://code.google.com/p/core-plot/issues/detail?id=338#c1

-scaleToFitPlots: should behave the same for all plot types. It computes ranges 
that exactly fit the plot data, excluding any bars, plot symbols, or other 
decorations.

Original comment by eskr...@mac.com on 3 Nov 2012 at 3:39