Skip to content

Commit e61d29e

Browse files
committed
Added a -debugQuickLookObject() method to many Core Plot classes for debugging and Swift playground support.
1 parent 240889c commit e61d29e

19 files changed

Lines changed: 414 additions & 21 deletions

framework/CorePlot.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@
551551
C3A695E5146A19BC00AF5653 /* CPTMutablePlotRange.h in Headers */ = {isa = PBXBuildFile; fileRef = C3A695E3146A19BC00AF5653 /* CPTMutablePlotRange.h */; settings = {ATTRIBUTES = (Public, ); }; };
552552
C3A695E6146A19BC00AF5653 /* CPTMutablePlotRange.m in Sources */ = {isa = PBXBuildFile; fileRef = C3A695E4146A19BC00AF5653 /* CPTMutablePlotRange.m */; };
553553
C3AFC9D10FB62969005DFFDC /* CPTImage.h in Headers */ = {isa = PBXBuildFile; fileRef = C3AFC9CF0FB62969005DFFDC /* CPTImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
554+
C3BB93191B729BD200004527 /* CPTDebugQuickLook.h in Headers */ = {isa = PBXBuildFile; fileRef = C3BB93181B729BD200004527 /* CPTDebugQuickLook.h */; };
555+
C3BB931A1B729BD200004527 /* CPTDebugQuickLook.h in Headers */ = {isa = PBXBuildFile; fileRef = C3BB93181B729BD200004527 /* CPTDebugQuickLook.h */; };
554556
C3BFFD1112274CB500DE22AC /* CPTNumericDataTypeConversionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C97EF08104D80D400B554F9 /* CPTNumericDataTypeConversionTests.m */; };
555557
C3C1C0801790D3B400E8B1B7 /* CPTLayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C1C07F1790D3B400E8B1B7 /* CPTLayerTests.m */; };
556558
C3C9CB0E165DB4D500739006 /* CPTAnimationOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C9CB0C165DB4D500739006 /* CPTAnimationOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -874,6 +876,7 @@
874876
C3B235631009931400970270 /* doxygen-cocoa-tags.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = "doxygen-cocoa-tags.xml"; path = "../documentation/doxygen/doxygen-cocoa-tags.xml"; sourceTree = "<group>"; };
875877
C3B25EDF1AC23A7D0063CCD8 /* CorePlot.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CorePlot.h; sourceTree = "<group>"; };
876878
C3BB7D1416322F7E00BC9515 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
879+
C3BB93181B729BD200004527 /* CPTDebugQuickLook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPTDebugQuickLook.h; sourceTree = "<group>"; };
877880
C3C032C710B8DEDC003A11B6 /* CPTAxisLabelGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPTAxisLabelGroup.h; sourceTree = "<group>"; };
878881
C3C032C810B8DEDC003A11B6 /* CPTAxisLabelGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CPTAxisLabelGroup.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
879882
C3C1C07E1790D3B400E8B1B7 /* CPTLayerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPTLayerTests.h; sourceTree = "<group>"; };
@@ -1276,6 +1279,7 @@
12761279
C3A695E4146A19BC00AF5653 /* CPTMutablePlotRange.m */,
12771280
C3F97F1C17A9E07B00A52FF2 /* CPTFunctionDataSource.h */,
12781281
C3F97F1D17A9E07B00A52FF2 /* CPTFunctionDataSource.m */,
1282+
C3BB93181B729BD200004527 /* CPTDebugQuickLook.h */,
12791283
076A775F0FBF0BFE003F6D97 /* Tests */,
12801284
);
12811285
name = "Types and Functions";
@@ -1749,6 +1753,7 @@
17491753
070622320FDF1B250066A6C4 /* CPTPathExtensions.h in Headers */,
17501754
0706223C0FDF215C0066A6C4 /* CPTBorderedLayer.h in Headers */,
17511755
07C4679B0FE1A24C00299939 /* CPTMutableTextStyle.h in Headers */,
1756+
C3BB93191B729BD200004527 /* CPTDebugQuickLook.h in Headers */,
17521757
07C467B80FE1A96E00299939 /* CPTTextStylePlatformSpecific.h in Headers */,
17531758
0772C9270FE2F71600EC4C16 /* CPTTheme.h in Headers */,
17541759
0772C92F0FE2F89000EC4C16 /* _CPTDarkGradientTheme.h in Headers */,
@@ -1897,6 +1902,7 @@
18971902
C38A0B241A46264500D45436 /* CPTPlatformSpecificFunctions.h in Headers */,
18981903
C38A0A3B1A461EDA00D45436 /* CPTAnnotationHostLayer.h in Headers */,
18991904
C38A0AF31A4625E800D45436 /* CPTAxisLabel.h in Headers */,
1905+
C3BB931A1B729BD200004527 /* CPTDebugQuickLook.h in Headers */,
19001906
C38A0A2F1A461EB100D45436 /* _CPTAnimationTimingFunctions.h in Headers */,
19011907
C38A0A4D1A461F1D00D45436 /* CPTMutableTextStyle.h in Headers */,
19021908
C38A0AA81A46240300D45436 /* CPTXYGraph.h in Headers */,

