Quadrant Setup

When looking at segments, think of them as being arranged in a grid with quadrants
Starting segment (left quadrants) should always be in Quadrants 2 or 3 (check work)
Ending segment (right quadrants) should always be in Quadrants 1 and 4 (check work)

First Data Point Rules:

Position label 0.5rem / 9px above point when segment is in Quadrant 3
If the point isn't near the x-axis, position label 0.5rem / 9px below point when segment is in Quadrant 1
If point is 20 pixels or less above x-axis (i.e., it's a low value and close to 0) position label 0.5rem / 9px above and 0.25rem / 4.5px to the left of point

Last Data Point Rules:
Position label 0.5rem / 9px above point when final segment is in Quadrant 4. This also works for when last data point is near x-axis (i.e. it's a low value that's close to 0)
If the point isn't near the x-axis and final segment is in Quadrant 2, position label 0.5rem / 9px below point
If the point is 20 pixels or less above x-axis (i.e., it's a low value and close to 0) then position label 0.5rem / 9px above and 0.25rem / 4.5px to the right of point

Middle Data Point Rules:
Position label 0.5rem / 9px above point when starting segment is in Quadrant 3 and ending segment is in Quadrant 4 and the angle created is 0°–180°

If the point isn't near the x-axis, position label 0.5rem / 9px below it when starting segment is in Quadrant 2 and ending segment is in Quadrant 1 and the angle created is 1°–179°
If the point is 20 pixels or less above x-axis (i.e., it's a low value and close to 0) and starting sement is in Quadrant 2 and ending segment is in Quadrant 1 then calculate the angle between the 2 segments:



If it's 135°–180° then position the label 0.5rem / 9px above the point
If it's  less than135°, calculate the angle created by the ending segment, if it's 68° or more then position the label 0.5rem / 9px above and 0.5rem / 9px to the right of the point
Otherwise, position the label 0.5rem / 9px above and 0.5rem / 9px to the left of the point
Position the label 0.5rem / 9px above and 0.5rem / 9px to the left of the point if starting segment is in Quadrant 3 and ending segment is in Quadrant 1 and the angle created is 92°–269°
Position the label 0.5rem / 9px above and 0.5rem / 9px to the right of the point if starting segment is in Quadrant 2 and ending segment is in Quadrant 4 and the angle created is 92°–269°