mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-14 09:17:37 +00:00
made charts based on states and not based on metrics.
This commit is contained in:
@ -36,83 +36,84 @@ class AqiDistributionChart extends StatelessWidget {
|
||||
final stackItems = <BarChartRodData>[];
|
||||
double currentY = 0;
|
||||
|
||||
if (data.aqi != null) {
|
||||
if (data.good != null) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + data.aqi!,
|
||||
color: AirQualityDataModel.metricColors['aqi']!,
|
||||
toY: currentY + data.good!,
|
||||
color: AirQualityDataModel.metricColors['good']!,
|
||||
borderRadius: _barBorderRadius,
|
||||
width: _barWidth,
|
||||
),
|
||||
);
|
||||
currentY += data.aqi! + _rodStackItemsSpacing;
|
||||
currentY += data.good! + _rodStackItemsSpacing;
|
||||
}
|
||||
|
||||
if (data.pm25 != null) {
|
||||
if (data.moderate != null) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + data.pm25!,
|
||||
color: AirQualityDataModel.metricColors['pm25']!,
|
||||
toY: currentY + data.moderate!,
|
||||
color: AirQualityDataModel.metricColors['moderate']!,
|
||||
borderRadius: _barBorderRadius,
|
||||
width: _barWidth,
|
||||
),
|
||||
);
|
||||
currentY += data.pm25! + _rodStackItemsSpacing;
|
||||
currentY += data.moderate! + _rodStackItemsSpacing;
|
||||
}
|
||||
|
||||
if (data.pm10 != null) {
|
||||
if (data.poor != null) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + data.pm10!,
|
||||
color: AirQualityDataModel.metricColors['pm10']!,
|
||||
toY: currentY + data.poor!,
|
||||
color: AirQualityDataModel.metricColors['poor']!,
|
||||
borderRadius: _barBorderRadius,
|
||||
width: _barWidth,
|
||||
),
|
||||
);
|
||||
currentY += data.pm10! + _rodStackItemsSpacing;
|
||||
currentY += data.poor! + _rodStackItemsSpacing;
|
||||
}
|
||||
|
||||
if (data.hcho != null) {
|
||||
if (data.unhealthy != null) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + data.hcho!,
|
||||
color: AirQualityDataModel.metricColors['hcho']!,
|
||||
toY: currentY + data.unhealthy!,
|
||||
color: AirQualityDataModel.metricColors['unhealthy']!,
|
||||
borderRadius: _barBorderRadius,
|
||||
width: _barWidth,
|
||||
),
|
||||
);
|
||||
currentY += data.hcho! + _rodStackItemsSpacing;
|
||||
currentY += data.unhealthy! + _rodStackItemsSpacing;
|
||||
}
|
||||
|
||||
if (data.tvoc != null) {
|
||||
if (data.severe != null) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + data.tvoc!,
|
||||
color: AirQualityDataModel.metricColors['tvoc']!,
|
||||
toY: currentY + data.severe!,
|
||||
color: AirQualityDataModel.metricColors['severe']!,
|
||||
borderRadius: _barBorderRadius,
|
||||
width: _barWidth,
|
||||
),
|
||||
);
|
||||
currentY += data.tvoc! + _rodStackItemsSpacing;
|
||||
currentY += data.severe! + _rodStackItemsSpacing;
|
||||
}
|
||||
|
||||
if (data.co2 != null) {
|
||||
if (data.hazardous != null) {
|
||||
stackItems.add(
|
||||
BarChartRodData(
|
||||
fromY: currentY,
|
||||
toY: currentY + data.co2!,
|
||||
color: AirQualityDataModel.metricColors['co2']!,
|
||||
toY: currentY + data.hazardous!,
|
||||
color: AirQualityDataModel.metricColors['hazardous']!,
|
||||
borderRadius: _barBorderRadius,
|
||||
width: _barWidth,
|
||||
),
|
||||
);
|
||||
currentY += data.co2! + _rodStackItemsSpacing;
|
||||
currentY += data.hazardous! + _rodStackItemsSpacing;
|
||||
}
|
||||
|
||||
return BarChartGroupData(
|
||||
x: index,
|
||||
barRods: stackItems,
|
||||
@ -146,7 +147,8 @@ class AqiDistributionChart extends StatelessWidget {
|
||||
.key
|
||||
.toLowerCase();
|
||||
return TextSpan(
|
||||
text: '$metricName: ${item.toY - item.fromY}\n',
|
||||
text:
|
||||
'$metricName: ${(item.toY - item.fromY).toStringAsFixed(1)}%\n',
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
fontSize: 12,
|
||||
|
@ -26,31 +26,31 @@ class AqiDistributionChartBox extends StatelessWidget {
|
||||
child: AqiDistributionChart(
|
||||
chartData: [
|
||||
AirQualityDataModel(
|
||||
date: DateTime.now(),
|
||||
aqi: 20,
|
||||
pm25: 10,
|
||||
pm10: 40,
|
||||
co2: 10,
|
||||
hcho: 0,
|
||||
tvoc: 20,
|
||||
date: DateTime(2025, 5, 1),
|
||||
good: 30,
|
||||
moderate: 25,
|
||||
poor: 15,
|
||||
unhealthy: 10,
|
||||
severe: 15,
|
||||
hazardous: 5,
|
||||
),
|
||||
AirQualityDataModel(
|
||||
date: DateTime.now(),
|
||||
aqi: 20,
|
||||
pm25: 10,
|
||||
pm10: 40,
|
||||
co2: 10,
|
||||
hcho: 0,
|
||||
tvoc: 20,
|
||||
date: DateTime(2025, 5, 2),
|
||||
good: 40,
|
||||
moderate: 20,
|
||||
poor: 20,
|
||||
unhealthy: 10,
|
||||
severe: 5,
|
||||
hazardous: 5,
|
||||
),
|
||||
AirQualityDataModel(
|
||||
date: DateTime.now(),
|
||||
aqi: 20,
|
||||
pm25: 10,
|
||||
pm10: 40,
|
||||
co2: 10,
|
||||
hcho: 0,
|
||||
tvoc: 20,
|
||||
date: DateTime(2025, 5, 3),
|
||||
good: 35,
|
||||
moderate: 30,
|
||||
poor: 15,
|
||||
unhealthy: 10,
|
||||
severe: 5,
|
||||
hazardous: 5,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
Reference in New Issue
Block a user