-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot.test.js
44 lines (40 loc) · 883 Bytes
/
plot.test.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
/* eslint-disable no-undef */
import { readDataSync } from 'indian-ocean';
import * as aq from 'arquero';
import plot from '../src/plot.js';
const events = readDataSync('./test/data/purchase_data.csv');
const dataset = aq
.from(events)
.derive({ date: aq.escape(d => new Date(d.date.split('T')[0])) })
.groupby('date', 'brand')
.rollup({ value: d => aq.op.sum(d.price_in_usd) })
.orderby('date', 'brand')
.objects();
const chart = data => {
return Plot.plot({
marks: [
Plot.line(data, {
x: 'date',
y: 'value',
stroke: 'brand',
strokeWidth: 2,
curve: 'linear'
})
],
width: 554,
height: 130,
x: { ticks: 3 },
marginLeft: 50,
color: {
legend: true,
width: 554,
columns: '120px'
}
});
};
await plot(chart, [dataset], {
library: 'observablehq/plot',
outPath: 'test/tmp/line-plot.png',
view: true,
title: 'Line chart'
});