Perforce JViews Diagrammer Code Example: Point Label Layout


Description

This sample illustrate the Annealing Label Layout provided by the JViews Label Layout module. It shows how labels can be automatically placed close to given points.

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, point-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 labels can be automatically placed close to given points. A typical application is the labeling of cities in a geographic map. Another application is to label the nodes of a graph. The label layout algorithm used in this sample is based on Simulated Annealing.
It tries to place labels such that the overlaps among 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 five samples:

Notes about this application

Installation Directory

The Point 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.