@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/package.json +1 -1
- package/peaks.js +331 -353
- package/src/line-indicator.js +0 -10
- package/src/line.js +172 -216
- package/src/lines.js +64 -53
- package/src/main.js +0 -7
- package/src/segments-group.js +4 -0
- package/src/source-group.js +82 -58
- package/src/sources-layer.js +85 -101
- package/src/timeline-sources.js +8 -6
package/src/sources-layer.js
CHANGED
|
@@ -57,7 +57,6 @@ define([
|
|
|
57
57
|
this._peaks.on('source.update', this._onSourceUpdate.bind(this));
|
|
58
58
|
this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
|
|
59
59
|
this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
|
|
60
|
-
this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
|
|
61
60
|
this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
|
|
62
61
|
}
|
|
63
62
|
|
|
@@ -99,30 +98,6 @@ define([
|
|
|
99
98
|
return this._allowEditing;
|
|
100
99
|
};
|
|
101
100
|
|
|
102
|
-
SourcesLayer.prototype._onOptionsLineHeightChange = function(oldHeight) {
|
|
103
|
-
var positions = [];
|
|
104
|
-
|
|
105
|
-
for (var sourceId in this._sourcesGroup) {
|
|
106
|
-
if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
|
|
107
|
-
var source = this._sourcesGroup[sourceId].getSource();
|
|
108
|
-
|
|
109
|
-
if (!positions.includes(source.position)) {
|
|
110
|
-
this._lines.changeLineHeight(
|
|
111
|
-
oldHeight,
|
|
112
|
-
this._peaks.options.lineHeight
|
|
113
|
-
);
|
|
114
|
-
positions.push(source.position);
|
|
115
|
-
}
|
|
116
|
-
this._removeSource(source);
|
|
117
|
-
this._addSourceGroup(source);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (positions) {
|
|
122
|
-
this.refresh();
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
101
|
SourcesLayer.prototype.refresh = function() {
|
|
127
102
|
var frameOffset = this._view.getFrameOffset();
|
|
128
103
|
var width = this._view.getWidth();
|
|
@@ -168,16 +143,6 @@ define([
|
|
|
168
143
|
this.draw();
|
|
169
144
|
};
|
|
170
145
|
|
|
171
|
-
SourcesLayer.prototype._onSourcesShow = function(sources) {
|
|
172
|
-
var self = this;
|
|
173
|
-
|
|
174
|
-
sources.forEach(function(source) {
|
|
175
|
-
self._sourcesGroup[source.id].setWrapping(false, true);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
this._layer.draw();
|
|
179
|
-
};
|
|
180
|
-
|
|
181
146
|
SourcesLayer.prototype._onSourcesAdd = function(sources) {
|
|
182
147
|
var self = this;
|
|
183
148
|
|
|
@@ -285,7 +250,7 @@ define([
|
|
|
285
250
|
var sourceGroup = this._createSourceGroup(source);
|
|
286
251
|
|
|
287
252
|
this._sourcesGroup[source.id] = sourceGroup;
|
|
288
|
-
this._lines.addSourceGroup(sourceGroup, source.position);
|
|
253
|
+
this._lines.addSourceGroup(source, sourceGroup, source.position);
|
|
289
254
|
|
|
290
255
|
// After creating and referencing the new group, we can start data retrieval
|
|
291
256
|
if (startDataRetrieval) {
|
|
@@ -320,8 +285,6 @@ define([
|
|
|
320
285
|
// Update sources in visible time range.
|
|
321
286
|
var sources = this.findSources(startTime, endTime);
|
|
322
287
|
|
|
323
|
-
// TODO: Should implement virtualization on Y
|
|
324
|
-
|
|
325
288
|
var count = sources.length;
|
|
326
289
|
|
|
327
290
|
sources.forEach(this._updateSource.bind(this));
|
|
@@ -337,20 +300,37 @@ define([
|
|
|
337
300
|
SourcesLayer.prototype.onSourcesGroupDragStart = function(element) {
|
|
338
301
|
this._initialTimeOffset = this._view.getTimeOffset();
|
|
339
302
|
this._mouseDownX = this._view.getPointerPosition().x;
|
|
340
|
-
this._activeElements = {};
|
|
341
303
|
|
|
342
304
|
const draggedElementId = element.currentTarget.attrs.sourceId;
|
|
343
|
-
|
|
305
|
+
|
|
306
|
+
var selectedElements = this._view.getSelectedElements();
|
|
307
|
+
const shouldDragSelectedElements = Object.keys(selectedElements).includes(
|
|
344
308
|
draggedElementId
|
|
345
309
|
);
|
|
346
310
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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;
|
|
323
|
+
|
|
324
|
+
return bounds;
|
|
325
|
+
}, {
|
|
326
|
+
initialStartTime: Infinity,
|
|
327
|
+
initialEndTime: -Infinity,
|
|
328
|
+
orderable: true
|
|
329
|
+
});
|
|
350
330
|
};
|
|
351
331
|
|
|
352
332
|
SourcesLayer.prototype.onSourcesGroupDragEnd = function() {
|
|
353
|
-
const updatedSources =
|
|
333
|
+
const updatedSources = this._draggedElements.map(
|
|
354
334
|
function(source) {
|
|
355
335
|
const sourceGroup = this._sourcesGroup[source.id];
|
|
356
336
|
|
|
@@ -365,8 +345,6 @@ define([
|
|
|
365
345
|
this._view.drawSourcesLayer();
|
|
366
346
|
this._view.updateTimelineLength();
|
|
367
347
|
|
|
368
|
-
this._activeElements = {};
|
|
369
|
-
|
|
370
348
|
this._peaks.emit('sources.updated', updatedSources);
|
|
371
349
|
};
|
|
372
350
|
|
|
@@ -388,41 +366,24 @@ define([
|
|
|
388
366
|
)
|
|
389
367
|
);
|
|
390
368
|
|
|
391
|
-
const
|
|
369
|
+
const timeDiff = this._view.pixelsToTime(mousePos - this._mouseDownX);
|
|
392
370
|
const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
|
|
393
371
|
const mousePosX = this._view.getPointerPosition().x;
|
|
394
372
|
const mousePosY = this._view.getPointerPosition().y;
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const { initialStartTime, initialEndTime } = this._activeElements[source.id];
|
|
407
|
-
|
|
408
|
-
newEnd = Math.max(newEnd, source.endTime);
|
|
409
|
-
|
|
410
|
-
shouldRedraw = this.updateSource(
|
|
411
|
-
source,
|
|
412
|
-
initialStartTime + diff + timeOffsetDiff,
|
|
413
|
-
initialEndTime + diff + timeOffsetDiff,
|
|
414
|
-
mousePosX,
|
|
415
|
-
mousePosY
|
|
416
|
-
) || shouldRedraw;
|
|
417
|
-
}.bind(this));
|
|
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
|
+
);
|
|
418
383
|
|
|
419
384
|
if (shouldRedraw) {
|
|
420
385
|
this.draw();
|
|
421
386
|
}
|
|
422
|
-
|
|
423
|
-
this._view.setTimelineLength(
|
|
424
|
-
this._view.timeToPixels(newEnd) + this._view.getWidth()
|
|
425
|
-
);
|
|
426
387
|
};
|
|
427
388
|
|
|
428
389
|
SourcesLayer.prototype.findSources = function(startTime, endTime) {
|
|
@@ -436,44 +397,68 @@ define([
|
|
|
436
397
|
);
|
|
437
398
|
};
|
|
438
399
|
|
|
439
|
-
SourcesLayer.prototype.
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
+
}
|
|
447
423
|
}
|
|
448
424
|
|
|
449
|
-
|
|
450
|
-
|
|
425
|
+
this.refresh();
|
|
426
|
+
};
|
|
451
427
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
);
|
|
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;
|
|
456
433
|
|
|
457
|
-
if (
|
|
458
|
-
this.
|
|
459
|
-
|
|
460
|
-
);
|
|
434
|
+
if (this._peaks.options.canMoveSourcesBetweenLines && typeof mouseY === 'number') {
|
|
435
|
+
this.manageVerticalPosition(sources, newStartTime, newEndTime, mouseX, mouseY);
|
|
436
|
+
}
|
|
461
437
|
|
|
462
|
-
|
|
438
|
+
if (orderable) {
|
|
439
|
+
({ newStartTime, newEndTime } = this.manageOrder(sources, newStartTime, newEndTime));
|
|
463
440
|
}
|
|
464
|
-
|
|
441
|
+
({ newStartTime, newEndTime } = this.manageCollision(sources, newStartTime, newEndTime));
|
|
442
|
+
|
|
443
|
+
this._applyTimeChangesToSources(sources, sources[0].startTime, newStartTime, newEndTime);
|
|
444
|
+
|
|
445
|
+
this._view.setTimelineLength(
|
|
446
|
+
this._view.timeToPixels(sources[sources.length - 1].endTime) + this._view.getWidth()
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
return true;
|
|
465
450
|
};
|
|
466
451
|
|
|
467
|
-
SourcesLayer.prototype.manageVerticalPosition = function(
|
|
468
|
-
return this._lines.manageVerticalPosition(
|
|
452
|
+
SourcesLayer.prototype.manageVerticalPosition = function(sources, startTime, endTime, mouseX, mouseY) {
|
|
453
|
+
return this._lines.manageVerticalPosition(sources, startTime, endTime, mouseX, mouseY);
|
|
469
454
|
};
|
|
470
455
|
|
|
471
|
-
SourcesLayer.prototype.
|
|
472
|
-
return this._lines.
|
|
456
|
+
SourcesLayer.prototype.manageOrder = function(sources, startTime, endTime) {
|
|
457
|
+
return this._lines.manageOrder(sources, startTime, endTime);
|
|
473
458
|
};
|
|
474
459
|
|
|
475
|
-
SourcesLayer.prototype.manageCollision = function(
|
|
476
|
-
return this._lines.manageCollision(
|
|
460
|
+
SourcesLayer.prototype.manageCollision = function(sources, newStartTime, newEndTime) {
|
|
461
|
+
return this._lines.manageCollision(sources, newStartTime, newEndTime);
|
|
477
462
|
};
|
|
478
463
|
|
|
479
464
|
/**
|
|
@@ -687,7 +672,6 @@ define([
|
|
|
687
672
|
this._peaks.off('source.update', this._onSourceUpdate);
|
|
688
673
|
this._peaks.off('data.retrieved', this._onDataRetrieved);
|
|
689
674
|
this._peaks.off('segments.show', this._onSegmentsShow);
|
|
690
|
-
this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
|
|
691
675
|
this._peaks.off('source.setIndicators', this.setIndicators);
|
|
692
676
|
};
|
|
693
677
|
|
package/src/timeline-sources.js
CHANGED
|
@@ -482,9 +482,10 @@ define([
|
|
|
482
482
|
*/
|
|
483
483
|
|
|
484
484
|
TimelineSources.prototype.showById = function(sourceId) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
485
|
+
if (this._sourcesById[sourceId].wrapped === false) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
488
489
|
this._sourcesById[sourceId].wrapped = false;
|
|
489
490
|
|
|
490
491
|
this._peaks.emit('sources.show', [this._sourcesById[sourceId]]);
|
|
@@ -498,9 +499,10 @@ define([
|
|
|
498
499
|
*/
|
|
499
500
|
|
|
500
501
|
TimelineSources.prototype.hideById = function(sourceId) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
502
|
+
if (this._sourcesById[sourceId].wrapped === true) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
|
|
504
506
|
this._sourcesById[sourceId].wrapped = true;
|
|
505
507
|
|
|
506
508
|
this._peaks.emit('sources.hide', [this._sourcesById[sourceId]]);
|