From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001 From: 单军华 Date: Wed, 11 Jul 2018 10:47:42 +0800 Subject: [PATCH] 首次上传 --- screendisplay/screendisplay/Classes/检测/Controller/DynamicViewController.m | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 362 insertions(+), 0 deletions(-) diff --git "a/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/DynamicViewController.m" "b/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/DynamicViewController.m" new file mode 100644 index 0000000..0615833 --- /dev/null +++ "b/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/DynamicViewController.m" @@ -0,0 +1,362 @@ +// +// DynamicViewController.m +// screendisplay +// +// Created by ��������� on 2018/7/10. +// Copyright �� 2018��� ���������. All rights reserved. +// + +#import "DynamicViewController.h" +#import "JHLineChart.h" +#import "DynamicService.h" + +@interface DynamicViewController () +{ + NSTimer * myTimer; // ������������������ +} + +/** digest */ +@property (nonatomic, strong) DynamicService *dynamicService; +/** digest */ +@property (nonatomic, strong) JHLineChart * historyRecordLineChart; + +@end + +@implementation DynamicViewController + +#pragma mark - getter + +- (DynamicService *)dynamicService +{ + if(_dynamicService == nil) + { + _dynamicService = [[DynamicService alloc] init]; + } + return _dynamicService; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. + + self.view.backgroundColor = kUIColorFromRGB(0x0b2f76); + + UIImageView * viewBackground = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(355))/2, NavBar_Height+AdaptedHeight(26), AdaptedWidth(355), AdaptedHeight(354+26+20+13+5+10+5))]; + viewBackground.image = [UIImage imageNamed:@"dynamic_back"]; + [self.view addSubview:viewBackground]; + + // 2, ��������������������� + CGSize aSize = CGSizeMake(kScreenWidth - 20, INFINITY); + + NSMutableAttributedString *attStrM0 = [[NSMutableAttributedString alloc] initWithString:@"PM2.5���������������" attributes:@{NSFontAttributeName : AdaptedFontSize(14), NSForegroundColorAttributeName : [UIColor whiteColor]}]; + attStrM0.yy_lineSpacing = 10; + YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:aSize text:attStrM0]; + + YYLabel *titelLabel = [[YYLabel alloc] init]; + titelLabel.backgroundColor = [UIColor clearColor]; + titelLabel.frame = CGRectMake((SCREEN_WIDTH-layout.textBoundingSize.width)/2, NavBar_Height+AdaptedHeight(26+13), layout.textBoundingSize.width, layout.textBoundingSize.height); + titelLabel.textLayout = layout; + [self.view addSubview:titelLabel]; + + UIImageView * icon_circle = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-layout.textBoundingSize.width)/2-10-10, NavBar_Height+AdaptedHeight(26+13+5), AdaptedWidth(10), AdaptedHeight(10))]; + icon_circle.image = [UIImage imageNamed:@"icon_circle"]; + [self.view addSubview:icon_circle]; + + UIImageView * icon_arrow = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-layout.textBoundingSize.width)/2+layout.textBoundingSize.width+10, NavBar_Height+AdaptedHeight(26+13+5), AdaptedWidth(10), AdaptedHeight(10))]; + icon_arrow.image = [UIImage imageNamed:@"icon_arrow"]; + [self.view addSubview:icon_arrow]; + + UILabel* unitLabel = [[UILabel alloc]initWithFrame:CGRectMake(AdaptedWidth(20), NavBar_Height+AdaptedHeight(26+13+5+10+5), AdaptedWidth(100), AdaptedHeight(20))]; + unitLabel.font = AdaptedFontSize(10); + unitLabel.textColor = kUIColorFromRGB(0x00fcff); + unitLabel.textAlignment = NSTextAlignmentLeft; + unitLabel.text = [NSString stringWithFormat:@"���������(%@)",self.detailModel.unit]; + [self.view addSubview:unitLabel]; + + //���1���������������function��������� + myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDynamicData) userInfo:nil repeats:YES]; + + [self GetDynamicDataList:8]; +} + + +-(void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:YES]; + + self.navigationController.navigationBarHidden = YES; + + if (myTimer == nil) + myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDynamicData) userInfo:nil repeats:YES]; + else + //��������������� + [myTimer setFireDate:[NSDate distantPast]]; +} + + +-(void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:YES]; + + //��������������� + if(myTimer) + [myTimer setFireDate:[NSDate distantFuture]]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +-(void) reDrawLine +{ +// if( modelArray.count == 10 ) +// { +// [_historyRecordLineChart.xLineDataArr removeAllObjects]; +// [_historyRecordLineChart.valueArr removeAllObjects]; +// } +// +// for (int i = 0; i < modelArray.count; i++) +// { +// //LiveDataModel * model = [modelArray objectAtIndex:i]; +// +// //[_historyRecordLineChart.valueArr addObject:model.x5]; +// [_historyRecordLineChart.xLineDataArr addObject:[NSString stringWithFormat:@"%d",i]]; +// } +// +// /*Start animation*/ +// [_historyRecordLineChart showAnimation]; +} + +-(void)drawHistoryRecordLine +{ + /* Create object */ + _historyRecordLineChart = [[JHLineChart alloc] initWithFrame:CGRectMake(AdaptedWidth(10), NavBar_Height+AdaptedHeight(39+50), SCREEN_WIDTH-AdaptedWidth(20), AdaptedHeight(354)) andLineChartType:JHChartLineEveryValueForEveryX]; + + /* The scale value of the X axis can be passed into the NSString or NSNumber type and the data structure changes with the change of the line chart type. The details look at the document or other quadrant X axis data source sample.*/ + + //co2LineChart.xLineDataArr = @[@"10:00",@"11:21",@"12:32",@"13:33",@"14:43",@"15:33",@"16:11",@"17:21"]; + + /* The different types of the broken line chart, according to the quadrant division, different quadrant correspond to different X axis scale data source and different value data source. */ + + _historyRecordLineChart.lineChartQuadrantType = JHLineChartQuadrantTypeFirstQuardrant; + + _historyRecordLineChart.lineWidth = 3.0; + _historyRecordLineChart.valueArr = [NSMutableArray array]; + NSMutableArray * valueTeampArr = [[NSMutableArray alloc] init]; + for (int i = 0; i < self.dynamicService.dynamicViewModels.count; i++) + { + DynamicModel * model = [self.dynamicService.dynamicViewModels objectAtIndex:i]; + + [valueTeampArr addObject:model.value]; + [_historyRecordLineChart.xLineDataArr addObject:[NSString stringWithFormat:@"%d",i]]; + } + + [_historyRecordLineChart.valueArr addObject:valueTeampArr]; + + [_historyRecordLineChart updateYScale]; + + /* ������������������������������*/ + _historyRecordLineChart.showYLevelLine = YES; + /* * whether this chart shows leading lines for value point or not,default is YES ������������������������������*/ + _historyRecordLineChart.showValueLeadingLine = NO; + //_historyRecordLineChart.showYLine = NO; + + if( [StringUtil isPureInt:self.detailModel.upper] || [StringUtil��isPureFloat:self.detailModel.upper]) + { + _historyRecordLineChart.yLineDataArr = [NSMutableArray array]; + float fMaxValue = [self.detailModel.upper floatValue]; + float fMinValue = 0;//[self.detailModel.lower floatValue]; + float fOffSetValue = fMaxValue - fMinValue; + float fAvgValue = fOffSetValue / 9; + int fCurrentValue = fAvgValue; + for (int index = 0; index < 10; index++) + { + if (index == 0) + { + fCurrentValue = fAvgValue; + } + else if(index == 9) + { + fCurrentValue = fMaxValue; + } + else + { + fCurrentValue = fCurrentValue+fAvgValue; + } + + NSString * currentStr = @""; + if(fCurrentValue < 0) + { + currentStr = [NSString stringWithFormat:@"-%d",fCurrentValue]; + } + else + { + currentStr = [NSString stringWithFormat:@"%d",fCurrentValue]; + } + + [_historyRecordLineChart.yLineDataArr addObject:currentStr]; + } + + } + else + { + _historyRecordLineChart.yLineDataArr = @[@"10",@"20",@"30",@"40",@"50",@"60",@"70",@"80",@"90",@"100"];//[NSMutableArray array]; + } + + // ������������ + /* Line Chart colors ������������ */ + _historyRecordLineChart.valueLineColorArr =@[RgbColor(143, 246, 218)]; + /* Colors for every line chart ������������������*/ + _historyRecordLineChart.pointColorArr = @[RgbColor(36, 209, 215)]; + + + /* color for XY axis XY������������������*/ + _historyRecordLineChart.xAndYLineColor = kUIColorFromRGB(0x00fcff); + /* XY axis scale color XY������������������������*/ + _historyRecordLineChart.xAndYNumberColor = kUIColorFromRGB(0x00fcff); + /* Dotted line color of the coordinate point */ + _historyRecordLineChart.positionLineColorArr = @[RgbColor(255, 255, 255)]; + /* ������������������������*/ + _historyRecordLineChart.pointNumberColorArr = @[[UIColor orangeColor]]; + /* Set whether to fill the content, the default is False ������������������������������ */ + _historyRecordLineChart.contentFill = NO; + /* Set whether the curve path */ + _historyRecordLineChart.pathCurve = YES; + /* Set fill color array ��������������������������������� */ + _historyRecordLineChart.contentFillColorArr = @[[UIColor orangeColor]]; + + [self.view addSubview:_historyRecordLineChart]; + /* Start animation */ + [_historyRecordLineChart showAnimation]; + + //GloriaLabel * timeTips = [[GloriaLabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-200)/2, 215+150, 200, 30)]; + //[timeTips setText:@"������(���)"]; + //timeTips.textColor = RgbColor(171, 172, 173); + //timeTips.textAlignment = UITextAlignmentCenter; + //timeTips.font = [UIFont boldSystemFontOfSize:14]; + //[self.view addSubview:timeTips]; + +} + +-(void)updateDynamicData +{ + [self GetDynamicDataList:1]; +} + +-(void)GetDynamicDataList:(int)pageSize +{ + NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; + [params setValue:[UserDefault stringForKey:@"mac"] forKey:@"mac"]; + [params setValue:self.detailModel.sensor_key forKey:@"sensorKey"]; + [params setValue:[NSString stringWithFormat:@"%d",pageSize] forKey:@"size"]; + + TWWeak(self); + [self.dynamicService getDynamicListWithParameters:params dataCount:pageSize completion:^(NSString *desc, int code) { + if(code == 1) + { + if( pageSize > 1) + { + [self drawHistoryRecordLine]; + } + else if(pageSize == 1) + { + NSMutableArray * historyRecordArr = [weakself.historyRecordLineChart.valueArr objectAtIndex:0]; + for (NSInteger i = 0; i < self.dynamicService.dynamicViewModels.count-1; i++) + { + [historyRecordArr replaceObjectAtIndex:i withObject:[historyRecordArr objectAtIndex:(i+1)]]; + } + + [historyRecordArr replaceObjectAtIndex:self.dynamicService.dynamicViewModels.count-1 withObject: self.dynamicService.dynamicViewModel.value]; + + [weakself.historyRecordLineChart clearLine]; + +// [weakself.historyRecordLineChart.xLineDataArr removeAllObjects]; +// [weakself.historyRecordLineChart.xLineDataArr addObjectsFromArray:self.dynamicService.dynamicViewModels]; +// [weakself.historyRecordLineChart clearLine]; + } + } + else + { + [Global alertMessageEx:desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + } + }]; +} + +#pragma mark - LMJNavUIBaseViewControllerDataSource + +- (UIStatusBarStyle)navUIBaseViewControllerPreferStatusBarStyle:(LMJNavUIBaseViewController *)navUIBaseViewController +{ + return UIStatusBarStyleDefault; +} + +/**������������*/ +- (NSMutableAttributedString*)lmjNavigationBarTitle:(LMJNavigationBar *)navigationBar +{ + return [self changeTitle:@"������������" changeColor:[UIColor whiteColor]]; +} + +//������������ +//- (UIImage *)lmjNavigationBarBackgroundImage:(LMJNavigationBar *)navigationBar +//{ +// return [UIImage imageNamed:@"map_top_bar_bk"]; +//} + +/** ��������� */ +- (UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar +{ + return kUIColorFromRGB(0x0b2f76); +} + +/** ������������������������ */ +- (BOOL)lmjNavigationIsHideBottomLine:(LMJNavigationBar *)navigationBar +{ + return YES; +} + +/** ������������������������ */ +- (UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar +{ + return [UIImage imageNamed:@"map_back"]; +} +/** ������������������������ */ +- (UIImage *)lmjNavigationBarRightButtonImage:(UIButton *)rightButton navigationBar:(LMJNavigationBar *)navigationBar +{ + //return [UIImage imageNamed:@"map_back"]; + + // [rightButton setTitle:@"������������" forState: UIControlStateNormal]; + // [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + // [rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted]; + // rightButton.titleLabel.font = [UIFont systemFontOfSize:15]; + // + // rightButton.lmj_width = 80; + + return nil; +} + +#pragma mark - LMJNavUIBaseViewControllerDelegate +/** ������������������������ */ +-(void)leftButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar +{ + [self.navigationController popViewControllerAnimated:YES]; + //[self dismissViewControllerAnimated:YES completion:nil]; +} + + +/** ������������������������ */ +-(void)rightButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar +{ + +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end -- Gitblit v1.8.0