TWaver Forums
http://twaver.servasoft.com/forum/

network. zoomOverview() 原理是什么
http://twaver.servasoft.com/forum/viewtopic.php?f=35&t=6174
Page 1 of 1

Author:  yk168168 [ 2019-08-13 16:59 ]
Post subject:  network. zoomOverview() 原理是什么

network. zoomOverview() 原理是什么

Author:  Paddy [ 2019-12-17 17:59 ]
Post subject:  Re: network. zoomOverview() 原理是什么

也就是将视图缩放到让所有数据元可见,下面是实现方式:
Code:
zoomOverview: function(animate) {
        if (this._unionBounds.width <= 0 || this._unionBounds.width <= 0) {
            return;
        }
        var zoom = this.getZoom();
        var ub = this._unionBounds;
        var rw = ub.width / zoom;
        var rh = ub.height / zoom;
        var wzoom = this.viewRect.width / rw;
        var hzoom = this.viewRect.height / rh;
        var min = Math.min(wzoom, hzoom);
        this.setZoom(min);
        var newZoom = this.getZoom();
        var offsetx = this.viewRect.width / 2 - this._unionBounds.width / 2 * newZoom / zoom;
        var offsety = this.viewRect.height / 2 - this._unionBounds.height / 2 * newZoom / zoom;
        this.setViewRect(this._unionBounds.x * newZoom / zoom - offsetx, this._unionBounds.y * newZoom / zoom - offsety, this.viewRect.width, this.viewRect.height);
    },

Author:  yk168168 [ 2019-12-21 9:59 ]
Post subject:  Re: network. zoomOverview() 原理是什么

zoomOverview 往往不生效或是有时生效有时不生效,

let zoomOverview = (evt) => {
this.network.removeViewListener(zoomOverview)
setTimeout(() => {
this.network.zoomOverview()
}, 300)
}
this.network.addViewListener(zoomOverview)
需要看倒计时时间,时间也依赖于数据量;监听事件没有完全达到监听所有元素创建完成 后缩放

Author:  Paddy [ 2019-12-23 14:52 ]
Post subject:  Re: network. zoomOverview() 原理是什么

您可以监听视图绘制的事件,在完成时调用zoomOverview。
Code:
var callback = function(e) {
      if (e.kind === 'validateEnd') {
        network.removeViewListener(callback);
        network.zoomOverview();
      }
    };
network.addViewListener(callback);

Page 1 of 1 All times are UTC + 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/