Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:49:01+00:00 2026-05-23T09:49:01+00:00

I can produce the below graph with either dot language using GraphViz directly or

  • 0

I can produce the below graph with either dot language using GraphViz directly or with the PEAR package Image_GraphViz using 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.
}

Dot files can set attribute defaults for all four element types (graph, cluster, node, edge). It appears that Image_GraphViz can only set defaults for graph level attributes.

<?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');
?>

Does anyone know the syntax for adding default attribute values for nodes and edges to a Image_GraphViz object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:49:02+00:00Added an answer on May 23, 2026 at 9:49 am

    It appears that the current Image_GraphViz package cannot handle default node/edge/cluster attributes. I’ve extended the class by changing these functions: _escape, _escapeArray, and parse. Here are my changes:

    function _escape($input, $html = false) {
            switch (strtolower($input)) {
            //removed case 'node' and case 'edge' so they won't be quoted
            case 'graph':
            case 'digraph':
            case 'subgraph':
            case 'strict':
                return '"'.$input.'"';
            } //...
    
    
    function _escapeArray($input) {
    //...
            default:
                if(is_array($v)){
                    $v=$this->_escapeArray($v); //added recursion to allow default node/edge/cluster attribute sets
                } else {
                    $v = $this->_escape($v);
                }
                $k = $this->_escape($k);
            }
    //...
    
    function parse() {
    //...
        foreach ($attr as $key => $value) {
            if(is_array($value)){
                $a=implode(',', 
                array_map(function($v,$k){ return $k . '='.$v;}, 
                    array_values($value),
                    array_keys($value)));
            //default format for node/edge/cluster: thing[att1="blah", att2="foo"];
                $parsedGraph .= $indent.$key.'['.$a."];\n";
            } else {
                $parsedGraph .= $indent.$key.'='.$value.";\n";
            }
        }
    //...
    

    I hope this is useful to someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: jsfiddle.net/bVgwc/2/ I can NOT produce a jquery code to make Darc checked (below)
Does anyone know if it is possible to write a query that can produce
Can anyone beat the performance of my integer to std::string code, linked below? There
Rationale : In my day-to-day C++ code development, I frequently need to answer basic
Edit: I've rewritten the question in hopes that the goal is a little clearer.
I'm trying to create a macro that produces in-cell graphing as seen over at
Our company plans to auto-generate our projects from the domain area up-to the presentation
Hello I am working in django how to use a search form from Django
Background I am designing a system which enables the development of dynamic authentication schemes
I am trying to use webkit's support for CSS3 transform: matrix3d(<matrix>) to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.