Skip to content

Commit

Permalink
fix: fixed reports for taskc
Browse files Browse the repository at this point in the history
  • Loading branch information
its-me-abhishek committed Jul 6, 2024
1 parent 7becfec commit 8aa5612
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 415 deletions.
36 changes: 27 additions & 9 deletions lib/app/modules/home/views/nav_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart';
import 'package:taskwarrior/app/modules/home/views/home_page_nav_drawer_menu_item.dart';
import 'package:taskwarrior/app/modules/home/views/theme_clipper.dart';
import 'package:taskwarrior/app/modules/reports/views/reports_view_taskc.dart';
import 'package:taskwarrior/app/routes/app_pages.dart';
import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart';
import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';
Expand Down Expand Up @@ -183,15 +184,32 @@ class NavDrawer extends StatelessWidget {
),
),
),
Obx(
() => NavDrawerMenuItem(
icon: Icons.summarize,
text: SentenceManager(
currentLanguage: homeController.selectedLanguage.value,
).sentences.navDrawerReports,
onTap: () {
Get.toNamed(Routes.REPORTS);
},
Visibility(
visible: !homeController.taskchampion.value,
child: Obx(
() => NavDrawerMenuItem(
icon: Icons.summarize,
text: SentenceManager(
currentLanguage: homeController.selectedLanguage.value,
).sentences.navDrawerReports,
onTap: () {
Get.toNamed(Routes.REPORTS);
},
),
),
),
Visibility(
visible: homeController.taskchampion.value,
child: Obx(
() => NavDrawerMenuItem(
icon: Icons.summarize,
text: SentenceManager(
currentLanguage: homeController.selectedLanguage.value,
).sentences.navDrawerReports,
onTap: () {
Get.to(() => ReportsHomeTaskc());
},
),
),
),
Obx(
Expand Down
8 changes: 7 additions & 1 deletion lib/app/modules/reports/controllers/reports_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:taskwarrior/api_service.dart';
import 'package:taskwarrior/app/models/json/task.dart';
import 'package:taskwarrior/app/models/storage.dart';
import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart';
Expand All @@ -24,7 +25,7 @@ class ReportsController extends GetxController
final GlobalKey daily = GlobalKey();
final GlobalKey weekly = GlobalKey();
final GlobalKey monthly = GlobalKey();

late TaskDatabase taskDatabase;
var isSaved = false.obs;
late TutorialCoachMark tutorialCoachMark;

Expand Down Expand Up @@ -344,6 +345,11 @@ class ReportsController extends GetxController
});
}

Future<List<Tasks>> fetchTasks() async {
await taskDatabase.open();
return await taskDatabase.fetchTasksFromDatabase();
}

// monthly report
late TooltipBehavior monthlyBurndownTooltipBehaviour;
RxMap<String, Map<String, int>> monthlyInfo =
Expand Down
247 changes: 122 additions & 125 deletions lib/app/modules/reports/views/burn_down_daily_taskc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,50 @@ import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';
import 'package:taskwarrior/app/utils/constants/utilites.dart';
import 'package:taskwarrior/app/utils/theme/app_settings.dart';

class BurnDownDailyTaskc extends StatefulWidget {
const BurnDownDailyTaskc({super.key});
class BurnDownDailyTaskc extends StatelessWidget {
BurnDownDailyTaskc({super.key});

@override
State<BurnDownDailyTaskc> createState() => _BurnDownDailyTaskcState();
}

class _BurnDownDailyTaskcState extends State<BurnDownDailyTaskc>
with TickerProviderStateMixin {
late TaskDatabase taskDatabase;
late TooltipBehavior _dailyBurndownTooltipBehaviour;
Map<String, Map<String, int>> dailyInfo = {};

@override
void initState() {
super.initState();

// Initialize the tooltip behavior for the chart
_dailyBurndownTooltipBehaviour = TooltipBehavior(
enable: true,
builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
int seriesIndex) {
final String date = data.x;
final int pendingCount = data.y1;
final int completedCount = data.y2;
final TooltipBehavior _dailyBurndownTooltipBehaviour = TooltipBehavior(
enable: true,
builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
int seriesIndex) {
final String date = data.x;
final int pendingCount = data.y1;
final int completedCount = data.y2;

return Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Date: $date',
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
),
),
Text(
'Pending: $pendingCount',
),
Text(
'Completed: $completedCount',
return Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Date: $date',
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
),
],
),
);
},
);
),
Text('Pending: $pendingCount'),
Text('Completed: $completedCount'),
],
),
);
},
);

