@@ -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;
0 commit comments