docs(animation.vue): 添加函数注释以增强代码可读性
为关键函数添加详细注释,解释其实现逻辑和用途,以便于其他开发者理解代码功能
Showing
1 changed file
with
20 additions
and
3 deletions
| ... | @@ -150,6 +150,11 @@ const pathData = computed(() => { | ... | @@ -150,6 +150,11 @@ const pathData = computed(() => { |
| 150 | }); | 150 | }); |
| 151 | 151 | ||
| 152 | // 计算两点之间的贝塞尔曲线路径段 | 152 | // 计算两点之间的贝塞尔曲线路径段 |
| 153 | +// 该函数使用三次贝塞尔曲线算法生成平滑的曲线路径: | ||
| 154 | +// 1. 计算路径的方向向量和单位向量 | ||
| 155 | +// 2. 添加垂直偏移以创建弧形效果 | ||
| 156 | +// 3. 根据路径方向动态调整控制点 | ||
| 157 | +// 4. 生成标准的SVG路径命令字符串 | ||
| 153 | // @param startPoint - 起始点坐标 {x, y} | 158 | // @param startPoint - 起始点坐标 {x, y} |
| 154 | // @param endPoint - 结束点坐标 {x, y} | 159 | // @param endPoint - 结束点坐标 {x, y} |
| 155 | // @returns 返回SVG路径字符串 | 160 | // @returns 返回SVG路径字符串 |
| ... | @@ -211,8 +216,12 @@ const pathColor = computed(() => { | ... | @@ -211,8 +216,12 @@ const pathColor = computed(() => { |
| 211 | // }; | 216 | // }; |
| 212 | 217 | ||
| 213 | // 处理下一步按钮点击事件 | 218 | // 处理下一步按钮点击事件 |
| 214 | -// 激活下一个节点并创建新的高亮路径段 | 219 | +// 该函数实现了动画的核心交互逻辑: |
| 215 | -// 当到达最后一个节点时,按钮将被禁用 | 220 | +// 1. 按顺序激活下一个节点 |
| 221 | +// 2. 创建新的高亮路径段并添加到动画序列 | ||
| 222 | +// 3. 更新节点状态和路径显示 | ||
| 223 | +// 4. 当到达最后一个节点时自动禁用按钮 | ||
| 224 | +// 5. 确保动画流程的连贯性和用户体验 | ||
| 216 | const nextStep = () => { | 225 | const nextStep = () => { |
| 217 | if (activeNodeIndex.value < points.value.length - 1) { | 226 | if (activeNodeIndex.value < points.value.length - 1) { |
| 218 | activeNodeIndex.value++; | 227 | activeNodeIndex.value++; |
| ... | @@ -280,6 +289,9 @@ const svgObj = [ | ... | @@ -280,6 +289,9 @@ const svgObj = [ |
| 280 | }, | 289 | }, |
| 281 | ]; | 290 | ]; |
| 282 | // 计算SVG容器尺寸 | 291 | // 计算SVG容器尺寸 |
| 292 | +// 该函数用于获取动画容器的实际尺寸,以便于后续计算SVG视图框 | ||
| 293 | +// 返回一个包含容器宽度和高度的对象 | ||
| 294 | +// 如果容器不存在,则返回默认值{width: 0, height: 0} | ||
| 283 | const containerSize = computed(() => { | 295 | const containerSize = computed(() => { |
| 284 | const container = document.querySelector('.animation-container'); | 296 | const container = document.querySelector('.animation-container'); |
| 285 | if (!container) return { width: 0, height: 0 }; | 297 | if (!container) return { width: 0, height: 0 }; |
| ... | @@ -306,7 +318,12 @@ onUnmounted(() => { | ... | @@ -306,7 +318,12 @@ onUnmounted(() => { |
| 306 | window.removeEventListener('resize', updateContainerSize); | 318 | window.removeEventListener('resize', updateContainerSize); |
| 307 | }); | 319 | }); |
| 308 | 320 | ||
| 309 | -// 更新svgViewBox计算属性 | 321 | +// 计算并更新SVG视图框(viewBox) |
| 322 | +// 该函数动态计算SVG视图框的尺寸和位置,以确保: | ||
| 323 | +// 1. 所有节点都在可视区域内 | ||
| 324 | +// 2. 保持适当的宽高比 | ||
| 325 | +// 3. 根据容器尺寸自适应调整 | ||
| 326 | +// 4. 在不同屏幕尺寸下保持良好的显示效果 | ||
| 310 | const svgViewBox = computed(() => { | 327 | const svgViewBox = computed(() => { |
| 311 | const maxX = Math.max(...points.value.map(p => p.x)); | 328 | const maxX = Math.max(...points.value.map(p => p.x)); |
| 312 | const maxY = Math.max(...points.value.map(p => p.y)); | 329 | const maxY = Math.max(...points.value.map(p => p.y)); | ... | ... |
-
Please register or login to post a comment