Skip to content

Commit

Permalink
Made dimensions dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
jrg94 committed Apr 18, 2019
1 parent b3f1618 commit 6cd0dc0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
6 changes: 4 additions & 2 deletions midiviz/js/NotesFrequencyPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class NotesFrequencyPane {
var svg = d3.select("#note-frequency");

var padding = 50;
var width = 700;
var height = 400;
var width;
var height;
[width, height] = getGraphDimensions("#note-frequency");

// TODO: Separate this padding into a map? top/bottom/left/right. It appears inconsistently centered now.

var keys = Object.keys(this.dashboard.midiFiles);
Expand Down
6 changes: 4 additions & 2 deletions midiviz/js/NotesPlayedPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class NotesPlayedPane {
// TODO: Adjust width here based on parameters? (# of notes, length of song, screen size)?
// Adjust title formula accordingly. Currently at * 2 for both
var padding = 50;
var width = 3500;
var height = 600;
var width;
var height;
[width, height] = getGraphDimensions("#notes-over-time");


let mapping = this.dashboard.mappings.notes;

Expand Down
5 changes: 3 additions & 2 deletions midiviz/js/NotesVelocityPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class NotesVelocityPane {
var svg = d3.select("#velocity-over-time");

var padding = 50;
var width = 1400;
var height = 400;
var width;
var height;
[width, height] = getGraphDimensions("#velocity-over-time");

var keys = Object.keys(this.dashboard.midiFiles);
var timestamps = this.dashboard.mappings.velocity;
Expand Down
8 changes: 8 additions & 0 deletions midiviz/js/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ function drawYAxis(svg, yScale, padding, height, label) {
.style("text-anchor", "middle")
.text(label);
}

function getGraphDimensions(graph) {
var svg = d3.select(graph);
var viewBox = svg.attr("viewBox").split(" ");
var width = parseInt(viewBox[2], 10);
var height = parseInt(viewBox[3], 10);
return [width, height];
}

0 comments on commit 6cd0dc0

Please sign in to comment.