Commit 7408f0a99e5b97257f8c095f4f0d9d352478a298
1 parent
4895c174ce
Exists in
master
and in
1 other branch
Add bar graph in history screen
Showing 4 changed files with 81 additions and 19 deletions Side-by-side Diff
LifeLog/LifeLog/HistoryViewController.h
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import <UIKit/UIKit.h> |
10 | +#import <Charts/Charts-Swift.h> | |
10 | 11 | |
11 | 12 | #import "CollectionView.h" |
12 | 13 | |
... | ... | @@ -16,6 +17,8 @@ |
16 | 17 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionTime; |
17 | 18 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType; |
18 | 19 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionShare; |
20 | + | |
21 | +@property (weak, nonatomic) IBOutlet BarChartView *viewBarChart; | |
19 | 22 | |
20 | 23 | @property (weak, nonatomic) IBOutlet UITableView *tableListHistory; |
21 | 24 | @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; |
LifeLog/LifeLog/HistoryViewController.m
... | ... | @@ -23,6 +23,27 @@ |
23 | 23 | self.title = NSLocalizedString(@"lifelog.tapbar.history", nil); |
24 | 24 | self.lblHeader.text = NSLocalizedString(@"lifelog.tapbar.history", nil); |
25 | 25 | |
26 | + [self setupView]; | |
27 | + [self setupChartView]; | |
28 | + //register nib for table view | |
29 | + [self.tableListHistory registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; | |
30 | +} | |
31 | + | |
32 | +- (void)viewDidAppear:(BOOL) animated | |
33 | +{ | |
34 | + [super viewDidAppear:animated]; | |
35 | + self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); | |
36 | + [self.scrollView setNeedsLayout]; | |
37 | + [self.scrollView setNeedsUpdateConstraints]; | |
38 | + | |
39 | +} | |
40 | + | |
41 | +- (void)didReceiveMemoryWarning { | |
42 | + [super didReceiveMemoryWarning]; | |
43 | + // Dispose of any resources that can be recreated. | |
44 | +} | |
45 | + | |
46 | +- (void)setupView { | |
26 | 47 | [self.viewCollectionTime setButtonNumber:5]; |
27 | 48 | [self.viewCollectionTime setSpacing:2]; |
28 | 49 | [self.viewCollectionTime setArrayTitle:[NSArray arrayWithObjects:@"1日", @"1週間", @"1ヶ月", @"3ヶ月", @"6ヶ月", nil]]; |
29 | 50 | |
30 | 51 | |
... | ... | @@ -37,22 +58,58 @@ |
37 | 58 | [self.viewCollectionShare setSpacing:3]; |
38 | 59 | [self.viewCollectionShare setSelectedIndex:-1]; |
39 | 60 | [self.viewCollectionShare setArrayTitle:[NSArray arrayWithObjects:@"facebook", @"twitter", @"line", @"メール", @"その他", nil]]; |
40 | - | |
41 | - [self.tableListHistory registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; | |
42 | 61 | } |
43 | 62 | |
44 | -- (void)viewDidAppear:(BOOL) animated | |
45 | -{ | |
46 | - [super viewDidAppear:animated]; | |
47 | - self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); | |
48 | - [self.scrollView setNeedsLayout]; | |
49 | - [self.scrollView setNeedsUpdateConstraints]; | |
50 | - | |
51 | -} | |
63 | +- (void)setupChartView { | |
64 | + self.viewBarChart.chartDescription.enabled = NO; | |
65 | + self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; | |
66 | + self.viewBarChart.rightAxis.drawGridLinesEnabled = NO; | |
67 | + self.viewBarChart.legend.enabled = NO; | |
52 | 68 | |
53 | -- (void)didReceiveMemoryWarning { | |
54 | - [super didReceiveMemoryWarning]; | |
55 | - // Dispose of any resources that can be recreated. | |
69 | + ChartXAxis *xAxis = self.viewBarChart.xAxis; | |
70 | + xAxis.labelPosition = XAxisLabelPositionBottom; | |
71 | + xAxis.drawGridLinesEnabled = NO; | |
72 | + xAxis.drawAxisLineEnabled = NO; | |
73 | + xAxis.drawLabelsEnabled = YES; | |
74 | + xAxis.labelPosition = XAxisLabelPositionBottom; | |
75 | + xAxis.labelFont = [UIFont systemFontOfSize:10.f]; | |
76 | + xAxis.labelTextColor = [UIColor whiteColor]; | |
77 | + xAxis.granularity = 1.0; // only intervals of 1 day | |
78 | + xAxis.labelCount = 8; | |
79 | + | |
80 | + self.viewBarChart.leftAxis.drawAxisLineEnabled = NO; | |
81 | + self.viewBarChart.rightAxis.drawAxisLineEnabled = NO; | |
82 | + | |
83 | + /*fake data for test*/ | |
84 | + NSMutableArray *yVals = [[NSMutableArray alloc] init]; | |
85 | + | |
86 | + for (int i = 0; i < 24; i++) | |
87 | + { | |
88 | + double val = (double) (arc4random_uniform(100)); | |
89 | + [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:val]]; | |
90 | + } | |
91 | + | |
92 | + BarChartDataSet *set1 = nil; | |
93 | + if (self.viewBarChart.data.dataSetCount > 0) | |
94 | + { | |
95 | + set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; | |
96 | + set1.values = yVals; | |
97 | + [self.viewBarChart.data notifyDataChanged]; | |
98 | + [self.viewBarChart notifyDataSetChanged]; | |
99 | + } | |
100 | + else | |
101 | + { | |
102 | + set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; | |
103 | + [set1 setColor:[UIColor whiteColor]]; | |
104 | + | |
105 | + NSMutableArray *dataSets = [[NSMutableArray alloc] init]; | |
106 | + [dataSets addObject:set1]; | |
107 | + | |
108 | + BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; | |
109 | + data.barWidth = 0.5f; | |
110 | + | |
111 | + self.viewBarChart.data = data; | |
112 | + } | |
56 | 113 | } |
57 | 114 | |
58 | 115 | #pragma mark UITableView Delegate |
LifeLog/LifeLog/HistoryViewController.xib
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | |
2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | |
3 | 3 | <device id="retina4_7" orientation="portrait"> |
4 | 4 | <adaptation id="fullscreen"/> |
5 | 5 | </device> |
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | <outlet property="scrollView" destination="rey-N3-l8b" id="s3w-fi-n5l"/> |
16 | 16 | <outlet property="tableListHistory" destination="FXQ-4O-sRc" id="VNN-sx-9xu"/> |
17 | 17 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
18 | + <outlet property="viewBarChart" destination="VqD-Y3-cYQ" id="RdJ-G5-pPy"/> | |
18 | 19 | <outlet property="viewCollectionShare" destination="Iw2-nW-e7g" id="LW3-j0-yEY"/> |
19 | 20 | <outlet property="viewCollectionTime" destination="yxY-4d-tB6" id="jp8-TP-N5g"/> |
20 | 21 | <outlet property="viewCollectionType" destination="BVv-qD-EHM" id="0MR-m4-P1Y"/> |
... | ... | @@ -362,9 +363,9 @@ |
362 | 363 | <constraint firstItem="j5h-QD-Igf" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="trailing" id="zOb-WE-3CI"/> |
363 | 364 | </constraints> |
364 | 365 | </view> |
365 | - <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VqD-Y3-cYQ"> | |
366 | - <rect key="frame" x="20" y="201" width="335" height="100"/> | |
367 | - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | |
366 | + <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VqD-Y3-cYQ" customClass="BarChartView" customModule="Charts"> | |
367 | + <rect key="frame" x="0.0" y="201" width="375" height="100"/> | |
368 | + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | |
368 | 369 | <constraints> |
369 | 370 | <constraint firstAttribute="height" constant="100" id="aQR-hf-MhR"/> |
370 | 371 | </constraints> |
... | ... | @@ -382,7 +383,7 @@ |
382 | 383 | <constraint firstItem="VqD-Y3-cYQ" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="bottom" constant="8" id="0BA-6p-JLT"/> |
383 | 384 | <constraint firstItem="Iw2-nW-e7g" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="2lH-sF-Mp0"/> |
384 | 385 | <constraint firstItem="iEh-Ze-suq" firstAttribute="top" secondItem="4ix-HE-d9T" secondAttribute="bottom" constant="8" id="9Sm-IQ-feL"/> |
385 | - <constraint firstItem="VqD-Y3-cYQ" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="Gbd-bD-rFf"/> | |
386 | + <constraint firstItem="VqD-Y3-cYQ" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" id="Gbd-bD-rFf"/> | |
386 | 387 | <constraint firstItem="4ix-HE-d9T" firstAttribute="top" secondItem="Cam-ML-IEO" secondAttribute="top" constant="30" id="JyQ-KD-MhR"/> |
387 | 388 | <constraint firstAttribute="trailing" secondItem="iEh-Ze-suq" secondAttribute="trailing" constant="20" id="RcZ-yN-56e"/> |
388 | 389 | <constraint firstAttribute="trailing" secondItem="Iw2-nW-e7g" secondAttribute="trailing" constant="20" id="Xso-Or-Fgf"/> |
... | ... | @@ -392,7 +393,7 @@ |
392 | 393 | <constraint firstItem="Iw2-nW-e7g" firstAttribute="top" secondItem="VqD-Y3-cYQ" secondAttribute="bottom" constant="15" id="ekR-kS-L5v"/> |
393 | 394 | <constraint firstItem="Kzk-mN-AOf" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="hFq-WM-gLq"/> |
394 | 395 | <constraint firstItem="4ix-HE-d9T" firstAttribute="leading" secondItem="Kzk-mN-AOf" secondAttribute="trailing" constant="8" id="hzO-hA-cNG"/> |
395 | - <constraint firstAttribute="trailing" secondItem="VqD-Y3-cYQ" secondAttribute="trailing" constant="20" id="ptF-2O-CNR"/> | |
396 | + <constraint firstAttribute="trailing" secondItem="VqD-Y3-cYQ" secondAttribute="trailing" id="ptF-2O-CNR"/> | |
396 | 397 | <constraint firstItem="iEh-Ze-suq" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="u5o-P4-qkL"/> |
397 | 398 | </constraints> |
398 | 399 | </view> |