paint difference wrt plan as surplus or deficit

* there may not be a plan for a given macro. accommodate this nicely
* a whole dedicated bar for 'planned' felt too much UI bloat
This commit is contained in:
Dieter Plaetinck
2024-04-15 12:53:28 +02:00
parent cc39b692b2
commit 6e37c09fc7
2 changed files with 48 additions and 18 deletions

View File

@@ -206,25 +206,49 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
final colorLogged7Day = LIST_OF_COLORS3[2];
BarChartGroupData barchartGroup(int x, double barsSpace, double barsWidth, String prop) {
final plan = planned.prop(prop);
BarChartRodData barChartRodData(double plan, double val, Color color) {
// paint a simple bar
if (plan == 0 || val == plan) {
return BarChartRodData(
toY: val,
color: color,
width: barsWidth,
);
}
// paint a surplus
if (val > plan) {
return BarChartRodData(
toY: val,
color: colorLoggedToday,
width: barsWidth,
rodStackItems: [
BarChartRodStackItem(0, plan, color),
BarChartRodStackItem(plan, val, Colors.red),
],
);
}
// paint a deficit
return BarChartRodData(
toY: plan,
color: colorLoggedToday,
width: barsWidth,
rodStackItems: [
BarChartRodStackItem(0, val, color),
BarChartRodStackItem(val, plan, colorPlanned),
],
);
}
return BarChartGroupData(
x: x,
barsSpace: barsSpace,
barRods: [
BarChartRodData(
toY: planned.prop(prop),
color: colorPlanned,
width: barsWidth,
),
BarChartRodData(
toY: loggedToday.prop(prop),
color: colorLoggedToday,
width: barsWidth,
),
BarChartRodData(
toY: logged7DayAvg.prop(prop),
color: colorLogged7Day,
width: barsWidth,
),
barChartRodData(plan, loggedToday.prop(prop), colorLoggedToday),
barChartRodData(plan, logged7DayAvg.prop(prop), colorLogged7Day),
],
);
}
@@ -235,8 +259,8 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
padding: const EdgeInsets.only(top: 16),
child: LayoutBuilder(
builder: (context, constraints) {
final barsSpace = 4.0 * constraints.maxWidth / 400;
final barsWidth = 8.0 * constraints.maxWidth / 400;
final barsSpace = 6.0 * constraints.maxWidth / 400;
final barsWidth = 12.0 * constraints.maxWidth / 400;
return BarChart(
BarChartData(
alignment: BarChartAlignment.center,

View File

@@ -105,7 +105,13 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
children: [
Indicator(
color: LIST_OF_COLORS3[0],
text: AppLocalizations.of(context).planned,
text: 'deficit',
isSquare: true,
marginRight: 0,
),
const Indicator(
color: Colors.red,
text: 'surplus',
isSquare: true,
marginRight: 0,
),