@checksub_team/peaks_timeline 1.16.1 → 2.0.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 +4716 -4409
- package/peaks.js.d.ts +5 -5
- package/src/{timeline-axis.js → components/axis.js} +244 -244
- package/src/{data-retriever.js → components/data-retriever.js} +117 -117
- package/src/{default-segment-marker.js → components/default-segment-marker.js} +132 -132
- package/src/{invoker.js → components/invoker.js} +81 -81
- package/src/components/line-group.js +692 -0
- package/src/components/line-groups.js +585 -0
- package/src/{line-indicator.js → components/line-indicator.js} +308 -303
- package/src/{marker-factories.js → components/marker-factories.js} +1 -1
- package/src/{mode-layer.js → components/mode-layer.js} +8 -12
- package/src/{playhead-layer.js → components/playhead-layer.js} +3 -3
- package/src/{segment-marker.js → components/segment-marker.js} +2 -2
- package/src/{segment-shape.js → components/segment-shape.js} +508 -508
- package/src/{segments-group.js → components/segments-group.js} +805 -801
- package/src/{source-group.js → components/source-group.js} +1661 -1640
- package/src/{sources-layer.js → components/sources-layer.js} +716 -730
- package/src/{waveform-builder.js → components/waveform-builder.js} +2 -2
- package/src/{waveform-shape.js → components/waveform-shape.js} +214 -214
- package/src/keyboard-handler.js +9 -9
- package/src/line-handler.js +179 -0
- package/src/main.js +110 -71
- package/src/models/line.js +156 -0
- package/src/{segment.js → models/segment.js} +420 -419
- package/src/{source.js → models/source.js} +1311 -1315
- package/src/player.js +2 -2
- package/src/{timeline-segments.js → segment-handler.js} +435 -435
- package/src/{timeline-sources.js → source-handler.js} +521 -514
- package/src/utils.js +5 -1
- package/src/{timeline-zoomview.js → view.js} +136 -137
- package/src/line.js +0 -690
- package/src/lines.js +0 -427
- /package/src/{data.js → components/data.js} +0 -0
- /package/src/{loader.js → components/loader.js} +0 -0
- /package/src/{mouse-drag-handler.js → components/mouse-drag-handler.js} +0 -0
- /package/src/{svgs.js → components/svgs.js} +0 -0
|
@@ -1,508 +1,508 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Defines the {@link SegmentShape} class.
|
|
5
|
-
*
|
|
6
|
-
* @module segment-shape
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
define([
|
|
10
|
-
'konva',
|
|
11
|
-
'./segment-marker',
|
|
12
|
-
'
|
|
13
|
-
], function(
|
|
14
|
-
Konva,
|
|
15
|
-
SegmentMarker,
|
|
16
|
-
Utils) {
|
|
17
|
-
'use strict';
|
|
18
|
-
|
|
19
|
-
var SEGMENT_WIDTH = 10;
|
|
20
|
-
var SEGMENT_CORNER_RADIUS = 10;
|
|
21
|
-
var INDICATOR_RADIUS = 4; // px
|
|
22
|
-
var INDICATORS_MARGIN_RIGHT = 4; // px
|
|
23
|
-
var INDICATORS_MARGIN_TOP = 8; // px
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates a waveform segment shape with optional start and end markers.
|
|
27
|
-
*
|
|
28
|
-
* @class
|
|
29
|
-
* @alias SegmentShape
|
|
30
|
-
*
|
|
31
|
-
* @param {Segment} segment
|
|
32
|
-
* @param {Peaks} peaks
|
|
33
|
-
* @param {SegmentsGroup} group
|
|
34
|
-
* @param {WaveformOverview|WaveformZoomView} view
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
function SegmentShape(segment, peaks, group, view) {
|
|
38
|
-
this._segment = segment;
|
|
39
|
-
this._peaks = peaks;
|
|
40
|
-
this._group = group;
|
|
41
|
-
this._view = view;
|
|
42
|
-
// this._waveformShape = null;
|
|
43
|
-
this._segmentsGroup = null;
|
|
44
|
-
this._label = null;
|
|
45
|
-
this._startMarker = null;
|
|
46
|
-
this._endMarker = null;
|
|
47
|
-
this._shapeGroup = null;
|
|
48
|
-
this._rectangle = null;
|
|
49
|
-
this._indicators = {};
|
|
50
|
-
|
|
51
|
-
var self = this;
|
|
52
|
-
|
|
53
|
-
this._segmentWidth = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
|
|
54
|
-
this._segmentHeight = this._peaks.options.segmentHeight;
|
|
55
|
-
|
|
56
|
-
this._shapeGroup = new Konva.Group({
|
|
57
|
-
x: this._view.timeToPixels(this._segment.startTime),
|
|
58
|
-
y: 0,
|
|
59
|
-
width: this._segmentWidth,
|
|
60
|
-
height: this._segmentHeight,
|
|
61
|
-
draggable: this._segment.editable,
|
|
62
|
-
clipFunc: function(ctx) {
|
|
63
|
-
self._drawRect(ctx);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
var width = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
|
|
68
|
-
var fillColor = segment.color + Math.round(segment.opacity * 255).toString(16);
|
|
69
|
-
|
|
70
|
-
this._rectangle = new Konva.Rect({
|
|
71
|
-
width: width,
|
|
72
|
-
height: this._segmentHeight,
|
|
73
|
-
cornerRadius: this._cornerRadius(),
|
|
74
|
-
stroke: segment.borderColor || segment.textColor + 'FF',
|
|
75
|
-
strokeWidth:
|
|
76
|
-
segment.borderWidth :
|
|
77
|
-
2,
|
|
78
|
-
fillPriority: segment.shouldShowWarning() ? 'linear-gradient' : 'color',
|
|
79
|
-
fill: fillColor,
|
|
80
|
-
fillLinearGradientColorStops: [
|
|
81
|
-
0, fillColor,
|
|
82
|
-
0.65, segment.warningColor
|
|
83
|
-
],
|
|
84
|
-
fillLinearGradientStartPointX: Math.max(width - 20, width / 2),
|
|
85
|
-
fillLinearGradientEndPointX: width
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
this._shapeGroup.add(this._rectangle);
|
|
89
|
-
|
|
90
|
-
this._shapeGroup.dragBoundFunc(function() {
|
|
91
|
-
return self._onShapeGroupDrag(this);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Set up event handlers to show/hide the segment label text when the user
|
|
95
|
-
// hovers the mouse over the segment.
|
|
96
|
-
this._shapeGroup.on('mouseenter', this._onMouseEnter.bind(this));
|
|
97
|
-
this._shapeGroup.on('mouseleave', this._onMouseLeave.bind(this));
|
|
98
|
-
this._shapeGroup.on('click', this._onClick.bind(this));
|
|
99
|
-
|
|
100
|
-
this._shapeGroup.on('dragstart', this._onSegmentDragStart.bind(this));
|
|
101
|
-
this._shapeGroup.on('dragend', this._onSegmentDragEnd.bind(this));
|
|
102
|
-
|
|
103
|
-
// Event handlers for markers
|
|
104
|
-
this._onSegmentHandleDrag = this._onSegmentHandleDrag.bind(this);
|
|
105
|
-
this._onSegmentHandleDragStart = this._onSegmentHandleDragStart.bind(this);
|
|
106
|
-
this._onSegmentHandleDragEnd = this._onSegmentHandleDragEnd.bind(this);
|
|
107
|
-
|
|
108
|
-
this._label = this._peaks.options.createSegmentLabel({
|
|
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
|
-
});
|
|
118
|
-
|
|
119
|
-
this._createMarkers();
|
|
120
|
-
|
|
121
|
-
this._indicatorsGroup = new Konva.Group();
|
|
122
|
-
this._shapeGroup.add(this._indicatorsGroup);
|
|
123
|
-
|
|
124
|
-
this.createIndicators();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
SegmentShape.prototype._onShapeGroupDrag = function(draggedElement) {
|
|
128
|
-
const diff = this._view.getPointerPosition().x - this._mouseDownX;
|
|
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
|
-
};
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
SegmentShape.prototype._cornerRadius = function() {
|
|
145
|
-
return
|
|
146
|
-
this._segment.borderRadius :
|
|
147
|
-
SEGMENT_CORNER_RADIUS;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
SegmentShape.prototype.update = function() {
|
|
151
|
-
var startPixel = this._view.timeToPixels(this._segment.startTime);
|
|
152
|
-
var endPixel = this._view.timeToPixels(this._segment.endTime);
|
|
153
|
-
var frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
|
|
154
|
-
|
|
155
|
-
this._shapeGroup.x(startPixel - frameOffset);
|
|
156
|
-
|
|
157
|
-
this._segmentWidth = endPixel - startPixel;
|
|
158
|
-
|
|
159
|
-
this._shapeGroup.width(this._segmentWidth);
|
|
160
|
-
this._rectangle.width(this._segmentWidth);
|
|
161
|
-
if (this._segment.shouldShowWarning()) {
|
|
162
|
-
this._rectangle.fillPriority('linear-gradient');
|
|
163
|
-
this._rectangle.fillLinearGradientStartPointX(
|
|
164
|
-
Math.max(this._segmentWidth - 20, this._segmentWidth / 2)
|
|
165
|
-
);
|
|
166
|
-
this._rectangle.fillLinearGradientEndPointX(this._segmentWidth);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
this._rectangle.fillPriority('color');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
this._indicatorsGroup.x(this._segmentWidth);
|
|
173
|
-
|
|
174
|
-
var newWidth = Math.floor(this._segmentWidth / 2);
|
|
175
|
-
|
|
176
|
-
if (this._segmentWidth
|
|
177
|
-
< this._startMarker.getHandleWidth() + this._endMarker.getHandleWidth()) {
|
|
178
|
-
this._startMarker.setHandleWidth(newWidth);
|
|
179
|
-
this._endMarker.setHandleWidth(newWidth);
|
|
180
|
-
}
|
|
181
|
-
else if (this._startMarker.getHandleWidth() < SEGMENT_WIDTH
|
|
182
|
-
&& newWidth > this._startMarker.getHandleWidth()) {
|
|
183
|
-
this._startMarker.setHandleWidth(Math.min(newWidth, SEGMENT_WIDTH));
|
|
184
|
-
this._endMarker.setHandleWidth(Math.min(newWidth, SEGMENT_WIDTH));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (this._startMarker) {
|
|
188
|
-
this._startMarker.setX(startPixel - frameOffset);
|
|
189
|
-
this._startMarker.timeUpdated(this._segment.startTime);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this._endMarker) {
|
|
193
|
-
this._endMarker.setX(endPixel - this._endMarker.getHandleWidth() - frameOffset);
|
|
194
|
-
this._endMarker.timeUpdated(this._segment.endTime);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (this._label) {
|
|
198
|
-
this._label.setX(startPixel - frameOffset);
|
|
199
|
-
this._label.setWidth(endPixel - startPixel);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
SegmentShape.prototype.getSegmentHeight = function() {
|
|
204
|
-
return this._segmentHeight;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
SegmentShape.prototype.getText = function() {
|
|
208
|
-
return this._label;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
SegmentShape.prototype.getSegment = function() {
|
|
212
|
-
return this._segment;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
SegmentShape.prototype.getSegmentsGroup = function() {
|
|
216
|
-
return this._segmentsGroup;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
SegmentShape.prototype.getStartMarker = function() {
|
|
220
|
-
return this._startMarker;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
SegmentShape.prototype.getEndMarker = function() {
|
|
224
|
-
return this._endMarker;
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
SegmentShape.prototype.
|
|
228
|
-
if (segmentsGroup) {
|
|
229
|
-
this._segmentsGroup = segmentsGroup;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (this._label) {
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (this._startMarker) {
|
|
239
|
-
this._startMarker.
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (this._endMarker) {
|
|
243
|
-
this._endMarker.
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
SegmentShape.prototype._createMarkers = function() {
|
|
248
|
-
var editable = this._group.isEditingEnabled() && this._segment.editable;
|
|
249
|
-
|
|
250
|
-
var startMarker = this._peaks.options.createSegmentMarker({
|
|
251
|
-
peaks: this._peaks,
|
|
252
|
-
segment: this._segment,
|
|
253
|
-
draggable: editable,
|
|
254
|
-
startMarker: true,
|
|
255
|
-
group: this._group,
|
|
256
|
-
view: this._view,
|
|
257
|
-
showSegmentMarkers: this._peaks.options.showSegmentMarkers,
|
|
258
|
-
segmentHeight: this._segmentHeight,
|
|
259
|
-
segmentWidth: SEGMENT_WIDTH,
|
|
260
|
-
y: this._segmentY
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
if (startMarker) {
|
|
264
|
-
this._startMarker = new SegmentMarker({
|
|
265
|
-
segment: this._segment,
|
|
266
|
-
segmentShape: this,
|
|
267
|
-
draggable: editable,
|
|
268
|
-
startMarker: true,
|
|
269
|
-
marker: startMarker,
|
|
270
|
-
onDrag: this._onSegmentHandleDrag,
|
|
271
|
-
onDragStart: this._onSegmentHandleDragStart,
|
|
272
|
-
onDragEnd: this._onSegmentHandleDragEnd,
|
|
273
|
-
view: this._view
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
var endMarker = this._peaks.options.createSegmentMarker({
|
|
278
|
-
peaks: this._peaks,
|
|
279
|
-
segment: this._segment,
|
|
280
|
-
draggable: editable,
|
|
281
|
-
startMarker: false,
|
|
282
|
-
group: this._group,
|
|
283
|
-
view: this._view,
|
|
284
|
-
showSegmentMarkers: this._peaks.options.showSegmentMarkers,
|
|
285
|
-
segmentHeight: this._segmentHeight,
|
|
286
|
-
segmentWidth: SEGMENT_WIDTH,
|
|
287
|
-
y: this._segmentY
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
if (endMarker) {
|
|
291
|
-
this._endMarker = new SegmentMarker({
|
|
292
|
-
segment: this._segment,
|
|
293
|
-
segmentShape: this,
|
|
294
|
-
draggable: editable,
|
|
295
|
-
startMarker: false,
|
|
296
|
-
marker: endMarker,
|
|
297
|
-
onDrag: this._onSegmentHandleDrag,
|
|
298
|
-
onDragStart: this._onSegmentHandleDragStart,
|
|
299
|
-
onDragEnd: this._onSegmentHandleDragEnd,
|
|
300
|
-
view: this._view
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
SegmentShape.prototype.createIndicators = function() {
|
|
306
|
-
var newIndicatorsColors = this._segment.indicators;
|
|
307
|
-
var oldIndicators = this._indicators;
|
|
308
|
-
var newIndicators = {};
|
|
309
|
-
|
|
310
|
-
if (newIndicatorsColors) {
|
|
311
|
-
newIndicatorsColors.forEach(function(indicatorColor) {
|
|
312
|
-
var oldIndicator = oldIndicators[indicatorColor];
|
|
313
|
-
|
|
314
|
-
if (oldIndicator) {
|
|
315
|
-
newIndicators[indicatorColor] = oldIndicator;
|
|
316
|
-
delete oldIndicators[indicatorColor];
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
newIndicators[indicatorColor] = null;
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
for (var color in oldIndicators) {
|
|
324
|
-
if (Utils.objectHasProperty(oldIndicators, color)) {
|
|
325
|
-
oldIndicators[color].destroy();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
this._indicators = Object.keys(newIndicators)
|
|
331
|
-
.sort()
|
|
332
|
-
.reverse()
|
|
333
|
-
.reduce(function(objEntries, key) {
|
|
334
|
-
objEntries[key] = newIndicators[key];
|
|
335
|
-
return objEntries;
|
|
336
|
-
}, {}
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
this._createIndicators();
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
SegmentShape.prototype._createIndicators = function() {
|
|
343
|
-
var currentX = 0;
|
|
344
|
-
var zIndex = 0;
|
|
345
|
-
|
|
346
|
-
for (var color in this._indicators) {
|
|
347
|
-
if (Utils.objectHasProperty(this._indicators, color)) {
|
|
348
|
-
if (!this._indicators[color]) {
|
|
349
|
-
this._indicators[color] = new Konva.Circle({
|
|
350
|
-
radius: INDICATOR_RADIUS,
|
|
351
|
-
fill: color,
|
|
352
|
-
strokeEnabled: false
|
|
353
|
-
});
|
|
354
|
-
this._indicatorsGroup.add(this._indicators[color]);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
this._indicators[color].x(currentX);
|
|
358
|
-
this._indicators[color].zIndex(zIndex);
|
|
359
|
-
currentX += INDICATOR_RADIUS;
|
|
360
|
-
zIndex += 1;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
this._indicatorsGroup.offsetX(currentX + INDICATORS_MARGIN_RIGHT);
|
|
365
|
-
this._indicatorsGroup.offsetY(-INDICATORS_MARGIN_TOP);
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
SegmentShape.prototype._onMouseEnter = function() {
|
|
369
|
-
this._view.setCursor('pointer');
|
|
370
|
-
|
|
371
|
-
this._view.setHoveredElement(this);
|
|
372
|
-
|
|
373
|
-
var fillColor = this._segment.hoverColor + Math.round(
|
|
374
|
-
this._segment.opacity * 255
|
|
375
|
-
).toString(16);
|
|
376
|
-
|
|
377
|
-
this._rectangle.fill(fillColor);
|
|
378
|
-
this._rectangle.fillLinearGradientColorStops([
|
|
379
|
-
0, fillColor,
|
|
380
|
-
0.65, this._segment.warningColor
|
|
381
|
-
]);
|
|
382
|
-
|
|
383
|
-
this._view.drawSourcesLayer();
|
|
384
|
-
|
|
385
|
-
this._peaks.emit('segments.mouseenter', this._segment);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
SegmentShape.prototype._onMouseLeave = function() {
|
|
389
|
-
this._view.setCursor('default');
|
|
390
|
-
|
|
391
|
-
this._view.setHoveredElement(null);
|
|
392
|
-
|
|
393
|
-
var fillColor = this._segment.color + Math.round(
|
|
394
|
-
this._segment.opacity * 255
|
|
395
|
-
).toString(16);
|
|
396
|
-
|
|
397
|
-
this._rectangle.fill(fillColor);
|
|
398
|
-
this._rectangle.fillLinearGradientColorStops([
|
|
399
|
-
0, fillColor,
|
|
400
|
-
0.65, this._segment.warningColor
|
|
401
|
-
]);
|
|
402
|
-
|
|
403
|
-
this._view.drawSourcesLayer();
|
|
404
|
-
|
|
405
|
-
this._peaks.emit('segments.mouseleave', this._segment);
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
SegmentShape.prototype._onClick = function() {
|
|
409
|
-
this._peaks.emit('segments.click', this._segment);
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
SegmentShape.prototype._onSegmentDragStart = function() {
|
|
413
|
-
this._view.setCursor('grab');
|
|
414
|
-
|
|
415
|
-
this._mouseDownX = this._view.getPointerPosition().x;
|
|
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);
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
SegmentShape.prototype._onSegmentDragEnd = function() {
|
|
425
|
-
this._view.setCursor('pointer');
|
|
426
|
-
|
|
427
|
-
this._peaks.emit('segments.dragend', this._segment);
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* @param {SegmentMarker} segmentMarker
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
SegmentShape.prototype._onSegmentHandleDrag = function() {
|
|
435
|
-
this._peaks.emit('segments.dragged');
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* @param {SegmentMarker} segmentMarker
|
|
440
|
-
*/
|
|
441
|
-
|
|
442
|
-
SegmentShape.prototype._onSegmentHandleDragStart = function(segmentMarker) {
|
|
443
|
-
var startMarker = segmentMarker.isStartMarker();
|
|
444
|
-
|
|
445
|
-
this._peaks.emit('segments.dragstart', this._segment, startMarker);
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* @param {SegmentMarker} segmentMarker
|
|
450
|
-
*/
|
|
451
|
-
|
|
452
|
-
SegmentShape.prototype._onSegmentHandleDragEnd = function(segmentMarker) {
|
|
453
|
-
var startMarker = segmentMarker.isStartMarker();
|
|
454
|
-
|
|
455
|
-
this._peaks.emit('segments.dragend', this._segment, startMarker);
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
SegmentShape.prototype.fitToView = function() {
|
|
459
|
-
if (this._startMarker) {
|
|
460
|
-
this._startMarker.fitToView();
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
if (this._endMarker) {
|
|
464
|
-
this._endMarker.fitToView();
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
SegmentShape.prototype.destroy = function() {
|
|
469
|
-
this._shapeGroup.destroy();
|
|
470
|
-
|
|
471
|
-
if (this._label) {
|
|
472
|
-
this._label.destroy();
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (this._startMarker) {
|
|
476
|
-
this._startMarker.destroy();
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
if (this._endMarker) {
|
|
480
|
-
this._endMarker.destroy();
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
SegmentShape.prototype._drawRect = function(ctx) {
|
|
485
|
-
var cornerRadius = this._cornerRadius();
|
|
486
|
-
|
|
487
|
-
ctx.beginPath();
|
|
488
|
-
ctx.moveTo(cornerRadius + 1.5, 0);
|
|
489
|
-
ctx.lineTo(this._segmentWidth - cornerRadius - 1.5, 0);
|
|
490
|
-
ctx.quadraticCurveTo(this._segmentWidth, 0, this._segmentWidth, cornerRadius + 1.5);
|
|
491
|
-
ctx.lineTo(this._segmentWidth, this._segmentHeight - cornerRadius - 1.5);
|
|
492
|
-
ctx.quadraticCurveTo(
|
|
493
|
-
this._segmentWidth,
|
|
494
|
-
this._segmentHeight,
|
|
495
|
-
this._segmentWidth - cornerRadius - 1.5,
|
|
496
|
-
this._segmentHeight
|
|
497
|
-
);
|
|
498
|
-
ctx.lineTo(cornerRadius + 1.5, this._segmentHeight);
|
|
499
|
-
ctx.quadraticCurveTo(
|
|
500
|
-
0, this._segmentHeight, 0, this._segmentHeight - cornerRadius - 1.5
|
|
501
|
-
);
|
|
502
|
-
ctx.lineTo(0, cornerRadius + 1.5);
|
|
503
|
-
ctx.quadraticCurveTo(0, 0, cornerRadius + 1.5, 0);
|
|
504
|
-
ctx.closePath();
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
return SegmentShape;
|
|
508
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link SegmentShape} class.
|
|
5
|
+
*
|
|
6
|
+
* @module segment-shape
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
define([
|
|
10
|
+
'konva',
|
|
11
|
+
'./segment-marker',
|
|
12
|
+
'../utils'
|
|
13
|
+
], function(
|
|
14
|
+
Konva,
|
|
15
|
+
SegmentMarker,
|
|
16
|
+
Utils) {
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
var SEGMENT_WIDTH = 10;
|
|
20
|
+
var SEGMENT_CORNER_RADIUS = 10;
|
|
21
|
+
var INDICATOR_RADIUS = 4; // px
|
|
22
|
+
var INDICATORS_MARGIN_RIGHT = 4; // px
|
|
23
|
+
var INDICATORS_MARGIN_TOP = 8; // px
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a waveform segment shape with optional start and end markers.
|
|
27
|
+
*
|
|
28
|
+
* @class
|
|
29
|
+
* @alias SegmentShape
|
|
30
|
+
*
|
|
31
|
+
* @param {Segment} segment
|
|
32
|
+
* @param {Peaks} peaks
|
|
33
|
+
* @param {SegmentsGroup} group
|
|
34
|
+
* @param {WaveformOverview|WaveformZoomView} view
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
function SegmentShape(segment, peaks, group, view) {
|
|
38
|
+
this._segment = segment;
|
|
39
|
+
this._peaks = peaks;
|
|
40
|
+
this._group = group;
|
|
41
|
+
this._view = view;
|
|
42
|
+
// this._waveformShape = null;
|
|
43
|
+
this._segmentsGroup = null;
|
|
44
|
+
this._label = null;
|
|
45
|
+
this._startMarker = null;
|
|
46
|
+
this._endMarker = null;
|
|
47
|
+
this._shapeGroup = null;
|
|
48
|
+
this._rectangle = null;
|
|
49
|
+
this._indicators = {};
|
|
50
|
+
|
|
51
|
+
var self = this;
|
|
52
|
+
|
|
53
|
+
this._segmentWidth = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
|
|
54
|
+
this._segmentHeight = this._peaks.options.segmentHeight;
|
|
55
|
+
|
|
56
|
+
this._shapeGroup = new Konva.Group({
|
|
57
|
+
x: this._view.timeToPixels(this._segment.startTime),
|
|
58
|
+
y: 0,
|
|
59
|
+
width: this._segmentWidth,
|
|
60
|
+
height: this._segmentHeight,
|
|
61
|
+
draggable: this._segment.editable,
|
|
62
|
+
clipFunc: function(ctx) {
|
|
63
|
+
self._drawRect(ctx);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
var width = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
|
|
68
|
+
var fillColor = segment.color + Math.round(segment.opacity * 255).toString(16);
|
|
69
|
+
|
|
70
|
+
this._rectangle = new Konva.Rect({
|
|
71
|
+
width: width,
|
|
72
|
+
height: this._segmentHeight,
|
|
73
|
+
cornerRadius: this._cornerRadius(),
|
|
74
|
+
stroke: segment.borderColor || segment.textColor + 'FF',
|
|
75
|
+
strokeWidth: !Utils.isNullOrUndefined(segment.borderWidth) ?
|
|
76
|
+
segment.borderWidth :
|
|
77
|
+
2,
|
|
78
|
+
fillPriority: segment.shouldShowWarning() ? 'linear-gradient' : 'color',
|
|
79
|
+
fill: fillColor,
|
|
80
|
+
fillLinearGradientColorStops: [
|
|
81
|
+
0, fillColor,
|
|
82
|
+
0.65, segment.warningColor
|
|
83
|
+
],
|
|
84
|
+
fillLinearGradientStartPointX: Math.max(width - 20, width / 2),
|
|
85
|
+
fillLinearGradientEndPointX: width
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
this._shapeGroup.add(this._rectangle);
|
|
89
|
+
|
|
90
|
+
this._shapeGroup.dragBoundFunc(function() {
|
|
91
|
+
return self._onShapeGroupDrag(this);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Set up event handlers to show/hide the segment label text when the user
|
|
95
|
+
// hovers the mouse over the segment.
|
|
96
|
+
this._shapeGroup.on('mouseenter', this._onMouseEnter.bind(this));
|
|
97
|
+
this._shapeGroup.on('mouseleave', this._onMouseLeave.bind(this));
|
|
98
|
+
this._shapeGroup.on('click', this._onClick.bind(this));
|
|
99
|
+
|
|
100
|
+
this._shapeGroup.on('dragstart', this._onSegmentDragStart.bind(this));
|
|
101
|
+
this._shapeGroup.on('dragend', this._onSegmentDragEnd.bind(this));
|
|
102
|
+
|
|
103
|
+
// Event handlers for markers
|
|
104
|
+
this._onSegmentHandleDrag = this._onSegmentHandleDrag.bind(this);
|
|
105
|
+
this._onSegmentHandleDragStart = this._onSegmentHandleDragStart.bind(this);
|
|
106
|
+
this._onSegmentHandleDragEnd = this._onSegmentHandleDragEnd.bind(this);
|
|
107
|
+
|
|
108
|
+
this._label = this._peaks.options.createSegmentLabel({
|
|
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
|
+
});
|
|
118
|
+
|
|
119
|
+
this._createMarkers();
|
|
120
|
+
|
|
121
|
+
this._indicatorsGroup = new Konva.Group();
|
|
122
|
+
this._shapeGroup.add(this._indicatorsGroup);
|
|
123
|
+
|
|
124
|
+
this.createIndicators();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
SegmentShape.prototype._onShapeGroupDrag = function(draggedElement) {
|
|
128
|
+
const diff = this._view.getPointerPosition().x - this._mouseDownX;
|
|
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
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
SegmentShape.prototype._cornerRadius = function() {
|
|
145
|
+
return !Utils.isNullOrUndefined(this._segment.borderRadius) ?
|
|
146
|
+
this._segment.borderRadius :
|
|
147
|
+
SEGMENT_CORNER_RADIUS;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
SegmentShape.prototype.update = function() {
|
|
151
|
+
var startPixel = this._view.timeToPixels(this._segment.startTime);
|
|
152
|
+
var endPixel = this._view.timeToPixels(this._segment.endTime);
|
|
153
|
+
var frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
|
|
154
|
+
|
|
155
|
+
this._shapeGroup.x(startPixel - frameOffset);
|
|
156
|
+
|
|
157
|
+
this._segmentWidth = endPixel - startPixel;
|
|
158
|
+
|
|
159
|
+
this._shapeGroup.width(this._segmentWidth);
|
|
160
|
+
this._rectangle.width(this._segmentWidth);
|
|
161
|
+
if (this._segment.shouldShowWarning()) {
|
|
162
|
+
this._rectangle.fillPriority('linear-gradient');
|
|
163
|
+
this._rectangle.fillLinearGradientStartPointX(
|
|
164
|
+
Math.max(this._segmentWidth - 20, this._segmentWidth / 2)
|
|
165
|
+
);
|
|
166
|
+
this._rectangle.fillLinearGradientEndPointX(this._segmentWidth);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this._rectangle.fillPriority('color');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this._indicatorsGroup.x(this._segmentWidth);
|
|
173
|
+
|
|
174
|
+
var newWidth = Math.floor(this._segmentWidth / 2);
|
|
175
|
+
|
|
176
|
+
if (this._segmentWidth
|
|
177
|
+
< this._startMarker.getHandleWidth() + this._endMarker.getHandleWidth()) {
|
|
178
|
+
this._startMarker.setHandleWidth(newWidth);
|
|
179
|
+
this._endMarker.setHandleWidth(newWidth);
|
|
180
|
+
}
|
|
181
|
+
else if (this._startMarker.getHandleWidth() < SEGMENT_WIDTH
|
|
182
|
+
&& newWidth > this._startMarker.getHandleWidth()) {
|
|
183
|
+
this._startMarker.setHandleWidth(Math.min(newWidth, SEGMENT_WIDTH));
|
|
184
|
+
this._endMarker.setHandleWidth(Math.min(newWidth, SEGMENT_WIDTH));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (this._startMarker) {
|
|
188
|
+
this._startMarker.setX(startPixel - frameOffset);
|
|
189
|
+
this._startMarker.timeUpdated(this._segment.startTime);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (this._endMarker) {
|
|
193
|
+
this._endMarker.setX(endPixel - this._endMarker.getHandleWidth() - frameOffset);
|
|
194
|
+
this._endMarker.timeUpdated(this._segment.endTime);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (this._label) {
|
|
198
|
+
this._label.setX(startPixel - frameOffset);
|
|
199
|
+
this._label.setWidth(endPixel - startPixel);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
SegmentShape.prototype.getSegmentHeight = function() {
|
|
204
|
+
return this._segmentHeight;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
SegmentShape.prototype.getText = function() {
|
|
208
|
+
return this._label;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
SegmentShape.prototype.getSegment = function() {
|
|
212
|
+
return this._segment;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
SegmentShape.prototype.getSegmentsGroup = function() {
|
|
216
|
+
return this._segmentsGroup;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
SegmentShape.prototype.getStartMarker = function() {
|
|
220
|
+
return this._startMarker;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
SegmentShape.prototype.getEndMarker = function() {
|
|
224
|
+
return this._endMarker;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
SegmentShape.prototype.moveTo = function(group, segmentsGroup) {
|
|
228
|
+
if (segmentsGroup) {
|
|
229
|
+
this._segmentsGroup = segmentsGroup;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this._shapeGroup.moveTo(group);
|
|
233
|
+
|
|
234
|
+
if (this._label) {
|
|
235
|
+
this._label.moveTo(group);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (this._startMarker) {
|
|
239
|
+
this._startMarker.moveTo(group);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (this._endMarker) {
|
|
243
|
+
this._endMarker.moveTo(group);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
SegmentShape.prototype._createMarkers = function() {
|
|
248
|
+
var editable = this._group.isEditingEnabled() && this._segment.editable;
|
|
249
|
+
|
|
250
|
+
var startMarker = this._peaks.options.createSegmentMarker({
|
|
251
|
+
peaks: this._peaks,
|
|
252
|
+
segment: this._segment,
|
|
253
|
+
draggable: editable,
|
|
254
|
+
startMarker: true,
|
|
255
|
+
group: this._group,
|
|
256
|
+
view: this._view,
|
|
257
|
+
showSegmentMarkers: this._peaks.options.showSegmentMarkers,
|
|
258
|
+
segmentHeight: this._segmentHeight,
|
|
259
|
+
segmentWidth: SEGMENT_WIDTH,
|
|
260
|
+
y: this._segmentY
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
if (startMarker) {
|
|
264
|
+
this._startMarker = new SegmentMarker({
|
|
265
|
+
segment: this._segment,
|
|
266
|
+
segmentShape: this,
|
|
267
|
+
draggable: editable,
|
|
268
|
+
startMarker: true,
|
|
269
|
+
marker: startMarker,
|
|
270
|
+
onDrag: this._onSegmentHandleDrag,
|
|
271
|
+
onDragStart: this._onSegmentHandleDragStart,
|
|
272
|
+
onDragEnd: this._onSegmentHandleDragEnd,
|
|
273
|
+
view: this._view
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
var endMarker = this._peaks.options.createSegmentMarker({
|
|
278
|
+
peaks: this._peaks,
|
|
279
|
+
segment: this._segment,
|
|
280
|
+
draggable: editable,
|
|
281
|
+
startMarker: false,
|
|
282
|
+
group: this._group,
|
|
283
|
+
view: this._view,
|
|
284
|
+
showSegmentMarkers: this._peaks.options.showSegmentMarkers,
|
|
285
|
+
segmentHeight: this._segmentHeight,
|
|
286
|
+
segmentWidth: SEGMENT_WIDTH,
|
|
287
|
+
y: this._segmentY
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (endMarker) {
|
|
291
|
+
this._endMarker = new SegmentMarker({
|
|
292
|
+
segment: this._segment,
|
|
293
|
+
segmentShape: this,
|
|
294
|
+
draggable: editable,
|
|
295
|
+
startMarker: false,
|
|
296
|
+
marker: endMarker,
|
|
297
|
+
onDrag: this._onSegmentHandleDrag,
|
|
298
|
+
onDragStart: this._onSegmentHandleDragStart,
|
|
299
|
+
onDragEnd: this._onSegmentHandleDragEnd,
|
|
300
|
+
view: this._view
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
SegmentShape.prototype.createIndicators = function() {
|
|
306
|
+
var newIndicatorsColors = this._segment.indicators;
|
|
307
|
+
var oldIndicators = this._indicators;
|
|
308
|
+
var newIndicators = {};
|
|
309
|
+
|
|
310
|
+
if (newIndicatorsColors) {
|
|
311
|
+
newIndicatorsColors.forEach(function(indicatorColor) {
|
|
312
|
+
var oldIndicator = oldIndicators[indicatorColor];
|
|
313
|
+
|
|
314
|
+
if (oldIndicator) {
|
|
315
|
+
newIndicators[indicatorColor] = oldIndicator;
|
|
316
|
+
delete oldIndicators[indicatorColor];
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
newIndicators[indicatorColor] = null;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
for (var color in oldIndicators) {
|
|
324
|
+
if (Utils.objectHasProperty(oldIndicators, color)) {
|
|
325
|
+
oldIndicators[color].destroy();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
this._indicators = Object.keys(newIndicators)
|
|
331
|
+
.sort()
|
|
332
|
+
.reverse()
|
|
333
|
+
.reduce(function(objEntries, key) {
|
|
334
|
+
objEntries[key] = newIndicators[key];
|
|
335
|
+
return objEntries;
|
|
336
|
+
}, {}
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
this._createIndicators();
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
SegmentShape.prototype._createIndicators = function() {
|
|
343
|
+
var currentX = 0;
|
|
344
|
+
var zIndex = 0;
|
|
345
|
+
|
|
346
|
+
for (var color in this._indicators) {
|
|
347
|
+
if (Utils.objectHasProperty(this._indicators, color)) {
|
|
348
|
+
if (!this._indicators[color]) {
|
|
349
|
+
this._indicators[color] = new Konva.Circle({
|
|
350
|
+
radius: INDICATOR_RADIUS,
|
|
351
|
+
fill: color,
|
|
352
|
+
strokeEnabled: false
|
|
353
|
+
});
|
|
354
|
+
this._indicatorsGroup.add(this._indicators[color]);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
this._indicators[color].x(currentX);
|
|
358
|
+
this._indicators[color].zIndex(zIndex);
|
|
359
|
+
currentX += INDICATOR_RADIUS;
|
|
360
|
+
zIndex += 1;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
this._indicatorsGroup.offsetX(currentX + INDICATORS_MARGIN_RIGHT);
|
|
365
|
+
this._indicatorsGroup.offsetY(-INDICATORS_MARGIN_TOP);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
SegmentShape.prototype._onMouseEnter = function() {
|
|
369
|
+
this._view.setCursor('pointer');
|
|
370
|
+
|
|
371
|
+
this._view.setHoveredElement(this);
|
|
372
|
+
|
|
373
|
+
var fillColor = this._segment.hoverColor + Math.round(
|
|
374
|
+
this._segment.opacity * 255
|
|
375
|
+
).toString(16);
|
|
376
|
+
|
|
377
|
+
this._rectangle.fill(fillColor);
|
|
378
|
+
this._rectangle.fillLinearGradientColorStops([
|
|
379
|
+
0, fillColor,
|
|
380
|
+
0.65, this._segment.warningColor
|
|
381
|
+
]);
|
|
382
|
+
|
|
383
|
+
this._view.drawSourcesLayer();
|
|
384
|
+
|
|
385
|
+
this._peaks.emit('segments.mouseenter', this._segment);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
SegmentShape.prototype._onMouseLeave = function() {
|
|
389
|
+
this._view.setCursor('default');
|
|
390
|
+
|
|
391
|
+
this._view.setHoveredElement(null);
|
|
392
|
+
|
|
393
|
+
var fillColor = this._segment.color + Math.round(
|
|
394
|
+
this._segment.opacity * 255
|
|
395
|
+
).toString(16);
|
|
396
|
+
|
|
397
|
+
this._rectangle.fill(fillColor);
|
|
398
|
+
this._rectangle.fillLinearGradientColorStops([
|
|
399
|
+
0, fillColor,
|
|
400
|
+
0.65, this._segment.warningColor
|
|
401
|
+
]);
|
|
402
|
+
|
|
403
|
+
this._view.drawSourcesLayer();
|
|
404
|
+
|
|
405
|
+
this._peaks.emit('segments.mouseleave', this._segment);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
SegmentShape.prototype._onClick = function() {
|
|
409
|
+
this._peaks.emit('segments.click', this._segment);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
SegmentShape.prototype._onSegmentDragStart = function() {
|
|
413
|
+
this._view.setCursor('grab');
|
|
414
|
+
|
|
415
|
+
this._mouseDownX = this._view.getPointerPosition().x;
|
|
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);
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
SegmentShape.prototype._onSegmentDragEnd = function() {
|
|
425
|
+
this._view.setCursor('pointer');
|
|
426
|
+
|
|
427
|
+
this._peaks.emit('segments.dragend', this._segment);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @param {SegmentMarker} segmentMarker
|
|
432
|
+
*/
|
|
433
|
+
|
|
434
|
+
SegmentShape.prototype._onSegmentHandleDrag = function() {
|
|
435
|
+
this._peaks.emit('segments.dragged');
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* @param {SegmentMarker} segmentMarker
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
SegmentShape.prototype._onSegmentHandleDragStart = function(segmentMarker) {
|
|
443
|
+
var startMarker = segmentMarker.isStartMarker();
|
|
444
|
+
|
|
445
|
+
this._peaks.emit('segments.dragstart', this._segment, startMarker);
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* @param {SegmentMarker} segmentMarker
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
SegmentShape.prototype._onSegmentHandleDragEnd = function(segmentMarker) {
|
|
453
|
+
var startMarker = segmentMarker.isStartMarker();
|
|
454
|
+
|
|
455
|
+
this._peaks.emit('segments.dragend', this._segment, startMarker);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
SegmentShape.prototype.fitToView = function() {
|
|
459
|
+
if (this._startMarker) {
|
|
460
|
+
this._startMarker.fitToView();
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (this._endMarker) {
|
|
464
|
+
this._endMarker.fitToView();
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
SegmentShape.prototype.destroy = function() {
|
|
469
|
+
this._shapeGroup.destroy();
|
|
470
|
+
|
|
471
|
+
if (this._label) {
|
|
472
|
+
this._label.destroy();
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (this._startMarker) {
|
|
476
|
+
this._startMarker.destroy();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (this._endMarker) {
|
|
480
|
+
this._endMarker.destroy();
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
SegmentShape.prototype._drawRect = function(ctx) {
|
|
485
|
+
var cornerRadius = this._cornerRadius();
|
|
486
|
+
|
|
487
|
+
ctx.beginPath();
|
|
488
|
+
ctx.moveTo(cornerRadius + 1.5, 0);
|
|
489
|
+
ctx.lineTo(this._segmentWidth - cornerRadius - 1.5, 0);
|
|
490
|
+
ctx.quadraticCurveTo(this._segmentWidth, 0, this._segmentWidth, cornerRadius + 1.5);
|
|
491
|
+
ctx.lineTo(this._segmentWidth, this._segmentHeight - cornerRadius - 1.5);
|
|
492
|
+
ctx.quadraticCurveTo(
|
|
493
|
+
this._segmentWidth,
|
|
494
|
+
this._segmentHeight,
|
|
495
|
+
this._segmentWidth - cornerRadius - 1.5,
|
|
496
|
+
this._segmentHeight
|
|
497
|
+
);
|
|
498
|
+
ctx.lineTo(cornerRadius + 1.5, this._segmentHeight);
|
|
499
|
+
ctx.quadraticCurveTo(
|
|
500
|
+
0, this._segmentHeight, 0, this._segmentHeight - cornerRadius - 1.5
|
|
501
|
+
);
|
|
502
|
+
ctx.lineTo(0, cornerRadius + 1.5);
|
|
503
|
+
ctx.quadraticCurveTo(0, 0, cornerRadius + 1.5, 0);
|
|
504
|
+
ctx.closePath();
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
return SegmentShape;
|
|
508
|
+
});
|