pembaruan evaporasi grafik dan overflowed tanggal
This commit is contained in:
parent
6f2f7b91a5
commit
0315ec1d31
|
|
@ -1,7 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:klimatologiot/simple_bloc_observer.dart';
|
|
||||||
import 'package:klimatologiot/app.dart';
|
import 'package:klimatologiot/app.dart';
|
||||||
import 'package:user_repository/user_repository.dart';
|
import 'package:user_repository/user_repository.dart';
|
||||||
import 'package:monitoring_repository/monitoring_repository.dart';
|
import 'package:monitoring_repository/monitoring_repository.dart';
|
||||||
|
|
@ -14,7 +12,6 @@ void main() async {
|
||||||
options: DefaultFirebaseOptions.currentPlatform,
|
options: DefaultFirebaseOptions.currentPlatform,
|
||||||
);
|
);
|
||||||
await initializeDateFormatting('id_ID', null);
|
await initializeDateFormatting('id_ID', null);
|
||||||
Bloc.observer = SimpleBlocObserver();
|
|
||||||
runApp(MyApp(
|
runApp(MyApp(
|
||||||
FirebaseUserRepo(),
|
FirebaseUserRepo(),
|
||||||
FirebaseMonitoringRepo(),
|
FirebaseMonitoringRepo(),
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
import 'package:fl_chart/fl_chart.dart';
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
const _tooltipBgColor = Colors.black87;
|
|
||||||
|
|
||||||
|
|
||||||
class EvaporasiChartWidget extends StatelessWidget {
|
class EvaporasiChartWidget extends StatelessWidget {
|
||||||
|
|
||||||
final List<double> dailyValues;
|
final List<double> dailyValues;
|
||||||
final List<double> dailyTemperatures;
|
final List<double> dailyTemperatures;
|
||||||
final String period;
|
final String period;
|
||||||
|
|
@ -114,7 +110,7 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
|
|
||||||
// Evaporasi mm biasanya >= 0, kita pakai min 0 agar estetik.
|
// Evaporasi mm biasanya >= 0, kita pakai min 0 agar estetik.
|
||||||
final evapMin = 0.0;
|
final evapMin = 0.0;
|
||||||
final evapMax = _clampDouble(evapMaxRaw * 1.3, 10.0, 100.0);
|
final evapMax = _clampDouble(evapMaxRaw * 1.15, 8.0, 50.0);
|
||||||
|
|
||||||
// Suhu bisa saja 0 jika data kosong; tetap aman.
|
// Suhu bisa saja 0 jika data kosong; tetap aman.
|
||||||
final tempMin = tempMinRaw;
|
final tempMin = tempMinRaw;
|
||||||
|
|
@ -128,8 +124,7 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
evapByX[s.x.toInt()] = s.y;
|
evapByX[s.x.toInt()] = s.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
final dedupEvapSpots = evapByX.entries
|
final dedupEvapSpots = evapByX.entries.toList()
|
||||||
.toList()
|
|
||||||
..sort((a, b) => a.key.compareTo(b.key));
|
..sort((a, b) => a.key.compareTo(b.key));
|
||||||
|
|
||||||
final Map<int, double> tempByX = {};
|
final Map<int, double> tempByX = {};
|
||||||
|
|
@ -149,9 +144,8 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
return FlSpot(x, y);
|
return FlSpot(x, y);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final evapSpots = dedupEvapSpots
|
final evapSpots =
|
||||||
.map((e) => FlSpot(e.key.toDouble(), e.value))
|
dedupEvapSpots.map((e) => FlSpot(e.key.toDouble(), e.value)).toList();
|
||||||
.toList();
|
|
||||||
|
|
||||||
if (evapSpots.isEmpty && tempSpots.isEmpty) {
|
if (evapSpots.isEmpty && tempSpots.isEmpty) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
|
|
@ -167,19 +161,32 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final chart = LineChart(
|
final chart = LineChart(
|
||||||
LineChartData(
|
LineChartData(
|
||||||
minY: evapMin,
|
minY: evapMin,
|
||||||
maxY: evapMax,
|
maxY: evapMax,
|
||||||
gridData: FlGridData(show: false),
|
gridData: FlGridData(
|
||||||
|
show: true,
|
||||||
|
drawVerticalLine: false,
|
||||||
|
horizontalInterval: (evapMax - evapMin) / 4,
|
||||||
|
getDrawingHorizontalLine: (value) {
|
||||||
|
return FlLine(
|
||||||
|
color: Colors.grey.withOpacity(0.15),
|
||||||
|
strokeWidth: 1,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
borderData: FlBorderData(show: false),
|
borderData: FlBorderData(show: false),
|
||||||
titlesData: FlTitlesData(
|
titlesData: FlTitlesData(
|
||||||
bottomTitles: AxisTitles(
|
bottomTitles: AxisTitles(
|
||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
reservedSize: 32,
|
reservedSize: 32,
|
||||||
interval: 1,
|
interval: period == 'Hari Ini'
|
||||||
|
? 3
|
||||||
|
: period == 'Minggu Ini'
|
||||||
|
? 1
|
||||||
|
: 5,
|
||||||
getTitlesWidget: (value, meta) {
|
getTitlesWidget: (value, meta) {
|
||||||
final index = value.toInt();
|
final index = value.toInt();
|
||||||
return Padding(
|
return Padding(
|
||||||
|
|
@ -228,11 +235,10 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
handleBuiltInTouches: true,
|
handleBuiltInTouches: true,
|
||||||
touchTooltipData: LineTouchTooltipData(
|
touchTooltipData: LineTouchTooltipData(
|
||||||
getTooltipItems: (spots) {
|
getTooltipItems: (spots) {
|
||||||
|
|
||||||
|
|
||||||
return spots.map((spot) {
|
return spots.map((spot) {
|
||||||
// fl_chart tidak mengekspos warna ke tooltip spot pada tipe LineBarSpot
|
final isTemp = spot.bar.color == Colors.orange.shade700;
|
||||||
// jadi kita tampilkan dua informasi sekaligus untuk memudahkan dosen.
|
|
||||||
|
if (isTemp) {
|
||||||
final temp = _evapScaleToTemp(
|
final temp = _evapScaleToTemp(
|
||||||
yEvap: spot.y,
|
yEvap: spot.y,
|
||||||
evapMin: evapMin,
|
evapMin: evapMin,
|
||||||
|
|
@ -240,9 +246,24 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
tempMin: tempMin,
|
tempMin: tempMin,
|
||||||
tempMax: tempMax,
|
tempMax: tempMax,
|
||||||
);
|
);
|
||||||
|
|
||||||
return LineTooltipItem(
|
return LineTooltipItem(
|
||||||
'Evap: ${spot.y.toStringAsFixed(1)} mm\nSuhu: ${temp.toStringAsFixed(1)} °C',
|
'🌡 Suhu\n${temp.toStringAsFixed(1)} °C',
|
||||||
const TextStyle(color: Colors.white, fontSize: 12),
|
const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return LineTooltipItem(
|
||||||
|
'💧 Evaporasi\n${spot.y.toStringAsFixed(1)} mm',
|
||||||
|
const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
},
|
},
|
||||||
|
|
@ -253,9 +274,15 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
LineChartBarData(
|
LineChartBarData(
|
||||||
spots: evapSpots,
|
spots: evapSpots,
|
||||||
isCurved: true,
|
isCurved: true,
|
||||||
|
curveSmoothness: 0.35,
|
||||||
|
isStrokeCapRound: true,
|
||||||
color: Colors.blue.shade700,
|
color: Colors.blue.shade700,
|
||||||
barWidth: 3,
|
barWidth: 3,
|
||||||
dotData: FlDotData(show: false),
|
showingIndicators: [0],
|
||||||
|
dotData: FlDotData(
|
||||||
|
show: false,
|
||||||
|
checkToShowDot: (spot, barData) => false,
|
||||||
|
),
|
||||||
belowBarData: BarAreaData(
|
belowBarData: BarAreaData(
|
||||||
show: true,
|
show: true,
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
|
|
@ -272,12 +299,20 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
LineChartBarData(
|
LineChartBarData(
|
||||||
spots: tempSpots,
|
spots: tempSpots,
|
||||||
isCurved: true,
|
isCurved: true,
|
||||||
|
curveSmoothness: 0.35,
|
||||||
|
isStrokeCapRound: true,
|
||||||
color: Colors.orange.shade700,
|
color: Colors.orange.shade700,
|
||||||
barWidth: 3,
|
barWidth: 3,
|
||||||
dotData: FlDotData(show: false),
|
showingIndicators: [0],
|
||||||
|
dotData: FlDotData(
|
||||||
|
show: false,
|
||||||
|
checkToShowDot: (spot, barData) => false,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
duration: const Duration(milliseconds: 350),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
);
|
);
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|
@ -297,25 +332,70 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// Legend
|
// Legend
|
||||||
Row(
|
Wrap(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
spacing: 16,
|
||||||
|
runSpacing: 8,
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Container(width: 10, height: 10, decoration: BoxDecoration(color: Colors.blue.shade700, shape: BoxShape.circle)),
|
Container(
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blue.shade700,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
const Text('Evaporasi (mm)', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Colors.blueGrey)),
|
const Text(
|
||||||
|
'Evaporasi (mm)',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.blueGrey,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Container(width: 10, height: 10, decoration: BoxDecoration(color: Colors.orange.shade700, shape: BoxShape.circle)),
|
Container(
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.orange.shade700,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
const Text('Suhu (°C)', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Colors.brown)),
|
const Text(
|
||||||
|
'Suhu (°C)',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.brown,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||||
|
child: Text(
|
||||||
|
'Monitoring Evaporasi & Suhu',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.blueGrey.shade700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
|
|
@ -328,4 +408,3 @@ class EvaporasiChartWidget extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ class EvaporasiPeriodSelector extends StatelessWidget {
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
),
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -30,10 +33,12 @@ class EvaporasiPeriodSelector extends StatelessWidget {
|
||||||
_buildDatePickerButton(context, viewMode, selectedDate),
|
_buildDatePickerButton(context, viewMode, selectedDate),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTab(BuildContext context, String label, String current, EvaporasiViewMode viewMode) {
|
Widget _buildTab(BuildContext context, String label, String current,
|
||||||
|
EvaporasiViewMode viewMode) {
|
||||||
// If in customDate mode, show period tabs as inactive
|
// If in customDate mode, show period tabs as inactive
|
||||||
bool isActive = viewMode == EvaporasiViewMode.period && label == current;
|
bool isActive = viewMode == EvaporasiViewMode.period && label == current;
|
||||||
|
|
||||||
|
|
@ -59,7 +64,8 @@ class EvaporasiPeriodSelector extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDatePickerButton(BuildContext context, EvaporasiViewMode viewMode, DateTime? selectedDate) {
|
Widget _buildDatePickerButton(BuildContext context,
|
||||||
|
EvaporasiViewMode viewMode, DateTime? selectedDate) {
|
||||||
final isActive = viewMode == EvaporasiViewMode.customDate;
|
final isActive = viewMode == EvaporasiViewMode.customDate;
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
|
@ -79,7 +85,6 @@ Widget _buildDatePickerButton(BuildContext context, EvaporasiViewMode viewMode,
|
||||||
child: const EvaporasiDatePicker(),
|
child: const EvaporasiDatePicker(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
|
@ -116,4 +121,3 @@ Widget _buildDatePickerButton(BuildContext context, EvaporasiViewMode viewMode,
|
||||||
return "${date.day}/${date.month}";
|
return "${date.day}/${date.month}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ class FirebaseMonitoringRepo implements MonitoringRepository {
|
||||||
final Map<dynamic, dynamic> data = snapshot.value as Map;
|
final Map<dynamic, dynamic> data = snapshot.value as Map;
|
||||||
|
|
||||||
final list = data.values.map((item) {
|
final list = data.values.map((item) {
|
||||||
print(item);
|
|
||||||
return mapper(item as Map<dynamic, dynamic>);
|
return mapper(item as Map<dynamic, dynamic>);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue