@checksub_team/peaks_timeline 1.4.34 → 1.4.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/segment.js CHANGED
@@ -1,263 +1,263 @@
1
- /**
2
- * @file
3
- *
4
- * Defines the {@link Segment} class.
5
- *
6
- * @module segment
7
- */
8
-
9
- define([
10
- './utils'
11
- ], function(Utils) {
12
- 'use strict';
13
-
14
- function validateSegment(peaks, options, context) {
15
- if (!Utils.isValidTime(options.startTime)) {
16
- // eslint-disable-next-line max-len
17
- throw new TypeError('peaks.segments.' + context + ': startTime should be a valid number');
18
- }
19
-
20
- if (!Utils.isValidTime(options.endTime)) {
21
- // eslint-disable-next-line max-len
22
- throw new TypeError('peaks.segments.' + context + ': endTime should be a valid number');
23
- }
24
-
25
- options.startTime = Utils.roundTime(options.startTime);
26
- options.endTime = Utils.roundTime(options.endTime);
27
- if (options.startTime < 0) {
28
- options.startTime = 0;
29
- }
30
-
31
- if (options.endTime < 0) {
32
- options.endTime = 0;
33
- }
34
- else if (options.endTime - options.startTime < peaks.options.minSegmentSize) {
35
- options.endTime = options.startTime + peaks.options.minSegmentSize;
36
- }
37
-
38
- options.startTime = Utils.roundTime(options.startTime);
39
- options.endTime = Utils.roundTime(options.endTime);
40
-
41
- if (options.opacity < 0 || options.opacity > 1) {
42
- // eslint-disable-next-line max-len
43
- throw new RangeError('peaks.segments.' + context + ': opacity should be between 0 and 1');
44
- }
45
-
46
- if (Utils.isNullOrUndefined(options.labelText)) {
47
- // Set default label text
48
- options.labelText = '';
49
- }
50
- else if (!Utils.isString(options.labelText)) {
51
- throw new TypeError('peaks.segments.' + context + ': labelText must be a string');
52
- }
53
-
54
- if (!Utils.isInteger(options.line)) {
55
- throw new TypeError('peaks.segments.' + context + ': line must be an integer');
56
- }
57
-
58
- if (Utils.isNullOrUndefined(options.editable)) {
59
- options.editable = true;
60
- }
61
- else if (!Utils.isBoolean(options.editable)) {
62
- throw new TypeError('peaks.segments.' + context + ': editable must be a boolean');
63
- }
64
-
65
- if (Utils.isNullOrUndefined(options.hoverColor)) {
66
- options.hoverColor = Utils.shadeColor(options.color, 20);
67
- }
68
- else if (!Utils.isValidColor(options.hoverColor)) {
69
- throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
70
- }
71
- }
72
-
73
- /**
74
- * A segment is a region of time, with associated label and color.
75
- *
76
- * @class
77
- * @alias Segment
78
- *
79
- * @param {Peaks} peaks A reference to the Peaks instance.
80
- * @param {String} id A unique identifier for the segment.
81
- * @param {Number} startTime Segment start time, in seconds.
82
- * @param {Number} endTime Segment end time, in seconds.
83
- * @param {String} labelText Segment label text.
84
- * @param {String} color Segment waveform color.
85
- * @param {Number} opacity Segment waveform opacity.
86
- * @param {Boolean} editable If <code>true</code> the segment start and
87
- * end times can be adjusted via the user interface.
88
- */
89
-
90
- function Segment(peaks, id, startTime, endTime, labelText, color,
91
- textColor, handleTextColor, hoverColor, opacity, editable,
92
- allowDeletion, line) {
93
- var opts = {
94
- startTime: startTime,
95
- endTime: endTime,
96
- labelText: labelText,
97
- color: color,
98
- textColor: textColor,
99
- handleTextColor: handleTextColor,
100
- hoverColor: hoverColor,
101
- opacity: opacity,
102
- editable: editable,
103
- allowDeletion: allowDeletion,
104
- line: line
105
- };
106
-
107
- validateSegment(peaks, opts, 'add()');
108
-
109
- this._peaks = peaks;
110
- this._id = id;
111
- this._startTime = opts.startTime;
112
- this._endTime = opts.endTime;
113
- this._labelText = opts.labelText;
114
- this._color = opts.color;
115
- this._hoverColor = opts.hoverColor;
116
- this._textColor = opts.textColor;
117
- this._handleTextColor = opts.handleTextColor;
118
- this._opacity = opts.opacity;
119
- this._editable = opts.editable;
120
- this._allowDeletion = opts.allowDeletion;
121
- this._line = opts.line;
122
- this._minSize = peaks.options.minSegmentSize;
123
- }
124
-
125
- Object.defineProperties(Segment.prototype, {
126
- id: {
127
- enumerable: true,
128
- get: function() {
129
- return this._id;
130
- }
131
- },
132
- startTime: {
133
- enumerable: true,
134
- get: function() {
135
- return this._startTime;
136
- },
137
-
138
- set: function(time) {
139
- this._startTime = Utils.roundTime(time);
140
- }
141
- },
142
- endTime: {
143
- enumerable: true,
144
- get: function() {
145
- return this._endTime;
146
- },
147
-
148
- set: function(time) {
149
- this._endTime = Utils.roundTime(time);
150
- }
151
- },
152
- labelText: {
153
- enumerable: true,
154
- get: function() {
155
- return this._labelText;
156
- }
157
- },
158
- color: {
159
- enumerable: true,
160
- get: function() {
161
- return this._color;
162
- }
163
- },
164
- hoverColor: {
165
- enumerable: true,
166
- get: function() {
167
- return this._hoverColor;
168
- }
169
- },
170
- textColor: {
171
- enumerable: true,
172
- get: function() {
173
- return this._textColor;
174
- }
175
- },
176
- handleTextColor: {
177
- enumerable: true,
178
- get: function() {
179
- return this._handleTextColor;
180
- }
181
- },
182
- opacity: {
183
- enumerable: true,
184
- get: function() {
185
- return this._opacity;
186
- }
187
- },
188
- editable: {
189
- enumerable: true,
190
- get: function() {
191
- return this._editable;
192
- }
193
- },
194
- allowDeletion: {
195
- enumerable: true,
196
- get: function() {
197
- return this._allowDeletion;
198
- }
199
- },
200
- line: {
201
- enumerable: true,
202
- get: function() {
203
- return this._line;
204
- }
205
- },
206
- minSize: {
207
- enumerable: true,
208
- get: function() {
209
- return this._minSize;
210
- }
211
- }
212
- });
213
-
214
- Segment.prototype.update = function(options) {
215
- var opts = {
216
- startTime: this.startTime,
217
- endTime: this.endTime,
218
- labelText: this.labelText,
219
- color: this.color,
220
- textColor: this.textColor,
221
- handleTextColor: this.handleTextColor,
222
- hoverColor: this.hoverColor,
223
- opacity: this.opacity,
224
- editable: this.editable,
225
- allowDeletion: this.allowDeletion,
226
- line: this.line
227
- };
228
-
229
- Utils.extend(opts, options);
230
-
231
- validateSegment(this._peaks, opts, 'update()');
232
-
233
- this._startTime = opts.startTime;
234
- this._endTime = opts.endTime;
235
- this._labelText = opts.labelText;
236
- this._color = opts.color;
237
- this._textColor = opts.textColor;
238
- this._handleTextColor = opts.handleTextColor;
239
- this._hoverColor = opts.hoverColor;
240
- this._opacity = opts.opacity;
241
- this._editable = opts.editable;
242
- this._allowDeletion = opts.allowDeletion;
243
- this._line = opts.line;
244
-
245
- this._peaks.emit('segment.updated', this);
246
- };
247
-
248
- /**
249
- * Returns <code>true</code> if the segment overlaps a given time region.
250
- *
251
- * @param {Number} startTime The start of the time region, in seconds.
252
- * @param {Number} endTime The end of the time region, in seconds.
253
- * @returns {Boolean}
254
- *
255
- * @see http://wiki.c2.com/?TestIfDateRangesOverlap
256
- */
257
-
258
- Segment.prototype.isVisible = function(startTime, endTime) {
259
- return this.startTime < endTime && startTime < this.endTime;
260
- };
261
-
262
- return Segment;
263
- });
1
+ /**
2
+ * @file
3
+ *
4
+ * Defines the {@link Segment} class.
5
+ *
6
+ * @module segment
7
+ */
8
+
9
+ define([
10
+ './utils'
11
+ ], function(Utils) {
12
+ 'use strict';
13
+
14
+ function validateSegment(peaks, options, context) {
15
+ if (!Utils.isValidTime(options.startTime)) {
16
+ // eslint-disable-next-line max-len
17
+ throw new TypeError('peaks.segments.' + context + ': startTime should be a valid number');
18
+ }
19
+
20
+ if (!Utils.isValidTime(options.endTime)) {
21
+ // eslint-disable-next-line max-len
22
+ throw new TypeError('peaks.segments.' + context + ': endTime should be a valid number');
23
+ }
24
+
25
+ options.startTime = Utils.roundTime(options.startTime);
26
+ options.endTime = Utils.roundTime(options.endTime);
27
+ if (options.startTime < 0) {
28
+ options.startTime = 0;
29
+ }
30
+
31
+ if (options.endTime < 0) {
32
+ options.endTime = 0;
33
+ }
34
+ else if (options.endTime - options.startTime < peaks.options.minSegmentSize) {
35
+ options.endTime = options.startTime + peaks.options.minSegmentSize;
36
+ }
37
+
38
+ options.startTime = Utils.roundTime(options.startTime);
39
+ options.endTime = Utils.roundTime(options.endTime);
40
+
41
+ if (options.opacity < 0 || options.opacity > 1) {
42
+ // eslint-disable-next-line max-len
43
+ throw new RangeError('peaks.segments.' + context + ': opacity should be between 0 and 1');
44
+ }
45
+
46
+ if (Utils.isNullOrUndefined(options.labelText)) {
47
+ // Set default label text
48
+ options.labelText = '';
49
+ }
50
+ else if (!Utils.isString(options.labelText)) {
51
+ throw new TypeError('peaks.segments.' + context + ': labelText must be a string');
52
+ }
53
+
54
+ if (!Utils.isInteger(options.line)) {
55
+ throw new TypeError('peaks.segments.' + context + ': line must be an integer');
56
+ }
57
+
58
+ if (Utils.isNullOrUndefined(options.editable)) {
59
+ options.editable = true;
60
+ }
61
+ else if (!Utils.isBoolean(options.editable)) {
62
+ throw new TypeError('peaks.segments.' + context + ': editable must be a boolean');
63
+ }
64
+
65
+ if (Utils.isNullOrUndefined(options.hoverColor)) {
66
+ options.hoverColor = Utils.shadeColor(options.color, 20);
67
+ }
68
+ else if (!Utils.isValidColor(options.hoverColor)) {
69
+ throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
70
+ }
71
+ }
72
+
73
+ /**
74
+ * A segment is a region of time, with associated label and color.
75
+ *
76
+ * @class
77
+ * @alias Segment
78
+ *
79
+ * @param {Peaks} peaks A reference to the Peaks instance.
80
+ * @param {String} id A unique identifier for the segment.
81
+ * @param {Number} startTime Segment start time, in seconds.
82
+ * @param {Number} endTime Segment end time, in seconds.
83
+ * @param {String} labelText Segment label text.
84
+ * @param {String} color Segment waveform color.
85
+ * @param {Number} opacity Segment waveform opacity.
86
+ * @param {Boolean} editable If <code>true</code> the segment start and
87
+ * end times can be adjusted via the user interface.
88
+ */
89
+
90
+ function Segment(peaks, id, startTime, endTime, labelText, color,
91
+ textColor, handleTextColor, hoverColor, opacity, editable,
92
+ allowDeletion, line) {
93
+ var opts = {
94
+ startTime: startTime,
95
+ endTime: endTime,
96
+ labelText: labelText,
97
+ color: color,
98
+ textColor: textColor,
99
+ handleTextColor: handleTextColor,
100
+ hoverColor: hoverColor,
101
+ opacity: opacity,
102
+ editable: editable,
103
+ allowDeletion: allowDeletion,
104
+ line: line
105
+ };
106
+
107
+ validateSegment(peaks, opts, 'add()');
108
+
109
+ this._peaks = peaks;
110
+ this._id = id;
111
+ this._startTime = opts.startTime;
112
+ this._endTime = opts.endTime;
113
+ this._labelText = opts.labelText;
114
+ this._color = opts.color;
115
+ this._hoverColor = opts.hoverColor;
116
+ this._textColor = opts.textColor;
117
+ this._handleTextColor = opts.handleTextColor;
118
+ this._opacity = opts.opacity;
119
+ this._editable = opts.editable;
120
+ this._allowDeletion = opts.allowDeletion;
121
+ this._line = opts.line;
122
+ this._minSize = peaks.options.minSegmentSize;
123
+ }
124
+
125
+ Object.defineProperties(Segment.prototype, {
126
+ id: {
127
+ enumerable: true,
128
+ get: function() {
129
+ return this._id;
130
+ }
131
+ },
132
+ startTime: {
133
+ enumerable: true,
134
+ get: function() {
135
+ return this._startTime;
136
+ },
137
+
138
+ set: function(time) {
139
+ this._startTime = Utils.roundTime(time);
140
+ }
141
+ },
142
+ endTime: {
143
+ enumerable: true,
144
+ get: function() {
145
+ return this._endTime;
146
+ },
147
+
148
+ set: function(time) {
149
+ this._endTime = Utils.roundTime(time);
150
+ }
151
+ },
152
+ labelText: {
153
+ enumerable: true,
154
+ get: function() {
155
+ return this._labelText;
156
+ }
157
+ },
158
+ color: {
159
+ enumerable: true,
160
+ get: function() {
161
+ return this._color;
162
+ }
163
+ },
164
+ hoverColor: {
165
+ enumerable: true,
166
+ get: function() {
167
+ return this._hoverColor;
168
+ }
169
+ },
170
+ textColor: {
171
+ enumerable: true,
172
+ get: function() {
173
+ return this._textColor;
174
+ }
175
+ },
176
+ handleTextColor: {
177
+ enumerable: true,
178
+ get: function() {
179
+ return this._handleTextColor;
180
+ }
181
+ },
182
+ opacity: {
183
+ enumerable: true,
184
+ get: function() {
185
+ return this._opacity;
186
+ }
187
+ },
188
+ editable: {
189
+ enumerable: true,
190
+ get: function() {
191
+ return this._editable;
192
+ }
193
+ },
194
+ allowDeletion: {
195
+ enumerable: true,
196
+ get: function() {
197
+ return this._allowDeletion;
198
+ }
199
+ },
200
+ line: {
201
+ enumerable: true,
202
+ get: function() {
203
+ return this._line;
204
+ }
205
+ },
206
+ minSize: {
207
+ enumerable: true,
208
+ get: function() {
209
+ return this._minSize;
210
+ }
211
+ }
212
+ });
213
+
214
+ Segment.prototype.update = function(options) {
215
+ var opts = {
216
+ startTime: this.startTime,
217
+ endTime: this.endTime,
218
+ labelText: this.labelText,
219
+ color: this.color,
220
+ textColor: this.textColor,
221
+ handleTextColor: this.handleTextColor,
222
+ hoverColor: this.hoverColor,
223
+ opacity: this.opacity,
224
+ editable: this.editable,
225
+ allowDeletion: this.allowDeletion,
226
+ line: this.line
227
+ };
228
+
229
+ Utils.extend(opts, options);
230
+
231
+ validateSegment(this._peaks, opts, 'update()');
232
+
233
+ this._startTime = opts.startTime;
234
+ this._endTime = opts.endTime;
235
+ this._labelText = opts.labelText;
236
+ this._color = opts.color;
237
+ this._textColor = opts.textColor;
238
+ this._handleTextColor = opts.handleTextColor;
239
+ this._hoverColor = opts.hoverColor;
240
+ this._opacity = opts.opacity;
241
+ this._editable = opts.editable;
242
+ this._allowDeletion = opts.allowDeletion;
243
+ this._line = opts.line;
244
+
245
+ this._peaks.emit('segment.updated', this);
246
+ };
247
+
248
+ /**
249
+ * Returns <code>true</code> if the segment overlaps a given time region.
250
+ *
251
+ * @param {Number} startTime The start of the time region, in seconds.
252
+ * @param {Number} endTime The end of the time region, in seconds.
253
+ * @returns {Boolean}
254
+ *
255
+ * @see http://wiki.c2.com/?TestIfDateRangesOverlap
256
+ */
257
+
258
+ Segment.prototype.isVisible = function(startTime, endTime) {
259
+ return this.startTime < endTime && startTime < this.endTime;
260
+ };
261
+
262
+ return Segment;
263
+ });