jmgraph 3.2.2 → 3.2.3
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 +4 -4
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3064 -351
- package/dist/jmgraph.min.js +1 -1
- package/index.js +4 -0
- package/package.json +4 -4
- package/src/core/jmControl.js +97 -57
- package/src/core/jmGradient.js +29 -14
- package/src/core/jmGraph.js +70 -26
- package/src/core/jmObject.js +2 -3
- package/src/core/jmPath.js +19 -3
- package/src/core/jmProperty.js +29 -14
- package/src/core/jmUtils.js +218 -31
- package/src/lib/earcut.js +680 -0
- package/src/lib/earcut.md +73 -0
- package/src/lib/webgl/base.js +201 -0
- package/src/lib/webgl/core/buffer.js +48 -0
- package/src/lib/webgl/core/mapSize.js +40 -0
- package/src/lib/webgl/core/mapType.js +43 -0
- package/src/lib/webgl/core/program.js +139 -0
- package/src/lib/webgl/core/shader.js +14 -0
- package/src/lib/webgl/core/texture.js +61 -0
- package/src/lib/webgl/gradient.js +196 -0
- package/src/lib/webgl/index.js +11 -0
- package/src/lib/webgl/path.js +679 -0
- package/src/shapes/jmArc.js +15 -11
- package/src/shapes/jmArrow.js +10 -10
- package/src/shapes/jmBezier.js +2 -2
- package/src/shapes/jmCircle.js +8 -1
- package/src/shapes/jmHArc.js +17 -15
- package/src/shapes/jmImage.js +68 -38
- package/src/shapes/jmLabel.js +11 -10
- package/src/shapes/jmLine.js +20 -12
- package/src/shapes/jmPrismatic.js +4 -2
- package/src/shapes/jmRect.js +5 -4
- package/src/shapes/jmResize.js +6 -4
package/src/core/jmPath.js
CHANGED
|
@@ -13,7 +13,7 @@ export default class jmPath extends jmControl {
|
|
|
13
13
|
constructor(params, t='jmPath') {
|
|
14
14
|
super(params, t);
|
|
15
15
|
this.points = params && params.points ? params.points : [];
|
|
16
|
-
|
|
16
|
+
this.polygonIndices = params && params.polygonIndices ? params.polygonIndices : [];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,13 +23,29 @@ export default class jmPath extends jmControl {
|
|
|
23
23
|
* @type {array}
|
|
24
24
|
*/
|
|
25
25
|
get points() {
|
|
26
|
-
let s = this.
|
|
26
|
+
let s = this.property('points');
|
|
27
27
|
return s;
|
|
28
28
|
}
|
|
29
29
|
set points(v) {
|
|
30
30
|
this.needUpdate = true;
|
|
31
|
-
return this.
|
|
31
|
+
return this.property('points', v);
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 顶点数组索引,对应points中的顶点
|
|
36
|
+
* @property polygonIndices
|
|
37
|
+
* @type {array}
|
|
38
|
+
*/
|
|
39
|
+
get polygonIndices() {
|
|
40
|
+
let s = this.property('polygonIndices');
|
|
41
|
+
return s;
|
|
42
|
+
}
|
|
43
|
+
set polygonIndices(v) {
|
|
44
|
+
this.needUpdate = true;
|
|
45
|
+
return this.property('polygonIndices', v);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
export { jmPath };
|
package/src/core/jmProperty.js
CHANGED
|
@@ -13,31 +13,31 @@ const PROPERTY_KEY = Symbol("properties");
|
|
|
13
13
|
*/
|
|
14
14
|
export default class jmProperty extends jmObject {
|
|
15
15
|
|
|
16
|
-
constructor() {
|
|
16
|
+
constructor(params) {
|
|
17
17
|
super();
|
|
18
|
-
|
|
19
18
|
this[PROPERTY_KEY] = {};
|
|
19
|
+
if(params && params.mode) this.mode = params.mode;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* 基础属性读写接口
|
|
24
|
-
* @method
|
|
24
|
+
* @method property
|
|
25
25
|
* @param {string} name 属性名
|
|
26
26
|
* @param {any} value 属性的值
|
|
27
27
|
* @returns {any} 属性的值
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
property(...pars) {
|
|
30
30
|
if(pars) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const pros = this[PROPERTY_KEY];
|
|
32
|
+
const name = pars[0];
|
|
33
33
|
if(pars.length > 1) {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const value = pars[1];
|
|
35
|
+
const args = {oldValue: pros[name], newValue: value};
|
|
36
36
|
pros[name] = pars[1];
|
|
37
37
|
if(this.emit) this.emit('propertyChange', name, args);
|
|
38
38
|
return pars[1];
|
|
39
39
|
}
|
|
40
|
-
else if(
|
|
40
|
+
else if(name) {
|
|
41
41
|
return pros[name];
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -49,10 +49,10 @@ export default class jmProperty extends jmObject {
|
|
|
49
49
|
* @type {boolean}
|
|
50
50
|
*/
|
|
51
51
|
get needUpdate() {
|
|
52
|
-
return this.
|
|
52
|
+
return this.property('needUpdate');
|
|
53
53
|
}
|
|
54
54
|
set needUpdate(v) {
|
|
55
|
-
this.
|
|
55
|
+
this.property('needUpdate', v);
|
|
56
56
|
//子控件属性改变,需要更新整个画板
|
|
57
57
|
if(v && !this.is('jmGraph') && this.graph) {
|
|
58
58
|
this.graph.needUpdate = true;
|
|
@@ -65,12 +65,27 @@ export default class jmProperty extends jmObject {
|
|
|
65
65
|
* @type {jmGraph}
|
|
66
66
|
*/
|
|
67
67
|
get graph() {
|
|
68
|
-
let g = this.
|
|
69
|
-
g = g || (this.
|
|
68
|
+
let g = this.property('graph');
|
|
69
|
+
g = g || (this.property('graph', this.findParent('jmGraph')));
|
|
70
70
|
return g;
|
|
71
71
|
}
|
|
72
72
|
set graph(v) {
|
|
73
|
-
return this.
|
|
73
|
+
return this.property('graph', v);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 绘制模式 2d/webgl
|
|
78
|
+
* @property mode
|
|
79
|
+
* @type {string}
|
|
80
|
+
*/
|
|
81
|
+
get mode() {
|
|
82
|
+
let m = this.property('mode');
|
|
83
|
+
if(m) return m;
|
|
84
|
+
else if(this.is('jmGraph')) return this.property('mode');
|
|
85
|
+
return this.graph.mode;
|
|
86
|
+
}
|
|
87
|
+
set mode(v) {
|
|
88
|
+
return this.property('mode', v);
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
/**
|
package/src/core/jmUtils.js
CHANGED
|
@@ -1,6 +1,151 @@
|
|
|
1
1
|
|
|
2
2
|
import { jmList } from './jmList.js';
|
|
3
3
|
|
|
4
|
+
const colorKeywords = {
|
|
5
|
+
aliceblue: "#f0f8ff",
|
|
6
|
+
antiquewhite: "#faebd7",
|
|
7
|
+
aqua: "#00ffff",
|
|
8
|
+
aquamarine: "#7fffd4",
|
|
9
|
+
azure: "#f0ffff",
|
|
10
|
+
beige: "#f5f5dc",
|
|
11
|
+
bisque: "#ffe4c4",
|
|
12
|
+
black: "#000000",
|
|
13
|
+
blanchedalmond: "#ffebcd",
|
|
14
|
+
blue: "#0000ff",
|
|
15
|
+
blueviolet: "#8a2be2",
|
|
16
|
+
brown: "#a52a2a",
|
|
17
|
+
burlywood: "#deb887",
|
|
18
|
+
cadetblue: "#5f9ea0",
|
|
19
|
+
chartreuse: "#7fff00",
|
|
20
|
+
chocolate: "#d2691e",
|
|
21
|
+
coral: "#ff7f50",
|
|
22
|
+
cornflowerblue: "#6495ed",
|
|
23
|
+
cornsilk: "#fff8dc",
|
|
24
|
+
crimson: "#dc143c",
|
|
25
|
+
cyan: "#00ffff",
|
|
26
|
+
darkblue: "#00008b",
|
|
27
|
+
darkcyan: "#008b8b",
|
|
28
|
+
darkgoldenrod: "#b8860b",
|
|
29
|
+
darkgray: "#a9a9a9",
|
|
30
|
+
darkgreen: "#006400",
|
|
31
|
+
darkkhaki: "#bdb76b",
|
|
32
|
+
darkmagenta: "#8b008b",
|
|
33
|
+
darkolivegreen: "#556b2f",
|
|
34
|
+
darkorange: "#ff8c00",
|
|
35
|
+
darkorchid: "#9932cc",
|
|
36
|
+
darkred: "#8b0000",
|
|
37
|
+
darksalmon: "#e9967a",
|
|
38
|
+
darkseagreen: "#8fbc8f",
|
|
39
|
+
darkslateblue: "#483d8b",
|
|
40
|
+
darkslategray: "#2f4f4f",
|
|
41
|
+
darkturquoise: "#00ced1",
|
|
42
|
+
darkviolet: "#9400d3",
|
|
43
|
+
deeppink: "#ff1493",
|
|
44
|
+
deepskyblue: "#00bfff",
|
|
45
|
+
dimgray: "#696969",
|
|
46
|
+
dodgerblue: "#1e90ff",
|
|
47
|
+
firebrick: "#b22222",
|
|
48
|
+
floralwhite: "#fffaf0",
|
|
49
|
+
forestgreen: "#228b22",
|
|
50
|
+
fuchsia: "#ff00ff",
|
|
51
|
+
gainsboro: "#dcdcdc",
|
|
52
|
+
ghostwhite: "#f8f8ff",
|
|
53
|
+
gold: "#ffd700",
|
|
54
|
+
goldenrod: "#daa520",
|
|
55
|
+
gray: "#808080",
|
|
56
|
+
green: "#008000",
|
|
57
|
+
greenyellow: "#adff2f",
|
|
58
|
+
grey: "#808080",
|
|
59
|
+
honeydew: "#f0fff0",
|
|
60
|
+
hotpink: "#ff69b4",
|
|
61
|
+
indianred: "#cd5c5c",
|
|
62
|
+
indigo: "#4b0082",
|
|
63
|
+
ivory: "#fffff0",
|
|
64
|
+
khaki: "#f0e68c",
|
|
65
|
+
lavender: "#e6e6fa",
|
|
66
|
+
lavenderblush: "#fff0f5",
|
|
67
|
+
lawngreen: "#7cfc00",
|
|
68
|
+
lemonchiffon: "#fffacd",
|
|
69
|
+
lightblue: "#add8e6",
|
|
70
|
+
lightcoral: "#f08080",
|
|
71
|
+
lightcyan: "#e0ffff",
|
|
72
|
+
lightgoldenrodyellow: "#fafad2",
|
|
73
|
+
lightgrey: "#d3d3d3",
|
|
74
|
+
lightgreen: "#90ee90",
|
|
75
|
+
lightpink: "#ffb6c1",
|
|
76
|
+
lightsalmon: "#ffa07a",
|
|
77
|
+
lightseagreen: "#20b2aa",
|
|
78
|
+
lightskyblue: "#87cefa",
|
|
79
|
+
lightslategray: "#778899",
|
|
80
|
+
lightsteelblue: "#b0c4de",
|
|
81
|
+
lightyellow: "#ffffe0",
|
|
82
|
+
lime: "#00ff00",
|
|
83
|
+
limegreen: "#32cd32",
|
|
84
|
+
linen: "#faf0e6",
|
|
85
|
+
magenta: "#ff00ff",
|
|
86
|
+
maroon: "#800000",
|
|
87
|
+
mediumaquamarine: "#66cdaa",
|
|
88
|
+
mediumblue: "#0000cd",
|
|
89
|
+
mediumorchid: "#ba55d3",
|
|
90
|
+
mediumpurple: "#9370d8",
|
|
91
|
+
mediumseagreen: "#3cb371",
|
|
92
|
+
mediumslateblue: "#7b68ee",
|
|
93
|
+
mediumspringgreen: "#00fa9a",
|
|
94
|
+
mediumturquoise: "#48d1cc",
|
|
95
|
+
mediumvioletred: "#c71585",
|
|
96
|
+
midnightblue: "#191970",
|
|
97
|
+
mintcream: "#f5fffa",
|
|
98
|
+
mistyrose: "#ffe4e1",
|
|
99
|
+
moccasin: "#ffe4b5",
|
|
100
|
+
navajowhite: "#ffdead",
|
|
101
|
+
navy: "#000080",
|
|
102
|
+
oldlace: "#fdf5e6",
|
|
103
|
+
olive: "#808000",
|
|
104
|
+
olivedrab: "#6b8e23",
|
|
105
|
+
orange: "#ffa500",
|
|
106
|
+
orangered: "#ff4500",
|
|
107
|
+
orchid: "#da70d6",
|
|
108
|
+
palegoldenrod: "#eee8aa",
|
|
109
|
+
palegreen: "#98fb98",
|
|
110
|
+
paleturquoise: "#afeeee",
|
|
111
|
+
palevioletred: "#d87093",
|
|
112
|
+
papayawhip: "#ffefd5",
|
|
113
|
+
peachpuff: "#ffdab9",
|
|
114
|
+
peru: "#cd853f",
|
|
115
|
+
pink: "#ffc0cb",
|
|
116
|
+
plum: "#dda0dd",
|
|
117
|
+
powderblue: "#b0e0e6",
|
|
118
|
+
purple: "#800080",
|
|
119
|
+
red: "#ff0000",
|
|
120
|
+
rosybrown: "#bc8f8f",
|
|
121
|
+
royalblue: "#4169e1",
|
|
122
|
+
saddlebrown: "#8b4513",
|
|
123
|
+
salmon: "#fa8072",
|
|
124
|
+
sandybrown: "#f4a460",
|
|
125
|
+
seagreen: "#2e8b57",
|
|
126
|
+
seashell: "#fff5ee",
|
|
127
|
+
sienna: "#a0522d",
|
|
128
|
+
silver: "#c0c0c0",
|
|
129
|
+
skyblue: "#87ceeb",
|
|
130
|
+
slateblue: "#6a5acd",
|
|
131
|
+
slategray: "#708090",
|
|
132
|
+
snow: "#fffafa",
|
|
133
|
+
springgreen: "#00ff7f",
|
|
134
|
+
steelblue: "#4682b4",
|
|
135
|
+
tan: "#d2b48c",
|
|
136
|
+
teal: "#008080",
|
|
137
|
+
thistle: "#d8bfd8",
|
|
138
|
+
tomato: "#ff6347",
|
|
139
|
+
turquoise: "#40e0d0",
|
|
140
|
+
violet: "#ee82ee",
|
|
141
|
+
wheat: "#f5deb3",
|
|
142
|
+
white: "#ffffff",
|
|
143
|
+
whitesmoke: "#f5f5f5",
|
|
144
|
+
yellow: "#ffff00",
|
|
145
|
+
yellowgreen: "#9acd32",
|
|
146
|
+
transparent: "rgba(0,0,0,0)"
|
|
147
|
+
};
|
|
148
|
+
|
|
4
149
|
/**
|
|
5
150
|
* 画图基础对象
|
|
6
151
|
* 当前库的工具类
|
|
@@ -63,7 +208,10 @@ export default class jmUtils {
|
|
|
63
208
|
if(k === 'constructor') continue;
|
|
64
209
|
const v = source[k];
|
|
65
210
|
// 不复制页面元素和class对象
|
|
66
|
-
if(v && (v.tagName || v.getContext))
|
|
211
|
+
if(v && (v.tagName || v.getContext)) {
|
|
212
|
+
target[k] = v;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
67
215
|
|
|
68
216
|
// 如果不是对象和空,则采用target的属性
|
|
69
217
|
if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
|
|
@@ -613,65 +761,104 @@ export default class jmUtils {
|
|
|
613
761
|
* @param {string}} hex 16进度的颜色
|
|
614
762
|
*/
|
|
615
763
|
static hexToRGBA(hex) {
|
|
616
|
-
hex = this.trim(hex);
|
|
764
|
+
if(typeof hex === 'string') hex = this.trim(hex);
|
|
765
|
+
else return hex;
|
|
766
|
+
|
|
767
|
+
// 如果缓存存在,则直接返回
|
|
768
|
+
this.__hexToRGBA_Cache = this.__hexToRGBA_Cache || {};
|
|
769
|
+
if(this.__hexToRGBA_Cache[hex]) return this.__hexToRGBA_Cache[hex];
|
|
770
|
+
|
|
771
|
+
let res = hex;
|
|
772
|
+
|
|
773
|
+
// 系统颜色
|
|
774
|
+
if(colorKeywords[res]) res = colorKeywords[res];
|
|
617
775
|
|
|
618
776
|
//当为7位时,表示需要转为带透明度的rgba
|
|
619
|
-
if(
|
|
777
|
+
if(res[0] == '#') {
|
|
620
778
|
const color = {
|
|
621
779
|
a: 1
|
|
622
780
|
};
|
|
623
|
-
if(
|
|
624
|
-
color.a =
|
|
625
|
-
color.g =
|
|
626
|
-
color.b =
|
|
627
|
-
color.r =
|
|
781
|
+
if(res.length >= 8) {
|
|
782
|
+
color.a = res.substr(1,2);
|
|
783
|
+
color.g = res.substr(5,2);
|
|
784
|
+
color.b = res.substr(7,2);
|
|
785
|
+
color.r = res.substr(3,2);
|
|
628
786
|
//透明度
|
|
629
|
-
color.a = (this.hexToNumber(color.a) / 255).toFixed(4);
|
|
787
|
+
color.a = Number((this.hexToNumber(color.a) / 255).toFixed(4));
|
|
630
788
|
|
|
631
789
|
color.r = this.hexToNumber(color.r||0);
|
|
632
790
|
color.g = this.hexToNumber(color.g||0);
|
|
633
791
|
color.b = this.hexToNumber(color.b||0);
|
|
634
|
-
|
|
792
|
+
res = color;
|
|
635
793
|
}
|
|
636
794
|
// #cccccc || #ccc
|
|
637
|
-
else if(
|
|
795
|
+
else if(res.length === 7 || res.length === 4) {
|
|
638
796
|
// #ccc这种情况,把每个位复制一份
|
|
639
|
-
if(
|
|
640
|
-
color.g =
|
|
797
|
+
if(res.length === 4) {
|
|
798
|
+
color.g = res.substr(2, 1);
|
|
641
799
|
color.g = color.g + color.g;
|
|
642
|
-
color.b =
|
|
800
|
+
color.b = res.substr(3, 1);
|
|
643
801
|
color.b = color.b + color.b;
|
|
644
|
-
color.r =
|
|
802
|
+
color.r = res.substr(1, 1);
|
|
645
803
|
color.r = color.r + color.r;
|
|
646
804
|
}
|
|
647
805
|
else {
|
|
648
|
-
color.g =
|
|
649
|
-
color.b =
|
|
650
|
-
color.r =
|
|
806
|
+
color.g = res.substr(3, 2);//除#号外的第二位
|
|
807
|
+
color.b = res.substr(5, 2);
|
|
808
|
+
color.r = res.substr(1, 2);
|
|
651
809
|
}
|
|
652
810
|
|
|
653
811
|
color.r = this.hexToNumber(color.r||0);
|
|
654
812
|
color.g = this.hexToNumber(color.g||0);
|
|
655
813
|
color.b = this.hexToNumber(color.b||0);
|
|
656
814
|
|
|
657
|
-
|
|
815
|
+
res = color;
|
|
658
816
|
}
|
|
659
817
|
//如果是5位的话,# 则第2位表示A,后面依次是r,g,b
|
|
660
|
-
else if(
|
|
661
|
-
color.a =
|
|
662
|
-
color.g =
|
|
663
|
-
color.b =
|
|
664
|
-
color.r =
|
|
818
|
+
else if(res.length === 5) {
|
|
819
|
+
color.a = res.substr(1,1);
|
|
820
|
+
color.g = res.substr(3,1);//除#号外的第二位
|
|
821
|
+
color.b = res.substr(4,1);
|
|
822
|
+
color.r = res.substr(2,1);
|
|
665
823
|
|
|
666
824
|
color.r = this.hexToNumber(color.r||0);
|
|
667
825
|
color.g = this.hexToNumber(color.g||0);
|
|
668
826
|
color.b = this.hexToNumber(color.b||0);
|
|
669
827
|
//透明度
|
|
670
|
-
color.a = (this.hexToNumber(color.a) / 255).toFixed(4);
|
|
671
|
-
|
|
828
|
+
color.a = Number((this.hexToNumber(color.a) / 255).toFixed(4));
|
|
829
|
+
res = color;
|
|
672
830
|
}
|
|
673
831
|
}
|
|
674
|
-
|
|
832
|
+
if(typeof res === 'string') {
|
|
833
|
+
const m = res.match(/rgb(a)?\s*\(\s*([\d\.]+)\s*,\s*([\d\.]+)\s*,\s*([\d\.]+)\s*(,\s*[\d\.]+)?\s*\)/i);
|
|
834
|
+
if(m && m.length === 6) {
|
|
835
|
+
const color = {
|
|
836
|
+
r: Number(m[2]),
|
|
837
|
+
g: Number(m[3]),
|
|
838
|
+
b: Number(m[4]),
|
|
839
|
+
a: Number(this.trimStart(m[5]||'1', ','))
|
|
840
|
+
};
|
|
841
|
+
res = color;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return this.__hexToRGBA_Cache[hex] = res;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* 把255的rgb值转为0-1的值
|
|
849
|
+
* @param {rgba} color 颜色
|
|
850
|
+
*/
|
|
851
|
+
static rgbToDecimal(color) {
|
|
852
|
+
color = this.clone(color);
|
|
853
|
+
color.r = this.byteToDecimal(color.r);
|
|
854
|
+
color.g = this.byteToDecimal(color.g);
|
|
855
|
+
color.b = this.byteToDecimal(color.b);
|
|
856
|
+
return color;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
//255值转为0-1的小数
|
|
860
|
+
static byteToDecimal(b) {
|
|
861
|
+
return b / 255;
|
|
675
862
|
}
|
|
676
863
|
|
|
677
864
|
/**
|
|
@@ -691,10 +878,10 @@ export default class jmUtils {
|
|
|
691
878
|
const color = this.hexToRGBA(r);
|
|
692
879
|
if(typeof color === 'string') return color;
|
|
693
880
|
|
|
694
|
-
r = color.r
|
|
695
|
-
g = color.g
|
|
696
|
-
b = color.b
|
|
697
|
-
a = color.a
|
|
881
|
+
r = typeof color.r !== 'undefined'? color.r: r;
|
|
882
|
+
g = typeof color.g !== 'undefined'? color.g: g;
|
|
883
|
+
b = typeof color.b !== 'undefined'? color.b: b;
|
|
884
|
+
a = typeof color.a !== 'undefined'? color.a: a;
|
|
698
885
|
}
|
|
699
886
|
if(typeof r != 'undefined' && typeof g != 'undefined' && typeof b != 'undefined') {
|
|
700
887
|
if(typeof a != 'undefined') {
|