Skip to content

Commit 5c670e7

Browse files
mbostockFil
authored andcommitted
move arc diagram example up
1 parent a522541 commit 5c670e7

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

docs/marks/arrow.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function samegroup({source, target}) {
2222

2323
# Arrow mark <VersionBadge version="0.4.0" />
2424

25+
:::tip
26+
See also the [vector mark](./vector.md), which draws arrows of a given length and direction.
27+
:::
28+
2529
The **arrow mark** draws arrows between two points [**x1**, **y1**] and [**x2**, **y2**] in quantitative dimensions. It is similar to the [link mark](./link.md), except it draws an arrowhead and is suitable for directed edges. With the **bend** option, it can be swoopy.⤵︎
2630

2731
For example, below we show the rising inequality (and population) in various U.S. cities from 1980 to 2015. Each arrow represents two observations of a city: the city’s population (**x**) and inequality (**y**) in 1980, and the same in 2015. The arrow’s **stroke** redundantly encodes the change in inequality: red indicates rising inequality, while blue (there are only four) indicates declining inequality.
@@ -100,7 +104,24 @@ Plot.plot({
100104
```
101105
:::
102106

103-
See also the [vector mark](./vector.md), which draws arrows of a given length and direction.
107+
For undirected edges, as in the arc diagram of character co-occurrence in *Les Misérables* below, set the **sweep** option to the desired orientation: *-y* for right-bulging links whose endpoints are vertically separated.
108+
109+
:::plot https://observablehq.com/@observablehq/plot-arc-diagram
110+
```js
111+
Plot.plot({
112+
height: 1080,
113+
marginLeft: 100,
114+
axis: null,
115+
x: {domain: [0, 1]}, // see https://github.com/observablehq/plot/issues/1541
116+
color: {domain: d3.range(10), unknown: "#ccc"},
117+
marks: [
118+
Plot.dot(miserables.nodes, {x: 0, y: "id", fill: "group", sort: {y: "fill"}}),
119+
Plot.text(miserables.nodes, {x: 0, y: "id", text: "id", textAnchor: "end", dx: -6, fill: "group"}),
120+
Plot.arrow(miserables.links, {x: 0, y1: "source", y2: "target", sweep: "-y", bend: 90, headLength: 0, stroke: samegroup, sort: samegroup, reverse: true})
121+
]
122+
})
123+
```
124+
:::
104125

105126
## Arrow options
106127

@@ -125,24 +146,7 @@ The arrow mark supports the [standard mark options](../features/marks.md#mark-op
125146

126147
The **bend** option sets the angle between the straight line connecting the two points and the outgoing direction of the arrow from the start point. It must be within ±90°. A positive angle will produce a clockwise curve; a negative angle will produce a counterclockwise curve; zero will produce a straight line. The **headAngle** determines how pointy the arrowhead is; it is typically between 0° and 180°. The **headLength** determines the scale of the arrowhead relative to the stroke width. Assuming the default of stroke width 1.5px, the **headLength** is the length of the arrowhead’s side in pixels.
127148

128-
The **sweep** option <VersionBadge pr="1740" /> controls the bend orientation. It defaults to 1 indicating a positive (clockwise) bend angle; -1 indicates a negative (anticlockwise) bend angle; 0 effectively clears the bend angle. If *-x*, the bend angle is flipped when the ending point is to the left of the starting point — ensuring all arrows bulge up (down if bend is negative); if *-y*, the bend angle is flipped when the ending point is above the starting point — ensuring all arrows bulge right (left if bend is negative); the sign is negated for *+x* and *+y*. Below, *-y* is used to render undirected edges in an arc diagram.
129-
130-
:::plot https://observablehq.com/@observablehq/plot-arc-diagram
131-
```js
132-
Plot.plot({
133-
height: 1080,
134-
marginLeft: 100,
135-
axis: null,
136-
x: {domain: [0, 1]}, // see https://github.com/observablehq/plot/issues/1541
137-
color: {domain: d3.range(10), unknown: "#ccc"},
138-
marks: [
139-
Plot.dot(miserables.nodes, {x: 0, y: "id", fill: "group", sort: {y: "fill"}}),
140-
Plot.text(miserables.nodes, {x: 0, y: "id", text: "id", textAnchor: "end", dx: -6, fill: "group"}),
141-
Plot.arrow(miserables.links, {x: 0, y1: "source", y2: "target", sweep: "-y", bend: 90, headLength: 0, stroke: samegroup, sort: samegroup, reverse: true})
142-
]
143-
})
144-
```
145-
:::
149+
The **sweep** option <VersionBadge pr="1740" /> controls the bend orientation. It defaults to 1 indicating a positive (clockwise) bend angle; -1 indicates a negative (anticlockwise) bend angle; 0 effectively clears the bend angle. If *-x*, the bend angle is flipped when the ending point is to the left of the starting point — ensuring all arrows bulge up (down if bend is negative); if *-y*, the bend angle is flipped when the ending point is above the starting point — ensuring all arrows bulge right (left if bend is negative); the sign is negated for *+x* and *+y*.
146150

147151
## arrow(*data*, *options*) {#arrow}
148152

docs/marks/vector.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ onMounted(() => {
3939

4040
# Vector mark <VersionBadge version="0.4.0" />
4141

42+
:::tip
43+
See also the [arrow mark](./arrow.md), which draws arrows between two points.
44+
:::
45+
4246
The **vector mark** draws little arrows, typically positioned in **x** and **y** quantitative dimensions, with an optional magnitude (**length**) and direction (**rotate**), as in a vector field. For example, the chart below, based on a [LitVis example](https://github.com/gicentre/litvis/blob/main/examples/windVectors.md), shows wind speed and direction for a section of western Europe.
4347

4448
:::plot defer https://observablehq.com/@observablehq/plot-wind-map

0 commit comments

Comments
 (0)