squid 0.0.0 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -17
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CHANGELOG.md +11 -0
  6. data/MIT-LICENSE +21 -0
  7. data/README.md +146 -2
  8. data/Rakefile +26 -1
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/examples/manual.rb +7 -0
  12. data/examples/readme/01-basic.rb +5 -0
  13. data/examples/readme/02-type-point.rb +5 -0
  14. data/examples/readme/03-type-line.rb +5 -0
  15. data/examples/readme/04-color.rb +5 -0
  16. data/examples/readme/05-gridlines.rb +5 -0
  17. data/examples/readme/06-ticks.rb +5 -0
  18. data/examples/readme/07-baseline.rb +5 -0
  19. data/examples/readme/08-every.rb +5 -0
  20. data/examples/readme/09-legend.rb +5 -0
  21. data/examples/readme/10-legend-offset.rb +5 -0
  22. data/examples/readme/11-format.rb +5 -0
  23. data/examples/readme/12-labels.rb +5 -0
  24. data/examples/readme/13-border.rb +5 -0
  25. data/examples/readme/14-height.rb +5 -0
  26. data/examples/readme/15-multiple-columns.rb +5 -0
  27. data/examples/readme/16-multiple-stacks.rb +5 -0
  28. data/examples/readme/17-two-axis.rb +7 -0
  29. data/examples/readme/readme.rb +28 -0
  30. data/examples/readme.rb +7 -0
  31. data/examples/screenshots/readme_00.png +0 -0
  32. data/examples/screenshots/readme_01.png +0 -0
  33. data/examples/screenshots/readme_02.png +0 -0
  34. data/examples/screenshots/readme_03.png +0 -0
  35. data/examples/screenshots/readme_04.png +0 -0
  36. data/examples/screenshots/readme_05.png +0 -0
  37. data/examples/screenshots/readme_06.png +0 -0
  38. data/examples/screenshots/readme_07.png +0 -0
  39. data/examples/screenshots/readme_08.png +0 -0
  40. data/examples/screenshots/readme_09.png +0 -0
  41. data/examples/screenshots/readme_10.png +0 -0
  42. data/examples/screenshots/readme_11.png +0 -0
  43. data/examples/screenshots/readme_12.png +0 -0
  44. data/examples/screenshots/readme_13.png +0 -0
  45. data/examples/screenshots/readme_14.png +0 -0
  46. data/examples/screenshots/readme_15.png +0 -0
  47. data/examples/screenshots/readme_16.png +0 -0
  48. data/examples/screenshots/readme_17.png +0 -0
  49. data/examples/squid/baseline.rb +9 -0
  50. data/examples/squid/basic.rb +9 -0
  51. data/examples/squid/border.rb +9 -0
  52. data/examples/squid/columns.rb +9 -0
  53. data/examples/squid/every.rb +11 -0
  54. data/examples/squid/format.rb +9 -0
  55. data/examples/squid/gridlines.rb +9 -0
  56. data/examples/squid/height.rb +9 -0
  57. data/examples/squid/labels.rb +9 -0
  58. data/examples/squid/legend.rb +9 -0
  59. data/examples/squid/legend_offset.rb +9 -0
  60. data/examples/squid/line.rb +9 -0
  61. data/examples/squid/line_width.rb +9 -0
  62. data/examples/squid/lines.rb +11 -0
  63. data/examples/squid/point.rb +9 -0
  64. data/examples/squid/points.rb +9 -0
  65. data/examples/squid/squid.rb +48 -0
  66. data/examples/squid/stacks.rb +10 -0
  67. data/examples/squid/ticks.rb +9 -0
  68. data/examples/squid/two_axis.rb +10 -0
  69. data/lib/squid/axis.rb +61 -0
  70. data/lib/squid/axis_label.rb +15 -0
  71. data/lib/squid/config.rb +46 -0
  72. data/lib/squid/configuration.rb +80 -0
  73. data/lib/squid/format.rb +22 -0
  74. data/lib/squid/graph.rb +113 -0
  75. data/lib/squid/gridline.rb +16 -0
  76. data/lib/squid/plotter.rb +187 -0
  77. data/lib/squid/point.rb +40 -0
  78. data/lib/squid/settings.rb +15 -0
  79. data/lib/squid/version.rb +1 -1
  80. data/lib/squid.rb +35 -3
  81. data/squid.gemspec +22 -14
  82. metadata +176 -23
  83. data/HISTORY.md +0 -1
  84. data/LICENSE.txt +0 -22
  85. data/bin/squid +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd30c909b777191445e84b30668138b1d901181b
