Class: ScaleBar

ScaleBar

ScaleBar class creates a visual scale bar that updates with viewer zoom level. Features:

  • Automatic scale adjustment based on zoom
  • Smart unit selection
  • SVG-based visualization
  • Configurable size and appearance

new ScaleBar(pixelSize, viewer [, options])

Creates a new ScaleBar instance.

Parameters:
Name Type Argument Description
pixelSize number

Size of a pixel in real-world units (in mm)

viewer Viewer

The OpenLIME viewer instance

options Object <optional>

Configuration options

Properties
Name Type Argument Default Description
width number <optional>
200

Width of the scale bar in pixels

fontSize number <optional>
24

Font size for scale text in pixels

precision number <optional>
0

Number of decimal places for scale values

Properties:
Name Type Description
svg SVGElement

Main SVG container element

line SVGElement

Scale bar line element

text SVGElement

Scale text element

lastScaleZoom number

Last zoom level where scale was updated

Source:

Extends

Methods


format(d [, unit])

Formats a measurement value with appropriate units. Automatically selects the best unit if none specified.

Parameters:
Name Type Argument Description
d number

Value to format (in millimeters)

unit string <optional>

Specific unit to use for formatting

Inherited From:
Overrides:
Source:
Returns:

Formatted measurement with units (e.g., "5.00 mm" or "1.00 m")

Type
string
Example
const units = new Units();
units.format(1500);       // Returns "1.50 m"
units.format(1500, 'mm'); // Returns "1500.00 mm"