Skip to content

Commit

Permalink
Merge pull request wger-project#449 from wger-project/fix/replace-cha…
Browse files Browse the repository at this point in the history
…rt-lib

Replace chart lib
  • Loading branch information
rolandgeider authored Nov 9, 2023
2 parents fead739 + ccc10b0 commit e49b571
Show file tree
Hide file tree
Showing 32 changed files with 1,231 additions and 670 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- '**.dart'
- 'pubspec.yaml'
pull_request:
branches: [ pull_request, master ]
branches: [ master, ]
paths:
- '**.dart'
- 'pubspec.yaml'
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SPEC CHECKSUMS:
image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
rive_common: 60ae7896ab40f9513974f36f015de33f70d2c5c5
rive_common: b5b1aa30c63b8f0f00f32cddc9ea394d3d3473b5
shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
video_player_avfoundation: 81e49bb3d9fb63dccf9fa0f6d877dc3ddbeac126
Expand Down
5 changes: 2 additions & 3 deletions lib/exceptions/http_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ class WgerHttpException implements Exception {
errors = {'unknown_error': 'An unknown error occurred, no further information available'};
} else {
try {
errors = json.decode(responseBody);
errors = {'unknown_error': json.decode(responseBody)};
} catch (e) {
errors = responseBody;
errors = {'unknown_error': responseBody};
}
}
errors = errors;
}

@override
Expand Down
5 changes: 5 additions & 0 deletions lib/helpers/charts.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
double chartGetInterval(DateTime first, DateTime last, {divider = 3}) {
final dayDiff = last.difference(first);

return dayDiff.inMilliseconds == 0 ? 1000 : dayDiff.inMilliseconds.abs() / divider;
}
43 changes: 43 additions & 0 deletions lib/helpers/colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:math';
import 'dart:ui';

const LIST_OF_COLORS8 = [
Color(0xFF2A4C7D),
Color(0xFF5B5291),
Color(0xFF8E5298),
Color(0xFFBF5092),
Color(0xFFE7537E),
Color(0xFFFF6461),
Color(0xFFFF813D),
Color(0xFFFFA600),
];

const LIST_OF_COLORS5 = [
Color(0xFF2A4C7D),
Color(0xFF825298),
Color(0xFFD45089),
Color(0xFFFF6A59),
Color(0xFFFFA600),
];

const LIST_OF_COLORS3 = [
Color(0xFF2A4C7D),
Color(0xFFD45089),
Color(0xFFFFA600),
];

Iterable<Color> generateChartColors(int nrOfItems) sync* {
final List<Color> colors;

if (nrOfItems <= 3) {
colors = LIST_OF_COLORS3;
} else if (nrOfItems <= 5) {
colors = LIST_OF_COLORS5;
} else {
colors = LIST_OF_COLORS8;
}

for (final color in colors) {
yield color;
}
}
24 changes: 24 additions & 0 deletions lib/models/nutrition/nutritional_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ class NutritionalPlan {
return out;
}

NutritionalValues get nutritionalValuesToday {
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);

return logEntriesValues.containsKey(today) ? logEntriesValues[today]! : NutritionalValues();
}

NutritionalValues get nutritionalValues7DayAvg {
final currentDate = DateTime.now();
final sevenDaysAgo = currentDate.subtract(Duration(days: 7));

final entries = logs.where((obj) {
DateTime objDate = obj.datetime;
return objDate.isAfter(sevenDaysAgo) && objDate.isBefore(currentDate);
}).toList();

var out = NutritionalValues();
entries.forEach((log) {
out = out + log.nutritionalValues;
});

return out;
}

/// Calculates the percentage each macro nutrient adds to the total energy
BaseNutritionalValues energyPercentage(NutritionalValues values) {
return BaseNutritionalValues(
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/nutrition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class NutritionPlansProvider with ChangeNotifier {
final data = await baseProvider.fetchPaginated(
baseProvider.makeUrl(
_nutritionDiaryPath,
query: {'plan': plan.id.toString(), 'limit': '999'},
query: {'plan': plan.id.toString(), 'limit': '999', 'ordering': 'datetime'},
),
);

Expand Down
1 change: 0 additions & 1 deletion lib/providers/workout_plans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import 'dart:convert';
import 'dart:developer' as dev;
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down
3 changes: 0 additions & 3 deletions lib/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:table_calendar/table_calendar.dart';
Expand All @@ -30,8 +29,6 @@ const Color wgerTextMuted = Colors.black38;
const Color wgerBackground = Color(0xfff4f4f6);

// Chart colors
const charts.Color wgerChartPrimaryColor = charts.Color(r: 0x2a, g: 0x4c, b: 0x7d);
const charts.Color wgerChartSecondaryColor = charts.Color(r: 0xe6, g: 0x39, b: 0x46);

/// Original sizes for the material text theme
/// https://api.flutter.dev/flutter/material/TextTheme-class.html
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/core/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import 'package:wger/screens/form_screen.dart';
import 'package:wger/widgets/core/about.dart';
import 'package:wger/widgets/user/forms.dart';

class MainAppBar extends StatelessWidget with PreferredSizeWidget {
class MainAppBar extends StatelessWidget implements PreferredSizeWidget {
final String _title;

MainAppBar(this._title);
Expand Down Expand Up @@ -113,7 +113,7 @@ class MainAppBar extends StatelessWidget with PreferredSizeWidget {
}

/// App bar that only displays a title
class EmptyAppBar extends StatelessWidget with PreferredSizeWidget {
class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget {
final String _title;

EmptyAppBar(this._title);
Expand Down
59 changes: 0 additions & 59 deletions lib/widgets/core/charts.dart

This file was deleted.

Loading

0 comments on commit e49b571

Please sign in to comment.