@antv/g 3.3.5 → 3.3.6

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/build/g.js CHANGED
@@ -328,6 +328,7 @@ var Util = __webpack_require__(0);
328
328
 
329
329
  var regexTags = /[MLHVQTCSAZ]([^MLHVQTCSAZ]*)/ig;
330
330
  var regexDot = /[^\s\,]+/ig;
331
+ var numColorCache = {};
331
332
  module.exports = {
332
333
  parseRadius: function parseRadius(radius) {
333
334
  var r1 = 0,
@@ -389,6 +390,23 @@ module.exports = {
389
390
  });
390
391
  return path;
391
392
  }
393
+ },
394
+ numberToColor: function numberToColor(num) {
395
+ // 增加缓存
396
+ var color = numColorCache[num];
397
+
398
+ if (!color) {
399
+ var str = num.toString(16);
400
+
401
+ for (var i = str.length; i < 6; i++) {
402
+ str = '0' + str;
403
+ }
404
+
405
+ color = '#' + str;
406
+ numColorCache[num] = color;
407
+ }
408
+
409
+ return color;
392
410
  }
393
411
  };
394
412
 
@@ -1977,6 +1995,11 @@ Util.augment(Marker, {
1977
1995
  method = Marker.Symbols[symbol];
1978
1996
  }
1979
1997
 
1998
+ if (!method) {
1999
+ console.warn(symbol + " marker is not supported.");
2000
+ return null;
2001
+ }
2002
+
1980
2003
  return method(x, y, r);
1981
2004
  },
1982
2005
  createPath: function createPath(context) {
@@ -7136,7 +7159,7 @@ module.exports = {
7136
7159
  PathUtil: __webpack_require__(20),
7137
7160
  Event: __webpack_require__(36),
7138
7161
  // version, etc.
7139
- version: '3.3.5'
7162
+ version: '3.3.6'
7140
7163
  };
7141
7164
 
7142
7165
  /***/ }),
@@ -7338,22 +7361,17 @@ Util.augment(Canvas, {
7338
7361
  }, false);
7339
7362
  },
7340
7363
  _scale: function _scale() {
7341
- if (this._cfg.renderType !== 'svg') {
7342
- var pixelRatio = this.get('pixelRatio');
7343
- this.scale(pixelRatio, pixelRatio);
7344
- }
7364
+ var pixelRatio = this.get('pixelRatio');
7365
+ this.scale(pixelRatio, pixelRatio);
7345
7366
  },
7346
7367
  _setGlobalParam: function _setGlobalParam() {
7347
- var renderType = this.get('renderer') || 'canvas';
7368
+ var pixelRatio = this.get('pixelRatio');
7348
7369
 
7349
- if (renderType === 'svg') {
7350
- this.set('pixelRatio', 1);
7351
- } else if (!this.get('pixelRatio')) {
7370
+ if (!pixelRatio) {
7352
7371
  this.set('pixelRatio', Util.getRatio());
7353
7372
  }
7354
7373
 
7355
- this._cfg.renderType = renderType;
7356
- var renderer = renderers[renderType];
7374
+ var renderer = renderers[this.get('renderer') || 'canvas'];
7357
7375
  this._cfg.renderer = renderer;
7358
7376
  this._cfg.canvas = this;
7359
7377
  var timeline = new Timeline(this);
@@ -7448,9 +7466,6 @@ Util.augment(Canvas, {
7448
7466
 
7449
7467
  return Canvas.superclass.getShape.call(this, x, y);
7450
7468
  },
7451
- getRenderer: function getRenderer() {
7452
- return this._cfg.renderType;
7453
- },
7454
7469
  _drawSync: function _drawSync() {
7455
7470
  this._cfg.painter.drawSync(this);
7456
7471
  },
@@ -13385,7 +13400,8 @@ var regexDot = /[^\s\,]+/ig;
13385
13400
  var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
13386
13401
  var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
13387
13402
  var regexPR = /^p\s*\(\s*([axyn])\s*\)\s*(.*)/i;
13388
- var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/ig; // const numColorCache = {};
13403
+ var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/ig;
13404
+ var numColorCache = {};
13389
13405
 
13390
13406
  function addStop(steps, gradient) {
13391
13407
  var arr = steps.match(regexColorStop);
@@ -13577,22 +13593,24 @@ module.exports = {
13577
13593
 
13578
13594
  return color;
13579
13595
  }
13580
- }
13581
- /* ,
13582
- numberToColor(num) {
13596
+ },
13597
+ numberToColor: function numberToColor(num) {
13583
13598
  // 增加缓存
13584
- let color = numColorCache[num];
13599
+ var color = numColorCache[num];
13600
+
13585
13601
  if (!color) {
13586
- let str = num.toString(16);
13587
- for (let i = str.length; i < 6; i++) {
13602
+ var str = num.toString(16);
13603
+
13604
+ for (var i = str.length; i < 6; i++) {
13588
13605
  str = '0' + str;
13589
13606
  }
13607
+
13590
13608
  color = '#' + str;
13591
13609
  numColorCache[num] = color;
13592
13610
  }
13593
- return color;
13594
- }*/
13595
13611
 
13612
+ return color;
13613
+ }
13596
13614
  };
13597
13615
 
13598
13616
  /***/ }),
@@ -13715,7 +13733,9 @@ function () {
13715
13733
  });
13716
13734
 
