Skip to content

Commit

Permalink
Merge pull request #56 from jrg94/text-fix
Browse files Browse the repository at this point in the history
Fixed Text Skewing
  • Loading branch information
jrg94 authored Apr 18, 2019
2 parents 3ffaa5c + 056f2f0 commit 7bf0ffa
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ JuxtaMIDI -- a tool to compare and contrast MIDI recordings.
- Final Report
- [PDF][6]
- [Source Code][16]

## Sample MIDI Files

- [Mario Theme][18]
Expand Down Expand Up @@ -55,4 +55,4 @@ JuxtaMIDI -- a tool to compare and contrast MIDI recordings.
[19]: data/Mario-Few.mid
[20]: data/Mario-Shift.mid
[21]: #sample-midi-files
[22]: https://github.com/jrg94/JuxtaMIDI/releases/tag/v1.3.0
[22]: https://github.com/jrg94/JuxtaMIDI/releases/tag/v1.3.1
6 changes: 5 additions & 1 deletion midiviz/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body {
.container {
display: grid;
grid-gap: 10px;
grid-template-columns: 9% 42% 42% auto;
grid-template-columns: 10% 42% 42% auto;
grid-template-rows: 60% auto;
width: 98%;
height: 98%;
Expand Down Expand Up @@ -121,6 +121,10 @@ div.graph-disabled {
padding: 2%;
}

.axes-labels {
font: 20px sans-serif;
}

.welcome-message {
align-self: center;
justify-self: center;
Expand Down
6 changes: 3 additions & 3 deletions midiviz/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
<div class="welcome-message">
Welcome to the MIDI Comparison Tool! To get started, add MIDI files using the pane on the left.
</div>
<svg id="notes-over-time" viewBox="0 0 3500 600" width="200%" height="100%" preserveAspectRatio="none"></svg>
<svg id="notes-over-time"></svg>
</div>

<div class="box graph-pane note-frequency-graph-pane">
<svg id="note-frequency" viewBox="0 0 700 400" width="100%" height="100%" preserveAspectRatio="none"></svg>
<svg id="note-frequency"></svg>
</div>

<div class="box graph-pane velocity-over-time-graph-pane">
<svg id="velocity-over-time" viewBox="0 0 1400 400" width="200%" height="100%" preserveAspectRatio="none"></svg>
<svg id="velocity-over-time"></svg>
</div>

<div class="box graph-view-buttons">
Expand Down
1 change: 1 addition & 0 deletions midiviz/js/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Dashboard {

clearSvgs() {
d3.selectAll("svg")
.html("")
.selectAll("*")
.remove();
}
Expand Down
2 changes: 1 addition & 1 deletion midiviz/js/GraphViewPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class GraphViewPane {
switchToPane(pane) {
d3.selectAll(".graph-view-buttons span").classed("disabled-view-button", false);
d3.selectAll(".graph-view-buttons span").classed("selected-view-button", false);
this.dashboard.clearSvgs();
if (pane == Views.ALL) {
d3.select("#view-all").classed("selected-view-button", true);
d3.selectAll(".graph-pane").classed("selected-view", false);
d3.selectAll(".graph-pane").classed("graph-disabled", false);
d3.selectAll(".graph-pane").classed("single-graph-activated", false);
this.dashboard.clearSvgs();
this.dashboard.panes.notesPlayed.graph();
this.dashboard.panes.notesFrequency.graph();
this.dashboard.panes.notesVelocity.graph();
Expand Down
9 changes: 3 additions & 6 deletions midiviz/js/NotesFrequencyPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ class NotesFrequencyPane {
graph() {
var svg = d3.select("#note-frequency");

var padding = 50;
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 width, height, padding;
[width, height, padding] = getPaneDimensions("#note-frequency");
setGraphDimensions("#note-frequency", width, height);

var keys = Object.keys(this.dashboard.midiFiles);
var mapping = this.dashboard.mappings.frequency;
Expand Down
11 changes: 4 additions & 7 deletions midiviz/js/NotesPlayedPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ class NotesPlayedPane {

var keys = Object.keys(this.dashboard.midiFiles);

// 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;
var height;
[width, height] = getGraphDimensions("#notes-over-time");

var padding, width, height;
[width, height, padding] = getPaneDimensions("#notes-over-time");
width *= 2;
setGraphDimensions("#notes-over-time", width, height, 2);

let mapping = this.dashboard.mappings.notes;

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

var padding = 50;
var width;
var height;
[width, height] = getGraphDimensions("#velocity-over-time");
var padding, width, height;
[width, height, padding] = getPaneDimensions("#velocity-over-time");
width *= 2;
setGraphDimensions("#velocity-over-time", width, height, 2);

var keys = Object.keys(this.dashboard.midiFiles);
var timestamps = this.dashboard.mappings.velocity;
Expand Down
34 changes: 25 additions & 9 deletions midiviz/js/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function drawTitle(svg, width, height, padding, title) {
.style("text-anchor", "middle")
.style("font-size", "18px")
.text(title)
.classed("axes-labels", true);
}

/**
Expand Down Expand Up @@ -66,12 +67,12 @@ function drawXAxis(svg, xScale, padding, height, width, label, rotated=false) {
.call(d3.axisBottom(xScale))
}


// Draw x-axis title
svg.append("text")
.attr("transform", "translate(" + ((width / 2) - padding / 2) + " ," + (height - 10) + ")")
.attr("transform", "translate(" + ((width / 2) - padding / 2) + " ," + (height - 5) + ")")
.style("text-anchor", "middle")
.text(label);
.text(label)
.classed("axes-labels", true);
}

/**
Expand All @@ -95,13 +96,28 @@ function drawYAxis(svg, yScale, padding, height, label) {
.attr("x", 0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text(label);
.text(label)
.classed("axes-labels", true);
}

function getGraphDimensions(graph) {
/**
* Grabs the dimensions of the SVG container
*/
function getPaneDimensions(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];
var width = svg.node().parentNode.getBoundingClientRect().width;
var height = svg.node().parentNode.getBoundingClientRect().height;
return [width, height, 50];
}

/**
* Sets the dimensions of the SVG
*/
function setGraphDimensions(graph, width, height, scalingFactor = 1) {
var widthPercentage = 100 * scalingFactor;
var svg = d3.select(graph)
.attr("width", `${widthPercentage}%`)
.attr("height", "100%")
.attr("viewBox", `0 0 ${width} ${height}`)
.attr("preserveAspectRatio", "none");
}

0 comments on commit 7bf0ffa

Please sign in to comment.