1 Star 2 Fork 2

w642833823/visualgo

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AnimatedPointer.js 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
kinlog 提交于 2016-03-09 16:00 +08:00 . add project
// JavaScript Document
// 动画指针
var AnimatedPointer = function(objectID, label, length, direction) {
this.objectID = objectID ; // 物体的ID
this.label = label ; // 物体的标签
this.length = length ; // 箭头长度
this.direction = direction ; // 方向
this.height = 8 ; // 高度
this.width = 6 ; // 宽度
this.interval = 10 ; // 间距
}
// 继承和构造函数
AnimatedPointer.prototype = new AnimatedObject() ;
AnimatedPointer.prototype.constructor = AnimatedPointer ;
// 画箭头
AnimatedPointer.prototype.drawArrow = function(ctx) {
ctx.beginPath() ;
// 判断方向
if(this.direction.toUpperCase() == 'UP') {
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x-this.width), parseInt(this.y+this.height)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x+this.width), parseInt(this.y+this.height)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(this.x, parseInt(this.y+this.length)) ;
}
else if(this.direction.toUpperCase() == 'DOWN') {
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x-this.width), parseInt(this.y-this.height)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x+this.width), parseInt(this.y-this.height)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(this.x, parseInt(this.y-this.length)) ;
}
else if(this.direction.toUpperCase() == 'LEFT') {
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x+this.height), parseInt(this.y-this.width)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x+this.height), parseInt(this.y+this.width)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x+this.length), this.y) ;
}
else if(this.direction.toUpperCase() == 'RIGHT') {
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x-this.height), parseInt(this.y-this.width)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x-this.height), parseInt(this.y+this.width)) ;
ctx.moveTo(this.x, this.y) ;
ctx.lineTo(parseInt(this.x-this.length), this.y) ;
}
ctx.closePath() ;
ctx.strokeStyle = this.foregroundColor ;
ctx.lineWidth = 2 ;
ctx.stroke();
ctx.fillStyle = this.foregroundColor ;
ctx.fill();
}
// 画图
AnimatedPointer.prototype.draw = function(ctx) {
// 开始画图
ctx.beginPath() ;
// 设置透明度
ctx.globalAlpha = 1.0 ;
// 画箭头
this.drawArrow(ctx) ;
// 写文字
ctx.font = "10px Arial" ;
ctx.textAlign = "center" ;
ctx.textBaseline = "middle" ;
ctx.fillStyle = this.foregroundColor ;
// 判断方向
if(this.direction.toUpperCase() == 'UP') {
ctx.fillText(this.label, this.x, parseInt(this.y+this.length+this.interval)) ;
}
else if(this.direction.toUpperCase() == 'DOWN') {
ctx.fillText(this.label, this.x, parseInt(this.y-this.length-this.interval)) ;
}
else if(this.direction.toUpperCase() == 'LEFT') {
ctx.fillText(this.label, parseInt(this.x-this.length-this.interval), this.y) ;
}
else if(this.direction.toUpperCase() == 'RIGHT') {
ctx.fillText(this.label, parseInt(this.x+this.length+this.interval), this.y) ;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/w642833823/visualgo.git
git@gitee.com:w642833823/visualgo.git
w642833823
visualgo
visualgo
gh-pages

搜索帮助