@checksub_team/peaks_timeline 1.16.0-alpha.0 → 1.16.0-alpha.2

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/lines.js CHANGED
@@ -43,9 +43,11 @@ define([
43
43
  );
44
44
 
45
45
  this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
46
- this._peaks.on('line.add', this._onLineAdd.bind(this));
47
46
  this._peaks.on('line.remove', this._onLineRemove.bind(this));
48
47
 
48
+ this._peaks.on('sources.show', this._onSourcesWrappingChanged.bind(this));
49
+ this._peaks.on('sources.hide', this._onSourcesWrappingChanged.bind(this));
50
+
49
51
  this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
50
52
  this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
51
53
  this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
@@ -101,35 +103,27 @@ define([
101
103
  this._view.updateTimeline();
102
104
  };
103
105
 
104
- Lines.prototype._onLineAdd = function(position) {
105
- this._createLine(position);
106
- this._setInteractions(position);
107
- this._updateLinesPosition(position);
108
- };
109
-
110
106
  Lines.prototype._onLineRemove = function(position) {
111
- this.removeLine(position);
107
+ this._removeLine(position);
112
108
  this._updateLinesPosition(position);
113
109
  };
114
110
 
115
- Lines.prototype.changeLineHeight = function(from, to) {
116
- for (var position in this._linesByPosition) {
117
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
118
- if (!this._linesByPosition[position].isSegmentsLine()) {
119
- this._linesByPosition[position].changeHeight(from, to);
120
- }
111
+ Lines.prototype._onSourcesWrappingChanged = function(sources) {
112
+ sources.forEach(function(source) {
113
+ if (this._linesByPosition[source.position]) {
114
+ this._linesByPosition[source.position].updateLineHeight(source, 'wrappingChanged');
121
115
  }
122
- }
116
+ }.bind(this));
123
117
  };
124
118
 
125
- Lines.prototype.addSourceGroup = function(sourceGroup, position) {
119
+ Lines.prototype.addSourceGroup = function(source, sourceGroup, position) {
126
120
  if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
127
121
  this._createLine(position);
128
122
  this._setInteractions(position);
129
123
  }
130
124
 
131
- sourceGroup.getSource().position = position;
132
- this._linesByPosition[position].addSourceGroup(sourceGroup);
125
+ source.position = position;
126
+ this._linesByPosition[position].addSourceGroup(source, sourceGroup);
133
127
  };
134
128
 
135
129
  Lines.prototype.addSegments = function(lineId, position) {
@@ -159,7 +153,7 @@ define([
159
153
  return sourceGroup;
160
154
  };
161
155
 
162
- Lines.prototype.removeLine = function(pos) {
156
+ Lines.prototype._removeLine = function(pos) {
163
157
  var oldLine = this._linesByPosition[pos];
164
158
  var lineId = oldLine.getId();
165
159
 
@@ -303,50 +297,62 @@ define([
303
297
  this._automaticallyCreatedLineId = null;
304
298
  };
305
299
 
306
- Lines.prototype.manageAutomaticLineCreation = function(pos, source) {
300
+ Lines.prototype.manageAutomaticLineCreation = function(newLinePosition, initialPosition, sources) {
307
301
  if (this._automaticallyCreatedLineId !== null) {
308
302
  return;
309
303
  }
310
304
  else if (
311
305
  this._automaticLineCreationPosition !== null
312
- && this._automaticLineCreationPosition !== pos
306
+ && this._automaticLineCreationPosition !== newLinePosition
313
307
  ) {
314
308
  this.stopAutomaticLineCreation();
315
309
  }
316
- else if (this._automaticLineCreationTimeout) {
310
+
311
+ if (this._automaticLineCreationTimeout) {
317
312
  return;
318
313
  }
319
314
 
320
- this._automaticLineCreationPosition = pos;
315
+ this._automaticLineCreationPosition = newLinePosition;
321
316
  this._automaticLineCreationTimeout = setTimeout(function() {
322
317
  this._automaticLineCreationTimeout = null;
323
- this._automaticallyCreatedLineId = this._createLine(pos);
324
- this._setInteractions(pos);
325
- this.moveSourceToPosition(source, pos);
318
+
319
+ var currentLine = this._linesByPosition[initialPosition];
320
+
321
+ if (currentLine.countRemainingElements() === sources.length) {
322
+ this.stopAutomaticLineCreation();
323
+ return;
324
+ }
325
+
326
+ this._automaticallyCreatedLineId = this._createLine(newLinePosition);
327
+ this._setInteractions(newLinePosition);
328
+ this.moveSourcesToPosition(sources, currentLine.getPosition(), newLinePosition);
326
329
  }.bind(this), this._peaks.options.automaticLineCreationDelay);
327
330
  };
328
331
 
329
- Lines.prototype.manageVerticalPosition = function(source, mouseX, mouseY) {
330
- if (mouseY !== null && mouseY !== undefined) {
331
- var linePos = this.getLinesUnderY(mouseY);
332
+ Lines.prototype.manageVerticalPosition = function(sources, startTime, endTime, mouseX, mouseY) {
333
+ if (mouseX === null || mouseX === undefined) {
334
+ return;
335
+ }
332
336
 
333
- if (linePos[0] !== linePos[1]) {
334
- this.manageAutomaticLineCreation(linePos[0] + 1, source);
335
- }
336
- else {
337
- this.stopAutomaticLineCreation();
337
+ const position = sources[0].position;
338
+ const linePos = this.getLinesUnderY(mouseY);
338
339
 
339
- if (
340
- mouseX !== null && mouseX !== undefined
341
- && linePos[0] !== source.position
342
- && !this._linesByPosition[linePos[0]].isSegmentsLine()
343
- ) {
344
- var mouseTime = this._view.pixelsToTime(mouseX + this._view.getFrameOffset());
345
- var sourceDuration = Utils.roundTime(source.endTime - source.startTime);
340
+ if (linePos[0] !== linePos[1]) {
341
+ this.manageAutomaticLineCreation(linePos[0] + 1, position, sources);
342
+ }
343
+ else {
344
+ this.stopAutomaticLineCreation();
346
345
 
347
- if (this._hasSpaceForSourceAt(linePos[0], mouseTime, sourceDuration)) {
348
- this.moveSourceToPosition(source, linePos[0]);
349
- }
346
+ if (
347
+ mouseX !== null && mouseX !== undefined
348
+ && linePos[0] !== position
349
+ && !this._linesByPosition[linePos[0]].isSegmentsLine()
350
+ ) {
351
+ var mouseTime = this._view.pixelsToTime(mouseX + this._view.getFrameOffset());
352
+ var sourceDuration = Utils.roundTime(endTime - startTime);
353
+
354
+ if (this._hasSpaceForSourceAt(linePos[0], mouseTime, sourceDuration)) {
355
+ this.moveSourcesToPosition(sources, position, linePos[0]);
350
356
  }
351
357
  }
352
358
  }
@@ -406,14 +412,18 @@ define([
406
412
  return pos;
407
413
  };
408
414
 
409
- Lines.prototype.moveSourceToPosition = function(source, pos) {
410
- var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, true);
415
+ Lines.prototype.moveSourcesToPosition = function(sources, initialPosition, targetPosition) {
416
+ sources.forEach(function(source) {
417
+ var sourceGroup = this._linesByPosition[initialPosition].removeSourceGroup(source, true);
411
418
 
412
- sourceGroup.moveTo(this._linesByPosition[pos].getKonvaGroup());
419
+ if (sourceGroup) {
420
+ sourceGroup.moveTo(this._linesByPosition[targetPosition].getKonvaGroup());
421
+ }
413
422
 
414
- this._updateLinesPosition(source.position);
423
+ this.addSourceGroup(source, sourceGroup, targetPosition);
424
+ }.bind(this));
415
425
 
416
- this.addSourceGroup(sourceGroup, pos);
426
+ this._updateLinesPosition(initialPosition);
417
427
  };
418
428
 
419
429
  Lines.prototype._getNextLineId = function() {
@@ -471,12 +481,13 @@ define([
471
481
  }
472
482
  };
473
483
 
474
- Lines.prototype.manageCollision = function(source, newTimes) {
475
- return this._linesByPosition[source.position].manageCollision(source, newTimes);
484
+ Lines.prototype.manageCollision = function(sources, newStartTime, newEndTime) {
485
+ return this._linesByPosition[sources[0].position].manageCollision(sources, newStartTime, newEndTime);
476
486
  };
477
487
 
478
- Lines.prototype.manageSourceOrder = function(source, newTimes) {
479
- return this._linesByPosition[source.position].manageSourceOrder(source, newTimes);
488
+ Lines.prototype.manageOrder = function(sources, startTime, endTime) {
489
+ // Assuming all ordered elements have the same position
490
+ return this._linesByPosition[sources[0].position].manageOrder(sources, startTime, endTime);
480
491
  };
481
492
 
482
493
  Lines.prototype._setInteractions = function(position) {
package/src/main.js CHANGED
@@ -777,13 +777,6 @@ define([
777
777
  window.removeEventListener('resize', this._onResize);
778
778
  };
779
779
 
780
- Peaks.prototype.setLineHeight = function(newLineHeight) {
781
- var oldHeight = this.options.lineHeight;
782
-
783
- this.options.lineHeight = newLineHeight;
784
- this.emit('options.set.line_height', oldHeight);
785
- };
786
-
787
780
  Peaks.prototype.zoomIn = function() {
788
781
  this.view.setZoom(
789
782
  this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1
@@ -72,6 +72,10 @@ define([
72
72
  return Object.keys(this._segments).length === 0;
73
73
  };
74
74
 
75
+ SegmentsGroup.prototype.countRemainingElements = function() {
76
+ return Object.keys(this._segments).length;
77
+ };
78
+
75
79
  /**
76
80
  * Adds the group to the given {Konva.Group}.
77
81
  *
@@ -47,15 +47,13 @@ define([
47
47
  var self = this;
48
48
 
49
49
  this._x = this._view.timeToPixels(source.startTime);
50
- this._roundedX = Math.round(this._x);
51
50
  this._width = this._view.timeToPixels(source.endTime - source.startTime);
52
- this._roundedWidth = Math.round(this._width);
53
- this._unwrappedHeight = source.binaryHeight && source.previewHeight ?
54
- source.binaryHeight + source.previewHeight :
55
- this._peaks.options.lineHeight;
56
- this._wrappedHeight = this._peaks.options.wrappedLineHeight;
51
+ var heights = SourceGroup.getHeights(source, peaks);
52
+
53
+ this._unwrappedHeight = heights.unwrapped;
54
+ this._wrappedHeight = heights.wrapped;
55
+ this._height = heights.current;
57
56
  this._borderWidth = this._source.borderWidth || 0;
58
- this._height = this._unwrappedHeight;
59
57
  this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
60
58
  this._selected = this._source.selected;
61
59
  this._isDragged = false;
@@ -174,8 +172,8 @@ define([
174
172
 
175
173
  this._view.updateWithAutoScroll(
176
174
  function() {
177
- if (this._layer.updateSource(
178
- this._source,
175
+ if (this._layer.manageSourceMovements(
176
+ [this._source],
179
177
  leftHandle ? start + diff + timeOffsetDiff : null,
180
178
  leftHandle ? null : end + diff + timeOffsetDiff
181
179
  )) {
@@ -184,10 +182,6 @@ define([
184
182
  }.bind(this)
185
183
  );
186
184
 
187
- this._view.setTimelineLength(
188
- this._view.timeToPixels(this._source.endTime) + this._view.getWidth()
189
- );
190
-
191
185
  return {
192
186
  x: draggedElement.absolutePosition().x,
193
187
  y: draggedElement.absolutePosition().y
@@ -203,13 +197,11 @@ define([
203
197
  this._group.x(startPixel - frameOffset);
204
198
 
205
199
  this._x = startPixel;
206
- this._roundedX = Math.round(this._x);
207
200
 
208
201
  const newWidth = endPixel - startPixel;
209
202
 
210
203
  if (newWidth !== this._width) {
211
204
  this._width = newWidth;
212
- this._roundedWidth = Math.round(this._width);
213
205
 
214
206
  // the zoom was changed
215
207
  if (newTimeToPixelsScale !== this._currentTimeToPixelsScaleUsed) {
@@ -277,11 +269,13 @@ define([
277
269
  start: this._source.startTime,
278
270
  end: this._source.endTime
279
271
  };
272
+ this._isDragged = true;
280
273
 
281
274
  this._hideButtons();
282
275
  };
283
276
 
284
277
  SourceGroup.prototype._onHandleDragEnd = function() {
278
+ this._isDragged = false;
285
279
  this._showButtons();
286
280
  };
287
281
 
@@ -386,7 +380,7 @@ define([
386
380
  Math.max(
387
381
  1,
388
382
  Math.min(
389
- this._roundedWidth / 2,
383
+ this._width / 2,
390
384
  Math.min(
391
385
  CORNER_RADIUS,
392
386
  this._height / 2
@@ -395,63 +389,65 @@ define([
395
389
  );
396
390
  var x = Math.max(
397
391
  0,
398
- this._view.getFrameOffset() - this._roundedX - radius
392
+ this._view.getFrameOffset() - this._x - 2 * radius
399
393
  );
400
394
  var width = Math.min(
401
- this._roundedWidth - x,
402
- this._view.getWidth() + radius - Math.max(
395
+ this._width - x,
396
+ this._view.getWidth() + 4 * radius - Math.max(
403
397
  0,
404
- this._roundedX - this._view.getFrameOffset()
398
+ this._x - this._view.getFrameOffset()
405
399
  )
406
400
  );
407
401
  var xWidth = x + width;
408
402
 
409
- ctx.beginPath();
410
- ctx.moveTo(x + radius, offset);
411
- ctx.lineTo(xWidth - radius, offset);
412
- ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
413
- ctx.lineTo(xWidth - offset, this._height - radius);
414
- ctx.quadraticCurveTo(
415
- xWidth - offset,
416
- this._height - offset,
417
- xWidth - radius,
418
- this._height - offset
419
- );
420
- ctx.lineTo(x + radius, this._height - offset);
421
- ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
422
- ctx.lineTo(x + offset, radius);
423
- ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
424
- ctx.closePath();
403
+ if (width > 0) {
404
+ ctx.beginPath();
405
+ ctx.moveTo(x + radius, offset);
406
+ ctx.lineTo(xWidth - radius, offset);
407
+ ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
408
+ ctx.lineTo(xWidth - offset, this._height - radius);
409
+ ctx.quadraticCurveTo(
410
+ xWidth - offset,
411
+ this._height - offset,
412
+ xWidth - radius,
413
+ this._height - offset
414
+ );
415
+ ctx.lineTo(x + radius, this._height - offset);
416
+ ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
417
+ ctx.lineTo(x + offset, radius);
418
+ ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
419
+ ctx.closePath();
425
420
 
426
- if (fill) {
427
- if (this._source.shouldShowWarning()) {
428
- var gradient = ctx.createLinearGradient(0, 0, this._roundedWidth, 0);
421
+ if (fill) {
422
+ if (this._source.shouldShowWarning()) {
423
+ var gradient = ctx.createLinearGradient(0, 0, this._width, 0);
429
424
 
430
- if (this._source.mediaEndTime < this._source.duration) {
431
- var rightStopPosition = Math.max(1 - (this._source.warningWidth / this._roundedWidth), 0.5);
425
+ if (this._source.mediaEndTime < this._source.duration) {
426
+ var rightStopPosition = Math.max(1 - (this._source.warningWidth / this._width), 0.5);
432
427
 
433
- gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
434
- gradient.addColorStop(1, this._source.warningColor);
435
- }
428
+ gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
429
+ gradient.addColorStop(1, this._source.warningColor);
430
+ }
436
431
 
437
- if (this._source.mediaStartTime > 0) {
438
- var leftStopPosition = Math.min(this._source.warningWidth / this._roundedWidth, 0.5);
432
+ if (this._source.mediaStartTime > 0) {
433
+ var leftStopPosition = Math.min(this._source.warningWidth / this._width, 0.5);
439
434
 
440
- gradient.addColorStop(0, this._source.warningColor);
441
- gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
442
- }
435
+ gradient.addColorStop(0, this._source.warningColor);
436
+ gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
437
+ }
443
438
 
444
- ctx.fillStyle = gradient;
445
- ctx.fill();
446
- }
447
- else {
448
- ctx.fillStyle = this._source.backgroundColor;
449
- ctx.fill();
439
+ ctx.fillStyle = gradient;
440
+ ctx.fill();
441
+ }
442
+ else {
443
+ ctx.fillStyle = this._source.backgroundColor;
444
+ ctx.fill();
445
+ }
450
446
  }
451
- }
452
447
 
453
- if (shape) {
454
- ctx.fillStrokeShape(shape);
448
+ if (shape) {
449
+ ctx.fillStrokeShape(shape);
450
+ }
455
451
  }
456
452
  };
457
453
 
@@ -1117,6 +1113,14 @@ define([
1117
1113
  return this._height;
1118
1114
  };
1119
1115
 
1116
+ SourceGroup.prototype.getHeights = function() {
1117
+ return {
1118
+ unwrapped: this._unwrappedHeight,
1119
+ wrapped: this._wrappedHeight,
1120
+ current: this._height
1121
+ };
1122
+ };
1123
+
1120
1124
  SourceGroup.prototype.setVisible = function(boolean) {
1121
1125
  this._group.visible(boolean);
1122
1126
  };
@@ -1617,5 +1621,25 @@ define([
1617
1621
  this._group.destroy();
1618
1622
  };
1619
1623
 
1624
+ /**
1625
+ * Static method to get height for a source
1626
+ * @param {Source} source - The source object
1627
+ * @param {Object} peaks - The peaks instance (for options)
1628
+ * @returns {number} The calculated height
1629
+ */
1630
+ SourceGroup.getHeights = function(source, peaks) {
1631
+ var unwrappedHeight = source.binaryHeight && source.previewHeight ?
1632
+ source.binaryHeight + source.previewHeight :
1633
+ peaks.options.lineHeight;
1634
+ var wrappedHeight = peaks.options.wrappedLineHeight;
1635
+ var height = source.wrapped ? wrappedHeight : unwrappedHeight;
1636
+
1637
+ return {
1638
+ unwrapped: unwrappedHeight,
1639
+ wrapped: wrappedHeight,
1640
+ current: height
1641
+ };
1642
+ };
1643
+
1620
1644
  return SourceGroup;
1621
1645
  });