Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for horizontal bar chart. #52

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions JHChartDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
E9D49A191E0927EC000453F0 /* 柱状图demo2.png in Resources */ = {isa = PBXBuildFile; fileRef = E9D49A181E0927EC000453F0 /* 柱状图demo2.png */; };
E9D49A1B1E092D21000453F0 /* 饼状图demo1.png in Resources */ = {isa = PBXBuildFile; fileRef = E9D49A1A1E092D21000453F0 /* 饼状图demo1.png */; };
E9DAFF3E1D6EB6E900D4E148 /* JHTableDataRowModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E9DAFF3D1D6EB6E900D4E148 /* JHTableDataRowModel.m */; };
F133F98C1FDA476E0056E5A5 /* UIDebuggingInformationOverlay+Enable.m in Sources */ = {isa = PBXBuildFile; fileRef = F133F98B1FDA476D0056E5A5 /* UIDebuggingInformationOverlay+Enable.m */; };
F1743D651FCFBB7300B2738A /* JHRowItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F1743D641FCFBB7300B2738A /* JHRowItem.m */; };
F1B4D44D1FCFF3020035E16D /* JHRowChart.m in Sources */ = {isa = PBXBuildFile; fileRef = F1743D611FCFBB0200B2738A /* JHRowChart.m */; };
F1E85A481FD7C91E00713875 /* JHDualBarChart.m in Sources */ = {isa = PBXBuildFile; fileRef = F1E85A471FD7C91E00713875 /* JHDualBarChart.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -138,6 +142,13 @@
E9D49A1A1E092D21000453F0 /* 饼状图demo1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "饼状图demo1.png"; sourceTree = "<group>"; };
E9DAFF3C1D6EB6E900D4E148 /* JHTableDataRowModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JHTableDataRowModel.h; sourceTree = "<group>"; };
E9DAFF3D1D6EB6E900D4E148 /* JHTableDataRowModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JHTableDataRowModel.m; sourceTree = "<group>"; };
F133F98B1FDA476D0056E5A5 /* UIDebuggingInformationOverlay+Enable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDebuggingInformationOverlay+Enable.m"; sourceTree = "<group>"; };
F1743D601FCFBB0200B2738A /* JHRowChart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JHRowChart.h; sourceTree = "<group>"; };
F1743D611FCFBB0200B2738A /* JHRowChart.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JHRowChart.m; sourceTree = "<group>"; };
F1743D631FCFBB7300B2738A /* JHRowItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JHRowItem.h; sourceTree = "<group>"; };
F1743D641FCFBB7300B2738A /* JHRowItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JHRowItem.m; sourceTree = "<group>"; };
F1E85A461FD7C91E00713875 /* JHDualBarChart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JHDualBarChart.h; sourceTree = "<group>"; };
F1E85A471FD7C91E00713875 /* JHDualBarChart.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JHDualBarChart.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -265,13 +276,20 @@
7DEA76341F09DD720060D893 /* JHColumnItem.m */,
7DEA76361F0A34200060D893 /* JHIndexPath.h */,
7DEA76371F0A34200060D893 /* JHIndexPath.m */,
F1743D601FCFBB0200B2738A /* JHRowChart.h */,
F1743D611FCFBB0200B2738A /* JHRowChart.m */,
F1743D631FCFBB7300B2738A /* JHRowItem.h */,
F1743D641FCFBB7300B2738A /* JHRowItem.m */,
F1E85A461FD7C91E00713875 /* JHDualBarChart.h */,
F1E85A471FD7C91E00713875 /* JHDualBarChart.m */,
);
path = JHChart;
sourceTree = "<group>";
};
AAF615181CBF9E7F00E066C3 /* GIFResource */ = {
isa = PBXGroup;
children = (
F133F98B1FDA476D0056E5A5 /* UIDebuggingInformationOverlay+Enable.m */,
7D5EE57A1EE67E5500246792 /* 折线图demo-1.png */,
7D5EE5781EE67E4B00246792 /* 表格图demo-1.png */,
E92CB0401E0BDBFF00861E35 /* 散点图demo1.png */,
Expand Down Expand Up @@ -357,12 +375,12 @@
AA5E2BA61CBA298F00FC19EE /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = JH;
TargetAttributes = {
AA5E2BAD1CBA298F00FC19EE = {
CreatedOnToolsVersion = 7.2.1;
DevelopmentTeam = HRJA43XU8W;
DevelopmentTeam = A4ZY6X2WCR;
};
AA5E2BC61CBA298F00FC19EE = {
CreatedOnToolsVersion = 7.2.1;
Expand Down Expand Up @@ -448,12 +466,15 @@
AA0031601CBCCFD500F4FDEB /* JHShowController.m in Sources */,
E9135FE61D2B810B00ED9F6D /* JHRingChart.m in Sources */,
AAA60A8F1CD8A81A0094D6E5 /* JHPieChart.m in Sources */,
F1B4D44D1FCFF3020035E16D /* JHRowChart.m in Sources */,
F133F98C1FDA476E0056E5A5 /* UIDebuggingInformationOverlay+Enable.m in Sources */,
E92CB03F1E0BA14900861E35 /* JHScatterChart.m in Sources */,
AA57D8A91CD9C492003EA0A7 /* JHShowInfoView.m in Sources */,
AAA60A911CD8A81A0094D6E5 /* JHPieItemsView.m in Sources */,
7DEA76351F09DD720060D893 /* JHColumnItem.m in Sources */,
AAE935E81CBE0CCA002517EB /* JHWaveChart.m in Sources */,
AA5E2BE71CBA2B3100FC19EE /* JHLineChart.m in Sources */,
F1E85A481FD7C91E00713875 /* JHDualBarChart.m in Sources */,
E922F8051D82A8B0000C7C77 /* JHRadarChart.m in Sources */,
7DEA76381F0A34200060D893 /* JHIndexPath.m in Sources */,
AA5E2BEA1CBA2CE700FC19EE /* JHChart.m in Sources */,
Expand All @@ -462,6 +483,7 @@
AA5E2BB61CBA298F00FC19EE /* AppDelegate.m in Sources */,
AAA60A901CD8A81A0094D6E5 /* JHPieForeBGView.m in Sources */,
AA5E2BB31CBA298F00FC19EE /* main.m in Sources */,
F1743D651FCFBB7300B2738A /* JHRowItem.m in Sources */,
E9DAFF3E1D6EB6E900D4E148 /* JHTableDataRowModel.m in Sources */,
E90C3EB01D6D971A0019BE6A /* JHTableChart.m in Sources */,
);
Expand Down Expand Up @@ -526,13 +548,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -569,13 +599,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -604,6 +642,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = A4ZY6X2WCR;
INFOPLIST_FILE = JHChartDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -619,6 +658,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = A4ZY6X2WCR;
INFOPLIST_FILE = JHChartDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>JHChartDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Binary file modified JHChartDemo/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions JHChartDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#if DEBUG
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlay");
[overlayClass performSelector:NSSelectorFromString(@"prepareDebuggingOverlay")];
#endif
return YES;
}

Expand Down
16 changes: 10 additions & 6 deletions JHChartDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="P5V-0a-TXk">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13770" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="P5V-0a-TXk">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13770"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="5NY-TH-FHx">
<objects>
<navigationController id="P5V-0a-TXk" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="2HR-0f-iqN">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand All @@ -30,9 +34,9 @@
<viewControllerLayoutGuide type="bottom" id="TH9-LD-UXd"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="pPA-Dw-lnD">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" id="IY1-hQ-z0M"/>
</viewController>
Expand Down
99 changes: 99 additions & 0 deletions JHChartDemo/GIFResource/UIDebuggingInformationOverlay+Enable.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// UIDebuggingInformationOverlay+Enable.m
// UIDebuggingInformationOverlay
//
// Created by whf5566 on 2017/12/05.
// Copyright © 2017年 whf5566. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <objc/runtime.h>


/*
In iOS 11, Apple added additional checks to disable this overlay unless the
device is an internal device. To get around this, we swizzle out the
-[UIDebuggingInformationOverlay init] method (which returns nil now if
the device is non-internal) and +[UIDebuggingInformationOverlay prepareDebuggingOverlay]
method.

Usage:
1.Copy this file to your project.
2.Add the following code to [AppDelegate application:didFinishLaunchingWithOptions:]

#if DEBUG
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlay");
[overlayClass performSelector:NSSelectorFromString(@"prepareDebuggingOverlay")];
#endif

*/


#if defined(DEBUG) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-implementation"
#pragma clang diagnostic ignored "-Wundeclared-selector"
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

@interface UIWindow (PrivateMethods)
- (void)_setWindowControlsStatusBarOrientation:(BOOL)orientation;
@end

@interface FakeWindowClass : UIWindow
@end

@implementation FakeWindowClass

- (instancetype)initSwizzled {
self = [super init];
if (self) {
[self _setWindowControlsStatusBarOrientation:NO];
}
return self;
}

@end

@implementation NSObject (UIDebuggingInformationOverlayEnable)

+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class cls = NSClassFromString(@"UIDebuggingInformationOverlay");
[FakeWindowClass swizzleSelector:@selector(init) newSelector:@selector(initSwizzled) forClass:cls isClassMethod:NO];
[self swizzleSelector:@selector(prepareDebuggingOverlay) newSelector:@selector(prepareDebuggingOverlaySwizzled) forClass:cls isClassMethod:YES];
});
}

