Skip to content

Commit

Permalink
Scale chart per interval
Browse files Browse the repository at this point in the history
  • Loading branch information
sruusk committed Dec 28, 2024
1 parent 09754e6 commit 4eb0d77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/utils/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ElectricityApi {
Future<List<ElectricityPrice>> getPricesForDays(int days) async {
final DateTime now = DateTime.now();
final DateTime start = DateTime(now.year, now.month, now.day - days, 0, 0, 0);
final DateTime end = DateTime(now.year, now.month, now.day, 23, 0, 0);
final DateTime end = DateTime(now.year, now.month, now.day + 1, 23, 0, 0);
return getPricesForInterval(start, end);
}
}
Expand Down
10 changes: 7 additions & 3 deletions lib/widgets/chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ class _ChartWidget extends State<ChartWidget> {
if(errorMessage != null) return Center(child: Text('Error: $errorMessage'));
if(prices == null) return const Center(child: CircularProgressIndicator());

double maxPrice = prices!.map((e) => e.priceWithModifiers(modifiers)).reduce(max).ceilToDouble();
double minPrice = min(0, prices!.map((e) => e.priceWithModifiers(modifiers)).reduce(min)).floorToDouble();
double maxPrice = prices!.sublist(interval[0].toInt(), interval[1].toInt() + 1).map((e) => e.priceWithModifiers(modifiers)).reduce(max).ceilToDouble();
double minPrice = min(0, prices!.sublist(interval[0].toInt(), interval[1].toInt() + 1).map((e) => e.priceWithModifiers(modifiers)).reduce(min)).floorToDouble();
double screenHeight = MediaQuery.of(context).size.height;

if(maxPrice - minPrice < 5) {
maxPrice = minPrice + 5;
}

return Center(
child: Column(
children: [
Expand All @@ -89,7 +93,7 @@ class _ChartWidget extends State<ChartWidget> {
color: Theme.of(context).colorScheme.surfaceContainerLow,
boxShadow: [
BoxShadow(
color: Theme.of(context).colorScheme.shadow.withOpacity(0.3),
color: Theme.of(context).colorScheme.shadow.withValues(alpha: 0.3),
spreadRadius: 0,
blurRadius: 0.5,
offset: const Offset(0, 2),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.9+1
version: 1.0.11+1

environment:
sdk: ^3.5.3
Expand Down

0 comments on commit 4eb0d77

Please sign in to comment.