-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 944 Bytes
/
index.js
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
import { readDataSync } from 'indian-ocean';
import notify from '@mhkeller/notify';
import * as aq from 'arquero';
import * as vl from 'vega-lite-api';
import { plotVega } from '@mhkeller/plot';
/**
* Read in the data file and view it
*/
notify({ m: 'Reading data...', d: 'header' });
const data = readDataSync('./data/athletes.json');
console.log(data);
debugger;
/**
* Calc average number of golds per country
*/
const goldsPerCountry = aq.from(data)
.groupby('nationality')
.rollup({ total_golds: aq.op.sum('gold') })
.orderby(aq.desc('total_golds'))
.print();
debugger
/**
* Plot top the 10 countries
*/
const topCountries = goldsPerCountry.objects()
.slice(0, 10);
const chart = vl
.markBar()
.description('Top ten gold medalist countries.')
.data(topCountries)
.encode(
vl.x().fieldO('nationality'),
vl.y().fieldQ('total_golds')
);
await plotVega(chart, {
outPath: './output/top-10-countries.png',
});
debugger