label-segment
Find suitable segments of a path for its label text.
Getting started
The ES2015 way
To add the dependency to your project, run
npm install --save label-segment
To use in your code, type
;
The vanilla JavaScript way
Include the following script tag in your HTML:
API
labelSegment
Considering a given path, maximum angle and label length, this function returns a straight enough subset of the path in correct direction for an upright label.
Example:
var path = 20 33 40 31 60 30 80 31 100 33;var textLength = 50; // Text has a width of 50 pixelsvar textPath = ;// Now render text along textPath
Parameters
path
Array<Array<number>> Path represented by coordinate pairs.maxAngle
number Maximum angle in radians for a suitable segment.labelLength
number Required segment length for the label.
Returns (Array<Array<number>> | undefined) Path to draw the label along, in the
correct direction for an upright label. Returns undefined
when no suitable
subset of the given path
was found.