// Initialize the database and fetch data
taskDatabase = TaskDatabase();
taskDatabase.open().then((_) {
taskDatabase.fetchTasksFromDatabase().then((tasks) {
setState(() {
// Process the data and update the chart
_processData(tasks);
});
});
});
Future<Map<String, Map<String, int>>> fetchDailyInfo() async {
TaskDatabase taskDatabase = TaskDatabase();
await taskDatabase.open();
List<Tasks> tasks = await taskDatabase.fetchTasksFromDatabase();
return _processData(tasks);
}

void _processData(List<Tasks> tasks) {
dailyInfo = {};
Map<String, Map<String, int>> _processData(List<Tasks> tasks) {
Map<String, Map<String, int>> dailyInfo = {};

// Sort tasks by entry date in ascending order
tasks.sort((a, b) => a.entry.compareTo(b.entry));
Expand All @@ -98,80 +74,101 @@ class _BurnDownDailyTaskcState extends State<BurnDownDailyTaskc>
};
}
}

return dailyInfo;
}

@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height; // Screen height

return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: SizedBox(
height: height * 0.6,
child: SfCartesianChart(
primaryXAxis: CategoryAxis(
title: AxisTitle(
text: 'Day - Month',
textStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
color: AppSettings.isDarkMode ? Colors.white : Colors.black,
fontSize: TaskWarriorFonts.fontSizeSmall,
return FutureBuilder<Map<String, Map<String, int>>>(
future: fetchDailyInfo(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}

if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
}

Map<String, Map<String, int>> dailyInfo = snapshot.data ?? {};

return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: SizedBox(
height: height * 0.6,
child: SfCartesianChart(
primaryXAxis: CategoryAxis(
title: AxisTitle(
text: 'Day - Month',
textStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
color: AppSettings.isDarkMode
? Colors.white
: Colors.black,
fontSize: TaskWarriorFonts.fontSizeSmall,
),
),
),
),
),
primaryYAxis: NumericAxis(
title: AxisTitle(
text: 'Tasks',
textStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
fontSize: TaskWarriorFonts.fontSizeSmall,
color: AppSettings.isDarkMode ? Colors.white : Colors.black,
primaryYAxis: NumericAxis(
title: AxisTitle(
text: 'Tasks',
textStyle: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
fontSize: TaskWarriorFonts.fontSizeSmall,
color: AppSettings.isDarkMode
? Colors.white
: Colors.black,
),
),
),
tooltipBehavior: _dailyBurndownTooltipBehaviour,
series: <ChartSeries>[
StackedColumnSeries<ChartData, String>(
groupName: 'Group A',
enableTooltip: true,
color: TaskWarriorColors.green,
dataSource: dailyInfo.entries
.map((entry) => ChartData(
entry.key,
entry.value['pending'] ?? 0,
entry.value['completed'] ?? 0,
))
.toList(),
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y2,
name: 'Completed',
),
StackedColumnSeries<ChartData, String>(
groupName: 'Group A',
color: TaskWarriorColors.yellow,
enableTooltip: true,
dataSource: dailyInfo.entries
.map((entry) => ChartData(
entry.key,
entry.value['pending'] ?? 0,
entry.value['completed'] ?? 0,
))
.toList(),
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y1,
name: 'Pending',
),
],
),
),
tooltipBehavior: _dailyBurndownTooltipBehaviour,
series: <ChartSeries>[
StackedColumnSeries<ChartData, String>(
groupName: 'Group A',
enableTooltip: true,
color: TaskWarriorColors.green,
dataSource: dailyInfo.entries
.map((entry) => ChartData(
entry.key,
entry.value['pending'] ?? 0,
entry.value['completed'] ?? 0,
))
.toList(),
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y2,
name: 'Completed',
),
StackedColumnSeries<ChartData, String>(
groupName: 'Group A',
color: TaskWarriorColors.yellow,
enableTooltip: true,
dataSource: dailyInfo.entries
.map((entry) => ChartData(
entry.key,
entry.value['pending'] ?? 0,
entry.value['completed'] ?? 0,
))
.toList(),
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y1,
name: 'Pending',
),
],
),
),
),
const CommonChartIndicator(
title: 'Daily Burndown Chart',
),
],
const CommonChartIndicator(
title: 'Daily Burndown Chart',
),
],
);
},
);
}
}
Loading

0 comments on commit 8aa5612

Please sign in to comment.