Ах, это опять испортило библиотеку графов: D
Давайте еще раз посмотрим на эту функцию выбора, а именно на onComplete
обратный вызов:
onComplete: function(){ // what a mess!
group.hide(group.prepare(getNodesToHide.call(that)), complete); // hide the nodes???
geom.setRightLevelToShow(node, canvas); // guess what this already moves stuff around!
that.compute("current"); // recomputes the graphs position
that.graph.eachNode(function(n) { // sets up the moved node positions
var pos = n.pos.getc(true);
n.startPos.setc(pos.x, pos.y);
n.endPos.setc(pos.x, pos.y);
n.visited = false;
});
// hey look! We don't use a global translation offset! So we need to translate the HTML stuff extra
var offset = { x: complete.offsetX, y: complete.offsetY };
that.geom.translate(node.endPos.add(offset).$scale(-1), ["start", "current", "end"]);
// show the nodes again?
group.show(getNodesToShow.call(that));
// the first useful call in here, redraw the updated graph!
that.plot();
complete.onAfterCompute(that.clickedNode); // callback better leave them here
complete.onComplete();
}
Таким образом, поскольку вы вообще не хотите изменять положение, мы можем изменить его (также известный как удаление некоторых строк):
onComplete: function(){
that.plot();
complete.onAfterCompute(that.clickedNode);
complete.onComplete();
}
Смотри, мам! Я сэкономил тонны байтов !!! Это все, что нужно, отдых не делает ничего важного для графика.
Конечно, когда-нибудь простое избавление от функциональности может отомстить вам, поэтому мы должны добавить center
параметр к select
:
select: function(id, center, onComplete) {
....
onComplete: function(){
if (center) {
group.hide(group.prepare(getNodesToHide.call(that)), complete);
geom.setRightLevelToShow(node, canvas);
that.compute("current");
that.graph.eachNode(function(n) {
var pos = n.pos.getc(true);
n.startPos.setc(pos.x, pos.y);
n.endPos.setc(pos.x, pos.y);
n.visited = false;
});
var offset = { x: complete.offsetX, y: complete.offsetY };
that.geom.translate(node.endPos.add(offset).$scale(-1), ["start", "current", "end"]);
}
group.show(getNodesToShow.call(that));
that.plot();
complete.onAfterCompute(that.clickedNode);
complete.onComplete();
}