Commit b3eda9e69251b0096a1fbeeeb488615393736d15

moved files around

Commit diff

lib/kipling/commands/timeline_command.rb

 
2222
2323 def renderer
2424 if out =~ /\.png/
25 Renderer::Ploticus.new(:day, out)
25 Renderer::Timeline::Ploticus.new(:day, out)
2626 else
2727 {
2828 'tabs' => lambda do
29 Renderer::Tabs.new
29 Renderer::Timeline::Tabs.new
3030 end,
3131 'ascii' => lambda do
32 Renderer::AsciiBar.new(:day, 333333)
32 Renderer::Timeline::Ascii.new(:day, 333333)
3333 end
3434 }[@renderer].call
3535 end
toggle raw diff

lib/kipling/renderer.rb

 
1require 'kipling/renderer/ploticus'
2require 'kipling/renderer/ascii_bar'
3require 'kipling/renderer/tabs'
1require 'kipling/renderer/timeline'
42require 'kipling/renderer/snapshot'
53
64module Kipling
toggle raw diff

lib/kipling/renderer/ascii_bar.rb

 
0module Kipling
1 module Renderer
2 # Original code from Neelakanth Nadgir, http://blogs.sun.com/realneel/entry/ascii_graphs_using_ruby
3 class AsciiBar
4 WIDTH = 72
5 HEIGHT = 16
6
7 def initialize(scale, out)
8 end
9
10 def render(data, names)
11 raise "data must have exactly 2 columns. It was #{data[0].length}" unless data[0].length == 2
12 data = data.map{|a| a[1]}
13
14 #Adjust X axis when there are more than WIDTH cols
15 if data.length > WIDTH then
16 old_values = data;
17 data = []
18 0.upto(WIDTH - 1){ |i| data << old_values[i*old_values.length/WIDTH]}
19 end
20 max = data.max
21 # initialize display with blanks
22 display = Array.new(HEIGHT).collect { Array.new(WIDTH, ' ') }
23 data.each_with_index do |e, i|
24 num= e*HEIGHT/max
25 (HEIGHT - 1).downto(HEIGHT - 1 - num){|j| display[j][i] = '|'}
26 end
27 display.each{|ar| ar.each{|e| putc e}; puts "\n"} #now print
28 end
29 end
30 end
31end
toggle raw diff

lib/kipling/renderer/ploticus.rb

 
0require 'time'
1
2module Kipling
3 module Renderer
4 class Ploticus
5 # http://ploticus.sourceforge.net/doc/dates.html
6 DATE_FORMATS = {
7 :day => {
8 :script_fmt => '%y/%m/%d',
9 :datefmt => 'yy/mm/dd',
10 :stubfmt => 'MMMdd',
11 :xinc => '"1 day"',
12 :mode => 'bars',
13 :xyears => 'xyears=yyyy'
14 },
15 :hour => {
16 :script_fmt => '%y/%m/%d.%H:%M',
17 :datefmt => 'yy/mm/dd',
18 :stubfmt => 'hh:mm',
19 :xinc => '"4 hours"',
20 :mode => 'line',
21 :xyears => nil
22 }
23 }
24
25 def initialize(scale, out)
26 @p = DATE_FORMATS[scale]
27 raise "BAD SCALE: #{scale}" if @p.nil?
28 @out = out
29 end
30
31 def render(points, grouping_values)
32 script = Tabs.new(@p[:script_fmt]).text(points, grouping_values)
33
34 # y=dev y2=done
35 n = 0
36 ys = grouping_values.map do |grouping_value|
37 n += 1
38 y = (n==1) ? '' : n
39 "y#{y}=#{grouping_value}"
40 end.join(' ')
41
42 # http://ploticus.sourceforge.net/doc/prefab_chron_ex.html
43 cmd = <<-EOF
44ploticus -png
45-o #{@out}
46-prefab chron
47header=yes
48x=dt
49#{ys}
50unittype=datetime
51mode=#{@p[:mode]}
52datefmt=#{@p[:datefmt]}
53xinc=#{@p[:xinc]}
54stubfmt=#{@p[:stubfmt]}
55#{@p[:xyears]}
56title=\"Iteration Burndown\"
57barwidth=0.2
58color=powderblue
59omitweekends=no
60data=stdin
61legendfmt=singleline
62EOF
63 cmd = cmd.split(/\n/).join(' ')
64 IO.popen(cmd, "w") do |io|
65 io << script
66 end
67 end
68 end
69 end
70end
toggle raw diff

