@checksub_team/peaks_timeline 1.4.30 → 1.4.33

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