feat(minimap): minimap view won't refresh when moving viewport

This commit is contained in:
elaine 2019-04-28 15:56:58 +08:00
parent 9cd19f0e1c
commit 57e1aa4957

View File

@ -76,9 +76,6 @@ class Minimap extends Base {
const cfgs = this._cfgs;
const size = cfgs.size;
const graph = cfgs.graph;
const pixelRatio = graph.get('pixelRatio') || graph.get('canvas').get('pixelRatio');
const widthRatio = graph.get('width') / size[0] * pixelRatio;
const heightRatio = graph.get('height') / size[1] * pixelRatio;
const canvas = this.get('canvas');
const containerDOM = canvas.get('containerDOM');
const viewport = createDOM('<div class="' + cfgs.viewportClassName + '" style="position:absolute;left:0;top:0;box-sizing:border-box;border: 2px solid #1980ff"></div>');
@ -90,6 +87,7 @@ class Minimap extends Base {
width, // 缓存viewport当前宽度
height; // 缓存viewport当前高度
containerDOM.addEventListener('mousedown', e => {
cfgs.refresh = false;
if (e.target !== viewport) {
return;
}
@ -131,15 +129,18 @@ class Minimap extends Base {
left: left + 'px',
top: top + 'px'
});
graph.translate(dx * widthRatio * pixelRatio, dy * heightRatio * pixelRatio);
const ratio = this.get('ratio');
graph.translate(dx / ratio, dy / ratio);
x = e.clientX;
y = e.clientY;
}, false);
containerDOM.addEventListener('mouseleave', () => {
dragging = false;
cfgs.refresh = true;
}, false);
containerDOM.addEventListener('mouseup', () => {
dragging = false;
cfgs.refresh = true;
}, false);
this.set('viewport', viewport);
containerDOM.appendChild(viewport);
@ -270,7 +271,7 @@ class Minimap extends Base {
if (height > size[1]) {
height = size[1];
}
this.set('ratio', ratio);
modifyCSS(viewport, {
left: left > 0 ? left + 'px' : 0,
top: top > 0 ? top + 'px' : 0,