Skip to content

Commit bf03025

Browse files
committed
Cleaned up the example apps. Removed some redundant code, clarified certain calculations and set operations, and updated numeric constants to reduce implicit type conversions performed by the compiler.
1 parent dce194c commit bf03025

35 files changed

Lines changed: 316 additions & 327 deletions

QCPlugin/CPScatterPlotPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ -(void)addPlotWithIndex:(NSUInteger)index
106106
lineColor = [self newDefaultColorForPlot:index alpha:1.0];
107107
fillColor = [self newDefaultColorForPlot:index alpha:0.25];
108108
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
109-
lineStyle.lineWidth = 3.f;
109+
lineStyle.lineWidth = 3.0;
110110
lineStyle.lineColor = [CPTColor colorWithCGColor:lineColor];
111111
scatterPlot.dataLineStyle = lineStyle;
112112
scatterPlot.areaFill = [CPTFill fillWithColor:[CPTColor colorWithCGColor:fillColor]];

QCPlugin/CorePlotQCPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ -(BOOL)execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArgu
793793

794794
// Draw the plot ...
795795
CGSize boundsSize = graph.bounds.size;
796-
CGContextClearRect( bitmapContext, CGRectMake(0.0f, 0.0f, boundsSize.width, boundsSize.height) );
796+
CGContextClearRect( bitmapContext, CGRectMake(0.0, 0.0, boundsSize.width, boundsSize.height) );
797797
CGContextSetRGBFillColor(bitmapContext, 0.0, 0.0, 0.0, 0.0);
798798
CGContextFillRect( bitmapContext, CGRectMake(0, 0, boundsSize.width, boundsSize.height) );
799799
CGContextSetAllowsAntialiasing(bitmapContext, true);

examples/AAPLot/APYahooDataPuller.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import "APFinancialData.h"
22
#import "APYahooDataPuller.h"
33

4-
NSTimeInterval timeIntervalForNumberOfWeeks(float numberOfWeeks)
4+
NSTimeInterval timeIntervalForNumberOfWeeks(double numberOfWeeks)
55
{
66
NSTimeInterval seconds = fabs(60.0 * 60.0 * 24.0 * 7.0 * numberOfWeeks);
77

@@ -152,7 +152,7 @@ -(id)initWithTargetSymbol:(NSString *)aSymbol targetStartDate:(NSDate *)aStartDa
152152

153153
-(id)init
154154
{
155-
NSTimeInterval secondsAgo = -timeIntervalForNumberOfWeeks(14.0f); //12 weeks ago
155+
NSTimeInterval secondsAgo = -timeIntervalForNumberOfWeeks(14.0); //12 weeks ago
156156
NSDate *start = [NSDate dateWithTimeIntervalSinceNow:secondsAgo];
157157

158158
NSDate *end = [NSDate date];

examples/AAPLot/Classes/MainViewController.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ -(void)viewDidLoad
4343
CPTTheme *theme = [CPTTheme themeNamed:kCPTStocksTheme];
4444
[graph applyTheme:theme];
4545
graph.frame = self.view.bounds;
46-
graph.paddingRight = 50.0f;
47-
graph.paddingLeft = 50.0f;
46+
graph.paddingRight = 50.0;
47+
graph.paddingLeft = 50.0;
4848
graph.plotAreaFrame.masksToBorder = NO;
49-
graph.plotAreaFrame.cornerRadius = 0.0f;
49+
graph.plotAreaFrame.cornerRadius = 0.0;
5050
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
5151
borderLineStyle.lineColor = [CPTColor whiteColor];
52-
borderLineStyle.lineWidth = 2.0f;
52+
borderLineStyle.lineWidth = 2.0;
5353
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
5454
self.graphHost.hostedGraph = graph;
5555

@@ -75,22 +75,22 @@ -(void)viewDidLoad
7575

7676
CPTColor *areaColor = [CPTColor colorWithComponentRed:1.0 green:1.0 blue:1.0 alpha:0.6];
7777
CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]];
78-
areaGradient.angle = -90.0f;
78+
areaGradient.angle = -90.0;
7979
CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient];
8080
dataSourceLinePlot.areaFill = areaGradientFill;
8181
dataSourceLinePlot.areaBaseValue = CPTDecimalFromDouble(200.0);
8282

