@checksub_team/peaks_timeline 2.0.0-alpha.9 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,18 +63,18 @@ define([
63
63
  Axis.prototype._onPlayheadMoved = function(playheadX, playheadWidth) {
64
64
  this._maskStart = playheadX + this._view.getFrameOffset();
65
65
  this._maskEnd = playheadX + this._view.getFrameOffset() + playheadWidth;
66
- this._frontLayer.draw();
66
+ this._frontLayer.batchDraw();
67
67
  };
68
68
 
69
69
  Axis.prototype._onPlayheadHidden = function() {
70
70
  this._maskStart = null;
71
71
  this._maskEnd = null;
72
- this._frontLayer.draw();
72
+ this._frontLayer.batchDraw();
73
73
  };
74
74
 
75
- Axis.prototype.draw = function() {
76
- this._backLayer.draw();
77
- this._frontLayer.draw();
75
+ Axis.prototype.batchDraw = function() {
76
+ this._backLayer.batchDraw();
77
+ this._frontLayer.batchDraw();
78
78
  };
79
79
 
80
80
  Axis.prototype.addBackToStage = function(stage) {
@@ -7,8 +7,9 @@
7
7
  */
8
8
 
9
9
  define([
10
- './data'
11
- ], function(Data) {
10
+ './data',
11
+ '../utils'
12
+ ], function(Data, Utils) {
12
13
  'use strict';
13
14
 
14
15
  /**
@@ -84,13 +85,11 @@ define([
84
85
 
85
86
  return response.blob();
86
87
  })
87
- .catch(function(err) {
88
- return later(delay)
89
- .then(function() {
90
- return recur(timesTried + 1, err);
91
- });
92
- })
93
88
  .then(function(blob) {
89
+ if (Utils.isNullOrUndefined(blob)) {
90
+ throw new Error('Failed to retrieve blob');
91
+ }
92
+
94
93
  var type = blob.type;
95
94
 
96
95
  if (type) {
@@ -108,6 +107,12 @@ define([
108
107
  self._peaks.emit('data.retrieved', data, src, url);
109
108
  });
110
109
  }
110
+ })
111
+ .catch(function(err) {
112
+ return later(delay)
113
+ .then(function() {
114
+ return recur(timesTried + 1, err);
115
+ });
111
116
  });
112
117
  }
113
118
 
@@ -86,12 +86,12 @@ define([
86
86
  if (self._options.draggable) {
87
87
  group.on('dragstart', function() {
88
88
  self._label.show();
89
- self._options.group.draw();
89
+ self._batchDraw();
90
90
  });
91
91
 
92
92
  group.on('dragend', function() {
93
93
  self._label.hide();
94
- self._options.group.draw();
94
+ self._batchDraw();
95
95
  });
96
96
  }
97
97
 
@@ -100,13 +100,13 @@ define([
100
100
  self._options.view.setCursor('ew-resize');
101
101
  self._label.show();
102
102
  self._group.moveToTop();
103
- self._options.view.drawSourcesLayer();
103
+ self._options.view.batchDrawSourcesLayer();
104
104
  });
105
105
 
106
106
  self._handle.on('mouseout touchend', function() {
107
107
  self._options.view.setCursor('default');
108
108
  self._label.hide();
109
- self._options.view.drawSourcesLayer();
109
+ self._options.view.batchDrawSourcesLayer();
110
110
  });
111
111
  }
112
112
  };
@@ -128,5 +128,14 @@ define([
128
128
  this._label.setText(Utils.formatTime(time, false));
129
129
  };
130
130
 
131
+ DefaultSegmentMarker.prototype._batchDraw = function() {
132
+ const group = this._options.group;
133
+ const layer = group && group.getLayer && group.getLayer();
134
+
135
+ if (layer && typeof layer.batchDraw === 'function') {
136
+ layer.batchDraw();
137
+ }
138
+ };
139
+
131
140
  return DefaultSegmentMarker;
132
141
  });
@@ -61,6 +61,8 @@ define([
61
61
  this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
62
62
 
63
63
  this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
64
+
65
+ this._peaks.on('lineIndicator.drag', this._onIndicatorDrag.bind(this));
64
66
  }
65
67
 
66
68
  LineGroups.prototype.fitToView = function() {
@@ -298,13 +300,25 @@ define([
298
300
  this._automaticLineCreationTimeout = setTimeout(function() {
299
301
  this._automaticLineCreationTimeout = null;
300
302
 
301
- var currentLine = this._lineGroupsByPosition[initialPosition];
303
+ const currentLine = this._lineGroupsByPosition[initialPosition];
302
304
 
303
305
  sources = sources.filter(function(source) {
304
306
  return currentLine.hasSource(source.id);
305
307
  });
306
308
 
307
- if (sources.length === 0 || sources.length === currentLine.countRemainingElements()) {
309
+ if (sources.length === 0) {
310
+ this.stopAutomaticLineCreation();
311
+ return;
312
+ }
313
+
314
+ const posAround = this.getLinesAroundPos(currentLine.getPosition());
315
+ const targetPosIsJustBefore = newLinePosition <= currentLine.getPosition() && newLinePosition > posAround[0];
316
+ const targetPosIsJustAfter = newLinePosition >= currentLine.getPosition() && newLinePosition <= posAround[1];
317
+
318
+ if (
319
+ sources.length === currentLine.countRemainingElements() &&
320
+ (targetPosIsJustBefore || targetPosIsJustAfter)
321
+ ) {
308
322
  this.stopAutomaticLineCreation();
309
323
  return;
310
324
  }
@@ -409,6 +423,26 @@ define([
409
423
  return pos;
410
424
  };
411
425
 
426
+ LineGroups.prototype.getLinesAroundPos = function(pos) {
427
+ var returnPos = [-1, this.getLastPosition() + 1];
428
+
429
+ for (var position in this._lineGroupsByPosition) {
430
+ if (Utils.objectHasProperty(this._lineGroupsByPosition, position)) {
431
+ var p = parseInt(position, 10);
432
+
433
+ if (p < pos) {
434
+ returnPos[0] = p;
435
+ }
436
+ else if (p > pos) {
437
+ returnPos[1] = p;
438
+ break;
439
+ }
440
+ }
441
+ }
442
+
443
+ return returnPos;
444
+ };
445
+
412
446
  LineGroups.prototype._moveSourcesToPositionIfPossible = function(sources, targetPosition, targetTime,
413
447
  sourcesDuration
414
448
  ) {
@@ -531,6 +565,40 @@ define([
531
565
  return line.id;
532
566
  };
533
567
 
568
+ LineGroups.prototype._onIndicatorDrag = function(lineId, y) {
569
+ const lineGroup = this._lineGroupsById[lineId];
570
+
571
+ if (!lineGroup) {
572
+ return;
573
+ }
574
+
575
+ const positions = this.getLinesUnderY(y);
576
+
577
+ if (positions[0] !== positions[1] || positions[0] === lineGroup.getPosition()) {
578
+ return;
579
+ }
580
+
581
+ const targetPos = positions[0];
582
+ const targetLineGroup = this._lineGroupsByPosition[targetPos];
583
+ const targetCenterY = targetLineGroup.y() + (targetLineGroup.lineHeight() / 2);
584
+ const movingDown = targetPos > lineGroup.getPosition();
585
+
586
+ if ((movingDown && y < targetCenterY) || (!movingDown && y > targetCenterY)) {
587
+ return;
588
+ }
589
+
590
+ if (targetPos === lineGroup.getPosition() + 1) {
591
+ this._setLinePosition(targetLineGroup.getId(), lineGroup.getPosition());
592
+ }
593
+ else {
594
+ this._setLinePosition(lineId, targetPos);
595
+ }
596
+
597
+ this.refreshLineYs();
598
+
599
+ this._peaks.emit('line.moved', lineGroup.getLine());
600
+ };
601
+
534
602
  LineGroups.prototype.updateSegments = function(frameStartTime, frameEndTime) {
535
603
  for (var lineId in this._segmentsGroups) {
536
604
  if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
@@ -68,7 +68,14 @@ define([
68
68
 
69
69
  this._layer.add(this._separatingLine);
70
70
 
71
- this._layer.draw();
71
+ this._layer.batchDraw();
72
+
73
+ this._isDragging = false;
74
+ this._dragLineId = null;
75
+ this._dragContainerRect = null;
76
+
77
+ this._onWindowMove = this._onWindowMove.bind(this);
78
+ this._onWindowUp = this._onWindowUp.bind(this);
72
79
  }
73
80
 
74
81
  LineIndicator.prototype.fitToView = function() {
@@ -165,7 +172,7 @@ define([
165
172
  indicator.getChildren().forEach(function(child) {
166
173
  child.fill(child.getAttr('selectedColor'));
167
174
  });
168
- self.draw();
175
+ self.batchDraw();
169
176
  self._stage.container().style.cursor = 'pointer';
170
177
  });
171
178
 
@@ -173,14 +180,27 @@ define([
173
180
  indicator.getChildren().forEach(function(child) {
174
181
  child.fill(child.getAttr('defaultColor'));
175
182
  });
176
- self.draw();
177
- self._stage.container().style.cursor = 'default';
183
+ self.batchDraw();
184
+ if (!self._isDragging) {
185
+ self._stage.container().style.cursor = 'default';
186
+ }
178
187
  });
179
188
 
180
189
  indicator.on('click', function(e) {
181
190
  self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
182
191
  });
183
192
 
193
+ indicator.on('mousedown touchstart', function() {
194
+ self._dragLineId = lineGroup.getId();
195
+ self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
196
+
197
+ window.addEventListener('mousemove', self._onWindowMove, false);
198
+ window.addEventListener('touchmove', self._onWindowMove, false);
199
+ window.addEventListener('mouseup', self._onWindowUp, false);
200
+ window.addEventListener('touchend', self._onWindowUp, false);
201
+ window.addEventListener('blur', self._onWindowUp, false);
202
+ });
203
+
184
204
  return indicator;
185
205
  };
186
206
 
@@ -199,7 +219,8 @@ define([
199
219
  this._indicators[line.id] = {
200
220
  lineGroup: lineGroup,
201
221
  indicator: indicator,
202
- type: line.indicatorType
222
+ type: line.indicatorType,
223
+ text: line.indicatorText
203
224
  };
204
225
  }
205
226
  };
@@ -230,7 +251,7 @@ define([
230
251
  indicatorData.type = line.indicatorType;
231
252
  indicatorData.text = line.indicatorText;
232
253
 
233
- this.draw();
254
+ this.batchDraw();
234
255
  };
235
256
 
236
257
  LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
@@ -300,13 +321,50 @@ define([
300
321
  }
301
322
 
302
323
  if (anyChange) {
303
- this.draw();
324
+ this.batchDraw();
304
325
  }
305
326
  return anyChange;
306
327
  };
307
328
 
308
- LineIndicator.prototype.draw = function() {
309
- this._layer.draw();
329
+ LineIndicator.prototype.batchDraw = function() {
330
+ this._layer.batchDraw();
331
+ };
332
+
333
+ LineIndicator.prototype._onWindowMove = function(event) {
334
+ if (!this._dragContainerRect) {
335
+ return;
336
+ }
337
+
338
+ if (!this._isDragging) {
339
+ this._stage.container().style.cursor = 'grabbing';
340
+ }
341
+
342
+ var clientY;
343
+
344
+ if (event.type === 'touchmove') {
345
+ clientY = Math.floor(event.changedTouches[0].clientY);
346
+ }
347
+ else {
348
+ clientY = event.clientY;
349
+ }
350
+
351
+ const relY = clientY - this._dragContainerRect.top;
352
+
353
+ this._peaks.emit('lineIndicator.drag', this._dragLineId, relY);
354
+ };
355
+
356
+ LineIndicator.prototype._onWindowUp = function() {
357
+ window.removeEventListener('mousemove', this._onWindowMove, false);
358
+ window.removeEventListener('touchmove', this._onWindowMove, false);
359
+ window.removeEventListener('mouseup', this._onWindowUp, false);
360
+ window.removeEventListener('touchend', this._onWindowUp, false);
361
+ window.removeEventListener('blur', this._onWindowUp, false);
362
+
363
+ this._isDragging = false;
364
+ this._dragLineId = null;
365
+ this._dragContainerRect = null;
366
+
367
+ this._stage.container().style.cursor = 'pointer';
310
368
  };
311
369
 
312
370
  return LineIndicator;
@@ -229,7 +229,7 @@ define([
229
229
  }
230
230
  else {
231
231
  this.deselectDifference([], true);
232
- this._view.drawSourcesLayer(); // Redraw sources layer to remove selection
232
+ this._view.batchDrawSourcesLayer(); // Redraw sources layer to remove selection
233
233
  }
234
234
  };
235
235
 
@@ -258,7 +258,7 @@ define([
258
258
  ModeLayer.prototype._onMouseEnterInCutMode = function() {
259
259
  this._cutGroup.visible(true);
260
260
 
261
- this._layer.draw();
261
+ this._layer.batchDraw();
262
262
  };
263
263
 
264
264
  ModeLayer.prototype._updateCursorTime = function(position) {
@@ -359,13 +359,13 @@ define([
359
359
  this._updateCursorTime(cuttingPosition);
360
360
  this._updateCuttingLine(cuttingPosition);
361
361
 
362
- this._layer.draw();
362
+ this._layer.batchDraw();
363
363
  };
364
364
 
365
365
  ModeLayer.prototype._onMouseLeaveInCutMode = function() {
366
366
  this._cutGroup.visible(false);
367
367
 
368
- this._layer.draw();
368
+ this._layer.batchDraw();
369
369
  };
370
370
 
371
371
  ModeLayer.prototype._onMouseClickInCutMode = function() {
@@ -417,7 +417,7 @@ define([
417
417
  this._updateCursorTime(cuttingPosition);
418
418
  this._updateCuttingLine(cuttingPosition);
419
419
 
420
- this._layer.draw();
420
+ this._layer.batchDraw();
421
421
  }
422
422
  }
423
423
  };
@@ -494,8 +494,8 @@ define([
494
494
  }
495
495
 
496
496
  this._mode = mode;
497
- this._layer.draw();
498
- this._view.drawSourcesLayer();
497
+ this._layer.batchDraw();
498
+ this._view.batchDrawSourcesLayer();
499
499
  };
500
500
 
501
501
  ModeLayer.prototype.getCurrentMode = function() {
@@ -269,7 +269,7 @@ define([
269
269
  }
270
270
 
271
271
  this._time = time;
272
- this._playheadLayer.draw();
272
+ this._playheadLayer.batchDraw();
273
273
  };
274
274
 
275
275
  /**
@@ -307,7 +307,7 @@ define([
307
307
  }
308
308
 
309
309
  if (updated) {
310
- this._playheadLayer.draw();
310
+ this._playheadLayer.batchDraw();
311
311
  }
312
312
  };
313
313
 
@@ -380,7 +380,7 @@ define([
380
380
  0.65, this._segment.warningColor
381
381
  ]);
382
382
 
383
- this._view.drawSourcesLayer();
383
+ this._view.batchDrawSourcesLayer();
384
384
 
385
385
  this._peaks.emit('segments.mouseenter', this._segment);
386
386
  };
@@ -400,7 +400,7 @@ define([
400
400
  0.65, this._segment.warningColor
401
401
  ]);
402
402
 
403
- this._view.drawSourcesLayer();
403
+ this._view.batchDrawSourcesLayer();
404
404
 
405
405
  this._peaks.emit('segments.mouseleave', this._segment);
406
406
  };
@@ -377,7 +377,7 @@ define([
377
377
  };
378
378
 
379
379
  SegmentsGroup.prototype._draw = function() {
380
- this._view.drawSourcesLayer();
380
+ this._view.batchDrawSourcesLayer();
381
381
  };
382
382
 
383
383
  /**