Spatial Layout
Created based on the slides at:
1. https://magrawala.github.io/cs448b-fa17/
2. http://www.cs.umd.edu/hcil/trs/98-09/98-09.pdf
3. http://www.merl.com/publications/docs/TR96-04.pdf
4. http://vis.berkeley.edu/papers/labellay/labellay.pdf
Problem
• Input: Set of graphic elements (scene description)
• Goal: Select visual attributes for elements
• Position
• Orientation
• Size
• Color
• …
How to Place Labels in a Graph
• Example
Approaches
• Direct rule-based methods
• Linear constraint satisfaction
• Optimization
• Example-based methods
Direct Rule-Based Methods
Example: Rule-based Timeline labeling
10 labels
• Alternate above/below line
• Center labels with respect to point on line
20 labels
• It doesn’t work well when lots of labels
Excentric Labeling
• Excentric labeling provides labels for a neighborhood of objects. The focus of the labeling
is centered on the cursor position. Labels are updated smoothly as the cursor moves over
the display, allowing hundreds of labels to be reviewed in a few seconds. The color of the
label border matches the object color.
http://www.cs.umd.edu/hcil/excentric/
Pros and Cons of Rule-Based Methods
• Pros:
• Designed to run extremely quickly
• Simple layout algorithms are easy to code
• Cons:
• Complex layouts require large rule bases with lots of special cases
Linear Constraint Satisfaction
Network of Layout Constraints
Constraints as Linear Equations
• Local propagation
• Set any variable
• Update other variables to maintain constraints
• One-way
• Each constraint has 1 output variable
• Update output when any input changes
• Multi-way
• Each constraint can be written with any variable as output
• More complicated to maintain
One-way Constraints
• One-way constraints form a directed acyclic graph (DAG). Given the value for any
variable, we propagate its value locally through the graph updating the other variables.
Example: Page Layout
Two layouts generated by
Weitzman’s system using
the same content and
abstract constraints with
different visual constraints
Adaptive Document Layout
• An adaptive layout style is encoded as a set of grid-based templates
that know how to adapt to a range of page sizes and other viewing
conditions.
• These templates include various types of layout elements (such as text,
figures, etc.) and define through constraint-based relationships, just
how these elements are to be laid out together as a function of both
the properties of the content itself, such as figure’s size and aspect ratio,
and the properties of the viewing conditions under which the content is
being displayed.
Adaptive Grid-Based Document Layout
• Examples of adaptive grid-based designs
at two different page sizes. This figure
shows how the system accommodates a
wide range of modern page-design
elements and ideas, including
arrangements of text in unusual
configurations, such as (from left to right)
text that starts beneath its continuation
and/or text that flows from regions with
one style of formatting to another; text
and captions that flow over colored
backdrops or other images; design
elements such as captions that carve out
text regions; and pull quotes. Also notice
how each example can automatically
adapt to portrait and landscape page
orientations by changing the
configuration of layout elements.
• Users authors templates which use one-
way constraints to adapt to changes in
page size.
Pros and Cons of Linear Constraint Methods
• Pros:
• Often run fast (at least one-way constraints)
• Constraint solving systems are available online
• Can be easier to specify relative layout constraints than to code direct layout
algorithm
• Cons:
• Easy to over-constrain the problem
• Constraint solving systems can only solve some types of layout problems
• Difficult to encode desired layout in terms of mathematical constraints.
Optimization
Layout as Optimization
• Scene description
• Geometry: polygons, bounding boxes, lines, points, etc.
• Layout parameters: position, orientation, scale, color, etc.
• Large design space of possible layout
• To use optimization we will specify …
• Initialize/Pertub functions: form a layout
• Penalty function: evaluate quality layout
• … and find layout that minimizes penalty
Optimization Algorithms
• There are lots of them:
• Line search, Newton’s method, A*, tabu, gradient descent, conjugate gradient,
linear programming, quadratic programming, simulated annealing, …
• Differences:
• Speed
• Memory
• Properties of the solution
• Requirements
Simulated Annealing
• Perturb: Efficiently cover layout design space
• Penalty: Describes desirable/undesirable features
Label placement technical approach
• Three following subtasks are used to label-placement task:
• Candidate-position generation:
• Given a point, line, or area feature, identify a set of candidate locations for its
label. A labeling is then a set of label positions, one drawn from each feature’s set
of candidate positions.
• Position evaluation:
• Given a labeling, efficiently compute a score that indicates its quality with respect
both to the position of labels relative to the labeled symbology, and to spatial
contention between the label and other features and feature labels.
• Position selection:
• Given a set of candidate label positions for each map feature, choose one label
position from each set so that the overall quality of the labeling, as determined
by the evaluation method, is as high as possible.
Position selection
• Given a set of generated candidate positions for each label and an overall
evaluation function, selecting positions for all the labels so that the
evaluation function is globally minimized is an optimization task.
• Although many different methods have been proposed for this task, we
favor a method based on simulated annealing
• First, place a label randomly in any one of the candidate positions for a feature
• Evaluate the quality of the random position
• Move the label to a new position randomly chosen from that feature’s set of candidate positions
• Evaluate the cost of the new position
• Compare them:
• If Cnew < Cold: move to the new solution
• If Cnew > Cold: maybe move to the new solution
• Repeat steps above until an acceptable solution is found or you reach some maximum number of
iterations.
Position evaluation
• The overall evaluation function is a weighted sum of the metrics described
below for each label on the map.
Position evaluation (Overlap Metrics)
• PointOver, LineOver, and AreaOver measures the number of point, line,
and area symbols that a given label overlaps.
• PointOver:
• The number of overlaps between a selected label position and all point-feature
symbols.
• labelOver:
• The number of overlaps between one selected label position and all others.
• LineOver and AreaOver:
• For area and line features, a label position that intersects and is parallel to the
polyline of a line feature or an area border is completely unacceptable. However, a
position that intersects the polyline at right angles might qualify as barely
acceptable.
• Example: let 𝑝1 and 𝑝2 be the points where a polyline enters and exits the label’s
bounding rectangle. Let the vector 𝑏 point in the direction of the label’s baseline
𝑝 −𝑝
and the vector 𝑣 = 2 1 approximate the direction of the polyline where it LineOver = 2.56
𝑝2 −𝑝1
intersects the label. The value of the metric (AreaOver or LineOver) is then 1 +
9 𝑣. 𝑏 .
LineOver = 9.86
• This metric ranges from 1.0 (label and line perpendicular: barely acceptable) to 10
(label and line parallel: unacceptable). Calculation of 𝑣 for the overlap metric
LineOver.
Positioning metrics (Point positioning)
• The sole metric for point-feature labels, PointPos, is determined by a ranking of a
discrete set of nineteen candidate positions surrounding a point.
• Label positions to the right of a point are preferred to those on the lest.
• Labels above a point are preferred to those below.
• The more a label’s baseline is offset from a horizontal line through the
center of its associated point, the less favored it is.
An example of 19 candidate label positions for a point feature and their PointPos values.
Positioning metrics (Line positioning)
• Definitions:
• baseline: the line which the characters are drawn.
• skyline: the bounding boxes of the label’s characters, which extends both above
and below the baseline.
• The ideal distance 𝛿 from the baseline of a label to a perfectly straight line
feature below it is included in several of the line-metric formulas. The ideal
distance should vary with both the thickness of the line feature and the type size,
𝑎𝑠𝑐𝑒𝑛𝑡 𝑡ℎ𝑖𝑐𝑘𝑛𝑒𝑠𝑠
so we set 𝛿 = + , where the ascent is the distance from the
4 2
baseline to the top of the capital letters of the label.
• The swath is an infinitely long strip, which is perpendicular to the baseline.
• The width of the swath is 20% greater than the width of the label.
Positioning metrics (Line positioning) Cntd.
• Positioning a label at an appropriate distance from its line feature is
crucial.
• To compute a local measure of the average distance 𝑑 from a label to its
associated line feature, we take the area between the swath line and the
lower side of the skyline, then divide by the width of the swath.
• Now we incorporate the average distance d into a useful metric:
(𝑑 − 𝛿)2
𝐴𝑣𝑒𝐷𝑖𝑠𝑡 =
𝛿2
Computing average distance.
Positioning metrics (Line positioning) Cntd.
Label positions with good AveDist values. Label positions with food Flatness values.
Generated label positions for a line feature.
Positioning metrics (Area positioning)
• We will assume that area features are usually large enough to accommodate their
labels, which consist of closely spaced horizontal text.
• The metric, AreaPos, measures the proximity of a label to its area’s centroid.
• Let 𝑐 be the distance from the center of a label position to the centroid of its
area feature. In the ideal case, 𝑐 = 0.
Candidate label positions for an area feature.
A labeled map.
Figure 1. The initial random labeling of
a randomly generated map
Figure 2. The map of figure 1, halfway
through position selection
Figure 3. The final labeling of the map of a
of figure 1.
Pros and Cons of Optimization Methods
• Pros:
• Much more flexible than linear constraint solving systems
• Cons:
• Can be relatively slow to converge
• Need to set penalty function parameters (weights)
• Difficult to encode desired layout in terms of mathematical penalty functions
Example-Based Methods
Preference Elicitation
• Learn characteristics of good designs
• Generate designs based on a parameterized design space
• Ask designers if they are good or bad
• Learn good parameters values based on responses
Nonlinear Inverse Optimization (NIO)
System overview: given an example layout style, the NIO learning algorithm produces a vector of style
parameters 𝜃. An energy-minimizing optimization then uses these style parameters to generate label layouts
for new diagrams in the same style.
Learn label layout style from a single example
Horizontal/Vertical layout style. Based on the single example layout style shown at top-left, our system learned a set of style parameters
and then automatically generated the other diagram layouts in the same style (from left-to-right, top row: violin, capsule; bottom row:
Skylab, phrenology, engine, pie chart).
The Horizontal/Vertical style favors leader lines oriented at 90 degrees, diagonals are strongly discouraged. The phrenology diagram is a
good example: since it is round, the labels can be placed around the figure to maintain the horizontal and vertical angle of the leader lines.
Some diagonal leader lines can not be avoided since our optimizer will not overlap labels with the illustration.
Learn label layout style from a single example
Parallel Leader Lines layout style encourages parallel leaders at arbitrary angles. For example, the leaders
below the capsule are all aligned, but not oriented at 90 degree increments like some previous styles.
Minimal training example
Minimal training example. Using a very simple diagram as an example style will not give NIO enough information to
specify . Even for a human, it is difficult to say what style is exemplified by the watch diagram, or whether it has been
correctly learned.
Pros and Cons of Example-based Methods
• Pros:
• Often much easier to specify desired layout via examples
• Cons:
• Usually requires underlying model
• Model will constrain types of layouts possible
• Large design spaces likely to require lots of examples to learn parameters well