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.
Files changed (77) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +251 -428
  3. package/build/gulpfile.js +142 -142
  4. package/build/package-lock.json +10666 -0
  5. package/build/package.json +71 -71
  6. package/dev.js +9 -9
  7. package/dist/jmgraph.core.min.js +1 -1
  8. package/dist/jmgraph.core.min.js.map +1 -1
  9. package/dist/jmgraph.js +3500 -2668
  10. package/dist/jmgraph.min.js +1 -1
  11. package/example/ball.html +216 -216
  12. package/example/base.html +111 -111
  13. package/example/canvas.html +53 -53
  14. package/example/cell.html +283 -283
  15. package/example/controls/arc.html +128 -128
  16. package/example/controls/arrowline.html +77 -77
  17. package/example/controls/bezier.html +298 -298
  18. package/example/controls/img.html +96 -96
  19. package/example/controls/label.html +86 -86
  20. package/example/controls/line.html +172 -172
  21. package/example/controls/prismatic.html +62 -62
  22. package/example/controls/rect.html +63 -63
  23. package/example/controls/resize.html +111 -111
  24. package/example/controls/test.html +359 -359
  25. package/example/es.html +69 -69
  26. package/example/es5module.html +62 -63
  27. package/example/heartarc.html +115 -115
  28. package/example/index.html +46 -46
  29. package/example/js/require.js +4 -4
  30. package/example/love/img/bling/bling.tps +265 -265
  31. package/example/love/img/bling.json +87 -87
  32. package/example/love/img/bling.tps +295 -295
  33. package/example/love/img/love.json +95 -95
  34. package/example/love/img/love.tps +315 -315
  35. package/example/love/img/qq/qq.tps +399 -399
  36. package/example/love/img/qq.json +242 -242
  37. package/example/love/index.html +40 -40
  38. package/example/love/js/game.js +558 -558
  39. package/example/music.html +210 -210
  40. package/example/node/test.js +137 -137
  41. package/example/pdf.html +186 -186
  42. package/example/progress.html +172 -172
  43. package/example/pso.html +147 -147
  44. package/example/sort.html +804 -815
  45. package/example/tweenjs.html +83 -83
  46. package/example/webgl.html +278 -278
  47. package/example/xfj/index.html +331 -331
  48. package/example/xfj/shake.js +48 -48
  49. package/example/xfj/testori.html +75 -75
  50. package/index.js +99 -99
  51. package/package.json +58 -56
  52. package/src/core/jmControl.js +1376 -1531
  53. package/src/core/jmEvents.js +240 -281
  54. package/src/core/jmGradient.js +231 -231
  55. package/src/core/jmGraph.js +569 -569
  56. package/src/core/jmList.js +92 -157
  57. package/src/core/jmObject.js +83 -103
  58. package/src/core/jmPath.js +35 -35
  59. package/src/core/jmProperty.js +71 -110
  60. package/src/core/jmShadow.js +65 -65
  61. package/src/core/jmUtils.js +906 -919
  62. package/src/lib/earcut.js +680 -680
  63. package/src/lib/earcut.md +73 -73
  64. package/src/lib/webgl/base.js +522 -452
  65. package/src/lib/webgl/core/buffer.js +48 -48
  66. package/src/lib/webgl/core/mapSize.js +40 -40
  67. package/src/lib/webgl/core/mapType.js +43 -43
  68. package/src/lib/webgl/core/program.js +138 -138
  69. package/src/lib/webgl/core/shader.js +13 -13
  70. package/src/lib/webgl/core/texture.js +60 -60
  71. package/src/lib/webgl/gradient.js +168 -168
  72. package/src/lib/webgl/index.js +137 -11
  73. package/src/lib/webgl/path.js +568 -561
  74. package/src/shapes/jmArrowLine.js +36 -36
  75. package/src/shapes/jmImage.js +244 -244
  76. package/src/shapes/jmLabel.js +271 -271
  77. package/src/shapes/jmResize.js +332 -330
package/README.md CHANGED
@@ -1,59 +1,57 @@
1
- jmGraph
2
- =========
1
+ # jmGraph
3
2
 
