Skip to content

Instantly share code, notes, and snippets.

@seanriordan08
Last active April 3, 2020 18:38
Show Gist options
  • Save seanriordan08/19bd057cd0e96c402fa8f1a8c8063943 to your computer and use it in GitHub Desktop.
Save seanriordan08/19bd057cd0e96c402fa8f1a8c8063943 to your computer and use it in GitHub Desktop.
Editorial Music Playlist Project
license: gpl-3.0
height: 600

We could keep a dynamic graph of each playlist where BPM is associated with track order per playlist/procedure

[
{
"Letter": "Breathe - Telepopmusik",
"Freq": 114
},
{
"Letter" : "Let Go - Frou Frou",
"Freq": 140
},
{
"Letter" : "Down the Road - C2C",
"Freq": 111
},
{
"Letter" : "Ohio - filous/Damien Jurado",
"Freq": 121
},
{
"Letter" : "Superposition - Young the Giant",
"Freq" : 170
},
{
"Letter" : "Here It Goes Again - OK Go",
"Freq" : 146
},
{
"Letter" : "Told You Once - Apples in Stereo",
"Freq" : 126
},
{
"Letter" : "Something Good Can Work - Two Door Cinema Club",
"Freq" : 119
},
{
"Letter" : "Luna - Bombay Bicycle Club",
"Freq" : 108
},
{
"Letter" : "Eat,Sleep,Wake(Nothing But You) - Bombay Bicycle Club",
"Freq" : 117
},
{
"Letter" : "Roma Fade - Andrew Bird",
"Freq" : 138
},
{
"Letter" : "Boy With A Coin",
"Freq" : 125
},
{
"Letter" : "Fresh Feeling - Eels",
"Freq" : 94
},
{
"Letter" : "Pressure Suit - Aqualung",
"Freq" : 156
},
{
"Letter" : "Woman - Mumford and Sons",
"Freq" : 156
}
]
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<style>
.bar{
fill: steelblue;
}
.bar:hover{
fill: brown;
}
.axis {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
// set the dimensions of the canvas
var margin = {top: 20, right: 20, bottom: 70, left: 40},
width = 600 - margin.left - margin.right,
height = 600 - margin.top - margin.bottom;
// set the ranges
var x = d3.scale.ordinal().rangeRoundBands([0, width], .05);
var y = d3.scale.linear().range([height, 0]);
// define the axis
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(10);
// add the SVG element
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 + ")");
// load the data
d3.json("data.json", function(error, data) {
data.forEach(function(d) {
d.Letter = d.Letter;
d.Freq = +d.Freq;
});
// scale the range of the data
x.domain(data.map(function(d) { return d.Letter; }));
y.domain([0, d3.max(data, function(d) { return d.Freq; })]);
// add axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", "-.55em")
.attr("transform", "rotate(-90)" );
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 5)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Tempo/BPM");
// Add bar chart
svg.selectAll("bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.Letter); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.Freq); })
.attr("height", function(d) { return height - y(d.Freq); });
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment