addNumbers method
Adds numbers to the graph indicating the grid steps.
Implementation
void addNumbers(Canvas canvas, Size size) {
double xPositiveLength = size.width / 2 + graph.focusPoint.x;
double yPositiveLength = (size.height / 2 + graph.focusPoint.y);
var counter = 0;
var pointsCountFromBeginning = (xPositiveLength / graph.gridStep).floor();
// Determine how many grid steps are on the screen.
for (double i = 0; i <= size.width; i += graph.gridStep) {
var offset = Offset(
(graph.gridStep * (pointsCountFromBeginning - counter)).toDouble() -
4,
0);
if ((pointsCountFromBeginning - counter) != 0) {
addObject(GraphLine(
color: graph.gridColor,
startOffset: Offset(
offset.dx + 4, -(size.height / 2 + graph.focusPoint.y.abs())),
endOffset: Offset(
offset.dx + 4, size.height / 2 + graph.focusPoint.y.abs()),
lineWidth: graph.gridWidth));
addObject(GraphText(
textStyle: graph.numbersStyle,
text: (pointsCountFromBeginning - counter).toString(),
offset: offset));
}
counter++;
}
counter = 0;
pointsCountFromBeginning = (yPositiveLength / graph.gridStep).floor();
// Draw numbers on the y-axis.
for (double i = 0; i <= size.height; i += graph.gridStep) {
var offset = Offset(
0,
(graph.gridStep * (pointsCountFromBeginning - counter)).toDouble() -
9);
if (pointsCountFromBeginning - counter != 0) {
addObject(GraphLine(
color: graph.gridColor,
startOffset: Offset(
-(size.width / 2 + graph.focusPoint.x.abs()), offset.dy + 10),
endOffset: Offset(
(size.width / 2 + graph.focusPoint.x.abs()), offset.dy + 10),
lineWidth: graph.gridWidth));
addObject(GraphText(
textStyle: graph.numbersStyle,
text: (-(pointsCountFromBeginning - counter)).toString(),
offset: offset,
));
}
counter++;
}
}