@checksub_team/peaks_timeline 1.16.0-alpha.2 → 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.
package/src/source.js CHANGED
@@ -121,16 +121,34 @@ define([
121
121
  );
122
122
  }
123
123
 
124
+ if (Utils.isNullOrUndefined(options.selectedBackgroundColor)) {
125
+ options.selectedBackgroundColor = options.backgroundColor;
126
+ }
127
+ else if (!Utils.isValidColor(options.selectedBackgroundColor)) {
128
+ throw new TypeError(
129
+ 'peaks.sources.' + context + ': selectedBackgroundColor should be a valid CSS color'
130
+ );
131
+ }
132
+
133
+ if (Utils.isNullOrUndefined(options.hoverBackgroundColor)) {
134
+ options.hoverBackgroundColor = Utils.shadeColor(options.backgroundColor, 30);
135
+ }
136
+ else if (!Utils.isValidColor(options.hoverBackgroundColor)) {
137
+ throw new TypeError(
138
+ 'peaks.sources.' + context + ': hoverBackgroundColor should be a valid CSS color'
139
+ );
140
+ }
141
+
124
142
  if (!Utils.isValidColor(options.borderColor)) {
125
143
  options.borderColor = options.color;
126
144
  }
127
145
 
128
- if (Utils.isNullOrUndefined(options.selectedColor)) {
129
- options.selectedColor = null;
146
+ if (Utils.isNullOrUndefined(options.selectedBorderColor)) {
147
+ options.selectedBorderColor = Utils.shadeColor(options.borderColor, 30);
130
148
  }
131
- else if (!Utils.isValidColor(options.selectedColor)) {
149
+ else if (!Utils.isValidColor(options.selectedBorderColor)) {
132
150
  throw new TypeError(
133
- 'peaks.sources.' + context + ': selectedColor should be a valid CSS color'
151
+ 'peaks.sources.' + context + ': selectedBorderColor should be a valid CSS color'
134
152
  );
135
153
  }
136
154
 
@@ -377,7 +395,7 @@ define([
377
395
  * @param {String} color Primary color of the source representation.
378
396
  * @param {String} backgroundColor Background color of the source.
379
397
  * @param {String} borderColor Border color of the source.
380
- * @param {String} selectedColor Color when the source is selected.
398
+ * @param {String} selectedBorderColor Color when the source is selected.
381
399
  * @param {String} warningColor Color used for warning states.
382
400
  * @param {String} volumeSliderColor Color of the volume slider.
383
401
  * @param {Number} volumeSliderWidth Width of the volume slider.
@@ -412,11 +430,11 @@ define([
412
430
 
413
431
  function Source(peaks, id, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind,
414
432
  subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
415
- borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth,
416
- volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition,
417
- textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable,
418
- cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor,
419
- markerWidth, volume, volumeRange, loading, ...customParams) {
433
+ hoverBackgroundColor, selectedBackgroundColor, borderColor, selectedBorderColor, warningColor, warningWidth,
434
+ volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor,
435
+ textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable,
436
+ orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers,
437
+ buttons, markerColor, markerWidth, volume, volumeRange, loading, ...customParams) {
420
438
  var opts = {
421
439
  title: title,
422
440
  titleAlignments: titleAlignments,
@@ -432,8 +450,10 @@ define([
432
450
  mediaEndTime: mediaEndTime,
433
451
  color: color,
434
452
  backgroundColor: backgroundColor,
453
+ hoverBackgroundColor: hoverBackgroundColor,
454
+ selectedBackgroundColor: selectedBackgroundColor,
435
455
  borderColor: borderColor,
436
- selectedColor: selectedColor,
456
+ selectedBorderColor: selectedBorderColor,
437
457
  warningColor: warningColor,
438
458
  warningWidth: warningWidth,
439
459
  textFont: textFont,
@@ -487,8 +507,10 @@ define([
487
507
  this._mediaEndTime = opts.mediaEndTime;
488
508
  this._color = opts.color;
489
509
  this._backgroundColor = opts.backgroundColor;
510
+ this._hoverBackgroundColor = opts.hoverBackgroundColor;
511
+ this._selectedBackgroundColor = opts.selectedBackgroundColor;
490
512
  this._borderColor = opts.borderColor;
491
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
513
+ this._selectedBorderColor = opts.selectedBorderColor;
492
514
  this._warningColor = opts.warningColor;
493
515
  this._warningWidth = opts.warningWidth;
494
516
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -664,6 +686,26 @@ define([
664
686
  this._backgroundColor = backgroundColor;
665
687
  }
666
688
  },
689
+ hoverBackgroundColor: {
690
+ enumerable: true,
691
+ get: function() {
692
+ return this._hoverBackgroundColor;
693
+ },
694
+
695
+ set: function(hoverBackgroundColor) {
696
+ this._hoverBackgroundColor = hoverBackgroundColor;
697
+ }
698
+ },
699
+ selectedBackgroundColor: {
700
+ enumerable: true,
701
+ get: function() {
702
+ return this._selectedBackgroundColor;
703
+ },
704
+
705
+ set: function(selectedBackgroundColor) {
706
+ this._selectedBackgroundColor = selectedBackgroundColor;
707
+ }
708
+ },
667
709
  borderColor: {
668
710
  enumerable: true,
669
711
  get: function() {
@@ -674,14 +716,14 @@ define([
674
716
  this._borderColor = borderColor;
675
717
  }
676
718
  },
677
- selectedColor: {
719
+ selectedBorderColor: {
678
720
  enumerable: true,
679
721
  get: function() {
680
- return this._selectedColor;
722
+ return this._selectedBorderColor;
681
723
  },
682
724
 
683
- set: function(selectedColor) {
684
- this._selectedColor = selectedColor;
725
+ set: function(selectedBorderColor) {
726
+ this._selectedBorderColor = selectedBorderColor;
685
727
  }
686
728
  },
687
729
  warningColor: {
@@ -1089,8 +1131,10 @@ define([
1089
1131
  mediaEndTime: this.mediaEndTime,
1090
1132
  color: this.color,
1091
1133
  backgroundColor: this.backgroundColor,
1134
+ hoverBackgroundColor: this.hoverBackgroundColor,
1135
+ selectedBackgroundColor: this.selectedBackgroundColor,
1092
1136
  borderColor: this.borderColor,
1093
- selectedColor: this.selectedColor,
1137
+ selectedBorderColor: this.selectedBorderColor,
1094
1138
  warningColor: this.warningColor,
1095
1139
  warningWidth: this.warningWidth,
1096
1140
  volumeSliderColor: this.volumeSliderColor,
@@ -1142,8 +1186,10 @@ define([
1142
1186
  this._mediaEndTime = opts.mediaEndTime;
1143
1187
  this._color = opts.color;
1144
1188
  this._backgroundColor = opts.backgroundColor;
1189
+ this._hoverBackgroundColor = opts.hoverBackgroundColor;
1190
+ this._selectedBackgroundColor = opts.selectedBackgroundColor;
1145
1191
  this._borderColor = opts.borderColor;
1146
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
1192
+ this._selectedBorderColor = opts.selectedBorderColor;
1147
1193
  this._warningColor = opts.warningColor;
1148
1194
  this._warningWidth = opts.warningWidth;
1149
1195
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -56,7 +56,9 @@ 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));
61
+ this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
60
62
  this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
61
63
  }
62
64
 
@@ -98,14 +100,34 @@ define([
98
100
  return this._allowEditing;
99
101
  };
100
102
 
101
- SourcesLayer.prototype.refresh = function() {
102
- var frameOffset = this._view.getFrameOffset();
103
- var width = this._view.getWidth();
103
+ SourcesLayer.prototype._onOptionsLineHeightChange = function(oldHeight) {
104
+ var positions = [];
104
105
 
105
- this.updateSources(
106
- this._view.pixelsToTime(frameOffset),
107
- this._view.pixelsToTime(frameOffset + width)
108
- );
106
+ for (var sourceId in this._sourcesGroup) {
107
+ if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
108
+ var source = this._sourcesGroup[sourceId].getSource();
109
+
110
+ if (!positions.includes(source.position)) {
111
+ this._lines.changeLineHeight(
112
+ oldHeight,
113
+ this._peaks.options.lineHeight
114
+ );
115
+ positions.push(source.position);
116
+ }
117
+ this._removeSource(source);
118
+ this._addSourceGroup(source);
119
+ }
120
+ }
121
+
122
+ if (positions) {
123
+ var frameOffset = this._view.getFrameOffset();
124
+ var width = this._view.getWidth();
125
+
126
+ this.updateSources(
127
+ this._view.pixelsToTime(frameOffset),
128
+ this._view.pixelsToTime(frameOffset + width)
129
+ );
130
+ }
109
131
  };
110
132
 
111
133
  SourcesLayer.prototype._onSourceUpdate = function(source) {
@@ -143,6 +165,16 @@ define([
143
165
  this.draw();
144
166
  };
145
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
+
146
178
  SourcesLayer.prototype._onSourcesAdd = function(sources) {
147
179
  var self = this;
148
180
 
@@ -220,6 +252,10 @@ define([
220
252
  }
221
253
  };
222
254
 
255
+ SourcesLayer.prototype._onSourcesRefresh = function() {
256
+ this._layer.draw();
257
+ };
258
+
223
259
  SourcesLayer.prototype._onSegmentsShow = function(lineId, position) {
224
260
  this._lines.addSegments(lineId, position);
225
261
  this._view.updateTimelineLength();
@@ -250,7 +286,7 @@ define([
250
286
  var sourceGroup = this._createSourceGroup(source);
251
287
 
252
288
  this._sourcesGroup[source.id] = sourceGroup;
253
- this._lines.addSourceGroup(source, sourceGroup, source.position);
289
+ this._lines.addSourceGroup(sourceGroup, source.position);
254
290
 
255
291
  // After creating and referencing the new group, we can start data retrieval
256
292
  if (startDataRetrieval) {
@@ -285,6 +321,8 @@ define([
285
321
  // Update sources in visible time range.
286
322
  var sources = this.findSources(startTime, endTime);
287
323
 
324
+ // Should implement virtualization on Y
325
+
288
326
  var count = sources.length;
289
327
 
290
328
  sources.forEach(this._updateSource.bind(this));
@@ -300,37 +338,28 @@ define([
300
338
  SourcesLayer.prototype.onSourcesGroupDragStart = function(element) {
301
339
  this._initialTimeOffset = this._view.getTimeOffset();
302
340
  this._mouseDownX = this._view.getPointerPosition().x;
341
+ this._activeElements = {};
303
342
 
304
343
  const draggedElementId = element.currentTarget.attrs.sourceId;
305
-
306
- var selectedElements = this._view.getSelectedElements();
307
- const shouldDragSelectedElements = Object.keys(selectedElements).includes(
344
+ const shouldDragSelectedElements = Object.keys(this._view.getSelectedElements()).includes(
308
345
  draggedElementId
309
346
  );
310
347
 
311
- if (shouldDragSelectedElements) {
312
- this._draggedElements = Object.values(selectedElements).sort((a, b) => a.startTime - b.startTime);
313
- }
314
- else {
315
- this._draggedElements = [this._sourcesGroup[draggedElementId].getSource()];
316
- this._view.deselectAll();
317
- }
318
-
319
- this._draggedElementsData = this._draggedElements.reduce(function(bounds, source) {
320
- bounds.initialStartTime = Math.min(source.startTime, bounds.initialStartTime);
321
- bounds.initialEndTime = Math.max(source.endTime, bounds.initialEndTime);
322
- bounds.orderable = source.orderable && bounds.orderable;
348
+ this._nonSelectedElement = shouldDragSelectedElements ?
349
+ null :
350
+ [this._sourcesGroup[draggedElementId].getSource()];
323
351
 
324
- return bounds;
325
- }, {
326
- initialStartTime: Infinity,
327
- initialEndTime: -Infinity,
328
- orderable: true
329
- });
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));
330
359
  };
331
360
 
332
361
  SourcesLayer.prototype.onSourcesGroupDragEnd = function() {
333
- const updatedSources = this._draggedElements.map(
362
+ const updatedSources = (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).map(
334
363
  function(source) {
335
364
  const sourceGroup = this._sourcesGroup[source.id];
336
365
 
@@ -345,6 +374,8 @@ define([
345
374
  this._view.drawSourcesLayer();
346
375
  this._view.updateTimelineLength();
347
376
 
377
+ this._activeElements = {};
378
+
348
379
  this._peaks.emit('sources.updated', updatedSources);
349
380
  };
350
381
 
@@ -366,24 +397,41 @@ define([
366
397
  )
367
398
  );
368
399
 
369
- const timeDiff = this._view.pixelsToTime(mousePos - this._mouseDownX);
400
+ const diff = this._view.pixelsToTime(mousePos - this._mouseDownX);
370
401
  const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
371
- const mousePosX = this._view.getPointerPosition().x;
372
402
  const mousePosY = this._view.getPointerPosition().y;
373
- const { initialStartTime, initialEndTime, orderable } = this._draggedElementsData;
374
-
375
- const shouldRedraw = this.manageSourceMovements(
376
- this._draggedElements,
377
- initialStartTime + timeOffsetDiff + timeDiff,
378
- initialEndTime + timeOffsetDiff + timeDiff,
379
- orderable,
380
- mousePosX,
381
- mousePosY
382
- );
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));
383
427
 
384
428
  if (shouldRedraw) {
385
429
  this.draw();
386
430
  }
431
+
432
+ this._view.setTimelineLength(
433
+ this._view.timeToPixels(newEnd) + this._view.getWidth()
434
+ );
387
435
  };
388
436
 
389
437
  SourcesLayer.prototype.findSources = function(startTime, endTime) {
@@ -397,68 +445,44 @@ define([
397
445
  );
398
446
  };
399
447
 
400
- SourcesLayer.prototype._applyTimeChangesToSources = function(sources, initialStartTime, newStartTime,
401
- newEndTime
402
- ) {
403
- if (sources.length === 1) {
404
- sources[0].updateTimes(
405
- newStartTime,
406
- newEndTime
407
- );
408
- }
409
- else {
410
- // We cannot have more than 1 source being resized at a time
411
- // Reaching this point implies that that we are only dragging, not resizing
412
- // So, we can safely assume that the difference between the initial times and the new times is the same
413
- const timeDiff = Utils.roundTime(newStartTime - initialStartTime);
414
-
415
- if (timeDiff !== 0) {
416
- sources.forEach(function(source) {
417
- source.updateTimes(
418
- Utils.roundTime(source.startTime + timeDiff),
419
- Utils.roundTime(source.endTime + timeDiff)
420
- );
421
- });
422
- }
423
- }
424
-
425
- this.refresh();
426
- };
427
-
428
- SourcesLayer.prototype.manageSourceMovements = function(sources, newStartTime, newEndTime, orderable, mouseX,
429
- mouseY
430
- ) {
431
- newStartTime = typeof newStartTime === 'number' ? Utils.roundTime(newStartTime) : newStartTime;
432
- newEndTime = typeof newEndTime === 'number' ? Utils.roundTime(newEndTime) : newEndTime;
433
-
434
- if (this._peaks.options.canMoveSourcesBetweenLines && typeof mouseY === 'number') {
435
- this.manageVerticalPosition(sources, newStartTime, newEndTime, mouseX, mouseY);
436
- }
448
+ SourcesLayer.prototype.updateSource = function(source, startTime, endTime, newY) {
449
+ var newTimes = {
450
+ start: startTime,
451
+ end: endTime
452
+ };
437
453
 
438
- if (orderable) {
439
- ({ newStartTime, newEndTime } = this.manageOrder(sources, newStartTime, newEndTime));
454
+ if (this._peaks.options.canMoveSourcesBetweenLines) {
455
+ this.manageVerticalPosition(source, newY);
440
456
  }
441
- ({ newStartTime, newEndTime } = this.manageCollision(sources, newStartTime, newEndTime));
442
457
 
443
- this._applyTimeChangesToSources(sources, sources[0].startTime, newStartTime, newEndTime);
458
+ newTimes = this.manageSourceOrder(source, newTimes);
459
+ newTimes = this.manageCollision(source, newTimes);
444
460
 
445
- this._view.setTimelineLength(
446
- this._view.timeToPixels(sources[sources.length - 1].endTime) + this._view.getWidth()
461
+ source.updateTimes(
462
+ newTimes.start,
463
+ newTimes.end
447
464
  );
448
465
 
449
- return true;
466
+ if (newTimes) {
467
+ this._updateSource(
468
+ source
469
+ );
470
+
471
+ return true;
472
+ }
473
+ return false;
450
474
  };
451
475
 
452
- SourcesLayer.prototype.manageVerticalPosition = function(sources, startTime, endTime, mouseX, mouseY) {
453
- return this._lines.manageVerticalPosition(sources, startTime, endTime, mouseX, mouseY);
476
+ SourcesLayer.prototype.manageVerticalPosition = function(source, newY) {
477
+ return this._lines.manageVerticalPosition(source, newY);
454
478
  };
455
479
 
456
- SourcesLayer.prototype.manageOrder = function(sources, startTime, endTime) {
457
- return this._lines.manageOrder(sources, startTime, endTime);
480
+ SourcesLayer.prototype.manageSourceOrder = function(source, newTimes) {
481
+ return this._lines.manageSourceOrder(source, newTimes);
458
482
  };
459
483
 
460
- SourcesLayer.prototype.manageCollision = function(sources, newStartTime, newEndTime) {
461
- return this._lines.manageCollision(sources, newStartTime, newEndTime);
484
+ SourcesLayer.prototype.manageCollision = function(source, newTimes) {
485
+ return this._lines.manageCollision(source, newTimes);
462
486
  };
463
487
 
464
488
  /**
@@ -671,7 +695,9 @@ define([
671
695
  this._peaks.off('sources.hide', this._onSourcesHide);
672
696
  this._peaks.off('source.update', this._onSourceUpdate);
673
697
  this._peaks.off('data.retrieved', this._onDataRetrieved);
698
+ this._peaks.off('sources.refresh', this._onSourcesRefresh);
674
699
  this._peaks.off('segments.show', this._onSegmentsShow);
700
+ this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
675
701
  this._peaks.off('source.setIndicators', this.setIndicators);
676
702
  };
677
703
 
@@ -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
  };