| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Oct 2024 09:54:34 +0200 | |
| changeset 1080 | 2b513bcb710a |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
1 |
import _ from "lodash"; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
2 |
import Raphael from "raphael"; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
3 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
4 |
const Sparkline = function (ns) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
5 |
return class extends ns.Widgets.Widget { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
6 |
constructor(player, config) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
7 |
super(player, config); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
8 |
} |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
9 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
10 |
static defaults = { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
11 |
lineColor: "#7492b4", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
12 |
fillColor: "#aeaeb8", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
13 |
lineWidth: 2, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
14 |
slice_count: 20, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
15 |
height: 50, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
16 |
margin: 5, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
17 |
}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
18 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
19 |
draw() { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
20 |
var _slices = [], |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
21 |
_duration = this.source.getDuration(), |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
22 |
_max = 0, |
| 876 | 23 |
_list = this.getWidgetAnnotations(); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
24 |
for (var _i = 0; _i < this.slice_count; _i++) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
25 |
var _begin = (_i * _duration) / this.slice_count, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
26 |
_end = ((_i + 1) * _duration) / this.slice_count, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
27 |
_volume = 0; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
28 |
_list.forEach(function (_annotation) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
29 |
if (_annotation.begin < _end && _annotation.end >= _begin) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
30 |
var _d = _annotation.getDuration().milliseconds; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
31 |
if (!_d) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
32 |
_volume += 1; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
33 |
} else { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
34 |
_volume += |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
35 |
(Math.min(_annotation.end, _end) - |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
36 |
Math.max(_annotation.begin, _begin)) / |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
37 |
_d; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
38 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
39 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
40 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
41 |
_max = Math.max(_max, _volume); |
| 981 | 42 |
_slices.push(_volume); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
43 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
44 |
if (!_max) { |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
45 |
return; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
46 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
47 |
this.paper = new Raphael(this.$[0], this.width, this.height); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
48 |
var _scale = (this.height - this.margin) / _max, |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
49 |
_width = this.width / this.slice_count, |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
50 |
_this = this, |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
51 |
_y = _(_slices).map(function (_v) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
52 |
return _this.margin + _this.height - _scale * _v; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
53 |
}).value(), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
54 |
_d = |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
55 |
_(_y).reduce(function (_memo, _v, _k) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
56 |
return ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
57 |
_memo + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
58 |
(_k |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
59 |
? "C" + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
60 |
_k * _width + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
61 |
" " + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
62 |
_y[_k - 1] + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
63 |
" " + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
64 |
_k * _width + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
65 |
" " + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
66 |
_v + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
67 |
" " + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
68 |
(_k + 0.5) * _width + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
69 |
" " + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
70 |
_v |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
71 |
: "M0 " + _v + "L" + 0.5 * _width + " " + _v) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
72 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
73 |
}, "") + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
74 |
"L" + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
75 |
this.width + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
76 |
" " + |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
77 |
_y[_y.length - 1], |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
78 |
_d2 = _d + "L" + this.width + " " + this.height + "L0 " + this.height; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
79 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
80 |
this.paper.path(_d2).attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
81 |
stroke: "none", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
82 |
fill: this.fillColor, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
83 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
84 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
85 |
this.paper.path(_d).attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
86 |
fill: "none", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
87 |
stroke: this.lineColor, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
88 |
"stroke-width": this.lineWidth, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
89 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
90 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
91 |
this.rectangleProgress = this.paper.rect(0, 0, 0, this.height).attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
92 |
stroke: "none", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
93 |
fill: "#808080", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
94 |
opacity: 0.3, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
95 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
96 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
97 |
this.ligneProgress = this.paper |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
98 |
.path("M0 0L0 " + this.height) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
99 |
.attr({ stroke: "#ff00ff", "line-width": 2 }); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
100 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
101 |
this.$.click(function (_e) { |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
102 |
var _x = _e.pageX - _this.$.offset().left; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
103 |
_this.media.setCurrentTime((_this.media.duration * _x) / _this.width); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
104 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
105 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
106 |
this.onMediaEvent("timeupdate", "onTimeupdate"); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
107 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
108 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
109 |
onTimeupdate(_time) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
110 |
var _x = Math.floor((this.width * _time) / this.media.duration); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
111 |
this.rectangleProgress.attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
112 |
width: _x, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
113 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
114 |
this.ligneProgress.attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
115 |
path: "M" + _x + " 0L" + _x + " " + this.height, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
116 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
117 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
118 |
}; |
| 1013 | 119 |
}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
120 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1013
diff
changeset
|
121 |
export { Sparkline }; |