forked from ft-interactive/visual-vocabulary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
196 lines (170 loc) · 5.89 KB
/
index.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<html>
<head>
<title>Visual Vocabulary</title>
<link rel="stylesheet" type="text/css" href="./mani.css">
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="v2-data.js"></script>
</head>
<body>
<style>
text{font-family:metric}
</style>
<script>
d3.csv("chartTypes.csv",function(error, chartData){
let plotCategories=catData.categories
let container = d3.select("body")
.append("div")
.attr("class", 'container');
window.onresize=redraw;
container.append("h1")
.text("Visual Vocabulary")
container.append("h2")
.text("Designing with data")
container.append("p")
.text("There are so many ways to visualise data – how do we know which one to pick? Click on the coloured categories below to decide which data relationship is most important in your story, then look at the different types of chart within the category to form some initial ideas about what might work best. This list is not meant to be exhaustive, nor a wizard, but is a useful starting point for making informative and meaningful data visualisations")
.attr('class', 'intro-text')
container.append("p")
.text("Inspired by the Graphic Continuum by Jon Schwabish and Severino Ribecca")
let plotWidth=container.node().getBoundingClientRect().width;
let cellWidth=(plotWidth)/plotCategories.length
let menus=container.append("svg")
.attr("width",plotWidth)
.attr("height",100)
let category=menus.selectAll(".categ")
.data(plotCategories)
.enter()
.append("g")
.attr("class","categ")
.attr("id",function(d,i){return i})
.on("mouseover",pointer)
.on("mousedown",addLink)
category.append("text")
.attr("class","buttonText")
.attr("x",function(d,i){return (cellWidth*i)+(cellWidth/2)})
.attr("y",20)
.attr("height",20)
.attr("width",50)
.attr("fill",function(d) {return d.colour})
.text(function(d){return d.category})
category.append("rect")
.attr("class","button")
.attr("x",function(d,i){return cellWidth*i})
.attr("y",30)
.attr("height",10)
.attr("width",cellWidth)
.attr("fill",function(d){return d.colour})
function addCharts(lookUp){
let chartWidth=((plotWidth-60)/6)-10
let chartHolder=d3.select("#charts")
.append("div")
let chart=chartHolder.selectAll(".chart")
.data(function(d){
let filtered=chartData.filter(function(d){
return d.category==lookUp
})
return filtered
})
.enter()
let div=chart.append("div")
.attr("class","chart")
.style("max-width",chartWidth)
div.append("div")
.attr("class","chart")
.style("height",55)
.html(function(d){return d.chartName})
div.append("img")
.attr("class","chart")
.style("background-color","#ffffff")
.style("opacity",function (d){
if(d.avail=="TRUE"){
return 0.85
}
else{return 0.2}
})
.attr("src",function(d){return "icons/"+d.img})
.attr("width", chartWidth-20)
.attr("height", chartWidth-20)
div.append("div")
.attr("class","chartDesc")
.html(function(d){return d.description})
}
function addInfo(el){
let loookUp=el.category
let infoPanel=container.append("div")
.attr("class","panel")
.attr("id","infoPanel")
.style("background-color",el.colour)
infoPanel.append("div")
.attr("class","infoHeading")
.html(loookUp)
infoPanel.append("div")
.attr("class","infoText")
.html(el.description)
infoPanel.append("div")
.attr("class","infoSubhead")
.html("Examples of use")
infoPanel.append("div")
.attr("class","infoText")
.html(el.example)
infoPanel.append("div")
.attr("class","infoSubhead")
.html("Chart types")
infoPanel.append("div")
.attr("id","charts")
.attr("class","charts")
addCharts(loookUp)
}
function addLink(d) {
//console.log("d",d)
d3.selectAll(".link")
.remove()
d3.selectAll(".panel")
.remove()
let x1=cellWidth*this.id+(cellWidth/2)
let lineData = [
{"x":x1,"y":40},
{"x":x1,"y":40},
{"x":x1,"y":40},
{"x":x1,"y":40}];
let lineData2 = [
{"x":x1,"y":40},
{"x":x1,"y":60},
{"x":10,"y":60},
{"x":10,"y":100}];
d3.selectAll(".link")
.data(d)
.enter()
menus.append("path")
.attr("class","link")
.attr("stroke",d.colour)
.attr("d", lineFunction(lineData))
.transition()
.duration(300)
.attr("d", lineFunction(lineData2))
.each("end", next)
function next(){
addInfo(d)
}
}
let lineFunction = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("linear");
function redraw() {
plotWidth=container.node().getBoundingClientRect().width;
cellWidth=plotWidth/plotCategories.length
menus.attr("width",plotWidth)
d3.selectAll(".button")
.attr("x",function(d,i){return cellWidth*i})
.attr("width",cellWidth)
d3.selectAll(".buttonText")
.attr("x",function(d,i){return (cellWidth*i)+(cellWidth/2)})
.attr("width",cellWidth)
}
function pointer() {
this.style.cursor='pointer'
}
})//end data load
</script>
</body>
</html>