feat: Enhance attendance dashboard by filtering roles with data and improving chart series mapping
This commit is contained in:
parent
25a1331878
commit
9e4c0378c6
@ -36,6 +36,11 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
List<String> get filteredRoles =>
|
List<String> get filteredRoles =>
|
||||||
filteredData.map((e) => e['role'] as String).toSet().toList();
|
filteredData.map((e) => e['role'] as String).toSet().toList();
|
||||||
|
|
||||||
|
List<String> get rolesWithData => filteredRoles.where((role) {
|
||||||
|
return filteredData.any(
|
||||||
|
(entry) => entry['role'] == role && (entry['present'] ?? 0) > 0);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
final Map<String, Color> _roleColorMap = {};
|
final Map<String, Color> _roleColorMap = {};
|
||||||
final List<Color> flatColors = [
|
final List<Color> flatColors = [
|
||||||
const Color(0xFFE57373),
|
const Color(0xFFE57373),
|
||||||
@ -52,7 +57,6 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
|
|
||||||
Color _getRoleColor(String role) {
|
Color _getRoleColor(String role) {
|
||||||
if (_roleColorMap.containsKey(role)) return _roleColorMap[role]!;
|
if (_roleColorMap.containsKey(role)) return _roleColorMap[role]!;
|
||||||
|
|
||||||
final index = _roleColorMap.length % flatColors.length;
|
final index = _roleColorMap.length % flatColors.length;
|
||||||
final color = flatColors[index];
|
final color = flatColors[index];
|
||||||
_roleColorMap[role] = color;
|
_roleColorMap[role] = color;
|
||||||
@ -62,7 +66,6 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
// Now this observes `controller.roleWiseData`, `isLoading`, `isChartView`, etc.
|
|
||||||
final isChartView = controller.isChartView.value;
|
final isChartView = controller.isChartView.value;
|
||||||
final selectedRange = controller.selectedRange.value;
|
final selectedRange = controller.selectedRange.value;
|
||||||
final isLoading = controller.isLoading.value;
|
final isLoading = controller.isLoading.value;
|
||||||
@ -78,8 +81,7 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
child: Card(
|
child: Card(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
elevation: 6,
|
elevation: 6,
|
||||||
shape:
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
||||||
shadowColor: Colors.black12,
|
shadowColor: Colors.black12,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
@ -116,10 +118,7 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
MyText.bodyMedium('Attendance Overview', fontWeight: 600),
|
MyText.bodyMedium('Attendance Overview', fontWeight: 600),
|
||||||
MyText.bodySmall(
|
MyText.bodySmall('Role-wise present count', color: Colors.grey),
|
||||||
'Role-wise present count',
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -213,7 +212,7 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
interval: 1,
|
interval: 1,
|
||||||
majorGridLines: const MajorGridLines(width: 0),
|
majorGridLines: const MajorGridLines(width: 0),
|
||||||
),
|
),
|
||||||
series: filteredRoles.map((role) {
|
series: rolesWithData.map((role) {
|
||||||
final data = filteredDates.map((formattedDate) {
|
final data = filteredDates.map((formattedDate) {
|
||||||
final key = '${role}_$formattedDate';
|
final key = '${role}_$formattedDate';
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user