jmgraph 3.2.19 → 3.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +174 -2
  2. package/dist/jmgraph.core.min.js +1 -1
  3. package/dist/jmgraph.core.min.js.map +1 -1
  4. package/dist/jmgraph.js +1640 -135
  5. package/dist/jmgraph.min.js +1 -1
  6. package/index.js +13 -2
  7. package/package.json +1 -1
  8. package/src/core/jmGraph.js +453 -4
  9. package/src/core/jmLayer.js +142 -0
  10. package/src/core/jmPath.js +55 -0
  11. package/src/shapes/jmEllipse.js +91 -0
  12. package/src/shapes/jmLabel.js +127 -15
  13. package/src/shapes/jmPolygon.js +129 -0
  14. package/src/shapes/jmStar.js +160 -0
  15. package/example/ball.html +0 -217
  16. package/example/base.html +0 -112
  17. package/example/canvas.html +0 -54
  18. package/example/cell.html +0 -284
  19. package/example/controls/arc.html +0 -129
  20. package/example/controls/arrowline.html +0 -78
  21. package/example/controls/bezier.html +0 -299
  22. package/example/controls/img.html +0 -97
  23. package/example/controls/label.html +0 -87
  24. package/example/controls/line.html +0 -173
  25. package/example/controls/prismatic.html +0 -63
  26. package/example/controls/rect.html +0 -64
  27. package/example/controls/resize.html +0 -112
  28. package/example/controls/test.html +0 -360
  29. package/example/es.html +0 -70
  30. package/example/es5module.html +0 -63
  31. package/example/heartarc.html +0 -116
  32. package/example/index.html +0 -47
  33. package/example/js/require.js +0 -5
  34. package/example/love/img/bling/bling.tps +0 -265
  35. package/example/love/img/bling.json +0 -87
  36. package/example/love/img/bling.tps +0 -295
  37. package/example/love/img/doc/bling.gif +0 -0
  38. package/example/love/img/love.json +0 -95
  39. package/example/love/img/love.tps +0 -315
  40. package/example/love/img/qq/qq.tps +0 -399
  41. package/example/love/img/qq.json +0 -242
  42. package/example/love/index.html +0 -40
  43. package/example/love/js/game.js +0 -558
  44. package/example/music.html +0 -211
  45. package/example/node/test.js +0 -138
  46. package/example/pdf.html +0 -187
  47. package/example/progress.html +0 -173
  48. package/example/pso.html +0 -148
  49. package/example/sort.html +0 -805
  50. package/example/tweenjs.html +0 -84
  51. package/example/webgl.html +0 -278
  52. package/example/xfj/img/dr_die.gif +0 -0
  53. package/example/xfj/index.html +0 -332
  54. package/example/xfj/shake.js +0 -49
  55. package/example/xfj/testori.html +0 -76
