@antv/g 5.0.5 → 5.0.9

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 (47) hide show
  1. package/dist/index.umd.min.js +15 -0
  2. package/es/Canvas.d.ts +4 -2
  3. package/es/Canvas.js +11 -5
  4. package/es/camera/Camera.d.ts +2 -1
  5. package/es/camera/Camera.js +13 -5
  6. package/es/components/Sortable.d.ts +4 -0
  7. package/es/components/Sortable.js +5 -0
  8. package/es/display-objects/Line.d.ts +6 -0
  9. package/es/display-objects/Line.js +7 -8
  10. package/es/display-objects/Path.js +3 -7
  11. package/es/display-objects/Polyline.js +3 -7
  12. package/es/display-objects/Text.js +3 -7
  13. package/es/dom/EventTarget.d.ts +1 -1
  14. package/es/dom/EventTarget.js +1 -1
  15. package/es/dom/interfaces.d.ts +5 -1
  16. package/es/dom/interfaces.js +5 -0
  17. package/es/global-module.js +1 -2
  18. package/es/property-handlers/localPosition.js +4 -2
  19. package/es/services/RenderingService.d.ts +1 -0
  20. package/es/services/RenderingService.js +14 -0
  21. package/es/services/SceneGraphService.js +4 -4
  22. package/es/types.d.ts +10 -2
  23. package/es/types.js +16 -0
  24. package/lib/Canvas.d.ts +4 -2
  25. package/lib/Canvas.js +11 -5
  26. package/lib/camera/Camera.d.ts +2 -1
  27. package/lib/camera/Camera.js +14 -5
  28. package/lib/components/Sortable.d.ts +4 -0
  29. package/lib/components/Sortable.js +5 -0
  30. package/lib/display-objects/Line.d.ts +6 -0
  31. package/lib/display-objects/Line.js +6 -7
  32. package/lib/display-objects/Path.js +2 -6
  33. package/lib/display-objects/Polyline.js +2 -6
  34. package/lib/display-objects/Text.js +2 -6
  35. package/lib/dom/EventTarget.d.ts +1 -1
  36. package/lib/dom/EventTarget.js +1 -1
  37. package/lib/dom/interfaces.d.ts +5 -1
  38. package/lib/dom/interfaces.js +5 -0
  39. package/lib/global-module.js +1 -2
  40. package/lib/property-handlers/localPosition.js +4 -2
  41. package/lib/services/RenderingService.d.ts +1 -0
  42. package/lib/services/RenderingService.js +15 -0
  43. package/lib/services/SceneGraphService.js +4 -4
  44. package/lib/types.d.ts +10 -2
  45. package/lib/types.js +19 -1
  46. package/package.json +4 -4
  47. package/dist/index.umd.js +0 -15
@@ -155,7 +155,7 @@ function (_super) {
155
155
 
156
156
  _this.fov = 30;
157
157
  _this.near = 0.1;
158
- _this.far = 10000;
158
+ _this.far = 1000;
159
159
  _this.aspect = 1;
160
160
  _this.projectionMatrix = _glMatrix.mat4.create();
161
161
  _this.projectionMatrixInverse = _glMatrix.mat4.create();
@@ -182,6 +182,10 @@ function (_super) {
182
182
  return _this;
183
183
  }
184
184
 
185
+ Camera.prototype.isOrtho = function () {
186
+ return this.projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
187
+ };
188
+
185
189
  Camera.prototype.clone = function () {
186
190
  var camera = new Camera();
187
191
  camera.setType(this.type, undefined); // camera.interactor = this.interactor;
@@ -317,6 +321,7 @@ function (_super) {
317
321
 
318
322
  Camera.prototype.setFov = function (fov) {
319
323
  this.setPerspective(this.near, this.far, fov, this.aspect);
324
+ return this;
320
325
  };
321
326
 
322
327
  Camera.prototype.setAspect = function (aspect) {
@@ -424,10 +429,11 @@ function (_super) {
424
429
  top -= this.view.offsetY * height / fullHeight;
425
430
  width *= this.view.width / fullWidth;
426
431
  height *= this.view.height / fullHeight;
427
- } // flip Y
432
+ }
428
433
 
434
+ (0, _math.makePerspective)(this.projectionMatrix, left, left + width, top, top - height, near, this.far); // flipY since the origin of OpenGL/WebGL is bottom-left compared with top-left in Canvas2D
429
435
 
430
- (0, _math.makePerspective)(this.projectionMatrix, left, left + width, top - height, top, near, this.far);
436
+ _glMatrix.mat4.scale(this.projectionMatrix, this.projectionMatrix, _glMatrix.vec3.fromValues(1, -1, 1));
431
437
 
432
438
  _glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
433
439
 
@@ -461,7 +467,10 @@ function (_super) {
461
467
  bottom = top - scaleH * this.view.height;
462
468
  }
463
469
 
464
- _glMatrix.mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
470
+ _glMatrix.mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far); // flipY since the origin of OpenGL/WebGL is bottom-left compared with top-left in Canvas2D
471
+
472
+
473
+ _glMatrix.mat4.scale(this.projectionMatrix, this.projectionMatrix, _glMatrix.vec3.fromValues(1, -1, 1));
465
474
 
466
475
  _glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
467
476
 
@@ -1033,7 +1042,7 @@ function (_super) {
1033
1042
 
1034
1043
  var rotZ = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 0, 1], -this.roll * Math.PI / 180);
1035
1044
 
1036
- _glMatrix.mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, _glMatrix.vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.bottom - this.top) / 2 - position[1], 0), _glMatrix.vec3.fromValues(this.zoom, this.zoom, 1), position);
1045
+ _glMatrix.mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, _glMatrix.vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), _glMatrix.vec3.fromValues(this.zoom, this.zoom, 1), position);
1037
1046
  };
