@antv/g-lite 2.0.1 → 2.0.3

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.js CHANGED
@@ -1720,6 +1720,12 @@ var Camera = /** @class */ (function () {
1720
1720
  this._update();
1721
1721
  return this;
1722
1722
  };
1723
+ /**
1724
+ * Set projection matrix manually.
1725
+ */
1726
+ Camera.prototype.setProjectionMatrix = function (matrix) {
1727
+ this.projectionMatrix = matrix;
1728
+ };
1723
1729
  Camera.prototype.setFov = function (fov) {
1724
1730
  this.setPerspective(this.near, this.far, fov, this.aspect);
1725
1731
  return this;
@@ -9509,13 +9515,35 @@ var EventService = /** @class */ (function () {
9509
9515
  this.mappingState = {};
9510
9516
  this.eventPool.clear();
9511
9517
  };
9512
- EventService.prototype.client2Viewport = function (client) {
9518
+ EventService.prototype.getScale = function () {
9513
9519
  var bbox = this.context.contextService.getBoundingClientRect();
9514
- return new Point(client.x - ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), client.y - ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
9520
+ var scaleX = 1;
9521
+ var scaleY = 1;
9522
+ var $el = this.context.contextService.getDomElement();
9523
+ if ($el && bbox) {
9524
+ var offsetWidth = $el.offsetWidth, offsetHeight = $el.offsetHeight;
9525
+ scaleX = bbox.width / offsetWidth;
9526
+ scaleY = bbox.height / offsetHeight;
9527
+ }
9528
+ return {
9529
+ scaleX: scaleX,
9530
+ scaleY: scaleY,
9531
+ bbox: bbox,
9532
+ };
9533
+ };
9534
+ /**
9535
+ * Should account for CSS Transform applied on container.
9536
+ * @see https://github.com/antvis/G/issues/1161
9537
+ * @see https://github.com/antvis/G/issues/1677
9538
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
9539
+ */
9540
+ EventService.prototype.client2Viewport = function (client) {
9541
+ var _a = this.getScale(), scaleX = _a.scaleX, scaleY = _a.scaleY, bbox = _a.bbox;
9542
+ return new Point((client.x - ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0)) / scaleX, (client.y - ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0)) / scaleY);
9515
9543
  };
9516
9544
  EventService.prototype.viewport2Client = function (canvas) {
9517
- var bbox = this.context.contextService.getBoundingClientRect();
9518
- return new Point(canvas.x + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), canvas.y + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
9545
+ var _a = this.getScale(), scaleX = _a.scaleX, scaleY = _a.scaleY, bbox = _a.bbox;
9546
+ return new Point((canvas.x + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0)) * scaleX, (canvas.y + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0)) * scaleY);
9519
9547
  };
