Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created May 17, 2013 23:35
Show Gist options
  • Save tonyarnold/b6a1c2b36a16929c1176 to your computer and use it in GitHub Desktop.
Save tonyarnold/b6a1c2b36a16929c1176 to your computer and use it in GitHub Desktop.
- (void)sChartRenderFinished:(ShinobiChart *)chart
{
if (YES == self.firstChartRender) {
self.firstChartRender = NO;
[chart removeAllAnnotations];
SChartCategoryAxis *categoryAxis = (SChartCategoryAxis *)chart.xAxis;
for (NSDictionary *resultDictionary in self.leftBreastData) {
NSNumber *referenceDate = resultDictionary[TBDEventAttributes.groupingDateSinceReferenceDate];
__block NSInteger xIndex = NSNotFound;
[categoryAxis.categories enumerateObjectsUsingBlock:^(NSNumber *obj, NSUInteger idx, BOOL *stop) {
if (obj.doubleValue == referenceDate.doubleValue) {
xIndex = idx;
*stop = YES;
}
}];
if (NSNotFound == xIndex) {
continue;
}
NSNumber *duration = resultDictionary[@"result"];
SChartAnnotation *newAnnotation = [SChartAnnotation annotationWithText:[NSString stringWithFormat:@"%.1f", [duration doubleValue] / 60.0 / 60.0] // Hours
andFont:[UIFont systemFontOfSize:10.f]
withXAxis:chart.xAxis
andYAxis:chart.yAxis
atXPosition:@(xIndex)
andYPosition:duration
withTextColor:[UIColor blackColor]
withBackgroundColor:[UIColor clearColor]];
newAnnotation.position = SChartAnnotationAboveData;
[chart addAnnotation:newAnnotation];
newAnnotation.transform = CGAffineTransformMakeTranslation(-14.f, -6.f);
}
for (NSDictionary *resultDictionary in self.rightBreastData) {
NSNumber *referenceDate = resultDictionary[TBDEventAttributes.groupingDateSinceReferenceDate];
__block NSInteger xIndex = NSNotFound;
[categoryAxis.categories enumerateObjectsUsingBlock:^(NSNumber *obj, NSUInteger idx, BOOL *stop) {
if (obj.doubleValue == referenceDate.doubleValue) {
xIndex = idx;
*stop = YES;
}
}];
if (NSNotFound == xIndex) {
continue;
}
NSNumber *duration = resultDictionary[@"result"];
SChartAnnotation *newAnnotation = [SChartAnnotation annotationWithText:[NSString stringWithFormat:@"%.1f", [duration doubleValue] / 60.0 / 60.0] // Hours
andFont:[UIFont systemFontOfSize:10.f]
withXAxis:chart.xAxis
andYAxis:chart.yAxis
atXPosition:@(xIndex)
andYPosition:duration
withTextColor:[UIColor blackColor]
withBackgroundColor:[UIColor clearColor]];
newAnnotation.position = SChartAnnotationAboveData;
[chart addAnnotation:newAnnotation];
newAnnotation.transform = CGAffineTransformMakeTranslation(14.f, -6.f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment