ifish/Ifish/controllers/HotBar/Views/IfishChatView.m

183 lines
5.9 KiB
Objective-C

//
// IfishChatView.m
// Ifish
//
// Created by 罗艺 on 2018/8/27.
// Copyright © 2018年 lianlian. All rights reserved.
//
#import "IfishChatView.h"
#import "IfishHistroyVo.h"
#define Normal_heaterPh 499 //只有499才是正常流量
#define Rect_Width kSizeFrom750(568)
#define Origin_Left kSizeFrom750(72)
#define Rect_Height kSizeFrom750(185)
@interface IfishChatView()
@property(nonatomic,strong)NSMutableArray*line1;
@property(nonatomic,strong)UIView *lablesView;
@property(nonatomic,strong)UILabel*numLable;
Strong NSMutableArray * heaterPhArray;//流量走势
@end
@implementation IfishChatView
-(UILabel *)numLable{
if (_numLable==nil) {
_numLable=[[UILabel alloc]init];
[self addSubview:_numLable];
}
return _numLable;
}
-(NSArray *)line1{
if (_line1==nil) {
_line1=[NSMutableArray array];
}
[_line1 removeAllObjects];
if (_datas.count) {
// CGFloat gapW= 357*scale*0.1;
for (int i=0; i<self.datas.count; i++) {
IfishHistroyVo*vo=self.datas[i];
CGFloat x=Origin_Left +([vo.heaterGatheringTime floatValue]/24)*Rect_Width;
if(vo.heaterWaterTemperature.integerValue>350){
vo.heaterWaterTemperature=@"350";
}else if(vo.heaterWaterTemperature.integerValue<250){
continue;
}
CGFloat y=Rect_Height*(1-((vo.heaterWaterTemperature.integerValue*0.1-25)/10))+kSizeFrom750(43);//*-1*+158;
CGPoint p1=CGPointMake(x, y);
// NSLog(@"%f-------%f--%f-",y,vo.heaterWaterTemperature.integerValue*0.1,x);
[_line1 addObject:NSStringFromCGPoint(p1)];
}
}
return _line1;
}
-(void)setDatas:(NSArray *)datas{
NSSortDescriptor *ageSD = [NSSortDescriptor sortDescriptorWithKey:@"heaterGatheringTime_int" ascending:YES];
datas = [datas sortedArrayUsingDescriptors:@[ageSD]];
_datas=datas;
[self layoutIfNeeded];
}
-(NSMutableArray *)heaterPhArray{
if (!_heaterPhArray) {
_heaterPhArray = InitObject(NSMutableArray);
//添加流量
for (int i=0; i<23; i++) {
CGFloat x=(i*(Rect_Width/24)+Origin_Left);
CGFloat y=kSizeFrom750(236);
UIView *lineView = [[UIView alloc] initWithFrame:RECT(x, y, Rect_Width/24, 1)];
lineView.tag = i+100;
[self addSubview:lineView];
[_heaterPhArray addObject:lineView];
}
}
return _heaterPhArray;
}
//刷新流量状态
-(void)reloadHeater{
for (UIView *view in self.heaterPhArray) {
[view.layer removeAllAnimations];
}
for (int i=0; i<self.datas.count-1; i++) {
IfishHistroyVo*vo=self.datas[i];
IfishHistroyVo*nextVo=self.datas[i+1];
//如果有时间段的数据拿不到,则直接使用虚线
if ([nextVo.heaterGatheringTime integerValue]-[vo.heaterGatheringTime integerValue]>1) {
for (int i=[vo.heaterGatheringTime intValue]; i<[nextVo.heaterGatheringTime intValue]; i++) {
UIView *emptyView = [self viewWithTag:i+100];
[self drawDashLine:emptyView lineLength:2 lineSpacing:1 lineColor:[UIColor redColor]];
}
}else{
UIView *lineView = [self viewWithTag:[vo.heaterGatheringTime integerValue]+100];
if([vo.heaterPh integerValue]==Normal_heaterPh&&[nextVo.heaterPh integerValue]==Normal_heaterPh){//正常流量
lineView.layer.backgroundColor = [UIColor greenColor].CGColor;
}else{
[self drawDashLine:lineView lineLength:2 lineSpacing:1 lineColor:[UIColor redColor]];
}
}
}
}
-(void)drawLine{
UIColor *color = [UIColor redColor];
[color set]; //设置线条颜色
UIBezierPath* path = [UIBezierPath bezierPath];
path.lineWidth = 1.0;
path.lineCapStyle = kCGLineCapRound; //线条拐角
path.lineJoinStyle = kCGLineJoinRound; //终点处理
// Draw the lines
for (int i=0; i<self.line1.count; i++) {
NSString* p=self.line1[i];
if (i==0) {
[path moveToPoint:CGPointFromString(p)];//起点
}
[path addLineToPoint:CGPointFromString(p)];
}
// [path closePath];//第五条线通过调用closePath方法得到的
[path stroke];//Draws line 根据坐标点连线
}
/**
** lineView: 需要绘制成虚线的view
** lineLength: 虚线的宽度
** lineSpacing: 虚线的间距
** lineColor: 虚线的颜色
**/
-(void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:lineView.bounds];
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
// 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:lineColor.CGColor];
// 设置虚线宽度
[shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
[shapeLayer setLineJoin:kCALineJoinRound];
// 设置线宽,线间距
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
// 设置路径
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);
[shapeLayer setPath:path];
CGPathRelease(path);
// 把绘制好的虚线添加上来
[lineView.layer addSublayer:shapeLayer];
}
-(void)clickPoint:(UIButton*)btn{
IfishHistroyVo*vo=self.datas[btn.tag];
self.numLable.text=vo.heaterWaterTemperature;
}
-(void)clickPoint1:(UIButton*)btn{
IfishHistroyVo*vo=self.datas[btn.tag];
self.numLable.text=vo.heaterPh;
}
//
-(void)drawRect:(CGRect)rect{
[self drawLine];
}
@end