@checksub_team/peaks_timeline 1.16.1 → 2.0.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 +4716 -4409
- package/peaks.js.d.ts +5 -5
- package/src/{timeline-axis.js → components/axis.js} +244 -244
- package/src/{data-retriever.js → components/data-retriever.js} +117 -117
- package/src/{default-segment-marker.js → components/default-segment-marker.js} +132 -132
- package/src/{invoker.js → components/invoker.js} +81 -81
- package/src/components/line-group.js +692 -0
- package/src/components/line-groups.js +585 -0
- package/src/{line-indicator.js → components/line-indicator.js} +308 -303
- package/src/{marker-factories.js → components/marker-factories.js} +1 -1
- package/src/{mode-layer.js → components/mode-layer.js} +8 -12
- package/src/{playhead-layer.js → components/playhead-layer.js} +3 -3
- package/src/{segment-marker.js → components/segment-marker.js} +2 -2
- package/src/{segment-shape.js → components/segment-shape.js} +508 -508
- package/src/{segments-group.js → components/segments-group.js} +805 -801
- package/src/{source-group.js → components/source-group.js} +1661 -1640
- package/src/{sources-layer.js → components/sources-layer.js} +716 -730
- package/src/{waveform-builder.js → components/waveform-builder.js} +2 -2
- package/src/{waveform-shape.js → components/waveform-shape.js} +214 -214
- package/src/keyboard-handler.js +9 -9
- package/src/line-handler.js +179 -0
- package/src/main.js +110 -71
- package/src/models/line.js +156 -0
- package/src/{segment.js → models/segment.js} +420 -419
- package/src/{source.js → models/source.js} +1311 -1315
- package/src/player.js +2 -2
- package/src/{timeline-segments.js → segment-handler.js} +435 -435
- package/src/{timeline-sources.js → source-handler.js} +521 -514
- package/src/utils.js +5 -1
- package/src/{timeline-zoomview.js → view.js} +136 -137
- package/src/line.js +0 -690
- package/src/lines.js +0 -427
- /package/src/{data.js → components/data.js} +0 -0
- /package/src/{loader.js → components/loader.js} +0 -0
- /package/src/{mouse-drag-handler.js → components/mouse-drag-handler.js} +0 -0
- /package/src/{svgs.js → components/svgs.js} +0 -0
package/peaks.js.d.ts
CHANGED
|
@@ -232,20 +232,20 @@ declare module 'peaks.js' {
|
|
|
232
232
|
'points.remove_all': () => void;
|
|
233
233
|
'points.remove': (points: Point[]) => void;
|
|
234
234
|
'points.enter': (point: Point) => void;
|
|
235
|
-
'segments.add': (segments: Segment[]) => void;
|
|
235
|
+
'handler.segments.add': (segments: Segment[]) => void;
|
|
236
236
|
'segments.dragstart': (segment: Segment, startMarker: boolean) => void;
|
|
237
237
|
'segments.dragged': (segment: Segment, startMarker: boolean) => void;
|
|
238
238
|
'segments.dragend': (segment: Segment, startMarker: boolean) => void;
|
|
239
|
-
'segments.remove_all': () => void;
|
|
240
|
-
'segments.remove': (segments: Segment[]) => void;
|
|
239
|
+
'handler.segments.remove_all': () => void;
|
|
240
|
+
'handler.segments.remove': (segments: Segment[]) => void;
|
|
241
241
|
'segments.mouseenter': (segment: Segment) => void;
|
|
242
242
|
'segments.mouseleave': (segment: Segment) => void;
|
|
243
243
|
'segments.click': (segment: Segment) => void;
|
|
244
244
|
'segments.enter': (segment: Segment) => void;
|
|
245
245
|
'segments.exit': (segment: Segment) => void;
|
|
246
246
|
'overview.dblclick': (time: number) => void;
|
|
247
|
-
'
|
|
248
|
-
'
|
|
247
|
+
'handler.view.dblclick': (time: number) => void;
|
|
248
|
+
'handler.view.updatezoom': (currentZoomLevel: number, previousZoomLevel: number) => void;
|
|
249
249
|
player_seek: (time: number) => void;
|
|
250
250
|
user_seek: (time: number) => void;
|
|
251
251
|
}
|
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Defines the {@link
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
define([
|
|
10
|
-
'
|
|
11
|
-
'konva'
|
|
12
|
-
], function(Utils, Konva) {
|
|
13
|
-
'use strict';
|
|
14
|
-
|
|
15
|
-
var LEFT_PADDING = 4;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates the timeline axis shapes and adds them to the given view layer.
|
|
19
|
-
*
|
|
20
|
-
* @class
|
|
21
|
-
* @alias
|
|
22
|
-
*
|
|
23
|
-
* @param {WaveformOverview|
|
|
24
|
-
* @param {Object} options
|
|
25
|
-
* @param {String} options.axisGridlineColor
|
|
26
|
-
* @param {String} options.axisLabelColor
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
function
|
|
30
|
-
this._view = view;
|
|
31
|
-
|
|
32
|
-
var self = this;
|
|
33
|
-
|
|
34
|
-
peaks.on('playhead.moved', this._onPlayheadMoved.bind(this));
|
|
35
|
-
peaks.on('playhead.hidden', this._onPlayheadHidden.bind(this));
|
|
36
|
-
|
|
37
|
-
self._axisGridlineColor = options.axisGridlineColor;
|
|
38
|
-
self._axisLabelColor = options.axisLabelColor;
|
|
39
|
-
|
|
40
|
-
self._backLayer = new Konva.Layer({
|
|
41
|
-
listening: false
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
self._frontLayer = new Konva.Layer({
|
|
45
|
-
listening: false
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
self._axisShape = new Konva.Shape({
|
|
49
|
-
sceneFunc: function(context) {
|
|
50
|
-
self.drawAxis(context, view);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
self._backLayer.add(self._axisShape);
|
|
54
|
-
|
|
55
|
-
self._timesShape = new Konva.Shape({
|
|
56
|
-
sceneFunc: function(context) {
|
|
57
|
-
self.drawTimes(context, view);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
self._frontLayer.add(self._timesShape);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this._maskStart = playheadX + this._view.getFrameOffset();
|
|
65
|
-
this._maskEnd = playheadX + this._view.getFrameOffset() + playheadWidth;
|
|
66
|
-
this._frontLayer.draw();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this._maskStart = null;
|
|
71
|
-
this._maskEnd = null;
|
|
72
|
-
this._frontLayer.draw();
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this._backLayer.draw();
|
|
77
|
-
this._frontLayer.draw();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
stage.add(this._backLayer);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
stage.add(this._frontLayer);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns number of seconds for each x-axis marker, appropriate for the
|
|
90
|
-
* current zoom level, ensuring that markers are not too close together
|
|
91
|
-
* and that markers are placed at intuitive time intervals (i.e., every 1,
|
|
92
|
-
* 2, 5, 10, 20, 30 seconds, then every 1, 2, 5, 10, 20, 30 minutes, then
|
|
93
|
-
* every 1, 2, 5, 10, 20, 30 hours).
|
|
94
|
-
*
|
|
95
|
-
* @param {WaveformOverview|WaveformZoomView} view
|
|
96
|
-
* @returns {Number}
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var baseSecs = 1; // seconds
|
|
101
|
-
var steps = [0.1, 0.5, 1, 2, 5, 10, 20, 30];
|
|
102
|
-
var minSpacing = 60;
|
|
103
|
-
var index = 0;
|
|
104
|
-
|
|
105
|
-
var secs;
|
|
106
|
-
|
|
107
|
-
for (;;) {
|
|
108
|
-
secs = baseSecs * steps[index];
|
|
109
|
-
var pixels = view.timeToPixels(secs);
|
|
110
|
-
|
|
111
|
-
if (pixels < minSpacing) {
|
|
112
|
-
if (++index === steps.length) {
|
|
113
|
-
baseSecs *= 60; // seconds -> minutes -> hours
|
|
114
|
-
index = 0;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return secs;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Draws the time axis and labels onto a view.
|
|
127
|
-
*
|
|
128
|
-
* @param {Konva.Context} context The context to draw on.
|
|
129
|
-
* @param {WaveformOverview|WaveformZoomView} view
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var currentFrameStartTime = view.pixelsToTime(view.getFrameOffset());
|
|
134
|
-
|
|
135
|
-
// Time interval between axis markers (seconds)
|
|
136
|
-
var axisLabelIntervalSecs = this.getAxisLabelScale(view);
|
|
137
|
-
|
|
138
|
-
// Time of first axis marker (seconds)
|
|
139
|
-
var firstAxisLabelSecs = Utils.roundUpToNearest(currentFrameStartTime, axisLabelIntervalSecs);
|
|
140
|
-
|
|
141
|
-
// Distance between waveform start time and first axis marker (seconds)
|
|
142
|
-
var axisLabelOffsetSecs = firstAxisLabelSecs - currentFrameStartTime;
|
|
143
|
-
|
|
144
|
-
// Distance between waveform start time and first axis marker (pixels)
|
|
145
|
-
var axisLabelOffsetPixels = view.timeToPixels(axisLabelOffsetSecs);
|
|
146
|
-
|
|
147
|
-
context.setAttr('strokeStyle', this._axisGridlineColor);
|
|
148
|
-
context.setAttr('lineWidth', 1);
|
|
149
|
-
|
|
150
|
-
// Set text style
|
|
151
|
-
context.setAttr('font', '11px sans-serif');
|
|
152
|
-
context.setAttr('fillStyle', this._axisLabelColor);
|
|
153
|
-
context.setAttr('textAlign', 'left');
|
|
154
|
-
context.setAttr('textBaseline', 'bottom');
|
|
155
|
-
|
|
156
|
-
var secs = firstAxisLabelSecs;
|
|
157
|
-
var x;
|
|
158
|
-
|
|
159
|
-
var width = view.getWidth();
|
|
160
|
-
var height = view.getHeight();
|
|
161
|
-
|
|
162
|
-
for (;;) {
|
|
163
|
-
// Position of axis marker (pixels)
|
|
164
|
-
x = axisLabelOffsetPixels + view.timeToPixels(secs - firstAxisLabelSecs);
|
|
165
|
-
if (x >= width) {
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
context.beginPath();
|
|
170
|
-
context.moveTo(x + 0.5, 0);
|
|
171
|
-
context.lineTo(x + 0.5, height);
|
|
172
|
-
context.stroke();
|
|
173
|
-
|
|
174
|
-
secs += axisLabelIntervalSecs;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var currentFrameStartTime = view.pixelsToTime(view.getFrameOffset());
|
|
180
|
-
|
|
181
|
-
// Time interval between axis markers (seconds)
|
|
182
|
-
var axisLabelIntervalSecs = this.getAxisLabelScale(view);
|
|
183
|
-
|
|
184
|
-
// Time of first axis marker (seconds)
|
|
185
|
-
var firstAxisLabelSecs = Utils.roundUpToNearestPositive(
|
|
186
|
-
currentFrameStartTime - 1,
|
|
187
|
-
axisLabelIntervalSecs
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
// Distance between waveform start time and first axis marker (seconds)
|
|
191
|
-
var axisLabelOffsetSecs = firstAxisLabelSecs - currentFrameStartTime;
|
|
192
|
-
|
|
193
|
-
// Distance between waveform start time and first axis marker (pixels)
|
|
194
|
-
var axisLabelOffsetPixels = view.timeToPixels(axisLabelOffsetSecs);
|
|
195
|
-
|
|
196
|
-
// Set text style
|
|
197
|
-
context.setAttr('font', '11px sans-serif');
|
|
198
|
-
context.setAttr('fillStyle', this._axisLabelColor);
|
|
199
|
-
context.setAttr('textAlign', 'left');
|
|
200
|
-
context.setAttr('textBaseline', 'bottom');
|
|
201
|
-
|
|
202
|
-
var secs = firstAxisLabelSecs;
|
|
203
|
-
var x;
|
|
204
|
-
|
|
205
|
-
var width = view.getWidth();
|
|
206
|
-
|
|
207
|
-
for (;;) {
|
|
208
|
-
// Position of axis marker (pixels)
|
|
209
|
-
x = axisLabelOffsetPixels + view.timeToPixels(secs - firstAxisLabelSecs);
|
|
210
|
-
|
|
211
|
-
if (x >= width) {
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
var label = Utils.formatTime(secs, false);
|
|
216
|
-
var measures = context.measureText(label);
|
|
217
|
-
var labelHeight = measures.actualBoundingBoxAscent
|
|
218
|
-
- measures.actualBoundingBoxDescent;
|
|
219
|
-
var labelWidth = measures.width;
|
|
220
|
-
var labelX = x + LEFT_PADDING;
|
|
221
|
-
var labelY = labelHeight;
|
|
222
|
-
|
|
223
|
-
if (!this._labelIsMasked(
|
|
224
|
-
labelX + view.getFrameOffset(),
|
|
225
|
-
labelX + view.getFrameOffset() + labelWidth
|
|
226
|
-
)) {
|
|
227
|
-
context.fillText(label, labelX, labelY);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
secs += axisLabelIntervalSecs;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (this._maskStart && this._maskEnd) {
|
|
236
|
-
if (labelEnd > this._maskStart && labelStart < this._maskEnd) {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return false;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
return
|
|
244
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link Axis} class.
|
|
5
|
+
*
|
|
6
|
+
* @module axis
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
define([
|
|
10
|
+
'../utils',
|
|
11
|
+
'konva'
|
|
12
|
+
], function(Utils, Konva) {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
var LEFT_PADDING = 4;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates the timeline axis shapes and adds them to the given view layer.
|
|
19
|
+
*
|
|
20
|
+
* @class
|
|
21
|
+
* @alias Axis
|
|
22
|
+
*
|
|
23
|
+
* @param {WaveformOverview|View} view
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
* @param {String} options.axisGridlineColor
|
|
26
|
+
* @param {String} options.axisLabelColor
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
function Axis(peaks, view, options) {
|
|
30
|
+
this._view = view;
|
|
31
|
+
|
|
32
|
+
var self = this;
|
|
33
|
+
|
|
34
|
+
peaks.on('playhead.moved', this._onPlayheadMoved.bind(this));
|
|
35
|
+
peaks.on('playhead.hidden', this._onPlayheadHidden.bind(this));
|
|
36
|
+
|
|
37
|
+
self._axisGridlineColor = options.axisGridlineColor;
|
|
38
|
+
self._axisLabelColor = options.axisLabelColor;
|
|
39
|
+
|
|
40
|
+
self._backLayer = new Konva.Layer({
|
|
41
|
+
listening: false
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
self._frontLayer = new Konva.Layer({
|
|
45
|
+
listening: false
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
self._axisShape = new Konva.Shape({
|
|
49
|
+
sceneFunc: function(context) {
|
|
50
|
+
self.drawAxis(context, view);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
self._backLayer.add(self._axisShape);
|
|
54
|
+
|
|
55
|
+
self._timesShape = new Konva.Shape({
|
|
56
|
+
sceneFunc: function(context) {
|
|
57
|
+
self.drawTimes(context, view);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
self._frontLayer.add(self._timesShape);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Axis.prototype._onPlayheadMoved = function(playheadX, playheadWidth) {
|
|
64
|
+
this._maskStart = playheadX + this._view.getFrameOffset();
|
|
65
|
+
this._maskEnd = playheadX + this._view.getFrameOffset() + playheadWidth;
|
|
66
|
+
this._frontLayer.draw();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
Axis.prototype._onPlayheadHidden = function() {
|
|
70
|
+
this._maskStart = null;
|
|
71
|
+
this._maskEnd = null;
|
|
72
|
+
this._frontLayer.draw();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
Axis.prototype.draw = function() {
|
|
76
|
+
this._backLayer.draw();
|
|
77
|
+
this._frontLayer.draw();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
Axis.prototype.addBackToStage = function(stage) {
|
|
81
|
+
stage.add(this._backLayer);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Axis.prototype.addFrontToStage = function(stage) {
|
|
85
|
+
stage.add(this._frontLayer);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns number of seconds for each x-axis marker, appropriate for the
|
|
90
|
+
* current zoom level, ensuring that markers are not too close together
|
|
91
|
+
* and that markers are placed at intuitive time intervals (i.e., every 1,
|
|
92
|
+
* 2, 5, 10, 20, 30 seconds, then every 1, 2, 5, 10, 20, 30 minutes, then
|
|
93
|
+
* every 1, 2, 5, 10, 20, 30 hours).
|
|
94
|
+
*
|
|
95
|
+
* @param {WaveformOverview|WaveformZoomView} view
|
|
96
|
+
* @returns {Number}
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
Axis.prototype.getAxisLabelScale = function(view) {
|
|
100
|
+
var baseSecs = 1; // seconds
|
|
101
|
+
var steps = [0.1, 0.5, 1, 2, 5, 10, 20, 30];
|
|
102
|
+
var minSpacing = 60;
|
|
103
|
+
var index = 0;
|
|
104
|
+
|
|
105
|
+
var secs;
|
|
106
|
+
|
|
107
|
+
for (;;) {
|
|
108
|
+
secs = baseSecs * steps[index];
|
|
109
|
+
var pixels = view.timeToPixels(secs);
|
|
110
|
+
|
|
111
|
+
if (pixels < minSpacing) {
|
|
112
|
+
if (++index === steps.length) {
|
|
113
|
+
baseSecs *= 60; // seconds -> minutes -> hours
|
|
114
|
+
index = 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return secs;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Draws the time axis and labels onto a view.
|
|
127
|
+
*
|
|
128
|
+
* @param {Konva.Context} context The context to draw on.
|
|
129
|
+
* @param {WaveformOverview|WaveformZoomView} view
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
Axis.prototype.drawAxis = function(context, view) {
|
|
133
|
+
var currentFrameStartTime = view.pixelsToTime(view.getFrameOffset());
|
|
134
|
+
|
|
135
|
+
// Time interval between axis markers (seconds)
|
|
136
|
+
var axisLabelIntervalSecs = this.getAxisLabelScale(view);
|
|
137
|
+
|
|
138
|
+
// Time of first axis marker (seconds)
|
|
139
|
+
var firstAxisLabelSecs = Utils.roundUpToNearest(currentFrameStartTime, axisLabelIntervalSecs);
|
|
140
|
+
|
|
141
|
+
// Distance between waveform start time and first axis marker (seconds)
|
|
142
|
+
var axisLabelOffsetSecs = firstAxisLabelSecs - currentFrameStartTime;
|
|
143
|
+
|
|
144
|
+
// Distance between waveform start time and first axis marker (pixels)
|
|
145
|
+
var axisLabelOffsetPixels = view.timeToPixels(axisLabelOffsetSecs);
|
|
146
|
+
|
|
147
|
+
context.setAttr('strokeStyle', this._axisGridlineColor);
|
|
148
|
+
context.setAttr('lineWidth', 1);
|
|
149
|
+
|
|
150
|
+
// Set text style
|
|
151
|
+
context.setAttr('font', '11px sans-serif');
|
|
152
|
+
context.setAttr('fillStyle', this._axisLabelColor);
|
|
153
|
+
context.setAttr('textAlign', 'left');
|
|
154
|
+
context.setAttr('textBaseline', 'bottom');
|
|
155
|
+
|
|
156
|
+
var secs = firstAxisLabelSecs;
|
|
157
|
+
var x;
|
|
158
|
+
|
|
159
|
+
var width = view.getWidth();
|
|
160
|
+
var height = view.getHeight();
|
|
161
|
+
|
|
162
|
+
for (;;) {
|
|
163
|
+
// Position of axis marker (pixels)
|
|
164
|
+
x = axisLabelOffsetPixels + view.timeToPixels(secs - firstAxisLabelSecs);
|
|
165
|
+
if (x >= width) {
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
context.beginPath();
|
|
170
|
+
context.moveTo(x + 0.5, 0);
|
|
171
|
+
context.lineTo(x + 0.5, height);
|
|
172
|
+
context.stroke();
|
|
173
|
+
|
|
174
|
+
secs += axisLabelIntervalSecs;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
Axis.prototype.drawTimes = function(context, view) {
|
|
179
|
+
var currentFrameStartTime = view.pixelsToTime(view.getFrameOffset());
|
|
180
|
+
|
|
181
|
+
// Time interval between axis markers (seconds)
|
|
182
|
+
var axisLabelIntervalSecs = this.getAxisLabelScale(view);
|
|
183
|
+
|
|
184
|
+
// Time of first axis marker (seconds)
|
|
185
|
+
var firstAxisLabelSecs = Utils.roundUpToNearestPositive(
|
|
186
|
+
currentFrameStartTime - 1,
|
|
187
|
+
axisLabelIntervalSecs
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// Distance between waveform start time and first axis marker (seconds)
|
|
191
|
+
var axisLabelOffsetSecs = firstAxisLabelSecs - currentFrameStartTime;
|
|
192
|
+
|
|
193
|
+
// Distance between waveform start time and first axis marker (pixels)
|
|
194
|
+
var axisLabelOffsetPixels = view.timeToPixels(axisLabelOffsetSecs);
|
|
195
|
+
|
|
196
|
+
// Set text style
|
|
197
|
+
context.setAttr('font', '11px sans-serif');
|
|
198
|
+
context.setAttr('fillStyle', this._axisLabelColor);
|
|
199
|
+
context.setAttr('textAlign', 'left');
|
|
200
|
+
context.setAttr('textBaseline', 'bottom');
|
|
201
|
+
|
|
202
|
+
var secs = firstAxisLabelSecs;
|
|
203
|
+
var x;
|
|
204
|
+
|
|
205
|
+
var width = view.getWidth();
|
|
206
|
+
|
|
207
|
+
for (;;) {
|
|
208
|
+
// Position of axis marker (pixels)
|
|
209
|
+
x = axisLabelOffsetPixels + view.timeToPixels(secs - firstAxisLabelSecs);
|
|
210
|
+
|
|
211
|
+
if (x >= width) {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var label = Utils.formatTime(secs, false);
|
|
216
|
+
var measures = context.measureText(label);
|
|
217
|
+
var labelHeight = measures.actualBoundingBoxAscent
|
|
218
|
+
- measures.actualBoundingBoxDescent;
|
|
219
|
+
var labelWidth = measures.width;
|
|
220
|
+
var labelX = x + LEFT_PADDING;
|
|
221
|
+
var labelY = labelHeight;
|
|
222
|
+
|
|
223
|
+
if (!this._labelIsMasked(
|
|
224
|
+
labelX + view.getFrameOffset(),
|
|
225
|
+
labelX + view.getFrameOffset() + labelWidth
|
|
226
|
+
)) {
|
|
227
|
+
context.fillText(label, labelX, labelY);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
secs += axisLabelIntervalSecs;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
Axis.prototype._labelIsMasked = function(labelStart, labelEnd) {
|
|
235
|
+
if (this._maskStart && this._maskEnd) {
|
|
236
|
+
if (labelEnd > this._maskStart && labelStart < this._maskEnd) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
return Axis;
|
|
244
|
+
});
|