Built with blockbuilder.org
xxxxxxxxxx
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Chronological Diagram of Asia</title>
<script type="text/javascript" src="nexusUI.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/d3@2.10.3/d3.v2.js"></script>
<!--<script src="https://d3js.org/d3.v4.min.js"></script>-->
<script type="text/javascript" src="notesOnlyJSON.js"></script>
<script src="Tone.js"></script>
<style type="text/css">
.chart {
shape-rendering: crispEdges;
}
.mini text {
font: 9px sans-serif;
}
.main text {
font: 12px sans-serif;
}
.miniItem0 {
fill: darksalmon;
stroke: black;
stroke-width: 2;
}
.miniItem1 {
fill: darkolivegreen;
fill-opacity: .7;
stroke: black;
stroke-width: 2
}
.miniItem2 {
fill: slategray;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem3 {
fill: #59e95e;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem4 {
fill: slategray;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem5 {
fill: #e94cbb;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem6 {
fill: #59e95e;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem7 {
fill: slategray;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem8 {
fill: #b077e9;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem9 {
fill: #64326b;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem10 {
fill: darksalmon;
stroke: black;
stroke-width: 2;
}
.miniItem11{
fill: darkolivegreen;
fill-opacity: .7;
stroke: black;
stroke-width: 2
}
.miniItem12 {
fill: slategray;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem13 {
fill: #59e95e;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem14 {
fill: slategray;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem15 {
fill: #e94cbb;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem16 {
fill: #59e95e;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem17 {
fill: slategray;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem18 {
fill: #b077e9;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem19 {
fill: #64326b;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.miniItem20 {
fill: #64326b;
fill-opacity: .7;
stroke: black;
stroke-width: 2;
}
.brush .selection {
fill: none;
}
</style>
</head>
<body>
<script type="text/javascript">
//data
var lanes = ["C3","D3","E3","F3","G3","A3","B3","C4","D4","E4","F4","G4","A4","B4","C5","D5","E5","F5","G5", "A5", "B5"], //21 pitches
laneLength = lanes.length,
timeBegin = 0,
timeEnd = 65.33326800000005;
</script>
<script type="text/javascript">
var m = [20, 15, 15, 120], //top right bottom left
w = 960 - m[1] - m[3],
h = 500 - m[0] - m[2],
miniHeight = laneLength * 18, //removed *12
mainHeight = h - miniHeight - 50;
//scales
var x = d3.scale.linear() //where is this positioned? at the top or bottom? this might be for main
.domain([timeBegin, timeEnd])
.range([0, w]);
var y2 = d3.scale.linear()
.domain([0, laneLength])
.range([0, miniHeight]);
var zoom = d3.behavior.zoom()
.scaleExtent([1, 10])
.on("zoom", zoomed);
var //xAxis = d3.svg.axis().scale(x1).orient("bottom"),
xAxis2 = d3.svg.axis().scale(x).orient("bottom"),
drag = d3.behavior.drag() //when moving rect from left side, other components of rectangle need to be resized //so we must include this...i think
.on("drag", dragmove);
var brush = d3.svg.brush();
//brush.on('brushend', bindSelect)
chart = d3.select("body")
.append("svg")
.attr("width", w + m[1] + m[3])
.attr("height", h + m[0] + m[2])
.attr("class", "chart")
.attr('id','mySVG')
.call(brush.x(x).y(y2).on('brushend',notesSelected))
.call(zoom);
var mini = chart.append("g")
.attr("transform", "translate(" + m[3] + "," + (mainHeight + m[0]) + ")")
.attr("width", w)
.attr("height", miniHeight)
.attr("class", "mini");
//var notesBrush = mini.append("g")
// .attr("class", "brush")
// .call(brush);
// notesBrush.call(brush.move);
//mini lanes and texts
mini.append("g").selectAll(".laneLines")
.data(minimalNotesFinal)
//.data(notes)
.enter().append("line")
.attr("x1", m[1])
.attr("y1", function(d) {return y2(d.lane);})
.attr("x2", w)
.attr("y2", function(d) {return y2(d.lane);})
.attr("stroke", "lightgray");
mini.append("g").selectAll(".laneText")
.data(lanes)
.enter().append("text")
.text(function(d) {return d;})
.attr("x", -m[1])
.attr("y", function(d, i) {return y2(i + .5);})
.attr("dy", ".5ex")
.attr("text-anchor", "end")
.attr("class", "laneText");
mini.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + miniHeight + ")")
.call(xAxis2);
//mini item rects soon to be brushes
mini.append("g").selectAll("miniItems")
.data(minimalNotesFinal)
.enter().append("rect") //"brush"
.attr("class", function(d) {return "miniItem" + d.lane;}) //midi
.attr("x", function(d) {return x(d.time);}) //time
.attr("y", function(d) {return y2(d.lane + .5) - 5;}) //midi
.attr("width", function(d) {
return x(d.duration);})
.attr("height", 10)
.on('click', noteClicked)
.call(drag);
//brush on mini chart
/*function bindSelect(){
if (d3.event.defaultPrevented) return; // dragged
d3.select('#mySVG rect.extent')
.on('click',function(){alert('hi mom!')})
}*/
/*function brushed(d,i){
if (d3.event.defaultPrevented) return; // dragged
var notesSelected = [];
d3.select(this);
notesSelected.push(d.name[i], d.duration[i]);
console.log(notesSelected);
}*/
function notesSelected() {
if (d3.event.defaultPrevented) return; // dragged
var synth = new Tone.FMSynth().toMaster();
d3.select(this);
synth.triggerAttackRelease(function(d,i){
return (d.name[i], d.duration[i])});
}
function noteClicked(d, i) { //
if (d3.event.defaultPrevented) return; // dragged
var synth = new Tone.FMSynth().toMaster();
d3.select(this);
synth.triggerAttackRelease(d.name, d.duration)
}
function dragmove(d) {
d3.select(this)
.attr("x", d.x = Math.max(0, d3.event.x));
}
function zoomed() {
mini.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
</script>
</body>
</html>
Modified http://mbostock.github.com/d3/d3.v2.js to a secure url
https://mbostock.github.com/d3/d3.v2.js
https://d3js.org/d3.v4.min.js