9520
9548
  EventService.prototype.viewport2Canvas = function (_a) {
9521
9549
  var x = _a.x, y = _a.y;
@@ -10099,7 +10127,7 @@ var RenderingService = /** @class */ (function () {
10099
10127
  return (!enableDirtyRectangleRendering ||
10100
10128
  this.context.renderingContext.renderReasons.has(exports.RenderReason.CAMERA_CHANGED));
10101
10129
  };
10102
- RenderingService.prototype.render = function (canvasConfig, rerenderCallback) {
10130
+ RenderingService.prototype.render = function (canvasConfig, frame, rerenderCallback) {
10103
10131
  var _this = this;
10104
10132
  this.stats.total = 0;
10105
10133
  this.stats.rendered = 0;
@@ -10118,7 +10146,7 @@ var RenderingService = /** @class */ (function () {
10118
10146
  if (shouldTriggerRenderHooks) {
10119
10147
  this.renderDisplayObject(renderingContext.root, canvasConfig, renderingContext);
10120
10148
  }
10121
- this.hooks.beginFrame.call();
10149
+ this.hooks.beginFrame.call(frame);
10122
10150
  if (shouldTriggerRenderHooks) {
10123
10151
  renderingContext.renderListCurrentFrame.forEach(function (object) {
10124
10152
  _this.hooks.beforeRender.call(object);
@@ -10126,7 +10154,7 @@ var RenderingService = /** @class */ (function () {
10126
10154
  _this.hooks.afterRender.call(object);
10127
10155
  });
10128
10156
  }
10129
- this.hooks.endFrame.call();
10157
+ this.hooks.endFrame.call(frame);
10130
10158
  renderingContext.renderListCurrentFrame = [];
10131
10159
  renderingContext.renderReasons.clear();
10132
10160
  rerenderCallback();
@@ -14480,28 +14508,6 @@ var EventPlugin = /** @class */ (function () {
14480
14508
  _this.setCursor(_this.context.eventService.cursor);
14481
14509
  });
14482
14510
  };
14483
- EventPlugin.prototype.getViewportXY = function (nativeEvent) {
14484
- var x;
14485
- var y;
14486
- /**
14487
- * Should account for CSS Transform applied on container.
14488
- * @see https://github.com/antvis/G/issues/1161
14489
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
14490
- */
14491
- var offsetX = nativeEvent.offsetX, offsetY = nativeEvent.offsetY, clientX = nativeEvent.clientX, clientY = nativeEvent.clientY;
14492
- if (this.context.config.supportsCSSTransform &&
14493
- !util.isNil(offsetX) &&
14494
- !util.isNil(offsetY)) {
14495
- x = offsetX;
14496
- y = offsetY;
14497
- }
14498
- else {
14499
- var point = this.context.eventService.client2Viewport(new Point(clientX, clientY));
14500
- x = point.x;
14501
- y = point.y;
14502
- }
14503
- return { x: x, y: y };
14504
- };
14505
14511
  EventPlugin.prototype.bootstrapEvent = function (event, normalizedEvent, view, nativeEvent) {
14506
14512
  event.view = view;
14507
14513
  event.originalEvent = null;
@@ -14517,7 +14523,10 @@ var EventPlugin = /** @class */ (function () {
14517
14523
  event.tiltY = normalizedEvent.tiltY;
14518
14524
  event.twist = normalizedEvent.twist;
14519
14525
  this.transferMouseData(event, normalizedEvent);
14520
- var _a = this.getViewportXY(normalizedEvent), x = _a.x, y = _a.y;
14526
+ var _a = this.context.eventService.client2Viewport({
14527
+ x: normalizedEvent.clientX,
14528
+ y: normalizedEvent.clientY,
14529
+ }), x = _a.x, y = _a.y;
14521
14530
  event.viewport.x = x;
14522
14531
  event.viewport.y = y;
14523
14532
  var _b = this.context.eventService.viewport2Canvas(event.viewport), canvasX = _b.x, canvasY = _b.y;
@@ -14544,7 +14553,10 @@ var EventPlugin = /** @class */ (function () {
14544
14553
  event.deltaX = nativeEvent.deltaX;
14545
14554
  event.deltaY = nativeEvent.deltaY;
14546
14555
  event.deltaZ = nativeEvent.deltaZ;
14547
- var _a = this.getViewportXY(nativeEvent), x = _a.x, y = _a.y;
14556
+ var _a = this.context.eventService.client2Viewport({
14557
+ x: nativeEvent.clientX,
14558
+ y: nativeEvent.clientY,
14559
+ }), x = _a.x, y = _a.y;
14548
14560
  event.viewport.x = x;
14549
14561
  event.viewport.y = y;
14550
14562
  var _b = this.context.eventService.viewport2Canvas(event.viewport), canvasX = _b.x, canvasY = _b.y;
@@ -15196,11 +15208,11 @@ var Canvas = /** @class */ (function (_super) {
15196
15208
  Canvas.prototype.destroyChildren = function () {
15197
15209
  this.document.documentElement.destroyChildren();
15198
15210
  };
15199
- Canvas.prototype.render = function () {
15211
+ Canvas.prototype.render = function (frame) {
15200
15212
  var _this = this;
15201
15213
  this.dispatchEvent(beforeRenderEvent);
15202
15214
  var renderingService = this.getRenderingService();
15203
- renderingService.render(this.getConfig(), function () {
15215
+ renderingService.render(this.getConfig(), frame, function () {
15204
15216
  // trigger actual rerender event
15205
15217
  // @see https://github.com/antvis/G/issues/1268
15206
15218
  _this.dispatchEvent(rerenderEvent);
@@ -15209,8 +15221,8 @@ var Canvas = /** @class */ (function (_super) {
15209
15221
  };
15210
15222
  Canvas.prototype.run = function () {
15211
15223
  var _this = this;
15212
- var tick = function () {
15213
- _this.render();
15224
+ var tick = function (time, frame) {
15225
+ _this.render(frame);
15214
15226
  _this.frameId = _this.requestAnimationFrame(tick);
15215
15227
  };
15216
15228
  tick();