gujjula / core-plot

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

plotAreaFrame is not resized accordingly to the graph's size change #299

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In my iPhone project using core-plot, I need to support landscape orientation 
as well as portrait orientation.
I simply called setFrame: to CPTGraphHostingView but the plotArea didn't get 
resized accordingly.
I suggest the following patch would solve the problem.

Index: iPhoneOnly/CPTGraphHostingView.m
===================================================================
--- iPhoneOnly/CPTGraphHostingView.m    (revision 38)
+++ iPhoneOnly/CPTGraphHostingView.m    (revision 39)
@@ -218,7 +218,8 @@
 -(void)setFrame:(CGRect)newFrame
 {
     [super setFrame:newFrame];
-    if ( !collapsesLayers ) 
+    [hostedGraph setNeedsLayout];
+    if ( !collapsesLayers )
        hostedGraph.frame = self.bounds;
     else 
        [self setNeedsDisplay];
@@ -227,6 +228,7 @@
 -(void)setBounds:(CGRect)newBounds
 {
     [super setBounds:newBounds];
+    [hostedGraph setNeedsLayout];
     if ( collapsesLayers ) [self setNeedsDisplay];
 }

Index: Source/CPTLayer.m
===================================================================
--- Source/CPTLayer.m   (revision 38)
+++ Source/CPTLayer.m   (revision 39)
@@ -473,6 +473,7 @@
    for (CALayer *subLayer in self.sublayers) {
        if (![excludedSublayers containsObject:subLayer] && [subLayer isKindOfClass:[CPTLayer class]]) {
             subLayer.frame = CGRectMake(leftPadding, bottomPadding, subLayerSize.width, subLayerSize.height);
+            [subLayer setNeedsLayout];
        }
    }
 }

Original issue reported on code.google.com by y...@wangsy.com on 30 Jun 2011 at 4:40

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 1 Jul 2011 at 1:39

GoogleCodeExporter commented 9 years ago
I had similar problem in my iPhone/iPad app as described above. Although in 
slightly more complicated scenario. My app has UITAbBarController, let say with 
ViewA and ViewB. Both of them display graphs. I experienced problem with graph 
not resizing in the following workflow:
1. Show ViewA in portrait
2. Switch to ViewB (still in portrait)
3. Rotate to landscape (no problem here, the graph in ViewB rotates as expected)
4. Switch back to ViewA. Now the graph in ViewA renders as it was still in the 
portrait mode (it actually draws outside of its frame).

I applied the patch from Issue 281 (two changes above in CPGraphHostingView.m). 
But it did not solve the problem. Only after applying the change to 
Source/CPLayer.m ([subLayer setNeedsLayout];), the graph in step 4 was redrawn 
correctly.

Original comment by Lubos.Mi...@gmail.com on 20 Sep 2011 at 8:31