1038
1047
 
1039
1048
  Camera.ProjectionMode = {
@@ -13,4 +13,8 @@ export declare class Sortable {
13
13
  * index in parent's children
14
14
  */
15
15
  lastSortedIndex: number;
16
+ /**
17
+ * render order in whole scenegraph
18
+ */
19
+ renderOrder: number;
16
20
  }
@@ -13,6 +13,11 @@ function () {
13
13
  * need to re-sort
14
14
  */
15
15
  this.dirty = false;
16
+ /**
17
+ * render order in whole scenegraph
18
+ */
19
+
20
+ this.renderOrder = 0;
16
21
  }
17
22
 
18
23
  Sortable.tag = 'c-sortable';
@@ -7,14 +7,20 @@ export interface LineStyleProps extends BaseStyleProps {
7
7
  y1: number;
8
8
  x2: number;
9
9
  y2: number;
10
+ z1?: number;
11
+ z2?: number;
12
+ isBillboard?: boolean;
10
13
  }
11
14
  export interface ParsedLineStyleProps extends ParsedBaseStyleProps {
12
15
  x1: number;
13
16
  y1: number;
14
17
  x2: number;
15
18
  y2: number;
19
+ z1?: number;
20
+ z2?: number;
16
21
  defX: number;
17
22
  defY: number;
23
+ isBillboard?: boolean;
18
24
  }
19
25
  export declare class Line extends DisplayObject<LineStyleProps, ParsedLineStyleProps> {
20
26
  constructor({ style, ...rest }: DisplayObjectConfig<LineStyleProps>);
@@ -30,13 +30,12 @@ function (_super) {
30
30
  y1: 0,
31
31
  x2: 0,
32
32
  y2: 0,
33
- lineJoin: "miter"
34
- /* Miter */
35
- ,
36
- lineCap: "butt"
37
- /* Butt */
38
- ,
39
- lineWidth: 1
33
+ z1: 0,
34
+ z2: 0,
35
+ lineJoin: _types.LINE_JOIN.Miter,
36
+ lineCap: _types.LINE_CAP.Butt,
37
+ lineWidth: 1,
38
+ isBillboard: false
40
39
  }, style)
41
40
  }, rest)) || this;
42
41
  }
@@ -29,12 +29,8 @@ function (_super) {
29
29
  type: _types.SHAPE.Path,
30
30
  style: (0, _tslib.__assign)({
31
31
  path: '',
32
- lineJoin: "miter"
33
- /* Miter */
34
- ,
35
- lineCap: "butt"
36
- /* Butt */
37
- ,
32
+ lineJoin: _types.LINE_JOIN.Miter,
33
+ lineCap: _types.LINE_CAP.Butt,
38
34
  lineWidth: 1
39
35
  }, style)
40
36
  }, rest)) || this;
