博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
制作TimeLine物流信息展示效果
阅读量:5961 次
发布时间:2019-06-19

本文共 6453 字,大约阅读时间需要 21 分钟。

1 var TimeLine = function (_id) {  2     this.id = _id;  3     this._top = 40;  4     this.vHeight = 40;  5     this.global_top = 40;  6     this.line_height = 4;  7     this.radius = 6;  8     this.startPosition = 6;  9     this.text_top = 40; 10     this.text_margin = 20; 11     this.text_left = [6, 15]; 12     this.canvas = null; 13     this.totalWidth = 0; 14     this.totalHeight = 0; 15     this.context = null; 16     this.stepPosition = 100; 17     this.font = "bold 35px sans-serif"; 18     this.Init(); 19 }; 20  21 TimeLine.prototype = { 22     Init: function () { 23         this.canvas = document.getElementById(this.id); 24         if (this.canvas == null) { 25             return false; 26         } 27  28         this.totalWidth = this.canvas.clientWidth * 0.95; 29         this.totalHeight = this.canvas.clientHeight; 30         this.stepPosition = 0.1 * this.totalWidth; 31         this.global_top = 0.1 * this.totalHeight; 32         this.vHeight = 0.1 * this.totalHeight; 33         this.text_margin = 0.06 * this.totalHeight; 34         this.radius = 0.01 * this.totalHeight; 35         this.text_left = [0.01 * this.totalHeight, 0.01 * this.totalWidth]; 36         this.startPosition = 0.02 * this.totalWidth; 37  38         this.context = this.canvas.getContext("2d"); 39         //每次重绘前清空 40         this.context.clearRect(0, 0, this.totalWidth, this.totalHeight); 41     }, 42  43     /** 44     *strDate:时间 45     *strContent:显示文本 46     *direction:走势,0水平,1垂直,-1结束 47     *status:状态,1,2已完成,0未完成 48     */ 49     AddEvent: function (strDate, strContent, direction, status) { 50         if (this.canvas == null) { 51             return false; 52         } 53         var okColor = 'green', onColor = 'gray'; 54         var passColor = "rgba(0,255,0,0.5)", waitColor = "rgba(99,99,99,0.5)"; 55         var passStrokeColor = "green", waitStrokeColor = "rgba(99,99,99,0.5)"; 56         if (direction == 0) { 57             this.stepPosition = strContent.length * 6; 58             if (this.stepPosition < 0.20 * this.totalWidth) this.stepPosition = 0.20 * this.totalWidth; 59             //设置透明度实践证明透明度值>0,<1值越低,越透明,值>=1时为纯色,值<=0时为完全透明 60             this.context.fillStyle = ((status == 1 || status == 2) ? passColor : waitColor); 61             this.context.fillRect(this.startPosition + this.radius, this.global_top, this.stepPosition, this.line_height); 62  63             //设置新图形(红色圆形) 64             this.context.beginPath(); 65             this.context.fillStyle = ((status == 1 || status == 2) ? okColor : onColor); 66             this.context.arc(this.startPosition + this.line_height / 2, this.global_top + this.line_height / 2, this.radius, 0, Math.PI * 2, false); 67             this.context.fill(); 68             this.context.fillStyle = ((status == 1 || status == 2) ? okColor : onColor); 69             this.context.font = this.font; 70             //this.text_top=this.global_top+this.line_height+this.text_margin; 71             this.text_top = this.text_margin; 72             //context.strokeStyle = ((status==1||status==2)?passStrokeColor:waitStrokeColor); 73             //context.strokeText(strContent,this.startPosition+text_left[0],this.text_top); 74             this.context.fillText(strContent, this.startPosition + this.text_left[0], this.text_top); 75             this.context.fillText(strDate, this.startPosition + this.text_left[0], this.global_top + this.text_top + 10); 76             this.startPosition += this.stepPosition; 77         } 78         else if (direction == 1) { 79             stepPosition = 50; 80             //设置透明度实践证明透明度值>0,<1值越低,越透明,值>=1时为纯色,值<=0时为完全透明 81             this.context.fillStyle = ((status == 1) ? passColor : waitColor); 82             this.context.fillRect(this.startPosition, this.vHeight + this.radius + this.line_height / 2, this.line_height, this.stepPosition * 0.2); 83             this.vHeight += this.stepPosition * 0.2; 84             this._top += +this.stepPosition * 0.2; 85             //设置新图形(红色圆形) 86             this.context.beginPath(); 87             this.context.fillStyle = ((status == 1) ? okColor : onColor); 88             this.context.arc(this.startPosition + this.line_height / 2, this.vHeight + this.line_height / 2, this.radius, 0, Math.PI * 2, false); 89             this.context.fill(); 90             this.context.fillStyle = ((status == 1) ? okColor : onColor); 91             this.context.font = this.font; 92             this.text_top = this._top + this.line_height / 2; 93             //this.context.strokeStyle = ((status==1)?passStrokeColor:waitStrokeColor); 94             //this.context.strokeText(strDate+'    '+strContent,this.startPosition+text_left[1],this.text_top); 95             this.context.fillText(strDate + '    ' + strContent, this.startPosition + this.text_left[1], this.vHeight + 10); 96             //this.context.fillText(strContent,this.startPosition+this.text_left[1],this.text_top+this.text_margin); 97         } 98         else if (direction == -1) { 99             //设置透明度实践证明透明度值>0,<1值越低,越透明,值>=1时为纯色,值<=0时为完全透明100             this.context.fillStyle = ((status == 1 || status == 2) ? passColor : waitColor);101             this.context.fillRect(this.startPosition + this.radius, this.global_top, this.stepPosition * 0.7, this.line_height);102             //设置新图形(红色圆形)103             this.context.beginPath();104             this.context.fillStyle = ((status == 1 || status == 2) ? okColor : onColor);105             this.context.arc(this.startPosition + this.line_height / 2 + this.stepPosition * 0.7 + this.radius, this.global_top + this.line_height / 2, this.radius, 0, Math.PI * 2, false);106             this.context.fill();107             this.context.fillStyle = ((status == 1 || status == 2) ? okColor : onColor);108             this.context.font = this.font;109             this.text_top = this.text_margin;110             //context.strokeStyle = ((status==1||status==2)?passStrokeColor:waitStrokeColor);111             //context.strokeText(strContent,this.startPosition+this.text_left[0]+this.stepPosition*2.5,this.text_top);112             this.context.fillText(strContent, this.startPosition + this.text_left[0] + this.stepPosition * 0.4, this.text_top);113             this.context.fillText(strDate, this.startPosition + this.text_left[0] + this.stepPosition * 0.4, this.global_top + this.text_margin + 10);114         }115     }116 };

 

转载于:https://www.cnblogs.com/ziranquliu/p/5625800.html

你可能感兴趣的文章
SpringBoot之SpringBoot+Mybatis+Mysql+Maven整合
查看>>
SQLServer BI 学习笔记
查看>>
20160504-hibernate入门
查看>>
工作四周年
查看>>
sql定时自动备份(定时作业)
查看>>
Excel 2013 表格自用技巧
查看>>
ubuntu安装VNC、Xfce桌面
查看>>
浅析支付系统的整体架构
查看>>
二位数组
查看>>
unix文件权限
查看>>
Python 模拟鼠键
查看>>
【Marva Collins' Way】第二章
查看>>
SDUT OJ 数据结构实验之链表一:顺序建立链表
查看>>
舒适的旅行(并查集)
查看>>
django-uuslug: 方便的将中文转化成拼音 slug 的工具
查看>>
布局类组件介绍
查看>>
Nginx反向代理+负载均衡简单实现
查看>>
树的操作
查看>>
键盘按键和键盘对应代码表:
查看>>
jquery中链式调用原理
查看>>