WSHã»JScriptãã Graphviz ãå©ç¨ããããã®ã¯ã©ã¹ãï¼é¢ä¿ã°ã©ããæç»ãã¦ãè¤éãªæ§é ã®ãã¼ã¿ãå¯è¦åããæ¹æ³ï¼
JScriptããGraphvizãå©ç¨ãã¦ãé¢ä¿ã°ã©ããææ©ãæç»ããã
ä¸è¨ã®ãããªä½¿ãæ¹ãã§ããã
var dr = new DotRecorder( "my_graph" ); // ãã¼ããç»é² dr.node( "1a", "å£" ); dr.node( "2a", "æ¥" ); dr.node( "2b", "å" ); dr.node( "3a", "ç®" ); dr.node( "3b", "å" ); dr.node( "4a", "ç°" ); // é¢ä¿ãç»é² dr.rel( "1a", "2a" ); dr.rel( "2a", "3a" ); dr.rel( "3a", "4a" ); dr.rel( "1a", "2b" ); dr.rel( "2b", "3b" ); dr.rel( "3b", "4a" ); // ã°ã©ãä½æ dr.dot( "hoge.dot" ); dr.png( "hoge.png" );
ããã¨ãhoge.pngã¨ãããã¡ã¤ã«åã§ãå³ä¸ã®ãããªã°ã©ãç»åãåºåã»ä¿åãããã
ãã®DotRecorderã¨ãããªãã¸ã§ã¯ãã®ã½ã¼ã¹ã³ã¼ãã¯ä¸è¨ã®éãã
â»ãã¡ããããã¦ã³ãã¼ãã§ãã¾ãã
http://www.name-of-this-site.org/codi...
/* Graphvizã®dotãä½æããã¯ã©ã¹ 説æï¼ ã»ãã¼ãã®ã©ãã«ã«æ¥æ¬èªã使ãã¾ãã 注æï¼ ã»äºåã«Graphvizãã¤ã³ã¹ãã¼ã«ããbinã«PATHãéãã¦ãããã¨ã Graphviz http://www.graphviz.org/ ã»ãã®jsãã¡ã¤ã«ã¯ãããã«ã¯ãªãã¯ãbatå¼ã³åºãã«ãã£ã¦å®è¡ãããã¨ã ï¼ãã以å¤ã®èµ·åæ¹æ³ã§ã¯ãã«ã¬ã³ããã£ã¬ã¯ããªãå¤ãã£ã¦ãã¾ãå ´åãããã¾ãï¼ æ´æ°ï¼ 09/01/23 : åçå ¬é 09/01/28 : åã©ã³ã¯ç»é²ã¨ï¼ã¨ãã¸ã®ã©ãã«ç»é²ã追å */ var DotRecorder = function( graph_name ){ // åæå this.graph_name = graph_name; this.arr_node = new Array(); this.arr_rel = new Array(); this.arr_same_rank = new Array(); }; DotRecorder.prototype = { // ã°ã©ãå graph_name : null, // ãã¡ã¤ã«å dot_path : null, // ããã¼ãã®IDã¨ååã®å¯¾å¿ãã®é å arr_node : null, // ããã¼ãå士ã®é¢ä¿ãã®é å arr_rel : null, // ãçã©ã³ã¯ãªãã¼ããã®é å arr_same_rank : null, // ãã¼ããç»é²ãã¾ã node : function( t_id, t_name ){ this.arr_node.push( { node_id : t_id, node_name : t_name } ); }, // é¢ä¿ãç»é²ãã¾ã rel : function( t_from, t_to ){ var t_label = ( arguments.length > 2 ) ? arguments[2] : "" ; this.arr_rel.push( { from_id : t_from, to_id : t_to, label : t_label } ); }, // åã©ã³ã¯ã«ç»é²ãã¾ããå¼æ°åæ°ã¯å¯å¤é·ã same_rank : function(){ var temp_arr = new Array(); for( var i = 0, len = arguments.length; i < len; i ++ ) { // å¼æ°ã®IDãpush temp_arr.push( arguments[i] ); } // é åãpush this.arr_same_rank.push( temp_arr ); }, // dotãã¡ã¤ã«ãåºåãã¾ã dot : function( file_path ){ // æ°è¦ãã¡ã¤ã«ä½æ // utf-8ã§æ¸ã込㿠// http://passing.breeze.cc/mt/archives/2008/05/jscript-utf8.html var adTypeText = 2; var adWriteChar = 0; var adWriteLine = 1; var adSaveCreateOverWrite = 2; var stw = new ActiveXObject("ADODB.Stream"); stw.Type = adTypeText; stw.charset = "utf-8"; stw.Open(); // ã°ã©ãä½æéå§ var sp = " "; stw.WriteText( "digraph " + this.graph_name + "{\r\n" + sp + "node [fontname=\"MS GOTHIC\"];\r\n" + "edge [fontname=\"MS GOTHIC\"];" , adWriteLine ); // ãã¼ãç»é² for( var i = 0, len = this.arr_node.length; i < len; i ++ ) { var node_id = this.arr_node[i].node_id; var node_name = this.arr_node[i].node_name; stw.WriteText( sp + "\"" + node_id + "\" [label=\"" + node_name + "\"];" , adWriteLine ); } // ã©ã³ã¯ç»é² for( var i = 0, len = this.arr_same_rank.length; i < len; i ++ ) { stw.WriteText( sp + "{rank=same;" , adWriteChar ); var arr_temp = this.arr_same_rank[ i ]; for( var j = 0, len2 = arr_temp.length; j < len2; j ++ ) { stw.WriteText( "\"" + arr_temp[j] + "\"" + ((j == len2 - 1) ? "" : " " ) , adWriteChar ); } stw.WriteText( "};", adWriteLine ); } // é¢ä¿ç»é² for( var i = 0, len = this.arr_rel.length; i < len; i ++ ) { var from_id = this.arr_rel[i].from_id; var to_id = this.arr_rel[i].to_id; var label = this.arr_rel[i].label; stw.WriteText( sp + "\"" + from_id + "\" -> \"" + to_id + "\"" + " [label=\"" + label + "\"]" + ";" , adWriteLine ); } // ã°ã©ãä½æçµäº stw.WriteText( "}", adWriteLine ); stw.SaveToFile( file_path, adSaveCreateOverWrite ); stw.Close(); // ç¡äºã«ãã¡ã¤ã«ãä½ããã®ã§ãã¡ã¤ã«ãã¹ãç»é² this.dot_path = file_path; }, // dotããpngãä½ãã¾ã png : function( png_path ){ // dotã¯ä½ææ¸ã¿ã if( this.dot_path.length > 0 ) { var cmd = "dot -Tpng -o " + png_path + " " + this.dot_path ; //WScript.Echo( cmd ); var ws = WScript.CreateObject("WScript.Shell"); ws.Run( cmd ); //dot -Tpng -o hoge.png hoge.dot } else { WScript.Echo("dotãã¡ã¤ã«ãæªä½æã§ãã"); } } }; // ã¯ã©ã¹ã®ãã¹ã /* var dr = new DotRecorder( "my_graph" ); // ãã¼ããç»é² dr.node( "1a", "å£" ); dr.node( "2a", "æ¥" ); dr.node( "2b", "å" ); dr.node( "3a", "ç®" ); dr.node( "3b", "å" ); dr.node( "4a", "ç°" ); // é¢ä¿ãç»é² dr.rel( "1a", "2a" ); dr.rel( "2a", "3a" ); dr.rel( "3a", "4a" ); dr.rel( "1a", "2b" ); dr.rel( "2b", "3b" ); dr.rel( "3b", "4a" ); // ã°ã©ãä½æ dr.dot( "hoge.dot" ); dr.png( "hoge.png" ); */
ã³ã¼ãä¸ã«ä½µè¨ããããã«ãGraphvizã®ã¤ã³ã¹ãã¼ã«ãæ¸ã¾ããbinãã©ã«ããPATHã«ç»é²ãã¦ãããã¨ãï¼dotãå¼ã³åºãã®ã§ï¼
å®è¡ã®éã«ã¯ãä¸è¨ã é©å½ãªåå.js ã§ä¿åãã¦ããã«ã¯ãªãã¯ã
ä¸éçæç©ã¨ãã¦ãhoge.dotãåºåãããã
digraph my_graph{ node [fontname="MS GOTHIC"]; "a" [label="å£"]; "b" [label="æ¥"]; "c" [label="å"]; "d" [label="ç°"]; "a" -> "b"; "b" -> "c"; "c" -> "d"; "d" -> "a"; }
è¤éãªæ§é ã®ãã¼ã¿ãè¦è¦åããéã«å½¹ç«ã¤ãããããªãã
ãããå¦çã¨è¨ãã¨ï¼ã大éã®ç©ãä¸æ¬ãã¦ä½ããããã¨ããæä½ã§ããäºãå¤ãã
ãã®æä½ã®æä¸ã«ï¼ä¸è¨ã®ã¯ã©ã¹ã®å¦çãã¡ãã£ã¨ã ãæ··ãã¦ã¿ãã°ï¼ãããå¦ççµæã®ã¬ãã¼ããç°¡åã«ä½ãããã¨ããå
·åã ã
è£è¶³
æ¥æ¬èªã§æåã°ã©ããæç»ããæ¹æ³ã«ã¤ãã¦ã¯ï¼ä¸è¨ãåç §ã
http://cassa.at.webry.info/200711/art...
- .dotãUTF8ã§æ¸ã
- æ¥æ¬èªãã©ã³ããæå®ãã
ãã®ããã«ã¯UTF8ã§ãã¡ã¤ã«å ¥åºåãè¡ãªãå¿ è¦ãããï¼ä¸è¨ãåèã«ããã¦é ããã
jscript㧠utf8ãªãã¡ã¤ã«åºå
http://passing.breeze.cc/mt/archives/...