jmgraph 3.2.7 → 3.2.8

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 (51) hide show
  1. package/README.md +0 -1
  2. package/dist/jmgraph.core.min.js +1 -1
  3. package/dist/jmgraph.core.min.js.map +1 -1
  4. package/dist/jmgraph.js +2834 -325
  5. package/dist/jmgraph.min.js +1 -1
  6. package/example/ball.html +8 -14
  7. package/example/cell.html +1 -1
  8. package/example/controls/arc.html +10 -7
  9. package/example/controls/arrowline.html +1 -0
  10. package/example/controls/img.html +30 -23
  11. package/example/controls/label.html +6 -4
  12. package/example/controls/line.html +54 -51
  13. package/example/controls/resize.html +45 -8
  14. package/example/index.html +2 -1
  15. package/example/music.html +101 -82
  16. package/example/webgl.html +48 -25
  17. package/package.json +56 -56
  18. package/src/core/jmControl.js +124 -95
  19. package/src/core/jmEvents.js +2 -2
  20. package/src/core/jmGradient.js +5 -3
  21. package/src/core/jmGraph.js +10 -20
  22. package/src/core/jmPath.js +1 -17
  23. package/src/core/jmUtils.js +6 -0
  24. package/src/lib/webgl/base.js +253 -1
  25. package/src/lib/webgl/core/buffer.js +2 -1
  26. package/src/lib/webgl/core/program.js +2 -2
  27. package/src/lib/webgl/core/texture.js +8 -8
  28. package/src/lib/webgl/gradient.js +11 -38
  29. package/src/lib/webgl/path.js +118 -235
  30. package/src/shapes/jmImage.js +18 -3
  31. package/src/shapes/jmLabel.js +84 -38
  32. package/src/shapes/jmRect.js +5 -2
  33. package/docs/_config.yml +0 -1
  34. package/docs/about.html +0 -41
  35. package/docs/api/jmGraph.md +0 -2302
  36. package/docs/css/index.css +0 -131
  37. package/docs/images/ball.gif +0 -0
  38. package/docs/images/bezier.gif +0 -0
  39. package/docs/images/cell.gif +0 -0
  40. package/docs/images/chart.gif +0 -0
  41. package/docs/images/editor.gif +0 -0
  42. package/docs/images/sort.gif +0 -0
  43. package/docs/index.html +0 -80
  44. package/docs/js/helper.js +0 -89
  45. package/docs/js/jquery.min.js +0 -6
  46. package/example/love/img/music/bg.mp3 +0 -0
  47. package/example/love/img/music/bg_2019130144035.mp3 +0 -0
  48. package/example/love/img/music/f.mp3 +0 -0
  49. package/example/love/img/music/fail.mp3 +0 -0
  50. package/example/love/img/music/s.mp3 +0 -0
  51. package/example/love/img/music/s_201913014415.mp3 +0 -0
package/example/ball.html CHANGED
@@ -32,7 +32,8 @@
32
32
  <script type="module">
33
33
  import jmGraph from "../index.js";
34
34
  var graph = new jmGraph('mycanvas', {
35
- mode: '2d'
35
+ mode: 'webgl',
36
+ autoRefresh: true
36
37
  });
37
38
  //初始化jmgraph
