履歴: ソフトウェア/tchart.rb
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 11 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2016/2/10 13:27:37 | ソフトウェア/tchart.rb 最新版 | 10,927 | +1 | -1 | 表示 | 差分 | — |
| 2016/2/10 13:27:37 | ソフトウェア/tchart.rb | 10,933 | +2 | -3 | 表示 | 表示中 | 選択 |
| 2016/2/10 4:27:37 | ソフトウェア/tchart.rb | 10,901 | +18 | -515 | 表示 | 差分 | 選択 |
| 2016/2/8 12:51:14 | ソフトウェア/tchart.rb | 20,840 | +3 | -4 | 表示 | 差分 | 選択 |
| 2016/2/8 12:51:14 | ソフトウェア/tchart.rb | 20,827 | +4 | -4 | 表示 | 差分 | 選択 |
| 2016/2/8 12:51:14 | ソフトウェア/tchart.rb | 20,768 | +19 | -14 | 表示 | 差分 | 選択 |
| 2016/2/8 12:51:14 | ソフトウェア/tchart.rb | 20,712 | +256 | -31 | 表示 | 差分 | 選択 |
| 2016/2/8 5:16:25 | ソフトウェア/tchart.rb | 16,250 | +61 | -14 | 表示 | 差分 | 選択 |
| 2016/2/5 18:13:23 | ソフトウェア/tchart.rb | 14,430 | +5 | -1 | 表示 | 差分 | 基準 |
| 2016/2/5 18:13:23 | ソフトウェア/tchart.rb | 14,376 | +673 | -0 | 表示 | 差分 | 選択 |
| 2016/2/5 16:23:17 | ソフトウェア/tchart.rb | 516 | — | — | 表示 | — | 選択 |
基準: ソフトウェア/tchart.rb (2016/2/5 18:13:23) → 比較: ソフトウェア/tchart.rb (2016/2/10 13:27:37)
@@ -4,7 +4,7 @@
* テキストファイルのソースを与えてタイミング図を作成するスクリプトです [#yf72bb15]
-"Timing chart formatter by kumagai" ~
+熊谷正朗さんの "Timing chart formatter by kumagai" ~
http://www.mech.tohoku-gakuin.ac.jp/rde/contents/library/tchart/indexframe.html
を参考にして、svg を出力するように ruby で作りました。
@@ -14,6 +14,23 @@
かなり走り書き的なところがありますが、ご容赦下さい。
+* もしかして、javascript で作った方が良かったんじゃないだろうか・・・ [#m8dba977]
+
+javascript で実装すればクライアント側の処理だけで図を描画できますし、
+最近はそのまま画像として保存することもできるそうで、
+
+http://www.pori2.net/html5/Canvas/150.html
+
+ずっと良かったのかもしれません???
+
+確かに・・・ずっとよさそうです。javascript で書き直した物をこちらで紹介しています。~
+[[ソフトウェア/タイミングチャート清書サービス]]
+
+javascript 版がいろいろ便利すぎたため、~
+COLOR(red){SIZE(30){以下の ruby 版は細かいバグを残したまま現在更新されておりません}}
+
+javascript 版をご利用ください。
+
* 使用例 [#ya5f8236]
次のようなテキストから、
@@ -34,251 +51,6 @@
ready _____________[~~]______
);
-* タイミング記述テキストの文法 [#g7420e8f]
-
-** # から始まる行はコメント行です [#ld750e11]
-
- # test test
- clk _~_~_~_~_~
- signal ___~~~~___
-
-&tchart(
-# test test
-clk _~_~_~_~_~
-signal ___~~~~___
-);
-
-** @ から始まる行で設定を変更できます [#q06c69eb]
-
- @signal_style stroke-linecap="round" stroke-width="2" stroke="green" fill="none"
- clk _~_~_~_~_~
- signal ___~~~~___
-
-&tchart(
-@signal_style stroke-linecap="round" stroke-width="2" stroke="green" fill="none"
-clk _~_~_~_~_~
-signal ___~~~~___
-);
-
-** % から始まる行で自由な位置に文字列を追加できます [#z209ee2f]
-
- %100 -5 test!
- clk _~_~_~_~_~
- signal ___~~~~___
-
-&tchart(
-%100 -5 test!
-clk _~_~_~_~_~
-signal ___~~~~___
-);
-
-** 空行があれば1行分だけ空白が空きます [#le587f61]
-
- clk1 _~_~_~_~_~
- clk2 __~~__~~__
-
- signal ___~~_____
-
-&tchart(
-clk1 _~_~_~_~_~
-clk2 __~~__~~__
-
-signal ___~~_____
-);
-
-** その他の文字から始まる行が信号になります [#e6c10712]
-
-フォーマットは
-
- 信号名 [空白] タイミング定義
-
-の形です。
-
-* 信号定義の文法と用例 [#qdaa4e35]
-
-** _ と ~ で 0 と 1 を表します。 [#dd9965b7]
-
-** - がハイインピーダンス状態です。 [#x82e48ed]
-
- clk _~_~_~_~_~_~_~_~_~
- data ___~~~~__~~____~~_
- enable ___~~~~~~~~~~_____
- output ---~~~~__~~__-----
-
-&tchart(
-clk _~_~_~_~_~_~_~_~_~
-data ___~~~~__~~____~~_
-enable ___~~~~~~~~~~_____
-output ---~~~~__~~__-----
-);
-
-** バス信号や不定値を表すのに = を使えます。 [#r60d0319]
-
-** X で値の切り替えを表せます。 [#uad781ca]
-
-** 信号定義に文字列を書き入れることができます。 [#f601e0b1]
-
-** ? を一文字だけ書くと不定値を表すために色が付きます。 [#dc4c5057]
-
-** 文字列を書いても時間は進みません。 [#b33c396f]
-
-** X は時間が進みます。イメージ的には X= のように働きます。 [#c73126b2]
-
- clk _~_~_~_~_~_~
- data =?==XDATA=====X=?=
- valid ___~~~~~~___
-
-&tchart(
-clk _~_~_~_~_~_~
-data =?==XDATA=====X=?=
-valid ___~~~~~~___
-);
-
- clk _~_~_~_~_~_~_~_~_~
- enable ___~~~~~~~~~~_____
- output ---=D0=X=D1X=D2X=D3X=D4-----
-
-&tchart(
-clk _~_~_~_~_~_~_~_~_~
-enable ___~~~~~~~~~~_____
-output ---=D0=X=D1X=D2X=D3X=D4-----
-);
-
-** : を入れると途切れさせることができます。 [#yb67ee5a]
-
- clk _~_~_~_:...:~_~_~_~_~
- data ___~~~~:...:~~____~~_
-
-&tchart(
-clk _~_~_~_:...:~_~_~_~_~
-data ___~~~~:...:~~____~~_
-);
-
-** 不定値部分を表すのに、/ \ * が使えます。 [#b5b09f01]
-
- clk _~_~_~_~_~_~_~
- rising ___==/=/=~~~~~
- falling ~~~==\=\=_____
- transition ___=D0=*=D1*=D2*=D3___
-
-&tchart(
-clk _~_~_~_~_~_~_~
-rising ___==/=/=~~~~~
-falling ~~~==\=\=_____
-transition ___=D0=*=D1*=D2*=D3___
-);
-
-** | を入れるとグリッド線を引けます。 [#d1263d2a]
-
-** [ ] でくくるとハイライトできます。 [#d41e1c81]
-
- clk _~_~_~_~_~_~_~_~_~
- data ___~~~~~~~~|____~~_
- enable ___[~~~~~~~~~~]_____
- output ---~~~~~~~~__-----
-
-&tchart(
-clk _~_~_~_~_~_~_~_~_~
-data ___~~~~~~~~|____~~_
-enable ___[~~~~~~~~~~]_____
-output ---~~~~~~~~__-----
-);
-
-
-** 全ての組み合わせを試してみる。 [#f93875da]
-
- # :-~_=/\X*
- 0 _~_~_~_~_~_~_[~_~_]~_
-
- 1 :::-:~:_:=:/:\:X:*:
- 2 -:---~-_-=-/-\-X-*-
- 3 ~:~-~~~_~=~/~\~X~*~
- 4 _:_-_~___=_/_\_X_*_
- 5 =:=-=|~=_===/=\=X=*=
- 6 /:/-/~/_/=///\/X/*/
- 7 \:\-\~\_\=\/\\\X\*\
- 8 X:X-X~X_X=X/X\XXX*X
- 9 *:*-*~*_*=*/*\*X***
-
-&tchart(
-# :-~_=/\X*
-0 _~_~_~_~_~_~_[~_~_]~_
-
-1 :::-:~:_:=:/:\:X:*:
-2 -:---~-_-=-/-\-X-*-
-3 ~:~-~~~_~=~/~\~X~*~
-4 _:_-_~___=_/_\_X_*_
-5 =:=-=|~=_===/=\=X=*=
-6 /:/-/~/_/=///\/X/*/
-7 \:\-\~\_\=\/\\\X\*\
-8 X:X-X~X_X=X/X\XXX*X
-9 *:*-*~*_*=*/*\*X***
-);
-
-** 不定値の塗り分けをテスト。 [#h695f4bc]
-
- @h_line 30
- @h_skip 20
- @w_transient 5
- @w_caption 60
- test =/=?\=\=?/=X=?X=*?=*=X=?-=?= =?X
-
-&tchart(
-@h_line 30
-@h_skip 20
-@w_transient 5
-@w_caption 60
-test =/=?\=\=?/=X=?X=*?=*=X=?-=?= =?X
-);
-
-** 遷移の傾きをなくすには @w_transient 0 とする [#l5475a84]
-
- @w_transient 0
- clk _~_~_~_~_~_~_~
- data ___|~~~~|_______
-
-&tchart(
-@w_transient 0
-clk _~_~_~_~_~_~_~
-data ___|~~~~|_______
-);
-
-* 設定値 [#rd2a2e82]
-
-** margin (= 10) [#b7fe0b8a]
-** w_caption (= 40) [#ge8b8cec]
-** w_hold (= 10) [#le7dd0fb]
-** w_transient (= 2) [#n3c4fb61]
-** h_line (= 10) [#p7e6f34c]
-** h_space (= 10) [#teb7c9f7]
-** signal_style [#v5ac38b6]
-
-'stroke-linecap="round" stroke-width="0.6" stroke="black" fill="none"',
-
-** grid_style [#ra37b0f5]
-
-'stroke-linecap="round" stroke-width="0.6" stroke="red" fill="none"',
-
-** highlight_style [#d1714e07]
-
-'stroke="none" fill="#ff8"',
-
-** notcare_style [#r0fb27ce]
-
-'fill="#ccc"',
-
-** caption_font [#z0c3eaff]
-
-'fill="black" font-family="Helvetica"',
-
-** signal_font [#sfe73988]
-
-'fill="black" font-family="Helvetica"'
-
-** rotate (= 0) [#s041342a]
-
-未実装
-
* ソースファイル [#u33d6dea]
いやほんと、走り書きですみません。
@@ -301,6 +73,7 @@
# default config
conf = {
+ scale: 1.0,
margin: 10,
w_caption: 40,
w_hold: 10,
@@ -520,7 +293,8 @@
x2r = x2t + @conf[:w_hold]
#
- svg = %Q(<text x="#{(x1h + x2h)/2.0}" y="#{y0-1.5}" text-anchor="middle" font-size="#{@conf[:h_line]}" #{@conf[:signal_font]}>#{string[1]}</text>)
+ sanitized = string[1].gsub(/</, '<').gsub(/>/, '>').gsub(/"/, '"')
+ svg = %Q(<text x="#{(x1h + x2h)/2.0}" y="#{y0-1.5}" text-anchor="middle" font-size="#{@conf[:h_line]}" #{@conf[:signal_font]}>#{sanitized}</text>)
if string[1] == '?'
line = "M#{x1t},#{y1}H#{x2}"
@@ -581,13 +355,14 @@
end
def caption2svg(conf, y, caption)
- %Q(<text x="#{conf[:w_caption]-5}" y="#{y+conf[:h_line]-1.5}" text-anchor="end" font-size="#{conf[:h_line]}" #{conf[:caption_font]}>#{caption}</text>)
+ sanitized = caption.gsub(/</, '<').gsub(/>/, '>').gsub(/"/, '"')
+ %Q(<text x="#{conf[:w_caption]-5}" y="#{y+conf[:h_line]-1.5}" text-anchor="end" font-size="#{conf[:h_line]}" #{conf[:caption_font]}>#{sanitized}</text>)
end
#####################################################################
svg = []
- y = 0
+ y = -1
x_max = 0
lines = readlines
lines.shift while lines[0] =~ /^\s*$/
@@ -618,12 +393,15 @@
next
end
- line.sub!(/\s*$/, '')
- if line == ''
- y += conf[:h_line] + conf[:h_space]
- next
+ if y < 0
+ y = 0
+ else
+ y += conf[:h_space]
end
+ line.sub!(/\s*$/, '')
+ next if line == ''
+
if line !~ /^([^\s]+)[\s]+([^\s].*)$/
STDERR.puts "Illegal Line: #{line}"
next
@@ -638,51 +416,52 @@
x_max = timeline.xr if x_max < timeline.xr
svg << timeline.svg
- y += conf[:h_line] + conf[:h_space]
+ y += conf[:h_line]
end
- w = "%g" % (x_max + conf[:margin]*2)
- h = "%g" % (y + conf[:margin]*2)
- l = "%g" % (-conf[:margin])
- t = "%g" % (-conf[:margin])
- r = "%g" % (x_max)
- b = "%g" % (y )
+ m = conf[:margin]
+ w = "%g" % ((x_max + 2*m) * conf[:scale])
+ h = "%g" % ((y + 2*m) * conf[:scale])
+ l = "%g" % (-m)
+ t = "%g" % (-m)
+ r = "%g" % (x_max+2*m)
+ b = "%g" % (y +2*m)
Timeline.grids.each do |g|
x = "%g" % g
- svg << %Q(<path d="M#{x},#{t}V#{b}" #{conf[:grid_style]} />)
+ svg << %Q(<path d="M#{x},#{'%g' % (-m/2)}V#{'%g' % (y+m/2)}" #{conf[:grid_style]} />)
end
Timeline.highlight.each do |h|
if h.is_a?(Array)
x1 = "%g" % h[0]
x2 = "%g" % h[1]
- svg.unshift %Q(<path d="M#{x1},#{t}V#{b}H#{x2}V#{t}R" #{conf[:highlight_style]} />)
+ svg.unshift %Q(<path d="M#{x1},#{'%g' % (-m/2)}V#{'%g' % (y+m/2)}H#{x2}V#{'%g' % (-m/2)}Z" #{conf[:highlight_style]} />)
end
end
print <<SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="#{w}pt" height="#{h}pt" viewBox="#{l} #{t} #{r} #{b}" version="1.1">
- <!--
- #{lines.join("\n")}
- -->
+ <![CDATA[
+ #{lines.join("\n").gsub(/\]\]\>/, ']]>')}
+ ]]>
<g>
#{svg.join("\n")}
</g>
</svg>
SVG
-
- exit
-
+
* ちょっと疑問 [#sfbfc96d]
ハイインピーダンスからの遷移の書き方はこれで良いんだろうか?
+他と傾きが違ってしまうけれど・・・
+
@h_line 30
@h_skip 20
@w_transient 8
- @w_caption 60
+ @w_caption 100
test1 ___|~~~|___|==|X=|X=
test2 ---~~~---==--==
@@ -690,12 +469,11 @@
@h_line 30
@h_skip 20
@w_transient 8
-@w_caption 60
+@w_caption 100
test1 ___|~~~|___|==|X=|X=
test2 ---~~~---==--==
);
-* もしかして、javascript で作った方が良かったんじゃないだろうか・・・ [#m8dba977]
* コメント・質問 [#jb4548c8]
#article_kcaptcha