8383
areaColor = [CPTColor colorWithComponentRed:0.0 green:1.0 blue:0.0 alpha:0.6];
8484
areaGradient = [CPTGradient gradientWithBeginningColor:[CPTColor clearColor] endingColor:areaColor];
85-
areaGradient.angle = -90.0f;
85+
areaGradient.angle = -90.0;
8686
areaGradientFill = [CPTFill fillWithGradient:areaGradient];
8787
dataSourceLinePlot.areaFill2 = areaGradientFill;
8888
dataSourceLinePlot.areaBaseValue2 = CPTDecimalFromDouble(400.0);
8989

9090
// OHLC plot
9191
CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle];
9292
whiteLineStyle.lineColor = [CPTColor whiteColor];
93-
whiteLineStyle.lineWidth = 1.0f;
93+
whiteLineStyle.lineWidth = 1.0;
9494
CPTTradingRangePlot *ohlcPlot = [[[CPTTradingRangePlot alloc] initWithFrame:graph.bounds] autorelease];
9595
ohlcPlot.identifier = @"OHLC";
9696
ohlcPlot.lineStyle = whiteLineStyle;
@@ -99,7 +99,7 @@ -(void)viewDidLoad
9999
whiteTextStyle.fontSize = 8.0;
100100
ohlcPlot.labelTextStyle = whiteTextStyle;
101101
ohlcPlot.labelOffset = 5.0;
102-
ohlcPlot.stickLength = 2.0f;
102+
ohlcPlot.stickLength = 2.0;
103103
ohlcPlot.dataSource = self;
104104
ohlcPlot.plotStyle = CPTTradingRangePlotStyleOHLC;
105105
ohlcPlot.cachePrecision = CPTPlotCachePrecisionDecimal;

examples/CPTTestApp-iPad/Classes/CPTTestApp_iPadViewController.m

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ -(void)viewDidAppear:(BOOL)animated
3131
// Add a rotation animation
3232
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
3333
rotation.removedOnCompletion = YES;
34-
rotation.fromValue = [NSNumber numberWithFloat:M_PI * 5];
35-
rotation.toValue = [NSNumber numberWithFloat:0.0f];
36-
rotation.duration = 1.0f;
34+
rotation.fromValue = [NSNumber numberWithDouble:M_PI * 5];
35+
rotation.toValue = [NSNumber numberWithDouble:0.0];
36+
rotation.duration = 1.0;
3737
rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
3838
rotation.delegate = self;
3939
[piePlot addAnimation:rotation forKey:@"rotation"];
@@ -56,15 +56,15 @@ -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOr
5656
{
5757
if ( UIInterfaceOrientationIsLandscape(fromInterfaceOrientation) ) {
5858
// Move the plots into place for portrait
59-
scatterPlotView.frame = CGRectMake(20.0f, 55.0f, 728.0f, 556.0f);
60-
barChartView.frame = CGRectMake(20.0f, 644.0f, 340.0f, 340.0f);
61-
pieChartView.frame = CGRectMake(408.0f, 644.0f, 340.0f, 340.0f);
59+
scatterPlotView.frame = CGRectMake(20.0, 55.0, 728.0, 556.0);
60+
barChartView.frame = CGRectMake(20.0, 644.0, 340.0, 340.0);
61+
pieChartView.frame = CGRectMake(408.0, 644.0, 340.0, 340.0);
6262
}
6363
else {
6464
// Move the plots into place for landscape
65-
scatterPlotView.frame = CGRectMake(20.0f, 51.0f, 628.0f, 677.0f);
66-
barChartView.frame = CGRectMake(684.0f, 51.0f, 320.0f, 320.0f);
67-
pieChartView.frame = CGRectMake(684.0f, 408.0f, 320.0f, 320.0f);
65+
scatterPlotView.frame = CGRectMake(20.0, 51.0, 628.0, 677.0);
66+
barChartView.frame = CGRectMake(684.0, 51.0, 320.0, 320.0);
67+
pieChartView.frame = CGRectMake(684.0, 408.0, 320.0, 320.0);
6868
}
6969
}
7070

@@ -101,30 +101,30 @@ -(void)constructScatterPlot
101101
// Setup plot space
102102
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
103103
plotSpace.allowsUserInteraction = YES;
104-
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(2.0)];
105-
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)];
104+
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(1.0) length:CPTDecimalFromDouble(2.0)];
105+
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(1.0) length:CPTDecimalFromDouble(3.0)];
106106