38
39
  /*jmGraph('mycanvas').then((g)=>{
@@ -45,12 +46,6 @@
45
46
 
46
47
  refreshBall(graph);
47
48
 
48
- //实时更新画布
49
- function update() {
50
- if(graph && graph.needUpdate) graph.redraw();
51
- graph.utils.requestAnimationFrame(update);
52
- }
53
- update();
54
49
 
55
50
 
56
51
  function refreshBall(g) {
@@ -82,10 +77,10 @@
82
77
  return {x:x,y:y};
83
78
  }
84
79
 
85
- for(var i=0;i<10;i++) {
80
+ for(var i=0;i<100;i++) {
86
81
  var radius = Math.random() * 10 + 8;
87
82
  var styletmp = graph.util.clone(style);
88
- styletmp.fill = graph.createRadialGradient(radius,radius,0,radius,radius,radius);
83
+ styletmp.fill = graph.createRadialGradient('50%','50%',0,'50%','50%',radius);
89
84
  var rr1 = Math.floor(Math.random() * 255);
90
85
  var gg1 = Math.floor(Math.random() * 255);
91
86
  var bb1 = Math.floor(Math.random() * 255);
@@ -111,8 +106,8 @@
111
106
  styletmp.fill.addStop(1, graph.util.toColor(255,149,255));
112
107
  var p = createPosition(radius,0);
113
108
  var b = new ball(graph,p.x,p.y,radius,styletmp);
114
- b.vx = 6;
115
- b.vy = 4;
109
+ b.vx = 106;
110
+ b.vy = 104;
116
111
  balls.push(b);
117
112
 
118
113
  function animate() {
@@ -186,10 +181,9 @@
186
181
  y = Math.min(maxY,y);
187
182
  b1.y(y);
188
183
  }
189
- graph.needUpdate = true;
190
- g.utils.requestAnimationFrame(animate);
184
+ graph.needUpdate = true;
191
185
  };
192
- animate();
186
+ g.on('update', animate);
193
187
  }
194
188
  function resize() {
195
189
  if(graph) {
package/example/cell.html CHANGED
@@ -35,7 +35,7 @@
35
35
  var balls = [];
36
36
  //初始化jmgraph
37
37
  var graph = new jmGraph('mycanvas', {
38
- mode: '2d'
38
+ mode: 'webgl'
39
39
  });
40
40
  graph.util.bindEvent(window,'resize',resize);
41
41
 
@@ -28,6 +28,7 @@
28
28
  width: 800,
29
29
  height: 600,
30
30
  mode: '2d',
31
+ autoRefresh: true,
31
32
  style: {
32
33
  fill: '#000'
33
34
  }
@@ -42,6 +43,9 @@
42
43
  stroke: '#ccc',
43
44
  fill: 'yellow',
44
45
  lineWidth: 4, //边线宽
46
+ rotation: {
47
+ angle: 0
48
+ }
45
49
  };
46
50
  //style.opacity = 0.2;
47
51
 
@@ -113,14 +117,13 @@
113
117
  end: Math.PI / 4,
114
118
  anticlockwise: true //false 顺时针,true 逆时针
115
119
  });
116
- g.children.add(harc);
120
+ g.children.add(harc);
121
+ harc.canMove(true);
117
122
 
118
- function update() {
119
- g.needUpdate && g.redraw();
120
- requestAnimationFrame(update);
121
- }
122
-
123
- update();
123
+ g.on('update', (time) => {
124
+ style.rotation.angle += 0.01;
125
+ g.needUpdate = true;
126
+ });
124
127
  }
125
128
  </script>
126
129
  </html>
@@ -24,6 +24,7 @@
24
24
  var g = jmGraph.create('mycanvas_container', {
25
25
  width: 800,
26
26
  height: 600,
27
+ mode: 'webgl',
27
28
  style: {
28
29
  fill: '#000'
29
30
  }
@@ -7,10 +7,10 @@
7
7
  html,body{
8
8
  margin:0;
9
9
  padding: 0;
10
- background-color: #000;;
11
10
  }
12
11
  #mycanvas_container{
13
- overflow: hidden;
12
+ overflow: hidden;
13
+ background-color: #000;
14
14
  }
15
15
  </style>
16
16
  </head>
@@ -29,7 +29,8 @@
29
29
  style: {
30
30
  //fill: '#000'
31
31
  },
32
- mode: '2d'
32
+ mode: '2d',
33
+ autoRefresh: true
33
34
  });
34
35
 
35
36
  init(g);
@@ -39,52 +40,58 @@
39
40
  //g.style.fill = '#000'; //画布背景
40
41
  var style = {
41
42
  //src: '//mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png'
42
- //stroke: 'red'
43
+ //stroke: 'red',
44
+ rotation: {
45
+ angle: 0
46
+ },
43
47
  };
44
- style.shadow = '0,0,10,#fff';
48
+ style.shadow = '0,0,20,#fff';
45
49
  //style.opacity = 0.2;
46
50
 
47
51
  //创建一个image
48
52
  var img = g.createShape('image',{
49
53
  style:style,
54
+ //伸展或缩小图像
55
+ width: 200,
50
56
  position: {x:100,y:100},
51
57
  image: '../qrcode.jpg'
52
58
  });
53
59
  //img.image = '//mat1.gtimg.com/www/qq2018/imgs/qq_logo_2018x2.png';
54
60
  g.children.add(img);
55
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);
56
73
 
57
74
  //截取logo
58
75
  var img2 = g.createShape('image',{
59
- style:style,
60
- position: {x:500,y:200},
76
+ style: style,
77
+ position: {x:100,y:100},
61
78
 
62
79
  //伸展或缩小图像
63
80
  width: 100,
64
81
  height: 60,
65
82
  image: '../x.png',
66
83
  sourcePosition: {x:0, y:0}, //截取起点
67
- sourceWidth: 60, //截取宽度,如果不填则用原图宽
68
- sourceHeight: 60 //截取高度,如果不填则用原图高
84
+ sourceWidth: 192, //截取宽度,如果不填则用原图宽
85
+ sourceHeight: 192 //截取高度,如果不填则用原图高
69
86
  });
70
87
  g.children.add(img2);
71
88
  img2.canMove(true);
72
-
73
- var style = {
74
- stroke: 'red',
75
- fill: 'yellow',
76
- lineWidth: 2 //边线宽
77
- };
78
- //style.opacity = 0.2;
79
-
80
89
 
81
90
 
82
- function update() {
83
- g.needUpdate && g.redraw();
84
- requestAnimationFrame(update);
85
- }
86
-
87
- update();
91
+ g.on('update', (time) => {
92
+ style.rotation.angle += 0.01;
93
+ g.needUpdate = true;
94
+ });
88
95
  }
89
96
  </script>
90
97
  </html>
@@ -17,18 +17,20 @@
17
17
  </head>
18
18
  <body>
19
19
  <div id="mycanvas_container"></div>
20
+ <canvas id="textureCanvas"></canvas>
20
21
  </body>
21
22
  <script type="module">
22
23
  import { jmGraph } from "../../index.js";
23
24
  import jmLabel from '../../src/shapes/jmLabel.js';
24
25
 
25
26
  var container = document.getElementById('mycanvas_container');
26
-
27
+ const textureCanvas = document.getElementById('textureCanvas');
28
+
27
29
  //开发模式下,引用jmGraph.js,请使用这种方式,内部会初始化组件
28
30
  var g = jmGraph.create('mycanvas_container', {
29
31
  width: 800,
30
32
  height: 600,
31
- mode: '2d',
33
+ mode: 'webgl',
32
34
  style: {
33
35
  fill: '#000'
34
36
  }
@@ -38,8 +40,8 @@
38
40
  function init(g){
39
41
  //g.style.fill = '#000'; //画布背景
40
42
  var style = {
41
- stroke: '#effaaa',
42
- fill: '#fff',
43
+ stroke: 'green',
44
+ fill: 'yellow',
43
45
  textAlign: 'right',
44
46
  textBaseline: 'middle',
45
47
  fontFamily: "Arial",
@@ -5,8 +5,8 @@
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
 
7
7
  </head>
8
- <body style="width:800px;margin:10px;border:1px solid blue; background-color: #fff;">
9
- <div id="mycanvas" style="border:1px solid red;margin:10px;width:100%;height:600px;"></div>
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
10
  <canvas id="textureCanvas"></canvas>
11
11
  <div id="eventposition"></div>
12
12
 
@@ -17,9 +17,9 @@
17
17
 
18
18
  const textureCanvas = document.getElementById('textureCanvas');
19
19
  var g = jmGraph.create('mycanvas', {
20
- width: 800,
21
- height: 600,
22
- mode: '2d',
20
+ width: window.innerWidth * 0.8,
21
+ height: window.innerHeight * 0.8,
22
+ mode: 'webgl',
23
23
  textureCanvas
24
24
  });
25
25
 
@@ -96,9 +96,10 @@
96
96
 
97
97
 
98
98
  style = graph.utils.clone(style);
99
- style.opacity = .8;
100
- var bg = graph.createLinearGradient(0,0,80,80);
101
- bg.addStop(0,'rgba(0,0,0,0.3)');
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)');
102
103
  bg.addStop(1,'rgba(150,200,180,0.8)');
103
104
  style.fill = bg;//'linear-gradient(0 0 0 100,#000 0,#73998A 1)';
104
105
  style.close = true;
@@ -114,55 +115,57 @@
114
115
  style = graph.utils.clone(style);
115
116
  var img = new Image();
116
117
  img.onload = ()=>{
117
- style.fillImage = img;
118
- style.fill = 'rgba(220,100,80, 0.8)';
118
+ //style.fillImage = img;
119
+ //style.fill = 'rgba(220,100,80, 0.5)';
120
+ style.lineWidth = 1.2;
119
121
  //delete style.fill;
120
122
  //style.close = true;
121
- var path = graph.createPath(null,style);
122
- path.points.push({x:200,y:60});
123
- path.points.push({x:400,y:60});
124
123
 
125
- path.points.push({x:220,y:120});
126
- path.points.push({x:260,y:300});
127
-
128
- path.points.push({x:420,y:100});
129
-
130
- path.points.push({x:260,y:20});
131
- path.points.push({x:250,y:80});
132
- path.points.push({x:200,y:10});
133
-
134
- /*path.points.push({x:300,y:60});
135
- path.points.push({x:400,y:60});
136
-
137
- path.points.push({x:360,y:130});
138
- //path.points.push({x:320,y:120});
139
-
140
- path.points.push({x:420,y:100});
141
-
142
- path.points.push({x:260,y:60});*/
143
-
144
-
145
- //rect.children.add(path);
146
-
147
- graph.children.add(path);
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);
148
159
 
