This commit is contained in:
kleponijo 2026-04-23 17:09:22 +07:00
parent c9221e45f6
commit 4b01a7e41b
1 changed files with 54 additions and 6 deletions

View File

@ -10,8 +10,20 @@ class WindSpeedChartWidget extends StatelessWidget {
const WindSpeedChartWidget( const WindSpeedChartWidget(
{super.key, required this.dailySpeeds, required this.period}); {super.key, required this.dailySpeeds, required this.period});
double _getMaxY() {
if (dailySpeeds.isEmpty) return 10;
final max = dailySpeeds.reduce((a, b) => a > b ? a : b);
return (max + 5).clamp(10, 100); // kasih padding
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<double> safeData = dailySpeeds.map((e) {
if (e.isNaN || e.isInfinite) return 0.0;
return e < 0 ? 0.0 : e;
}).toList();
return Container( return Container(
height: 270, height: 270,
padding: const EdgeInsets.fromLTRB(10, 20, 20, 10), padding: const EdgeInsets.fromLTRB(10, 20, 20, 10),
@ -27,9 +39,12 @@ class WindSpeedChartWidget extends StatelessWidget {
], ],
), ),
child: LineChart( child: LineChart(
duration: const Duration(milliseconds: 600),
curve: Curves.easeOutCubic,
LineChartData( LineChartData(
minY: 0, minY: 0,
maxY: 50,
maxY: _getMaxY(),
gridData: const FlGridData(show: false), gridData: const FlGridData(show: false),
borderData: FlBorderData(show: false), borderData: FlBorderData(show: false),
@ -61,27 +76,60 @@ class WindSpeedChartWidget extends StatelessWidget {
}))), }))),
lineBarsData: [ lineBarsData: [
LineChartBarData( LineChartBarData(
spots: dailySpeeds.asMap().entries.map((e) { spots: safeData.asMap().entries.map((e) {
return FlSpot(e.key.toDouble(), e.value); return FlSpot(e.key.toDouble(), e.value);
}).toList(), }).toList(),
isCurved: true, isCurved: true,
curveSmoothness: 0.2,
preventCurveOverShooting: true,
color: Colors.blue.shade700, color: Colors.blue.shade700,
barWidth: 4, barWidth: 3,
isStrokeCapRound: true, isStrokeCapRound: true,
dotData: const FlDotData(show: false), dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, bar, index) {
if (index == dailySpeeds.length - 1) {
return FlDotCirclePainter(
radius: 5,
color: Colors.red,
strokeWidth: 2,
strokeColor: Colors.white,
);
}
return FlDotCirclePainter(radius: 0);
},
),
belowBarData: BarAreaData( belowBarData: BarAreaData(
show: true, show: true,
gradient: LinearGradient( gradient: LinearGradient(
colors: [ colors: [
Colors.blue.withOpacity(0.3), Colors.blue.withOpacity(0.35),
Colors.blue.withOpacity(0.0) Colors.blue.withOpacity(0.1),
Colors.transparent
], ],
begin: Alignment.topCenter, begin: Alignment.topCenter,
end: Alignment.bottomCenter, end: Alignment.bottomCenter,
), ),
), ),
shadow: Shadow(
color: Colors.blue.withOpacity(0.3),
blurRadius: 6,
),
), ),
], ],
lineTouchData: LineTouchData(
handleBuiltInTouches: true,
touchTooltipData: LineTouchTooltipData(
getTooltipItems: (touchedSpots) {
return touchedSpots.map((spot) {
return LineTooltipItem(
"${spot.y.toStringAsFixed(1)} m/s",
const TextStyle(color: Colors.white),
);
}).toList();
},
),
),
), ),
), ),
); );