You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
269 lines
8.4 KiB
269 lines
8.4 KiB
// |
|
// ChartViewModel.swift |
|
// HPlusFit |
|
// |
|
// Created by lemo. on 2019/9/24. |
|
// Copyright © 2019 lemo. All rights reserved. |
|
// |
|
|
|
import Foundation |
|
|
|
enum ChartViewType { |
|
/// 折线(血压使用,两段折线) |
|
case polyline |
|
/// 火柴图 |
|
case stickMatch |
|
/// 渐变填充图 |
|
case gradentFill |
|
/// 直线图 |
|
case vertical |
|
/// 分段条形 |
|
case segmentBar |
|
/// 柱状分段条形图 |
|
case rectangleSegBar |
|
/// 水平分段图 |
|
case horizontalSegment |
|
/// 圆角柱状图(血氧) |
|
case roundBar |
|
/// 常规条形图 |
|
case regularBar |
|
/// 步数圆角条形图 |
|
case stepRoundBar |
|
/// hrv心电折线图 |
|
case hrvEcg |
|
// 体温折线图 |
|
case temp |
|
} |
|
|
|
/// 图例数据结构 |
|
struct LegendData { |
|
let docColor: UIColor |
|
let name: String |
|
} |
|
|
|
/// 睡眠数据结构 |
|
struct sleepData { |
|
var type: Int? |
|
var value: Float32? |
|
var begin: String? |
|
var end: String? |
|
|
|
init(type: Int?, value: Float32?) { |
|
self.type = type |
|
self.value = value |
|
} |
|
|
|
init(type: Int?, value: Float32?, begin: String?, end: String?) { |
|
self.type = type |
|
self.value = value |
|
self.begin = begin |
|
self.end = end |
|
} |
|
} |
|
|
|
struct ChartViewData { |
|
var date: String? |
|
var maxValue: Int = 0 |
|
var minValue: Int = 0 |
|
var aveValue: Int = 0 |
|
var value: Int = 0 |
|
var sleeps: [sleepData]? |
|
var sum: Float = 0 |
|
var number: Int = 0 |
|
var fallingsleepTimes: String = "" |
|
var awakeTimes: String = "" |
|
var sleep: sleepData? |
|
// 另一组值 |
|
var value2: Int = 0 |
|
/// 浮点值 |
|
var floatValue: CGFloat = 0 |
|
|
|
/// 图表模型 |
|
/// |
|
/// - Parameters: |
|
/// - date: 日期 |
|
/// - maxValue: 最大值, 默认:0 |
|
/// - aveValue: 平均值, 默认:0 |
|
/// - minValue: 最小值, 默认:0 |
|
/// - value: 当前值, 默认:0 |
|
init(date: String?, maxValue: Int = 0,aveValue: Int = 0, minValue: Int = 0, value: Int = 0, value2: Int = 0, floatValue: CGFloat = 0) { |
|
self.date = date |
|
self.maxValue = maxValue |
|
self.minValue = minValue |
|
self.aveValue = aveValue |
|
self.value = value |
|
self.value2 = value2 |
|
self.floatValue = floatValue |
|
} |
|
|
|
/// 睡眠图表数据初始化 |
|
/// |
|
/// - Parameters: |
|
/// - date: 日期 |
|
/// - number: 清醒次数,默认:0 |
|
/// - sum: 睡眠总时长, 默认:0.0 |
|
/// - sleeps: 睡眠详情数据 |
|
init(date: String?, number: Int = 0, sum: Float = 0.0, sleeps:[sleepData] = []) { |
|
self.date = date |
|
self.sleeps = sleeps |
|
self.sum = sum |
|
self.number = number |
|
} |
|
|
|
init(date: String?, number: Int = 0, sum: Float = 0.0, sleeps:[sleepData] = [],fallingsleepTimes: String = "", awakeTimes: String = "") { |
|
self.date = date |
|
self.sleeps = sleeps |
|
self.sum = sum |
|
self.number = number |
|
self.fallingsleepTimes = fallingsleepTimes |
|
self.awakeTimes = awakeTimes |
|
} |
|
|
|
/// 日睡眠数据初始化 |
|
init(sleep: sleepData?) { |
|
self.sleep = sleep |
|
} |
|
} |
|
|
|
struct ChartViewModel { |
|
var leftIcon: String? |
|
var title: String? |
|
var legends: Array<LegendData>? |
|
var source: Array<ChartViewData>? |
|
var chartType: ChartViewType = .polyline |
|
var maxAxis: Int? |
|
var lineColor: UIColor? |
|
var xAxis: [String]? |
|
var rightTime: String = "" |
|
var points: Int = 0 // 实际绘制的点个数 |
|
var maxpoints: Int = 0 // 能显示的最多点个数 |
|
var isContinuous: Bool = true //折线是否连续 |
|
var isShowMeasureLine: Bool = false //是否显示测量线 |
|
var isDrawAvgLine: Bool = false // 是否绘制平均值线 |
|
// 中心值 && 单位 |
|
var centerColor: UIColor? = nil |
|
var centerValue: String? = nil |
|
var centerUnitValue: String? = nil |
|
// 浮点值数据 |
|
var floatMaxAxis: CGFloat = 0 |
|
|
|
init() { |
|
|
|
} |
|
|
|
init(leftIcon: String?, title: String?) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
} |
|
|
|
init(title: String?, rightTime: String) { |
|
self.title = title |
|
self.rightTime = rightTime |
|
} |
|
|
|
init(leftIcon: String?, title: String?, rightTime: String) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.rightTime = rightTime |
|
} |
|
|
|
init(leftIcon: String?, title: String?, legends: Array<LegendData>?, source: Array<ChartViewData>?, chartType: ChartViewType) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.legends = legends |
|
self.source = source |
|
self.chartType = chartType |
|
} |
|
|
|
init(leftIcon: String?, title: String?, source: Array<ChartViewData>?,chartType: ChartViewType,maxAxis: Int?) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.source = source |
|
self.chartType = chartType |
|
self.maxAxis = maxAxis |
|
} |
|
|
|
init(leftIcon: String?, title: String?, legends: Array<LegendData>?, source: Array<ChartViewData>?, chartType: ChartViewType, maxAxis: Int?) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.legends = legends |
|
self.source = source |
|
self.chartType = chartType |
|
self.maxAxis = maxAxis |
|
} |
|
|
|
init(leftIcon: String?, title: String?, legends: Array<LegendData>?, source: Array<ChartViewData>?, chartType: ChartViewType, maxAxis: Int?, xAxis: [String]?, isShowMeasureLine: Bool = false) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.legends = legends |
|
self.source = source |
|
self.chartType = chartType |
|
self.maxAxis = maxAxis |
|
self.xAxis = xAxis |
|
self.isShowMeasureLine = isShowMeasureLine |
|
} |
|
|
|
init(leftIcon: String?, title: String?, legends: Array<LegendData>?, source: Array<ChartViewData>?, chartType: ChartViewType, maxAxis: Int?, lineColor: UIColor?, isShowMeasureLine: Bool = false, center: String? = nil, centerColor: UIColor? = nil, centerUnit: String? = nil) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.legends = legends |
|
self.source = source |
|
self.chartType = chartType |
|
self.maxAxis = maxAxis |
|
self.lineColor = lineColor |
|
self.isShowMeasureLine = isShowMeasureLine |
|
self.centerValue = center |
|
self.centerColor = centerColor |
|
self.centerUnitValue = centerUnit |
|
} |
|
|
|
|
|
/// 图表模型初始化 |
|
/// |
|
/// - Parameters: |
|
/// - leftIcon: 图表图表 |
|
/// - title: 标题 |
|
/// - legends: 图例 |
|
/// - source: 图表数据 |
|
/// - chartType: 图表类型 |
|
/// - maxAxis: 最大值 |
|
/// - xAxis: x轴坐标 |
|
/// - lineColor: 线的颜色 |
|
/// - points: 实际绘制的点 |
|
/// - maxpoints: 能绘制的最多点数 |
|
/// - isContinuous: 折线是否连续,默认连续 |
|
/// - isDrawAvgLine: 是否绘制平均值折线 |
|
init(leftIcon: String?, title: String?, legends: Array<LegendData>?, source: Array<ChartViewData>?, chartType: ChartViewType, maxAxis: Int?,xAxis: [String]?, lineColor: UIColor?, points: Int = 0, maxpoints: Int = 0,isContinuous: Bool = true,isShowMeasureLine: Bool = false, isDrawAvgLine: Bool = false, center: String? = nil, centerColor: UIColor? = nil, centerUnit: String? = nil) { |
|
self.leftIcon = leftIcon |
|
self.title = title |
|
self.legends = legends |
|
self.source = source |
|
self.chartType = chartType |
|
self.maxAxis = maxAxis |
|
self.xAxis = xAxis |
|
self.lineColor = lineColor |
|
self.points = points |
|
self.maxpoints = maxpoints |
|
self.isContinuous = isContinuous |
|
self.isShowMeasureLine = isShowMeasureLine |
|
self.isDrawAvgLine = isDrawAvgLine |
|
self.centerValue = center |
|
self.centerColor = centerColor |
|
self.centerUnitValue = centerUnit |
|
} |
|
|
|
/// 体温使用 |
|
init(source: Array<ChartViewData>?, chartType: ChartViewType, floatMaxAxis: CGFloat, xAxis: [String]?, lineColor: UIColor, isContinuous: Bool, isShowMeasureLine: Bool, center: String, centerColor: UIColor, centerUnit: String? = nil) { |
|
self.source = source |
|
self.chartType = chartType |
|
self.floatMaxAxis = floatMaxAxis |
|
self.xAxis = xAxis |
|
self.lineColor = lineColor |
|
self.isContinuous = isContinuous |
|
self.isShowMeasureLine = isShowMeasureLine |
|
self.centerValue = center |
|
self.centerColor = centerColor |
|
self.centerUnitValue = centerUnit |
|
} |
|
|
|
}
|
|
|