Skip to content

Commit 87c19cd

Browse files
committed
Turned on the standard Core Plot warnings in the Quartz Composer plug-in and fixed the resulting warnings.
1 parent 76f8e10 commit 87c19cd

9 files changed

Lines changed: 301 additions & 276 deletions

File tree

QCPlugin/CPTBarPlotPlugin.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#import "CorePlotQCPlugIn.h"
22
#import <Cocoa/Cocoa.h>
33

4-
@interface CPTBarPlotPlugIn : CorePlotQCPlugIn<CPTBarPlotDataSource> {
5-
}
4+
@interface CPTBarPlotPlugIn : CorePlotQCPlugIn<CPTBarPlotDataSource>
65

7-
@property (nonatomic, readwrite, assign) double inputBaseValue;
8-
@property (nonatomic, readwrite, assign) double inputBarWidth;
9-
@property (nonatomic, readwrite, assign) double inputBarOffset;
10-
@property (nonatomic, readwrite, assign) BOOL inputHorizontalBars;
6+
@property (readwrite, assign) double inputBaseValue;
7+
@property (readwrite, assign) double inputBarWidth;
8+
@property (readwrite, assign) double inputBarOffset;
9+
@property (readwrite, assign) BOOL inputHorizontalBars;
1110

1211
@end

QCPlugin/CPTBarPlotPlugin.m

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ -(void)addPlotWithIndex:(NSUInteger)index
109109
QCPortAttributeTypeKey: QCPortTypeStructure }
110110
];
111111

112-
NSColor *lineColor = [self newDefaultColorForPlot:index alpha:1.0];
112+
CGColorRef lineColor = [self newDefaultColorForPlot:index alpha:1.0];
113113
[self addInputPortWithType:QCPortTypeColor
114114
forKey:[NSString stringWithFormat:@"plotDataLineColor%lu", (unsigned long)index]
115115
withAttributes:@{ QCPortAttributeNameKey: [NSString stringWithFormat:@"Plot Line Color %lu", (unsigned long)(index + 1)],
116116
QCPortAttributeTypeKey: QCPortTypeColor,
117-
QCPortAttributeDefaultValueKey: lineColor }
117+
QCPortAttributeDefaultValueKey: CFBridgingRelease(lineColor) }
118118
];
119119

120-
NSColor *fillColor = [self newDefaultColorForPlot:index alpha:0.25];
120+
CGColorRef fillColor = [self newDefaultColorForPlot:index alpha:0.25];
121121
[self addInputPortWithType:QCPortTypeColor
122122
forKey:[NSString stringWithFormat:@"plotFillColor%lu", (unsigned long)index]
123123
withAttributes:@{ QCPortAttributeNameKey: [NSString stringWithFormat:@"Plot Fill Color %lu", (unsigned long)(index + 1)],
124124
QCPortAttributeTypeKey: QCPortTypeColor,
125-
QCPortAttributeDefaultValueKey: fillColor }
125+
QCPortAttributeDefaultValueKey: CFBridgingRelease(fillColor) }
126126
];
127127

128128
[self addInputPortWithType:QCPortTypeNumber
@@ -137,42 +137,47 @@ -(void)addPlotWithIndex:(NSUInteger)index
137137
CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor greenColor] horizontalBars:NO];
138138
barPlot.identifier = [NSString stringWithFormat:@"Bar Plot %lu", (unsigned long)(index + 1)];
139139
barPlot.dataSource = self;
140-
[graph addPlot:barPlot];
140+
[self.graph addPlot:barPlot];
141141
}
142142

