Skip to content

Commit e57ac9c

Browse files
committed
Time marks stay when you scroll
1 parent a115675 commit e57ac9c

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

src/timeline/js/directives/ruler.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ App.directive("tlRuler", function ($timeout) {
175175
// startTime : time[0]; endTime : time[1]
176176
fps = scope.project.fps.num / scope.project.fps.den;
177177
time = [ startPos / scope.pixelsPerSecond, endPos / scope.pixelsPerSecond];
178-
time[0] -= time[0]%1;
178+
time[0] -= time[0]%2;
179179
time[1] -= time[1]%1 - 1;
180180

181181
startFrame = time[0] * Math.round(fps);
@@ -185,21 +185,17 @@ App.directive("tlRuler", function ($timeout) {
185185
let tPrev;
186186
showTime = true;
187187

188-
// timePerTick = framesPerTick(scope.pixelsPerSecond, scope.project.fps.num ,scope.project.fps.num) / fps;
189-
// console.log('FPT: ' + framesPerTick(scope.pixelsPerSecond, scope.project.fps.num ,scope.project.fps.num));
190-
fpt = framesPerTick(scope.pixelsPerSecond, scope.project.fps.num ,scope.project.fps.den)
191-
frame = startFrame
192-
console.log ("Start: "+ startFrame)
193-
console.log ("End : "+ endFrame)
194-
console.log ("FPT : "+ fpt)
195-
console.log ("start Time : "+ time[0])
188+
fpt = framesPerTick(scope.pixelsPerSecond, scope.project.fps.num ,scope.project.fps.den);
189+
frame = startFrame;
190+
console.log('fpt: ' + fpt);
191+
console.log('startFrame: ' + startFrame);
196192
while ( frame <= endFrame){
197193
t = frame / fps;
198194
pos = t * scope.pixelsPerSecond;
199195
tickSpan = $('<span style="left:'+pos+'px;"></span>');
200196
tickSpan.addClass("tick_mark");
201197

202-
if (showTime) {
198+
if ((frame - startFrame) % (fpt * 2) == 0) {
203199
timeSpan = $('<span style="left:'+pos+'px;"></span>');
204200
timeSpan.addClass("ruler_time");
205201
timeText = secondsToTime(t, scope.project.fps.num, scope.project.fps.den);
@@ -209,19 +205,15 @@ App.directive("tlRuler", function ($timeout) {
209205
if (fpt < Math.round(fps)) {
210206
timeSpan[0].innerText += ',' + timeText['frame'];
211207
}
212-
// timeText['frame'];
213208
tickSpan[0].style['height'] = '20px';
214-
showTime = false;
215-
} else {
216-
showTime = true;
217209
}
218210
ruler.append(timeSpan);
219211
ruler.append(tickSpan);
220212

221213
frame += fpt;
222214
}
223215
return;
224-
}
216+
};
225217

226218
scope.$watch("project.scale + project.duration + scrollLeft", function (val) {
227219
if (val) {

src/timeline/js/functions.js

+32-13
Original file line numberDiff line numberDiff line change
@@ -335,26 +335,48 @@ function moveBoundingBox(scope, previous_x, previous_y, x_offset, y_offset, left
335335
}
336336

337337
/**
338+
* Primes are used for factoring.
339+
* Store any that have been found for future use.
340+
*/
341+
global_primes = new Set();
342+
343+
/**
344+
* Creates a list of all primes less than n.
345+
* Stores primes in a set for better performance in the future.
346+
* If some primes have been found, start with that list,
347+
* and check the remaining numbers up to n.
338348
* @param {any number} n
339349
* @returns the list of all primes less than n
340350
*/
341351
function primesUpTo(n) {
352+
n = Math.floor(n);
353+
if (Array.from(global_primes).pop() >= n) { // All primes already found
354+
return Array.from(global_primes).filter( x => { return x < n });
355+
}
356+
start = 2; // 0 and 1 can't be prime
342357
primes = [...Array(n+1).keys()]; // List from 0 to n
343-
primes = primes.slice(2,primes.length -1); // 0 and 1 divide nothing and everything
344-
primes.forEach( p => {
358+
if (Array.from(global_primes).length) { // Some primes already found
359+
start = Array.from(global_primes).pop() + 1;
360+
primes = primes.slice(start,primes.length -1);
361+
primes = Array.from(global_primes).concat(primes);
362+
} else {
363+
primes = primes.slice(start,primes.length -1);
364+
}
365+
primes.forEach( p => { // Sieve of Eratosthenes method of prime factoring
345366
primes = primes.filter( test => { return (test % p != 0) || (test == p) } );
346-
});
347-
primes.forEach( p => {
348367
global_primes.add(p);
349-
})
368+
});
350369
return primes;
351370
}
352371

353372
/**
373+
* Every integer is either prime,
374+
* is the product of some list of primes.
354375
* @param {integer to factor} n
355376
* @returns the list of prime factors of n
356377
*/
357378
function primeFactorsOf(n) {
379+
n = Math.floor(n);
358380
factors = [];
359381
primes = primesUpTo(n);
360382
primes.push(n);
@@ -373,6 +395,9 @@ function primeFactorsOf(n) {
373395
* From the pixels per second of the project,
374396
* Find a number of frames between each ruler mark,
375397
* such that the tick marks remain at least 50px apart.
398+
*
399+
* Increases the number of frames by factors of FPS.
400+
* This way each tick should land neatly on a second mark
376401
* @param {Pixels per second} pps
377402
* @param fps_num
378403
* @param fps_den
@@ -384,15 +409,9 @@ function framesPerTick(pps, fps_num, fps_den) {
384409
seconds = () => { return frames / fps };
385410
pixels = () => { return seconds() * pps };
386411
factors = primeFactorsOf(Math.round(fps));
387-
while (pixels() < 35) {
412+
while (pixels() < 40) {
388413
frames *= factors.shift() || 2;
389414
}
390415

391416
return frames;
392-
}
393-
394-
/**
395-
* Primes are used for factoring.
396-
* Store any that have been found for future use.
397-
*/
398-
global_primes = new Set();
417+
}

0 commit comments

Comments
 (0)