@antv/g-svg 0.5.5 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/g.min.js +1 -31
  2. package/dist/g.min.js.map +1 -1
  3. package/esm/canvas.d.ts +1 -1
  4. package/esm/group.d.ts +1 -1
  5. package/esm/index.d.ts +3 -4
  6. package/esm/index.js +2 -5
  7. package/esm/index.js.map +1 -1
  8. package/esm/interfaces.d.ts +2 -2
  9. package/esm/interfaces.js +1 -1
  10. package/esm/interfaces.js.map +1 -1
  11. package/esm/shape/base.d.ts +1 -1
  12. package/esm/shape/base.js +1 -1
  13. package/esm/shape/base.js.map +1 -1
  14. package/esm/shape/line.js +1 -1
  15. package/esm/shape/line.js.map +1 -1
  16. package/esm/shape/path.d.ts +1 -1
  17. package/esm/shape/polyline.d.ts +1 -1
  18. package/esm/shape/polyline.js +2 -2
  19. package/esm/shape/polyline.js.map +1 -1
  20. package/esm/types.d.ts +1 -1
  21. package/esm/types.js +1 -1
  22. package/esm/types.js.map +1 -1
  23. package/esm/util/draw.d.ts +1 -1
  24. package/lib/canvas.d.ts +1 -1
  25. package/lib/group.d.ts +1 -1
  26. package/lib/index.d.ts +3 -4
  27. package/lib/index.js +3 -7
  28. package/lib/index.js.map +1 -1
  29. package/lib/interfaces.d.ts +2 -2
  30. package/lib/interfaces.js +1 -1
  31. package/lib/interfaces.js.map +1 -1
  32. package/lib/shape/base.d.ts +1 -1
  33. package/lib/shape/base.js +2 -2
  34. package/lib/shape/base.js.map +1 -1
  35. package/lib/shape/line.js +3 -3
  36. package/lib/shape/line.js.map +1 -1
  37. package/lib/shape/path.d.ts +1 -1
  38. package/lib/shape/polyline.d.ts +1 -1
  39. package/lib/shape/polyline.js +5 -5
  40. package/lib/shape/polyline.js.map +1 -1
  41. package/lib/types.d.ts +1 -1
  42. package/lib/types.js +1 -1
  43. package/lib/types.js.map +1 -1
  44. package/lib/util/draw.d.ts +1 -1
  45. package/package.json +9 -8
  46. package/src/canvas.ts +100 -0
  47. package/src/constant.ts +67 -0
  48. package/src/defs/arrow.ts +83 -0
  49. package/src/defs/clip.ts +38 -0
  50. package/src/defs/gradient.ts +129 -0
  51. package/src/defs/index.ts +110 -0
  52. package/src/defs/pattern.ts +56 -0
  53. package/src/defs/shadow.ts +81 -0
  54. package/src/group.ts +99 -0
  55. package/src/index.ts +9 -0
  56. package/src/interfaces.ts +27 -0
  57. package/src/shape/base.ts +246 -0
  58. package/src/shape/circle.ts +39 -0
  59. package/src/shape/dom.ts +40 -0
  60. package/src/shape/ellipse.ts +40 -0
  61. package/src/shape/image.ts +81 -0
  62. package/src/shape/index.ts +12 -0
  63. package/src/shape/line.ts +67 -0
  64. package/src/shape/marker/index.ts +56 -0
  65. package/src/shape/marker/symbols.ts +49 -0
  66. package/src/shape/path.ts +90 -0
  67. package/src/shape/polygon.ts +27 -0
  68. package/src/shape/polyline.ts +146 -0
  69. package/src/shape/rect.ts +91 -0
  70. package/src/shape/text.ts +126 -0
  71. package/src/types.ts +2 -0
  72. package/src/util/dom.ts +95 -0
  73. package/src/util/draw.ts +67 -0
  74. package/src/util/format.ts +62 -0
  75. package/src/util/svg.ts +51 -0
