|
@@ -259,6 +259,14 @@ export default {
|
|
|
this.startSimulation()
|
|
this.startSimulation()
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ // hex → rgba(小程序不支持 8 位 hex 颜色 #RRGGBBAA)
|
|
|
|
|
+ hexToRgba: function(hex, alpha) {
|
|
|
|
|
+ var r = parseInt(hex.slice(1, 3), 16)
|
|
|
|
|
+ var g = parseInt(hex.slice(3, 5), 16)
|
|
|
|
|
+ var b = parseInt(hex.slice(5, 7), 16)
|
|
|
|
|
+ return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
startSimulation: function() {
|
|
startSimulation: function() {
|
|
|
if (this.isSimulating) return
|
|
if (this.isSimulating) return
|
|
|
this.isSimulating = true
|
|
this.isSimulating = true
|
|
@@ -399,10 +407,10 @@ export default {
|
|
|
// 6. 渲染
|
|
// 6. 渲染
|
|
|
this.render()
|
|
this.render()
|
|
|
|
|
|
|
|
- // 7. 下一帧
|
|
|
|
|
- this.animFrameId = requestAnimationFrame(function() {
|
|
|
|
|
|
|
+ // 7. 下一帧(小程序无 requestAnimationFrame,用 setTimeout 降级)
|
|
|
|
|
+ this.animFrameId = setTimeout(function() {
|
|
|
self.simulationTick()
|
|
self.simulationTick()
|
|
|
- })
|
|
|
|
|
|
|
+ }, 16)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
// ===== 渲染 =====
|
|
// ===== 渲染 =====
|
|
@@ -474,7 +482,7 @@ export default {
|
|
|
ctx.lineWidth = 3
|
|
ctx.lineWidth = 3
|
|
|
ctx.stroke()
|
|
ctx.stroke()
|
|
|
} else {
|
|
} else {
|
|
|
- ctx.fillStyle = this.themeColor + '22'
|
|
|
|
|
|
|
+ ctx.fillStyle = this.hexToRgba(this.themeColor, 0.13)
|
|
|
ctx.fill()
|
|
ctx.fill()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -529,18 +537,18 @@ export default {
|
|
|
ctx.setLineWidth(3)
|
|
ctx.setLineWidth(3)
|
|
|
ctx.stroke()
|
|
ctx.stroke()
|
|
|
} else {
|
|
} else {
|
|
|
- ctx.setFillStyle(this.themeColor + '22')
|
|
|
|
|
|
|
+ ctx.setFillStyle(this.hexToRgba(this.themeColor, 0.13))
|
|
|
ctx.fill()
|
|
ctx.fill()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ctx.setFillStyle(node.isSelf ? this.themeColor : '#4A5568')
|
|
ctx.setFillStyle(node.isSelf ? this.themeColor : '#4A5568')
|
|
|
- ctx.setFont('bold ' + (r * 0.9) + 'px sans-serif')
|
|
|
|
|
|
|
+ ctx.font = 'bold ' + (r * 0.9) + 'px sans-serif'
|
|
|
ctx.setTextAlign('center')
|
|
ctx.setTextAlign('center')
|
|
|
ctx.setTextBaseline('middle')
|
|
ctx.setTextBaseline('middle')
|
|
|
ctx.fillText(node.displayName, node.x, node.y)
|
|
ctx.fillText(node.displayName, node.x, node.y)
|
|
|
|
|
|
|
|
ctx.setFillStyle(node.isSelf ? this.themeColor : '#94A3B8')
|
|
ctx.setFillStyle(node.isSelf ? this.themeColor : '#94A3B8')
|
|
|
- ctx.setFont((r * 0.4) + 'px sans-serif')
|
|
|
|
|
|
|
+ ctx.font = (r * 0.4) + 'px sans-serif'
|
|
|
ctx.fillText(node.nickname.substring(0, 3), node.x, node.y + r + 10)
|
|
ctx.fillText(node.nickname.substring(0, 3), node.x, node.y + r + 10)
|
|
|
}
|
|
}
|
|
|
|
|
|