gpt4 book ai didi

php - 使用 Image_Graphviz 包设置默认节点属性

转载 作者:可可西里 更新时间:2023-10-31 23:50:15 26 4
gpt4 key购买 nike

我可以使用 GraphViz 使用任一点语言生成下图直接或使用 PEAR 包 Image_GraphViz使用 PHP。

graphviz png image from below code

//DOT language
digraph test{
URL="http://example.com/fish/";
bgcolor="#BBCAF2";

//defaults for all nodes
node[style=filled,
fillcolor=white,
color="#8A94B4",
fixedsize=true,
fontname="sans-serif",
fontsize=8,
URL="?fish_id=\N",
margin="0.02,0.02"];

//defaults for all edges
edge[arrowsize=0.6,
sametail=true,
fontsize=8,
fontname="sans-serif"];

//a few edges
57->23[color="blue"]; 42->23[color="red"];
25->26[color="blue", label="10M"]; 25->26[color="red", label="10F"];
//etc.

//a few nodes
29[label="100128 AB"];
38[label="100730 AB"];
39[label="110208"];
//etc.
}

点文件可以为所有四种元素类型(图、簇、节点、边)设置属性默认值。似乎 Image_GraphViz 只能为图级属性设置默认值。

<?php
$gatts=array( //defaults for graph level attributes
'URL'=>"http://example.com/fish/",
'bgcolor'=>"#ff0000",
'font'=>"sans-serif",
);

$gv=new Image_GraphViz(true,$gatts,'test',false,true);

$q_ne="SELECT parentname, parent_id, childname, child_id, parenttype, parentcount
FROM fish_crosses";
$r_ne=$dbii->query($q_ne);
while($ne=$r_ne->fetch_assoc()){
$nodeatts=array('label' => $ne['parentname'],
'style'=>"filled",
'fillcolor'=>'#ffffff',
'fixedsize'=>true,
'fontname'=>"sans-serif",
'fontsize'=>8);
if(!$ne['child_id']) {
$gv->addNode($ne['parent_id'], $nodeatts);
continue;
}
if($ne['parenttype']=='dam'){
$ecolor= '#ff0000';
$elabel= $ne['parentcount'].'F';
} else {
$ecolor= '#0000ff';
$elabel=$ne['parentcount'].'F';
}
$edgeatts=array('color'=>$ecolor, 'fontname'=>'sans-serif','fontsize'=>8);
if($ne['parentcount']) $edgeatts['label']=$elabel;

$gv->addEdge(array($ne['parent_id']=>$ne['child_id']), $edgeatts);
$gv->addNode($ne['parent_id'], $nodeatts);
$gv->addNode($ne['child_id'], $nodeatts);
}

echo $gv->image('png');
?>

有谁知道将节点和边的默认属性值添加到 Image_GraphViz 对象的语法?

最佳答案

这只是一个想法,无法对其进行测试:您是否尝试过简单地添加一个名为 node(或 edge)的节点并在该节点上定义属性?

类似$gv->addNode('node', array('style'=>'filled', 'fixedsize'=>true))

关于php - 使用 Image_Graphviz 包设置默认节点属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430771/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com