Skip to content

A fast (linear time) algorithm for vertical label placement

License

Notifications You must be signed in to change notification settings

KateMorley/vertical_label_placement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vertical label placement

Functions for vertical label placement that minimise the maximum absolute offset of any label from its preferred position, while respecting limits on how high or low labels may be placed. This crate serves as a reference implementation of the algorithm described in Kate Morley’s article Vertical label placement.

Examples

Placing labels, respecting a minimum separation:

let preferred_positions = vec![-10, -1, 1, 10];

let permitted_positions = vertical_label_placement::place(&preferred_positions, 10);

assert_eq!([-15, -5, 5, 15], *permitted_positions);

Placing labels, respecting a minimum separation and minimum and maximum positions:

let preferred_positions = vec![-10, -1, 1, 10];

let permitted_positions = vertical_label_placement::place_with_limits(
    &preferred_positions,
    10,
    0,
    100
);

assert_eq!([0, 10, 20, 30], *permitted_positions);

About

A fast (linear time) algorithm for vertical label placement

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages