SP-1494 reworks.

1. When the chart loads, we see it coming from the top right corner (check the attached video).
2. Day 1 is missing on the X axis.
3. Overlapping line not removed.
This commit is contained in:
Faris Armoush
2025-05-19 10:17:48 +03:00
parent 17aad13b2a
commit f67d0e2912
3 changed files with 30 additions and 22 deletions

View File

@ -20,12 +20,12 @@ abstract final class EnergyManagementChartsHelper {
interval: 1, interval: 1,
reservedSize: 32, reservedSize: 32,
showTitles: true, showTitles: true,
maxIncluded: false, maxIncluded: true,
minIncluded: false, minIncluded: true,
getTitlesWidget: (value, meta) => Padding( getTitlesWidget: (value, meta) => Padding(
padding: const EdgeInsetsDirectional.only(top: 20.0), padding: const EdgeInsetsDirectional.only(top: 20.0),
child: Text( child: Text(
(value + 1).toString(), value.toString(),
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.greyColor, color: ColorsManager.greyColor,
fontSize: 12, fontSize: 12,
@ -72,7 +72,7 @@ abstract final class EnergyManagementChartsHelper {
static List<LineTooltipItem?> getTooltipItems(List<LineBarSpot> touchedSpots) { static List<LineTooltipItem?> getTooltipItems(List<LineBarSpot> touchedSpots) {
return touchedSpots.map((spot) { return touchedSpots.map((spot) {
return LineTooltipItem( return LineTooltipItem(
getToolTipLabel(spot.x + 1, spot.y), getToolTipLabel(spot.x, spot.y),
const TextStyle( const TextStyle(
color: ColorsManager.textPrimaryColor, color: ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@ -93,31 +93,38 @@ abstract final class EnergyManagementChartsHelper {
); );
} }
static FlBorderData borderData() {
return FlBorderData(
show: true,
border: const Border.symmetric(
horizontal: BorderSide(
color: ColorsManager.greyColor,
style: BorderStyle.solid,
width: 1,
),
),
);
}
static FlGridData gridData() { static FlGridData gridData() {
return const FlGridData( return FlGridData(
show: true, show: true,
drawVerticalLine: false, drawVerticalLine: false,
drawHorizontalLine: true, drawHorizontalLine: true,
horizontalInterval: 250,
getDrawingHorizontalLine: (value) {
return FlLine(
color: ColorsManager.greyColor,
strokeWidth: 1,
dashArray: value == 0 ? null : [5, 5],
);
},
);
}
static FlBorderData borderData() {
return FlBorderData(
border: const Border(
bottom: BorderSide(
color: ColorsManager.greyColor,
style: BorderStyle.solid,
),
),
show: true,
); );
} }
static LineTouchData lineTouchData() { static LineTouchData lineTouchData() {
return LineTouchData( return LineTouchData(
handleBuiltInTouches: true, handleBuiltInTouches: true,
touchSpotThreshold: 2, touchSpotThreshold: 16,
touchTooltipData: EnergyManagementChartsHelper.lineTouchTooltipData(), touchTooltipData: EnergyManagementChartsHelper.lineTouchTooltipData(),
); );
} }

View File

@ -16,6 +16,7 @@ class EnergyConsumptionPerDeviceChart extends StatelessWidget {
context, context,
leftTitlesInterval: 250, leftTitlesInterval: 250,
), ),
gridData: EnergyManagementChartsHelper.gridData().copyWith( gridData: EnergyManagementChartsHelper.gridData().copyWith(
checkToShowHorizontalLine: (value) => true, checkToShowHorizontalLine: (value) => true,
horizontalInterval: 250, horizontalInterval: 250,
@ -36,7 +37,7 @@ class EnergyConsumptionPerDeviceChart extends StatelessWidget {
); );
}).toList(), }).toList(),
), ),
duration: Durations.extralong1, duration: Duration.zero,
curve: Curves.easeIn, curve: Curves.easeIn,
); );
} }

View File

@ -26,7 +26,7 @@ class TotalEnergyConsumptionChart extends StatelessWidget {
lineTouchData: EnergyManagementChartsHelper.lineTouchData(), lineTouchData: EnergyManagementChartsHelper.lineTouchData(),
lineBarsData: _lineBarsData, lineBarsData: _lineBarsData,
), ),
duration: Durations.extralong1, duration: Duration.zero,
curve: Curves.easeIn, curve: Curves.easeIn,
), ),
); );
@ -43,7 +43,7 @@ class TotalEnergyConsumptionChart extends StatelessWidget {
.entries .entries
.map( .map(
(entry) => FlSpot( (entry) => FlSpot(
entry.key.toDouble(), entry.value.date.day.toDouble(),
entry.value.value, entry.value.value,
), ),
) )