@checksub_team/peaks_timeline 2.5.0-alpha.0 → 2.5.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/peaks.js +157 -34
- package/peaks.js.d.ts +8 -0
- package/src/components/default-segment-marker.js +4 -0
- package/src/components/segment-marker.js +6 -0
- package/src/components/segment-shape.js +81 -30
- package/src/components/segments-group.js +9 -0
- package/src/components/sources-layer.js +19 -2
- package/src/models/segment.js +81 -8
- package/src/segment-handler.js +4 -0
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -14753,6 +14753,9 @@ module.exports = function (Utils, Konva) {
|
|
|
14753
14753
|
DefaultSegmentMarker.prototype.timeUpdated = function (time) {
|
|
14754
14754
|
this._label.setText(Utils.formatTime(time, false));
|
|
14755
14755
|
};
|
|
14756
|
+
DefaultSegmentMarker.prototype.setTextColor = function (color) {
|
|
14757
|
+
this._label.fill(color);
|
|
14758
|
+
};
|
|
14756
14759
|
DefaultSegmentMarker.prototype._batchDraw = function () {
|
|
14757
14760
|
const group = this._options.group;
|
|
14758
14761
|
const layer = group && group.getLayer && group.getLayer();
|
|
@@ -17227,6 +17230,11 @@ module.exports = function (Konva) {
|
|
|
17227
17230
|
this._marker.timeUpdated(time);
|
|
17228
17231
|
}
|
|
17229
17232
|
};
|
|
17233
|
+
SegmentMarker.prototype.setTextColor = function (color) {
|
|
17234
|
+
if (this._marker.setTextColor) {
|
|
17235
|
+
this._marker.setTextColor(color);
|
|
17236
|
+
}
|
|
17237
|
+
};
|
|
17230
17238
|
SegmentMarker.prototype.destroy = function () {
|
|
17231
17239
|
this._group.destroyChildren();
|
|
17232
17240
|
this._group.destroy();
|
|
@@ -17253,6 +17261,8 @@ module.exports = function (Konva, SegmentMarker, Utils) {
|
|
|
17253
17261
|
this._shapeGroup = null;
|
|
17254
17262
|
this._rectangle = null;
|
|
17255
17263
|
this._indicators = {};
|
|
17264
|
+
this._selected = this._segment.selected;
|
|
17265
|
+
this._hovered = false;
|
|
17256
17266
|
var self = this;
|
|
17257
17267
|
this._segmentWidth = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
|
|
17258
17268
|
this._segmentHeight = this._peaks.options.segmentHeight;
|
|
@@ -17297,20 +17307,12 @@ module.exports = function (Konva, SegmentMarker, Utils) {
|
|
|
17297
17307
|
this._onSegmentHandleDrag = this._onSegmentHandleDrag.bind(this);
|
|
17298
17308
|
this._onSegmentHandleDragStart = this._onSegmentHandleDragStart.bind(this);
|
|
17299
17309
|
this._onSegmentHandleDragEnd = this._onSegmentHandleDragEnd.bind(this);
|
|
17300
|
-
this.
|
|
17301
|
-
x: this._view.timeToPixels(segment.startTime),
|
|
17302
|
-
y: this._segmentY,
|
|
17303
|
-
width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
|
|
17304
|
-
height: this._segmentHeight,
|
|
17305
|
-
segment: segment,
|
|
17306
|
-
view: this._view.getName(),
|
|
17307
|
-
group: this._group,
|
|
17308
|
-
fontSize: 12
|
|
17309
|
-
});
|
|
17310
|
+
this._createLabel();
|
|
17310
17311
|
this._createMarkers();
|
|
17311
17312
|
this._indicatorsGroup = new Konva.Group();
|
|
17312
17313
|
this._shapeGroup.add(this._indicatorsGroup);
|
|
17313
17314
|
this.createIndicators();
|
|
17315
|
+
this._applyVisualState();
|
|
17314
17316
|
}
|
|
17315
17317
|
SegmentShape.prototype._onShapeGroupDrag = function (draggedElement) {
|
|
17316
17318
|
return this._view._sourcesLayer.onSegmentDrag(draggedElement);
|
|
@@ -17318,9 +17320,67 @@ module.exports = function (Konva, SegmentMarker, Utils) {
|
|
|
17318
17320
|
SegmentShape.prototype._cornerRadius = function () {
|
|
17319
17321
|
return !Utils.isNullOrUndefined(this._segment.borderRadius) ? this._segment.borderRadius : SEGMENT_CORNER_RADIUS;
|
|
17320
17322
|
};
|
|
17323
|
+
SegmentShape.prototype._createLabel = function () {
|
|
17324
|
+
this._label = this._peaks.options.createSegmentLabel({
|
|
17325
|
+
x: this._view.timeToPixels(this._segment.startTime),
|
|
17326
|
+
y: this._segmentY,
|
|
17327
|
+
width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
|
|
17328
|
+
height: this._segmentHeight,
|
|
17329
|
+
segment: this._segment,
|
|
17330
|
+
view: this._view.getName(),
|
|
17331
|
+
group: this._group,
|
|
17332
|
+
fontSize: 12
|
|
17333
|
+
});
|
|
17334
|
+
};
|
|
17335
|
+
SegmentShape.prototype._getFillColor = function () {
|
|
17336
|
+
var color = this._segment.color;
|
|
17337
|
+
if (this._selected) {
|
|
17338
|
+
color = this._segment.selectedColor;
|
|
17339
|
+
} else if (this._hovered) {
|
|
17340
|
+
color = this._segment.hoverColor;
|
|
17341
|
+
}
|
|
17342
|
+
return color + Math.round(this._segment.opacity * 255).toString(16);
|
|
17343
|
+
};
|
|
17344
|
+
SegmentShape.prototype._getStrokeColor = function () {
|
|
17345
|
+
if (this._selected) {
|
|
17346
|
+
return this._segment.selectedBorderColor;
|
|
17347
|
+
}
|
|
17348
|
+
return this._segment.borderColor || this._segment.textColor + 'FF';
|
|
17349
|
+
};
|
|
17350
|
+
SegmentShape.prototype._getLabelTextColor = function () {
|
|
17351
|
+
return this._selected ? this._segment.selectedTextColor : this._segment.textColor;
|
|
17352
|
+
};
|
|
17353
|
+
SegmentShape.prototype._getHandleTextColor = function () {
|
|
17354
|
+
return this._selected ? this._segment.selectedHandleTextColor : this._segment.handleTextColor;
|
|
17355
|
+
};
|
|
17356
|
+
SegmentShape.prototype._applyVisualState = function () {
|
|
17357
|
+
var fillColor = this._getFillColor();
|
|
17358
|
+
var handleTextColor = this._getHandleTextColor();
|
|
17359
|
+
this._rectangle.fill(fillColor);
|
|
17360
|
+
this._rectangle.stroke(this._getStrokeColor());
|
|
17361
|
+
this._rectangle.fillLinearGradientColorStops([
|
|
17362
|
+
0,
|
|
17363
|
+
fillColor,
|
|
17364
|
+
0.65,
|
|
17365
|
+
this._segment.warningColor
|
|
17366
|
+
]);
|
|
17367
|
+
if (this._label && this._label.fill) {
|
|
17368
|
+
this._label.fill(this._getLabelTextColor());
|
|
17369
|
+
}
|
|
17370
|
+
if (this._startMarker) {
|
|
17371
|
+
this._startMarker.setTextColor(handleTextColor);
|
|
17372
|
+
}
|
|
17373
|
+
if (this._endMarker) {
|
|
17374
|
+
this._endMarker.setTextColor(handleTextColor);
|
|
17375
|
+
}
|
|
17376
|
+
};
|
|
17321
17377
|
SegmentShape.prototype.update = function () {
|
|
17322
17378
|
this._applyDisplayTimes(this._segment.startTime, this._segment.endTime);
|
|
17323
17379
|
};
|
|
17380
|
+
SegmentShape.prototype.setSelected = function () {
|
|
17381
|
+
this._selected = this._segment.selected;
|
|
17382
|
+
this._applyVisualState();
|
|
17383
|
+
};
|
|
17324
17384
|
SegmentShape.prototype._applyDisplayTimes = function (startTime, endTime) {
|
|
17325
17385
|
var startPixel = this._view.timeToPixels(startTime);
|
|
17326
17386
|
var endPixel = this._view.timeToPixels(endTime);
|
|
@@ -17498,28 +17558,16 @@ module.exports = function (Konva, SegmentMarker, Utils) {
|
|
|
17498
17558
|
SegmentShape.prototype._onMouseEnter = function () {
|
|
17499
17559
|
this._view.setCursor('pointer');
|
|
17500
17560
|
this._view.setHoveredElement(this);
|
|
17501
|
-
|
|
17502
|
-
this.
|
|
17503
|
-
this._rectangle.fillLinearGradientColorStops([
|
|
17504
|
-
0,
|
|
17505
|
-
fillColor,
|
|
17506
|
-
0.65,
|
|
17507
|
-
this._segment.warningColor
|
|
17508
|
-
]);
|
|
17561
|
+
this._hovered = true;
|
|
17562
|
+
this._applyVisualState();
|
|
17509
17563
|
this._view.batchDrawSourcesLayer();
|
|
17510
17564
|
this._peaks.emit('segments.mouseenter', this._segment);
|
|
17511
17565
|
};
|
|
17512
17566
|
SegmentShape.prototype._onMouseLeave = function () {
|
|
17513
17567
|
this._view.setCursor('default');
|
|
17514
17568
|
this._view.setHoveredElement(null);
|
|
17515
|
-
|
|
17516
|
-
this.
|
|
17517
|
-
this._rectangle.fillLinearGradientColorStops([
|
|
17518
|
-
0,
|
|
17519
|
-
fillColor,
|
|
17520
|
-
0.65,
|
|
17521
|
-
this._segment.warningColor
|
|
17522
|
-
]);
|
|
17569
|
+
this._hovered = false;
|
|
17570
|
+
this._applyVisualState();
|
|
17523
17571
|
this._view.batchDrawSourcesLayer();
|
|
17524
17572
|
this._peaks.emit('segments.mouseleave', this._segment);
|
|
17525
17573
|
};
|
|
@@ -17923,6 +17971,13 @@ module.exports = function (SegmentShape, Utils, Konva) {
|
|
|
17923
17971
|
this._draw();
|
|
17924
17972
|
}
|
|
17925
17973
|
};
|
|
17974
|
+
SegmentsGroup.prototype.setSelected = function (segment) {
|
|
17975
|
+
var segmentShape = this._segmentShapes[segment.id];
|
|
17976
|
+
if (segmentShape) {
|
|
17977
|
+
segmentShape.setSelected();
|
|
17978
|
+
this._draw();
|
|
17979
|
+
}
|
|
17980
|
+
};
|
|
17926
17981
|
SegmentsGroup.prototype.addToUpdatedSegments = function (segment) {
|
|
17927
17982
|
if (this._updatedSegments.indexOf(segment) === -1) {
|
|
17928
17983
|
this._updatedSegments.push(segment);
|
|
@@ -19946,6 +20001,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19946
20001
|
this._peaks.on('handler.sources.show', this._onSourcesShow.bind(this));
|
|
19947
20002
|
this._peaks.on('handler.sources.hide', this._onSourcesHide.bind(this));
|
|
19948
20003
|
this._peaks.on('sources.setSelected', this._onSourcesSetSelected.bind(this));
|
|
20004
|
+
this._peaks.on('segments.setSelected', this._onSegmentsSetSelected.bind(this));
|
|
19949
20005
|
this._peaks.on('model.source.update', this._onSourceUpdate.bind(this));
|
|
19950
20006
|
this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
|
|
19951
20007
|
this._peaks.on('handler.segments.show', this._onSegmentsShow.bind(this));
|
|
@@ -20066,12 +20122,23 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
20066
20122
|
}
|
|
20067
20123
|
};
|
|
20068
20124
|
SourcesLayer.prototype._onSourcesSetSelected = function (sources) {
|
|
20125
|
+
var sourcesGroups = this._lineGroups.getSourcesGroups();
|
|
20069
20126
|
sources.forEach(function (source) {
|
|
20070
|
-
const sourceGroup =
|
|
20127
|
+
const sourceGroup = sourcesGroups[source.id];
|
|
20071
20128
|
if (sourceGroup) {
|
|
20072
20129
|
sourceGroup.setSelected();
|
|
20073
20130
|
}
|
|
20074
|
-
}
|
|
20131
|
+
});
|
|
20132
|
+
this.batchDraw();
|
|
20133
|
+
};
|
|
20134
|
+
SourcesLayer.prototype._onSegmentsSetSelected = function (segments) {
|
|
20135
|
+
var segmentsGroups = this._lineGroups.getSegmentsGroups();
|
|
20136
|
+
segments.forEach(function (segment) {
|
|
20137
|
+
var segmentsGroup = segmentsGroups[segment.line];
|
|
20138
|
+
if (segmentsGroup) {
|
|
20139
|
+
segmentsGroup.setSelected(segment);
|
|
20140
|
+
}
|
|
20141
|
+
});
|
|
20075
20142
|
this.batchDraw();
|
|
20076
20143
|
};
|
|
20077
20144
|
SourcesLayer.prototype._onSourcesAdd = function (sources) {
|
|
@@ -21850,6 +21917,26 @@ module.exports = function (Utils) {
|
|
|
21850
21917
|
} else if (!Utils.isValidColor(options.hoverColor)) {
|
|
21851
21918
|
throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
|
|
21852
21919
|
}
|
|
21920
|
+
if (Utils.isNullOrUndefined(options.selectedColor)) {
|
|
21921
|
+
options.selectedColor = options.color;
|
|
21922
|
+
} else if (!Utils.isValidColor(options.selectedColor)) {
|
|
21923
|
+
throw new TypeError('peaks.segments.' + context + ': selectedColor must be a valid CSS color');
|
|
21924
|
+
}
|
|
21925
|
+
if (Utils.isNullOrUndefined(options.selectedTextColor)) {
|
|
21926
|
+
options.selectedTextColor = options.textColor;
|
|
21927
|
+
} else if (!Utils.isValidColor(options.selectedTextColor)) {
|
|
21928
|
+
throw new TypeError('peaks.segments.' + context + ': selectedTextColor must be a valid CSS color');
|
|
21929
|
+
}
|
|
21930
|
+
if (Utils.isNullOrUndefined(options.selectedHandleTextColor)) {
|
|
21931
|
+
options.selectedHandleTextColor = options.handleTextColor;
|
|
21932
|
+
} else if (!Utils.isValidColor(options.selectedHandleTextColor)) {
|
|
21933
|
+
throw new TypeError('peaks.segments.' + context + ': selectedHandleTextColor must be a valid CSS color');
|
|
21934
|
+
}
|
|
21935
|
+
if (Utils.isNullOrUndefined(options.selectedBorderColor)) {
|
|
21936
|
+
options.selectedBorderColor = Utils.shadeColor(options.borderColor || options.textColor + 'FF', 30);
|
|
21937
|
+
} else if (!Utils.isValidColor(options.selectedBorderColor)) {
|
|
21938
|
+
throw new TypeError('peaks.segments.' + context + ': selectedBorderColor must be a valid CSS color');
|
|
21939
|
+
}
|
|
21853
21940
|
if (Utils.isNullOrUndefined(options.warningColor)) {
|
|
21854
21941
|
options.warningColor = '#E48023';
|
|
21855
21942
|
} else if (!Utils.isValidColor(options.warningColor)) {
|
|
@@ -21857,7 +21944,7 @@ module.exports = function (Utils) {
|
|
|
21857
21944
|
}
|
|
21858
21945
|
return shouldNotifyUpdate;
|
|
21859
21946
|
}
|
|
21860
|
-
function Segment(peaks, id, startTime, endTime, duration, labelText, color, textColor, handleTextColor, hoverColor, warningColor, opacity, borderColor, borderWidth, borderRadius, editable, allowDeletion, line, indicators) {
|
|
21947
|
+
function Segment(peaks, id, startTime, endTime, duration, labelText, color, textColor, handleTextColor, hoverColor, selectedColor, selectedTextColor, selectedHandleTextColor, warningColor, opacity, borderColor, selectedBorderColor, borderWidth, borderRadius, editable, allowDeletion, line, indicators) {
|
|
21861
21948
|
var opts = {
|
|
21862
21949
|
startTime: startTime,
|
|
21863
21950
|
endTime: endTime,
|
|
@@ -21867,9 +21954,13 @@ module.exports = function (Utils) {
|
|
|
21867
21954
|
textColor: textColor,
|
|
21868
21955
|
handleTextColor: handleTextColor,
|
|
21869
21956
|
hoverColor: hoverColor,
|
|
21957
|
+
selectedColor: selectedColor,
|
|
21958
|
+
selectedTextColor: selectedTextColor,
|
|
21959
|
+
selectedHandleTextColor: selectedHandleTextColor,
|
|
21870
21960
|
warningColor: warningColor,
|
|
21871
21961
|
opacity: opacity,
|
|
21872
21962
|
borderColor: borderColor,
|
|
21963
|
+
selectedBorderColor: selectedBorderColor,
|
|
21873
21964
|
borderWidth: borderWidth,
|
|
21874
21965
|
borderRadius: borderRadius,
|
|
21875
21966
|
editable: editable,
|
|
@@ -21888,9 +21979,13 @@ module.exports = function (Utils) {
|
|
|
21888
21979
|
this._hoverColor = opts.hoverColor;
|
|
21889
21980
|
this._textColor = opts.textColor;
|
|
21890
21981
|
this._handleTextColor = opts.handleTextColor;
|
|
21982
|
+
this._selectedColor = opts.selectedColor;
|
|
21983
|
+
this._selectedTextColor = opts.selectedTextColor;
|
|
21984
|
+
this._selectedHandleTextColor = opts.selectedHandleTextColor;
|
|
21891
21985
|
this._warningColor = opts.warningColor;
|
|
21892
21986
|
this._opacity = opts.opacity;
|
|
21893
21987
|
this._borderColor = opts.borderColor;
|
|
21988
|
+
this._selectedBorderColor = opts.selectedBorderColor;
|
|
21894
21989
|
this._borderWidth = opts.borderWidth;
|
|
21895
21990
|
this._borderRadius = opts.borderRadius;
|
|
21896
21991
|
this._editable = opts.editable;
|
|
@@ -21956,18 +22051,36 @@ module.exports = function (Utils) {
|
|
|
21956
22051
|
return this._hoverColor;
|
|
21957
22052
|
}
|
|
21958
22053
|
},
|
|
22054
|
+
selectedColor: {
|
|
22055
|
+
enumerable: true,
|
|
22056
|
+
get: function () {
|
|
22057
|
+
return this._selectedColor;
|
|
22058
|
+
}
|
|
22059
|
+
},
|
|
21959
22060
|
textColor: {
|
|
21960
22061
|
enumerable: true,
|
|
21961
22062
|
get: function () {
|
|
21962
22063
|
return this._textColor;
|
|
21963
22064
|
}
|
|
21964
22065
|
},
|
|
22066
|
+
selectedTextColor: {
|
|
22067
|
+
enumerable: true,
|
|
22068
|
+
get: function () {
|
|
22069
|
+
return this._selectedTextColor;
|
|
22070
|
+
}
|
|
22071
|
+
},
|
|
21965
22072
|
handleTextColor: {
|
|
21966
22073
|
enumerable: true,
|
|
21967
22074
|
get: function () {
|
|
21968
22075
|
return this._handleTextColor;
|
|
21969
22076
|
}
|
|
21970
22077
|
},
|
|
22078
|
+
selectedHandleTextColor: {
|
|
22079
|
+
enumerable: true,
|
|
22080
|
+
get: function () {
|
|
22081
|
+
return this._selectedHandleTextColor;
|
|
22082
|
+
}
|
|
22083
|
+
},
|
|
21971
22084
|
warningColor: {
|
|
21972
22085
|
enumerable: true,
|
|
21973
22086
|
get: function () {
|
|
@@ -21986,6 +22099,12 @@ module.exports = function (Utils) {
|
|
|
21986
22099
|
return this._borderColor;
|
|
21987
22100
|
}
|
|
21988
22101
|
},
|
|
22102
|
+
selectedBorderColor: {
|
|
22103
|
+
enumerable: true,
|
|
22104
|
+
get: function () {
|
|
22105
|
+
return this._selectedBorderColor;
|
|
22106
|
+
}
|
|
22107
|
+
},
|
|
21989
22108
|
borderWidth: {
|
|
21990
22109
|
enumerable: true,
|
|
21991
22110
|
get: function () {
|
|
@@ -22057,9 +22176,13 @@ module.exports = function (Utils) {
|
|
|
22057
22176
|
textColor: this.textColor,
|
|
22058
22177
|
handleTextColor: this.handleTextColor,
|
|
22059
22178
|
hoverColor: this.hoverColor,
|
|
22179
|
+
selectedColor: this.selectedColor,
|
|
22180
|
+
selectedTextColor: this.selectedTextColor,
|
|
22181
|
+
selectedHandleTextColor: this.selectedHandleTextColor,
|
|
22060
22182
|
warningColor: this.warningColor,
|
|
22061
22183
|
opacity: this.opacity,
|
|
22062
22184
|
borderColor: this.borderColor,
|
|
22185
|
+
selectedBorderColor: this.selectedBorderColor,
|
|
22063
22186
|
borderWidth: this.borderWidth,
|
|
22064
22187
|
borderRadius: this.borderRadius,
|
|
22065
22188
|
editable: this.editable,
|
|
@@ -22077,9 +22200,13 @@ module.exports = function (Utils) {
|
|
|
22077
22200
|
this._textColor = opts.textColor;
|
|
22078
22201
|
this._handleTextColor = opts.handleTextColor;
|
|
22079
22202
|
this._hoverColor = opts.hoverColor;
|
|
22203
|
+
this._selectedColor = opts.selectedColor;
|
|
22204
|
+
this._selectedTextColor = opts.selectedTextColor;
|
|
22205
|
+
this._selectedHandleTextColor = opts.selectedHandleTextColor;
|
|
22080
22206
|
this._warningColor = opts.warningColor;
|
|
22081
22207
|
this._opacity = opts.opacity;
|
|
22082
22208
|
this._borderColor = opts.borderColor;
|
|
22209
|
+
this._selectedBorderColor = opts.selectedBorderColor;
|
|
22083
22210
|
this._borderWidth = opts.borderWidth;
|
|
22084
22211
|
this._borderRadius = opts.borderRadius;
|
|
22085
22212
|
this._editable = opts.editable;
|
|
@@ -22096,10 +22223,6 @@ module.exports = function (Utils) {
|
|
|
22096
22223
|
this._endTime = Utils.roundTime(newEndTime);
|
|
22097
22224
|
}
|
|
22098
22225
|
};
|
|
22099
|
-
Segment.prototype.setSelected = function (selected) {
|
|
22100
|
-
this._selected = selected;
|
|
22101
|
-
this._peaks.emit('model.segment.selected', this);
|
|
22102
|
-
};
|
|
22103
22226
|
Segment.prototype.isVisible = function (startTime, endTime) {
|
|
22104
22227
|
return this.startTime < endTime && startTime < this.endTime;
|
|
22105
22228
|
};
|
|
@@ -23255,7 +23378,7 @@ module.exports = function (Colors, Segment, Utils) {
|
|
|
23255
23378
|
if (!Utils.isObject(options)) {
|
|
23256
23379
|
throw new TypeError('peaks.segments.add(): expected a Segment object parameter');
|
|
23257
23380
|
}
|
|
23258
|
-
var segment = new Segment(this._peaks, Utils.isNullOrUndefined(options.id) ? this._getNextSegmentId() : options.id, options.startTime, options.endTime, options.duration, options.labelText, options.color || this._getSegmentColor(), options.textColor || '#000000', options.handleTextColor || '#000000', options.hoverColor, options.warningColor, options.opacity || 1, options.borderColor, options.borderWidth, options.borderRadius, options.editable, options.allowDeletion || false, options.line, options.indicators);
|
|
23381
|
+
var segment = new Segment(this._peaks, Utils.isNullOrUndefined(options.id) ? this._getNextSegmentId() : options.id, options.startTime, options.endTime, options.duration, options.labelText, options.color || this._getSegmentColor(), options.textColor || '#000000', options.handleTextColor || '#000000', options.hoverColor, options.selectedColor, options.selectedTextColor, options.selectedHandleTextColor, options.warningColor, options.opacity || 1, options.borderColor, options.selectedBorderColor, options.borderWidth, options.borderRadius, options.editable, options.allowDeletion || false, options.line, options.indicators);
|
|
23259
23382
|
return segment;
|
|
23260
23383
|
};
|
|
23261
23384
|
SegmentHandler.prototype.getSegments = function () {
|
package/peaks.js.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ declare module 'peaks.js' {
|
|
|
9
9
|
endTime: number;
|
|
10
10
|
editable?: boolean;
|
|
11
11
|
color?: string;
|
|
12
|
+
selectedColor?: string;
|
|
13
|
+
selectedTextColor?: string;
|
|
14
|
+
selectedHandleTextColor?: string;
|
|
15
|
+
selectedBorderColor?: string;
|
|
12
16
|
labelText?: string;
|
|
13
17
|
id?: string;
|
|
14
18
|
}
|
|
@@ -18,6 +22,10 @@ declare module 'peaks.js' {
|
|
|
18
22
|
endTime?: number;
|
|
19
23
|
editable?: boolean;
|
|
20
24
|
color?: string;
|
|
25
|
+
selectedColor?: string;
|
|
26
|
+
selectedTextColor?: string;
|
|
27
|
+
selectedHandleTextColor?: string;
|
|
28
|
+
selectedBorderColor?: string;
|
|
21
29
|
labelText?: string;
|
|
22
30
|
}
|
|
23
31
|
|
|
@@ -128,6 +128,10 @@ define([
|
|
|
128
128
|
this._label.setText(Utils.formatTime(time, false));
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
+
DefaultSegmentMarker.prototype.setTextColor = function(color) {
|
|
132
|
+
this._label.fill(color);
|
|
133
|
+
};
|
|
134
|
+
|
|
131
135
|
DefaultSegmentMarker.prototype._batchDraw = function() {
|
|
132
136
|
const group = this._options.group;
|
|
133
137
|
const layer = group && group.getLayer && group.getLayer();
|
|
@@ -134,6 +134,12 @@ define([
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
+
SegmentMarker.prototype.setTextColor = function(color) {
|
|
138
|
+
if (this._marker.setTextColor) {
|
|
139
|
+
this._marker.setTextColor(color);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
137
143
|
SegmentMarker.prototype.destroy = function() {
|
|
138
144
|
this._group.destroyChildren();
|
|
139
145
|
this._group.destroy();
|
|
@@ -47,6 +47,8 @@ define([
|
|
|
47
47
|
this._shapeGroup = null;
|
|
48
48
|
this._rectangle = null;
|
|
49
49
|
this._indicators = {};
|
|
50
|
+
this._selected = this._segment.selected;
|
|
51
|
+
this._hovered = false;
|
|
50
52
|
|
|
51
53
|
var self = this;
|
|
52
54
|
|
|
@@ -105,16 +107,7 @@ define([
|
|
|
105
107
|
this._onSegmentHandleDragStart = this._onSegmentHandleDragStart.bind(this);
|
|
106
108
|
this._onSegmentHandleDragEnd = this._onSegmentHandleDragEnd.bind(this);
|
|
107
109
|
|
|
108
|
-
this.
|
|
109
|
-
x: this._view.timeToPixels(segment.startTime),
|
|
110
|
-
y: this._segmentY,
|
|
111
|
-
width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
|
|
112
|
-
height: this._segmentHeight,
|
|
113
|
-
segment: segment,
|
|
114
|
-
view: this._view.getName(),
|
|
115
|
-
group: this._group,
|
|
116
|
-
fontSize: 12
|
|
117
|
-
});
|
|
110
|
+
this._createLabel();
|
|
118
111
|
|
|
119
112
|
this._createMarkers();
|
|
120
113
|
|
|
@@ -122,6 +115,7 @@ define([
|
|
|
122
115
|
this._shapeGroup.add(this._indicatorsGroup);
|
|
123
116
|
|
|
124
117
|
this.createIndicators();
|
|
118
|
+
this._applyVisualState();
|
|
125
119
|
}
|
|
126
120
|
|
|
127
121
|
SegmentShape.prototype._onShapeGroupDrag = function(draggedElement) {
|
|
@@ -134,10 +128,83 @@ define([
|
|
|
134
128
|
SEGMENT_CORNER_RADIUS;
|
|
135
129
|
};
|
|
136
130
|
|
|
131
|
+
SegmentShape.prototype._createLabel = function() {
|
|
132
|
+
this._label = this._peaks.options.createSegmentLabel({
|
|
133
|
+
x: this._view.timeToPixels(this._segment.startTime),
|
|
134
|
+
y: this._segmentY,
|
|
135
|
+
width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
|
|
136
|
+
height: this._segmentHeight,
|
|
137
|
+
segment: this._segment,
|
|
138
|
+
view: this._view.getName(),
|
|
139
|
+
group: this._group,
|
|
140
|
+
fontSize: 12
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
SegmentShape.prototype._getFillColor = function() {
|
|
145
|
+
var color = this._segment.color;
|
|
146
|
+
|
|
147
|
+
if (this._selected) {
|
|
148
|
+
color = this._segment.selectedColor;
|
|
149
|
+
}
|
|
150
|
+
else if (this._hovered) {
|
|
151
|
+
color = this._segment.hoverColor;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return color + Math.round(this._segment.opacity * 255).toString(16);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
SegmentShape.prototype._getStrokeColor = function() {
|
|
158
|
+
if (this._selected) {
|
|
159
|
+
return this._segment.selectedBorderColor;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return this._segment.borderColor || this._segment.textColor + 'FF';
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
SegmentShape.prototype._getLabelTextColor = function() {
|
|
166
|
+
return this._selected ? this._segment.selectedTextColor : this._segment.textColor;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
SegmentShape.prototype._getHandleTextColor = function() {
|
|
170
|
+
return this._selected ?
|
|
171
|
+
this._segment.selectedHandleTextColor :
|
|
172
|
+
this._segment.handleTextColor;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
SegmentShape.prototype._applyVisualState = function() {
|
|
176
|
+
var fillColor = this._getFillColor();
|
|
177
|
+
var handleTextColor = this._getHandleTextColor();
|
|
178
|
+
|
|
179
|
+
this._rectangle.fill(fillColor);
|
|
180
|
+
this._rectangle.stroke(this._getStrokeColor());
|
|
181
|
+
this._rectangle.fillLinearGradientColorStops([
|
|
182
|
+
0, fillColor,
|
|
183
|
+
0.65, this._segment.warningColor
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
if (this._label && this._label.fill) {
|
|
187
|
+
this._label.fill(this._getLabelTextColor());
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (this._startMarker) {
|
|
191
|
+
this._startMarker.setTextColor(handleTextColor);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this._endMarker) {
|
|
195
|
+
this._endMarker.setTextColor(handleTextColor);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
137
199
|
SegmentShape.prototype.update = function() {
|
|
138
200
|
this._applyDisplayTimes(this._segment.startTime, this._segment.endTime);
|
|
139
201
|
};
|
|
140
202
|
|
|
203
|
+
SegmentShape.prototype.setSelected = function() {
|
|
204
|
+
this._selected = this._segment.selected;
|
|
205
|
+
this._applyVisualState();
|
|
206
|
+
};
|
|
207
|
+
|
|
141
208
|
SegmentShape.prototype._applyDisplayTimes = function(startTime, endTime) {
|
|
142
209
|
var startPixel = this._view.timeToPixels(startTime);
|
|
143
210
|
var endPixel = this._view.timeToPixels(endTime);
|
|
@@ -364,16 +431,8 @@ define([
|
|
|
364
431
|
this._view.setCursor('pointer');
|
|
365
432
|
|
|
366
433
|
this._view.setHoveredElement(this);
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
this._segment.opacity * 255
|
|
370
|
-
).toString(16);
|
|
371
|
-
|
|
372
|
-
this._rectangle.fill(fillColor);
|
|
373
|
-
this._rectangle.fillLinearGradientColorStops([
|
|
374
|
-
0, fillColor,
|
|
375
|
-
0.65, this._segment.warningColor
|
|
376
|
-
]);
|
|
434
|
+
this._hovered = true;
|
|
435
|
+
this._applyVisualState();
|
|
377
436
|
|
|
378
437
|
this._view.batchDrawSourcesLayer();
|
|
379
438
|
|
|
@@ -384,16 +443,8 @@ define([
|
|
|
384
443
|
this._view.setCursor('default');
|
|
385
444
|
|
|
386
445
|
this._view.setHoveredElement(null);
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
this._segment.opacity * 255
|
|
390
|
-
).toString(16);
|
|
391
|
-
|
|
392
|
-
this._rectangle.fill(fillColor);
|
|
393
|
-
this._rectangle.fillLinearGradientColorStops([
|
|
394
|
-
0, fillColor,
|
|
395
|
-
0.65, this._segment.warningColor
|
|
396
|
-
]);
|
|
446
|
+
this._hovered = false;
|
|
447
|
+
this._applyVisualState();
|
|
397
448
|
|
|
398
449
|
this._view.batchDrawSourcesLayer();
|
|
399
450
|
|
|
@@ -546,6 +546,15 @@ define([
|
|
|
546
546
|
}
|
|
547
547
|
};
|
|
548
548
|
|
|
549
|
+
SegmentsGroup.prototype.setSelected = function(segment) {
|
|
550
|
+
var segmentShape = this._segmentShapes[segment.id];
|
|
551
|
+
|
|
552
|
+
if (segmentShape) {
|
|
553
|
+
segmentShape.setSelected();
|
|
554
|
+
this._draw();
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
549
558
|
SegmentsGroup.prototype.addToUpdatedSegments = function(segment) {
|
|
550
559
|
if (this._updatedSegments.indexOf(segment) === -1) {
|
|
551
560
|
this._updatedSegments.push(segment);
|
|
@@ -77,6 +77,7 @@ define([
|
|
|
77
77
|
this._peaks.on('handler.sources.show', this._onSourcesShow.bind(this));
|
|
78
78
|
this._peaks.on('handler.sources.hide', this._onSourcesHide.bind(this));
|
|
79
79
|
this._peaks.on('sources.setSelected', this._onSourcesSetSelected.bind(this));
|
|
80
|
+
this._peaks.on('segments.setSelected', this._onSegmentsSetSelected.bind(this));
|
|
80
81
|
this._peaks.on('model.source.update', this._onSourceUpdate.bind(this));
|
|
81
82
|
this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
|
|
82
83
|
this._peaks.on('handler.segments.show', this._onSegmentsShow.bind(this));
|
|
@@ -270,13 +271,29 @@ define([
|
|
|
270
271
|
};
|
|
271
272
|
|
|
272
273
|
SourcesLayer.prototype._onSourcesSetSelected = function(sources) {
|
|
274
|
+
var sourcesGroups = this._lineGroups.getSourcesGroups();
|
|
275
|
+
|
|
273
276
|
sources.forEach(function(source) {
|
|
274
|
-
const sourceGroup =
|
|
277
|
+
const sourceGroup = sourcesGroups[source.id];
|
|
275
278
|
|
|
276
279
|
if (sourceGroup) {
|
|
277
280
|
sourceGroup.setSelected();
|
|
278
281
|
}
|
|
279
|
-
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
this.batchDraw();
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
SourcesLayer.prototype._onSegmentsSetSelected = function(segments) {
|
|
288
|
+
var segmentsGroups = this._lineGroups.getSegmentsGroups();
|
|
289
|
+
|
|
290
|
+
segments.forEach(function(segment) {
|
|
291
|
+
var segmentsGroup = segmentsGroups[segment.line];
|
|
292
|
+
|
|
293
|
+
if (segmentsGroup) {
|
|
294
|
+
segmentsGroup.setSelected(segment);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
280
297
|
|
|
281
298
|
this.batchDraw();
|
|
282
299
|
};
|
package/src/models/segment.js
CHANGED
|
@@ -71,6 +71,43 @@ define([
|
|
|
71
71
|
throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
if (Utils.isNullOrUndefined(options.selectedColor)) {
|
|
75
|
+
options.selectedColor = options.color;
|
|
76
|
+
}
|
|
77
|
+
else if (!Utils.isValidColor(options.selectedColor)) {
|
|
78
|
+
throw new TypeError('peaks.segments.' + context + ': selectedColor must be a valid CSS color');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (Utils.isNullOrUndefined(options.selectedTextColor)) {
|
|
82
|
+
options.selectedTextColor = options.textColor;
|
|
83
|
+
}
|
|
84
|
+
else if (!Utils.isValidColor(options.selectedTextColor)) {
|
|
85
|
+
throw new TypeError(
|
|
86
|
+
'peaks.segments.' + context + ': selectedTextColor must be a valid CSS color'
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (Utils.isNullOrUndefined(options.selectedHandleTextColor)) {
|
|
91
|
+
options.selectedHandleTextColor = options.handleTextColor;
|
|
92
|
+
}
|
|
93
|
+
else if (!Utils.isValidColor(options.selectedHandleTextColor)) {
|
|
94
|
+
throw new TypeError(
|
|
95
|
+
'peaks.segments.' + context + ': selectedHandleTextColor must be a valid CSS color'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (Utils.isNullOrUndefined(options.selectedBorderColor)) {
|
|
100
|
+
options.selectedBorderColor = Utils.shadeColor(
|
|
101
|
+
options.borderColor || options.textColor + 'FF',
|
|
102
|
+
30
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
else if (!Utils.isValidColor(options.selectedBorderColor)) {
|
|
106
|
+
throw new TypeError(
|
|
107
|
+
'peaks.segments.' + context + ': selectedBorderColor must be a valid CSS color'
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
74
111
|
if (Utils.isNullOrUndefined(options.warningColor)) {
|
|
75
112
|
options.warningColor = '#E48023';
|
|
76
113
|
}
|
|
@@ -104,9 +141,10 @@ define([
|
|
|
104
141
|
*/
|
|
105
142
|
|
|
106
143
|
function Segment(peaks, id, startTime, endTime, duration, labelText,
|
|
107
|
-
color, textColor, handleTextColor, hoverColor,
|
|
108
|
-
|
|
109
|
-
|
|
144
|
+
color, textColor, handleTextColor, hoverColor, selectedColor,
|
|
145
|
+
selectedTextColor, selectedHandleTextColor, warningColor, opacity,
|
|
146
|
+
borderColor, selectedBorderColor, borderWidth, borderRadius, editable,
|
|
147
|
+
allowDeletion, line, indicators) {
|
|
110
148
|
var opts = {
|
|
111
149
|
startTime: startTime,
|
|
112
150
|
endTime: endTime,
|
|
@@ -116,9 +154,13 @@ define([
|
|
|
116
154
|
textColor: textColor,
|
|
117
155
|
handleTextColor: handleTextColor,
|
|
118
156
|
hoverColor: hoverColor,
|
|
157
|
+
selectedColor: selectedColor,
|
|
158
|
+
selectedTextColor: selectedTextColor,
|
|
159
|
+
selectedHandleTextColor: selectedHandleTextColor,
|
|
119
160
|
warningColor: warningColor,
|
|
120
161
|
opacity: opacity,
|
|
121
162
|
borderColor: borderColor,
|
|
163
|
+
selectedBorderColor: selectedBorderColor,
|
|
122
164
|
borderWidth: borderWidth,
|
|
123
165
|
borderRadius: borderRadius,
|
|
124
166
|
editable: editable,
|
|
@@ -139,9 +181,13 @@ define([
|
|
|
139
181
|
this._hoverColor = opts.hoverColor;
|
|
140
182
|
this._textColor = opts.textColor;
|
|
141
183
|
this._handleTextColor = opts.handleTextColor;
|
|
184
|
+
this._selectedColor = opts.selectedColor;
|
|
185
|
+
this._selectedTextColor = opts.selectedTextColor;
|
|
186
|
+
this._selectedHandleTextColor = opts.selectedHandleTextColor;
|
|
142
187
|
this._warningColor = opts.warningColor;
|
|
143
188
|
this._opacity = opts.opacity;
|
|
144
189
|
this._borderColor = opts.borderColor;
|
|
190
|
+
this._selectedBorderColor = opts.selectedBorderColor;
|
|
145
191
|
this._borderWidth = opts.borderWidth;
|
|
146
192
|
this._borderRadius = opts.borderRadius;
|
|
147
193
|
this._editable = opts.editable;
|
|
@@ -213,18 +259,36 @@ define([
|
|
|
213
259
|
return this._hoverColor;
|
|
214
260
|
}
|
|
215
261
|
},
|
|
262
|
+
selectedColor: {
|
|
263
|
+
enumerable: true,
|
|
264
|
+
get: function() {
|
|
265
|
+
return this._selectedColor;
|
|
266
|
+
}
|
|
267
|
+
},
|
|
216
268
|
textColor: {
|
|
217
269
|
enumerable: true,
|
|
218
270
|
get: function() {
|
|
219
271
|
return this._textColor;
|
|
220
272
|
}
|
|
221
273
|
},
|
|
274
|
+
selectedTextColor: {
|
|
275
|
+
enumerable: true,
|
|
276
|
+
get: function() {
|
|
277
|
+
return this._selectedTextColor;
|
|
278
|
+
}
|
|
279
|
+
},
|
|
222
280
|
handleTextColor: {
|
|
223
281
|
enumerable: true,
|
|
224
282
|
get: function() {
|
|
225
283
|
return this._handleTextColor;
|
|
226
284
|
}
|
|
227
285
|
},
|
|
286
|
+
selectedHandleTextColor: {
|
|
287
|
+
enumerable: true,
|
|
288
|
+
get: function() {
|
|
289
|
+
return this._selectedHandleTextColor;
|
|
290
|
+
}
|
|
291
|
+
},
|
|
228
292
|
warningColor: {
|
|
229
293
|
enumerable: true,
|
|
230
294
|
get: function() {
|
|
@@ -243,6 +307,12 @@ define([
|
|
|
243
307
|
return this._borderColor;
|
|
244
308
|
}
|
|
245
309
|
},
|
|
310
|
+
selectedBorderColor: {
|
|
311
|
+
enumerable: true,
|
|
312
|
+
get: function() {
|
|
313
|
+
return this._selectedBorderColor;
|
|
314
|
+
}
|
|
315
|
+
},
|
|
246
316
|
borderWidth: {
|
|
247
317
|
enumerable: true,
|
|
248
318
|
get: function() {
|
|
@@ -316,9 +386,13 @@ define([
|
|
|
316
386
|
textColor: this.textColor,
|
|
317
387
|
handleTextColor: this.handleTextColor,
|
|
318
388
|
hoverColor: this.hoverColor,
|
|
389
|
+
selectedColor: this.selectedColor,
|
|
390
|
+
selectedTextColor: this.selectedTextColor,
|
|
391
|
+
selectedHandleTextColor: this.selectedHandleTextColor,
|
|
319
392
|
warningColor: this.warningColor,
|
|
320
393
|
opacity: this.opacity,
|
|
321
394
|
borderColor: this.borderColor,
|
|
395
|
+
selectedBorderColor: this.selectedBorderColor,
|
|
322
396
|
borderWidth: this.borderWidth,
|
|
323
397
|
borderRadius: this.borderRadius,
|
|
324
398
|
editable: this.editable,
|
|
@@ -339,9 +413,13 @@ define([
|
|
|
339
413
|
this._textColor = opts.textColor;
|
|
340
414
|
this._handleTextColor = opts.handleTextColor;
|
|
341
415
|
this._hoverColor = opts.hoverColor;
|
|
416
|
+
this._selectedColor = opts.selectedColor;
|
|
417
|
+
this._selectedTextColor = opts.selectedTextColor;
|
|
418
|
+
this._selectedHandleTextColor = opts.selectedHandleTextColor;
|
|
342
419
|
this._warningColor = opts.warningColor;
|
|
343
420
|
this._opacity = opts.opacity;
|
|
344
421
|
this._borderColor = opts.borderColor;
|
|
422
|
+
this._selectedBorderColor = opts.selectedBorderColor;
|
|
345
423
|
this._borderWidth = opts.borderWidth;
|
|
346
424
|
this._borderRadius = opts.borderRadius;
|
|
347
425
|
this._editable = opts.editable;
|
|
@@ -371,11 +449,6 @@ define([
|
|
|
371
449
|
}
|
|
372
450
|
};
|
|
373
451
|
|
|
374
|
-
Segment.prototype.setSelected = function(selected) {
|
|
375
|
-
this._selected = selected;
|
|
376
|
-
this._peaks.emit('model.segment.selected', this);
|
|
377
|
-
};
|
|
378
|
-
|
|
379
452
|
/**
|
|
380
453
|
* Returns <code>true</code> if the segment overlaps a given time region.
|
|
381
454
|
*
|
package/src/segment-handler.js
CHANGED
|
@@ -136,9 +136,13 @@ define([
|
|
|
136
136
|
options.textColor || '#000000',
|
|
137
137
|
options.handleTextColor || '#000000',
|
|
138
138
|
options.hoverColor,
|
|
139
|
+
options.selectedColor,
|
|
140
|
+
options.selectedTextColor,
|
|
141
|
+
options.selectedHandleTextColor,
|
|
139
142
|
options.warningColor,
|
|
140
143
|
options.opacity || 1,
|
|
141
144
|
options.borderColor,
|
|
145
|
+
options.selectedBorderColor,
|
|
142
146
|
options.borderWidth,
|
|
143
147
|
options.borderRadius,
|
|
144
148
|
options.editable,
|