jmchart 1.2.7 → 1.2.10

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.
@@ -174,6 +174,151 @@ class jmList extends Array {
174
174
  }
175
175
  }
176
176
 
177
+ const colorKeywords = {
178
+ aliceblue: "#f0f8ff",
179
+ antiquewhite: "#faebd7",
180
+ aqua: "#00ffff",
181
+ aquamarine: "#7fffd4",
182
+ azure: "#f0ffff",
183
+ beige: "#f5f5dc",
184
+ bisque: "#ffe4c4",
185
+ black: "#000000",
186
+ blanchedalmond: "#ffebcd",
187
+ blue: "#0000ff",
188
+ blueviolet: "#8a2be2",
189
+ brown: "#a52a2a",
190
+ burlywood: "#deb887",
191
+ cadetblue: "#5f9ea0",
192
+ chartreuse: "#7fff00",
193
+ chocolate: "#d2691e",
194
+ coral: "#ff7f50",
195
+ cornflowerblue: "#6495ed",
196
+ cornsilk: "#fff8dc",
197
+ crimson: "#dc143c",
198
+ cyan: "#00ffff",
199
+ darkblue: "#00008b",
200
+ darkcyan: "#008b8b",
201
+ darkgoldenrod: "#b8860b",
202
+ darkgray: "#a9a9a9",
203
+ darkgreen: "#006400",
204
+ darkkhaki: "#bdb76b",
205
+ darkmagenta: "#8b008b",
206
+ darkolivegreen: "#556b2f",
207
+ darkorange: "#ff8c00",
208
+ darkorchid: "#9932cc",
209
+ darkred: "#8b0000",
210
+ darksalmon: "#e9967a",
211
+ darkseagreen: "#8fbc8f",
212
+ darkslateblue: "#483d8b",
213
+ darkslategray: "#2f4f4f",
214
+ darkturquoise: "#00ced1",
215
+ darkviolet: "#9400d3",
216
+ deeppink: "#ff1493",
217
+ deepskyblue: "#00bfff",
218
+ dimgray: "#696969",
219
+ dodgerblue: "#1e90ff",
220
+ firebrick: "#b22222",
221
+ floralwhite: "#fffaf0",
222
+ forestgreen: "#228b22",
223
+ fuchsia: "#ff00ff",
224
+ gainsboro: "#dcdcdc",
225
+ ghostwhite: "#f8f8ff",
226
+ gold: "#ffd700",
227
+ goldenrod: "#daa520",
228
+ gray: "#808080",
229
+ green: "#008000",
230
+ greenyellow: "#adff2f",
231
+ grey: "#808080",
232
+ honeydew: "#f0fff0",
233
+ hotpink: "#ff69b4",
234
+ indianred: "#cd5c5c",
235
+ indigo: "#4b0082",
236
+ ivory: "#fffff0",
237
+ khaki: "#f0e68c",
238
+ lavender: "#e6e6fa",
239
+ lavenderblush: "#fff0f5",
240
+ lawngreen: "#7cfc00",
241
+ lemonchiffon: "#fffacd",
242
+ lightblue: "#add8e6",
243
+ lightcoral: "#f08080",
244
+ lightcyan: "#e0ffff",
245
+ lightgoldenrodyellow: "#fafad2",
246
+ lightgrey: "#d3d3d3",
247
+ lightgreen: "#90ee90",
248
+ lightpink: "#ffb6c1",
249
+ lightsalmon: "#ffa07a",
250
+ lightseagreen: "#20b2aa",
251
+ lightskyblue: "#87cefa",
252
+ lightslategray: "#778899",
253
+ lightsteelblue: "#b0c4de",
254
+ lightyellow: "#ffffe0",
255
+ lime: "#00ff00",
256
+ limegreen: "#32cd32",
257
+ linen: "#faf0e6",
258
+ magenta: "#ff00ff",
259
+ maroon: "#800000",
260
+ mediumaquamarine: "#66cdaa",
261
+ mediumblue: "#0000cd",
262
+ mediumorchid: "#ba55d3",
263
+ mediumpurple: "#9370d8",
264
+ mediumseagreen: "#3cb371",
265
+ mediumslateblue: "#7b68ee",
266
+ mediumspringgreen: "#00fa9a",
267
+ mediumturquoise: "#48d1cc",
268
+ mediumvioletred: "#c71585",
269
+ midnightblue: "#191970",
270
+ mintcream: "#f5fffa",
271
+ mistyrose: "#ffe4e1",
272
+ moccasin: "#ffe4b5",
273
+ navajowhite: "#ffdead",
274
+ navy: "#000080",
275
+ oldlace: "#fdf5e6",
276
+ olive: "#808000",
277
+ olivedrab: "#6b8e23",
278
+ orange: "#ffa500",
279
+ orangered: "#ff4500",
280
+ orchid: "#da70d6",
281
+ palegoldenrod: "#eee8aa",
282
+ palegreen: "#98fb98",
283
+ paleturquoise: "#afeeee",
284
+ palevioletred: "#d87093",
285
+ papayawhip: "#ffefd5",
286
+ peachpuff: "#ffdab9",
287
+ peru: "#cd853f",
288
+ pink: "#ffc0cb",
289
+ plum: "#dda0dd",
290
+ powderblue: "#b0e0e6",
291
+ purple: "#800080",
292
+ red: "#ff0000",
293
+ rosybrown: "#bc8f8f",
294
+ royalblue: "#4169e1",
295
+ saddlebrown: "#8b4513",
296
+ salmon: "#fa8072",
297
+ sandybrown: "#f4a460",
298
+ seagreen: "#2e8b57",
299
+ seashell: "#fff5ee",
300
+ sienna: "#a0522d",
301
+ silver: "#c0c0c0",
302
+ skyblue: "#87ceeb",
303
+ slateblue: "#6a5acd",
304
+ slategray: "#708090",
305
+ snow: "#fffafa",
306
+ springgreen: "#00ff7f",
307
+ steelblue: "#4682b4",
308
+ tan: "#d2b48c",
309
+ teal: "#008080",
310
+ thistle: "#d8bfd8",
311
+ tomato: "#ff6347",
312
+ turquoise: "#40e0d0",
313
+ violet: "#ee82ee",
314
+ wheat: "#f5deb3",
315
+ white: "#ffffff",
316
+ whitesmoke: "#f5f5f5",
317
+ yellow: "#ffff00",
318
+ yellowgreen: "#9acd32",
319
+ transparent: "rgba(0,0,0,0)"
320
+ };
321
+
177
322
  /**
178
323
  * 画图基础对象
179
324
  * 当前库的工具类
@@ -236,7 +381,10 @@ class jmUtils {
236
381
  if(k === 'constructor') continue;
237
382
  const v = source[k];
238
383
  // 不复制页面元素和class对象
239
- if(v && (v.tagName || v.getContext)) continue;
384
+ if(v && (v.tagName || v.getContext)) {
385
+ target[k] = v;
386
+ continue;
387
+ }
240
388
 
241
389
  // 如果不是对象和空,则采用target的属性
242
390
  if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
@@ -786,65 +934,104 @@ class jmUtils {
786
934
  * @param {string}} hex 16进度的颜色
787
935
  */