4
- data.tar.gz: 3812e0e240a624a4e22f7838461bf92b01358b14
3
+ metadata.gz: 6df26faf36554dfaaae941ba20b4d73e8dced3b3
4
+ data.tar.gz: 69a3176e49028324269eb76fd1ebbc1977884e69
5
5
  SHA512:
6
- metadata.gz: d9c45cedbcd7c9e36f5746fa21a24b9cdb263e66ccc454d7639aa7f27bcce69dac294ef6f2c0e28c531fefb2c321664a6d1c27fb357aa71e224d207b0e5e8ddc
7
- data.tar.gz: 6b94093525f67eb7aac794832ef45c725fe283440fe690b1bafcc60059bfc917f1630d1665c2e670b1077a264e048828647be64cc08a97a20b64cfd4edebf3ec
6
+ metadata.gz: 199f46e3f7d63dc58b473db627cc13ee0ee1517652a67199c51037345b4ba7d00e23b5796e14653e0862bd454221d523ba7e4e18e44deaf51ff8afe3fd565f80
7
+ data.tar.gz: 253d51d670c652531f11f2be4802abe04bd5c8337aaa70818bcd8a3f1638d81796992060becb376afaeec2d1a77e19744ba8da4dbf14296803562d11e04fa6df
data/.gitignore CHANGED
@@ -1,17 +1,11 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ manual.pdf
11
+ readme.pdf
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --fail-fast
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ cache: bundler
3
+ notifications:
4
+ email: true
5
+ matrix:
6
+ include:
7
+ - rvm: 2.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ For more information about changelogs, check
6
+ [Keep a Changelog](http://keepachangelog.com) and
7
+ [Vandamme](http://tech-angels.github.io/vandamme).
8
+
9
+ ## 1.0.0 - unreleased
10
+
11
+ * [FEATURE] Add `chart` method to Prawn::Document to draw graphs.
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Fullscreen, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,147 @@
1
- # Squid
1
+ Squid
2
+ =====
2
3
 
3
- TODO: Write a gem description
4
+ Squid helps you write Ruby code to draw graphs in PDF files.
5
+
6
+ The **source code** is available on [GitHub](https://github.com/Fullscreen/squid) and the **documentation** on [RubyDoc](http://www.rubydoc.info/github/Fullscreen/squid/master/Squid/Interface).
7
+
8
+ [![Build Status](http://img.shields.io/travis/Fullscreen/squid/master.svg)](https://travis-ci.org/Fullscreen/squid)
9
+ [![Coverage Status](http://img.shields.io/coveralls/Fullscreen/squid/master.svg)](https://coveralls.io/r/Fullscreen/squid)
10
+ [![Dependency Status](http://img.shields.io/gemnasium/Fullscreen/squid.svg)](https://gemnasium.com/Fullscreen/squid)
11
+ [![Code Climate](http://img.shields.io/codeclimate/github/Fullscreen/squid.svg)](https://codeclimate.com/github/Fullscreen/squid)
12
+ [![Online docs](http://img.shields.io/badge/docs-✓-green.svg)](http://www.rubydoc.info/github/Fullscreen/squid/master/Squid/Interface)
13
+ [![Gem Version](http://img.shields.io/gem/v/squid.svg)](http://rubygems.org/gems/squid)
14
+
15
+ [Prawn](http://prawnpdf.org) is a great Ruby library to generate PDF files
16
+ but lacks high-level components to draw graphs.
17
+
18
+ Squid adds a single method `chart(data = {}, options = {})` to Prawn.
19
+
20
+ Provide the `data` to plot as a hash, with each key/value representing a series.
21
+
22
+ For instance, the following code generates the graph below:
23
+
24
+ ```ruby
25
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
26
+ chart data
27
+ ```
28
+
29
+ ![01-basic](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_01.png "chart(data)")
30
+
31
+
32
+ Graph options
33
+ -------------
34
+
35
+ By providing `options` to the `chart` method, you can customize the format of the graph.
36
+
37
+ Multiple options can be combined. Here is a comprehensive list.
38
+
39
+ ##### `:type` sets the type of graph. Can be `:column` (default), `:point`, or `:line`.
40
+
41
+ ![02-type-point](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_02.png "chart(data, type: :point)")
42
+
43
+ ##### `:line_widths` changes the line width (default: `[3]`, only applies to line graphs).
44
+
45
+ ![03-type-line](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_03.png "chart(data, type: :line, line_widths: [10])")
46
+
47
+ ##### `:colors` changes the colors of the chart (default: `%w(2e578c 5d9648 e7a13d bc2d30 6f3d79 7d807f)`).
48
+
49
+ ![04-colors](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_04.png "chart(data, colors: ['5d9648'])")
50
+
51
+ ##### `:steps` changes the number of gridlines (default: `4`).
52
+
53
+ ![05-gridlines](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_05.png "chart(data, steps: 6)")
54
+
55
+ ##### `:ticks` shows/hides the ticks between the baseline and each category (default: `true`).
56
+
57
+ ![06-ticks](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_06.png "chart(data, ticks: false)")
58
+
59
+ ##### `:baseline` shows/hides the baseline (default: `true`).
60
+
61
+ ![07-baseline](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_07.png "chart(data, baseline: false)")
62
+
63
+ ##### `:every` specifies how often to show category labels on the baseline (default: `1`).
64
+
65
+ ![08-every](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_08.png "chart(data, every: 2)")
66
+
67
+ ##### `:legend` shows/hides the legend (default: `true`).
68
+
69
+ ![09-legend](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_09.png "chart(data, legend: false)")
70
+
71
+ ##### `:legend` can also set the distance of the legend from the right margin (default: `{offset: 0}`).
72
+
73
+ ![10-legend-offset](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_10.png "chart(data, legend: {offset: 50})")
74
+
75
+ ##### `:format` changes the format of the label values. Can be `:integer` (default), `:float`, `:percentage`, `:currency`, or `:seconds`.
76
+
77
+ ![11-format](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_11.png "chart(data, format: :percentage)")
78
+
79
+ ##### `:labels` shows/hides the value for each point in the graph (default: `false`).
80
+
81
+ ![12-labels](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_12.png "chart(data, labels: true)")
82
+
83
+ ##### `:border` shows/hides a border around the graph (default: `false`).
84
+
85
+ ![13-border](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_13.png "chart(data, border: true)")
86
+
87
+ ##### `:height` changes the height of the graph (default: `250`).
88
+
89
+ ![14-height](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_14.png "chart(data, height: 150)")
90
+
91
+ Multiple series
92
+ ---------------
93
+
94
+ By providing multiple key/values `data` to the `chart` method, you can plot multiple series on a graph.
95
+
96
+ For instance, the following code generates the graph below:
97
+
98
+ ```ruby
99
+ data = {safari: {2013 => 43.2, 2014 => 46.1, 2015 => 50.7},
100
+ firefox: {2013 => 56.8, 2014 => 53.9, 2015 => 49.3}}
101
+ chart data, labels: true, format: :percentage
102
+ ```
103
+
104
+ ![15-multiple-columns](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_15.png "chart(data, labels: true, format: :percentage)")
105
+
106
+ When plotting multiple series, the option `type: :stack` can be set to display stacked columns:
107
+
108
+ ![16-multiple-stacks](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_16.png "chart(data, type: :stack, format: :percentage)")
109
+
110
+ Finally, the option `type: :two_axis` can be set to display two separate axes in your series belong to two different domains.
111
+
112
+ For instance, the following code generates the graph below:
113
+
114
+ ```ruby
115
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 88},
116
+ earnings: {2013 => 104_323, 2014 => 27_234, 2015 => 14_123}}
117
+ chart data, type: :two_axis
118
+ ```
119
+
120
+ ![17-two-axis](https://raw.githubusercontent.com/fullscreen/squid/master/examples/screenshots/readme_17.png "chart(data, type: :two_axis)")
121
+
122
+ How to install
123
+ ==============
124
+
125
+ Squid requires **Ruby 2.1 or higher**.
126
+ If used in a Rails project, requires **Rails 4.0 or higher**.
127
+
128
+ To include in your project, add `gem 'squid', github: 'fullscreen/squid'` to the `Gemfile` file of your Ruby project.
129
+
130
+ How to generate the manual
131
+ ==========================
132
+
133
+ `rake manual`
134
+
135
+ How to contribute
136
+ =================
137
+
138
+ If you’ve made it this far in the README… thanks! :v:
139
+
140
+ I’m about to release version 1 of this gem.
141
+ Feel free to try it out and send issues or pull requests.
142
+
143
+ All pull requests will have to make Travis and Code Climate happy in order to be accepted. :kissing_smiling_eyes:
144
+
145
+ You can also run the tests locally with `bundle exec rspec`.
146
+
147
+ Happy hacking!
data/Rakefile CHANGED
@@ -1 +1,26 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc 'Generate the manual'
4
+ task :manual do
5
+ print 'Building manual... '
6
+ require_relative 'examples/manual'
7
+ puts 'DONE!'
8
+ end
9
+
10
+ desc 'Generate the readme'
11
+ task :readme do
12
+ print 'Building readme... '
13
+ require_relative 'examples/readme'
14
+ print 'Extracting screenshots...'
15
+ `convert -density 175 -colorspace sRGB readme.pdf -resize 50% -quality 100 -crop 744x320+0+280 examples/screenshots/readme_%02d.png`
16
+ puts 'DONE!'
17
+ end
18
+
19
+
20
+ require "rspec/core/rake_task"
21
+ require "rspec/core/version"
22
+
23
+ desc "Run all examples"
24
+ RSpec::Core::RakeTask.new :spec
25
+
26
+ task default: [:spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'squid'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'squid'
2
+ require 'prawn/manual_builder'
3
+ Prawn::ManualBuilder.manual_dir = File.dirname(__FILE__)
4
+ Prawn::Font::AFM.hide_m17n_warning = true
5
+ Prawn::ManualBuilder::Example.generate 'manual.pdf', skip_page_creation: true do
6
+ load_package 'squid'
7
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, type: :point
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, type: :line, line_widths: [10]
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, colors: ['5d9648']
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, steps: 6
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, ticks: false
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, baseline: false
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, every: 2
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, legend: false
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, legend: {offset: 50}
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182/3.62, 2014 => 46/3.62, 2015 => 134/3.62}}
4
+ chart data, format: :percentage
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, labels: true
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, border: true
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
4
+ chart data, height: 150
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {safari: {2013 => 43.2, 2014 => 46.1, 2015 => 50.7}, firefox: {2013 => 56.8, 2014 => 53.9, 2015 => 49.3}}
4
+ chart data, labels: true, format: :percentage
5
+ end
@@ -0,0 +1,5 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {safari: {2013 => 43.2, 2014 => 46.1, 2015 => 50.7}, firefox: {2013 => 56.8, 2014 => 53.9, 2015 => 49.3}}
4
+ chart data, type: :stack, format: :percentage
5
+ end
@@ -0,0 +1,7 @@
1
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
2
+ Prawn::ManualBuilder::Example.generate(filename) do
3
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 88}, earnings: {2013 => 104_323, 2014 => 27_234, 2015 => 14_123}}
4
+ chart data, type: :two_axis
5
+ end
6
+
7
+
@@ -0,0 +1,28 @@
1
+ Prawn::ManualBuilder::Example.generate 'readme.pdf' do
2
+ package 'readme' do |p|
3
+ p.name = 'Readme'
4
+
5
+ p.intro do
6
+ end
7
+
8
+ p.section 'Single series' do |s|
9
+ s.example '01-basic'
10
+ s.example '02-type-point'
11
+ s.example '03-type-line'
12
+ s.example '04-color'
13
+ s.example '05-gridlines'
14
+ s.example '06-ticks'
15
+ s.example '07-baseline'
16
+ s.example '08-every'
17
+ s.example '09-legend'
18
+ s.example '10-legend-offset'
19
+ s.example '11-format'
20
+ s.example '12-labels'
21
+ s.example '13-border'
22
+ s.example '14-height'
23
+ s.example '15-multiple-columns'
24
+ s.example '16-multiple-stacks'
25
+ s.example '17-two-axis'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'squid'
2
+ require 'prawn/manual_builder'
3
+ Prawn::ManualBuilder.manual_dir = File.dirname(__FILE__)
4
+ Prawn::Font::AFM.hide_m17n_warning = true
5
+ Prawn::ManualBuilder::Example.generate 'readme.pdf', skip_page_creation: true do
6
+ load_package 'readme'
7
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> plots a baseline at the bottom of the graph.
2
+ #
3
+ # You can use the <code>:baseline</code> option to disable this behavior.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 802000000000000000}}
8
+ chart data, baseline: false, format: :float
9
+ end
@@ -0,0 +1,9 @@
1
+ # Creating graphs with Squid is easy. Just use the <code>chart</code> method.
2
+ #
3
+ # Provide a hash containing the data of the series and plot it with <code>chart</code>.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 134}}
8
+ chart data
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> is not plotted with an outer border.
2
+ #
3
+ # You can use the <code>:border</code> option to enable this behavior.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {Safari: 45.20001, Firefox: 33.3999, Chrome: 21.4}}
8
+ chart data, border: true
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> plots a graph for each series.
2
+ #
3
+ # Provide multiple key/value pairs to <code>:data</code> to plot multiple series.
4
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
5
+ Prawn::ManualBuilder::Example.generate(filename) do
6
+ data = {views: {2013 => 182, 2014 => 46, 2015 => 88},
7
+ uniques: {2013 => 104, 2014 => -27, 2015 => 14}}
8
+ chart data, labels: true
9
+ end
@@ -0,0 +1,11 @@
1
+ # By default, <code>chart</code> plots every category on the baseline.
2
+ #
3
+ # You can use the <code>:every</code> option to change this behavior.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {'Jan 1' => 12, 'Jan 2' => 13, 'Jan 3' => 21, 'Jan 4' => 42,
8
+ 'Jan 5' => 32, 'Jan 6' => 45, 'Jan 7' => 62, 'Jan 8' => 22, 'Jan 9' => 31,
9
+ 'Jan 10' => 11, 'Jan 11' => 40, 'Jan 12' => 6, 'Jan 13' => 9}}
10
+ chart data, every: 3
11
+ end
@@ -0,0 +1,9 @@
1
+ # You can specify the format of the axis values with the <code>:format</code> option.
2
+ #
3
+ # Valid options are: <code>:percentage</code>, <code>:currency</code>, <code>:seconds</code>, <code>:float</code>.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {Safari: 45.20001, Firefox: 33.3999, Chrome: 21.4}}
8
+ chart data, format: :percentage
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> plots 5 equidistant horizontal gridlines.
2
+ #
3
+ # You can use the <code>:steps</code> option to change this number.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {2013 => 182000, 2014 => -46000, 2015 => 102000}}
8
+ chart data, steps: 8
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> generates charts with a height of 250.
2
+ #
3
+ # You can use the <code>:height</code> option to manually set the height.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {2013 => 18.2, 2014 => 4.6, 2015 => 10.2}}
8
+ chart data, height: 350
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> does not write value labels on the chart.
2
+ #
3
+ # You can use the <code>:labels</code> option to enable this behavior.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {a_very_long_label_to_test_padding_with_labels: {2013 => 182000, 2014 => -182000, 2015 => 182000}}
8
+ chart data, labels: true
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> adds a legend in the top-right corner.
2
+ #
3
+ # You can use the <code>:legend</code> option to disable this behavior.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {2013 => 182, 2014 => 46}, uniques: {2013 => 94, 2014 => 27}}
8
+ chart data, legend: false
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> adds a legend in the top-right corner.
2
+ #
3
+ # You can use the <code>:legend</code> option to change the position of the legend.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {2013 => 182, 2014 => 46}, uniques: {2013 => 94, 2014 => 27}}
8
+ chart data, legend: {offset: 50}
9
+ end
@@ -0,0 +1,9 @@
1
+ # By default, <code>chart</code> plots a column chart.
2
+ #
3
+ # You can use the <code>:type</code> option to plot a line chart instead.
4
+ #
5
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
+ Prawn::ManualBuilder::Example.generate(filename) do
7
+ data = {views: {Safari: 45.20001, Firefox: 63.3999, Chrome: 21.4}}
8
+ chart data, type: :line
9
+ end