| | |
| | | this.opts = { // 默认配置 |
| | | lineWidth: 3, // 线宽 |
| | | onOffBase: { // 开关的基础配置 |
| | | radius: 3, |
| | | radius: 4, |
| | | width: 16, |
| | | lineWidth: 2, |
| | | }, |
| | | moveDot: { |
| | | radius: 6, |
| | | step: 1, |
| | | step: 0.8, |
| | | gravity: 0.08 |
| | | }, |
| | | ripplesStep: 0.6 |
| | | }; |
| | | |
| | | // 转动轴全局配置 |
| | | this.rollAxis = { |
| | | speed: 0.1, |
| | | start: 0, |
| | | }; |
| | | |
| | | // 显示线条的id |
| | | this.showLineId = true; |
| | | } |
| | |
| | | option.right = [point[0] + option.width, point[1] + option.height / 2]; |
| | | option.top = [point[0] + option.width / 2, point[1]]; |
| | | option.bottom = [point[0] + option.width / 2, point[1] + option.height]; |
| | | |
| | | // 设置执行的方法 |
| | | option.method = "drawImage"; |
| | | // 添加配置项 |
| | |
| | | }); |
| | | }; |
| | | |
| | | /** |
| | | * 绘制转动的轴 |
| | | * @param option 配置项 |
| | | * start起始坐标点,end结束坐标点必填项 |
| | | * start.y=end.y |
| | | */ |
| | | Diagram.prototype.drawRollAxis = function (option) { |
| | | let ctx = option.flush ? this.f_ctx : this.s_ctx; // 获取上下文 |
| | | let start = option.start; |
| | | let end = option.end; |
| | | let height = option.height ? option.height : 16; |
| | | let width = Math.abs(start[0] - end[0]); |
| | | let rollAxis = this.rollAxis; |
| | | |
| | | let rollNumber = rollAxis.start; // 旋转轴的开始点 |
| | | let rollSpeed = rollAxis.speed; // 旋转的速度 |
| | | let color1 = option.color1 ? option.color1 : "#cdcaca"; // 开始颜色 |
| | | let color2 = option.color2 ? option.color2 : "#FFFFFF"; // 中间颜色 |
| | | let grd = ctx.createLinearGradient(start[0], start[0], start[0], height + start[0]); // 渐变色 |
| | | grd.addColorStop(rollNumber - Math.floor(rollNumber), color1); |
| | | rollNumber = rollNumber + 0.25; |
| | | grd.addColorStop(rollNumber - Math.floor(rollNumber), color2); |
| | | rollNumber = rollNumber + 0.25; |
| | | grd.addColorStop(rollNumber - Math.floor(rollNumber), color1); |
| | | rollNumber = rollNumber + 0.25; |
| | | grd.addColorStop(rollNumber - Math.floor(rollNumber), color2); |
| | | rollNumber = rollNumber + 0.25; |
| | | grd.addColorStop(rollNumber - Math.floor(rollNumber), color1); |
| | | ctx.fillStyle = grd; |
| | | ctx.fillRect(start[0], start[1], width, height); |
| | | |
| | | rollAxis.start += rollSpeed; |
| | | if (rollAxis.start > 1.25) { |
| | | rollAxis.start = 0; |
| | | } |
| | | |
| | | // 添加配置项 |
| | | option.method = "drawRollAxis"; |
| | | this.addOptions(option); |
| | | return { |
| | | left: [start[0], start[1] + height / 2], |
| | | bottom: [end[0], end[1] + height / 2], |
| | | } |
| | | } |
| | | |
| | | export default Diagram; |