forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairports-point-choropleth.ts
73 lines (72 loc) · 1.82 KB
/
airports-point-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { csv } from 'd3-fetch';
import { feature } from 'topojson';
import { autoType } from 'd3-dsv';
import { G2Spec } from '../../../src';
export async function airportsPointChoropleth(): Promise<G2Spec> {
const us = await fetch('data/us-10m.json').then((res) => res.json());
const airports = await csv('data/airports.csv', autoType);
const flights = await csv('data/flights-airport.csv', autoType);
const states = feature(us, us.objects.states).features;
return {
type: 'geoView',
coordinate: {
type: 'albersUsa',
},
children: [
{
type: 'geoPath',
data: states,
style: {
fill: 'lightgray',
stroke: 'white',
},
},
{
type: 'point',
data: airports,
encode: {
y: 'latitude',
x: 'longitude',
shape: 'point',
size: 1,
},
style: {
fill: 'gray',
},
},
{
type: 'link',
data: {
value: flights,
transform: [
{
type: 'filter',
callback: (d) => d.origin === 'SEA',
},
{
type: 'join',
join: airports,
on: ['origin', 'iata'],
select: ['latitude', 'longitude'],
as: ['origin_latitude', 'origin_longitude'],
},
{
type: 'join',
join: airports,
on: ['destination', 'iata'],
select: ['latitude', 'longitude'],
as: ['dest_latitude', 'dest_longitude'],
},
],
},
encode: {
x: ['origin_longitude', 'dest_longitude'],
y: ['origin_latitude', 'dest_latitude'],
},
style: {
stroke: 'black',
},
},
],
};
}