@@ -97,9 +97,7 @@ -(void)setupGraph |
97 | 97 | { |
98 | 98 | // Create graph and apply a dark theme |
99 | 99 | CPTXYGraph *newGraph = [[CPTXYGraph alloc] initWithFrame:NSRectToCGRect(self.hostView.bounds)]; |
100 | | - CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; |
101 | 100 |
|
102 | | - [newGraph applyTheme:theme]; |
103 | 101 | self.hostView.hostedGraph = newGraph; |
104 | 102 | self.graph = newGraph; |
105 | 103 |
|
@@ -108,8 +106,8 @@ -(void)setupGraph |
108 | 106 | NSString *lineTwo = @"This is the Second Line of the Title"; |
109 | 107 |
|
110 | 108 | NSMutableAttributedString *graphTitle = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@", lineOne, lineTwo]]; |
111 | | - [graphTitle addAttribute:NSForegroundColorAttributeName value:[NSColor grayColor] range:NSMakeRange(0, lineOne.length)]; |
112 | | - [graphTitle addAttribute:NSForegroundColorAttributeName value:[NSColor darkGrayColor] range:NSMakeRange(lineOne.length + 1, lineTwo.length)]; |
| 109 | + [graphTitle addAttribute:NSForegroundColorAttributeName value:[NSColor labelColor] range:NSMakeRange(0, lineOne.length)]; |
| 110 | + [graphTitle addAttribute:NSForegroundColorAttributeName value:[NSColor secondaryLabelColor] range:NSMakeRange(lineOne.length + 1, lineTwo.length)]; |
113 | 111 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; |
114 | 112 | paragraphStyle.alignment = CPTTextAlignmentCenter; |
115 | 113 | [graphTitle addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, graphTitle.length)]; |
@@ -122,11 +120,14 @@ -(void)setupGraph |
122 | 120 | newGraph.titleDisplacement = CGPointMake(0.0, 50.0); |
123 | 121 | newGraph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; |
124 | 122 |
|
| 123 | + // newGraph.fill = [CPTFill fillWithColor:[CPTColor colorWithNSColor:[NSColor windowBackgroundColor]]]; |
| 124 | + newGraph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor colorWithNSColor:[NSColor controlBackgroundColor]]]; |
| 125 | + |
125 | 126 | // Graph padding |
126 | | - newGraph.paddingLeft = 60.0; |
| 127 | + newGraph.paddingLeft = 10.0; |
127 | 128 | newGraph.paddingTop = 60.0; |
128 | | - newGraph.paddingRight = 60.0; |
129 | | - newGraph.paddingBottom = 60.0; |
| 129 | + newGraph.paddingRight = 10.0; |
| 130 | + newGraph.paddingBottom = 10.0; |
130 | 131 |
|
131 | 132 | // Plot area delegate |
132 | 133 | newGraph.plotAreaFrame.plotArea.delegate = self; |
@@ -143,20 +144,25 @@ -(void)setupAxes |
143 | 144 | // Grid line styles |
144 | 145 | CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle]; |
145 | 146 | majorGridLineStyle.lineWidth = 0.75; |
146 | | - majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.2] colorWithAlphaComponent:0.75]; |
| 147 | + majorGridLineStyle.lineColor = [[CPTColor colorWithNSColor:[NSColor gridColor]] colorWithAlphaComponent:0.75]; |
147 | 148 |
|
148 | 149 | CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle]; |
149 | 150 | minorGridLineStyle.lineWidth = 0.25; |
150 | | - minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1]; |
| 151 | + minorGridLineStyle.lineColor = [[CPTColor colorWithNSColor:[NSColor gridColor]] colorWithAlphaComponent:0.1]; |
151 | 152 |
|
152 | 153 | CPTMutableLineStyle *redLineStyle = [CPTMutableLineStyle lineStyle]; |
153 | 154 | redLineStyle.lineWidth = 10.0; |
154 | | - redLineStyle.lineColor = [[CPTColor redColor] colorWithAlphaComponent:0.5]; |
| 155 | + redLineStyle.lineColor = [[CPTColor colorWithNSColor:[NSColor systemRedColor]] colorWithAlphaComponent:0.5]; |
155 | 156 |
|
156 | 157 | // Axes |
157 | 158 | // Label x axis with a fixed interval policy |
158 | 159 | CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet; |
159 | 160 | CPTXYAxis *x = axisSet.xAxis; |
| 161 | + |
| 162 | + CPTMutableTextStyle *textStyle = [x.titleTextStyle mutableCopy]; |
| 163 | + textStyle.color = [CPTColor colorWithNSColor:[NSColor secondaryLabelColor]]; |
| 164 | + |
| 165 | + x.labelTextStyle = textStyle; |
160 | 166 | x.majorIntervalLength = @0.5; |
161 | 167 | x.orthogonalPosition = @2.0; |
162 | 168 | x.minorTicksPerInterval = 2; |
@@ -168,8 +174,8 @@ -(void)setupAxes |
168 | 174 | x.labelExclusionRanges = exclusionRanges; |
169 | 175 |
|
170 | 176 | NSMutableAttributedString *xTitle = [[NSMutableAttributedString alloc] initWithString:@"X Axis\nLine 2"]; |
171 | | - [xTitle addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0, 6)]; |
172 | | - [xTitle addAttribute:NSForegroundColorAttributeName value:[NSColor grayColor] range:NSMakeRange(7, 6)]; |
| 177 | + [xTitle addAttribute:NSForegroundColorAttributeName value:[NSColor secondaryLabelColor] range:NSMakeRange(0, 6)]; |
| 178 | + [xTitle addAttribute:NSForegroundColorAttributeName value:[NSColor tertiaryLabelColor] range:NSMakeRange(7, 6)]; |
173 | 179 | NSMutableParagraphStyle *xParagraphStyle = [[NSMutableParagraphStyle alloc] init]; |
174 | 180 | xParagraphStyle.alignment = CPTTextAlignmentCenter; |
175 | 181 | [xTitle addAttribute:NSParagraphStyleAttributeName value:xParagraphStyle range:NSMakeRange(0, xTitle.length)]; |
@@ -181,6 +187,7 @@ -(void)setupAxes |
181 | 187 | // Label y with an automatic label policy. |
182 | 188 | CPTXYAxis *y = axisSet.yAxis; |
183 | 189 | y.labelingPolicy = CPTAxisLabelingPolicyAutomatic; |
| 190 | + y.labelTextStyle = textStyle; |
184 | 191 | y.orthogonalPosition = @2.0; |
185 | 192 | y.minorTicksPerInterval = 2; |
186 | 193 | y.preferredNumberOfMajorTicks = 8; |
@@ -193,8 +200,8 @@ -(void)setupAxes |
193 | 200 | y.labelExclusionRanges = exclusionRanges; |
194 | 201 |
|
195 | 202 | NSMutableAttributedString *yTitle = [[NSMutableAttributedString alloc] initWithString:@"Y Axis\nLine 2"]; |
196 | | - [yTitle addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0, 6)]; |
197 | | - [yTitle addAttribute:NSForegroundColorAttributeName value:[NSColor grayColor] range:NSMakeRange(7, 6)]; |
| 203 | + [yTitle addAttribute:NSForegroundColorAttributeName value:[NSColor secondaryLabelColor] range:NSMakeRange(0, 6)]; |
| 204 | + [yTitle addAttribute:NSForegroundColorAttributeName value:[NSColor tertiaryLabelColor] range:NSMakeRange(7, 6)]; |
198 | 205 | NSMutableParagraphStyle *yParagraphStyle = [[NSMutableParagraphStyle alloc] init]; |
199 | 206 | yParagraphStyle.alignment = CPTTextAlignmentCenter; |
200 | 207 | [yTitle addAttribute:NSParagraphStyleAttributeName value:yParagraphStyle range:NSMakeRange(0, yTitle.length)]; |
@@ -209,6 +216,7 @@ -(void)setupAxes |
209 | 216 | // Add an extra y axis (red) |
210 | 217 | // We add constraints to this axis below |
211 | 218 | CPTXYAxis *y2 = [[CPTXYAxis alloc] initWithFrame:CGRectZero]; |
| 219 | + |
212 | 220 | y2.labelingPolicy = CPTAxisLabelingPolicyAutomatic; |
213 | 221 | y2.orthogonalPosition = @3.0; |
214 | 222 | y2.minorTicksPerInterval = 0; |
@@ -223,8 +231,10 @@ -(void)setupAxes |
223 | 231 | y2.minorTickLineStyle = nil; |
224 | 232 | y2.labelTextStyle = nil; |
225 | 233 | y2.visibleRange = [CPTPlotRange plotRangeWithLocation:@2.0 length:@3.0]; |
| 234 | + y2.titleTextStyle = textStyle; |
226 | 235 | y2.title = @"Y2 title"; |
227 | 236 | y2.titleLocation = @3.0; |
| 237 | + |
228 | 238 | // Set axes |
229 | 239 | self.graph.axisSet.axes = @[x, y, y2]; |
230 | 240 | } |
@@ -249,17 +259,19 @@ -(void)setupScatterPlots |
249 | 259 | [boundLinePlot bind:CPTScatterPlotBindingYValues toObject:self withKeyPath:@"arrangedObjects.y" options:nil]; |
250 | 260 |
|
251 | 261 | // Put an area gradient under the plot above |
252 | | - CPTImage *fillImage = [CPTImage imageNamed:@"BlueTexture"]; |
253 | | - fillImage.tiled = YES; |
254 | | - CPTFill *areaImageFill = [CPTFill fillWithImage:fillImage]; |
255 | | - boundLinePlot.areaFill = areaImageFill; |
| 262 | + CPTColor *areaColor = [CPTColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8]; |
| 263 | + CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]]; |
| 264 | + areaGradient.angle = -90.0; |
| 265 | + CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient]; |
| 266 | + |
| 267 | + boundLinePlot.areaFill = areaGradientFill; |
256 | 268 | boundLinePlot.areaBaseValue = @1.0; |
257 | 269 |
|
258 | 270 | // Add plot symbols |
259 | 271 | CPTMutableLineStyle *symbolLineStyle = [CPTMutableLineStyle lineStyle]; |
260 | 272 | symbolLineStyle.lineColor = [CPTColor blackColor]; |
261 | 273 | CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol]; |
262 | | - plotSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]]; |
| 274 | + plotSymbol.fill = [CPTFill fillWithColor:[CPTColor colorWithNSColor:[NSColor systemBlueColor]]]; |
263 | 275 | plotSymbol.lineStyle = symbolLineStyle; |
264 | 276 | plotSymbol.size = CGSizeMake(10.0, 10.0); |
265 | 277 | boundLinePlot.plotSymbol = plotSymbol; |
@@ -276,14 +288,14 @@ -(void)setupScatterPlots |
276 | 288 |
|
277 | 289 | lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy]; |
278 | 290 | lineStyle.lineWidth = 1.0; |
279 | | - lineStyle.lineColor = [CPTColor greenColor]; |
| 291 | + lineStyle.lineColor = [CPTColor colorWithNSColor:[NSColor systemGreenColor]]; |
280 | 292 | dataSourceLinePlot.dataLineStyle = lineStyle; |
281 | 293 |
|
282 | 294 | dataSourceLinePlot.dataSource = self; |
283 | 295 |
|
284 | | - CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle]; |
285 | | - whiteTextStyle.color = [CPTColor whiteColor]; |
286 | | - dataSourceLinePlot.labelTextStyle = whiteTextStyle; |
| 296 | + CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; |
| 297 | + textStyle.color = [CPTColor colorWithNSColor:[NSColor secondaryLabelColor]]; |
| 298 | + dataSourceLinePlot.labelTextStyle = textStyle; |
287 | 299 |
|
288 | 300 | dataSourceLinePlot.labelOffset = 5.0; |
289 | 301 | dataSourceLinePlot.labelRotation = M_PI_4; |
@@ -293,10 +305,11 @@ -(void)setupScatterPlots |
293 | 305 | dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationStepped; |
294 | 306 |
|
295 | 307 | // Put an area gradient under the plot above |
296 | | - CPTColor *areaColor = [CPTColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8]; |
297 | | - CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]]; |
| 308 | + areaColor = [CPTColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8]; |
| 309 | + areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]]; |
298 | 310 | areaGradient.angle = -90.0; |
299 | | - CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient]; |
| 311 | + areaGradientFill = [CPTFill fillWithGradient:areaGradient]; |
| 312 | + |
300 | 313 | dataSourceLinePlot.areaFill = areaGradientFill; |
301 | 314 | dataSourceLinePlot.areaBaseValue = @1.75; |
302 | 315 |
|
@@ -355,15 +368,16 @@ -(void)setupBarPlots |
355 | 368 | [self.graph addPlotSpace:barPlotSpace]; |
356 | 369 |
|
357 | 370 | // First bar plot |
358 | | - CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle]; |
359 | | - whiteTextStyle.color = [CPTColor whiteColor]; |
| 371 | + CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; |
| 372 | + textStyle.color = [CPTColor colorWithNSColor:[NSColor secondaryLabelColor]]; |
| 373 | + |
360 | 374 | CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor darkGrayColor] horizontalBars:YES]; |
361 | 375 | barPlot.baseValue = @20.0; |
362 | 376 | barPlot.dataSource = self; |
363 | 377 | barPlot.barOffset = @(-0.25); |
364 | 378 | barPlot.identifier = barPlot1; |
365 | 379 | barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@7.0]; |
366 | | - barPlot.labelTextStyle = whiteTextStyle; |
| 380 | + barPlot.labelTextStyle = textStyle; |
367 | 381 | [self.graph addPlot:barPlot toPlotSpace:barPlotSpace]; |
368 | 382 |
|
369 | 383 | // Second bar plot |
@@ -476,7 +490,7 @@ -(void)scatterPlot:(nonnull CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordI |
476 | 490 |
|
477 | 491 | // Setup a style for the annotation |
478 | 492 | CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle]; |
479 | | - hitAnnotationTextStyle.color = [CPTColor whiteColor]; |
| 493 | + hitAnnotationTextStyle.color = [CPTColor colorWithNSColor:[NSColor labelColor]]; |
480 | 494 | hitAnnotationTextStyle.fontSize = CPTFloat(16.0); |
481 | 495 | hitAnnotationTextStyle.fontName = @"Helvetica-Bold"; |
482 | 496 |
|
@@ -521,14 +535,15 @@ -(void)barPlot:(nonnull CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUIntege |
521 | 535 |
|
522 | 536 | // Setup a style for the annotation |
523 | 537 | CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle]; |
524 | | - hitAnnotationTextStyle.color = [CPTColor redColor]; |
| 538 | + hitAnnotationTextStyle.color = [CPTColor colorWithNSColor:[NSColor labelColor]]; |
525 | 539 | hitAnnotationTextStyle.fontSize = 16.0; |
526 | 540 | hitAnnotationTextStyle.fontName = @"Helvetica-Bold"; |
527 | 541 |
|
528 | 542 | // Determine point of symbol in plot coordinates |
529 | 543 |
|
530 | | - NSNumber *x = @0; |
531 | | - NSNumber *y = [self numberForPlot:plot field:0 recordIndex:index]; |
| 544 | + NSNumber *x = @0; |
| 545 | + NSNumber *y = [self numberForPlot:plot field:CPTBarPlotFieldBarLocation recordIndex:index]; |
| 546 | + |
532 | 547 | CPTNumberArray *anchorPoint = @[x, @(index)]; |
533 | 548 |
|
534 | 549 | // Add annotation |
@@ -538,10 +553,10 @@ -(void)barPlot:(nonnull CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUIntege |
538 | 553 | NSString *yString = [formatter stringFromNumber:y]; |
539 | 554 |
|
540 | 555 | // Now add the annotation to the plot area |
541 | | - CPTPlotSpace *defaultSpace = self.graph.defaultPlotSpace; |
542 | | - if ( defaultSpace ) { |
| 556 | + CPTPlotSpace *plotSpace = plot.plotSpace; |
| 557 | + if ( plotSpace ) { |
543 | 558 | CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle]; |
544 | | - annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:defaultSpace anchorPlotPoint:anchorPoint]; |
| 559 | + annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace anchorPlotPoint:anchorPoint]; |
545 | 560 | annotation.contentLayer = textLayer; |
546 | 561 | annotation.displacement = CGPointMake(0.0, 0.0); |
547 | 562 | [self.graph.plotAreaFrame.plotArea addAnnotation:annotation]; |
|