@checksub_team/peaks_timeline 1.4.38 → 1.4.39
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/CHANGELOG.md +530 -0
- package/COPYING +165 -165
- package/package.json +88 -88
- package/peaks.js +492 -305
- package/src/data-retriever.js +89 -89
- package/src/default-segment-marker.js +132 -132
- package/src/invoker.js +81 -81
- package/src/keyboard-handler.js +112 -112
- package/src/line-indicator.js +377 -377
- package/src/line.js +678 -678
- package/src/lines.js +427 -427
- package/src/main.js +702 -702
- package/src/mode-layer.js +398 -391
- package/src/player.js +178 -178
- package/src/playhead-layer.js +423 -423
- package/src/segment-shape.js +354 -354
- package/src/segment.js +263 -263
- package/src/segments-group.js +765 -765
- package/src/source-group.js +987 -987
- package/src/source.js +688 -688
- package/src/sources-layer.js +592 -592
- package/src/timeline-axis.js +238 -238
- package/src/timeline-segments.js +395 -395
- package/src/timeline-sources.js +431 -431
- package/src/timeline-zoomview.js +880 -880
- package/src/utils.js +339 -339
- package/src/waveform-shape.js +216 -216
package/src/line-indicator.js
CHANGED
|
@@ -1,377 +1,377 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Defines the {@link LineIndicator} class.
|
|
5
|
-
*
|
|
6
|
-
* @module line-indicator
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
define([
|
|
10
|
-
'konva',
|
|
11
|
-
'./utils'
|
|
12
|
-
], function(
|
|
13
|
-
Konva,
|
|
14
|
-
Utils) {
|
|
15
|
-
'use strict';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a Konva.Stage that displays a representation of each line.
|
|
19
|
-
*
|
|
20
|
-
* @class
|
|
21
|
-
* @alias LineIndicator
|
|
22
|
-
*
|
|
23
|
-
* @param {Peaks} peaks
|
|
24
|
-
* @param {WaveformOverview|WaveformZoomView} view
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
function LineIndicator(peaks, view, container) {
|
|
28
|
-
this._peaks = peaks;
|
|
29
|
-
this._view = view;
|
|
30
|
-
this._container = container;
|
|
31
|
-
|
|
32
|
-
this._width = this._peaks.options.lineIndicatorWidth;
|
|
33
|
-
this._height = this._view.getHeight();
|
|
34
|
-
|
|
35
|
-
this._indicatorRadius = this._width / 4;
|
|
36
|
-
|
|
37
|
-
this._stage = new Konva.Stage({
|
|
38
|
-
container: container,
|
|
39
|
-
width: this._width,
|
|
40
|
-
height: this._height
|
|
41
|
-
});
|
|
42
|
-
this._layer = new Konva.Layer();
|
|
43
|
-
this._stage.add(this._layer);
|
|
44
|
-
|
|
45
|
-
this._indicators = {};
|
|
46
|
-
|
|
47
|
-
this._layer.add(
|
|
48
|
-
new Konva.Line({
|
|
49
|
-
points: [this._width, 0, this._width, this._height],
|
|
50
|
-
stroke: 'gray',
|
|
51
|
-
strokeWidth: 1,
|
|
52
|
-
listening: false
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
this._layer.draw();
|
|
57
|
-
|
|
58
|
-
if (this._peaks.options.enableLineIndicatorContextMenu) {
|
|
59
|
-
this._createContextMenu();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/* eslint-disable max-len */
|
|
63
|
-
this.ICON_SIZE = 18;
|
|
64
|
-
this._volumeSVGPath = 'M0 6.00001V12H4L9 17V1.00001L4 6.00001H0ZM13.5 9.00001C13.5 7.23001 12.48 5.71001 11 4.97001V13.02C12.48 12.29 13.5 10.77 13.5 9.00001ZM11 0.230011V2.29001C13.89 3.15001 16 5.83001 16 9.00001C16 12.17 13.89 14.85 11 15.71V17.77C15.01 16.86 18 13.28 18 9.00001C18 4.72001 15.01 1.14001 11 0.230011Z';
|
|
65
|
-
this._noVolumeSVGPath = 'M13.5 9C13.5 7.23 12.48 5.71 11 4.97V7.18L13.45 9.63C13.48 9.43 13.5 9.22 13.5 9ZM16 9C16 9.94 15.8 10.82 15.46 11.64L16.97 13.15C17.63 11.91 18 10.5 18 9C18 4.72 15.01 1.14 11 0.23V2.29C13.89 3.15 16 5.83 16 9ZM1.27 0L0 1.27L4.73 6H0V12H4L9 17V10.27L13.25 14.52C12.58 15.04 11.83 15.45 11 15.7V17.76C12.38 17.45 13.63 16.81 14.69 15.95L16.73 18L18 16.73L9 7.73L1.27 0ZM9 1L6.91 3.09L9 5.18V1Z';
|
|
66
|
-
/* eslint-enable max-len */
|
|
67
|
-
|
|
68
|
-
this._peaks.on('lineIndicator.setType', this._onSetType.bind(this));
|
|
69
|
-
|
|
70
|
-
this._types = ['default', 'volume', 'noVolume'];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
LineIndicator.prototype._onSetType = function(lineId, type) {
|
|
74
|
-
this.removeIndicator(lineId, true);
|
|
75
|
-
|
|
76
|
-
type = this._types.includes(type) ? type : 'default';
|
|
77
|
-
|
|
78
|
-
var indicator = this._createIndicator(
|
|
79
|
-
this._indicators[lineId].line,
|
|
80
|
-
type
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
this._layer.add(indicator);
|
|
84
|
-
|
|
85
|
-
this._indicators[lineId].indicator = indicator;
|
|
86
|
-
this._indicators[lineId].type = type;
|
|
87
|
-
|
|
88
|
-
this.draw();
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
LineIndicator.prototype._showMenu = function(menu) {
|
|
92
|
-
menu.style.display = 'block';
|
|
93
|
-
var containerRect = this._stage.container().getBoundingClientRect();
|
|
94
|
-
|
|
95
|
-
menu.style.top = containerRect.top
|
|
96
|
-
+ this._stage.getPointerPosition().y
|
|
97
|
-
- menu.offsetHeight + 'px';
|
|
98
|
-
menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
LineIndicator.prototype._createIndicator = function(line, type) {
|
|
102
|
-
var indicator;
|
|
103
|
-
|
|
104
|
-
type = typeof type !== 'undefined' ? type : 'default';
|
|
105
|
-
|
|
106
|
-
if (type === 'default') {
|
|
107
|
-
indicator = new Konva.Circle({
|
|
108
|
-
x: this._width / 2,
|
|
109
|
-
y: line.getY() + (line.lineHeight() / 2),
|
|
110
|
-
radius: this._indicatorRadius,
|
|
111
|
-
fill: this._peaks.options.lineIndicatorColor,
|
|
112
|
-
strokeWidth: 0,
|
|
113
|
-
lineId: line.getId()
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
var scaleFactor = (this._width / 2) / this.ICON_SIZE;
|
|
118
|
-
|
|
119
|
-
indicator = new Konva.Path({
|
|
120
|
-
x: this._width / 4,
|
|
121
|
-
y: line.getY() + (line.lineHeight() / 2) - (this._width / 4),
|
|
122
|
-
data: type === 'volume' ?
|
|
123
|
-
this._volumeSVGPath :
|
|
124
|
-
this._noVolumeSVGPath,
|
|
125
|
-
fill: this._peaks.options.lineIndicatorColor,
|
|
126
|
-
scale: {
|
|
127
|
-
x: scaleFactor,
|
|
128
|
-
y: scaleFactor
|
|
129
|
-
},
|
|
130
|
-
lineId: line.getId()
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
var self = this;
|
|
135
|
-
|
|
136
|
-
indicator.on('mouseover', function() {
|
|
137
|
-
indicator.fill(self._peaks.options.lineIndicatorSelected);
|
|
138
|
-
self.draw();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
indicator.on('mouseout', function() {
|
|
142
|
-
indicator.fill(self._peaks.options.lineIndicatorColor);
|
|
143
|
-
self.draw();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
indicator.on('click', function(e) {
|
|
147
|
-
self._peaks.emit('lineIndicator.click', self._indicators[line.getId()], e.evt);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
return indicator;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
LineIndicator.prototype.addIndicator = function(line) {
|
|
154
|
-
if (!this._indicators[line.getId()]) {
|
|
155
|
-
var indicator = this._createIndicator(line);
|
|
156
|
-
|
|
157
|
-
this._layer.add(indicator);
|
|
158
|
-
|
|
159
|
-
this._indicators[line.getId()] = {
|
|
160
|
-
indicator: indicator,
|
|
161
|
-
line: line,
|
|
162
|
-
type: 'default'
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
|
|
168
|
-
if (this._indicators[lineId]) {
|
|
169
|
-
if (this._indicators[lineId].indicator) {
|
|
170
|
-
this._indicators[lineId].indicator.destroy();
|
|
171
|
-
}
|
|
172
|
-
if (!keepInList) {
|
|
173
|
-
delete this._indicators[lineId];
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
this._indicators[lineId].indicator = null;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
LineIndicator.prototype.getPixelsFromCenter = function(lineId) {
|
|
182
|
-
return this._indicators[lineId].type === 'default' ?
|
|
183
|
-
0 :
|
|
184
|
-
this._width / 4;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
LineIndicator.prototype.updateIndicator = function(lineId) {
|
|
188
|
-
if (this._indicators[lineId]) {
|
|
189
|
-
var y = this._indicators[lineId].line.getY()
|
|
190
|
-
+ (this._indicators[lineId].line.lineHeight() / 2);
|
|
191
|
-
|
|
192
|
-
if (y + this._indicatorRadius > 0 && y - this._indicatorRadius < this._height) {
|
|
193
|
-
// The indicator is visible
|
|
194
|
-
if (!this._indicators[lineId].indicator) {
|
|
195
|
-
this._indicators[lineId].indicator = this._createIndicator(
|
|
196
|
-
this._indicators[lineId].line,
|
|
197
|
-
this._indicators[lineId].type
|
|
198
|
-
);
|
|
199
|
-
this._layer.add(this._indicators[lineId].indicator);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
this._indicators[lineId].indicator.y(y - this.getPixelsFromCenter(lineId));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
// The indicator is out of the view, we remove it
|
|
207
|
-
this.removeIndicator(lineId, true);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
LineIndicator.prototype.updateIndicators = function() {
|
|
213
|
-
for (var lineId in this._indicators) {
|
|
214
|
-
if (Utils.objectHasProperty(this._indicators, lineId)) {
|
|
215
|
-
this.updateIndicator(lineId);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
LineIndicator.prototype.draw = function() {
|
|
221
|
-
this._layer.draw();
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
LineIndicator.prototype._createContextMenu = function() {
|
|
225
|
-
var menu = document.createElement('div');
|
|
226
|
-
var addLine = document.createElement('button');
|
|
227
|
-
var addLineAbove = document.createElement('button');
|
|
228
|
-
var addLineBelow = document.createElement('button');
|
|
229
|
-
var deleteLine = document.createElement('button');
|
|
230
|
-
var currentIndicator = null;
|
|
231
|
-
var self = this;
|
|
232
|
-
|
|
233
|
-
menu.style.display = 'none';
|
|
234
|
-
menu.style.position = 'absolute';
|
|
235
|
-
menu.style.backgroundColor = 'white';
|
|
236
|
-
menu.style.boxShadow = '0 0 5px grey';
|
|
237
|
-
menu.style.borderRadius = '3px';
|
|
238
|
-
menu.style.zIndex = 2;
|
|
239
|
-
|
|
240
|
-
addLine.style.display = 'none';
|
|
241
|
-
addLine.style.border = 'none';
|
|
242
|
-
addLine.style.margin = '0';
|
|
243
|
-
addLine.style.width = '100%';
|
|
244
|
-
addLine.style.backgroundColor = 'white';
|
|
245
|
-
addLine.style.padding = '10px';
|
|
246
|
-
|
|
247
|
-
addLine.textContent = 'Add first line';
|
|
248
|
-
|
|
249
|
-
addLine.onmouseover = function() {
|
|
250
|
-
this.style.backgroundColor = 'lightgray';
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
addLine.onmouseout = function() {
|
|
254
|
-
this.style.backgroundColor = 'white';
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
addLineAbove.style.display = 'none';
|
|
258
|
-
addLineAbove.style.border = 'none';
|
|
259
|
-
addLineAbove.style.margin = '0';
|
|
260
|
-
addLineAbove.style.width = '100%';
|
|
261
|
-
addLineAbove.style.backgroundColor = 'white';
|
|
262
|
-
addLineAbove.style.padding = '10px';
|
|
263
|
-
|
|
264
|
-
addLineAbove.textContent = 'Add line above';
|
|
265
|
-
|
|
266
|
-
addLineAbove.onmouseover = function() {
|
|
267
|
-
this.style.backgroundColor = 'lightgray';
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
addLineAbove.onmouseout = function() {
|
|
271
|
-
this.style.backgroundColor = 'white';
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
addLineBelow.style.display = 'none';
|
|
275
|
-
addLineBelow.style.border = 'none';
|
|
276
|
-
addLineBelow.style.margin = '0';
|
|
277
|
-
addLineBelow.style.width = '100%';
|
|
278
|
-
addLineBelow.style.backgroundColor = 'white';
|
|
279
|
-
addLineBelow.style.padding = '10px';
|
|
280
|
-
|
|
281
|
-
addLineBelow.textContent = 'Add line below';
|
|
282
|
-
|
|
283
|
-
addLineBelow.onmouseover = function() {
|
|
284
|
-
this.style.backgroundColor = 'lightgray';
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
addLineBelow.onmouseout = function() {
|
|
288
|
-
this.style.backgroundColor = 'white';
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
deleteLine.style.display = 'none';
|
|
292
|
-
deleteLine.style.border = 'none';
|
|
293
|
-
deleteLine.style.margin = '0';
|
|
294
|
-
deleteLine.style.width = '100%';
|
|
295
|
-
deleteLine.style.backgroundColor = 'white';
|
|
296
|
-
deleteLine.style.padding = '10px';
|
|
297
|
-
|
|
298
|
-
deleteLine.textContent = 'Delete line';
|
|
299
|
-
|
|
300
|
-
deleteLine.onmouseover = function() {
|
|
301
|
-
this.style.backgroundColor = 'lightgray';
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
deleteLine.onmouseout = function() {
|
|
305
|
-
this.style.backgroundColor = 'white';
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
menu.appendChild(addLine);
|
|
309
|
-
menu.appendChild(addLineAbove);
|
|
310
|
-
menu.appendChild(addLineBelow);
|
|
311
|
-
menu.appendChild(deleteLine);
|
|
312
|
-
this._container.appendChild(menu);
|
|
313
|
-
|
|
314
|
-
addLine.addEventListener('click', function() {
|
|
315
|
-
self._peaks.emit('line.add', 0);
|
|
316
|
-
self.draw();
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
addLineAbove.addEventListener('click', function() {
|
|
320
|
-
var line = self._indicators[currentIndicator.getAttr('lineId')].line;
|
|
321
|
-
|
|
322
|
-
self._peaks.emit('line.add', Number(line.getPosition()));
|
|
323
|
-
self.draw();
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
addLineBelow.addEventListener('click', function() {
|
|
327
|
-
var line = self._indicators[currentIndicator.getAttr('lineId')].line;
|
|
328
|
-
|
|
329
|
-
self._peaks.emit('line.add', Number(line.getPosition()) + 1);
|
|
330
|
-
self.draw();
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
deleteLine.addEventListener('click', function() {
|
|
334
|
-
var line = self._indicators[currentIndicator.getAttr('lineId')].line;
|
|
335
|
-
|
|
336
|
-
self._peaks.emit('line.remove', Number(line.getPosition()));
|
|
337
|
-
self.draw();
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
window.addEventListener('click', function() {
|
|
341
|
-
// hide menu
|
|
342
|
-
menu.style.display = 'none';
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
this._stage.on('contextmenu', function(e) {
|
|
346
|
-
// prevent default behavior
|
|
347
|
-
e.evt.preventDefault();
|
|
348
|
-
|
|
349
|
-
if (e.target === self._stage && Object.keys(self._indicators).length === 0) {
|
|
350
|
-
// if we are on empty place of the stage
|
|
351
|
-
// we will show the possibility to add a first line
|
|
352
|
-
addLine.style.display = 'block';
|
|
353
|
-
addLineAbove.style.display = 'none';
|
|
354
|
-
addLineBelow.style.display = 'none';
|
|
355
|
-
deleteLine.style.display = 'none';
|
|
356
|
-
|
|
357
|
-
// show menu
|
|
358
|
-
self._showMenu(menu);
|
|
359
|
-
}
|
|
360
|
-
else if (e.target !== self._stage) {
|
|
361
|
-
currentIndicator = e.target;
|
|
362
|
-
|
|
363
|
-
addLine.style.display = 'none';
|
|
364
|
-
addLineAbove.style.display = 'block';
|
|
365
|
-
addLineBelow.style.display = 'block';
|
|
366
|
-
deleteLine.style.display = 'block';
|
|
367
|
-
|
|
368
|
-
deleteLine.disabled = !self._indicators[currentIndicator.getAttr('lineId')].line.isEmpty();
|
|
369
|
-
|
|
370
|
-
// show menu
|
|
371
|
-
self._showMenu(menu);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
return LineIndicator;
|
|
377
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link LineIndicator} class.
|
|
5
|
+
*
|
|
6
|
+
* @module line-indicator
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
define([
|
|
10
|
+
'konva',
|
|
11
|
+
'./utils'
|
|
12
|
+
], function(
|
|
13
|
+
Konva,
|
|
14
|
+
Utils) {
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a Konva.Stage that displays a representation of each line.
|
|
19
|
+
*
|
|
20
|
+
* @class
|
|
21
|
+
* @alias LineIndicator
|
|
22
|
+
*
|
|
23
|
+
* @param {Peaks} peaks
|
|
24
|
+
* @param {WaveformOverview|WaveformZoomView} view
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
function LineIndicator(peaks, view, container) {
|
|
28
|
+
this._peaks = peaks;
|
|
29
|
+
this._view = view;
|
|
30
|
+
this._container = container;
|
|
31
|
+
|
|
32
|
+
this._width = this._peaks.options.lineIndicatorWidth;
|
|
33
|
+
this._height = this._view.getHeight();
|
|
34
|
+
|
|
35
|
+
this._indicatorRadius = this._width / 4;
|
|
36
|
+
|
|
37
|
+
this._stage = new Konva.Stage({
|
|
38
|
+
container: container,
|
|
39
|
+
width: this._width,
|
|
40
|
+
height: this._height
|
|
41
|
+
});
|
|
42
|
+
this._layer = new Konva.Layer();
|
|
43
|
+
this._stage.add(this._layer);
|
|
44
|
+
|
|
45
|
+
this._indicators = {};
|
|
46
|
+
|
|
47
|
+
this._layer.add(
|
|
48
|
+
new Konva.Line({
|
|
49
|
+
points: [this._width, 0, this._width, this._height],
|
|
50
|
+
stroke: 'gray',
|
|
51
|
+
strokeWidth: 1,
|
|
52
|
+
listening: false
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
this._layer.draw();
|
|
57
|
+
|
|
58
|
+
if (this._peaks.options.enableLineIndicatorContextMenu) {
|
|
59
|
+
this._createContextMenu();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* eslint-disable max-len */
|
|
63
|
+
this.ICON_SIZE = 18;
|
|
64
|
+
this._volumeSVGPath = 'M0 6.00001V12H4L9 17V1.00001L4 6.00001H0ZM13.5 9.00001C13.5 7.23001 12.48 5.71001 11 4.97001V13.02C12.48 12.29 13.5 10.77 13.5 9.00001ZM11 0.230011V2.29001C13.89 3.15001 16 5.83001 16 9.00001C16 12.17 13.89 14.85 11 15.71V17.77C15.01 16.86 18 13.28 18 9.00001C18 4.72001 15.01 1.14001 11 0.230011Z';
|
|
65
|
+
this._noVolumeSVGPath = 'M13.5 9C13.5 7.23 12.48 5.71 11 4.97V7.18L13.45 9.63C13.48 9.43 13.5 9.22 13.5 9ZM16 9C16 9.94 15.8 10.82 15.46 11.64L16.97 13.15C17.63 11.91 18 10.5 18 9C18 4.72 15.01 1.14 11 0.23V2.29C13.89 3.15 16 5.83 16 9ZM1.27 0L0 1.27L4.73 6H0V12H4L9 17V10.27L13.25 14.52C12.58 15.04 11.83 15.45 11 15.7V17.76C12.38 17.45 13.63 16.81 14.69 15.95L16.73 18L18 16.73L9 7.73L1.27 0ZM9 1L6.91 3.09L9 5.18V1Z';
|
|
66
|
+
/* eslint-enable max-len */
|
|
67
|
+
|
|
68
|
+
this._peaks.on('lineIndicator.setType', this._onSetType.bind(this));
|
|
69
|
+
|
|
70
|
+
this._types = ['default', 'volume', 'noVolume'];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
LineIndicator.prototype._onSetType = function(lineId, type) {
|
|
74
|
+
this.removeIndicator(lineId, true);
|
|
75
|
+
|
|
76
|
+
type = this._types.includes(type) ? type : 'default';
|
|
77
|
+
|
|
78
|
+
var indicator = this._createIndicator(
|
|
79
|
+
this._indicators[lineId].line,
|
|
80
|
+
type
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
this._layer.add(indicator);
|
|
84
|
+
|
|
85
|
+
this._indicators[lineId].indicator = indicator;
|
|
86
|
+
this._indicators[lineId].type = type;
|
|
87
|
+
|
|
88
|
+
this.draw();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
LineIndicator.prototype._showMenu = function(menu) {
|
|
92
|
+
menu.style.display = 'block';
|
|
93
|
+
var containerRect = this._stage.container().getBoundingClientRect();
|
|
94
|
+
|
|
95
|
+
menu.style.top = containerRect.top
|
|
96
|
+
+ this._stage.getPointerPosition().y
|
|
97
|
+
- menu.offsetHeight + 'px';
|
|
98
|
+
menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
LineIndicator.prototype._createIndicator = function(line, type) {
|
|
102
|
+
var indicator;
|
|
103
|
+
|
|
104
|
+
type = typeof type !== 'undefined' ? type : 'default';
|
|
105
|
+
|
|
106
|
+
if (type === 'default') {
|
|
107
|
+
indicator = new Konva.Circle({
|
|
108
|
+
x: this._width / 2,
|
|
109
|
+
y: line.getY() + (line.lineHeight() / 2),
|
|
110
|
+
radius: this._indicatorRadius,
|
|
111
|
+
fill: this._peaks.options.lineIndicatorColor,
|
|
112
|
+
strokeWidth: 0,
|
|
113
|
+
lineId: line.getId()
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
var scaleFactor = (this._width / 2) / this.ICON_SIZE;
|
|
118
|
+
|
|
119
|
+
indicator = new Konva.Path({
|
|
120
|
+
x: this._width / 4,
|
|
121
|
+
y: line.getY() + (line.lineHeight() / 2) - (this._width / 4),
|
|
122
|
+
data: type === 'volume' ?
|
|
123
|
+
this._volumeSVGPath :
|
|
124
|
+
this._noVolumeSVGPath,
|
|
125
|
+
fill: this._peaks.options.lineIndicatorColor,
|
|
126
|
+
scale: {
|
|
127
|
+
x: scaleFactor,
|
|
128
|
+
y: scaleFactor
|
|
129
|
+
},
|
|
130
|
+
lineId: line.getId()
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
var self = this;
|
|
135
|
+
|
|
136
|
+
indicator.on('mouseover', function() {
|
|
137
|
+
indicator.fill(self._peaks.options.lineIndicatorSelected);
|
|
138
|
+
self.draw();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
indicator.on('mouseout', function() {
|
|
142
|
+
indicator.fill(self._peaks.options.lineIndicatorColor);
|
|
143
|
+
self.draw();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
indicator.on('click', function(e) {
|
|
147
|
+
self._peaks.emit('lineIndicator.click', self._indicators[line.getId()], e.evt);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return indicator;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
LineIndicator.prototype.addIndicator = function(line) {
|
|
154
|
+
if (!this._indicators[line.getId()]) {
|
|
155
|
+
var indicator = this._createIndicator(line);
|
|
156
|
+
|
|
157
|
+
this._layer.add(indicator);
|
|
158
|
+
|
|
159
|
+
this._indicators[line.getId()] = {
|
|
160
|
+
indicator: indicator,
|
|
161
|
+
line: line,
|
|
162
|
+
type: 'default'
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
|
|
168
|
+
if (this._indicators[lineId]) {
|
|
169
|
+
if (this._indicators[lineId].indicator) {
|
|
170
|
+
this._indicators[lineId].indicator.destroy();
|
|
171
|
+
}
|
|
172
|
+
if (!keepInList) {
|
|
173
|
+
delete this._indicators[lineId];
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this._indicators[lineId].indicator = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
LineIndicator.prototype.getPixelsFromCenter = function(lineId) {
|
|
182
|
+
return this._indicators[lineId].type === 'default' ?
|
|
183
|
+
0 :
|
|
184
|
+
this._width / 4;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
LineIndicator.prototype.updateIndicator = function(lineId) {
|
|
188
|
+
if (this._indicators[lineId]) {
|
|
189
|
+
var y = this._indicators[lineId].line.getY()
|
|
190
|
+
+ (this._indicators[lineId].line.lineHeight() / 2);
|
|
191
|
+
|
|
192
|
+
if (y + this._indicatorRadius > 0 && y - this._indicatorRadius < this._height) {
|
|
193
|
+
// The indicator is visible
|
|
194
|
+
if (!this._indicators[lineId].indicator) {
|
|
195
|
+
this._indicators[lineId].indicator = this._createIndicator(
|
|
196
|
+
this._indicators[lineId].line,
|
|
197
|
+
this._indicators[lineId].type
|
|
198
|
+
);
|
|
199
|
+
this._layer.add(this._indicators[lineId].indicator);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this._indicators[lineId].indicator.y(y - this.getPixelsFromCenter(lineId));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
// The indicator is out of the view, we remove it
|
|
207
|
+
this.removeIndicator(lineId, true);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
LineIndicator.prototype.updateIndicators = function() {
|
|
213
|
+
for (var lineId in this._indicators) {
|
|
214
|
+
if (Utils.objectHasProperty(this._indicators, lineId)) {
|
|
215
|
+
this.updateIndicator(lineId);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
LineIndicator.prototype.draw = function() {
|
|
221
|
+
this._layer.draw();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
LineIndicator.prototype._createContextMenu = function() {
|
|
225
|
+
var menu = document.createElement('div');
|
|
226
|
+
var addLine = document.createElement('button');
|
|
227
|
+
var addLineAbove = document.createElement('button');
|
|
228
|
+
var addLineBelow = document.createElement('button');
|
|
229
|
+
var deleteLine = document.createElement('button');
|
|
230
|
+
var currentIndicator = null;
|
|
231
|
+
var self = this;
|
|
232
|
+
|
|
233
|
+
menu.style.display = 'none';
|
|
234
|
+
menu.style.position = 'absolute';
|
|
235
|
+
menu.style.backgroundColor = 'white';
|
|
236
|
+
menu.style.boxShadow = '0 0 5px grey';
|
|
237
|
+
menu.style.borderRadius = '3px';
|
|
238
|
+
menu.style.zIndex = 2;
|
|
239
|
+
|
|
240
|
+
addLine.style.display = 'none';
|
|
241
|
+
addLine.style.border = 'none';
|
|
242
|
+
addLine.style.margin = '0';
|
|
243
|
+
addLine.style.width = '100%';
|
|
244
|
+
addLine.style.backgroundColor = 'white';
|
|
245
|
+
addLine.style.padding = '10px';
|
|
246
|
+
|
|
247
|
+
addLine.textContent = 'Add first line';
|
|
248
|
+
|
|
249
|
+
addLine.onmouseover = function() {
|
|
250
|
+
this.style.backgroundColor = 'lightgray';
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
addLine.onmouseout = function() {
|
|
254
|
+
this.style.backgroundColor = 'white';
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
addLineAbove.style.display = 'none';
|
|
258
|
+
addLineAbove.style.border = 'none';
|
|
259
|
+
addLineAbove.style.margin = '0';
|
|
260
|
+
addLineAbove.style.width = '100%';
|
|
261
|
+
addLineAbove.style.backgroundColor = 'white';
|
|
262
|
+
addLineAbove.style.padding = '10px';
|
|
263
|
+
|
|
264
|
+
addLineAbove.textContent = 'Add line above';
|
|
265
|
+
|
|
266
|
+
addLineAbove.onmouseover = function() {
|
|
267
|
+
this.style.backgroundColor = 'lightgray';
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
addLineAbove.onmouseout = function() {
|
|
271
|
+
this.style.backgroundColor = 'white';
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
addLineBelow.style.display = 'none';
|
|
275
|
+
addLineBelow.style.border = 'none';
|
|
276
|
+
addLineBelow.style.margin = '0';
|
|
277
|
+
addLineBelow.style.width = '100%';
|
|
278
|
+
addLineBelow.style.backgroundColor = 'white';
|
|
279
|
+
addLineBelow.style.padding = '10px';
|
|
280
|
+
|
|
281
|
+
addLineBelow.textContent = 'Add line below';
|
|
282
|
+
|
|
283
|
+
addLineBelow.onmouseover = function() {
|
|
284
|
+
this.style.backgroundColor = 'lightgray';
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
addLineBelow.onmouseout = function() {
|
|
288
|
+
this.style.backgroundColor = 'white';
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
deleteLine.style.display = 'none';
|
|
292
|
+
deleteLine.style.border = 'none';
|
|
293
|
+
deleteLine.style.margin = '0';
|
|
294
|
+
deleteLine.style.width = '100%';
|
|
295
|
+
deleteLine.style.backgroundColor = 'white';
|
|
296
|
+
deleteLine.style.padding = '10px';
|
|
297
|
+
|
|
298
|
+
deleteLine.textContent = 'Delete line';
|
|
299
|
+
|
|
300
|
+
deleteLine.onmouseover = function() {
|
|
301
|
+
this.style.backgroundColor = 'lightgray';
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
deleteLine.onmouseout = function() {
|
|
305
|
+
this.style.backgroundColor = 'white';
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
menu.appendChild(addLine);
|
|
309
|
+
menu.appendChild(addLineAbove);
|
|
310
|
+
menu.appendChild(addLineBelow);
|
|
311
|
+
menu.appendChild(deleteLine);
|
|
312
|
+
this._container.appendChild(menu);
|
|
313
|
+
|
|
314
|
+
addLine.addEventListener('click', function() {
|
|
315
|
+
self._peaks.emit('line.add', 0);
|
|
316
|
+
self.draw();
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
addLineAbove.addEventListener('click', function() {
|
|
320
|
+
var line = self._indicators[currentIndicator.getAttr('lineId')].line;
|
|
321
|
+
|
|
322
|
+
self._peaks.emit('line.add', Number(line.getPosition()));
|
|
323
|
+
self.draw();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
addLineBelow.addEventListener('click', function() {
|
|
327
|
+
var line = self._indicators[currentIndicator.getAttr('lineId')].line;
|
|
328
|
+
|
|
329
|
+
self._peaks.emit('line.add', Number(line.getPosition()) + 1);
|
|
330
|
+
self.draw();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
deleteLine.addEventListener('click', function() {
|
|
334
|
+
var line = self._indicators[currentIndicator.getAttr('lineId')].line;
|
|
335
|
+
|
|
336
|
+
self._peaks.emit('line.remove', Number(line.getPosition()));
|
|
337
|
+
self.draw();
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
window.addEventListener('click', function() {
|
|
341
|
+
// hide menu
|
|
342
|
+
menu.style.display = 'none';
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
this._stage.on('contextmenu', function(e) {
|
|
346
|
+
// prevent default behavior
|
|
347
|
+
e.evt.preventDefault();
|
|
348
|
+
|
|
349
|
+
if (e.target === self._stage && Object.keys(self._indicators).length === 0) {
|
|
350
|
+
// if we are on empty place of the stage
|
|
351
|
+
// we will show the possibility to add a first line
|
|
352
|
+
addLine.style.display = 'block';
|
|
353
|
+
addLineAbove.style.display = 'none';
|
|
354
|
+
addLineBelow.style.display = 'none';
|
|
355
|
+
deleteLine.style.display = 'none';
|
|
356
|
+
|
|
357
|
+
// show menu
|
|
358
|
+
self._showMenu(menu);
|
|
359
|
+
}
|
|
360
|
+
else if (e.target !== self._stage) {
|
|
361
|
+
currentIndicator = e.target;
|
|
362
|
+
|
|
363
|
+
addLine.style.display = 'none';
|
|
364
|
+
addLineAbove.style.display = 'block';
|
|
365
|
+
addLineBelow.style.display = 'block';
|
|
366
|
+
deleteLine.style.display = 'block';
|
|
367
|
+
|
|
368
|
+
deleteLine.disabled = !self._indicators[currentIndicator.getAttr('lineId')].line.isEmpty();
|
|
369
|
+
|
|
370
|
+
// show menu
|
|
371
|
+
self._showMenu(menu);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
return LineIndicator;
|
|
377
|
+
});
|