Skip to content

Commit c75ad08

Browse files
committed
replace complicated v-counties example with state labels
1 parent f959489 commit c75ad08

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

docs/transforms/centroid.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as topojson from "topojson-client";
66
import {computed, shallowRef, onMounted} from "vue";
77

88
const us = shallowRef(null);
9-
const countymesh = computed(() => us.value ? topojson.mesh(us.value, us.value.objects.counties) : {type: null});
109
const statemesh = computed(() => us.value ? topojson.mesh(us.value, us.value.objects.states) : {type: null});
1110
const states = computed(() => us.value ? topojson.feature(us.value, us.value.objects.states).features : []);
1211
const counties = computed(() => us.value ? topojson.feature(us.value, us.value.objects.counties).features : []);
@@ -20,34 +19,15 @@ onMounted(() => {
2019

2120
# Centroid transform
2221

23-
Plot offers two transforms that derive centroids from GeoJSON geometries: [centroid](#centroid-options) and [geoCentroid](#geocentroid-options). These transforms can be used by any mark that accepts **x** and **y** channels. For instance, to label the U.S. counties with names starting with V—this is more interesting than it seems—we can use a [dot mark](../marks/dot.md) and a [text mark](../marks/text.md).
22+
Plot offers two transforms that derive centroids from GeoJSON geometries: [centroid](#centroid-options) and [geoCentroid](#geocentroid-options). These transforms can be used by any mark that accepts **x** and **y** channels. For instance, a [text mark](../marks/text.md) to label the U.S. States.
2423

25-
:::plot defer https://observablehq.com/@observablehq/plot-v-counties
24+
:::plot defer https://observablehq.com/@observablehq/plot-state-labels
2625
```js
2726
Plot.plot({
2827
projection: "albers-usa",
2928
marks: [
30-
Plot.geo(countymesh, {strokeWidth: 0.1}),
31-
Plot.geo(statemesh, {strokeWidth: 0.5}),
32-
Plot.dot(
33-
counties,
34-
Plot.centroid({
35-
filter: (d) => d.properties.name.match(/^V/),
36-
fill: "currentColor",
37-
stroke: "var(--vp-c-bg)"
38-
})
39-
),
40-
Plot.text(
41-
counties,
42-
Plot.centroid({
43-
filter: (d) => d.properties.name.match(/^V/),
44-
text: (d) => d.properties.name,
45-
fill: "currentColor",
46-
stroke: "var(--vp-c-bg)",
47-
frameAnchor: "left",
48-
dx: 6
49-
})
50-
)
29+
Plot.geo(statemesh),
30+
Plot.text(states, Plot.centroid({text: (d) => d.properties.name, fill: "currentColor", stroke: "var(--vp-c-bg)"}))
5131
]
5232
})
5333
```

0 commit comments

Comments
 (0)