how_is 10.0.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/how_is/chart.rb DELETED
@@ -1,83 +0,0 @@
1
- class HowIs::Chart
2
- # Generates the gnuplot script in data/issues.plg.
3
- #
4
- # Some configuration is available. Font locations are path to a TTF or other
5
- # Gnuplot-readable font name.
6
- #
7
- # For example that could be '/Users/anne/Library/Fonts/InputMono-Medium.ttf'
8
- # or just 'Helvetica'.
9
- #
10
- # @param font_location [String] Font for the chart
11
- # @param font_size [Integer] Size of the chart text
12
- # @param label_font_location [String] Font for labels
13
- # @param label_font_size [Integer] Size of the label text
14
- #
15
- # @return void
16
- def self.gnuplot(font_location: nil,
17
- font_size: 16,
18
- label_font_location: nil,
19
- label_font_size: 10,
20
- chartsize: '500,500',
21
- data_file:,
22
- png_file:)
23
- default_font_location =
24
- if Gem.win_platform?
25
- 'Arial'
26
- else
27
- 'Helvetica'
28
- end
29
-
30
- font_location ||= default_font_location
31
- label_font_location ||= font_location
32
-
33
- cmd = %Q{
34
- gnuplot -e "labelfont='#{label_font_location},#{label_font_size}'" \
35
- -e "chartfont='#{font_location},#{font_size}'" \
36
- -e "chartsize='#{chartsize}'" \
37
- -e "data='#{data_file}'" \
38
- -e "pngfile='#{png_file}'" \
39
- -c data/issues.plg
40
- }
41
- puts cmd
42
- IO.popen(cmd, 'w')
43
- end
44
-
45
- def self.rotate(offset, filename)
46
- if Gem.win_platform?
47
- rotate_with_dotnet(filename, offset)
48
- else
49
- rotate_with_minimagick(filename, offset)
50
- end
51
- end
52
-
53
- def self.rotate_with_dotnet(filename, offset)
54
- ps_rotate_flip = {
55
- 90 => 'Rotate90FlipNone',
56
- 180 => 'Rotate180FlipNone',
57
- 270 => 'Rotate270FlipNone',
58
- -90 => 'Rotate270FlipNone'
59
- }[offset]
60
-
61
- command = %Q{
62
- $path = "#{filename}"
63
-
64
- [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");
65
- $i = new-object System.Drawing.Bitmap $path
66
-
67
- $i.RotateFlip("#{ps_rotate_flip}")
68
-
69
- $i.Save($path,"png")
70
-
71
- exit
72
- }
73
-
74
- IO.popen(["powershell", "-Command", command], 'w') { |io| }
75
- end
76
-
77
- def self.rotate_with_minimagick(filename, offset)
78
- require 'mini_magick'
79
- image = MiniMagick::Image.new(filename) { |b| b.rotate offset.to_s }
80
- image.format 'png'
81
- image.write filename
82
- end
83
- end
@@ -1,78 +0,0 @@
1
- require 'prawn'
2
- require 'how_is/chart'
3
-
4
- module HowIs
5
- class PdfReport < BaseReport
6
- def format
7
- :pdf
8
- end
9
-
10
- attr_accessor :pdf
11
-
12
- def title(_text)
13
- pdf.pad_bottom(10) {
14
- pdf.text(_text, size: 25)
15
- }
16
- end
17
-
18
- def header(_text)
19
- pdf.pad_top(15) {
20
- pdf.pad_bottom(3) {
21
- pdf.text _text, size: 20
22
- }
23
- }
24
- end
25
-
26
- def link(_text, url)
27
- # TODO: Actually have links.
28
- _text
29
- end
30
-
31
- def horizontal_bar_graph(data)
32
- filename_base = "./issues-per-label"
33
- dat_file = filename_base + '.dat'
34
- png_file = filename_base + '.png'
35
-
36
- File.open(dat_file, 'w') do |f|
37
- data.each_with_index do |(label, n, link), i|
38
- f.puts "#{i}\t#{n}\t\"#{label}\""
39
- end
40
- end
41
-
42
- Chart.gnuplot(label_font_size: 10,
43
- font_size: 16,
44
- data_file: dat_file,
45
- png_file: png_file)
46
- Chart.rotate(90, png_file)
47
-
48
- pdf.image png_file
49
- end
50
-
51
- def text(_text)
52
- pdf.text _text
53
- end
54
-
55
- # Prawn (afaict) doesn't let you export to a binary blob.
56
- # So export to a file, then read the file.
57
- def export(&block)
58
- # TODO: Use actual temporary file.
59
- export!('temp.pdf', &block)
60
-
61
- open('temp.pdf').read
62
- end
63
-
64
- def export!(file, &block)
65
- _self = self
66
-
67
- Prawn::Document.generate(file) do |pdf|
68
- _self.pdf = pdf
69
-
70
- pdf.font("Helvetica")
71
-
72
- pdf.span(450, position: :center) do
73
- _self.instance_eval(&block)
74
- end
75
- end
76
- end
77
- end
78
- end