From 3e8437ae559487362fae3525beb79c534c213a51 Mon Sep 17 00:00:00 2001
From: 单军华
Date: Thu, 12 Jul 2018 13:44:34 +0800
Subject: [PATCH] bug修复和功能优化

---
 screendisplay/screendisplay/Classes/检测/Controller/DynamicViewController.m |  372 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 372 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..3e346cf
--- /dev/null
+++ "b/screendisplay/screendisplay/Classes/\346\243\200\346\265\213/Controller/DynamicViewController.m"
@@ -0,0 +1,372 @@
+//
+//  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(AdaptedWidth(5), NavBar_Height+AdaptedHeight(26), SCREEN_WIDTH-AdaptedWidth(10), AdaptedHeight(354+26+30+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: [NSString stringWithFormat:@"%@���������������",self.detailModel.name] 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+3), 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+3), 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(15), 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 = 2.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])
+    {
+        if([self.detailModel.upper intValue] <= 1)
+        {
+            _historyRecordLineChart.yLineDataArr  = @[@"0.1",@"0.2",@"0.3",@"0.4",@"0.5",@"0.6",@"0.7",@"0.8",@"0.9",@"1"];
+        }
+        else
+        {
+            _historyRecordLineChart.yLineDataArr  = [NSMutableArray array];
+            float fMaxValue = [self.detailModel.upper floatValue];
+            if( fMaxValue < [self.detailModel.value floatValue])
+            {
+                fMaxValue = [self.detailModel.value 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(255, 255, 255)];
+    /* Colors for every line chart ������������������*/
+    _historyRecordLineChart.pointColorArr = @[RgbColor(36, 209, 215)];
+    
+    _historyRecordLineChart.xyFontSize = AdaptedWidth(7);
+    _historyRecordLineChart.numberFontSize = AdaptedWidth(10);
+    /* 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 = @[RgbColor(255, 255, 255)];
+    /*        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)
+            {
+                [weakself drawHistoryRecordLine];
+            }
+            else if(pageSize == 1)
+            {
+                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];
+                }
+                
+                [weakself.historyRecordLineChart.valueArr removeAllObjects];
+                [weakself.historyRecordLineChart.valueArr addObject:valueTeampArr];
+                [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