Skip to content

Instantly share code, notes, and snippets.

@robcrock
Last active January 1, 2020 11:05
Show Gist options
  • Save robcrock/0fc302f92c3fc0fad35bdbb13574fc35 to your computer and use it in GitHub Desktop.
Save robcrock/0fc302f92c3fc0fad35bdbb13574fc35 to your computer and use it in GitHub Desktop.
Love Interests

MakeoverMonday W2 2018

This weeks viz was largely inspired by Elijah Meek's book D3 in Action. Chapter 7 of that book shares some ways we can create less conventional charts types. I used code from that chapter to begin building an adjacency matrix in an attempt to show the relationship between the characteristic women voted on and their rank.

The data set this week was provide by Matthew Smith from YouGov

source target percentage
Looks 1 0.1
Looks 2 0.07
Looks 3 0.06
Looks 4 0.13
Looks 5 0.34
Looks 6 0.29
Personality 1 0.38
Personality 2 0.26
Personality 3 0.2
Personality 4 0.09
Personality 5 0.04
Personality 6 0.03
Humor 1 0.13
Humor 2 0.27
Humor 3 0.24
Humor 4 0.18
Humor 5 0.11
Humor 6 0.07
Intelligence 1 0.15
Intelligence 2 0.19
Intelligence 3 0.25
Intelligence 4 0.28
Intelligence 5 0.08
Intelligence 6 0.04
Money 1 0.03
Money 2 0.04
Money 3 0.06
Money 4 0.1
Money 5 0.27
Money 6 0.49
Interests 1 0.2
Interests 2 0.17
Interests 3 0.18
Interests 4 0.22
Interests 5 0.15
Interests 6 0.08
source target percentage
Looks 1 0.11
Looks 2 0.1
Looks 3 0.13
Looks 4 0.17
Looks 5 0.3
Looks 6 0.19
Personality 1 0.45
Personality 2 0.2
Personality 3 0.14
Personality 4 0.08
Personality 5 0.09
Personality 6 0.05
Humor 1 0.06
Humor 2 0.16
Humor 3 0.19
Humor 4 0.24
Humor 5 0.19
Humor 6 0.16
Intelligence 1 0.15
Intelligence 2 0.25
Intelligence 3 0.22
Intelligence 4 0.17
Intelligence 5 0.11
Intelligence 6 0.1
Money 1 0.04
Money 2 0.09
Money 3 0.14
Money 4 0.14
Money 5 0.22
Money 6 0.37
Interests 1 0.19
Interests 2 0.21
Interests 3 0.17
Interests 4 0.2
Interests 5 0.09
Interests 6 0.14
source target percentage
Looks 1 0.1
Looks 2 0.07
Looks 3 0.16
Looks 4 0.12
Looks 5 0.37
Looks 6 0.19
Personality 1 0.49
Personality 2 0.24
Personality 3 0.14
Personality 4 0.08
Personality 5 0.04
Personality 6 0.02
Humor 1 0.15
Humor 2 0.32
Humor 3 0.24
Humor 4 0.16
Humor 5 0.08
Humor 6 0.05
Intelligence 1 0.1
Intelligence 2 0.19
Intelligence 3 0.2
Intelligence 4 0.27
Intelligence 5 0.19
Intelligence 6 0.05
Money 1 0.01
Money 2 0.03
Money 3 0.07
Money 4 0.11
Money 5 0.2
Money 6 0.59
Interests 1 0.15
Interests 2 0.15
Interests 3 0.2
Interests 4 0.25
Interests 5 0.14
Interests 6 0.11
source target percentage
Looks 1 0.05
Looks 2 0.06
Looks 3 0.09
Looks 4 0.17
Looks 5 0.41
Looks 6 0.21
Personality 1 0.52
Personality 2 0.25
Personality 3 0.16
Personality 4 0.05
Personality 5 0.02
Personality 6 0.01
Humor 1 0.21
Humor 2 0.33
Humor 3 0.24
Humor 4 0.14
Humor 5 0.07
Humor 6 0.01
Intelligence 1 0.08
Intelligence 2 0.14
Intelligence 3 0.2
Intelligence 4 0.39
Intelligence 5 0.16
Intelligence 6 0.04
Money 1 0.01
Money 2 0.02
Money 3 0.03
Money 4 0.05
Money 5 0.22
Money 6 0.67
Interests 1 0.13
Interests 2 0.21
Interests 3 0.28
Interests 4 0.2
Interests 5 0.13
Interests 6 0.06
source target percentage
Looks 1 0.05
Looks 2 0.06
Looks 3 0.11
Looks 4 0.19
Looks 5 0.44
Looks 6 0.16
Personality 1 0.69
Personality 2 0.17
Personality 3 0.1
Personality 4 0.02
Personality 5 0.01
Personality 6 0.01
Humor 1 0.14
Humor 2 0.45
Humor 3 0.25
Humor 4 0.11
Humor 5 0.03
Humor 6 0.01
Intelligence 1 0.07
Intelligence 2 0.19
Intelligence 3 0.31
Intelligence 4 0.29
Intelligence 5 0.12
Intelligence 6 0.02
Money 1 0
Money 2 0.02
Money 3 0.02
Money 4 0.04
Money 5 0.2
Money 6 0.72
Interests 1 0.05
Interests 2 0.12
Interests 3 0.21
Interests 4 0.34
Interests 5 0.2
Interests 6 0.08
source target percentage
Looks 1 0.12
Looks 2 0.09
Looks 3 0.13
Looks 4 0.2
Looks 5 0.27
Looks 6 0.2
Personality 1 0.53
Personality 2 0.21
Personality 3 0.11
Personality 4 0.07
Personality 5 0.06
Personality 6 0.02
Humor 1 0.06
Humor 2 0.17
Humor 3 0.17
Humor 4 0.27
Humor 5 0.21
Humor 6 0.11
Intelligence 1 0.13
Intelligence 2 0.29
Intelligence 3 0.27
Intelligence 4 0.16
Intelligence 5 0.1
Intelligence 6 0.05
Money 1 0.01
Money 2 0.05
Money 3 0.1
Money 4 0.14
Money 5 0.22
Money 6 0.48
Interests 1 0.14
Interests 2 0.19
Interests 3 0.23
Interests 4 0.16
Interests 5 0.15
Interests 6 0.13
source target percentage
Looks 1 0.08
Looks 2 0.09
Looks 3 0.11
Looks 4 0.13
Looks 5 0.26
Looks 6 0.33
Personality 1 0.41
Personality 2 0.19
Personality 3 0.19
Personality 4 0.1
Personality 5 0.07
Personality 6 0.03
Humor 1 0.16
Humor 2 0.26
Humor 3 0.21
Humor 4 0.16
Humor 5 0.12
Humor 6 0.09
Intelligence 1 0.17
Intelligence 2 0.17
Intelligence 3 0.21
Intelligence 4 0.24
Intelligence 5 0.15
Intelligence 6 0.07
Money 1 0.04
Money 2 0.09
Money 3 0.12
Money 4 0.15
Money 5 0.24
Money 6 0.36
Interests 1 0.13
Interests 2 0.19
Interests 3 0.17
Interests 4 0.21
Interests 5 0.16
Interests 6 0.13
source target percentage
Looks 1 0.05
Looks 2 0.05
Looks 3 0.09
Looks 4 0.16
Looks 5 0.4
Looks 6 0.26
Personality 1 0.59
Personality 2 0.24
Personality 3 0.12
Personality 4 0.03
Personality 5 0.01
Personality 6 0.01
Humor 1 0.14
Humor 2 0.32
Humor 3 0.28
Humor 4 0.18
Humor 5 0.06
Humor 6 0.03
Intelligence 1 0.07
Intelligence 2 0.14
Intelligence 3 0.24
Intelligence 4 0.34
Intelligence 5 0.17
Intelligence 6 0.03
Money 1 0.01
Money 2 0.02
Money 3 0.03
Money 4 0.08
Money 5 0.24
Money 6 0.62
Interests 1 0.15
Interests 2 0.23
Interests 3 0.24
Interests 4 0.21
Interests 5 0.11
Interests 6 0.05
source target percentage
Looks 1 0.11
Looks 2 0.09
Looks 3 0.11
Looks 4 0.17
Looks 5 0.35
Looks 6 0.17
Personality 1 0.42
Personality 2 0.26
Personality 3 0.17
Personality 4 0.1
Personality 5 0.04
Personality 6 0.02
Humor 1 0.17
Humor 2 0.22
Humor 3 0.3
Humor 4 0.17
Humor 5 0.1
Humor 6 0.04
Intelligence 1 0.09
Intelligence 2 0.18
Intelligence 3 0.2
Intelligence 4 0.32
Intelligence 5 0.18
Intelligence 6 0.03
Money 1 0.01
Money 2 0.01
Money 3 0.04
Money 4 0.05
Money 5 0.19
Money 6 0.7
Interests 1 0.19
Interests 2 0.24
Interests 3 0.19
Interests 4 0.19
Interests 5 0.14
Interests 6 0.05
source target percentage
Looks 1 0.07
Looks 2 0.07
Looks 3 0.09
Looks 4 0.17
Looks 5 0.35
Looks 6 0.24
Personality 1 0.56
Personality 2 0.21
Personality 3 0.11
Personality 4 0.07
Personality 5 0.04
Personality 6 0.02
Humor 1 0.17
Humor 2 0.32
Humor 3 0.26
Humor 4 0.13
Humor 5 0.08
Humor 6 0.05
Intelligence 1 0.07
Intelligence 2 0.19
Intelligence 3 0.23
Intelligence 4 0.31
Intelligence 5 0.14
Intelligence 6 0.05
Money 1 0.01
Money 2 0.03
Money 3 0.07
Money 4 0.1
Money 5 0.25
Money 6 0.55
Interests 1 0.13
Interests 2 0.19
Interests 3 0.24
Interests 4 0.22
Interests 5 0.14
Interests 6 0.09
source target percentage
Looks 1 0.19
Looks 2 0.11
Looks 3 0.17
Looks 4 0.17
Looks 5 0.21
Looks 6 0.17
Personality 1 0.53
Personality 2 0.23
Personality 3 0.1
Personality 4 0.06
Personality 5 0.04
Personality 6 0.04
Humor 1 0.09
Humor 2 0.22
Humor 3 0.25
Humor 4 0.19
Humor 5 0.16
Humor 6 0.09
Intelligence 1 0.08
Intelligence 2 0.14
Intelligence 3 0.19
Intelligence 4 0.27
Intelligence 5 0.19
Intelligence 6 0.12
Money 1 0.03
Money 2 0.05
Money 3 0.09
Money 4 0.15
Money 5 0.26
Money 6 0.42
Interests 1 0.09
Interests 2 0.25
Interests 3 0.2
Interests 4 0.16
Interests 5 0.14
Interests 6 0.16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<script src="https://d3js.org/d3.v4.min.js"></script>
<meta name="viewport" content="width=625px, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Adjacency Matric</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col s8">
<h2>Love Interests</h1>
<div>Women around the world were asked to rank the characteristics listed along the right from 1 to 6.</div>
</div>
<div class="col s4">
<svg class="key" height="140px" width="180px"></svg>
</div>
</div>
<div class="row">
<div class="col s3">
<div>German</div>
<svg class="german" height="90px" width="90px"></svg>
</div>
<div class="col s3">
<div>British</div>
<svg class="british" height="90px" width="90px"></svg>
</div>
<div class="col s3">
<div>Malaysian</div>
<svg class="malaysian" height="90px" width="90px">
</svg>
</div>
<div class="col s3">
<div>Hong Kong</div>
<svg class="hong_kong" height="90px" width="90px"></svg>
</div>
<div class="col s3">
<div>Filipino</div>
<svg class="filipino" height="90" width="90"></svg>
</div>
</div>
<div class="row">
<div class="col s3">
<div>American</div>
<svg class="american" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Indonesian</div>
<svg class="indonesian" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Singaporean</div>
<svg class="singaporean" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Thai</div>
<svg class="thai" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>French</div>
<svg class="french" height="90" width="90"></svg>
</div>
</div>
<div class="row">
<div class="col s3">
<div>Indian</div>
<svg class="indian" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Australian</div>
<svg class="australian" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Danish</div>
<svg class="danish" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Swedish</div>
<svg class="swedish" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Finnish</div>
<svg class="finnish" height="90" width="90"></svg>
</div>
</div>
<div class="row">
<div class="col s3">
<div>Vietnamese</div>
<svg class="vietnamese" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Egyptian</div>
<svg class="egyptian" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>UAE</div>
<svg class="uae" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Arabian</div>
<svg class="arabian" height="90" width="90"></svg>
</div>
<div class="col s3">
<div>Norwegian</div>
<svg class="norwegian" height="90" width="90"></svg>
</div>
</div>
<div class="row">
<div class="col s6">SOURCE | YouGov</div>
<div class='col s6 right-align'>DESIGN | @robcrock</div>
</div>
</div>
<script src="script.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
</body>
</html>
source target percentage
Looks 1 0.06
Looks 2 0.11
Looks 3 0.12
Looks 4 0.16
Looks 5 0.27
Looks 6 0.28
Personality 1 0.28
Personality 2 0.18
Personality 3 0.18
Personality 4 0.17
Personality 5 0.12
Personality 6 0.06
Humor 1 0.19
Humor 2 0.22
Humor 3 0.2
Humor 4 0.16
Humor 5 0.14
Humor 6 0.1
Intelligence 1 0.22
Intelligence 2 0.23
Intelligence 3 0.23
Intelligence 4 0.17
Intelligence 5 0.1
Intelligence 6 0.04
Money 1 0.04
Money 2 0.09
Money 3 0.09
Money 4 0.16
Money 5 0.23
Money 6 0.39
Interests 1 0.2
Interests 2 0.18
Interests 3 0.18
Interests 4 0.17
Interests 5 0.14
Interests 6 0.13
source target percentage
Looks 1 0.18
Looks 2 0.12
Looks 3 0.14
Looks 4 0.18
Looks 5 0.22
Looks 6 0.17
Personality 1 0.46
Personality 2 0.2
Personality 3 0.12
Personality 4 0.1
Personality 5 0.08
Personality 6 0.04
Humor 1 0.09
Humor 2 0.22
Humor 3 0.2
Humor 4 0.17
Humor 5 0.19
Humor 6 0.14
Intelligence 1 0.18
Intelligence 2 0.26
Intelligence 3 0.27
Intelligence 4 0.16
Intelligence 5 0.08
Intelligence 6 0.05
Money 1 0.05
Money 2 0.1
Money 3 0.14
Money 4 0.19
Money 5 0.23
Money 6 0.28
Interests 1 0.03
Interests 2 0.11
Interests 3 0.12
Interests 4 0.2
Interests 5 0.22
Interests 6 0.32
source target percentage
Money 5 0.25
Money 6 0.21
Interests 1 0.08
Interests 2 0.15
Interests 3 0.19
Interests 4 0.17
Interests 5 0.2
Interests 6 0.22
Looks 1 0.09
Looks 2 0.08
Looks 3 0.11
Looks 4 0.14
Looks 5 0.2
Looks 6 0.38
Personality 1 0.47
Personality 2 0.23
Personality 3 0.13
Personality 4 0.09
Personality 5 0.05
Personality 6 0.03
Humor 1 0.14
Humor 2 0.21
Humor 3 0.21
Humor 4 0.2
Humor 5 0.12
Humor 6 0.11
Intelligence 1 0.13
Intelligence 2 0.2
Intelligence 3 0.22
Intelligence 4 0.22
Intelligence 5 0.17
Intelligence 6 0.06
Money 1 0.09
Money 2 0.13
Money 3 0.14
Money 4 0.18
source target percentage
Looks 1 0.05
Looks 2 0.09
Looks 3 0.1
Looks 4 0.22
Looks 5 0.37
Looks 6 0.17
Personality 1 0.66
Personality 2 0.2
Personality 3 0.07
Personality 4 0.05
Personality 5 0.01
Personality 6 0.01
Humor 1 0.14
Humor 2 0.34
Humor 3 0.29
Humor 4 0.12
Humor 5 0.08
Humor 6 0.03
Intelligence 1 0.05
Intelligence 2 0.16
Intelligence 3 0.25
Intelligence 4 0.34
Intelligence 5 0.17
Intelligence 6 0.03
Money 1 0.01
Money 2 0.01
Money 3 0.04
Money 4 0.05
Money 5 0.2
Money 6 0.69
Interests 1 0.1
Interests 2 0.21
Interests 3 0.25
Interests 4 0.21
Interests 5 0.16
Interests 6 0.07
var PromiseWrapper = d => new Promise(resolve => d3.csv(d, p => resolve(p)));
Promise
.all([
PromiseWrapper("german.csv"),
PromiseWrapper("british.csv"),
PromiseWrapper("malaysian.csv"),
PromiseWrapper("hong_kong.csv"),
PromiseWrapper("filipino.csv"),
PromiseWrapper("american.csv"),
PromiseWrapper("indonesian.csv"),
PromiseWrapper("singaporean.csv"),
PromiseWrapper("thai.csv"),
PromiseWrapper("french.csv"),
PromiseWrapper("indian.csv"),
PromiseWrapper("australian.csv"),
PromiseWrapper("danish.csv"),
PromiseWrapper("swedish.csv"),
PromiseWrapper("finnish.csv"),
PromiseWrapper("vietnamese.csv"),
PromiseWrapper("egyptian.csv"),
PromiseWrapper("uae.csv"),
PromiseWrapper("arabian.csv"),
PromiseWrapper("norwegian.csv")
])
.then(resolve => {
createAdjacencyMatrix(
resolve[0],
resolve[1],
resolve[2],
resolve[3],
resolve[4],
resolve[5],
resolve[6],
resolve[7],
resolve[8],
resolve[9],
resolve[10],
resolve[11],
resolve[12],
resolve[13],
resolve[14],
resolve[15],
resolve[16],
resolve[17],
resolve[18],
resolve[19]
);
});
function createAdjacencyMatrix(
german,
british,
malaysian,
hong_kong,
american,
filipino,
indonesian,
singaporean,
thai,
french,
indian,
australian,
danish,
swedish,
finnish,
vietnamese,
egyptian,
uae,
arabian,
norwegian
) {
// KEY
var keyMatrix = [];
const characteristics = ["Personality", "Humor", "Intelligence", "Looks", "Interests", "Money"];
const rank = [1, 2, 3, 4, 5, 6];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
keyMatrix.push(grid);
});
});
d3.select(".key")
.append("g")
.attr('transform', 'translate(5, 40)')
.selectAll("rect").data(keyMatrix).enter()
.append("rect")
.attr("class", "key")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", .1);
d3.select(".key")
.append('g')
.attr('transform', 'translate(100, 52)')
.selectAll('text').data(characteristics).enter()
.append('text')
.attr('y', (d, i) => i * 15)
.text(d => d)
.style('text-anchor', 'start')
.style('font-family', 'Roboto')
.style('font-size', '10px');
d3.select(".key")
.append('g')
.attr('transform', 'translate(10,140)')
.selectAll('text').data(rank).enter()
.append('text')
.attr('x', (d, i) => i * 15)
.text(d => d)
.style('font-family', 'Roboto')
.style('font-size', '10px');
// GERMAN
var germanHash = {};
german.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
germanHash[id] = edge;
});
var germanMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (germanHash[grid.id]) {
grid.percentage = germanHash[grid.id].percentage;
}
germanMatrix.push(grid);
});
});
d3.select(".german")
.append("g")
.selectAll("rect").data(germanMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// BRITISH
var britishHash = {};
british.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
britishHash[id] = edge;
});
var britishMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (britishHash[grid.id]) {
grid.percentage = britishHash[grid.id].percentage;
}
britishMatrix.push(grid);
});
});
d3.select(".british")
.append("g")
.selectAll("rect").data(britishMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// MALAYSIAN
var malaysianHash = {};
malaysian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
malaysianHash[id] = edge;
});
var malaysianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (malaysianHash[grid.id]) {
grid.percentage = malaysianHash[grid.id].percentage;
}
malaysianMatrix.push(grid);
});
});
d3.select(".malaysian")
.append("g")
.selectAll("rect").data(malaysianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// HONG KONG
var hongKongHash = {};
hong_kong.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
hongKongHash[id] = edge;
});
var hongKongMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (hongKongHash[grid.id]) {
grid.percentage = hongKongHash[grid.id].percentage;
}
hongKongMatrix.push(grid);
});
});
d3.select(".hong_kong")
.append("g")
.selectAll("rect").data(hongKongMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// filipino
var filipinoHash = {};
filipino.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
filipinoHash[id] = edge;
});
var filipinoMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (filipinoHash[grid.id]) {
grid.percentage = filipinoHash[grid.id].percentage;
}
filipinoMatrix.push(grid);
});
});
d3.select(".filipino")
.append("g")
.selectAll("rect").data(filipinoMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// american
var americanHash = {};
american.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
americanHash[id] = edge;
});
var americanMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (americanHash[grid.id]) {
grid.percentage = americanHash[grid.id].percentage;
}
americanMatrix.push(grid);
});
});
d3.select(".american")
.append("g")
.selectAll("rect").data(americanMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// indonesian
var indonesianHash = {};
indonesian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
indonesianHash[id] = edge;
});
var indonesianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (indonesianHash[grid.id]) {
grid.percentage = indonesianHash[grid.id].percentage;
}
indonesianMatrix.push(grid);
});
});
d3.select(".indonesian")
.append("g")
.selectAll("rect").data(indonesianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// singaporean
var singaporeanHash = {};
singaporean.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
singaporeanHash[id] = edge;
});
var singaporeanMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (singaporeanHash[grid.id]) {
grid.percentage = singaporeanHash[grid.id].percentage;
}
singaporeanMatrix.push(grid);
});
});
d3.select(".singaporean")
.append("g")
.selectAll("rect").data(singaporeanMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// thai
var thaiHash = {};
thai.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
thaiHash[id] = edge;
});
var thaiMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (thaiHash[grid.id]) {
grid.percentage = thaiHash[grid.id].percentage;
}
thaiMatrix.push(grid);
});
});
d3.select(".thai")
.append("g")
.selectAll("rect").data(thaiMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// french
var frenchHash = {};
french.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
frenchHash[id] = edge;
});
var frenchMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (frenchHash[grid.id]) {
grid.percentage = frenchHash[grid.id].percentage;
}
frenchMatrix.push(grid);
});
});
d3.select(".french")
.append("g")
.selectAll("rect").data(frenchMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// indian
var indianHash = {};
indian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
indianHash[id] = edge;
});
var indianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (indianHash[grid.id]) {
grid.percentage = indianHash[grid.id].percentage;
}
indianMatrix.push(grid);
});
});
d3.select(".indian")
.append("g")
.selectAll("rect").data(indianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// australian
var australianHash = {};
australian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
australianHash[id] = edge;
});
var australianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (australianHash[grid.id]) {
grid.percentage = australianHash[grid.id].percentage;
}
australianMatrix.push(grid);
});
});
d3.select(".australian")
.append("g")
.selectAll("rect").data(australianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// danish
var danishHash = {};
danish.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
danishHash[id] = edge;
});
var danishMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (danishHash[grid.id]) {
grid.percentage = danishHash[grid.id].percentage;
}
danishMatrix.push(grid);
});
});
d3.select(".danish")
.append("g")
.selectAll("rect").data(danishMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// swedish
var swedishHash = {};
swedish.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
swedishHash[id] = edge;
});
var swedishMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (swedishHash[grid.id]) {
grid.percentage = swedishHash[grid.id].percentage;
}
swedishMatrix.push(grid);
});
});
d3.select(".swedish")
.append("g")
.selectAll("rect").data(swedishMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// finnish
var finnishHash = {};
finnish.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
finnishHash[id] = edge;
});
var finnishMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (finnishHash[grid.id]) {
grid.percentage = finnishHash[grid.id].percentage;
}
finnishMatrix.push(grid);
});
});
d3.select(".finnish")
.append("g")
.selectAll("rect").data(finnishMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// vietnamese
var vietnameseHash = {};
vietnamese.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
vietnameseHash[id] = edge;
});
var vietnameseMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (vietnameseHash[grid.id]) {
grid.percentage = vietnameseHash[grid.id].percentage;
}
vietnameseMatrix.push(grid);
});
});
d3.select(".vietnamese")
.append("g")
.selectAll("rect").data(vietnameseMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// egyptian
var egyptianHash = {};
egyptian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
egyptianHash[id] = edge;
});
var egyptianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (egyptianHash[grid.id]) {
grid.percentage = egyptianHash[grid.id].percentage;
}
egyptianMatrix.push(grid);
});
});
d3.select(".egyptian")
.append("g")
.selectAll("rect").data(egyptianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// uae
var uaeHash = {};
uae.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
uaeHash[id] = edge;
});
var uaeMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (uaeHash[grid.id]) {
grid.percentage = uaeHash[grid.id].percentage;
}
uaeMatrix.push(grid);
});
});
d3.select(".uae")
.append("g")
.selectAll("rect").data(uaeMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// arabian
var arabianHash = {};
arabian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
arabianHash[id] = edge;
});
var arabianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (arabianHash[grid.id]) {
grid.percentage = arabianHash[grid.id].percentage;
}
arabianMatrix.push(grid);
});
});
d3.select(".arabian")
.append("g")
.selectAll("rect").data(arabianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// norwegian
var norwegianHash = {};
norwegian.forEach(edge => {
var id = `${edge.source}-${edge.target}`;
norwegianHash[id] = edge;
});
var norwegianMatrix = [];
characteristics.forEach((source, a) => {
rank.forEach((target, b) => {
var grid = {
id: `${source}-${target}`,
x: b,
y: a,
percentage: 0
};
if (norwegianHash[grid.id]) {
grid.percentage = norwegianHash[grid.id].percentage;
}
norwegianMatrix.push(grid);
});
});
d3.select(".norwegian")
.append("g")
.selectAll("rect").data(norwegianMatrix).enter()
.append("rect")
.attr("class", "grid")
.attr("width", 15)
.attr("height", 15)
.attr("x", d => d.x * 15)
.attr("y", d => d.y * 15)
.style("fill-opacity", d => d.percentage);
// MOUSE OVER FUN
d3.selectAll("rect.key").on("mouseover", keyOver);
d3.selectAll("rect.key").on("mouseout", keyOut);
function keyOut(d) {
d3.selectAll("rect.key ")
.style("fill", "#ccc")
.style("stroke", "")
.style("stroke-width", "0px");
d3.selectAll("rect.grid ")
.style("fill", "grey");
}
function keyOver(d) {
d3.selectAll("rect.key ")
.style("fill", function (p) {
return p.x * 15 == d.x * 15 || p.y * 15 == d.y * 15 ? "#666" : "#ccc"
})
.style("stroke", function(p) {
return p.x * 15 == d.x * 15 && p.y * 15 == d.y * 15 ? "#999" : ""
})
.style("stroke-width", function (p) {
return p.x * 15 == d.x * 15 || p.y * 15 == d.y * 15 ? "1px" : "0px"
});
d3.selectAll("rect.grid ")
.style("fill", function (p) {
return p.x * 15 == d.x * 15 || p.y * 15 == d.y * 15 ? "red" : "grey"
});
}
}
source target percentage
Looks 1 0.09
Looks 2 0.06
Looks 3 0.09
Looks 4 0.14
Looks 5 0.23
Looks 6 0.4
Personality 1 0.5
Personality 2 0.21
Personality 3 0.13
Personality 4 0.09
Personality 5 0.04
Personality 6 0.03
Humor 1 0.16
Humor 2 0.28
Humor 3 0.23
Humor 4 0.16
Humor 5 0.1
Humor 6 0.07
Intelligence 1 0.12
Intelligence 2 0.16
Intelligence 3 0.21
Intelligence 4 0.26
Intelligence 5 0.19
Intelligence 6 0.08
Money 1 0.03
Money 2 0.07
Money 3 0.13
Money 4 0.16
Money 5 0.3
Money 6 0.3
Interests 1 0.1
Interests 2 0.23
Interests 3 0.22
Interests 4 0.19
Interests 5 0.14
Interests 6 0.13
.container {
width: 625px !important;
}
.row {
margin-bottom: 10px !important;
}
.row .col.s3 {
width: 20% !important;
}
source target percentage
Looks 1 0.05
Looks 2 0.1
Looks 3 0.11
Looks 4 0.21
Looks 5 0.4
Looks 6 0.13
Personality 1 0.73
Personality 2 0.13
Personality 3 0.07
Personality 4 0.05
Personality 5 0.02
Personality 6 0.01
Humor 1 0.08
Humor 2 0.37
Humor 3 0.26
Humor 4 0.19
Humor 5 0.07
Humor 6 0.03
Intelligence 1 0.07
Intelligence 2 0.18
Intelligence 3 0.28
Intelligence 4 0.28
Intelligence 5 0.17
Intelligence 6 0.02
Money 1 0
Money 2 0.01
Money 3 0.02
Money 4 0.05
Money 5 0.16
Money 6 0.76
Interests 1 0.08
Interests 2 0.22
Interests 3 0.26
Interests 4 0.22
Interests 5 0.18
Interests 6 0.05
source target percentage
Looks 1 0.2
Looks 2 0.15
Looks 3 0.19
Looks 4 0.18
Looks 5 0.13
Looks 6 0.14
Personality 1 0.33
Personality 2 0.18
Personality 3 0.14
Personality 4 0.17
Personality 5 0.13
Personality 6 0.06
Humor 1 0.15
Humor 2 0.21
Humor 3 0.19
Humor 4 0.18
Humor 5 0.16
Humor 6 0.11
Intelligence 1 0.13
Intelligence 2 0.24
Intelligence 3 0.25
Intelligence 4 0.2
Intelligence 5 0.12
Intelligence 6 0.07
Money 1 0.04
Money 2 0.11
Money 3 0.11
Money 4 0.12
Money 5 0.23
Money 6 0.4
Interests 1 0.16
Interests 2 0.11
Interests 3 0.13
Interests 4 0.15
Interests 5 0.24
Interests 6 0.22
source target percentage
Looks 1 0.12
Looks 2 0.11
Looks 3 0.11
Looks 4 0.19
Looks 5 0.23
Looks 6 0.25
Personality 1 0.43
Personality 2 0.18
Personality 3 0.14
Personality 4 0.1
Personality 5 0.11
Personality 6 0.04
Humor 1 0.15
Humor 2 0.22
Humor 3 0.23
Humor 4 0.17
Humor 5 0.13
Humor 6 0.09
Intelligence 1 0.15
Intelligence 2 0.21
Intelligence 3 0.23
Intelligence 4 0.2
Intelligence 5 0.14
Intelligence 6 0.06
Money 1 0.03
Money 2 0.1
Money 3 0.1
Money 4 0.15
Money 5 0.19
Money 6 0.43
Interests 1 0.12
Interests 2 0.18
Interests 3 0.19
Interests 4 0.18
Interests 5 0.2
Interests 6 0.13
source target percentage
Looks 1 0.21
Looks 2 0.13
Looks 3 0.15
Looks 4 0.12
Looks 5 0.18
Looks 6 0.21
Personality 1 0.33
Personality 2 0.23
Personality 3 0.17
Personality 4 0.11
Personality 5 0.1
Personality 6 0.06
Humor 1 0.11
Humor 2 0.19
Humor 3 0.16
Humor 4 0.18
Humor 5 0.2
Humor 6 0.16
Intelligence 1 0.19
Intelligence 2 0.21
Intelligence 3 0.2
Intelligence 4 0.21
Intelligence 5 0.11
Intelligence 6 0.07
Money 1 0.05
Money 2 0.1
Money 3 0.17
Money 4 0.18
Money 5 0.21
Money 6 0.28
Interests 1 0.1
Interests 2 0.14
Interests 3 0.14
Interests 4 0.19
Interests 5 0.2
Interests 6 0.22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment