@checksub_team/peaks_timeline 2.2.0 → 2.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -15576,7 +15576,8 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15576
15576
  this._peaks.addLine({
15577
15577
  position: newLinePosition,
15578
15578
  indicatorType: this._peaks.options.defaultLineIndicatorType,
15579
- indicatorText: this._peaks.options.defaultLineIndicatorText
15579
+ indicatorText: this._peaks.options.defaultLineIndicatorText,
15580
+ indicatorSubText: this._peaks.options.defaultLineIndicatorSubText
15580
15581
  }, true);
15581
15582
  const automaticallyCreatedLineGroup = this._lineGroupsByPosition[newLinePosition];
15582
15583
  if (!automaticallyCreatedLineGroup) {
@@ -15833,7 +15834,8 @@ module.exports = function (Konva, SVGs, Utils) {
15833
15834
  }
15834
15835
  };
15835
15836
  this._yPadding = 30;
15836
- this._defaultPadding = 5;
15837
+ this._topPadding = this._peaks.options.lineIndicatorPadding.top;
15838
+ this._bottomPadding = this._peaks.options.lineIndicatorPadding.bottom;
15837
15839
  this._types = ['default'].concat(Object.keys(SVGs));
15838
15840
  this._stage = new Konva.Stage({
15839
15841
  container: container,
@@ -15873,109 +15875,191 @@ module.exports = function (Konva, SVGs, Utils) {
15873
15875
  ]);
15874
15876
  this.refreshIndicators();
15875
15877
  };
