@checksub_team/peaks_timeline 1.5.0 → 1.5.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": "1.5.0",
3
+ "version": "1.5.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
@@ -15587,7 +15587,7 @@ module.exports = function (DefaultSegmentMarker, Utils, Konva) {
15587
15587
  y: options.y,
15588
15588
  width: options.width,
15589
15589
  height: options.height,
15590
- text: Utils.removeLineBreaks(options.segment.labelText),
15590
+ text: '#' + options.segment.relativeId + ' ' + Utils.removeLineBreaks(options.segment.labelText),
15591
15591
  textAlign: 'left',
15592
15592
  verticalAlign: 'middle',
15593
15593
  wrap: 'none',
@@ -16681,6 +16681,7 @@ module.exports = function (Utils) {
16681
16681
  this._line = opts.line;
16682
16682
  this._indicators = opts.indicators;
16683
16683
  this._minSize = peaks.options.minSegmentSize;
16684
+ this._relativeId = 0;
16684
16685
  if (shouldNotifyUpdate) {
16685
16686
  peaks.emit('segments.updated', [this]);
16686
16687
  }
@@ -16775,6 +16776,15 @@ module.exports = function (Utils) {
16775
16776
  get: function () {
16776
16777
  return this._minSize;
16777
16778
  }
16779
+ },
16780
+ relativeId: {
16781
+ enumerable: true,
16782
+ get: function () {
16783
+ return this._relativeId;
16784
+ },
16785
+ set: function (newId) {
16786
+ this._relativeId = newId;
16787
+ }
16778
16788
  }
16779
16789
  });
16780
16790
  Segment.prototype.update = function (options) {
@@ -19181,8 +19191,18 @@ module.exports = function (Colors, Segment, Utils) {
19181
19191
  segments.forEach(function (segment) {
19182
19192
  self._addSegment(segment);
19183
19193
  });
19194
+ this.refreshRelativeIds();
19184
19195
  this._peaks.emit('segments.add', segments);
19185
19196
  };
19197
+ TimelineSegments.prototype.refreshRelativeIds = function () {
19198
+ var idsByPosition = {};
19199
+ this._segments.sort(function (a, b) {
19200
+ return a.startTime - b.startTime;
19201
+ }).forEach(function (segment) {
19202
+ segment.relativeId = (idsByPosition[segment.line] || 0) + 1;
19203
+ idsByPosition[segment.line] = segment.relativeId;
19204
+ });
19205
+ };
19186
19206
  TimelineSegments.prototype._findSegment = function (predicate) {
19187
19207
  var indexes = [];
19188
19208
  for (var i = 0, length = this._segments.length; i < length; i++) {
@@ -19205,6 +19225,7 @@ module.exports = function (Colors, Segment, Utils) {
19205
19225
  TimelineSegments.prototype._removeSegments = function (predicate) {
19206
19226
  var indexes = this._findSegment(predicate);
19207
19227
  var removed = this._removeIndexes(indexes);
19228
+ this.refreshRelativeIds();
19208
19229
  this._peaks.emit('segments.remove', removed);
19209
19230
  return removed;
19210
19231
  };
@@ -71,7 +71,10 @@ define([
71
71
  y: options.y,
72
72
  width: options.width,
73
73
  height: options.height,
74
- text: Utils.removeLineBreaks(options.segment.labelText),
74
+ text: '#'
75
+ + options.segment.relativeId
76
+ + ' '
77
+ + Utils.removeLineBreaks(options.segment.labelText),
75
78
  textAlign: 'left',
76
79
  verticalAlign: 'middle',
77
80
  wrap: 'none',
package/src/segment.js CHANGED
@@ -131,6 +131,7 @@ define([
131
131
  this._line = opts.line;
132
132
  this._indicators = opts.indicators;
133
133
  this._minSize = peaks.options.minSegmentSize;
134
+ this._relativeId = 0;
134
135
 
135
136
  if (shouldNotifyUpdate) {
136
137
  peaks.emit('segments.updated', [this]);
@@ -229,6 +230,15 @@ define([
229
230
  get: function() {
230
231
  return this._minSize;
231
232
  }
233
+ },
234
+ relativeId: {
235
+ enumerable: true,
236
+ get: function() {
237
+ return this._relativeId;
238
+ },
239
+ set: function(newId) {
240
+ this._relativeId = newId;
241
+ }
232
242
  }
233
243
  });
234
244
 
@@ -251,9 +251,28 @@ define([
251
251
  self._addSegment(segment);
252
252
  });
253
253
 
254
+ this.refreshRelativeIds();
255
+
254
256
  this._peaks.emit('segments.add', segments);
255
257
  };
256
258
 
259
+ /**
260
+ * Set relative ids for all segments.
261
+ *
262
+ * @private
263
+ */
264
+
265
+ TimelineSegments.prototype.refreshRelativeIds = function() {
266
+ var idsByPosition = {};
267
+
268
+ this._segments.sort(function(a, b) {
269
+ return a.startTime - b.startTime;
270
+ }).forEach(function(segment) {
271
+ segment.relativeId = (idsByPosition[segment.line] || 0) + 1;
272
+ idsByPosition[segment.line] = segment.relativeId;
273
+ });
274
+ };
275
+
257
276
  /**
258
277
  * Returns the indexes of segments that match the given predicate.
259
278
  *
@@ -317,6 +336,8 @@ define([
317
336
 
318
337
  var removed = this._removeIndexes(indexes);
319
338
 
339
+ this.refreshRelativeIds();
340
+
320
341
  this._peaks.emit('segments.remove', removed);
321
342
 
322
343
  return removed;