jmgraph 3.2.18 → 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 (57) 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 +1672 -147
  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 +460 -5
  9. package/src/core/jmLayer.js +142 -0
  10. package/src/core/jmPath.js +55 -0
  11. package/src/lib/webgl/base.js +6 -0
  12. package/src/lib/webgl/path.js +8 -11
  13. package/src/shapes/jmEllipse.js +91 -0
  14. package/src/shapes/jmLabel.js +127 -15
  15. package/src/shapes/jmPolygon.js +129 -0
  16. package/src/shapes/jmStar.js +160 -0
  17. package/example/ball.html +0 -217
  18. package/example/base.html +0 -112
  19. package/example/canvas.html +0 -54
  20. package/example/cell.html +0 -284
  21. package/example/controls/arc.html +0 -129
  22. package/example/controls/arrowline.html +0 -78
  23. package/example/controls/bezier.html +0 -299
  24. package/example/controls/img.html +0 -97
  25. package/example/controls/label.html +0 -87
  26. package/example/controls/line.html +0 -173
  27. package/example/controls/prismatic.html +0 -63
  28. package/example/controls/rect.html +0 -64
  29. package/example/controls/resize.html +0 -112
  30. package/example/controls/test.html +0 -360
  31. package/example/es.html +0 -70
  32. package/example/es5module.html +0 -63
  33. package/example/heartarc.html +0 -116
  34. package/example/index.html +0 -47
  35. package/example/js/require.js +0 -5
  36. package/example/love/img/bling/bling.tps +0 -265
  37. package/example/love/img/bling.json +0 -87
  38. package/example/love/img/bling.tps +0 -295
  39. package/example/love/img/doc/bling.gif +0 -0
  40. package/example/love/img/love.json +0 -95
  41. package/example/love/img/love.tps +0 -315
  42. package/example/love/img/qq/qq.tps +0 -399
  43. package/example/love/img/qq.json +0 -242
  44. package/example/love/index.html +0 -40
  45. package/example/love/js/game.js +0 -558
  46. package/example/music.html +0 -211
  47. package/example/node/test.js +0 -138
  48. package/example/pdf.html +0 -187
  49. package/example/progress.html +0 -173
  50. package/example/pso.html +0 -148
  51. package/example/sort.html +0 -805
  52. package/example/tweenjs.html +0 -84
  53. package/example/webgl.html +0 -278
  54. package/example/xfj/img/dr_die.gif +0 -0
  55. package/example/xfj/index.html +0 -332
  56. package/example/xfj/shake.js +0 -49
  57. package/example/xfj/testori.html +0 -76
