angular的canvas畫圖例子

angular的例子:

成都創(chuàng)新互聯(lián)公司主要從事做網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)冊亨,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792

運(yùn)行下面代碼

angular的canvas畫圖例子

<!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">
  <!--
    界面的這個(gè)元素會被替換成canvas元素;  -->
    <div ang:round:progress data-round-progress-model="roundProgressData"></div>
    <br>
    <input type="number" ng-model="roundProgressData.label"/>
    <script>
                                   //引用angular.directives-round-progress這個(gè)模塊;
     var APP = angular.module('APP', ['angular.directives-round-progress']).
     controller('MainCtrl', function($scope) {
        $scope.roundProgressData = {          //這個(gè)是初始化的數(shù)據(jù);          label: 11,
          percentage: 0.11
        }        //通過監(jiān)聽scope下的這個(gè)roundProgressData屬性, 對界面的canvas進(jìn)行重繪;        $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'));        //相當(dāng)于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');            //監(jiān)聽模型, O了
            //就監(jiān)聽一個(gè)屬性;          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進(jìn)行操作, 再對$socpe進(jìn)行監(jiān)聽;    compile: compilationFunction,
    replace: true
  };  return roundProgress;
}]);</script></body></html>

angular的canvas畫圖例子

 新航道雅思

本文題目:angular的canvas畫圖例子
本文路徑:http://muchs.cn/article28/ihdsjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站搜索引擎優(yōu)化、軟件開發(fā)、用戶體驗(yàn)、、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)