-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
51 lines (44 loc) · 1.01 KB
/
main.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
45
46
47
48
49
50
51
import { html, ReactiveElement } from 'cami';
import { json } from 'd3-fetch';
import * as Plot from '@observablehq/plot';
class BarChart extends ReactiveElement {
title = '';
subtitle = '';
caption = '';
src = '';
plotData = [];
fetchData() {
this.plotData = this.query({
queryKey: [ 'plotData' ],
queryFn: () => json(this.src),
staleTime: Infinity
});
}
onConnect() {
this.observableAttributes({
title: (title) => title,
subtitle: (subtitle) => subtitle,
caption: (caption) => caption,
src: (src) => src
});
this.fetchData();
}
template() {
var plt;
if (this.plotData.data) {
plt = Plot.plot({
title: this.title,
subtitle: this.subtitle,
caption: this.caption,
marks: [
Plot.barY(this.plotData.data, { x: "Name", y: "Count", sort: { x: "y"} }),
Plot.ruleY([0])
]
})
}
return html`
${plt}
`;
}
}
customElements.define('bar-chart', BarChart);