var Options = function() {
var args = arguments;
for(var i=0, l=args.length, ans={}; i<l; i++) {
var opt = Options[args[i]];
if(opt.$extend) {
$.extend(ans, opt);
} else {
ans[args[i]] = opt;
}
}
return ans;
};
同时,各个配置项作为Options的属性,这样就可以根据属性名找到相应的配置项的对象。
Options.Node = {
$extend: false,
overridable: false,
type: 'circle',
color: '#ccb',
alpha: 1,
dim: 3,
height: 20,
width: 90,
autoHeight: false,
autoWidth: false,
lineWidth: 1,
transform: true,
align: "center",
angularWidth:1,
span:1,
//Raw canvas styles to be
//applied to the context instance
//before plotting a node
CanvasStyles: {}
};
Options.Edge = {
$extend: false,
........
}
Options.Canvas = {
$extend: false,
........
}
......
在spaceTree.js中的使用示例:
var config= {
levelsToShow: 2,
levelDistance: 30,
constrained: true,
Node: {
type: 'rectangle'
},
duration: 700,
offsetX: 0,
offsetY: 0
};
this.controller = this.config = $.merge(
Options("Canvas", "Fx", "Tree", "Node", "Edge", "Controller",
"Tips", "NodeStyles", "Events", "Navigation", "Label"), config, controller);