jmgraph 3.2.19 → 3.2.21
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/README.md +311 -6
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +2022 -368
- package/dist/jmgraph.min.js +1 -1
- package/index.js +23 -25
- package/package.json +1 -1
- package/src/core/jmControl.js +199 -30
- package/src/core/jmFilter.js +150 -0
- package/src/core/jmGraph.js +207 -7
- package/src/core/jmLayer.js +142 -0
- package/src/core/jmPath.js +55 -0
- package/src/core/jmUtils.js +46 -37
- package/src/lib/webgl/base.js +10 -36
- package/src/lib/webgl/gradient.js +16 -3
- package/src/lib/webgl/index.js +5 -4
- package/src/lib/webgl/path.js +156 -33
- package/src/shapes/jmEllipse.js +91 -0
- package/src/shapes/jmLabel.js +126 -75
- package/src/shapes/jmPolygon.js +129 -0
- package/src/shapes/jmRect.js +107 -29
- package/src/shapes/jmStar.js +160 -0
- package/example/ball.html +0 -217
- package/example/base.html +0 -112
- package/example/canvas.html +0 -54
- package/example/cell.html +0 -284
- package/example/controls/arc.html +0 -129
- package/example/controls/arrowline.html +0 -78
- package/example/controls/bezier.html +0 -299
- package/example/controls/img.html +0 -97
- package/example/controls/label.html +0 -87
- package/example/controls/line.html +0 -173
- package/example/controls/prismatic.html +0 -63
- package/example/controls/rect.html +0 -64
- package/example/controls/resize.html +0 -112
- package/example/controls/test.html +0 -360
- package/example/es.html +0 -70
- package/example/es5module.html +0 -63
- package/example/heartarc.html +0 -116
- package/example/index.html +0 -47
- package/example/js/require.js +0 -5
- package/example/love/img/bling/bling.tps +0 -265
- package/example/love/img/bling.json +0 -87
- package/example/love/img/bling.tps +0 -295
- package/example/love/img/doc/bling.gif +0 -0
- package/example/love/img/love.json +0 -95
- package/example/love/img/love.tps +0 -315
- package/example/love/img/qq/qq.tps +0 -399
- package/example/love/img/qq.json +0 -242
- package/example/love/index.html +0 -40
- package/example/love/js/game.js +0 -558
- package/example/music.html +0 -211
- package/example/node/test.js +0 -138
- package/example/pdf.html +0 -187
- package/example/progress.html +0 -173
- package/example/pso.html +0 -148
- package/example/sort.html +0 -805
- package/example/tweenjs.html +0 -84
- package/example/webgl.html +0 -278
- package/example/xfj/img/dr_die.gif +0 -0
- package/example/xfj/index.html +0 -332
- package/example/xfj/shake.js +0 -49
- package/example/xfj/testori.html +0 -76
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
6
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
7
|
-
<title>贝塞尔曲线</title>
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body style="width:100%;margin:10px auto;border:1px solid blue;">
|
|
11
|
-
可用鼠标移动节点位置
|
|
12
|
-
<br />
|
|
13
|
-
<div id="mycanvas" style="border:1px solid red;margin:10px;width:1024px;height:300px;"></div>
|
|
14
|
-
<div id="mycanvas2" style="border:1px solid red;margin:10px;width:1024px;height:500px;"></div>
|
|
15
|
-
</body>
|
|
16
|
-
|
|
17
|
-
</html>
|
|
18
|
-
|
|
19
|
-
<script type="module">
|
|
20
|
-
import jmGraph from "../../index.js";
|
|
21
|
-
|
|
22
|
-
var psize = 6;
|
|
23
|
-
var style = {
|
|
24
|
-
stroke: 'rgb(120,20,80)',
|
|
25
|
-
lineWidth: 3
|
|
26
|
-
};
|
|
27
|
-
style.shadow = '4,4,6,rgb(39,40,34)';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//初始化jmgraph
|
|
32
|
-
var g1 = jmGraph.create('mycanvas', {
|
|
33
|
-
mode: '2d'
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
init1(g1);
|
|
37
|
-
|
|
38
|
-
function init1(graph1) {
|
|
39
|
-
var lstyle = graph1.util.clone(style);
|
|
40
|
-
lstyle.stroke = 'rgba(131,237,111,0.7)';
|
|
41
|
-
lstyle.lineWidth = 1;
|
|
42
|
-
var pstyle = graph1.util.clone(style);
|
|
43
|
-
pstyle.fill = 'rgb(191,216,44)';
|
|
44
|
-
|
|
45
|
-
var p0 = { x: 160, y: 200 };
|
|
46
|
-
var p1 = { x: 200, y: 80 };
|
|
47
|
-
var p2 = { x: 400, y: 100 };
|
|
48
|
-
var p3 = { x: 420, y: 210 };
|
|
49
|
-
var p4 = { x: 500, y: 120 };
|
|
50
|
-
|
|
51
|
-
//一个固定的bezier曲线
|
|
52
|
-
var bezier = graph1.createShape('bezier', { style: style, points: [p0, p1, p2, p3, p4] });
|
|
53
|
-
graph1.children.add(bezier);
|
|
54
|
-
bezier.canMove(true);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var path = graph1.createShape('path', { style: lstyle, points: [p0, p1, p2, p3, p4] });
|
|
58
|
-
graph1.children.add(path);
|
|
59
|
-
path.canMove(true);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var p0arc = graph1.createShape('arc', { style: pstyle, center: p0, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
64
|
-
graph1.children.add(p0arc);
|
|
65
|
-
p0arc.canMove(true);
|
|
66
|
-
var p1arc = graph1.createShape('arc', { style: pstyle, center: p1, radius: psize, width: psize, height: psize, start: 0, end: Math.PI * 2, anticlockwise: true });
|
|
67
|
-
graph1.children.add(p1arc);
|
|
68
|
-
p1arc.canMove(true);
|
|
69
|
-
var p2arc = graph1.createShape('arc', { style: pstyle, center: p2, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
70
|
-
graph1.children.add(p2arc);
|
|
71
|
-
p2arc.canMove(true);
|
|
72
|
-
var p3arc = graph1.createShape('arc', { style: pstyle, center: p3, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
73
|
-
graph1.children.add(p3arc);
|
|
74
|
-
p3arc.canMove(true);
|
|
75
|
-
var p4arc = graph1.createShape('arc', { style: pstyle, center: p4, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
76
|
-
graph1.children.add(p4arc);
|
|
77
|
-
p4arc.canMove(true);
|
|
78
|
-
|
|
79
|
-
drawManualArc(graph1);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//初始化jmgraph
|
|
84
|
-
var g2 = jmGraph.create('mycanvas2', {
|
|
85
|
-
mode: '2d'
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function init2(graph2) {
|
|
91
|
-
var lstyle = graph2.util.clone(style);
|
|
92
|
-
lstyle.stroke = 'rgba(131,237,111,0.7)';
|
|
93
|
-
lstyle.lineWidth = 1;
|
|
94
|
-
var pstyle = graph2.util.clone(style);
|
|
95
|
-
pstyle.fill = 'rgb(191,216,44)';
|
|
96
|
-
|
|
97
|
-
//动画部分
|
|
98
|
-
var mp0 = { x: 160, y: 300 };
|
|
99
|
-
var mp1 = { x: 200, y: 130 };
|
|
100
|
-
var mp2 = { x: 400, y: 80 };
|
|
101
|
-
var mp3 = { x: 420, y: 300 };
|
|
102
|
-
var mp4 = { x: 500, y: 320 };
|
|
103
|
-
var mp5 = { x: 600, y: 81 };
|
|
104
|
-
var mp6 = { x: 700, y: 90 };
|
|
105
|
-
var mp7 = { x: 650, y: 320 };
|
|
106
|
-
var mp8 = { x: 760, y: 350 };
|
|
107
|
-
var mp9 = { x: 800, y: 60 };
|
|
108
|
-
var mlstyle = graph2.util.clone(lstyle);
|
|
109
|
-
mlstyle.lineWidth = 2;
|
|
110
|
-
mlstyle.stroke = '#086C0A';
|
|
111
|
-
delete mlstyle.shadow;
|
|
112
|
-
var mpath = graph2.createShape('path', { style: mlstyle, points: [mp0, mp1, mp2, mp3, mp4, mp5, mp6, mp7, mp8, mp9] });
|
|
113
|
-
graph2.children.add(mpath);
|
|
114
|
-
//mpath.canMove(true);
|
|
115
|
-
var p0arc = graph2.createShape('arc', { style: pstyle, center: mp0, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
116
|
-
graph2.children.add(p0arc);
|
|
117
|
-
p0arc.canMove(true);
|
|
118
|
-
var p1arc = graph2.createShape('arc', { style: pstyle, center: mp1, radius: psize, width: psize, height: psize, start: 0, end: Math.PI * 2, anticlockwise: true });
|
|
119
|
-
graph2.children.add(p1arc);
|
|
120
|
-
p1arc.canMove(true);
|
|
121
|
-
var p2arc = graph2.createShape('arc', { style: pstyle, center: mp2, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
122
|
-
graph2.children.add(p2arc);
|
|
123
|
-
p2arc.canMove(true);
|
|
124
|
-
var p3arc = graph2.createShape('arc', { style: pstyle, center: mp3, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
125
|
-
graph2.children.add(p3arc);
|
|
126
|
-
p3arc.canMove(true);
|
|
127
|
-
var p4arc = graph2.createShape('arc', { style: pstyle, center: mp4, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
128
|
-
graph2.children.add(p4arc);
|
|
129
|
-
p4arc.canMove(true);
|
|
130
|
-
var p5arc = graph2.createShape('arc', { style: pstyle, center: mp5, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
131
|
-
graph2.children.add(p5arc);
|
|
132
|
-
p5arc.canMove(true);
|
|
133
|
-
var p6arc = graph2.createShape('arc', { style: pstyle, center: mp6, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
134
|
-
graph2.children.add(p6arc);
|
|
135
|
-
p6arc.canMove(true);
|
|
136
|
-
var p7arc = graph2.createShape('arc', { style: pstyle, center: mp7, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
137
|
-
graph2.children.add(p7arc);
|
|
138
|
-
p7arc.canMove(true);
|
|
139
|
-
var p8arc = graph2.createShape('arc', { style: pstyle, center: mp8, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
140
|
-
graph2.children.add(p8arc);
|
|
141
|
-
p8arc.canMove(true);
|
|
142
|
-
var p9arc = graph2.createShape('arc', { style: pstyle, center: mp9, radius: psize, start: 0, end: Math.PI * 2, width: psize, height: psize });
|
|
143
|
-
graph2.children.add(p9arc);
|
|
144
|
-
p9arc.canMove(true);
|
|
145
|
-
|
|
146
|
-
style.zIndex = 100;
|
|
147
|
-
var mbezierpath = graph2.createShape('path', { style: style });
|
|
148
|
-
graph2.children.add(mbezierpath);
|
|
149
|
-
|
|
150
|
-
var arrstyle = graph2.util.clone(style);
|
|
151
|
-
var arr = graph2.createShape('arrow', { style: arrstyle });
|
|
152
|
-
graph2.children.add(arr);
|
|
153
|
-
|
|
154
|
-
var chplines = [];
|
|
155
|
-
var chpstyle = graph2.util.clone(mlstyle);
|
|
156
|
-
chpstyle.lineWidth = 1;
|
|
157
|
-
chpstyle.stroke = 'rgb(142,142,15)';
|
|
158
|
-
function getpoint(ps, t, index) {
|
|
159
|
-
if (ps.length == 1) return ps[0];
|
|
160
|
-
if (ps.length == 2) {
|
|
161
|
-
var p = {};
|
|
162
|
-
p.x = (ps[1].x - ps[0].x) * t + ps[0].x;
|
|
163
|
-
p.y = (ps[1].y - ps[0].y) * t + ps[0].y;
|
|
164
|
-
return p;
|
|
165
|
-
}
|
|
166
|
-
if (ps.length > 2) {
|
|
167
|
-
var ppp;
|
|
168
|
-
if (chplines.length <= index) {
|
|
169
|
-
ppp = chplines[index] = graph2.createShape('path', { style: chpstyle });
|
|
170
|
-
graph2.children.add(ppp);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
ppp = chplines[index];
|
|
174
|
-
}
|
|
175
|
-
ppp.points = [];
|
|
176
|
-
for (var i = 0; i < ps.length - 1; i++) {
|
|
177
|
-
var p = getpoint([ps[i], ps[i + 1]], t);
|
|
178
|
-
if (p) {
|
|
179
|
-
ppp.points.push(p);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
index++;
|
|
183
|
-
return getpoint(ppp.points, t, index);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
var t = 0;
|
|
188
|
-
var dir = 0;
|
|
189
|
-
var speed = 0.02;
|
|
190
|
-
setInterval(function () {
|
|
191
|
-
if (t > 1) {
|
|
192
|
-
t = 1;
|
|
193
|
-
dir = 1;
|
|
194
|
-
mbezierpath.points = [];
|
|
195
|
-
}
|
|
196
|
-
else if (t < 0) {
|
|
197
|
-
t = 0;
|
|
198
|
-
dir = 0;
|
|
199
|
-
mbezierpath.points = [];
|
|
200
|
-
}
|
|
201
|
-
/*for(var i in chplines) {
|
|
202
|
-
graph2.children.remove(chplines[i]);
|
|
203
|
-
delete chplines[i];
|
|
204
|
-
}*/
|
|
205
|
-
var mp = getpoint(mpath.points, t, 0);
|
|
206
|
-
mbezierpath.points.push(mp);
|
|
207
|
-
|
|
208
|
-
if (mbezierpath.points.length > 1) {
|
|
209
|
-
arr.start = mbezierpath.points[mbezierpath.points.length - 2];
|
|
210
|
-
arr.end = mbezierpath.points[mbezierpath.points.length - 1];
|
|
211
|
-
}
|
|
212
|
-
t = dir == 0 ? (t + speed) : (t - speed);
|
|
213
|
-
}, 50);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
init2(g2);
|
|
217
|
-
|
|
218
|
-
// 手绘式圆
|
|
219
|
-
function drawManualArc(g) {
|
|
220
|
-
const baseRadius = 60; // 基础半径
|
|
221
|
-
const points = 12; // 分割成多少点,减少点数以避免毛刺
|
|
222
|
-
const variance = 20; // 半径的随机偏移量
|
|
223
|
-
const center = {
|
|
224
|
-
x: 600, y: 100
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
// 生成半径偏移的函数,使用简单的正弦函数模拟平滑变化
|
|
228
|
-
function getRadius(angleIndex, totalPoints) {
|
|
229
|
-
const angle = (angleIndex / totalPoints) * Math.PI * 2;
|
|
230
|
-
// 使用正弦函数创建周期性变化
|
|
231
|
-
const noise = Math.sin(angle * 1) * (variance / 2); // 3决定波动次数,可调节
|
|
232
|
-
// 添加随机偏移
|
|
233
|
-
const randomOffset = (Math.random() - 0.5) * (variance / 2);
|
|
234
|
-
return baseRadius + noise + randomOffset;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
var p = g.createShape('path', { style: {
|
|
238
|
-
stroke: 'rgb(120,20,80)',
|
|
239
|
-
lineWidth: 3,
|
|
240
|
-
close: true,
|
|
241
|
-
}, points: [] });
|
|
242
|
-
|
|
243
|
-
//一个固定的bezier曲线
|
|
244
|
-
var bezier = g.createShape('bezier', { style: style, points: [] });
|
|
245
|
-
let start = {
|
|
246
|
-
x: 0,
|
|
247
|
-
y: 0
|
|
248
|
-
};
|
|
249
|
-
for (let i = 0; i <= points; i++) {
|
|
250
|
-
const angleIndex = i % points;
|
|
251
|
-
const angle = (angleIndex / points) * Math.PI * 2;
|
|
252
|
-
const r = getRadius(angleIndex, points);
|
|
253
|
-
const x = center.x + r * Math.cos(angle);
|
|
254
|
-
const y = center.y + r * Math.sin(angle);
|
|
255
|
-
|
|
256
|
-
if (i === 0) {
|
|
257
|
-
start = {
|
|
258
|
-
x, y
|
|
259
|
-
};
|
|
260
|
-
} else {
|
|
261
|
-
// 使用二次贝塞尔曲线连接点
|
|
262
|
-
const prevIndex = (i - 1) % points;
|
|
263
|
-
const prevAngle = (prevIndex / points) * Math.PI * 2;
|
|
264
|
-
const prevR = getRadius(prevIndex, points);
|
|
265
|
-
const prevX = center.x + prevR * Math.cos(prevAngle);
|
|
266
|
-
const prevY = center.y + prevR * Math.sin(prevAngle);
|
|
267
|
-
|
|
268
|
-
// 控制点为当前点和前一个点的中点,加上偏移量
|
|
269
|
-
const cpX = (prevX + x) / 2;
|
|
270
|
-
const cpY = (prevY + y) / 2;
|
|
271
|
-
bezier.cpoints = [
|
|
272
|
-
start,{
|
|
273
|
-
x: prevX,
|
|
274
|
-
y: prevY
|
|
275
|
-
}, {
|
|
276
|
-
x: cpX,
|
|
277
|
-
y: cpY
|
|
278
|
-
}]
|
|
279
|
-
//ctx.quadraticCurveTo(prevX, prevY, cpX, cpY);
|
|
280
|
-
p.points.push(...bezier.initPoints());
|
|
281
|
-
start = {
|
|
282
|
-
x: cpX,
|
|
283
|
-
y: cpY
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
//p.points.push(start);
|
|
288
|
-
console.log(p.points)
|
|
289
|
-
g.children.add(p);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
//实时更新画布
|
|
293
|
-
function update() {
|
|
294
|
-
if(g1.needUpdate) g1.redraw();
|
|
295
|
-
if(g2.needUpdate) g2.redraw();
|
|
296
|
-
requestAnimationFrame(update);
|
|
297
|
-
}
|
|
298
|
-
update();
|
|
299
|
-
</script>
|
|
@@ -1,97 +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
|
-
background-color: #000;
|
|
14
|
-
}
|
|
15
|
-
</style>
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<div id="mycanvas_container"></div>
|
|
19
|
-
</body>
|
|
20
|
-
<script type="module">
|
|
21
|
-
import jmGraph from "../../index.js";
|
|
22
|
-
|
|
23
|
-
var container = document.getElementById('mycanvas_container');
|
|
24
|
-
|
|
25
|
-
//开发模式下,引用jmGraph.js,请使用这种方式,内部会初始化组件
|
|
26
|
-
var g = jmGraph.create('mycanvas_container', {
|
|
27
|
-
width: 800,
|
|
28
|
-
height: 600,
|
|
29
|
-
style: {
|
|
30
|
-
//fill: '#000'
|
|
31
|
-
},
|
|
32
|
-
mode: '2d',
|
|
33
|
-
autoRefresh: true
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
init(g);
|
|
37
|
-
|
|
38
|
-
function init(g){
|
|
39
|
-
|
|
40
|
-
//g.style.fill = '#000'; //画布背景
|
|
41
|
-
var style = {
|
|
42
|
-
//src: '//mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png'
|
|
43
|
-
//stroke: 'red',
|
|
44
|
-
rotation: {
|
|
45
|
-
angle: 0
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
style.shadow = '0,0,20,#fff';
|
|
49
|
-
//style.opacity = 0.2;
|
|
50
|
-
|
|
51
|
-
//创建一个image
|
|
52
|
-
var img = g.createShape('image',{
|
|
53
|
-
style:style,
|
|
54
|
-
//伸展或缩小图像
|
|
55
|
-
width: 200,
|
|
56
|
-
position: {x:100,y:100},
|
|
57
|
-
image: '../qrcode.jpg'
|
|
58
|
-
});
|
|
59
|
-
//img.image = '//mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png';
|
|
60
|
-
g.children.add(img);
|
|
61
|
-
img.canMove(true);
|
|
62
|
-
|
|
63
|
-
//创建一个image
|
|
64
|
-
var img3 = g.createShape('image',{
|
|
65
|
-
style: g.utils.clone(style),
|
|
66
|
-
//伸展或缩小图像
|
|
67
|
-
width: 200,
|
|
68
|
-
position: {x:100,y:100},
|
|
69
|
-
image: '../qrcode.jpg'
|
|
70
|
-
});
|
|
71
|
-
//img.image = '//mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png';
|
|
72
|
-
g.children.add(img3);
|
|
73
|
-
|
|
74
|
-
//截取logo
|
|
75
|
-
var img2 = g.createShape('image',{
|
|
76
|
-
style: style,
|
|
77
|
-
position: {x:100,y:100},
|
|
78
|
-
|
|
79
|
-
//伸展或缩小图像
|
|
80
|
-
width: 100,
|
|
81
|
-
height: 60,
|
|
82
|
-
image: '../x.png',
|
|
83
|
-
sourcePosition: {x:0, y:0}, //截取起点
|
|
84
|
-
sourceWidth: 192, //截取宽度,如果不填则用原图宽
|
|
85
|
-
sourceHeight: 192 //截取高度,如果不填则用原图高
|
|
86
|
-
});
|
|
87
|
-
g.children.add(img2);
|
|
88
|
-
img2.canMove(true);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
g.on('update', (time) => {
|
|
92
|
-
style.rotation.angle += 0.01;
|
|
93
|
-
g.needUpdate = true;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
</script>
|
|
97
|
-
</html>
|
|
@@ -1,87 +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="../../dist/jmgraph.min.js"></script>-->
|
|
17
|
-
</head>
|
|
18
|
-
<body>
|
|
19
|
-
<div id="mycanvas_container"></div>
|
|
20
|
-
<canvas id="textureCanvas"></canvas>
|
|
21
|
-
</body>
|
|
22
|
-
<script type="module">
|
|
23
|
-
import { jmGraph } from "../../index.js";
|
|
24
|
-
import jmLabel from '../../src/shapes/jmLabel.js';
|
|
25
|
-
|
|
26
|
-
var container = document.getElementById('mycanvas_container');
|
|
27
|
-
const textureCanvas = document.getElementById('textureCanvas');
|
|
28
|
-
|
|
29
|
-
//开发模式下,引用jmGraph.js,请使用这种方式,内部会初始化组件
|
|
30
|
-
var g = jmGraph.create('mycanvas_container', {
|
|
31
|
-
width: 800,
|
|
32
|
-
height: 600,
|
|
33
|
-
mode: 'webgl',
|
|
34
|
-
style: {
|
|
35
|
-
fill: '#000'
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
init(g);
|
|
39
|
-
|
|
40
|
-
function init(g){
|
|
41
|
-
//g.style.fill = '#000'; //画布背景
|
|
42
|
-
var style = {
|
|
43
|
-
stroke: 'green',
|
|
44
|
-
fill: 'yellow',
|
|
45
|
-
textAlign: 'right',
|
|
46
|
-
textBaseline: 'middle',
|
|
47
|
-
fontFamily: "Arial",
|
|
48
|
-
fontSize: 24,
|
|
49
|
-
border: {
|
|
50
|
-
left:1,
|
|
51
|
-
top:1,
|
|
52
|
-
right:1,
|
|
53
|
-
bottom:1,
|
|
54
|
-
style: {
|
|
55
|
-
stroke: 'red'
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
shadow: '0,0,10,#fff'
|
|
59
|
-
};
|
|
60
|
-
//style.opacity = 0.2;
|
|
61
|
-
|
|
62
|
-
//创建一个label
|
|
63
|
-
var label = g.createShape(jmLabel,{
|
|
64
|
-
style:style,
|
|
65
|
-
//position:{x:200,y:150},
|
|
66
|
-
center: {x: 250, y: 250},
|
|
67
|
-
text:'test label',
|
|
68
|
-
//width:120,
|
|
69
|
-
height:80
|
|
70
|
-
});
|
|
71
|
-
g.children.add(label);
|
|
72
|
-
label.canMove(true);
|
|
73
|
-
|
|
74
|
-
g.bind('touchleave', (args) => {
|
|
75
|
-
console.log('touchleave', args);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
function update() {
|
|
80
|
-
if(g.needUpdate) g.redraw();
|
|
81
|
-
requestAnimationFrame(update);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
update();
|
|
85
|
-
}
|
|
86
|
-
</script>
|
|
87
|
-
</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
|
-
|
|
7
|
-
</head>
|
|
8
|
-
<body style="margin:10px;border:1px solid blue; background-color: #fff;">
|
|
9
|
-
<div id="mycanvas" style="border:1px solid red;margin:10px;"></div>
|
|
10
|
-
<canvas id="textureCanvas"></canvas>
|
|
11
|
-
<div id="eventposition"></div>
|
|
12
|
-
|
|
13
|
-
<img id="dataimg" />
|
|
14
|
-
</body>
|
|
15
|
-
<script type="module">
|
|
16
|
-
import jmGraph from "../../index.js";
|
|
17
|
-
|
|
18
|
-
const textureCanvas = document.getElementById('textureCanvas');
|
|
19
|
-
var g = jmGraph.create('mycanvas', {
|
|
20
|
-
width: window.innerWidth * 0.8,
|
|
21
|
-
height: window.innerHeight * 0.8,
|
|
22
|
-
mode: 'webgl',
|
|
23
|
-
textureCanvas
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
init(g);
|
|
27
|
-
|
|
28
|
-
function update() {
|
|
29
|
-
if(g.needUpdate) g.redraw();
|
|
30
|
-
requestAnimationFrame(update);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
update();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function init(graph){
|
|
37
|
-
graph.style.fill = '#fff';
|
|
38
|
-
var style = {
|
|
39
|
-
stroke:'#D07814FF',
|
|
40
|
-
lineWidth: 3,
|
|
41
|
-
close:true
|
|
42
|
-
};
|
|
43
|
-
style.shadow = '0,0,5,#fff';
|
|
44
|
-
style.opacity = 1;
|
|
45
|
-
//graph.createShadow('shadow(0,0,10,#000)');//new jmShadow('shadow(10,10,20,#000)');
|
|
46
|
-
//style.shadow = graph.createShadow(4,4,6,'#000000');
|
|
47
|
-
//style.lineCap = 'round';
|
|
48
|
-
|
|
49
|
-
var line = graph.createLine({x:10,y:200},{x:80,y:120},style);
|
|
50
|
-
|
|
51
|
-
line.bind('mouseover',function(evt) {
|
|
52
|
-
this.style.stroke = 'rgba(39,72,188,1)';
|
|
53
|
-
this.cursor = 'pointer';
|
|
54
|
-
this.needUpdate = true;
|
|
55
|
-
});
|
|
56
|
-
line.bind('mouseleave',function(evt) {
|
|
57
|
-
this.style.stroke = 'rgb(120,20,80)';
|
|
58
|
-
this.cursor = 'default';
|
|
59
|
-
this.needUpdate = true;
|
|
60
|
-
});
|
|
61
|
-
line.bind('touchstart',function(evt) {
|
|
62
|
-
console.log('touchstart',evt);
|
|
63
|
-
});
|
|
64
|
-
line.bind('touchmove',function(evt) {
|
|
65
|
-
console.log('touchmove',evt);
|
|
66
|
-
});
|
|
67
|
-
line.bind('touchend',function(evt) {
|
|
68
|
-
console.log('touchend',evt);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
graph.children.add(line);
|
|
72
|
-
line.canMove(true);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
style = graph.utils.clone(style);
|
|
76
|
-
delete style['rotation'];
|
|
77
|
-
|
|
78
|
-
style.lineType = "dotted";
|
|
79
|
-
style.dashLength = 10;
|
|
80
|
-
style.lineWidth = 2;
|
|
81
|
-
var line = graph.createLine({x:50,y:50},{x:200,y:400}, style);
|
|
82
|
-
style.zIndex = 20;
|
|
83
|
-
graph.children.add(line);
|
|
84
|
-
line.bind('mouseover',function(evt) {
|
|
85
|
-
this.style.stroke = 'rgba(39,72,188,1)';
|
|
86
|
-
//graph.canvas.style.cursor = 'pointer';
|
|
87
|
-
this.needUpdate = true;
|
|
88
|
-
});
|
|
89
|
-
line.bind('mouseleave',function(evt) {
|
|
90
|
-
this.style.stroke = 'rgb(120,20,80)';
|
|
91
|
-
//graph.canvas.style.cursor = 'default';
|
|
92
|
-
this.needUpdate = true;
|
|
93
|
-
});
|
|
94
|
-
line.canMove(true);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
style = graph.utils.clone(style);
|
|
99
|
-
//style.opacity = .8;
|
|
100
|
-
var bg = graph.createRadialGradient('50%','50%', 0,'50%','50%', 40);
|
|
101
|
-
bg.addStop(0,'rgba(0,0,0, 0.1)');
|
|
102
|
-
bg.addStop(0.5,'rgba(0,255,0,5)');
|
|
103
|
-
bg.addStop(1,'rgba(150,200,180,0.8)');
|
|
104
|
-
style.fill = bg;//'linear-gradient(0 0 0 100,#000 0,#73998A 1)';
|
|
105
|
-
style.close = true;
|
|
106
|
-
var rect = graph.createPath(null,style, {
|
|
107
|
-
isRegular: true
|
|
108
|
-
});
|
|
109
|
-
rect.points.push({x:20,y:20});
|
|
110
|
-
rect.points.push({x:20,y:100});
|
|
111
|
-
rect.points.push({x:100,y:100});
|
|
112
|
-
rect.points.push({x:100,y:20});
|
|
113
|
-
graph.children.add(rect);
|
|
114
|
-
|
|
115
|
-
style = graph.utils.clone(style);
|
|
116
|
-
var img = new Image();
|
|
117
|
-
img.onload = ()=>{
|
|
118
|
-
//style.fillImage = img;
|
|
119
|
-
//style.fill = 'rgba(220,100,80, 0.5)';
|
|
120
|
-
style.lineWidth = 1.2;
|
|
121
|
-
//delete style.fill;
|
|
122
|
-
//style.close = true;
|
|
123
|
-
|
|
124
|
-
for(let i=0; i< 1000; i++) {
|
|
125
|
-
var path = graph.createPath(null,style, {
|
|
126
|
-
isRegular: true,
|
|
127
|
-
needCut: false
|
|
128
|
-
});
|
|
129
|
-
const startx = Math.random() * window.innerWidth;
|
|
130
|
-
const starty = Math.random() * window.innerHeight;
|
|
131
|
-
if(i === 0) {
|
|
132
|
-
path.points = [{x:600, y:370}, {x:700, y:600}, {x:780, y:420}, {x:730, y:570}, {x:590, y:520}];
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
path.points.push({x:startx+200,y:60+starty});
|
|
136
|
-
path.points.push({x:startx+400,y:60+starty});
|
|
137
|
-
|
|
138
|
-
path.points.push({x:startx+220,y:120+starty});
|
|
139
|
-
path.points.push({x:startx+260,y:300+starty});
|
|
140
|
-
|
|
141
|
-
path.points.push({x:startx+420,y:100+starty});
|
|
142
|
-
|
|
143
|
-
path.points.push({x:startx+260,y:20+starty});
|
|
144
|
-
path.points.push({x:startx+250,y:80+starty});
|
|
145
|
-
path.points.push({x:startx+200,y:10+starty});
|
|
146
|
-
}
|
|
147
|
-
/*path.points.push({x:300,y:60});
|
|
148
|
-
path.points.push({x:400,y:60});
|
|
149
|
-
|
|
150
|
-
path.points.push({x:360,y:130});
|
|
151
|
-
//path.points.push({x:320,y:120});
|
|
152
|
-
|
|
153
|
-
path.points.push({x:420,y:100});
|
|
154
|
-
|
|
155
|
-
path.points.push({x:260,y:60});*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
//rect.children.add(path);
|
|
159
|
-
|
|
160
|
-
graph.children.add(path);
|
|
161
|
-
|
|
162
|
-
//line.canMove(true);
|
|
163
|
-
path.canMove(true);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
img.src = '../x.png';
|
|
167
|
-
|
|
168
|
-
rect.canMove(true);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
</script>
|
|
173
|
-
</html>
|