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.
- package/README.md +174 -2
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +1672 -147
- package/dist/jmgraph.min.js +1 -1
- package/index.js +13 -2
- package/package.json +1 -1
- package/src/core/jmGraph.js +460 -5
- package/src/core/jmLayer.js +142 -0
- package/src/core/jmPath.js +55 -0
- package/src/lib/webgl/base.js +6 -0
- package/src/lib/webgl/path.js +8 -11
- package/src/shapes/jmEllipse.js +91 -0
- package/src/shapes/jmLabel.js +127 -15
- package/src/shapes/jmPolygon.js +129 -0
- 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
package/README.md
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
- 🎭 **事件系统** - 完整的鼠标和触摸事件支持
|
|
17
17
|
- 🔧 **可扩展** - 支持自定义图形控件
|
|
18
18
|
- 🌈 **样式丰富** - 支持渐变、阴影、透明度等样式
|
|
19
|
+
- 📐 **图层管理** - 支持多图层操作,包括创建、切换、删除图层
|
|
20
|
+
- 🔍 **缩放平移** - 支持画布缩放和平移操作
|
|
21
|
+
- 📤 **导出功能** - 支持导出为 PNG、JPEG 和 SVG 格式
|
|
22
|
+
- 📝 **文本换行** - 支持文本自动换行显示
|
|
19
23
|
|
|
20
24
|
## 📦 安装
|
|
21
25
|
|
|
@@ -96,6 +100,7 @@ g.redraw();
|
|
|
96
100
|
## 📚 文档
|
|
97
101
|
|
|
98
102
|
- [在线示例](https://fefeding.github.io/jmgraph/example/index.html)
|
|
103
|
+
- [新特性示例](https://fefeding.github.io/jmgraph/example/new-features.html)
|
|
99
104
|
- [基于 jmGraph 的图表库](https://github.com/fefeding/jmchart)
|
|
100
105
|
|
|
101
106
|
## 🎨 样式说明
|
|
@@ -121,6 +126,7 @@ jmGraph 支持简化的样式名称和原生 Canvas 样式:
|
|
|
121
126
|
| textBaseline | textBaseline | 文本垂直对齐 |
|
|
122
127
|
| lineJoin | lineJoin | 线条连接样式 |
|
|
123
128
|
| lineCap | lineCap | 线条端点样式 |
|
|
129
|
+
| maxWidth | maxWidth | 文本最大宽度(用于自动换行) |
|
|
124
130
|
|
|
125
131
|
## 🎯 内置图形
|
|
126
132
|
|
|
@@ -195,15 +201,50 @@ const label = g.createShape('label', {
|
|
|
195
201
|
textAlign: 'center',
|
|
196
202
|
textBaseline: 'middle',
|
|
197
203
|
fontSize: 24,
|
|
198
|
-
fontFamily: 'Arial'
|
|
204
|
+
fontFamily: 'Arial',
|
|
205
|
+
maxWidth: 200 // 文本最大宽度,超过会自动换行
|
|
199
206
|
},
|
|
200
207
|
position: {x: 200, y: 150},
|
|
201
|
-
text: '
|
|
208
|
+
text: '这是一段测试文本,展示文本换行功能',
|
|
209
|
+
width: 200,
|
|
210
|
+
height: 100
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 椭圆 (Ellipse)
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
const ellipse = g.createShape('ellipse', {
|
|
218
|
+
style: style,
|
|
219
|
+
center: {x: 100, y: 150},
|
|
202
220
|
width: 120,
|
|
203
221
|
height: 80
|
|
204
222
|
});
|
|
205
223
|
```
|
|
206
224
|
|
|
225
|
+
### 多边形 (Polygon)
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
const polygon = g.createShape('polygon', {
|
|
229
|
+
style: style,
|
|
230
|
+
center: {x: 100, y: 150},
|
|
231
|
+
sides: 6, // 边数
|
|
232
|
+
radius: 50 // 半径
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### 星形 (Star)
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
const star = g.createShape('star', {
|
|
240
|
+
style: style,
|
|
241
|
+
center: {x: 100, y: 150},
|
|
242
|
+
points: 5, // 顶点数
|
|
243
|
+
radius: 50, // 外半径
|
|
244
|
+
innerRadius: 25 // 内半径
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
207
248
|
## 🎮 事件系统
|
|
208
249
|
|
|
209
250
|
### 事件绑定
|
|
@@ -287,6 +328,137 @@ this.canvastouchend = function (...arg) {
|
|
|
287
328
|
}
|
|
288
329
|
```
|
|
289
330
|
|
|
331
|
+
## 🔍 缩放平移功能
|
|
332
|
+
|
|
333
|
+
### 设置缩放
|
|
334
|
+
|
|
335
|
+
```javascript
|
|
336
|
+
// 设置缩放因子,以指定点为中心
|
|
337
|
+
// 缩放因子,1为原始大小
|
|
338
|
+
// x, y 缩放中心坐标
|
|
339
|
+
g.setZoom(1.5, 400, 300);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### 平移画布
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
// 平移画布
|
|
346
|
+
// dx, dy 平移距离
|
|
347
|
+
g.pan(100, 50);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### 重置视图
|
|
351
|
+
|
|
352
|
+
```javascript
|
|
353
|
+
// 重置缩放和平移
|
|
354
|
+
g.resetTransform();
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## 📐 图层管理
|
|
358
|
+
|
|
359
|
+
### 创建图层
|
|
360
|
+
|
|
361
|
+
```javascript
|
|
362
|
+
// 创建新图层
|
|
363
|
+
// name 图层名称
|
|
364
|
+
// options 图层选项
|
|
365
|
+
const layer = g.createLayer('My Layer', {
|
|
366
|
+
visible: true,
|
|
367
|
+
locked: false
|
|
368
|
+
});
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### 切换图层
|
|
372
|
+
|
|
373
|
+
```javascript
|
|
374
|
+
// 切换到指定图层
|
|
375
|
+
// layer 图层名称或图层对象
|
|
376
|
+
g.setActiveLayer('My Layer');
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### 获取图层
|
|
380
|
+
|
|
381
|
+
```javascript
|
|
382
|
+
// 获取所有图层
|
|
383
|
+
const layers = g.getLayers();
|
|
384
|
+
|
|
385
|
+
// 获取指定名称的图层
|
|
386
|
+
const layer = g.getLayer('My Layer');
|
|
387
|
+
|
|
388
|
+
// 获取当前活动图层
|
|
389
|
+
const activeLayer = g.getActiveLayer();
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### 移除图层
|
|
393
|
+
|
|
394
|
+
```javascript
|
|
395
|
+
// 移除指定图层
|
|
396
|
+
// layer 图层名称或图层对象
|
|
397
|
+
const success = g.removeLayer('My Layer');
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### 图层操作
|
|
401
|
+
|
|
402
|
+
```javascript
|
|
403
|
+
// 将形状添加到指定图层
|
|
404
|
+
// shape 形状对象
|
|
405
|
+
// layer 图层名称或图层对象,默认为当前活动图层
|
|
406
|
+
g.addShapeToLayer(shape, 'My Layer');
|
|
407
|
+
|
|
408
|
+
// 从图层中移除形状
|
|
409
|
+
// shape 形状对象
|
|
410
|
+
g.removeShapeFromLayer(shape);
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## 📤 导出功能
|
|
414
|
+
|
|
415
|
+
### 导出为 PNG
|
|
416
|
+
|
|
417
|
+
```javascript
|
|
418
|
+
// 导出为 PNG 图片
|
|
419
|
+
// fileName 文件名
|
|
420
|
+
// format 图片格式,默认为 image/png
|
|
421
|
+
// quality 图片质量,0-1之间
|
|
422
|
+
g.exportToPNG('my-graph', 'image/png', 0.9);
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### 导出为 JPEG
|
|
426
|
+
|
|
427
|
+
```javascript
|
|
428
|
+
// 导出为 JPEG 图片
|
|
429
|
+
// fileName 文件名
|
|
430
|
+
// quality 图片质量,0-1之间
|
|
431
|
+
g.exportToJPEG('my-graph', 0.8);
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### 导出为 SVG
|
|
435
|
+
|
|
436
|
+
```javascript
|
|
437
|
+
// 导出为 SVG
|
|
438
|
+
// fileName 文件名
|
|
439
|
+
g.exportToSVG('my-graph');
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## 📝 文本换行
|
|
443
|
+
|
|
444
|
+
当文本长度超过 `maxWidth` 时,会自动换行显示:
|
|
445
|
+
|
|
446
|
+
```javascript
|
|
447
|
+
const label = g.createShape('label', {
|
|
448
|
+
style: {
|
|
449
|
+
fill: '#333',
|
|
450
|
+
fontSize: 14,
|
|
451
|
+
fontFamily: 'Arial',
|
|
452
|
+
textAlign: 'center',
|
|
453
|
+
maxWidth: 200 // 文本最大宽度,超过会自动换行
|
|
454
|
+
},
|
|
455
|
+
position: {x: 200, y: 150},
|
|
456
|
+
text: '这是一段测试文本,当文本长度超过最大宽度时,会自动换行显示。',
|
|
457
|
+
width: 200,
|
|
458
|
+
height: 100
|
|
459
|
+
});
|
|
460
|
+
```
|
|
461
|
+
|
|
290
462
|
## 🛠️ 开发
|
|
291
463
|
|
|
292
464
|
### 构建
|