forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarley-line-trail.ts
45 lines (44 loc) · 1.16 KB
/
barley-line-trail.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
import { csv } from 'd3-fetch';
import { autoType } from 'd3-dsv';
import { rollup } from 'd3-array';
import { G2Spec } from '../../../src';
export async function barleyLineTrail(): Promise<G2Spec> {
const data = await csv('data/barley.csv', autoType);
const key = (d) => `${d.site},${d.variety}`;
const keyDelta = rollup(
data,
([a, b]) => {
if (b.year < a.year) [a, b] = [b, a];
return b.yield - a.yield;
},
key,
);
return {
type: 'facetRect',
data,
paddingLeft: 130,
paddingBottom: 40,
encode: { x: 'site' },
children: [
{
type: 'line',
frame: false,
encode: {
x: (d) => `${d.year}`,
y: 'variety',
series: 'variety',
color: (d) => keyDelta.get(key(d)),
size: 'yield',
},
tooltip: { title: '', items: [{ field: 'year' }, { field: 'yield' }] },
legend: { size: false, color: { title: 'yield delta' } },
scale: {
size: { range: [0, 12] },
color: { palette: 'rdBu' },
},
style: { shape: 'trail' },
interaction: { tooltip: { series: false } },
},
],
};
}