statannot
statannot copied to clipboard
Place adjacent annotations side-by-side instead of stacking
Side-by-side annotations
(Sun, Thur), (Thur, Fri), and (Fri, Sat) comparisons are all placed on the same line, saving vertical space.
Original
(Thur, Fri) annotation is on a different line from (Sun, Thur) and (Fri, Sat) in the current master.
How does it work?
The current master vertically arranges annotations by creating a stack of vertical offsets over the center of each category. When an annotation is added, statannot checks the height of all the stacks between each of the categories being compared (inclusively) and uses/pushes an offset based on the height of the tallest stack. (If I remember correctly---I actually wrote the code in this PR months ago because I needed some really compact graphs in a hurry.)
This PR basically works the same way, but creates sub-stacks slightly to the left and right of the center of each category.
- If we have categories A, B, C and we want to add an annotation to (A, B), we check the current height of
A.right_baseline
andB.left_baseline
, draw the annotation, and increment those two values. - If we later want to add an annotation to (B, C), we check
B.right_baseline
which is independent ofB.left_baseline
. - Finally, if we want to add (A, C), we check the height of
A.right_baseline
,C.left_baseline
, andB.max_baseline
(whereB.max_baseline == max(B.left_baseline, B.right_baseline)
).
New objects
This PR introduced a couple of new objects _EligibleBaseline
and _EligibleBaselineGroup
to handle vertical annotation layout. In particular, _EligibleBaselineGroup
abstracts the process of calculating the vertical baseline for an annotation based on its horizontal position.