@@ -0,0 +1,67 @@
1
+ import { ChangeType } from '@antv/g-base';
2
+ import { IElement } from '../interfaces';
3
+ import { setTransform, setClip } from './svg';
4
+ import { sortDom, moveTo } from './dom';
5
+ import Defs from '../defs';
6
+
7
+ export function drawChildren(context: Defs, children: IElement[]) {
8
+ children.forEach((child) => {
9
+ child.draw(context);
10
+ });
11
+ }
12
+
13
+ /**
14
+ * 更新元素,包括 group 和 shape
15
+ * @param {IElement} element SVG 元素
16
+ * @param {ChangeType} changeType 更新类型
17
+ */
18
+ export function refreshElement(element: IElement, changeType: ChangeType) {
19
+ // 对于还没有挂载到画布下的元素,canvas 可能为空
20
+ const canvas = element.get('canvas');
21
+ // 只有挂载到画布下,才对元素进行实际渲染
22
+ if (canvas && canvas.get('autoDraw')) {
23
+ const context = canvas.get('context');
24
+ const parent = element.getParent();
25
+ const parentChildren = parent ? parent.getChildren() : [canvas];
26
+ const el = element.get('el');
27
+ if (changeType === 'remove') {
28
+ const isClipShape = element.get('isClipShape');
29
+ // 对于 clip,不仅需要将 clipShape 对于的 SVG 元素删除,还需要将上层的 clipPath 元素也删除
30
+ if (isClipShape) {
31
+ const clipPathEl = el && el.parentNode;
32
+ const defsEl = clipPathEl && clipPathEl.parentNode;
33
+ if (clipPathEl && defsEl) {
34
+ defsEl.removeChild(clipPathEl);
35
+ }
36
+ } else if (el && el.parentNode) {
37
+ el.parentNode.removeChild(el);
38
+ }
39
+ } else if (changeType === 'show') {
40
+ el.setAttribute('visibility', 'visible');
41
+ } else if (changeType === 'hide') {
42
+ el.setAttribute('visibility', 'hidden');
43
+ } else if (changeType === 'zIndex') {
44
+ moveTo(el, parentChildren.indexOf(element));
45
+ } else if (changeType === 'sort') {
46
+ const children = element.get('children');
47
+ if (children && children.length) {
48
+ sortDom(element, (a: IElement, b: IElement) => {
49
+ return children.indexOf(a) - children.indexOf(b) ? 1 : 0;
50
+ });
51
+ }
52
+ } else if (changeType === 'clear') {
53
+ // el maybe null for group
54
+ if (el) {
55
+ el.innerHTML = '';
56
+ }
57
+ } else if (changeType === 'matrix') {
58
+ setTransform(element);
59
+ } else if (changeType === 'clip') {
60
+ setClip(element, context);
61
+ } else if (changeType === 'attr') {
62
+ // 已在 afterAttrsChange 进行了处理,此处 do nothing
63
+ } else if (changeType === 'add') {
64
+ element.draw(context);
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,62 @@
1
+ import { each, isArray, isString } from '@antv/util';
2
+
3
+ const regexTags = /[MLHVQTCSAZ]([^MLHVQTCSAZ]*)/gi;
4
+ const regexDot = /[^\s,]+/gi;
5
+
6
+ export function parseRadius(radius) {
7
+ let r1 = 0;
8
+ let r2 = 0;
9
+ let r3 = 0;
10
+ let r4 = 0;
11
+ if (isArray(radius)) {
12
+ if (radius.length === 1) {
13
+ r1 = r2 = r3 = r4 = radius[0];
14
+ } else if (radius.length === 2) {
15
+ r1 = r3 = radius[0];
16
+ r2 = r4 = radius[1];
17
+ } else if (radius.length === 3) {
18
+ r1 = radius[0];
19
+ r2 = r4 = radius[1];
20
+ r3 = radius[2];
21
+ } else {
22
+ r1 = radius[0];
23
+ r2 = radius[1];
24
+ r3 = radius[2];
25
+ r4 = radius[3];
26
+ }
27
+ } else {
28
+ r1 = r2 = r3 = r4 = radius;
29
+ }
30
+ return {
31
+ r1,
32
+ r2,
33
+ r3,
34
+ r4,
35
+ };
36
+ }
37
+
38
+ export function parsePath(path) {
39
+ path = path || [];
40
+ if (isArray(path)) {
41
+ return path;
42
+ }
43
+
44
+ if (isString(path)) {
45
+ path = path.match(regexTags);
46
+ each(path, (item, index) => {
47
+ item = item.match(regexDot);
48
+ if (item[0].length > 1) {
49
+ const tag = item[0].charAt(0);
50
+ item.splice(1, 0, item[0].substr(1));
51
+ item[0] = tag;
52
+ }
53
+ each(item, (sub, i) => {
54
+ if (!isNaN(sub)) {
55
+ item[i] = +sub;
56
+ }
57
+ });
58
+ path[index] = item;
59
+ });
60
+ return path;
61
+ }
62
+ }
@@ -0,0 +1,51 @@
1
+ import { createDom } from './dom';
2
+
3
+ export function setShadow(model, context) {
4
+ const el = model.cfg.el;
5
+ const attrs = model.attr();
6
+ const cfg = {
7
+ dx: attrs.shadowOffsetX,
8
+ dy: attrs.shadowOffsetY,
9
+ blur: attrs.shadowBlur,
10
+ color: attrs.shadowColor,
11
+ };
12
+ if (!cfg.dx && !cfg.dy && !cfg.blur && !cfg.color) {
13
+ el.removeAttribute('filter');
14
+ } else {
15
+ let id = context.find('filter', cfg);
16
+ if (!id) {
17
+ id = context.addShadow(cfg);
18
+ }
19
+ el.setAttribute('filter', `url(#${id})`);
20
+ }
21
+ }
22
+
23
+ export function setTransform(model) {
24
+ const { matrix } = model.attr();
25
+ if (matrix) {
26
+ const el = model.cfg.el;
27
+ let transform: any = [];
28
+ for (let i = 0; i < 9; i += 3) {
29
+ transform.push(`${matrix[i]},${matrix[i + 1]}`);
30
+ }
31
+ transform = transform.join(',');
32
+ if (transform.indexOf('NaN') === -1) {
33
+ el.setAttribute('transform', `matrix(${transform})`);
34
+ } else {
35
+ console.warn('invalid matrix:', matrix);
36
+ }
37
+ }
38
+ }
39
+
40
+ export function setClip(model, context) {
41
+ const clip = model.getClip();
42
+ const el = model.get('el');
43
+ if (!clip) {
44
+ el.removeAttribute('clip-path');
45
+ } else if (clip && !el.hasAttribute('clip-path')) {
46
+ createDom(clip);
47
+ clip.createPath(context);
48
+ const id = context.addClip(clip);
49
+ el.setAttribute('clip-path', `url(#${id})`);
50
+ }
51
+ }