angular的canvas画图例子
angular的例子:
<!DOCTYPE html>
<html ng-app="APP">
<head>
<meta charset="UTF-8">
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.12/angular.min.js"></script> </head>
<body ng-controller="MainCtrl">
<!--
界面的这个元素会被替换成canvas元素;
-->
<div ang:round:progress data-round-progress-model="roundProgressData"></div>
<br>
<input type="number" ng-model="roundProgressData.label"/>
<script>
//引用angular.directives-round-progress这个模块;
var APP = angular.module('APP', ['angular.directives-round-progress']).
controller('MainCtrl', function($scope) {
$scope.roundProgressData = {
//这个是初始化的数据;
label: 11,
percentage: 0.11
} //通过监听scope下的这个roundProgressData属性, 对界面的canvas进行重绘;
$scope.$watch('roundProgressData', function (newValue) {
newValue.percentage = newValue.label / 100;
}, true);
});
</script> <script>
/*!
* AngularJS Round Progress Directive
*
* Copyright 2013 Stephane Begaudeau
* Released under the MIT license
*/
angular.module('angular.directives-round-progress', []).directive('angRoundProgress', [function () {
var compilationFunction = function (templateElement, templateAttributes, transclude) {
if (templateElement.length === 1) {
//初始化DOM模型, 包括初始化canvas等;
var node = templateElement[0]; var width = node.getAttribute('data-round-progress-width') || '400';
var height = node.getAttribute('data-round-progress-height') || '400'; var canvas = document.createElement('canvas');
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
canvas.setAttribute('data-round-progress-model', node.getAttribute('data-round-progress-model')); //相当于demo, 替换原来的元素;
node.parentNode.replaceChild(canvas, node); //各种配置;
var outerCircleWidth = node.getAttribute('data-round-progress-outer-circle-width') || '20';
var innerCircleWidth = node.getAttribute('data-round-progress-inner-circle-width') || '5'; var outerCircleBackgroundColor = node.getAttribute('data-round-progress-outer-circle-background-color') || '#505769';
var outerCircleForegroundColor = node.getAttribute('data-round-progress-outer-circle-foreground-color') || '#12eeb9';
var innerCircleColor = node.getAttribute('data-round-progress-inner-circle-color') || '#505769';
var labelColor = node.getAttribute('data-round-progress-label-color') || '#12eeb9'; var outerCircleRadius = node.getAttribute('data-round-progress-outer-circle-radius') || '100';
var innerCircleRadius = node.getAttribute('data-round-progress-inner-circle-radius') || '70'; var labelFont = node.getAttribute('data-round-progress-label-font') || '50pt Calibri'; return {
pre: function preLink(scope, instanceElement, instanceAttributes, controller) {
var expression = canvas.getAttribute('data-round-progress-model');
//监听模型, O了
//就监听一个属性;
scope.$watch(expression, function (newValue, oldValue) {
// Create the content of the canvas
//包括新建和重绘;
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, width, height); // The "background" circle
var x = width / 2;
var y = height / 2;
ctx.beginPath();
ctx.arc(x, y, parseInt(outerCircleRadius), 0, Math.PI * 2, false);
ctx.lineWidth = parseInt(outerCircleWidth);
ctx.strokeStyle = outerCircleBackgroundColor;
ctx.stroke(); // The inner circle
ctx.beginPath();
ctx.arc(x, y, parseInt(innerCircleRadius), 0, Math.PI * 2, false);
ctx.lineWidth = parseInt(innerCircleWidth);
ctx.strokeStyle = innerCircleColor;
ctx.stroke(); // The inner number
ctx.font = labelFont;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = labelColor;
ctx.fillText(newValue.label, x, y); // The "foreground" circle
var startAngle = - (Math.PI / 2);
var endAngle = ((Math.PI * 2 ) * newValue.percentage) - (Math.PI / 2);
var anticlockwise = false;
ctx.beginPath();
ctx.arc(x, y, parseInt(outerCircleRadius), startAngle, endAngle, anticlockwise);
ctx.lineWidth = parseInt(outerCircleWidth);
ctx.strokeStyle = outerCircleForegroundColor;
ctx.stroke();
}, true);
},
post: function postLink(scope, instanceElement, instanceAttributes, controller) {}
};
}
}; var roundProgress = {
//compile里面先对dom进行操作, 再对$socpe进行监听;
compile: compilationFunction,
replace: true
};
return roundProgress;
}]);
</script>
</body>
</html>
angular的canvas画图例子的更多相关文章
- SVG和canvas画图,js求数组最大最小值
windows命令行的内容怎么复制,右键选择标记,选中内容后再点击鼠标右键就复制了. 安装Node.js后再用npm install命令会出现如下warn:saveError ENOENT: no s ...
- 解决canvas画图模糊的问题
canvas 画图经常发现他是模糊的.解决这个问题主要从两个方面下手. 改变canvas渲染的像素情况:画1像素的线条看起来模糊不清,好像更宽的样子. 解决方案 var ctx = canvas.ge ...
- html5之canvas画图基础
HTML5+CSS3的好处是,你可以编写一个页面分别用于不同的平台,只需要设置不同的css样式就可以了,现在基本主流浏览器都支持全新的HTML5和CSS3,因为它的跨平台开发.因为是原生代码所以它的页 ...
- Canvas画图在360浏览器中跑偏的问题
问题描述,canvas画图的js代码中编写的是画正方形的代码,结果在360浏览器上变成了长方形,不知道怎么回事,请问各位大神是否遇到过此类问题? <!DOCTYPE html> <h ...
- h5 canvas 画图
h5 canvas 画图 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- html5 Canvas画图3:1px线条模糊问题
点击查看原文地址: html5 Canvas画图3:1px线条模糊问题 本文属于<html5 Canvas画图系列教程> 接上一篇canvas画线条教程 上次我们讲到,canvas有时候会 ...
- 使用 canvas 画图时图像文字模糊的解决办法
最近在使用 canvas 画图的时候,遇到了图像文字模糊的问题,解决思路就是根据分辨率创建不同尺寸的画布.以下是创建高分辨率画布的代码: /** * 创建高分辨率画布 * @param w 画布宽 * ...
- html5 canvas 画图移动端出现锯齿毛边的解决方法
使用HTML5的canvas元素画出来的.在移动端手机上测试都发现画图有一点锯齿问题 出现这个问题的原因应该是手机的宽是720像素的, 而这个canvas是按照小于720像素画出来的, 所以在720像 ...
- HTML5 canvas画图
HTML5 canvas画图 HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript).不过,<canvas> 元素本身并没有绘制能力(它仅仅是 ...
随机推荐
- android自定义radiobutton样式文字颜色随选中状态而改变
主要是写一个 color selector 在res/建一个文件夹取名color res/color/color_radiobutton.xml <selector xmlns:android= ...
- 使用EntityFramework6完成增删查改和事务
使用EntityFramework6完成增删查改和事务 上一节我们已经学习了如何使用EF连接数据库,并简单演示了一下如何使用EF6对数据库进行操作,这一节我来详细讲解一下. 使用EF对数据库进行操作, ...
- NPOI 读取excel到DataTable 读取隐藏列 读取公式列
处理思路: 1.打开excel 用NPOI进行读取: 2.读取第一个Sheet: 读取过程中: a.先设置相应列 不隐藏 b.读取Cell时 先判断是否的包含公式 相应代码如下: public sta ...
- RPC(远程过程调用)的应用
接触背景 因为工作上某项目的需要设计一种分布式处理耗时的运算,每个节点然后将运算结果返回给中心服务器,而最初未了解RPC这部分之前我的设计是在每一个RPC服务器上搭建一个webserver,然后部署运 ...
- runv start container 流程分析
1.runv/start.go func startContainer(context *cli.Context, container, address string, config *spec.Sp ...
- Java 嵌套解析 json
1.首先需要安装org.json.jar 2.类JSONObject用于创建一个json对象.其中的JSONObject.put(KEY, VALUE)用于向其中添加条目 3.JSONObject.g ...
- AC日记——热浪 codevs 1557 (最短路模板题)
1557 热浪 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...
- 关于phpmyadmin #1045无法登陆服务器的问题
修改/home/wwwroot/phpmyadmin/libraries/config.default.php 文件,找到下面两行 $cfg['Servers'][$i]['nopassword'] ...
- Flash相关知识
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" wid ...
- LINUX SSH显示中文乱码
ssh登陆后,执行: export LANG=zh_CN.gb2312就可以显示中文了.编辑/etc/sysconfig/i18n 将LANG="zh_CN.UTF-8" 改为 L ...