import 'package:easy_localization/easy_localization.dart'; import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; import 'package:scrobbles/config/app_colors.dart'; class CustomChart extends StatelessWidget { const CustomChart({super.key}); final double chartHeight = 150.0; final double verticalTicksInterval = 10; final String verticalAxisTitleSuffix = ''; final double titleFontSize = 9; @override Widget build(BuildContext context) { return SizedBox( height: this.chartHeight, ); } double getNextRoundNumber(double number, double scale) { return scale * ((number ~/ scale).toInt() + 1); } Color getColorFromIndex(int index) { const List<int> hexValues = [ 0x8dd3c7, 0xffffb3, 0xbebada, 0xfb8072, 0x80b1d3, 0xfdb462, 0xb3de69, 0xfccde5, 0xd9d9d9, 0xbc80bd, 0xccebc5, 0xffed6f, ]; return Color(hexValues[index % hexValues.length] + 0xff000000); } String getDayShortName(int dayIndex) { switch (dayIndex) { case 1: return 'MON'; case 2: return 'TUE'; case 3: return 'WED'; case 4: return 'THU'; case 5: return 'FRI'; case 6: return 'SAT'; case 7: return 'SUN'; default: } return ''; } FlBorderData get noBorderData { return FlBorderData( show: false, ); } FlBorderData get simpleBorderData { return FlBorderData( show: true, border: Border.all( color: AppColors.borderColor, width: 2, ), ); } FlGridData get noGridData { return const FlGridData( show: false, ); } FlGridData get horizontalGridData { return const FlGridData( show: true, drawHorizontalLine: true, drawVerticalLine: false, ); } FlTitlesData getTitlesData() { return FlTitlesData( show: false, ); } Widget getHorizontalTitlesWidget(double value, TitleMeta meta) { return Text(''); } Widget getHorizontalTitlesWidgetWithDate(double value, TitleMeta meta) { final DateFormat formatter = DateFormat('dd/MM'); final DateTime date = DateTime.fromMillisecondsSinceEpoch(value.toInt()); final String text = formatter.format(date); return SideTitleWidget( axisSide: meta.axisSide, space: 4, child: Padding( padding: EdgeInsets.only(right: 10), child: RotationTransition( turns: new AlwaysStoppedAnimation(-30 / 360), child: Text( text, style: TextStyle( color: AppColors.mainTextColor1, fontSize: this.titleFontSize, ), ), ), ), ); } Widget getHorizontalTitlesWidgetWithDay(double value, TitleMeta meta) { final String dayShortName = getDayShortName(value.toInt()); return SideTitleWidget( axisSide: meta.axisSide, space: 2, child: Text( tr(dayShortName), style: const TextStyle( color: AppColors.mainTextColor1, fontSize: 11, ), ), ); } Widget getHorizontalTitlesWidgetWithHour(double value, TitleMeta meta) { String text = ''; if (value % 4 == 0 || value == 23) { text = value.toInt().toString().padLeft(2, '0'); } return SideTitleWidget( axisSide: meta.axisSide, space: 2, child: Text( text, style: TextStyle( color: AppColors.mainTextColor1, fontSize: this.titleFontSize, ), ), ); } Widget getVerticalTitlesSpacerWidget(double value, TitleMeta meta) { return SideTitleWidget( axisSide: meta.axisSide, space: 4, child: Text(''), ); } Widget getVerticalTitlesWidget(double value, TitleMeta meta) { String suffix = this.verticalAxisTitleSuffix != '' ? ' ' + this.verticalAxisTitleSuffix : ''; return SideTitleWidget( axisSide: meta.axisSide, space: 4, child: Text( value.toInt().toString() + suffix, style: TextStyle( color: AppColors.mainTextColor1, fontSize: this.titleFontSize, ), ), ); } }