Perforce JViews Diagrammer Code Example: Link Label Layout


Description

This sample illustrate the Annealing Label Layout provided by the JViews Label Layout module. It shows how to automatically place labels close to polyline links of a grapher.

How to Use the Code Example

How to Run the Code Example as an Application

This code example can be run as an application. The installation directory contains an executable JAR file, link-label-layout.jar, that allows you to execute the code example with a double click from a file browser. Note that if you are using Internet Explorer, you can open the installation directory and execute the JAR file from the browser. This technique may not work in other Web browsers.

Alternatively, you can run the code example application from the command line. First check that the Ant utility is properly configured. If not, see the instructions on how to configure Ant for Perforce JViews.

Then, go to the installation directory of the code example and type:

ant run

Topics Covered

Detailed Description

This application illustrates how to automatically place labels close to the polyline links of a grapher. The same mechanism can be used to place labels close to any polylines. That is, it can be used to label the roads of a map: each label is placed close to the polyline object that represents the road. The label layout algorithm used in this sample is based on Simulated Annealing.
It tries to place labels such that the overlaps among labels, and between labels and obstacles are small. Overlaps are avoided in order to keep labels readable.
Simulated annealing is a quality controlled, randomized iterative heuristic. The labels are placed according to a temperature scheme, and the quality of the placement increases when the temperature decreases. The quality is defined by the amount of overlaps between pairs of labels and between labels and obstacles. The fewer overlaps the higher the quality. Simulated annealing, as randomized algorithm, does not guarantee a placement of the labels without overlaps. However, it produces a quality layout with a high probability.

Samples

There are four samples:

Notes about this application

Installation Directory

The Link Label Layout code example is installed here.

Classes Involved

Source Files

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All rights reserved. Legal terms.