jmgraph 3.2.16 → 3.2.18
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.
- package/LICENSE +21 -21
- package/README.md +251 -428
- package/build/gulpfile.js +142 -142
- package/build/package-lock.json +10666 -0
- package/build/package.json +71 -71
- package/dev.js +9 -9
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3500 -2668
- package/dist/jmgraph.min.js +1 -1
- package/example/ball.html +216 -216
- package/example/base.html +111 -111
- package/example/canvas.html +53 -53
- package/example/cell.html +283 -283
- package/example/controls/arc.html +128 -128
- package/example/controls/arrowline.html +77 -77
- package/example/controls/bezier.html +298 -298
- package/example/controls/img.html +96 -96
- package/example/controls/label.html +86 -86
- package/example/controls/line.html +172 -172
- package/example/controls/prismatic.html +62 -62
- package/example/controls/rect.html +63 -63
- package/example/controls/resize.html +111 -111
- package/example/controls/test.html +359 -359
- package/example/es.html +69 -69
- package/example/es5module.html +62 -63
- package/example/heartarc.html +115 -115
- package/example/index.html +46 -46
- package/example/js/require.js +4 -4
- package/example/love/img/bling/bling.tps +265 -265
- package/example/love/img/bling.json +87 -87
- package/example/love/img/bling.tps +295 -295
- package/example/love/img/love.json +95 -95
- package/example/love/img/love.tps +315 -315
- package/example/love/img/qq/qq.tps +399 -399
- package/example/love/img/qq.json +242 -242
- package/example/love/index.html +40 -40
- package/example/love/js/game.js +558 -558
- package/example/music.html +210 -210
- package/example/node/test.js +137 -137
- package/example/pdf.html +186 -186
- package/example/progress.html +172 -172
- package/example/pso.html +147 -147
- package/example/sort.html +804 -815
- package/example/tweenjs.html +83 -83
- package/example/webgl.html +278 -278
- package/example/xfj/index.html +331 -331
- package/example/xfj/shake.js +48 -48
- package/example/xfj/testori.html +75 -75
- package/index.js +99 -99
- package/package.json +58 -56
- package/src/core/jmControl.js +1376 -1531
- package/src/core/jmEvents.js +240 -281
- package/src/core/jmGradient.js +231 -231
- package/src/core/jmGraph.js +569 -569
- package/src/core/jmList.js +92 -157
- package/src/core/jmObject.js +83 -103
- package/src/core/jmPath.js +35 -35
- package/src/core/jmProperty.js +71 -110
- package/src/core/jmShadow.js +65 -65
- package/src/core/jmUtils.js +906 -919
- package/src/lib/earcut.js +680 -680
- package/src/lib/earcut.md +73 -73
- package/src/lib/webgl/base.js +522 -452
- package/src/lib/webgl/core/buffer.js +48 -48
- package/src/lib/webgl/core/mapSize.js +40 -40
- package/src/lib/webgl/core/mapType.js +43 -43
- package/src/lib/webgl/core/program.js +138 -138
- package/src/lib/webgl/core/shader.js +13 -13
- package/src/lib/webgl/core/texture.js +60 -60
- package/src/lib/webgl/gradient.js +168 -168
- package/src/lib/webgl/index.js +137 -11
- package/src/lib/webgl/path.js +568 -561
- package/src/shapes/jmArrowLine.js +36 -36
- package/src/shapes/jmImage.js +244 -244
- package/src/shapes/jmLabel.js +271 -271
- package/src/shapes/jmResize.js +332 -330
package/example/ball.html
CHANGED
|
@@ -1,217 +1,217 @@
|
|
|
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="../index.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 = new jmGraph('mycanvas', {
|
|
35
|
-
mode: 'webgl',
|
|
36
|
-
autoRefresh: true
|
|
37
|
-
});
|
|
38
|
-
//初始化jmgraph
|
|
39
|
-
/*jmGraph('mycanvas').then((g)=>{
|
|
40
|
-
graph = g;
|
|
41
|
-
jmUtils.bindEvent(window,'resize',resize);
|
|
42
|
-
refreshBall(g);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}); */
|
|
46
|
-
|
|
47
|
-
refreshBall(graph);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
function refreshBall(g) {
|
|
52
|
-
resize();
|
|
53
|
-
|
|
54
|
-
var style = {
|
|
55
|
-
lineWidth: 1.2,
|
|
56
|
-
close:true,
|
|
57
|
-
stroke:'#fff',
|
|
58
|
-
fill:'#05a2e2'
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var balls = [];
|
|
63
|
-
function createPosition(radius,i) {
|
|
64
|
-
var x = Math.random() * graph.width + radius;
|
|
65
|
-
var y = Math.random() * graph.height + radius;
|
|
66
|
-
|
|
67
|
-
for(var j=i+1;j<balls.length;j++) {
|
|
68
|
-
var b2= balls[j];
|
|
69
|
-
var lx = Math.abs(x - b2.x());
|
|
70
|
-
var ly = Math.abs(y - b2.y());
|
|
71
|
-
var l = Math.sqrt(lx * lx + ly * ly);
|
|
72
|
-
//如果二个球重叠则放 弃当前球
|
|
73
|
-
if(l < radius + b2.radius) {
|
|
74
|
-
return createPosition(radius);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return {x:x,y:y};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for(var i=0;i<100;i++) {
|
|
81
|
-
var radius = Math.random() * 10 + 8;
|
|
82
|
-
var styletmp = graph.util.clone(style);
|
|
83
|
-
styletmp.fill = graph.createRadialGradient('50%','50%',0,'50%','50%',radius);
|
|
84
|
-
var rr1 = Math.floor(Math.random() * 255);
|
|
85
|
-
var gg1 = Math.floor(Math.random() * 255);
|
|
86
|
-
var bb1 = Math.floor(Math.random() * 255);
|
|
87
|
-
var rr2 = Math.floor(Math.random() * 255);
|
|
88
|
-
var gg2 = Math.floor(Math.random() * 255);
|
|
89
|
-
var bb2 = Math.floor(Math.random() * 255);
|
|
90
|
-
styletmp.fill.addStop(0,graph.util.toColor(rr1,gg1,bb1));
|
|
91
|
-
styletmp.fill.addStop(1,graph.util.toColor(rr2,gg2,bb2));
|
|
92
|
-
//styletmp.fill = 'r(0.5,0.1)#ccc-#ccc';
|
|
93
|
-
var p = createPosition(radius);
|
|
94
|
-
var b = new ball(graph,p.x,p.y,radius,styletmp);
|
|
95
|
-
b.vx = 0;//Math.random() * 20 - 10;
|
|
96
|
-
b.vy = 0;//Math.random() * 20 - 10;
|
|
97
|
-
//b.ax = 0;
|
|
98
|
-
//b.ay = 0.4;
|
|
99
|
-
balls.push(b);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
var radius = Math.random() * 10 + 6;
|
|
103
|
-
var styletmp = graph.util.clone(style);
|
|
104
|
-
styletmp.fill = graph.createRadialGradient(radius,radius,0,radius,radius,radius);
|
|
105
|
-
styletmp.fill.addStop(0,'#fff');
|
|
106
|
-
styletmp.fill.addStop(1, graph.util.toColor(255,149,255));
|
|
107
|
-
var p = createPosition(radius,0);
|
|
108
|
-
var b = new ball(graph,p.x,p.y,radius,styletmp);
|
|
109
|
-
b.vx = 106;
|
|
110
|
-
b.vy = 104;
|
|
111
|
-
balls.push(b);
|
|
112
|
-
|
|
113
|
-
function animate() {
|
|
114
|
-
var bs = balls;
|
|
115
|
-
var len = bs.length;
|
|
116
|
-
//var mvx = 0;
|
|
117
|
-
//var mvy = 0;
|
|
118
|
-
for(var i=0;i<len;i++) {
|
|
119
|
-
var b1 = bs[i];
|
|
120
|
-
b1.vx += b1.ax;
|
|
121
|
-
b1.vy += b1.ay;
|
|
122
|
-
for(var j=i+1;j<len;j++) {
|
|
123
|
-
var b2= bs[j];
|
|
124
|
-
var lx = b1.x() - b2.x();
|
|
125
|
-
var ly = b1.y() - b2.y();
|
|
126
|
-
var l = Math.sqrt(lx * lx + ly * ly);
|
|
127
|
-
if(l <= b1.radius + b2.radius) {
|
|
128
|
-
var vx = b1.vx;
|
|
129
|
-
var vy = b1.vy;
|
|
130
|
-
var vxb = b2.vx;
|
|
131
|
-
var vyb = b2.vy;
|
|
132
|
-
|
|
133
|
-
var angle = Math.atan2(ly,lx);
|
|
134
|
-
var sine = Math.sin(angle);
|
|
135
|
-
var cosine = Math.cos(angle);
|
|
136
|
-
|
|
137
|
-
var x = 0;
|
|
138
|
-
var y = 0;
|
|
139
|
-
|
|
140
|
-
var xb = lx * cosine + ly * sine;
|
|
141
|
-
var yb = ly * cosine - lx * sine;
|
|
142
|
-
|
|
143
|
-
var vx = b1.vx * cosine + b1.vy * sine;
|
|
144
|
-
var vy = b1.vy * cosine - b1.vx * sine;
|
|
145
|
-
var vxb = b2.vx * cosine + b2.vy * sine;
|
|
146
|
-
var vyb = b2.vy * cosine - b2.vx * sine;
|
|
147
|
-
|
|
148
|
-
var vtotal = vx - vxb;
|
|
149
|
-
|
|
150
|
-
vx = ((b1.radius - b2.radius) * vx + 2 * b2.radius * vxb) / (b1.radius + b2.radius);
|
|
151
|
-
vxb = vtotal + vx;
|
|
152
|
-
|
|
153
|
-
var vx1 = vx * cosine - vy * sine;
|
|
154
|
-
var vy1 = vy * cosine + vx * sine;
|
|
155
|
-
|
|
156
|
-
var vx2 = vxb * cosine - vyb * sine;
|
|
157
|
-
var vy2 = vyb * cosine + vxb * sine;
|
|
158
|
-
|
|
159
|
-
b1.vx = vx1;
|
|
160
|
-
b1.vy = vy1;
|
|
161
|
-
b2.vx = vx2;
|
|
162
|
-
b2.vy = vy2;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
var x = b1.x() + b1.vx;
|
|
166
|
-
var maxX = b1.graph.width - b1.radius ;
|
|
167
|
-
if(x <= b1.radius || x >= maxX) {
|
|
168
|
-
//b1.vy -= 0.4;
|
|
169
|
-
b1.vx *= -1;
|
|
170
|
-
}
|
|
171
|
-
x = Math.max(x,b1.radius);
|
|
172
|
-
x = Math.min(maxX,x);
|
|
173
|
-
b1.x(x);
|
|
174
|
-
var y = b1.y() + b1.vy;
|
|
175
|
-
var maxY = b1.graph.height - b1.radius;
|
|
176
|
-
if(y <= b1.radius || y >= maxY) {
|
|
177
|
-
//if(y >= maxY && b1.vy > 0) {b1.vy -= 1;b1.vx -= 0.4;}
|
|
178
|
-
b1.vy *= -1;
|
|
179
|
-
}
|
|
180
|
-
y = Math.max(y,b1.radius);
|
|
181
|
-
y = Math.min(maxY,y);
|
|
182
|
-
b1.y(y);
|
|
183
|
-
}
|
|
184
|
-
graph.needUpdate = true;
|
|
185
|
-
};
|
|
186
|
-
g.on('update', animate);
|
|
187
|
-
}
|
|
188
|
-
function resize() {
|
|
189
|
-
if(graph) {
|
|
190
|
-
graph.width = window.innerWidth - 10;
|
|
191
|
-
graph.height = window.innerHeight - 10;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function ball(graph,x,y,radius,style) {
|
|
196
|
-
this.graph = graph;
|
|
197
|
-
this.radius = radius;
|
|
198
|
-
this.center = {x:x,y:y};
|
|
199
|
-
this.shape = graph.createShape('arc',{style:style,center:this.center,radius:this.radius,anticlockwise:true});
|
|
200
|
-
graph.children.add(this.shape);
|
|
201
|
-
this.shape.canMove(true);
|
|
202
|
-
this.vx = 0;
|
|
203
|
-
this.vy = 0;
|
|
204
|
-
this.ax = 0;
|
|
205
|
-
this.ay = 0;
|
|
206
|
-
|
|
207
|
-
this.x = function(x) {
|
|
208
|
-
if(typeof x !== 'undefined') this.center.x = x;
|
|
209
|
-
return this.center.x;
|
|
210
|
-
}
|
|
211
|
-
this.y = function(y) {
|
|
212
|
-
if(typeof y !== 'undefined') this.center.y = y;
|
|
213
|
-
return this.center.y;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
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="../index.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 = new jmGraph('mycanvas', {
|
|
35
|
+
mode: 'webgl',
|
|
36
|
+
autoRefresh: true
|
|
37
|
+
});
|
|
38
|
+
//初始化jmgraph
|
|
39
|
+
/*jmGraph('mycanvas').then((g)=>{
|
|
40
|
+
graph = g;
|
|
41
|
+
jmUtils.bindEvent(window,'resize',resize);
|
|
42
|
+
refreshBall(g);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
}); */
|
|
46
|
+
|
|
47
|
+
refreshBall(graph);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function refreshBall(g) {
|
|
52
|
+
resize();
|
|
53
|
+
|
|
54
|
+
var style = {
|
|
55
|
+
lineWidth: 1.2,
|
|
56
|
+
close:true,
|
|
57
|
+
stroke:'#fff',
|
|
58
|
+
fill:'#05a2e2'
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
var balls = [];
|
|
63
|
+
function createPosition(radius,i) {
|
|
64
|
+
var x = Math.random() * graph.width + radius;
|
|
65
|
+
var y = Math.random() * graph.height + radius;
|
|
66
|
+
|
|
67
|
+
for(var j=i+1;j<balls.length;j++) {
|
|
68
|
+
var b2= balls[j];
|
|
69
|
+
var lx = Math.abs(x - b2.x());
|
|
70
|
+
var ly = Math.abs(y - b2.y());
|
|
71
|
+
var l = Math.sqrt(lx * lx + ly * ly);
|
|
72
|
+
//如果二个球重叠则放 弃当前球
|
|
73
|
+
if(l < radius + b2.radius) {
|
|
74
|
+
return createPosition(radius);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {x:x,y:y};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for(var i=0;i<100;i++) {
|
|
81
|
+
var radius = Math.random() * 10 + 8;
|
|
82
|
+
var styletmp = graph.util.clone(style);
|
|
83
|
+
styletmp.fill = graph.createRadialGradient('50%','50%',0,'50%','50%',radius);
|
|
84
|
+
var rr1 = Math.floor(Math.random() * 255);
|
|
85
|
+
var gg1 = Math.floor(Math.random() * 255);
|
|
86
|
+
var bb1 = Math.floor(Math.random() * 255);
|
|
87
|
+
var rr2 = Math.floor(Math.random() * 255);
|
|
88
|
+
var gg2 = Math.floor(Math.random() * 255);
|
|
89
|
+
var bb2 = Math.floor(Math.random() * 255);
|
|
90
|
+
styletmp.fill.addStop(0,graph.util.toColor(rr1,gg1,bb1));
|
|
91
|
+
styletmp.fill.addStop(1,graph.util.toColor(rr2,gg2,bb2));
|
|
92
|
+
//styletmp.fill = 'r(0.5,0.1)#ccc-#ccc';
|
|
93
|
+
var p = createPosition(radius);
|
|
94
|
+
var b = new ball(graph,p.x,p.y,radius,styletmp);
|
|
95
|
+
b.vx = 0;//Math.random() * 20 - 10;
|
|
96
|
+
b.vy = 0;//Math.random() * 20 - 10;
|
|
97
|
+
//b.ax = 0;
|
|
98
|
+
//b.ay = 0.4;
|
|
99
|
+
balls.push(b);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var radius = Math.random() * 10 + 6;
|
|
103
|
+
var styletmp = graph.util.clone(style);
|
|
104
|
+
styletmp.fill = graph.createRadialGradient(radius,radius,0,radius,radius,radius);
|
|
105
|
+
styletmp.fill.addStop(0,'#fff');
|
|
106
|
+
styletmp.fill.addStop(1, graph.util.toColor(255,149,255));
|
|
107
|
+
var p = createPosition(radius,0);
|
|
108
|
+
var b = new ball(graph,p.x,p.y,radius,styletmp);
|
|
109
|
+
b.vx = 106;
|
|
110
|
+
b.vy = 104;
|
|
111
|
+
balls.push(b);
|
|
112
|
+
|
|
113
|
+
function animate() {
|
|
114
|
+
var bs = balls;
|
|
115
|
+
var len = bs.length;
|
|
116
|
+
//var mvx = 0;
|
|
117
|
+
//var mvy = 0;
|
|
118
|
+
for(var i=0;i<len;i++) {
|
|
119
|
+
var b1 = bs[i];
|
|
120
|
+
b1.vx += b1.ax;
|
|
121
|
+
b1.vy += b1.ay;
|
|
122
|
+
for(var j=i+1;j<len;j++) {
|
|
123
|
+
var b2= bs[j];
|
|
124
|
+
var lx = b1.x() - b2.x();
|
|
125
|
+
var ly = b1.y() - b2.y();
|
|
126
|
+
var l = Math.sqrt(lx * lx + ly * ly);
|
|
127
|
+
if(l <= b1.radius + b2.radius) {
|
|
128
|
+
var vx = b1.vx;
|
|
129
|
+
var vy = b1.vy;
|
|
130
|
+
var vxb = b2.vx;
|
|
131
|
+
var vyb = b2.vy;
|
|
132
|
+
|
|
133
|
+
var angle = Math.atan2(ly,lx);
|
|
134
|
+
var sine = Math.sin(angle);
|
|
135
|
+
var cosine = Math.cos(angle);
|
|
136
|
+
|
|
137
|
+
var x = 0;
|
|
138
|
+
var y = 0;
|
|
139
|
+
|
|
140
|
+
var xb = lx * cosine + ly * sine;
|
|
141
|
+
var yb = ly * cosine - lx * sine;
|
|
142
|
+
|
|
143
|
+
var vx = b1.vx * cosine + b1.vy * sine;
|
|
144
|
+
var vy = b1.vy * cosine - b1.vx * sine;
|
|
145
|
+
var vxb = b2.vx * cosine + b2.vy * sine;
|
|
146
|
+
var vyb = b2.vy * cosine - b2.vx * sine;
|
|
147
|
+
|
|
148
|
+
var vtotal = vx - vxb;
|
|
149
|
+
|
|
150
|
+
vx = ((b1.radius - b2.radius) * vx + 2 * b2.radius * vxb) / (b1.radius + b2.radius);
|
|
151
|
+
vxb = vtotal + vx;
|
|
152
|
+
|
|
153
|
+
var vx1 = vx * cosine - vy * sine;
|
|
154
|
+
var vy1 = vy * cosine + vx * sine;
|
|
155
|
+
|
|
156
|
+
var vx2 = vxb * cosine - vyb * sine;
|
|
157
|
+
var vy2 = vyb * cosine + vxb * sine;
|
|
158
|
+
|
|
159
|
+
b1.vx = vx1;
|
|
160
|
+
b1.vy = vy1;
|
|
161
|
+
b2.vx = vx2;
|
|
162
|
+
b2.vy = vy2;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
var x = b1.x() + b1.vx;
|
|
166
|
+
var maxX = b1.graph.width - b1.radius ;
|
|
167
|
+
if(x <= b1.radius || x >= maxX) {
|
|
168
|
+
//b1.vy -= 0.4;
|
|
169
|
+
b1.vx *= -1;
|
|
170
|
+
}
|
|
171
|
+
x = Math.max(x,b1.radius);
|
|
172
|
+
x = Math.min(maxX,x);
|
|
173
|
+
b1.x(x);
|
|
174
|
+
var y = b1.y() + b1.vy;
|
|
175
|
+
var maxY = b1.graph.height - b1.radius;
|
|
176
|
+
if(y <= b1.radius || y >= maxY) {
|
|
177
|
+
//if(y >= maxY && b1.vy > 0) {b1.vy -= 1;b1.vx -= 0.4;}
|
|
178
|
+
b1.vy *= -1;
|
|
179
|
+
}
|
|
180
|
+
y = Math.max(y,b1.radius);
|
|
181
|
+
y = Math.min(maxY,y);
|
|
182
|
+
b1.y(y);
|
|
183
|
+
}
|
|
184
|
+
graph.needUpdate = true;
|
|
185
|
+
};
|
|
186
|
+
g.on('update', animate);
|
|
187
|
+
}
|
|
188
|
+
function resize() {
|
|
189
|
+
if(graph) {
|
|
190
|
+
graph.width = window.innerWidth - 10;
|
|
191
|
+
graph.height = window.innerHeight - 10;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function ball(graph,x,y,radius,style) {
|
|
196
|
+
this.graph = graph;
|
|
197
|
+
this.radius = radius;
|
|
198
|
+
this.center = {x:x,y:y};
|
|
199
|
+
this.shape = graph.createShape('arc',{style:style,center:this.center,radius:this.radius,anticlockwise:true});
|
|
200
|
+
graph.children.add(this.shape);
|
|
201
|
+
this.shape.canMove(true);
|
|
202
|
+
this.vx = 0;
|
|
203
|
+
this.vy = 0;
|
|
204
|
+
this.ax = 0;
|
|
205
|
+
this.ay = 0;
|
|
206
|
+
|
|
207
|
+
this.x = function(x) {
|
|
208
|
+
if(typeof x !== 'undefined') this.center.x = x;
|
|
209
|
+
return this.center.x;
|
|
210
|
+
}
|
|
211
|
+
this.y = function(y) {
|
|
212
|
+
if(typeof y !== 'undefined') this.center.y = y;
|
|
213
|
+
return this.center.y;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
217
|
</script>
|
package/example/base.html
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
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="../dist/jmGraph.min.js"></script>
|
|
17
|
-
</head>
|
|
18
|
-
<body>
|
|
19
|
-
<div id="mycanvas_container"></div>
|
|
20
|
-
</body>
|
|
21
|
-
<script type="text/javascript">
|
|
22
|
-
//import jmGraph from "../index.js";
|
|
23
|
-
|
|
24
|
-
var container = document.getElementById('mycanvas_container');
|
|
25
|
-
|
|
26
|
-
var g = jmGraph.create(container, {
|
|
27
|
-
width: 800,
|
|
28
|
-
height: 600,
|
|
29
|
-
mode: '2d',
|
|
30
|
-
style: {
|
|
31
|
-
fill: '#000'
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
init(g);
|
|
35
|
-
|
|
36
|
-
function init(g){
|
|
37
|
-
g.style.fill = '#000'; //画布背景
|
|
38
|
-
var style = {
|
|
39
|
-
stroke:'#46BF86',
|
|
40
|
-
fill: '#556662',
|
|
41
|
-
lineWidth: 1.5
|
|
42
|
-
};
|
|
43
|
-
style.shadow = '0,0,10,#fff';
|
|
44
|
-
style.opacity = 0.2;
|
|
45
|
-
//style.lineCap = 'round';
|
|
46
|
-
|
|
47
|
-
//创建一个方块
|
|
48
|
-
|
|
49
|
-
var rect = g.createShape('rect',{
|
|
50
|
-
style:style,
|
|
51
|
-
position: {x:300,y:100},
|
|
52
|
-
width:100,
|
|
53
|
-
height:100
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
var rect2 = g.createShape('rect',{
|
|
57
|
-
style:style,
|
|
58
|
-
position: {x:'50%',y:'50%'},
|
|
59
|
-
width:50,
|
|
60
|
-
height:50
|
|
61
|
-
});
|
|
62
|
-
rect.children.add(rect2);
|
|
63
|
-
|
|
64
|
-
g.children.add(rect);
|
|
65
|
-
rect.canMove(true);
|
|
66
|
-
|
|
67
|
-
// 画二个五角星
|
|
68
|
-
var coordinates = [
|
|
69
|
-
{x:50,y:100},
|
|
70
|
-
{x:250,y:100},
|
|
71
|
-
{x:250,y:50},
|
|
72
|
-
{x:300,y:200},
|
|
73
|
-
{x:200,y:200},
|
|
74
|
-
{x:50,y:300},
|
|
75
|
-
];
|
|
76
|
-
style = g.utils.clone(style);
|
|
77
|
-
var star1 = g.createShape('path',{
|
|
78
|
-
style:style,
|
|
79
|
-
points: coordinates
|
|
80
|
-
});
|
|
81
|
-
g.children.add(star1);
|
|
82
|
-
star1.canMove(true);
|
|
83
|
-
|
|
84
|
-
var coordinates2 = [
|
|
85
|
-
{x:50,y:300},
|
|
86
|
-
{x:250,y:300},
|
|
87
|
-
{x:100,y:350},
|
|
88
|
-
{x:150,y:250},
|
|
89
|
-
{x:200,y:350},
|
|
90
|
-
{x:50,y:300},
|
|
91
|
-
];
|
|
92
|
-
style = g.utils.clone(style);
|
|
93
|
-
delete style.fill;
|
|
94
|
-
var star2 = g.createShape('path',{
|
|
95
|
-
style:style,
|
|
96
|
-
points: coordinates2
|
|
97
|
-
});
|
|
98
|
-
g.children.add(star2);
|
|
99
|
-
star2.canMove(true);
|
|
100
|
-
|
|
101
|
-
function update() {
|
|
102
|
-
if(g.needUpdate) {
|
|
103
|
-
console.log(coordinates);
|
|
104
|
-
g.redraw();
|
|
105
|
-
}
|
|
106
|
-
requestAnimationFrame(update);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
update();
|
|
110
|
-
}
|
|
111
|
-
</script>
|
|
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="../dist/jmGraph.min.js"></script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<div id="mycanvas_container"></div>
|
|
20
|
+
</body>
|
|
21
|
+
<script type="text/javascript">
|
|
22
|
+
//import jmGraph from "../index.js";
|
|
23
|
+
|
|
24
|
+
var container = document.getElementById('mycanvas_container');
|
|
25
|
+
|
|
26
|
+
var g = jmGraph.create(container, {
|
|
27
|
+
width: 800,
|
|
28
|
+
height: 600,
|
|
29
|
+
mode: '2d',
|
|
30
|
+
style: {
|
|
31
|
+
fill: '#000'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
init(g);
|
|
35
|
+
|
|
36
|
+
function init(g){
|
|
37
|
+
g.style.fill = '#000'; //画布背景
|
|
38
|
+
var style = {
|
|
39
|
+
stroke:'#46BF86',
|
|
40
|
+
fill: '#556662',
|
|
41
|
+
lineWidth: 1.5
|
|
42
|
+
};
|
|
43
|
+
style.shadow = '0,0,10,#fff';
|
|
44
|
+
style.opacity = 0.2;
|
|
45
|
+
//style.lineCap = 'round';
|
|
46
|
+
|
|
47
|
+
//创建一个方块
|
|
48
|
+
|
|
49
|
+
var rect = g.createShape('rect',{
|
|
50
|
+
style:style,
|
|
51
|
+
position: {x:300,y:100},
|
|
52
|
+
width:100,
|
|
53
|
+
height:100
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
var rect2 = g.createShape('rect',{
|
|
57
|
+
style:style,
|
|
58
|
+
position: {x:'50%',y:'50%'},
|
|
59
|
+
width:50,
|
|
60
|
+
height:50
|
|
61
|
+
});
|
|
62
|
+
rect.children.add(rect2);
|
|
63
|
+
|
|
64
|
+
g.children.add(rect);
|
|
65
|
+
rect.canMove(true);
|
|
66
|
+
|
|
67
|
+
// 画二个五角星
|
|
68
|
+
var coordinates = [
|
|
69
|
+
{x:50,y:100},
|
|
70
|
+
{x:250,y:100},
|
|
71
|
+
{x:250,y:50},
|
|
72
|
+
{x:300,y:200},
|
|
73
|
+
{x:200,y:200},
|
|
74
|
+
{x:50,y:300},
|
|
75
|
+
];
|
|
76
|
+
style = g.utils.clone(style);
|
|
77
|
+
var star1 = g.createShape('path',{
|
|
78
|
+
style:style,
|
|
79
|
+
points: coordinates
|
|
80
|
+
});
|
|
81
|
+
g.children.add(star1);
|
|
82
|
+
star1.canMove(true);
|
|
83
|
+
|
|
84
|
+
var coordinates2 = [
|
|
85
|
+
{x:50,y:300},
|
|
86
|
+
{x:250,y:300},
|
|
87
|
+
{x:100,y:350},
|
|
88
|
+
{x:150,y:250},
|
|
89
|
+
{x:200,y:350},
|
|
90
|
+
{x:50,y:300},
|
|
91
|
+
];
|
|
92
|
+
style = g.utils.clone(style);
|
|
93
|
+
delete style.fill;
|
|
94
|
+
var star2 = g.createShape('path',{
|
|
95
|
+
style:style,
|
|
96
|
+
points: coordinates2
|
|
97
|
+
});
|
|
98
|
+
g.children.add(star2);
|
|
99
|
+
star2.canMove(true);
|
|
100
|
+
|
|
101
|
+
function update() {
|
|
102
|
+
if(g.needUpdate) {
|
|
103
|
+
console.log(coordinates);
|
|
104
|
+
g.redraw();
|
|
105
|
+
}
|
|
106
|
+
requestAnimationFrame(update);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
update();
|
|
110
|
+
}
|
|
111
|
+
</script>
|
|
112
112
|
</html>
|