15876
- LineIndicator.prototype._createIndicator = function (lineGroup, type, text) {
15878
+ LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText) {
15877
15879
  const indicator = new Konva.Group();
15878
15880
  let indicatorHeight = 0;
15881
+ var self = this;
15882
+ var textGroup, iconGroup, subTextGroup;
15883
+ var textNode, iconNode, subTextNode;
15879
15884
  if (text) {
15880
- const textNode = new Konva.Text({
15881
- text: text,
15882
- fontSize: this._sizes.font,
15883
- fontFamily: this._peaks.options.lineIndicatorFont,
15884
- fill: this._peaks.options.lineIndicatorTextColor,
15885
- align: 'center',
15886
- width: this._width,
15887
- listening: false
15885
+ [textGroup, textNode] = this._createIndicatorText(text);
15886
+ indicator.add(textGroup);
15887
+ indicatorHeight += textGroup.getAttr('trueHeight') + this._topPadding;
15888
+ }
15889
+ [iconGroup, iconNode] = this._createIndicatorIcon(type);
15890
+ iconGroup.y(indicatorHeight);
15891
+ indicator.add(iconGroup);
15892
+ indicatorHeight += iconGroup.getAttr('trueHeight');
15893
+ if (subText) {
15894
+ indicatorHeight += this._bottomPadding;
15895
+ [subTextGroup, subTextNode] = this._createIndicatorText(subText);
15896
+ subTextGroup.y(indicatorHeight);
15897
+ indicator.add(subTextGroup);
15898
+ indicatorHeight += subTextGroup.getAttr('trueHeight');
15899
+ }
15900
+ if (textGroup) {
15901
+ textGroup.on('mouseenter', function () {
15902
+ textNode.fill(textNode.getAttr('selectedColor'));
15903
+ if (iconNode) {
15904
+ iconNode.fill(iconNode.getAttr('selectedColor'));
15905
+ }
15906
+ self.batchDraw();
15907
+ self._stage.container().style.cursor = 'pointer';
15908
+ });
15909
+ textGroup.on('mouseout', function () {
15910
+ textNode.fill(textNode.getAttr('defaultColor'));
15911
+ if (iconNode) {
15912
+ iconNode.fill(iconNode.getAttr('defaultColor'));
15913
+ }
15914
+ self.batchDraw();
15915
+ if (!self._isDragging) {
15916
+ self._stage.container().style.cursor = 'default';
15917
+ }
15918
+ });
15919
+ textGroup.on('click', function (e) {
15920
+ self._peaks.emit('lineIndicator.text.click', self._indicators[lineGroup.getId()], e.evt);
15921
+ });
15922
+ }
15923
+ if (iconGroup) {
15924
+ iconGroup.on('mouseenter', function () {
15925
+ iconNode.fill(iconNode.getAttr('selectedColor'));
15926
+ if (textNode) {
15927
+ textNode.fill(textNode.getAttr('selectedColor'));
15928
+ }
15929
+ self.batchDraw();
15930
+ self._stage.container().style.cursor = 'pointer';
15931
+ });
15932
+ iconGroup.on('mouseout', function () {
15933
+ iconNode.fill(iconNode.getAttr('defaultColor'));
15934
+ if (textNode) {
15935
+ textNode.fill(textNode.getAttr('defaultColor'));
15936
+ }
15937
+ self.batchDraw();
15938
+ if (!self._isDragging) {
15939
+ self._stage.container().style.cursor = 'default';
15940
+ }
15941
+ });
15942
+ iconGroup.on('click', function (e) {
15943
+ self._peaks.emit('lineIndicator.icon.click', self._indicators[lineGroup.getId()], e.evt);
15944
+ });
15945
+ iconGroup.on('mousedown touchstart', function () {
15946
+ self._dragLineId = lineGroup.getId();
15947
+ self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
15948
+ window.addEventListener('mousemove', self._onWindowMove, false);
15949
+ window.addEventListener('touchmove', self._onWindowMove, false);
15950
+ window.addEventListener('mouseup', self._onWindowUp, false);
15951
+ window.addEventListener('touchend', self._onWindowUp, false);
15952
+ window.addEventListener('blur', self._onWindowUp, false);
15888
15953
  });
15889
- textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
15890
- textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
15891
- indicator.add(textNode);
15892
- indicatorHeight += this._sizes.font;
15893
15954
  }
15955
+ if (subTextGroup) {
15956
+ subTextGroup.on('mouseenter', function () {
15957
+ subTextNode.fill(subTextNode.getAttr('selectedColor'));
15958
+ self.batchDraw();
15959
+ self._stage.container().style.cursor = 'pointer';
15960
+ });
15961
+ subTextGroup.on('mouseout', function () {
15962
+ subTextNode.fill(subTextNode.getAttr('defaultColor'));
15963
+ self.batchDraw();
15964
+ if (!self._isDragging) {
15965
+ self._stage.container().style.cursor = 'default';
15966
+ }
15967
+ });
15968
+ subTextGroup.on('click', function (e) {
15969
+ self._peaks.emit('lineIndicator.subText.click', self._indicators[lineGroup.getId()], e.evt);
15970
+ });
15971
+ }
15972
+ indicator.setAttr('trueHeight', indicatorHeight);
15973
+ indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
15974
+ return indicator;
15975
+ };
15976
+ LineIndicator.prototype._createIndicatorText = function (text) {
15977
+ const textGroup = new Konva.Group();
15978
+ const textNode = new Konva.Text({
15979
+ text: text,
15980
+ fontSize: this._sizes.font,
15981
+ fontFamily: this._peaks.options.lineIndicatorFont,
15982
+ fill: this._peaks.options.lineIndicatorTextColor,
15983
+ align: 'center',
15984
+ width: this._width,
15985
+ listening: false
15986
+ });
15987
+ textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
15988
+ textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
15989
+ var textRect = new Konva.Rect({
15990
+ x: 0,
15991
+ y: 0,
15992
+ width: this._width,
15993
+ height: this._sizes.font,
15994
+ fill: 'transparent',
15995
+ listening: true
15996
+ });
15997
+ textGroup.add(textNode);
15998
+ textGroup.add(textRect);
15999
+ textRect.moveToTop();
16000
+ textGroup.setAttr('trueHeight', this._sizes.font);
16001
+ return [
16002
+ textGroup,
16003
+ textNode
16004
+ ];
16005
+ };
16006
+ LineIndicator.prototype._createIndicatorIcon = function (type) {
15894
16007
  type = this._types.includes(type) ? type : 'default';
16008
+ const iconGroup = new Konva.Group();
16009
+ var iconHeight = this._sizes.icon[type];
15895
16010
  var iconNode;
15896
16011
  if (type === 'default') {
15897
- var padding = text ? this._defaultPadding : 0;
15898
16012
  iconNode = new Konva.Circle({
15899
16013
  x: this._width / 2,
15900
- y: indicatorHeight + this._sizes.icon.default / 2 + padding,
16014
+ y: this._sizes.icon.default / 2,
15901
16015
  radius: this._sizes.icon.default / 2,
15902
16016
  fill: this._peaks.options.lineIndicatorIconColor,
15903
16017
  strokeWidth: 0,
15904
- lineId: lineGroup.getId(),
15905
16018
  listening: false
15906
16019
  });
15907
- indicatorHeight += padding;
15908
16020
  } else {
15909
16021
  iconNode = new Konva.Path({
15910
16022
  x: (this._width - this._sizes.icon[type]) / 2,
15911
- y: indicatorHeight,
16023
+ y: 0,
15912
16024
  data: SVGs[type].path,
15913
16025
  fill: this._peaks.options.lineIndicatorIconColor,
15914
16026
  scale: {
15915
16027
  x: this._sizes.icon[type] / SVGs[type].width,
15916
16028
  y: this._sizes.icon[type] / SVGs[type].height
15917
16029
  },
15918
- lineId: lineGroup.getId(),
15919
16030
  listening: false
15920
16031
  });
15921
16032
  }
15922
16033
  iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
15923
16034
  iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
15924
- indicator.add(iconNode);
15925
- indicatorHeight += this._sizes.icon[type];
15926
- indicator.setAttr('trueHeight', indicatorHeight);
15927
- var backgroundRect = new Konva.Rect({
16035
+ var iconRect = new Konva.Rect({
15928
16036
  x: 0,
15929
16037
  y: 0,
15930
16038
  width: this._width,
15931
- height: indicatorHeight,
16039
+ height: iconHeight,
15932
16040
  fill: 'transparent',
15933
16041
  listening: true
15934
16042
  });
15935
- indicator.add(backgroundRect);
15936
- backgroundRect.moveToTop();
15937
- indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
15938
- var self = this;
15939
- indicator.on('mouseenter', function () {
15940
- indicator.getChildren().forEach(function (child) {
15941
- child.fill(child.getAttr('selectedColor'));
15942
- });
15943
- self.batchDraw();
15944
- self._stage.container().style.cursor = 'pointer';
15945
- });
15946
- indicator.on('mouseout', function () {
15947
- indicator.getChildren().forEach(function (child) {
15948
- child.fill(child.getAttr('defaultColor'));
15949
- });
15950
- self.batchDraw();
15951
- if (!self._isDragging) {
15952
- self._stage.container().style.cursor = 'default';
15953
- }
15954
- });
15955
- indicator.on('click', function (e) {
15956
- self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
15957
- });
15958
- indicator.on('mousedown touchstart', function () {
15959
- self._dragLineId = lineGroup.getId();
15960
- self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
15961
- window.addEventListener('mousemove', self._onWindowMove, false);
15962
- window.addEventListener('touchmove', self._onWindowMove, false);
15963
- window.addEventListener('mouseup', self._onWindowUp, false);
15964
- window.addEventListener('touchend', self._onWindowUp, false);
15965
- window.addEventListener('blur', self._onWindowUp, false);
15966
- });
15967
- return indicator;
16043
+ iconGroup.add(iconNode);
16044
+ iconGroup.add(iconRect);
16045
+ iconRect.moveToTop();
16046
+ iconGroup.setAttr('trueHeight', iconHeight);
16047
+ return [
16048
+ iconGroup,
16049
+ iconNode
16050
+ ];
15968
16051
  };
15969
16052
  LineIndicator.prototype.addIndicator = function (lineGroup) {
15970
16053
  var line = lineGroup.getLine();
15971
16054
  if (!this._indicators[lineGroup.id]) {
15972
- const indicator = this._createIndicator(lineGroup, line.indicatorType, line.indicatorText);
16055
+ const indicator = this._createIndicator(lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText);
15973
16056
  this._layer.add(indicator);
15974
16057
  this._indicators[line.id] = {
15975
16058
  lineGroup: lineGroup,
15976
16059
  indicator: indicator,
15977
16060
  type: line.indicatorType,
15978
- text: line.indicatorText
16061
+ text: line.indicatorText,
16062
+ subText: line.indicatorSubText
15979
16063
  };
15980
16064
  }
15981
16065
  };
@@ -15989,11 +16073,12 @@ module.exports = function (Konva, SVGs, Utils) {
15989
16073
  return;
15990
16074
  }
15991
16075
  this.removeIndicator(line.id, true);
15992
- var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText);
16076
+ var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText);
15993
16077
  this._layer.add(indicator);
15994
16078
  indicatorData.indicator = indicator;
15995
16079
  indicatorData.type = line.indicatorType;
15996
16080
  indicatorData.text = line.indicatorText;
16081
+ indicatorData.subText = line.indicatorSubText;
15997
16082
  this.batchDraw();
15998
16083
  };
15999
16084
  LineIndicator.prototype.removeIndicator = function (lineId, keepInList) {
@@ -16016,7 +16101,7 @@ module.exports = function (Konva, SVGs, Utils) {
16016
16101
  const hasNoIndicator = !this._indicators[lineId].indicator;
16017
16102
  if (isVisible) {
16018
16103
  if (hasNoIndicator) {
16019
- this._indicators[lineId].indicator = this._createIndicator(this._indicators[lineId].lineGroup, this._indicators[lineId].type, this._indicators[lineId].text);
16104
+ this._indicators[lineId].indicator = this._createIndicator(this._indicators[lineId].lineGroup, this._indicators[lineId].type, this._indicators[lineId].text, this._indicators[lineId].subText);
16020
16105
  this._layer.add(this._indicators[lineId].indicator);
16021
16106
  anyChange = true;
16022
16107
  } else {
@@ -19994,7 +20079,7 @@ module.exports = function (Line, Utils) {
19994
20079
  if (!Utils.isObject(options)) {
19995
20080
  throw new TypeError('peaks.lines.add(): expected a Line object parameter');
19996
20081
  }
19997
- var line = new Line(this._peaks, Utils.isNullOrUndefined(options.id) ? Utils.createUuidv4() : options.id, options.position, options.indicatorType, options.indicatorText, options.locked);
20082
+ var line = new Line(this._peaks, Utils.isNullOrUndefined(options.id) ? Utils.createUuidv4() : options.id, options.position, options.indicatorType, options.indicatorText, options.indicatorSubText, options.locked);
19998
20083
  return line;
19999
20084
  };
20000
20085
  LineHandler.prototype.getLines = function () {
@@ -20096,6 +20181,10 @@ module.exports = function (Colors, EventEmitter, SegmentHandler, SourceHandler,
20096
20181
  lineIndicatorIconColor: '#8A8F98',
20097
20182
  lineIndicatorSelectedTextColor: '#ccc',
20098
20183
  lineIndicatorSelectedIconColor: '#ccc',
20184
+ lineIndicatorPadding: {
20185
+ top: 0,
20186
+ bottom: 3
20187
+ },
20099
20188
  sourceSelectedBorderWidth: 3,
20100
20189
  sourceHandleWidth: 12,
20101
20190
  sourceTextXOffset: 10,
@@ -20112,7 +20201,8 @@ module.exports = function (Colors, EventEmitter, SegmentHandler, SourceHandler,
20112
20201
  canMoveSourcesBetweenLines: true,
20113
20202
  automaticLineCreationDelay: 100,
20114
20203
  defaultLineIndicatorType: 'default',
20115
- defaultLineIndicatorText: ''
20204
+ defaultLineIndicatorText: '',
20205
+ defaultLineIndicatorSubText: ''
20116
20206
  };
20117
20207
  this.logger = console.error.bind(console);
20118
20208
  return this;
@@ -20343,17 +20433,23 @@ module.exports = function (Utils) {
20343
20433
  } else if (!Utils.isString(options.indicatorText)) {
20344
20434
  throw new TypeError('peaks.lines.' + context + ': indicatorText must be a string');
20345
20435
  }
20436
+ if (Utils.isNullOrUndefined(options.indicatorSubText)) {
20437
+ options.indicatorSubText = '';
20438
+ } else if (!Utils.isString(options.indicatorSubText)) {
20439
+ throw new TypeError('peaks.lines.' + context + ': indicatorSubText must be a string');
20440
+ }
20346
20441
  if (Utils.isNullOrUndefined(options.locked)) {
20347
20442
  options.locked = false;
20348
20443
  } else if (!Utils.isBoolean(options.locked)) {
20349
20444
  throw new TypeError('peaks.lines.' + context + ': locked must be a boolean');
20350
20445
  }
20351
20446
  }
20352
- function Line(peaks, id, position, indicatorType, indicatorText, locked) {
20447
+ function Line(peaks, id, position, indicatorType, indicatorText, indicatorSubText, locked) {
20353
20448
  var opts = {
20354
20449
  position: position,
20355
20450
  indicatorType: indicatorType,
20356
20451
  indicatorText: indicatorText,
20452
+ indicatorSubText: indicatorSubText,
20357
20453
  locked: locked
20358
20454
  };
20359
20455
  validateLine(opts, 'add()');
@@ -20362,6 +20458,7 @@ module.exports = function (Utils) {
20362
20458
  this._position = opts.position;
20363
20459
  this._indicatorType = opts.indicatorType;
20364
20460
  this._indicatorText = opts.indicatorText;
20461
+ this._indicatorSubText = opts.indicatorSubText;
20365
20462
  this._locked = opts.locked;
20366
20463
  }
20367
20464
  Object.defineProperties(Line.prototype, {
@@ -20392,6 +20489,12 @@ module.exports = function (Utils) {
20392
20489
  return this._indicatorText;
20393
20490
  }
20394
20491
  },
20492
+ indicatorSubText: {
20493
+ enumerable: true,
20494
+ get: function () {
20495
+ return this._indicatorSubText;
20496
+ }
20497
+ },
20395
20498
  locked: {
20396
20499
  enumerable: true,
20397
20500
  get: function () {
@@ -20404,6 +20507,7 @@ module.exports = function (Utils) {
20404
20507
  position: this.position,
20405
20508
  indicatorType: this.indicatorType,
20406
20509
  indicatorText: this.indicatorText,
20510
+ indicatorSubText: this.indicatorSubText,
20407
20511
  locked: this.locked
20408
20512
  };
20409
20513
  Utils.extend(opts, options);
@@ -20411,6 +20515,7 @@ module.exports = function (Utils) {
20411
20515
  this._position = opts.position;
20412
20516
  this._indicatorType = opts.indicatorType;
20413
20517
  this._indicatorText = opts.indicatorText;
20518
+ this._indicatorSubText = opts.indicatorSubText;
20414
20519
  this._locked = opts.locked;
20415
20520
  this._peaks.emit('model.line.update', this);
20416
20521
  };
@@ -330,7 +330,8 @@ define([
330
330
  this._peaks.addLine({
331
331
  position: newLinePosition,
332
332
  indicatorType: this._peaks.options.defaultLineIndicatorType,
333
- indicatorText: this._peaks.options.defaultLineIndicatorText
333
+ indicatorText: this._peaks.options.defaultLineIndicatorText,
334
+ indicatorSubText: this._peaks.options.defaultLineIndicatorSubText
334
335
  }, true);
335
336
  const automaticallyCreatedLineGroup = this._lineGroupsByPosition[newLinePosition];
336
337
 
@@ -46,7 +46,8 @@ define([
46
46
  };
47
47
 
48
48
  this._yPadding = 30;
49
- this._defaultPadding = 5;
49
+ this._topPadding = this._peaks.options.lineIndicatorPadding.top;
50
+ this._bottomPadding = this._peaks.options.lineIndicatorPadding.bottom;
50
51
  this._types = ['default'].concat(Object.keys(SVGs));
51
52
 
52
53
  this._stage = new Konva.Stage({
@@ -88,58 +89,187 @@ define([
88
89
  this.refreshIndicators();
89
90
  };
90
91
 
91
- LineIndicator.prototype._createIndicator = function(lineGroup, type, text) {
92
+ LineIndicator.prototype._createIndicator = function(lineGroup, type, text, subText) {
92
93
  const indicator = new Konva.Group();
93
94
  let indicatorHeight = 0;
95
+ var self = this;
96
+ var textGroup, iconGroup, subTextGroup;
97
+ var textNode, iconNode, subTextNode;
94
98
 
95
99
  if (text) {
96
- const textNode = new Konva.Text({
97
- text: text,
98
- fontSize: this._sizes.font,
99
- fontFamily: this._peaks.options.lineIndicatorFont,
100
- fill: this._peaks.options.lineIndicatorTextColor,
101
- align: 'center',
102
- width: this._width,
103
- listening: false
100
+ [textGroup, textNode] = this._createIndicatorText(text);
101
+
102
+ indicator.add(textGroup);
103
+ indicatorHeight += textGroup.getAttr('trueHeight') + this._topPadding;
104
+ }
105
+
106
+ [iconGroup, iconNode] = this._createIndicatorIcon(type);
107
+
108
+ iconGroup.y(indicatorHeight);
109
+ indicator.add(iconGroup);
110
+ indicatorHeight += iconGroup.getAttr('trueHeight');
111
+
112
+ if (subText) {
113
+ indicatorHeight += this._bottomPadding;
114
+
115
+ [subTextGroup, subTextNode] = this._createIndicatorText(subText);
116
+
117
+ subTextGroup.y(indicatorHeight);
118
+ indicator.add(subTextGroup);
119
+ indicatorHeight += subTextGroup.getAttr('trueHeight');
120
+ }
121
+
122
+ if (textGroup) {
123
+ textGroup.on('mouseenter', function() {
124
+ textNode.fill(textNode.getAttr('selectedColor'));
125
+ if (iconNode) {
126
+ iconNode.fill(iconNode.getAttr('selectedColor'));
127
+ }
128
+ self.batchDraw();
129
+ self._stage.container().style.cursor = 'pointer';
104
130
  });
105
131
 
106
- textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
107
- textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
132
+ textGroup.on('mouseout', function() {
133
+ textNode.fill(textNode.getAttr('defaultColor'));
134
+ if (iconNode) {
135
+ iconNode.fill(iconNode.getAttr('defaultColor'));
136
+ }
137
+ self.batchDraw();
138
+ if (!self._isDragging) {
139
+ self._stage.container().style.cursor = 'default';
140
+ }
141
+ });
108
142
 
109
- indicator.add(textNode);
110
- indicatorHeight += this._sizes.font;
143
+ textGroup.on('click', function(e) {
144
+ self._peaks.emit('lineIndicator.text.click', self._indicators[lineGroup.getId()], e.evt);
145
+ });
111
146
  }
112
147
 
148
+ if (iconGroup) {
149
+ iconGroup.on('mouseenter', function() {
150
+ iconNode.fill(iconNode.getAttr('selectedColor'));
151
+ if (textNode) {
152
+ textNode.fill(textNode.getAttr('selectedColor'));
153
+ }
154
+ self.batchDraw();
155
+ self._stage.container().style.cursor = 'pointer';
156
+ });
157
+
158
+ iconGroup.on('mouseout', function() {
159
+ iconNode.fill(iconNode.getAttr('defaultColor'));
160
+ if (textNode) {
161
+ textNode.fill(textNode.getAttr('defaultColor'));
162
+ }
163
+ self.batchDraw();
164
+ if (!self._isDragging) {
165
+ self._stage.container().style.cursor = 'default';
166
+ }
167
+ });
168
+
169
+ iconGroup.on('click', function(e) {
170
+ self._peaks.emit('lineIndicator.icon.click', self._indicators[lineGroup.getId()], e.evt);
171
+ });
172
+
173
+ iconGroup.on('mousedown touchstart', function() {
174
+ self._dragLineId = lineGroup.getId();
175
+ self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
176
+
177
+ window.addEventListener('mousemove', self._onWindowMove, false);
178
+ window.addEventListener('touchmove', self._onWindowMove, false);
179
+ window.addEventListener('mouseup', self._onWindowUp, false);
180
+ window.addEventListener('touchend', self._onWindowUp, false);
181
+ window.addEventListener('blur', self._onWindowUp, false);
182
+ });
183
+ }
184
+
185
+ if (subTextGroup) {
186
+ subTextGroup.on('mouseenter', function() {
187
+ subTextNode.fill(subTextNode.getAttr('selectedColor'));
188
+ self.batchDraw();
189
+ self._stage.container().style.cursor = 'pointer';
190
+ });
191
+
192
+ subTextGroup.on('mouseout', function() {
193
+ subTextNode.fill(subTextNode.getAttr('defaultColor'));
194
+ self.batchDraw();
195
+ if (!self._isDragging) {
196
+ self._stage.container().style.cursor = 'default';
197
+ }
198
+ });
199
+
200
+ subTextGroup.on('click', function(e) {
201
+ self._peaks.emit('lineIndicator.subText.click', self._indicators[lineGroup.getId()], e.evt);
202
+ });
203
+ }
204
+
205
+ indicator.setAttr('trueHeight', indicatorHeight);
206
+ indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
207
+
208
+ return indicator;
209
+ };
210
+
211
+ LineIndicator.prototype._createIndicatorText = function(text) {
212
+ const textGroup = new Konva.Group();
213
+
214
+ const textNode = new Konva.Text({
215
+ text: text,
216
+ fontSize: this._sizes.font,
217
+ fontFamily: this._peaks.options.lineIndicatorFont,
218
+ fill: this._peaks.options.lineIndicatorTextColor,
219
+ align: 'center',
220
+ width: this._width,
221
+ listening: false
222
+ });
223
+
224
+ textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
225
+ textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
226
+
227
+ var textRect = new Konva.Rect({
228
+ x: 0,
229
+ y: 0,
230
+ width: this._width,
231
+ height: this._sizes.font,
232
+ fill: 'transparent',
233
+ listening: true
234
+ });
235
+
236
+ textGroup.add(textNode);
237
+ textGroup.add(textRect);
238
+ textRect.moveToTop();
239
+
240
+ textGroup.setAttr('trueHeight', this._sizes.font);
241
+
242
+ return [textGroup, textNode];
243
+ };
244
+
245
+ LineIndicator.prototype._createIndicatorIcon = function(type) {
113
246
  type = this._types.includes(type) ? type : 'default';
114
247
 
248
+ const iconGroup = new Konva.Group();
249
+
250
+ var iconHeight = this._sizes.icon[type];
115
251
  var iconNode;
116
252
 
117
253
  if (type === 'default') {
118
- var padding = text ? this._defaultPadding : 0;
119
-
120
254
  iconNode = new Konva.Circle({
121
255
  x: this._width / 2,
122
- y: indicatorHeight + this._sizes.icon.default / 2 + padding,
256
+ y: this._sizes.icon.default / 2,
123
257
  radius: this._sizes.icon.default / 2,
124
258
  fill: this._peaks.options.lineIndicatorIconColor,
125
259
  strokeWidth: 0,
126
- lineId: lineGroup.getId(),
127
260
  listening: false
128
261
  });
129
-
130
- indicatorHeight += padding;
131
262
  }
132
263
  else {
133
264
  iconNode = new Konva.Path({
134
265
  x: (this._width - this._sizes.icon[type]) / 2,
135
- y: indicatorHeight,
266
+ y: 0,
136
267
  data: SVGs[type].path,
137
268
  fill: this._peaks.options.lineIndicatorIconColor,
138
269
  scale: {
139
270
  x: (this._sizes.icon[type]) / SVGs[type].width,
140
271
  y: (this._sizes.icon[type]) / SVGs[type].height
141
272
  },
142
- lineId: lineGroup.getId(),
143
273
  listening: false
144
274
  });
145
275
  }
@@ -147,61 +277,22 @@ define([
147
277
  iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
148
278
  iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
149
279
 
150
- indicator.add(iconNode);
151
- indicatorHeight += this._sizes.icon[type];
152
-
153
- indicator.setAttr('trueHeight', indicatorHeight);
154
-
155
- var backgroundRect = new Konva.Rect({
280
+ var iconRect = new Konva.Rect({
156
281
  x: 0,
157
282
  y: 0,
158
283
  width: this._width,
159
- height: indicatorHeight,
284
+ height: iconHeight,
160
285
  fill: 'transparent',
161
286
  listening: true
162
287
  });
163
288
 
164
- indicator.add(backgroundRect);
165
- backgroundRect.moveToTop();
166
-
167
- indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
168
-
169
- var self = this;
170
-
171
- indicator.on('mouseenter', function() {
172
- indicator.getChildren().forEach(function(child) {
173
- child.fill(child.getAttr('selectedColor'));
174
- });
175
- self.batchDraw();
176
- self._stage.container().style.cursor = 'pointer';
177
- });
178
-
179
- indicator.on('mouseout', function() {
180
- indicator.getChildren().forEach(function(child) {
181
- child.fill(child.getAttr('defaultColor'));
182
- });
183
- self.batchDraw();
184
- if (!self._isDragging) {
185
- self._stage.container().style.cursor = 'default';
186
- }
187
- });
188
-
189
- indicator.on('click', function(e) {
190
- self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
191
- });
289
+ iconGroup.add(iconNode);
290
+ iconGroup.add(iconRect);
291
+ iconRect.moveToTop();
192
292
 
193
- indicator.on('mousedown touchstart', function() {
194
- self._dragLineId = lineGroup.getId();
195
- self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
293
+ iconGroup.setAttr('trueHeight', iconHeight);
196
294
 
197
- window.addEventListener('mousemove', self._onWindowMove, false);
198
- window.addEventListener('touchmove', self._onWindowMove, false);
199
- window.addEventListener('mouseup', self._onWindowUp, false);
200
- window.addEventListener('touchend', self._onWindowUp, false);
201
- window.addEventListener('blur', self._onWindowUp, false);
202
- });
203
-
204
- return indicator;
295
+ return [iconGroup, iconNode];
205
296
  };
206
297
 
207
298
  LineIndicator.prototype.addIndicator = function(lineGroup) {
@@ -211,7 +302,8 @@ define([
211
302
  const indicator = this._createIndicator(
212
303
  lineGroup,
213
304
  line.indicatorType,
214
- line.indicatorText
305
+ line.indicatorText,
306
+ line.indicatorSubText
215
307
  );
216
308
 
217
309
  this._layer.add(indicator);
@@ -220,7 +312,8 @@ define([
220
312
  lineGroup: lineGroup,
221
313
  indicator: indicator,
222
314
  type: line.indicatorType,
223
- text: line.indicatorText
315
+ text: line.indicatorText,
316
+ subText: line.indicatorSubText
224
317
  };
225
318
  }
226
319
  };
@@ -242,7 +335,8 @@ define([
242
335
  var indicator = this._createIndicator(
243
336
  indicatorData.lineGroup,
244
337
  line.indicatorType,
245
- line.indicatorText
338
+ line.indicatorText,
339
+ line.indicatorSubText
246
340
  );
247
341
 
248
342
  this._layer.add(indicator);
@@ -250,6 +344,7 @@ define([
250
344
  indicatorData.indicator = indicator;
251
345
  indicatorData.type = line.indicatorType;
252
346
  indicatorData.text = line.indicatorText;
347
+ indicatorData.subText = line.indicatorSubText;
253
348
 
254
349
  this.batchDraw();
255
350
  };
@@ -282,7 +377,8 @@ define([
282
377
  this._indicators[lineId].indicator = this._createIndicator(
283
378
  this._indicators[lineId].lineGroup,
284
379
  this._indicators[lineId].type,
285
- this._indicators[lineId].text
380
+ this._indicators[lineId].text,
381
+ this._indicators[lineId].subText
286
382
  );
287
383
  this._layer.add(this._indicators[lineId].indicator);
288
384
  anyChange = true;
@@ -21,6 +21,8 @@ define([
21
21
  * @param {Number} position Position of the line on the timeline.
22
22
  * @param {String} indicatorType Type of the line indicator.
23
23
  * @param {String} indicatorText Text to display above the line indicator.
24
+ * @param {String} indicatorSubText Text to display below the line indicator.
25
+ * @param {Boolean} locked Whether the line is locked in place.
24
26
  */
25
27
 
26
28
  /**
@@ -69,6 +71,7 @@ define([
69
71
  options.position,
70
72
  options.indicatorType,
71
73
  options.indicatorText,
74
+ options.indicatorSubText,
72
75
  options.locked
73
76
  );
74
77
 
package/src/main.js CHANGED
@@ -316,6 +316,14 @@ define([
316
316
  */
317
317
  lineIndicatorSelectedIconColor: '#ccc',
318
318
 
319
+ /**
320
+ * Line indicators' top and bottom padding, in pixels
321
+ */
322
+ lineIndicatorPadding: {
323
+ top: 0,
324
+ bottom: 3
325
+ },
326
+
319
327
  /**
320
328
  * Border width of a source when selected
321
329
  */
@@ -409,7 +417,13 @@ define([
409
417
  * Default text of the line indicator.
410
418
  * This will be used when a new line is automatically created by a component.
411
419
  */
412
- defaultLineIndicatorText: ''
420
+ defaultLineIndicatorText: '',
421
+
422
+ /**
423
+ * Default sub text of the line indicator.
424
+ * This will be used when a new line is automatically created by a component.
425
+ */
426
+ defaultLineIndicatorSubText: ''
413
427
  };
414
428
 
415
429
  /**
@@ -446,7 +460,7 @@ define([
446
460
  }
447
461
 
448
462
  /*
449
- Setup the fonts
463
+ * Setup the fonts
450
464
  */
451
465
  var fonts = [
452
466
  'https://fonts.gstatic.com/s/opensans/v27/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjZ0B4kaVIGxA.woff2',
@@ -30,6 +30,13 @@ define([
30
30
  throw new TypeError('peaks.lines.' + context + ': indicatorText must be a string');
31
31
  }
32
32
 
33
+ if (Utils.isNullOrUndefined(options.indicatorSubText)) {
34
+ options.indicatorSubText = '';
35
+ }
36
+ else if (!Utils.isString(options.indicatorSubText)) {
37
+ throw new TypeError('peaks.lines.' + context + ': indicatorSubText must be a string');
38
+ }
39
+
33
40
  if (Utils.isNullOrUndefined(options.locked)) {
34
41
  options.locked = false;
35
42
  }
@@ -51,22 +58,24 @@ define([
51
58
  * @param {String} indicatorText Text to display above the line indicator.
52
59
  */
53
60
 
54
- function Line(peaks, id, position, indicatorType, indicatorText, locked) {
61
+ function Line(peaks, id, position, indicatorType, indicatorText, indicatorSubText, locked) {
55
62
  var opts = {
56
- position: position,
57
- indicatorType: indicatorType,
58
- indicatorText: indicatorText,
59
- locked: locked
63
+ position: position,
64
+ indicatorType: indicatorType,
65
+ indicatorText: indicatorText,
66
+ indicatorSubText: indicatorSubText,
67
+ locked: locked
60
68
  };
61
69
 
62
70
  validateLine(opts, 'add()');
63
71
 
64
- this._peaks = peaks;
65
- this._id = id;
66
- this._position = opts.position;
67
- this._indicatorType = opts.indicatorType;
68
- this._indicatorText = opts.indicatorText;
69
- this._locked = opts.locked;
72
+ this._peaks = peaks;
73
+ this._id = id;
74
+ this._position = opts.position;
75
+ this._indicatorType = opts.indicatorType;
76
+ this._indicatorText = opts.indicatorText;
77
+ this._indicatorSubText = opts.indicatorSubText;
78
+ this._locked = opts.locked;
70
79
  }
71
80
 
72
81
  Object.defineProperties(Line.prototype, {
@@ -98,6 +107,12 @@ define([
98
107
  return this._indicatorText;
99
108
  }
100
109
  },
110
+ indicatorSubText: {
111
+ enumerable: true,
112
+ get: function() {
113
+ return this._indicatorSubText;
114
+ }
115
+ },
101
116
  locked: {
102
117
  enumerable: true,
103
118
  get: function() {
@@ -108,20 +123,22 @@ define([
108
123
 
109
124
  Line.prototype.update = function(options) {
110
125
  var opts = {
111
- position: this.position,
112
- indicatorType: this.indicatorType,
113
- indicatorText: this.indicatorText,
114
- locked: this.locked
126
+ position: this.position,
127
+ indicatorType: this.indicatorType,
128
+ indicatorText: this.indicatorText,
129
+ indicatorSubText: this.indicatorSubText,
130
+ locked: this.locked
115
131
  };
116
132
 
117
133
  Utils.extend(opts, options);
118
134
 
119
135
  validateLine(opts, 'update()');
120
136
 
121
- this._position = opts.position;
122
- this._indicatorType = opts.indicatorType;
123
- this._indicatorText = opts.indicatorText;
124
- this._locked = opts.locked;
137
+ this._position = opts.position;
138
+ this._indicatorType = opts.indicatorType;
139
+ this._indicatorText = opts.indicatorText;
140
+ this._indicatorSubText = opts.indicatorSubText;
141
+ this._locked = opts.locked;
125
142
 
126
143
  this._peaks.emit('model.line.update', this);
127
144
  };