Skip to main content
100%

Directional arrows #4

✓ Published0🌍 Public
TThanaporn-sk
Last edited May 6, 2017
Created on May 6, 2017

A D3 v4 visualization renders 20 arrow markers along a hand-coded SVG path loop, with each arrow offset 15 pixels to one side. The code uses native SVG path methods like `getTotalLength()`, `getPointAtLength()`, and `atan2` to approximate tangent angles for placement. Arrows are drawn as separate SVG path elements with a `marker-end` reference to an arrowhead, and spacing is computed by walking along the path in 3-pixel increments and measuring cumulative lengths to ensure roughly even distribution.

AI-generated description

Placing some offset directional arrows along a path, take 4.

This method is definitely overkill. It calculates one offset point per three pixels along the original path, and then walks that list of points one at a time to ensure that the resulting arrows are roughly evenly spaced and roughly the same length, regardless of the angles of their curves. You could make this slower + more precise, or faster + less precise, by changing the number of pixels per step.

marker-segment and marker-pattern should make this easier eventually.

forked from <a href='http://bl.ocks.org/veltman/'>veltman</a>'s block: <a href='http://bl.ocks.org/veltman/2ffca9dfddbfe67dc8e70a08fa429d6b'>Directional arrows #4</a>

mit Licensed

Similar vizzes