@antv/g 5.0.5 → 5.0.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/dist/index.umd.js +1 -1
- package/es/Canvas.js +9 -6
- package/es/camera/Camera.d.ts +2 -1
- package/es/camera/Camera.js +13 -5
- package/es/components/Sortable.d.ts +4 -0
- package/es/components/Sortable.js +5 -0
- package/es/display-objects/Line.d.ts +4 -0
- package/es/display-objects/Line.js +2 -0
- package/es/dom/interfaces.d.ts +5 -1
- package/es/dom/interfaces.js +5 -0
- package/es/global-module.js +1 -2
- package/es/property-handlers/localPosition.js +4 -2
- package/es/services/RenderingService.d.ts +1 -0
- package/es/services/RenderingService.js +14 -0
- package/es/types.d.ts +8 -0
- package/lib/Canvas.js +9 -6
- package/lib/camera/Camera.d.ts +2 -1
- package/lib/camera/Camera.js +14 -5
- package/lib/components/Sortable.d.ts +4 -0
- package/lib/components/Sortable.js +5 -0
- package/lib/display-objects/Line.d.ts +4 -0
- package/lib/display-objects/Line.js +2 -0
- package/lib/dom/interfaces.d.ts +5 -1
- package/lib/dom/interfaces.js +5 -0
- package/lib/global-module.js +1 -2
- package/lib/property-handlers/localPosition.js +4 -2
- package/lib/services/RenderingService.d.ts +1 -0
- package/lib/services/RenderingService.js +15 -0
- package/lib/types.d.ts +8 -0
- package/package.json +2 -2
package/es/Canvas.js
CHANGED
|
@@ -50,9 +50,12 @@ function (_super) {
|
|
|
50
50
|
_this.customElements = new CustomElementRegistry();
|
|
51
51
|
cleanExistedCanvas(config.container, _this);
|
|
52
52
|
|
|
53
|
-
var mergedConfig = __assign(
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
var mergedConfig = __assign({
|
|
54
|
+
width: 300,
|
|
55
|
+
height: 150,
|
|
56
|
+
cursor: 'default',
|
|
57
|
+
background: 'white'
|
|
58
|
+
}, config);
|
|
56
59
|
|
|
57
60
|
_this.initRenderingContext(mergedConfig);
|
|
58
61
|
|
|
@@ -98,8 +101,7 @@ function (_super) {
|
|
|
98
101
|
|
|
99
102
|
Canvas.prototype.initDefaultCamera = function (width, height) {
|
|
100
103
|
// set a default ortho camera
|
|
101
|
-
var camera = new Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0)
|
|
102
|
-
.setOrthographic(width / -2, width / 2, height / -2, height / 2, 0.1, 1000); // redraw when camera changed
|
|
104
|
+
var camera = new Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, 0.1, 1000); // redraw when camera changed
|
|
103
105
|
|
|
104
106
|
var context = this.container.get(RenderingContext);
|
|
105
107
|
camera.on(CAMERA_EVENT.Updated, function () {
|
|
@@ -207,9 +209,10 @@ function (_super) {
|
|
|
207
209
|
|
|
208
210
|
var camera = this.container.get(DefaultCamera);
|
|
209
211
|
var projectionMode = camera.getProjectionMode();
|
|
212
|
+
camera.setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0);
|
|
210
213
|
|
|
211
214
|
if (projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
212
|
-
camera.
|
|
215
|
+
camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
|
|
213
216
|
} else {
|
|
214
217
|
camera.setAspect(width / height);
|
|
215
218
|
}
|
package/es/camera/Camera.d.ts
CHANGED
|
@@ -129,6 +129,7 @@ export declare class Camera extends EventEmitter {
|
|
|
129
129
|
* ortho matrix for Canvas2D & SVG
|
|
130
130
|
*/
|
|
131
131
|
private orthoMatrix;
|
|
132
|
+
isOrtho(): boolean;
|
|
132
133
|
clone(): Camera;
|
|
133
134
|
getProjectionMode(): CAMERA_PROJECTION_MODE;
|
|
134
135
|
getPerspective(): mat4;
|
|
@@ -167,7 +168,7 @@ export declare class Camera extends EventEmitter {
|
|
|
167
168
|
* 设置相机矩阵
|
|
168
169
|
*/
|
|
169
170
|
setMatrix(matrix: mat4): this;
|
|
170
|
-
setFov(fov: number):
|
|
171
|
+
setFov(fov: number): this;
|
|
171
172
|
setAspect(aspect: number): this;
|
|
172
173
|
setNear(near: number): this;
|
|
173
174
|
setFar(far: number): this;
|
package/es/camera/Camera.js
CHANGED
|
@@ -136,7 +136,7 @@ function (_super) {
|
|
|
136
136
|
|
|
137
137
|
_this.fov = 30;
|
|
138
138
|
_this.near = 0.1;
|
|
139
|
-
_this.far =
|
|
139
|
+
_this.far = 1000;
|
|
140
140
|
_this.aspect = 1;
|
|
141
141
|
_this.projectionMatrix = mat4.create();
|
|
142
142
|
_this.projectionMatrixInverse = mat4.create();
|
|
@@ -163,6 +163,10 @@ function (_super) {
|
|
|
163
163
|
return _this;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
Camera.prototype.isOrtho = function () {
|
|
167
|
+
return this.projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
|
|
168
|
+
};
|
|
169
|
+
|
|
166
170
|
Camera.prototype.clone = function () {
|
|
167
171
|
var camera = new Camera();
|
|
168
172
|
camera.setType(this.type, undefined); // camera.interactor = this.interactor;
|
|
@@ -297,6 +301,7 @@ function (_super) {
|
|
|
297
301
|
|
|
298
302
|
Camera.prototype.setFov = function (fov) {
|
|
299
303
|
this.setPerspective(this.near, this.far, fov, this.aspect);
|
|
304
|
+
return this;
|
|
300
305
|
};
|
|
301
306
|
|
|
302
307
|
Camera.prototype.setAspect = function (aspect) {
|
|
@@ -404,10 +409,11 @@ function (_super) {
|
|
|
404
409
|
top -= this.view.offsetY * height / fullHeight;
|
|
405
410
|
width *= this.view.width / fullWidth;
|
|
406
411
|
height *= this.view.height / fullHeight;
|
|
407
|
-
}
|
|
412
|
+
}
|
|
408
413
|
|
|
414
|
+
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
|
|
409
415
|
|
|
410
|
-
|
|
416
|
+
mat4.scale(this.projectionMatrix, this.projectionMatrix, vec3.fromValues(1, -1, 1));
|
|
411
417
|
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
412
418
|
this.emit(CAMERA_EVENT.Updated);
|
|
413
419
|
return this;
|
|
@@ -439,7 +445,9 @@ function (_super) {
|
|
|
439
445
|
bottom = top - scaleH * this.view.height;
|
|
440
446
|
}
|
|
441
447
|
|
|
442
|
-
mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
|
|
448
|
+
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
|
|
449
|
+
|
|
450
|
+
mat4.scale(this.projectionMatrix, this.projectionMatrix, vec3.fromValues(1, -1, 1));
|
|
443
451
|
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
444
452
|
|
|
445
453
|
this._getOrthoMatrix();
|
|
@@ -960,7 +968,7 @@ function (_super) {
|
|
|
960
968
|
|
|
961
969
|
var position = this.position;
|
|
962
970
|
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], -this.roll * Math.PI / 180);
|
|
963
|
-
mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.
|
|
971
|
+
mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), vec3.fromValues(this.zoom, this.zoom, 1), position);
|
|
964
972
|
};
|
|
965
973
|
|
|
966
974
|
Camera.ProjectionMode = {
|
|
@@ -7,12 +7,16 @@ export interface LineStyleProps extends BaseStyleProps {
|
|
|
7
7
|
y1: number;
|
|
8
8
|
x2: number;
|
|
9
9
|
y2: number;
|
|
10
|
+
z1?: number;
|
|
11
|
+
z2?: number;
|
|
10
12
|
}
|
|
11
13
|
export interface ParsedLineStyleProps extends ParsedBaseStyleProps {
|
|
12
14
|
x1: number;
|
|
13
15
|
y1: number;
|
|
14
16
|
x2: number;
|
|
15
17
|
y2: number;
|
|
18
|
+
z1?: number;
|
|
19
|
+
z2?: number;
|
|
16
20
|
defX: number;
|
|
17
21
|
defY: number;
|
|
18
22
|
}
|
package/es/dom/interfaces.d.ts
CHANGED
|
@@ -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;
|
package/es/dom/interfaces.js
CHANGED
|
@@ -29,4 +29,9 @@ export var ElementEvent;
|
|
|
29
29
|
ElementEvent["MOUNTED"] = "mounted";
|
|
30
30
|
ElementEvent["UNMOUNTED"] = "unmounted";
|
|
31
31
|
ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
|
|
32
|
+
/**
|
|
33
|
+
* trigger when z-index changed
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
ElementEvent["RENDER_ORDER_CHANGED"] = "render-order-changed";
|
|
32
37
|
})(ElementEvent || (ElementEvent = {}));
|
package/es/global-module.js
CHANGED
|
@@ -154,8 +154,7 @@ export var containerModule = Module(function (register) {
|
|
|
154
154
|
|
|
155
155
|
addPropertyHandler('points', parsePoints, undefined, undefined); // update local position
|
|
156
156
|
|
|
157
|
-
addPropertiesHandler(['x', 'y', 'points', 'path', 'x1', 'x2', 'y1', 'y2'
|
|
158
|
-
undefined, undefined, updateLocalPosition);
|
|
157
|
+
addPropertiesHandler(['x', 'y', 'z', 'points', 'path', 'x1', 'x2', 'y1', 'y2', 'z1', 'z2'], undefined, undefined, updateLocalPosition);
|
|
159
158
|
addPropertyHandler('filter', parseFilter, undefined, undefined);
|
|
160
159
|
addPropertyHandler('anchor', undefined, undefined, updateAnchor);
|
|
161
160
|
});
|
|
@@ -3,7 +3,9 @@ export function updateLocalPosition(oldValue, newValue, object) {
|
|
|
3
3
|
_b = _a.x,
|
|
4
4
|
x = _b === void 0 ? 0 : _b,
|
|
5
5
|
_c = _a.y,
|
|
6
|
-
y = _c === void 0 ? 0 : _c
|
|
6
|
+
y = _c === void 0 ? 0 : _c,
|
|
7
|
+
_d = _a.z,
|
|
8
|
+
z = _d === void 0 ? 0 : _d; // update local position when x/y changed
|
|
7
9
|
|
|
8
|
-
object.setLocalPosition(x, y);
|
|
10
|
+
object.setLocalPosition(x, y, z);
|
|
9
11
|
}
|
|
@@ -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>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __decorate, __generator, __metadata } from "tslib";
|
|
2
2
|
import { inject, singleton, contrib, Syringe, Contribution } from 'mana-syringe';
|
|
3
3
|
import { SyncHook, SyncWaterfallHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } from 'tapable';
|
|
4
|
+
import { ElementEvent } from '../dom';
|
|
4
5
|
import { RenderingContext, RENDER_REASON } from './RenderingContext';
|
|
5
6
|
import { SceneGraphService, sortByZIndex } from './SceneGraphService';
|
|
6
7
|
export var RenderingPluginContribution = Syringe.defineToken('RenderingPluginContribution');
|
|
@@ -23,6 +24,7 @@ function () {
|
|
|
23
24
|
total: 0,
|
|
24
25
|
rendered: 0
|
|
25
26
|
};
|
|
27
|
+
this.zIndexCounter = 0;
|
|
26
28
|
this.hooks = {
|
|
27
29
|
init: new AsyncSeriesHook(),
|
|
28
30
|
prepare: new SyncWaterfallHook(['object']),
|
|
@@ -82,6 +84,7 @@ function () {
|
|
|
82
84
|
RenderingService.prototype.render = function () {
|
|
83
85
|
this.stats.total = 0;
|
|
84
86
|
this.stats.rendered = 0;
|
|
87
|
+
this.zIndexCounter = 0;
|
|
85
88
|
this.sceneGraphService.syncHierarchy(this.renderingContext.root);
|
|
86
89
|
|
|
87
90
|
if (this.renderingContext.renderReasons.size && this.inited) {
|
|
@@ -107,6 +110,7 @@ function () {
|
|
|
107
110
|
|
|
108
111
|
|
|
109
112
|
var objectToRender = this.hooks.prepare.call(displayObject);
|
|
113
|
+
displayObject.sortable.renderOrder = this.zIndexCounter++;
|
|
110
114
|
this.stats.total++;
|
|
111
115
|
|
|
112
116
|
if (objectToRender) {
|
|
@@ -125,10 +129,12 @@ function () {
|
|
|
125
129
|
|
|
126
130
|
|
|
127
131
|
var sortable = displayObject.sortable;
|
|
132
|
+
var renderOrderChanged = false;
|
|
128
133
|
|
|
129
134
|
if (sortable.dirty) {
|
|
130
135
|
// sortable.sorted = [...(displayObject.childNodes as IElement[])].sort(sortByZIndex);
|
|
131
136
|
sortable.sorted = displayObject.childNodes.slice().sort(sortByZIndex);
|
|
137
|
+
renderOrderChanged = true;
|
|
132
138
|
sortable.dirty = false;
|
|
133
139
|
} // recursive rendering its children
|
|
134
140
|
|
|
@@ -136,6 +142,14 @@ function () {
|
|
|
136
142
|
(sortable.sorted || displayObject.childNodes).forEach(function (child) {
|
|
137
143
|
_this.renderDisplayObject(child);
|
|
138
144
|
});
|
|
145
|
+
|
|
146
|
+
if (renderOrderChanged) {
|
|
147
|
+
displayObject.forEach(function (child) {
|
|
148
|
+
child.emit(ElementEvent.RENDER_ORDER_CHANGED, {
|
|
149
|
+
renderOrder: child.sortable.renderOrder
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
139
153
|
};
|
|
140
154
|
|
|
141
155
|
RenderingService.prototype.destroy = function () {
|
package/es/types.d.ts
CHANGED
|
@@ -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/Canvas.js
CHANGED
|
@@ -71,9 +71,12 @@ function (_super) {
|
|
|
71
71
|
|
|
72
72
|
_this.customElements = new _CustomElementRegistry.CustomElementRegistry();
|
|
73
73
|
(0, _canvas.cleanExistedCanvas)(config.container, _this);
|
|
74
|
-
var mergedConfig = (0, _tslib.__assign)(
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
var mergedConfig = (0, _tslib.__assign)({
|
|
75
|
+
width: 300,
|
|
76
|
+
height: 150,
|
|
77
|
+
cursor: 'default',
|
|
78
|
+
background: 'white'
|
|
79
|
+
}, config);
|
|
77
80
|
|
|
78
81
|
_this.initRenderingContext(mergedConfig);
|
|
79
82
|
|
|
@@ -119,8 +122,7 @@ function (_super) {
|
|
|
119
122
|
|
|
120
123
|
Canvas.prototype.initDefaultCamera = function (width, height) {
|
|
121
124
|
// set a default ortho camera
|
|
122
|
-
var camera = new _camera.Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0)
|
|
123
|
-
.setOrthographic(width / -2, width / 2, height / -2, height / 2, 0.1, 1000); // redraw when camera changed
|
|
125
|
+
var camera = new _camera.Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, 0.1, 1000); // redraw when camera changed
|
|
124
126
|
|
|
125
127
|
var context = this.container.get(_RenderingContext.RenderingContext);
|
|
126
128
|
camera.on(_camera.CAMERA_EVENT.Updated, function () {
|
|
@@ -228,9 +230,10 @@ function (_super) {
|
|
|
228
230
|
|
|
229
231
|
var camera = this.container.get(_camera.DefaultCamera);
|
|
230
232
|
var projectionMode = camera.getProjectionMode();
|
|
233
|
+
camera.setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0);
|
|
231
234
|
|
|
232
235
|
if (projectionMode === _camera.CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
233
|
-
camera.
|
|
236
|
+
camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
|
|
234
237
|
} else {
|
|
235
238
|
camera.setAspect(width / height);
|
|
236
239
|
}
|
package/lib/camera/Camera.d.ts
CHANGED
|
@@ -129,6 +129,7 @@ export declare class Camera extends EventEmitter {
|
|
|
129
129
|
* ortho matrix for Canvas2D & SVG
|
|
130
130
|
*/
|
|
131
131
|
private orthoMatrix;
|
|
132
|
+
isOrtho(): boolean;
|
|
132
133
|
clone(): Camera;
|
|
133
134
|
getProjectionMode(): CAMERA_PROJECTION_MODE;
|
|
134
135
|
getPerspective(): mat4;
|
|
@@ -167,7 +168,7 @@ export declare class Camera extends EventEmitter {
|
|
|
167
168
|
* 设置相机矩阵
|
|
168
169
|
*/
|
|
169
170
|
setMatrix(matrix: mat4): this;
|
|
170
|
-
setFov(fov: number):
|
|
171
|
+
setFov(fov: number): this;
|
|
171
172
|
setAspect(aspect: number): this;
|
|
172
173
|
setNear(near: number): this;
|
|
173
174
|
setFar(far: number): this;
|
package/lib/camera/Camera.js
CHANGED
|
@@ -155,7 +155,7 @@ function (_super) {
|
|
|
155
155
|
|
|
156
156
|
_this.fov = 30;
|
|
157
157
|
_this.near = 0.1;
|
|
158
|
-
_this.far =
|
|
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
|
-
}
|
|
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
|
-
|
|
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.
|
|
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 = {
|
|
@@ -7,12 +7,16 @@ export interface LineStyleProps extends BaseStyleProps {
|
|
|
7
7
|
y1: number;
|
|
8
8
|
x2: number;
|
|
9
9
|
y2: number;
|
|
10
|
+
z1?: number;
|
|
11
|
+
z2?: number;
|
|
10
12
|
}
|
|
11
13
|
export interface ParsedLineStyleProps extends ParsedBaseStyleProps {
|
|
12
14
|
x1: number;
|
|
13
15
|
y1: number;
|
|
14
16
|
x2: number;
|
|
15
17
|
y2: number;
|
|
18
|
+
z1?: number;
|
|
19
|
+
z2?: number;
|
|
16
20
|
defX: number;
|
|
17
21
|
defY: number;
|
|
18
22
|
}
|
package/lib/dom/interfaces.d.ts
CHANGED
|
@@ -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;
|
package/lib/dom/interfaces.js
CHANGED
|
@@ -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 = {}));
|
package/lib/global-module.js
CHANGED
|
@@ -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'
|
|
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
|
|
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 () {
|
package/lib/types.d.ts
CHANGED
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"description": "A core module including ECS and DI container.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"umd": "webpack"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "dce0982c006f8205d73b6537ef620b15218a47d0"
|
|
54
54
|
}
|