@checksub_team/peaks_timeline 1.8.2 → 1.9.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 +324 -177
- package/src/line.js +22 -0
- package/src/lines.js +4 -0
- package/src/main.js +12 -2
- package/src/mode-layer.js +77 -30
- package/src/playhead-layer.js +3 -5
- package/src/segment-shape.js +18 -19
- package/src/segment.js +6 -0
- package/src/source-group.js +101 -139
- package/src/source.js +35 -3
- package/src/sources-layer.js +109 -3
- package/src/timeline-sources.js +2 -1
- package/src/timeline-zoomview.js +50 -23
package/src/source-group.js
CHANGED
|
@@ -21,6 +21,9 @@ define([
|
|
|
21
21
|
var SPACING_BETWEEN_PREVIEW_AND_BORDER_RATIO = 0.15;
|
|
22
22
|
var SPACING_BETWEEN_PREVIEWS = 1.5;
|
|
23
23
|
var CORNER_RADIUS = 8;
|
|
24
|
+
var INDICATOR_RADIUS = 4; // px
|
|
25
|
+
var INDICATORS_MARGIN_LEFT = 8; // px
|
|
26
|
+
var INDICATORS_MARGIN_TOP = 12; // px
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Creates a source group for the given source.
|
|
@@ -39,6 +42,7 @@ define([
|
|
|
39
42
|
this._peaks = peaks;
|
|
40
43
|
this._layer = layer;
|
|
41
44
|
this._view = view;
|
|
45
|
+
this._indicators = {};
|
|
42
46
|
|
|
43
47
|
var self = this;
|
|
44
48
|
|
|
@@ -54,16 +58,16 @@ define([
|
|
|
54
58
|
|
|
55
59
|
this._group = new Konva.Group({
|
|
56
60
|
x: this._x,
|
|
61
|
+
sourceId: this._source.id,
|
|
57
62
|
draggable: this._source.draggable,
|
|
58
63
|
dragBoundFunc: function() {
|
|
59
|
-
return
|
|
60
|
-
x: this.absolutePosition().x,
|
|
61
|
-
y: this.absolutePosition().y
|
|
62
|
-
};
|
|
64
|
+
return self._layer.onSourcesGroupDrag(this);
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
|
|
66
|
-
this._group.on('dragstart', this.
|
|
68
|
+
this._group.on('dragstart', this._layer.onSourcesGroupDragStart.bind(this._layer));
|
|
69
|
+
this._group.on('dragend', this._layer.onSourcesGroupDragEnd.bind(this._layer));
|
|
70
|
+
|
|
67
71
|
this._group.on('mouseover', function() {
|
|
68
72
|
self._view.setHoveredElement(self);
|
|
69
73
|
if (self._view.getCurrentMode() === 'cut') {
|
|
@@ -78,7 +82,6 @@ define([
|
|
|
78
82
|
self.toggleResizing(true);
|
|
79
83
|
}
|
|
80
84
|
});
|
|
81
|
-
this._group.on('dragend', this._onSourceGroupDragEnd.bind(this));
|
|
82
85
|
|
|
83
86
|
this._group.add(new Konva.Group());
|
|
84
87
|
|
|
@@ -94,6 +97,13 @@ define([
|
|
|
94
97
|
this._addHandles();
|
|
95
98
|
|
|
96
99
|
this.setWrapping(source.wrapped);
|
|
100
|
+
|
|
101
|
+
this._setSelected();
|
|
102
|
+
|
|
103
|
+
this._indicatorsGroup = new Konva.Group();
|
|
104
|
+
this._group.add(this._indicatorsGroup);
|
|
105
|
+
|
|
106
|
+
this.createIndicators();
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
// SourceGroup.prototype.rescale = function() {
|
|
@@ -114,78 +124,25 @@ define([
|
|
|
114
124
|
// });
|
|
115
125
|
// };
|
|
116
126
|
|
|
117
|
-
SourceGroup.prototype.
|
|
118
|
-
this._dragged = true;
|
|
119
|
-
this._mouseDownX = this._view.getPointerPosition().x;
|
|
120
|
-
this._initialStartTime = this._source.startTime;
|
|
121
|
-
this._initialStartPixel = this._view.timeToPixels(this._initialStartTime);
|
|
122
|
-
this._initialEndTime = this._source.endTime;
|
|
123
|
-
this._initialEndPixel = this._view.timeToPixels(this._initialEndTime);
|
|
124
|
-
this._initialFrameOffset = this._view.getFrameOffset();
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
SourceGroup.prototype._onSourceGroupDragEnd = function() {
|
|
127
|
+
SourceGroup.prototype.prepareDragEnd = function() {
|
|
128
128
|
var handleWidth = Math.min(this._peaks.options.sourceHandleWidth, this._width / 2);
|
|
129
129
|
|
|
130
130
|
this._leftHandle.width(handleWidth);
|
|
131
131
|
this._rightHandle.width(handleWidth);
|
|
132
132
|
this._rightHandle.x(this._width - handleWidth);
|
|
133
|
-
|
|
134
|
-
this._view.drawSourcesLayer();
|
|
135
|
-
|
|
136
|
-
this._dragged = false;
|
|
137
|
-
this._view.updateTimelineLength();
|
|
138
|
-
|
|
139
|
-
this._peaks.emit('sources.updated', [this._source]);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
SourceGroup.prototype._onSourceGroupDrag = function(draggedElement) {
|
|
143
|
-
var self = this;
|
|
144
|
-
|
|
145
|
-
var pos = this._view.updateWithAutoScroll(
|
|
146
|
-
draggedElement,
|
|
147
|
-
function() {
|
|
148
|
-
var mousePos = Math.min(
|
|
149
|
-
self._view.getWidth() - self._peaks.options.autoScrollThreshold * self._view.getWidth(),
|
|
150
|
-
Math.max(
|
|
151
|
-
0,
|
|
152
|
-
self._view.getPointerPosition().x
|
|
153
|
-
)
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
var diff = mousePos - self._mouseDownX;
|
|
157
|
-
|
|
158
|
-
self._layer.updateSource(
|
|
159
|
-
self._source,
|
|
160
|
-
self._initialStartPixel + diff + (self._view.getFrameOffset() - self._initialFrameOffset),
|
|
161
|
-
self._initialEndPixel + diff + (self._view.getFrameOffset() - self._initialFrameOffset),
|
|
162
|
-
self._view.getPointerPosition().y
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
self._view.setTimelineLength(
|
|
166
|
-
self._view.timeToPixels(self._source.endTime) + self._view.getWidth()
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
x: pos.x,
|
|
173
|
-
y: pos.y
|
|
174
|
-
};
|
|
175
133
|
};
|
|
176
134
|
|
|
177
135
|
SourceGroup.prototype._onSourceGroupHandleDrag = function(draggedElement, dragPos, leftHandle) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var pos = this._view.updateWithAutoScroll(
|
|
181
|
-
draggedElement,
|
|
136
|
+
this._view.updateWithAutoScroll(
|
|
182
137
|
function() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
leftHandle ? dragPos.x +
|
|
186
|
-
leftHandle ? null : dragPos.x + draggedElement.width() +
|
|
187
|
-
)
|
|
188
|
-
|
|
138
|
+
if (this._layer.updateSource(
|
|
139
|
+
this._source,
|
|
140
|
+
leftHandle ? dragPos.x + this._view.getFrameOffset() : null,
|
|
141
|
+
leftHandle ? null : dragPos.x + draggedElement.width() + this._view.getFrameOffset()
|
|
142
|
+
)) {
|
|
143
|
+
this._layer.draw();
|
|
144
|
+
}
|
|
145
|
+
}.bind(this)
|
|
189
146
|
);
|
|
190
147
|
|
|
191
148
|
this._view.setTimelineLength(
|
|
@@ -193,8 +150,8 @@ define([
|
|
|
193
150
|
);
|
|
194
151
|
|
|
195
152
|
return {
|
|
196
|
-
x:
|
|
197
|
-
y:
|
|
153
|
+
x: draggedElement.absolutePosition().x,
|
|
154
|
+
y: draggedElement.absolutePosition().y
|
|
198
155
|
};
|
|
199
156
|
};
|
|
200
157
|
|
|
@@ -264,13 +221,6 @@ define([
|
|
|
264
221
|
});
|
|
265
222
|
|
|
266
223
|
if (this._source.resizable) {
|
|
267
|
-
this._leftHandle.on('dragend', function() {
|
|
268
|
-
if (this._scrollingInterval) {
|
|
269
|
-
clearInterval(this._scrollingInterval);
|
|
270
|
-
this._scrollingInterval = null;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
|
|
274
224
|
this._leftHandle.on('mouseover', function() {
|
|
275
225
|
self._view.setCursor('ew-resize');
|
|
276
226
|
});
|
|
@@ -294,13 +244,6 @@ define([
|
|
|
294
244
|
});
|
|
295
245
|
|
|
296
246
|
if (this._source.resizable) {
|
|
297
|
-
this._rightHandle.on('dragend', function() {
|
|
298
|
-
if (this._scrollingInterval) {
|
|
299
|
-
clearInterval(this._scrollingInterval);
|
|
300
|
-
this._scrollingInterval = null;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
|
|
304
247
|
this._rightHandle.on('mouseover', function() {
|
|
305
248
|
self._view.setCursor('ew-resize');
|
|
306
249
|
});
|
|
@@ -410,13 +353,6 @@ define([
|
|
|
410
353
|
var unwrap = new Konva.Group({
|
|
411
354
|
width: this._width,
|
|
412
355
|
height: this._unwrappedHeight,
|
|
413
|
-
draggable: this._source.draggable,
|
|
414
|
-
dragBoundFunc: function() {
|
|
415
|
-
return {
|
|
416
|
-
x: this.absolutePosition().x,
|
|
417
|
-
y: this.absolutePosition().y
|
|
418
|
-
};
|
|
419
|
-
},
|
|
420
356
|
clipFunc: function(ctx) {
|
|
421
357
|
self.drawSourceShape(ctx, null, true);
|
|
422
358
|
}
|
|
@@ -429,17 +365,6 @@ define([
|
|
|
429
365
|
unwrap.on('mouseout', function() {
|
|
430
366
|
self._view.setCursor('default');
|
|
431
367
|
});
|
|
432
|
-
|
|
433
|
-
unwrap.on('dragstart', function() {
|
|
434
|
-
this._scrollInterval = null;
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
unwrap.on('dragend', function() {
|
|
438
|
-
if (this._scrollingInterval) {
|
|
439
|
-
clearInterval(this._scrollingInterval);
|
|
440
|
-
this._scrollingInterval = null;
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
368
|
}
|
|
444
369
|
|
|
445
370
|
var background = new Konva.Group();
|
|
@@ -448,10 +373,6 @@ define([
|
|
|
448
373
|
fill: this._source.backgroundColor,
|
|
449
374
|
sceneFunc: function(ctx, shape) {
|
|
450
375
|
self.drawSourceShape(ctx, shape, true);
|
|
451
|
-
},
|
|
452
|
-
draggable: this._source.draggable,
|
|
453
|
-
dragBoundFunc: function() {
|
|
454
|
-
return self._onSourceGroupDrag(this);
|
|
455
376
|
}
|
|
456
377
|
}));
|
|
457
378
|
|
|
@@ -490,13 +411,6 @@ define([
|
|
|
490
411
|
var wrap = new Konva.Group({
|
|
491
412
|
width: this._width,
|
|
492
413
|
height: this._wrappedHeight,
|
|
493
|
-
draggable: this._source.draggable,
|
|
494
|
-
dragBoundFunc: function() {
|
|
495
|
-
return {
|
|
496
|
-
x: this.absolutePosition().x,
|
|
497
|
-
y: this.absolutePosition().y
|
|
498
|
-
};
|
|
499
|
-
},
|
|
500
414
|
clipFunc: function(ctx) {
|
|
501
415
|
self.drawSourceShape(ctx, null, true);
|
|
502
416
|
}
|
|
@@ -509,17 +423,6 @@ define([
|
|
|
509
423
|
wrap.on('mouseout', function() {
|
|
510
424
|
self._view.setCursor('default');
|
|
511
425
|
});
|
|
512
|
-
|
|
513
|
-
wrap.on('dragstart', function() {
|
|
514
|
-
this._scrollInterval = null;
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
wrap.on('dragend', function() {
|
|
518
|
-
if (this._scrollingInterval) {
|
|
519
|
-
clearInterval(this._scrollingInterval);
|
|
520
|
-
this._scrollingInterval = null;
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
426
|
}
|
|
524
427
|
|
|
525
428
|
var background = new Konva.Group();
|
|
@@ -528,10 +431,6 @@ define([
|
|
|
528
431
|
fill: this._source.backgroundColor,
|
|
529
432
|
sceneFunc: function(ctx, shape) {
|
|
530
433
|
self.drawSourceShape(ctx, shape, true);
|
|
531
|
-
},
|
|
532
|
-
draggable: this._source.draggable,
|
|
533
|
-
dragBoundFunc: function() {
|
|
534
|
-
return self._onSourceGroupDrag(this);
|
|
535
434
|
}
|
|
536
435
|
}));
|
|
537
436
|
|
|
@@ -842,9 +741,9 @@ define([
|
|
|
842
741
|
});
|
|
843
742
|
};
|
|
844
743
|
|
|
845
|
-
SourceGroup.prototype.
|
|
744
|
+
SourceGroup.prototype._setSelected = function() {
|
|
846
745
|
if (this._border) {
|
|
847
|
-
if (
|
|
746
|
+
if (this._source._selected) {
|
|
848
747
|
this._border.fill(this._source.selectedColor);
|
|
849
748
|
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
850
749
|
}
|
|
@@ -861,7 +760,7 @@ define([
|
|
|
861
760
|
});
|
|
862
761
|
|
|
863
762
|
if (unwrap_background) {
|
|
864
|
-
if (
|
|
763
|
+
if (this._source._selected) {
|
|
865
764
|
unwrap_background.stroke(this._source.selectedColor);
|
|
866
765
|
unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
867
766
|
}
|
|
@@ -878,7 +777,7 @@ define([
|
|
|
878
777
|
});
|
|
879
778
|
|
|
880
779
|
if (wrap_background) {
|
|
881
|
-
if (
|
|
780
|
+
if (this._source._selected) {
|
|
882
781
|
wrap_background.stroke(this._source.selectedColor);
|
|
883
782
|
wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
884
783
|
}
|
|
@@ -888,8 +787,7 @@ define([
|
|
|
888
787
|
}
|
|
889
788
|
}
|
|
890
789
|
}
|
|
891
|
-
|
|
892
|
-
this._view.drawSourcesLayer();
|
|
790
|
+
// this.setDraggingBehavior();
|
|
893
791
|
};
|
|
894
792
|
|
|
895
793
|
SourceGroup.prototype.updatePreviews = function() {
|
|
@@ -1023,10 +921,6 @@ define([
|
|
|
1023
921
|
return this._group.visible();
|
|
1024
922
|
};
|
|
1025
923
|
|
|
1026
|
-
SourceGroup.prototype.isDragged = function() {
|
|
1027
|
-
return this._dragged;
|
|
1028
|
-
};
|
|
1029
|
-
|
|
1030
924
|
SourceGroup.prototype.isCuttable = function() {
|
|
1031
925
|
return this._source.cuttable;
|
|
1032
926
|
};
|
|
@@ -1039,5 +933,73 @@ define([
|
|
|
1039
933
|
this._group.destroy();
|
|
1040
934
|
};
|
|
1041
935
|
|
|
936
|
+
SourceGroup.prototype.getLine = function() {
|
|
937
|
+
return this._source.position;
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
SourceGroup.prototype.createIndicators = function() {
|
|
941
|
+
var newIndicatorsColors = this._source.indicators;
|
|
942
|
+
|
|
943
|
+
var oldIndicators = this._indicators;
|
|
944
|
+
var newIndicators = {};
|
|
945
|
+
|
|
946
|
+
if (newIndicatorsColors) {
|
|
947
|
+
newIndicatorsColors.forEach(function(indicatorColor) {
|
|
948
|
+
var oldIndicator = oldIndicators[indicatorColor];
|
|
949
|
+
|
|
950
|
+
if (oldIndicator) {
|
|
951
|
+
newIndicators[indicatorColor] = oldIndicator;
|
|
952
|
+
delete oldIndicators[indicatorColor];
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
newIndicators[indicatorColor] = null;
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
for (var color in oldIndicators) {
|
|
960
|
+
if (Utils.objectHasProperty(oldIndicators, color)) {
|
|
961
|
+
oldIndicators[color].destroy();
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
this._indicators = Object.keys(newIndicators)
|
|
967
|
+
.sort()
|
|
968
|
+
.reverse()
|
|
969
|
+
.reduce(function(objEntries, key) {
|
|
970
|
+
objEntries[key] = newIndicators[key];
|
|
971
|
+
return objEntries;
|
|
972
|
+
}, {}
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
this._createIndicators();
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
SourceGroup.prototype._createIndicators = function() {
|
|
979
|
+
var currentX = 0;
|
|
980
|
+
var zIndex = 0;
|
|
981
|
+
|
|
982
|
+
for (var color in this._indicators) {
|
|
983
|
+
if (Utils.objectHasProperty(this._indicators, color)) {
|
|
984
|
+
if (!this._indicators[color]) {
|
|
985
|
+
this._indicators[color] = new Konva.Circle({
|
|
986
|
+
radius: INDICATOR_RADIUS,
|
|
987
|
+
fill: color,
|
|
988
|
+
strokeEnabled: false
|
|
989
|
+
});
|
|
990
|
+
this._indicatorsGroup.add(this._indicators[color]);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
this._indicators[color].x(currentX);
|
|
994
|
+
this._indicators[color].zIndex(zIndex);
|
|
995
|
+
currentX -= INDICATOR_RADIUS;
|
|
996
|
+
zIndex += 1;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
this._indicatorsGroup.offsetX(currentX - INDICATORS_MARGIN_LEFT);
|
|
1001
|
+
this._indicatorsGroup.offsetY(-INDICATORS_MARGIN_TOP);
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1042
1004
|
return SourceGroup;
|
|
1043
1005
|
});
|
package/src/source.js
CHANGED
|
@@ -246,6 +246,10 @@ define([
|
|
|
246
246
|
else if (options.wrapping === 'complete') {
|
|
247
247
|
options.wrapped = false;
|
|
248
248
|
}
|
|
249
|
+
|
|
250
|
+
if (Utils.isNullOrUndefined(options.indicators)) {
|
|
251
|
+
options.indicators = [];
|
|
252
|
+
}
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
/**
|
|
@@ -266,13 +270,14 @@ define([
|
|
|
266
270
|
* @param {Number} position Position of the source on the timeline.
|
|
267
271
|
* Correspond to the index of the line.
|
|
268
272
|
* @param {Boolean} segments If <code>true</code> this source will integrate the segments.
|
|
273
|
+
* @param {Array<String>} indicators Array containing the colors of all indicators.
|
|
269
274
|
*/
|
|
270
275
|
|
|
271
276
|
function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
|
|
272
277
|
subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
|
|
273
278
|
borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor,
|
|
274
279
|
textPosition, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable,
|
|
275
|
-
cuttable, deletable, wrapping, previewHeight, binaryHeight) {
|
|
280
|
+
cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators) {
|
|
276
281
|
var opts = {
|
|
277
282
|
title: title,
|
|
278
283
|
url: url,
|
|
@@ -305,7 +310,8 @@ define([
|
|
|
305
310
|
deletable: deletable,
|
|
306
311
|
wrapping: wrapping,
|
|
307
312
|
previewHeight: previewHeight,
|
|
308
|
-
binaryHeight: binaryHeight
|
|
313
|
+
binaryHeight: binaryHeight,
|
|
314
|
+
indicators: indicators
|
|
309
315
|
};
|
|
310
316
|
|
|
311
317
|
validateSource(peaks, opts, 'add()');
|
|
@@ -346,7 +352,9 @@ define([
|
|
|
346
352
|
this._wrapping = opts.wrapping;
|
|
347
353
|
this._previewHeight = opts.previewHeight;
|
|
348
354
|
this._binaryHeight = opts.binaryHeight;
|
|
355
|
+
this._indicators = opts.indicators;
|
|
349
356
|
this._minSize = peaks.options.minSourceSize;
|
|
357
|
+
this._selected = false;
|
|
350
358
|
}
|
|
351
359
|
|
|
352
360
|
Object.defineProperties(Source.prototype, {
|
|
@@ -650,6 +658,12 @@ define([
|
|
|
650
658
|
this._binaryHeight = binaryHeight;
|
|
651
659
|
}
|
|
652
660
|
},
|
|
661
|
+
indicators: {
|
|
662
|
+
enumerable: true,
|
|
663
|
+
get: function() {
|
|
664
|
+
return this._indicators;
|
|
665
|
+
}
|
|
666
|
+
},
|
|
653
667
|
minSize: {
|
|
654
668
|
enumerable: true,
|
|
655
669
|
get: function() {
|
|
@@ -806,7 +820,8 @@ define([
|
|
|
806
820
|
deletable: this.deletable,
|
|
807
821
|
wrapping: this.wrapping,
|
|
808
822
|
previewHeight: this.previewHeight,
|
|
809
|
-
binaryHeight: this.binaryHeight
|
|
823
|
+
binaryHeight: this.binaryHeight,
|
|
824
|
+
indicators: this.indicators
|
|
810
825
|
};
|
|
811
826
|
|
|
812
827
|
Utils.extend(opts, options);
|
|
@@ -845,10 +860,16 @@ define([
|
|
|
845
860
|
this._wrapping = opts.wrapping;
|
|
846
861
|
this._previewHeight = opts.previewHeight;
|
|
847
862
|
this._binaryHeight = opts.binaryHeight;
|
|
863
|
+
this._indicators = opts.indicators;
|
|
848
864
|
|
|
849
865
|
this._peaks.emit('source.update', this);
|
|
850
866
|
};
|
|
851
867
|
|
|
868
|
+
Source.prototype.setSelected = function(selected) {
|
|
869
|
+
this._selected = selected;
|
|
870
|
+
this._peaks.emit('source.update', this);
|
|
871
|
+
};
|
|
872
|
+
|
|
852
873
|
/**
|
|
853
874
|
* Returns <code>true</code> if the source overlaps a given time region.
|
|
854
875
|
*
|
|
@@ -862,5 +883,16 @@ define([
|
|
|
862
883
|
return this._startTime < endTime && startTime < this._endTime;
|
|
863
884
|
};
|
|
864
885
|
|
|
886
|
+
/**
|
|
887
|
+
* Update the indicators of this source.
|
|
888
|
+
*
|
|
889
|
+
* @param {Array<String>} newIndicators The new indicators.
|
|
890
|
+
*/
|
|
891
|
+
|
|
892
|
+
Source.prototype.setIndicators = function(newIndicators) {
|
|
893
|
+
this._indicators = newIndicators;
|
|
894
|
+
this._peaks.emit('source.setIndicators', this);
|
|
895
|
+
};
|
|
896
|
+
|
|
865
897
|
return Source;
|
|
866
898
|
});
|
package/src/sources-layer.js
CHANGED
|
@@ -58,6 +58,7 @@ define([
|
|
|
58
58
|
this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
|
|
59
59
|
this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
|
|
60
60
|
this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
|
|
61
|
+
this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
SourcesLayer.prototype.fitToView = function() {
|
|
@@ -280,6 +281,15 @@ define([
|
|
|
280
281
|
return sourceGroup;
|
|
281
282
|
};
|
|
282
283
|
|
|
284
|
+
SourcesLayer.prototype.setIndicators = function(source) {
|
|
285
|
+
var sourceGroup = this._sourcesGroup[source.id];
|
|
286
|
+
|
|
287
|
+
if (sourceGroup) {
|
|
288
|
+
sourceGroup.createIndicators();
|
|
289
|
+
this._layer.draw();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
283
293
|
/**
|
|
284
294
|
* Updates the positions of all displayed sources in the view.
|
|
285
295
|
*
|
|
@@ -310,6 +320,95 @@ define([
|
|
|
310
320
|
}
|
|
311
321
|
};
|
|
312
322
|
|
|
323
|
+
SourcesLayer.prototype.onSourcesGroupDragStart = function(element) {
|
|
324
|
+
this._initialFrameOffset = this._view.getFrameOffset();
|
|
325
|
+
this._mouseDownX = this._view.getPointerPosition().x;
|
|
326
|
+
this._selectedElements = {};
|
|
327
|
+
|
|
328
|
+
const draggedElementId = element.currentTarget.attrs.sourceId;
|
|
329
|
+
const shouldDragSelectedElements = Object.keys(this._view.getSelectedElements()).includes(
|
|
330
|
+
draggedElementId
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
this._nonSelectedElement = shouldDragSelectedElements ?
|
|
334
|
+
null :
|
|
335
|
+
[this._sourcesGroup[draggedElementId].getSource()];
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
SourcesLayer.prototype.onSourcesGroupDragEnd = function() {
|
|
339
|
+
const updatedSources = (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).map(
|
|
340
|
+
function(source) {
|
|
341
|
+
const sourceGroup = this._sourcesGroup[source.id];
|
|
342
|
+
|
|
343
|
+
if (sourceGroup) {
|
|
344
|
+
sourceGroup.prepareDragEnd();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return source;
|
|
348
|
+
}.bind(this)
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
this._view.drawSourcesLayer();
|
|
352
|
+
this._view.updateTimelineLength();
|
|
353
|
+
|
|
354
|
+
this._selectedElements = {};
|
|
355
|
+
|
|
356
|
+
this._peaks.emit('sources.updated', updatedSources);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
SourcesLayer.prototype.onSourcesGroupDrag = function(draggedElement) {
|
|
360
|
+
this._view.updateWithAutoScroll(this._updateSourcesGroup.bind(this));
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
x: draggedElement.absolutePosition().x,
|
|
364
|
+
y: draggedElement.absolutePosition().y
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
SourcesLayer.prototype._updateSourcesGroup = function() {
|
|
369
|
+
var mousePos = Math.min(
|
|
370
|
+
this._view.getWidth() - this._peaks.options.autoScrollThreshold * this._view.getWidth(),
|
|
371
|
+
Math.max(
|
|
372
|
+
0,
|
|
373
|
+
this._view.getPointerPosition().x
|
|
374
|
+
)
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const diff = mousePos - this._mouseDownX;
|
|
378
|
+
const currentFrameOffset = this._view.getFrameOffset();
|
|
379
|
+
const mousePosY = this._view.getPointerPosition().y;
|
|
380
|
+
var newEnd = 0;
|
|
381
|
+
var shouldRedraw = false;
|
|
382
|
+
|
|
383
|
+
(this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function(source) {
|
|
384
|
+
if (!this._selectedElements[source.id]) {
|
|
385
|
+
this._selectedElements[source.id] = {
|
|
386
|
+
startX: this._view.timeToPixels(source.startTime),
|
|
387
|
+
endX: this._view.timeToPixels(source.endTime)
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const { startX, endX } = this._selectedElements[source.id];
|
|
392
|
+
|
|
393
|
+
newEnd = Math.max(newEnd, source.endTime);
|
|
394
|
+
|
|
395
|
+
shouldRedraw = this.updateSource(
|
|
396
|
+
source,
|
|
397
|
+
startX + diff + (currentFrameOffset - this._initialFrameOffset),
|
|
398
|
+
endX + diff + (currentFrameOffset - this._initialFrameOffset),
|
|
399
|
+
mousePosY
|
|
400
|
+
) || shouldRedraw;
|
|
401
|
+
}.bind(this));
|
|
402
|
+
|
|
403
|
+
if (shouldRedraw) {
|
|
404
|
+
this.draw();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
this._view.setTimelineLength(
|
|
408
|
+
this._view.timeToPixels(newEnd) + this._view.getWidth()
|
|
409
|
+
);
|
|
410
|
+
};
|
|
411
|
+
|
|
313
412
|
SourcesLayer.prototype.findSources = function(startTime, endTime) {
|
|
314
413
|
var sources = this._peaks.sources.find(startTime, endTime);
|
|
315
414
|
var positions = this._lines.getVisibleLines();
|
|
@@ -347,8 +446,9 @@ define([
|
|
|
347
446
|
newXs.updateWidth
|
|
348
447
|
);
|
|
349
448
|
|
|
350
|
-
|
|
449
|
+
return true;
|
|
351
450
|
}
|
|
451
|
+
return false;
|
|
352
452
|
};
|
|
353
453
|
|
|
354
454
|
SourcesLayer.prototype.manageVerticalPosition = function(source, newY) {
|
|
@@ -400,8 +500,7 @@ define([
|
|
|
400
500
|
if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
|
|
401
501
|
var source = this._sourcesGroup[sourceId].getSource();
|
|
402
502
|
|
|
403
|
-
if (!this._isSourceVisible(source, startTime, endTime)
|
|
404
|
-
&& !this._sourcesGroup[sourceId].isDragged()) {
|
|
503
|
+
if (!this._isSourceVisible(source, startTime, endTime)) {
|
|
405
504
|
this._removeSource(source);
|
|
406
505
|
count++;
|
|
407
506
|
}
|
|
@@ -506,6 +605,10 @@ define([
|
|
|
506
605
|
return this._sourcesGroup[sourceId];
|
|
507
606
|
};
|
|
508
607
|
|
|
608
|
+
SourcesLayer.prototype.getSourcesOnLineAfter = function(lineId, time) {
|
|
609
|
+
return this._lines.getSourcesOnLineAfter(lineId, time);
|
|
610
|
+
};
|
|
611
|
+
|
|
509
612
|
SourcesLayer.prototype._sourcesOverlapped = function(source1, source2) {
|
|
510
613
|
var endsLater = (source1.startTime < source2.startTime)
|
|
511
614
|
&& (source1.endTime > source2.startTime);
|
|
@@ -565,9 +668,12 @@ define([
|
|
|
565
668
|
this._peaks.off('sources.destroy', this._onSourcesDestroy);
|
|
566
669
|
this._peaks.off('sources.show', this._onSourcesShow);
|
|
567
670
|
this._peaks.off('sources.hide', this._onSourcesHide);
|
|
671
|
+
this._peaks.off('source.update', this._onSourceUpdate);
|
|
568
672
|
this._peaks.off('data.retrieved', this._onDataRetrieved);
|
|
569
673
|
this._peaks.off('sources.refresh', this._onSourcesRefresh);
|
|
570
674
|
this._peaks.off('segments.show', this._onSegmentsShow);
|
|
675
|
+
this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
|
|
676
|
+
this._peaks.off('source.setIndicators', this.setIndicators);
|
|
571
677
|
};
|
|
572
678
|
|
|
573
679
|
SourcesLayer.prototype.getHeight = function() {
|