@checksub_team/peaks_timeline 2.4.0 → 2.5.0-alpha.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.
- package/package.json +1 -1
- package/peaks.js +482 -98
- package/peaks.js.d.ts +6 -0
- package/src/components/line-group.js +14 -0
- package/src/components/line-groups.js +24 -2
- package/src/components/mode-layer.js +11 -6
- package/src/components/segment-marker.js +10 -44
- package/src/components/segment-shape.js +72 -42
- package/src/components/segments-group.js +162 -4
- package/src/components/source-group.js +6 -34
- package/src/components/sources-layer.js +371 -2
- package/src/main.js +32 -0
- package/src/models/segment.js +17 -3
- package/src/view.js +41 -3
package/peaks.js.d.ts
CHANGED
|
@@ -267,6 +267,12 @@ declare module 'peaks.js' {
|
|
|
267
267
|
interface PeaksInstance {
|
|
268
268
|
setSource: (options: SetSourceOptions, callback: SetSourceCallback) => void;
|
|
269
269
|
destroy: () => void;
|
|
270
|
+
getSelectedElements: () => object[];
|
|
271
|
+
selectSourceById: (sourceId: string) => void;
|
|
272
|
+
selectSourcesOnLineAfter: (lineId: string, time: number) => void;
|
|
273
|
+
selectSegmentById: (segmentId: string) => void;
|
|
274
|
+
selectSegmentsOnLineAfter: (lineId: string | number, time: number) => void;
|
|
275
|
+
deselectAll: (notify?: boolean) => void;
|
|
270
276
|
/** Player API */
|
|
271
277
|
player: {
|
|
272
278
|
play: () => void;
|
|
@@ -646,6 +646,20 @@ define([
|
|
|
646
646
|
return sources;
|
|
647
647
|
};
|
|
648
648
|
|
|
649
|
+
/**
|
|
650
|
+
* Returns all segments on this line whose start time is at or after the given time.
|
|
651
|
+
*
|
|
652
|
+
* @param {Number} time
|
|
653
|
+
* @returns {Array<Segment>}
|
|
654
|
+
*/
|
|
655
|
+
LineGroup.prototype.getSegmentsAfter = function(time) {
|
|
656
|
+
if (!this.isSegmentsLine()) {
|
|
657
|
+
return [];
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return this._segmentsGroup.getSegmentsAfter(time);
|
|
661
|
+
};
|
|
662
|
+
|
|
649
663
|
LineGroup.prototype.getSourcesAround = function(time) {
|
|
650
664
|
var left = null;
|
|
651
665
|
var right = null;
|
|
@@ -120,8 +120,13 @@ define([
|
|
|
120
120
|
this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
LineGroups.prototype._onSegmentUpdated = function(
|
|
124
|
-
this._segmentsGroups
|
|
123
|
+
LineGroups.prototype._onSegmentUpdated = function() {
|
|
124
|
+
for (var lineId in this._segmentsGroups) {
|
|
125
|
+
if (Utils.objectHasProperty(this._segmentsGroups, lineId)
|
|
126
|
+
&& this._segmentsGroups[lineId].hasUpdatedSegments()) {
|
|
127
|
+
this._segmentsGroups[lineId].onSegmentUpdated();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
125
130
|
};
|
|
126
131
|
|
|
127
132
|
LineGroups.prototype._onSegmentsRemove = function(segments) {
|
|
@@ -232,6 +237,23 @@ define([
|
|
|
232
237
|
return this._lineGroupsById[lineId].getSourcesAfter(time);
|
|
233
238
|
};
|
|
234
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Returns all segments in the given segment group or displayed line whose start time is at or after the given time.
|
|
242
|
+
*
|
|
243
|
+
* @param {String|Number} lineId A rendered line identifier or a segment group identifier.
|
|
244
|
+
* @param {Number} time
|
|
245
|
+
* @returns {Array<Segment>}
|
|
246
|
+
*/
|
|
247
|
+
LineGroups.prototype.getSegmentsOnLineAfter = function(lineId, time) {
|
|
248
|
+
const lineGroup = this._lineGroupsById[lineId] || this._segmentsGroupToLine[lineId];
|
|
249
|
+
|
|
250
|
+
if (!lineGroup) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return lineGroup.getSegmentsAfter(time);
|
|
255
|
+
};
|
|
256
|
+
|
|
235
257
|
LineGroups.prototype.getSegmentsGroups = function() {
|
|
236
258
|
return this._segmentsGroups;
|
|
237
259
|
};
|
|
@@ -93,6 +93,12 @@ define([
|
|
|
93
93
|
stage.add(this._layer);
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Selects the given elements.
|
|
98
|
+
*
|
|
99
|
+
* @param {Array<Source|Segment>} elements Elements to select.
|
|
100
|
+
* @param {Boolean} notify When <code>true</code>, selection events are emitted.
|
|
101
|
+
*/
|
|
96
102
|
ModeLayer.prototype.selectElements = function(elements, notify) {
|
|
97
103
|
const sources = [];
|
|
98
104
|
const segments = [];
|
|
@@ -232,12 +238,11 @@ define([
|
|
|
232
238
|
const hoveredKonvaElement = this._view.getHoveredElement();
|
|
233
239
|
|
|
234
240
|
if (hoveredKonvaElement) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
+
const element = hoveredKonvaElement instanceof SourceGroup ?
|
|
242
|
+
hoveredKonvaElement.getSource() :
|
|
243
|
+
hoveredKonvaElement.getSegment();
|
|
244
|
+
|
|
245
|
+
this.selectElements([element], true);
|
|
241
246
|
}
|
|
242
247
|
else {
|
|
243
248
|
this.deselectDifference([], true);
|
|
@@ -84,50 +84,8 @@ define([
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
SegmentMarker.prototype._dragBoundFunc = function(
|
|
88
|
-
|
|
89
|
-
var newStartX;
|
|
90
|
-
|
|
91
|
-
if (this._segment.duration) {
|
|
92
|
-
newStartX = Math.max(
|
|
93
|
-
pos.x + this._view.getFrameOffset(),
|
|
94
|
-
this._view.timeToPixels(this._segment.endTime - this._segment.duration)
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
newStartX = pos.x + this._view.getFrameOffset();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
this._segmentShape.getSegmentsGroup().updateSegment(
|
|
102
|
-
this._segment,
|
|
103
|
-
newStartX,
|
|
104
|
-
null
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
var newEndX;
|
|
109
|
-
|
|
110
|
-
if (this._segment.duration) {
|
|
111
|
-
newEndX = Math.min(
|
|
112
|
-
pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth(),
|
|
113
|
-
this._view.timeToPixels(this._segment.startTime + this._segment.duration)
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
newEndX = pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this._segmentShape.getSegmentsGroup().updateSegment(
|
|
121
|
-
this._segment,
|
|
122
|
-
null,
|
|
123
|
-
newEndX
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
x: this._group.getAbsolutePosition().x,
|
|
129
|
-
y: this._group.getAbsolutePosition().y
|
|
130
|
-
};
|
|
87
|
+
SegmentMarker.prototype._dragBoundFunc = function() {
|
|
88
|
+
return this._view._sourcesLayer.onSegmentHandleDrag(this);
|
|
131
89
|
};
|
|
132
90
|
|
|
133
91
|
SegmentMarker.prototype.moveTo = function(group) {
|
|
@@ -142,6 +100,10 @@ define([
|
|
|
142
100
|
return this._group.getX();
|
|
143
101
|
};
|
|
144
102
|
|
|
103
|
+
SegmentMarker.prototype.getAbsolutePosition = function() {
|
|
104
|
+
return this._group.getAbsolutePosition();
|
|
105
|
+
};
|
|
106
|
+
|
|
145
107
|
SegmentMarker.prototype.getWidth = function() {
|
|
146
108
|
return this._group.getWidth();
|
|
147
109
|
};
|
|
@@ -162,6 +124,10 @@ define([
|
|
|
162
124
|
this._group.setX(x);
|
|
163
125
|
};
|
|
164
126
|
|
|
127
|
+
SegmentMarker.prototype.stopDrag = function() {
|
|
128
|
+
this._group.stopDrag();
|
|
129
|
+
};
|
|
130
|
+
|
|
165
131
|
SegmentMarker.prototype.timeUpdated = function(time) {
|
|
166
132
|
if (this._marker.timeUpdated) {
|
|
167
133
|
this._marker.timeUpdated(time);
|
|
@@ -105,16 +105,7 @@ define([
|
|
|
105
105
|
this._onSegmentHandleDragStart = this._onSegmentHandleDragStart.bind(this);
|
|
106
106
|
this._onSegmentHandleDragEnd = this._onSegmentHandleDragEnd.bind(this);
|
|
107
107
|
|
|
108
|
-
this.
|
|
109
|
-
x: this._view.timeToPixels(segment.startTime),
|
|
110
|
-
y: this._segmentY,
|
|
111
|
-
width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
|
|
112
|
-
height: this._segmentHeight,
|
|
113
|
-
segment: segment,
|
|
114
|
-
view: this._view.getName(),
|
|
115
|
-
group: this._group,
|
|
116
|
-
fontSize: 12
|
|
117
|
-
});
|
|
108
|
+
this._createLabel();
|
|
118
109
|
|
|
119
110
|
this._createMarkers();
|
|
120
111
|
|
|
@@ -125,20 +116,7 @@ define([
|
|
|
125
116
|
}
|
|
126
117
|
|
|
127
118
|
SegmentShape.prototype._onShapeGroupDrag = function(draggedElement) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this._group.updateSegment(
|
|
131
|
-
this._segment,
|
|
132
|
-
this._initialStartPixel + diff, this._initialEndPixel + diff
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
this._startMarker.timeUpdated(this._segment.startTime);
|
|
136
|
-
this._endMarker.timeUpdated(this._segment.endTime);
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
x: draggedElement.absolutePosition().x,
|
|
140
|
-
y: draggedElement.absolutePosition().y
|
|
141
|
-
};
|
|
119
|
+
return this._view._sourcesLayer.onSegmentDrag(draggedElement);
|
|
142
120
|
};
|
|
143
121
|
|
|
144
122
|
SegmentShape.prototype._cornerRadius = function() {
|
|
@@ -147,9 +125,67 @@ define([
|
|
|
147
125
|
SEGMENT_CORNER_RADIUS;
|
|
148
126
|
};
|
|
149
127
|
|
|
128
|
+
SegmentShape.prototype._createLabel = function() {
|
|
129
|
+
this._label = this._peaks.options.createSegmentLabel({
|
|
130
|
+
x: this._view.timeToPixels(this._segment.startTime),
|
|
131
|
+
y: this._segmentY,
|
|
132
|
+
width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
|
|
133
|
+
height: this._segmentHeight,
|
|
134
|
+
segment: this._segment,
|
|
135
|
+
view: this._view.getName(),
|
|
136
|
+
group: this._group,
|
|
137
|
+
fontSize: 12
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
SegmentShape.prototype._rebuildSelectionDependentNodes = function() {
|
|
142
|
+
var group = this._shapeGroup.getParent();
|
|
143
|
+
|
|
144
|
+
if (this._label) {
|
|
145
|
+
this._label.destroy();
|
|
146
|
+
this._label = null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (this._startMarker) {
|
|
150
|
+
this._startMarker.destroy();
|
|
151
|
+
this._startMarker = null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (this._endMarker) {
|
|
155
|
+
this._endMarker.destroy();
|
|
156
|
+
this._endMarker = null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this._createLabel();
|
|
160
|
+
this._createMarkers();
|
|
161
|
+
|
|
162
|
+
if (group) {
|
|
163
|
+
if (this._label) {
|
|
164
|
+
this._label.moveTo(group);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (this._startMarker) {
|
|
168
|
+
this._startMarker.moveTo(group);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (this._endMarker) {
|
|
172
|
+
this._endMarker.moveTo(group);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
150
177
|
SegmentShape.prototype.update = function() {
|
|
151
|
-
|
|
152
|
-
|
|
178
|
+
this._applyDisplayTimes(this._segment.startTime, this._segment.endTime);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
SegmentShape.prototype.setSelected = function() {
|
|
182
|
+
this._rebuildSelectionDependentNodes();
|
|
183
|
+
this.update();
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
SegmentShape.prototype._applyDisplayTimes = function(startTime, endTime) {
|
|
187
|
+
var startPixel = this._view.timeToPixels(startTime);
|
|
188
|
+
var endPixel = this._view.timeToPixels(endTime);
|
|
153
189
|
var frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
|
|
154
190
|
|
|
155
191
|
this._shapeGroup.x(startPixel - frameOffset);
|
|
@@ -186,12 +222,12 @@ define([
|
|
|
186
222
|
|
|
187
223
|
if (this._startMarker) {
|
|
188
224
|
this._startMarker.setX(startPixel - frameOffset);
|
|
189
|
-
this._startMarker.timeUpdated(
|
|
225
|
+
this._startMarker.timeUpdated(startTime);
|
|
190
226
|
}
|
|
191
227
|
|
|
192
228
|
if (this._endMarker) {
|
|
193
229
|
this._endMarker.setX(endPixel - this._endMarker.getHandleWidth() - frameOffset);
|
|
194
|
-
this._endMarker.timeUpdated(
|
|
230
|
+
this._endMarker.timeUpdated(endTime);
|
|
195
231
|
}
|
|
196
232
|
|
|
197
233
|
if (this._label) {
|
|
@@ -224,6 +260,10 @@ define([
|
|
|
224
260
|
return this._endMarker;
|
|
225
261
|
};
|
|
226
262
|
|
|
263
|
+
SegmentShape.prototype.stopDrag = function() {
|
|
264
|
+
this._shapeGroup.stopDrag();
|
|
265
|
+
};
|
|
266
|
+
|
|
227
267
|
SegmentShape.prototype.moveTo = function(group, segmentsGroup) {
|
|
228
268
|
if (segmentsGroup) {
|
|
229
269
|
this._segmentsGroup = segmentsGroup;
|
|
@@ -412,19 +452,13 @@ define([
|
|
|
412
452
|
SegmentShape.prototype._onSegmentDragStart = function() {
|
|
413
453
|
this._view.setCursor('grab');
|
|
414
454
|
|
|
415
|
-
this.
|
|
416
|
-
this._initialStartTime = this._segment.startTime;
|
|
417
|
-
this._initialStartPixel = this._view.timeToPixels(this._initialStartTime);
|
|
418
|
-
this._initialEndTime = this._segment.endTime;
|
|
419
|
-
this._initialEndPixel = this._view.timeToPixels(this._initialEndTime);
|
|
420
|
-
|
|
421
|
-
this._peaks.emit('segments.dragstart', this._segment);
|
|
455
|
+
this._view._sourcesLayer.onSegmentDragStart(this);
|
|
422
456
|
};
|
|
423
457
|
|
|
424
458
|
SegmentShape.prototype._onSegmentDragEnd = function() {
|
|
425
459
|
this._view.setCursor('pointer');
|
|
426
460
|
|
|
427
|
-
this.
|
|
461
|
+
this._view._sourcesLayer.onSegmentDragEnd(this);
|
|
428
462
|
};
|
|
429
463
|
|
|
430
464
|
/**
|
|
@@ -440,9 +474,7 @@ define([
|
|
|
440
474
|
*/
|
|
441
475
|
|
|
442
476
|
SegmentShape.prototype._onSegmentHandleDragStart = function(segmentMarker) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
this._peaks.emit('segments.dragstart', this._segment, startMarker);
|
|
477
|
+
this._view._sourcesLayer.onSegmentHandleDragStart(segmentMarker);
|
|
446
478
|
};
|
|
447
479
|
|
|
448
480
|
/**
|
|
@@ -450,9 +482,7 @@ define([
|
|
|
450
482
|
*/
|
|
451
483
|
|
|
452
484
|
SegmentShape.prototype._onSegmentHandleDragEnd = function(segmentMarker) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
this._peaks.emit('segments.dragend', this._segment, startMarker);
|
|
485
|
+
this._view._sourcesLayer.onSegmentHandleDragEnd(segmentMarker);
|
|
456
486
|
};
|
|
457
487
|
|
|
458
488
|
SegmentShape.prototype.fitToView = function() {
|
|
@@ -392,6 +392,35 @@ define([
|
|
|
392
392
|
return visibleSegments;
|
|
393
393
|
};
|
|
394
394
|
|
|
395
|
+
/**
|
|
396
|
+
* Returns all segments on this line whose start time is at or after the given time.
|
|
397
|
+
*
|
|
398
|
+
* @param {Number} time
|
|
399
|
+
* @returns {Array<Segment>}
|
|
400
|
+
*/
|
|
401
|
+
SegmentsGroup.prototype.getSegmentsAfter = function(time) {
|
|
402
|
+
const segments = [];
|
|
403
|
+
var currentId = this._firstSegmentId;
|
|
404
|
+
|
|
405
|
+
while (currentId) {
|
|
406
|
+
var segmentData = this._segments[currentId];
|
|
407
|
+
|
|
408
|
+
if (segmentData.segment.startTime >= time) {
|
|
409
|
+
while (currentId) {
|
|
410
|
+
segmentData = this._segments[currentId];
|
|
411
|
+
|
|
412
|
+
segments.push(segmentData.segment);
|
|
413
|
+
currentId = segmentData.nextSegmentId;
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
currentId = segmentData.nextSegmentId;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return segments;
|
|
422
|
+
};
|
|
423
|
+
|
|
395
424
|
SegmentsGroup.prototype._draw = function() {
|
|
396
425
|
this._view.batchDrawSourcesLayer();
|
|
397
426
|
};
|
|
@@ -504,6 +533,10 @@ define([
|
|
|
504
533
|
return this._isMagnetized;
|
|
505
534
|
};
|
|
506
535
|
|
|
536
|
+
SegmentsGroup.prototype.markSegmentsUpdated = function(segments) {
|
|
537
|
+
segments.forEach(this.addToUpdatedSegments.bind(this));
|
|
538
|
+
};
|
|
539
|
+
|
|
507
540
|
SegmentsGroup.prototype.setIndicators = function(segment) {
|
|
508
541
|
var segmentShape = this._segmentShapes[segment.id];
|
|
509
542
|
|
|
@@ -513,21 +546,144 @@ define([
|
|
|
513
546
|
}
|
|
514
547
|
};
|
|
515
548
|
|
|
549
|
+
SegmentsGroup.prototype.setSelected = function(segment) {
|
|
550
|
+
var segmentShape = this._segmentShapes[segment.id];
|
|
551
|
+
|
|
552
|
+
if (segmentShape) {
|
|
553
|
+
segmentShape.setSelected();
|
|
554
|
+
this._draw();
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
516
558
|
SegmentsGroup.prototype.addToUpdatedSegments = function(segment) {
|
|
517
559
|
if (this._updatedSegments.indexOf(segment) === -1) {
|
|
518
560
|
this._updatedSegments.push(segment);
|
|
519
561
|
}
|
|
520
562
|
};
|
|
521
563
|
|
|
522
|
-
SegmentsGroup.prototype.
|
|
564
|
+
SegmentsGroup.prototype.hasUpdatedSegments = function() {
|
|
565
|
+
return this._updatedSegments.length > 0;
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Returns the allowed drag offset bounds for a set of segments that move together.
|
|
570
|
+
*
|
|
571
|
+
* @param {Array<Segment>} segments
|
|
572
|
+
* @param {Object<String, {startTime: Number, endTime: Number}>} initialPositions
|
|
573
|
+
* @returns {{minTimeOffset: Number, maxTimeOffset: Number}}
|
|
574
|
+
*/
|
|
575
|
+
SegmentsGroup.prototype.getSegmentsDragTimeLimits = function(segments, initialPositions) {
|
|
576
|
+
var selectedIds = {};
|
|
577
|
+
var minTimeOffset = -Infinity;
|
|
578
|
+
var maxTimeOffset = Infinity;
|
|
579
|
+
|
|
580
|
+
segments.forEach(function(segment) {
|
|
581
|
+
selectedIds[segment.id] = true;
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
segments.forEach(function(segment) {
|
|
585
|
+
var segmentData = this._segments[segment.id];
|
|
586
|
+
var initialPosition = initialPositions[segment.id];
|
|
587
|
+
var previousSegmentId = segmentData.prevSegmentId;
|
|
588
|
+
var nextSegmentId = segmentData.nextSegmentId;
|
|
589
|
+
|
|
590
|
+
while (previousSegmentId && selectedIds[previousSegmentId]) {
|
|
591
|
+
previousSegmentId = this._segments[previousSegmentId].prevSegmentId;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
while (nextSegmentId && selectedIds[nextSegmentId]) {
|
|
595
|
+
nextSegmentId = this._segments[nextSegmentId].nextSegmentId;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (previousSegmentId) {
|
|
599
|
+
minTimeOffset = Math.max(
|
|
600
|
+
minTimeOffset,
|
|
601
|
+
this._segments[previousSegmentId].segment.endTime - initialPosition.startTime
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
minTimeOffset = Math.max(minTimeOffset, -initialPosition.startTime);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (nextSegmentId) {
|
|
609
|
+
maxTimeOffset = Math.min(
|
|
610
|
+
maxTimeOffset,
|
|
611
|
+
this._segments[nextSegmentId].segment.startTime - initialPosition.endTime
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}.bind(this));
|
|
615
|
+
|
|
616
|
+
return {
|
|
617
|
+
minTimeOffset: minTimeOffset,
|
|
618
|
+
maxTimeOffset: maxTimeOffset
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Updates a set of dragged segments by the same time offset and refreshes only the visible slice.
|
|
624
|
+
*
|
|
625
|
+
* @param {Array<Segment>} segments
|
|
626
|
+
* @param {Object<String, {startTime: Number, endTime: Number}>} initialPositions
|
|
627
|
+
* @param {Number} timeOffset
|
|
628
|
+
*/
|
|
629
|
+
SegmentsGroup.prototype.dragSegmentsByTimeOffset = function(segments, initialPositions, timeOffset) {
|
|
630
|
+
var hasChanges = false;
|
|
631
|
+
|
|
632
|
+
segments.forEach(function(segment) {
|
|
633
|
+
var initialPosition = initialPositions[segment.id];
|
|
634
|
+
var newStartTime = Utils.roundTime(initialPosition.startTime + timeOffset);
|
|
635
|
+
var newEndTime = Utils.roundTime(initialPosition.endTime + timeOffset);
|
|
636
|
+
|
|
637
|
+
if (segment.startTime !== newStartTime || segment.endTime !== newEndTime) {
|
|
638
|
+
segment.updateTimes(newStartTime, newEndTime);
|
|
639
|
+
hasChanges = true;
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
if (hasChanges) {
|
|
644
|
+
this._updateVisibleSegmentsInView();
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Returns the current visible time range for the view.
|
|
650
|
+
*
|
|
651
|
+
* @returns {{startTime: Number, endTime: Number}}
|
|
652
|
+
*/
|
|
653
|
+
SegmentsGroup.prototype._getVisibleTimeRange = function() {
|
|
654
|
+
var frameOffset = this._view.getFrameOffset();
|
|
655
|
+
var width = this._view.getWidth();
|
|
656
|
+
|
|
657
|
+
return {
|
|
658
|
+
startTime: this._view.pixelsToTime(frameOffset),
|
|
659
|
+
endTime: this._view.pixelsToTime(frameOffset + width)
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Refreshes the rendered segments for the current viewport without forcing an immediate draw.
|
|
665
|
+
*/
|
|
666
|
+
SegmentsGroup.prototype._updateVisibleSegmentsInView = function() {
|
|
667
|
+
var visibleTimeRange = this._getVisibleTimeRange();
|
|
668
|
+
|
|
669
|
+
this.find(visibleTimeRange.startTime, visibleTimeRange.endTime)
|
|
670
|
+
.forEach(this._updateSegment.bind(this));
|
|
671
|
+
this._removeInvisibleSegments(visibleTimeRange.startTime, visibleTimeRange.endTime);
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
SegmentsGroup.prototype.updateSegment = function(segment, newStartX, newEndX, shouldDraw) {
|
|
523
675
|
var newXs = this.manageCollision(segment, newStartX, newEndX);
|
|
524
676
|
|
|
677
|
+
if (Utils.isNullOrUndefined(shouldDraw)) {
|
|
678
|
+
shouldDraw = true;
|
|
679
|
+
}
|
|
680
|
+
|
|
525
681
|
if (!Utils.isNullOrUndefined(newXs.startX)) {
|
|
526
|
-
segment.
|
|
682
|
+
segment.updateTimes(this._view.pixelsToTime(newXs.startX), null);
|
|
527
683
|
}
|
|
528
684
|
|
|
529
685
|
if (!Utils.isNullOrUndefined(newXs.endX)) {
|
|
530
|
-
segment.
|
|
686
|
+
segment.updateTimes(null, this._view.pixelsToTime(newXs.endX));
|
|
531
687
|
}
|
|
532
688
|
|
|
533
689
|
if (newXs) {
|
|
@@ -535,7 +691,9 @@ define([
|
|
|
535
691
|
|
|
536
692
|
this.addToUpdatedSegments(segment);
|
|
537
693
|
|
|
538
|
-
|
|
694
|
+
if (shouldDraw) {
|
|
695
|
+
this._draw();
|
|
696
|
+
}
|
|
539
697
|
}
|
|
540
698
|
};
|
|
541
699
|
|
|
@@ -263,30 +263,7 @@ define([
|
|
|
263
263
|
};
|
|
264
264
|
|
|
265
265
|
SourceGroup.prototype._onSourceGroupHandleDrag = function(draggedElement, leftHandle) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this._view.updateWithAutoScroll(
|
|
269
|
-
function() {
|
|
270
|
-
var pointer = this._view.getPointerPosition();
|
|
271
|
-
var pointerX = pointer ? pointer.x : this._mouseDownX;
|
|
272
|
-
|
|
273
|
-
const diff = this._view.pixelsToTime(pointerX - this._mouseDownX);
|
|
274
|
-
const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
|
|
275
|
-
|
|
276
|
-
if (this._layer.manageSourceMovements(
|
|
277
|
-
[this._source],
|
|
278
|
-
leftHandle ? start + diff + timeOffsetDiff : null,
|
|
279
|
-
leftHandle ? null : end + diff + timeOffsetDiff
|
|
280
|
-
)) {
|
|
281
|
-
this._layer.batchDraw();
|
|
282
|
-
}
|
|
283
|
-
}.bind(this)
|
|
284
|
-
, null, false);
|
|
285
|
-
|
|
286
|
-
return {
|
|
287
|
-
x: draggedElement.absolutePosition().x,
|
|
288
|
-
y: draggedElement.absolutePosition().y
|
|
289
|
-
};
|
|
266
|
+
return this._layer.onSourceHandleDrag(draggedElement, leftHandle);
|
|
290
267
|
};
|
|
291
268
|
|
|
292
269
|
SourceGroup.prototype.update = function() {
|
|
@@ -373,21 +350,16 @@ define([
|
|
|
373
350
|
}
|
|
374
351
|
};
|
|
375
352
|
|
|
376
|
-
SourceGroup.prototype._onHandleDragStart = function() {
|
|
377
|
-
this._initialTimeOffset = this._view.getTimeOffset();
|
|
378
|
-
this._mouseDownX = this._view.getPointerPosition().x;
|
|
379
|
-
this._initialTimes = {
|
|
380
|
-
start: this._source.startTime,
|
|
381
|
-
end: this._source.endTime
|
|
382
|
-
};
|
|
353
|
+
SourceGroup.prototype._onHandleDragStart = function(leftHandle) {
|
|
383
354
|
this._isHandleDragged = true;
|
|
384
355
|
this._hideButtons();
|
|
356
|
+
this._layer.onSourceHandleDragStart(this, leftHandle);
|
|
385
357
|
};
|
|
386
358
|
|
|
387
359
|
SourceGroup.prototype._onHandleDragEnd = function() {
|
|
388
360
|
this._isHandleDragged = false;
|
|
389
361
|
this._showButtons();
|
|
390
|
-
this._layer.
|
|
362
|
+
this._layer.onSourceHandleDragEnd(this);
|
|
391
363
|
};
|
|
392
364
|
|
|
393
365
|
SourceGroup.prototype._addHandles = function(forceCreate) {
|
|
@@ -408,7 +380,7 @@ define([
|
|
|
408
380
|
|
|
409
381
|
this._leftHandle.on('dragstart', function(event) {
|
|
410
382
|
event.cancelBubble = true;
|
|
411
|
-
self._onHandleDragStart(
|
|
383
|
+
self._onHandleDragStart(true);
|
|
412
384
|
});
|
|
413
385
|
|
|
414
386
|
this._leftHandle.on('dragend', function(event) {
|
|
@@ -441,7 +413,7 @@ define([
|
|
|
441
413
|
|
|
442
414
|
this._rightHandle.on('dragstart', function(event) {
|
|
443
415
|
event.cancelBubble = true;
|
|
444
|
-
self._onHandleDragStart(
|
|
416
|
+
self._onHandleDragStart(false);
|
|
445
417
|
});
|
|
446
418
|
|
|
447
419
|
this._rightHandle.on('dragend', function(event) {
|