123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- var zrUtil = require("zrender/lib/core/util");
- var vector = require("zrender/lib/core/vector");
- var matrix = require("zrender/lib/core/matrix");
- var BoundingRect = require("zrender/lib/core/BoundingRect");
- var Transformable = require("zrender/lib/mixin/Transformable");
- var v2ApplyTransform = vector.applyTransform;
- function TransformDummy() {
- Transformable.call(this);
- }
- zrUtil.mixin(TransformDummy, Transformable);
- function View(name) {
-
- this.name = name;
-
- this.zoomLimit;
- Transformable.call(this);
- this._roamTransformable = new TransformDummy();
- this._rawTransformable = new TransformDummy();
- this._center;
- this._zoom;
- }
- View.prototype = {
- constructor: View,
- type: 'view',
-
- dimensions: ['x', 'y'],
-
-
- setBoundingRect: function (x, y, width, height) {
- this._rect = new BoundingRect(x, y, width, height);
- return this._rect;
- },
-
-
- getBoundingRect: function () {
- return this._rect;
- },
-
- setViewRect: function (x, y, width, height) {
- this.transformTo(x, y, width, height);
- this._viewRect = new BoundingRect(x, y, width, height);
- },
-
- transformTo: function (x, y, width, height) {
- var rect = this.getBoundingRect();
- var rawTransform = this._rawTransformable;
- rawTransform.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
- rawTransform.decomposeTransform();
- this._updateTransform();
- },
-
- setCenter: function (centerCoord) {
- if (!centerCoord) {
- return;
- }
- this._center = centerCoord;
- this._updateCenterAndZoom();
- },
-
- setZoom: function (zoom) {
- zoom = zoom || 1;
- var zoomLimit = this.zoomLimit;
- if (zoomLimit) {
- if (zoomLimit.max != null) {
- zoom = Math.min(zoomLimit.max, zoom);
- }
- if (zoomLimit.min != null) {
- zoom = Math.max(zoomLimit.min, zoom);
- }
- }
- this._zoom = zoom;
- this._updateCenterAndZoom();
- },
-
- getDefaultCenter: function () {
-
- var rawRect = this.getBoundingRect();
- var cx = rawRect.x + rawRect.width / 2;
- var cy = rawRect.y + rawRect.height / 2;
- return [cx, cy];
- },
- getCenter: function () {
- return this._center || this.getDefaultCenter();
- },
- getZoom: function () {
- return this._zoom || 1;
- },
-
- getRoamTransform: function () {
- return this._roamTransformable.getLocalTransform();
- },
-
- _updateCenterAndZoom: function () {
-
- var rawTransformMatrix = this._rawTransformable.getLocalTransform();
- var roamTransform = this._roamTransformable;
- var defaultCenter = this.getDefaultCenter();
- var center = this.getCenter();
- var zoom = this.getZoom();
- center = vector.applyTransform([], center, rawTransformMatrix);
- defaultCenter = vector.applyTransform([], defaultCenter, rawTransformMatrix);
- roamTransform.origin = center;
- roamTransform.position = [defaultCenter[0] - center[0], defaultCenter[1] - center[1]];
- roamTransform.scale = [zoom, zoom];
- this._updateTransform();
- },
-
- _updateTransform: function () {
- var roamTransformable = this._roamTransformable;
- var rawTransformable = this._rawTransformable;
- rawTransformable.parent = roamTransformable;
- roamTransformable.updateTransform();
- rawTransformable.updateTransform();
- matrix.copy(this.transform || (this.transform = []), rawTransformable.transform || matrix.create());
- this._rawTransform = rawTransformable.getLocalTransform();
- this.invTransform = this.invTransform || [];
- matrix.invert(this.invTransform, this.transform);
- this.decomposeTransform();
- },
- getTransformInfo: function () {
- var roamTransform = this._roamTransformable.transform;
- var rawTransformable = this._rawTransformable;
- return {
- roamTransform: roamTransform ? zrUtil.slice(roamTransform) : matrix.create(),
- rawScale: zrUtil.slice(rawTransformable.scale),
- rawPosition: zrUtil.slice(rawTransformable.position)
- };
- },
-
- getViewRect: function () {
- return this._viewRect;
- },
-
- getViewRectAfterRoam: function () {
- var rect = this.getBoundingRect().clone();
- rect.applyTransform(this.transform);
- return rect;
- },
-
- dataToPoint: function (data, noRoam, out) {
- var transform = noRoam ? this._rawTransform : this.transform;
- out = out || [];
- return transform ? v2ApplyTransform(out, data, transform) : vector.copy(out, data);
- },
-
- pointToData: function (point) {
- var invTransform = this.invTransform;
- return invTransform ? v2ApplyTransform([], point, invTransform) : [point[0], point[1]];
- },
-
- convertToPixel: zrUtil.curry(doConvert, 'dataToPoint'),
-
- convertFromPixel: zrUtil.curry(doConvert, 'pointToData'),
-
- containPoint: function (point) {
- return this.getViewRectAfterRoam().contain(point[0], point[1]);
- }
-
-
-
-
-
-
-
- };
- zrUtil.mixin(View, Transformable);
- function doConvert(methodName, ecModel, finder, value) {
- var seriesModel = finder.seriesModel;
- var coordSys = seriesModel ? seriesModel.coordinateSystem : null;
- return coordSys === this ? coordSys[methodName](value) : null;
- }
- var _default = View;
- module.exports = _default;
|