More JS optimization in svgcanvas.js
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@459 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
13fc0f5d08
commit
06069ae984
|
@ -275,12 +275,14 @@ function SvgCanvas(c)
|
||||||
var bbox = cur_bbox || canvas.getBBox(this.selectedElement);
|
var bbox = cur_bbox || canvas.getBBox(this.selectedElement);
|
||||||
// console.log({'cur_bbox':cur_bbox, 'bbox':bbox });
|
// console.log({'cur_bbox':cur_bbox, 'bbox':bbox });
|
||||||
var l=bbox.x-offset, t=bbox.y-offset, w=bbox.width+(offset<<1), h=bbox.height+(offset<<1);
|
var l=bbox.x-offset, t=bbox.y-offset, w=bbox.width+(offset<<1), h=bbox.height+(offset<<1);
|
||||||
|
var sr_handle = svgroot.suspendRedraw(100);
|
||||||
assignAttributes(selectedBox, {
|
assignAttributes(selectedBox, {
|
||||||
'x': l,
|
'x': l,
|
||||||
'y': t,
|
'y': t,
|
||||||
'width': w,
|
'width': w,
|
||||||
'height': h
|
'height': h
|
||||||
});
|
});
|
||||||
|
|
||||||
var gripCoords = {
|
var gripCoords = {
|
||||||
nw: [l-3, t-3],
|
nw: [l-3, t-3],
|
||||||
ne: [l+w-3, t-3],
|
ne: [l+w-3, t-3],
|
||||||
|
@ -311,6 +313,7 @@ function SvgCanvas(c)
|
||||||
this.selectorGroup.setAttribute("transform", rotstr);
|
this.selectorGroup.setAttribute("transform", rotstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
svgroot.unsuspendRedraw(sr_handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
// now initialize the selector
|
// now initialize the selector
|
||||||
|
@ -420,11 +423,14 @@ function SvgCanvas(c)
|
||||||
return canvas.updateElementFromJson(data)
|
return canvas.updateElementFromJson(data)
|
||||||
};
|
};
|
||||||
|
|
||||||
var assignAttributes = function(node, attrs) {
|
var assignAttributes = function(node, attrs, suspendLength) {
|
||||||
var handle = svgroot.suspendRedraw(60);
|
if(!suspendLength) suspendLength = 0;
|
||||||
|
var handle = svgroot.suspendRedraw(suspendLength);
|
||||||
|
|
||||||
for (i in attrs) {
|
for (i in attrs) {
|
||||||
node.setAttributeNS(null, i, attrs[i]);
|
node.setAttributeNS(null, i, attrs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
svgroot.unsuspendRedraw(handle);
|
svgroot.unsuspendRedraw(handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -462,7 +468,7 @@ function SvgCanvas(c)
|
||||||
shape = svgdoc.createElementNS(svgns, data.element);
|
shape = svgdoc.createElementNS(svgns, data.element);
|
||||||
svgroot.appendChild(shape);
|
svgroot.appendChild(shape);
|
||||||
}
|
}
|
||||||
assignAttributes(shape, data.attr);
|
assignAttributes(shape, data.attr, 100);
|
||||||
cleanupElement(shape);
|
cleanupElement(shape);
|
||||||
return shape;
|
return shape;
|
||||||
};
|
};
|
||||||
|
@ -1268,7 +1274,7 @@ function SvgCanvas(c)
|
||||||
'width': 0,
|
'width': 0,
|
||||||
'height': 0,
|
'height': 0,
|
||||||
'display': 'inline'
|
'display': 'inline'
|
||||||
});
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1332,10 +1338,12 @@ function SvgCanvas(c)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "multiselect":
|
case "multiselect":
|
||||||
rubberBox.setAttribute("x", Math.min(start_x,x));
|
assignAttributes(rubberBox, {
|
||||||
rubberBox.setAttribute("y", Math.min(start_y,y));
|
'x': Math.min(start_x,x),
|
||||||
rubberBox.setAttribute("width", Math.abs(x-start_x));
|
'y': Math.min(start_y,y)),
|
||||||
rubberBox.setAttribute("height", Math.abs(y-start_y));
|
'width': Math.abs(x-start_x),
|
||||||
|
'height': Math.abs(y-start_y)
|
||||||
|
},100);
|
||||||
|
|
||||||
// this code will probably be faster than using getIntersectionList(), but
|
// this code will probably be faster than using getIntersectionList(), but
|
||||||
// not as accurate (only grabs an element if the mouse happens to pass over
|
// not as accurate (only grabs an element if the mouse happens to pass over
|
||||||
|
@ -1441,10 +1449,10 @@ function SvgCanvas(c)
|
||||||
selectorManager.requestSelector(selected).resize(selectedBBox);
|
selectorManager.requestSelector(selected).resize(selectedBBox);
|
||||||
break;
|
break;
|
||||||
case "text":
|
case "text":
|
||||||
var handle = svgroot.suspendRedraw(1000);
|
assignAttributes(shape,{
|
||||||
shape.setAttribute("x", x);
|
'x': x,
|
||||||
shape.setAttribute("y", y);
|
'y': y
|
||||||
svgroot.unsuspendRedraw(handle);
|
},1000);
|
||||||
break;
|
break;
|
||||||
case "line":
|
case "line":
|
||||||
var handle = svgroot.suspendRedraw(1000);
|
var handle = svgroot.suspendRedraw(1000);
|
||||||
|
@ -1454,20 +1462,20 @@ function SvgCanvas(c)
|
||||||
break;
|
break;
|
||||||
case "square":
|
case "square":
|
||||||
var size = Math.max( Math.abs(x - start_x), Math.abs(y - start_y) );
|
var size = Math.max( Math.abs(x - start_x), Math.abs(y - start_y) );
|
||||||
var handle = svgroot.suspendRedraw(1000);
|
assignAttributes(shape,{
|
||||||
shape.setAttributeNS(null, "width", size);
|
'width': size,
|
||||||
shape.setAttributeNS(null, "height", size);
|
'height': size,
|
||||||
shape.setAttributeNS(null, "x", start_x < x ? start_x : start_x - size);
|
'x': start_x < x ? start_x : start_x - size,
|
||||||
shape.setAttributeNS(null, "y", start_y < y ? start_y : start_y - size);
|
'y': start_y < y ? start_y : start_y - size
|
||||||
svgroot.unsuspendRedraw(handle);
|
},1000);
|
||||||
break;
|
break;
|
||||||
case "rect":
|
case "rect":
|
||||||
var handle = svgroot.suspendRedraw(1000);
|
assignAttributes(shape,{
|
||||||
shape.setAttributeNS(null, "x", Math.min(start_x,x));
|
'width': Math.abs(x-start_x),
|
||||||
shape.setAttributeNS(null, "y", Math.min(start_y,y));
|
'height': Math.abs(y-start_y),
|
||||||
shape.setAttributeNS(null, "width", Math.abs(x-start_x));
|
'x': Math.min(start_x,x),
|
||||||
shape.setAttributeNS(null, "height", Math.abs(y-start_y));
|
'y': Math.min(start_y,y)
|
||||||
svgroot.unsuspendRedraw(handle);
|
},1000);
|
||||||
break;
|
break;
|
||||||
case "circle":
|
case "circle":
|
||||||
var cx = shape.getAttributeNS(null, "cx");
|
var cx = shape.getAttributeNS(null, "cx");
|
||||||
|
|
Loading…
Reference in New Issue