framework/MacOnly/CPTPlatformSpecificFunctions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "CPTDefinitions.h"
2+
#import "CPTPlatformSpecificDefines.h"
23

34
/// @file
45

@@ -26,6 +27,12 @@ CPTRGBAColor CPTRGBAColorFromNSColor(NSColor *__nonnull nsColor);
2627

2728
/// @}
2829

30+
/// @name Debugging
31+
/// @{
32+
CPTNativeImage *__nonnull CPTQuickLookImage(CGRect rect, __nonnull CPTQuickLookImageBlock renderBlock);
33+
34+
/// @}
35+
2936
#if __cplusplus
3037
}
3138
#endif

framework/MacOnly/CPTPlatformSpecificFunctions.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,36 @@ CPTRGBAColor CPTRGBAColorFromNSColor(NSColor *nsColor)
111111

112112
return rgbColor;
113113
}
114+
115+
#pragma mark -
116+
#pragma mark Debugging
117+
118+
CPTNativeImage * __nonnull CPTQuickLookImage(CGRect rect, __nonnull CPTQuickLookImageBlock renderBlock)
119+
{
120+
NSBitmapImageRep *layerImage = [[NSBitmapImageRep alloc]
121+
initWithBitmapDataPlanes:NULL
122+
pixelsWide:(NSInteger)rect.size.width
123+
pixelsHigh:(NSInteger)rect.size.height
124+
bitsPerSample:8
125+
samplesPerPixel:4
126+
hasAlpha:YES
127+
isPlanar:NO
128+
colorSpaceName:NSCalibratedRGBColorSpace
129+
bytesPerRow:(NSInteger)rect.size.width * 4
130+
bitsPerPixel:32];
131+
132+
NSGraphicsContext *bitmapContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:layerImage];
133+
134+
CGContextRef context = (CGContextRef)[bitmapContext graphicsPort];
135+
136+
CGContextClearRect(context, rect);
137+
138+
renderBlock(context, 1.0, rect);
139+
140+
CGContextFlush(context);
141+
142+
NSImage *image = [[NSImage alloc] initWithSize:NSSizeFromCGSize(rect.size)];
143+
[image addRepresentation:layerImage];
144+
145+
return image;
146+
}

framework/Source/CPTColor.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#import "CPTColorSpace.h"
44
#import "CPTDefinitions.h"
5+
#import "CPTPlatformSpecificCategories.h"
56
#import "NSCoderExtensions.h"
67

78
/** @brief An immutable color.
@@ -515,4 +516,21 @@ -(NSUInteger)hash
515516

516517
/// @endcond
517518

519+
#pragma mark -
520+
#pragma mark Debugging
521+
522+
/// @cond
523+
524+
-(id)debugQuickLookObject
525+
{
526+
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
527+
return self.uiColor;
528+
529+
#else
530+
return self.nsColor;
531+
#endif
532+
}
533+
534+
/// @endcond
535+
518536
@end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @brief Methods used to show QuickLook previews of objects in the Xcode debugger and Swift playgrounds.
3+
**/
4+
@protocol CPTDebugQuickLook<NSObject>
5+
6+
/// @name Debugging
7+
/// @{
8+
9+
/**
10+
* @brief Used to show QuickLook previews of objects in the Xcode debugger and Swift playgrounds.
11+
**/
12+
-(id)debugQuickLookObject;
13+
14+
/// @}
15+
16+
@end
17+
18+
#pragma mark -
19+
20+
/** @category NSObject(CPTDebugQuickLookExtension)
21+
* @brief Debugging extensions to NSObject.
22+
**/
23+
@interface NSObject(CPTDebugQuickLookExtension)<CPTDebugQuickLook> {
24+
}
25+
26+
@end

