Rotation of UIView (CPHostingView) is centered on whole screen, not the chart

350 views
Skip to first unread message

MrMadders

unread,
Oct 18, 2010, 5:44:41 AM10/18/10
to coreplot-discuss
Morning,

I have a Core Plot piechart which I want to rotate on touch-dragging.
I have placed the graph in my own view class (of type CPHostingView),
and it is positioned in the bottom corner of a larger view, inside a
UISplitview.

I have got the graph to rotate on touchMoved, however the center point
for the rotation seems to be the center of the whole view, not the
graph itself.

I've tried to play with the layer.anchorPoint of this CPHostingView
class, but it doesn't seem to solve the problem?

Any ideas??

Thanks very much
R

Drew McCormack

unread,
Oct 18, 2010, 6:34:12 AM10/18/10
to coreplot...@googlegroups.com
I would think that if the graph is inside a hosting view, you shouldn't have to be playing with the graphs rotation at all. Just try to get the hosting view to rotate properly, and the graph should follow.

Drew

> --
> You received this message because you are subscribed to the Google Groups "coreplot-discuss" group.
> To post to this group, send email to coreplot...@googlegroups.com.
> To unsubscribe from this group, send email to coreplot-discu...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/coreplot-discuss?hl=en.
>

Eric

unread,
Oct 18, 2010, 6:56:08 AM10/18/10
to coreplot-discuss
To rotate a pie chart, just change the starting angle property. You
don't have to rotate the whole graph.

Eric

MrMadders

unread,
Oct 18, 2010, 10:23:03 AM10/18/10
to coreplot-discuss
Thanks guys.

Drew, Sorry I should have been clearer.
It is my hosting view class that receives the touch events and the
transform is applied to this. So I was confused the centre seems to be
located in the overall screen.

Thanks again guys! We'll get there in the end :-)


Code below:

1) Piechartview.h
----------------------------------------------
#import <UIKit/UIKit.h>
#import "CPLayerHostingView.h">



@interface PieChartView : CPLayerHostingView {
CGPoint lastLocation;
}

@end
----------------------------------------------

2) PieChartView.m
----------------------------------------------

#import "PieChartView.h"
#import <QuartzCore/QuartzCore.h>

@implementation PieChartView

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}

//self.layer.anchorPoint = CGPointMake(0.5,0.5); Tried this although
it had no effect.

return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during
animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

/*
***************************
Touch Methods
***************************
*/

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
lastLocation = [touch locationInView:self];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:[self superview]];

CGFloat xDisplacement = location.x - lastLocation.x;
CGFloat yDisplacement = location.y - lastLocation.y;

CGFloat rad = atan2f(yDisplacement,xDisplacement);

self.transform = CGAffineTransformMakeRotation(rad);
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:[self superview]];

CGFloat xDisplacement = location.x - lastLocation.x;
CGFloat yDisplacement = location.y - lastLocation.y;

CGFloat rad = atan2f(yDisplacement,xDisplacement);

//Loop to continue rotattion

self.transform = CGAffineTransformMakeRotation(rad);

}

- (void)dealloc {
[super dealloc];
}


@end

----------------------------------------------

Eric

unread,
Oct 18, 2010, 7:21:40 PM10/18/10
to coreplot-discuss
Try setting the transform on self.hostedGraph.

Eric

MrMadders

unread,
Oct 19, 2010, 4:38:12 AM10/19/10
to coreplot-discuss
is hosted graph a property of a CPLayerHostingView? As it's not
available to me in code?

I'm wondering if I have the latest version of the code, as I also
can't successfully compile with references to CPPieChartDelegate.

I did download Alpha 0.2 release....

Thanks again Eric,
R

Drew McCormack

unread,
Oct 19, 2010, 4:40:45 AM10/19/10
to coreplot...@googlegroups.com
Alpha 0.2 is a few weeks out of date. The changes you refer to are very recent. You will need to checkout the hg version for that.

Drew

MrMadders

unread,
Oct 19, 2010, 7:03:41 AM10/19/10
to coreplot-discuss
Ah great, thanks very much

Could you please provide some info on how to download it? Is it the
checkout > Create Clone link?

Drew McCormack

unread,
Oct 19, 2010, 7:25:23 AM10/19/10
to coreplot...@googlegroups.com
There are instructions on the google code site under source code.
In short, you install Mercurial, and then follow instructions here

http://code.google.com/p/core-plot/source/checkout

Drew

MrMadders

unread,
Oct 19, 2010, 7:26:32 AM10/19/10
to coreplot-discuss

Hmm, so I've actually now got Mercurial up and running. But I'm
getting timeouts when running the following in the Terminal?
Any ideas?


hg clone https://core-plot.googlecode.com/hg/ core-plot


Really appreciate your help chaps,
R

MrMadders

unread,
Oct 19, 2010, 8:32:19 AM10/19/10
to coreplot-discuss
Ok, sorted that too - we had some security policies we had to
overcome.

The instructions for incorporation of core-plot aren't that clear.
I have swapped out the original libCorePlot-CocoaTouch.a file, by
overwritting the previous version and then updating the linked
library.
Unfortunately, I'm getting two of these errors:

"_OBJC_CLASS_$_CPLayerHostingView", referenced from:

Is there a more clear way to add in the new version of CorePlot to an
existing project?

Thanks very much,
R


PS I appreciate this has gone slightly off topic, but thanks again for
your assistance.

Eric

unread,
Oct 19, 2010, 8:55:00 AM10/19/10
to coreplot-discuss
On iOS, CPLayerHostingView was recently changed to CPGraphHostingView.
The hostedLayer property also changed to hostedGraph.

Eric

MrMadders

unread,
Oct 19, 2010, 9:18:10 AM10/19/10
to coreplot-discuss
Oh right, thanks... although Find/Replace then complains that the
CPGraphHostingView class can't be found. Should that have worked?

Perhaps there is a more comprehensive set of steps for incorporating a
new release into an existing solution?

Thanks again Eric,
R
Reply all
Reply to author
Forward
0 new messages