Newer
Older
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
import 'package:easy_localization/easy_localization.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:scrobbles/config/app_colors.dart';
class CustomChart extends StatelessWidget {
const CustomChart({super.key});
final double chartHeight = 150.0;
final double verticalTicksInterval = 10;
final String verticalAxisTitleSuffix = '';
final double titleFontSize = 9;
@override
Widget build(BuildContext context) {
return SizedBox(
height: this.chartHeight,
);
}
double getNextRoundNumber(double number, double scale) {
return scale * ((number ~/ scale).toInt() + 1);
}
Color getColorFromIndex(int index) {
const List<int> hexValues = [
0x8dd3c7,
0xffffb3,
0xbebada,
0xfb8072,
0x80b1d3,
0xfdb462,
0xb3de69,
0xfccde5,
0xd9d9d9,
0xbc80bd,
0xccebc5,
0xffed6f,
];
return Color(hexValues[index % hexValues.length] + 0xff000000);
}
String getDayShortName(int dayIndex) {
switch (dayIndex) {
case 1:
return 'MON';
case 2:
return 'TUE';
case 3:
return 'WED';
case 4:
return 'THU';
case 5:
return 'FRI';
case 6:
return 'SAT';
case 7:
return 'SUN';
default:
}
return '';
}
FlBorderData get noBorderData {
return FlBorderData(
show: false,
);
}
FlBorderData get simpleBorderData {
return FlBorderData(
show: true,
border: Border.all(
color: AppColors.borderColor,
width: 2,
),
);
}
FlGridData get noGridData {
return const FlGridData(
show: false,
);
}
FlGridData get horizontalGridData {
return const FlGridData(
show: true,
drawHorizontalLine: true,
drawVerticalLine: false,
);
}
FlTitlesData getTitlesData() {
return FlTitlesData(
show: false,
);
}
Widget getHorizontalTitlesWidget(double value, TitleMeta meta) {
return Text('');
}
Widget getHorizontalTitlesWidgetWithDate(double value, TitleMeta meta) {
final DateFormat formatter = DateFormat('dd/MM');
final DateTime date = DateTime.fromMillisecondsSinceEpoch(value.toInt());
final String text = formatter.format(date);
return SideTitleWidget(
axisSide: meta.axisSide,
space: 4,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: RotationTransition(
turns: new AlwaysStoppedAnimation(-30 / 360),
child: Text(
text,
style: TextStyle(
color: AppColors.mainTextColor1,
fontSize: this.titleFontSize,
),
),
),
),
);
}
Widget getHorizontalTitlesWidgetWithDay(double value, TitleMeta meta) {
final String dayShortName = getDayShortName(value.toInt());
return SideTitleWidget(
axisSide: meta.axisSide,
space: 2,
child: Text(
tr(dayShortName),
style: const TextStyle(
color: AppColors.mainTextColor1,
fontSize: 11,
),
),
);
}
Widget getHorizontalTitlesWidgetWithHour(double value, TitleMeta meta) {
String text = '';
if (value % 4 == 0 || value == 23) {
text = value.toInt().toString().padLeft(2, '0');
}
return SideTitleWidget(
axisSide: meta.axisSide,
space: 2,
child: Text(
text,
style: TextStyle(
color: AppColors.mainTextColor1,
fontSize: this.titleFontSize,
),
),
);
}
Widget getVerticalTitlesSpacerWidget(double value, TitleMeta meta) {
return SideTitleWidget(
axisSide: meta.axisSide,
space: 4,
child: Text(''),
);
}
Widget getVerticalTitlesWidget(double value, TitleMeta meta) {
String suffix =
this.verticalAxisTitleSuffix != '' ? ' ' + this.verticalAxisTitleSuffix : '';
return SideTitleWidget(
axisSide: meta.axisSide,
space: 4,
child: Text(
value.toInt().toString() + suffix,
style: TextStyle(
color: AppColors.mainTextColor1,
fontSize: this.titleFontSize,
),
),
);
}
}