framework/Source/CPTDefinitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,5 @@ typedef struct _CPTEdgeInsets {
235235
CPTEdgeInsets;
236236

237237
extern const CPTEdgeInsets CPTEdgeInsetsZero; ///< Defines a set of stretchable image edge insets where all of the values are zero (@num{0}).
238+
239+
typedef void (^CPTQuickLookImageBlock)(__nonnull CGContextRef context, CGFloat scale, CGRect bounds); ///< Render a Quick Look image into the given context.

framework/Source/CPTFill.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#import "CPTColor.h"
44
#import "CPTImage.h"
5+
#import "CPTPlatformSpecificFunctions.h"
56
#import "_CPTFillColor.h"
67
#import "_CPTFillGradient.h"
78
#import "_CPTFillImage.h"
@@ -178,4 +179,20 @@ -(void)fillPathInContext:(CGContextRef)context
178179
// do nothing--subclasses override to do drawing here
179180
}
180181

182+
#pragma mark -
183+
#pragma mark Debugging
184+
185+
/// @cond
186+
187+
-(id)debugQuickLookObject
188+
{
189+
const CGRect rect = CGRectMake(0.0, 0.0, 100.0, 100.0);
190+
191+
return CPTQuickLookImage(rect, ^(CGContextRef context, CGFloat scale, CGRect bounds) {
192+
[self fillRect:bounds inContext:context];
193+
});
194+
}
195+
196+
/// @endcond
197+
181198
@end

framework/Source/CPTGradient.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#import "CPTColor.h"
44
#import "CPTColorSpace.h"
5+
#import "CPTPlatformSpecificFunctions.h"
56
#import "CPTUtilities.h"
67
#import "NSCoderExtensions.h"
78
#import <tgmath.h>
@@ -1623,4 +1624,29 @@ void CPTResolveHSV(CGFloat *color1, CGFloat *color2) // H value may be undefined
16231624

16241625
/// @endcond
16251626

1627+
#pragma mark -
1628+
#pragma mark Debugging
1629+
1630+
/// @cond
1631+
1632+
-(id)debugQuickLookObject
1633+
{
1634+
const CGRect rect = CGRectMake(0.0, 0.0, 100.0, 100.0);
1635+
1636+
return CPTQuickLookImage(rect, ^(CGContextRef context, CGFloat scale, CGRect bounds) {
1637+
switch ( self.gradientType ) {
1638+
case CPTGradientTypeAxial:
1639+
CGContextAddRect(context, bounds);
1640+
break;
1641+
1642+
case CPTGradientTypeRadial:
1643+
CGContextAddEllipseInRect(context, bounds);
1644+
break;
1645+
}
1646+
[self fillPathInContext:context];
1647+
});
1648+
}
1649+
1650+
/// @endcond
1651+
16261652
@end

framework/Source/CPTImage.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,4 +818,16 @@ -(void)drawInRect:(CGRect)rect inContext:(CGContextRef)context
818818
self.lastDrawnScale = contextScale;
819819
}
820820

821+
#pragma mark -
822+
#pragma mark Debugging
823+
824+
/// @cond
825+
826+
-(id)debugQuickLookObject
827+
{
828+
return self.nativeImage;
829+
}
830+
831+
/// @endcond
832+
821833
@end

framework/Source/CPTLayer.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#import "CPTGraph.h"
44
#import "CPTPathExtensions.h"
5+
#import "CPTPlatformSpecificCategories.h"
56
#import "CPTPlatformSpecificFunctions.h"
67
#import "CPTShadow.h"
78
#import "CPTUtilities.h"
@@ -1067,4 +1068,16 @@ -(NSString *)subLayersAtIndex:(NSUInteger)idx
10671068

10681069
/// @endcond
10691070

1071+
#pragma mark -
1072+
#pragma mark Debugging
1073+
1074+
/// @cond
1075+
1076+
-(id)debugQuickLookObject
1077+
{
1078+
return [self imageOfLayer];
1079+
}
1080+
1081+
/// @endcond
1082+
10701083
@end

0 commit comments

Comments
 (0)