Skip to content

Commit

Permalink
[Presentation] Added a chart that shows the most common ascension stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed May 18, 2022
1 parent baf2740 commit cd37c2e
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 120 deletions.
1 change: 1 addition & 0 deletions lib/application/bloc.dart
Expand Up @@ -13,6 +13,7 @@ export 'calculator_asc_materials/sessions_order/calculator_asc_materials_session
export 'changelog/changelog_bloc.dart';
export 'character/character_bloc.dart';
export 'characters/characters_bloc.dart';
export 'charts/ascension_stats/chart_ascension_stats_bloc.dart';
export 'charts/birthdays/chart_birthdays_bloc.dart';
export 'charts/elements/chart_elements_bloc.dart';
export 'charts/elements/chart_elements_bloc.dart';
Expand Down
5 changes: 5 additions & 0 deletions lib/injection.dart
Expand Up @@ -178,6 +178,11 @@ class Injection {
return ChartElementsBloc(genshinService);
}

static ChartAscensionStatsBloc get chartAscensionStatsBloc {
final genshinService = getIt<GenshinService>();
return ChartAscensionStatsBloc(genshinService);
}

static BirthdaysPerMonthBloc get birthdaysPerMonthBloc {
final genshinService = getIt<GenshinService>();
final telemetryService = getIt<TelemetryService>();
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Expand Up @@ -433,6 +433,7 @@
"birthdays": "Birthdays",
"topCharacters": "Top characters",
"topWeapons": "Top weapons",
"ascensionStats": "Ascension Stats",
"xStarsWithMostReruns": "{xStars} with most reruns",
"xStarsWithLeastReruns": "{xStars} with least reruns",
"birthdaysPerMonth": "Birthdays per month",
Expand Down
274 changes: 204 additions & 70 deletions lib/presentation/charts/charts_page.dart

Large diffs are not rendered by default.

60 changes: 40 additions & 20 deletions lib/presentation/charts/widgets/horizontal_bar_chart.dart
Expand Up @@ -2,6 +2,7 @@ import 'dart:math';

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:shiori/domain/extensions/string_extensions.dart';
import 'package:shiori/presentation/shared/styles.dart';

class HorizontalBarDataModel {
Expand Down Expand Up @@ -35,6 +36,9 @@ class HorizontalBarChart extends StatelessWidget {

final Color? toolTipBgColor;

final int bottomTextMaxLength;
final int leftTextMaxLength;

const HorizontalBarChart({
Key? key,
required this.items,
Expand All @@ -49,6 +53,8 @@ class HorizontalBarChart extends StatelessWidget {
this.minY = 0,
this.barWidth = 4,
this.toolTipBgColor,
this.bottomTextMaxLength = 10,
this.leftTextMaxLength = 10,
}) : super(key: key);

@override
Expand Down Expand Up @@ -85,34 +91,48 @@ class HorizontalBarChart extends StatelessWidget {
showTitles: true,
reservedSize: 32,
interval: xIntervals,
getTitlesWidget: (value, meta) => !canValueBeRendered(value)
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
getBottomText(value),
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 12,
),
getTitlesWidget: (value, meta) {
if (!canValueBeRendered(value)) {
return const SizedBox.shrink();
}

final text = getBottomText(value);
return Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Tooltip(
message: text,
child: Text(
text.substringIfOverflow(bottomTextMaxLength),
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
),
);
},
),
),
rightTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)),
topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)),
leftTitles: AxisTitles(
sideTitles: SideTitles(
getTitlesWidget: (value, meta) => Text(
getLeftText(value),
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
getTitlesWidget: (value, meta) {
final text = getLeftText(value);
return Tooltip(
message: text,
child: Text(
text.substringIfOverflow(leftTextMaxLength),
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
);
},
showTitles: true,
interval: yIntervals,
reservedSize: 40,
Expand Down
54 changes: 41 additions & 13 deletions lib/presentation/charts/widgets/vertical_bar_chart.dart
@@ -1,5 +1,6 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:shiori/domain/extensions/string_extensions.dart';

typedef OnBarChartTap = void Function(int);
typedef GetText = String Function(double);
Expand All @@ -24,6 +25,11 @@ class VerticalBarChart extends StatelessWidget {

final Color? tooltipColor;

final int bottomTextMaxLength;
final int leftTextMaxLength;

final bool rotateBottomText;

const VerticalBarChart({
Key? key,
required this.items,
Expand All @@ -33,6 +39,9 @@ class VerticalBarChart extends StatelessWidget {
required this.maxY,
required this.interval,
this.tooltipColor,
this.bottomTextMaxLength = 10,
this.leftTextMaxLength = 10,
this.rotateBottomText = false,
}) : super(key: key);

@override
Expand Down Expand Up @@ -69,14 +78,27 @@ class VerticalBarChart extends StatelessWidget {
bottomTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
getTitlesWidget: (value, meta) => Padding(
padding: const EdgeInsets.only(top: 10),
child: Text(
getBottomText(value),
textAlign: TextAlign.center,
style: textStyle,
),
),
getTitlesWidget: (value, meta) {
final text = getBottomText(value);
final tooltip = Tooltip(
message: text,
child: Text(
text.substringIfOverflow(bottomTextMaxLength),
textAlign: TextAlign.center,
style: textStyle,
overflow: TextOverflow.ellipsis,
),
);
return Padding(
padding: const EdgeInsets.only(top: 10),
child: !rotateBottomText
? tooltip
: RotationTransition(
turns: const AlwaysStoppedAnimation(15 / 360),
child: tooltip,
),
);
},
reservedSize: 40,
),
),
Expand All @@ -85,11 +107,17 @@ class VerticalBarChart extends StatelessWidget {
showTitles: true,
reservedSize: 40,
interval: interval,
getTitlesWidget: (value, meta) => Text(
getLeftText(value),
textAlign: TextAlign.center,
style: textStyle,
),
getTitlesWidget: (value, meta) {
final text = getLeftText(value);
return Tooltip(
message: text,
child: Text(
text.substringIfOverflow(leftTextMaxLength),
textAlign: TextAlign.center,
style: textStyle,
),
);
},
),
),
),
Expand Down
19 changes: 2 additions & 17 deletions lib/presentation/weapons/widgets/weapon_bottom_sheet.dart
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:responsive_builder/responsive_builder.dart';
import 'package:shiori/application/bloc.dart';
import 'package:shiori/domain/app_constants.dart';
import 'package:shiori/domain/enums/enums.dart';
import 'package:shiori/generated/l10n.dart';
import 'package:shiori/presentation/shared/bottom_sheets/common_bottom_sheet.dart';
Expand All @@ -16,22 +17,6 @@ import 'package:shiori/presentation/shared/sort_direction_popupmenu_filter.dart'
import 'package:shiori/presentation/shared/styles.dart';
import 'package:shiori/presentation/shared/weapons_button_bar.dart';

final _ignoredSubStats = [
StatType.atk,
StatType.critAtk,
StatType.critRate,
StatType.physDmgPercentage,
StatType.hp,
StatType.electroDmgBonusPercentage,
StatType.cryoDmgBonusPercentage,
StatType.pyroDmgBonusPercentage,
StatType.hydroDmgBonusPercentage,
StatType.geoDmgBonusPercentage,
StatType.anemoDmgBonusPercentage,
StatType.healingBonusPercentage,
StatType.def,
];

const _areWeaponTypesEnabledKey = 'areWeaponTypesEnabled';

class WeaponBottomSheet extends StatelessWidget {
Expand Down Expand Up @@ -163,7 +148,7 @@ class _OtherFilters extends StatelessWidget {
tooltipText: s.secondaryState,
onAllOrValueSelected: (v) => context.read<WeaponsBloc>().add(WeaponsEvent.weaponSubStatTypeChanged(v != null ? StatType.values[v] : null)),
selectedValue: tempWeaponSubStatType?.index,
values: StatType.values.where((el) => !_ignoredSubStats.contains(el)).map((e) => e.index).toList(),
values: getWeaponPossibleAscensionStats().map((e) => e.index).toList(),
itemText: (val, _) => s.translateStatTypeWithoutValue(StatType.values[val]),
icon: Icon(Shiori.sliders_h, size: Styles.getIconSizeForItemPopupMenuFilter(forEndDrawer, false)),
),
Expand Down

0 comments on commit cd37c2e

Please sign in to comment.