├── HCLineChartView Sample
├── HCLineChartView Sample.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── hypercube2.xcuserdatad
│ │ │ ├── IDEFindNavigatorScopes.plist
│ │ │ ├── UserInterfaceState.xcuserstate
│ │ │ └── xcdebugger
│ │ │ └── Expressions.xcexplist
│ └── xcuserdata
│ │ ├── hypercube2.xcuserdatad
│ │ ├── xcdebugger
│ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ │ ├── HCLineChartView Sample.xcscheme
│ │ │ └── xcschememanagement.plist
│ │ └── vladimirdinic.xcuserdatad
│ │ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
└── HCLineChartView Sample
│ ├── AppDelegate
│ ├── AppDelegate.h
│ └── AppDelegate.m
│ ├── Interface
│ ├── Storyboards
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ ├── View Controllers
│ │ ├── ChartExampleSettingsViewController
│ │ │ ├── Chart Settings Cells
│ │ │ │ ├── SettingsColorCell
│ │ │ │ │ ├── SettingsColorCell.h
│ │ │ │ │ └── SettingsColorCell.m
│ │ │ │ ├── SettingsSliderCell
│ │ │ │ │ ├── SettingsSliderCell.h
│ │ │ │ │ └── SettingsSliderCell.m
│ │ │ │ ├── SettingsSwitchCell
│ │ │ │ │ ├── SettingsSwitchCell.h
│ │ │ │ │ └── SettingsSwitchCell.m
│ │ │ │ └── SettingsTextCell
│ │ │ │ │ ├── SettingsTextCell.h
│ │ │ │ │ └── SettingsTextCell.m
│ │ │ ├── ChartExampleSettingsViewController.h
│ │ │ └── ChartExampleSettingsViewController.m
│ │ └── ChartExampleViewController
│ │ │ ├── ChartExampleViewController.h
│ │ │ └── ChartExampleViewController.m
│ └── Xibs
│ │ ├── SettingsColorCell.xib
│ │ ├── SettingsSliderCell.xib
│ │ ├── SettingsSwitchCell.xib
│ │ └── SettingsTextCell.xib
│ ├── Libs
│ ├── HCChartSettings
│ │ ├── HCChartSettings.h
│ │ └── HCChartSettings.m
│ ├── RoundViewWithBorders
│ │ ├── RoundViewWithBorder.h
│ │ └── RoundViewWithBorder.m
│ └── iOS-Color-Picker
│ │ ├── FCColorPickerViewController.h
│ │ ├── FCColorPickerViewController.m
│ │ ├── FCColorPickerViewController.xib
│ │ ├── LICENSE
│ │ ├── Private
│ │ ├── FCBrightDarkGradView.h
│ │ ├── FCBrightDarkGradView.m
│ │ ├── FCColorSwatchView.h
│ │ └── FCColorSwatchView.m
│ │ └── Resources
│ │ └── colormap.png
│ └── Supporting Files
│ ├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-App-20x20@1x.png
│ │ ├── Icon-App-20x20@2x.png
│ │ ├── Icon-App-20x20@3x.png
│ │ ├── Icon-App-29x29@1x.png
│ │ ├── Icon-App-29x29@2x.png
│ │ ├── Icon-App-29x29@3x.png
│ │ ├── Icon-App-40x40@1x.png
│ │ ├── Icon-App-40x40@2x.png
│ │ ├── Icon-App-40x40@3x.png
│ │ ├── Icon-App-57x57@1x.png
│ │ ├── Icon-App-57x57@2x.png
│ │ ├── Icon-App-60x60@2x.png
│ │ ├── Icon-App-60x60@3x.png
│ │ ├── Icon-App-72x72@1x.png
│ │ ├── Icon-App-72x72@2x.png
│ │ ├── Icon-App-76x76@1x.png
│ │ ├── Icon-App-76x76@2x.png
│ │ ├── Icon-App-83.5x83.5@2x.png
│ │ ├── Icon-Small-50x50@1x.png
│ │ └── Icon-Small-50x50@2x.png
│ ├── Contents.json
│ ├── LaunchImage.launchimage
│ │ └── Contents.json
│ ├── hcLineChartLogo.imageset
│ │ ├── Contents.json
│ │ ├── hc_line_chart_logo.png
│ │ ├── hc_line_chart_logo@2x.png
│ │ └── hc_line_chart_logo@3x.png
│ ├── hcLineChartSplashLogo.imageset
│ │ ├── Contents.json
│ │ ├── SplashLogo.png
│ │ ├── SplashLogo@2x.png
│ │ └── SplashLogo@3x.png
│ └── hypercubeLogo.imageset
│ │ ├── Contents.json
│ │ ├── logo hc app @2x.png
│ │ ├── logo hc app @3x.png
│ │ └── logo hc app.png
│ ├── Info.plist
│ └── main.m
├── HCLineChartView.podspec
├── Images
├── HCLineChartView-Logo.png
└── Screenshots
│ ├── HCLineChartView-Screenshot-1.jpg
│ ├── HCLineChartView-Screenshot-2.jpg
│ ├── HCLineChartView-Screenshot-3.jpg
│ ├── HCLineChartView-Screenshot-4.jpg
│ ├── HCLineChartView-Screenshot-5.jpg
│ └── HCLineChartView-Storyboard-Screenshot.png
├── LICENSE
├── README.md
└── Source
└── HCLineChartView
├── HCChartDrawer
├── HCChartDrawer+Extensions
│ ├── HCChartDrawer+Axis
│ │ ├── HCChartDrawer+Axis.h
│ │ └── HCChartDrawer+Axis.m
│ ├── HCChartDrawer+Background
│ │ ├── HCChartDrawer+Background.h
│ │ └── HCChartDrawer+Background.m
│ ├── HCChartDrawer+CalculationAndPreparation
│ │ ├── HCChartDrawer+CalculationAndPreparation.h
│ │ └── HCChartDrawer+CalculationAndPreparation.m
│ ├── HCChartDrawer+ChartLine
│ │ ├── HCChartDrawer+ChartLine.h
│ │ └── HCChartDrawer+ChartLine.m
│ ├── HCChartDrawer+General
│ │ ├── HCChartDrawer+General.h
│ │ └── HCChartDrawer+General.m
│ ├── HCChartDrawer+Text
│ │ ├── HCChartDrawer+Text.h
│ │ └── HCChartDrawer+Text.m
│ └── HCChartDrawer+TitleAndSubtitle
│ │ ├── HCChartDrawer+TitleAndSubtitle.h
│ │ └── HCChartDrawer+TitleAndSubtitle.m
├── HCChartDrawer.h
└── HCChartDrawer.m
├── HCLineChartView.h
├── HCLineChartView.m
└── HCSupporting Files
├── HCChartPoint
├── HCChartPoint.h
└── HCChartPoint.m
├── HCEnums.h
└── HCTimeStep
├── HCTimeStep.h
└── HCTimeStep.m
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/project.xcworkspace/xcuserdata/hypercube2.xcuserdatad/IDEFindNavigatorScopes.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/project.xcworkspace/xcuserdata/hypercube2.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/project.xcworkspace/xcuserdata/hypercube2.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/project.xcworkspace/xcuserdata/hypercube2.xcuserdatad/xcdebugger/Expressions.xcexplist:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
8 |
10 |
11 |
12 |
13 |
15 |
16 |
18 |
19 |
21 |
22 |
24 |
25 |
26 |
27 |
29 |
30 |
32 |
33 |
35 |
36 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/xcuserdata/hypercube2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/xcuserdata/hypercube2.xcuserdatad/xcschemes/HCLineChartView Sample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
56 |
58 |
64 |
65 |
66 |
67 |
68 |
69 |
75 |
77 |
83 |
84 |
85 |
86 |
88 |
89 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/xcuserdata/hypercube2.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HCLineChartView Sample.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | A53DA62C1F613F3D0089CFF2
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/xcuserdata/vladimirdinic.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample.xcodeproj/xcuserdata/vladimirdinic.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HCLineChartView Demo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 | HCLineChartView Sample.xcscheme
13 |
14 | orderHint
15 | 0
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/AppDelegate/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/AppDelegate/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 |
21 | [self setStatusBarAppearance];
22 |
23 | return YES;
24 | }
25 |
26 | -(void)setStatusBarAppearance
27 | {
28 | [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
29 | [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
30 | [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
31 | }
32 |
33 |
34 | - (void)applicationWillResignActive:(UIApplication *)application {
35 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
36 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
37 | }
38 |
39 |
40 | - (void)applicationDidEnterBackground:(UIApplication *)application {
41 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
42 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
43 | }
44 |
45 |
46 | - (void)applicationWillEnterForeground:(UIApplication *)application {
47 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
48 | }
49 |
50 |
51 | - (void)applicationDidBecomeActive:(UIApplication *)application {
52 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
53 | }
54 |
55 |
56 | - (void)applicationWillTerminate:(UIApplication *)application {
57 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
58 | }
59 |
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/Storyboards/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsColorCell/SettingsColorCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsColorCell.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCColorPickerViewController.h"
11 |
12 | typedef void (^HCChartSettingsColorHandler) (UIColor* color);
13 |
14 | @interface SettingsColorCell : UITableViewCell
15 |
16 | @property HCChartSettingsColorHandler handler;
17 | @property (weak, nonatomic) IBOutlet UIView *cellColorView;
18 | @property (weak, nonatomic) IBOutlet UILabel *cellLabel;
19 |
20 | - (IBAction)cellChangeColor:(id)sender;
21 | -(void)updateWithLabelString:(NSString*)labelString color:(UIColor*)color andHandler:(HCChartSettingsColorHandler)handler;
22 |
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsColorCell/SettingsColorCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsColorCell.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "SettingsColorCell.h"
10 |
11 | @implementation SettingsColorCell
12 |
13 | - (void)awakeFromNib {
14 | [super awakeFromNib];
15 | // Initialization code
16 | }
17 |
18 | -(void)updateWithLabelString:(NSString*)labelString color:(UIColor*)color andHandler:(HCChartSettingsColorHandler)handler
19 | {
20 | [self.cellLabel setText:labelString];
21 | [self.cellColorView setBackgroundColor:color];
22 | self.handler = handler;
23 | }
24 |
25 | - (IBAction)cellChangeColor:(id)sender {
26 | FCColorPickerViewController *colorPicker = [FCColorPickerViewController colorPicker];
27 | colorPicker.color = self.cellColorView.backgroundColor;
28 | colorPicker.delegate = self;
29 |
30 | [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:colorPicker animated:YES completion:nil];
31 | }
32 |
33 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
34 | [super setSelected:selected animated:animated];
35 |
36 | // Configure the view for the selected state
37 | }
38 |
39 | #pragma mark FCColorPickerViewControllerDelegate methods
40 |
41 | -(void)colorPickerViewControllerDidCancel:(FCColorPickerViewController *)colorPicker
42 | {
43 | [[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissViewControllerAnimated:YES completion:^{
44 |
45 | }];
46 | }
47 |
48 | -(void)colorPickerViewController:(FCColorPickerViewController *)colorPicker didSelectColor:(UIColor *)color
49 | {
50 | [[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissViewControllerAnimated:YES completion:^{
51 |
52 | }];
53 | [self.cellColorView setBackgroundColor:color];
54 | self.handler(color);
55 | }
56 |
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsSliderCell/SettingsSliderCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsSliderCell.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef void (^HCChartSettingsValueHandler) (double value);
12 |
13 | @interface SettingsSliderCell : UITableViewCell
14 | @property (weak, nonatomic) IBOutlet UILabel *cellLabel;
15 | @property (weak, nonatomic) IBOutlet UISlider *cellSlider;
16 | @property HCChartSettingsValueHandler handler;
17 |
18 | - (IBAction)sliderValueChanged:(id)sender;
19 | -(void)updateWithLabelString:(NSString*)labelString value:(double)value maxValue:(double)maxValue minValue:(double)minValue andHandler:(HCChartSettingsValueHandler)handler;
20 |
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsSliderCell/SettingsSliderCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsSliderCell.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "SettingsSliderCell.h"
10 |
11 | @implementation SettingsSliderCell
12 |
13 | - (void)awakeFromNib {
14 | [super awakeFromNib];
15 | // Initialization code
16 | }
17 |
18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 | [super setSelected:selected animated:animated];
20 |
21 | // Configure the view for the selected state
22 | }
23 |
24 | -(void)updateWithLabelString:(NSString*)labelString value:(double)value maxValue:(double)maxValue minValue:(double)minValue andHandler:(HCChartSettingsValueHandler)handler
25 | {
26 | [self.cellLabel setText:labelString];
27 | [self.cellSlider setMinimumValue:minValue];
28 | [self.cellSlider setMaximumValue:maxValue];
29 | [self.cellSlider setValue:value];
30 | self.handler = handler;
31 | }
32 |
33 | - (IBAction)sliderValueChanged:(id)sender {
34 | self.handler(self.cellSlider.value);
35 | }
36 |
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsSwitchCell/SettingsSwitchCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsSwitchCell.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef void (^HCChartSettingsBoolHandler) (BOOL isOn);
12 |
13 | @interface SettingsSwitchCell : UITableViewCell
14 | @property (weak, nonatomic) IBOutlet UILabel *cellLabel;
15 | @property (weak, nonatomic) IBOutlet UISwitch *cellSwitch;
16 | @property HCChartSettingsBoolHandler handler;
17 |
18 | - (IBAction)changeSwitch:(id)sender;
19 | -(void)updateWithLabelString:(NSString*)labelString isOn:(BOOL)isOn andHandler:(HCChartSettingsBoolHandler)handler;
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsSwitchCell/SettingsSwitchCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsSwitchCell.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "SettingsSwitchCell.h"
10 |
11 | @implementation SettingsSwitchCell
12 |
13 | - (void)awakeFromNib {
14 | [super awakeFromNib];
15 | // Initialization code
16 | }
17 |
18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 | [super setSelected:selected animated:animated];
20 |
21 | // Configure the view for the selected state
22 | }
23 |
24 | -(void)updateWithLabelString:(NSString*)labelString isOn:(BOOL)isOn andHandler:(HCChartSettingsBoolHandler)handler
25 | {
26 | [self.cellLabel setText:labelString];
27 | [self.cellSwitch setOn:isOn];
28 | self.handler = handler;
29 | }
30 |
31 | - (IBAction)changeSwitch:(id)sender
32 | {
33 | self.handler(self.cellSwitch.isOn);
34 | }
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsTextCell/SettingsTextCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsCell.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef void (^HCChartSettingsTextHandler) (NSString* text);
12 |
13 | @interface SettingsTextCell : UITableViewCell
14 | @property (weak, nonatomic) IBOutlet UILabel *cellLabel;
15 | @property (weak, nonatomic) IBOutlet UITextField *cellTextField;
16 | @property HCChartSettingsTextHandler handler;
17 |
18 | -(void)updateWithLabelString:(NSString*)labelString textFieldPlaceholder:(NSString*)textFieldPlaceholder textFieldString:(NSString*)textFieldString andHandler:(HCChartSettingsTextHandler)handler;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/Chart Settings Cells/SettingsTextCell/SettingsTextCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // SettingsCell.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "SettingsTextCell.h"
10 |
11 | @implementation SettingsTextCell
12 |
13 | - (void)awakeFromNib {
14 | [super awakeFromNib];
15 | // Initialization code
16 | }
17 |
18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 | [super setSelected:selected animated:animated];
20 |
21 | // Configure the view for the selected state
22 | }
23 |
24 | -(void)updateWithLabelString:(NSString*)labelString textFieldPlaceholder:(NSString*)textFieldPlaceholder textFieldString:(NSString*)textFieldString andHandler:(HCChartSettingsTextHandler)handler;
25 | {
26 | [self.cellLabel setText:labelString];
27 | [self.cellTextField setPlaceholder:textFieldPlaceholder];
28 | [self.cellTextField setText:textFieldString];
29 | self.handler = handler;
30 | [self.cellTextField addTarget:self
31 | action:@selector(textFieldDidChange:)
32 | forControlEvents:UIControlEventEditingChanged];
33 | }
34 |
35 | -(void)textFieldDidChange:(UITextField*)textField
36 | {
37 | self.handler(textField.text);
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleSettingsViewController/ChartExampleSettingsViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ChartExampleSettingsViewController.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HCChartSettings.h"
11 |
12 | @interface ChartExampleSettingsViewController : UIViewController
13 |
14 | @property (retain, nonatomic) HCChartSettings* localChartSettings;
15 |
16 | @property (weak, nonatomic) IBOutlet UITableView *settingsTableView;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleViewController/ChartExampleViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // MyChart
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HCLineChartView.h"
11 | #import "HCChartSettings.h"
12 |
13 | @interface ChartExampleViewController : UIViewController
14 |
15 | @property (strong, nonatomic) IBOutlet HCLineChartView *hcLineChartView;
16 |
17 | - (IBAction)generateRandomChartDataWithDatesOnXAxis:(id)sender;
18 | - (IBAction)generateRandomChartDataWithNumbersOnXAxis:(id)sender;
19 |
20 | - (IBAction)generateRandomChartSettings:(id)sender;
21 | - (IBAction)changeChartSettings:(id)sender;
22 |
23 | @end
24 |
25 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/View Controllers/ChartExampleViewController/ChartExampleViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // MyChart
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "ChartExampleViewController.h"
10 |
11 | @interface ChartExampleViewController ()
12 |
13 | @end
14 |
15 | @implementation ChartExampleViewController
16 |
17 | #pragma mark Basic ChartExampleViewController methods
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view, typically from a nib.
22 | [self loadChartSettings];
23 | }
24 |
25 | - (void)didReceiveMemoryWarning {
26 | [super didReceiveMemoryWarning];
27 | // Dispose of any resources that can be recreated.
28 | }
29 |
30 | -(void)viewWillAppear:(BOOL)animated
31 | {
32 | [super viewWillAppear:animated];
33 | [self setNavigationBar];
34 | [self updateChartWithSettings];
35 | [self.hcLineChartView drawChart];
36 | }
37 |
38 | -(void)setNavigationBar
39 | {
40 | [self.navigationController.navigationBar setTranslucent:YES];
41 |
42 | UIButton *leftImageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 122, 25)];
43 | [leftImageButton setBackgroundImage:[UIImage imageNamed:@"hcLineChartLogo"] forState:UIControlStateNormal];
44 | [leftImageButton setUserInteractionEnabled:NO];
45 | UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageButton];
46 | self.navigationItem.leftBarButtonItem = leftBarButtonItem;
47 |
48 | UIButton *rightImageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 125, 25)];
49 | [rightImageButton setBackgroundImage:[UIImage imageNamed:@"hypercubeLogo"] forState:UIControlStateNormal];
50 | [rightImageButton addTarget:self action:@selector(openHypercubeSoftWebPage) forControlEvents:UIControlEventTouchUpInside];
51 | UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightImageButton];
52 | self.navigationItem.rightBarButtonItem = rightBarButtonItem;
53 |
54 | [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:10.0/255.0 green:146.0/255.0 blue:242.0/255.0 alpha:1.0]];
55 | }
56 |
57 | #pragma mark User interactions
58 |
59 | - (IBAction)changeChartSettings:(id)sender
60 | {
61 | [self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"ChartExampleSettingsViewController"] animated:YES];
62 | }
63 |
64 | - (IBAction)generateRandomChartDataWithDatesOnXAxis:(id)sender
65 | {
66 | [self addRandomDataWithDatesOnXAxis:YES];
67 | [self.hcLineChartView drawChart];
68 | }
69 |
70 | - (IBAction)generateRandomChartDataWithNumbersOnXAxis:(id)sender
71 | {
72 | [self addRandomDataWithDatesOnXAxis:NO];
73 | [self.hcLineChartView drawChart];
74 | }
75 |
76 | - (IBAction)generateRandomChartSettings:(id)sender
77 | {
78 | [self generateRandomSettingsAndRefresh];
79 | }
80 |
81 | -(void)openHypercubeSoftWebPage
82 | {
83 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hypercubesoft.com"] options:@{} completionHandler:NULL];
84 | }
85 |
86 | #pragma mark Handle chart data
87 |
88 | -(void)addRandomDataWithDatesOnXAxis:(BOOL)datesOnXAxis
89 | {
90 | [self.hcLineChartView.xElements removeAllObjects];
91 | [self.hcLineChartView.yElements removeAllObjects];
92 | double averageXValue = arc4random_uniform(10000000);
93 | double lastXValue = arc4random_uniform((int)averageXValue * 2) - averageXValue;
94 | double xValueMaxJump = arc4random_uniform(100000);
95 | int averageYValue = arc4random_uniform(10000);
96 | int lastYValue = arc4random_uniform(averageYValue * 2) - averageYValue;
97 | int numberOfElements = 1+arc4random_uniform(100);
98 |
99 | BOOL yValueIsDecimal = rand()%2;
100 | BOOL xValueIsDecimal = rand()%2;
101 |
102 | for (int i = 0 ; i < numberOfElements; i++)
103 | {
104 | if (datesOnXAxis)
105 | {
106 | [self.hcLineChartView.xElements addObject:[NSDate dateWithTimeIntervalSince1970:lastXValue + [[NSDate date] timeIntervalSince1970]]];
107 | lastXValue += 1 + arc4random_uniform(xValueMaxJump);
108 | }
109 | else
110 | {
111 | [self.hcLineChartView.xElements addObject:@(lastXValue / (xValueIsDecimal ? 1000000000.0 : 1.0))];
112 | lastXValue += 1 + arc4random_uniform(10 * (xValueIsDecimal ? 100000 : 1));
113 | }
114 | [self.hcLineChartView.yElements addObject:@(lastYValue / (yValueIsDecimal ? 1000000.0 : 1.0))];
115 | int rand = arc4random_uniform(1000);
116 | lastYValue += rand - 500;
117 | }
118 | }
119 |
120 |
121 |
122 | #pragma mark Handle chart settings
123 |
124 | -(void)loadChartSettings
125 | {
126 | [HCChartSettings sharedInstance].chartLineColor = self.hcLineChartView.chartLineColor;
127 | [HCChartSettings sharedInstance].chartLineWidth = self.hcLineChartView.chartLineWidth;
128 | [HCChartSettings sharedInstance].chartTitle = self.hcLineChartView.chartTitle;
129 | [HCChartSettings sharedInstance].chartSubTitle = self.hcLineChartView.chartSubTitle;
130 | [HCChartSettings sharedInstance].chartGradient = self.hcLineChartView.chartGradient;
131 | [HCChartSettings sharedInstance].chartWithRoundedCorners = self.hcLineChartView.chartWithRoundedCorners;
132 | [HCChartSettings sharedInstance].chartTransparentBackground = self.hcLineChartView.chartTransparentBackground;
133 | [HCChartSettings sharedInstance].chartLineWithCircles = self.hcLineChartView.chartLineWithCircles;
134 | [HCChartSettings sharedInstance].chartGradientUnderline = self.hcLineChartView.chartGradientUnderline;
135 | [HCChartSettings sharedInstance].chartTitleColor = self.hcLineChartView.chartTitleColor;
136 | [HCChartSettings sharedInstance].chartSubtitleColor = self.hcLineChartView.chartSubtitleColor;
137 | [HCChartSettings sharedInstance].chartAxisColor = self.hcLineChartView.chartAxisColor;
138 | [HCChartSettings sharedInstance].backgroundGradientTopColor = self.hcLineChartView.backgroundGradientTopColor;
139 | [HCChartSettings sharedInstance].backgroundGradientBottomColor = self.hcLineChartView.backgroundGradientBottomColor;
140 | [HCChartSettings sharedInstance].underLineChartGradientTopColor = self.hcLineChartView.underLineChartGradientTopColor;
141 | [HCChartSettings sharedInstance].underLineChartGradientBottomColor = self.hcLineChartView.underLineChartGradientBottomColor;
142 | [HCChartSettings sharedInstance].showSubtitle = self.hcLineChartView.showSubtitle;
143 | [HCChartSettings sharedInstance].isValueChartWithRealXAxisDistribution = self.hcLineChartView.isValueChartWithRealXAxisDistribution;
144 | [HCChartSettings sharedInstance].underLineChartGradientBottomColorIsTransparent = self.hcLineChartView.underLineChartGradientBottomColorIsTransparent;
145 | [HCChartSettings sharedInstance].showXValueAsCurrency = self.hcLineChartView.showXValueAsCurrency;
146 | [HCChartSettings sharedInstance].xAxisCurrencyCode = self.hcLineChartView.xAxisCurrencyCode;
147 | [HCChartSettings sharedInstance].showYValueAsCurrency = self.hcLineChartView.showYValueAsCurrency;
148 | [HCChartSettings sharedInstance].yAxisCurrencyCode = self.hcLineChartView.yAxisCurrencyCode;
149 | [HCChartSettings sharedInstance].horizontalValuesOnXAxis = self.hcLineChartView.horizontalValuesOnXAxis;
150 | [HCChartSettings sharedInstance].drawHorizontalLinesForYTicks = self.hcLineChartView.drawHorizontalLinesForYTicks;
151 | [HCChartSettings sharedInstance].fontSizeForTitle = self.hcLineChartView.fontSizeForTitle;
152 | [HCChartSettings sharedInstance].fontSizeForSubTitle = self.hcLineChartView.fontSizeForSubTitle;
153 | [HCChartSettings sharedInstance].fontSizeForAxis = self.hcLineChartView.fontSizeForAxis;
154 | }
155 |
156 | -(void)updateChartWithSettings
157 | {
158 | self.hcLineChartView.chartLineColor = [HCChartSettings sharedInstance].chartLineColor;
159 | self.hcLineChartView.chartLineWidth = [HCChartSettings sharedInstance].chartLineWidth;
160 | self.hcLineChartView.chartTitle = [HCChartSettings sharedInstance].chartTitle;
161 | self.hcLineChartView.chartSubTitle = [HCChartSettings sharedInstance].chartSubTitle;
162 | self.hcLineChartView.chartGradient = [HCChartSettings sharedInstance].chartGradient;
163 | self.hcLineChartView.chartWithRoundedCorners = [HCChartSettings sharedInstance].chartWithRoundedCorners;
164 | self.hcLineChartView.chartTransparentBackground = [HCChartSettings sharedInstance].chartTransparentBackground;
165 | self.hcLineChartView.chartLineWithCircles = [HCChartSettings sharedInstance].chartLineWithCircles;
166 | self.hcLineChartView.chartGradientUnderline = [HCChartSettings sharedInstance].chartGradientUnderline;
167 | self.hcLineChartView.chartTitleColor = [HCChartSettings sharedInstance].chartTitleColor;
168 | self.hcLineChartView.chartSubtitleColor = [HCChartSettings sharedInstance].chartSubtitleColor;
169 | self.hcLineChartView.chartAxisColor = [HCChartSettings sharedInstance].chartAxisColor;
170 | self.hcLineChartView.backgroundGradientTopColor = [HCChartSettings sharedInstance].backgroundGradientTopColor;
171 | self.hcLineChartView.backgroundGradientBottomColor = [HCChartSettings sharedInstance].backgroundGradientBottomColor;
172 | self.hcLineChartView.underLineChartGradientTopColor = [HCChartSettings sharedInstance].underLineChartGradientTopColor;
173 | self.hcLineChartView.underLineChartGradientBottomColor = [HCChartSettings sharedInstance].underLineChartGradientBottomColor;
174 | self.hcLineChartView.showSubtitle = [HCChartSettings sharedInstance].showSubtitle;
175 | self.hcLineChartView.isValueChartWithRealXAxisDistribution = [HCChartSettings sharedInstance].isValueChartWithRealXAxisDistribution;
176 | self.hcLineChartView.underLineChartGradientBottomColorIsTransparent = [HCChartSettings sharedInstance].underLineChartGradientBottomColorIsTransparent;
177 | self.hcLineChartView.showXValueAsCurrency = [HCChartSettings sharedInstance].showXValueAsCurrency;
178 | self.hcLineChartView.xAxisCurrencyCode = [HCChartSettings sharedInstance].xAxisCurrencyCode;
179 | self.hcLineChartView.showYValueAsCurrency = [HCChartSettings sharedInstance].showYValueAsCurrency;
180 | self.hcLineChartView.yAxisCurrencyCode = [HCChartSettings sharedInstance].yAxisCurrencyCode;
181 | self.hcLineChartView.horizontalValuesOnXAxis = [HCChartSettings sharedInstance].horizontalValuesOnXAxis;
182 | self.hcLineChartView.drawHorizontalLinesForYTicks = [HCChartSettings sharedInstance].drawHorizontalLinesForYTicks;
183 | self.hcLineChartView.fontSizeForTitle = [HCChartSettings sharedInstance].fontSizeForTitle;
184 | self.hcLineChartView.fontSizeForSubTitle = [HCChartSettings sharedInstance].fontSizeForSubTitle;
185 | self.hcLineChartView.fontSizeForAxis = [HCChartSettings sharedInstance].fontSizeForAxis;
186 | [self.hcLineChartView drawChart];
187 | }
188 |
189 | -(void)generateRandomSettingsAndRefresh
190 | {
191 | BOOL darkBackground = rand()%2;
192 | NSArray* currencyCodes = @[@"USD",@"EUR",@"GBP"];
193 | self.hcLineChartView.chartLineColor = darkBackground ? [self randomLightColor] : [self randomDarkColor];
194 | self.hcLineChartView.chartLineWidth = 1+arc4random_uniform(9);
195 | self.hcLineChartView.chartTitle = @"Chart title";
196 | self.hcLineChartView.chartSubTitle = @"Chart subtitle";
197 | self.hcLineChartView.chartGradient = rand()%2;
198 | self.hcLineChartView.chartWithRoundedCorners = rand()%2;
199 | self.hcLineChartView.chartTransparentBackground = darkBackground ? NO : arc4random_uniform(9) == 0;
200 | self.hcLineChartView.chartLineWithCircles = arc4random_uniform(5) == 0;
201 | self.hcLineChartView.chartGradientUnderline = rand()%2 == 0;
202 | self.hcLineChartView.chartTitleColor = darkBackground ? [self randomLightColor] : [self randomDarkColor];
203 | self.hcLineChartView.chartSubtitleColor = darkBackground ? [self randomLightColor] : [self randomDarkColor];
204 | self.hcLineChartView.chartAxisColor = darkBackground ? [self randomLightColor] : [self randomDarkColor];
205 | self.hcLineChartView.backgroundGradientTopColor = darkBackground ? [self randomDarkColor] : [self randomLightColor];
206 | self.hcLineChartView.backgroundGradientBottomColor = darkBackground ? [self randomDarkColor] : [self randomLightColor];
207 | self.hcLineChartView.underLineChartGradientTopColor = darkBackground ? [self randomDarkColor] : [self randomLightColor];
208 | self.hcLineChartView.underLineChartGradientBottomColor = darkBackground ? [self randomDarkColor] : [self randomLightColor];
209 | self.hcLineChartView.showSubtitle = rand()%2 ;
210 | self.hcLineChartView.isValueChartWithRealXAxisDistribution = rand()%2;
211 | self.hcLineChartView.underLineChartGradientBottomColorIsTransparent = rand()%2;
212 | self.hcLineChartView.showXValueAsCurrency = rand()%2;
213 | self.hcLineChartView.xAxisCurrencyCode = currencyCodes[rand()%3];
214 | self.hcLineChartView.showYValueAsCurrency = rand()%2;
215 | self.hcLineChartView.yAxisCurrencyCode = currencyCodes[rand()%3];
216 | self.hcLineChartView.horizontalValuesOnXAxis = rand()%2;
217 | self.hcLineChartView.drawHorizontalLinesForYTicks = rand()%2;
218 | self.hcLineChartView.fontSizeForTitle = 18+rand()%8;
219 | self.hcLineChartView.fontSizeForSubTitle = 12+rand()%6;
220 | self.hcLineChartView.fontSizeForAxis = 8+rand()%4;
221 | [self loadChartSettings];
222 | [self.hcLineChartView drawChart];
223 | }
224 |
225 | #pragma mark Help methods for chart settings
226 |
227 | -(UIColor*)randomDarkColor
228 | {
229 | return [UIColor colorWithRed:(arc4random_uniform(127))/255.0 green:(arc4random_uniform(127))/255.0 blue:(arc4random_uniform(127))/255.0 alpha:1.0];;
230 | }
231 |
232 | -(UIColor*)randomLightColor
233 | {
234 | return [UIColor colorWithRed:(128.0+arc4random_uniform(127))/255.0 green:(128.0+arc4random_uniform(127))/255.0 blue:(128.0+arc4random_uniform(127))/255.0 alpha:1.0];
235 | }
236 |
237 |
238 | @end
239 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/Xibs/SettingsColorCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/Xibs/SettingsSliderCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/Xibs/SettingsSwitchCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Interface/Xibs/SettingsTextCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/HCChartSettings/HCChartSettings.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartSettings.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | /// Helper class for storing basic chart settings
12 | @interface HCChartSettings : NSObject
13 |
14 | #pragma mark Chart Background Settings
15 |
16 | /// This property defines if chart background is transparent or not.
17 | @property IBInspectable BOOL chartTransparentBackground;
18 |
19 | /// This property defines if chart background has the gradient.
20 | @property IBInspectable BOOL chartGradient;
21 |
22 | /// This property defines the top color for background gradient. It is also the background color for the chart if chartGradient is set to NO.
23 | @property (retain, nonatomic) IBInspectable UIColor* backgroundGradientTopColor;
24 |
25 | /// This property defines the bottom color for background gradient.
26 | @property (retain, nonatomic) IBInspectable UIColor* backgroundGradientBottomColor;
27 |
28 | /// This property defines if chart view should have rounder corners.
29 | @property IBInspectable BOOL chartWithRoundedCorners;
30 |
31 | #pragma mark Title and Subtitle Settings
32 |
33 | /// This property defines chart title.
34 | @property (retain, nonatomic) IBInspectable NSString* chartTitle;
35 |
36 | /// This property defines chart title color.
37 | @property (retain, nonatomic) IBInspectable UIColor* chartTitleColor;
38 |
39 | /// This property defines font size for chart title.
40 | @property IBInspectable double fontSizeForTitle;
41 |
42 | /// This property defines if the chart has a subtitle.
43 | @property IBInspectable BOOL showSubtitle;
44 |
45 | /// This property defines chart subtitle.
46 | @property (retain, nonatomic) IBInspectable NSString* chartSubTitle;
47 |
48 | /// This property defines font size for chart subtitle.
49 | @property IBInspectable double fontSizeForSubTitle;
50 |
51 | /// This property defines chart subtitle color.
52 | @property (retain, nonatomic) IBInspectable UIColor* chartSubtitleColor;
53 |
54 | #pragma mark Chart Axis Settings
55 |
56 | /// This property defines chart axes color.
57 | @property (retain, nonatomic) IBInspectable UIColor* chartAxisColor;
58 |
59 | /// This property defines font size for chart axes.
60 | @property IBInspectable double fontSizeForAxis;
61 |
62 | /// This property defines if values on the X axis should be in currency format. It is useful in cases where we need to show exchange rate on chart
63 | @property IBInspectable BOOL showXValueAsCurrency;
64 |
65 | /// This property defines currency code for the X axis. It is relevant if showXValueAsCurrency parameter is set to YES. If you don't define currency code or currency code is not valid, the chart will display your local currency code.
66 | @property (retain, nonatomic) NSString* xAxisCurrencyCode;
67 |
68 | /// This property defines if values on the Y axis should be in currency format. It is useful when we need to show exchange rate on the chart (if showXValueAsCurrency is also set to YES), or in any other case where we need to show Y values in currency format (price, saving, debt, surplus, deficit,...)
69 | @property IBInspectable BOOL showYValueAsCurrency;
70 |
71 | /// This property defines currency code for the Y axis. It is relevant if showYValueAsCurrency parameter is set to YES. If you don't define currency code or currency code is not valid, the chart will display your local currency code.
72 | @property (retain, nonatomic) NSString* yAxisCurrencyCode;
73 |
74 | /// This property defines if chart should have horizontal dashed lines for every Y tick
75 | @property IBInspectable BOOL drawHorizontalLinesForYTicks;
76 |
77 | /// This property defines if values on this axis should have horizontal orientation (default orientation is vertical)
78 | @property IBInspectable BOOL horizontalValuesOnXAxis;
79 |
80 | #pragma mark Chart Line Settings
81 |
82 | /// This property defines chart line width.
83 | @property IBInspectable float chartLineWidth;
84 |
85 | /// This property defines chart line color.
86 | @property (retain, nonatomic) IBInspectable UIColor* chartLineColor;
87 |
88 | /// This property defines if chart points should have circles
89 | @property IBInspectable BOOL chartLineWithCircles;
90 |
91 | /// This property defines if the area under chart line should have gradient
92 | @property IBInspectable BOOL chartGradientUnderline;
93 |
94 | /// This property defines the background color or top gradient color for the area under chart line.
95 | @property (retain, nonatomic) IBInspectable UIColor* underLineChartGradientTopColor;
96 |
97 | /// This property defines if bottom gradient color for area under chart line is transparent.
98 | @property IBInspectable BOOL underLineChartGradientBottomColorIsTransparent;
99 |
100 | /// This property defines bottom gradient color for the area under chart line.
101 | @property (retain, nonatomic) IBInspectable UIColor* underLineChartGradientBottomColor;
102 |
103 | /// This property defines if the distribution of values on X axis should be value based.
104 | @property IBInspectable BOOL isValueChartWithRealXAxisDistribution;
105 |
106 | #pragma mark HCCHartSettings Methods
107 |
108 | /// This method returns shared (singleton) instance of this class
109 | /// @return Shared (singleton) instance of this class
110 | + (HCChartSettings*) sharedInstance;
111 |
112 | //Update chart with new settings
113 | /// @param settings New settings for settings instance
114 | -(void)updateWithSettings:(HCChartSettings*)settings;
115 |
116 | @end
117 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/HCChartSettings/HCChartSettings.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartSettings.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartSettings.h"
10 |
11 | static HCChartSettings *instance=nil;
12 |
13 | @implementation HCChartSettings
14 |
15 | + (HCChartSettings*) sharedInstance
16 | {
17 | @synchronized(self) {
18 | if (instance == nil)
19 | {
20 | instance = [[HCChartSettings alloc] init];
21 | }
22 | }
23 | return instance;
24 | }
25 |
26 | + (void)setSharedSettings:(HCChartSettings*)settings
27 | {
28 | instance = settings;
29 | }
30 |
31 | -(void)updateWithSettings:(HCChartSettings*)settings
32 | {
33 | self.chartLineColor = settings.chartLineColor;
34 | self.chartLineWidth = settings.chartLineWidth;
35 | self.chartTitle = settings.chartTitle;
36 | self.chartSubTitle = settings.chartSubTitle;
37 | self.chartGradient = settings.chartGradient;
38 | self.chartWithRoundedCorners = settings.chartWithRoundedCorners;
39 | self.chartTransparentBackground = settings.chartTransparentBackground;
40 | self.chartLineWithCircles = settings.chartLineWithCircles;
41 | self.chartGradientUnderline = settings.chartGradientUnderline;
42 | self.chartTitleColor = settings.chartTitleColor;
43 | self.chartSubtitleColor = settings.chartSubtitleColor;
44 | self.chartAxisColor = settings.chartAxisColor;
45 | self.backgroundGradientTopColor = settings.backgroundGradientTopColor;
46 | self.backgroundGradientBottomColor = settings.backgroundGradientBottomColor;
47 | self.underLineChartGradientTopColor = settings.underLineChartGradientTopColor;
48 | self.underLineChartGradientBottomColor = settings.underLineChartGradientBottomColor;
49 | self.showSubtitle = settings.showSubtitle;
50 | self.isValueChartWithRealXAxisDistribution = settings.isValueChartWithRealXAxisDistribution;
51 | self.underLineChartGradientBottomColorIsTransparent = settings.underLineChartGradientBottomColorIsTransparent;
52 | self.showXValueAsCurrency = settings.showXValueAsCurrency;
53 | self.xAxisCurrencyCode = settings.xAxisCurrencyCode;
54 | self.showYValueAsCurrency = settings.showYValueAsCurrency;
55 | self.yAxisCurrencyCode = settings.yAxisCurrencyCode;
56 | self.horizontalValuesOnXAxis = settings.horizontalValuesOnXAxis;
57 | self.drawHorizontalLinesForYTicks = settings.drawHorizontalLinesForYTicks;
58 | self.fontSizeForTitle = settings.fontSizeForTitle;
59 | self.fontSizeForSubTitle = settings.fontSizeForSubTitle;
60 | self.fontSizeForAxis = settings.fontSizeForAxis;
61 | }
62 |
63 | -(id)copy
64 | {
65 | HCChartSettings* chartSettings = [HCChartSettings new];
66 | chartSettings.chartLineColor = self.chartLineColor;
67 | chartSettings.chartLineWidth = self.chartLineWidth;
68 | chartSettings.chartTitle = self.chartTitle;
69 | chartSettings.chartSubTitle = self.chartSubTitle;
70 | chartSettings.chartGradient = self.chartGradient;
71 | chartSettings.chartWithRoundedCorners = self.chartWithRoundedCorners;
72 | chartSettings.chartTransparentBackground = self.chartTransparentBackground;
73 | chartSettings.chartLineWithCircles = self.chartLineWithCircles;
74 | chartSettings.chartGradientUnderline = self.chartGradientUnderline;
75 | chartSettings.chartTitleColor = self.chartTitleColor;
76 | chartSettings.chartSubtitleColor = self.chartSubtitleColor;
77 | chartSettings.chartAxisColor = self.chartAxisColor;
78 | chartSettings.backgroundGradientTopColor = self.backgroundGradientTopColor;
79 | chartSettings.backgroundGradientBottomColor = self.backgroundGradientBottomColor;
80 | chartSettings.underLineChartGradientTopColor = self.underLineChartGradientTopColor;
81 | chartSettings.underLineChartGradientBottomColor = self.underLineChartGradientBottomColor;
82 | chartSettings.showSubtitle = self.showSubtitle;
83 | chartSettings.isValueChartWithRealXAxisDistribution = self.isValueChartWithRealXAxisDistribution;
84 | chartSettings.underLineChartGradientBottomColorIsTransparent = self.underLineChartGradientBottomColorIsTransparent;
85 | chartSettings.showXValueAsCurrency = self.showXValueAsCurrency;
86 | chartSettings.xAxisCurrencyCode = self.xAxisCurrencyCode;
87 | chartSettings.showYValueAsCurrency = self.showYValueAsCurrency;
88 | chartSettings.yAxisCurrencyCode = self.yAxisCurrencyCode;
89 | chartSettings.horizontalValuesOnXAxis = self.horizontalValuesOnXAxis;
90 | chartSettings.drawHorizontalLinesForYTicks = self.drawHorizontalLinesForYTicks;
91 | chartSettings.fontSizeForTitle = self.fontSizeForTitle;
92 | chartSettings.fontSizeForSubTitle = self.fontSizeForSubTitle;
93 | chartSettings.fontSizeForAxis = self.fontSizeForAxis;
94 | return chartSettings;
95 | }
96 |
97 | @end
98 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/RoundViewWithBorders/RoundViewWithBorder.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewWithBorder.h
3 | // PromotionalFinance
4 | //
5 | // Created by Lazar Djordjevic on 8/31/15.
6 | // Copyright (c) 2015 Lazar Djordjevic. All rights reserved.
7 | //
8 |
9 | #import
10 | IB_DESIGNABLE
11 |
12 | @interface RoundViewWithBorder : UIView
13 |
14 | @property (nonatomic) IBInspectable UIColor* borderIBColor;
15 | @property IBInspectable float thickness;
16 | @property IBInspectable float cornerRadius;
17 | @property CALayer* leftLayer;
18 | @property CALayer* topLayer;
19 | @property CALayer* bottomLayer;
20 | @property CALayer* rightLayer;
21 |
22 | - (void)drawBorder;
23 |
24 | @end
25 |
26 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/RoundViewWithBorders/RoundViewWithBorder.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewWithBorder.m
3 | // PromotionalFinance
4 | //
5 | // Created by Lazar Djordjevic on 8/31/15.
6 | // Copyright (c) 2015 Lazar Djordjevic. All rights reserved.
7 | //
8 |
9 | #import "RoundViewWithBorder.h"
10 |
11 |
12 | @implementation RoundViewWithBorder
13 |
14 |
15 | - (instancetype)initWithFrame:(CGRect)frame
16 | {
17 | self = [super initWithFrame:frame];
18 | if (self) {
19 | self.thickness = 1.0f;
20 | self.borderIBColor = [UIColor blackColor];
21 | }
22 | return self;
23 | }
24 |
25 | - (id)initWithCoder:(NSCoder *)aDecoder {
26 | if ((self = [super initWithCoder:aDecoder])) {
27 | self.thickness = 1.05f;
28 | self.borderIBColor = [UIColor blackColor];
29 | [self performSelector:@selector(drawBorder) withObject:nil afterDelay:0.0];
30 | }
31 | return self;
32 | }
33 |
34 | - (void)drawBorder
35 | {
36 | self.layer.cornerRadius = self.cornerRadius;
37 | self.layer.masksToBounds = YES;
38 | self.layer.borderColor = self.borderIBColor.CGColor;
39 | self.layer.borderWidth = self.thickness;
40 | }
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/FCColorPickerViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ColorPickerViewController.h
3 | // ColorPicker
4 | //
5 | // Created by Fabián Cañas
6 | // Based on work by Gilly Dekel on 23/3/09
7 | // Copyright 2010-2014. All rights reserved.
8 | //
9 |
10 | #import
11 |
12 | NS_ASSUME_NONNULL_BEGIN
13 |
14 | /**
15 | `FCColorPickerViewController` is a view controller that displays a color picker to the user.
16 |
17 | To use it, instantiate a `FCColorPickerViewController` with one of the class constructors, set a delegate that
18 | implements the `FCColorPickerViewControllerDelegate` protocol, and present the color picker however you wish,
19 | *e.g.* modally full screen, modally in a form, in a popover, etc. You are responsible for dismissing the color
20 | picker when the user finishes picking a color. The delegate methods in the `FCColorPickerViewControllerDelegate`
21 | protocol and the `color` property of the color picker provide a reference to the color the user picked.
22 | */
23 | @class FCColorPickerViewController, FCBrightDarkGradView, FCColorSwatchView;
24 |
25 | /**
26 | The delegate of an `FCColorPickerViewController` must adopt the `FCColorPickerViewControllerDelegate` protocol.
27 |
28 | The primary responsibility of the delegate is hiding or dismissing the picker controller when the picker has finished.
29 | The delegate is the object that is told which color the picker picked.
30 | */
31 | @protocol FCColorPickerViewControllerDelegate
32 |
33 | /**
34 | Called on the delegate of `colorPicker` when the user has finished selecting a color.
35 |
36 | @param colorPicker The `FCColorPickerViewController` that has finished picking a color.
37 | @param color The color that was picked by the user.
38 | */
39 | - (void)colorPickerViewController:(FCColorPickerViewController *)colorPicker didSelectColor:(UIColor *)color;
40 |
41 | /**
42 | Called on the delegate of `colorPicker` when the user has canceled selecting a color.
43 |
44 | @param colorPicker The `FCColorPickerViewController` that has canceled picking a color.
45 | */
46 | - (void)colorPickerViewControllerDidCancel:(FCColorPickerViewController *)colorPicker;
47 |
48 | @end
49 |
50 | @interface FCColorPickerViewController : UIViewController
51 |
52 | /// @name Initializing a Color Picker object
53 |
54 | /**
55 | Creates and returns a color picker.
56 | */
57 | + (nonnull instancetype)colorPicker;
58 |
59 | /**
60 | Creates and returns a color picker initialized with the provided color and delegate.
61 | @paran color The initial value for the color picker's `color` property. The color picker will represent this color when presented.
62 | @param delegate An object implementing the `FCColorPickerViewControllerDelegate` protocol to act as the picker's delegate
63 | @see -color,
64 | @see -delegate
65 | */
66 | + (instancetype)colorPickerWithColor:(nullable UIColor *)color delegate:(nullable id) delegate;
67 |
68 | /// @name The Color
69 |
70 | /**
71 | The color that the picker is representing.
72 |
73 | Its value changes as the user interacts with the picker, and changing the property will update the UI accordingly.
74 | */
75 | @property (readwrite, nonatomic, copy, nullable) UIColor *color;
76 |
77 | /// @name Managing the Delegate
78 |
79 | /**
80 | The object that acts as the delegate of the receiving color picker.
81 |
82 | The delegate must adopt the `FCColorPickerViewControllerDelegate` protocol. The delegate is not retained.
83 |
84 | @see FCColorPickerViewControllerDelegate protocol
85 | */
86 | @property (nonatomic, weak, nullable) id delegate;
87 |
88 | /// @name Controlling the Color Picker's Appearance
89 |
90 | /**
91 | The view controller's background color.
92 |
93 | The default value is nil, which results in a dark gray color on iPhones, and a clear color on iPads.
94 | @see -tintColor
95 | */
96 | @property (nonatomic, copy, nullable) UIColor *backgroundColor;
97 |
98 | /**
99 | The view controller's tint color.
100 |
101 | Updates to the `tintColor` property are forwarded to the color picker's view. The tint color affects the coloring of the "Choose" and "Cancel" buttons in iOS 7. Below iOS 7, this property has no effect.
102 | `tintColor` is initially derived from the view hierarchy in the normal way for views iOS 7+. Setting this property to `nil` restores this behavior.
103 | @see -backgroundColor
104 | */
105 | @property (nonatomic, copy, null_resettable) UIColor *tintColor;
106 |
107 | @end
108 |
109 | NS_ASSUME_NONNULL_END
110 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/FCColorPickerViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ColorPickerViewController.m
3 | // ColorPicker
4 | //
5 | // Created by Fabián Cañas
6 | // Based on work by Gilly Dekel on 23/3/09
7 | // Copyright 2010-2014. All rights reserved.
8 | //
9 |
10 | #import "FCColorPickerViewController.h"
11 | #import "FCBrightDarkGradView.h"
12 | #import "FCColorSwatchView.h"
13 |
14 | @interface FCColorPickerViewController () {
15 | CGFloat currentBrightness;
16 | CGFloat currentHue;
17 | CGFloat currentSaturation;
18 | BOOL viewIsLoaded;
19 | UIColor *_tintColor;
20 | }
21 |
22 | @property (readwrite, nonatomic, strong) IBOutlet FCBrightDarkGradView *gradientView;
23 | @property (readwrite, nonatomic, strong) IBOutlet UIImageView *hueSatImage;
24 | @property (readwrite, nonatomic, strong) IBOutlet UIView *crossHairs;
25 | @property (readwrite, nonatomic, strong) IBOutlet UIView *brightnessBar;
26 | @property (readwrite, nonatomic, strong) IBOutlet FCColorSwatchView *swatch;
27 |
28 | - (IBAction) chooseSelectedColor;
29 | - (IBAction) cancelColorSelection;
30 |
31 | @end
32 |
33 | @implementation FCColorPickerViewController
34 |
35 | + (instancetype)colorPicker {
36 | return [[self alloc] initWithNibName:@"FCColorPickerViewController" bundle:nil];
37 | }
38 |
39 | + (instancetype)colorPickerWithColor:(UIColor *)color delegate:(id) delegate {
40 | FCColorPickerViewController *picker = [self colorPicker];
41 | picker.color = color;
42 | picker.delegate = delegate;
43 | return picker;
44 | }
45 |
46 | - (void)viewDidLoad {
47 | [super viewDidLoad];
48 | [self.view bringSubviewToFront:_crossHairs];
49 | [self.view bringSubviewToFront:_brightnessBar];
50 | viewIsLoaded = YES;
51 |
52 | UIColor *edgeColor = [UIColor colorWithWhite:0.9 alpha:0.8];
53 |
54 | self.crossHairs.layer.cornerRadius = 19;
55 | self.crossHairs.layer.borderColor = edgeColor.CGColor;
56 | self.crossHairs.layer.borderWidth = 2;
57 | self.crossHairs.layer.shadowColor = [UIColor blackColor].CGColor;
58 | self.crossHairs.layer.shadowOffset = CGSizeZero;
59 | self.crossHairs.layer.shadowRadius = 1;
60 | self.crossHairs.layer.shadowOpacity = 0.5;
61 |
62 | self.brightnessBar.layer.cornerRadius = 9;
63 | self.brightnessBar.layer.borderColor = edgeColor.CGColor;
64 | self.brightnessBar.layer.borderWidth = 2;
65 | }
66 |
67 | - (void)viewWillAppear:(BOOL)animated {
68 | [super viewWillAppear:animated];
69 | [self setColor:_color];
70 | [self updateBrightnessPosition];
71 | [self updateGradientColor];
72 | [self updateCrosshairPosition];
73 | _swatch.color = _color;
74 | self.tintColor = self.tintColor;
75 | self.backgroundColor = self.backgroundColor;
76 | }
77 |
78 | - (void)viewWillLayoutSubviews {
79 | [self updateBrightnessPosition];
80 | [self updateCrosshairPosition];
81 | }
82 |
83 | #pragma mark - Appearance
84 |
85 | - (void)setTintColor:(UIColor *)tintColor
86 | {
87 | _tintColor = [tintColor copy];
88 | if (!viewIsLoaded) {
89 | return;
90 | }
91 | if ([self.view respondsToSelector:@selector(setTintColor:)]) {
92 | [self.view setTintColor:self.tintColor];
93 | }
94 | }
95 |
96 | - (UIColor *)tintColor
97 | {
98 | if (_tintColor) {
99 | return _tintColor;
100 | }
101 | return self.view.tintColor;
102 | }
103 |
104 | #pragma mark - Color Manipulation
105 |
106 | - (void)_setColor:(UIColor *)newColor {
107 | if (![_color isEqual:newColor]) {
108 |
109 | CGFloat brightness;
110 | [newColor getHue:NULL saturation:NULL brightness:&brightness alpha:NULL];
111 | CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(CGColorGetColorSpace(newColor.CGColor));
112 | if (colorSpaceModel==kCGColorSpaceModelMonochrome) {
113 | const CGFloat *c = CGColorGetComponents(newColor.CGColor);
114 | _color = [UIColor colorWithHue:0
115 | saturation:0
116 | brightness:c[0]
117 | alpha:1.0];
118 | } else {
119 | _color = [newColor copy];
120 | }
121 |
122 | _swatch.color = _color;
123 | }
124 | }
125 |
126 | - (void)setColor:(UIColor *)newColor {
127 |
128 | CGFloat hue, saturation;
129 | [newColor getHue:&hue saturation:&saturation brightness:NULL alpha:NULL];
130 |
131 | currentHue = hue;
132 | currentSaturation = saturation;
133 | [self _setColor:newColor];
134 | [self updateGradientColor];
135 | [self updateBrightnessPosition];
136 | [self updateCrosshairPosition];
137 | }
138 |
139 | - (void)updateBrightnessPosition {
140 | [_color getHue:NULL saturation:NULL brightness:¤tBrightness alpha:NULL];
141 |
142 | CGPoint brightnessPosition;
143 | brightnessPosition.x = (1.0-currentBrightness)*_gradientView.frame.size.width + _gradientView.frame.origin.x;
144 | brightnessPosition.y = _gradientView.center.y;
145 | _brightnessBar.center = brightnessPosition;
146 | }
147 |
148 | - (void)updateCrosshairPosition {
149 | CGPoint hueSatPosition;
150 |
151 | hueSatPosition.x = (currentHue*_hueSatImage.frame.size.width)+_hueSatImage.frame.origin.x;
152 | hueSatPosition.y = (1.0-currentSaturation)*_hueSatImage.frame.size.height+_hueSatImage.frame.origin.y;
153 |
154 | _crossHairs.center = hueSatPosition;
155 | [self updateGradientColor];
156 | }
157 |
158 | - (void)updateGradientColor {
159 | UIColor *gradientColor = [UIColor colorWithHue: currentHue
160 | saturation: currentSaturation
161 | brightness: 1.0
162 | alpha:1.0];
163 |
164 | _brightnessBar.layer.backgroundColor = _color.CGColor;
165 | _crossHairs.layer.backgroundColor = gradientColor.CGColor;
166 |
167 | [_gradientView setColor:gradientColor];
168 | }
169 |
170 | - (void)updateHueSatWithMovement:(CGPoint) position {
171 |
172 | currentHue = (position.x-_hueSatImage.frame.origin.x)/_hueSatImage.frame.size.width;
173 | currentSaturation = 1.0 - (position.y-_hueSatImage.frame.origin.y)/_hueSatImage.frame.size.height;
174 |
175 | UIColor *_tcolor = [UIColor colorWithHue:currentHue
176 | saturation:currentSaturation
177 | brightness:currentBrightness
178 | alpha:1.0];
179 | UIColor *gradientColor = [UIColor colorWithHue: currentHue
180 | saturation: currentSaturation
181 | brightness: 1.0
182 | alpha:1.0];
183 |
184 |
185 | _crossHairs.layer.backgroundColor = gradientColor.CGColor;
186 | [self updateGradientColor];
187 |
188 | [self _setColor:_tcolor];
189 |
190 | _swatch.color = _color;
191 | _brightnessBar.layer.backgroundColor = _color.CGColor;
192 | }
193 |
194 | - (void)updateBrightnessWithMovement:(CGPoint) position {
195 |
196 | currentBrightness = 1.0 - ((position.x - _gradientView.frame.origin.x)/_gradientView.frame.size.width) ;
197 |
198 | UIColor *_tcolor = [UIColor colorWithHue:currentHue
199 | saturation:currentSaturation
200 | brightness:currentBrightness
201 | alpha:1.0];
202 | [self _setColor:_tcolor];
203 |
204 | _brightnessBar.layer.backgroundColor = _color.CGColor;
205 | _swatch.color = _color;
206 | }
207 |
208 | #pragma mark - Touch Handling
209 |
210 | // Handles the start of a touch
211 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
212 | for (UITouch *touch in touches) {
213 | [self dispatchTouchEvent:[touch locationInView:self.view]];
214 | }
215 | }
216 |
217 | // Handles the continuation of a touch.
218 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
219 | for (UITouch *touch in touches){
220 | [self dispatchTouchEvent:[touch locationInView:self.view]];
221 | }
222 | }
223 |
224 | - (void)dispatchTouchEvent:(CGPoint)position {
225 | if (CGRectContainsPoint(_hueSatImage.frame,position)) {
226 | _crossHairs.center = position;
227 | [self updateHueSatWithMovement:position];
228 | } else if (CGRectContainsPoint(_gradientView.frame, position)) {
229 | _brightnessBar.center = CGPointMake(position.x, _gradientView.center.y);
230 | [self updateBrightnessWithMovement:position];
231 | }
232 | }
233 |
234 | #pragma mark - IBActions
235 |
236 | - (IBAction)chooseSelectedColor {
237 | [_delegate colorPickerViewController:self didSelectColor:self.color];
238 | }
239 |
240 | - (IBAction)cancelColorSelection {
241 | [_delegate colorPickerViewControllerDidCancel:self];
242 | }
243 |
244 | @end
245 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/FCColorPickerViewController.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
44 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Fabian Canas
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/Private/FCBrightDarkGradView.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCBrightDarkGradView.h
3 | // ColorPicker
4 | //
5 | // Created by Fabián Cañas
6 | // Copyright 2010-2014. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FCBrightDarkGradView : UIView
12 |
13 | @property (readwrite,nonatomic,copy) UIColor *color;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/Private/FCBrightDarkGradView.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCBrightDarkGradView.h
3 | // ColorPicker
4 | //
5 | // Created by Fabián Cañas
6 | // Copyright 2010-2014. All rights reserved.
7 | //
8 |
9 | #import "FCBrightDarkGradView.h"
10 |
11 | @interface FCBrightDarkGradView () {
12 | CGGradientRef gradient;
13 | }
14 |
15 | @end
16 |
17 | @implementation FCBrightDarkGradView
18 |
19 | -(void)setColor:(UIColor *)color {
20 | if (_color != color) {
21 | _color = [color copy];
22 | [self setupGradient];
23 | [self setNeedsDisplay];
24 | }
25 | }
26 |
27 | - (void)setupGradient {
28 | // Create a color equivalent to the current color with brightness maximized
29 | const CGFloat *c = CGColorGetComponents([_color CGColor]);
30 | CGFloat colors[] =
31 | {
32 | c[0],c[1],c[2],1.0,
33 | 0.0/255.0,0.0/255.0,0.0/255.0,1.0, // black
34 | };
35 |
36 | CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
37 |
38 | if (gradient!=nil) {
39 | CGGradientRelease(gradient);
40 | }
41 | gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
42 | CGColorSpaceRelease(rgb);
43 | }
44 |
45 | - (void)drawRect:(CGRect)rect {
46 | CGContextRef context = UIGraphicsGetCurrentContext();
47 |
48 | // The clipping rects we plan to use, which also defines the locations of each gradient
49 | CGRect clippingRect = CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height);
50 |
51 | CGPoint endPoints[] =
52 | {
53 | CGPointMake(0,0),
54 | CGPointMake(self.frame.size.width,0),
55 | };
56 |
57 | // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
58 | // so that we can revert to the previous larger area.
59 | CGContextSaveGState(context);
60 | CGContextClipToRect(context, clippingRect);
61 |
62 | CGContextDrawLinearGradient(context, gradient, endPoints[0], endPoints[1], 0);
63 | CGContextRestoreGState(context);
64 | }
65 |
66 | - (void)dealloc {
67 | CGGradientRelease(gradient);
68 | }
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/Private/FCColorSwatchView.h:
--------------------------------------------------------------------------------
1 | //
2 | // ColorSwatchView.h
3 | // ColorPicker
4 | //
5 | // Created by Fabián Cañas on 9/9/10.
6 | // Copyright 2010-2014 Fabián Cañas. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FCColorSwatchView : UIView
12 |
13 | @property (readwrite, copy, nonatomic) UIColor *color;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/Private/FCColorSwatchView.m:
--------------------------------------------------------------------------------
1 | //
2 | // ColorSwatchView.m
3 | // ColorPicker
4 | //
5 | // Created by Fabián Cañas on 9/9/10.
6 | // Copyright 2010-2014 Fabián Cañas. All rights reserved.
7 | //
8 |
9 | #import "FCColorSwatchView.h"
10 | #import
11 |
12 | @implementation FCColorSwatchView
13 |
14 | -(id)initWithCoder:(NSCoder *)aDecoder {
15 | self = [super initWithCoder:aDecoder];
16 | if (self) {
17 | [self setupLayers];
18 | }
19 | return self;
20 | }
21 |
22 | -(void)setupLayers {
23 | CALayer *layer = self.layer;
24 | UIColor *edgeColor = [UIColor colorWithWhite:0.9 alpha:0.8];
25 | [layer setBackgroundColor:self.color.CGColor];
26 | [layer setCornerRadius:7];
27 | [layer setBorderWidth:2.0f];
28 | [layer setBorderColor:edgeColor.CGColor];
29 | }
30 |
31 | -(void)setColor:(UIColor *)swatchColor {
32 | if (_color != swatchColor) {
33 | _color = [swatchColor copy];
34 | [self.layer setBackgroundColor:_color.CGColor];
35 | }
36 | }
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/Resources/colormap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Libs/iOS-Color-Picker/Resources/colormap.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "57x57",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-57x57@1x.png",
49 | "scale" : "1x"
50 | },
51 | {
52 | "size" : "57x57",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-57x57@2x.png",
55 | "scale" : "2x"
56 | },
57 | {
58 | "size" : "60x60",
59 | "idiom" : "iphone",
60 | "filename" : "Icon-App-60x60@2x.png",
61 | "scale" : "2x"
62 | },
63 | {
64 | "size" : "60x60",
65 | "idiom" : "iphone",
66 | "filename" : "Icon-App-60x60@3x.png",
67 | "scale" : "3x"
68 | },
69 | {
70 | "size" : "20x20",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-20x20@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "20x20",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-20x20@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "29x29",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-29x29@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "29x29",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-29x29@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "40x40",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-40x40@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "40x40",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-40x40@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "50x50",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-Small-50x50@1x.png",
109 | "scale" : "1x"
110 | },
111 | {
112 | "size" : "50x50",
113 | "idiom" : "ipad",
114 | "filename" : "Icon-Small-50x50@2x.png",
115 | "scale" : "2x"
116 | },
117 | {
118 | "size" : "72x72",
119 | "idiom" : "ipad",
120 | "filename" : "Icon-App-72x72@1x.png",
121 | "scale" : "1x"
122 | },
123 | {
124 | "size" : "72x72",
125 | "idiom" : "ipad",
126 | "filename" : "Icon-App-72x72@2x.png",
127 | "scale" : "2x"
128 | },
129 | {
130 | "size" : "76x76",
131 | "idiom" : "ipad",
132 | "filename" : "Icon-App-76x76@1x.png",
133 | "scale" : "1x"
134 | },
135 | {
136 | "size" : "76x76",
137 | "idiom" : "ipad",
138 | "filename" : "Icon-App-76x76@2x.png",
139 | "scale" : "2x"
140 | },
141 | {
142 | "size" : "83.5x83.5",
143 | "idiom" : "ipad",
144 | "filename" : "Icon-App-83.5x83.5@2x.png",
145 | "scale" : "2x"
146 | },
147 | {
148 | "idiom" : "ios-marketing",
149 | "size" : "1024x1024",
150 | "scale" : "1x"
151 | }
152 | ],
153 | "info" : {
154 | "version" : 1,
155 | "author" : "xcode"
156 | }
157 | }
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@1x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "ipad",
6 | "extent" : "full-screen",
7 | "minimum-system-version" : "7.0",
8 | "scale" : "1x"
9 | },
10 | {
11 | "orientation" : "landscape",
12 | "idiom" : "ipad",
13 | "extent" : "full-screen",
14 | "minimum-system-version" : "7.0",
15 | "scale" : "1x"
16 | },
17 | {
18 | "orientation" : "portrait",
19 | "idiom" : "ipad",
20 | "extent" : "full-screen",
21 | "minimum-system-version" : "7.0",
22 | "scale" : "2x"
23 | },
24 | {
25 | "orientation" : "landscape",
26 | "idiom" : "ipad",
27 | "extent" : "full-screen",
28 | "minimum-system-version" : "7.0",
29 | "scale" : "2x"
30 | }
31 | ],
32 | "info" : {
33 | "version" : 1,
34 | "author" : "xcode"
35 | }
36 | }
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "hc_line_chart_logo.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "hc_line_chart_logo@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "hc_line_chart_logo@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/hc_line_chart_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/hc_line_chart_logo.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/hc_line_chart_logo@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/hc_line_chart_logo@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/hc_line_chart_logo@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartLogo.imageset/hc_line_chart_logo@3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "SplashLogo.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "SplashLogo@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "SplashLogo@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/SplashLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/SplashLogo.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/SplashLogo@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/SplashLogo@2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/SplashLogo@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hcLineChartSplashLogo.imageset/SplashLogo@3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "logo hc app.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "logo hc app @2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "logo hc app @3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/logo hc app @2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/logo hc app @2x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/logo hc app @3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/logo hc app @3x.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/logo hc app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Assets.xcassets/hypercubeLogo.imageset/logo hc app.png
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIcons
10 |
11 | CFBundleIcons~ipad
12 |
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | $(PRODUCT_NAME)
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | 1.0
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIMainStoryboardFile
30 | Main
31 | UIRequiredDeviceCapabilities
32 |
33 | armv7
34 |
35 | UIRequiresFullScreen
36 |
37 | UIStatusBarStyle
38 | UIStatusBarStyleLightContent
39 | UISupportedInterfaceOrientations
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationLandscapeLeft
43 | UIInterfaceOrientationLandscapeRight
44 |
45 | UISupportedInterfaceOrientations~ipad
46 |
47 | UIInterfaceOrientationPortrait
48 | UIInterfaceOrientationPortraitUpsideDown
49 | UIInterfaceOrientationLandscapeLeft
50 | UIInterfaceOrientationLandscapeRight
51 |
52 | UIViewControllerBasedStatusBarAppearance
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/HCLineChartView Sample/HCLineChartView Sample/Supporting Files/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/HCLineChartView.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 |
3 | s.platform = :ios
4 | s.name = "HCLineChartView"
5 | s.version = "1.0.2"
6 | s.summary = "HCLineChartView is an iOS library for drawing line charts."
7 |
8 | s.description = <<-DESC
9 | HCLineChartView is a beautiful iOS library which makes it super fast and easy to create and customize line charts.
10 | DESC
11 |
12 | s.homepage = "https://github.com/Hypercubesoft/HCLineChartView"
13 | s.license = { :type => "MIT", :file => "LICENSE" }
14 | s.author = { "Hypercubesoft" => "office@hypercubesoft.com" }
15 | s.source = { :git => "https://github.com/Hypercubesoft/HCLineChartView.git", :tag => "#{s.version}"}
16 |
17 | s.ios.deployment_target = "8.0"
18 | s.source_files = "Source/HCLineChartView", "Source/HCLineChartView/**/*"
19 |
20 | end
21 |
--------------------------------------------------------------------------------
/Images/HCLineChartView-Logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/HCLineChartView-Logo.png
--------------------------------------------------------------------------------
/Images/Screenshots/HCLineChartView-Screenshot-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/Screenshots/HCLineChartView-Screenshot-1.jpg
--------------------------------------------------------------------------------
/Images/Screenshots/HCLineChartView-Screenshot-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/Screenshots/HCLineChartView-Screenshot-2.jpg
--------------------------------------------------------------------------------
/Images/Screenshots/HCLineChartView-Screenshot-3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/Screenshots/HCLineChartView-Screenshot-3.jpg
--------------------------------------------------------------------------------
/Images/Screenshots/HCLineChartView-Screenshot-4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/Screenshots/HCLineChartView-Screenshot-4.jpg
--------------------------------------------------------------------------------
/Images/Screenshots/HCLineChartView-Screenshot-5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/Screenshots/HCLineChartView-Screenshot-5.jpg
--------------------------------------------------------------------------------
/Images/Screenshots/HCLineChartView-Storyboard-Screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hypercubesoft/HCLineChartView/fa5ec4a9e222102e4b15367cc22252e1555ac17d/Images/Screenshots/HCLineChartView-Storyboard-Screenshot.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Hypercube
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [](http://cocoapods.org/pods/HCLineChartView)
3 | [](http://cocoapods.org/pods/HCLineChartView)
4 | [](http://cocoapods.org/pods/HCLineChartView)
5 | 
6 |
7 | 
8 |
9 | **HCLineChartView** is a beautiful iOS library which makes it super fast and easy to create and customize line charts.
10 |
11 | With this library, you can fully customize how your line chart looks. It’s easy to setup and use in any iOS project. It supports chart settings directly from interface builder with live preview. Automatic redrawing on orientation change will make it easy for an application that has portrait and landscape layout.
12 |
13 | Take a look at the sample app for examples and usage.
14 |
15 | ## Examples of usage:
16 |
17 | HCLineChartView makes it easy to customize line chart settings and appearance. There are some examples:
18 |
19 | 
20 | 
21 | 
22 | 
23 | 
24 |
25 | ## Features:
26 | * Easy to set up
27 | * Easy to customize line chart settings and appearance, i.e. to set up line chart attributes (title, subtitle, colors, gradients, chart line or axis width, font size, ...) directly in interface builder with live preview or from code.
28 | * Easy to set or change chart data and reload the chart
29 | * Automatic detecting if values on the X axis are numerical values or date/time values. Also, it checks if values on the X axis and Y axis are valid.
30 | * Automatic calculating positions and values for ticks for both axes based on chart data and chart frame.
31 | * Automatic redrawing on orientation change events, without distortions.
32 |
33 | ## Installing
34 |
35 | ### Podfile
36 |
37 | [CocoaPods](https://cocoapods.org/) is a dependency manager for Objective-C and Swift, which automates and simplifies the process of using 3rd-party libraries like HCLineChartView in your projects.
38 | To integrate **HCLineChartView** into your Xcode project using CocoaPods, specify it in your Podfile:
39 |
40 | ```Ruby
41 | target '' do
42 | use_frameworks!
43 | pod 'HCLineChartView'
44 | end
45 | ```
46 |
47 | Then, run the following command:
48 |
49 | ```
50 | $ pod install
51 | ```
52 |
53 | ### With source code
54 |
55 | If you prefer not to use CocoaPods as a dependency manager, you can integrate HCLineChartView into your project manually. Just download repository and include Source/HCLineChartView folder into your project.
56 |
57 | ## Usage
58 |
59 | 1. Add HCLineChartView library to your project via CocoaPods or manually.
60 |
**Note**: HCLineChartView is a library written in Objective-C, but it can also be added to Swift projects using [Bridging Header](https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html).
61 | 2. Include HCLineChartView library where it is needed. If you have installed this library using Podfile, include it using directive:
62 |
63 | ```objective-c
64 | #include
65 | ```
66 | If you have manually added this library to your project, include it using:
67 | ```objective-c
68 | #import "HCLineChartView.h"
69 | ```
70 |
71 | 3. Place a UIView into your .storyboard or .xib file and define HCLineChartView as its class:
72 |
73 | 
74 |
75 | Also, create the outlet for this HCLineChartView in the appropriate file.
76 |
77 | ```objective-c
78 | @property (strong, nonatomic) IBOutlet HCLineChartView *hcLineChartView;
79 | ```
80 | You can also add this view from code, like any other view:
81 |
82 | ```objective-c
83 | HCLineChartView* hcLineChartView = [[HCLineChartView alloc] initWithFrame:CGRectMake(100, 100, 300, 300)];
84 | [self.view addSubview: hcLineChartView];
85 | ```
86 |
87 | 5. If you want to change line chart appearance and basic settings, you can setup chart settings in Interface Builder or from code. You don't have to change these parameters. In that case, the chart will be drawn with default settings. If you still want to customize the chart, you can change multiple attributes (title, subtitle, colors, corner radius, ...) directly from the storyboard or xib file. Also, you can change desired properties directly from the code, like in the following example:
88 |
89 | ```objective-c
90 | self.hcLineChartView.chartTitle = @"Revenue over time";
91 | self.hcLineChartView.chartTitleColor = [UIColor yellowColor];
92 | self.hcLineChartView.showSubtitle = NO;
93 | self.hcLineChartView.chartGradient = YES;
94 | self.hcLineChartView.backgroundGradientTopColor = [UIColor colorWithRed:0.0 green:0.5 blue:0.5 alpha:1.0];
95 | self.hcLineChartView.backgroundGradientBottomColor = [UIColor colorWithRed:0.0 green:0.3 blue:0.3 alpha:1.0];
96 | self.hcLineChartView.chartLineColor = [UIColor yellowColor];
97 | self.hcLineChartView.chartAxisColor = [UIColor yellowColor];
98 | self.hcLineChartView.chartGradientUnderline = YES;
99 | self.hcLineChartView.underLineChartGradientTopColor = [UIColor yellowColor];
100 | self.hcLineChartView.underLineChartGradientBottomColor = [UIColor orangeColor];
101 | ```
102 | You can set all other parameters in the same way.
103 | 5. Setup or update chart data:
104 |
105 | ```objective-c
106 | self.hcLineChartView.xElements = [[NSMutableArray alloc] initWithObjects:@(10),@(20),@(25),@(30),@(40),@(45),@(60),@(65),@(70),@(75),@(80),@(85),@(100),@(120),@(125),@(130),@(145),@(150),@(155),@(165),@(175),@(185),@(195),@(200), nil];
107 | self.hcLineChartView.yElements = [[NSMutableArray alloc] initWithObjects:@(210),@(222),@(212),@(216),@(232),@(247),@(262),@(261),@(276),@(274),@(281),@(288),@(290),@(283),@(242),@(250),@(270),@(265),@(260),@(262),@(277),@(272),@(281),@(289), nil];
108 | ```
109 | If you want to show time on the X axis, you should populate ```xElements``` array with NSDate instances, like in this example:
110 | ```objective-c
111 | self.hcLineChartView.xElements = [[NSMutableArray alloc] initWithObjects:
112 | [NSDate dateWithTimeIntervalSince1970:1504785810],
113 | [NSDate dateWithTimeIntervalSince1970:1504795873],
114 | [NSDate dateWithTimeIntervalSince1970:1504805270],
115 | [NSDate dateWithTimeIntervalSince1970:1504815840],
116 | [NSDate dateWithTimeIntervalSince1970:1504825810],
117 | [NSDate dateWithTimeIntervalSince1970:1504835873],
118 | [NSDate dateWithTimeIntervalSince1970:1504845270],
119 | [NSDate dateWithTimeIntervalSince1970:1504855840], NULL];
120 | ```
121 |
122 | 6. Draw/redraw the chart.
After changing the attributes or after updating chart data, you have to redraw the chart:
123 |
124 | ```objective-c
125 | [self.hcLineChartView drawChart];
126 | ```
127 | Also, if you want to update chart data and redraw the chart, you can use updateChartWithData method:
128 |
129 | ```objective-c
130 | NSMutableArray* xElements = [[NSMutableArray alloc] initWithObjects:@(10),@(20),@(25),@(30),@(40),@(45),@(60),@(65),@(70),@(75),@(80),@(85),@(100),@(120),@(125),@(130),@(145),@(150),@(155),@(165),@(175),@(185),@(195),@(200), nil];
131 | NSMutableArray* yElements = [[NSMutableArray alloc] initWithObjects:@(210),@(222),@(212),@(216),@(232),@(247),@(262),@(261),@(276),@(274),@(281),@(288),@(290),@(283),@(242),@(250),@(270),@(265),@(260),@(262),@(277),@(272),@(281),@(289), nil];
132 | [self.hcLineChartView updateChartWithXElements:xElements yElements:yElements];
133 | ```
134 |
135 | In any case, you can download and run HCLineChartView Sample project from this repository. In this project, there is an example of usage where you can find out how to use this library.
136 |
137 | ## Short preview of HCLineChartView basic parameters and methods
138 |
139 | For the better understanding how to use those parameters and methods, here is the short overview of basic HCLineChartView attributes and methods which you can use to setup chart.
140 |
141 | ### HCLineChartView basic attributes
142 |
143 | #### Chart Background Settings
144 | ```objective-c
145 | /// This property defines if chart background is transparent or not.
146 | @property IBInspectable BOOL chartTransparentBackground;
147 |
148 | /// This property defines if chart background has the gradient.
149 | @property IBInspectable BOOL chartGradient;
150 |
151 | /// This property defines the top color for background gradient. It is also the background color for the chart if chartGradient is set to NO.
152 | @property (retain, nonatomic) IBInspectable UIColor* backgroundGradientTopColor;
153 |
154 | /// This property defines the bottom color for background gradient.
155 | @property (retain, nonatomic) IBInspectable UIColor* backgroundGradientBottomColor;
156 |
157 | /// This property defines if chart view should have rounded corners.
158 | @property IBInspectable BOOL chartWithRoundedCorners;
159 | ```
160 |
161 | #### Title and Subtitle Settings
162 | ```objective-c
163 | @property (retain, nonatomic) IBInspectable NSString* chartTitle;
164 |
165 | /// This property defines chart title color.
166 | @property (retain, nonatomic) IBInspectable UIColor* chartTitleColor;
167 |
168 | /// This property defines font size for chart title.
169 | @property IBInspectable double fontSizeForTitle;
170 |
171 | /// This property defines if the chart has a subtitle.
172 | @property IBInspectable BOOL showSubtitle;
173 |
174 | /// This property defines chart subtitle.
175 | @property (retain, nonatomic) IBInspectable NSString* chartSubTitle;
176 |
177 | /// This property defines font size for chart subtitle.
178 | @property IBInspectable double fontSizeForSubTitle;
179 |
180 | /// This property defines chart subtitle color.
181 | @property (retain, nonatomic) IBInspectable UIColor* chartSubtitleColor;
182 | ```
183 |
184 | #### Chart Axis Settings
185 |
186 | ```objective-c
187 | /// This property defines chart axes color.
188 | @property (retain, nonatomic) IBInspectable UIColor* chartAxisColor;
189 |
190 | /// This property defines font size for chart axes.
191 | @property IBInspectable double fontSizeForAxis;
192 |
193 | /// This property defines if values on the X axis should be in currency format. It is useful in cases where we need to show exchange rate on chart
194 | @property IBInspectable BOOL showXValueAsCurrency;
195 |
196 | /// TThis property defines currency code for the X axis. It is relevant if showXValueAsCurrency parameter is set to YES. If you don't define currency code or currency code is not valid, the chart will display your local currency code.
197 | @property (retain, nonatomic) IBInspectable NSString* xAxisCurrencyCode;
198 |
199 | /// This property defines if values on the Y axis should be in currency format. It is useful when we need to show exchange rate on the chart (if showXValueAsCurrency is also set to YES), or in any other case where we need to show Y values in currency format (price, saving, debt, surplus, deficit,...)
200 | @property IBInspectable BOOL showYValueAsCurrency;
201 |
202 | /// This property defines currency code for the Y axis. It is relevant if showYValueAsCurrency parameter is set to YES. If you don't define currency code or currency code is not valid, the chart will display your local currency code.
203 | @property (retain, nonatomic) IBInspectable NSString* yAxisCurrencyCode;
204 |
205 | /// This property defines if values on X axis should be presented horizontally (vertically is default).
206 | @property IBInspectable BOOL horizontalValuesOnXAxis;
207 |
208 | /// This property defines if values on this axis should have horizontal orientation (default orientation is vertical)
209 | @property IBInspectable BOOL drawHorizontalLinesForYTicks;
210 | ```
211 |
212 | #### HCLineChartView Settings
213 | ```objective-c
214 | /// This property defines chart line width.
215 | @property IBInspectable float chartLineWidth;
216 |
217 | /// This property defines chart line color.
218 | @property (retain, nonatomic) IBInspectable UIColor* chartLineColor;
219 |
220 | /// This property defines if chart points should have circles
221 | @property IBInspectable BOOL chartLineWithCircles;
222 |
223 | /// This property defines if the area under chart line should have gradient
224 | @property IBInspectable BOOL chartGradientUnderline;
225 |
226 | /// This property defines if bottom gradient color for the area under chart line is transparent.
227 | @property (retain, nonatomic) IBInspectable UIColor* underLineChartGradientTopColor;
228 |
229 | /// This property defines if bottom gradient color for the area under chart line is transparent.
230 | @property IBInspectable BOOL underLineChartGradientBottomColorIsTransparent;
231 |
232 | /// This property defines bottom gradient color for the area under chart line. This parameter is valid only if chart itself isn't transparent
233 | @property (retain, nonatomic) IBInspectable UIColor* underLineChartGradientBottomColor;
234 |
235 | /// This property defines if the distribution of values on X axis should be value based.
236 | @property IBInspectable BOOL isValueChartWithRealXAxisDistribution;
237 | ```
238 |
239 | #### HCLineChartView Data
240 | ```objective-c
241 | /// It is recommended to provide already sorted data before drawing the chart. If you don't have values for X axis sorted ascending, you can set this parameter to YES. In that case, provided values for X axis (xElements) will be sorted ascending, with the parallel sorting of paired values for Y axis (yElements). Sorting data could have a small impact on chart drawing performance.
242 | @property IBInspectable BOOL sortData;
243 |
244 | /// Array for storing values for the X axis. Only NSNumber and NSDate values are allowed.
245 | @property (retain, nonatomic) NSMutableArray* xElements;
246 |
247 | /// Array for storing values for the Y axis. Only NSNumber values are allowed.
248 | @property (retain, nonatomic) NSMutableArray* yElements;
249 | ```
250 | By changing these arrays you actually change chart rate data.
251 |
252 | ### HCLineChartView Methods
253 | #### Drawing and Updating Methods
254 | ```objective-c
255 | /// Draws/redraws chart with current data and settings.
256 | -(void)drawChart;
257 |
258 | /// Updates chart with new data
259 | /// @param xElements Values for X axis.
260 | /// @param yElements Values for Y axis.
261 | -(void)updateChartWithXElements:(NSArray*)xElements yElements:(NSArray*)yElements;
262 | ```
263 |
264 | ## Notes
265 | * Parameter should have reasonable values. For example. ```chartWithCircles``` parameter should be set to YES only when you have small amount of data. If you have big amount of data, those circles will overlap. Also, ```chartLineWidth``` shouldn't be too big. The same goes for the others.
266 | * It's obvious that some attributes turn off some others. For example, if *showSubtitle* is set to NO the subtitle will be hidden, whatever text you set as a *chartSubTitle*. Also, for example, if you set transparent background, you'll not see background gradient, even if you set it.
267 | * Only NSNumber or NSDate values are allowed for X axis and only NSNumber values for Y axis.
268 | * Provided values for X axis should be in ascending order. If they aren't or you want to be sure that they are sorted ascending, you should set sortData parameter to YES.
269 | * You should set a bigger frame for your HCLineChartView, i.e. big enough to draw chart line, both axes, and other elements. Minimal frame depends on chart settings (font size, chart data, the orientation of values on X axis (horizontal or vertical),...).
270 |
271 |
272 | If you find any bug, please report it, and we will try to fix it ASAP. Also, any suggestion is welcome.
273 |
274 | ## Credits
275 |
276 | **HCLineChartView** is owned and maintained by the [Hypercube](http://hypercubesoft.com/).
277 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+Axis/HCChartDrawer+Axis.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Axis.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (Axis)
12 |
13 | /// This method is used for preparation and drawing X and Y axis
14 | -(void)drawBothAxises;
15 |
16 | /// This method draws horizontal lines for Y ticks
17 | -(void)drawHorizontalLinesForYTicks;
18 |
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+Background/HCChartDrawer+Background.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Background.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (Background)
12 |
13 | /// Draws chart background
14 | -(void)drawBackground;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+Background/HCChartDrawer+Background.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Background.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer+Background.h"
10 |
11 | @implementation HCChartDrawer (Background)
12 |
13 | #pragma mark Draw background methods
14 |
15 | -(void)drawBackground
16 | {
17 | [hcLineChartView setBackgroundColor:[UIColor clearColor]];
18 | if (!hcLineChartView.chartTransparentBackground)
19 | {
20 | CGContextRef context = UIGraphicsGetCurrentContext();
21 | CGContextSaveGState(context);
22 | CGContextClearRect(context, chartRect);
23 | CGContextSetFillColorWithColor(context, hcLineChartView.backgroundGradientTopColor.CGColor);
24 | NSArray *colors = @[(__bridge id) hcLineChartView.backgroundGradientTopColor.CGColor, (__bridge id) (hcLineChartView.chartGradient ? hcLineChartView.backgroundGradientBottomColor.CGColor : hcLineChartView.backgroundGradientTopColor.CGColor)];
25 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
26 | CGFloat locations[] = { 0.0, 1.0 };
27 | CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
28 | CGPoint startPoint = CGPointMake(CGRectGetMidX(chartRect), CGRectGetMinY(chartRect));
29 | CGPoint endPoint = CGPointMake(CGRectGetMidX(chartRect), CGRectGetMaxY(chartRect));
30 | UIBezierPath* backgroundRoundedRectPath = [UIBezierPath bezierPathWithRoundedRect:chartRect cornerRadius:chartCornerRadius];
31 | [backgroundRoundedRectPath fill];
32 | [backgroundRoundedRectPath addClip];
33 | CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
34 | CGContextRestoreGState(context);
35 | [hcLineChartView setOpaque:NO];
36 | [hcLineChartView.layer setOpaque:NO];
37 | [hcLineChartView.layer setCornerRadius:chartCornerRadius];
38 | [hcLineChartView setClipsToBounds:YES];
39 | [hcLineChartView.layer setMasksToBounds:YES];
40 | }
41 | }
42 |
43 |
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+CalculationAndPreparation/HCChartDrawer+CalculationAndPreparation.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Preparation.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (CalculationAndPreparation)
12 |
13 | /// Performs all calculations and preparations required for chart drawing
14 | - (void)prepareChartForDrawing;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+ChartLine/HCChartDrawer+ChartLine.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+ChartLine.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (ChartLine)
12 |
13 | /// Draws chart line
14 | -(void)drawChartLine;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+ChartLine/HCChartDrawer+ChartLine.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+ChartLine.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer+ChartLine.h"
10 | #import "HCChartDrawer+CalculationAndPreparation.h"
11 | #import "HCChartDrawer+General.h"
12 |
13 | @implementation HCChartDrawer (ChartLine)
14 |
15 | #pragma mark Draw chart line and chart dots
16 |
17 | /// Draws chart line
18 | -(void)drawChartLine
19 | {
20 | if (numberOfElements > 0)
21 | {
22 | [self drawPoints];
23 | }
24 | }
25 |
26 | /// This is the method for drawing the chart line, the most important part of the chart
27 | -(void)drawPoints
28 | {
29 | if (numberOfElements > 1)
30 | {
31 | if (hcLineChartView.chartGradientUnderline)
32 | {
33 | if ((hcLineChartView.chartTransparentBackground && !hcLineChartView.underLineChartGradientBottomColorIsTransparent) || !hcLineChartView.chartTransparentBackground)
34 | {
35 | [self drawGradientUnderChartLine];
36 | if (!hcLineChartView.chartTransparentBackground)
37 | {
38 | [self hideGradientBorders];
39 | }
40 | }
41 | }
42 | [self drawLinesAndDots];
43 | }
44 | else
45 | {
46 | CGPoint chartSingleCenterPoint = CGPointMake(chartRect.size.width * (pointsRectLeftProportionalDistance + pointsRectProportionalWidth / 2.0) - chartPointDiameter / 2.0, chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight / 2.0) - chartPointDiameter / 2.0);
47 | if (hcLineChartView.chartLineWithCircles)
48 | {
49 | [self drawChartPointAtPositionInside:chartSingleCenterPoint];
50 | [self drawChartPointAtPositionOutside:chartSingleCenterPoint];
51 | }
52 | else
53 | {
54 | [self drawLineFromPoint:chartSingleCenterPoint toPoint:chartSingleCenterPoint withColor:hcLineChartView.chartLineColor andWidth:hcLineChartView.chartLineWidth];
55 | }
56 | }
57 | }
58 |
59 |
60 | /// This method is used for drawing lines and dots
61 | -(void)drawLinesAndDots
62 | {
63 | if (chartStyle == chartLineWithCircles)
64 | {
65 | for (int i=0; i < numberOfElements - 1; i++)
66 | {
67 | [self drawLineFromPoint: [((NSValue*)[startDots objectAtIndex:i]) CGPointValue] toPoint:[((NSValue*)[endDots objectAtIndex:i]) CGPointValue] withColor:hcLineChartView.chartLineColor andWidth:hcLineChartView.chartLineWidth];
68 | }
69 | for (int i=0 ; i < numberOfElements ; i++)
70 | {
71 | HCChartPoint* HCChartPointt = (HCChartPoint*)[chartDots objectAtIndex:i];
72 | [self drawChartPointAtPositionOutside:CGPointMake(HCChartPointt.x, HCChartPointt.y)];
73 | }
74 | }
75 | else if (chartStyle == chartWithoutCircles)
76 | {
77 | for (int i=0; i < numberOfElements - 1; i++)
78 | {
79 | [self drawLineFromPoint: [((NSValue*)[middleDots objectAtIndex:i]) CGPointValue] toPoint:[((NSValue*)[middleDots objectAtIndex:i + 1]) CGPointValue] withColor:hcLineChartView.chartLineColor andWidth:hcLineChartView.chartLineWidth];
80 | }
81 | }
82 | }
83 |
84 | /// This method creates small circle, i.e. BezierPath (which is used for appending with gradientPath, in this case)
85 | /// @param position Position for drawing the chart circle, as a part of Bezier path which will be attached to the basic chart gradient area Bezier path
86 | /// @return Bezier path, i.e. circle which represents chart point
87 | -(UIBezierPath*)drawChartPointAtPositionInside:(CGPoint)position
88 | {
89 | CGRect rect = CGRectMake(position.x - chartPointDiameter/2.0, position.y - chartPointDiameter/2.0, chartPointDiameter, chartPointDiameter);
90 | CGRect rectInside = CGRectMake(rect.origin.x + hcLineChartView.chartLineWidth, rect.origin.y + hcLineChartView.chartLineWidth, chartPointDiameter - 2.0 * hcLineChartView.chartLineWidth, chartPointDiameter - 2.0 * hcLineChartView.chartLineWidth);
91 | UIBezierPath* circlePath = [UIBezierPath bezierPathWithOvalInRect:rectInside];
92 | return circlePath;
93 | }
94 |
95 | /// This method is used for drawing circle at specific position
96 | /// @param position Position for drawing the border around the circle which represents chart point
97 | -(void)drawChartPointAtPositionOutside:(CGPoint)position
98 | {
99 | CGContextRef ctx= UIGraphicsGetCurrentContext();
100 | CGRect bounds = [hcLineChartView bounds];
101 | CGPoint center;
102 | center.x = bounds.origin.x + bounds.size.width / 2.0;
103 | center.y = bounds.origin.y + bounds.size.height / 2.0;
104 | CGContextSaveGState(ctx);
105 | CGContextSetLineWidth(ctx,hcLineChartView.chartLineWidth);
106 | NSArray* components = [self colorComponents:hcLineChartView.chartLineColor];
107 | CGFloat red = [components objectAtIndex:0].floatValue;
108 | CGFloat green = [components objectAtIndex:1].floatValue;
109 | CGFloat blue = [components objectAtIndex:2].floatValue;
110 | CGFloat alpha = [components objectAtIndex:3].floatValue;
111 | CGContextSetRGBStrokeColor(ctx,red,green,blue,alpha);
112 | CGContextAddArc(ctx,position.x,position.y, (chartPointDiameter - hcLineChartView.chartLineWidth) / 2.0 ,0.0,M_PI*2,YES);
113 | CGContextStrokePath(ctx);
114 | }
115 |
116 |
117 | #pragma mark Draw gradient under chart line
118 |
119 | /// This method draws gradient under the chart line
120 | -(void)drawGradientUnderChartLine
121 | {
122 | CGContextRef context = UIGraphicsGetCurrentContext();
123 | CGContextSaveGState(context);
124 | CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
125 | UIBezierPath *aPath = [UIBezierPath bezierPath];
126 | NSArray *colors = @[(__bridge id) hcLineChartView.underLineChartGradientTopColor.CGColor, (__bridge id) (hcLineChartView.underLineChartGradientBottomColorIsTransparent ? (hcLineChartView.chartGradient ? [self bottomColorForUnderLineAreaFromGradient] : hcLineChartView.backgroundGradientTopColor) : hcLineChartView.underLineChartGradientBottomColor).CGColor];
127 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
128 | CGFloat locations[] = { 0.0, 1.0 };
129 | CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
130 | int numberOfPoints = 0;
131 | if (chartStyle == chartLineWithCircles)
132 | {
133 | while (numberOfPoints < numberOfElements - 1) {
134 | CGPoint startPoint = [[startDots objectAtIndex:numberOfPoints] CGPointValue];
135 | CGPoint endPoint = [[endDots objectAtIndex:numberOfPoints] CGPointValue];
136 | if (numberOfPoints == 0)
137 | {
138 | [aPath moveToPoint:CGPointMake(startPoint.x-1, startPoint.y)];
139 | [aPath addLineToPoint:startPoint];
140 | }
141 | if (numberOfPoints > 0)
142 | {
143 | [aPath addLineToPoint:startPoint];
144 | }
145 | if (numberOfPoints < numberOfElements - 2)
146 | {
147 | [aPath addLineToPoint:endPoint];
148 | }
149 | else
150 | {
151 | HCChartPoint* chartPoint = (HCChartPoint*)[chartDots lastObject];
152 | [aPath addLineToPoint:CGPointMake(chartPoint.x, chartPoint.y)];
153 | [aPath addLineToPoint:CGPointMake(chartPoint.x+1, chartPoint.y)];
154 | }
155 | numberOfPoints++;
156 | }
157 | }
158 | else
159 | {
160 | for (NSValue* middlePointValue in middleDots)
161 | {
162 | CGPoint middlePoint = [middlePointValue CGPointValue];
163 | if (numberOfPoints == 0)
164 | {
165 | [aPath moveToPoint:CGPointMake(middlePoint.x-1, middlePoint.y)];
166 | [aPath addLineToPoint:middlePoint];
167 | }
168 | if (numberOfPoints > 0)
169 | {
170 | [aPath addLineToPoint:middlePoint];
171 | if (numberOfPoints == numberOfElements - 1)
172 | {
173 | [aPath addLineToPoint:CGPointMake(middlePoint.x+1, middlePoint.y)];
174 | }
175 | }
176 | numberOfPoints++;
177 | }
178 | }
179 | CGPoint bottomLeftPoint = CGPointMake(minXCoordinateOnChart - 1, chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight));
180 | CGPoint topLeftPoint = [middleDots.firstObject CGPointValue];
181 | topLeftPoint.x -= 1;
182 | CGPoint rightPoint = CGPointMake(maxXCoordinateOnChart + 1, chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight));
183 | [aPath addLineToPoint:rightPoint];
184 | [aPath addLineToPoint:bottomLeftPoint];
185 | [aPath addLineToPoint:topLeftPoint];
186 | [aPath closePath];
187 | if (chartStyle == chartLineWithCircles)
188 | {
189 | for (int i=0 ; i < numberOfElements ; i++)
190 | {
191 | HCChartPoint* HCChartPointt = (HCChartPoint*)[chartDots objectAtIndex:i];
192 | [aPath appendPath:[self drawChartPointAtPositionInside:CGPointMake(HCChartPointt.x, HCChartPointt.y)]];
193 | }
194 | }
195 | CGPoint startPoint = CGPointMake(CGRectGetMidX(chartRect), minYCoordinateOnChart - chartPointDiameter/2.0);
196 | CGPoint endPoint = CGPointMake(CGRectGetMidX(chartRect), MAX(bottomLeftPoint.y,maxYCoordinateOnChart + chartPointDiameter/2.0 - hcLineChartView.chartLineWidth));
197 | [aPath fill];
198 | [aPath addClip];
199 | CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
200 | CGContextRestoreGState(context);
201 | }
202 |
203 | /// This method is responsible for hiding gradient borders below chart line. It draws two gradient rects to hide unnecessary parts of gradient border
204 | -(void)hideGradientBorders
205 | {
206 | if (numberOfElements > 1)
207 | {
208 | CGPoint last = [[middleDots lastObject] CGPointValue];
209 | CGPoint first = [[middleDots firstObject] CGPointValue];
210 |
211 | NSArray* topComponentsFirst = [self colorComponents:chartStyle == chartLineWithCircles ? [self getGradientColorWithPercentage:(first.y + chartPointDiameter * 0.5) / chartRect.size.height forGradientColor1:hcLineChartView.backgroundGradientTopColor andGradientColor2:hcLineChartView.backgroundGradientBottomColor] : [self getGradientColorWithPercentage:first.y / chartRect.size.height forGradientColor1:hcLineChartView.backgroundGradientTopColor andGradientColor2:hcLineChartView.backgroundGradientBottomColor]];
212 |
213 | NSArray* topComponentsLast = [self colorComponents:chartStyle == chartLineWithCircles ? [self getGradientColorWithPercentage:(last.y + chartPointDiameter * 0.5) / chartRect.size.height forGradientColor1:hcLineChartView.backgroundGradientTopColor andGradientColor2:hcLineChartView.backgroundGradientBottomColor] : [self getGradientColorWithPercentage:last.y / chartRect.size.height forGradientColor1:hcLineChartView.backgroundGradientTopColor andGradientColor2:hcLineChartView.backgroundGradientBottomColor]];
214 |
215 | NSArray* bottomComponents = [self colorComponents:[self bottomColorForUnderLineAreaFromGradient]];
216 |
217 | CGFloat colorsFirst [] = {
218 | [topComponentsFirst objectAtIndex:0].floatValue, [topComponentsFirst objectAtIndex:1].floatValue, [topComponentsFirst objectAtIndex:2].floatValue, [topComponentsFirst objectAtIndex:3].floatValue ,
219 | [bottomComponents objectAtIndex:0].floatValue, [bottomComponents objectAtIndex:1].floatValue, [bottomComponents objectAtIndex:2].floatValue, [bottomComponents objectAtIndex:3].floatValue
220 | };
221 |
222 | CGFloat colorsLast [] = {
223 | [topComponentsLast objectAtIndex:0].floatValue, [topComponentsLast objectAtIndex:1].floatValue, [topComponentsLast objectAtIndex:2].floatValue, [topComponentsLast objectAtIndex:3].floatValue ,
224 | [bottomComponents objectAtIndex:0].floatValue, [bottomComponents objectAtIndex:1].floatValue, [bottomComponents objectAtIndex:2].floatValue, [bottomComponents objectAtIndex:3].floatValue
225 | };
226 |
227 | CGRect rectLast = CGRectMake(last.x, chartStyle == chartLineWithCircles ? last.y + chartPointDiameter * 0.5 : last.y, 2, chartStyle == chartLineWithCircles ? chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight) - last.y - chartPointDiameter * 0.5 : chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight) - last.y);
228 | CGRect rectFirst = CGRectMake(first.x - 2, chartStyle == chartLineWithCircles ? first.y + chartPointDiameter * 0.5 : first.y, 2, chartStyle == chartLineWithCircles ? chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight) - first.y - chartPointDiameter * 0.5 : chartRect.size.height * (pointsRectTopProportionalDistance + pointsRectProportionalHeight) - first.y);
229 |
230 | if (hcLineChartView.chartGradient)
231 | {
232 | [self drawRect:rectFirst withColors:colorsFirst];
233 | [self drawRect:rectLast withColors:colorsLast];
234 | }
235 | else
236 | {
237 | [self drawRect:rectFirst withBackgroundColor:hcLineChartView.backgroundGradientTopColor];
238 | [self drawRect:rectLast withBackgroundColor:hcLineChartView.backgroundGradientTopColor];
239 | }
240 | }
241 | }
242 |
243 | /// This method generates color components array from the given color. This method is used as a helper method for other methods, primarly for drawing gradient
244 | /// @param color Given color for which we need to calculate color components
245 | /// @return Color components array
246 | -(NSArray*)colorComponents:(UIColor*)color
247 | {
248 | int numColorComponents = (int)CGColorGetNumberOfComponents(color.CGColor);
249 | const CGFloat* colorComponents = CGColorGetComponents(color.CGColor);
250 | CGFloat components[4];
251 | if (numColorComponents == 2)
252 | {
253 | components[0] = 1.0 * colorComponents[0];
254 | components[1] = 1.0 * colorComponents[0];
255 | components[2] = 1.0 * colorComponents[0];
256 | components[3] = 1.0 * colorComponents[1];
257 | }
258 | else
259 | {
260 | components[0] = 1.0 * colorComponents[0];
261 | components[1] = 1.0 * colorComponents[1];
262 | components[2] = 1.0 * colorComponents[2];
263 | components[3] = numColorComponents == 4 ? (1.0 * colorComponents[3]) : 1.0;
264 | }
265 | return [NSArray arrayWithObjects:@(components[0]),@(components[1]),@(components[2]),@(components[3]), nil];
266 | }
267 |
268 | /// This method calculates and returns bottom color for gradient area under chart line if you want to make a transparency effect for bottom color for gradient (i.e., if underLineChartGradientBottomColorIsTransparent parameter in HCLineChartView is set to YES)
269 | /// @return Bottom color for the gradient under chart line which simulates transparency effect
270 | -(UIColor*)bottomColorForUnderLineAreaFromGradient
271 | {
272 | double percentage = pointsRectTopProportionalDistance + pointsRectProportionalHeight;
273 | return [self getGradientColorWithPercentage:percentage forGradientColor1:hcLineChartView.backgroundGradientTopColor andGradientColor2:hcLineChartView.backgroundGradientBottomColor];
274 | }
275 |
276 | /// Helper method which returns the color from the gradient, based on the given percentage parameter and gradient colors
277 | /// @param percentage The relative position between start and end of the gradient
278 | /// @param gradientColor1 First color in gradient
279 | /// @param gradientColor2 Last collor in gradient
280 | -(UIColor*)getGradientColorWithPercentage:(double)percentage forGradientColor1:(UIColor*)gradientColor1 andGradientColor2:(UIColor*)gradientColor2
281 | {
282 | NSArray* components1 = [self colorComponents:gradientColor1];
283 |
284 | NSArray* components2 = [self colorComponents:gradientColor2];
285 |
286 | float redComponent = [components1 objectAtIndex:0].floatValue + percentage * ([components2 objectAtIndex:0].floatValue - [components1 objectAtIndex:0].floatValue);
287 | float greenComponent = [components1 objectAtIndex:1].floatValue + percentage * ([components2 objectAtIndex:1].floatValue - [components1 objectAtIndex:1].floatValue);
288 | float blueComponent = [components1 objectAtIndex:2].floatValue + percentage * ([components2 objectAtIndex:2].floatValue - [components1 objectAtIndex:2].floatValue);
289 | float alphaComponent = [components1 objectAtIndex:3].floatValue + percentage * ([components2 objectAtIndex:3].floatValue - [components1 objectAtIndex:3].floatValue);
290 | return [UIColor colorWithRed:MIN(1,redComponent) green:MIN(1,greenComponent) blue:MIN(1,blueComponent) alpha:alphaComponent];
291 | }
292 |
293 | @end
294 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+General/HCChartDrawer+General.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Helper.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (General)
12 |
13 | /// This method draws line from startPoint to endPoint with specified lineColor and lineWidth
14 | /// @param startPoint Start point for drawing the line.
15 | /// @param endPoint End point for drawing the line.
16 | /// @param lineColor Line color.
17 | /// @param lineWidth Line width.
18 | -(void)drawLineFromPoint:(CGPoint)startPoint toPoint: (CGPoint) endPoint withColor:(UIColor*)lineColor andWidth:(double)lineWidth;
19 |
20 |
21 | /// This method creates dashed line accross the chart (for example, when Y value is 0)
22 | /// @param startPoint Start point for drawing the line.
23 | /// @param endPoint End point for drawing the line.
24 | -(void)drawDashedLineFromPoint:(CGPoint)startPoint toEndPoint:(CGPoint)endPoint;
25 |
26 |
27 | /// This method draws rect with given background color
28 | /// @param rect This property defines rect, i.e. position and size for desired rect.
29 | /// @param backgroundColor This property defines background color for desired rect.
30 | -(void)drawRect:(CGRect)rect withBackgroundColor:(UIColor*)backgroundColor;
31 |
32 | /// Helper method for drawing rect with gradient
33 | /// @param rect Given rect for drawing
34 | /// @param colors Array of colors which make gradient
35 | -(void)drawRect:(CGRect)rect withColors:(CGFloat*)colors;
36 |
37 | /// This method generates attributes dictionary for desired font and some other settings
38 | /// @param font This property defines font for desired text.
39 | /// @param fontColor This property defines font color for desired text.
40 | /// @param textAlignment This property defines text alignment for desired text.
41 | /// @param lineBreakMode This property defines line break mode for desired text.
42 | /// @return Generated font attributes for defined parameters
43 | -(NSDictionary*)fontAttributesWithFont: (UIFont*)font fontColor:(UIColor*)fontColor textAlignment:(NSTextAlignment)textAlignment andLineBreakMode:(NSLineBreakMode)lineBreakMode;
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+General/HCChartDrawer+General.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Helper.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer+General.h"
10 |
11 | @implementation HCChartDrawer (General)
12 |
13 | #pragma mark Draw line methods
14 |
15 | -(void)drawLineFromPoint:(CGPoint)startPoint toPoint: (CGPoint) endPoint withColor:(UIColor*)lineColor andWidth:(double)lineWidth
16 | {
17 | CGContextRef context = UIGraphicsGetCurrentContext();
18 | CGContextSaveGState(context);
19 | CGContextSetLineCap(context, kCGLineCapRound);
20 | CGContextSetStrokeColorWithColor(context, lineColor.CGColor);
21 | CGContextSetLineWidth(context, lineWidth);
22 | CGContextMoveToPoint(context, startPoint.x, startPoint.y );
23 | CGContextAddLineToPoint(context, endPoint.x, endPoint.y );
24 | CGContextStrokePath(context);
25 | CGContextRestoreGState(context);
26 | }
27 |
28 | -(void)drawDashedLineFromPoint:(CGPoint)startPoint toEndPoint:(CGPoint)endPoint
29 | {
30 | [hcLineChartView.chartAxisColor setStroke];
31 | UIBezierPath * path = [[UIBezierPath alloc] init];
32 | [path moveToPoint:startPoint];
33 | [path addLineToPoint:endPoint];
34 | CGFloat dashes[] = {1, 2};
35 | [path setLineDash:dashes count:2 phase:0];
36 | [path stroke];
37 | }
38 |
39 | #pragma mark Draw rect methods
40 |
41 | -(void)drawRect:(CGRect)rect withBackgroundColor:(UIColor*)backgroundColor
42 | {
43 | UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: rect];
44 | [backgroundColor setFill];
45 | [rectanglePath fill];
46 | }
47 |
48 | -(void)drawRect:(CGRect)rect withColors:(CGFloat*)colors
49 | {
50 | CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
51 | CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2);
52 | (void)(CGColorSpaceRelease(baseSpace)), baseSpace = NULL;
53 |
54 | CGContextRef context = UIGraphicsGetCurrentContext();
55 | CGContextSetLineWidth(context, 0);
56 |
57 | CGContextSaveGState(context);
58 | CGContextAddRect(context, rect);
59 | CGContextClip(context);
60 |
61 | CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
62 | CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
63 |
64 | CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
65 | (void)(CGGradientRelease(gradient)), gradient = NULL;
66 |
67 | CGContextRestoreGState(context);
68 |
69 | CGContextAddRect(context, rect);
70 | CGContextDrawPath(context, kCGPathStroke);
71 | }
72 |
73 | #pragma mark Font attributes generator
74 |
75 | -(NSDictionary*)fontAttributesWithFont: (UIFont*)font fontColor:(UIColor*)fontColor textAlignment:(NSTextAlignment)textAlignment andLineBreakMode:(NSLineBreakMode)lineBreakMode
76 | {
77 | NSMutableParagraphStyle *myStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
78 | myStyle.lineBreakMode = lineBreakMode;
79 | myStyle.alignment = textAlignment;
80 | NSDictionary *attributes = @{ NSFontAttributeName: font,
81 | NSParagraphStyleAttributeName: myStyle ,
82 | NSForegroundColorAttributeName: fontColor};
83 | return attributes;
84 | }
85 |
86 | @end
87 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+Text/HCChartDrawer+Text.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Text.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (Text)
12 |
13 | /// This method calculates text size based on given fontSize
14 | /// @param text Text for which we need to calculate size
15 | /// @param fontSize Font size for given text
16 | /// @return Size of given text with given font size
17 | - (CGSize)sizeOfText:(NSString *)text withFontSize:(double)fontSize;
18 |
19 | /// This method generates string for given timestamp (dateWithTimeIntervalSince1970 value)
20 | /// @param timestamp Timestamp which should be converted to Date and represented as text (NSString)
21 | /// @return Generated string for given timestamp
22 | - (NSString*)timeStringForValue:(double)timestamp;
23 |
24 | /// This method generates string for given date and given format
25 | /// @param date NSDate instance which should be converted to NSString
26 | /// @param dateFormat Date format for presenting given NSDate instance as NSString.
27 | /// @return Generated string for given NSDate instance
28 | - (NSString*)timeStringForDate:(NSDate*)date withFormat:(NSString*)dateFormat;
29 |
30 | /// This method draws text with predefined position and size (rect), attributes, offset and orientation (vertical or horizontal)
31 | /// @param text Text to be drawn
32 | /// @param rect Rect, i.e. position and size for drawing the text
33 | /// @param attributes Text attributes (font, text color, alignment,...) for drawing the text
34 | /// @param offset Position offset for drawing the text (used during drawing successive values on axis)
35 | /// @param isVertical Boolean value which defines if text should be drawn as horizontal or vertical
36 | - (void)drawText:(NSString*)text withRect:(CGRect)rect withAtributes:(NSDictionary*)attributes withOffset:(CGPoint)offset isVertical:(BOOL)isVertical;
37 |
38 | /// Returns number as a currency string
39 | /// @param value number which should be converted to string
40 | /// @param numberOfDecimalPlaces Number of decimal places for currency string
41 | /// @param currencyCode Currency code for value which shoud be presented as currency. If this parameter is not set, i.e., it is NULL, currency formatter will use local currency
42 | /// @return Numerical value converted to string
43 | -(NSString*)currencyStringForValue:(double)value numberOfDecimalPlaces:(int)numberOfDecimalPlaces currencyCode:(NSString*)currencyCode;
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+Text/HCChartDrawer+Text.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+Text.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer+Text.h"
10 | #import "HCTimeStep.h"
11 |
12 | @implementation HCChartDrawer (Text)
13 |
14 | #pragma mark Draw text
15 |
16 | -(void)drawText:(NSString*)text withRect:(CGRect)rect withAtributes:(NSDictionary*)attributes withOffset:(CGPoint)offset isVertical:(BOOL)isVertical
17 | {
18 | CGContextRef context = UIGraphicsGetCurrentContext();
19 | CGContextSaveGState(context);
20 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
21 | CGContextTranslateCTM(context, offset.x, offsetForAxisOrHeader + offset.y);
22 |
23 | if (isVertical)
24 | {
25 | CGContextTranslateCTM(context, rect.origin.x + rect.size.width * 0.5 + rect.size.height * 0.5, rect.origin.y);
26 | CGContextRotateCTM(context, M_PI_2);
27 | rect.origin = CGPointZero;
28 | [text drawInRect:rect withAttributes:attributes];
29 | }
30 | else
31 | {
32 | [text drawInRect:rect withAttributes:attributes];
33 | }
34 |
35 | CGColorSpaceRelease(colorSpace);
36 | CGContextRestoreGState(context);
37 | }
38 |
39 | #pragma mark Text size calculation
40 |
41 | - (CGSize)sizeOfText:(NSString *)text withFontSize:(double)fontSize {
42 |
43 | double descriptionMaxHeight = fontSize;
44 | CGSize maximumLabelSize = CGSizeMake(CGFLOAT_MAX, descriptionMaxHeight);
45 | CGRect textRect = [text boundingRectWithSize:maximumLabelSize
46 | options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
47 | attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:fontSize]}
48 | context:nil];
49 | CGSize textSize = textRect.size;
50 | textSize.width += 2.0;
51 | return textSize;
52 | }
53 |
54 | -(CGSize)sizeForLabel:(NSString*)text font:(UIFont*)font width:(CGFloat)width lineNumber:(int)lineNumber
55 | {
56 | UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, CGFLOAT_MAX)];
57 | label.numberOfLines = lineNumber;
58 | label.lineBreakMode = NSLineBreakByWordWrapping;
59 | label.font = font;
60 | label.text = text;
61 | [label sizeToFit];
62 | return label.frame.size;
63 | }
64 |
65 | #pragma mark Text generator
66 |
67 | -(NSString*)currencyStringForValue:(double)value numberOfDecimalPlaces:(int)numberOfDecimalPlaces currencyCode:(NSString*)currencyCode
68 | {
69 | NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
70 | [numberFormatter setMaximumFractionDigits:numberOfDecimalPlaces];
71 | [numberFormatter setMinimumFractionDigits:numberOfDecimalPlaces];
72 | [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
73 | if (currencyCode)
74 | {
75 | BOOL currencyCodeIsValid = NO;
76 | for (NSString* local in [NSLocale availableLocaleIdentifiers])
77 | {
78 | NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:local];
79 | NSString* localeCurrencyCode = [locale objectForKey:NSLocaleCurrencyCode];
80 | if ([localeCurrencyCode isEqualToString:currencyCode])
81 | {
82 | currencyCodeIsValid = YES;
83 | break;
84 | }
85 | }
86 | if (currencyCodeIsValid)
87 | {
88 | [numberFormatter setCurrencyCode:currencyCode];
89 | }
90 | }
91 | NSString *numberAsCurrency = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:value]];
92 | return numberAsCurrency;
93 | }
94 |
95 | -(NSString*)timeStringForValue:(double)timestamp
96 | {
97 | return [self timeStringForDate:[NSDate dateWithTimeIntervalSince1970:timestamp] withFormat:xAxisDateTick.useAlternativeTimeFormat ? (xAxisDateTick.alternativeTimeFormat ? xAxisDateTick.alternativeTimeFormat : [timeSteps firstObject].timeFormat) : xAxisDateTick.timeFormat ? xAxisDateTick.timeFormat : [timeSteps firstObject].timeFormat];
98 | }
99 |
100 | -(NSString*)timeStringForDate:(NSDate*)date withFormat:(NSString*)dateFormat
101 | {
102 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
103 | [formatter setDateFormat:dateFormat];
104 | NSString* xAxisString = [formatter stringFromDate:date];
105 | return xAxisString;
106 | }
107 |
108 | @end
109 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+TitleAndSubtitle/HCChartDrawer+TitleAndSubtitle.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+TitleAndSubtitle.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 |
11 | @interface HCChartDrawer (TitleAndSubtitle)
12 |
13 | /// This method draws title and subtitle for the chart
14 | -(void)drawTitleAndSubtitle;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer+Extensions/HCChartDrawer+TitleAndSubtitle/HCChartDrawer+TitleAndSubtitle.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer+TitleAndSubtitle.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer+TitleAndSubtitle.h"
10 | #import "HCChartDrawer+Text.h"
11 | #import "HCChartDrawer+General.h"
12 |
13 | @implementation HCChartDrawer (TitleAndSubtitle)
14 |
15 | -(void)drawTitleAndSubtitle
16 | {
17 | [self drawTitleText];
18 | if (hcLineChartView.showSubtitle)
19 | {
20 | [self drawSubTitleText];
21 | }
22 | }
23 |
24 | #pragma mark Draw title
25 |
26 | /// This method draws chart title
27 | -(void)drawTitleText
28 | {
29 | UIFont* titleFont;
30 | if (@available(iOS 8.2, *))
31 | {
32 | titleFont = [UIFont systemFontOfSize:hcLineChartView.fontSizeForTitle weight:2.0];
33 | }
34 | else
35 | {
36 | titleFont = [UIFont boldSystemFontOfSize:hcLineChartView.fontSizeForTitle];
37 | }
38 | NSDictionary* attributes = [self fontAttributesWithFont:titleFont fontColor:hcLineChartView.chartTitleColor textAlignment:NSTextAlignmentCenter andLineBreakMode:NSLineBreakByTruncatingTail];
39 | [self drawText:hcLineChartView.chartTitle withRect:[self chartTitleRect] withAtributes:attributes withOffset:CGPointMake(0.0, 0.0) isVertical:NO];
40 | }
41 |
42 | /// This property defines rect for chart title
43 | /// @return Chart title rect
44 | -(CGRect)chartTitleRect
45 | {
46 | CGSize textSize = [self sizeOfText:hcLineChartView.chartTitle withFontSize:hcLineChartView.fontSizeForTitle];
47 | CGRect textRect = chartRect;
48 | textRect.size.height = textSize.height;
49 | textRect.origin.x = chartCornerRadius * sqrt(2.0) * 0.5;
50 | textRect.size.width -= chartCornerRadius * sqrt(2.0);
51 | return textRect;
52 | }
53 |
54 | #pragma mark Draw subtitle
55 |
56 | /// This method draws chart subtitle
57 | -(void)drawSubTitleText
58 | {
59 | UIFont* subtitleFont;
60 | if (@available(iOS 8.2, *))
61 | {
62 | subtitleFont = [UIFont systemFontOfSize:hcLineChartView.fontSizeForSubTitle weight:1.0];
63 | }
64 | else
65 | {
66 | subtitleFont = [UIFont systemFontOfSize:hcLineChartView.fontSizeForSubTitle];
67 | }
68 | NSDictionary* attributes = [self fontAttributesWithFont:subtitleFont fontColor:hcLineChartView.chartSubtitleColor textAlignment:NSTextAlignmentCenter andLineBreakMode:NSLineBreakByTruncatingTail];
69 | [self drawText:hcLineChartView.chartSubTitle withRect:[self chartSubtitleRect] withAtributes:attributes withOffset:CGPointMake(0.0, hcLineChartView.fontSizeForTitle + 4.0) isVertical:NO];
70 | }
71 |
72 | /// This property defines rect for chart subtitle
73 | /// @return Chart subtitle rect
74 | -(CGRect)chartSubtitleRect
75 | {
76 | CGSize textSize = [self sizeOfText:hcLineChartView.chartSubTitle withFontSize:hcLineChartView.fontSizeForSubTitle];
77 | CGRect textRect = chartRect;
78 | textRect.origin.x = chartCornerRadius * sqrt(2.0) * 0.5;
79 | textRect.size.width -= chartCornerRadius * sqrt(2.0);
80 | textRect.size.height = textSize.height;
81 | return textRect;
82 | }
83 |
84 | @end
85 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HCLineChartView.h"
11 |
12 | @class HCTimeStep;
13 |
14 | @interface HCChartDrawer : NSObject
15 | {
16 |
17 | #pragma mark Chart Coordinates
18 | /// This property defines minimal X coordinate on chart. It is calculated runtime.
19 | double minXCoordinateOnChart;
20 |
21 | /// This property defines maximal X coordinate on chart. It is calculated runtime.
22 | double maxXCoordinateOnChart;
23 |
24 | /// This property defines minimal Y coordinate on chart. It is calculated runtime.
25 | double minYCoordinateOnChart;
26 |
27 | /// This property defines maximal Y coordinate on chart. It is calculated runtime.
28 | double maxYCoordinateOnChart;
29 |
30 | #pragma mark Represented Values on Chart
31 |
32 | /// This property defines minimal value for X axis on chart. It is calculated runtime.
33 | double minXValueOnChart;
34 |
35 | /// This property defines maximal value for X axis on chart. It is calculated runtime.
36 | double maxXValueOnChart;
37 |
38 | /// This property defines minimal value for Y axis on chart. It is calculated runtime.
39 | double minYValueOnChart;
40 |
41 | /// This property defines maximal value for Y axis on chart. It is calculated runtime.
42 | double maxYValueOnChart;
43 |
44 | /// Helper attribute, i.e. current value for X axis during drawing values on X axis
45 | double currentValueX;
46 |
47 | /// Helper attribute, i.e. current value for Y axis during drawing values on Y axis
48 | double currentValueY;
49 |
50 | /// Decimal format for values on X axis (if values on X axis are numeric).
51 | NSString* decimalFormatX;
52 |
53 | /// Helper attribute, i.e. current position (X coordinate) for X axis during drawing values on X axis
54 | double currentPositionX;
55 |
56 | /// Helper attribute, which defines number of values on X axis which are bypassed when there are more values on X axis then there is possible to draw value for every of them on chart.
57 | double jumpOverX;
58 |
59 | #pragma mark Chart Data Maximal and Minimal Values
60 |
61 | /// This property defines minimal value for values in X array. It is calculated runtime.
62 | double minXValue;
63 |
64 | /// This property defines maximal value for values in X array. It is calculated runtime.
65 | double maxXValue;
66 |
67 | /// This property defines minimal value for values in Y array. It is calculated runtime.
68 | double minYValue;
69 |
70 | /// This property defines maximal value for values in Y array. It is calculated runtime.
71 | double maxYValue;
72 |
73 | #pragma mark Chart Dots
74 |
75 | /// Array with help dots, i.e. start dots for lines between circles if chart dots are represented with circles.
76 | NSMutableArray* startDots;
77 |
78 | /// Array with help dots, i.e. end dots for lines between circles if chart dots are represented with circles.
79 | NSMutableArray* endDots;
80 |
81 | /// Array with help dots, i.e. start dots for lines between circles if chart dots are not represented with circles.
82 | NSMutableArray* middleDots;
83 |
84 | /// Array with chart dots.
85 | NSMutableArray* chartDots;
86 |
87 | /// This property defines offset for drawing chart header or chart axis
88 | double offsetForAxisOrHeader;
89 |
90 | /// Reference to HCLineChartView instance where HCChartDrawer needs to draw the chart.
91 | HCLineChartView* hcLineChartView;
92 |
93 | /// HCLineChartView rect size, necessary for accurate drawing chart componente
94 | CGRect chartRect;
95 |
96 | /// This property defines X axis tick size if values on X axis are represented as numerical values. It is calculated runtime.
97 | double xAxisTick;
98 |
99 | /// This property defines X axis tick size if values on X axis are represented as date / time values. It is calculated runtime.
100 | HCTimeStep* xAxisDateTick;
101 |
102 | /// This property defines Y axis tick size. It is calculated runtime.
103 | double yAxisTick;
104 |
105 | /// This property defines space between ticks on X axis. It is calculated runtime.
106 | double xStep;
107 |
108 | /// This property defines space between ticks on Y axis. It is calculated runtime.
109 | double yStep;
110 |
111 | /// This property defines number of decimals places for values on X axis. It is calculated runtime.
112 | int numberOfXDecimals;
113 |
114 | /// This property defines number of decimals places for values on Y axis. It is calculated runtime.
115 | int numberOfYDecimals;
116 |
117 | /// This property defines Y coordinate of the top of the vertical (Y) axis. It is calculated runtime.
118 | double startVertical;
119 |
120 | /// This property defines Y coordinate of the bottom of the vertical (Y) axis. It is calculated runtime.
121 | double endVertical;
122 |
123 | /// This property defines value for the most top value on Y axis. It is calculated runtime.
124 | double startVerticalValue;
125 |
126 | /// This property defines value for the most bottom value on Y axis. It is calculated runtime.
127 | double endVerticalValue;
128 |
129 | /// This property defines value for the first value on X axis. It is calculated runtime.
130 | double startHorizontalValue;
131 |
132 | /// This property defines array for storing HCTimeStep instances, i.e. potential options for displaying values on X axis if values for X axis are represented as date / time values.
133 | NSArray* timeSteps;
134 |
135 | /// This property indicates that all values on horizontal (X) axis are equal.
136 | BOOL horizontalValuesAreAllEqual;
137 |
138 | /// This property indicates that all values on vertical (Y) axis are equal.
139 | BOOL verticalValuesAreAllEqual;
140 |
141 | #pragma mark Chart Dimensions
142 | /// This property defines relative distance between chart and its borders
143 | double leftOrBottomOffsetProportional;
144 |
145 | /// This property defines chart point diameter if chart points are represented with circles
146 | double chartPointDiameter;
147 |
148 |
149 | /// This property defines corner radius for rounded rect if user selects to use chart with rounded corners.
150 | float chartCornerRadius;
151 |
152 | /// This property defines axis width
153 | double axisWidth;
154 |
155 | /// This property defines relative distance from axes to points
156 | double axisDistanceFromPointsProportionaly;
157 |
158 | /// This property defines proportional width of chart area (part of chart where the dots are presented) relative to chart view width. It is calculated runtime.
159 | double pointsRectProportionalWidth;
160 |
161 | /// This property defines proportional height of chart area (part of chart where the dots are presented) relative to chart view height. It is calculated runtime.
162 | double pointsRectProportionalHeight;
163 |
164 | /// This property defines relative distance between chart dots and top edge of the chart view. It is calculated runtime.
165 | double pointsRectTopProportionalDistance;
166 |
167 | /// efines relative distance between chart dots and left edge of the chart view. It is calculated runtime.
168 | double pointsRectLeftProportionalDistance;
169 |
170 | /// This property defines maximal text size for values on X axis. It is calculated runtime
171 | CGSize xAxisLabelTextSize;
172 |
173 | /// This property defines maximal text size for values on Y axis. It is calculated runtime
174 | CGSize yAxisLabelTextSize;
175 |
176 | /// Standard offset parameter for drawing chart axis
177 | double standardOffset;
178 |
179 | #pragma mark Chart Settings
180 |
181 | /// This property defines chart calendar type, it is calculated runtime
182 | HCCalendarType calendarType;
183 |
184 | /// This property defines chart type. It is calculated runtime.
185 | HCChartType chartType;
186 |
187 | /// This property defines if dots in chart are represented as simple dots or with circles. This property is indirectly defined by user, by chartLineWithCircles parameter in HCLineChartView.
188 | HCChartStyle chartStyle;
189 |
190 | #pragma mark Chart Data
191 | /// Used for storing number of values to be presented in chart.
192 | int numberOfElements;
193 | }
194 |
195 | /// Method for drawing chart inside linearChartView. This method, in fact, uses another methods for pre-drawing calulations and for drawing separate parts of chart, like chart background, title, subtitle, dots, axes,...
196 | /// @param linearChartView Reference to the HCLineChartView instance. HCChartDrawer needs to draw chart inside this instance
197 | /// @param rect Rect for HCLineChartView
198 | -(void)drawChart:(HCLineChartView*)linearChartView inRect:(CGRect)rect;
199 |
200 | @end
201 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCChartDrawer/HCChartDrawer.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartDrawer.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartDrawer.h"
10 | #import "HCLineChartView.h"
11 | #import "HCChartDrawer+Background.h"
12 | #import "HCChartDrawer+TitleAndSubtitle.h"
13 | #import "HCChartDrawer+Text.h"
14 | #import "HCChartDrawer+CalculationAndPreparation.h"
15 | #import "HCChartDrawer+Axis.h"
16 | #import "HCChartDrawer+General.h"
17 | #import "HCChartDrawer+ChartLine.h"
18 | #import "HCTimeStep.h"
19 |
20 |
21 | @implementation HCChartDrawer
22 |
23 | #pragma mark Draw chart
24 |
25 | -(void)drawChart:(HCLineChartView*)linearChartView inRect:(CGRect)rect
26 | {
27 | hcLineChartView = linearChartView;
28 | chartRect = rect;
29 | [self drawLineChart];
30 | chartStyle = chartLineWithCircles;
31 | }
32 |
33 |
34 | /// This method calls all main functions for drawing the chart
35 | -(void)drawLineChart
36 | {
37 | [self prepareChartForDrawing];
38 | [self drawBackground];
39 | [self drawTitleAndSubtitle];
40 | if (chartType != chartWithInvalidValues)
41 | {
42 | [self drawHorizontalLinesForYTicks];
43 | [self drawChartLine];
44 | [self drawBothAxises];
45 | }
46 | else
47 | {
48 | [self handleInvalidValues];
49 | }
50 | }
51 |
52 | #pragma mark Handle invalid values
53 |
54 | /// This method handles error if chart values are invalid
55 | -(void)handleInvalidValues
56 | {
57 | NSString* chartWithInvalidValuesString = @"Invalid values";
58 | CGSize textSize = [self sizeOfText:chartWithInvalidValuesString withFontSize:hcLineChartView.fontSizeForTitle];
59 | CGRect textRext = CGRectMake((chartRect.size.width - textSize.width) * 0.5, (chartRect.size.height - textSize.height) * 0.5, textSize.width, textSize.height);
60 | NSMutableParagraphStyle *myStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
61 | myStyle.lineBreakMode = NSLineBreakByWordWrapping;
62 | myStyle.alignment = NSTextAlignmentCenter;
63 | UIFont *font = [UIFont systemFontOfSize:hcLineChartView.fontSizeForTitle];
64 | NSDictionary *attributes = @{ NSFontAttributeName: font,
65 | NSParagraphStyleAttributeName: myStyle ,
66 | NSForegroundColorAttributeName: [UIColor whiteColor]};
67 | [self drawText:chartWithInvalidValuesString withRect:textRext withAtributes:attributes withOffset:CGPointZero isVertical:NO];
68 | }
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCLineChartView.h:
--------------------------------------------------------------------------------
1 | //
2 | // LineChart.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HCChartPoint.h"
11 | #import "HCEnums.h"
12 |
13 | @class HCChartDrawer;
14 |
15 | IB_DESIGNABLE
16 | /// Custom UIView inside which we're drawing the chart.
17 | @interface HCLineChartView : UIView
18 | {
19 | ///This class is used for drawing all elements in HCLineChartView.
20 | HCChartDrawer* hcChartDrawer;
21 | }
22 |
23 | #pragma mark Chart Background Settings
24 |
25 | /// This property defines if chart background is transparent or not.
26 | @property IBInspectable BOOL chartTransparentBackground;
27 |
28 | /// This property defines if chart background has the gradient.
29 | @property IBInspectable BOOL chartGradient;
30 |
31 | /// This property defines the top color for background gradient. It is also the background color for the chart if chartGradient is set to NO.
32 | @property (retain, nonatomic) IBInspectable UIColor* backgroundGradientTopColor;
33 |
34 | /// This property defines the bottom color for background gradient.
35 | @property (retain, nonatomic) IBInspectable UIColor* backgroundGradientBottomColor;
36 |
37 | /// This property defines if chart view should have rounded corners.
38 | @property IBInspectable BOOL chartWithRoundedCorners;
39 |
40 | #pragma mark Title and Subtitle Settings
41 |
42 | /// This property defines chart title.
43 | @property (retain, nonatomic) IBInspectable NSString* chartTitle;
44 |
45 | /// This property defines chart title color.
46 | @property (retain, nonatomic) IBInspectable UIColor* chartTitleColor;
47 |
48 | /// This property defines font size for chart title.
49 | @property IBInspectable double fontSizeForTitle;
50 |
51 | /// This property defines if the chart has a subtitle.
52 | @property IBInspectable BOOL showSubtitle;
53 |
54 | /// This property defines chart subtitle.
55 | @property (retain, nonatomic) IBInspectable NSString* chartSubTitle;
56 |
57 | /// This property defines font size for chart subtitle.
58 | @property IBInspectable double fontSizeForSubTitle;
59 |
60 | /// This property defines chart subtitle color.
61 | @property (retain, nonatomic) IBInspectable UIColor* chartSubtitleColor;
62 |
63 | #pragma mark Chart Axis Settings
64 |
65 | /// This property defines chart axes color.
66 | @property (retain, nonatomic) IBInspectable UIColor* chartAxisColor;
67 |
68 | /// This property defines font size for chart axes.
69 | @property IBInspectable double fontSizeForAxis;
70 |
71 | /// This property defines if values on the X axis should be in currency format. It is useful in cases where we need to show exchange rate on chart
72 | @property IBInspectable BOOL showXValueAsCurrency;
73 |
74 | /// TThis property defines currency code for the X axis. It is relevant if showXValueAsCurrency parameter is set to YES. If you don't define currency code or currency code is not valid, the chart will display your local currency code.
75 | @property (retain, nonatomic) IBInspectable NSString* xAxisCurrencyCode;
76 |
77 | /// This property defines if values on the Y axis should be in currency format. It is useful when we need to show exchange rate on the chart (if showXValueAsCurrency is also set to YES), or in any other case where we need to show Y values in currency format (price, saving, debt, surplus, deficit,...)
78 | @property IBInspectable BOOL showYValueAsCurrency;
79 |
80 | /// This property defines currency code for the Y axis. It is relevant if showYValueAsCurrency parameter is set to YES. If you don't define currency code or currency code is not valid, the chart will display your local currency code.
81 | @property (retain, nonatomic) IBInspectable NSString* yAxisCurrencyCode;
82 |
83 | /// This property defines if values on X axis should be presented horizontally (vertically is default).
84 | @property IBInspectable BOOL horizontalValuesOnXAxis;
85 |
86 | /// This property defines if values on this axis should have horizontal orientation (default orientation is vertical)
87 | @property IBInspectable BOOL drawHorizontalLinesForYTicks;
88 |
89 | #pragma mark Chart Line Settings
90 |
91 | /// This property defines chart line width.
92 | @property IBInspectable float chartLineWidth;
93 |
94 | /// This property defines chart line color.
95 | @property (retain, nonatomic) IBInspectable UIColor* chartLineColor;
96 |
97 | /// This property defines if chart points should have circles
98 | @property IBInspectable BOOL chartLineWithCircles;
99 |
100 | /// This property defines if the area under chart line should have gradient
101 | @property IBInspectable BOOL chartGradientUnderline;
102 |
103 | /// This property defines if bottom gradient color for the area under chart line is transparent.
104 | @property (retain, nonatomic) IBInspectable UIColor* underLineChartGradientTopColor;
105 |
106 | /// This property defines if bottom gradient color for the area under chart line is transparent.
107 | @property IBInspectable BOOL underLineChartGradientBottomColorIsTransparent;
108 |
109 | /// This property defines bottom gradient color for the area under chart line. This parameter is valid only if chart itself isn't transparent
110 | @property (retain, nonatomic) IBInspectable UIColor* underLineChartGradientBottomColor;
111 |
112 | /// This property defines if the distribution of values on X axis should be value based.
113 | @property IBInspectable BOOL isValueChartWithRealXAxisDistribution;
114 |
115 | #pragma mark Chart Data and Methods
116 |
117 | /// It is recommended to provide already sorted data before drawing the chart. If you don't have values for X axis sorted ascending, you can set this parameter to YES. In that case, provided values for X axis (xElements) will be sorted ascending, with the parallel sorting of paired values for Y axis (yElements). Sorting data could have a small impact on chart drawing performance.
118 | @property IBInspectable BOOL sortData;
119 |
120 | /// Array for storing values for the X axis. Only NSNumber and NSDate values are allowed.
121 | @property (retain, nonatomic) NSMutableArray* xElements;
122 |
123 | /// Array for storing values for the Y axis. Only NSNumber values are allowed.
124 | @property (retain, nonatomic) NSMutableArray* yElements;
125 |
126 | #pragma mark Drawing and Updating Methods
127 |
128 | /// Draws/redraws chart with current data and settings. Calling this method will call onDraw method
129 | -(void)drawChart;
130 |
131 | /// Updates chart with new data
132 | /// @param xElements Values for X axis.
133 | /// @param yElements Values for Y axis.
134 | -(void)updateChartWithXElements:(NSArray*)xElements yElements:(NSArray*)yElements;
135 |
136 | @end
137 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCLineChartView.m:
--------------------------------------------------------------------------------
1 | //
2 | // LineChart.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCLineChartView.h"
10 | #import
11 | #import "HCChartDrawer.h"
12 |
13 | @implementation HCLineChartView
14 |
15 | #pragma mark Initialization
16 |
17 | /// Override standard constructor
18 | -(id)initWithFrame:(CGRect)frame
19 | {
20 | self = [super initWithFrame:frame];
21 | if (!self)
22 | {
23 | return NULL;
24 | }
25 |
26 | [self setDefaultValues];
27 |
28 | return self;
29 | }
30 |
31 | /// Override standard constructor
32 | -(id)initWithCoder:(NSCoder *)aDecoder
33 | {
34 | self = [super initWithCoder:aDecoder];
35 | if (!self)
36 | {
37 | return NULL;
38 | }
39 |
40 | [self setDefaultValues];
41 |
42 | return self;
43 | }
44 |
45 | /// This method sets default settings for chart drawing if user don't setup them
46 | -(void)setDefaultValues
47 | {
48 | self.chartTitle = @"";
49 | self.chartSubTitle = @"";
50 | self.backgroundGradientTopColor = [UIColor whiteColor];
51 | self.backgroundGradientBottomColor = [UIColor whiteColor];
52 | self.underLineChartGradientTopColor = [UIColor whiteColor];
53 | self.underLineChartGradientBottomColor = [UIColor whiteColor];
54 | self.chartTitleColor = [UIColor blackColor];
55 | self.chartSubtitleColor = [UIColor blackColor];
56 | self.chartAxisColor = [UIColor blackColor];
57 | self.chartLineWidth = 2.0;
58 | self.fontSizeForTitle = 18.0;
59 | self.fontSizeForSubTitle = 12.0;
60 | self.fontSizeForAxis = 9.0;
61 | self.chartLineColor = [UIColor blackColor];
62 | }
63 |
64 | /// This is a method which is called automatically when view is presented, or when phone changes orientation, or, for example, when user calls function setNeedsDisplay
65 | - (void)drawRect:(CGRect)rect {
66 | hcChartDrawer = [HCChartDrawer new];
67 | [self setContentMode:UIViewContentModeRedraw];
68 |
69 | #if TARGET_INTERFACE_BUILDER
70 | [self generateRandomDataForInterfaceBuilder];
71 | #endif
72 |
73 | [hcChartDrawer drawChart:self inRect:rect];
74 |
75 | }
76 |
77 | /// This method generates random data for interface builder presentation
78 | -(void)generateRandomDataForInterfaceBuilder
79 | {
80 | self.xElements = [NSMutableArray new];
81 | self.yElements = [NSMutableArray new];
82 | int averageXValue = arc4random_uniform(10000);
83 | int lastXValue = arc4random_uniform(averageXValue * 2) - averageXValue;
84 | int averageYValue = arc4random_uniform(10000);
85 | int lastYValue = arc4random_uniform(averageYValue * 2) - averageYValue;
86 |
87 | for (int i = 0 ; i < (self.chartLineWithCircles ? 20 : 100); i++)
88 | {
89 | [self.xElements addObject:@(lastXValue)];
90 | lastXValue += 1 + arc4random_uniform(10);
91 | [self.yElements addObject:@(lastYValue)];
92 | lastYValue += arc4random_uniform(21) - 10;
93 | }
94 | }
95 |
96 |
97 | -(void)drawChart
98 | {
99 | [self setNeedsDisplay];
100 | }
101 |
102 | -(void)updateChartWithXElements:(NSArray*)xElements yElements:(NSArray*)yElements
103 | {
104 | self.xElements = [xElements mutableCopy];
105 | self.yElements = [yElements mutableCopy];
106 | [self drawChart];
107 | }
108 | @end
109 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCSupporting Files/HCChartPoint/HCChartPoint.h:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartPoint.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | /// Helper class for storing single chart point / dot
12 | @interface HCChartPoint : NSObject
13 |
14 | /// This property defines X coordinate for chart point
15 | @property double x;
16 |
17 | /// This property defines Y coordinate for chart point
18 | @property double y;
19 |
20 | /// Contructor
21 | /// @param x X coordinate for chart point
22 | /// @param y Y coordinate for chart point
23 | /// @return Class insntance
24 | -(id)initWithX:(double)x andY:(double)y;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCSupporting Files/HCChartPoint/HCChartPoint.m:
--------------------------------------------------------------------------------
1 | //
2 | // HCChartPoint.m
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #import "HCChartPoint.h"
10 |
11 | @implementation HCChartPoint
12 |
13 | -(id)initWithX:(double)x andY:(double)y
14 | {
15 | self = [super init];
16 | self.x = x;
17 | self.y = y;
18 | return self;
19 | }
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCSupporting Files/HCEnums.h:
--------------------------------------------------------------------------------
1 | //
2 | // Header.h
3 | // HCLineChartView
4 | //
5 | // Created by Hypercube on 5/19/17.
6 | // Copyright © 2017 Hypercube. All rights reserved.
7 | //
8 |
9 | #ifndef Header_h
10 | #define Header_h
11 |
12 | /// This property defines chart type based on values on X asix. It is defined automatic.
13 | typedef enum HCChartType
14 | {
15 | chartWithNoDefinedValues,
16 | chartWithNumericalValues,
17 | chartWithDateValues,
18 | chartWithInvalidValues
19 | } HCChartType;
20 |
21 | /// This property defines if axis is horizontal (X axis) or vertical (Y axis)
22 | typedef enum HCAxis
23 | {
24 | xAxis,
25 | yAxis
26 | } HCAxis;
27 |
28 | /// This property defines chart style, i.e. if points in charts should be represented with simple dots (withoud circles) or with cirles
29 | typedef enum HCChartStyle
30 | {
31 | chartLineWithCircles,
32 | chartWithoutCircles
33 | } HCChartStyle;
34 |
35 |
36 | /// This property defines calendar type for the chart. It is used inside HCLineChartView library for displaying appropriate date / time values on X axis if values on X axis are represented as NSDate instances.
37 | typedef enum HCCalendarType
38 | {
39 | calendarWithYears,
40 | calendarWithMonths,
41 | calendarWithWeeks,
42 | calendarWithDays,
43 | calendarWithHours,
44 | calendarWithMinutes,
45 | calendarWithSeconds
46 | } HCCalendarType;
47 |
48 |
49 |
50 | #endif /* Header_h */
51 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCSupporting Files/HCTimeStep/HCTimeStep.h:
--------------------------------------------------------------------------------
1 | //
2 | // TimeStep.h
3 | // HCLineChartView
4 | //
5 | // Created by Vladimir Dinic on 7/18/17.
6 | // Copyright © 2017 Hypercube 2. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HCChartDrawer.h"
11 |
12 | /// Helper class for storing some information about tick size for date/time values if values on X axis are represented as date/time
13 | @interface HCTimeStep : NSObject
14 |
15 | /// This property defines time step, i.e. tick size in seconds.
16 | /// For example, if time step is 3 hours, then multiplier is 3 * 60 * 60 = 10800
17 | @property double multiplier;
18 |
19 | /// This property defines number of basic time units which define a time step.
20 | /// For example, if time step is 3 months, then multiplier is 3
21 | @property int value;
22 |
23 | /// This property defines time format, for example DD/MM/YYYY
24 | @property (retain, nonatomic) NSString* timeFormat;
25 |
26 | /// Boolean value which defines if alternative time format should be used. It is calculated runtime
27 | @property BOOL useAlternativeTimeFormat;
28 |
29 | /// This property defines alternative time format, for example DD/MM/YYYY HH:mm:ss. It is used in cases where we aren't sure which time format is best solution for given dates range and number of values. It is calculated runtime
30 | @property (retain, nonatomic) NSString* alternativeTimeFormat;
31 |
32 | /// This property defines calendar type, i.e. time unit. In other words, it defines if tick on X axis is represented in seconds, days, months, years,...
33 | @property HCCalendarType calendarType;
34 |
35 | /// This property defines referent, i.e. minimal range for using alternative time format. It is only valid if alternativeTimeFormat isn't nil.
36 | @property int referentRangeForAlternativeText;
37 |
38 | /// Creates and returns NSDateComponents instance required for calculation tick size and drawing values for X axis
39 | /// @return NSDateComponents instance required for calculation tick size and drawing values for X axis
40 | -(NSDateComponents*)dateComponent;
41 |
42 | /// Constructor for HCTimeStep class.
43 | /// @param multiplier Number of basic time units which define a time step
44 | /// @param calendarType Calendar type, i.e. time unit
45 | /// @param value Number of basic time units which define a time step
46 | /// @return Class instance generated with given parameters
47 | -(id)initWithTimeFormat:(NSString*)timeFormat withMultiplier:(double)multiplier calendarType:(HCCalendarType)calendarType value:(int)value;
48 |
49 | /// Constructor for HCTimeStep class.
50 | /// @param timeFormat Time format, for example DD/MM/YYYY
51 | /// @param alternativeTimeFormat Alternative time format, for example DD/MM/YYYY HH:mm:ss
52 | /// @param multiplier Number of basic time units which define a time step
53 | /// @param calendarType Calendar type, i.e. time unit
54 | /// @param value Number of basic time units which define a time step
55 | /// @param referentRangeForAlternativeText Numerical value which indicates minimal range for using alternative time format
56 | /// @return Class instance generated with given parameters
57 | -(id)initWithTimeFormat:(NSString*)timeFormat alternativeTimeFormat:(NSString*)alternativeTimeFormat withMultiplier:(double)multiplier calendarType:(HCCalendarType)calendarType value:(int)value referentRangeForAlternativeText:(int)referentRangeForAlternativeText;
58 |
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/Source/HCLineChartView/HCSupporting Files/HCTimeStep/HCTimeStep.m:
--------------------------------------------------------------------------------
1 | //
2 | // TimeStep.m
3 | // HCLineChartView
4 | //
5 | // Created by Vladimir Dinic on 7/18/17.
6 | // Copyright © 2017 Hypercube 2. All rights reserved.
7 | //
8 |
9 | #import "HCTimeStep.h"
10 |
11 | @implementation HCTimeStep
12 |
13 | -(id)initWithTimeFormat:(NSString *)timeFormat withMultiplier:(double)multiplier calendarType:(HCCalendarType)calendarType value:(int)value
14 | {
15 | if (self = [super init])
16 | {
17 | self.timeFormat = timeFormat;
18 | self.multiplier = multiplier;
19 | self.calendarType = calendarType;
20 | self.value = value;
21 | }
22 | return self;
23 | }
24 |
25 | -(id)initWithTimeFormat:(NSString*)timeFormat alternativeTimeFormat:(NSString*)alternativeTimeFormat withMultiplier:(double)multiplier calendarType:(HCCalendarType)calendarType value:(int)value referentRangeForAlternativeText:(int)referentRangeForAlternativeText
26 | {
27 | if (self = [super init])
28 | {
29 | self.timeFormat = timeFormat;
30 | self.alternativeTimeFormat = alternativeTimeFormat;
31 | self.multiplier = multiplier;
32 | self.calendarType = calendarType;
33 | self.value = value;
34 | self.referentRangeForAlternativeText = referentRangeForAlternativeText;
35 | }
36 | return self;
37 | }
38 |
39 | -(NSDateComponents*)dateComponent
40 | {
41 | switch (self.calendarType)
42 | {
43 | case calendarWithSeconds:
44 | {
45 | NSDateComponents* seconds = [NSDateComponents new];
46 | [seconds setSecond:self.value];
47 | return seconds;
48 | }
49 | case calendarWithMinutes:
50 | {
51 | NSDateComponents* minutes = [NSDateComponents new];
52 | [minutes setMinute:self.value];
53 | return minutes;
54 | }
55 | case calendarWithHours:
56 | {
57 | NSDateComponents* hours = [NSDateComponents new];
58 | [hours setHour:self.value];
59 | return hours;
60 | }
61 | case calendarWithDays:
62 | {
63 | NSDateComponents* days = [NSDateComponents new];
64 | [days setDay:self.value];
65 | return days;
66 | }
67 | case calendarWithWeeks:
68 | {
69 | NSDateComponents* weeks = [NSDateComponents new];
70 | [weeks setDay:self.value*7];
71 | return weeks;
72 | }
73 | case calendarWithMonths:
74 | {
75 | NSDateComponents* months = [NSDateComponents new];
76 | [months setMonth:self.value];
77 | return months;
78 | }
79 | case calendarWithYears:
80 | {
81 | NSDateComponents* years = [NSDateComponents new];
82 | [years setYear:self.value];
83 | return years;
84 | }
85 | default:
86 | break;
87 | }
88 | return nil;
89 | }
90 |
91 |
92 | @end
93 |
--------------------------------------------------------------------------------