Coreplot y-axis label issue - ios8

I just upgraded core-plot to 1.6 from 1.2. The label on y-axis is screwed up in iOS 8. when running same project for target 7.1 works fine.
Anyone having same issue?
The y.majorIntervalLength is 150 and
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.f) length:CPTDecimalFromFloat(2000.f)];
[![enter image description here][1]][1] [![enter image description here][2]][2]
Fig. iOS 8.2 . Fig. iOS 7.1
// Axes config code
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)_graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = _startDate;
x.labelFormatter = timeFormatter;
x.labelTextStyle = textStyle;
x.majorIntervalLength = CPTDecimalFromFloat(DT_ONE_DAY*3);
x.minorTicksPerInterval = 2;
CPTXYAxis *y = axisSet.yAxis;
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.maximumSignificantDigits = 0;
y.labelFormatter = numberFormatter;
y.labelTextStyle = textStyle;
y.majorIntervalLength = CPTDecimalFromString(#"150");
y.minorTicksPerInterval = 1;

Related

core plot x axis labels vertical

I have a very crowded xy graph and I'm trying to display the x-axis labels vertically instead of the default horizontal. I can't find documentation on how to do this. Can anyone explain how to do this or point me to the right documentation? I have adjusted the x.labelrotation but it does rotate the x axis label
thanks.
#pragma mark - Chart behavior
-(void)initPlotThree {
[self configureHostThree];
[self configureGraphThree];
[self configurePlotsThree];
[self configureAxesThree];
}
-(void)configureHostThree {
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
self.hostView.allowPinchScaling = YES;
[self.myViewThree addSubview:self.hostView];
CPTGraphHostingView *BarGraphView = [[CPTGraphHostingView alloc] init];
self.hostView.frame = CGRectMake(self.myViewThree.bounds.origin.x, self.myViewThree.bounds.origin.y, self.myViewThree.bounds.size.width, self.myViewThree.bounds.size.height);
[self.hostView addSubview:BarGraphView];
}
-(void)configureGraphThree {
// 1 - Create the graph
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
// [graph applyTheme:[CPTTheme themeNamed:kCPTSlateTheme]];
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
self.hostView.hostedGraph = graph;
// 2 - Set graph title
NSString *title = #"Tremor";
graph.title = title;
// 3 - Create and set text style
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor blackColor];
titleStyle.fontName = #"Helvetica-Bold";
titleStyle.fontSize = 12.0f;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, 17.0f);
// 4 - Set padding for plot area
[graph.plotAreaFrame setPaddingLeft:1.0f];
[graph.plotAreaFrame setPaddingBottom:1.0f];
// 5 - Enable user interactions for plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
}
-(void)configurePlotsThree {
// 1 - Get graph and plot space
CPTGraph *graph = self.hostView.hostedGraph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
// 2 - Create the plots
CPTScatterPlot *tremorPlot = [[CPTScatterPlot alloc] init];
tremorPlot.dataSource = self;
tremorPlot.identifier = tremorSCORE;
CPTColor *tremorColor = [CPTColor blueColor];
[graph addPlot:tremorPlot toPlotSpace:plotSpace];
// 3 - Set up plot space
[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:tremorPlot, nil]];
CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
[xRange expandRangeByFactor:CPTDecimalFromCGFloat(1.1f)];
plotSpace.xRange = xRange;
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.2f)];
plotSpace.yRange = yRange;
// 4 - Create styles and symbols
CPTMutableLineStyle *tremorLineStyle = [tremorPlot.dataLineStyle mutableCopy];
tremorLineStyle.lineWidth = 2.0;
tremorLineStyle.lineColor = tremorColor;
tremorPlot.dataLineStyle = tremorLineStyle;
CPTMutableLineStyle *tremorSymbolLineStyle = [CPTMutableLineStyle lineStyle];
tremorSymbolLineStyle.lineColor = tremorColor;}
-(void)configureAxesThree {
// 1 - Create styles
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor blackColor];
axisTitleStyle.fontName = #"Helvetica-Bold";
axisTitleStyle.fontSize = 10.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = .01f;
axisLineStyle.lineColor = [CPTColor blackColor];
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor blackColor];
axisTextStyle.fontName = #"Helvetica-Bold";
axisTextStyle.fontSize = 9.0f;
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor blackColor];
tickLineStyle.lineWidth = 1.0f;
CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor blackColor];
tickLineStyle.lineWidth = 1.0f;
// 2 - Get axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
// 3 - Configure x-axis
CPTAxis *x = axisSet.xAxis;
x.title = #"";
x.titleTextStyle = axisTitleStyle;
x.titleOffset = 20.0f;
x.axisLineStyle = axisLineStyle;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.labelTextStyle = axisTextStyle;
x.majorTickLineStyle = axisLineStyle;
x.majorTickLength = 4.0f;
x.tickDirection = CPTSignNegative;
x.labelRotation = .6;
x.labelOffset = 15;
CGFloat dateCount = [self.dates count];
NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
NSInteger i = 0;
for (NSString *date in self.dates) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:date textStyle:x.labelTextStyle];
CGFloat location = i++;
label.tickLocation = CPTDecimalFromCGFloat(location);
label.offset = x.majorTickLength;
if (label) {
[xLabels addObject:label];
[xLocations addObject:[NSNumber numberWithFloat:location]];
}
}
x.axisLabels = xLabels;
x.majorTickLocations = xLocations;
// CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:15.0]; // 8-22
// 4 - Configure y-axis
CPTAxis *y = axisSet.yAxis;
y.title = #"";
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -40.0f;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = nil;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = nil;
y.labelOffset = 16.0f;
y.majorTickLineStyle = nil;
y.majorTickLength = 4.0f;
y.minorTickLength = 1.0f;
y.tickDirection = CPTSignPositive;
NSInteger majorIncrement = 2;
NSInteger minorIncrement = 1;
CGFloat yMax = 700.0f; // should determine dynamically based on max price
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
for (NSInteger j = minorIncrement; j <= yMax; j += minorIncrement) {
NSUInteger mod = j % majorIncrement;
if (mod == 0) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:#"%li", (long)j] textStyle:y.labelTextStyle];
NSDecimal location = CPTDecimalFromInteger(j);
label.tickLocation = location;
label.offset = -y.majorTickLength - y.labelOffset;
if (label) {
[yLabels addObject:label];
}
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
} else {
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
}
}
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
y.minorTickLocations = yMinorLocations;
}
Set the labelRotation on the x-axis to rotate the labels when using one of the automatic labelling policies. When creating custom labels, you need to set the rotation on each label directly.

