mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Refactored RangeOfAqiChart
to consolidate line chart creation into a reusable method, improving code maintainability and reducing duplication.
This commit is contained in:
@ -65,46 +65,26 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
}
|
||||
|
||||
LineChartBarData _buildMinLine() {
|
||||
return LineChartBarData(
|
||||
spots: List.generate(
|
||||
minValues.length,
|
||||
(i) => FlSpot(i.toDouble(), minValues[i]),
|
||||
),
|
||||
isCurved: true,
|
||||
return _buildLine(
|
||||
values: minValues,
|
||||
color: const Color(0xFF93AAFD),
|
||||
barWidth: 3,
|
||||
isStrokeCapRound: true,
|
||||
dotData: _buildDotData(const Color(0xFF023DFE)),
|
||||
belowBarData: BarAreaData(show: false),
|
||||
dotColor: const Color(0xFF023DFE),
|
||||
);
|
||||
}
|
||||
|
||||
LineChartBarData _buildAverageLine() {
|
||||
return LineChartBarData(
|
||||
spots: List.generate(
|
||||
avgValues.length,
|
||||
(i) => FlSpot(i.toDouble(), avgValues[i]),
|
||||
),
|
||||
isCurved: true,
|
||||
return _buildLine(
|
||||
values: avgValues,
|
||||
color: Colors.white,
|
||||
barWidth: 3,
|
||||
dotData: const FlDotData(show: false),
|
||||
belowBarData: BarAreaData(show: false),
|
||||
dotColor: null,
|
||||
);
|
||||
}
|
||||
|
||||
LineChartBarData _buildMaxLine() {
|
||||
return LineChartBarData(
|
||||
spots: List.generate(
|
||||
maxValues.length,
|
||||
(i) => FlSpot(i.toDouble(), maxValues[i]),
|
||||
),
|
||||
isCurved: true,
|
||||
return _buildLine(
|
||||
values: maxValues,
|
||||
color: const Color(0xFF962DFF),
|
||||
barWidth: 3,
|
||||
isStrokeCapRound: true,
|
||||
dotData: _buildDotData(const Color(0xFF5F00BD)),
|
||||
belowBarData: BarAreaData(show: false),
|
||||
dotColor: const Color(0xFF5F00BD),
|
||||
);
|
||||
}
|
||||
|
||||
@ -120,6 +100,26 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
LineChartBarData _buildLine({
|
||||
required List<double> values,
|
||||
required Color color,
|
||||
Color? dotColor,
|
||||
}) {
|
||||
return LineChartBarData(
|
||||
spots: List.generate(
|
||||
values.length,
|
||||
(i) => FlSpot(i.toDouble(), values[i]),
|
||||
),
|
||||
isCurved: true,
|
||||
color: color,
|
||||
barWidth: 4,
|
||||
isStrokeCapRound: true,
|
||||
dotData:
|
||||
dotColor != null ? _buildDotData(dotColor) : const FlDotData(show: false),
|
||||
belowBarData: BarAreaData(show: false),
|
||||
);
|
||||
}
|
||||
|
||||
FlTitlesData _titlesData(BuildContext context) {
|
||||
final titlesData = EnergyManagementChartsHelper.titlesData(context);
|
||||
return titlesData.copyWith(
|
||||
|
Reference in New Issue
Block a user