788
936
  static hexToRGBA(hex) {
789
- hex = this.trim(hex);
937
+ if(typeof hex === 'string') hex = this.trim(hex);
938
+ else return hex;
939
+
940
+ // 如果缓存存在,则直接返回
941
+ this.__hexToRGBA_Cache = this.__hexToRGBA_Cache || {};
942
+ if(this.__hexToRGBA_Cache[hex]) return this.__hexToRGBA_Cache[hex];
943
+
944
+ let res = hex;
945
+
946
+ // 系统颜色
947
+ if(colorKeywords[res]) res = colorKeywords[res];
790
948
 
791
949
  //当为7位时,表示需要转为带透明度的rgba
792
- if(hex[0] == '#') {
950
+ if(res[0] == '#') {
793
951
  const color = {
794
952
  a: 1
795
953
  };
796
- if(hex.length >= 8) {
797
- color.a = hex.substr(1,2);
798
- color.g = hex.substr(5,2);
799
- color.b = hex.substr(7,2);
800
- color.r = hex.substr(3,2);
954
+ if(res.length >= 8) {
955
+ color.a = res.substr(1,2);
956
+ color.g = res.substr(5,2);
957
+ color.b = res.substr(7,2);
958
+ color.r = res.substr(3,2);
801
959
  //透明度
802
- color.a = (this.hexToNumber(color.a) / 255).toFixed(4);
960
+ color.a = Number((this.hexToNumber(color.a) / 255).toFixed(4));
803
961
 
804
962
  color.r = this.hexToNumber(color.r||0);
805
963
  color.g = this.hexToNumber(color.g||0);
806
964
  color.b = this.hexToNumber(color.b||0);
807
- return color;
965
+ res = color;
808
966
  }
809
967
  // #cccccc || #ccc
810
- else if(hex.length === 7 || hex.length === 4) {
968
+ else if(res.length === 7 || res.length === 4) {
811
969
  // #ccc这种情况,把每个位复制一份
812
- if(hex.length === 4) {
813
- color.g = hex.substr(2, 1);
970
+ if(res.length === 4) {
971
+ color.g = res.substr(2, 1);
814
972
  color.g = color.g + color.g;
815
- color.b = hex.substr(3, 1);
973
+ color.b = res.substr(3, 1);
816
974
  color.b = color.b + color.b;
817
- color.r = hex.substr(1, 1);
975
+ color.r = res.substr(1, 1);
818
976
  color.r = color.r + color.r;
819
977
  }
820
978
  else {
821
- color.g = hex.substr(3, 2);//除#号外的第二位
822
- color.b = hex.substr(5, 2);
823
- color.r = hex.substr(1, 2);
979
+ color.g = res.substr(3, 2);//除#号外的第二位
980
+ color.b = res.substr(5, 2);
981
+ color.r = res.substr(1, 2);
824
982
  }
825
983
 
826
984
  color.r = this.hexToNumber(color.r||0);
827
985
  color.g = this.hexToNumber(color.g||0);
828
986
  color.b = this.hexToNumber(color.b||0);
829
987
 
830
- return color;
988
+ res = color;
831
989
  }
832
990
  //如果是5位的话,# 则第2位表示A,后面依次是r,g,b
833
- else if(hex.length === 5) {
834
- color.a = hex.substr(1,1);
835
- color.g = hex.substr(3,1);//除#号外的第二位
836
- color.b = hex.substr(4,1);
837
- color.r = hex.substr(2,1);
991
+ else if(res.length === 5) {
992
+ color.a = res.substr(1,1);
993
+ color.g = res.substr(3,1);//除#号外的第二位
994
+ color.b = res.substr(4,1);
995
+ color.r = res.substr(2,1);
838
996
 
839
997
  color.r = this.hexToNumber(color.r||0);
840
998
  color.g = this.hexToNumber(color.g||0);
841
999
  color.b = this.hexToNumber(color.b||0);
842
1000
  //透明度
843
- color.a = (this.hexToNumber(color.a) / 255).toFixed(4);
844
- return color;
1001
+ color.a = Number((this.hexToNumber(color.a) / 255).toFixed(4));
1002
+ res = color;
845
1003
  }
846
1004
  }
847
- return hex;
1005
+ if(typeof res === 'string') {
1006
+ const m = res.match(/rgb(a)?\s*\(\s*([\d\.]+)\s*,\s*([\d\.]+)\s*,\s*([\d\.]+)\s*(,\s*[\d\.]+)?\s*\)/i);
1007
+ if(m && m.length === 6) {
1008
+ const color = {
1009
+ r: Number(m[2]),
1010
+ g: Number(m[3]),
1011
+ b: Number(m[4]),
1012
+ a: Number(this.trimStart(m[5]||'1', ','))
1013
+ };
1014
+ res = color;
1015
+ }
1016
+ }
1017
+ return this.__hexToRGBA_Cache[hex] = res;
1018
+ }
1019
+
1020
+ /**
1021
+ * 把255的rgb值转为0-1的值
1022
+ * @param {rgba} color 颜色
1023
+ */
1024
+ static rgbToDecimal(color) {
1025
+ color = this.clone(color);
1026
+ color.r = this.byteToDecimal(color.r);
1027
+ color.g = this.byteToDecimal(color.g);
1028
+ color.b = this.byteToDecimal(color.b);
1029
+ return color;
1030
+ }
1031
+
1032
+ //255值转为0-1的小数
1033
+ static byteToDecimal(b) {
1034
+ return b / 255;
848
1035
  }
849
1036
 
850
1037
  /**
@@ -864,10 +1051,10 @@ class jmUtils {
864
1051
  const color = this.hexToRGBA(r);
865
1052
  if(typeof color === 'string') return color;
866
1053
 
867
- r = color.r || r;
868
- g = color.g || g;
869
- b = color.b || b;
870
- a = color.a || a;
1054
+ r = typeof color.r !== 'undefined'? color.r: r;
1055
+ g = typeof color.g !== 'undefined'? color.g: g;
1056
+ b = typeof color.b !== 'undefined'? color.b: b;
1057
+ a = typeof color.a !== 'undefined'? color.a: a;
871
1058
  }
872
1059
  if(typeof r != 'undefined' && typeof g != 'undefined' && typeof b != 'undefined') {
873
1060
  if(typeof a != 'undefined') {
@@ -973,8 +1160,13 @@ class jmGradient {
973
1160
  let sy1 = Number(y1) + bounds.top;
974
1161
  let sx2 = Number(x2) + bounds.left;
975
1162
  let sy2 = Number(y2) + bounds.top;
976
- if(this.type === 'linear') {
977
- gradient = context.createLinearGradient(sx1, sy1, sx2, sy2);
1163
+ if(this.type === 'linear') {
1164
+ if(control.mode === 'webgl' && control.webglControl) {
1165
+ gradient = control.webglControl.createLinearGradient(x1, y1, x2, y2, bounds);
1166
+ }
1167
+ else {
1168
+ context.createLinearGradient && (gradient = context.createLinearGradient(sx1, sy1, sx2, sy2));
1169
+ }
978
1170
  }
979
1171
  else if(this.type === 'radial') {
980
1172
  let r1 = this.r1||0;
@@ -986,22 +1178,32 @@ class jmGradient {
986
1178
  if(jmUtils.checkPercent(r2)) {
987
1179
  r2 = jmUtils.percentToNumber(r2);
988
1180
  r2 = d * r2;
1181
+ }
1182
+ if(control.mode === 'webgl' && control.webglControl) {
1183
+ gradient = control.webglControl.createRadialGradient(x1, y1, r1, x2, y2, r2, bounds);
989
1184
  }
990
1185
  //offsetLine = Math.abs(r2 - r1);//二圆半径差
1186
+ else if(context.createRadialGradient) {
1187
+ gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
1188
+ }
991
1189
  //小程序的接口特殊
992
- if(context.createCircularGradient) {
1190
+ else if(context.createCircularGradient) {
993
1191
  gradient = context.createCircularGradient(sx1, sy1, r2);
994
1192
  }
995
- else {
996
- gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
997
- }
998
1193
  }
1194
+
999
1195
  //颜色渐变
1000
- this.stops.each(function(i,s) {
1001
- let c = jmUtils.toColor(s.color);
1002
- //s.offset 0.0 ~ 1.0
1003
- gradient.addColorStop(s.offset, c);
1004
- });
1196
+ if(gradient) {
1197
+ this.stops.each(function(i,s) {
1198
+ let c = jmUtils.toColor(s.color);
1199
+ //s.offset 0.0 ~ 1.0
1200
+ gradient && gradient.addColorStop(s.offset, c);
1201
+ });
1202
+ }
1203
+ else {
1204
+ const s = this.stops.get(0);
1205
+ return (s && s.color) || '#000';
1206
+ }
1005
1207
 
1006
1208
  return gradient;
1007
1209
  }
@@ -1080,14 +1282,14 @@ class jmGradient {
1080
1282
  toString() {
1081
1283
  let str = this.type + '-gradient(';
1082
1284
  if(this.type == 'linear') {
1083
- str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
1285
+ str += this.x1.toFixed(2) + ' ' + this.y1.toFixed(2) + ' ' + this.x2.toFixed(2) + ' ' + this.y2.toFixed(2);
1084
1286
  }
1085
1287
  else {
1086
- str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
1288
+ str += this.x1.toFixed(2) + ' ' + this.y1.toFixed(2) + ' ' + this.r1.toFixed(2) + ' ' + this.x2.toFixed(2) + ' ' + this.y2.toFixed(2) + ' ' + this.r2.toFixed(2);
1087
1289
  }
1088
1290
  //颜色渐变
1089
1291
  this.stops.each(function(i,s) {
1090
- str += ',' + s.color + ' ' + s.offset;
1292
+ str += ',' + s.color + ' ' + s.offset.toFixed(2);
1091
1293
  });
1092
1294
  return str + ')';
1093
1295
  }
@@ -1156,6 +1358,7 @@ class jmShadow {
1156
1358
  }
1157
1359
  }
1158
1360
 
1361
+ var control_id_counter = 0;
1159
1362
  /**
1160
1363
  * 所有jm对象的基础对象
1161
1364
  *
@@ -1168,7 +1371,7 @@ class jmObject {
1168
1371
  if(g && g.type == 'jmGraph') {
1169
1372
  this.graph = g;
1170
1373
  }
1171
- //this.id = Symbol("id"); //生成一个唯一id
1374
+ this.id = ++control_id_counter; //生成一个唯一id
1172
1375
  }
1173
1376
 
1174
1377
  /**
@@ -1266,31 +1469,31 @@ const PROPERTY_KEY = Symbol("properties");
1266
1469
  */
1267
1470
  class jmProperty extends jmObject {
1268
1471
 
1269
- constructor() {
1472
+ constructor(params) {
1270
1473
  super();
1271
-
1272
1474
  this[PROPERTY_KEY] = {};
1475
+ if(params && params.mode) this.mode = params.mode;
1273
1476
  }
1274
1477
 
1275
1478
  /**
1276
1479
  * 基础属性读写接口
1277
- * @method __pro
1480
+ * @method property
1278
1481
  * @param {string} name 属性名
1279
1482
  * @param {any} value 属性的值
1280
1483
  * @returns {any} 属性的值
1281
1484
  */
1282
- __pro(...pars) {
1485
+ property(...pars) {
1283
1486
  if(pars) {
1284
- let pros = this[PROPERTY_KEY];
1285
- let name = pars[0];
1487
+ const pros = this[PROPERTY_KEY];
1488
+ const name = pars[0];
1286
1489
  if(pars.length > 1) {
1287
- let value = pars[1];
1288
- let args = {oldValue: pros[name], newValue: value};
1490
+ const value = pars[1];
1491
+ const args = {oldValue: pros[name], newValue: value};
1289
1492
  pros[name] = pars[1];
1290
1493
  if(this.emit) this.emit('propertyChange', name, args);
1291
1494
  return pars[1];
1292
1495
  }
1293
- else if(pars.length == 1) {
1496
+ else if(name) {
1294
1497
  return pros[name];
1295
1498
  }
1296
1499
  }
@@ -1302,10 +1505,10 @@ class jmProperty extends jmObject {
1302
1505
  * @type {boolean}
1303
1506
  */
1304
1507
  get needUpdate() {
1305
- return this.__pro('needUpdate');
1508
+ return this.property('needUpdate');
1306
1509
  }
1307
1510
  set needUpdate(v) {
1308
- this.__pro('needUpdate', v);
1511
+ this.property('needUpdate', v);
1309
1512
  //子控件属性改变,需要更新整个画板
1310
1513
  if(v && !this.is('jmGraph') && this.graph) {
1311
1514
  this.graph.needUpdate = true;
@@ -1318,12 +1521,27 @@ class jmProperty extends jmObject {
1318
1521
  * @type {jmGraph}
1319
1522
  */
1320
1523
  get graph() {
1321
- let g = this.__pro('graph');
1322
- g = g || (this.__pro('graph', this.findParent('jmGraph')));
1524
+ let g = this.property('graph');
1525
+ g = g || (this.property('graph', this.findParent('jmGraph')));
1323
1526
  return g;
1324
1527
  }
1325
1528
  set graph(v) {
1326
- return this.__pro('graph', v);
1529
+ return this.property('graph', v);
1530
+ }
1531
+
1532
+ /**
1533
+ * 绘制模式 2d/webgl
1534
+ * @property mode
1535
+ * @type {string}
1536
+ */
1537
+ get mode() {
1538
+ let m = this.property('mode');
1539
+ if(m) return m;
1540
+ else if(this.is('jmGraph')) return this.property('mode');
1541
+ return this.graph.mode;
1542
+ }
1543
+ set mode(v) {
1544
+ return this.property('mode', v);
1327
1545
  }
1328
1546
 
1329
1547
  /**
@@ -1343,9 +1561,12 @@ class jmProperty extends jmObject {
1343
1561
  }
1344
1562
  }
1345
1563
 
1564
+ //import WebglPath from "../lib/webgl/path.js";
1565
+
1346
1566
  //样式名称,也当做白名单使用
1347
1567
  const jmStyleMap = {
1348
1568
  'fill':'fillStyle',
1569
+ 'fillImage':'fillImage',
1349
1570
  'stroke':'strokeStyle',
1350
1571
  'shadow.blur':'shadowBlur',
1351
1572
  'shadow.x':'shadowOffsetX',
@@ -1378,8 +1599,8 @@ class jmControl extends jmProperty {
1378
1599
 
1379
1600
  constructor(params, t) {
1380
1601
  params = params||{};
1381
- super();
1382
- this.__pro('type', t || new.target.name);
1602
+ super(params);
1603
+ this.property('type', t || new.target.name);
1383
1604
  this.style = params && params.style ? params.style : {};
1384
1605
  //this.position = params.position || {x:0,y:0};
1385
1606
  this.width = params.width || 0;
@@ -1393,6 +1614,15 @@ class jmControl extends jmProperty {
1393
1614
  this.zIndex = params.zIndex || 0;
1394
1615
  this.interactive = typeof params.interactive == 'undefined'? true : params.interactive;
1395
1616
 
1617
+ // webgl模式
1618
+ /*if(this.mode === 'webgl') {
1619
+ this.webglControl = new WebglPath(this.graph, {
1620
+ style: this.style,
1621
+ isRegular: params.isRegular,
1622
+ needCut: params.needCut
1623
+ });
1624
+ }*/
1625
+
1396
1626
  this.initializing();
1397
1627
 
1398
1628
  this.on = this.bind;
@@ -1408,7 +1638,7 @@ class jmControl extends jmProperty {
1408
1638
  * @type string
1409
1639
  */
1410
1640
  get type() {
1411
- return this.__pro('type');
1641
+ return this.property('type');
1412
1642
  }
1413
1643
 
1414
1644
  /**
@@ -1417,17 +1647,17 @@ class jmControl extends jmProperty {
1417
1647
  * @type {object}
1418
1648
  */
1419
1649
  get context() {
1420
- let s = this.__pro('context');
1650
+ let s = this.property('context');
1421
1651
  if(s) return s;
1422
1652
  else if(this.is('jmGraph') && this.canvas && this.canvas.getContext) {
1423
- return this.context = this.canvas.getContext('2d');
1653
+ return this.context = this.canvas.getContext(this.mode || '2d');
1424
1654
  }
1425
- let g = this.graph;
1655
+ const g = this.graph;
1426
1656
  if(g) return g.context;
1427
- return g.canvas.getContext('2d');
1657
+ return g.canvas.getContext(this.mode || '2d');
1428
1658
  }
1429
1659
  set context(v) {
1430
- return this.__pro('context', v);
1660
+ return this.property('context', v);
1431
1661
  }
1432
1662
 
1433
1663
  /**
@@ -1436,13 +1666,13 @@ class jmControl extends jmProperty {
1436
1666
  * @type {object}
1437
1667
  */
1438
1668
  get style() {
1439
- let s = this.__pro('style');
1440
- if(!s) s = this.__pro('style', {});
1669
+ let s = this.property('style');
1670
+ if(!s) s = this.property('style', {});
1441
1671
  return s;
1442
1672
  }
1443
1673
  set style(v) {
1444
1674
  this.needUpdate = true;
1445
- return this.__pro('style', v);
1675
+ return this.property('style', v);
1446
1676
  }
1447
1677
 
1448
1678
  /**
@@ -1452,13 +1682,13 @@ class jmControl extends jmProperty {
1452
1682
  * @type {boolean}
1453
1683
  */
1454
1684
  get visible() {
1455
- let s = this.__pro('visible');
1456
- if(typeof s == 'undefined') s = this.__pro('visible', true);
1685
+ let s = this.property('visible');
1686
+ if(typeof s == 'undefined') s = this.property('visible', true);
1457
1687
  return s;
1458
1688
  }
1459
1689
  set visible(v) {
1460
1690
  this.needUpdate = true;
1461
- return this.__pro('visible', v);
1691
+ return this.property('visible', v);
1462
1692
  }
1463
1693
 
1464
1694
  /**
@@ -1469,11 +1699,11 @@ class jmControl extends jmProperty {
1469
1699
  * @type {boolean}
1470
1700
  */
1471
1701
  get interactive() {
1472
- let s = this.__pro('interactive');
1702
+ let s = this.property('interactive');
1473
1703
  return s;
1474
1704
  }
1475
1705
  set interactive(v) {
1476
- return this.__pro('interactive', v);
1706
+ return this.property('interactive', v);
1477
1707
  }
1478
1708
 
1479
1709
  /**
@@ -1482,13 +1712,13 @@ class jmControl extends jmProperty {
1482
1712
  * @type {list}
1483
1713
  */
1484
1714
  get children() {
1485
- let s = this.__pro('children');
1486
- if(!s) s = this.__pro('children', new jmList());
1715
+ let s = this.property('children');
1716
+ if(!s) s = this.property('children', new jmList());
1487
1717
  return s;
1488
1718
  }
1489
1719
  set children(v) {
1490
1720
  this.needUpdate = true;
1491
- return this.__pro('children', v);
1721
+ return this.property('children', v);
1492
1722
  }
1493
1723
 
1494
1724
  /**
@@ -1497,13 +1727,13 @@ class jmControl extends jmProperty {
1497
1727
  * @type {number}
1498
1728
  */
1499
1729
  get width() {
1500
- let s = this.__pro('width');
1501
- if(typeof s == 'undefined') s = this.__pro('width', 0);
1730
+ let s = this.property('width');
1731
+ if(typeof s == 'undefined') s = this.property('width', 0);
1502
1732
  return s;
1503
1733
  }
1504
1734
  set width(v) {
1505
1735
  this.needUpdate = true;
1506
- return this.__pro('width', v);
1736
+ return this.property('width', v);
1507
1737
  }
1508
1738
 
1509
1739
  /**
@@ -1512,13 +1742,13 @@ class jmControl extends jmProperty {
1512
1742
  * @type {number}
1513
1743
  */
1514
1744
  get height() {
1515
- let s = this.__pro('height');
1516
- if(typeof s == 'undefined') s = this.__pro('height', 0);
1745
+ let s = this.property('height');
1746
+ if(typeof s == 'undefined') s = this.property('height', 0);
1517
1747
  return s;
1518
1748
  }
1519
1749
  set height(v) {
1520
1750
  this.needUpdate = true;
1521
- return this.__pro('height', v);
1751
+ return this.property('height', v);
1522
1752
  }
1523
1753
 
1524
1754
  /**
@@ -1527,13 +1757,13 @@ class jmControl extends jmProperty {
1527
1757
  * @type {number}
1528
1758
  */
1529
1759
  get zIndex() {
1530
- let s = this.__pro('zIndex');
1531
- if(!s) s = this.__pro('zIndex', 0);
1760
+ let s = this.property('zIndex');
1761
+ if(!s) s = this.property('zIndex', 0);
1532
1762
  return s;
1533
1763
  }
1534
1764
  set zIndex(v) {
1535
1765
  this.needUpdate = true;
1536
- this.__pro('zIndex', v);
1766
+ this.property('zIndex', v);
1537
1767
  this.children.sort();//层级发生改变,需要重新排序
1538
1768
  this.needUpdate = true;
1539
1769
  return v;
@@ -1714,12 +1944,25 @@ class jmControl extends jmProperty {
1714
1944
  __setStyle(styleValue.toGradient(this), mpname||name);
1715
1945
  }
1716
1946
  else if(mpname) {
1717
- //只有存在白名单中才处理
1718
- //颜色转换
1719
- if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
1720
- styleValue = jmUtils.toColor(styleValue);
1947
+
1948
+ if(this.webglControl) {
1949
+ //只有存在白名单中才处理
1950
+ //颜色转换
1951
+ if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
1952
+ styleValue = jmUtils.hexToRGBA(styleValue);
1953
+ }
1954
+
1955
+ this.webglControl.setStyle(mpname, styleValue);
1956
+ }
1957
+ else {
1958
+ //只有存在白名单中才处理
1959
+ //颜色转换
1960
+ if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
1961
+ styleValue = jmUtils.toColor(styleValue);
1962
+ }
1963
+
1964
+ this.context[mpname] = styleValue;
1721
1965
  }
1722
- this.context[mpname] = styleValue;
1723
1966
  }
1724
1967
  else {
1725
1968
  switch(name) {
@@ -1736,7 +1979,7 @@ class jmControl extends jmProperty {
1736
1979
  }
1737
1980
  //平移
1738
1981
  case 'translate' : {
1739
- this.context.translate(styleValue.x, styleValue.y);
1982
+ this.context.translate && this.context.translate(styleValue.x, styleValue.y);
1740
1983
  break;
1741
1984
  }
1742
1985
  //旋转
@@ -1755,9 +1998,9 @@ class jmControl extends jmProperty {
1755
1998
  tranY = styleValue.rotateY + bounds.top;
1756
1999
  }
1757
2000
 
1758
- if(tranX!=0 || tranY != 0) this.context.translate(tranX,tranY);
2001
+ if(tranX!=0 || tranY != 0) this.context.translate && this.context.translate(tranX,tranY);
1759
2002
  this.context.rotate(styleValue.angle);
1760
- if(tranX!=0 || tranY != 0) this.context.translate(-tranX,-tranY);
2003
+ if(tranX!=0 || tranY != 0) this.context.translate && this.context.translate(-tranX,-tranY);
1761
2004
  break;
1762
2005
  }
1763
2006
  case 'transform' : {
@@ -2116,7 +2359,8 @@ class jmControl extends jmProperty {
2116
2359
  */
2117
2360
  beginDraw() {
2118
2361
  this.getLocation(true);//重置位置信息
2119
- this.context.beginPath();
2362
+ this.context.beginPath && this.context.beginPath();
2363
+ //if(this.webglControl && this.webglControl.beginDraw) this.webglControl.beginDraw();
2120
2364
  }
2121
2365
 
2122
2366
  /**
@@ -2127,16 +2371,24 @@ class jmControl extends jmProperty {
2127
2371
  endDraw() {
2128
2372
  //如果当前为封闭路径
2129
2373
  if(this.style.close) {
2130
- this.context.closePath();
2374
+ //if(this.webglControl) this.webglControl.closePath();
2375
+ this.context.closePath && this.context.closePath();
2131
2376
  }
2132
2377
 
2133
2378
  if(this.style['fill']) {
2134
- this.context.fill();
2379
+ /*if(this.webglControl) {
2380
+ const bounds = this.getBounds();
2381
+ this.webglControl.fill(bounds);
2382
+ }*/
2383
+ this.context.fill && this.context.fill();
2135
2384
  }
2136
- if(this.style['stroke'] || !this.style['fill']) {
2137
- this.context.stroke();
2385
+ if(this.style['stroke'] || (!this.style['fill'] && !this.is('jmGraph'))) {
2386
+ //if(this.webglControl) this.webglControl.stroke();
2387
+ this.context.stroke && this.context.stroke();
2138
2388
  }
2139
2389
 
2390
+ //if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
2391
+
2140
2392
  this.needUpdate = false;
2141
2393
  }
2142
2394
 
@@ -2149,20 +2401,27 @@ class jmControl extends jmProperty {
2149
2401
  draw() {
2150
2402
  if(this.points && this.points.length > 0) {
2151
2403
  //获取当前控件的绝对位置
2152
- let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
2153
-
2154
- this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
2155
- let len = this.points.length;
2156
- for(let i=1; i < len;i++) {
2157
- let p = this.points[i];
2158
- //移至当前坐标
2159
- if(p.m) {
2160
- this.context.moveTo(p.x + bounds.left,p.y + bounds.top);
2161
- }
2162
- else {
2163
- this.context.lineTo(p.x+ bounds.left,p.y + bounds.top);
2164
- }
2165
- }
2404
+ const bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
2405
+ /*if(this.webglControl) {
2406
+ this.webglControl.setParentBounds(bounds);
2407
+ this.webglControl.draw([
2408
+ ...this.points
2409
+ ]);
2410
+ }*/
2411
+ if(this.context && this.context.moveTo) {
2412
+ this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
2413
+ let len = this.points.length;
2414
+ for(let i=1; i < len;i++) {
2415
+ let p = this.points[i];
2416
+ //移至当前坐标
2417
+ if(p.m) {
2418
+ this.context.moveTo(p.x + bounds.left,p.y + bounds.top);
2419
+ }
2420
+ else {
2421
+ this.context.lineTo(p.x+ bounds.left,p.y + bounds.top);
2422
+ }
2423
+ }
2424
+ }
2166
2425
  }
2167
2426
  }
2168
2427
 
@@ -2186,7 +2445,7 @@ class jmControl extends jmProperty {
2186
2445
  else if(this.absoluteBounds.bottom <= 0) needDraw = false;
2187
2446
  }
2188
2447
 
2189
- this.context.save();
2448
+ this.context.save && this.context.save();
2190
2449
 
2191
2450
  this.emit('beginDraw', this);
2192
2451
 
@@ -2203,7 +2462,7 @@ class jmControl extends jmProperty {
2203
2462
  }
2204
2463
 
2205
2464
  this.emit('endDraw',this);
2206
- this.context.restore();
2465
+ this.context.restore && this.context.restore();
2207
2466
 
2208
2467
  this.needUpdate = false;
2209
2468
  }
@@ -2703,7 +2962,7 @@ class jmPath extends jmControl {
2703
2962
  constructor(params, t='jmPath') {
2704
2963
  super(params, t);
2705
2964
  this.points = params && params.points ? params.points : [];
2706
-
2965
+ this.polygonIndices = params && params.polygonIndices ? params.polygonIndices : [];
2707
2966
  }
2708
2967
 
2709
2968
  /**
@@ -2713,13 +2972,29 @@ class jmPath extends jmControl {
2713
2972
  * @type {array}
2714
2973
  */
2715
2974
  get points() {
2716
- let s = this.__pro('points');
2975
+ let s = this.property('points');
2717
2976
  return s;
2718
2977
  }
2719
2978
  set points(v) {
2720
2979
  this.needUpdate = true;
2721
- return this.__pro('points', v);
2980
+ return this.property('points', v);
2981
+ }
2982
+
2983
+ /**
2984
+ * 顶点数组索引,对应points中的顶点
2985
+ * @property polygonIndices
2986
+ * @type {array}
2987
+ */
2988
+ get polygonIndices() {
2989
+ let s = this.property('polygonIndices');
2990
+ return s;
2991
+ }
2992
+ set polygonIndices(v) {
2993
+ this.needUpdate = true;
2994
+ return this.property('polygonIndices', v);
2722
2995
  }
2996
+
2997
+
2723
2998
  }
2724
2999
 
2725
3000
  /**
@@ -2733,6 +3008,9 @@ class jmArc extends jmPath {
2733
3008
 
2734
3009
  constructor(params, t='jmArc') {
2735
3010
  if(!params) params = {};
3011
+ params.isRegular = params.isRegular === false? false: true;// 规则的
3012
+ params.needCut = params.needCut === true? true: false;// 规则的
3013
+
2736
3014
  super(params, t);
2737
3015
 
2738
3016
  this.center = params.center || {x:0,y:0};
@@ -2753,11 +3031,11 @@ class jmArc extends jmPath {
2753
3031
  * @type {point}
2754
3032
  */
2755
3033
  get center() {
2756
- return this.__pro('center');
3034
+ return this.property('center');
2757
3035
  }
2758
3036
  set center(v) {
2759
3037
  this.needUpdate = true;
2760
- return this.__pro('center', v);
3038
+ return this.property('center', v);
2761
3039
  }
2762
3040
 
2763
3041
  /**
@@ -2766,11 +3044,11 @@ class jmArc extends jmPath {
2766
3044
  * @type {number}
2767
3045
  */
2768
3046
  get radius() {
2769
- return this.__pro('radius');
3047
+ return this.property('radius');
2770
3048
  }
2771
3049
  set radius(v) {
2772
3050
  this.needUpdate = true;
2773
- return this.__pro('radius', v);
3051
+ return this.property('radius', v);
2774
3052
  }
2775
3053
 
2776
3054
  /**
@@ -2779,11 +3057,11 @@ class jmArc extends jmPath {
2779
3057
  * @type {number}
2780
3058
  */
2781
3059
  get startAngle() {
2782
- return this.__pro('startAngle');
3060
+ return this.property('startAngle');
2783
3061
  }
2784
3062
  set startAngle(v) {
2785
3063
  this.needUpdate = true;
2786
- return this.__pro('startAngle', v);
3064
+ return this.property('startAngle', v);
2787
3065
  }
2788
3066
 
2789
3067
  /**
@@ -2792,11 +3070,11 @@ class jmArc extends jmPath {
2792
3070
  * @type {number}
2793
3071
  */
2794
3072
  get endAngle() {
2795
- return this.__pro('endAngle');
3073
+ return this.property('endAngle');
2796
3074
  }
2797
3075
  set endAngle(v) {
2798
3076
  this.needUpdate = true;
2799
- return this.__pro('endAngle', v);
3077
+ return this.property('endAngle', v);
2800
3078
  }
2801
3079
 
2802
3080
  /**
@@ -2806,11 +3084,11 @@ class jmArc extends jmPath {
2806
3084
  * @type {boolean}
2807
3085
  */
2808
3086
  get anticlockwise() {
2809
- return this.__pro('anticlockwise');
3087
+ return this.property('anticlockwise');
2810
3088
  }
2811
3089
  set anticlockwise(v) {
2812
3090
  this.needUpdate = true;
2813
- return this.__pro('anticlockwise', v);
3091
+ return this.property('anticlockwise', v);
2814
3092
  }
2815
3093
 
2816
3094
 
@@ -2860,7 +3138,7 @@ class jmArc extends jmPath {
2860
3138
  if(step > 0 && r > end) r = end;
2861
3139
  else if(step < 0 && r < end) r = end;
2862
3140
 
2863
- let p = {
3141
+ const p = {
2864
3142
  x : Math.cos(r) * mw + cx,
2865
3143
  y : Math.sin(r) * mh + cy
2866
3144
  };
@@ -2901,11 +3179,11 @@ class jmArrow extends jmPath {
2901
3179
  * @type {point}
2902
3180
  */
2903
3181
  get start() {
2904
- return this.__pro('start');
3182
+ return this.property('start');
2905
3183
  }
2906
3184
  set start(v) {
2907
3185
  this.needUpdate = true;
2908
- return this.__pro('start', v);
3186
+ return this.property('start', v);
2909
3187
  }
2910
3188
 
2911
3189
  /**
@@ -2916,11 +3194,11 @@ class jmArrow extends jmPath {
2916
3194
  * @type {point} 结束点
2917
3195
  */
2918
3196
  get end() {
2919
- return this.__pro('end');
3197
+ return this.property('end');
2920
3198
  }
2921
3199
  set end(v) {
2922
3200
  this.needUpdate = true;
2923
- return this.__pro('end', v);
3201
+ return this.property('end', v);
2924
3202
  }
2925
3203
 
2926
3204
  /**
@@ -2931,11 +3209,11 @@ class jmArrow extends jmPath {
2931
3209
  * @type {number} 箭头角度
2932
3210
  */
2933
3211
  get angle() {
2934
- return this.__pro('angle');
3212
+ return this.property('angle');
2935
3213
  }
2936
3214
  set angle(v) {
2937
3215
  this.needUpdate = true;
2938
- return this.__pro('angle', v);
3216
+ return this.property('angle', v);
2939
3217
  }
2940
3218
 
2941
3219
  /**
@@ -2946,11 +3224,11 @@ class jmArrow extends jmPath {
2946
3224
  * @type {number}
2947
3225
  */
2948
3226
  get offsetX() {
2949
- return this.__pro('offsetX');
3227
+ return this.property('offsetX');
2950
3228
  }
2951
3229
  set offsetX(v) {
2952
3230
  this.needUpdate = true;
2953
- return this.__pro('offsetX', v);
3231
+ return this.property('offsetX', v);
2954
3232
  }
2955
3233
 
2956
3234
  /**
@@ -2961,11 +3239,11 @@ class jmArrow extends jmPath {
2961
3239
  * @type {number}
2962
3240
  */
2963
3241
  get offsetY() {
2964
- return this.__pro('offsetY');
3242
+ return this.property('offsetY');
2965
3243
  }
2966
3244
  set offsetY(v) {
2967
3245
  this.needUpdate = true;
2968
- return this.__pro('offsetY', v);
3246
+ return this.property('offsetY', v);
2969
3247
  }
2970
3248
 
2971
3249
  /**
@@ -3057,11 +3335,11 @@ class jmBezier extends jmPath {
3057
3335
  * @type {array}
3058
3336
  */
3059
3337
  get cpoints() {
3060
- return this.__pro('cpoints');
3338
+ return this.property('cpoints');
3061
3339
  }
3062
3340
  set cpoints(v) {
3063
3341
  this.needUpdate = true;
3064
- return this.__pro('cpoints', v);
3342
+ return this.property('cpoints', v);
3065
3343
  }
3066
3344
 
3067
3345
  /**
@@ -3148,6 +3426,7 @@ class jmBezier extends jmPath {
3148
3426
  class jmCircle extends jmArc {
3149
3427
 
3150
3428
  constructor(params, t='jmCircle') {
3429
+ params.isRegular = true;// 规则的
3151
3430
  super(params, t);
3152
3431
  }
3153
3432
  /**
@@ -3157,7 +3436,10 @@ class jmCircle extends jmArc {
3157
3436
  * @private
3158
3437
  * @for jmCircle
3159
3438
  */
3160
- initPoints() {
3439
+ initPoints() {
3440
+ if(this.graph.mode === 'webgl') {
3441
+ return super.initPoints();
3442
+ }
3161
3443
  let location = this.getLocation();
3162
3444
 
3163
3445
  if(!location.radius) {
@@ -3176,6 +3458,9 @@ class jmCircle extends jmArc {
3176
3458
  * @method draw
3177
3459
  */
3178
3460
  draw() {
3461
+ if(this.graph.mode === 'webgl') {
3462
+ return super.draw();
3463
+ }
3179
3464
  let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3180
3465
  let location = this.getLocation();
3181
3466
 
@@ -3201,6 +3486,8 @@ class jmCircle extends jmArc {
3201
3486
  class jmHArc extends jmArc {
3202
3487
 
3203
3488
  constructor(params, t='jmHArc') {
3489
+ params.isRegular = true;// 规则的
3490
+ params.needCut = true;
3204
3491
  super(params, t);
3205
3492
 
3206
3493
  this.minRadius = params.minRadius || this.style.minRadius || 0;
@@ -3215,11 +3502,11 @@ class jmHArc extends jmArc {
3215
3502
  * @type {number}
3216
3503
  */
3217
3504
  get minRadius() {
3218
- return this.__pro('minRadius');
3505
+ return this.property('minRadius');
3219
3506
  }
3220
3507
  set minRadius(v) {
3221
3508
  this.needUpdate = true;
3222
- return this.__pro('minRadius', v);
3509
+ return this.property('minRadius', v);
3223
3510
  }
3224
3511
 
3225
3512
  /**
@@ -3230,11 +3517,11 @@ class jmHArc extends jmArc {
3230
3517
  * @type {number}
3231
3518
  */
3232
3519
  get maxRadius() {
3233
- return this.__pro('maxRadius');
3520
+ return this.property('maxRadius');
3234
3521
  }
3235
3522
  set maxRadius(v) {
3236
3523
  this.needUpdate = true;
3237
- return this.__pro('maxRadius', v);
3524
+ return this.property('maxRadius', v);
3238
3525
  }
3239
3526
 
3240
3527
  /**
@@ -3244,18 +3531,18 @@ class jmHArc extends jmArc {
3244
3531
  * @private
3245
3532
  */
3246
3533
  initPoints() {
3247
- let location = this.getLocation();
3534
+ const location = this.getLocation();
3248
3535
  //如果设定了半径。则以半径为主
3249
- let minr = this.minRadius;
3250
- let maxr = this.maxRadius;
3536
+ const minr = this.minRadius;
3537
+ const maxr = this.maxRadius;
3251
3538
 
3252
3539
  let start = this.startAngle;
3253
3540
  let end = this.endAngle;
3254
- let anticlockwise = this.anticlockwise;
3541
+ const anticlockwise = this.anticlockwise;
3255
3542
 
3256
3543
  //如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
3257
3544
  if(anticlockwise) {
3258
- let p2 = Math.PI*2;
3545
+ const p2 = Math.PI*2;
3259
3546
  start = p2 - start;
3260
3547
  end = p2 - end;
3261
3548
  }
@@ -3263,8 +3550,8 @@ class jmHArc extends jmArc {
3263
3550
  let step = 0.1;
3264
3551
  if(start > end) step = -step;
3265
3552
 
3266
- let minps = [];
3267
- let maxps = [];
3553
+ const minps = [];
3554
+ const maxps = [];
3268
3555
  //椭圆方程x=a*cos(r) ,y=b*sin(r)
3269
3556
  for(let r=start;;r += step) {
3270
3557
  if(step > 0 && r > end) {
@@ -3274,13 +3561,13 @@ class jmHArc extends jmArc {
3274
3561
  r = end;
3275
3562
  }
3276
3563
 
3277
- let cos = Math.cos(r);
3278
- let sin = Math.sin(r);
3279
- let p1 = {
3564
+ const cos = Math.cos(r);
3565
+ const sin = Math.sin(r);
3566
+ const p1 = {
3280
3567
  x : cos * minr + location.center.x,
3281
3568
  y : sin * minr + location.center.y
3282
3569
  };
3283
- let p2 = {
3570
+ const p2 = {
3284
3571
  x : cos * maxr + location.center.x,
3285
3572
  y : sin * maxr + location.center.y
3286
3573
  };
@@ -3308,12 +3595,16 @@ class jmHArc extends jmArc {
3308
3595
  class jmLine extends jmPath {
3309
3596
 
3310
3597
  constructor(params, t='jmLine') {
3598
+
3599
+ params.isRegular = true;// 规则的
3600
+
3311
3601
  super(params, t);
3312
3602
 
3313
3603
  this.start = params.start || {x:0,y:0};
3314
3604
  this.end = params.end || {x:0,y:0};
3315
3605
  this.style.lineType = this.style.lineType || 'solid';
3316
3606
  this.style.dashLength = this.style.dashLength || 4;
3607
+ this.style.close = false;
3317
3608
  }
3318
3609
 
3319
3610
  /**
@@ -3324,11 +3615,11 @@ class jmLine extends jmPath {
3324
3615
  * @type {point}
3325
3616
  */
3326
3617
  get start() {
3327
- return this.__pro('start');
3618
+ return this.property('start');
3328
3619
  }
3329
3620
  set start(v) {
3330
3621
  this.needUpdate = true;
3331
- return this.__pro('start', v);
3622
+ return this.property('start', v);
3332
3623
  }
3333
3624
 
3334
3625
  /**
@@ -3339,11 +3630,11 @@ class jmLine extends jmPath {
3339
3630
  * @type {point}
3340
3631
  */
3341
3632
  get end() {
3342
- return this.__pro('end');
3633
+ return this.property('end');
3343
3634
  }
3344
3635
  set end(v) {
3345
3636
  this.needUpdate = true;
3346
- return this.__pro('end', v);
3637
+ return this.property('end', v);
3347
3638
  }
3348
3639
 
3349
3640
  /**
@@ -3352,30 +3643,34 @@ class jmLine extends jmPath {
3352
3643
  * @private
3353
3644
  */
3354
3645
  initPoints() {
3355
- let start = this.start;
3356
- let end = this.end;
3646
+ const start = this.start;
3647
+ const end = this.end;
3357
3648
  this.points = [];
3358
3649
  this.points.push(start);
3359
3650
 
3360
3651
  if(this.style.lineType === 'dotted') {
3361
3652
  let dx = end.x - start.x;
3362
3653
  let dy = end.y - start.y;
3363
- let lineLen = Math.sqrt(dx * dx + dy * dy);
3654
+ const lineLen = Math.sqrt(dx * dx + dy * dy);
3364
3655
  dx = dx / lineLen;
3365
3656
  dy = dy / lineLen;
3366
3657
  let dottedstart = false;
3367
3658
 
3368
- let dashLen = this.style.dashLength || 5;
3369
- let dottedsp = dashLen / 2;
3659
+ const dashLen = this.style.dashLength || 5;
3660
+ const dottedsp = dashLen / 2;
3370
3661
  for(let l=dashLen; l<=lineLen;) {
3371
- if(dottedstart == false) {
3372
- this.points.push({x: start.x + dx * l, y: start.y + dy * l});
3662
+ const p = {
3663
+ x: start.x + dx * l,
3664
+ y: start.y + dy * l
3665
+ };
3666
+ if(dottedstart === false) {
3373
3667
  l += dottedsp;
3374
3668
  }
3375
3669
  else {
3376
- this.points.push({x: start.x + dx * l, y: start.y+ dy * l, m: true});
3670
+ p.m = true;// 移动到当时坐标
3377
3671
  l += dashLen;
3378
3672
  }
3673
+ this.points.push(p);
3379
3674
  dottedstart = !dottedstart;
3380
3675
  }
3381
3676
  }
@@ -3394,6 +3689,8 @@ class jmLine extends jmPath {
3394
3689
  class jmPrismatic extends jmPath {
3395
3690
 
3396
3691
  constructor(params, t='jmPrismatic') {
3692
+ params.isRegular = true;// 规则的
3693
+
3397
3694
  super(params, t);
3398
3695
  this.style.close = typeof this.style.close == 'undefined'? true : this.style.close;
3399
3696
 
@@ -3411,11 +3708,11 @@ class jmPrismatic extends jmPath {
3411
3708
  * @type {point}
3412
3709
  */
3413
3710
  get center() {
3414
- return this.__pro('center');
3711
+ return this.property('center');
3415
3712
  }
3416
3713
  set center(v) {
3417
3714
  this.needUpdate = true;
3418
- return this.__pro('center', v);
3715
+ return this.property('center', v);
3419
3716
  }
3420
3717
 
3421
3718
  /**
@@ -3449,6 +3746,7 @@ class jmRect extends jmPath {
3449
3746
 
3450
3747
  constructor(params, t='jmRect') {
3451
3748
  params = params||{};
3749
+ params.isRegular = true;// 规则的
3452
3750
  super(params, t);
3453
3751
 
3454
3752
  this.style.close = true;
@@ -3460,11 +3758,11 @@ class jmRect extends jmPath {
3460
3758
  * @type {number}
3461
3759
  */
3462
3760
  get radius() {
3463
- return this.__pro('radius');
3761
+ return this.property('radius');
3464
3762
  }
3465
3763
  set radius(v) {
3466
3764
  this.needUpdate = true;
3467
- return this.__pro('radius', v);
3765
+ return this.property('radius', v);
3468
3766
  }
3469
3767
 
3470
3768
  /**
@@ -3473,11 +3771,11 @@ class jmRect extends jmPath {
3473
3771
  * @type {point}
3474
3772
  */
3475
3773
  get position() {
3476
- return this.__pro('position');
3774
+ return this.property('position');
3477
3775
  }
3478
3776
  set position(v) {
3479
3777
  this.needUpdate = true;
3480
- return this.__pro('position', v);
3778
+ return this.property('position', v);
3481
3779
  }
3482
3780
 
3483
3781
  /**
@@ -3652,6 +3950,7 @@ class jmImage extends jmControl {
3652
3950
 
3653
3951
  constructor(params, t) {
3654
3952
  params = params || {};
3953
+ params.isRegular = true;// 规则的
3655
3954
  super(params, t||'jmImage');
3656
3955
 
3657
3956
  this.style.fill = this.fill || 'transparent';//默认指定一个fill,为了可以鼠标选中
@@ -3669,10 +3968,10 @@ class jmImage extends jmControl {
3669
3968
  * @type {point}
3670
3969
  */
3671
3970
  get sourcePosition() {
3672
- return this.__pro('sourcePosition');
3971
+ return this.property('sourcePosition');
3673
3972
  }
3674
3973
  set sourcePosition(v) {
3675
- return this.__pro('sourcePosition', v);
3974
+ return this.property('sourcePosition', v);
3676
3975
  }
3677
3976
 
3678
3977
  /**
@@ -3682,11 +3981,11 @@ class jmImage extends jmControl {
3682
3981
  * @type {number}
3683
3982
  */
3684
3983
  get sourceWidth() {
3685
- return this.__pro('sourceWidth');
3984
+ return this.property('sourceWidth');
3686
3985
  }
3687
3986
  set sourceWidth(v) {
3688
3987
  this.needUpdate = true;
3689
- return this.__pro('sourceWidth', v);
3988
+ return this.property('sourceWidth', v);
3690
3989
  }
3691
3990
 
3692
3991
  /**
@@ -3696,11 +3995,11 @@ class jmImage extends jmControl {
3696
3995
  * @type {number}
3697
3996
  */
3698
3997
  get sourceHeight() {
3699
- return this.__pro('sourceHeight');
3998
+ return this.property('sourceHeight');
3700
3999
  }
3701
4000
  set sourceHeight(v) {
3702
4001
  this.needUpdate = true;
3703
- return this.__pro('sourceHeight', v);
4002
+ return this.property('sourceHeight', v);
3704
4003
  }
3705
4004
 
3706
4005
  /**
@@ -3710,11 +4009,11 @@ class jmImage extends jmControl {
3710
4009
  * @type {img}
3711
4010
  */
3712
4011
  get image() {
3713
- return this.__pro('image');
4012
+ return this.property('image');
3714
4013
  }
3715
4014
  set image(v) {
3716
4015
  this.needUpdate = true;
3717
- return this.__pro('image', v);
4016
+ return this.property('image', v);
3718
4017
  }
3719
4018
 
3720
4019
  /**
@@ -3724,23 +4023,9 @@ class jmImage extends jmControl {
3724
4023
  * @method draw
3725
4024
  */
3726
4025
  draw() {
3727
- try {
3728
-
3729
- let img = this.getImage();
3730
- if(this.graph.isWXMiniApp && this.graph.canvas && typeof img === 'string') {
3731
- // 图片对象
3732
- const image = this.graph.canvas.createImage();
3733
- // 图片加载完成回调
3734
- image.onload = () => {
3735
- // 将图片绘制到 canvas 上
3736
- this.drawImg(image);
3737
- };
3738
- // 设置图片src
3739
- image.src = img;
3740
- }
3741
- else {
3742
- this.drawImg(img);
3743
- }
4026
+ try {
4027
+ const img = this.getImage();
4028
+ this.drawImg(img);
3744
4029
  }
3745
4030
  catch(e) {
3746
4031
  console.error && console.error(e);
@@ -3749,42 +4034,72 @@ class jmImage extends jmControl {
3749
4034
 
3750
4035
  // 绘制
3751
4036
  drawImg(img) {
3752
- if(!img) {
4037
+ if(!img || !img.complete) {
3753
4038
  console.warn('image is empty');
3754
4039
  return;
3755
4040
  }
3756
4041
  let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3757
4042
  if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3758
- let p = this.getLocation();
3759
- p.left += bounds.left;
3760
- p.top += bounds.top;
4043
+
4044
+ let p = this.getLocation();
3761
4045
 
3762
4046
  let sp = this.sourcePosition;
3763
4047
  let sw = this.sourceWidth;
3764
4048
  let sh = this.sourceHeight;
3765
4049
 
4050
+ const ctx = this.webglControl || this.context;
4051
+ if(this.webglControl) {
4052
+ ctx.setParentBounds && ctx.setParentBounds(bounds);
4053
+ const localBounds = this.getBounds();
4054
+ // 给图片给定顶点
4055
+ ctx.draw([
4056
+ {
4057
+ x: localBounds.left,
4058
+ y: localBounds.top
4059
+ },
4060
+ {
4061
+ x: localBounds.left + localBounds.width,
4062
+ y: localBounds.top
4063
+ },
4064
+ {
4065
+ x: localBounds.left + localBounds.width,
4066
+ y: localBounds.top + localBounds.height
4067
+ },
4068
+ {
4069
+ x: localBounds.left,
4070
+ y: localBounds.top + localBounds.height
4071
+ }
4072
+ ], bounds);
4073
+ ctx.drawImage(img, localBounds.left, localBounds.top, localBounds.width, localBounds.height);
4074
+ return;
4075
+ }
4076
+
4077
+ // 计算绝对定位
4078
+ p.left += bounds.left;
4079
+ p.top += bounds.top;
4080
+
3766
4081
  if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
3767
4082
  if(typeof sw == 'undefined') sw= p.width || img.width || 0;
3768
4083
  if(typeof sh == 'undefined') sh= p.height || img.height || 0;
3769
4084
  sp = sp || {x:0, y:0};
3770
4085
 
3771
- if(p.width && p.height) this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
4086
+ if(p.width && p.height) ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
3772
4087
  else if(p.width) {
3773
- this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
4088
+ ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
3774
4089
  }
3775
4090
  else if(p.height) {
3776
- this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
4091
+ ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
3777
4092
  }
3778
- else this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
4093
+ else ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
3779
4094
  }
3780
4095
  else if(p) {
3781
- if(p.width && p.height) this.context.drawImage(img,p.left,p.top,p.width,p.height);
3782
- else if(p.width) this.context.drawImage(img,p.left,p.top,p.width,img.height);
3783
- else if(p.height) this.context.drawImage(img,p.left,p.top,img.width,p.height);
3784
- else this.context.drawImage(img,p.left,p.top);
4096
+ if(p.width && p.height) ctx.drawImage(img,p.left,p.top,p.width,p.height);
4097
+ else if(p.width) ctx.drawImage(img,p.left,p.top,p.width,img.height);
4098
+ else if(p.height) ctx.drawImage(img,p.left,p.top,img.width,p.height);
4099
+ else ctx.drawImage(img,p.left,p.top);
3785
4100
  }
3786
4101
  else {
3787
- this.context.drawImage(img);
4102
+ ctx.drawImage(img);
3788
4103
  }
3789
4104
  }
3790
4105
 
@@ -3816,7 +4131,7 @@ class jmImage extends jmControl {
3816
4131
  * @return {img} 图片对象
3817
4132
  */
3818
4133
  getImage() {
3819
- let src = this.image || this.style.src || this.style.image;
4134
+ const src = this.image || this.style.src || this.style.image;
3820
4135
  if(this.__img && this.__img.src && this.__img.src.indexOf(src) != -1) {
3821
4136
  return this.__img;
3822
4137
  }
@@ -3825,11 +4140,24 @@ class jmImage extends jmControl {
3825
4140
  }
3826
4141
  else if(typeof document !== 'undefined' && document.createElement) {
3827
4142
  this.__img = document.createElement('img');
4143
+ this.__img.onload = ()=>{
4144
+ this.needUpdate = true;
4145
+ };
3828
4146
  if(src && typeof src == 'string') this.__img.src = src;
3829
4147
  }
4148
+ else if(this.graph.isWXMiniApp && this.graph.canvas && typeof src === 'string') {
4149
+ // 图片对象
4150
+ this.__img = this.graph.canvas.createImage();
4151
+ this.__img.onload = ()=>{
4152
+ this.needUpdate = true;
4153
+ };
4154
+ // 设置图片src
4155
+ this.__img.src = src;
4156
+ }
3830
4157
  else {
3831
4158
  this.__img = src;
3832
4159
  }
4160
+ if(this.__img) this.image = this.__img.src;
3833
4161
  return this.__img;
3834
4162
  }
3835
4163
  }
@@ -3845,6 +4173,7 @@ class jmLabel extends jmControl {
3845
4173
 
3846
4174
  constructor(params, t) {
3847
4175
  params = params || {};
4176
+ params.isRegular = true;// 规则的
3848
4177
  super(params, t||'jmLabel');
3849
4178
 
3850
4179
  this.style.font = this.style.font || "15px Arial";
@@ -3867,11 +4196,11 @@ class jmLabel extends jmControl {
3867
4196
  * @type {string}
3868
4197
  */
3869
4198
  get text() {
3870
- return this.__pro('text');
4199
+ return this.property('text');
3871
4200
  }
3872
4201
  set text(v) {
3873
4202
  this.needUpdate = true;
3874
- return this.__pro('text', v);
4203
+ return this.property('text', v);
3875
4204
  }
3876
4205
 
3877
4206
  /**
@@ -3881,11 +4210,11 @@ class jmLabel extends jmControl {
3881
4210
  * @type {point}
3882
4211
  */
3883
4212
  get center() {
3884
- return this.__pro('center');
4213
+ return this.property('center');
3885
4214
  }
3886
4215
  set center(v) {
3887
4216
  this.needUpdate = true;
3888
- return this.__pro('center', v);
4217
+ return this.property('center', v);
3889
4218
  }
3890
4219
 
3891
4220
  /**
@@ -3894,11 +4223,11 @@ class jmLabel extends jmControl {
3894
4223
  * @type {point}
3895
4224
  */
3896
4225
  get position() {
3897
- return this.__pro('position');
4226
+ return this.property('position');
3898
4227
  }
3899
4228
  set position(v) {
3900
4229
  this.needUpdate = true;
3901
- return this.__pro('position', v);
4230
+ return this.property('position', v);
3902
4231
  }
3903
4232
 
3904
4233
  /**
@@ -3949,17 +4278,17 @@ class jmLabel extends jmControl {
3949
4278
  testSize() {
3950
4279
  if(this.__size) return this.__size;
3951
4280
 
3952
- this.context.save();
4281
+ this.context.save && this.context.save();
3953
4282
  // 修改字体,用来计算
3954
4283
  this.setStyle({
3955
- font: this.style.font || (this.style.fontSize + 'px ' + this.style.fontFamily)
4284
+ font: this.style.font || `${this.style.fontSize}px "${this.style.fontFamily}"`
3956
4285
  });
3957
4286
  //计算宽度
3958
4287
  this.__size = this.context.measureText?
3959
4288
  this.context.measureText(this.text):
3960
4289
  {width:15};
3961
- this.context.restore();
3962
- this.__size.height = this.style.fontSize?this.style.fontSize:15;
4290
+ this.context.restore && this.context.restore();
4291
+ if(!this.__size.height) this.__size.height = this.style.fontSize? this.style.fontSize: 15;
3963
4292
  if(!this.width) this.width = this.__size.width;
3964
4293
  if(!this.height) this.height = this.__size.height;
3965
4294
  return this.__size;
@@ -4027,7 +4356,7 @@ class jmLabel extends jmControl {
4027
4356
  if(this.style.border) {
4028
4357
  //如果指定了边框样式
4029
4358
  if(this.style.border.style) {
4030
- this.context.save();
4359
+ this.context.save && this.context.save();
4031
4360
  this.setStyle(this.style.border.style);
4032
4361
  }
4033
4362
  this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
@@ -4051,7 +4380,7 @@ class jmLabel extends jmControl {
4051
4380
  }
4052
4381
  //如果指定了边框颜色
4053
4382
  if(this.style.border.style) {
4054
- this.context.restore();
4383
+ this.context.restore && this.context.restore();
4055
4384
  }
4056
4385
  }
4057
4386
  }
@@ -4069,6 +4398,8 @@ class jmResize extends jmRect {
4069
4398
 
4070
4399
  constructor(params, t='jmResize') {
4071
4400
  params = params || {};
4401
+ params.isRegular = true;// 规则的
4402
+
4072
4403
  super(params, t);
4073
4404
  //是否可拉伸
4074
4405
  this.resizable = params.resizable === false?false:true;
@@ -4084,10 +4415,10 @@ class jmResize extends jmRect {
4084
4415
  * @type {number}
4085
4416
  */
4086
4417
  get rectSize() {
4087
- return this.__pro('rectSize');
4418
+ return this.property('rectSize');
4088
4419
  }
4089
4420
  set rectSize(v) {
4090
- return this.__pro('rectSize', v);
4421
+ return this.property('rectSize', v);
4091
4422
  }
4092
4423
 
4093
4424
  /**
@@ -4096,10 +4427,10 @@ class jmResize extends jmRect {
4096
4427
  * @type {boolean}
4097
4428
  */
4098
4429
  get resizable() {
4099
- return this.__pro('resizable');
4430
+ return this.property('resizable');
4100
4431
  }
4101
4432
  set resizable(v) {
4102
- return this.__pro('resizable', v);
4433
+ return this.property('resizable', v);
4103
4434
  }
4104
4435
 
4105
4436
  /**
@@ -4414,7 +4745,7 @@ class jmMouseEvent {
4414
4745
 
4415
4746
  init(instance, container, target) {
4416
4747
  let canvas = this.target;
4417
- let doc = typeof typeof document != 'undefined'?document:null;
4748
+ let doc = typeof document != 'undefined'? document: null;
4418
4749
  //禁用鼠标右健系统菜单
4419
4750
  //canvas.oncontextmenu = function() {
4420
4751
  // return false;
@@ -4539,7 +4870,7 @@ class jmKeyEvent {
4539
4870
  * 初始化健盘事件
4540
4871
  */
4541
4872
  init(container, target) {
4542
- let doc = typeof typeof document != 'undefined'?document:null;
4873
+ let doc = typeof document != 'undefined'? document: null;
4543
4874
  /**
4544
4875
  * 检查是否触发健盘事件至画布
4545
4876
  * 如果触发对象为输入框等对象则不响应事件
@@ -4617,9 +4948,10 @@ class jmGraph$1 extends jmControl {
4617
4948
  }
4618
4949
 
4619
4950
  option = option || {};
4620
- option.mode = option.mode || '2d'; // webgl | 2d
4951
+ option.mode = '2d'; // webgl | 2d 暂不支持webgl
4621
4952
  option.interactive = true;
4622
-
4953
+ option.isRegular = true;// 规则的
4954
+
4623
4955
  super(option, 'jmGraph');
4624
4956
 
4625
4957
  this.option = option || {};
@@ -4631,7 +4963,9 @@ class jmGraph$1 extends jmControl {
4631
4963
  * @property utils/util
4632
4964
  * @type {jmUtils}
4633
4965
  */
4634
- this.util = this.utils = jmUtils;
4966
+ this.util = this.utils = jmUtils;
4967
+ // 模式 webgl | 2d
4968
+ this.mode = option.mode;
4635
4969
 
4636
4970
  //如果是小程序
4637
4971
  if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
@@ -4647,7 +4981,7 @@ class jmGraph$1 extends jmControl {
4647
4981
  canvas = canvas[0];
4648
4982
  }
4649
4983
 
4650
- if(canvas.tagName != 'CANVAS') {
4984
+ if(!canvas.getContext && typeof document != 'undefined') {
4651
4985
  this.container = canvas;
4652
4986
  let cn = document.createElement('canvas');
4653
4987
  canvas.appendChild(cn);
@@ -4660,7 +4994,25 @@ class jmGraph$1 extends jmControl {
4660
4994
  }
4661
4995
  }
4662
4996
  this.canvas = canvas;
4663
- this.context = canvas.getContext('2d');
4997
+ this.context = canvas.getContext(this.mode);
4998
+
4999
+ this.textureCanvas = option.textureCanvas || null;
5000
+
5001
+ // webgl模式
5002
+ if(this.mode === 'webgl') {
5003
+
5004
+ this.context.enable(this.context.BLEND);// 开启混合功能:(注意,它不可和gl.DEPTH_TEST一起使用)
5005
+ this.context.blendFunc(this.context.SRC_ALPHA, this.context.ONE_MINUS_SRC_ALPHA); // 指定混合函数:
5006
+ // webglcontextlost webglcontextrestored
5007
+ jmUtils.bindEvent(canvas, 'webglcontextlost', (e)=> {
5008
+ console.log('canvas webglcontextlost', e);
5009
+ this.emit('webglcontextlost', e);
5010
+ });
5011
+ jmUtils.bindEvent(canvas, 'webglcontextrestored', (e)=> {
5012
+ console.log('canvas webglcontextrestored', e);
5013
+ this.emit('webglcontextrestored', e);
5014
+ });
5015
+ }
4664
5016
  this.__init(callback);
4665
5017
  }
4666
5018
 
@@ -4683,13 +5035,13 @@ class jmGraph$1 extends jmControl {
4683
5035
  * 为了解决一像素线条问题
4684
5036
  */
4685
5037
  this.on('beginDraw', function() {
4686
- this.context.translate(0.5, 0.5);
5038
+ this.context.translate && this.context.translate(0.5, 0.5);
4687
5039
  });
4688
5040
  /**
4689
5041
  * 结束控件绘制 为了解决一像素线条问题
4690
5042
  */
4691
5043
  this.on('endDraw', function() {
4692
- this.context.translate(-0.5, -0.5);
5044
+ this.context.translate && this.context.translate(-0.5, -0.5);
4693
5045
  });
4694
5046
 
4695
5047
  // devicePixelRatio初始化
@@ -4700,7 +5052,7 @@ class jmGraph$1 extends jmControl {
4700
5052
  this.devicePixelRatio = dpr;
4701
5053
  // 为了解决锯齿问题,先放大canvas再缩放
4702
5054
  this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
4703
-
5055
+
4704
5056
  if(this.option.width > 0) this.width = this.option.width;
4705
5057
  if(this.option.height > 0) this.height = this.option.height;
4706
5058
  this.resize();
@@ -4728,9 +5080,17 @@ class jmGraph$1 extends jmControl {
4728
5080
 
4729
5081
  this.css('width', w + "px");
4730
5082
  this.css('height', h + "px");
4731
- this.canvas.height = h * this.dprScaleSize;
4732
- this.canvas.width = w * this.dprScaleSize;
4733
- this.context.scale(this.dprScaleSize, this.dprScaleSize);
5083
+ if(this.mode === '2d') {
5084
+ this.canvas.height = h * this.dprScaleSize;
5085
+ this.canvas.width = w * this.dprScaleSize;
5086
+ if(this.dprScaleSize !== 1) this.context.scale && this.context.scale(this.dprScaleSize, this.dprScaleSize);
5087
+ }
5088
+ else {
5089
+ this.canvas.width = w;
5090
+ this.canvas.height = h;
5091
+ }
5092
+
5093
+ this.context.viewport && this.context.viewport(0, 0, w, h);
4734
5094
  }
4735
5095
 
4736
5096
  /**
@@ -4800,7 +5160,7 @@ class jmGraph$1 extends jmControl {
4800
5160
  * @return {postion} 返回定位坐标
4801
5161
  */
4802
5162
  getPosition() {
4803
- let p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
5163
+ const p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
4804
5164
  p.width = this.width;
4805
5165
  p.height = this.height;
4806
5166
  p.right = p.left + p.width;
@@ -4851,7 +5211,7 @@ class jmGraph$1 extends jmControl {
4851
5211
  * @return {jmShadow} 阴影对象
4852
5212
  */
4853
5213
  createShadow(x, y, blur, color) {
4854
- let sh = new jmShadow(x, y, blur, color);
5214
+ const sh = new jmShadow(x, y, blur, color);
4855
5215
  return sh;
4856
5216
  }
4857
5217
 
@@ -4866,7 +5226,7 @@ class jmGraph$1 extends jmControl {
4866
5226
  * @return {jmGradient} 线性渐变对象
4867
5227
  */
4868
5228
  createLinearGradient(x1, y1, x2, y2) {
4869
- let gradient = new jmGradient({
5229
+ const gradient = new jmGradient({
4870
5230
  type:'linear',
4871
5231
  x1: x1,
4872
5232
  y1: y1,
@@ -4889,7 +5249,7 @@ class jmGraph$1 extends jmControl {
4889
5249
  * @return {jmGradient} 放射渐变对象
4890
5250
  */
4891
5251
  createRadialGradient(x1, y1, r1, x2, y2, r2) {
4892
- let gradient = new jmGradient({
5252
+ const gradient = new jmGradient({
4893
5253
  type:'radial',
4894
5254
  x1: x1,
4895
5255
  y1: y1,
@@ -4944,16 +5304,30 @@ class jmGraph$1 extends jmControl {
4944
5304
  h = h / this.scaleSize.y;
4945
5305
  }*/
4946
5306
  }
4947
- //如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
4948
- if(this.style && this.style.fill) {
4949
- this.points = [
4950
- {x:0,y:0},
4951
- {x:w,y:0},
4952
- {x:w,y:h},
4953
- {x:0,y:h}
4954
- ];
5307
+
5308
+ if(this.context.clearRect) {
5309
+ if(this.style && this.style.fill) {
5310
+ this.points = [
5311
+ {x:0, y:0},
5312
+ {x:w, y:0},
5313
+ {x:w, y:h},
5314
+ {x:0, y:h}
5315
+ ];
5316
+ this.style.close = true;// 封闭填充
5317
+ }
5318
+
5319
+ this.context.clearRect(0, 0, w, h);
5320
+ }
5321
+ else if(this.mode === 'webgl' && this.context.clear) {
5322
+ const color = this.style && this.style.fill? this.utils.hexToRGBA(this.style.fill): {
5323
+ r: 0,
5324
+ g: 0,
5325
+ b: 0,
5326
+ a: 0
5327
+ };
5328
+ this.context.clearColor(color.r, color.g, color.b, color.a); // 设置清空颜色缓冲时的颜色值
5329
+ this.context.clear(this.context.COLOR_BUFFER_BIT); // 清空颜色缓冲区,也就是清空画布
4955
5330
  }
4956
- else if(this.context.clearRect) this.context.clearRect(0,0,w,h);
4957
5331
  }
4958
5332
 
4959
5333
  /**
@@ -4978,10 +5352,11 @@ class jmGraph$1 extends jmControl {
4978
5352
  * @param {style} style 当前路径的样式
4979
5353
  * @return {jmPath} 路径对象jmPath
4980
5354
  */
4981
- createPath(points, style) {
4982
- let path = this.createShape('path',{
5355
+ createPath(points, style, option={}) {
5356
+ const path = this.createShape('path',{
4983
5357
  points: points,
4984
- style: style
5358
+ style: style,
5359
+ ...option
4985
5360
  });
4986
5361
  return path;
4987
5362
  }
@@ -4996,7 +5371,7 @@ class jmGraph$1 extends jmControl {
4996
5371
  * @return {jmLine} 直线对象
4997
5372
  */
4998
5373
  createLine(start, end, style) {
4999
- let line = this.createShape('line', {
5374
+ const line = this.createShape('line', {
5000
5375
  start: start,
5001
5376
  end: end,
5002
5377
  style: style
@@ -5146,7 +5521,16 @@ class jmGraph extends jmGraph$1 {
5146
5521
 
5147
5522
  super(canvas, option, callback);
5148
5523
  }
5149
- }
5524
+
5525
+ static create(...args) {
5526
+ return createJmGraph(...args);
5527
+ }
5528
+ }
5529
+
5530
+ //创建实例
5531
+ const createJmGraph = (...args) => {
5532
+ return new jmGraph(...args);
5533
+ };
5150
5534
 
5151
5535
  /**
5152
5536
  * 基础样式