107107
// Axes
108108
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
109109
CPTXYAxis *x = axisSet.xAxis;
110-
x.majorIntervalLength = CPTDecimalFromString(@"0.5");
111-
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"2");
110+
x.majorIntervalLength = CPTDecimalFromDouble(0.5);
111+
x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(2.0);
112112
x.minorTicksPerInterval = 2;
113113
NSArray *exclusionRanges = [NSArray arrayWithObjects:
114-
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.99) length:CPTDecimalFromFloat(0.02)],
115-
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.99) length:CPTDecimalFromFloat(0.02)],
116-
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(2.99) length:CPTDecimalFromFloat(0.02)],
114+
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(1.99) length:CPTDecimalFromDouble(0.02)],
115+
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.99) length:CPTDecimalFromDouble(0.02)],
116+
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(2.99) length:CPTDecimalFromDouble(0.02)],
117117
nil];
118118
x.labelExclusionRanges = exclusionRanges;
119119

120120
CPTXYAxis *y = axisSet.yAxis;
121-
y.majorIntervalLength = CPTDecimalFromString(@"0.5");
121+
y.majorIntervalLength = CPTDecimalFromDouble(0.5);
122122
y.minorTicksPerInterval = 5;
123-
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"2");
123+
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(2.0);
124124
exclusionRanges = [NSArray arrayWithObjects:
125-
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.99) length:CPTDecimalFromFloat(0.02)],
126-
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.99) length:CPTDecimalFromFloat(0.02)],
127-
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(3.99) length:CPTDecimalFromFloat(0.02)],
125+
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(1.99) length:CPTDecimalFromDouble(0.02)],
126+
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.99) length:CPTDecimalFromDouble(0.02)],
127+
[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(3.99) length:CPTDecimalFromDouble(0.02)],
128128
nil];
129129
y.labelExclusionRanges = exclusionRanges;
130130

@@ -133,7 +133,7 @@ -(void)constructScatterPlot
133133
dataSourceLinePlot.identifier = @"Green Plot";
134134

135135
CPTMutableLineStyle *lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy];
136-
lineStyle.lineWidth = 3.f;
136+
lineStyle.lineWidth = 3.0;
137137
lineStyle.lineColor = [CPTColor greenColor];
138138
lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.0f], [NSNumber numberWithFloat:5.0f], nil];
139139
dataSourceLinePlot.dataLineStyle = lineStyle;
@@ -143,18 +143,18 @@ -(void)constructScatterPlot
143143
// Put an area gradient under the plot above
144144
CPTColor *areaColor = [CPTColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8];
145145
CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]];
146-
areaGradient.angle = -90.0f;
146+
areaGradient.angle = -90.0;
147147
CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient];
148148
dataSourceLinePlot.areaFill = areaGradientFill;
149-
dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"1.75");
149+
dataSourceLinePlot.areaBaseValue = CPTDecimalFromDouble(1.75);
150150

151151
// Animate in the new plot, as an example
152-
dataSourceLinePlot.opacity = 0.0f;
152+
dataSourceLinePlot.opacity = 0.0;
153153
dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDecimal;
154154
[graph addPlot:dataSourceLinePlot];
155155

156156
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
157-
fadeInAnimation.duration = 1.0f;
157+
fadeInAnimation.duration = 1.0;
158158
fadeInAnimation.removedOnCompletion = NO;
159159
fadeInAnimation.fillMode = kCAFillModeForwards;
160160
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
@@ -165,8 +165,8 @@ -(void)constructScatterPlot
165165
boundLinePlot.identifier = @"Blue Plot";
166166

167167
lineStyle = [boundLinePlot.dataLineStyle mutableCopy];
168-
lineStyle.miterLimit = 1.0f;
169-
lineStyle.lineWidth = 3.0f;
168+
lineStyle.miterLimit = 1.0;
169+
lineStyle.lineWidth = 3.0;
170170
lineStyle.lineColor = [CPTColor blueColor];
171171

