Pregunta

Estoy utilizando el Javascript InfoVis SpaceTree. Tengo un árbol que tiene el siguiente aspecto:

http://zygonia.net/so/ex2.html

Sin embargo deseo seleccionar el nodo 'ahora' para que se resalte la parte posterior ruta de acceso al nodo raíz, sino evitar que este nodo de centrado. es decir:.

http://zygonia.net/so/ex3.html

setPos() pero esto no funciona.

¿Alguna idea?

Añadido casquillos de la pantalla en caso de que se vaya enlaces:

introducir descripción de la imagen aquí

introducir descripción de la imagen aquí

¿Fue útil?

Solución

Ah, que en mal estado biblioteca Gráfico de nuevo: D

Vamos a echar otro vistazo a la función de selección, específicamente la devolución de llamada 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();
}

Así que ya no desea ningún cambio de posición en absoluto, podemos refactorizar (también conocida como la supresión de algunas líneas) que:

onComplete: function(){             
    that.plot();
    complete.onAfterCompute(that.clickedNode);
    complete.onComplete();
}

ma Mira! Me salvó un montón de bytes !!! Eso es todo lo que se necesita resto no hace nada vital para la gráfica.

Por supuesto, simplemente deshacerse de la funcionalidad puede morder a algunos días, por lo que debemos añadir un parámetro center a 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();
}

Otros consejos

Definición de las posiciones OffsetX y OffsetY como esta:

var st = new $jit.ST({
    'injectInto': 'infovis',
    //set duration for the animation
    duration: 800,
    //set animation transition type
    transition: $jit.Trans.Quart.easeInOut,
    //set distance between node and its children
    levelDistance: 50,
    //set max levels to show. Useful when used with
    //the request method for requesting trees of specific depth
    levelsToShow: 4,
    orientation: 'top',
    align: 'center',
    //set node and edge styles
    //set overridable=true for styling individual
    //nodes or edges 
    offsetX: 0, offsetY: 110,
    Node: {
        height: 30,
        width: 31,
        //use a custom
        //node rendering function
        type: 'nodeline',
        color: '#f76b14',
        lineWidth: 1,
        align: "center",
        overridable: true
    },

El infovis div, es decir, el div que contiene el SpaceTree, no se mostrará todo el gráfico a veces. Añadiendo el siguiente código en el evento onComplete haría el truco.

Esto establecería la altura de la div para acomodar todo el gráfico. Estoy utilizando la orientación como 'superior'.

onComplete: function () {
        var LastnodeTop = 0;
        $("div.node").each(function () {
            var pos = $(this).position();
            if (pos.top > LastnodeTop)
                LastnodeTop = pos.top;
        });
        var LastnodeTopStr = LastnodeTop.toString();
        LastnodeTopStr = LastnodeTopStr.substring(0, 4);
        var LastnodeTopInt = parseInt(LastnodeTopStr) + 100;            
        $("#infovis").attr("style", "height:" + LastnodeTopInt + "px");
    }

Gracias.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top