/**
  * @param Digraph $graph
  * @param int $vertex
  */
 private function depthSearch(Digraph $graph, int $vertex)
 {
     $this->marked[$vertex] = true;
     foreach ($graph->adjacent($vertex) as $item) {
         if ($this->marked($item)) {
             continue;
         }
         $this->depthSearch($graph, $item);
     }
 }
Esempio n. 2
0
 /**
  * Build the reversed digraph of this digraph
  *
  * @return Digraph
  */
 public function getReversed()
 {
     $newGraph = new Digraph();
     foreach ($this->graph->getVertexSet() as $vx) {
         // for isolated vertex :
         $newGraph->addVertex($vx);
         // we reverse each edge :
         foreach ($this->graph->getSuccessor($vx) as $vy) {
             $newGraph->addEdge($vy, $vx);
         }
     }
     return $newGraph;
 }
function relgraph_generate_dep_graph($p_bug_id, $p_bug = null, $p_horizontal = false)
{
    # List of visited issues and their data.
    $v_bug_list = array();
    # Firstly, we visit all ascendant issues and all descendant issues
    # and collect all the necessary data in the $v_bug_list variable.
    # We do not visit other descendants of our parents, neither other
    # ascendants of our children, to avoid displaying too much unrelated
    # issues. We still collect the information about those relationships,
    # so, if these issues happen to be visited also, relationship links
    # will be preserved.
    # The first issue in the list is the one we are parting from.
    if (null === $p_bug) {
        $p_bug = bug_get($p_bug_id, true);
    }
    $v_bug_list[$p_bug_id] = $p_bug;
    $v_bug_list[$p_bug_id]->is_descendant = true;
    $v_bug_list[$p_bug_id]->parents = array();
    $v_bug_list[$p_bug_id]->children = array();
    # Now we visit all ascendants of the root issue.
    $t_relationships = relationship_get_all_dest($p_bug_id);
    foreach ($t_relationships as $t_relationship) {
        if ($t_relationship->type != BUG_DEPENDANT) {
            continue;
        }
        $v_bug_list[$p_bug_id]->parents[] = $t_relationship->src_bug_id;
        relgraph_add_parent($v_bug_list, $t_relationship->src_bug_id);
    }
    $t_relationships = relationship_get_all_src($p_bug_id);
    foreach ($t_relationships as $t_relationship) {
        if ($t_relationship->type != BUG_DEPENDANT) {
            continue;
        }
        $v_bug_list[$p_bug_id]->children[] = $t_relationship->dest_bug_id;
        relgraph_add_child($v_bug_list, $t_relationship->dest_bug_id);
    }
    # We have already collected all the information we need to generate
    # the graph. Now it is the matter to create a Digraph object and
    # store the information there, along with graph formatting attributes.
    $t_id_string = relgraph_bug_format_id($p_bug_id);
    $t_graph_fontname = config_get('relationship_graph_fontname');
    $t_graph_fontsize = config_get('relationship_graph_fontsize');
    $t_graph_fontpath = get_font_path();
    $t_view_on_click = config_get('relationship_graph_view_on_click');
    $t_dot_tool = config_get('dot_tool');
    $t_graph_attributes = array();
    if (!empty($t_graph_fontpath)) {
        $t_graph_attributes['fontpath'] = $t_graph_fontpath;
    }
    if ($p_horizontal) {
        $t_graph_attributes['rankdir'] = 'LR';
        $t_graph_orientation = 'horizontal';
    } else {
        $t_graph_orientation = 'vertical';
    }
    $t_graph = new Digraph($t_id_string, $t_graph_attributes, $t_dot_tool);
    $t_graph->set_default_node_attr(array('fontname' => $t_graph_fontname, 'fontsize' => $t_graph_fontsize, 'shape' => 'record', 'style' => 'filled', 'height' => '0.2', 'width' => '0.4'));
    $t_graph->set_default_edge_attr(array('style' => 'solid', 'color' => '#C00000', 'dir' => 'back'));
    # Add all issue nodes and edges to the graph.
    foreach ($v_bug_list as $t_related_bug_id => $t_related_bug) {
        $t_id_string = relgraph_bug_format_id($t_related_bug_id);
        if ($t_view_on_click) {
            $t_url = string_get_bug_view_url($t_related_bug_id);
        } else {
            $t_url = "bug_relationship_graph.php?bug_id={$t_related_bug_id}&graph=dependency&orientation={$t_graph_orientation}";
        }
        relgraph_add_bug_to_graph($t_graph, $t_id_string, $t_related_bug, $t_url, $t_related_bug_id == $p_bug_id);
        # Now add all relationship edges to the graph.
        foreach ($v_bug_list[$t_related_bug_id]->parents as $t_parent_id) {
            # Do not create edges for unvisited bugs.
            if (!isset($v_bug_list[$t_parent_id])) {
                continue;
            }
            $t_parent_node = relgraph_bug_format_id($t_parent_id);
            $t_graph->add_edge($t_parent_node, $t_id_string);
        }
    }
    return $t_graph;
}