@checksub_team/peaks_timeline 1.4.25 → 1.4.28
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 +269 -85
- package/src/line.js +38 -1
- package/src/lines.js +62 -5
- package/src/main.js +30 -3
- package/src/mode-layer.js +47 -17
- package/src/playhead-layer.js +36 -26
- package/src/segment-shape.js +10 -1
- package/src/segment.js +30 -6
- package/src/segments-group.js +30 -16
- package/src/source.js +1 -1
- package/src/sources-layer.js +39 -8
- package/src/timeline-segments.js +7 -5
- package/src/timeline-zoomview.js +13 -1
package/src/line.js
CHANGED
|
@@ -91,6 +91,43 @@ define([
|
|
|
91
91
|
return this._height;
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
Line.prototype.changeHeight = function(from, to) {
|
|
95
|
+
if (this._sourceHeights[from]) {
|
|
96
|
+
var oldHeight = this._height;
|
|
97
|
+
|
|
98
|
+
if (this._sourceHeights[to]) {
|
|
99
|
+
this._sourceHeights[to] += this._sourceHeights[from];
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this._sourceHeights[to] = this._sourceHeights[from];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (to > this._height) {
|
|
106
|
+
this._height = to;
|
|
107
|
+
}
|
|
108
|
+
else if (from === this._height) {
|
|
109
|
+
this._height = 0;
|
|
110
|
+
for (var height in this._sourceHeights) {
|
|
111
|
+
if (Utils.objectHasProperty(this._sourceHeights, height)) {
|
|
112
|
+
var parsedHeight = parseInt(height, 10);
|
|
113
|
+
|
|
114
|
+
if (parsedHeight !== from) {
|
|
115
|
+
if (parsedHeight > this._height) {
|
|
116
|
+
this._height = parsedHeight;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (this._height !== oldHeight) {
|
|
124
|
+
this._peaks.emit('line.heightChanged', this._position);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
delete this._sourceHeights[from];
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
94
131
|
Line.prototype.updateLineHeight = function(sourceGroup, action) {
|
|
95
132
|
var oldHeight = this._height;
|
|
96
133
|
var sourceGroupHeight;
|
|
@@ -127,7 +164,7 @@ define([
|
|
|
127
164
|
if (Utils.objectHasProperty(this._sourceHeights, height)) {
|
|
128
165
|
var parsedHeight = parseInt(height, 10);
|
|
129
166
|
|
|
130
|
-
if (
|
|
167
|
+
if (parsedHeight > this._height) {
|
|
131
168
|
this._height = parsedHeight;
|
|
132
169
|
}
|
|
133
170
|
}
|
package/src/lines.js
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
define([
|
|
10
|
+
'./segments-group',
|
|
10
11
|
'./line',
|
|
11
12
|
'./line-indicator',
|
|
12
13
|
'./utils'
|
|
13
14
|
], function(
|
|
15
|
+
SegmentsGroup,
|
|
14
16
|
Line,
|
|
15
17
|
LineIndicator,
|
|
16
18
|
Utils) {
|
|
@@ -26,6 +28,8 @@ define([
|
|
|
26
28
|
this._areSourceInteractionsAllowed = true;
|
|
27
29
|
this._areSegmentInteractionsAllowed = true;
|
|
28
30
|
|
|
31
|
+
this._segmentsGroups = {};
|
|
32
|
+
|
|
29
33
|
this._lineId = 0;
|
|
30
34
|
|
|
31
35
|
this._lineIndicator = new LineIndicator(
|
|
@@ -37,8 +41,46 @@ define([
|
|
|
37
41
|
this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
|
|
38
42
|
this._peaks.on('line.add', this._onLineAdd.bind(this));
|
|
39
43
|
this._peaks.on('line.remove', this._onLineRemove.bind(this));
|
|
44
|
+
|
|
45
|
+
this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
|
|
46
|
+
this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
|
|
47
|
+
this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
|
|
48
|
+
this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
|
|
49
|
+
this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
|
|
40
50
|
}
|
|
41
51
|
|
|
52
|
+
Lines.prototype._onSegmentsAdd = function(segments) {
|
|
53
|
+
var self = this;
|
|
54
|
+
|
|
55
|
+
segments.forEach(function(segment) {
|
|
56
|
+
if (!self._segmentsGroups[segment.line]) {
|
|
57
|
+
self._segmentsGroups[segment.line] = new SegmentsGroup(self._peaks, self._view, true);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
self._segmentsGroups[segment.line].onSegmentsAdd([segment]);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
Lines.prototype._onSegmentsUpdate = function(segment) {
|
|
65
|
+
this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
Lines.prototype._onSegmentUpdated = function(segment) {
|
|
69
|
+
this._segmentsGroups[segment.line].onSegmentUpdated();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
Lines.prototype._onSegmentsRemove = function(segments) {
|
|
73
|
+
var self = this;
|
|
74
|
+
|
|
75
|
+
segments.forEach(function(segment) {
|
|
76
|
+
self._segmentsGroups[segment.line].onSegmentsRemove([segment]);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
Lines.prototype._onSegmentsRemoveAll = function(lineId) {
|
|
81
|
+
this._segmentsGroups[lineId].onSegmentsRemoveAll();
|
|
82
|
+
};
|
|
83
|
+
|
|
42
84
|
Lines.prototype._onLineHeightChanged = function(position) {
|
|
43
85
|
this._updateLinesPosition(position);
|
|
44
86
|
this._view.updateTimeline();
|
|
@@ -57,6 +99,16 @@ define([
|
|
|
57
99
|
this._updateLinesPosition(position, lineNewY);
|
|
58
100
|
};
|
|
59
101
|
|
|
102
|
+
Lines.prototype.changeLineHeight = function(from, to) {
|
|
103
|
+
for (var position in this._linesByPosition) {
|
|
104
|
+
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
105
|
+
if (!this._linesByPosition[position].isSegmentsLine()) {
|
|
106
|
+
this._linesByPosition[position].changeHeight(from, to);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
60
112
|
Lines.prototype.addSourceGroup = function(sourceGroup, position) {
|
|
61
113
|
if (!this._linesByPosition[position]) {
|
|
62
114
|
this._createLine(position);
|
|
@@ -68,12 +120,11 @@ define([
|
|
|
68
120
|
this._linesBySourceId[sourceGroup.getSource().id] = this._linesByPosition[position];
|
|
69
121
|
};
|
|
70
122
|
|
|
71
|
-
Lines.prototype.addSegments = function(
|
|
123
|
+
Lines.prototype.addSegments = function(lineId, position) {
|
|
72
124
|
this._createLine(position);
|
|
73
125
|
|
|
74
126
|
this._linesByPosition[position].allowInteractions(this._areSegmentInteractionsAllowed);
|
|
75
|
-
this._linesByPosition[position].addSegments(
|
|
76
|
-
this._segmentsLine = this._linesByPosition[position];
|
|
127
|
+
this._linesByPosition[position].addSegments(this._segmentsGroups[lineId]);
|
|
77
128
|
|
|
78
129
|
this._setInteractions(position);
|
|
79
130
|
|
|
@@ -120,6 +171,10 @@ define([
|
|
|
120
171
|
return positions;
|
|
121
172
|
};
|
|
122
173
|
|
|
174
|
+
Lines.prototype.getSegmentsGroups = function() {
|
|
175
|
+
return this._segmentsGroups;
|
|
176
|
+
};
|
|
177
|
+
|
|
123
178
|
Lines.prototype.addToLayer = function(layer) {
|
|
124
179
|
for (var position in this._linesByPosition) {
|
|
125
180
|
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
@@ -292,8 +347,10 @@ define([
|
|
|
292
347
|
};
|
|
293
348
|
|
|
294
349
|
Lines.prototype.updateSegments = function(frameStartTime, frameEndTime) {
|
|
295
|
-
|
|
296
|
-
this.
|
|
350
|
+
for (var lineId in this._segmentsGroups) {
|
|
351
|
+
if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
|
|
352
|
+
this._segmentsGroups[lineId].updateSegments(frameStartTime, frameEndTime);
|
|
353
|
+
}
|
|
297
354
|
}
|
|
298
355
|
};
|
|
299
356
|
|
package/src/main.js
CHANGED
|
@@ -233,7 +233,7 @@ define([
|
|
|
233
233
|
lineHeight: 80,
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
|
-
*
|
|
236
|
+
* Height of a segment, in pixels.
|
|
237
237
|
*/
|
|
238
238
|
segmentHeight: 32,
|
|
239
239
|
|
|
@@ -596,8 +596,18 @@ define([
|
|
|
596
596
|
this.sources.hideById(sourceId);
|
|
597
597
|
};
|
|
598
598
|
|
|
599
|
-
Peaks.prototype.showSegments = function(position) {
|
|
600
|
-
this.segments.addSegmentsToPosition(position);
|
|
599
|
+
Peaks.prototype.showSegments = function(lineId, position) {
|
|
600
|
+
this.segments.addSegmentsToPosition(lineId, position);
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Destroy a segment from the {@link Peaks} instance.
|
|
605
|
+
*
|
|
606
|
+
* @param {String} segmentId
|
|
607
|
+
*/
|
|
608
|
+
|
|
609
|
+
Peaks.prototype.destroySegment = function(segmentId) {
|
|
610
|
+
this.segments.removeById(segmentId);
|
|
601
611
|
};
|
|
602
612
|
|
|
603
613
|
Peaks.prototype.setDefaultMode = function() {
|
|
@@ -628,6 +638,16 @@ define([
|
|
|
628
638
|
.allowInteractions(forSources, forSegments);
|
|
629
639
|
};
|
|
630
640
|
|
|
641
|
+
Peaks.prototype.selectSourceById = function(sourceId) {
|
|
642
|
+
return this.view
|
|
643
|
+
.selectSourceById(sourceId);
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
Peaks.prototype.deselectSource = function() {
|
|
647
|
+
return this.view
|
|
648
|
+
.deselectElement();
|
|
649
|
+
};
|
|
650
|
+
|
|
631
651
|
Peaks.prototype._addWindowResizeHandler = function() {
|
|
632
652
|
this._onResize = this._onResize.bind(this);
|
|
633
653
|
window.addEventListener('resize', this._onResize);
|
|
@@ -641,6 +661,13 @@ define([
|
|
|
641
661
|
window.removeEventListener('resize', this._onResize);
|
|
642
662
|
};
|
|
643
663
|
|
|
664
|
+
Peaks.prototype.setLineHeight = function(newLineHeight) {
|
|
665
|
+
var oldHeight = this.options.lineHeight;
|
|
666
|
+
|
|
667
|
+
this.options.lineHeight = newLineHeight;
|
|
668
|
+
this.emit('options.set.line_height', oldHeight);
|
|
669
|
+
};
|
|
670
|
+
|
|
644
671
|
/**
|
|
645
672
|
* Cleans up a Peaks instance after use.
|
|
646
673
|
*/
|
package/src/mode-layer.js
CHANGED
|
@@ -61,6 +61,37 @@ define([
|
|
|
61
61
|
stage.add(this._layer);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
ModeLayer.prototype.selectElement = function(element, notify) {
|
|
65
|
+
this.deselectElement(notify);
|
|
66
|
+
if (element) {
|
|
67
|
+
this._selectedElement = element;
|
|
68
|
+
this._selectedElement.setSelected(true);
|
|
69
|
+
if (notify) {
|
|
70
|
+
if (element instanceof SourceGroup) {
|
|
71
|
+
this._peaks.emit('source.selected', this._selectedElement.getSource());
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this._peaks.emit('segment.selected', this._selectedElement.getSegment());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
ModeLayer.prototype.deselectElement = function(notify) {
|
|
81
|
+
if (this._selectedElement) {
|
|
82
|
+
this._selectedElement.setSelected(false);
|
|
83
|
+
if (notify) {
|
|
84
|
+
if (this._selectedElement instanceof SourceGroup) {
|
|
85
|
+
this._peaks.emit('source.deselected', this._selectedElement.getSource());
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this._peaks.emit('segment.deselected', this._selectedElement.getSegment());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this._selectedElement = null;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
64
95
|
ModeLayer.prototype._prepareDefaultMode = function() {
|
|
65
96
|
this._selectedElement = null;
|
|
66
97
|
};
|
|
@@ -119,25 +150,27 @@ define([
|
|
|
119
150
|
var hoveredElement = this._view.getHoveredElement();
|
|
120
151
|
|
|
121
152
|
if (hoveredElement) {
|
|
122
|
-
|
|
123
|
-
this._selectedElement.setSelected(false);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this._selectedElement = hoveredElement;
|
|
127
|
-
|
|
128
|
-
this._selectedElement.setSelected(true);
|
|
153
|
+
this.selectElement(hoveredElement, true);
|
|
129
154
|
}
|
|
130
155
|
else {
|
|
131
|
-
|
|
132
|
-
this._selectedElement.setSelected(false);
|
|
133
|
-
this._selectedElement = null;
|
|
134
|
-
}
|
|
156
|
+
this.deselectElement(true);
|
|
135
157
|
}
|
|
136
158
|
};
|
|
137
159
|
|
|
138
160
|
ModeLayer.prototype._onKeyboardDelete = function() {
|
|
139
|
-
if (this._selectedElement
|
|
140
|
-
this.
|
|
161
|
+
if (this._selectedElement) {
|
|
162
|
+
var selectedElement = this._selectedElement;
|
|
163
|
+
|
|
164
|
+
this.deselectElement(true);
|
|
165
|
+
|
|
166
|
+
if (selectedElement instanceof SourceGroup) {
|
|
167
|
+
this._peaks.destroySource(selectedElement.getSource().id);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
if (selectedElement.getSegment().allowDeletion) {
|
|
171
|
+
this._peaks.destroySegment(selectedElement.getSegment().id);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
141
174
|
}
|
|
142
175
|
};
|
|
143
176
|
|
|
@@ -303,13 +336,10 @@ define([
|
|
|
303
336
|
case 'default':
|
|
304
337
|
this._stage.off('click', this._onMouseClickInDefaultMode);
|
|
305
338
|
this._peaks.off('keyboard.delete', this._onKeyboardDelete);
|
|
306
|
-
if (this._selectedElement) {
|
|
307
|
-
this._selectedElement.setSelected(false);
|
|
308
|
-
}
|
|
309
339
|
break;
|
|
310
340
|
}
|
|
311
341
|
|
|
312
|
-
this.
|
|
342
|
+
this.deselectElement(true);
|
|
313
343
|
|
|
314
344
|
// Set new mode
|
|
315
345
|
switch (mode) {
|
package/src/playhead-layer.js
CHANGED
|
@@ -26,10 +26,10 @@ define([
|
|
|
26
26
|
* is shown next to the playhead.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
function PlayheadLayer(peaks, view,
|
|
29
|
+
function PlayheadLayer(peaks, view, lines, showTime) {
|
|
30
30
|
this._peaks = peaks;
|
|
31
31
|
this._view = view;
|
|
32
|
-
this.
|
|
32
|
+
this._lines = lines;
|
|
33
33
|
this._playheadPixel = 0;
|
|
34
34
|
this._playheadLineAnimation = null;
|
|
35
35
|
this._playheadVisible = false;
|
|
@@ -38,8 +38,8 @@ define([
|
|
|
38
38
|
|
|
39
39
|
this._playheadLayer = new Konva.Layer();
|
|
40
40
|
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
41
|
+
this._activeSegments = {};
|
|
42
|
+
this._lastActiveSegments = {};
|
|
43
43
|
|
|
44
44
|
this._createPlayhead(this._playheadColor);
|
|
45
45
|
|
|
@@ -56,22 +56,26 @@ define([
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
PlayheadLayer.prototype._onSegmentsRemoveAll = function() {
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
59
|
+
this._activeSegments = {};
|
|
60
|
+
this._lastActiveSegments = {};
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
PlayheadLayer.prototype._onSegmentsRemove = function(segments) {
|
|
64
|
-
if (this.
|
|
65
|
-
var activeSegmentId = this._activeSegment ? this._activeSegment.id : null;
|
|
66
|
-
var lastActiveSegmentId = this._lastActiveSegmentId ? this._lastActiveSegmentId.id : null;
|
|
67
|
-
|
|
64
|
+
if (this._activeSegments || this._lastActiveSegments) {
|
|
68
65
|
for (var id in segments) {
|
|
69
66
|
if (Utils.objectHasProperty(segments, id)) {
|
|
67
|
+
var activeSegmentId = this._activeSegments[segments[id].line] ?
|
|
68
|
+
this._activeSegments[segments[id].line].id :
|
|
69
|
+
null;
|
|
70
|
+
var lastActiveSegmentId = this._lastActiveSegments[segments[id].line] ?
|
|
71
|
+
this._lastActiveSegments[segments[id].line].id :
|
|
72
|
+
null;
|
|
73
|
+
|
|
70
74
|
if (segments[id].id === activeSegmentId) {
|
|
71
|
-
this.
|
|
75
|
+
delete this._activeSegments[segments[id].line];
|
|
72
76
|
}
|
|
73
77
|
if (segments[id].id === lastActiveSegmentId) {
|
|
74
|
-
this.
|
|
78
|
+
delete this._lastActiveSegments[segments[id].line];
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
}
|
|
@@ -279,21 +283,27 @@ define([
|
|
|
279
283
|
var playheadPositionDiff = this._playheadGroup.x() - playheadX;
|
|
280
284
|
|
|
281
285
|
if (playheadPositionDiff) {
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
var segmentsGroup = this._lines.getSegmentsGroups();
|
|
287
|
+
|
|
288
|
+
for (var lineId in segmentsGroup) {
|
|
289
|
+
if (Utils.objectHasProperty(segmentsGroup, lineId)) {
|
|
290
|
+
var newActiveSegment = segmentsGroup[lineId].getActiveSegment(
|
|
291
|
+
this._view.pixelsToTime(playheadX + frameOffset),
|
|
292
|
+
null,
|
|
293
|
+
true
|
|
294
|
+
);
|
|
287
295
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
if (newActiveSegment !== this._activeSegments[lineId]) {
|
|
297
|
+
if (this._activeSegments[lineId]) {
|
|
298
|
+
this._peaks.emit('segments.exit', this._activeSegments[lineId]);
|
|
299
|
+
delete this._activeSegments[lineId];
|
|
300
|
+
}
|
|
301
|
+
if (newActiveSegment) {
|
|
302
|
+
this._peaks.emit('segments.enter', newActiveSegment);
|
|
303
|
+
this._activeSegments[lineId] = newActiveSegment;
|
|
304
|
+
this._lastActiveSegments[lineId] = this._activeSegments[lineId];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
309
|
}
|
package/src/segment-shape.js
CHANGED
|
@@ -39,6 +39,7 @@ define([
|
|
|
39
39
|
this._startMarker = null;
|
|
40
40
|
this._endMarker = null;
|
|
41
41
|
this._rectangle = null;
|
|
42
|
+
this._isSelected = false;
|
|
42
43
|
|
|
43
44
|
this._segmentHeight = this._peaks.options.segmentHeight;
|
|
44
45
|
|
|
@@ -244,7 +245,9 @@ define([
|
|
|
244
245
|
SegmentShape.prototype._onMouseEnter = function() {
|
|
245
246
|
this._view.setCursor('pointer');
|
|
246
247
|
|
|
247
|
-
this.
|
|
248
|
+
this._view.setHoveredElement(this);
|
|
249
|
+
|
|
250
|
+
this._rectangle.fill(this._segment.activeColor + Math.round(
|
|
248
251
|
this._segment.opacity * 255
|
|
249
252
|
).toString(16));
|
|
250
253
|
|
|
@@ -256,6 +259,8 @@ define([
|
|
|
256
259
|
SegmentShape.prototype._onMouseLeave = function() {
|
|
257
260
|
this._view.setCursor('default');
|
|
258
261
|
|
|
262
|
+
this._view.setHoveredElement(null);
|
|
263
|
+
|
|
259
264
|
this._rectangle.fill(this._segment.color + Math.round(
|
|
260
265
|
this._segment.opacity * 255
|
|
261
266
|
).toString(16));
|
|
@@ -315,6 +320,10 @@ define([
|
|
|
315
320
|
this._peaks.emit('segments.dragend', this._segment, startMarker);
|
|
316
321
|
};
|
|
317
322
|
|
|
323
|
+
SegmentShape.prototype.setSelected = function(isSelected) {
|
|
324
|
+
this._isSelected = isSelected;
|
|
325
|
+
};
|
|
326
|
+
|
|
318
327
|
SegmentShape.prototype.fitToView = function() {
|
|
319
328
|
if (this._startMarker) {
|
|
320
329
|
this._startMarker.fitToView();
|
package/src/segment.js
CHANGED
|
@@ -50,6 +50,10 @@ define([
|
|
|
50
50
|
else if (!Utils.isString(options.labelText)) {
|
|
51
51
|
throw new TypeError('peaks.segments.' + context + ': labelText must be a string');
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
if (!Utils.isInteger(options.line)) {
|
|
55
|
+
throw new TypeError('peaks.segments.' + context + ': line must be an integer');
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
/**
|
|
@@ -70,7 +74,7 @@ define([
|
|
|
70
74
|
*/
|
|
71
75
|
|
|
72
76
|
function Segment(peaks, id, startTime, endTime, labelText, color,
|
|
73
|
-
textColor, handleTextColor, opacity, editable) {
|
|
77
|
+
textColor, handleTextColor, opacity, editable, allowDeletion, line) {
|
|
74
78
|
var opts = {
|
|
75
79
|
startTime: startTime,
|
|
76
80
|
endTime: endTime,
|
|
@@ -79,7 +83,9 @@ define([
|
|
|
79
83
|
textColor: textColor,
|
|
80
84
|
handleTextColor: handleTextColor,
|
|
81
85
|
opacity: opacity,
|
|
82
|
-
editable: editable
|
|
86
|
+
editable: editable,
|
|
87
|
+
allowDeletion: allowDeletion,
|
|
88
|
+
line: line
|
|
83
89
|
};
|
|
84
90
|
|
|
85
91
|
validateSegment(peaks, opts, 'add()');
|
|
@@ -90,11 +96,13 @@ define([
|
|
|
90
96
|
this._endTime = opts.endTime;
|
|
91
97
|
this._labelText = opts.labelText;
|
|
92
98
|
this._color = opts.color;
|
|
93
|
-
this.
|
|
99
|
+
this._activeColor = Utils.shadeColor(color, 20);
|
|
94
100
|
this._textColor = opts.textColor;
|
|
95
101
|
this._handleTextColor = opts.handleTextColor;
|
|
96
102
|
this._opacity = opts.opacity;
|
|
97
103
|
this._editable = opts.editable;
|
|
104
|
+
this._allowDeletion = opts.allowDeletion;
|
|
105
|
+
this._line = opts.line;
|
|
98
106
|
this._minSize = peaks.options.minSegmentSize;
|
|
99
107
|
}
|
|
100
108
|
|
|
@@ -137,10 +145,10 @@ define([
|
|
|
137
145
|
return this._color;
|
|
138
146
|
}
|
|
139
147
|
},
|
|
140
|
-
|
|
148
|
+
activeColor: {
|
|
141
149
|
enumerable: true,
|
|
142
150
|
get: function() {
|
|
143
|
-
return this.
|
|
151
|
+
return this._activeColor;
|
|
144
152
|
}
|
|
145
153
|
},
|
|
146
154
|
textColor: {
|
|
@@ -167,6 +175,18 @@ define([
|
|
|
167
175
|
return this._editable;
|
|
168
176
|
}
|
|
169
177
|
},
|
|
178
|
+
allowDeletion: {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function() {
|
|
181
|
+
return this._allowDeletion;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
line: {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
get: function() {
|
|
187
|
+
return this._line;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
170
190
|
minSize: {
|
|
171
191
|
enumerable: true,
|
|
172
192
|
get: function() {
|
|
@@ -184,7 +204,9 @@ define([
|
|
|
184
204
|
textColor: this.textColor,
|
|
185
205
|
handleTextColor: this.handleTextColor,
|
|
186
206
|
opacity: this.opacity,
|
|
187
|
-
editable: this.editable
|
|
207
|
+
editable: this.editable,
|
|
208
|
+
allowDeletion: this.allowDeletion,
|
|
209
|
+
line: this.line
|
|
188
210
|
};
|
|
189
211
|
|
|
190
212
|
Utils.extend(opts, options);
|
|
@@ -199,6 +221,8 @@ define([
|
|
|
199
221
|
this._handleTextColor = opts.handleTextColor;
|
|
200
222
|
this._opacity = opts.opacity;
|
|
201
223
|
this._editable = opts.editable;
|
|
224
|
+
this._allowDeletion = opts.allowDeletion;
|
|
225
|
+
this._line = opts.line;
|
|
202
226
|
|
|
203
227
|
this._peaks.emit('segment.updated', this);
|
|
204
228
|
};
|
package/src/segments-group.js
CHANGED
|
@@ -44,11 +44,6 @@ define([
|
|
|
44
44
|
|
|
45
45
|
this._isMagnetized = false;
|
|
46
46
|
|
|
47
|
-
this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
|
|
48
|
-
this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
|
|
49
|
-
this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
|
|
50
|
-
this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
|
|
51
|
-
this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
|
|
52
47
|
this._peaks.on('segments.setMagnetizing', this.setMagnetizing.bind(this));
|
|
53
48
|
}
|
|
54
49
|
|
|
@@ -112,7 +107,7 @@ define([
|
|
|
112
107
|
return activeSegment;
|
|
113
108
|
};
|
|
114
109
|
|
|
115
|
-
SegmentsGroup.prototype.
|
|
110
|
+
SegmentsGroup.prototype.onSegmentsUpdate = function(segment) {
|
|
116
111
|
if (this._segments[segment.id]) {
|
|
117
112
|
var redraw = false;
|
|
118
113
|
var segmentShape = this._segmentShapes[segment.id];
|
|
@@ -140,12 +135,12 @@ define([
|
|
|
140
135
|
}
|
|
141
136
|
};
|
|
142
137
|
|
|
143
|
-
SegmentsGroup.prototype.
|
|
138
|
+
SegmentsGroup.prototype.onSegmentUpdated = function() {
|
|
144
139
|
this._peaks.emit('segments.updated', this._updatedSegments);
|
|
145
140
|
this._updatedSegments = [];
|
|
146
141
|
};
|
|
147
142
|
|
|
148
|
-
SegmentsGroup.prototype.
|
|
143
|
+
SegmentsGroup.prototype.onSegmentsAdd = function(segments) {
|
|
149
144
|
var self = this;
|
|
150
145
|
|
|
151
146
|
var frameOffset = self._view.getFrameOffset();
|
|
@@ -161,7 +156,7 @@ define([
|
|
|
161
156
|
self.updateSegments(frameStartTime, frameEndTime);
|
|
162
157
|
};
|
|
163
158
|
|
|
164
|
-
SegmentsGroup.prototype.
|
|
159
|
+
SegmentsGroup.prototype.onSegmentsRemove = function(segments) {
|
|
165
160
|
var self = this;
|
|
166
161
|
|
|
167
162
|
segments.forEach(function(segment) {
|
|
@@ -178,7 +173,7 @@ define([
|
|
|
178
173
|
this._draw();
|
|
179
174
|
};
|
|
180
175
|
|
|
181
|
-
SegmentsGroup.prototype.
|
|
176
|
+
SegmentsGroup.prototype.onSegmentsRemoveAll = function() {
|
|
182
177
|
this._group.removeChildren();
|
|
183
178
|
this._firstSegmentId = null;
|
|
184
179
|
this._segments = {};
|
|
@@ -313,7 +308,7 @@ define([
|
|
|
313
308
|
|
|
314
309
|
SegmentsGroup.prototype.updateSegments = function(startTime, endTime) {
|
|
315
310
|
// Update segments in visible time range.
|
|
316
|
-
var segments = this.
|
|
311
|
+
var segments = this.find(startTime, endTime);
|
|
317
312
|
|
|
318
313
|
var count = segments.length;
|
|
319
314
|
|
|
@@ -327,6 +322,29 @@ define([
|
|
|
327
322
|
}
|
|
328
323
|
};
|
|
329
324
|
|
|
325
|
+
SegmentsGroup.prototype.find = function(startTime, endTime) {
|
|
326
|
+
var currentSegment = null;
|
|
327
|
+
var visibleSegments = [];
|
|
328
|
+
|
|
329
|
+
do {
|
|
330
|
+
if (!currentSegment) {
|
|
331
|
+
currentSegment = this._segments[this._firstSegmentId];
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
currentSegment = this._segments[currentSegment.nextSegmentId];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (currentSegment.segment.isVisible(startTime, endTime)) {
|
|
338
|
+
visibleSegments.push(currentSegment.segment);
|
|
339
|
+
}
|
|
340
|
+
else if (visibleSegments.length) {
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
} while (currentSegment.nextSegmentId);
|
|
344
|
+
|
|
345
|
+
return visibleSegments;
|
|
346
|
+
};
|
|
347
|
+
|
|
330
348
|
SegmentsGroup.prototype._draw = function() {
|
|
331
349
|
this._view.drawSourcesLayer();
|
|
332
350
|
};
|
|
@@ -693,11 +711,7 @@ define([
|
|
|
693
711
|
};
|
|
694
712
|
|
|
695
713
|
SegmentsGroup.prototype.destroy = function() {
|
|
696
|
-
this._peaks.off('
|
|
697
|
-
this._peaks.off('segments.add', this._onSegmentsAdd);
|
|
698
|
-
this._peaks.off('segments.remove', this._onSegmentsRemove);
|
|
699
|
-
this._peaks.off('segments.remove_all', this._onSegmentsRemoveAll);
|
|
700
|
-
this._peaks.off('segments.dragged', this._onSegmentsDragged);
|
|
714
|
+
this._peaks.off('segments.setMagnetizing', this.setMagnetizing);
|
|
701
715
|
};
|
|
702
716
|
|
|
703
717
|
SegmentsGroup.prototype.fitToView = function() {
|