-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.html
More file actions
153 lines (135 loc) · 5.65 KB
/
matrix.html
File metadata and controls
153 lines (135 loc) · 5.65 KB
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
<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.js"></script>
<div id="vis"></div>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script>
// set the dimensions and margins of the graph
var len = window.innerWidth - 52;
var margin = { top: 80, right: 50, bottom: 50, left: 80 },
width = len - margin.left - margin.right,
height = len - margin.top - margin.bottom;
// append the svg object to the body of the page
var svg = d3.select("#vis")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
//Read the data
//d3.csv("./files/testmatrix.csv", function (data) { // this one doesnt work because chrome blocks loading csvs from disk
d3.csv("https://raw.githubusercontent.com/FISH-HAT/Matrix-Display/main/files/testmatrix.csv", function (data) { // this one requires the github link to work
// Build color scale
var arr = data.map(d => d.value)
var maxval = Math.max(...arr)
var minval = Math.min(...arr)
var myColor = d3.scaleSequential()
.interpolator(d3.interpolate("green", "red"))
.domain([minval, maxval])
// I'm sorry to whoever has to read this, this is just easier for me than figuring out how PHP works
var qs = location.search.substring(1)
var q = qs.split("&")
var qa = q[0].split("=")
var showAbove = qa[1]
var qb = q[1].split("=")
var showBelow = qb[1]
if (showAbove == "") { showAbove = 0 }
if (showBelow == "") { showBelow = 100000000 }
console.log("a: " + showAbove + "\nb: " + showBelow)
if (Number(showAbove) > Number(showBelow)) {
tempdata = data.filter(function(row) {
return (row['value'] > Number(showAbove) || row['value'] < Number(showBelow)) && row['group'] != row['variable']
})
} else if (Number(showAbove) < Number(showBelow)) {
tempdata = data.filter(function(row) {
return (row['value'] > Number(showAbove) && row['value'] < Number(showBelow)) && row['group'] != row['variable']
})
} else {
tempdata = data
}
var myGroups = d3.map(tempdata, function (d) { return d.group; }).keys()
var myVars = d3.map(tempdata, function (d) { return d.variable; }).keys()
data = data.filter(function(row) {
return myGroups.includes(row['group']) && myVars.includes(row['variable'])
})
// Labels of row and columns -> unique identifier of the column called 'group' and 'variable'
myGroups = myGroups.sort()
myVars = myVars.sort()
// Build X scales and axis:
var x = d3.scaleBand()
.range([0, width])
.domain(myGroups)
.padding(.05);
svg.append("g")
.style("font-size", 15)
.attr("transform", "translate(8,-5)")
.call(d3.axisBottom(x).tickSize(0))
.selectAll("text")
.style("text-anchor", "end")
.attr("transform", "rotate(90)")
svg.select(".domain").remove()
// Build Y scales and axis:
var y = d3.scaleBand()
.range([0, height])
.domain(myVars)
.padding(0.05);
svg.append("g")
.style("font-size", 15)
.call(d3.axisLeft(y).tickSize(0))
.select(".domain").remove()
// create a tooltip
var tooltip = d3.select("#vis")
.append("div")
.style("opacity", 0)
.attr("class", "tooltip")
.style("background-color", "white")
.style("border", "solid")
.style("border-width", "2px")
.style("border-radius", "5px")
.style("padding", "5px")
// Three function that change the tooltip when user hover / move / leave a cell
var mouseover = function (d) {
tooltip
.style("opacity", 1)
d3.select(this)
.style("stroke", "black")
.style("opacity", 1)
}
var mousemove = function (d) {
tooltip
.html("Correlation between " + d.group + " and " + d.variable + ": " + d.value)
.style("left", (d3.mouse(this)[0] + 70) + "px")
.style("top", (d3.mouse(this)[1]) + "px")
}
var mouseleave = function (d) {
tooltip
.style("opacity", 0)
d3.select(this)
.style("stroke", "none")
.style("opacity", 0.8)
}
var mouseclick = function (d) {
var l = "./fileview.html?" + d.group + "-" + d.variable
window.location.href = l
}
// add the squares
svg.selectAll()
.data(data, function (d) { return d.group + ':' + d.variable; })
.enter()
.append("rect")
.attr("x", function (d) { return x(d.group) })
.attr("y", function (d) { return y(d.variable) })
.attr("rx", 4)
.attr("ry", 4)
.attr("width", x.bandwidth())
.attr("height", y.bandwidth())
.style("fill", function (d) { return myColor(d.value) })
.style("stroke-width", 4)
.style("stroke", "none")
.style("opacity", 0.8)
.on("mouseover", mouseover)
.on("mousemove", mousemove)
.on("mouseleave", mouseleave)
.on("click", mouseclick)
})
</script>