2010年2月10日水曜日

SVG Graph Generator

Note: I recommend you to read this entry with Firefox 3.6 (or later).

HTML 5 supports SVG image in HTML document, and recently it was implemented in Firefox 3.6.
I wrote a dynamic graph data visualizer with SVG and Javascript in 2007, and now I can use it in HTML. Hooray!

A sample of it is shown below.
Currently you need to use Firefox 3.6 and enable HTML 5 to see it.
The way to enable it is:
  1. Input "about:counfig" to the location bar
  2. Change the value of "html5.enable" to "true"
When you reload this page after the process, you will see the example here.

The arrangement of nodes bases on attraction repulsion model, and you can drag and drop each of them.

Here is the script file.
SVG Graph Generator (Apache Licence 2.0)

All you need to write in your HTML file is like this.
<!-- Include the script file. -->
<script src="URL_TO_THE_SCRIPT"></script>

<!-- Add svg element to HTML. "id" attribute is required. -->
<svg viewBox="0 0 200 150" id="svg"></svg>

<script>
// Create a graph object.
// The argument is the id of svg element.
var graph = new Graph("svg");

// Add Nodes to the graph object.
// The argument is text appears on it.
// Each node is assigned an ID which starts with 0.
graph.addNode("Alice"); // Node ID 0
graph.addNode("Bob"); // Node ID 1
graph.addNode("Charlie"); // Node ID 2
graph.addNode("Dave"); // Node ID 3
graph.addNode("Eve"); // Node ID 4

// Connect nodes.
// The arguments are two node IDs
// and connection strength (between 0 and 1)
// Currently connection strength has
// no influence on the graph.
graph.joint(0, 1, 1);
graph.joint(1, 2, 1);
graph.joint(1, 3, 1);
graph.joint(3, 4, 1);

// Start to move.
// You can stop it by "graph.sleep()"
graph.wake();
</script>
If it appeals to you, please create something with it!

2010年1月7日木曜日

単純な .screenrc の紹介

GNU Screen、ターミナルでリモートログインして作業するにはほとんど必須のアプリケーションですよね。
今回はその設定ファイル .screenrc に関して。
ここで紹介する .screenrc をホームディレクトリに置けば、こんな感じに仕上がります。それでは行ってみましょう。

現在の僕の .screenrc

defutf8 on
defencoding utf8
encoding utf-8 utf-8

escape ^z^z

bind x
bind ^x

startup_message off
autodetach on
vbell off

caption always "%-w%10L>%{=b bw}%n %t%{-}%+w%-0="
hardstatus alwayslastline "%H%=%Y/%m/%d %02c"
shelltitle "$ |shell"

bindkey -k kD stuff \177

termcapinfo xterm* ti@:te@

shell $SHELL

解説

defutf8 on
defencoding utf8
encoding utf-8 utf-8
文字コードを UTF-8 にする。
web 上の設定サンプルには文字コードの指定に kanji とか defkanji といったコマンドを使っているものがあるが、それらは 3.9.10 以前の古いバージョンでのコマンドで、最新バージョンではすでに無効。現在は encoding と defencoding を使う。
escape ^z^z
エスケープ文字を C-Z に設定。C-Z 自体を入力したいときには それに続けてさらに C-Z を入力。
bind x
bind ^x
デフォルトで C-Z x と C-Z C-X にバインドされている lockscreen を無効化
startup_message off
autodetach on
vbell off
それぞれ
  • 起動時のメッセージを非表示
  • ターミナルが落ちたら自動的にデタッチ
  • 音声ベルが鳴らない時に可視ベルが "Wuff, ---- Wuff!!" とうるさいので可視ベルをオフにする
caption always "%-w%10L>%{=b bw}%n %t%{-}%+w%-0="
hardstatus alwayslastline "%H%=%Y/%m/%d %02c"
caption はウィンドウごとにあるけれど、hardstatus は一つの screen プロセスに一つ。書式は以下の通り。
  • %-w 表示しているウィンドウより前のウィンドウ番号とウィンドウ名
  • %10L> ここを左から10%くらいに配置
  • %{=b bw} 文字のスタイルの変更
  • %n %t 表示しているウィンドウのウィンドウ番号 (%n) とウィンドウ名 (%t)
  • %{-} 文字のスタイルを元に戻す
  • %-w 表示しているウィンドウより後のウィンドウ番号とウィンドウ名
  • %-0= ここを右端にする
  • %H Hostname
  • %Y/%m/%d %02c 日付と時刻
shelltitle "$ |shell"
shelltitle でウィンドウ名を設定。
screen はシェルから出力されたエスケープシーケンスを頼りにプロンプトを特定して、その後に入力されたコマンドを拾ってここに表示する。
詳しくいえば、"^[k^[\" ("^[" はエスケープ文字) が出力されてから、上記 shelltitle で "|" の直前までに入力した文字列までを読み飛ばして、その後に入力された文字列をコマンドとして解釈してくれる。なので、shelltitle の "|" までに書く文字列はシェルの末尾と一致している必要があり、またシェルは上記のエスケープシーケンスを出力しなければならない。シェルの設定はまたの機会に。
"|" 以降の文字列はデフォルトのウィンドウ名。
bindkey -k kD stuff \177
Mac の delete キーを BackSpace として使うためのキーバインド。
termcapinfo xterm* ti@:te@
マウスホイールを利用可能にする。
shell $SHELL
Cygwin 上で screen を実行したときにログインシェルは zsh なのに bash が立ち上がったので追加。

情報募集

上記の設定をしていても、一度デタッチしたスクリーンをレジュームすると UTF-8 の文字が全て "?" になってしまいます。
レジューム時の screen にコマンドラインオプション -U を付ければ UTF-8 モードになってうまくいくのですが、.screenrc での設定だけで完結することはできないのでしょうか。
そもそもなぜデタッチで設定が無効になるのかよく分かりません。