149
- path.bind('mouseover',function(evt) {
150
- this.style.stroke = 'rgba(39,72,188,0.5)';
151
- this.needUpdate = true;
152
- //graph.canvas.style.cursor = 'pointer';
160
+ graph.children.add(path);
153
161
 
154
- });
155
- path.bind('mouseleave',function(evt) {
156
- this.style.stroke = 'rgb(120,20,80)';
157
- this.needUpdate = true;
158
- //graph.canvas.style.cursor = 'default';
159
- });
160
-
161
- rect.canMove(true);
162
- //line.canMove(true);
163
- path.canMove(true);
162
+ //line.canMove(true);
163
+ path.canMove(true);
164
+ }
164
165
  }
165
- img.src = '../x.png';
166
+ img.src = '../x.png';
167
+
168
+ rect.canMove(true);
166
169
  }
167
170
 
168
171
 
@@ -9,12 +9,17 @@
9
9
  padding: 0;
10
10
  }
11
11
  #mycanvas_container{
12
- overflow: hidden;
12
+ overflow: hidden;
13
+ text-align: center;
13
14
  }
15
+
14
16
  </style>
15
17
  </head>
16
18
  <body>
17
19
  <div id="mycanvas_container"></div>
20
+ <button onclick="zoomIn()">放大</button>
21
+ <button onclick="zoomOut()">缩小</button>
22
+ <button onclick="zoomActual()">复原</button>
18
23
  </body>
