graphene 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -51,6 +51,15 @@ See Graphene.percentages for more info.
51
51
 
52
52
  Same as percentages above, except that subtotals are returned instead. See Graphene.subtotals for more info.
53
53
 
54
+ == Adding a dimension
55
+
56
+ Marty, you're not thinking fourth-dimensionally!
57
+
58
+ puts Graphene.percentages(logs, :browser).over(:date)
59
+ => {#<Date: 2012-07-22> => [["Firefox", 45], ["Chrome", 40], ["Internet Explorer", 15]],
60
+ #<Date: 2012-07-23> => [["Firefox", 41], ["Chrome", 40], ["Internet Explorer", 19]],
61
+ #<Date: 2012-07-24> => [["Chrome", 50], ["Firefox", 40], ["Internet Explorer", 10]]}
62
+
54
63
  == Tablizer
55
64
 
56
65
  Integration with the tablizer gem provides quick ASCII tables.
@@ -89,7 +98,11 @@ Provides helpers for generating Gruff graphs. Requires the "gruff" Ruby gem.
89
98
  end
90
99
  end
91
100
 
92
- See Graphene::OneDGraphs and Graphene::TwoDGraphs for more types and examples. See http://gruff.rubyforge.org/classes/Gruff/Base.html for more Gruff options.
101
+ See Graphene::OneDGraphs and Graphene::TwoDGraphs for more types and examples.
102
+
103
+ See http://www.ruby-doc.org/gems/docs/f/fhs-gruff-0.3.6.2/README_txt.html for more on Gruff.
104
+ Specifically, http://www.ruby-doc.org/gems/docs/f/fhs-gruff-0.3.6.2/Gruff/Base.html will let
105
+ you know many things that can be customized in the optional block.
93
106
 
94
107
  == TODO
95
108
 
@@ -316,6 +316,80 @@ module Graphene
316
316
  end
317
317
  alias_method :net_chart, :net_graph
318
318
 
319
+ # Returns a Gruff::Dot object with the stats set.
320
+ #
321
+ # Optionally you may pass a file path and graph title. If you pass a file path, the graph will
322
+ # be written to file automatically. Otherwise, you would call "write('/path/to/graph.png')" on the
323
+ # returned graph object.
324
+ #
325
+ # If you pass a block, it will be called, giving you access to the Gruff::Dot object before it is
326
+ # written to file (that is, if you also passed a file path). It will also give you access to a Proc
327
+ # for labeling the X axis.
328
+ #
329
+ # Example 1:
330
+ #
331
+ # Graphene.percentages(logs, :browser).over(:date).dot_graph('/path/to/browser-share.png', 'Browser Share')
332
+ #
333
+ # Example 2:
334
+ #
335
+ # Graphene.subtotals(logs, :browser).over(:date).dot_graph('/path/to/browser-share.png') do |chart, labeler|
336
+ # chart.title = 'Browser Share'
337
+ # chart.font = '/path/to/font.ttf'
338
+ # chart.theme = pie.theme_37signals
339
+ # end
340
+ #
341
+ # Example 3:
342
+ #
343
+ # Graphene.subtotals(logs, :browser).over(:date).dot_graph('/path/to/browser-share.png') do |chart, labeler|
344
+ # chart.title = 'Browser Share'
345
+ #
346
+ # # Both the 10 and the block are optional.
347
+ # # - "10" means that only every 10'th label will be printed. Otherwise, each would be.
348
+ # # - The block is passed each label (the return value of the "over attribute") and may return a formatted version.
349
+ # labeler.call(10) do |date|
350
+ # date.strftime('%m/%d/%Y')
351
+ # end
352
+ # end
353
+ #
354
+ # Example 4:
355
+ #
356
+ # Graphene.percentages(logs, :platform, :browser).over(->(l) { l.date.strftime('%m/%Y') }).dot_graph('/path/to/os-browser-share.png', 'OS / Browser Share by Month')
357
+ #
358
+ def dot_graph(path=nil, title=nil, &block)
359
+ Graphene.gruff do
360
+ graph(Gruff::Dot.new, path, title, &block)
361
+ end
362
+ end
363
+ alias_method :dot_chart, :dot_graph
364
+
365
+ # Returns a Gruff::AccumulatorBar object with the stats set. This is different than most other graphs in that it may only
366
+ # have one row of data. For example, if you limit the browser to Firefox, it could show the relative gains in Firefox
367
+ # usage over time. You might start out with:
368
+ #
369
+ # Optionally you may pass a file path and graph title. If you pass a file path, the graph will
370
+ # be written to file automatically. Otherwise, you would call "write('/path/to/graph.png')" on the
371
+ # returned graph object.
372
+ #
373
+ # If you pass a block, it will be called, giving you access to the Gruff::AccumulatorBar object before it is
374
+ # written to file (that is, if you also passed a file path). It will also give you access to a Proc
375
+ # for labeling the X axis.
376
+ #
377
+ # Example:
378
+ #
379
+ # logs = SomeLogParser.parse('/logs/*').select { |log| log.browser == 'Firefox' }
380
+ # Graphene.subtotals(logs, :browser).over(:date).accumulator_bar_graph('/path/to/firefox-share.png', 'Firefox Share')
381
+ #
382
+ def accumulator_bar_graph(path=nil, title=nil, &block)
383
+ Graphene.gruff do
384
+ begin
385
+ graph(Gruff::AccumulatorBar.new, path, title, &block)
386
+ rescue Gruff::IncorrectNumberOfDatasetsException => e
387
+ raise GrapheneException, "An Accumulator Bar Graph may only have one row of data - #{e.class.name}"
388
+ end
389
+ end
390
+ end
391
+ alias_method :accumulator_bar_chart, :accumulator_bar_graph
392
+
319
393
  private
320
394
 
321
395
  # Builds a graph
@@ -1,4 +1,4 @@
1
1
  module Graphene
2
2
  # Version number
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jordan Hollinger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-07-22 00:00:00 -04:00
17
+ date: 2012-07-23 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -43,12 +43,11 @@ files:
43
43
  - lib/graphene.rb
44
44
  - lib/graphene/graphene.rb
45
45
  - lib/graphene/gruff.rb
46
- - lib/graphene/gruff_helpers.rb
46
+ - lib/graphene/version.rb
47
47
  - lib/graphene/percentages.rb
48
48
  - lib/graphene/result_set.rb
49
49
  - lib/graphene/subtotals.rb
50
50
  - lib/graphene/tablizer.rb
51
- - lib/graphene/version.rb
52
51
  - lib/graphene/over_x.rb
53
52
  - lib/graphene/lazy_enumerable.rb
54
53
  - README.rdoc
File without changes