Skip to content

Commit c9f3db0

Browse files
committed
inline options
1 parent 6495c34 commit c9f3db0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/plots/music-revenue.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Plot from "@observablehq/plot";
22
import * as d3 from "d3";
33

44
export async function musicRevenue() {
5-
const data = await d3.csv<any>("data/riaa-us-revenue.csv", d3.autoType);
5+
const riaa = await d3.csv<any>("data/riaa-us-revenue.csv", d3.autoType);
66
const stack: Plot.AreaYOptions = {
77
x: "year",
88
y: "revenue",
@@ -16,21 +16,15 @@ export async function musicRevenue() {
1616
transform: (d) => d / 1000
1717
},
1818
marks: [
19-
Plot.areaY(data, Plot.stackY({...stack, fill: "group", title: (d) => `${d.format}\n${d.group}`})),
20-
Plot.lineY(data, Plot.stackY2({...stack, stroke: "white", strokeWidth: 1})),
19+
Plot.areaY(riaa, Plot.stackY({...stack, fill: "group", title: (d) => `${d.format}\n${d.group}`})),
20+
Plot.lineY(riaa, Plot.stackY2({...stack, stroke: "white", strokeWidth: 1})),
2121
Plot.ruleY([0])
2222
]
2323
});
2424
}
2525

2626
export async function musicRevenueCustomOrder() {
27-
const data = await d3.csv<any>("data/riaa-us-revenue.csv", d3.autoType);
28-
const stack: Plot.AreaYOptions = {
29-
x: "year",
30-
y: "revenue",
31-
z: "format",
32-
order: (a, b) => d3.ascending(a.group, b.group) || d3.descending(a.revenue, b.revenue)
33-
};
27+
const riaa = await d3.csv<any>("data/riaa-us-revenue.csv", d3.autoType);
3428
return Plot.plot({
3529
y: {
3630
grid: true,
@@ -39,8 +33,16 @@ export async function musicRevenueCustomOrder() {
3933
},
4034
marks: [
4135
Plot.areaY(
42-
data,
43-
Plot.stackY({...stack, fill: "group", stroke: "white", title: (d) => `${d.format}\n${d.group}`})
36+
riaa,
37+
Plot.stackY({
38+
x: "year",
39+
y: "revenue",
40+
z: "format",
41+
order: (a, b) => d3.ascending(a.group, b.group) || d3.descending(a.revenue, b.revenue),
42+
fill: "group",
43+
stroke: "white",
44+
title: (d) => `${d.format}\n${d.group}`
45+
})
4446
),
4547
Plot.ruleY([0])
4648
]

0 commit comments

Comments
 (0)