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
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
// 生成纹理
|
|
3
|
-
function create2DTexture(gl) {
|
|
4
|
-
const texture = gl.createTexture();
|
|
5
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1); // 图像反转Y轴
|
|
6
|
-
gl.activeTexture(gl.TEXTURE0); // 激活纹理单元
|
|
7
|
-
gl.bindTexture(gl.TEXTURE_2D, texture); // 绑定纹理对象
|
|
8
|
-
|
|
9
|
-
//gl.generateMipmap(gl.TEXTURE_2D);
|
|
10
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // 放大处理方式 // LINEAR / NEAREST
|
|
11
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // 缩小处理方式
|
|
12
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // 水平平铺方式
|
|
13
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // 竖直平铺方式
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return texture;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 创建图片纹理
|
|
20
|
-
function createImgTexture(gl, img) {
|
|
21
|
-
const texture = create2DTexture(gl);
|
|
22
|
-
|
|
23
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img) // 配置纹理图像
|
|
24
|
-
return {
|
|
25
|
-
texture
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 用像素值来绘制纹理
|
|
30
|
-
function createDataTexture(gl, pixels) {
|
|
31
|
-
const data = new Uint8Array(pixels.data || pixels);
|
|
32
|
-
|
|
33
|
-
const texture = create2DTexture(gl);
|
|
34
|
-
|
|
35
|
-
gl.texImage2D(
|
|
36
|
-
gl.TEXTURE_2D, // 纹理目标
|
|
37
|
-
0, // 细节级别,指定详细级别。0 级是基本图像等级,n 级是第 n 个金字塔简化级。
|
|
38
|
-
gl.RGBA, // 纹理内部格式
|
|
39
|
-
pixels.width || 1, // 指定纹理的宽度
|
|
40
|
-
pixels.height || 1, // 指定纹理的高度
|
|
41
|
-
0, // 指定纹理的边框宽度。必须为 0。
|
|
42
|
-
gl.RGBA, // 源图像数据格式
|
|
43
|
-
gl.UNSIGNED_BYTE, // 纹理数据类型
|
|
44
|
-
data // 数据
|
|
45
|
-
);
|
|
46
|
-
return {
|
|
47
|
-
texture
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 删除纹理
|
|
52
|
-
function deleteTexture(gl, texture) {
|
|
53
|
-
return gl.deleteTexture(texture);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
create2DTexture,
|
|
58
|
-
createImgTexture,
|
|
59
|
-
createDataTexture,
|
|
60
|
-
deleteTexture
|
|
1
|
+
|
|
2
|
+
// 生成纹理
|
|
3
|
+
function create2DTexture(gl) {
|
|
4
|
+
const texture = gl.createTexture();
|
|
5
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1); // 图像反转Y轴
|
|
6
|
+
gl.activeTexture(gl.TEXTURE0); // 激活纹理单元
|
|
7
|
+
gl.bindTexture(gl.TEXTURE_2D, texture); // 绑定纹理对象
|
|
8
|
+
|
|
9
|
+
//gl.generateMipmap(gl.TEXTURE_2D);
|
|
10
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // 放大处理方式 // LINEAR / NEAREST
|
|
11
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // 缩小处理方式
|
|
12
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // 水平平铺方式
|
|
13
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // 竖直平铺方式
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
return texture;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 创建图片纹理
|
|
20
|
+
function createImgTexture(gl, img) {
|
|
21
|
+
const texture = create2DTexture(gl);
|
|
22
|
+
|
|
23
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img) // 配置纹理图像
|
|
24
|
+
return {
|
|
25
|
+
texture
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 用像素值来绘制纹理
|
|
30
|
+
function createDataTexture(gl, pixels) {
|
|
31
|
+
const data = new Uint8Array(pixels.data || pixels);
|
|
32
|
+
|
|
33
|
+
const texture = create2DTexture(gl);
|
|
34
|
+
|
|
35
|
+
gl.texImage2D(
|
|
36
|
+
gl.TEXTURE_2D, // 纹理目标
|
|
37
|
+
0, // 细节级别,指定详细级别。0 级是基本图像等级,n 级是第 n 个金字塔简化级。
|
|
38
|
+
gl.RGBA, // 纹理内部格式
|
|
39
|
+
pixels.width || 1, // 指定纹理的宽度
|
|
40
|
+
pixels.height || 1, // 指定纹理的高度
|
|
41
|
+
0, // 指定纹理的边框宽度。必须为 0。
|
|
42
|
+
gl.RGBA, // 源图像数据格式
|
|
43
|
+
gl.UNSIGNED_BYTE, // 纹理数据类型
|
|
44
|
+
data // 数据
|
|
45
|
+
);
|
|
46
|
+
return {
|
|
47
|
+
texture
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 删除纹理
|
|
52
|
+
function deleteTexture(gl, texture) {
|
|
53
|
+
return gl.deleteTexture(texture);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
create2DTexture,
|
|
58
|
+
createImgTexture,
|
|
59
|
+
createDataTexture,
|
|
60
|
+
deleteTexture
|
|
61
61
|
}
|
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
const WebglGradientTextureCache = {};
|
|
2
|
-
// 渐变
|
|
3
|
-
class WebglGradient {
|
|
4
|
-
// type:[linear= 线性渐变,radial=放射性渐变]
|
|
5
|
-
constructor(type='linear', params={}) {
|
|
6
|
-
this.type = type || 'linear';
|
|
7
|
-
|
|
8
|
-
this.x1 = params.x1 || 0;
|
|
9
|
-
this.y1 = params.y1 || 0;
|
|
10
|
-
this.r1 = params.r1 || 0;
|
|
11
|
-
this.x2 = params.x2 || 0;
|
|
12
|
-
this.y2 = params.y2 || 0;
|
|
13
|
-
this.r2 = params.r2 || 0;
|
|
14
|
-
|
|
15
|
-
this.bounds = params.bounds || {
|
|
16
|
-
left: 0,
|
|
17
|
-
top: 0,
|
|
18
|
-
width: 0,
|
|
19
|
-
height: 0
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.control = params.control;
|
|
23
|
-
|
|
24
|
-
this.stops = [];
|
|
25
|
-
this.init();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
init() {
|
|
29
|
-
const dx = this.x2 - this.x1;
|
|
30
|
-
const dy = this.y2 - this.y1;
|
|
31
|
-
|
|
32
|
-
if(this.type === 'radial') {
|
|
33
|
-
this.length = this.r2 - this.r1;
|
|
34
|
-
}
|
|
35
|
-
else if(dx === 0 && dy === 0) {
|
|
36
|
-
this.length = 0;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// 渐变中心的距离
|
|
40
|
-
this.length = Math.sqrt(Math.pow(dx, 2), Math.pow(dy, 2));
|
|
41
|
-
this.sin = dy / this.length;
|
|
42
|
-
this.cos = dx / this.length;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 渐变颜色
|
|
47
|
-
addColorStop(offset, color) {
|
|
48
|
-
this.stops.push({
|
|
49
|
-
offset,
|
|
50
|
-
color
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 转为渐变为纹理
|
|
55
|
-
toImageData(control, bounds, points=null) {
|
|
56
|
-
//const key = this.key || this.toString();
|
|
57
|
-
//if(WebglGradientTextureCache[key]) return WebglGradientTextureCache[key];
|
|
58
|
-
if(!control.textureContext) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
let gradient = null;
|
|
62
|
-
if(this.type === 'linear') {
|
|
63
|
-
gradient = control.textureContext.createLinearGradient(this.x1, this.y1, this.x2, this.y2);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
gradient = control.textureContext.createRadialGradient(this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
|
|
67
|
-
}
|
|
68
|
-
this.stops.forEach(function(s, i) {
|
|
69
|
-
const c = control.graph.utils.toColor(s.color);
|
|
70
|
-
gradient && gradient.addColorStop(s.offset, c);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const data = control.toFillTexture(gradient, bounds, points);
|
|
74
|
-
|
|
75
|
-
//WebglGradientTextureCache[key] = data;
|
|
76
|
-
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 根据绘制图形的坐标计算出对应点的颜色
|
|
81
|
-
/*
|
|
82
|
-
toPointColors(points) {
|
|
83
|
-
const stops = this.getStops();
|
|
84
|
-
const colors = [];
|
|
85
|
-
for(let i=0; i<points.length; i+=2) {
|
|
86
|
-
const p = {
|
|
87
|
-
x: points[i],
|
|
88
|
-
y: points[i+1]
|
|
89
|
-
}
|
|
90
|
-
if(this.type === 'radial') {
|
|
91
|
-
const dx = p.x - this.x1;
|
|
92
|
-
const dy = p.y - this.y1;
|
|
93
|
-
const len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
94
|
-
const rang = this.getStopRange(len, stops);
|
|
95
|
-
if(!rang.start && rang.end) {
|
|
96
|
-
colors.push(rang.end.color);
|
|
97
|
-
}
|
|
98
|
-
else if(!rang.end && rang.start) {
|
|
99
|
-
colors.push(rang.start.color);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
const rangLength = rang.end.length - rang.start.length;
|
|
103
|
-
const offlen = len - rang.start.length;
|
|
104
|
-
const per = offlen / rangLength;
|
|
105
|
-
const color = {
|
|
106
|
-
r: rang.start.color.r + (rang.end.color.r - rang.start.color.r) * per,
|
|
107
|
-
g: rang.start.color.g + (rang.end.color.g - rang.start.color.g) * per,
|
|
108
|
-
b: rang.start.color.b + (rang.end.color.b - rang.start.color.b) * per,
|
|
109
|
-
a: rang.start.color.a + (rang.end.color.a - rang.start.color.a) * per,
|
|
110
|
-
};
|
|
111
|
-
colors.push(color);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return colors;
|
|
116
|
-
}
|
|
117
|
-
*/
|
|
118
|
-
// 根据起点距离获取边界stop
|
|
119
|
-
/*
|
|
120
|
-
getStopRange(len, stops) {
|
|
121
|
-
const res = {};
|
|
122
|
-
for(const s of stops) {
|
|
123
|
-
if(s.length <= len) {
|
|
124
|
-
res.start = s;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
res.end = s;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return res;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 根据stop计算offset长度
|
|
134
|
-
getStops() {
|
|
135
|
-
const stops = this.stops.sort((p1, p2) => p1.offset - p2.offset); // 渐变色排序从小于大
|
|
136
|
-
for(const s of stops) {
|
|
137
|
-
|
|
138
|
-
const color = typeof s.color === 'string'? this.control.graph.utils.hexToRGBA(s.color) : s.color;
|
|
139
|
-
console.log(s, color);
|
|
140
|
-
s.color = this.control.graph.utils.rgbToDecimal(color);
|
|
141
|
-
s.length = s.offset * this.length;
|
|
142
|
-
}
|
|
143
|
-
return stops;
|
|
144
|
-
}
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* 转换为渐变的字符串表达
|
|
148
|
-
*
|
|
149
|
-
* @method toString
|
|
150
|
-
* @for jmGradient
|
|
151
|
-
* @return {string} linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
152
|
-
*/
|
|
153
|
-
toString() {
|
|
154
|
-
let str = this.type + '-gradient(';
|
|
155
|
-
if(this.type == 'linear') {
|
|
156
|
-
str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
|
|
160
|
-
}
|
|
161
|
-
//颜色渐变
|
|
162
|
-
this.stops.forEach(function(s) {
|
|
163
|
-
str += ',' + s.color + ' ' + s.offset;
|
|
164
|
-
});
|
|
165
|
-
return str + ')';
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
1
|
+
const WebglGradientTextureCache = {};
|
|
2
|
+
// 渐变
|
|
3
|
+
class WebglGradient {
|
|
4
|
+
// type:[linear= 线性渐变,radial=放射性渐变]
|
|
5
|
+
constructor(type='linear', params={}) {
|
|
6
|
+
this.type = type || 'linear';
|
|
7
|
+
|
|
8
|
+
this.x1 = params.x1 || 0;
|
|
9
|
+
this.y1 = params.y1 || 0;
|
|
10
|
+
this.r1 = params.r1 || 0;
|
|
11
|
+
this.x2 = params.x2 || 0;
|
|
12
|
+
this.y2 = params.y2 || 0;
|
|
13
|
+
this.r2 = params.r2 || 0;
|
|
14
|
+
|
|
15
|
+
this.bounds = params.bounds || {
|
|
16
|
+
left: 0,
|
|
17
|
+
top: 0,
|
|
18
|
+
width: 0,
|
|
19
|
+
height: 0
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.control = params.control;
|
|
23
|
+
|
|
24
|
+
this.stops = [];
|
|
25
|
+
this.init();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
init() {
|
|
29
|
+
const dx = this.x2 - this.x1;
|
|
30
|
+
const dy = this.y2 - this.y1;
|
|
31
|
+
|
|
32
|
+
if(this.type === 'radial') {
|
|
33
|
+
this.length = this.r2 - this.r1;
|
|
34
|
+
}
|
|
35
|
+
else if(dx === 0 && dy === 0) {
|
|
36
|
+
this.length = 0;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// 渐变中心的距离
|
|
40
|
+
this.length = Math.sqrt(Math.pow(dx, 2), Math.pow(dy, 2));
|
|
41
|
+
this.sin = dy / this.length;
|
|
42
|
+
this.cos = dx / this.length;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 渐变颜色
|
|
47
|
+
addColorStop(offset, color) {
|
|
48
|
+
this.stops.push({
|
|
49
|
+
offset,
|
|
50
|
+
color
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 转为渐变为纹理
|
|
55
|
+
toImageData(control, bounds, points=null) {
|
|
56
|
+
//const key = this.key || this.toString();
|
|
57
|
+
//if(WebglGradientTextureCache[key]) return WebglGradientTextureCache[key];
|
|
58
|
+
if(!control.textureContext) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
let gradient = null;
|
|
62
|
+
if(this.type === 'linear') {
|
|
63
|
+
gradient = control.textureContext.createLinearGradient(this.x1, this.y1, this.x2, this.y2);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
gradient = control.textureContext.createRadialGradient(this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
|
|
67
|
+
}
|
|
68
|
+
this.stops.forEach(function(s, i) {
|
|
69
|
+
const c = control.graph.utils.toColor(s.color);
|
|
70
|
+
gradient && gradient.addColorStop(s.offset, c);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const data = control.toFillTexture(gradient, bounds, points);
|
|
74
|
+
|
|
75
|
+
//WebglGradientTextureCache[key] = data;
|
|
76
|
+
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 根据绘制图形的坐标计算出对应点的颜色
|
|
81
|
+
/*
|
|
82
|
+
toPointColors(points) {
|
|
83
|
+
const stops = this.getStops();
|
|
84
|
+
const colors = [];
|
|
85
|
+
for(let i=0; i<points.length; i+=2) {
|
|
86
|
+
const p = {
|
|
87
|
+
x: points[i],
|
|
88
|
+
y: points[i+1]
|
|
89
|
+
}
|
|
90
|
+
if(this.type === 'radial') {
|
|
91
|
+
const dx = p.x - this.x1;
|
|
92
|
+
const dy = p.y - this.y1;
|
|
93
|
+
const len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
94
|
+
const rang = this.getStopRange(len, stops);
|
|
95
|
+
if(!rang.start && rang.end) {
|
|
96
|
+
colors.push(rang.end.color);
|
|
97
|
+
}
|
|
98
|
+
else if(!rang.end && rang.start) {
|
|
99
|
+
colors.push(rang.start.color);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const rangLength = rang.end.length - rang.start.length;
|
|
103
|
+
const offlen = len - rang.start.length;
|
|
104
|
+
const per = offlen / rangLength;
|
|
105
|
+
const color = {
|
|
106
|
+
r: rang.start.color.r + (rang.end.color.r - rang.start.color.r) * per,
|
|
107
|
+
g: rang.start.color.g + (rang.end.color.g - rang.start.color.g) * per,
|
|
108
|
+
b: rang.start.color.b + (rang.end.color.b - rang.start.color.b) * per,
|
|
109
|
+
a: rang.start.color.a + (rang.end.color.a - rang.start.color.a) * per,
|
|
110
|
+
};
|
|
111
|
+
colors.push(color);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return colors;
|
|
116
|
+
}
|
|
117
|
+
*/
|
|
118
|
+
// 根据起点距离获取边界stop
|
|
119
|
+
/*
|
|
120
|
+
getStopRange(len, stops) {
|
|
121
|
+
const res = {};
|
|
122
|
+
for(const s of stops) {
|
|
123
|
+
if(s.length <= len) {
|
|
124
|
+
res.start = s;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
res.end = s;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return res;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 根据stop计算offset长度
|
|
134
|
+
getStops() {
|
|
135
|
+
const stops = this.stops.sort((p1, p2) => p1.offset - p2.offset); // 渐变色排序从小于大
|
|
136
|
+
for(const s of stops) {
|
|
137
|
+
|
|
138
|
+
const color = typeof s.color === 'string'? this.control.graph.utils.hexToRGBA(s.color) : s.color;
|
|
139
|
+
console.log(s, color);
|
|
140
|
+
s.color = this.control.graph.utils.rgbToDecimal(color);
|
|
141
|
+
s.length = s.offset * this.length;
|
|
142
|
+
}
|
|
143
|
+
return stops;
|
|
144
|
+
}
|
|
145
|
+
*/
|
|
146
|
+
/**
|
|
147
|
+
* 转换为渐变的字符串表达
|
|
148
|
+
*
|
|
149
|
+
* @method toString
|
|
150
|
+
* @for jmGradient
|
|
151
|
+
* @return {string} linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
152
|
+
*/
|
|
153
|
+
toString() {
|
|
154
|
+
let str = this.type + '-gradient(';
|
|
155
|
+
if(this.type == 'linear') {
|
|
156
|
+
str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
|
|
160
|
+
}
|
|
161
|
+
//颜色渐变
|
|
162
|
+
this.stops.forEach(function(s) {
|
|
163
|
+
str += ',' + s.color + ' ' + s.offset;
|
|
164
|
+
});
|
|
165
|
+
return str + ')';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
169
|
export default WebglGradient;
|
package/src/lib/webgl/index.js
CHANGED
|
@@ -1,11 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 采用webgl基础绘图
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 采用webgl基础绘图
|
|
5
|
+
*/
|
|
6
|
+
import WebglBase from './base.js';
|
|
7
|
+
import WebglPath from './path.js';
|
|
8
|
+
|
|
9
|
+
class webgl {
|
|
10
|
+
constructor(context, option) {
|
|
11
|
+
this.option = option || {};
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.base = new WebglBase(null, option);
|
|
14
|
+
this.base.context = context;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 保存当前状态
|
|
18
|
+
save() {
|
|
19
|
+
this.base.save();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 恢复上一个状态
|
|
23
|
+
restore() {
|
|
24
|
+
this.base.restore();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 平移变换
|
|
28
|
+
translate(x, y) {
|
|
29
|
+
this.base.translate(x, y);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 缩放变换
|
|
33
|
+
scale(sx, sy) {
|
|
34
|
+
this.base.scale(sx, sy);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 旋转变换
|
|
38
|
+
rotate(angle) {
|
|
39
|
+
this.base.rotate(angle);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 矩阵变换
|
|
43
|
+
transform(a, b, c, d, e, f) {
|
|
44
|
+
this.base.transform(a, b, c, d, e, f);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 开始路径
|
|
48
|
+
beginPath() {
|
|
49
|
+
// WebGL 中不需要 beginPath,由具体的绘制方法处理
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 关闭路径
|
|
53
|
+
closePath() {
|
|
54
|
+
// WebGL 中不需要 closePath,由具体的绘制方法处理
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 移动到指定点
|
|
58
|
+
moveTo(x, y) {
|
|
59
|
+
// WebGL 中不需要 moveTo,由具体的绘制方法处理
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 绘制直线
|
|
63
|
+
lineTo(x, y) {
|
|
64
|
+
// WebGL 中不需要 lineTo,由具体的绘制方法处理
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 填充路径
|
|
68
|
+
fill() {
|
|
69
|
+
// WebGL 中不需要 fill,由具体的绘制方法处理
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 描边路径
|
|
73
|
+
stroke() {
|
|
74
|
+
// WebGL 中不需要 stroke,由具体的绘制方法处理
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 清除矩形区域
|
|
78
|
+
clearRect(x, y, width, height) {
|
|
79
|
+
this.context.clearColor(0, 0, 0, 0);
|
|
80
|
+
this.context.clear(this.context.COLOR_BUFFER_BIT);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 设置线条宽度
|
|
84
|
+
lineWidth(width) {
|
|
85
|
+
// 由具体的绘制方法处理
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 设置填充样式
|
|
89
|
+
fillStyle(style) {
|
|
90
|
+
// 由具体的绘制方法处理
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 设置描边样式
|
|
94
|
+
strokeStyle(style) {
|
|
95
|
+
// 由具体的绘制方法处理
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 绘制文本
|
|
99
|
+
fillText(text, x, y, maxWidth) {
|
|
100
|
+
// 由具体的绘制方法处理
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 描边文本
|
|
104
|
+
strokeText(text, x, y, maxWidth) {
|
|
105
|
+
// 由具体的绘制方法处理
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 测量文本宽度
|
|
109
|
+
measureText(text) {
|
|
110
|
+
// 使用 2D canvas 测量
|
|
111
|
+
const canvas = document.createElement('canvas');
|
|
112
|
+
const ctx = canvas.getContext('2d');
|
|
113
|
+
return ctx.measureText(text);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 创建线性渐变
|
|
117
|
+
createLinearGradient(x1, y1, x2, y2) {
|
|
118
|
+
return this.base.createLinearGradient(x1, y1, x2, y2);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 创建径向渐变
|
|
122
|
+
createRadialGradient(x1, y1, r1, x2, y2, r2) {
|
|
123
|
+
return this.base.createRadialGradient(x1, y1, r1, x2, y2, r2);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 绘制图像
|
|
127
|
+
drawImage(img, dx, dy, dWidth, dHeight) {
|
|
128
|
+
// 由具体的绘制方法处理
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 创建 WebglPath 实例
|
|
132
|
+
createPath(option) {
|
|
133
|
+
return new WebglPath(null, option);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default webgl;
|