@@ -27,12 +27,8 @@ function (_super) {
27
27
  type: _types.SHAPE.Polyline,
28
28
  style: (0, _tslib.__assign)({
29
29
  points: [],
30
- lineJoin: "miter"
31
- /* Miter */
32
- ,
33
- lineCap: "butt"
34
- /* Butt */
35
- ,
30
+ lineJoin: _types.LINE_JOIN.Miter,
31
+ lineCap: _types.LINE_CAP.Butt,
36
32
  lineWidth: 1
37
33
  }, style)
38
34
  }, rest)) || this;
@@ -39,12 +39,8 @@ function (_super) {
39
39
  fill: '#000',
40
40
  letterSpacing: 0,
41
41
  lineHeight: 0,
42
- lineJoin: "miter"
43
- /* Miter */
44
- ,
45
- lineCap: "butt"
46
- /* Butt */
47
- ,
42
+ lineJoin: _types.LINE_JOIN.Miter,
43
+ lineCap: _types.LINE_CAP.Butt,
48
44
  lineWidth: 0,
49
45
  miterLimit: 10,
50
46
  padding: 0,
@@ -27,7 +27,7 @@ export declare class EventTarget implements IEventTarget {
27
27
  */
28
28
  off(type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions): this;
29
29
  removeAllEventListeners(): void;
30
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): this;
30
+ removeEventListener(type: string, listener?: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): this;
31
31
  /**
32
32
  * @deprecated
33
33
  * @alias dispatchEvent
@@ -124,7 +124,7 @@ function () {
124
124
  var capture = (0, _util.isBoolean)(options) && options || (0, _util.isObject)(options) && options.capture;
125
125
  var context = (0, _util.isFunction)(listener) ? undefined : listener;
126
126
  type = capture ? type + "capture" : type;
127
- listener = (0, _util.isFunction)(listener) ? listener : listener.handleEvent;
127
+ listener = (0, _util.isFunction)(listener) ? listener : listener === null || listener === void 0 ? void 0 : listener.handleEvent;
128
128
  this.emitter.off(type, listener, context);
129
129
  return this;
130
130
  };
@@ -31,7 +31,11 @@ export declare enum ElementEvent {
31
31
  CHILD_REMOVED = "child-removed",
32
32
  MOUNTED = "mounted",
33
33
  UNMOUNTED = "unmounted",
34
- BOUNDS_CHANGED = "bounds-changed"
34
+ BOUNDS_CHANGED = "bounds-changed",
35
+ /**
36
+ * trigger when z-index changed
37
+ */
38
+ RENDER_ORDER_CHANGED = "render-order-changed"
35
39
  }
36
40
  export interface IEventTarget {
37
41
  emitter: EventEmitter;
@@ -37,4 +37,9 @@ exports.ElementEvent = ElementEvent;
37
37
  ElementEvent["MOUNTED"] = "mounted";
38
38
  ElementEvent["UNMOUNTED"] = "unmounted";
39
39
  ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
40
+ /**
41
+ * trigger when z-index changed
42
+ */
43
+
44
+ ElementEvent["RENDER_ORDER_CHANGED"] = "render-order-changed";
40
45
  })(ElementEvent || (exports.ElementEvent = ElementEvent = {}));
@@ -172,8 +172,7 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
172
172
 
173
173
  addPropertyHandler('points', _propertyHandlers.parsePoints, undefined, undefined); // update local position
174
174
 
175
- addPropertiesHandler(['x', 'y', 'points', 'path', 'x1', 'x2', 'y1', 'y2'], // ['x', 'y'],
176
- undefined, undefined, _propertyHandlers.updateLocalPosition);
175
+ addPropertiesHandler(['x', 'y', 'z', 'points', 'path', 'x1', 'x2', 'y1', 'y2', 'z1', 'z2'], undefined, undefined, _propertyHandlers.updateLocalPosition);
177
176
  addPropertyHandler('filter', _propertyHandlers.parseFilter, undefined, undefined);
178
177
  addPropertyHandler('anchor', undefined, undefined, _propertyHandlers.updateAnchor);
179
178
  });
