@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/src/lines.js CHANGED
@@ -1,427 +1,427 @@
1
- /**
2
- * @file
3
- *
4
- * Defines the {@link lines} class.
5
- *
6
- * @module lines
7
- */
8
-
9
- define([
10
- './segments-group',
11
- './line',
12
- './line-indicator',
13
- './utils'
14
- ], function(
15
- SegmentsGroup,
16
- Line,
17
- LineIndicator,
18
- Utils) {
19
- 'use strict';
20
-
21
- function Lines(peaks, view, layer) {
22
- this._peaks = peaks;
23
- this._view = view;
24
- this._layer = layer;
25
- this._linesBySourceId = {};
26
- this._linesByPosition = {};
27
- this._autoAddToLayer = false;
28
- this._areSourceInteractionsAllowed = true;
29
- this._areSegmentInteractionsAllowed = true;
30
-
31
- this._segmentsGroups = {};
32
- this._segmentsGroupToLine = {};
33
-
34
- this._lineId = 0;
35
-
36
- this._lineIndicator = new LineIndicator(
37
- peaks,
38
- view,
39
- document.getElementById('line-indicator-container')
40
- );
41
-
42
- this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
43
- this._peaks.on('line.add', this._onLineAdd.bind(this));
44
- this._peaks.on('line.remove', this._onLineRemove.bind(this));
45
-
46
- this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
47
- this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
48
- this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
49
- this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
50
- this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
51
- }
52
-
53
- Lines.prototype._onSegmentsAdd = function(segments) {
54
- var self = this;
55
-
56
- segments.forEach(function(segment) {
57
- if (!self._segmentsGroups[segment.line]) {
58
- self._segmentsGroups[segment.line] = new SegmentsGroup(self._peaks, self._view, true);
59
- }
60
-
61
- self._segmentsGroups[segment.line].onSegmentsAdd([segment]);
62
- if (Utils.objectHasProperty(self._segmentsGroupToLine, segment.line)) {
63
- self._segmentsGroupToLine[segment.line].refreshSegmentsHeight();
64
- }
65
- });
66
- };
67
-
68
- Lines.prototype._onSegmentsUpdate = function(segment) {
69
- this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
70
- };
71
-
72
- Lines.prototype._onSegmentUpdated = function(segment) {
73
- this._segmentsGroups[segment.line].onSegmentUpdated();
74
- };
75
-
76
- Lines.prototype._onSegmentsRemove = function(segments) {
77
- var self = this;
78
-
79
- segments.forEach(function(segment) {
80
- self._segmentsGroups[segment.line].onSegmentsRemove([segment]);
81
- });
82
- };
83
-
84
- Lines.prototype._onSegmentsRemoveAll = function(lineId) {
85
- this._segmentsGroups[lineId].onSegmentsRemoveAll();
86
-
87
- if (Utils.objectHasProperty(this._segmentsGroupToLine, lineId)) {
88
- this._segmentsGroupToLine[lineId].refreshSegmentsHeight();
89
- }
90
- };
91
-
92
- Lines.prototype._onLineHeightChanged = function(position) {
93
- this._updateLinesPosition(position);
94
- this._view.updateTimeline();
95
- };
96
-
97
- Lines.prototype._onLineAdd = function(position) {
98
- this._createLine(position);
99
- this._setInteractions(position);
100
- this._updateLinesPosition(position);
101
- };
102
-
103
- Lines.prototype._onLineRemove = function(position) {
104
- var oldLine = this.removeLine(position);
105
- var lineNewY = oldLine.getY();
106
-
107
- this._updateLinesPosition(position, lineNewY);
108
- };
109
-
110
- Lines.prototype.changeLineHeight = function(from, to) {
111
- for (var position in this._linesByPosition) {
112
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
113
- if (!this._linesByPosition[position].isSegmentsLine()) {
114
- this._linesByPosition[position].changeHeight(from, to);
115
- }
116
- }
117
- }
118
- };
119
-
120
- Lines.prototype.addSourceGroup = function(sourceGroup, position) {
121
- if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
122
- this._createLine(position);
123
- this._setInteractions(position);
124
- }
125
-
126
- sourceGroup.getSource().position = position;
127
- this._linesByPosition[position].addSourceGroup(sourceGroup);
128
- this._linesBySourceId[sourceGroup.getSource().id] = this._linesByPosition[position];
129
- };
130
-
131
- Lines.prototype.addSegments = function(lineId, position) {
132
- this._createLine(position);
133
-
134
- this._linesByPosition[position].allowInteractions(this._areSegmentInteractionsAllowed);
135
- this._linesByPosition[position].addSegments(this._segmentsGroups[lineId]);
136
-
137
- this._segmentsGroupToLine[lineId] = this._linesByPosition[position];
138
-
139
- this._setInteractions(position);
140
-
141
- this._updateLinesPosition(position);
142
- };
143
-
144
- Lines.prototype.removeSourceGroup = function(source, isPermanent) {
145
- var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, isPermanent);
146
-
147
- if (isPermanent) {
148
- delete this._linesBySourceId[source.id];
149
- this._updateLinesPosition(source.position);
150
- }
151
-
152
- return sourceGroup;
153
- };
154
-
155
- Lines.prototype.removeLine = function(pos) {
156
- var oldLine = this._linesByPosition[pos];
157
-
158
- oldLine.destroy();
159
-
160
- delete this._linesByPosition[pos];
161
-
162
- this._lineIndicator.removeIndicator(oldLine.getId(), false);
163
-
164
- return oldLine;
165
- };
166
-
167
- Lines.prototype.isLineVisible = function(position) {
168
- return this._linesByPosition[position].isVisible();
169
- };
170
-
171
- Lines.prototype.getVisibleLines = function() {
172
- var positions = {};
173
-
174
- for (var position in this._linesByPosition) {
175
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
176
- if (this._linesByPosition[position].isVisible()) {
177
- positions[position] = true;
178
- }
179
- }
180
- }
181
- return positions;
182
- };
183
-
184
- Lines.prototype.getSegmentsGroups = function() {
185
- return this._segmentsGroups;
186
- };
187
-
188
- Lines.prototype.addToLayer = function(layer) {
189
- for (var position in this._linesByPosition) {
190
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
191
- this._linesByPosition[position].addToLayer(layer);
192
- }
193
- }
194
-
195
- this._autoAddToLayer = true;
196
- };
197
-
198
- Lines.prototype.updateLines = function(position) {
199
- this._updateLinesPosition(position);
200
- };
201
-
202
- Lines.prototype._updateLinesPosition = function(position, forceNewY) {
203
- var line = this._linesByPosition[position];
204
- var dy = null;
205
- var newY;
206
-
207
- if (forceNewY) {
208
- newY = forceNewY;
209
- }
210
- else {
211
- newY = line.getY() + line.lineHeight() + this._peaks.options.interline;
212
- }
213
-
214
- for (var pos in this._linesByPosition) {
215
- if (Utils.objectHasProperty(this._linesByPosition, pos)) {
216
- if (parseInt(pos, 10) > position) {
217
- if (dy === null) {
218
- dy = newY - this._linesByPosition[pos].getY();
219
- this._linesByPosition[pos].moveOnY(dy);
220
- }
221
- else {
222
- this._linesByPosition[pos].moveOnY(dy);
223
- }
224
- }
225
- }
226
- }
227
-
228
- this._lineIndicator.updateIndicators();
229
- this._lineIndicator.draw();
230
-
231
- this._view.drawSourcesLayer();
232
- };
233
-
234
- Lines.prototype.setOffsetY = function(frameOffset) {
235
- for (var position in this._linesByPosition) {
236
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
237
- var line = this._linesByPosition[position];
238
-
239
- line.y(line.getInitialY() - frameOffset);
240
- }
241
- }
242
-
243
- this._lineIndicator.updateIndicators();
244
- this._lineIndicator.draw();
245
- };
246
-
247
- Lines.prototype.height = function() {
248
- var height = 2 * this._peaks.options.padding;
249
-
250
- for (var position in this._linesByPosition) {
251
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
252
- height += this._linesByPosition[position].lineHeight() + this._peaks.options.interline;
253
- }
254
- }
255
-
256
- height -= this._peaks.options.interline;
257
-
258
- return height;
259
- };
260
-
261
- Lines.prototype.linesLength = function() {
262
- var length = 0;
263
-
264
- for (var position in this._linesByPosition) {
265
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
266
- var lineLength = this._linesByPosition[position].lineLength();
267
-
268
- if (lineLength > length) {
269
- length = lineLength;
270
- }
271
- }
272
- }
273
-
274
- return length;
275
- };
276
-
277
- Lines.prototype.manageVerticalPosition = function(source, newY) {
278
- if (newY !== null && newY !== undefined) {
279
- var pos = this.getLineOnPosition(newY);
280
-
281
- if (pos[0] === pos[1]
282
- && pos[0] !== source.position
283
- && !this._linesByPosition[pos[0]].isSegmentsLine()) {
284
- this.moveSourceToPosition(source, pos[0]);
285
- }
286
- }
287
- };
288
-
289
- Lines.prototype.getLineByPosition = function(pos) {
290
- return this._linesByPosition[pos];
291
- };
292
-
293
- Lines.prototype.getLineOnPosition = function(y) {
294
- var height;
295
- var pos = [-1, Number.MAX_VALUE];
296
-
297
- for (var position in this._linesByPosition) {
298
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
299
- height = this._linesByPosition[position].lineHeight();
300
-
301
- if (y > this._linesByPosition[position].getY()) {
302
- pos[0] = Math.max(pos[0], parseInt(position, 10));
303
- }
304
-
305
- if (y < this._linesByPosition[position].getY() + height) {
306
- pos[1] = Math.min(pos[1], parseInt(position, 10));
307
- }
308
- }
309
- }
310
-
311
- return pos;
312
- };
313
-
314
- Lines.prototype.moveSourceToPosition = function(source, pos) {
315
- var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, true);
316
-
317
- delete this._linesBySourceId[source.id];
318
-
319
- sourceGroup.moveTo(this._linesByPosition[pos].getKonvaGroup());
320
-
321
- this._updateLinesPosition(source.position);
322
-
323
- this.addSourceGroup(sourceGroup, pos);
324
- };
325
-
326
- Lines.prototype._getNextLineId = function() {
327
- this._lineId++;
328
- return this._lineId;
329
- };
330
-
331
- Lines.prototype._createLine = function(position) {
332
- var y = this._peaks.options.padding;
333
- var currentPos;
334
- var newLinesByPosition = Object.assign({},this._linesByPosition);
335
-
336
- for (var pos in this._linesByPosition) {
337
- if (Utils.objectHasProperty(this._linesByPosition, pos)) {
338
- currentPos = parseInt(pos, 10);
339
- if (currentPos < position) {
340
- y += this._linesByPosition[pos].lineHeight() + this._peaks.options.interline;
341
- }
342
- else {
343
- if (this._linesByPosition[position]) {
344
- this._linesByPosition[currentPos].updatePosition(currentPos + 1);
345
- newLinesByPosition[currentPos + 1] = this._linesByPosition[currentPos];
346
- }
347
- }
348
- }
349
- }
350
-
351
- var line = new Line(this._peaks, this._view, y, this._getNextLineId(), position);
352
-
353
- this._lineIndicator.addIndicator(line);
354
-
355
- if (this._autoAddToLayer) {
356
- line.addToLayer(this._layer);
357
- }
358
-
359
- newLinesByPosition[position] = line;
360
- this._linesByPosition = newLinesByPosition;
361
- };
362
-
363
- Lines.prototype.updateSegments = function(frameStartTime, frameEndTime) {
364
- for (var lineId in this._segmentsGroups) {
365
- if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
366
- this._segmentsGroups[lineId].updateSegments(frameStartTime, frameEndTime);
367
- }
368
- }
369
- };
370
-
371
- Lines.prototype.manageCollision = function(source, newStartX, newEndX) {
372
- return this._linesBySourceId[source.id].manageCollision(source, newStartX, newEndX);
373
- };
374
-
375
- Lines.prototype.manageSourceOrder = function(source, newStartX, newEndX) {
376
- return this._linesBySourceId[source.id].manageSourceOrder(source, newStartX, newEndX);
377
- };
378
-
379
- // Lines.prototype.rescale = function() {
380
- // for (var position in this._linesByPosition) {
381
- // if (Utils.objectHasProperty(this._linesByPosition, position)) {
382
- // this._linesByPosition[position].rescale();
383
- // }
384
- // }
385
- // };
386
-
387
- Lines.prototype._setInteractions = function(position) {
388
- var line = this._linesByPosition[position];
389
-
390
- if (this._areInteractionsOverridden) {
391
- line.allowInteractions(this._areInteractionsAllowed);
392
- }
393
- else {
394
- line.allowInteractions(
395
- line.isSegmentsLine() ?
396
- this._areSegmentInteractionsAllowed :
397
- this._areSourceInteractionsAllowed
398
- );
399
- }
400
- };
401
-
402
- Lines.prototype.overrideInteractions = function(bool, areInteractionsAllowed) {
403
- this._areInteractionsOverridden = typeof bool !== 'undefined' ?
404
- bool : this._areInteractionsOverridden;
405
- this._areInteractionsAllowed = typeof areInteractionsAllowed !== 'undefined' ?
406
- areInteractionsAllowed : this._areInteractionsAllowed;
407
- for (var position in this._linesByPosition) {
408
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
409
- this._setInteractions(position);
410
- }
411
- }
412
- };
413
-
414
- Lines.prototype.allowInteractions = function(forSources, forSegments) {
415
- this._areSourceInteractionsAllowed = typeof forSources !== 'undefined' ?
416
- forSources : this._areSourceInteractionsAllowed;
417
- this._areSegmentInteractionsAllowed = typeof forSegments !== 'undefined' ?
418
- forSegments : this._areSegmentInteractionsAllowed;
419
- for (var position in this._linesByPosition) {
420
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
421
- this._setInteractions(position);
422
- }
423
- }
424
- };
425
-
426
- return Lines;
427
- });
1
+ /**
2
+ * @file
3
+ *
4
+ * Defines the {@link lines} class.
5
+ *
6
+ * @module lines
7
+ */
8
+
9
+ define([
10
+ './segments-group',
11
+ './line',
12
+ './line-indicator',
13
+ './utils'
14
+ ], function(
15
+ SegmentsGroup,
16
+ Line,
17
+ LineIndicator,
18
+ Utils) {
19
+ 'use strict';
20
+
21
+ function Lines(peaks, view, layer) {
22
+ this._peaks = peaks;
23
+ this._view = view;
24
+ this._layer = layer;
25
+ this._linesBySourceId = {};
26
+ this._linesByPosition = {};
27
+ this._autoAddToLayer = false;
28
+ this._areSourceInteractionsAllowed = true;
29
+ this._areSegmentInteractionsAllowed = true;
30
+
31
+ this._segmentsGroups = {};
32
+ this._segmentsGroupToLine = {};
33
+
34
+ this._lineId = 0;
35
+
36
+ this._lineIndicator = new LineIndicator(
37
+ peaks,
38
+ view,
39
+ document.getElementById('line-indicator-container')
40
+ );
41
+
42
+ this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
43
+ this._peaks.on('line.add', this._onLineAdd.bind(this));
44
+ this._peaks.on('line.remove', this._onLineRemove.bind(this));
45
+
46
+ this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
47
+ this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
48
+ this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
49
+ this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
50
+ this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
51
+ }
52
+
53
+ Lines.prototype._onSegmentsAdd = function(segments) {
54
+ var self = this;
55
+
56
+ segments.forEach(function(segment) {
57
+ if (!self._segmentsGroups[segment.line]) {
58
+ self._segmentsGroups[segment.line] = new SegmentsGroup(self._peaks, self._view, true);
59
+ }
60
+
61
+ self._segmentsGroups[segment.line].onSegmentsAdd([segment]);
62
+ if (Utils.objectHasProperty(self._segmentsGroupToLine, segment.line)) {
63
+ self._segmentsGroupToLine[segment.line].refreshSegmentsHeight();
64
+ }
65
+ });
66
+ };
67
+
68
+ Lines.prototype._onSegmentsUpdate = function(segment) {
69
+ this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
70
+ };
71
+
72
+ Lines.prototype._onSegmentUpdated = function(segment) {
73
+ this._segmentsGroups[segment.line].onSegmentUpdated();
74
+ };
75
+
76
+ Lines.prototype._onSegmentsRemove = function(segments) {
77
+ var self = this;
78
+
79
+ segments.forEach(function(segment) {
80
+ self._segmentsGroups[segment.line].onSegmentsRemove([segment]);
81
+ });
82
+ };
83
+
84
+ Lines.prototype._onSegmentsRemoveAll = function(lineId) {
85
+ this._segmentsGroups[lineId].onSegmentsRemoveAll();
86
+
87
+ if (Utils.objectHasProperty(this._segmentsGroupToLine, lineId)) {
88
+ this._segmentsGroupToLine[lineId].refreshSegmentsHeight();
89
+ }
90
+ };
91
+
92
+ Lines.prototype._onLineHeightChanged = function(position) {
93
+ this._updateLinesPosition(position);
94
+ this._view.updateTimeline();
95
+ };
96
+
97
+ Lines.prototype._onLineAdd = function(position) {
98
+ this._createLine(position);
99
+ this._setInteractions(position);
100
+ this._updateLinesPosition(position);
101
+ };
102
+
103
+ Lines.prototype._onLineRemove = function(position) {
104
+ var oldLine = this.removeLine(position);
105
+ var lineNewY = oldLine.getY();
106
+
107
+ this._updateLinesPosition(position, lineNewY);
108
+ };
109
+
110
+ Lines.prototype.changeLineHeight = function(from, to) {
111
+ for (var position in this._linesByPosition) {
112
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
113
+ if (!this._linesByPosition[position].isSegmentsLine()) {
114
+ this._linesByPosition[position].changeHeight(from, to);
115
+ }
116
+ }
117
+ }
118
+ };
119
+
120
+ Lines.prototype.addSourceGroup = function(sourceGroup, position) {
121
+ if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
122
+ this._createLine(position);
123
+ this._setInteractions(position);
124
+ }
125
+
126
+ sourceGroup.getSource().position = position;
127
+ this._linesByPosition[position].addSourceGroup(sourceGroup);
128
+ this._linesBySourceId[sourceGroup.getSource().id] = this._linesByPosition[position];
129
+ };
130
+
131
+ Lines.prototype.addSegments = function(lineId, position) {
132
+ this._createLine(position);
133
+
134
+ this._linesByPosition[position].allowInteractions(this._areSegmentInteractionsAllowed);
135
+ this._linesByPosition[position].addSegments(this._segmentsGroups[lineId]);
136
+
137
+ this._segmentsGroupToLine[lineId] = this._linesByPosition[position];
138
+
139
+ this._setInteractions(position);
140
+
141
+ this._updateLinesPosition(position);
142
+ };
143
+
144
+ Lines.prototype.removeSourceGroup = function(source, isPermanent) {
145
+ var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, isPermanent);
146
+
147
+ if (isPermanent) {
148
+ delete this._linesBySourceId[source.id];
149
+ this._updateLinesPosition(source.position);
150
+ }
151
+
152
+ return sourceGroup;
153
+ };
154
+
155
+ Lines.prototype.removeLine = function(pos) {
156
+ var oldLine = this._linesByPosition[pos];
157
+
158
+ oldLine.destroy();
159
+
160
+ delete this._linesByPosition[pos];
161
+
162
+ this._lineIndicator.removeIndicator(oldLine.getId(), false);
163
+
164
+ return oldLine;
165
+ };
166
+
167
+ Lines.prototype.isLineVisible = function(position) {
168
+ return this._linesByPosition[position].isVisible();
169
+ };
170
+
171
+ Lines.prototype.getVisibleLines = function() {
172
+ var positions = {};
173
+
174
+ for (var position in this._linesByPosition) {
175
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
176
+ if (this._linesByPosition[position].isVisible()) {
177
+ positions[position] = true;
178
+ }
179
+ }
180
+ }
181
+ return positions;
182
+ };
183
+
184
+ Lines.prototype.getSegmentsGroups = function() {
185
+ return this._segmentsGroups;
186
+ };
187
+
188
+ Lines.prototype.addToLayer = function(layer) {
189
+ for (var position in this._linesByPosition) {
190
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
191
+ this._linesByPosition[position].addToLayer(layer);
192
+ }
193
+ }
194
+
195
+ this._autoAddToLayer = true;
196
+ };
197
+
198
+ Lines.prototype.updateLines = function(position) {
199
+ this._updateLinesPosition(position);
200
+ };
201
+
202
+ Lines.prototype._updateLinesPosition = function(position, forceNewY) {
203
+ var line = this._linesByPosition[position];
204
+ var dy = null;
205
+ var newY;
206
+
207
+ if (forceNewY) {
208
+ newY = forceNewY;
209
+ }
210
+ else {
211
+ newY = line.getY() + line.lineHeight() + this._peaks.options.interline;
212
+ }
213
+
214
+ for (var pos in this._linesByPosition) {
215
+ if (Utils.objectHasProperty(this._linesByPosition, pos)) {
216
+ if (parseInt(pos, 10) > position) {
217
+ if (dy === null) {
218
+ dy = newY - this._linesByPosition[pos].getY();
219
+ this._linesByPosition[pos].moveOnY(dy);
220
+ }
221
+ else {
222
+ this._linesByPosition[pos].moveOnY(dy);
223
+ }
224
+ }
225
+ }
226
+ }
227
+
228
+ this._lineIndicator.updateIndicators();
229
+ this._lineIndicator.draw();
230
+
231
+ this._view.drawSourcesLayer();
232
+ };
233
+
234
+ Lines.prototype.setOffsetY = function(frameOffset) {
235
+ for (var position in this._linesByPosition) {
236
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
237
+ var line = this._linesByPosition[position];
238
+
239
+ line.y(line.getInitialY() - frameOffset);
240
+ }
241
+ }
242
+
243
+ this._lineIndicator.updateIndicators();
244
+ this._lineIndicator.draw();
245
+ };
246
+
247
+ Lines.prototype.height = function() {
248
+ var height = 2 * this._peaks.options.padding;
249
+
250
+ for (var position in this._linesByPosition) {
251
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
252
+ height += this._linesByPosition[position].lineHeight() + this._peaks.options.interline;
253
+ }
254
+ }
255
+
256
+ height -= this._peaks.options.interline;
257
+
258
+ return height;
259
+ };
260
+
261
+ Lines.prototype.linesLength = function() {
262
+ var length = 0;
263
+
264
+ for (var position in this._linesByPosition) {
265
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
266
+ var lineLength = this._linesByPosition[position].lineLength();
267
+
268
+ if (lineLength > length) {
269
+ length = lineLength;
270
+ }
271
+ }
272
+ }
273
+
274
+ return length;
275
+ };
276
+
277
+ Lines.prototype.manageVerticalPosition = function(source, newY) {
278
+ if (newY !== null && newY !== undefined) {
279
+ var pos = this.getLineOnPosition(newY);
280
+
281
+ if (pos[0] === pos[1]
282
+ && pos[0] !== source.position
283
+ && !this._linesByPosition[pos[0]].isSegmentsLine()) {
284
+ this.moveSourceToPosition(source, pos[0]);
285
+ }
286
+ }
287
+ };
288
+
289
+ Lines.prototype.getLineByPosition = function(pos) {
290
+ return this._linesByPosition[pos];
291
+ };
292
+
293
+ Lines.prototype.getLineOnPosition = function(y) {
294
+ var height;
295
+ var pos = [-1, Number.MAX_VALUE];
296
+
297
+ for (var position in this._linesByPosition) {
298
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
299
+ height = this._linesByPosition[position].lineHeight();
300
+
301
+ if (y > this._linesByPosition[position].getY()) {
302
+ pos[0] = Math.max(pos[0], parseInt(position, 10));
303
+ }
304
+
305
+ if (y < this._linesByPosition[position].getY() + height) {
306
+ pos[1] = Math.min(pos[1], parseInt(position, 10));
307
+ }
308
+ }
309
+ }
310
+
311
+ return pos;
312
+ };
313
+
314
+ Lines.prototype.moveSourceToPosition = function(source, pos) {
315
+ var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, true);
316
+
317
+ delete this._linesBySourceId[source.id];
318
+
319
+ sourceGroup.moveTo(this._linesByPosition[pos].getKonvaGroup());
320
+
321
+ this._updateLinesPosition(source.position);
322
+
323
+ this.addSourceGroup(sourceGroup, pos);
324
+ };
325
+
326
+ Lines.prototype._getNextLineId = function() {
327
+ this._lineId++;
328
+ return this._lineId;
329
+ };
330
+
331
+ Lines.prototype._createLine = function(position) {
332
+ var y = this._peaks.options.padding;
333
+ var currentPos;
334
+ var newLinesByPosition = Object.assign({},this._linesByPosition);
335
+
336
+ for (var pos in this._linesByPosition) {
337
+ if (Utils.objectHasProperty(this._linesByPosition, pos)) {
338
+ currentPos = parseInt(pos, 10);
339
+ if (currentPos < position) {
340
+ y += this._linesByPosition[pos].lineHeight() + this._peaks.options.interline;
341
+ }
342
+ else {
343
+ if (this._linesByPosition[position]) {
344
+ this._linesByPosition[currentPos].updatePosition(currentPos + 1);
345
+ newLinesByPosition[currentPos + 1] = this._linesByPosition[currentPos];
346
+ }
347
+ }
348
+ }
349
+ }
350
+
351
+ var line = new Line(this._peaks, this._view, y, this._getNextLineId(), position);
352
+
353
+ this._lineIndicator.addIndicator(line);
354
+
355
+ if (this._autoAddToLayer) {
356
+ line.addToLayer(this._layer);
357
+ }
358
+
359
+ newLinesByPosition[position] = line;
360
+ this._linesByPosition = newLinesByPosition;
361
+ };
362
+
363
+ Lines.prototype.updateSegments = function(frameStartTime, frameEndTime) {
364
+ for (var lineId in this._segmentsGroups) {
365
+ if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
366
+ this._segmentsGroups[lineId].updateSegments(frameStartTime, frameEndTime);
367
+ }
368
+ }
369
+ };
370
+
371
+ Lines.prototype.manageCollision = function(source, newStartX, newEndX) {
372
+ return this._linesBySourceId[source.id].manageCollision(source, newStartX, newEndX);
373
+ };
374
+
375
+ Lines.prototype.manageSourceOrder = function(source, newStartX, newEndX) {
376
+ return this._linesBySourceId[source.id].manageSourceOrder(source, newStartX, newEndX);
377
+ };
378
+
379
+ // Lines.prototype.rescale = function() {
380
+ // for (var position in this._linesByPosition) {
381
+ // if (Utils.objectHasProperty(this._linesByPosition, position)) {
382
+ // this._linesByPosition[position].rescale();
383
+ // }
384
+ // }
385
+ // };
386
+
387
+ Lines.prototype._setInteractions = function(position) {
388
+ var line = this._linesByPosition[position];
389
+
390
+ if (this._areInteractionsOverridden) {
391
+ line.allowInteractions(this._areInteractionsAllowed);
392
+ }
393
+ else {
394
+ line.allowInteractions(
395
+ line.isSegmentsLine() ?
396
+ this._areSegmentInteractionsAllowed :
397
+ this._areSourceInteractionsAllowed
398
+ );
399
+ }
400
+ };
401
+
402
+ Lines.prototype.overrideInteractions = function(bool, areInteractionsAllowed) {
403
+ this._areInteractionsOverridden = typeof bool !== 'undefined' ?
404
+ bool : this._areInteractionsOverridden;
405
+ this._areInteractionsAllowed = typeof areInteractionsAllowed !== 'undefined' ?
406
+ areInteractionsAllowed : this._areInteractionsAllowed;
407
+ for (var position in this._linesByPosition) {
408
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
409
+ this._setInteractions(position);
410
+ }
411
+ }
412
+ };
413
+
414
+ Lines.prototype.allowInteractions = function(forSources, forSegments) {
415
+ this._areSourceInteractionsAllowed = typeof forSources !== 'undefined' ?
416
+ forSources : this._areSourceInteractionsAllowed;
417
+ this._areSegmentInteractionsAllowed = typeof forSegments !== 'undefined' ?
418
+ forSegments : this._areSegmentInteractionsAllowed;
419
+ for (var position in this._linesByPosition) {
420
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
421
+ this._setInteractions(position);
422
+ }
423
+ }
424
+ };
425
+
426
+ return Lines;
427
+ });