Skip to content

Commit 4fa81bb

Browse files
author
Lukas Meier
committed
Added bars to the infosection at the top left
1 parent 3749b5d commit 4fa81bb

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

js/Graph.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ var Graph = /** @class */ (function () {
124124
_this.visibleRange.start = Math.floor(delta);
125125
_this.visibleRange.end = Math.floor(stepsPerViewPort + delta);
126126
initialDelta = delta * _this.stepSize;
127+
_this.scrollPercentage = Math.round((delta / (_this.songs.length - stepsPerViewPort)) * 100);
127128
});
128129
document.addEventListener("mouseup", function (e) {
129130
dragging = false;
@@ -245,6 +246,9 @@ var Graph = /** @class */ (function () {
245246
* @returns {number} The time in seconds
246247
*/
247248
Graph.prototype.timeStringToSeconds = function (timeString) {
249+
var regex = /^([0-9]|[0-9]{2})[:][0-5][0-9]$/;
250+
if (!regex.test(timeString))
251+
return 0;
248252
var total = 0;
249253
var tmp = timeString.split(":");
250254
total += parseInt(tmp[0]) * 60;
@@ -256,13 +260,22 @@ var Graph = /** @class */ (function () {
256260
* the top left of the graph
257261
*/
258262
Graph.prototype.drawFps = function () {
263+
var color;
259264
if (this.calculatedFps > 30) {
260-
this.ctx.fillStyle = "#000";
265+
color = "#15871D";
261266
}
262267
else {
263-
this.ctx.fillStyle = "#FF4F19";
268+
color = "#FF4F19";
264269
}
270+
this.ctx.fillStyle = color;
265271
this.ctx.fillText("FPS: " + this.calculatedFps, 5, 12);
272+
this.ctx.fillStyle = "#000";
273+
this.ctx.fillRect(60, 4, 102, 10);
274+
this.ctx.fillStyle = "#fff";
275+
this.ctx.fillRect(61, 5, 100, 8);
276+
this.ctx.fillStyle = color;
277+
var fpsWidth = this.calculatedFps / this.fps * 100;
278+
this.ctx.fillRect(61, 5, fpsWidth, 8);
266279
};
267280
/**
268281
* Will draw the percentage scrolled at
@@ -271,6 +284,11 @@ var Graph = /** @class */ (function () {
271284
Graph.prototype.drawScrollPercentage = function () {
272285
this.ctx.fillStyle = "#000";
273286
this.ctx.fillText(this.scrollPercentage + "%", 5, 25);
287+
this.ctx.fillRect(60, 16, 102, 10);
288+
this.ctx.fillStyle = "#fff";
289+
this.ctx.fillRect(61, 17, 100, 8);
290+
this.ctx.fillStyle = "#0B0284";
291+
this.ctx.fillRect(61, 17, this.scrollPercentage, 8);
274292
};
275293
/**
276294
* Since the FPS should not be updated every

ts/Graph.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class Graph {
101101
this.visibleRange.end = Math.floor(stepsPerViewPort + delta);
102102

103103
initialDelta = delta * this.stepSize;
104+
105+
this.scrollPercentage = Math.round(
106+
(delta / (this.songs.length - stepsPerViewPort)) * 100
107+
);
104108
});
105109

106110
document.addEventListener("mouseup", e => {
@@ -273,6 +277,8 @@ class Graph {
273277
* @returns {number} The time in seconds
274278
*/
275279
timeStringToSeconds(timeString: string): number {
280+
let regex = /^([0-9]|[0-9]{2})[:][0-5][0-9]$/;
281+
if (!regex.test(timeString)) return 0;
276282
let total = 0;
277283
let tmp = timeString.split(":");
278284
total += parseInt(tmp[0]) * 60;
@@ -285,12 +291,25 @@ class Graph {
285291
* the top left of the graph
286292
*/
287293
drawFps(): void {
294+
let color : string;
288295
if (this.calculatedFps > 30) {
289-
this.ctx.fillStyle = "#000";
296+
color = "#15871D";
290297
} else {
291-
this.ctx.fillStyle = "#FF4F19";
298+
color = "#FF4F19";
292299
}
300+
this.ctx.fillStyle = color;
301+
293302
this.ctx.fillText("FPS: " + this.calculatedFps, 5, 12);
303+
304+
this.ctx.fillStyle = "#000";
305+
this.ctx.fillRect(60, 4, 102, 10);
306+
307+
this.ctx.fillStyle = "#fff";
308+
this.ctx.fillRect(61, 5, 100, 8);
309+
310+
this.ctx.fillStyle = color;
311+
let fpsWidth = this.calculatedFps / this.fps * 100
312+
this.ctx.fillRect(61, 5, fpsWidth, 8);
294313
}
295314

296315
/**
@@ -300,6 +319,14 @@ class Graph {
300319
drawScrollPercentage(): void {
301320
this.ctx.fillStyle = "#000";
302321
this.ctx.fillText(this.scrollPercentage + "%", 5, 25);
322+
323+
this.ctx.fillRect(60, 16, 102, 10);
324+
325+
this.ctx.fillStyle = "#fff";
326+
this.ctx.fillRect(61, 17, 100, 8);
327+
328+
this.ctx.fillStyle = "#0B0284";
329+
this.ctx.fillRect(61, 17, this.scrollPercentage, 8);
303330
}
304331

305332
/**

0 commit comments

Comments
 (0)