+ (void)swizzleSelector:(SEL)originalSelector newSelector:(SEL)swizzledSelector forClass:(Class)class isClassMethod:(BOOL)isClassMethod {
Method originalMethod = NULL;
Method swizzledMethod = NULL;

if (isClassMethod) {
originalMethod = class_getClassMethod(class, originalSelector);
swizzledMethod = class_getClassMethod([self class], swizzledSelector);
} else {
originalMethod = class_getInstanceMethod(class, originalSelector);
swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
}
method_exchangeImplementations(originalMethod, swizzledMethod);
}

+ (void)prepareDebuggingOverlaySwizzled {
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlayInvokeGestureHandler");
id handler = [overlayClass performSelector:NSSelectorFromString(@"mainHandler")];

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:handler action:@selector(_handleActivationGesture:)];
tapGesture.numberOfTouchesRequired = 2;
tapGesture.numberOfTapsRequired = 1;
tapGesture.delegate = handler;

UIView *statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
[statusBarWindow addGestureRecognizer:tapGesture];
}

@end
#pragma clang diagnostic pop

#endif
8 changes: 8 additions & 0 deletions JHChartDemo/JHChart/JHChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
#import <Foundation/Foundation.h>

#define P_M(x,y) CGPointMake(x, y)
#define G_W(r) CGRectGetWidth(r)
#define G_H(r) CGRectGetHeight(r)