4
- [![Latest NPM release][npm-badge]][npm-badge-url]
5
- [![Build Status](https://travis-ci.org/jiamao/jmgraph.svg?branch=master)](https://travis-ci.org/jiamao/jmgraph)
3
+ [![npm version](https://img.shields.io/npm/v/jmgraph.svg)](https://www.npmjs.com/package/jmgraph)
4
+ [![npm downloads](https://img.shields.io/npm/dm/jmgraph.svg)](https://www.npmjs.com/package/jmgraph)
5
+ [![License: MIT](https://img.shields.io/npm/l/jmgraph.svg)](https://github.com/fefeding/jmgraph/blob/master/LICENSE)
6
+ [![Build Status](https://travis-ci.org/fefeding/jmgraph.svg?branch=master)](https://travis-ci.org/fefeding/jmgraph)
6
7
 
7
- 基于CANVAS的简单画图组件
8
- `让你用类似于dom的方式,在canvas上画图,感觉会不会很爽。`
8
+ 基于 Canvas 的简单画图组件,让你用类似于 DOM 的方式,在 Canvas 上画图。
9
9
 
10
- - 主页:[https://jiamao.github.io/jmgraph/](https://jiamao.github.io/jmgraph/)
11
- - 示例:[https://jiamao.github.io/jmgraph/example/index.html](https://jiamao.github.io/jmgraph/example/index.html)
10
+ ## ✨ 特性
12
11
 
13
- 基于它的图表应用:[https://github.com/jiamao/jmchart](https://github.com/jiamao/jmchart)
12
+ - 🎨 **简单易用** - 类似 DOM 的 API 设计,学习成本低
13
+ - 🚀 **高性能** - 基于 Canvas 原生渲染,支持大量图形
14
+ - 📱 **跨平台** - 支持浏览器、Node.js 和微信小程序
15
+ - 🎯 **丰富图形** - 内置矩形、圆形、线条、箭头、贝塞尔曲线等常用图形
16
+ - 🎭 **事件系统** - 完整的鼠标和触摸事件支持
17
+ - 🔧 **可扩展** - 支持自定义图形控件
18
+ - 🌈 **样式丰富** - 支持渐变、阴影、透明度等样式
14
19
 
15
- 安装
16
- ---
17
- 直接从github下载包或npm安装。
18
- 如需要构建,直接在项目录下执行`npm run build`即可。
19
- ```shell
20
+ ## 📦 安装
21
+
22
+ ### npm
23
+
24
+ ```bash
20
25
  npm install jmgraph
21
26
  ```
22
- ```shell
27
+
28
+ ### yarn
29
+
30
+ ```bash
23
31
  yarn add jmgraph
24
32
  ```
25
33
 
26
- 入门
27
- --------
34
+ ### CDN
28
35
 
29
- ### es5引用办法
36
+ 直接下载 `dist/jmgraph.min.js` 并在 HTML 中引用:
30
37
 
31
- 下载`dist/jmgraph.min.js`代码,并引用到你的html中。
32
- ```html
33
- <script type="text/javascript" src="../dist/jmgraph.min.js"></script>
34
- ```
35
- 也可以用`commonjs`、`requirejs`等模块化库。
36
- ##### requirejs
37
38
  ```html
38
- <script type="text/javascript" src="js/require.js"></script>
39
- <script>
40
- require(['../dist/jmgraph.js'], function(m) {
41
- var g = new m.jmGraph();
42
- });
43
- </script>
39
+ <script type="text/javascript" src="../dist/jmgraph.min.js"></script>
44
40
  ```
45
- ##### es6模块引用
46
- 也可以直接用es6中的import来引用
41
+
42
+ ## 🚀 快速开始
43
+
44
+ ### ES6 模块方式
45
+
47
46
  ```html
48
47
  <script type="module">
49
- // import jmGraph from "../dist/jmgraph.es6.js";
50
- // import jmGraph from "./node_modules/jmgraph/index.js";
51
48
  import jmGraph from "jmgraph";
52
- var container = document.getElementById('mycanvas_container');
53
- var g = new jmGraph(container, {
49
+
50
+ const container = document.getElementById('mycanvas_container');
51
+ const g = new jmGraph(container, {
54
52
  width: 800,
55
53
  height: 600,
56
- autoRefresh: true, // 是否自动刷新变化
54
+ autoRefresh: true,
57
55
  style: {
58
56
  fill: '#000'
59
57
  }
@@ -61,457 +59,282 @@ yarn add jmgraph
61
59
  </script>
62
60
  ```
63
61
 
62
+ ### CommonJS 方式
64
63
 
65
- 在dom中添加一个`div或canvas`,然后初始化jmGraph。
66
- ```html
67
- <div id="mycanvas_container"></div>
68
- <script type="text/javascript">
69
- //也可以是一个dom对象或一个jquery对象
70
- //例如:$('#mycanvas_container') || document.getElementById('mycanvas_container')
71
- var container = 'mycanvas_container';
72
-
73
- var g = jmGraph.create(container, {
74
- width: 800,
75
- height: 600,
76
- //样式,规则请参照样式说明
77
- style: {
78
- fill: '#000' //指定背景色
79
- }
80
- });
81
- </script>
64
+ ```javascript
65
+ const jmGraph = require('jmgraph');
66
+
67
+ const g = jmGraph.create('mycanvas_container', {
68
+ width: 800,
69
+ height: 600,
70
+ style: {
71
+ fill: '#000'
72
+ }
73
+ });
82
74
  ```
83
- 在画布上画一个方块
75
+
76
+ ### 绘制一个矩形
77
+
84
78
  ```javascript
79
+ const style = {
80
+ stroke: '#46BF86',
81
+ lineWidth: 2,
82
+ shadow: '0,0,10,#fff'
83
+ };
85
84
 
86
- function init(g){
87
- var style = {
88
- stroke:'#46BF86',
89
- lineWidth: 2
90
- };
91
- style.shadow = '0,0,10,#fff';//阴影
92
- //style.opacity = 0.2;
93
- //style.lineCap = 'round';
94
-
95
- //创建一个方块
96
- var rect = g.createShape('rect',{
97
- style:style,
98
- position: {x:100,y:100}, //左上角坐标
99
- width:100,
100
- height:100
101
- });
102
- g.children.add(rect);
103
-
104
- //绘制,可以用requestAnimationFrame动态刷新
105
- function update() {
106
- g.redraw();
107
- //requestAnimationFrame(update);
108
- }
109
- update();
110
- }
85
+ const rect = g.createShape('rect', {
86
+ style: style,
87
+ position: {x: 100, y: 100},
88
+ width: 100,
89
+ height: 100
90
+ });
91
+
92
+ g.children.add(rect);
93
+ g.redraw();
111
94
  ```
112
95
 
113
- 样式
114
- ---
96
+ ## 📚 文档
115
97
 
116
- 样式可以直接用`canvas`支持的名称,也可以用本组件简化后的。
117
-
118
- #### 样式一览
119
- | 简化名称 | 原生名称 | 说明
120
- | :- | :- | :- |
121
- | fill | fillStyle | 用于填充绘画的颜色、渐变或模式
122
- | stroke | strokeStyle | 用于笔触的颜色、渐变或模式
123
- | shadow | 没有对应的 | 最终会解析成以下几个属性,格式:'0,0,10,#fff'或g.createShadow(0,0,20,'#000');
124
- | shadow.blur | shadowBlur | 用于阴影的模糊级别
125
- | shadow.x | shadowOffsetX | 阴影距形状的水平距离
126
- | shadow.y | shadowOffsetY | 阴影距形状的垂直距离
127
- | shadow.color | shadowColor | 阴影颜色,格式:'#000'、'#46BF86'、'rgb(255,255,255)'或'rgba(39,72,188,0.5)'
128
- | lineWidth | lineWidth | 当前的线条宽度
129
- | miterLimit | miterLimit | 最大斜接长度
130
- | font | font | 请使用下面的 fontSize 和 fontFamily
131
- | fontSize | font | 字体大小
132
- | fontFamily | font | 字体
133
- | opacity | globalAlpha | 绘图的当前 alpha 或透明值
134
- | textAlign | textAlign | 文本内容的当前对齐方式
135
- | textBaseline | textBaseline | 在绘制文本时使用的当前文本基线
136
- | lineJoin | lineJoin | 两条线相交时,所创建的拐角类型:miter(默认,尖角),bevel(斜角),round(圆角)
137
- | lineCap | lineCap | 线条的结束端点样式:butt(默认,平),round(圆),square(方)
138
-
139
-
140
- 事件
141
- ---
98
+ - [在线示例](https://fefeding.github.io/jmgraph/example/index.html)
99
+ - [基于 jmGraph 的图表库](https://github.com/fefeding/jmchart)
100
+
101
+ ## 🎨 样式说明
102
+
103
+ jmGraph 支持简化的样式名称和原生 Canvas 样式:
104
+
105
+ | 简化名称 | 原生名称 | 说明 |
106
+ | :- | :- | :- |
107
+ | fill | fillStyle | 填充颜色、渐变或模式 |
108
+ | stroke | strokeStyle | 描边颜色、渐变或模式 |
109
+ | shadow | - | 阴影,格式:'0,0,10,#fff' |
110
+ | shadow.blur | shadowBlur | 阴影模糊级别 |
111
+ | shadow.x | shadowOffsetX | 阴影水平偏移 |
112
+ | shadow.y | shadowOffsetY | 阴影垂直偏移 |
113
+ | shadow.color | shadowColor | 阴影颜色 |
114
+ | lineWidth | lineWidth | 线条宽度 |
115
+ | miterLimit | miterLimit | 最大斜接长度 |
116
+ | font | font | 字体 |
117
+ | fontSize | font | 字体大小 |
118
+ | fontFamily | font | 字体名称 |
119
+ | opacity | globalAlpha | 透明度 |
120
+ | textAlign | textAlign | 文本水平对齐 |
121
+ | textBaseline | textBaseline | 文本垂直对齐 |
122
+ | lineJoin | lineJoin | 线条连接样式 |
123
+ | lineCap | lineCap | 线条端点样式 |
124
+
125
+ ## 🎯 内置图形
126
+
127
+ ### 矩形 (Rect)
142
128
 
143
- 事件的绑定函数:`bind/unbind`
144
- 示例:
145
129
  ```javascript
146
- //创建一条线
147
- var line = graph.createLine({x:10,y:200},{x:80,y:120},style);
148
- //鼠标移到上面显示不同的样式
149
- line.bind('mouseover',function(evt) {
150
- this.style.stroke = 'rgba(39,72,188,0.5)';
151
- this.cursor('pointer');
152
- this.neadUpdate = true; //需要刷新
130
+ const rect = g.createShape('rect', {
131
+ style: style,
132
+ position: {x: 100, y: 100},
133
+ width: 100,
134
+ height: 100
153
135
  });
154
136
  ```
155
137
 
156
- > 如果要某个控件不响用操作事件,设置其`interactive`为`false`即可。
157
-
158
- #### 事件一览
159
- | 名称 | 说明 | 回调参数
160
- | :- | :- | :- |
161
- | mousedown | 鼠标按下时触发 | -
162
- | mousemove | 鼠标在对象上移动时触发 |{target:当前元素,position: 当前位置}
163
- | mouseover | 鼠标从某元素移开 | {target:当前元素}
164
- | mouseleave | 某个鼠标按键被松开 | -
165
- | mouseup | 某个鼠标按键被松开 | -
166
- | dblclick | 鼠标双击某个对象 | -
167
- | click | 鼠标点击某个对象 | -
168
- | touchstart | 触控开始 | position: 当前位置
169
- | touchmove | 触控移动手指 | position: 当前位置
170
- | touchend | 触控结束 | position: 当前位置
171
-
172
- 控件
173
- ---
174
-
175
- #### Path
176
- `path`是多数图形的基类,可以指定一个points数组来绘制一个路径。
177
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/line.html)
138
+ ### 圆形/椭圆 (Arc)
178
139
 
179
140
  ```javascript
180
- var path = graph.createPath(null, style);
181
- path.points.push({x:10,y:10});
182
- path.points.push({x:10,y:60});
183
- path.points.push({x:80,y:20});
184
- path.points.push({x:90,y:80});
185
- path.points.push({x:80,y:80});
141
+ const arc = g.createShape('arc', {
142
+ style: style,
143
+ center: {x: 100, y: 150},
144
+ width: 120,
145
+ height: 80
146
+ });
186
147
  ```
187
- #### 圆
188
- `arc`可以创建椭圆、圆弧和圆,circle调用的是原生的arc函数绘制,harc可以绘制一个圆环。
189
- 具体请参考示例。
190
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/arc.html)
148
+
149
+ ### 线条 (Line)
191
150
 
192
151
  ```javascript
193
- //创建一个椭圆,指定不同的宽高就为椭圆。如果相同或指定半径则为圆。
194
- var arc1 = g.createShape('arc', {
195
- style: style,
196
- center: {x:100, y:150},
197
- width: 120,
198
- height: 80
199
- });
152
+ const line = g.createLine(
153
+ {x: 10, y: 200},
154
+ {x: 80, y: 120},
155
+ style
156
+ );
200
157
  ```
201
158
 
202
- #### 箭头
203
- `arrow`为创建一个箭头,
204
- `Arrowline`是一条带箭头的直线。
205
- 具体请参考示例。
206
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/Arrowline.html)
159
+ ### 箭头 (Arrow)
207
160
 
208
161
  ```javascript
209
- //带箭头的直线
210
- var shape = g.createShape('Arrowline', {
211
- style:style,
212
- start: {x:100,y:100},
213
- end: {x: 200, y: 350}
214
- });
215
- //一起结束点和一个角度angle可以决定一个箭头,如果不填angle,则会用start和end来计算角度
216
- var arrow = g.createShape('arrow', {
217
- style:style,
218
- start: {x:150, y:120},
219
- end: {x: 160, y: 150}
220
- //angle: Math.PI/2, //箭头角度 可以不填
221
- //offsetX: 5, //箭头X偏移量
222
- //offsetY: 8 //箭头Y偏移量
223
- });
162
+ const arrow = g.createShape('arrow', {
163
+ style: style,
164
+ start: {x: 150, y: 120},
165
+ end: {x: 160, y: 150}
166
+ });
224
167
  ```
225
168
 
226
- #### 贝塞尔曲线
227
- `bezier`可以指定无数个控制点,绘制复杂的曲线。
228
- 具体请参考示例。
229
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/bezier.html)
169
+ ### 贝塞尔曲线 (Bezier)
230
170
 
231
171
  ```javascript
232
- //一个固定的bezier曲线
233
- var bezier = g.createShape('bezier', { style: style, points: [p0, p1, p2, p3, p4] });
172
+ const bezier = g.createShape('bezier', {
173
+ style: style,
174
+ points: [p0, p1, p2, p3, p4]
175
+ });
234
176
  ```
235
177
 
236
- #### 图片
237
- `img`是用来承载一张图片的控件,可以用style.src来指定图片url。
238
- 具体请参考示例。
239
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/img.html)
178
+ ### 图片 (Image)
240
179
 
241
180
  ```javascript
242
- var style = {
243
- src: 'http://mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png'
244
- };
245
- style.shadow = '0,0,10,#fff';
246
- //style.opacity = 0.2;
247
-
248
- //创建一个image
249
- var img = g.createShape('image',{
250
- style:style,
251
- position: {x:100,y:100}
252
- });
253
- //设置图片可以用鼠标移动
181
+ const img = g.createShape('image', {
182
+ style: {src: 'image.png'},
183
+ position: {x: 100, y: 100}
184
+ });
254
185
  img.canMove(true);
255
186
  ```
256
187
 
257
- #### 文字
258
- `label`可以用来绘制文字,通过style指定样式。
259
- 具体请参考示例。
260
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/label.html)
188
+ ### 文字 (Label)
261
189
 
262
190
  ```javascript
263
- var style = {
191
+ const label = g.createShape('label', {
192
+ style: {
264
193
  stroke: '#effaaa',
265
194
  fill: '#fff',
266
- textAlign: 'center', //水平居中
267
- textBaseline: 'middle', //垂直居中
195
+ textAlign: 'center',
196
+ textBaseline: 'middle',
268
197
  fontSize: 24,
269
- fontFamily: 'Arial',
270
- border: {
271
- left:1,
272
- top:1,
273
- right:1,
274
- bottom:1,
275
- //边框样式
276
- style: {
277
- stroke: 'red' //颜色
278
- }
279
- }, //边框
280
- shadow: '0,0,10,#fff'
281
- };
282
- //style.opacity = 0.2;
283
-
284
- //创建一个label
285
- var label = g.createShape('label',{
286
- style:style,
287
- position:{x:200,y:150},
288
- text:'test label',
289
- width:120,
290
- height:80
291
- });
198
+ fontFamily: 'Arial'
199
+ },
200
+ position: {x: 200, y: 150},
201
+ text: 'Hello World',
202
+ width: 120,
203
+ height: 80
204
+ });
292
205
  ```
293
206
 
294
- #### 棱形
295
- `prismatic`
296
- 具体请参考示例。
297
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/prismatic.html)
298
-
299
- ```javascript
300
- var prismatic = g.createShape('prismatic',{
301
- style:style,
302
- center:{x:200,y:150},
303
- width:120,
304
- height:80
305
- });
306
- ```
207
+ ## 🎮 事件系统
307
208
 
308
- #### 可缩放控件
309
- `resize` 可以自由放大缩小的控件。
310
- 具体请参考示例。
311
- [在线示例](http://jiamao.github.io/jmgraph/example/controls/resize.html)
209
+ ### 事件绑定
312
210
 
313
211
  ```javascript
314
- var style = {
315
- stroke: 'red',
316
- fill: 'yellow',
317
- lineWidth: 2, //边线宽
318
- //小方块样式
319
- rectStyle: {
320
- stroke: 'green', //小方块边颜色
321
- fill: 'transparent',//小方块填充色
322
- lineWidth: 1, //小方块线宽
323
- close: true
324
- }
325
- };
326
- //style.opacity = 0.2;
327
-
328
- //创建一个resize
329
- var resize = g.createShape('resize', {
330
- style: style,
331
- position: {x:200, y:150},
332
- width: 120,
333
- height: 80
334
- });
335
- //大小改变事件
336
- resize.on('resize', function() {
337
- console.log(arguments);
338
- });
212
+ const shape = g.createShape('rect', {...});
213
+
214
+ shape.bind('mouseover', function(evt) {
215
+ this.style.stroke = 'rgba(39,72,188,0.5)';
216
+ this.cursor('pointer');
217
+ this.needUpdate = true;
218
+ });
339
219
  ```
340
220
 
341
- #### 自定义控件
221
+ ### 支持的事件
342
222
 
343
- 大多数控件直接继承`jmPath`即可,然后通过实现`initPoints`来绘制当前控件。
344
- `当需要从某点重新开始画时,给点指定m属性为true,表示移到当前点。` 。
223
+ | 事件名称 | 说明 | 回调参数 |
224
+ | :- | :- | :- |
225
+ | mousedown | 鼠标按下 | - |
226
+ | mousemove | 鼠标移动 | {target, position} |
227
+ | mouseover | 鼠标移入 | {target} |
228
+ | mouseleave | 鼠标移出 | {target} |
229
+ | mouseup | 鼠标松开 | - |
230
+ | click | 鼠标点击 | - |
231
+ | dblclick | 鼠标双击 | - |
232
+ | touchstart | 触摸开始 | {position} |
233
+ | touchmove | 触摸移动 | {position} |
234
+ | touchend | 触摸结束 | {position} |
345
235
 
346
- 继承这里需要用到`es6`的模块,所以当你用的是`script标签`时,记得给`type="module"`。
347
- 或写一个class的js文件,构建成es5的。
236
+ ## 🔧 自定义控件
348
237
 
238
+ 大多数控件继承 `jmPath` 即可,通过实现 `initPoints` 方法来绘制自定义图形:
349
239
 
350
- ##### 示例
351
- 来画一个X
352
- 在线示例:[http://jiamao.github.io/jmgraph/example/controls/test.html](http://jiamao.github.io/jmgraph/example/controls/test.html)
353
240
  ```javascript
354
- import {jmGraph} from "../../src/jmGraph.js";
355
- import {jmPath} from "../../src/shapes/jmPath.js";
356
- /**
357
- * 测试
358
- */
359
- class jmTest extends jmPath {
360
- constructor(params) {
361
- if(!params) params = {};
362
- super(params);
363
- this.center = params.center || {x:0, y:0};
364
- this.radius = params.radius || 0;
365
- }
366
-
367
- //定义属性
368
- /**
369
- * 中心点
370
- * point格式:{x:0,y:0,m:true}
371
- * @property center
372
- * @type {point}
373
- */
374
- get center() {
375
- return this.property('center');
376
- }
377
- set center(v) {
378
- return this.property('center', v);
379
- }
380
- /**
381
- * 半径
382
- * @property radius
383
- * @type {number}
384
- */
385
- get radius() {
386
- return this.property('radius');
387
- }
388
- set radius(v) {
389
- return this.property('radius', v);
390
- }
241
+ import {jmPath} from "jmgraph";
242
+
243
+ class CustomShape extends jmPath {
244
+ constructor(params) {
245
+ super(params);
246
+ this.center = params.center || {x: 0, y: 0};
247
+ this.radius = params.radius || 0;
248
+ }
391
249
 
392
- /**
393
- * 初始化图形点
394
- * 控件都是由点形成
395
- *
396
- * @method initPoint
397
- * @private
398
- * @for jmArc
399
- */
400
- initPoints() {
401
- //可以获取当前控件的左上坐标,可以用来画相对位置
402
- var location = this.getLocation();//获取位置参数
403
-
404
- var cx = location.center.x ;
405
- var cy = location.center.y ;
250
+ initPoints() {
251
+ const location = this.getLocation();
252
+ const cx = location.center.x;
253
+ const cy = location.center.y;
254
+
255
+ this.points = [];
256
+ this.points.push({x: cx - this.radius, y: cy - this.radius});
257
+ this.points.push({x: cx + this.radius, y: cy + this.radius});
406
258
 
407
- this.points = [];
259
+ return this.points;
260
+ }
261
+ }
262
+ ```
408
263
 
409
- //简单的画一个X
264
+ ## 📱 微信小程序支持
410
265
 
411
- //根据半径计算x,y偏移量
412
- //由于是圆,偏移量相同
413
- var offw = Math.sqrt(location.radius * location.radius / 2);
414
- //左上角到右下角对角线
415
- this.points.push({x:cx - offw, y:cy-offw}, {x:cx + offw, y:cy+offw});
266
+ jmGraph 支持微信小程序,详情请参考 [mini-jmchart](https://github.com/fefeding/mini-jmchart)。
416
267
 
417
- //左下角到右上角对角线
418
- //画完上面的线后,需要重新移到这条线的起点,指定m:true即可
419
- this.points.push({x:cx - offw, y:cy+offw, m:true}, {x:cx + offw, y:cy-offw});
268
+ ### 使用方法
420
269
 
421
- return this.points;
422
- }
423
- }
424
- ```
270
+ ```javascript
271
+ const jmGraph = require('../../utils/jmgraph');
425
272
 
273
+ const g = jmGraph.create('mycanvas', {
274
+ style: {fill: '#000'},
275
+ width: 400,
276
+ height: 600
277
+ });
426
278
 
427
- #### 微信小程序支持
428
- 线上体验小程序:
429
- ![截图](https://raw.githubusercontent.com/jiamao/jmgraph/master/example/qrcode.jpg)
279
+ this.canvastouchstart = function (...arg) {
280
+ return g.eventHandler.touchStart(...arg);
281
+ }
282
+ this.canvastouchmove = function (...arg) {
283
+ return g.eventHandler.touchMove(...arg);
284
+ }
285
+ this.canvastouchend = function (...arg) {
286
+ return g.eventHandler.touchEnd(...arg);
287
+ }
288
+ ```
430
289
 
431
- 源码:[https://github.com/jiamao/mini-jmchart](https://github.com/jiamao/mini-jmchart)
290
+ ## 🛠️ 开发
432
291
 
433
- 微信小程序稍有差别,因为无需压缩,请直接把`dist`中的`jmgraph.js`合并后的文件引用到你的小程序中。
292
+ ### 构建
434
293
 
435
- ##### 示例
436
- `wxml`
437
- ```html
438
- <canvas style="width: 400px; height: 600px;background:#000;"
439
- canvas-id="mycanvas"
440
- bindtouchstart="canvastouchstart"
441
- bindtouchmove="canvastouchmove"
442
- bindtouchend="canvastouchend"
443
- bindtouchcancel="canvastouchcancel">
444
- </canvas>
294
+ ```bash
295
+ npm run build
445
296
  ```
446
- `javascript`
447
- ```javascript
448
- /**
449
- * 生命周期函数--监听页面初次渲染完成
450
- */
451
- onReady: function () {
452
-
453
- //这里引用jmgraph
454
- let jmGraph = require('../../utils/jmgraph');
455
-
456
- var self = this;
457
-
458
- var g = jmGraph.create('mycanvas', {
459
- style: {
460
- fill: '#000'
461
- },
462
- width: 400,
463
- height: 600
464
- });
465
- init(g);
466
-
467
- function init(g) {
468
- //g.style.fill = '#000'; //画布背景
469
- var style = {
470
- stroke: '#46BF86',
471
- fill: '#556662',
472
- lineWidth: 2
473
- };
474
- style.shadow = '0,0,10,#fff';
475
- //style.opacity = 0.2;
476
- //style.lineCap = 'round';
477
-
478
- //创建一个方块
479
- var rect = g.createShape('rect', {
480
- style: style,
481
- position: { x: 100, y: 100 },
482
- width: 100,
483
- height: 100
484
- });
485
- rect.canMove(true);
486
- g.children.add(rect);
487
-
488
- function update() {
489
- if (g.needUpdate) g.redraw();
490
- setTimeout(update, 20);
491
- }
492
-
493
- update();
494
-
495
- //初始化jmGraph事件
496
- //把小程序中的canvas事件交给jmGraph处理
497
- this.canvastouchstart = function (...arg) {
498
- return g.eventHandler.touchStart(...arg);
499
- }
500
- this.canvastouchmove = function (...arg) {
501
- return g.eventHandler.touchMove(...arg);
502
- }
503
- this.canvastouchend = function (...arg) {
504
- return g.eventHandler.touchEnd(...arg);
505
- }
506
- this.canvastouchcancel = function (...arg) {
507
- return g.eventHandler.touchCancel(...arg);
508
- }
509
- }
510
- }
297
+
298
+ ### 运行示例
299
+
300
+ ```bash
301
+ npm run dev
511
302
  ```
512
303
 
513
-
514
- [npm-badge]: https://img.shields.io/npm/v/jmgraph.svg
515
- [npm-badge-url]: https://www.npmjs.com/package/jmgraph
516
- [license-badge]: https://img.shields.io/npm/l/jmgraph.svg
517
- [license-badge-url]: ./LICENSE
304
+ ## 🤝 贡献
305
+
306
+ 欢迎贡献代码!请遵循以下步骤:
307
+
308
+ 1. Fork 本仓库
309
+ 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
310
+ 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
311
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
312
+ 5. 开启 Pull Request
313
+
314
+ ## 📄 许可证
315
+
316
+ 本项目采用 [MIT](LICENSE) 许可证。
317
+
318
+ ## 💬 讨论
319
+
320
+ - [GitHub Issues](https://github.com/fefeding/jmgraph/issues) - 报告 Bug 和功能请求
321
+ - [GitHub Discussions](https://github.com/fefeding/jmgraph/discussions) - 问题和讨论
322
+
323
+ ## 🙏 致谢
324
+
325
+ 感谢所有为本项目做出贡献的开发者!
326
+
327
+ ## 🔗 相关项目
328
+
329
+ - [jmChart](https://github.com/fefeding/jmchart) - 基于 jmGraph 的图表库
330
+ - [mini-jmchart](https://github.com/fefeding/mini-jmchart) - 微信小程序图表库
331
+
332
+ ## 📮 联系方式
333
+
334
+ - 作者: jiamao
335
+ - 邮箱: haofefe@163.com
336
+ - 主页: https://fefeding.github.io/jmgraph/
337
+
338
+ ---
339
+
340
+ 如果这个项目对你有帮助,请给个 ⭐️ Star!