diff --git a/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultColumns.swift b/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultColumns.swift index fe221f5a..ffd86987 100644 --- a/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultColumns.swift +++ b/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultColumns.swift @@ -198,6 +198,52 @@ extension MetricsColumnList { } ?? Text(verbatim: Constants.nilValueIndicator) }), + // Rainfall 1-hour + MetricsTableColumn( + id: "rainfall1H", + keyPath: \.rainfall1H, + name: "Rainfall (1H)", + abbreviatedName: "Rain 1H", + minWidth: 30, maxWidth: 60, + visible: false, + tableBody: { _, rainfall in + rainfall.map { + let rain = Measurement( + value: Double($0), unit: UnitLength.millimeters) + return Text( + rain.formatted( + .measurement( + width: .abbreviated, + numberFormatStyle: .number.grouping(.never) + .precision( + .fractionLength(0)))) + ) + } ?? Text(Constants.nilValueIndicator) + }), + + // Rainfall 24-hour + MetricsTableColumn( + id: "rainfall24H", + keyPath: \.rainfall24H, + name: "Rainfall (24H)", + abbreviatedName: "Rain 24H", + minWidth: 30, maxWidth: 60, + visible: false, + tableBody: { _, rainfall in + rainfall.map { + let rain = Measurement( + value: Double($0), unit: UnitLength.millimeters) + return Text( + rain.formatted( + .measurement( + width: .abbreviated, + numberFormatStyle: .number.grouping(.never) + .precision( + .fractionLength(0)))) + ) + } ?? Text(Constants.nilValueIndicator) + }), + // Weight MetricsTableColumn( id: "weight", diff --git a/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultSeries.swift b/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultSeries.swift index 1db9b025..d3762845 100644 --- a/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultSeries.swift +++ b/Meshtastic/Views/Nodes/Helpers/Metrics Columns/EnvironmentDefaultSeries.swift @@ -266,6 +266,98 @@ extension MetricsSeriesList { } }), + // Combined Wind Speed and Direction Series Configuration -- For use in Chart only + MetricsChartSeries( + id: "windSpeedAndDirection", + keyPath: \.windSpeedAndDirection, + name: "Wind Speed/Direction", + abbreviatedName: "Speed/Dir", + visible: false, + foregroundStyle: { _ in + .linearGradient( + colors: [Color(UIColor.yellow.darker(componentDelta: 0.3)), Color(UIColor.yellow.darker(componentDelta: 0.1))], + startPoint: .bottom, endPoint: .top + ) + }, + chartBody: { series, _, time, wsad in + if let wsad { + // debug data: var wsad = WindSpeedAndDirection(windSpeed:Float.random(in:0...25), windDirection: Int32.random(in:0..<3)*90 ) + LineMark( + x: .value("Time", time), + y: .value(series.abbreviatedName, wsad.windSpeed) + ) + .interpolationMethod(.catmullRom) + .foregroundStyle(by: .value("Series", series.abbreviatedName)) + .lineStyle(StrokeStyle(lineWidth: 4)) + .alignsMarkStylesWithPlotArea() + PointMark( + x: .value("Time", time), + y: .value(series.abbreviatedName, wsad.windSpeed) + ) + .symbol { + if let wd = wsad.windDirection { + Image(systemName: "location.north.circle.fill") + .symbolRenderingMode(.palette) + .foregroundStyle(Color.white, Color(UIColor.yellow.darker(componentDelta: 0.3))) + .rotationEffect( + .degrees(Double(wd))) + } + }.foregroundStyle(.yellow) + } + }), + + // Rainfaill 1-hour + MetricsChartSeries( + id: "rainfall1H", + keyPath: \.rainfall1H, + name: "Rainfall 1H", + abbreviatedName: "Rain 1H", + visible: false, + foregroundStyle: { _ in + .linearGradient( + colors: [Color(UIColor.systemBlue.darker(componentDelta: 0.5)), .blue], + startPoint: .bottom, endPoint: .top + ) + }, + chartBody: { series, _, time, rainfall in + if let rainfall { + LineMark( + x: .value("Time", time), + y: .value(series.abbreviatedName, rainfall) + ) + .interpolationMethod(.catmullRom) + .foregroundStyle(by: .value("Series", series.abbreviatedName)) + .lineStyle(StrokeStyle(lineWidth: 4)) + .alignsMarkStylesWithPlotArea() + } + }), + + // Rainfaill 24-hour + MetricsChartSeries( + id: "rainfall24H", + keyPath: \.rainfall24H, + name: "Rainfall 24H", + abbreviatedName: "Rain 24H", + visible: false, + foregroundStyle: { _ in + .linearGradient( + colors: [Color(UIColor.systemBlue.darker(componentDelta: 0.5)), .cyan], + startPoint: .bottom, endPoint: .top + ) + }, + chartBody: { series, _, time, rainfall in + if let rainfall { + LineMark( + x: .value("Time", time), + y: .value(series.abbreviatedName, rainfall) + ) + .interpolationMethod(.catmullRom) + .foregroundStyle(by: .value("Series", series.abbreviatedName)) + .lineStyle(StrokeStyle(lineWidth: 4)) + .alignsMarkStylesWithPlotArea() + } + }), + // Weight MetricsChartSeries( id: "weight", @@ -369,46 +461,6 @@ extension MetricsSeriesList { .alignsMarkStylesWithPlotArea() } }), - - // Combined Wind Speed and Direction Series Configuration -- For use in Chart only - MetricsChartSeries( - id: "windSpeedAndDirection", - keyPath: \.windSpeedAndDirection, - name: "Wind Speed/Direction", - abbreviatedName: "Speed/Dir", - visible: false, - foregroundStyle: { _ in - .linearGradient( - colors: [Color(UIColor.yellow.darker(componentDelta: 0.3)), Color(UIColor.yellow.darker(componentDelta: 0.1))], - startPoint: .bottom, endPoint: .top - ) - }, - chartBody: { series, _, time, wsad in - if let wsad { - // debug data: var wsad = WindSpeedAndDirection(windSpeed:Float.random(in:0...25), windDirection: Int32.random(in:0..<3)*90 ) - LineMark( - x: .value("Time", time), - y: .value(series.abbreviatedName, wsad.windSpeed) - ) - .interpolationMethod(.catmullRom) - .foregroundStyle(by: .value("Series", series.abbreviatedName)) - .lineStyle(StrokeStyle(lineWidth: 4)) - .alignsMarkStylesWithPlotArea() - PointMark( - x: .value("Time", time), - y: .value(series.abbreviatedName, wsad.windSpeed) - ) - .symbol { - if let wd = wsad.windDirection { - Image(systemName: "location.north.circle.fill") - .symbolRenderingMode(.palette) - .foregroundStyle(Color.white, Color(UIColor.yellow.darker(componentDelta: 0.3))) - .rotationEffect( - .degrees(Double(wd))) - } - }.foregroundStyle(.yellow) - } - }) ]) } }