143143
-(void)removePlots:(NSUInteger)count
144144
{
145145
// Clean up a deleted plot
146+
CPTGraph *theGraph = self.graph;
146147

147-
for ( int i = numberOfPlots; i > numberOfPlots - count; i-- ) {
148-
[self removeInputPortForKey:[NSString stringWithFormat:@"plotNumbers%i", i - 1]];
149-
[self removeInputPortForKey:[NSString stringWithFormat:@"plotDataLineColor%i", i - 1]];
150-
[self removeInputPortForKey:[NSString stringWithFormat:@"plotFillColor%i", i - 1]];
151-
[self removeInputPortForKey:[NSString stringWithFormat:@"plotDataLineWidth%i", i - 1]];
148+
NSUInteger plotCount = self.numberOfPlots;
152149

153-
[graph removePlot:[[graph allPlots] lastObject]];
150+
for ( NSUInteger i = plotCount; i > plotCount - count; i-- ) {
151+
[self removeInputPortForKey:[NSString stringWithFormat:@"plotNumbers%lu", (unsigned long)(i - 1)]];
152+
[self removeInputPortForKey:[NSString stringWithFormat:@"plotDataLineColor%lu", (unsigned long)(i - 1)]];
153+
[self removeInputPortForKey:[NSString stringWithFormat:@"plotFillColor%lu", (unsigned long)(i - 1)]];
154+
[self removeInputPortForKey:[NSString stringWithFormat:@"plotDataLineWidth%lu", (unsigned long)(i - 1)]];
155+
156+
[theGraph removePlot:[[theGraph allPlots] lastObject]];
154157
}
155158
}
156159

157160
-(BOOL)configurePlots
158161
{
162+
CPTGraph *theGraph = self.graph;
163+
159164
// The pixel width of a single plot unit (1..2) along the x axis of the plot
160-
double count = (double)[[graph allPlots] count];
161-
double unitWidth = graph.plotAreaFrame.bounds.size.width / (self.inputXMax - self.inputXMin);
165+
double count = (double)[[theGraph allPlots] count];
166+
double unitWidth = theGraph.plotAreaFrame.bounds.size.width / (self.inputXMax - self.inputXMin);
162167
double barWidth = self.inputBarWidth * unitWidth / count;
163168

164169
// Configure scatter plots for active plot inputs
165-
for ( CPTBarPlot *plot in [graph allPlots] ) {
166-
int index = [[graph allPlots] indexOfObject:plot];
170+
for ( CPTBarPlot *plot in [theGraph allPlots] ) {
171+
NSUInteger index = [[theGraph allPlots] indexOfObject:plot];
167172
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
168-
lineStyle.lineColor = [CPTColor colorWithCGColor:[self dataLineColor:index].CGColor];
173+
lineStyle.lineColor = [CPTColor colorWithCGColor:[self dataLineColor:index]];
169174
lineStyle.lineWidth = [self dataLineWidth:index];
170175
plot.lineStyle = lineStyle;
171176
plot.baseValue = CPTDecimalFromDouble(self.inputBaseValue);
172177
plot.barWidth = CPTDecimalFromDouble(barWidth);
173178
plot.barOffset = CPTDecimalFromDouble(self.inputBarOffset);
174179
plot.barsAreHorizontal = self.inputHorizontalBars;
175-
plot.fill = [CPTFill fillWithColor:[CPTColor colorWithCGColor:[self areaFillColor:index].CGColor]];
180+
plot.fill = [CPTFill fillWithColor:[CPTColor colorWithCGColor:(CGColorRef)[self areaFillColor : index]]];
176181

177182
[plot reloadData];
178183
}
@@ -185,33 +190,30 @@ -(BOOL)configurePlots
185190

186191
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
187192
{
188-
NSUInteger plotIndex = [[graph allPlots] indexOfObject:plot];
193+
NSUInteger plotIndex = [[self.graph allPlots] indexOfObject:plot];
189194
NSString *key = [NSString stringWithFormat:@"plotNumbers%lu", (unsigned long)plotIndex];
190195

191-
if ( ![self valueForInputKey:key] ) {
192-
return 0;
193-
}
194-
195196
return [[self valueForInputKey:key] count];
196197
}
197198

198-
-(NSArray *)numbersForPlot:(CPTBarPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange
199+
-(NSArray *)numbersForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange
199200
{
200-
NSUInteger plotIndex = [[graph allPlots] indexOfObject:plot];
201+
NSUInteger plotIndex = [[self.graph allPlots] indexOfObject:plot];
201202
NSString *key = [NSString stringWithFormat:@"plotNumbers%lu", (unsigned long)plotIndex];
202203

203-
if ( ![self valueForInputKey:key] ) {
204+
NSDictionary *dict = [self valueForInputKey:key];
205+
206+
if ( !dict ) {
204207
return nil;
205208
}
206209

207-
NSDictionary *dict = [self valueForInputKey:key];
208210
NSUInteger keyCount = [[dict allKeys] count];
209211
NSMutableArray *array = [NSMutableArray array];
210212

211213
if ( fieldEnum == CPTBarPlotFieldBarLocation ) {
212214
// Calculate horizontal position of bar - nth bar index + barWidth*plotIndex + 0.5
213215
float xpos;
214-
float plotCount = [[graph allPlots] count];
216+
float plotCount = [[self.graph allPlots] count];
215217

216218
for ( NSUInteger i = 0; i < keyCount; i++ ) {
217219
xpos = (float)i + (float)plotIndex / (plotCount);

QCPlugin/CPTPieChartPlugin.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#import "CorePlotQCPlugIn.h"
22
#import <Cocoa/Cocoa.h>
33

4-
@interface CPTPieChartPlugIn : CorePlotQCPlugIn<CPTPieChartDataSource> {
5-
}
4+
@interface CPTPieChartPlugIn : CorePlotQCPlugIn<CPTPieChartDataSource>
65

7-
@property (nonatomic, readwrite, assign) double inputPieRadius;
8-
@property (nonatomic, readwrite, assign) double inputSliceLabelOffset;
9-
@property (nonatomic, readwrite, assign) double inputStartAngle;
10-
@property (nonatomic, readwrite, assign) NSUInteger inputSliceDirection;
11-
@property (nonatomic, readwrite, assign) double inputBorderWidth;
12-
@property (nonatomic, readwrite, strong) NSColor *inputBorderColor;
13-
@property (nonatomic, readwrite, strong) NSColor *inputLabelColor;
6+
@property (readwrite, assign) double inputPieRadius;
7+
@property (readwrite, assign) double inputSliceLabelOffset;
8+
@property (readwrite, assign) double inputStartAngle;
9+
@property (readwrite, assign) NSUInteger inputSliceDirection;
10+
@property (readwrite, assign) double inputBorderWidth;
11+
@property (readwrite, assign) CGColorRef inputBorderColor;
12+
@property (readwrite, assign) CGColorRef inputLabelColor;
1413

1514
@end

QCPlugin/CPTPieChartPlugin.m

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ +(NSDictionary *)attributesForPropertyPortWithKey:(NSString *)key
105105
};
106106
}
107107
else if ( [key isEqualToString:@"inputBorderColor"] ) {
108+
CGColorRef grayColor = CGColorCreateGenericGray(0.0, 1.0);
108109
NSDictionary *result = @{
109110
QCPortAttributeNameKey: @"Border Color",
110-
QCPortAttributeDefaultValueKey: [NSColor colorWithSRGBRed:0.0 green:0.0 blue:0.0 alpha:1.0]
111+
QCPortAttributeDefaultValueKey: CFBridgingRelease(grayColor)
111112
};
112113
return result;
113114
}
114115
else if ( [key isEqualToString:@"inputLabelColor"] ) {
116+
CGColorRef grayColor = CGColorCreateGenericGray(1.0, 1.0);
115117
NSDictionary *result = @{
116118
QCPortAttributeNameKey: @"Label Color",
117-
QCPortAttributeDefaultValueKey: [NSColor colorWithSRGBRed:1.0 green:1.0 blue:1.0 alpha:1.0]
119+
QCPortAttributeDefaultValueKey: CFBridgingRelease(grayColor)
118120
};
119121
return result;
120122
}
@@ -140,19 +142,20 @@ -(void)addPlotWithIndex:(NSUInteger)index
140142

141143
// TODO: add support for used defined fill colors. As of now we use a single color
142144
// multiplied against the 'default' pie chart colors
145+
CGColorRef grayColor = CGColorCreateGenericGray(1.0, 1.0);
143146
[self addInputPortWithType:QCPortTypeColor
144147
forKey:[NSString stringWithFormat:@"plotFillColor%lu", (unsigned long)index]
145148
withAttributes:@{ QCPortAttributeNameKey: [NSString stringWithFormat:@"Primary Fill Color %lu", (unsigned long)(index + 1)],
146149
QCPortAttributeTypeKey: QCPortTypeColor,
147-
QCPortAttributeDefaultValueKey: [NSColor colorWithSRGBRed:1.0 green:1.0 blue:1.0 alpha:1.0] }
150+
QCPortAttributeDefaultValueKey: CFBridgingRelease(grayColor) }
148151
];
149152

150153
// Add the new plot to the graph
151154
CPTPieChart *pieChart = [[CPTPieChart alloc] init];
152155
pieChart.identifier = [NSString stringWithFormat:@"Pie Chart %lu", (unsigned long)(index + 1)];
153156
pieChart.dataSource = self;
154157

155-
[graph addPlot:pieChart];
158+
[self.graph addPlot:pieChart];
156159
}
157160
}
158161

@@ -161,26 +164,29 @@ -(void)addPlotWithIndex:(NSUInteger)index
161164

162165
-(void)createGraph
163166
{
164-
if ( !graph ) {
167+
if ( !self.graph ) {
165168
// Create graph from theme
166169
CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
167-
graph = (CPTXYGraph *)[theme newGraph];
168-
graph.axisSet = nil;
170+
self.graph = (CPTXYGraph *)[theme newGraph];
171+
172+
self.graph.axisSet = nil;
169173
}
170174
}
171175

172176
-(BOOL)configureAxis
173177
{
174178
// We use no axis for the pie chart
175-
graph.axisSet = nil;
176-
graph.plotAreaFrame.plotArea.borderLineStyle = nil;
179+
self.graph.axisSet = nil;
180+
181+
self.graph.plotAreaFrame.plotArea.borderLineStyle = nil;
182+
177183
return YES;
178184
}
179185

180186
-(BOOL)configurePlots
181187
{
182188
// Configure the pie chart
183-
for ( CPTPieChart *pieChart in [graph allPlots] ) {
189+
for ( CPTPieChart *pieChart in [self.graph allPlots] ) {
184190
pieChart.plotArea.borderLineStyle = nil;
185191

186192
pieChart.pieRadius = self.inputPieRadius * MIN(self.inputPixelsWide, self.inputPixelsHigh) / 2.0;
@@ -192,7 +198,7 @@ -(BOOL)configurePlots
192198
if ( self.inputBorderWidth > 0.0 ) {
193199
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
194200
borderLineStyle.lineWidth = self.inputBorderWidth;
195-
borderLineStyle.lineColor = [CPTColor colorWithCGColor:self.inputBorderColor.CGColor];
201+
borderLineStyle.lineColor = [CPTColor colorWithCGColor:self.inputBorderColor];
196202
borderLineStyle.lineCap = kCGLineCapSquare;
197203
borderLineStyle.lineJoin = kCGLineJoinBevel;
198204
pieChart.borderLineStyle = borderLineStyle;
@@ -212,33 +218,31 @@ -(BOOL)configurePlots
212218

213219
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
214220
{
215-
NSUInteger plotIndex = [[graph allPlots] indexOfObject:plot];
221+
NSUInteger plotIndex = [[self.graph allPlots] indexOfObject:plot];
216222
NSString *key = [NSString stringWithFormat:@"plotNumbers%lu", (unsigned long)plotIndex];
217223

218-
if ( ![self valueForInputKey:key] ) {
219-
return 0;
220-
}
221-
222224
return [[self valueForInputKey:key] count];
223225
}
224226

225227
-(id)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
226228
{
227-
NSUInteger plotIndex = [[graph allPlots] indexOfObject:plot];
229+
NSUInteger plotIndex = [[self.graph allPlots] indexOfObject:plot];
228230
NSString *key = [NSString stringWithFormat:@"plotNumbers%lu", (unsigned long)plotIndex];
229231

230-
if ( ![self valueForInputKey:key] ) {
232+
NSDictionary *dict = [self valueForInputKey:key];
233+
234+
if ( dict ) {
235+
return [NSDecimalNumber decimalNumberWithString:[dict[[NSString stringWithFormat:@"%lu", (unsigned long)index]] stringValue]];
236+
}
237+
else {
231238
return nil;
232239
}
233-
234-
NSDictionary *dict = [self valueForInputKey:key];
235-
return [NSDecimalNumber decimalNumberWithString:[dict[[NSString stringWithFormat:@"%lu", (unsigned long)index]] stringValue]];
236240
}
237241

238242
-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
239243
{
240244
CGColorRef plotFillColor = [[CPTPieChart defaultPieSliceColorForIndex:index] cgColor];
241-
CGColorRef inputFillColor = [self areaFillColor:0].CGColor;
245+
CGColorRef inputFillColor = (CGColorRef)[self areaFillColor : 0];
242246

243247
const CGFloat *plotColorComponents = CGColorGetComponents(plotFillColor);
244248
const CGFloat *inputColorComponents = CGColorGetComponents(inputFillColor);
@@ -257,22 +261,22 @@ -(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger
257261

258262
-(CPTTextLayer *)sliceLabelForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
259263
{
260-
NSUInteger plotIndex = [[graph allPlots] indexOfObject:pieChart];
264+
NSUInteger plotIndex = [[self.graph allPlots] indexOfObject:pieChart];
261265
NSString *key = [NSString stringWithFormat:@"plotLabels%lu", (unsigned long)plotIndex];
262266

263-
if ( ![self valueForInputKey:key] ) {
267+
NSDictionary *dict = [self valueForInputKey:key];
268+
269+
if ( !dict ) {
264270
return nil;
265271
}
266272

267-
NSDictionary *dict = [self valueForInputKey:key];
268-
269273
NSString *label = dict[[NSString stringWithFormat:@"%lu", (unsigned long)index]];
270274

271275
CPTTextLayer *layer = [[CPTTextLayer alloc] initWithText:label];
272276
[layer sizeToFit];
273277

274278
CPTMutableTextStyle *style = [CPTMutableTextStyle textStyle];
275-
style.color = [CPTColor colorWithCGColor:self.inputLabelColor.CGColor];
279+
style.color = [CPTColor colorWithCGColor:self.inputLabelColor];
276280
layer.textStyle = style;
277281

278282
return layer;

QCPlugin/CPTScatterPlotPlugin.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import "CorePlotQCPlugIn.h"
22
#import <Cocoa/Cocoa.h>
33

4-
@interface CPTScatterPlotPlugIn : CorePlotQCPlugIn {
5-
}
4+
@interface CPTScatterPlotPlugIn : CorePlotQCPlugIn
65

76
@end

0 commit comments

Comments
 (0)