@@ -23,133 +23,6 @@ A powerful, lightweight visualization for COM-480 built with Hugo, Tailwind CSS.
2323### Scale countries by amount of books published by author's from these countries
2424
2525
26- ## Bar chart
27-
28- <!-- prettier-ignore-start -->
29- {{< d3 >}}
30- const margin = {top: 20, right: 20, bottom: 40, left: 40};
31- const width = container.clientWidth - margin.left - margin.right;
32- const height = 300 - margin.top - margin.bottom;
33-
34- const labels = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July'] ;
35- const data = [ 65, 59, 80, 81, 56, 55, 40] ;
36-
37- const svg = d3.select(container).append("svg")
38- .attr("width", width + margin.left + margin.right)
39- .attr("height", height + margin.top + margin.bottom)
40- .append("g")
41- .attr("transform", ` translate(${margin.left},${margin.top}) ` );
42-
43- const x = d3.scaleBand().domain(labels).range([ 0, width] ).padding(0.2);
44- const y = d3.scaleLinear().domain([ 0, d3.max(data)] ).nice().range([ height, 0] );
45-
46- svg.append("g").attr("transform", ` translate(0,${height}) ` ).call(d3.axisBottom(x));
47- svg.append("g").call(d3.axisLeft(y));
48-
49- svg.selectAll(".bar")
50- .data(data)
51- .enter().append("rect")
52- .attr("x", (d, i) => x(labels[ i] ))
53- .attr("y", d => y(d))
54- .attr("width", x.bandwidth())
55- .attr("height", d => height - y(d))
56- .attr("fill", congoColors.primary300)
57- .attr("stroke", congoColors.primary500)
58- .attr("stroke-width", 1);
59- {{< /d3 >}}
60- <!-- prettier-ignore-end -->
61-
62- ## Line chart
63-
64- <!-- prettier-ignore-start -->
65- {{< d3 >}}
66- const margin = {top: 20, right: 20, bottom: 40, left: 40};
67- const width = container.clientWidth - margin.left - margin.right;
68- const height = 300 - margin.top - margin.bottom;
69-
70- const labels = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July'] ;
71- const data = [ 65, 59, 80, 81, 56, 55, 40] ;
72-
73- const svg = d3.select(container).append("svg")
74- .attr("width", width + margin.left + margin.right)
75- .attr("height", height + margin.top + margin.bottom)
76- .append("g")
77- .attr("transform", ` translate(${margin.left},${margin.top}) ` );
78-
79- const x = d3.scalePoint().domain(labels).range([ 0, width] );
80- const y = d3.scaleLinear().domain([ 0, d3.max(data)] ).nice().range([ height, 0] );
81-
82- svg.append("g").attr("transform", ` translate(0,${height}) ` ).call(d3.axisBottom(x));
83- svg.append("g").call(d3.axisLeft(y));
84-
85- const line = d3.line()
86- .x((d, i) => x(labels[ i] ))
87- .y(d => y(d))
88- .curve(d3.curveCatmullRom.alpha(0.2));
89-
90- svg.append("path")
91- .datum(data)
92- .attr("fill", "none")
93- .attr("stroke", congoColors.primary400)
94- .attr("stroke-width", 2)
95- .attr("d", line);
96-
97- svg.selectAll(".dot")
98- .data(data)
99- .enter().append("circle")
100- .attr("cx", (d, i) => x(labels[ i] ))
101- .attr("cy", d => y(d))
102- .attr("r", 4)
103- .attr("fill", congoColors.primary300)
104- .attr("stroke", congoColors.primary400);
105- {{< /d3 >}}
106- <!-- prettier-ignore-end -->
107-
108- ## Doughnut chart
109-
110- <!-- prettier-ignore-start -->
111- {{< d3 >}}
112- const width = container.clientWidth;
113- const height = 300;
114- const radius = Math.min(width, height) / 2 - 20;
115-
116- const labels = [ 'Red', 'Blue', 'Yellow'] ;
117- const data = [ 300, 50, 100] ;
118-
119- const svg = d3.select(container).append("svg")
120- .attr("width", width)
121- .attr("height", height)
122- .append("g")
123- .attr("transform", ` translate(${width / 2},${height / 2}) ` );
124-
125- const pie = d3.pie().value(d => d);
126- const arc = d3.arc().innerRadius(radius * 0.6).outerRadius(radius);
127- const arcHover = d3.arc().innerRadius(radius * 0.6).outerRadius(radius + 4);
128-
129- const color = d3.scaleOrdinal()
130- .domain(labels)
131- .range([ congoColors.primary200, congoColors.primary300, congoColors.primary400] );
132-
133-
134- svg.selectAll(".slice")
135- .data(pie(data))
136- .enter().append("path")
137- .attr("d", arc)
138- .attr("fill", (d, i) => color(labels[ i] ))
139- .attr("stroke", "none")
140- .on("mouseover", function() { d3.select(this).attr("d", arcHover); })
141- .on("mouseout", function() { d3.select(this).attr("d", arc); });
142-
143- const legend = svg.selectAll(".legend")
144- .data(labels)
145- .enter().append("g")
146- .attr("transform", (d, i) => ` translate(${radius + 10}, ${-radius + i * 22}) ` );
147-
148- legend.append("rect").attr("width", 14).attr("height", 14).attr("fill", (d, i) => color(labels[ i] ));
149- legend.append("text").attr("x", 18).attr("y", 11).style("font-size", "13px").text(d => d);
150- {{< /d3 >}}
151- <!-- prettier-ignore-end -->
152-
15326## Cartogram
15427
15528<!-- prettier-ignore-start -->
0 commit comments