package/example/cell.html DELETED
@@ -1,284 +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
- <!--<script type="text/javascript" src="../src/jmGraph.js"></script>
7
- <script type="text/javascript" src="../dist/jmGraph.min.js"></script> -->
8
- <style>
9
- html,body {
10
- margin:0;
11
- padding:0;
12
- width:100%;
13
- height:100%;
14
- overflow: hidden;
15
- }
16
- #mycanvas {
17
- background-color:#000;
18
- position: absolute;
19
- width: 100%;
20
- height: 100%;
21
- }
22
- </style>
23
-
24
- </head>
25
- <body >
26
- <div id="mycanvas">
27
- </div>
28
-
29
- </body>
30
- </html>
31
-
32
- <script type="module">
33
- import jmGraph from "../index.js";
34
- var graph;
35
- var balls = [];
36
- //初始化jmgraph
37
- var graph = new jmGraph('mycanvas', {
38
- mode: 'webgl'
39
- });
40
- graph.util.bindEvent(window,'resize',resize);
41
-
42
- refreshBall(graph);
43
-
44
- //实时更新画布
45
- function update() {
46
- if(graph.needUpdate) graph.redraw();
47
- graph.requestAnimationFrame(update);
48
- }
49
- update();
50
-
51
- function createPosition(radius,i) {
52
- var canvas = document.getElementById('mycanvas');
53
- var x = Math.random() * graph.width + radius;
54
- var y = Math.random() * graph.height + radius;
55
-
56
- for(var j=i+1;j<balls.length;j++) {
57
- var b2= balls[j];
58
- var lx = Math.abs(x - b2.x());
59
- var ly = Math.abs(y - b2.y());
60
- var l = Math.sqrt(lx * lx + ly * ly);
61
- //如果二个球重叠则放 弃当前球
62
- if(l < radius + b2.radius) {
63
- return createPosition(radius);
64
- }
65
- }
66
- return {x:x,y:y};
67
- }
68
-
69
- function createCell(x,y,r,style) {
70
- var c = new cell(graph,x,y,r,style);
71
- balls.push(c);
72
- return c;
73
- }
74
-
75
- function refreshBall(g) {
76
-
77
- var style = {
78
- lineWidth:1,
79
- close:true
80
- };
81
-
82
- resize();
83
-
84
- style.shadow = graph.createShadow(0,0,20,'#000');
85
-
86
-
87
-
88
- style.fill = graph.createRadialGradient('50%','50%',0,'50%','50%','50%');
89
- //var rr1 = Math.floor(Math.random() * 255);
90
- //var gg1 = Math.floor(Math.random() * 255);
91
- //var bb1 = Math.floor(Math.random() * 255);
92
- //var rr2 = Math.floor(Math.random() * 255);
93
- //var gg2 = Math.floor(Math.random() * 255);
94
- //var bb2 = Math.floor(Math.random() * 255);
95
- style.fill.addStop(0,'rgb(112,154,22)');
96
- style.fill.addStop(1,'rgb(49,95,118)');
97
-
98
- var count = 100;
99
-
100
- for(var i=0; i<count; i++) {
101
- var radius = Math.random() * 10 + 4;
102
-
103
- var p = createPosition(radius);
104
- var b = createCell(p.x, p.y, radius, style);
105
- b.vx = Math.random() - Math.random();
106
- b.vy = Math.random() - Math.random();
107
- }
108
-
109
-
110
- //var radius = Math.random() * 10 + 6;
111
- var styletmp = graph.util.clone(style);
112
- styletmp.fill = graph.createRadialGradient('50%','50%',0,'50%','50%','50%');
113
- styletmp.fill.addStop(0,'rgb(255,255,255)');
114
- styletmp.fill.addStop(1,'rgb(255,149,255)');
115
-
116
- //主体细胞
117
- var myCell = createCell(graph.width / 2,graph.height / 2,14,styletmp);//new cell(graph,graph.width() / 2,graph.height() / 2,10,styletmp);
118
-
119
- //balls.push(myCell);
120
-
121
- graph.bind('click',function(evt) {
122
- var x = evt.position.x;
123
- var y = evt.position.y;
124
- myCell.go(x,y);
125
- return false;
126
- });
127
-
128
- function animate() {
129
- var bs = balls;
130
- var len = bs.length;
131
- //var mvx = 0;
132
- //var mvy = 0;
133
- for(var i=0;i<len;i++) {
134
- var b1 = bs[i];
135
- if(!b1 || !b1.visible) continue;
136
- b1.vx += b1.ax;
137
- b1.vy += b1.ay;
138
- for(var j=i+1;j<len;j++) {
139
- var b2= bs[j];
140
- if(!b2 || !b2.visible) continue;
141
- var lx = b1.x() - b2.x();
142
- var ly = b1.y() - b2.y();
143
- var l = Math.sqrt(lx * lx + ly * ly);
144
- var lr = b1.radius() + b2.radius();
145
- var dr = (lr - l) / 2;
146
- if(dr > 0) {
147
- var vx = b1.vx;
148
- var vy = b1.vy;
149
- var vxb = b2.vx;
150
- var vyb = b2.vy;
151
-
152
- var bigB,smallB;
153
- var smallindex = i;
154
- if(b1.radius() > b2.radius()) {
155
- bigB = b1;
156
- smallB = b2;
157
- smallindex = j;
158
- }
159
- else {
160
- bigB = b2;
161
- smallB = b1;
162
- }
163
-
164
- var smr = smallB.radius() - dr;
165
- var darea = 0;
166
- if(smr > 0) {
167
- darea = smallB.radius() * smallB.radius() - smr * smr;
168
- smallB.radius(smr);
169
- }
170
- else {
171
- darea = smallB.radius() * smallB.radius();
172
- dr = smallB.radius();
173
- smallB.visible(false);
174
- balls.splice(smallindex,1);
175
- }
176
- var bigr = Math.sqrt(bigB.radius() * bigB.radius() + darea);
177
-
178
- bigB.vx = (bigB.radius() * bigB.vx + dr * smallB.vx) / bigr;
179
- bigB.vy = (bigB.radius() * bigB.vy + dr * smallB.vy) / bigr;
180
- bigB.radius(bigr);
181
-
182
- }
183
- }
184
-
185
- if(!b1.visible) continue;
186
- var x = b1.x() + b1.vx;
187
- var maxX = b1.graph.width - b1.radius();
188
- if(x <= b1.radius() || x >= maxX) {
189
- //b1.vy -= 0.4;
190
- b1.vx *= -1;
191
- }
192
- x = Math.max(x,b1.radius());
193
- x = Math.min(maxX,x);
194
- b1.x(x);
195
- var y = b1.y() + b1.vy;
196
- var maxY = b1.graph.height - b1.radius();
197
- if(y <= b1.radius() || y >= maxY) {
198
- //if(y >= maxY && b1.vy > 0) {b1.vy -= 1;b1.vx -= 0.4;}
199
- b1.vy *= -1;
200
- }
201
- y = Math.max(y,b1.radius());
202
- y = Math.min(maxY,y);
203
- b1.y(y);
204
- }
205
- graph.needUpdate = true;
206
- setTimeout(animate,20);
207
- };
208
- animate();
209
- }
210
- function resize() {
211
- //canvas.width = window.innerWidth;
212
- //canvas.height = window.innerHeight;
213
-
214
- if(graph) {
215
- graph.width = document.getElementById('mycanvas').clientWidth;
216
- graph.height = document.getElementById('mycanvas').clientHeight;
217
- graph.needUpdate = true;
218
- }
219
- }
220
-
221
- function cell(graph, x, y, radius, style) {
222
- this.graph = graph;
223
-
224
- this.center = {x:x,y:y};
225
- this.shape = graph.createShape('circle',{style:style,center:this.center,radius:radius,anticlockwise:true});
226
- graph.children.add(this.shape);
227
-
228
- this.vx = 0;
229
- this.vy = 0;
230
- this.ax = 0;
231
- this.ay = 0;
232
-
233
- this.go = function(x,y) {
234
- var r = this.radius();
235
- if(r <= 4) return;
236
-
237
- var myx = this.x();
238
- var myy = this.y();
239
-
240
- var dx = x - myx;
241
- var dy = y - myy;
242
- var dp = Math.sqrt(dx * dx + dy * dy);
243
- var vx = dx / dp * 1;
244
- var vy = dy / dp * 1;
245
- var px = myx + vx * (r + 4);
246
- var py = myy + vy * (r + 4);
247
-
248
- var mc = createCell(px,py,1,style);
249
- mc.vx = vx;
250
- mc.vy = vy;
251
-
252
- var radius = Math.sqrt(r * r - mc.radius() * mc.radius());
253
- this.radius(radius);
254
-
255
- this.vx = (this.vx * r - mc.vx * mc.radius()) / this.radius();
256
- this.vy = (this.vy * r - mc.vy * mc.radius()) / this.radius();
257
-
258
- this.graph.needUpdate = true;
259
- }
260
- this.x = function(x) {
261
- if(typeof x !== 'undefined') this.center.x = x;
262
- return this.center.x;
263
- }
264
- this.y = function(y) {
265
- if(typeof y !== 'undefined') this.center.y = y;
266
- return this.center.y;
267
- }
268
-
269
- this.radius = function(r) {
270
- if(typeof r == 'undefined') return this.shape.radius;
271
- return this.shape.radius = r;
272
- }
273
- this.visible = function(v) {
274
- if(typeof v !== 'undefined') {
275
- this.shape.visible = v;
276
- if(!v) {
277
- this.graph.children.remove(this.shape);
278
- }
279
- }
280
- return this.shape.visible;
281
- }
282
- }
283
-
284
- </script>
@@ -1,129 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
5
-
6
- <meta name="viewport" content="width=device-width,initial-scale=1">
7
-
8
- <style>
9
- html,body{
10
- margin:0;
11
- padding: 0;
12
- overflow: auto;
13
- }
14
- #mycanvas_container{
15
- overflow: scroll;
16
- }
17
- </style>
18
- </head>
19
- <body>
20
- <div id="mycanvas_container"></div>
21
- </body>
22
- <script type="module">
23
- import jmGraph from "../../index.js";
24
- var container = document.getElementById('mycanvas_container');
25
-
26
- //开发模式下,引用jmGraph.js,请使用这种方式,内部会初始化组件
27
- var g = jmGraph.create('mycanvas_container', {
28
- width: 800,
29
- height: 600,
30
- mode: '2d',
31
- autoRefresh: true,
32
- style: {
33
- fill: '#000'
34
- }
35
- });
36
-
37
- init(g);
38
-
39
-
40
- function init(g){
41
- //g.style.fill = '#000'; //画布背景
42
- var style = {
43
- stroke: '#ccc',
44
- fill: 'yellow',
45
- lineWidth: 4, //边线宽
46
- rotation: {
47
- angle: 0
48
- }
49
- };
50
- //style.opacity = 0.2;
51
-
52
- //创建一个椭圆
53
- var arc1 = g.createShape('arc', {
54
- style: style,
55
- center: {x:100, y:150},
56
- width: 120,
57
- height: 80
58
- });
59
- g.children.add(arc1);
60
- arc1.canMove(true);
61
-
62
-
63
-
64
- //实圆
65
- style = g.util.clone(style);
66
- style.stroke = 'red';
67
- //创建一个全圆
68
- var arc2 = g.createShape('arc', {
69
- style: style,
70
- center: {x:280, y:150},
71
- radius: 50
72
- });
73
- g.children.add(arc2);
74
-
75
- //圆弧
76
- style = g.util.clone(style);
77
- style.stroke = 'green';
78
- delete style.fill;//圆弧不设为实心
79
- //创建一个圆弧
80
- var arc3 = g.createShape('arc', {
81
- style: style,
82
- center: {x:400, y:150},
83
- start: 0,
84
- end: Math.PI / 2,
85
- radius: 50
86
- });
87
-
88
- g.children.add(arc3);
89
- var arc4 = g.createShape('arc', {
90
- style: style,
91
- center: {x:540, y:150},
92
- start: 0,
93
- end: Math.PI / 2,
94
- radius: 50,
95
- anticlockwise: true //顺时针
96
- });
97
- g.children.add(arc4);
98
-
99
- //这种个是直接调用canvas画的,性能会好一点
100
- var circle = g.createShape('circle', {
101
- style: style,
102
- center: {x:200, y:400},
103
- radius: 50
104
- });
105
- g.children.add(circle);
106
-
107
- //圆环
108
- style = g.util.clone(style);
109
- style.fill = 'blue';
110
- style.close = true; //如果是满圆,即end = Math.PI*2 时,把这个设为false
111
- var harc = g.createShape('harc', {
112
- style: style,
113
- center: {x:400, y:400},
114
- minRadius: 40,
115
- maxRadius: 80,
116
- start: 0,
117
- end: Math.PI / 4,
118
- anticlockwise: true //false 顺时针,true 逆时针
119
- });
120
- g.children.add(harc);
121
- harc.canMove(true);
122
-
123
- g.on('update', (time) => {
124
- style.rotation.angle += 0.01;
125
- g.needUpdate = true;
126
- });
127
- }
128
- </script>
129
- </html>
@@ -1,78 +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
- </head>
16
- <body>
17
- <div id="mycanvas_container"></div>
18
- </body>
19
- <script type="module">
20
- import jmGraph from "../../index.js";
21
- var container = document.getElementById('mycanvas_container');
22
-
23
- //开发模式下,引用jmGraph.js,请使用这种方式,内部会初始化组件
24
- var g = jmGraph.create('mycanvas_container', {
25
- width: 800,
26
- height: 600,
27
- mode: 'webgl',
28
- style: {
29
- fill: '#000'
30
- }
31
- });
32
-
33
- init(g);
34
-
35
- function init(g){
36
- //g.style.fill = '#000'; //画布背景
37
- var style = {
38
- lineType: 'dotted', //虚线
39
- dashLength: 10,
40
- stroke: '#48EA08'
41
- };
42
- style.shadow = '0,0,10,#fff';
43
- //style.opacity = 0.2;
44
-
45
- //创建
46
- var shape = g.createShape('arrowline',{
47
- style:style,
48
- start: {x:100,y:100},
49
- end: {x: 200, y: 350}
50
- //height:100
51
- });
52
-
53
- g.children.add(shape);
54
-
55
- style = g.util.clone(style);
56
- style.fill = '#48EA08'; //实心箭头
57
- //创建
58
- //一起结束点和一个角度angle可以决定一个箭头,如果不填angle,则会用start和end来计算角度
59
- var arrow = g.createShape('arrow',{
60
- style:style,
61
- start: {x:150, y:120},
62
- end: {x: 160, y: 150},
63
- //angle: Math.PI/2, //箭头角度 可以不填
64
- //offsetX: 5, //箭头X偏移量
65
- //offsetY: 8 //箭头Y偏移量
66
- });
67
-
68
- g.children.add(arrow);
69
-
70
- function update() {
71
- g.redraw();
72
- //requestAnimationFrame(update);
73
- }
74
-
75
- update();
76
- }
77
- </script>
78
- </html>