Text That Follows the Curve: Labels Along Any Path in CanvasXpress
▶ Curved Contour-Level Labels▶ Curved Density-Curve Labels (Iris)
Labels are where a lot of charts quietly fall apart. A contour map with its level values stamped flat and horizontal across curving iso-lines looks bolted-on. A line chart that drops each series name at the far right edge forces the reader's eye to travel back and forth. The information is all there, but it does not sit on the thing it describes.
CanvasXpress now draws text that follows a path. Each glyph is rotated to the local direction of the curve it rides, so a label flows along a contour ring or a trend line the way a river name flows along a river on a good map. When a label sits on a line, the line can even break to make room, so the text reads cleanly without a stroke running through it.
Two places you can use it today
The new capability is wired into the two spots where it helps most, each behind a simple, default-off switch so nothing about your existing charts changes unless you ask.
Curved contour labels. Turn on curvedContourLabels and each iso-line's level value is drawn as curved text that hugs the line, rotated glyph by glyph to match the local tangent, with a gap cut in the line where the label sits. Contour plots suddenly read like topographic maps instead of grids with numbers floating over them.
Labels along line series. Turn on showLineLabels and each series name is drawn along its own line rather than parked at the end. On a busy multi-series chart that is the difference between a legend-hunting exercise and a chart that labels itself in place. The same mechanism also labels density curves, so a distribution plot can name each curve right on the curve.
A concrete example
new CanvasXpress("chart", data, {
graphType: "Contour",
showContourLevel: true,
curvedContourLabels: true
});
That one flag takes the contour level labels you already had and lays them along the iso-lines, rotated and with a clean gap in each ring. For line series:
new CanvasXpress("chart", data, {
graphType: "Line",
showLineLabels: true
});
Every visible series gets its name curved along its trajectory. The line label styling — color, size, style, alignment, baseline — is adjustable as a bundle, so you can tune how the labels sit without fighting the engine.
What makes curved text actually hard
It is easy to underestimate this. Rotating each letter to the tangent of a curve sounds like a one-liner, and the naive version produces text that is almost right and deeply wrong in the ways that matter:
- On a jittery curve — a contour ring traced out of a grid, for instance — using the raw direction of each tiny segment makes the letters jitter too, so the word looks shattered. The engine averages the tangent over a small window so the text bends smoothly.
- When a path runs right-to-left across the screen, walking the letters in reading order along the curve spells the word backwards. The engine detects the flip and walks the string the other way, so the label always reads left-to-right to a human.
- Letters that would otherwise end up upside-down on the underside of a curve are flipped upright, so text is never mirrored or inverted.
- Where a label is longer than the line it would sit on, the engine falls back to a flat label rather than dropping it silently — you never lose information.
All of this rides on the engine's existing text and export pipeline, so curved labels come through in saved images and vector exports exactly as they appear on screen. There is no separate export path to maintain and no surprise when you save the figure.
Why it is worth turning on
Good label placement is one of those things readers never notice when it is done well and always notice when it is done badly. Flat labels over curved geometry read as a chart that was generated rather than designed. Text that follows the curve reads as a chart someone cared about.
The practical wins are concrete. Contour plots become legible without a separate legend mapping colors to levels — the value is written right on the line. Multi-series line charts stop needing the reader to cross-reference a legend against line colors, because each line says its own name. Distribution plots label their curves in place. And because the whole thing is default-off and controlled by a single parameter per use, you adopt it exactly where it helps and leave everything else untouched.
Getting started
Add curvedContourLabels: true to a contour chart, or showLineLabels: true to a line or density chart, and look at the result. For anything with curving geometry and text that needs to describe it, labels that follow the path are the detail that makes a chart feel finished.