-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
charts_page.dart
215 lines (207 loc) · 10.1 KB
/
charts_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:shiori/application/bloc.dart';
import 'package:shiori/domain/enums/enums.dart';
import 'package:shiori/domain/extensions/iterable_extensions.dart';
import 'package:shiori/generated/l10n.dart';
import 'package:shiori/injection.dart';
import 'package:shiori/presentation/banner_history/widgets/version_details_dialog.dart';
import 'package:shiori/presentation/character/character_page.dart';
import 'package:shiori/presentation/charts/widgets/chart_card.dart';
import 'package:shiori/presentation/charts/widgets/chart_legend.dart';
import 'package:shiori/presentation/charts/widgets/horizontal_bar_chart.dart';
import 'package:shiori/presentation/charts/widgets/pie_chart.dart';
import 'package:shiori/presentation/charts/widgets/vertical_bar_chart.dart';
import 'package:shiori/presentation/shared/extensions/element_type_extensions.dart';
import 'package:shiori/presentation/shared/extensions/i18n_extensions.dart';
import 'package:shiori/presentation/shared/loading.dart';
import 'package:shiori/presentation/shared/styles.dart';
import 'package:shiori/presentation/weapon/weapon_page.dart';
const double _topCardWidth = 350;
const double _topCardHeight = 300;
const double _topCardBoxHeight = _topCardHeight + 20;
const _topCharacterTypes = [
ChartType.topFiveStarCharacterMostReruns,
ChartType.topFiveStarCharacterLeastReruns,
ChartType.topFourStarCharacterMostReruns,
ChartType.topFourStarCharacterLeastReruns,
];
const _topWeaponTypes = [
ChartType.topFiveStarWeaponMostReruns,
ChartType.topFiveStarWeaponLeastReruns,
ChartType.topFourStarWeaponMostReruns,
ChartType.topFourStarWeaponLeastReruns,
];
const _topCharacterColors = [Colors.red, Colors.orange, Colors.yellow, Colors.green, Colors.blue];
const _topWeaponColors = [Colors.red, Colors.orange, Colors.yellow, Colors.green, Colors.blue];
class ChartsPage extends StatelessWidget {
const ChartsPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final mq = MediaQuery.of(context);
final s = S.of(context);
final now = DateTime.now();
final formatter = DateFormat('MMM');
final List<String> months = List.generate(DateTime.monthsPerYear, (int index) {
final date = DateTime(now.year, index + 1);
return formatter.format(date);
});
return BlocProvider<ChartsBloc>(
create: (context) => Injection.chartsBloc..add(const ChartsEvent.init()),
child: Scaffold(
appBar: AppBar(
title: Text(s.charts),
),
body: SingleChildScrollView(
child: Padding(
padding: Styles.edgeInsetAll5,
child: BlocBuilder<ChartsBloc, ChartsState>(
builder: (context, state) => state.map(
loading: (_) => const Loading(useScaffold: false),
initial: (state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(s.topCharacters, style: theme.textTheme.headline5),
SizedBox(
height: _topCardBoxHeight,
//TODO: SPACE BETWEEN ITEMS
child: ListView.builder(
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: _topCharacterTypes.length,
itemBuilder: (ctx, index) {
final type = _topCharacterTypes[index];
final items = state.tops.where((el) => el.type == type).toList();
return ChartCard(
height: _topCardHeight,
width: _topCardWidth,
title: s.translateChartType(type),
//TODO: THIS TEXT
bottom: Text(
'Number of times a character was released',
style: theme.textTheme.caption,
textAlign: TextAlign.center,
),
child: Row(
children: [
Flexible(flex: 70, fit: FlexFit.tight, child: TopPieChart(items: items, colors: _topCharacterColors)),
Flexible(
flex: 30,
fit: FlexFit.tight,
child: ChartLegend(
indicators: items
.mapIndex(
(e, i) => ChartLegendIndicator(
text: e.name,
color: _topCharacterColors[i],
tap: () => CharacterPage.route(e.key, context),
),
)
.toList(),
),
),
],
),
);
},
),
),
Text(s.topWeapons, style: theme.textTheme.headline5),
SizedBox(
height: _topCardBoxHeight,
child: ListView.builder(
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: _topWeaponTypes.length,
itemBuilder: (ctx, index) {
final type = _topWeaponTypes[index];
final items = state.tops.where((el) => el.type == type).toList();
return ChartCard(
height: _topCardHeight,
width: _topCardWidth,
title: s.translateChartType(type),
bottom: Text(
'Number of times a character was released',
style: theme.textTheme.caption,
textAlign: TextAlign.center,
),
child: Row(
children: [
Flexible(flex: 70, fit: FlexFit.tight, child: TopPieChart(items: items, colors: _topWeaponColors)),
Flexible(
flex: 30,
fit: FlexFit.tight,
child: ChartLegend(
indicators: items
.mapIndex(
(e, i) => ChartLegendIndicator(
text: e.name,
color: _topWeaponColors[i],
tap: () => WeaponPage.route(e.key, context),
),
)
.toList(),
),
),
],
),
);
},
),
),
const SizedBox(height: 10),
Text(s.elements, style: theme.textTheme.headline5),
//TODO: VERSIONS WILL GROW OVER TIME AND THIS CHART MAY LOOK UGLY
ChartCard(
width: mq.size.width,
height: 400,
title: s.mostAndLeastReleased,
bottom: Row(
mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: WrapCrossAlignment.center,
// alignment: WrapAlignment.center,
children: state.elements
.map(
(e) => ChartLegendIndicator(
color: e.type.getElementColorFromContext(context),
text: s.translateElementType(e.type),
expandText: false,
lineThrough: state.selectedElementTypes.contains(e.type),
tap: () => context.read<ChartsBloc>().add(ChartsEvent.elementSelected(type: e.type)),
),
)
.toList(),
),
child: HorizontalBarChart(
items: state.filteredElements,
canValueBeRendered: ChartsBloc.isValidVersion,
onPointTap: (version) => showDialog(
context: context,
builder: (_) => VersionDetailsDialog(
version: version,
showWeapons: false,
),
),
),
),
Text(s.birthdays, style: theme.textTheme.headline5),
ChartCard(
width: 300,
height: 400,
title: s.mostAndLeastRepeated,
child: VerticalBarChart(items: state.birthdays, months: months),
),
],
);
},
),
),
),
),
),
);
}
}