fix pixelsToCoords and coordsToPixels function calls

This commit is contained in:
Devin Howard 2016-10-26 14:06:54 +08:00
parent f5712e6979
commit 0f76d83a6e

View file

@ -772,17 +772,17 @@ const JIT = {
// if it's a left click, or a touch, move the node // if it's a left click, or a touch, move the node
if (e.touches || (e.button === 0 && !e.altKey && !e.ctrlKey && (e.buttons === 0 || e.buttons === 1 || e.buttons === undefined))) { if (e.touches || (e.button === 0 && !e.altKey && !e.ctrlKey && (e.buttons === 0 || e.buttons === 1 || e.buttons === undefined))) {
var width = Metamaps.Visualize.mGraph.canvas.getSize().width, var width = Visualize.mGraph.canvas.getSize().width,
height = Metamaps.Visualize.mGraph.canvas.getSize().height, height = Visualize.mGraph.canvas.getSize().height,
xPix = Metamaps.Util.coordsToPixels(pos).x, xPix = Util.coordsToPixels(Visualize.mGraph, pos).x,
yPix = Metamaps.Util.coordsToPixels(pos).y; yPix = Util.coordsToPixels(Visualize.mGraph, pos).y;
if(self.dragFlag === 0){ if(self.dragFlag === 0){
self.mouseDownPix = Metamaps.Util.coordsToPixels(eventInfo.getPos()); self.mouseDownPix = Util.coordsToPixels(eventInfo.getPos());
self.dragFlag = 1; self.dragFlag = 1;
} }
if(Metamaps.Util.getDistance(Metamaps.Util.coordsToPixels(pos),self.mouseDownPix) > 2 && !self.dragTolerance){ if(Util.getDistance(Util.coordsToPixels(pos),self.mouseDownPix) > 2 && !self.dragTolerance){
self.dragTolerance = 1; self.dragTolerance = 1;
} }
@ -791,14 +791,14 @@ const JIT = {
clearInterval(self.dragRightEdge); clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge); clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge); clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:EDGE_THICKNESS,y:yPix}).x - SHIFT,y:pos.y}; self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: EDGE_THICKNESS, y: yPix }).x - SHIFT, y: pos.y }
Metamaps.Visualize.mGraph.canvas.translate(SHIFT,0); Visualize.mGraph.canvas.translate(SHIFT, 0);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
self.dragLeftEdge = setInterval( function(){ self.dragLeftEdge = setInterval( function(){
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:EDGE_THICKNESS,y:yPix}).x - SHIFT,y:pos.y}; self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: EDGE_THICKNESS, y: yPix }).x - SHIFT, y: pos.y }
Metamaps.Visualize.mGraph.canvas.translate(SHIFT,0); Visualize.mGraph.canvas.translate(SHIFT, 0);
self.updateTopicPositions(node,self.virtualPointer); self.updateTopicPositions(node,self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
} , PERIOD); } , PERIOD);
@ -809,14 +809,14 @@ const JIT = {
clearInterval(self.dragRightEdge); clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge); clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge); clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:width - EDGE_THICKNESS,y:yPix}).x + SHIFT,y:pos.y}; self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y }
Metamaps.Visualize.mGraph.canvas.translate(-SHIFT,0); Visualize.mGraph.canvas.translate(-SHIFT, 0);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
self.dragRightEdge = setInterval( function(){ self.dragRightEdge = setInterval( function(){
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:width - EDGE_THICKNESS,y:yPix}).x + SHIFT,y:pos.y}; self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y }
Metamaps.Visualize.mGraph.canvas.translate(-SHIFT,0); Visualize.mGraph.canvas.translate(-SHIFT, 0);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
} , PERIOD); } , PERIOD);
@ -826,14 +826,14 @@ const JIT = {
clearInterval(self.dragRightEdge); clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge); clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge); clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:EDGE_THICKNESS}).y - SHIFT}; self.virtualPointer = { x:pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT }
Metamaps.Visualize.mGraph.canvas.translate(0,SHIFT); Visualize.mGraph.canvas.translate(0, SHIFT);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
self.dragTopEdge = setInterval( function(){ self.dragTopEdge = setInterval( function(){
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:EDGE_THICKNESS}).y - SHIFT}; self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT }
Metamaps.Visualize.mGraph.canvas.translate(0,SHIFT); Visualize.mGraph.canvas.translate(0, SHIFT);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
} , PERIOD); } , PERIOD);
@ -843,20 +843,20 @@ const JIT = {
clearInterval(self.dragRightEdge); clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge); clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge); clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:height - EDGE_THICKNESS}).y + SHIFT}; self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT }
Metamaps.Visualize.mGraph.canvas.translate(0,-SHIFT); Visualize.mGraph.canvas.translate(0, -SHIFT);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
self.dragBottomEdge = setInterval( function(){ self.dragBottomEdge = setInterval(function () {
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:height - EDGE_THICKNESS}).y + SHIFT}; self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT }
Metamaps.Visualize.mGraph.canvas.translate(0,-SHIFT); Visualize.mGraph.canvas.translate(0, -SHIFT);
self.updateTopicPositions(node, self.virtualPointer); self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot(); Visualize.mGraph.plot();
} , PERIOD); }, PERIOD)
} }
if(xPix >= EDGE_THICKNESS && width - xPix >= EDGE_THICKNESS && yPix >= EDGE_THICKNESS && height - yPix >= EDGE_THICKNESS){ if(xPix >= EDGE_THICKNESS && width - xPix >= EDGE_THICKNESS && yPix >= EDGE_THICKNESS && height - yPix >= EDGE_THICKNESS) {
clearInterval(self.dragLeftEdge); clearInterval(self.dragLeftEdge);
clearInterval(self.dragRightEdge); clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge); clearInterval(self.dragTopEdge);