1.0.0 • Published 8 years ago
label-segment v1.0.0
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-segmentTo use in your code, type
import labelSegment from 'label-segment';The vanilla JavaScript way
Include the following script tag in your HTML:
<script src="http://unpkg.com/label-segment/dist/label-segment.js"></script>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 pixels
var textPath = labelSegment(path, Math.PI / 8, 50);
// Now render text along textPathParameters
pathArray<Array<number>> Path represented by coordinate pairs.maxAnglenumber Maximum angle in radians for a suitable segment.labelLengthnumber 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.
1.0.0
8 years ago