13717
13735
  try {
13718
- self._drawChildren(model);
13736
+ model.resetMatrix();
13737
+
13738
+ self._drawGroup(model, false);
13719
13739
  } catch (ev) {
13720
13740
  // 绘制时异常,中断重绘
13721
13741
  console.warn('error in draw canvas, detail as:');
@@ -13734,15 +13754,25 @@ function () {
13734
13754
  };
13735
13755
 
13736
13756
  _proto.drawSync = function drawSync(model) {
13737
- this._drawChildren(model);
13757
+ this._drawChildren(model, false);
13738
13758
  };
13739
13759
 
13740
- _proto._drawGroup = function _drawGroup(model, index) {
13760
+ _proto._drawGroup = function _drawGroup(model, redraw) {
13741
13761
  var cfg = model._cfg;
13742
13762
 
13743
13763
  if (cfg.removed || cfg.destroyed) {
13744
13764
  return;
13745
13765
  }
13766
+ /**
13767
+ * FIXME redraw: 为了使元素置顶的临时解决方案
13768
+ * 如果直接将dom元素重排可以解决部分问题。但是如果重排后的group中有新增的shape,置顶效果就没有了
13769
+ * 所以只能删除原有节点,新增节点以及所有子节点。这时候哪怕shape有el,也需要判断一下是否需要重绘
13770
+ */
13771
+
13772
+
13773
+ if (!cfg.el && cfg.attrs) {
13774
+ redraw = true;
13775
+ }
13746
13776
 
13747
13777
  if (cfg.tobeRemoved) {
13748
13778
  Util.each(cfg.tobeRemoved, function (item) {
@@ -13753,14 +13783,14 @@ function () {
13753
13783
  cfg.tobeRemoved = [];
13754
13784
  }
13755
13785
 
13756
- this._drawShape(model, index);
13786
+ this._drawShape(model, redraw);
13757
13787
 
13758
13788
  if (cfg.children && cfg.children.length > 0) {
13759
- this._drawChildren(model);
13789
+ this._drawChildren(model, redraw);
13760
13790
  }
13761
13791
  };
13762
13792
 
13763
- _proto._drawChildren = function _drawChildren(parent) {
13793
+ _proto._drawChildren = function _drawChildren(parent, redraw) {
13764
13794
  var self = this;
13765
13795
  var children = parent._cfg.children;
13766
13796
  var shape; // 防止在画children的时候,父group已经被destroy
@@ -13769,18 +13799,27 @@ function () {
13769
13799
  return;
13770
13800
  }
13771
13801
 
13802
+ if (parent._cfg.el && !redraw) {
13803
+ // FIXME 这边是为了解决一个group中有元素已经生成el,还有一些没生成el时,没生成el的置底效果不work
13804
+ var childLen = parent._cfg.el.childNodes.length + 1;
13805
+
13806
+ if (childLen !== 0 && childLen !== children.length) {
13807
+ redraw = true;
13808
+ }
13809
+ }
13810
+
13772
13811
  for (var i = 0; i < children.length; i++) {
13773
13812
  shape = children[i];
13774
13813
 
13775
13814
  if (shape.isGroup) {
13776
- self._drawGroup(shape, i);
13815
+ self._drawGroup(shape, redraw);
13777
13816
  } else {
13778
- self._drawShape(shape, i);
13817
+ self._drawShape(shape, redraw);
13779
13818
  }
13780
13819
  }
13781
13820
  };
13782
13821
 
13783
- _proto._drawShape = function _drawShape(model, index) {
13822
+ _proto._drawShape = function _drawShape(model, redraw) {
13784
13823
  var self = this;
13785
13824
  var attrs = model._attrs;
13786
13825
  var cfg = model._cfg;
@@ -13792,11 +13831,17 @@ function () {
13792
13831
  }
13793
13832
 
13794
13833
  return;
13834
+ } // 重绘节点
13835
+
13836
+
13837
+ if (redraw && el) {
13838
+ el.parentNode && el.parentNode.removeChild(el);
13839
+ el = null;
13795
13840
  } // 新增节点
13796
13841
 
13797
13842
 
13798
13843
  if (!el && cfg.parent) {
13799
- self._createDom(model, index);
13844
+ self._createDom(model);
13800
13845
 
13801
13846
  self._updateShape(model);
13802
13847
  }
@@ -13992,11 +14037,9 @@ function () {
13992
14037
  }
13993
14038
  };
13994
14039
 
13995
- _proto._createDom = function _createDom(model, index) {
14040
+ _proto._createDom = function _createDom(model) {
13996
14041
  var type = SHAPE_TO_TAGS[model.type];
13997
14042
  var attrs = model._attrs;
13998
- var parent = model._cfg.parent;
13999
- var parentNode = parent._cfg.el;
14000
14043
 
14001
14044
  if (!type) {
14002
14045
  throw new Error('the type' + model.type + 'is not supported by svg');
@@ -14005,22 +14048,8 @@ function () {
14005
14048
  var shape = document.createElementNS('http://www.w3.org/2000/svg', type);
14006
14049
  model._cfg.el = shape;
14007
14050
 
14008
- if (parent) {
14009
- if (typeof index === 'undefined') {
14010
- parentNode.appendChild(shape);
14011
- } else {
14012
- var childNodes = parent._cfg.el.childNodes; // svg下天然有defs作为子节点,svg下子元素index需要+1
14013
-
14014
- if (parentNode.tagName === 'svg') {
14015
- index += 1;
14016
- }
14017
-
14018
- if (childNodes.length <= index) {
14019
- parentNode.appendChild(shape);
14020
- } else {
14021
- parentNode.insertBefore(shape, childNodes[index]);
14022
- }
14023
- }
14051
+ if (model._cfg.parent) {
14052
+ model._cfg.parent.get('el').appendChild(shape);
14024
14053
  }
14025
14054
 
14026
14055
  model._cfg.attrs = {};