fix getPastelColor function (I think) (#850)

* fix getPastelColor function (I think)

* fix pixelsToCoords and coordsToPixels function calls

* update signature of coord/pixel functions in Util.spec.js
This commit is contained in:
Devin Howard 2016-10-26 14:26:48 +08:00 committed by GitHub
parent 8a95262f2c
commit 98725b3ee4
3 changed files with 33 additions and 33 deletions

View file

@ -772,17 +772,17 @@ const JIT = {
// 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))) {
var width = Metamaps.Visualize.mGraph.canvas.getSize().width,
height = Metamaps.Visualize.mGraph.canvas.getSize().height,
xPix = Metamaps.Util.coordsToPixels(pos).x,
yPix = Metamaps.Util.coordsToPixels(pos).y;
var width = Visualize.mGraph.canvas.getSize().width,
height = Visualize.mGraph.canvas.getSize().height,
xPix = Util.coordsToPixels(Visualize.mGraph, pos).x,
yPix = Util.coordsToPixels(Visualize.mGraph, pos).y;
if(self.dragFlag === 0){
self.mouseDownPix = Metamaps.Util.coordsToPixels(eventInfo.getPos());
self.mouseDownPix = Util.coordsToPixels(eventInfo.getPos());
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;
}
@ -791,14 +791,14 @@ const JIT = {
clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:EDGE_THICKNESS,y:yPix}).x - SHIFT,y:pos.y};
Metamaps.Visualize.mGraph.canvas.translate(SHIFT,0);
self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: EDGE_THICKNESS, y: yPix }).x - SHIFT, y: pos.y }
Visualize.mGraph.canvas.translate(SHIFT, 0);
self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot();
self.dragLeftEdge = setInterval( function(){
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:EDGE_THICKNESS,y:yPix}).x - SHIFT,y:pos.y};
Metamaps.Visualize.mGraph.canvas.translate(SHIFT,0);
self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: EDGE_THICKNESS, y: yPix }).x - SHIFT, y: pos.y }
Visualize.mGraph.canvas.translate(SHIFT, 0);
self.updateTopicPositions(node,self.virtualPointer);
Visualize.mGraph.plot();
} , PERIOD);
@ -809,14 +809,14 @@ const JIT = {
clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:width - EDGE_THICKNESS,y:yPix}).x + SHIFT,y:pos.y};
Metamaps.Visualize.mGraph.canvas.translate(-SHIFT,0);
self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y }
Visualize.mGraph.canvas.translate(-SHIFT, 0);
self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot();
self.dragRightEdge = setInterval( function(){
self.virtualPointer = {x:Metamaps.Util.pixelsToCoords({x:width - EDGE_THICKNESS,y:yPix}).x + SHIFT,y:pos.y};
Metamaps.Visualize.mGraph.canvas.translate(-SHIFT,0);
self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y }
Visualize.mGraph.canvas.translate(-SHIFT, 0);
self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot();
} , PERIOD);
@ -826,14 +826,14 @@ const JIT = {
clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:EDGE_THICKNESS}).y - SHIFT};
Metamaps.Visualize.mGraph.canvas.translate(0,SHIFT);
self.virtualPointer = { x:pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT }
Visualize.mGraph.canvas.translate(0, SHIFT);
self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot();
self.dragTopEdge = setInterval( function(){
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:EDGE_THICKNESS}).y - SHIFT};
Metamaps.Visualize.mGraph.canvas.translate(0,SHIFT);
self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT }
Visualize.mGraph.canvas.translate(0, SHIFT);
self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot();
} , PERIOD);
@ -843,20 +843,20 @@ const JIT = {
clearInterval(self.dragRightEdge);
clearInterval(self.dragTopEdge);
clearInterval(self.dragBottomEdge);
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:height - EDGE_THICKNESS}).y + SHIFT};
Metamaps.Visualize.mGraph.canvas.translate(0,-SHIFT);
self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT }
Visualize.mGraph.canvas.translate(0, -SHIFT);
self.updateTopicPositions(node, self.virtualPointer);
Visualize.mGraph.plot();
self.dragBottomEdge = setInterval( function(){
self.virtualPointer = {x:pos.x,y:Metamaps.Util.pixelsToCoords({x:xPix,y:height - EDGE_THICKNESS}).y + SHIFT};
Metamaps.Visualize.mGraph.canvas.translate(0,-SHIFT);
self.dragBottomEdge = setInterval(function () {
self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT }
Visualize.mGraph.canvas.translate(0, -SHIFT);
self.updateTopicPositions(node, self.virtualPointer);
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.dragRightEdge);
clearInterval(self.dragTopEdge);

View file

@ -88,10 +88,10 @@ const Util = {
}
return coords
},
getPastelColor: function ({ rseed, gseed, bseed }) {
if (rseed === undefined) rseed = Math.random()
if (gseed === undefined) gseed = Math.random()
if (bseed === undefined) bseed = Math.random()
getPastelColor: function (opts = {}) {
const rseed = opts.rseed === undefined ? Math.random() : opts.rseed
const gseed = opts.gseed === undefined ? Math.random() : opts.gseed
const bseed = opts.bseed === undefined ? Math.random() : opts.bseed
var r = (Math.round(rseed * 127) + 127).toString(16)
var g = (Math.round(gseed * 127) + 127).toString(16)
var b = (Math.round(bseed * 127) + 127).toString(16)

View file

@ -44,15 +44,15 @@ describe('Metamaps.Util.js', function () {
})
describe('coordsToPixels', function () {
it('returns 0,0 for null canvas', function () {
expect(Util.coordsToPixels(null).x).to.equal(0)
expect(Util.coordsToPixels(null).y).to.equal(0)
expect(Util.coordsToPixels(null, {}).x).to.equal(0)
expect(Util.coordsToPixels(null, {}).y).to.equal(0)
})
it.skip('TODO need initialized mGraph to test further')
})
describe('pixelsToCoords', function () {
it('returns 0,0 for null canvas', function () {
expect(Util.pixelsToCoords(null).x).to.equal(0)
expect(Util.pixelsToCoords(null).y).to.equal(0)
expect(Util.pixelsToCoords(null, {}).x).to.equal(0)
expect(Util.pixelsToCoords(null, {}).y).to.equal(0)
})
it.skip('TODO need initialized mGraph to test further')
})