]> source.dussan.org Git - svg.js.git/commitdiff
add default parameter for timeSource
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Wed, 21 Nov 2018 20:33:03 +0000 (21:33 +0100)
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Wed, 21 Nov 2018 20:33:03 +0000 (21:33 +0100)
dirty.html
dist/svg.js
src/animation/Timeline.js

index 8824c6b51ea5a54c621d6ba94ff839a3485121e4..712c13c140b3302c20cd8cacd6c8a147f52b1454 100644 (file)
@@ -135,9 +135,9 @@ var mover = canvas.line(100, 100, 100, 300).attr('stroke', 'black')
 mover.clone().insertAfter(mover)
 canvas.line(100, 300, 800, 300).attr('stroke', 'black')
 
-// t.on('time', function (e) {
-//   mover.x(100 + e.detail/10)
-// })
+t.on('time', function (e) {
+  mover.x(100 + e.detail/10)
+})
 
 
 console.log(schedule)
index 6abe275777e8d897a2d2928013449209bf6a35e4..9d7a8611e8c1c8b4c08936e202881ba017da3af2 100644 (file)
@@ -6,7 +6,7 @@
 * @copyright Wout Fierens <wout@mick-wout.com>
 * @license MIT
 *
-* BUILT: Tue Nov 20 2018 16:59:18 GMT+0100 (GMT+01:00)
+* BUILT: Wed Nov 21 2018 10:58:56 GMT+0100 (GMT+01:00)
 */;
 var SVG = (function () {
   'use strict';
@@ -5010,6 +5010,11 @@ var SVG = (function () {
     };
   };
 
+  var defaultSource = function defaultSource() {
+    var w = globals.window;
+    return (w.performance || w.Date).now();
+  };
+
   var Timeline =
   /*#__PURE__*/
   function (_EventTarget) {
@@ -5019,15 +5024,12 @@ var SVG = (function () {
     function Timeline() {
       var _this;
 
+      var timeSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultSource;
+
       _classCallCheck(this, Timeline);
 
       _this = _possibleConstructorReturn(this, _getPrototypeOf(Timeline).call(this));
-
-      _this._timeSource = function () {
-        var w = globals.window;
-        return (w.performance || w.Date).now();
-      }; // Store the timing variables
-
+      _this._timeSource = timeSource; // Store the timing variables
 
       _this._startTime = 0;
       _this._speed = 1.0; // Play control variables control how the animation proceeds
@@ -5043,20 +5045,15 @@ var SVG = (function () {
       _this._lastSourceTime = 0;
       _this._lastStepTime = 0;
       return _this;
-    }
-    /**
-     *
-     */
-    // schedules a runner on the timeline
+    } // schedules a runner on the timeline
 
 
     _createClass(Timeline, [{
       key: "schedule",
       value: function schedule(runner, delay, when) {
-        // FIXME: how to sort? maybe by runner id?
         if (runner == null) {
           return this._runners.map(makeSchedule).sort(function (a, b) {
-            return a.runner.id - b.runner.id; // return (a.start - b.start) || (a.duration - b.duration)
+            return a.runner.id - b.runner.id;
           });
         }
 
@@ -5256,6 +5253,7 @@ var SVG = (function () {
         if (runnersLeft) {
           this._nextFrame = Animator.frame(this._step.bind(this));
         } else {
+          this.fire('finished');
           this._nextFrame = null;
         }
 
index 6e1ed8d8449dd8a5baf1b190692447bd9f6faa07..a0d8069ebd90e21970c6fc0c066c8b8b470b9076 100644 (file)
@@ -10,15 +10,17 @@ var makeSchedule = function (runnerInfo) {
   return { start: start, duration: duration, end: end, runner: runnerInfo.runner }
 }
 
+const defaultSource = function () {
+  let w = globals.window
+  return (w.performance || w.Date).now()
+}
+
 export default class Timeline extends EventTarget {
   // Construct a new timeline on the given element
-  constructor () {
+  constructor (timeSource = defaultSource) {
     super()
 
-    this._timeSource = function () {
-      let w = globals.window
-      return (w.performance || w.Date).now()
-    }
+    this._timeSource = timeSource
 
     // Store the timing variables
     this._startTime = 0