@checksub_team/peaks_timeline 1.16.0-alpha.1 → 1.16.0

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.
@@ -56,6 +56,7 @@ define([
56
56
  this._peaks.on('sources.setSelected', this._onSourcesSetSelected.bind(this));
57
57
  this._peaks.on('source.update', this._onSourceUpdate.bind(this));
58
58
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
59
+ this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
59
60
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
60
61
  this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
61
62
  this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
@@ -119,18 +120,14 @@ define([
119
120
  }
120
121
 
121
122
  if (positions) {
122
- this.refresh();
123
- }
124
- };
123
+ var frameOffset = this._view.getFrameOffset();
124
+ var width = this._view.getWidth();
125
125
 
126
- SourcesLayer.prototype.refresh = function() {
127
- var frameOffset = this._view.getFrameOffset();
128
- var width = this._view.getWidth();
129
-
130
- this.updateSources(
131
- this._view.pixelsToTime(frameOffset),
132
- this._view.pixelsToTime(frameOffset + width)
133
- );
126
+ this.updateSources(
127
+ this._view.pixelsToTime(frameOffset),
128
+ this._view.pixelsToTime(frameOffset + width)
129
+ );
130
+ }
134
131
  };
135
132
 
136
133
  SourcesLayer.prototype._onSourceUpdate = function(source) {
@@ -168,6 +165,16 @@ define([
168
165
  this.draw();
169
166
  };
170
167
 
168
+ SourcesLayer.prototype._onSourcesShow = function(sources) {
169
+ var self = this;
170
+
171
+ sources.forEach(function(source) {
172
+ self._sourcesGroup[source.id].setWrapping(false, true);
173
+ });
174
+
175
+ this._layer.draw();
176
+ };
177
+
171
178
  SourcesLayer.prototype._onSourcesAdd = function(sources) {
172
179
  var self = this;
173
180
 
@@ -245,6 +252,10 @@ define([
245
252
  }
246
253
  };
247
254
 
255
+ SourcesLayer.prototype._onSourcesRefresh = function() {
256
+ this._layer.draw();
257
+ };
258
+
248
259
  SourcesLayer.prototype._onSegmentsShow = function(lineId, position) {
249
260
  this._lines.addSegments(lineId, position);
250
261
  this._view.updateTimelineLength();
@@ -275,7 +286,7 @@ define([
275
286
  var sourceGroup = this._createSourceGroup(source);
276
287
 
277
288
  this._sourcesGroup[source.id] = sourceGroup;
278
- this._lines.addSourceGroup(source, sourceGroup, source.position);
289
+ this._lines.addSourceGroup(sourceGroup, source.position);
279
290
 
280
291
  // After creating and referencing the new group, we can start data retrieval
281
292
  if (startDataRetrieval) {
@@ -310,7 +321,7 @@ define([
310
321
  // Update sources in visible time range.
311
322
  var sources = this.findSources(startTime, endTime);
312
323
 
313
- // TODO: Should implement virtualization on Y
324
+ // Should implement virtualization on Y
314
325
 
315
326
  var count = sources.length;
316
327
 
@@ -327,33 +338,28 @@ define([
327
338
  SourcesLayer.prototype.onSourcesGroupDragStart = function(element) {
328
339
  this._initialTimeOffset = this._view.getTimeOffset();
329
340
  this._mouseDownX = this._view.getPointerPosition().x;
341
+ this._activeElements = {};
330
342
 
331
343
  const draggedElementId = element.currentTarget.attrs.sourceId;
332
-
333
- var selectedElements = this._view.getSelectedElements();
334
- const shouldDragSelectedElements = Object.keys(selectedElements).includes(
344
+ const shouldDragSelectedElements = Object.keys(this._view.getSelectedElements()).includes(
335
345
  draggedElementId
336
346
  );
337
347
 
338
- this._draggedElements = shouldDragSelectedElements ?
339
- Object.values(selectedElements).sort((a, b) => a.startTime - b.startTime) :
348
+ this._nonSelectedElement = shouldDragSelectedElements ?
349
+ null :
340
350
  [this._sourcesGroup[draggedElementId].getSource()];
341
351
 
342
- this._draggedElementsData = this._draggedElements.reduce(function(bounds, source) {
343
- bounds.initialStartTime = Math.min(source.startTime, bounds.initialStartTime);
344
- bounds.initialEndTime = Math.max(source.endTime, bounds.initialEndTime);
345
- bounds.orderable = source.orderable && bounds.orderable;
346
-
347
- return bounds;
348
- }, {
349
- initialStartTime: Infinity,
350
- initialEndTime: -Infinity,
351
- orderable: true
352
- });
352
+ this._isDraggable = true;
353
+ (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function(source) {
354
+ if (!source.draggable) {
355
+ this._isDraggable = false;
356
+ return;
357
+ }
358
+ }.bind(this));
353
359
  };
354
360
 
355
361
  SourcesLayer.prototype.onSourcesGroupDragEnd = function() {
356
- const updatedSources = this._draggedElements.map(
362
+ const updatedSources = (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).map(
357
363
  function(source) {
358
364
  const sourceGroup = this._sourcesGroup[source.id];
359
365
 
@@ -368,6 +374,8 @@ define([
368
374
  this._view.drawSourcesLayer();
369
375
  this._view.updateTimelineLength();
370
376
 
377
+ this._activeElements = {};
378
+
371
379
  this._peaks.emit('sources.updated', updatedSources);
372
380
  };
373
381
 
@@ -391,22 +399,39 @@ define([
391
399
 
392
400
  const diff = this._view.pixelsToTime(mousePos - this._mouseDownX);
393
401
  const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
394
- const mousePosX = this._view.getPointerPosition().x;
395
402
  const mousePosY = this._view.getPointerPosition().y;
396
- const { initialStartTime, initialEndTime, orderable } = this._draggedElementsData;
397
-
398
- const shouldRedraw = this.manageSourceMovements(
399
- this._draggedElements,
400
- initialStartTime + timeOffsetDiff + diff,
401
- initialEndTime + timeOffsetDiff + diff,
402
- orderable,
403
- mousePosX,
404
- mousePosY
405
- );
403
+ var newEnd = 0;
404
+ var shouldRedraw = false;
405
+
406
+ (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function(source) {
407
+ if (!this._activeElements[source.id]) {
408
+ this._activeElements[source.id] = {
409
+ initialStartTime: source.startTime,
410
+ initialEndTime: source.endTime
411
+ };
412
+ }
413
+
414
+ const { initialStartTime, initialEndTime } = this._activeElements[source.id];
415
+
416
+ newEnd = Math.max(newEnd, source.endTime);
417
+
418
+ if (this._isDraggable) {
419
+ shouldRedraw = this.updateSource(
420
+ source,
421
+ initialStartTime + diff + timeOffsetDiff,
422
+ initialEndTime + diff + timeOffsetDiff,
423
+ mousePosY
424
+ ) || shouldRedraw;
425
+ }
426
+ }.bind(this));
406
427
 
407
428
  if (shouldRedraw) {
408
429
  this.draw();
409
430
  }
431
+
432
+ this._view.setTimelineLength(
433
+ this._view.timeToPixels(newEnd) + this._view.getWidth()
434
+ );
410
435
  };
411
436
 
412
437
  SourcesLayer.prototype.findSources = function(startTime, endTime) {
@@ -420,65 +445,44 @@ define([
420
445
  );
421
446
  };
422
447
 
423
- SourcesLayer.prototype._applyTimeChangesToSources = function(sources, initialStartTime, newStartTime,
424
- newEndTime
425
- ) {
426
- if (sources.length === 1) {
427
- sources[0].updateTimes(
428
- newStartTime,
429
- newEndTime
430
- );
431
- }
432
- else {
433
- // We cannot have more than 1 source being resized at a time
434
- // Reaching this point implies that that we are only dragging, not resizing
435
- // So, we can safely assume that the difference between the initial times and the new times is the same
436
- const timeDiff = Utils.roundTime(newStartTime - initialStartTime);
437
-
438
- if (timeDiff !== 0) {
439
- sources.forEach(function(source) {
440
- source.updateTimes(
441
- Utils.roundTime(source.startTime + timeDiff),
442
- Utils.roundTime(source.endTime + timeDiff)
443
- );
444
- });
445
- }
446
- }
447
-
448
- this.refresh();
449
- };
450
-
451
- SourcesLayer.prototype.manageSourceMovements = function(sources, newStartTime, newEndTime, orderable, mouseX,
452
- mouseY
453
- ) {
454
- if (this._peaks.options.canMoveSourcesBetweenLines && typeof mouseY === 'number') {
455
- this.manageVerticalPosition(sources, newStartTime, newEndTime, mouseX, mouseY);
456
- }
448
+ SourcesLayer.prototype.updateSource = function(source, startTime, endTime, newY) {
449
+ var newTimes = {
450
+ start: startTime,
451
+ end: endTime
452
+ };
457
453
 
458
- if (orderable) {
459
- ({ newStartTime, newEndTime } = this.manageOrder(sources, newStartTime, newEndTime));
454
+ if (this._peaks.options.canMoveSourcesBetweenLines) {
455
+ this.manageVerticalPosition(source, newY);
460
456
  }
461
- ({ newStartTime, newEndTime } = this.manageCollision(sources, newStartTime, newEndTime));
462
457
 
463
- this._applyTimeChangesToSources(sources, sources[0].startTime, newStartTime, newEndTime);
458
+ newTimes = this.manageSourceOrder(source, newTimes);
459
+ newTimes = this.manageCollision(source, newTimes);
464
460
 
465
- this._view.setTimelineLength(
466
- this._view.timeToPixels(newEndTime) + this._view.getWidth()
461
+ source.updateTimes(
462
+ newTimes.start,
463
+ newTimes.end
467
464
  );
468
465
 
469
- return true;
466
+ if (newTimes) {
467
+ this._updateSource(
468
+ source
469
+ );
470
+
471
+ return true;
472
+ }
473
+ return false;
470
474
  };
471
475
 
472
- SourcesLayer.prototype.manageVerticalPosition = function(sources, startTime, endTime, mouseX, mouseY) {
473
- return this._lines.manageVerticalPosition(sources, startTime, endTime, mouseX, mouseY);
476
+ SourcesLayer.prototype.manageVerticalPosition = function(source, newY) {
477
+ return this._lines.manageVerticalPosition(source, newY);
474
478
  };
475
479
 
476
- SourcesLayer.prototype.manageOrder = function(sources, startTime, endTime) {
477
- return this._lines.manageOrder(sources, startTime, endTime);
480
+ SourcesLayer.prototype.manageSourceOrder = function(source, newTimes) {
481
+ return this._lines.manageSourceOrder(source, newTimes);
478
482
  };
479
483
 
480
- SourcesLayer.prototype.manageCollision = function(sources, newStartTime, newEndTime) {
481
- return this._lines.manageCollision(sources, newStartTime, newEndTime);
484
+ SourcesLayer.prototype.manageCollision = function(source, newTimes) {
485
+ return this._lines.manageCollision(source, newTimes);
482
486
  };
483
487
 
484
488
  /**
@@ -691,6 +695,7 @@ define([
691
695
  this._peaks.off('sources.hide', this._onSourcesHide);
692
696
  this._peaks.off('source.update', this._onSourceUpdate);
693
697
  this._peaks.off('data.retrieved', this._onDataRetrieved);
698
+ this._peaks.off('sources.refresh', this._onSourcesRefresh);
694
699
  this._peaks.off('segments.show', this._onSegmentsShow);
695
700
  this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
696
701
  this._peaks.off('source.setIndicators', this.setIndicators);
@@ -80,8 +80,10 @@ define([
80
80
  mediaEndTime: originalMediaEndTime,
81
81
  color: sourceToCut.color,
82
82
  backgroundColor: sourceToCut.backgroundColor,
83
+ hoverBackgroundColor: sourceToCut.hoverBackgroundColor,
84
+ selectedBackgroundColor: sourceToCut.selectedBackgroundColor,
83
85
  borderColor: sourceToCut.borderColor,
84
- selectedColor: sourceToCut.selectedColor,
86
+ selectedBorderColor: sourceToCut.selectedBorderColor,
85
87
  warningColor: sourceToCut.warningColor,
86
88
  warningWidth: sourceToCut.warningWidth,
87
89
  volumeSliderColor: sourceToCut.volumeSliderColor,
@@ -191,8 +193,10 @@ define([
191
193
  options.mediaEndTime,
192
194
  options.color,
193
195
  options.backgroundColor,
196
+ options.hoverBackgroundColor,
197
+ options.selectedBackgroundColor,
194
198
  options.borderColor,
195
- options.selectedColor,
199
+ options.selectedBorderColor,
196
200
  options.warningColor,
197
201
  options.warningWidth,
198
202
  options.volumeSliderColor,
@@ -482,10 +486,9 @@ define([
482
486
  */
483
487
 
484
488
  TimelineSources.prototype.showById = function(sourceId) {
485
- if (this._sourcesById[sourceId].wrapped === false) {
486
- return;
487
- }
488
-
489
+ // var indexes = this._findSource(function(source) {
490
+ // return source.id === sourceId;
491
+ // })
489
492
  this._sourcesById[sourceId].wrapped = false;
490
493
 
491
494
  this._peaks.emit('sources.show', [this._sourcesById[sourceId]]);
@@ -499,10 +502,9 @@ define([
499
502
  */
500
503
 
501
504
  TimelineSources.prototype.hideById = function(sourceId) {
502
- if (this._sourcesById[sourceId].wrapped === true) {
503
- return;
504
- }
505
-
505
+ // var indexes = this._findSource(function(source) {
506
+ // return source.id === sourceId;
507
+ // })
506
508
  this._sourcesById[sourceId].wrapped = true;
507
509
 
508
510
  this._peaks.emit('sources.hide', [this._sourcesById[sourceId]]);
@@ -430,10 +430,6 @@ define([
430
430
  this._sourcesLayer.draw();
431
431
  };
432
432
 
433
- TimelineZoomView.prototype.refresh = function() {
434
- this._sourcesLayer.refresh();
435
- };
436
-
437
433
  TimelineZoomView.prototype.getSegmentsGroup = function() {
438
434
  return this._sourcesLayer.getSegmentsGroup();
439
435
  };