#define SAFE_ACCESS(a, i) (((a).count > i) ? (a)[i] : nil)

#define weakSelf(weakSelf) __weak typeof(self) weakself = self;
#define XORYLINEMAXSIZE CGSizeMake(CGFLOAT_MAX,30)

@interface JHChart : UIView


Expand Down Expand Up @@ -150,4 +155,7 @@
- (CGSize)sizeOfStringWithMaxSize:(CGSize)maxSize
textFont:(CGFloat)fontSize
aimString:(NSString *)aimString;

- (CGSize)sizeOfString:(NSString *)string withFont:(UIFont *)font;

@end
10 changes: 7 additions & 3 deletions JHChartDemo/JHChart/JHChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ - (void)drawPointWithRedius:(CGFloat)redius andColor:(UIColor *)color andPoint:(
* @return 占用尺寸
*/
- (CGSize)sizeOfStringWithMaxSize:(CGSize)maxSize textFont:(CGFloat)fontSize aimString:(NSString *)aimString{


return [[NSString stringWithFormat:@"%@",aimString] boundingRectWithSize:maxSize options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;

}

- (CGSize)sizeOfString:(NSString *)string withFont:(UIFont *)font {
return [string boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT)
options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingTruncatesLastVisibleLine
attributes:@{NSFontAttributeName:font} context:nil].size;
}


-(void)dealloc{
#if DEBUG
NSLog(@"%@ has dealloc",NSStringFromClass([self class]));
Expand Down
4 changes: 3 additions & 1 deletion JHChartDemo/JHChart/JHChartHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// Copyright © 2016年 JH. All rights reserved.
//


#import "JHChart.h"
#import "JHLineChart.h"
#import "JHWaveChart.h"
#import "JHPieChart.h"
#import "JHRingChart.h"
#import "JHColumnChart.h"
#import "JHRowChart.h"
#import "JHRowChart.h"
#import "JHTableChart.h"
#import "JHRadarChart.h"
#import "JHScatterChart.h"
#import "JHDualBarChart.h"
Loading