Skip to content

Instantly share code, notes, and snippets.

@Indy9000
Created June 13, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Indy9000/0c90bb62f65a133d3196af6d6a285428 to your computer and use it in GitHub Desktop.
Save Indy9000/0c90bb62f65a133d3196af6d6a285428 to your computer and use it in GitHub Desktop.
line-chart-widget
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