@@ -1,211 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
6
- <title>music-jmgraph</title>
7
- <style>
8
- html,body{
9
- color: #9DA0AD;
10
- background-color: #272822;
11
- overflow: hidden;
12
- }
13
- </style>
14
- </head>
15
- <body>
16
- <div style="border-radius: 10px; border: 1px solid #ccc; box-shadow: #fff 0 0 10px; background-color: rgba(255,255,255,0.2); color:#000; width: 400px; height: 200px; position: fixed; top: 40%; left: 40%">
17
- <span>请选择音频文件</span> <br />
18
- <input type="file" id="my_sound" /> <br />
19
- <input type="checkbox" id="chk_loop" checked="true" /> <span>循环播放</span><br />
20
- <button id="btn_play">播放</button> <br />
21
- <span id="txtstatus"></span><br />
22
- </div>
23
- <canvas id="sound_canvas"></canvas>
24
- <script type="module">
25
- import jmGraph from "../index.js";
26
- (function(){
27
- //初始化jmgraph
28
- var graph = new jmGraph('sound_canvas', {
29
- mode: 'webgl',
30
- width: window.innerWidth,
31
- height: window.innerHeight * 0.95,
32
- });
33
-
34
- window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;
35
- //动画用到
36
- window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame;
37
-
38
- if(typeof window.AudioContext == 'undefined') {
39
- alert('不支持');
40
- return;
41
- }
42
- var audioContext = null;
43
- //音频容器
44
- var audioBufferSouceNode, analyser, currentAudioData = null;
45
-
46
- //读取音频文件
47
- window.readSound = function(file) {
48
- var fr = new FileReader();
49
- fr.onload = function(e) {
50
- //解码文件
51
- decodeAudio(e.target.result);
52
- //currentAudioData = e.target.result;
53
- }
54
- fr.readAsArrayBuffer(file);
55
- }
56
-
57
- //解码
58
- function decodeAudio(data) {
59
- if(!audioContext) {
60
- audioContext = new window.AudioContext();
61
- audioContext.onstatechange = function(e) {
62
- console.log(e);
63
- }
64
- }
65
-
66
- currentAudioData = data.slice(0);
67
-
68
- log('解码中...');
69
- audioContext.decodeAudioData(data, function(buffer){
70
- log('解码成功');
71
- play(buffer); //播放
72
- }, function(e){
73
- log('解码失败,' + e.message);
74
- });
75
- }
76
-
77
- //播放
78
- function play(buffer) {
79
- //如果 已在播放,则中止
80
- if(audioBufferSouceNode) {
81
- audioBufferSouceNode.stop();
82
- }
83
- //AudioBufferSourceNode
84
- audioBufferSouceNode = audioContext.createBufferSource();
85
- audioBufferSouceNode.buffer = buffer;
86
- audioBufferSouceNode.loop = document.getElementById('chk_loop').checked; // 循环
87
-
88
- audioBufferSouceNode.onended = function(e) {
89
- log('播放结束', e);
90
- }
91
- ////连接到扬声器
92
- //audioBufferSouceNode.connect(audioContext.destination);
93
- //处理频谱
94
- createAnalyser(audioBufferSouceNode);
95
- //开始播放
96
- audioBufferSouceNode.start(0);
97
- log('播放中');
98
- }
99
-
100
- //生成频谱分析
101
- function createAnalyser(souceNode) {
102
- if(analyser) {
103
- analyser.disconnect(audioContext.destination);
104
- }
105
- //频谱能量分析器
106
- analyser = audioContext.createAnalyser();
107
- souceNode.connect(analyser);
108
-
109
- //扬声器
110
- analyser.connect(audioContext.destination);
111
- }
112
-
113
- //画频谱能量图
114
- function drawAnalyserData() {
115
- if(analyser) {
116
- //获取频率能量值
117
- var array = new Uint8Array(analyser.frequencyBinCount);
118
- analyser.getByteFrequencyData(array);
119
- var arrper = 10;
120
- var count = Math.floor(array.length / arrper);
121
- //每个柱子的宽度
122
- var w = graph.width / count;
123
-
124
- var perh = graph.height / 300;
125
-
126
- for(var i=0;i<count; i++) {
127
- var start = i*arrper;
128
- var end = start + arrper;
129
- var arr = array.slice(start, end);
130
- var sum = 0;
131
- arr.forEach(p=>sum+=p);
132
-
133
- var h = perh * sum/arr.length;
134
- var bar = graph.children.get(i);
135
- var y = graph.height - h;
136
-
137
- if(!bar) {
138
- var x = i * (w + 4);
139
- bar = graph.createShape('rect', {
140
- position: {
141
- x, y
142
- },
143
- width: w,
144
- height: h,
145
- style: {
146
- //stroke: '#cccccc',
147
- // linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...)
148
- fill: '#B2F70D'//'linear-gradient(0 0 0 100%, #0D8E21 1, #B2F70D 0.5, #D6FA03 0)'
149
- }
150
- });
151
- graph.children.add(bar);
152
- }
153
- else {
154
- bar.height = h;
155
- }
156
- bar.position.y = y;
157
- }
158
-
159
- graph.redraw();
160
- }
161
- window.requestAnimationFrame(drawAnalyserData);
162
- }
163
-
164
- bindEvent();
165
-
166
- drawAnalyserData(analyser);//绘制漂亮的频谱图
167
-
168
- log('加载中mp3...');
169
- loadSoundFile('data/ringing_short.mp3', function(buffer) {
170
- //decodeAudio(buffer);
171
- currentAudioData = buffer;
172
- log('加载完成');
173
- });
174
-
175
- function bindEvent() {
176
- //选择文件
177
- document.getElementById('my_sound').onchange = function(e) {
178
- if(this.files.length) {
179
- var file = this.files[0];
180
- window.readSound(file);
181
- }
182
- }
183
- document.getElementById('btn_play').onclick = function(e) {
184
- if(currentAudioData) {
185
- decodeAudio(currentAudioData);
186
- }
187
- }
188
- }
189
- })();
190
-
191
-
192
- //获取远程音频文件
193
- function loadSoundFile(url,callback) {
194
- var request = new XMLHttpRequest();
195
- request.open('GET', url, true);
196
- request.responseType = 'arraybuffer';
197
- //音频获取
198
- request.onload = function() {
199
- var arraybuffer = request.response;
200
- callback && callback(arraybuffer);
201
- }
202
- request.send();
203
- }
204
-
205
- function log(msg) {
206
- document.getElementById('txtstatus').innerHTML = msg;
207
- console.log(...arguments);
208
- }
209
- </script>
210
- </body>
211
- </html>
@@ -1,138 +0,0 @@
1
- const fs = require('fs');
2
- const jmGraph = require("../../dist/jmgraph.js");
3
- const { createCanvas, Image, registerFont } = require('canvas');
4
-
5
- registerFont('msyh.ttf', { family: '微软雅黑' });
6
-
7
- const mycanvas = createCanvas(800, 600);
8
- console.log(mycanvas.type);
9
- const g = jmGraph.create(mycanvas, {
10
- width: 800,
11
- height: 600,
12
- mode: '2d',
13
- style: {
14
- fill: '#000'
15
- }
16
- });
17
- init(g);
18
-
19
- const img = new Image();
20
- img.onload = () => {
21
- //创建一个image
22
- var imgControl = g.createShape('image',{
23
- style: {
24
- shadow: '0,0,10,#fff'
25
- },
26
- position: {x:300, y:300},
27
- image: img
28
- });
29
- g.children.add(imgControl);
30
-
31
- saveToImage();
32
- }
33
- img.onerror = err => { throw err }
34
- img.src = 'https://mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png'
35
-
36
- // 导出为图片
37
- function saveToImage() {
38
- g.redraw();
39
- const out = fs.createWriteStream(__dirname + '/test.png');
40
- const stream = mycanvas.createPNGStream();
41
- stream.pipe(out);
42
- out.on('finish', () => console.log('The PNG file was created.'));
43
- }
44
-
45
- function init(g){
46
- g.style.fill = '#000'; //画布背景
47
- var style = {
48
- stroke:'#46BF86',
49
- fill: '#556662',
50
- lineWidth: 1.5
51
- };
52
- style.shadow = '0,0,10,#fff';
53
- style.opacity = 0.2;
54
- //style.lineCap = 'round';
55
-
56
- //创建一个方块
57
-
58
- var rect = g.createShape('rect',{
59
- style:style,
60
- position: {x:300,y:100},
61
- width:100,
62
- height:100
63
- });
64
-
65
- var rect2 = g.createShape('rect',{
66
- style:style,
67
- position: {x:'50%',y:'50%'},
68
- width:50,
69
- height:50
70
- });
71
- rect.children.add(rect2);
72
-
73
- g.children.add(rect);
74
- rect.canMove(true);
75
-
76
- // 画二个五角星
77
- var coordinates = [
78
- {x:50,y:100},
79
- {x:250,y:100},
80
- {x:250,y:50},
81
- {x:300,y:200},
82
- {x:200,y:200},
83
- {x:50,y:300},
84
- ];
85
- style = g.utils.clone(style);
86
- var star1 = g.createShape('path',{
87
- style:style,
88
- points: coordinates
89
- });
90
- g.children.add(star1);
91
- star1.canMove(true);
92
-
93
- var coordinates2 = [
94
- {x:50,y:300},
95
- {x:250,y:300},
96
- {x:100,y:350},
97
- {x:150,y:250},
98
- {x:200,y:350},
99
- {x:50,y:300},
100
- ];
101
- style = g.utils.clone(style);
102
- delete style.fill;
103
- var star2 = g.createShape('path',{
104
- style:style,
105
- points: coordinates2
106
- });
107
- g.children.add(star2);
108
-
109
- style = {
110
- stroke: '#effaaa',
111
- fill: '#fff',
112
- textAlign: 'right',
113
- textBaseline: 'middle',
114
- font: '24px "微软雅黑"', // 需要加载字体
115
- border: {
116
- left:1,
117
- top:1,
118
- right:1,
119
- bottom:1,
120
- style: {
121
- stroke: 'red'
122
- }
123
- },
124
- shadow: '0,0,10,#fff'
125
- };
126
- //style.opacity = 0.2;
127
-
128
- //创建一个label
129
- var label = g.createShape('label',{
130
- style:style,
131
- //position:{x:200,y:150},
132
- center: {x: 250, y: 250},
133
- text:'test label 中文',
134
- //width:120,
135
- height:80
136
- });
137
- g.children.add(label);
138
- }
package/example/pdf.html DELETED
@@ -1,187 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- html,body{
8
- margin:0;
9
- padding: 0;
10
- }
11
- #mycanvas_container{
12
- overflow: hidden;
13
- }
14
- </style>
15
-
16
- <script type="text/javascript" src="//jtcospublic.ciccten.com/public/pdfjs/pdf.min.js"></script>
17
- </head>
18
- <body>
19
- <div id="mycanvas_container"></div>
20
- </body>
21
- <script type="module">
22
- import jmGraph from "../index.js";
23
-
24
- var pdfDocument, pdfImage;
25
-
26
- var container = document.getElementById('mycanvas_container');
27
-
28
- init();
29
-
30
- function init(g){
31
-
32
- // 初始化pdf组件 这里的worker请下到你站点内,不能跨域
33
- pdfjsLib.GlobalWorkerOptions.workerSrc = '//jtcospublic.ciccten.com/public/pdfjs/pdf.worker.min.js';//'//qian-img.tenpay.com/static/pdfjs/pdf.worker.min.js';
34
- loadPdf('//qian-img.tenpay.com/resources/vtools/img/201906/20ff3e6197e118dcb82fac4cf5a5feeb.pdf');
35
- }
36
-
37
- // 加载PDF
38
- async function loadPdf(url) {
39
- const pdf = await pdfjsLib.getDocument(url).promise;
40
-
41
- if (pdf.numPages > 0) {
42
- for (var i = 0; i < pdf.numPages; i++) {
43
- await renderPage(pdf, i);// 默认打开第一页
44
- }
45
- }
46
- }
47
- // 打开当前PDF指定页
48
- async function renderPage(pdf, page) {
49
- const canvas = document.createElement('canvas');
50
- canvas.style.width = '100%';
51
- container.appendChild(canvas);
52
-
53
- const pageInstance = await pdf.getPage(page + 1);
54
-
55
- const scale = 1;
56
- const viewport = pageInstance.getViewport({
57
- scale
58
- });
59
-
60
- const context = canvas.getContext('2d');
61
-
62
- canvas.height = viewport.height || viewport.viewBox[3]; /* viewport.height is NaN */
63
-
64
- canvas.width = viewport.width || viewport.viewBox[2]; /* viewport.width is also NaN */
65
-
66
- //
67
- // Render PDF page into canvas context
68
- //
69
- const renderContext = {
70
- canvasContext: context,
71
- viewport: viewport
72
- };
73
-
74
-
75
- await pageInstance.render(renderContext).promise;
76
-
77
- initGraph(canvas);
78
- }
79
-
80
- // 初始化当前页,并改造支持放大缩小
81
- function initGraph(canvas) {
82
- const el = new Image();
83
-
84
- el.onload = () => {
85
- const width = canvas.clientWidth || canvas.offsetWidth;
86
- const height = canvas.clientHeight || canvas.offsetHeight;
87
-
88
- const g = new jmGraph(canvas, {
89
- width,
90
- height,
91
- autoRefresh: true // 自动刷新
92
- });
93
- const img = g.createShape('image', {
94
- //sourcePosition: {x: 0, y: 0},
95
- //sourceWidth: width,
96
- //sourceHeight: height,
97
- position: {x: 0, y: 0},
98
- width: '100%',
99
- height: '100%',
100
- image: el
101
- });
102
-
103
- //img.canMove(true);
104
-
105
- // 初始化缩放属性
106
- img.transform = {
107
- scaleX: 1,
108
- scaleY: 1,
109
- skewX: 0,
110
- skewY: 0,
111
- offsetX: 0,
112
- offsetY: 0
113
- };
114
-
115
- let prePosition;
116
- g.on('touchstart', (e) => {
117
- console.log('touchstart', e.position);
118
- // 二个手指滑动
119
- if(e.position?.touches?.length === 2) {
120
- prePosition = e.position;
121
- }
122
- });
123
-
124
- g.on('touchmove', (e) => {
125
- //console.log('touchmove', prePosition, e.position);
126
- if(e.position?.touches?.length !== 2) return;
127
-
128
- e.event?.stopPropagation();
129
- e.event?.preventDefault();
130
-
131
- // 没有上一个滑动,则这次就当上次
132
- if(!prePosition) {
133
- prePosition = e.position;
134
- return;
135
- }
136
-
137
- //上次滑动二指的距离
138
- const preOffX = prePosition.touches[0].pageX - prePosition.touches[1].pageX;
139
- const preOffY = prePosition.touches[0].pageY - prePosition.touches[1].pageY;
140
- const preDis = Math.sqrt(preOffX * preOffX + preOffY * preOffY);
141
- //当次滑动二指的距离
142
- const curOffX = e.position.touches[0].pageX - e.position.touches[1].pageX;
143
- const curOffY = e.position.touches[0].pageY - e.position.touches[1].pageY;
144
- const curDis = Math.sqrt(curOffX * curOffX + curOffY * curOffY);
145
-
146
- // 如果二指移动距离小于1,则认为是在移动图片,不缩放
147
- if(Math.abs(preDis - curDis) < 0.05) {
148
- img.offset(e.position.touches[0].pageX - prePosition.touches[0].pageX,
149
- e.position.touches[0].pageY - prePosition.touches[0].pageY);
150
- }
151
- else {
152
- const disx = Math.abs(preOffX - curOffX) / width;//x轴滑行的距离
153
- const disy = Math.abs(preOffY - curOffY) / height;//y轴滑行的距离
154
-
155
- let offScale = Math.max(disx, disy);
156
-
157
- console.log('offScale1', offScale);
158
-
159
- offScale = img.transform.scaleX * (curDis > preDis? (1+offScale): (1-offScale));
160
-
161
- console.log('offScale2', offScale);
162
-
163
- img.transform.scaleX = img.transform.scaleY = offScale;
164
-
165
- const imgBounds = img.getBounds();
166
-
167
- img.transform.offsetX = (g.width - imgBounds.width * offScale) / 2;
168
- img.transform.offsetY = (g.height - imgBounds.height * offScale) / 2;
169
-
170
- console.log('transform', img.transform);
171
- }
172
- img.needUpdate = true;
173
- prePosition = e.position;
174
-
175
- return false;
176
- });
177
-
178
- g.on('touchend touchcancel touchleave', (e) => {
179
- prePosition = null;
180
- });
181
-
182
- g.children.add(img);
183
- };
184
- el.src = canvas.toDataURL('image/png');
185
- }
186
- </script>
187
- </html>
@@ -1,173 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- </head>
7
- <body style="margin:10px auto;">
8
- <div id="mycanvas" width="1200" height="600" style="border:1px solid red;margin:10px;background-color:#000; display:inline-block;"></div>
9
- </body>
10
- </html>
11
-
12
- <script type="module">
13
- import * as jmGraph from "../index.js";
14
- //初始化jmgraph
15
- var g = jmGraph.create('mycanvas', {
16
- width: 800,
17
- height: 600,
18
- mode: 'webgl'
19
- });
20
-
21
- //实时更新画布
22
- function update() {
23
- if(g.needUpdate) g.redraw();
24
- requestAnimationFrame(update);
25
- }
26
- update();
27
-
28
- init(g);
29
-
30
- function init(graph){
31
- var style = {
32
- stroke:'rgb(120,20,80)',
33
- lineWidth:6,
34
- close:true,
35
- zIndex:1
36
- };
37
- var bg = graph.createRadialGradient('50%','50%',0,'50%','50%','50%');
38
- bg.addStop(0,'green');
39
- bg.addStop('0.2','blue');
40
- bg.addStop(0.8,'yellow');
41
- bg.addStop(1,'red');
42
- style.fill = 'radial-gradient(50% 50% 0 50% 50% 50%, green 0,blue 0.2, yellow 0.8, red 1)';
43
- style.shadow = graph.createShadow(0,0,20,'rgb(255,255,255)');
44
- var arc = graph.createShape('arc',{style:style,center:{x:250,y:250},width:200,height: 200,start:0,end:Math.PI * 2});
45
-
46
- arc.bind('mouseover',function(evt) {
47
- this.style.stroke = 'rgba(88,200,155,0.5)';
48
- });
49
- arc.bind('mouseleave',function(evt) {
50
- this.style.stroke = 'rgb(120,20,80)';
51
- });
52
-
53
- //arc.bind('touchstart',function(evt) {
54
- //this.style.stroke = 'rgba(88,200,155,0.5)';
55
- //graph.refresh();
56
- //});
57
-
58
- graph.children.add(arc);
59
- arc.canMove(true);
60
-
61
- style = g.util.clone(style);
62
- style.stroke = 'rgb(255,255,255)';
63
- style.close=false;
64
- style.zIndex = 3;
65
- delete style.shadow;
66
- delete style.fill;
67
-
68
- var step = Math.PI / 25;
69
- var bluestop = 0.5;
70
- var bluedir = 0;
71
- var yellowstop = 0.8;
72
- var yellowdir = 0;
73
- var childarc = graph.createShape('arc',{style:style,center:{x:arc.width / 2,y:arc.height / 2},start:0,end: Math.PI / 3,radius:arc.width / 2,anticlockwise:false});
74
-
75
- style = g.util.clone(style);
76
- style.close = true;
77
- style.lineWidth = 1.1;
78
- style.fill = 'red';
79
- style.zIndex = 4;
80
- var harc = graph.createShape('harc',{style:style, center:{x:600,y:380}, startAngle:0, endAngle: Math.PI * 2, minRadius:100, maxRadius:150, anticlockwise:false});
81
- graph.children.add(harc);
82
-
83
- function arcAni() {
84
- var s=childarc.startAngle + step;
85
- var e = childarc.endAngle + step;
86
- if(s > Math.PI * 2) {
87
- s = 0;
88
- e = Math.PI / 3;
89
- }
90
- childarc.startAngle = s;
91
- childarc.endAngle = e;
92
- harc.endAngle = s;
93
-
94
-
95
- if(bluestop >= yellowstop) {
96
- bluedir = 1;
97
- //return false;
98
- }
99
- else if(bluestop < 0.1) {
100
- bluedir = 0;
101
- }
102
- bluestop = bluedir == 0?bluestop + 0.01:bluestop-0.01;
103
-
104
- arc.style.fill='radial-gradient(50% 50% 0 50% 50% 50%, green 0,blue '+bluestop+', yellow '+yellowstop+', red 1)';
105
- graph.needUpdate = true;
106
- }
107
- arc.children.add(childarc);
108
- childarc.animate(arcAni, 10);
109
-
110
-
111
- harc.canMove(true);
112
-
113
-
114
- //画一个进度显示
115
- var w = 100;
116
- var h = 100;
117
- var forceColor = '#037CFC';
118
- //先画底层圆
119
- var style = {
120
- stroke: '#efeff4',
121
- lineWidth: 4,
122
- close: true,
123
- zIndex: 1
124
- };
125
- var radius = (w - style.lineWidth) / 2 - 1;
126
- var bgarc = graph.createShape('circle', {
127
- style: style,
128
- center: { x: 120, y: 120 },
129
- radius: radius,
130
- start: 0,
131
- end: Math.PI * 2
132
- });
133
-
134
- style = graph.util.clone(style);
135
- style.stroke = forceColor;
136
- delete style.close; //进度圆不需要封闭
137
- var progressArc = graph.createShape('arc', {
138
- style: style,
139
- center: { x: '50%', y: '50%' },
140
- start: -Math.PI / 2,
141
- end: -Math.PI / 2,
142
- radius: radius,
143
- anticlockwise: false
144
- });
145
- graph.children.add(bgarc);
146
- bgarc.children.add(progressArc);
147
-
148
- style = graph.util.clone(style);
149
- style.fill = forceColor
150
- style.textAlign = 'center';
151
- style.textBaseline = 'middle';
152
- style.font = '22px Arial';
153
- //创建一个label
154
- var progressLabel = graph.createShape('label', {
155
- style: style,
156
- position: { x: 0, y: 0 },
157
- text: '0%',
158
- width: w,
159
- height: h
160
- });
161
- bgarc.children.add(progressLabel);
162
-
163
- //改变进度
164
- var curprogress = 0;
165
- setInterval(function(){
166
- progressArc.endAngle = curprogress/100 * Math.PI * 2 + progressArc.startAngle;//当前进度应该转到的角度
167
- progressLabel.text = Math.ceil(curprogress) + '%';
168
-
169
- curprogress++;
170
- if(curprogress >= 100) curprogress = 0;
171
- }, 100);
172
- }
173
- </script>