Skip to content

Commit f959489

Browse files
committed
copy interactive tip example to the centroid page
1 parent 99dcd9a commit f959489

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/transforms/centroid.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {computed, shallowRef, onMounted} from "vue";
88
const us = shallowRef(null);
99
const countymesh = computed(() => us.value ? topojson.mesh(us.value, us.value.objects.counties) : {type: null});
1010
const statemesh = computed(() => us.value ? topojson.mesh(us.value, us.value.objects.states) : {type: null});
11+
const states = computed(() => us.value ? topojson.feature(us.value, us.value.objects.states).features : []);
1112
const counties = computed(() => us.value ? topojson.feature(us.value, us.value.objects.counties).features : []);
13+
const nation = computed(() => us.value ? topojson.feature(us.value, us.value.objects.nation) : []);
1214

1315
onMounted(() => {
1416
d3.json("../data/us-counties-10m.json").then((data) => (us.value = data));
@@ -86,6 +88,22 @@ Plot.dot(counties, Plot.hexbin({r:"count"}, Plot.geoCentroid())).plot({projectio
8688
```
8789
:::
8890

91+
Combined with the [pointer transform](../interactions/pointer.md), the centroid transform can add [interactive tips](./tip.md) on a map:
92+
93+
:::plot defer https://observablehq.com/@observablehq/plot-state-centroids
94+
```js
95+
Plot.plot({
96+
projection: "albers-usa",
97+
marks: [
98+
Plot.geo(statemesh, {strokeOpacity: 0.2}),
99+
Plot.geo(nation),
100+
Plot.dot(states, Plot.centroid({fill: "red", stroke: "var(--vp-c-bg-alt)"})),
101+
Plot.tip(states, Plot.pointer(Plot.centroid({title: (d) => d.properties.name})))
102+
]
103+
})
104+
```
105+
:::
106+
89107
## centroid(*options*)
90108

91109
```js

0 commit comments

Comments
 (0)