Skip to content

Commit dda39bb

Browse files
author
Lukas Meier
committed
Y Axis is now scaled so all songs fit completely
1 parent 8fd1f82 commit dda39bb

File tree

4 files changed

+28504
-69
lines changed

4 files changed

+28504
-69
lines changed

js/Graph.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var Graph = /** @class */ (function () {
4444
*/
4545
this.loadData = function () { return __awaiter(_this, void 0, void 0, function () {
4646
var response, _a;
47+
var _this = this;
4748
return __generator(this, function (_b) {
4849
switch (_b.label) {
4950
case 0: return [4 /*yield*/, fetch("/res/liked_songs.json")];
@@ -53,6 +54,11 @@ var Graph = /** @class */ (function () {
5354
return [4 /*yield*/, response.json()];
5455
case 2:
5556
_a.songs = _b.sent();
57+
this.songs.forEach(function (song) {
58+
var dur = _this.timeStringToSeconds(song.duration);
59+
_this.longestDuration =
60+
_this.longestDuration > dur ? _this.longestDuration : dur;
61+
});
5662
this.init();
5763
return [2 /*return*/];
5864
}
@@ -76,6 +82,7 @@ var Graph = /** @class */ (function () {
7682
start: 0,
7783
end: this.canvasSize.width
7884
};
85+
this.scaleY = this.canvasSize.height / this.longestDuration;
7986
this.startDrawingInterval();
8087
this.changeViewport();
8188
this.updateFps();
@@ -104,7 +111,8 @@ var Graph = /** @class */ (function () {
104111
_this.songs.forEach(function (song) { return (song.active = false); });
105112
if (e.offsetY >
106113
_this.canvasSize.height -
107-
_this.timeStringToSeconds(_this.songs[clickedSong].duration)) {
114+
_this.timeStringToSeconds(_this.songs[clickedSong].duration) *
115+
_this.scaleY) {
108116
_this.songs[clickedSong].active = true;
109117
_this.detailInfos = _this.songs[clickedSong];
110118
}
@@ -156,7 +164,7 @@ var Graph = /** @class */ (function () {
156164
* bar based of the length of the song
157165
*/
158166
Graph.prototype.drawDurationGraph = function () {
159-
this.stepSize = 5;
167+
this.stepSize = 15;
160168
var x = 0;
161169
var infoX = 0;
162170
var infoY = 0;
@@ -175,11 +183,11 @@ var Graph = /** @class */ (function () {
175183
else {
176184
this.ctx.fillStyle = "red";
177185
}
178-
this.ctx.fillRect(x, this.canvasSize.height - height, this.stepSize, height);
186+
this.ctx.fillRect(x, this.canvasSize.height - height * this.scaleY, this.stepSize, height * this.scaleY);
179187
x += this.stepSize;
180188
}
181189
if (drawInfo) {
182-
this.drawDetailBubble(infoX, this.canvasSize.height - infoY - 100);
190+
this.drawDetailBubble(infoX, (this.canvasSize.height - infoY - 20) * this.scaleY);
183191
}
184192
};
185193
/**

0 commit comments

Comments
 (0)