feat: adjust chart styling

lauritz-branch
98spag 2023-06-01 13:19:55 +02:00
parent ae7f64ac1e
commit 8d33371966
6 changed files with 127 additions and 38 deletions

View File

@ -608,7 +608,7 @@
"languageVersion": "2.19" "languageVersion": "2.19"
} }
], ],
"generated": "2023-06-01T10:16:20.370625Z", "generated": "2023-06-01T11:12:57.602326Z",
"generator": "pub", "generator": "pub",
"generatorVersion": "3.0.2" "generatorVersion": "3.0.2"
} }

View File

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/bogdan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.2/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/bogdan/.pub-cache/hosted/pub.dev/path_provider_android-2.0.27/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/bogdan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.2/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/bogdan/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/bogdan/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.6/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-05-31 22:57:37.224562","version":"3.7.9"} {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-06-01 13:16:00.226015","version":"3.10.2"}

View File

@ -7,7 +7,7 @@ String getFoodListStringByFood(String foodName, int count, int calories){
} }
String getWeeklyRankingString(String foodName){ String getWeeklyRankingString(String foodName){
int maxWidth = 50; int maxWidth = 45;
String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ... " : foodName; String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ... " : foodName;
return limitedText; return limitedText;
} }

View File

@ -292,8 +292,7 @@ class StatisticsService {
if(value > maxValue){ if(value > maxValue){
maxValue = value; maxValue = value;
} }
result[i][j] = value;
result[i][j] = (value * 175) ~/ 100;
} }
} }
} }
@ -313,8 +312,6 @@ class StatisticsService {
color: Colors.green, color: Colors.green,
toY: result[0][2].toDouble(), // Second segment color toY: result[0][2].toDouble(), // Second segment color
),], ),],
showingTooltipIndicators: [0],
groupVertically: true
), ),
BarChartGroupData( BarChartGroupData(
x: 1, x: 1,
@ -332,7 +329,6 @@ class StatisticsService {
color: Colors.green, color: Colors.green,
toY: result[1][2].toDouble(), // Second segment color toY: result[1][2].toDouble(), // Second segment color
),], ),],
showingTooltipIndicators: [0],
), ),
BarChartGroupData( BarChartGroupData(
x: 2, x: 2,
@ -349,7 +345,6 @@ class StatisticsService {
color: Colors.green, color: Colors.green,
toY: result[2][2].toDouble(), // Second segment color toY: result[2][2].toDouble(), // Second segment color
),], ),],
showingTooltipIndicators: [0],
), ),
BarChartGroupData( BarChartGroupData(
x: 3, x: 3,
@ -383,7 +378,6 @@ class StatisticsService {
color: Colors.green, color: Colors.green,
toY: result[4][2].toDouble(), // Second segment color toY: result[4][2].toDouble(), // Second segment color
),], ),],
showingTooltipIndicators: [0],
), ),
BarChartGroupData( BarChartGroupData(
x: 5, x: 5,
@ -399,7 +393,7 @@ class StatisticsService {
width: 7.5, // Adjust the width of the bar if needed width: 7.5, // Adjust the width of the bar if needed
color: Colors.green, color: Colors.green,
toY: result[5][2].toDouble(), // Second segment color toY: result[5][2].toDouble(), // Second segment color
),], showingTooltipIndicators: [0], ),],
), ),
BarChartGroupData( BarChartGroupData(
x: 6, x: 6,

View File

@ -37,18 +37,15 @@ class ProgressPage extends StatelessWidget {
return Container( return Container(
height: 100, height: 100,
width: 400, width: 400,
decoration: BoxDecoration(
border: Border.all(),
),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const TitleComponent("Kalorien"), const TitleComponent("Täglicher Durchschnitt (in kcal)"),
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
const SecondaryTextComponent("Durchschnittlich"), const SecondaryTextComponent("Durchschnittlich"),
SecondaryBigTextComponent(value.toString()), SecondaryBigTextComponent("${value.toString()} kcal/Tag"),
], ],
), ),
); );
@ -58,24 +55,94 @@ class ProgressPage extends StatelessWidget {
valueListenable: StatisticsService.instance.barChartData, valueListenable: StatisticsService.instance.barChartData,
builder: (context, value, child) { builder: (context, value, child) {
return SizedBox( return SizedBox(
height: 205, height: 325,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox( SizedBox(
height: 200, height: 15, // Adjust the height of the legend as needed
child: BarChart( child: Row(
BarChartData( mainAxisAlignment: MainAxisAlignment.center,
barTouchData: barTouchData, children: [
titlesData: titlesData, Container(
borderData: borderData, margin: const EdgeInsets.symmetric(horizontal: 8.0), // Adjust the spacing between legend items
barGroups: value, child: Row(
gridData: FlGridData(show: false), children: [
alignment: BarChartAlignment.spaceAround, Container(
maxY: 200, width: 12,
height: 12,
decoration: const BoxDecoration(
color: Colors.red, // Use the color of the first bar rod for the legend item
shape: BoxShape.circle,
),
),
const SizedBox(width: 4.0), // Adjust the spacing between the color indicator and the legend label
const Text(
'Frühstück', // Replace with your desired legend label
style: TextStyle(fontSize: 12), // Adjust the font size of the legend labels
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0), // Adjust the spacing between legend items
child: Row(
children: [
Container(
width: 12,
height: 12,
decoration: const BoxDecoration(
color: Colors.green, // Use the color of the first bar rod for the legend item
shape: BoxShape.circle,
),
),
const SizedBox(width: 4.0), // Adjust the spacing between the color indicator and the legend label
const Text(
'Mittagessen', // Replace with your desired legend label
style: TextStyle(fontSize: 12), // Adjust the font size of the legend labels
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0), // Adjust the spacing between legend items
child: Row(
children: [
Container(
width: 12,
height: 12,
decoration: const BoxDecoration(
color: Colors.yellow, // Use the color of the first bar rod for the legend item
shape: BoxShape.circle,
),
),
const SizedBox(width: 4.0), // Adjust the spacing between the color indicator and the legend label
const Text(
'Abendessen', // Replace with your desired legend label
style: TextStyle(fontSize: 12), // Adjust the font size of the legend labels
),
],
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top:50.0), // Adjust the margin value as needed
child: SizedBox(
height: 250,
child: BarChart(
BarChartData(
barTouchData: barTouchData,
titlesData: titlesData,
borderData: borderData,
barGroups: value,
gridData: FlGridData(show: false),
alignment: BarChartAlignment.spaceAround,
),
), ),
), ),
) ),
], ],
), ),
); );
@ -124,7 +191,7 @@ class ProgressPage extends StatelessWidget {
return BarTooltipItem( return BarTooltipItem(
rod.toY.round().toString(), rod.toY.round().toString(),
const TextStyle( const TextStyle(
color: Colors.orange, color: Colors.transparent,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
); );
@ -134,7 +201,7 @@ class ProgressPage extends StatelessWidget {
Widget getTitles(double value, TitleMeta meta) { Widget getTitles(double value, TitleMeta meta) {
const style = TextStyle( const style = TextStyle(
color: Colors.red, color: Colors.orange,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 14, fontSize: 14,
); );
@ -181,20 +248,48 @@ class ProgressPage extends StatelessWidget {
getTitlesWidget: getTitles, getTitlesWidget: getTitles,
), ),
), ),
leftTitles: AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
topTitles: AxisTitles( topTitles: AxisTitles(
sideTitles: SideTitles(showTitles: false), sideTitles: SideTitles(showTitles: false),
), ),
rightTitles: AxisTitles( rightTitles: AxisTitles(
sideTitles: SideTitles(showTitles: false), sideTitles: SideTitles(
showTitles: false,
),
), ),
leftTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
getTitlesWidget: (value, _) {
// Return a custom widget for each axis value
return Container(
constraints: BoxConstraints.tightFor(width: double.infinity),
child: Padding(
padding: const EdgeInsets.only(right: 3.0), // Adjust the margin value as needed
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(
value.toInt().toString(),
style: const TextStyle(
color: Colors.orange,
fontWeight: FontWeight.bold,
),
),
),
),
);
},
),
)
); );
FlBorderData get borderData => FlBorderData( FlBorderData get borderData => FlBorderData(
show: false, show: true, // Set to true to display the chart border
); border: const Border(
bottom: BorderSide(color: Colors.black, width: 1),
left: BorderSide(color: Colors.black, width: 1),// Hide the left border
),
);
} }

View File

@ -27,7 +27,7 @@ void main() async {
await Hive.openBox(dotenv.env['STATISTICS_MAIN_BOX'] ?? 'STATISTICS_MAIN_BOX'); await Hive.openBox(dotenv.env['STATISTICS_MAIN_BOX'] ?? 'STATISTICS_MAIN_BOX');
await Hive.openBox(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN'); await Hive.openBox(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN');
await Hive.openBox<User>('USER_BOX'); await Hive.openBox<User>('USER_BOX');
//Hive.deleteFromDisk();
setupTodayBox(); setupTodayBox();
if (defaultTargetPlatform == TargetPlatform.android) { if (defaultTargetPlatform == TargetPlatform.android) {