172172
boundLinePlot.dataSource = self;
@@ -177,7 +177,7 @@ -(void)constructScatterPlot
177177
// Do a blue gradient
178178
CPTColor *areaColor1 = [CPTColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8];
179179
CPTGradient *areaGradient1 = [CPTGradient gradientWithBeginningColor:areaColor1 endingColor:[CPTColor clearColor]];
180-
areaGradient1.angle = -90.0f;
180+
areaGradient1.angle = -90.0;
181181
areaGradientFill = [CPTFill fillWithGradient:areaGradient1];
182182
boundLinePlot.areaFill = areaGradientFill;
183183
boundLinePlot.areaBaseValue = [[NSDecimalNumber zero] decimalValue];
@@ -195,8 +195,8 @@ -(void)constructScatterPlot
195195
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
196196
NSUInteger i;
197197
for ( i = 0; i < 60; i++ ) {
198-
id x = [NSNumber numberWithFloat:1 + i * 0.05];
199-
id y = [NSNumber numberWithFloat:1.2 * rand() / (float)RAND_MAX + 1.2];
198+
NSNumber *x = [NSNumber numberWithFloat:1 + i * 0.05];
199+
NSNumber *y = [NSNumber numberWithFloat:1.2 * rand() / (float)RAND_MAX + 1.2];
200200
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
201201
}
202202
self.dataForPlot = contentArray;
@@ -226,42 +226,42 @@ -(void)constructBarChart
226226
x.axisLineStyle = nil;
227227
x.majorTickLineStyle = nil;
228228
x.minorTickLineStyle = nil;
229-
x.majorIntervalLength = CPTDecimalFromString(@"5");
230-
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
229+
x.majorIntervalLength = CPTDecimalFromDouble(5.0);
230+
x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0);
231231
x.title = @"X Axis";
232232
x.titleLocation = CPTDecimalFromFloat(7.5f);
233-
x.titleOffset = 55.0f;
233+
x.titleOffset = 55.0;
234234

235235
// Define some custom labels for the data elements
236-
x.labelRotation = M_PI / 4;
236+
x.labelRotation = M_PI_4;
237237
x.labelingPolicy = CPTAxisLabelingPolicyNone;
238238
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];
239-
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
239+
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", nil];
240240
NSUInteger labelLocation = 0;
241-
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
241+
NSMutableSet *customLabels = [NSMutableSet setWithCapacity:[xAxisLabels count]];
242242
for ( NSNumber *tickLocation in customTickLocations ) {
243243
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
244244
newLabel.tickLocation = [tickLocation decimalValue];
245245
newLabel.offset = x.labelOffset + x.majorTickLength;
246-
newLabel.rotation = M_PI / 4;
246+
newLabel.rotation = M_PI_4;
247247
[customLabels addObject:newLabel];
248248
}
249249

250-
x.axisLabels = [NSSet setWithArray:customLabels];
250+
x.axisLabels = customLabels;
251251

252252
CPTXYAxis *y = axisSet.yAxis;
253253
y.axisLineStyle = nil;
254254
y.majorTickLineStyle = nil;
255255
y.minorTickLineStyle = nil;
256-
y.majorIntervalLength = CPTDecimalFromString(@"50");
257-
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
256+
y.majorIntervalLength = CPTDecimalFromDouble(50.0);
257+
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0);
258258
y.title = @"Y Axis";
259-
y.titleOffset = 45.0f;
259+
y.titleOffset = 45.0;
260260
y.titleLocation = CPTDecimalFromFloat(150.0f);
261261

262262
// First bar plot
263263
CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor darkGrayColor] horizontalBars:NO];
264-
barPlot.baseValue = CPTDecimalFromString(@"0");
264+
barPlot.baseValue = CPTDecimalFromDouble(0.0);
265265
barPlot.dataSource = self;
266266
barPlot.barOffset = CPTDecimalFromFloat(-0.25f);
267267
barPlot.identifier = @"Bar Plot 1";
@@ -270,9 +270,9 @@ -(void)constructBarChart
270270
// Second bar plot
271271
barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
272272
barPlot.dataSource = self;
273-
barPlot.baseValue = CPTDecimalFromString(@"0");
273+
barPlot.baseValue = CPTDecimalFromDouble(0.0);
274274
barPlot.barOffset = CPTDecimalFromFloat(0.25f);
275-
barPlot.barCornerRadius = 2.0f;
275+
barPlot.barCornerRadius = 2.0;
276276
barPlot.identifier = @"Bar Plot 2";
277277
barPlot.delegate = self;
278278
[barChart addPlot:barPlot toPlotSpace:plotSpace];

0 commit comments

Comments
 (0)