lib/kipling/renderer/tabs.rb

 
0require 'time'
1
2module Kipling
3 module Renderer
4 # Renders a timeline as a tab-delimited file
5 class Tabs
6 def initialize(time_format = '%y/%m/%d')
7 @time_format = time_format
8 end
9
10 def render(points, grouping_values)
11 puts text(points, grouping_values)
12 end
13
14 def text(points, grouping_values)
15 script = "dt #{grouping_values.join(' ')}\n" + points.map do |point|
16 point = point.dup
17 point[0] = point[0].strftime(@time_format)
18 point.join(" ")
19 end.join("\n")
20 end
21 end
22 end
23end
toggle raw diff

lib/kipling/renderer/timeline.rb

 
1require 'kipling/renderer/timeline/ascii'
2require 'kipling/renderer/timeline/tabs'
3require 'kipling/renderer/timeline/ploticus'
toggle raw diff

lib/kipling/renderer/timeline/ascii.rb

 
1module Kipling
2 module Renderer
3 module Timeline
4 # Original code from Neelakanth Nadgir, http://blogs.sun.com/realneel/entry/ascii_graphs_using_ruby
5 class Ascii
6 WIDTH = 72
7 HEIGHT = 16
8
9 def initialize(scale, out)
10 end
11
12 def render(data, names)
13 raise "data must have exactly 2 columns. It was #{data[0].length}" unless data[0].length == 2
14 data = data.map{|a| a[1]}
15
16 #Adjust X axis when there are more than WIDTH cols
17 if data.length > WIDTH then
18 old_values = data;
19 data = []
20 0.upto(WIDTH - 1){ |i| data << old_values[i*old_values.length/WIDTH]}
21 end
22 max = data.max
23 # initialize display with blanks
24 display = Array.new(HEIGHT).collect { Array.new(WIDTH, ' ') }
25 data.each_with_index do |e, i|
26 num= e*HEIGHT/max
27 (HEIGHT - 1).downto(HEIGHT - 1 - num){|j| display[j][i] = '|'}
28 end
29 display.each{|ar| ar.each{|e| putc e}; puts "\n"} #now print
30 end
31 end
32 end
33 end
34end
toggle raw diff

lib/kipling/renderer/timeline/ploticus.rb

 
1require 'time'
2
3module Kipling
4 module Renderer
5 module Timeline
6 class Ploticus
7 # http://ploticus.sourceforge.net/doc/dates.html
8 DATE_FORMATS = {
9 :day => {
10 :script_fmt => '%y/%m/%d',
11 :datefmt => 'yy/mm/dd',
12 :stubfmt => 'MMMdd',
13 :xinc => '"1 day"',
14 :mode => 'bars',
15 :xyears => 'xyears=yyyy'
16 },
17 :hour => {
18 :script_fmt => '%y/%m/%d.%H:%M',
19 :datefmt => 'yy/mm/dd',
20 :stubfmt => 'hh:mm',
21 :xinc => '"4 hours"',
22 :mode => 'line',
23 :xyears => nil
24 }
25 }
26
27 def initialize(scale, out)
28 @p = DATE_FORMATS[scale]
29 raise "BAD SCALE: #{scale}" if @p.nil?
30 @out = out
31 end
32
33 def render(points, grouping_values)
34 script = Tabs.new(@p[:script_fmt]).text(points, grouping_values)
35
36 # y=dev y2=done
37 n = 0
38 ys = grouping_values.map do |grouping_value|
39 n += 1
40 y = (n==1) ? '' : n
41 "y#{y}=#{grouping_value}"
42 end.join(' ')
43
44 # http://ploticus.sourceforge.net/doc/prefab_chron_ex.html
45 cmd = <<-EOF
46ploticus -png
47-o #{@out}
48-prefab chron
49header=yes
50x=dt
51#{ys}
52unittype=datetime
53mode=#{@p[:mode]}
54datefmt=#{@p[:datefmt]}
55xinc=#{@p[:xinc]}
56stubfmt=#{@p[:stubfmt]}
57#{@p[:xyears]}
58title=\"Iteration Burndown\"
59barwidth=0.2
60color=powderblue
61omitweekends=no
62data=stdin
63legendfmt=singleline
64EOF
65 cmd = cmd.split(/\n/).join(' ')
66 IO.popen(cmd, "w") do |io|
67 io << script
68 end
69 end
70 end
71 end
72 end
73end
toggle raw diff

lib/kipling/renderer/timeline/tabs.rb

 
1require 'time'
2
3module Kipling
4 module Renderer
5 module Timeline
6 # Renders a timeline as a tab-delimited file
7 class Tabs
8 def initialize(time_format = '%y/%m/%d')
9 @time_format = time_format
10 end
11
12 def render(points, grouping_values)
13 puts text(points, grouping_values)
14 end
15
16 def text(points, grouping_values)
17 script = "dt #{grouping_values.join(' ')}\n" + points.map do |point|
18 point = point.dup
19 point[0] = point[0].strftime(@time_format)
20 point.join(" ")
21 end.join("\n")
22 end
23 end
24 end
25 end
26end
toggle raw diff