|
import * as util from '../../util'; |
|
import * as is from '../../is'; |
|
import { copyPosition } from '../../math'; |
|
|
|
let defaults = { |
|
positions: undefined, |
|
zoom: undefined, |
|
pan: undefined, |
|
fit: true, |
|
padding: 30, |
|
spacingFactor: undefined, |
|
animate: false, |
|
animationDuration: 500, |
|
animationEasing: undefined, |
|
animateFilter: function ( node, i ){ return true; }, |
|
ready: undefined, |
|
stop: undefined, |
|
transform: function (node, position ){ return position; } |
|
}; |
|
|
|
function PresetLayout( options ){ |
|
this.options = util.extend( {}, defaults, options ); |
|
} |
|
|
|
PresetLayout.prototype.run = function(){ |
|
let options = this.options; |
|
let eles = options.eles; |
|
|
|
let nodes = eles.nodes(); |
|
let posIsFn = is.fn( options.positions ); |
|
|
|
function getPosition( node ){ |
|
if( options.positions == null ){ |
|
return copyPosition( node.position() ); |
|
} |
|
|
|
if( posIsFn ){ |
|
return options.positions( node ); |
|
} |
|
|
|
let pos = options.positions[ node._private.data.id ]; |
|
|
|
if( pos == null ){ |
|
return null; |
|
} |
|
|
|
return pos; |
|
} |
|
|
|
nodes.layoutPositions( this, options, function( node, i ){ |
|
let position = getPosition( node ); |
|
|
|
if( node.locked() || position == null ){ |
|
return false; |
|
} |
|
|
|
return position; |
|
} ); |
|
|
|
return this; |
|
}; |
|
|
|
export default PresetLayout; |
|
|