@@ -44,6 +44,7 @@ var Graph = /** @class */ (function () {
44
44
*/
45
45
this . loadData = function ( ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
46
46
var response , _a ;
47
+ var _this = this ;
47
48
return __generator ( this , function ( _b ) {
48
49
switch ( _b . label ) {
49
50
case 0 : return [ 4 /*yield*/ , fetch ( "/res/liked_songs.json" ) ] ;
@@ -53,6 +54,11 @@ var Graph = /** @class */ (function () {
53
54
return [ 4 /*yield*/ , response . json ( ) ] ;
54
55
case 2 :
55
56
_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
+ } ) ;
56
62
this . init ( ) ;
57
63
return [ 2 /*return*/ ] ;
58
64
}
@@ -76,6 +82,7 @@ var Graph = /** @class */ (function () {
76
82
start : 0 ,
77
83
end : this . canvasSize . width
78
84
} ;
85
+ this . scaleY = this . canvasSize . height / this . longestDuration ;
79
86
this . startDrawingInterval ( ) ;
80
87
this . changeViewport ( ) ;
81
88
this . updateFps ( ) ;
@@ -104,7 +111,8 @@ var Graph = /** @class */ (function () {
104
111
_this . songs . forEach ( function ( song ) { return ( song . active = false ) ; } ) ;
105
112
if ( e . offsetY >
106
113
_this . canvasSize . height -
107
- _this . timeStringToSeconds ( _this . songs [ clickedSong ] . duration ) ) {
114
+ _this . timeStringToSeconds ( _this . songs [ clickedSong ] . duration ) *
115
+ _this . scaleY ) {
108
116
_this . songs [ clickedSong ] . active = true ;
109
117
_this . detailInfos = _this . songs [ clickedSong ] ;
110
118
}
@@ -156,7 +164,7 @@ var Graph = /** @class */ (function () {
156
164
* bar based of the length of the song
157
165
*/
158
166
Graph . prototype . drawDurationGraph = function ( ) {
159
- this . stepSize = 5 ;
167
+ this . stepSize = 15 ;
160
168
var x = 0 ;
161
169
var infoX = 0 ;
162
170
var infoY = 0 ;
@@ -175,11 +183,11 @@ var Graph = /** @class */ (function () {
175
183
else {
176
184
this . ctx . fillStyle = "red" ;
177
185
}
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 ) ;
179
187
x += this . stepSize ;
180
188
}
181
189
if ( drawInfo ) {
182
- this . drawDetailBubble ( infoX , this . canvasSize . height - infoY - 100 ) ;
190
+ this . drawDetailBubble ( infoX , ( this . canvasSize . height - infoY - 20 ) * this . scaleY ) ;
183
191
}
184
192
} ;
185
193
/**
0 commit comments