19
24
  <script type="module">
20
25
  import { jmGraph } from "../../index.js";
@@ -23,12 +28,13 @@
23
28
  var container = document.getElementById('mycanvas_container');
24
29
 
25
30
  //开发模式下,引用jmGraph.js,请使用这种方式,内部会初始化组件
26
- var g = jmGraph.create('mycanvas_container', {
31
+ var g = window.graph = jmGraph.create('mycanvas_container', {
27
32
  width: 800,
28
33
  height: 600,
29
34
  mode: '2d',
35
+ autoRefresh: true,
30
36
  style: {
31
- fill: '#000'
37
+ fill: '#000',
32
38
  }
33
39
  });
34
40
  init(g);
@@ -40,6 +46,9 @@
40
46
  stroke: 'red',
41
47
  fill: 'yellow',
42
48
  lineWidth: 2, //边线宽
49
+ rotation: {
50
+ angle: 0
51
+ },
43
52
  //小方块样式
44
53
  rectStyle: {
45
54
  stroke: 'green', //小方块边颜色
@@ -64,12 +73,40 @@
64
73
  resize.canMove(true);
65
74
  g.children.add(resize);
66
75
 
67
- function update() {
68
- g.redraw();
69
- requestAnimationFrame(update);
70
- }
76
+ g.on('update', (time) => {
77
+ //style.rotation.angle += 0.001;
78
+ //g.needUpdate = true;
79
+ });
80
+ }
81
+
82
+
83
+ </script>
84
+ <script>
85
+ var curentScale = {x: 1, y: 1};
86
+ function zoomIn() {
87
+ window.graph && window.graph.scale(1.1, 1.1);
88
+ //window.graph && window.graph.resize(window.graph.width * 1.1, window.graph.height * 1.1);
89
+ //curentScale.x += 0.1;
90
+ //curentScale.y += 0.1;
91
+ //window.graph && (window.graph.canvas.style.transform = `scale(${curentScale.x}, ${curentScale.y})`);
92
+ }
93
+
94
+ function zoomOut() {
95
+ window.graph && window.graph.scale(0.9, 0.9);
96
+ //window.graph && window.graph.resize(window.graph.width * 0.9, window.graph.height * 0.9);
97
+ //curentScale.x -= 0.1;
98
+ //curentScale.y -= 0.1;
99
+ //window.graph && (window.graph.canvas.style.transform = `scale(${curentScale.x}, ${curentScale.y})`);
100
+
101
+ }
102
+
103
+ function zoomActual() {
104
+ window.graph && window.graph.zoomActual();
105
+ //window.graph && window.graph.resize(800, 600);
106
+ //curentScale.x = 1;
107
+ //curentScale.y = 1;
108
+ //window.graph && (window.graph.canvas.style.transform = `scale(${curentScale.x}, ${curentScale.y})`);
71
109
 
72
- update();
73
110
  }
74
111
  </script>
75
112
  </html>
@@ -32,11 +32,12 @@
32
32
  <li>
33
33
  <a href="controls/bezier.html" target="webbrowers">贝塞尔曲线</a></li>
34
34
 
35
- <li><a href="controls/Arrowline.html" target="webbrowers">箭头</a></li>
35
+ <li><a href="controls/arrowline.html" target="webbrowers">箭头</a></li>
36
36
  <li><a href="controls/img.html" target="webbrowers">图片</a></li>
37
37
  <li><a href="controls/label.html" target="webbrowers">文字</a></li>
38
38
  <li><a href="controls/prismatic.html" target="webbrowers">棱形</a></li>
39
39
  <li><a href="controls/resize.html" target="webbrowers">可缩放方块</a></li>
40
+ <li><a href="music.html" target="webbrowers">音乐图谱</a></li>
40
41
  <li><a href="pso.html" target="webbrowers">PSO</a></li>
41
42
  <li><a href="heartarc.html" target="webbrowers">心图</a></li>
42
43
  </ul>