Created
June 13, 2021 16:51
-
-
Save Indy9000/0c90bb62f65a133d3196af6d6a285428 to your computer and use it in GitHub Desktop.
line-chart-widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WeekDays = ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; | |
class LineChartPainter extends CustomPainter { | |
final List<Score> scores; | |
late double _min, _max; | |
late List<double> _Y; | |
late List<String> _X; | |
LineChartPainter(this.scores) { | |
var min = double.maxFinite; | |
var max = -double.maxFinite; | |
scores.forEach((p) { | |
min = min > p.value ? p.value : min; | |
max = max < p.value ? p.value : max; | |
}); | |
_min = min; | |
_max = max; | |
_Y = scores.map((p) => p.value).toList(); | |
_X = scores | |
.map((p) => "${WeekDays[p.time.weekday]}\n${p.time.day}") | |
.toList(); | |
} | |
@override | |
void paint(Canvas canvas, Size size) {} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment