|
@@ -28,7 +28,7 @@ type smoothAnimationType = {
|
|
|
aveSpeed: number
|
|
|
}
|
|
|
|
|
|
-const _numberOfSegments = 60 // 中间切割线的个数
|
|
|
+let _numberOfSegments = 56 // 中间切割线的个数
|
|
|
const _canvasDomHeight = 60 // canvans 高度
|
|
|
|
|
|
export const smoothAnimationState = {
|
|
@@ -71,6 +71,9 @@ export function initSmoothAnimation() {
|
|
|
smoothAnimationState.batePos = batePos
|
|
|
const batePos1 = dataFilter([...batePos])
|
|
|
console.log(batePos1, "排序之后的数据")
|
|
|
+ // 这里性能优化,对于超级长的曲子,_numberOfSegments值 动态变化
|
|
|
+ const numberOfSegments = parseInt(16000 / batePos1.length + "")
|
|
|
+ _numberOfSegments = Math.max(18, Math.min(_numberOfSegments, numberOfSegments))
|
|
|
const batePos2 = createSmoothCurvePoints(batePos1, _numberOfSegments)
|
|
|
smoothAnimationState.pointsPos = batePos2
|
|
|
// 初始化旋律线
|
|
@@ -403,7 +406,7 @@ function quantileScale(data: number[], minRange = 0, maxRange = _canvasDomHeight
|
|
|
/**
|
|
|
* 使用传入的曲线的顶点坐标创建平滑曲线的顶点。
|
|
|
* @param {Array} points 曲线顶点坐标数组,
|
|
|
- * @param {Int} numberOfSegments 平滑曲线 2 个顶点间的线段数,默认为 20
|
|
|
+ * @param {Int} numberOfSegments 平滑曲线 2 个顶点间的线段数
|
|
|
* @return {Array} 平滑曲线的顶点坐标数组
|
|
|
*/
|
|
|
function createSmoothCurvePoints(points: pointsPosType, numSegments: number) {
|