forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunemployment-choropleth.ts
46 lines (44 loc) · 1.24 KB
/
unemployment-choropleth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { tsv } from 'd3-fetch';
import { feature } from 'topojson';
import { autoType } from 'd3-dsv';
import { G2Spec, ELEMENT_CLASS_NAME } from '../../../src';
import { step } from './utils';
export async function unemploymentChoropleth(): Promise<G2Spec> {
const us = await fetch('data/us-10m.json').then((res) => res.json());
const unemployment = await tsv('data/unemployment.tsv', autoType);
const counties = feature(us, us.objects.counties).features;
return {
type: 'geoPath',
coordinate: { type: 'albersUsa' },
data: {
value: counties,
transform: [
{
type: 'join',
join: unemployment,
on: ['id', 'id'],
select: ['rate'],
},
],
},
scale: {
color: {
unknown: '#fff',
},
},
state: {
active: { fill: 'red' },
},
encode: {
color: 'rate',
},
legend: { color: { layout: { justifyContent: 'center' } } },
interaction: { elementHighlight: true },
};
}
unemploymentChoropleth.steps = ({ canvas }) => {
const { document } = canvas;
const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME);
const e = elements.find((d) => d.__data__.title === 6071);
return [step(e, 'pointerover')];
};