CorePlot hosting view and CPTXYGraph frame issues

I'm trying to set up a simple pie chart in my OSX project, in Xcode 5, following the tutorial at :http://www.raywenderlich.com/13269/how-to-draw-graphs-with-core-plot-part-1.
The problem is that the graph doesn't show and both the CPTGraphHostingView and the CPTXYGraph have a height and width of 0.00.
Here is the code I use, after which I should be able to see the title for the graph in the view. The hostView is a reference to an NSView in the xib file.
-(void)configureHost {
self.graphHostingView = [(CPTGraphHostingView *)[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 1103, 532)];
NSLog(#"%f", self.graphHostingView.frame.size.width);
[hostView addSubview:self.graphHostingView];
}
-(void)configureGraph {
NSRect parentRect = CGRectMake(0, 0, 1103, 532);
//create graph
CPTGraph *graph = [[CPTXYGraph alloc] init];
[graph setFrame:parentRect];
NSLog(#"%f", graph.frame.size.width);
self.graphHostingView.hostedGraph = graph;
graph.paddingBottom = 0.0f;
graph.paddingLeft = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingRight = 0.0f;
graph.axisSet = nil;
//text in graph
CPTMutableTextStyle *textStlye = [CPTMutableTextStyle textStyle];
textStlye.color = [CPTColor grayColor];
textStlye.fontName = #"Helvetica-Bold";
textStlye.fontSize = 16.0f;
//graph title
graph.title = #"Title";
graph.titleTextStyle = textStlye;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -12.0f);
self.theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
}
Not as important, but I'm also getting an error when I use the kCPTPlainWhiteTheme const, or other theme consts. a thread 1:EXC_BAD_ACCESS(code=1, address=0x0).
It's probably an obvious issue but I just cant see it.
Thanks in advance.

Inaccurate rotation with CABasicAnimation... doesn't match the correct angle

I am developing a maps application. I draw an animated line in the map and then use an image (a ruler image) which should be draw just over the line. To draw the line I use a CABasicAnimation with path:
-(void)lineaAnimation {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"path"];
animation.duration = animDuration;
animation.delegate=self;
animation.repeatCount = 0;
animation.autoreverses = NO;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = (id)inip;
animation.toValue = (id)finp;
animation.fillMode=kCAFillModeForwards;
animation.removedOnCompletion=NO;
[shapeLayer addAnimation:animation forKey:#"animatePath"];
}
-(void)linea:(CGPoint)origen to:(CGPoint)destino animado:(BOOL)anim duracion:(float)durac inicio:(float)delay {
inip = CGPathCreateMutable();
finp = CGPathCreateMutable();
CGPathMoveToPoint(inip, nil, origen.x, origen.y);
CGPathAddLineToPoint(inip, nil, origen.x, origen.y);
CGPathCloseSubpath(inip);
CGPathMoveToPoint(finp, nil, origen.x, origen.y);
CGPathAddLineToPoint(finp, nil, destino.x, destino.y);
CGPathCloseSubpath(finp);
rootLayer = [CALayer layer];
rootLayer.frame = fondo.bounds;
[fondo.layer addSublayer:rootLayer];
shapeLayer = [CAShapeLayer layer];
shapeLayer.path = inip;
UIColor *fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
shapeLayer.fillColor = fillColor.CGColor;
UIColor *strokeColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
shapeLayer.strokeColor = strokeColor.CGColor;
shapeLayer.lineWidth = 5.0;
shapeLayer.fillRule = kCAFillRuleEvenOdd;
[morrallaLayer addObject:shapeLayer];
[rootLayer addSublayer:shapeLayer];
animDuration=durac;
[self performSelector:#selector(lineaAnimation) withObject:nil afterDelay:delay];
}
Then I try to move the center of the rule to the point and rotate the ruler image using this code:
delta=acos((destino.y-origen.y)/(destino.x-origen.x));
giroIni=0.0;
giroFin=delta;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
animation.fromValue= [NSNumber numberWithFloat:giroIni];
animation.toValue= [NSNumber numberWithFloat:giroFin];
animation.delegate = self;
animation.repeatCount = 0;
animation.autoreverses = NO;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = animDuration;
animation.fillMode=kCAFillModeForwards;
animation.removedOnCompletion=NO;
[ruleL addAnimation:animation forKey:#"giroAngulo"];
The problem is that the ruler borderline doesn't match the line draw, there are around a degree of difference depending on the final orientation... why?
Thanks a lot!
Ooooops... sorry for your time :(
I found the problem and.. as usual the error is not in the stars but in ourselves
I use the acos function when OBVIOUSLY I should use atan

How can I crop my UIPickerView?

Here is my horizontal UIPickerView (by rotate & scale the ori UIpicker) : htp://s7.postimage.org/qzez9d0pn/Original.png
And now, what I want to do is cut off these two spaces : http://s7.postimage.org/bryzp08uz/Process.png
To have this better look result : http://s7.postimage.org/6ulf3w6vv/Result.png
Somebody please help me how to do it...?
my rotate & scale code :
thePickerView.delegate = self;
thePickerView.showsSelectionIndicator =YES;
thePickerView.center = CGPointMake(xVar, yVar); // position
CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2); // rotate
rotate = CGAffineTransformScale(rotate, 0.1, 1); // scale
[thePickerView setTransform:rotate];
UILabel *theview[num];
CGAffineTransform rotateItem = CGAffineTransformMakeRotation(3.14/2);
for (int i=0;i<num;i++) {
theview[i] = [[UILabel alloc] init];
theview[i].text = [NSString stringWithFormat:#"%d",i+1];
theview[i].textColor = [UIColor blackColor];
theview[i].frame = CGRectMake(0,0, 100, 100);
theview[i].backgroundColor = [UIColor clearColor];
theview[i].textAlignment = UITextAlignmentCenter;
theview[i].shadowColor = [UIColor whiteColor];
theview[i].shadowOffset = CGSizeMake(-1,-1);
theview[i].adjustsFontSizeToFitWidth = YES;
theview[i].transform = CGAffineTransformScale(rotateItem, 1, 10);
}
itemArray = [[NSMutableArray alloc] init];
for (int j=0;j<num;j++) {[itemArray addObject:theview[j]];}
[thePickerView selectRow:row inComponent:0 animated:NO];
[self.view addSubview:thePickerView];
My temporary solution while searching & waiting for better coding answer is create an overlay background image then transparent the desire space of PickerView =.=

UITapRecognizer and ImageView

I have a UIImageView with a UITapGestureRecognizer attached. This is just a ball moving around the screen. It moves once a second.
ball.image = [UIImage imageNamed:#"chicken.png"];
ball.frame = CGRectMake(160, 160, 50, 50);
ball.autoresizesSubviews = NO;
speed = 10;
objTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(ballMove:) userInfo:nil repeats:YES];
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
The method called when the imageView is clicked is
-(void)handleTap:(UITapGestureRecognizer *)sender
{
CGPoint obj = [sender locationInView:ball];
NSLog(#"x = %f",obj.x);
NSLog(#"y = %f",obj.y);
.......
}
It doesn't grab all taps. It only picks up taps where y is less than 1 however.
x = 14.958618
y = 0.879913
x = 23.996643
y = 0.975830
x = 24.542923
y = 0.557907
And so on...
The imageView description is: <UIImageView: 0x6814800; frame = (161.747 183.826; 50 1); opaque = NO; autoresize = W+H; autoresizesSubviews = NO; layer = <CALayer: 0x6814880>>
Check whether your UIImageView interactions are enabled:
ball.userInteractionEnabled = YES;

Resources