An open API service indexing awesome lists of open source software.

https://github.com/harrystevens/d3-arrow

Attach arrowheads to SVG elements.
https://github.com/harrystevens/d3-arrow

Last synced: 18 days ago
JSON representation

Attach arrowheads to SVG elements.

Awesome Lists containing this project

README

        

# d3-arrow
Attach arrowheads to SVG elements. This module is in alpha, so use with caution.

## Installing

If you use NPM, `npm install d3-arrow`. Otherwise, download the [latest release](https://github.com/HarryStevens/d3-arrow/raw/master/dist/d3-arrow.zip). AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3 global is exported:

```html

const arrow = d3.arrow1();

```

## API Reference

The API is based on the list of arrows in Adobe Illustrator v24.1.2. To add an arrowhead to an SVG element, you must first add the arrowhead generator to your SVG using [selection.call](https://github.com/d3/d3-selection#selection_call). Then, pass the generator's [id](#arrow_id) to the element's "marker-end" attribute:

```js
const svg = d3.select("body").append("svg")
.attr("width", 60)
.attr("height", 20);

const arrow = d3.arrow1()
.id("my-arrow")
.attr("fill", "steelblue")
.attr("stroke", "steelblue");

svg.call(arrow);

svg.append("polyline")
.attr("marker-end", "url(#my-arrow)")
.attr("points", [[5, 10], [55, 10]])
.attr("stroke", "steelblue")
.attr("stroke-width", 2);
```

# d3.arrow1() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-1.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-1" and a [scale](#arrow_scale) of 1.

# d3.arrow2() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-2.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-2" and a [scale](#arrow_scale) of 1.

# d3.arrow3() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-3.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-3" and a [scale](#arrow_scale) of 1.

# d3.arrow5() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-5.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-5" and a [scale](#arrow_scale) of 1.

# d3.arrow10() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-10.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-10" and a [scale](#arrow_scale) of 1.

# d3.arrow11() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-11.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-11" and a [scale](#arrow_scale) of 1.

# d3.arrow13() · [Source](https://github.com/harrystevens/d3-arrow/blob/master/src/arrow-13.js "Source"), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Creates a new arrow generator with an [id](#arrow_id) of "d3-arrow-13" and a [scale](#arrow_scale) of 1.

# arrow(context) · [Source](https://github.com/d3/d3-arrow/blob/master/src/index.js), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Add the arrow generator to the given context, which should be a selection of SVG elements.

# arrow.id([id]) · [Source](https://github.com/d3/d3-arrow/blob/master/src/index.js), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Sets or gets the arrow's unique id string, which you'll reference when setting the element's "marker-end" attribute.

# arrow.scale([scale]) · [Source](https://github.com/d3/d3-arrow/blob/master/src/index.js), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Sets or gets the arrow's scale number.

# arrow.attr(key[, value]) · [Source](https://github.com/d3/d3-arrow/blob/master/src/utils/iterate.js), [Example](https://observablehq.com/d/7759e56ba89ced03 "Example")

Sets or gets an appearance attribute's value.