Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Created December 28, 2017 16:39
Show Gist options
  • Save mpmckenna8/328d7e6c861e588ed129869546e71640 to your computer and use it in GitHub Desktop.
Save mpmckenna8/328d7e6c861e588ed129869546e71640 to your computer and use it in GitHub Desktop.
berlin52 plot
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
let berlin52 = [[565,575],[25,185],[345,750],[945,685],[845,655],
[880,660],[25,230],[525,1000],[580,1175],[650,1130],[1605,620],
[1220,580],[1465,200],[1530,5],[845,680],[725,370],[145,665],
[415,635],[510,875],[560,365],[300,465],[520,585],[480,415],
[835,625],[975,580],[1215,245],[1320,315],[1250,400],[660,180],
[410,250],[420,555],[575,665],[1150,1160],[700,580],[685,595],
[685,610],[770,610],[795,645],[720,635],[760,650],[475,960],
[95,260],[875,920],[700,500],[555,815],[830,485],[1170,65],
[830,610],[605,625],[595,360],[1340,725],[1740,245]]
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var svg = d3.select("body").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 + ")");
svg.append("text")
.text("Berlin52, lets find an optimal solution!!")
.attr("y", 200)
.attr("x", 120)
.attr("font-size", 19)
.attr("font-family", "monospace")
let x = d3.scaleLinear().range([0, width])
let y = d3.scaleLinear().range([height, 0])
x.domain([0, d3.max(berlin52, function(d) {
return d[0]
})])
y.domain([0, d3.max(berlin52, function(d) {
return d[1]
})])
svg.selectAll('dot')
.data(berlin52)
.enter()
.append('circle')
.attr('r', 6)
.attr('cx', function(d) {
return x(d[0])
})
.attr('cy', function(d) {
return y(d[1])
})
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment