@checksub_team/peaks_timeline 1.5.12 → 1.6.0-beta.0
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 +99 -108
- package/src/main.js +17 -2
- package/src/source-group.js +124 -130
- package/src/sources-layer.js +3 -4
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -15408,7 +15408,7 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
|
|
|
15408
15408
|
sources: null,
|
|
15409
15409
|
lineHeight: 80,
|
|
15410
15410
|
segmentHeight: 32,
|
|
15411
|
-
wrappedLineHeight:
|
|
15411
|
+
wrappedLineHeight: 30,
|
|
15412
15412
|
emptyLineHeight: 10,
|
|
15413
15413
|
interline: 10,
|
|
15414
15414
|
padding: 30,
|
|
@@ -15427,6 +15427,9 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
|
|
|
15427
15427
|
lineIndicatorIconColor: '#8A8F98',
|
|
15428
15428
|
lineIndicatorSelectedTextColor: '#ccc',
|
|
15429
15429
|
lineIndicatorSelectedIconColor: '#ccc',
|
|
15430
|
+
sourceSelectedBorderWidth: 3,
|
|
15431
|
+
sourceTextXOffset: 10,
|
|
15432
|
+
sourceTextYOffset: 10,
|
|
15430
15433
|
autoScrollThreshold: 0.05,
|
|
15431
15434
|
enableLineIndicatorContextMenu: true,
|
|
15432
15435
|
minSourceSize: 0.05,
|
|
@@ -17514,7 +17517,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17514
17517
|
var SPACING_BETWEEN_PREVIEWS = 1.5;
|
|
17515
17518
|
var HANDLE_WIDTH = 8;
|
|
17516
17519
|
var CORNER_RADIUS = 8;
|
|
17517
|
-
var SELECTED_BORDER_WIDTH = 6;
|
|
17518
17520
|
function SourceGroup(source, peaks, layer, view) {
|
|
17519
17521
|
this._source = source;
|
|
17520
17522
|
this._peaks = peaks;
|
|
@@ -17525,6 +17527,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17525
17527
|
this._width = this._view.timeToPixels(source.endTime - source.startTime);
|
|
17526
17528
|
this._unwrappedHeight = source.binaryHeight && source.previewHeight ? source.binaryHeight + source.previewHeight : this._peaks.options.lineHeight;
|
|
17527
17529
|
this._wrappedHeight = this._peaks.options.wrappedLineHeight;
|
|
17530
|
+
this._borderWidth = this._source.borderWidth;
|
|
17528
17531
|
this._previewList = [];
|
|
17529
17532
|
this._group = new Konva.Group({
|
|
17530
17533
|
x: this._x,
|
|
@@ -17534,9 +17537,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17534
17537
|
x: this.absolutePosition().x,
|
|
17535
17538
|
y: this.absolutePosition().y
|
|
17536
17539
|
};
|
|
17537
|
-
},
|
|
17538
|
-
clipFunc: function (ctx) {
|
|
17539
|
-
self.drawSourceShape(ctx);
|
|
17540
17540
|
}
|
|
17541
17541
|
});
|
|
17542
17542
|
this._group.on('dragstart', this._onSourceGroupDragStart.bind(this));
|
|
@@ -17555,9 +17555,15 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17555
17555
|
}
|
|
17556
17556
|
});
|
|
17557
17557
|
this._group.on('dragend', this._onSourceGroupDragEnd.bind(this));
|
|
17558
|
-
this.
|
|
17559
|
-
|
|
17560
|
-
|
|
17558
|
+
if (this._borderWidth) {
|
|
17559
|
+
this._border = new Konva.Shape({
|
|
17560
|
+
fill: this._source.borderColor,
|
|
17561
|
+
sceneFunc: function (ctx, shape) {
|
|
17562
|
+
self.drawSourceShape(ctx, shape);
|
|
17563
|
+
}
|
|
17564
|
+
});
|
|
17565
|
+
this._group.add(this._border);
|
|
17566
|
+
}
|
|
17561
17567
|
this._addHandles(true);
|
|
17562
17568
|
this.setWrapping(source.wrapped);
|
|
17563
17569
|
}
|
|
@@ -17612,18 +17618,20 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17612
17618
|
this.updatePreviews();
|
|
17613
17619
|
}
|
|
17614
17620
|
};
|
|
17615
|
-
SourceGroup.prototype.setWrapping = function (wrap) {
|
|
17621
|
+
SourceGroup.prototype.setWrapping = function (wrap, forceCreate, notify) {
|
|
17616
17622
|
if (wrap) {
|
|
17617
|
-
this.
|
|
17623
|
+
this._removeUnwrap();
|
|
17624
|
+
this._addWrap(forceCreate);
|
|
17618
17625
|
this._height = this._wrappedHeight;
|
|
17619
17626
|
} else {
|
|
17620
|
-
this.
|
|
17627
|
+
this._removeWrap();
|
|
17628
|
+
this._addUnwrap(forceCreate);
|
|
17621
17629
|
this._height = this._unwrappedHeight;
|
|
17622
17630
|
}
|
|
17623
|
-
if (this._title) {
|
|
17624
|
-
this._title.y(this._getTitleY());
|
|
17625
|
-
}
|
|
17626
17631
|
this.setHandlesWrapping(wrap);
|
|
17632
|
+
if (notify) {
|
|
17633
|
+
this._peaks.emit('source.wrappingChanged', this);
|
|
17634
|
+
}
|
|
17627
17635
|
};
|
|
17628
17636
|
SourceGroup.prototype.setHandlesWrapping = function (wrap) {
|
|
17629
17637
|
if (wrap) {
|
|
@@ -17691,13 +17699,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17691
17699
|
this._group.add(this._leftHandle);
|
|
17692
17700
|
this._group.add(this._rightHandle);
|
|
17693
17701
|
};
|
|
17694
|
-
SourceGroup.prototype._addUnwrap = function (forceCreate) {
|
|
17695
|
-
if (!this._unwrap || forceCreate) {
|
|
17696
|
-
this._unwrap = this._createUnwrap();
|
|
17697
|
-
this._unwrap.visible(false);
|
|
17698
|
-
}
|
|
17699
|
-
this._group.add(this._unwrap);
|
|
17700
|
-
};
|
|
17701
17702
|
SourceGroup.prototype.toggleDragging = function (bool) {
|
|
17702
17703
|
var background;
|
|
17703
17704
|
if (this._wrap) {
|
|
@@ -17725,27 +17726,35 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17725
17726
|
this._rightHandle.draggable(bool);
|
|
17726
17727
|
}
|
|
17727
17728
|
};
|
|
17728
|
-
SourceGroup.prototype.drawSourceShape = function (ctx, shape) {
|
|
17729
|
+
SourceGroup.prototype.drawSourceShape = function (ctx, shape, addBorderWidth) {
|
|
17730
|
+
var offset = addBorderWidth && this._borderWidth ? this._borderWidth : 0;
|
|
17729
17731
|
var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ? this._source.borderRadius : Math.max(1, Math.min(this._width / 2, Math.min(CORNER_RADIUS, this._height / 2)));
|
|
17730
17732
|
var x = Math.max(0, this._view.getFrameOffset() - this._x - radius);
|
|
17731
17733
|
var width = Math.min(this._width - x, this._view.getOriginalWidth() + radius - Math.max(0, this._x - this._view.getFrameOffset()));
|
|
17732
17734
|
var xWidth = x + width;
|
|
17733
17735
|
ctx.beginPath();
|
|
17734
|
-
ctx.moveTo(x + radius,
|
|
17735
|
-
ctx.lineTo(xWidth - radius,
|
|
17736
|
-
ctx.quadraticCurveTo(xWidth,
|
|
17737
|
-
ctx.lineTo(xWidth, this._height - radius);
|
|
17738
|
-
ctx.quadraticCurveTo(xWidth, this._height, xWidth - radius, this._height);
|
|
17739
|
-
ctx.lineTo(x + radius, this._height);
|
|
17740
|
-
ctx.quadraticCurveTo(x, this._height, x, this._height - radius);
|
|
17741
|
-
ctx.lineTo(x, radius);
|
|
17742
|
-
ctx.quadraticCurveTo(x,
|
|
17736
|
+
ctx.moveTo(x + radius, offset);
|
|
17737
|
+
ctx.lineTo(xWidth - radius, offset);
|
|
17738
|
+
ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
|
|
17739
|
+
ctx.lineTo(xWidth - offset, this._height - radius);
|
|
17740
|
+
ctx.quadraticCurveTo(xWidth - offset, this._height - offset, xWidth - radius, this._height - offset);
|
|
17741
|
+
ctx.lineTo(x + radius, this._height - offset);
|
|
17742
|
+
ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
|
|
17743
|
+
ctx.lineTo(x + offset, radius);
|
|
17744
|
+
ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
|
|
17743
17745
|
ctx.closePath();
|
|
17744
17746
|
if (shape) {
|
|
17745
17747
|
ctx.fillStrokeShape(shape);
|
|
17746
17748
|
}
|
|
17747
17749
|
};
|
|
17750
|
+
SourceGroup.prototype._addUnwrap = function (forceCreate) {
|
|
17751
|
+
if (!this._unwrap || forceCreate) {
|
|
17752
|
+
this._unwrap = this._createUnwrap();
|
|
17753
|
+
}
|
|
17754
|
+
this._group.add(this._unwrap);
|
|
17755
|
+
};
|
|
17748
17756
|
SourceGroup.prototype._createUnwrap = function () {
|
|
17757
|
+
var self = this;
|
|
17749
17758
|
var unwrap = new Konva.Group({
|
|
17750
17759
|
width: this._width,
|
|
17751
17760
|
height: this._unwrappedHeight,
|
|
@@ -17755,15 +17764,15 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17755
17764
|
x: this.absolutePosition().x,
|
|
17756
17765
|
y: this.absolutePosition().y
|
|
17757
17766
|
};
|
|
17767
|
+
},
|
|
17768
|
+
clipFunc: function (ctx) {
|
|
17769
|
+
self.drawSourceShape(ctx, null, true);
|
|
17758
17770
|
}
|
|
17759
17771
|
});
|
|
17760
|
-
var self = this;
|
|
17761
17772
|
var background = new Konva.Shape({
|
|
17762
17773
|
fill: this._source.backgroundColor,
|
|
17763
|
-
stroke: this._source.borderColor,
|
|
17764
|
-
strokeWidth: this._source.borderWidth,
|
|
17765
17774
|
sceneFunc: function (ctx, shape) {
|
|
17766
|
-
self.drawSourceShape(ctx, shape);
|
|
17775
|
+
self.drawSourceShape(ctx, shape, true);
|
|
17767
17776
|
},
|
|
17768
17777
|
draggable: this._source.draggable,
|
|
17769
17778
|
dragBoundFunc: function () {
|
|
@@ -17787,17 +17796,24 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17787
17796
|
}
|
|
17788
17797
|
});
|
|
17789
17798
|
}
|
|
17799
|
+
var title = this._createTitle(false);
|
|
17790
17800
|
unwrap.add(background);
|
|
17801
|
+
unwrap.add(title);
|
|
17791
17802
|
return unwrap;
|
|
17792
17803
|
};
|
|
17804
|
+
SourceGroup.prototype._removeUnwrap = function () {
|
|
17805
|
+
if (this._unwrap) {
|
|
17806
|
+
this._unwrap.remove();
|
|
17807
|
+
}
|
|
17808
|
+
};
|
|
17793
17809
|
SourceGroup.prototype._addWrap = function (forceCreate) {
|
|
17794
17810
|
if (!this._wrap || forceCreate) {
|
|
17795
17811
|
this._wrap = this._createWrap();
|
|
17796
|
-
this._wrap.visible(false);
|
|
17797
17812
|
}
|
|
17798
17813
|
this._group.add(this._wrap);
|
|
17799
17814
|
};
|
|
17800
17815
|
SourceGroup.prototype._createWrap = function () {
|
|
17816
|
+
var self = this;
|
|
17801
17817
|
var wrap = new Konva.Group({
|
|
17802
17818
|
width: this._width,
|
|
17803
17819
|
height: this._wrappedHeight,
|
|
@@ -17807,15 +17823,15 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17807
17823
|
x: this.absolutePosition().x,
|
|
17808
17824
|
y: this.absolutePosition().y
|
|
17809
17825
|
};
|
|
17826
|
+
},
|
|
17827
|
+
clipFunc: function (ctx) {
|
|
17828
|
+
self.drawSourceShape(ctx, null, true);
|
|
17810
17829
|
}
|
|
17811
17830
|
});
|
|
17812
|
-
var self = this;
|
|
17813
17831
|
var background = new Konva.Shape({
|
|
17814
17832
|
fill: this._source.backgroundColor,
|
|
17815
|
-
stroke: this._source.borderColor,
|
|
17816
|
-
strokeWidth: this._source.borderWidth,
|
|
17817
17833
|
sceneFunc: function (ctx, shape) {
|
|
17818
|
-
self.drawSourceShape(ctx, shape);
|
|
17834
|
+
self.drawSourceShape(ctx, shape, true);
|
|
17819
17835
|
},
|
|
17820
17836
|
draggable: this._source.draggable,
|
|
17821
17837
|
dragBoundFunc: function () {
|
|
@@ -17839,31 +17855,23 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17839
17855
|
}
|
|
17840
17856
|
});
|
|
17841
17857
|
}
|
|
17858
|
+
var title = this._createTitle(true);
|
|
17842
17859
|
wrap.add(background);
|
|
17860
|
+
wrap.add(title);
|
|
17843
17861
|
return wrap;
|
|
17844
17862
|
};
|
|
17845
|
-
SourceGroup.prototype.
|
|
17846
|
-
if (
|
|
17847
|
-
this.
|
|
17848
|
-
}
|
|
17849
|
-
this._group.add(this._title);
|
|
17850
|
-
};
|
|
17851
|
-
SourceGroup.prototype._getTitleY = function () {
|
|
17852
|
-
if (!this._title) {
|
|
17853
|
-
return 0;
|
|
17854
|
-
}
|
|
17855
|
-
if (this._source.textPosition === 'bottom') {
|
|
17856
|
-
return Math.max(this._height - this._title.getClientRect().height - 5, 5);
|
|
17857
|
-
} else {
|
|
17858
|
-
return 5;
|
|
17863
|
+
SourceGroup.prototype._removeWrap = function () {
|
|
17864
|
+
if (this._wrap) {
|
|
17865
|
+
this._wrap.remove();
|
|
17859
17866
|
}
|
|
17860
17867
|
};
|
|
17861
|
-
SourceGroup.prototype._createTitle = function () {
|
|
17868
|
+
SourceGroup.prototype._createTitle = function (isWrap) {
|
|
17862
17869
|
var self = this;
|
|
17863
17870
|
var defaultWidth;
|
|
17871
|
+
var y = this._source.textPosition === 'bottom' ? Math.max((isWrap ? this._wrappedHeight : this._unwrappedHeight) - this._source.textFontSize - this._peaks.options.sourceTextYOffset, this._peaks.options.sourceTextYOffset) : this._peaks.options.sourceTextYOffset;
|
|
17864
17872
|
var title = new Konva.Text({
|
|
17865
|
-
x:
|
|
17866
|
-
y:
|
|
17873
|
+
x: this._peaks.options.sourceTextXOffset,
|
|
17874
|
+
y: y,
|
|
17867
17875
|
text: Utils.removeLineBreaks(this._source.title),
|
|
17868
17876
|
textAlign: 'left',
|
|
17869
17877
|
verticalAlign: 'middle',
|
|
@@ -18079,28 +18087,40 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18079
18087
|
});
|
|
18080
18088
|
};
|
|
18081
18089
|
SourceGroup.prototype.setSelected = function (isSelected) {
|
|
18082
|
-
|
|
18083
|
-
return node.getClassName() === 'Shape';
|
|
18084
|
-
});
|
|
18085
|
-
if (background) {
|
|
18090
|
+
if (this._border) {
|
|
18086
18091
|
if (isSelected) {
|
|
18087
|
-
|
|
18088
|
-
|
|
18092
|
+
this._border.fill(this._source.selectedColor);
|
|
18093
|
+
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
18089
18094
|
} else {
|
|
18090
|
-
|
|
18091
|
-
|
|
18095
|
+
this._border.fill(this._source.borderColor);
|
|
18096
|
+
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
18092
18097
|
}
|
|
18093
|
-
}
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
18102
|
-
|
|
18103
|
-
|
|
18098
|
+
} else {
|
|
18099
|
+
if (this._unwrap) {
|
|
18100
|
+
var unwrap_background = this._unwrap.getChildren(function (node) {
|
|
18101
|
+
return node.getClassName() === 'Shape';
|
|
18102
|
+
});
|
|
18103
|
+
if (unwrap_background) {
|
|
18104
|
+
if (isSelected) {
|
|
18105
|
+
unwrap_background.stroke(this._source.selectedColor);
|
|
18106
|
+
unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
18107
|
+
} else {
|
|
18108
|
+
unwrap_background.strokeWidth(0);
|
|
18109
|
+
}
|
|
18110
|
+
}
|
|
18111
|
+
}
|
|
18112
|
+
if (this._wrap) {
|
|
18113
|
+
var wrap_background = this._wrap.getChildren(function (node) {
|
|
18114
|
+
return node.getClassName() === 'Shape';
|
|
18115
|
+
});
|
|
18116
|
+
if (wrap_background) {
|
|
18117
|
+
if (isSelected) {
|
|
18118
|
+
wrap_background.stroke(this._source.selectedColor);
|
|
18119
|
+
wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
18120
|
+
} else {
|
|
18121
|
+
wrap_background.strokeWidth(0);
|
|
18122
|
+
}
|
|
18123
|
+
}
|
|
18104
18124
|
}
|
|
18105
18125
|
}
|
|
18106
18126
|
this._view.drawSourcesLayer();
|
|
@@ -18192,34 +18212,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18192
18212
|
SourceGroup.prototype.getCurrentHeight = function () {
|
|
18193
18213
|
return this._height;
|
|
18194
18214
|
};
|
|
18195
|
-
SourceGroup.prototype.wrap = function (notify) {
|
|
18196
|
-
if (!this._wrap.visible()) {
|
|
18197
|
-
if (this._wrap) {
|
|
18198
|
-
this._wrap.visible(true);
|
|
18199
|
-
if (this._unwrap) {
|
|
18200
|
-
this._unwrap.visible(false);
|
|
18201
|
-
}
|
|
18202
|
-
this._source.wrapped = true;
|
|
18203
|
-
if (notify) {
|
|
18204
|
-
this._peaks.emit('source.wrappingChanged', this);
|
|
18205
|
-
}
|
|
18206
|
-
}
|
|
18207
|
-
}
|
|
18208
|
-
};
|
|
18209
|
-
SourceGroup.prototype.unwrap = function (notify) {
|
|
18210
|
-
if (!this._unwrap.visible()) {
|
|
18211
|
-
if (this._unwrap) {
|
|
18212
|
-
this._unwrap.visible(true);
|
|
18213
|
-
if (this._wrap) {
|
|
18214
|
-
this._wrap.visible(false);
|
|
18215
|
-
}
|
|
18216
|
-
this._source.wrapped = false;
|
|
18217
|
-
if (notify) {
|
|
18218
|
-
this._peaks.emit('source.wrappingChanged', this);
|
|
18219
|
-
}
|
|
18220
|
-
}
|
|
18221
|
-
}
|
|
18222
|
-
};
|
|
18223
18215
|
SourceGroup.prototype.setVisible = function (boolean) {
|
|
18224
18216
|
this._group.visible(boolean);
|
|
18225
18217
|
};
|
|
@@ -19007,7 +18999,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
|
|
|
19007
18999
|
SourcesLayer.prototype._onSourcesShow = function (sources) {
|
|
19008
19000
|
var self = this;
|
|
19009
19001
|
sources.forEach(function (source) {
|
|
19010
|
-
self._sourcesGroup[source.id].
|
|
19002
|
+
self._sourcesGroup[source.id].setWrapping(false, true);
|
|
19011
19003
|
});
|
|
19012
19004
|
this._layer.draw();
|
|
19013
19005
|
};
|
|
@@ -19034,14 +19026,14 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
|
|
|
19034
19026
|
SourcesLayer.prototype._onSourcesShow = function (sources) {
|
|
19035
19027
|
var self = this;
|
|
19036
19028
|
sources.forEach(function (source) {
|
|
19037
|
-
self._sourcesGroup[source.id].
|
|
19029
|
+
self._sourcesGroup[source.id].setWrapping(false, true);
|
|
19038
19030
|
});
|
|
19039
19031
|
this._layer.draw();
|
|
19040
19032
|
};
|
|
19041
19033
|
SourcesLayer.prototype._onSourcesHide = function (sources) {
|
|
19042
19034
|
var self = this;
|
|
19043
19035
|
sources.forEach(function (source) {
|
|
19044
|
-
self._sourcesGroup[source.id].
|
|
19036
|
+
self._sourcesGroup[source.id].setWrapping(true, true);
|
|
19045
19037
|
});
|
|
19046
19038
|
this._layer.draw();
|
|
19047
19039
|
};
|
|
@@ -19255,7 +19247,6 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
|
|
|
19255
19247
|
this._peaks.off('sources.destroy', this._onSourcesDestroy);
|
|
19256
19248
|
this._peaks.off('sources.show', this._onSourcesShow);
|
|
19257
19249
|
this._peaks.off('sources.hide', this._onSourcesHide);
|
|
19258
|
-
this._peaks.off('source.wrappingChanged', this._onSourceWrappingChanged);
|
|
19259
19250
|
this._peaks.off('data.retrieved', this._onDataRetrieved);
|
|
19260
19251
|
this._peaks.off('sources.refresh', this._onSourcesRefresh);
|
|
19261
19252
|
this._peaks.off('segments.show', this._onSegmentsShow);
|
package/src/main.js
CHANGED
|
@@ -242,7 +242,7 @@ define([
|
|
|
242
242
|
* This height will correspond to the height of the group
|
|
243
243
|
* containing the line and title of the wrapped source.
|
|
244
244
|
*/
|
|
245
|
-
wrappedLineHeight:
|
|
245
|
+
wrappedLineHeight: 30,
|
|
246
246
|
|
|
247
247
|
/**
|
|
248
248
|
* Height of an empty line, in pixels.
|
|
@@ -335,6 +335,21 @@ define([
|
|
|
335
335
|
*/
|
|
336
336
|
lineIndicatorSelectedIconColor: '#ccc',
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Border width of a source when selected
|
|
340
|
+
*/
|
|
341
|
+
sourceSelectedBorderWidth: 3,
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* X Offset of the text in the source, in pixels
|
|
345
|
+
*/
|
|
346
|
+
sourceTextXOffset: 10,
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Y Offset of the text in the source, in pixels
|
|
350
|
+
*/
|
|
351
|
+
sourceTextYOffset: 10,
|
|
352
|
+
|
|
338
353
|
/**
|
|
339
354
|
* Threshold size on the left and right border of the view,
|
|
340
355
|
* where auto scrolling is activated, between 0 and 1.
|
|
@@ -651,7 +666,7 @@ define([
|
|
|
651
666
|
* @param {String} segmentId
|
|
652
667
|
*/
|
|
653
668
|
|
|
654
|
-
|
|
669
|
+
Peaks.prototype.destroySegment = function(segmentId) {
|
|
655
670
|
this.segments.removeById(segmentId);
|
|
656
671
|
};
|
|
657
672
|
|
package/src/source-group.js
CHANGED
|
@@ -22,7 +22,6 @@ define([
|
|
|
22
22
|
var SPACING_BETWEEN_PREVIEWS = 1.5;
|
|
23
23
|
var HANDLE_WIDTH = 8;
|
|
24
24
|
var CORNER_RADIUS = 8;
|
|
25
|
-
var SELECTED_BORDER_WIDTH = 6;
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Creates a source group for the given source.
|
|
@@ -50,6 +49,7 @@ define([
|
|
|
50
49
|
source.binaryHeight + source.previewHeight :
|
|
51
50
|
this._peaks.options.lineHeight;
|
|
52
51
|
this._wrappedHeight = this._peaks.options.wrappedLineHeight;
|
|
52
|
+
this._borderWidth = this._source.borderWidth;
|
|
53
53
|
|
|
54
54
|
this._previewList = [];
|
|
55
55
|
|
|
@@ -61,9 +61,6 @@ define([
|
|
|
61
61
|
x: this.absolutePosition().x,
|
|
62
62
|
y: this.absolutePosition().y
|
|
63
63
|
};
|
|
64
|
-
},
|
|
65
|
-
clipFunc: function(ctx) {
|
|
66
|
-
self.drawSourceShape(ctx);
|
|
67
64
|
}
|
|
68
65
|
});
|
|
69
66
|
|
|
@@ -84,9 +81,15 @@ define([
|
|
|
84
81
|
});
|
|
85
82
|
this._group.on('dragend', this._onSourceGroupDragEnd.bind(this));
|
|
86
83
|
|
|
87
|
-
this.
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
if (this._borderWidth) {
|
|
85
|
+
this._border = new Konva.Shape({
|
|
86
|
+
fill: this._source.borderColor,
|
|
87
|
+
sceneFunc: function(ctx, shape) {
|
|
88
|
+
self.drawSourceShape(ctx, shape);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
this._group.add(this._border);
|
|
92
|
+
}
|
|
90
93
|
this._addHandles(true);
|
|
91
94
|
|
|
92
95
|
this.setWrapping(source.wrapped);
|
|
@@ -207,21 +210,23 @@ define([
|
|
|
207
210
|
}
|
|
208
211
|
};
|
|
209
212
|
|
|
210
|
-
SourceGroup.prototype.setWrapping = function(wrap) {
|
|
213
|
+
SourceGroup.prototype.setWrapping = function(wrap, forceCreate, notify) {
|
|
211
214
|
if (wrap) {
|
|
212
|
-
this.
|
|
215
|
+
this._removeUnwrap();
|
|
216
|
+
this._addWrap(forceCreate);
|
|
213
217
|
this._height = this._wrappedHeight;
|
|
214
218
|
}
|
|
215
219
|
else {
|
|
216
|
-
this.
|
|
220
|
+
this._removeWrap();
|
|
221
|
+
this._addUnwrap(forceCreate);
|
|
217
222
|
this._height = this._unwrappedHeight;
|
|
218
223
|
}
|
|
219
224
|
|
|
220
|
-
if (this._title) {
|
|
221
|
-
this._title.y(this._getTitleY());
|
|
222
|
-
}
|
|
223
|
-
|
|
224
225
|
this.setHandlesWrapping(wrap);
|
|
226
|
+
|
|
227
|
+
if (notify) {
|
|
228
|
+
this._peaks.emit('source.wrappingChanged', this);
|
|
229
|
+
}
|
|
225
230
|
};
|
|
226
231
|
|
|
227
232
|
SourceGroup.prototype.setHandlesWrapping = function(wrap) {
|
|
@@ -302,15 +307,6 @@ define([
|
|
|
302
307
|
this._group.add(this._rightHandle);
|
|
303
308
|
};
|
|
304
309
|
|
|
305
|
-
SourceGroup.prototype._addUnwrap = function(forceCreate) {
|
|
306
|
-
if (!this._unwrap || forceCreate) {
|
|
307
|
-
this._unwrap = this._createUnwrap();
|
|
308
|
-
this._unwrap.visible(false);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
this._group.add(this._unwrap);
|
|
312
|
-
};
|
|
313
|
-
|
|
314
310
|
SourceGroup.prototype.toggleDragging = function(bool) {
|
|
315
311
|
var background;
|
|
316
312
|
|
|
@@ -343,19 +339,20 @@ define([
|
|
|
343
339
|
}
|
|
344
340
|
};
|
|
345
341
|
|
|
346
|
-
SourceGroup.prototype.drawSourceShape = function(ctx, shape) {
|
|
342
|
+
SourceGroup.prototype.drawSourceShape = function(ctx, shape, addBorderWidth) {
|
|
343
|
+
var offset = addBorderWidth && this._borderWidth ? this._borderWidth : 0;
|
|
347
344
|
var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ?
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
345
|
+
this._source.borderRadius :
|
|
346
|
+
Math.max(
|
|
347
|
+
1,
|
|
348
|
+
Math.min(
|
|
349
|
+
this._width / 2,
|
|
351
350
|
Math.min(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
CORNER_RADIUS,
|
|
355
|
-
this._height / 2
|
|
356
|
-
)
|
|
351
|
+
CORNER_RADIUS,
|
|
352
|
+
this._height / 2
|
|
357
353
|
)
|
|
358
|
-
)
|
|
354
|
+
)
|
|
355
|
+
);
|
|
359
356
|
var x = Math.max(
|
|
360
357
|
0,
|
|
361
358
|
this._view.getFrameOffset() - this._x - radius
|
|
@@ -370,15 +367,20 @@ define([
|
|
|
370
367
|
var xWidth = x + width;
|
|
371
368
|
|
|
372
369
|
ctx.beginPath();
|
|
373
|
-
ctx.moveTo(x + radius,
|
|
374
|
-
ctx.lineTo(xWidth - radius,
|
|
375
|
-
ctx.quadraticCurveTo(xWidth,
|
|
376
|
-
ctx.lineTo(xWidth, this._height - radius);
|
|
377
|
-
ctx.quadraticCurveTo(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
370
|
+
ctx.moveTo(x + radius, offset);
|
|
371
|
+
ctx.lineTo(xWidth - radius, offset);
|
|
372
|
+
ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
|
|
373
|
+
ctx.lineTo(xWidth - offset, this._height - radius);
|
|
374
|
+
ctx.quadraticCurveTo(
|
|
375
|
+
xWidth - offset,
|
|
376
|
+
this._height - offset,
|
|
377
|
+
xWidth - radius,
|
|
378
|
+
this._height - offset
|
|
379
|
+
);
|
|
380
|
+
ctx.lineTo(x + radius, this._height - offset);
|
|
381
|
+
ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
|
|
382
|
+
ctx.lineTo(x + offset, radius);
|
|
383
|
+
ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
|
|
382
384
|
ctx.closePath();
|
|
383
385
|
|
|
384
386
|
if (shape) {
|
|
@@ -386,7 +388,17 @@ define([
|
|
|
386
388
|
}
|
|
387
389
|
};
|
|
388
390
|
|
|
391
|
+
SourceGroup.prototype._addUnwrap = function(forceCreate) {
|
|
392
|
+
if (!this._unwrap || forceCreate) {
|
|
393
|
+
this._unwrap = this._createUnwrap();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
this._group.add(this._unwrap);
|
|
397
|
+
};
|
|
398
|
+
|
|
389
399
|
SourceGroup.prototype._createUnwrap = function() {
|
|
400
|
+
var self = this;
|
|
401
|
+
|
|
390
402
|
var unwrap = new Konva.Group({
|
|
391
403
|
width: this._width,
|
|
392
404
|
height: this._unwrappedHeight,
|
|
@@ -396,17 +408,16 @@ define([
|
|
|
396
408
|
x: this.absolutePosition().x,
|
|
397
409
|
y: this.absolutePosition().y
|
|
398
410
|
};
|
|
411
|
+
},
|
|
412
|
+
clipFunc: function(ctx) {
|
|
413
|
+
self.drawSourceShape(ctx, null, true);
|
|
399
414
|
}
|
|
400
415
|
});
|
|
401
416
|
|
|
402
|
-
var self = this;
|
|
403
|
-
|
|
404
417
|
var background = new Konva.Shape({
|
|
405
418
|
fill: this._source.backgroundColor,
|
|
406
|
-
stroke: this._source.borderColor,
|
|
407
|
-
strokeWidth: this._source.borderWidth,
|
|
408
419
|
sceneFunc: function(ctx, shape) {
|
|
409
|
-
self.drawSourceShape(ctx, shape);
|
|
420
|
+
self.drawSourceShape(ctx, shape, true);
|
|
410
421
|
},
|
|
411
422
|
draggable: this._source.draggable,
|
|
412
423
|
dragBoundFunc: function() {
|
|
@@ -434,21 +445,31 @@ define([
|
|
|
434
445
|
});
|
|
435
446
|
}
|
|
436
447
|
|
|
448
|
+
var title = this._createTitle(false);
|
|
449
|
+
|
|
437
450
|
unwrap.add(background);
|
|
451
|
+
unwrap.add(title);
|
|
438
452
|
|
|
439
453
|
return unwrap;
|
|
440
454
|
};
|
|
441
455
|
|
|
456
|
+
SourceGroup.prototype._removeUnwrap = function() {
|
|
457
|
+
if (this._unwrap) {
|
|
458
|
+
this._unwrap.remove();
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
442
462
|
SourceGroup.prototype._addWrap = function(forceCreate) {
|
|
443
463
|
if (!this._wrap || forceCreate) {
|
|
444
464
|
this._wrap = this._createWrap();
|
|
445
|
-
this._wrap.visible(false);
|
|
446
465
|
}
|
|
447
466
|
|
|
448
467
|
this._group.add(this._wrap);
|
|
449
468
|
};
|
|
450
469
|
|
|
451
470
|
SourceGroup.prototype._createWrap = function() {
|
|
471
|
+
var self = this;
|
|
472
|
+
|
|
452
473
|
var wrap = new Konva.Group({
|
|
453
474
|
width: this._width,
|
|
454
475
|
height: this._wrappedHeight,
|
|
@@ -458,17 +479,16 @@ define([
|
|
|
458
479
|
x: this.absolutePosition().x,
|
|
459
480
|
y: this.absolutePosition().y
|
|
460
481
|
};
|
|
482
|
+
},
|
|
483
|
+
clipFunc: function(ctx) {
|
|
484
|
+
self.drawSourceShape(ctx, null, true);
|
|
461
485
|
}
|
|
462
486
|
});
|
|
463
487
|
|
|
464
|
-
var self = this;
|
|
465
|
-
|
|
466
488
|
var background = new Konva.Shape({
|
|
467
489
|
fill: this._source.backgroundColor,
|
|
468
|
-
stroke: this._source.borderColor,
|
|
469
|
-
strokeWidth: this._source.borderWidth,
|
|
470
490
|
sceneFunc: function(ctx, shape) {
|
|
471
|
-
self.drawSourceShape(ctx, shape);
|
|
491
|
+
self.drawSourceShape(ctx, shape, true);
|
|
472
492
|
},
|
|
473
493
|
draggable: this._source.draggable,
|
|
474
494
|
dragBoundFunc: function() {
|
|
@@ -496,39 +516,33 @@ define([
|
|
|
496
516
|
});
|
|
497
517
|
}
|
|
498
518
|
|
|
519
|
+
var title = this._createTitle(true);
|
|
520
|
+
|
|
499
521
|
wrap.add(background);
|
|
522
|
+
wrap.add(title);
|
|
500
523
|
|
|
501
524
|
return wrap;
|
|
502
525
|
};
|
|
503
526
|
|
|
504
|
-
SourceGroup.prototype.
|
|
505
|
-
if (
|
|
506
|
-
this.
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
this._group.add(this._title);
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
SourceGroup.prototype._getTitleY = function() {
|
|
513
|
-
if (!this._title) {
|
|
514
|
-
return 0;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (this._source.textPosition === 'bottom') {
|
|
518
|
-
return Math.max(this._height - this._title.getClientRect().height - 5, 5);
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
return 5;
|
|
527
|
+
SourceGroup.prototype._removeWrap = function() {
|
|
528
|
+
if (this._wrap) {
|
|
529
|
+
this._wrap.remove();
|
|
522
530
|
}
|
|
523
531
|
};
|
|
524
532
|
|
|
525
|
-
SourceGroup.prototype._createTitle = function() {
|
|
533
|
+
SourceGroup.prototype._createTitle = function(isWrap) {
|
|
526
534
|
var self = this;
|
|
527
535
|
var defaultWidth;
|
|
536
|
+
var y = (this._source.textPosition === 'bottom') ?
|
|
537
|
+
Math.max(
|
|
538
|
+
(isWrap ? this._wrappedHeight : this._unwrappedHeight)
|
|
539
|
+
- this._source.textFontSize - this._peaks.options.sourceTextYOffset,
|
|
540
|
+
this._peaks.options.sourceTextYOffset
|
|
541
|
+
) : this._peaks.options.sourceTextYOffset;
|
|
528
542
|
|
|
529
543
|
var title = new Konva.Text({
|
|
530
|
-
x:
|
|
531
|
-
y:
|
|
544
|
+
x: this._peaks.options.sourceTextXOffset,
|
|
545
|
+
y: y,
|
|
532
546
|
text: Utils.removeLineBreaks(this._source.title),
|
|
533
547
|
textAlign: 'left',
|
|
534
548
|
verticalAlign: 'middle',
|
|
@@ -807,35 +821,49 @@ define([
|
|
|
807
821
|
};
|
|
808
822
|
|
|
809
823
|
SourceGroup.prototype.setSelected = function(isSelected) {
|
|
810
|
-
|
|
811
|
-
var background = this._unwrap.getChildren(function(node) {
|
|
812
|
-
return node.getClassName() === 'Shape';
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
if (background) {
|
|
824
|
+
if (this._border) {
|
|
816
825
|
if (isSelected) {
|
|
817
|
-
|
|
818
|
-
|
|
826
|
+
this._border.fill(this._source.selectedColor);
|
|
827
|
+
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
819
828
|
}
|
|
820
829
|
else {
|
|
821
|
-
|
|
822
|
-
|
|
830
|
+
this._border.fill(this._source.borderColor);
|
|
831
|
+
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
823
832
|
}
|
|
824
833
|
}
|
|
834
|
+
else {
|
|
835
|
+
if (this._unwrap) {
|
|
836
|
+
// update unwrap
|
|
837
|
+
var unwrap_background = this._unwrap.getChildren(function(node) {
|
|
838
|
+
return node.getClassName() === 'Shape';
|
|
839
|
+
});
|
|
825
840
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
841
|
+
if (unwrap_background) {
|
|
842
|
+
if (isSelected) {
|
|
843
|
+
unwrap_background.stroke(this._source.selectedColor);
|
|
844
|
+
unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
unwrap_background.strokeWidth(0);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
835
850
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
851
|
+
|
|
852
|
+
if (this._wrap) {
|
|
853
|
+
// update wrap
|
|
854
|
+
var wrap_background = this._wrap.getChildren(function(node) {
|
|
855
|
+
return node.getClassName() === 'Shape';
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
if (wrap_background) {
|
|
859
|
+
if (isSelected) {
|
|
860
|
+
wrap_background.stroke(this._source.selectedColor);
|
|
861
|
+
wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
wrap_background.strokeWidth(0);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
839
867
|
}
|
|
840
868
|
}
|
|
841
869
|
|
|
@@ -961,40 +989,6 @@ define([
|
|
|
961
989
|
return this._height;
|
|
962
990
|
};
|
|
963
991
|
|
|
964
|
-
SourceGroup.prototype.wrap = function(notify) {
|
|
965
|
-
if (!this._wrap.visible()) {
|
|
966
|
-
if (this._wrap) {
|
|
967
|
-
this._wrap.visible(true);
|
|
968
|
-
if (this._unwrap) {
|
|
969
|
-
this._unwrap.visible(false);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
this._source.wrapped = true;
|
|
973
|
-
|
|
974
|
-
if (notify) {
|
|
975
|
-
this._peaks.emit('source.wrappingChanged', this);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
};
|
|
980
|
-
|
|
981
|
-
SourceGroup.prototype.unwrap = function(notify) {
|
|
982
|
-
if (!this._unwrap.visible()) {
|
|
983
|
-
if (this._unwrap) {
|
|
984
|
-
this._unwrap.visible(true);
|
|
985
|
-
if (this._wrap) {
|
|
986
|
-
this._wrap.visible(false);
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
this._source.wrapped = false;
|
|
990
|
-
|
|
991
|
-
if (notify) {
|
|
992
|
-
this._peaks.emit('source.wrappingChanged', this);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
};
|
|
997
|
-
|
|
998
992
|
SourceGroup.prototype.setVisible = function(boolean) {
|
|
999
993
|
this._group.visible(boolean);
|
|
1000
994
|
};
|
package/src/sources-layer.js
CHANGED
|
@@ -155,7 +155,7 @@ define([
|
|
|
155
155
|
var self = this;
|
|
156
156
|
|
|
157
157
|
sources.forEach(function(source) {
|
|
158
|
-
self._sourcesGroup[source.id].
|
|
158
|
+
self._sourcesGroup[source.id].setWrapping(false, true);
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
this._layer.draw();
|
|
@@ -195,7 +195,7 @@ define([
|
|
|
195
195
|
var self = this;
|
|
196
196
|
|
|
197
197
|
sources.forEach(function(source) {
|
|
198
|
-
self._sourcesGroup[source.id].
|
|
198
|
+
self._sourcesGroup[source.id].setWrapping(false, true);
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
this._layer.draw();
|
|
@@ -205,7 +205,7 @@ define([
|
|
|
205
205
|
var self = this;
|
|
206
206
|
|
|
207
207
|
sources.forEach(function(source) {
|
|
208
|
-
self._sourcesGroup[source.id].
|
|
208
|
+
self._sourcesGroup[source.id].setWrapping(true, true);
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
this._layer.draw();
|
|
@@ -565,7 +565,6 @@ define([
|
|
|
565
565
|
this._peaks.off('sources.destroy', this._onSourcesDestroy);
|
|
566
566
|
this._peaks.off('sources.show', this._onSourcesShow);
|
|
567
567
|
this._peaks.off('sources.hide', this._onSourcesHide);
|
|
568
|
-
this._peaks.off('source.wrappingChanged', this._onSourceWrappingChanged);
|
|
569
568
|
this._peaks.off('data.retrieved', this._onDataRetrieved);
|
|
570
569
|
this._peaks.off('sources.refresh', this._onSourcesRefresh);
|
|
571
570
|
this._peaks.off('segments.show', this._onSegmentsShow);
|