@@ -10,7 +10,9 @@ function updateLocalPosition(oldValue, newValue, object) {
10
10
  _b = _a.x,
11
11
  x = _b === void 0 ? 0 : _b,
12
12
  _c = _a.y,
13
- y = _c === void 0 ? 0 : _c; // update local position when x/y changed
13
+ y = _c === void 0 ? 0 : _c,
14
+ _d = _a.z,
15
+ z = _d === void 0 ? 0 : _d; // update local position when x/y changed
14
16
 
15
- object.setLocalPosition(x, y);
17
+ object.setLocalPosition(x, y, z);
16
18
  }
@@ -25,6 +25,7 @@ export declare class RenderingService {
25
25
  private sceneGraphService;
26
26
  private inited;
27
27
  private stats;
28
+ private zIndexCounter;
28
29
  hooks: {
29
30
  init: AsyncSeriesHook<[], import("tapable").UnsetAdditionalOptions>;
30
31
  prepare: SyncWaterfallHook<[DisplayObject<any, any>], import("tapable").UnsetAdditionalOptions>;
@@ -11,6 +11,8 @@ var _manaSyringe = require("mana-syringe");
11
11
 
12
12
  var _tapable = require("tapable");
13
13
 
14
+ var _dom = require("../dom");
15
+
14
16
  var _RenderingContext = require("./RenderingContext");
15
17
 
16
18
  var _SceneGraphService = require("./SceneGraphService");
@@ -38,6 +40,7 @@ function () {
38
40
  total: 0,
39
41
  rendered: 0
40
42
  };
43
+ this.zIndexCounter = 0;
41
44
  this.hooks = {
42
45
  init: new _tapable.AsyncSeriesHook(),
43
46
  prepare: new _tapable.SyncWaterfallHook(['object']),
@@ -97,6 +100,7 @@ function () {
97
100
  RenderingService.prototype.render = function () {
98
101
  this.stats.total = 0;
99
102
  this.stats.rendered = 0;
103
+ this.zIndexCounter = 0;
100
104
  this.sceneGraphService.syncHierarchy(this.renderingContext.root);
101
105
 
102
106
  if (this.renderingContext.renderReasons.size && this.inited) {
@@ -122,6 +126,7 @@ function () {
122
126
 
123
127
 
124
128
  var objectToRender = this.hooks.prepare.call(displayObject);
129
+ displayObject.sortable.renderOrder = this.zIndexCounter++;
125
130
  this.stats.total++;
126
131
 
127
132
  if (objectToRender) {
@@ -140,10 +145,12 @@ function () {
140
145
 
141
146
 
142
147
  var sortable = displayObject.sortable;
148
+ var renderOrderChanged = false;
143
149
 
144
150
  if (sortable.dirty) {
145
151
  // sortable.sorted = [...(displayObject.childNodes as IElement[])].sort(sortByZIndex);
146
152
  sortable.sorted = displayObject.childNodes.slice().sort(_SceneGraphService.sortByZIndex);
153
+ renderOrderChanged = true;
147
154
  sortable.dirty = false;
148
155
  } // recursive rendering its children
149
156
 
@@ -151,6 +158,14 @@ function () {
151
158
  (sortable.sorted || displayObject.childNodes).forEach(function (child) {
152
159
  _this.renderDisplayObject(child);
153
160
  });
161
+
162
+ if (renderOrderChanged) {
163
+ displayObject.forEach(function (child) {
164
+ child.emit(_dom.ElementEvent.RENDER_ORDER_CHANGED, {
165
+ renderOrder: child.sortable.renderOrder
166
+ });
167
+ });
168
+ }
154
169
  };
155
170
 
156
171
  RenderingService.prototype.destroy = function () {
@@ -165,7 +165,7 @@ function () {
165
165
 
166
166
  var transform = element.transformable;
167
167
 
168
- if (element.parentNode === null) {
168
+ if (element.parentNode === null || !element.parentNode.transformable) {
169
169
  _this.rotateLocal(element, degrees);
170
170
  } else {
171
171
  var rotation = _glMatrix.quat.create();
@@ -244,7 +244,7 @@ function () {
244
244
 
245
245
  var transform = element.transformable;
246
246
 
247
- if (element.parentNode === null) {
247
+ if (element.parentNode === null || !element.parentNode.transformable) {
248
248
  _this.setLocalEulerAngles(element, degrees);
249
249
  } else {
250
250
  _glMatrix.quat.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
@@ -318,7 +318,7 @@ function () {
318
318
 
319
319
  transform.position = position;
320
320
 
321
- if (element.parentNode === null) {
321
+ if (element.parentNode === null || !element.parentNode.transformable) {
322
322
  _glMatrix.vec3.copy(transform.localPosition, position);
323
323
  } else {
324
324
  var parentTransform = element.parentNode.transformable;
@@ -595,7 +595,7 @@ function () {
595
595
  return transform.worldTransform;
596
596
  }
597
597
 
598
- if (element.parentNode) {
598
+ if (element.parentNode && element.parentNode.transformable) {
599
599
  this.getWorldTransform(element.parentNode);
600
600
  }
601
601
 
package/lib/types.d.ts CHANGED
@@ -25,12 +25,12 @@ export interface EventPosition {
25
25
  x: number;
26
26
  y: number;
27
27
  }
28
- export declare const enum LINE_CAP {
28
+ export declare enum LINE_CAP {
29
29
  Butt = "butt",
30
30
  Round = "round",
31
31
  Square = "square"
32
32
  }
33
- export declare const enum LINE_JOIN {
33
+ export declare enum LINE_JOIN {
34
34
  Bevel = "bevel",
35
35
  Round = "round",
36
36
  Miter = "miter"
@@ -44,6 +44,10 @@ export interface BaseStyleProps {
44
44
  * y in local space
45
45
  */
46
46
  y?: number;
47
+ /**
48
+ * z in local space
49
+ */
50
+ z?: number;
47
51
  /**
48
52
  * the origin of rotation and scaling, default to (0, 0)
49
53
  */
@@ -180,6 +184,10 @@ export interface CanvasConfig {
180
184
  * @type {number}
181
185
  */
182
186
  height: number;
187
+ /**
188
+ * 画布背景色
189
+ */
190
+ background?: ColorType;
183
191
  /**
184
192
  * 是否可监听
185
193
  * @type {boolean}
package/lib/types.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SHAPE = exports.CanvasConfig = void 0;
6
+ exports.SHAPE = exports.LINE_JOIN = exports.LINE_CAP = exports.CanvasConfig = void 0;
7
7
  var SHAPE;
8
8
  exports.SHAPE = SHAPE;
9
9
 
@@ -21,5 +21,23 @@ exports.SHAPE = SHAPE;
21
21
  SHAPE["HTML"] = "html";
22
22
  })(SHAPE || (exports.SHAPE = SHAPE = {}));
23
23
 
24
+ var LINE_CAP;
25
+ exports.LINE_CAP = LINE_CAP;
26
+
27
+ (function (LINE_CAP) {
28
+ LINE_CAP["Butt"] = "butt";
29
+ LINE_CAP["Round"] = "round";
30
+ LINE_CAP["Square"] = "square";
31
+ })(LINE_CAP || (exports.LINE_CAP = LINE_CAP = {}));
32
+
33
+ var LINE_JOIN;
34
+ exports.LINE_JOIN = LINE_JOIN;
35
+
36
+ (function (LINE_JOIN) {
37
+ LINE_JOIN["Bevel"] = "bevel";
38
+ LINE_JOIN["Round"] = "round";
39
+ LINE_JOIN["Miter"] = "miter";
40
+ })(LINE_JOIN || (exports.LINE_JOIN = LINE_JOIN = {}));
41
+
24
42
  var CanvasConfig = 'CanvasConfig';
25
43
  exports.CanvasConfig = CanvasConfig;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "5.0.5",
3
+ "version": "5.0.9",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
7
7
  "types": "es/index.d.ts",
8
- "unpkg": "dist/index.umd.js",
8
+ "unpkg": "dist/index.umd.min.js",
9
9
  "files": [
10
10
  "package.json",
11
11
  "dist",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://github.com/antvis/g#readme",
39
39
  "dependencies": {
40
- "@antv/g-math": "^1.0.5",
40
+ "@antv/g-math": "^1.0.8",
41
41
  "@antv/path-util": "^2.0.14",
42
42
  "@antv/util": "^2.0.13",
43
43
  "d3-color": "^1.4.0",
@@ -50,5 +50,5 @@
50
50
  "scripts": {
51
51
  "umd": "webpack"
52
52
  },
53
- "gitHead": "039cea4e9baf6988a7d6105bb3a907ed816a2fd9"
53
+ "gitHead": "a7b98694f386141877710e6b3a41695686deb048"
54
54
  }