added chrome specific logic to improve the drag and drop performance until the chrome bug is fixed

This commit is contained in:
Eric Rowell 2012-04-14 10:13:07 -07:00
parent 1c8669eb7a
commit 2108736df7
4 changed files with 38 additions and 28 deletions

31
dist/kinetic-core.js vendored
View File

@ -46,6 +46,7 @@ Kinetic.GlobalObject = {
animIdCounter: 0,
dragTimeInterval: 0,
maxDragTimeInterval: 20,
isChrome: navigator.userAgent.toLowerCase().indexOf('chrome') > -1,
frame: {
time: 0,
timeDiff: 0,
@ -1779,20 +1780,24 @@ Kinetic.Stage.prototype = {
};
/*
* handle dynamice drag time interval. As the distance between
* the mouse and cursor increases, we need to increase the drag
* time interval to reduce the number of layer draws so that
* the node position can catch back up to the cursor. When the difference
* is zero, the time interval is zero. When the difference approahces
* infinity, the time interval approaches the max drag time interval
* chrome currently has a bug that slows down drag and drop.
* For google chrome instances, dynamically set the dragTimeInterval
* to improve drag and drop performance while not effecting other browsers
*/
/*
var dragDiffX = Math.abs(newNodePos.x - node.attrs.x);
var dragDiffY = Math.abs(newNodePos.y - node.attrs.y);
var dragDiff = Math.sqrt(Math.pow(dragDiffX, 2) + Math.pow(dragDiffY, 2));
go.dragTimeInterval = go.maxDragTimeInterval * (dragDiff - 1) / (dragDiff + 1);
console.log(dragDiff + ',' + go.dragTimeInterval);
*/
if(go.isChrome) {
/*
* handle dynamice drag time interval. As the distance between
* the mouse and cursor increases, we need to increase the drag
* time interval to reduce the number of layer draws so that
* the node position can catch back up to the cursor. When the difference
* is zero, the time interval is zero. When the difference approahces
* infinity, the time interval approaches the max drag time interval
*/
var dragDiffX = Math.abs(newNodePos.x - node.attrs.x);
var dragDiffY = Math.abs(newNodePos.y - node.attrs.y);
var dragDiff = Math.sqrt(Math.pow(dragDiffX, 2) + Math.pow(dragDiffY, 2));
go.dragTimeInterval = go.maxDragTimeInterval * (dragDiff - 1) / (dragDiff + 1);
}
// bounds overrides
if(db.left !== undefined && newNodePos.x < db.left) {

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,7 @@ Kinetic.GlobalObject = {
animIdCounter: 0,
dragTimeInterval: 0,
maxDragTimeInterval: 20,
isChrome: navigator.userAgent.toLowerCase().indexOf('chrome') > -1,
frame: {
time: 0,
timeDiff: 0,

View File

@ -725,20 +725,24 @@ Kinetic.Stage.prototype = {
};
/*
* handle dynamice drag time interval. As the distance between
* the mouse and cursor increases, we need to increase the drag
* time interval to reduce the number of layer draws so that
* the node position can catch back up to the cursor. When the difference
* is zero, the time interval is zero. When the difference approahces
* infinity, the time interval approaches the max drag time interval
* chrome currently has a bug that slows down drag and drop.
* For google chrome instances, dynamically set the dragTimeInterval
* to improve drag and drop performance while not effecting other browsers
*/
/*
var dragDiffX = Math.abs(newNodePos.x - node.attrs.x);
var dragDiffY = Math.abs(newNodePos.y - node.attrs.y);
var dragDiff = Math.sqrt(Math.pow(dragDiffX, 2) + Math.pow(dragDiffY, 2));
go.dragTimeInterval = go.maxDragTimeInterval * (dragDiff - 1) / (dragDiff + 1);
console.log(dragDiff + ',' + go.dragTimeInterval);
*/
if(go.isChrome) {
/*
* handle dynamice drag time interval. As the distance between
* the mouse and cursor increases, we need to increase the drag
* time interval to reduce the number of layer draws so that
* the node position can catch back up to the cursor. When the difference
* is zero, the time interval is zero. When the difference approahces
* infinity, the time interval approaches the max drag time interval
*/
var dragDiffX = Math.abs(newNodePos.x - node.attrs.x);
var dragDiffY = Math.abs(newNodePos.y - node.attrs.y);
var dragDiff = Math.sqrt(Math.pow(dragDiffX, 2) + Math.pow(dragDiffY, 2));
go.dragTimeInterval = go.maxDragTimeInterval * (dragDiff - 1) / (dragDiff + 1);
}
// bounds overrides
if(db.left !== undefined && newNodePos.x < db.left) {