charted 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +5 -12
  2. data/lib/charted.rb +24 -23
  3. metadata +2 -18
data/README.md CHANGED
@@ -38,14 +38,10 @@ Then initialize the database:
38
38
 
39
39
  $ charted --migrate
40
40
 
41
- The app should be mounted to `/charted` path on your domain. Then in your app,
42
- include the script right before the closing `</body>` tag:
41
+ The app should be mounted to `/charted` path on your domain
43
42
 
44
- <script src="/charted/script.js" async></script>
45
-
46
- If you concatenate your JavaScript, you can generate the `script.js` file and
47
- add it to your project. The downside being when you update the charted gem,
48
- you'll also have to remember to update the JavaScript:
43
+ In your app, generate a `charted.js` file. This can be safely concatenated with
44
+ you other JavaScript assets.
49
45
 
50
46
  $ charted --js > /path/to/my/project/public/charted.js
51
47
 
@@ -54,7 +50,7 @@ Updating
54
50
 
55
51
  $ gem install charted
56
52
 
57
- If you concatenated the JavaScript, you may need to do it again:
53
+ You may need to generate a `charted.js` file again:
58
54
 
59
55
  $ charted --js > /path/to/my/project/public/charted.js
60
56
 
@@ -135,10 +131,7 @@ TODO
135
131
  ====
136
132
 
137
133
  * don't catch-all load error, makes debugging config.ru difficult
138
- * fix sorting
139
- * fix search terms
140
- * consider removing colored titles
141
- * shorten lists (too many single entries) on dashboard, add --full?
134
+ * add --full or --single
142
135
  * browser version (IE6, IE7, IE8...) ?
143
136
  * handle 255 string length limit
144
137
 
@@ -13,14 +13,13 @@ require 'geoip'
13
13
  require 'pony'
14
14
  require 'useragent'
15
15
  require 'search_terms'
16
- require 'colorize'
17
16
  require 'dashes'
18
17
 
19
18
  DataMapper::Model.raise_on_save_failure = true
20
19
  DataMapper::Property::String.length(255)
21
20
 
22
21
  module Charted
23
- VERSION = '0.0.5'
22
+ VERSION = '0.0.6'
24
23
  GEOIP = GeoIP.new("#{File.dirname(__FILE__)}/../geoip.dat")
25
24
  JS_FILE = "#{File.dirname(__FILE__)}/../public/charted/script.js"
26
25
 
@@ -338,17 +337,15 @@ module Charted
338
337
  max_width = [`tput cols`.to_i / 2, 60].min
339
338
  chart = Dashes::Chart.new.
340
339
  max_width(max_width).
341
- title("Total Visits".colorize(:light_green))
340
+ title("Total Visits")
342
341
  chart2 = Dashes::Chart.new.
343
342
  max_width(max_width).
344
- title("Unique Visits".colorize(:light_green))
343
+ title("Unique Visits")
345
344
  table = Dashes::Table.new.
346
345
  max_width(max_width).
347
346
  spacing(:min, :min, :max).
348
347
  align(:right, :right, :left).
349
- row('Total'.colorize(:light_blue),
350
- 'Unique'.colorize(:light_blue),
351
- 'Visits'.colorize(:light_green)).
348
+ row('Total', 'Unique', 'Visits').
352
349
  separator
353
350
  (0..11).each do |delta|
354
351
  date = Charted.prev_month(Date.today, delta)
@@ -374,9 +371,7 @@ module Charted
374
371
  max_width(max_width).
375
372
  spacing(:min, :min, :max).
376
373
  align(:right, :right, :left).
377
- row('Total'.colorize(:light_blue),
378
- '%'.colorize(:light_blue),
379
- column.colorize(:light_green)).separator
374
+ row('Total', '%', column).separator
380
375
  rows = []
381
376
  total = @site.send(type).count(field.not => nil)
382
377
  @site.send(type).aggregate(field, :all.count).each do |label, count|
@@ -385,52 +380,49 @@ module Charted
385
380
  label = "#{label[0..37]}..." if label.length > 40
386
381
  rows << [format(count), "#{((count / total.to_f) * 100).round}%", label]
387
382
  end
388
- rows.sort_by { |r| r[1] }.reverse.each { |row| table.row(*row) }
383
+ add_truncated(table, rows)
389
384
  nodes << table
390
385
  end
391
386
  table = Dashes::Table.new.
392
387
  max_width(max_width).
393
388
  spacing(:min, :min, :max).
394
389
  align(:right, :right, :left).
395
- row('Total'.colorize(:light_blue),
396
- 'Unique'.colorize(:light_blue),
397
- 'Events'.colorize(:light_green)).separator
390
+ row('Total', 'Unique', 'Events').
391
+ separator
398
392
  rows = []
399
393
  @site.events.aggregate(:label, :all.count).each do |label, count|
400
394
  unique = @site.visitors.count(:events => {label: label})
401
395
  rows << [format(count), format(unique), label]
402
396
  end
403
- rows.sort_by { |r| r[1] }.reverse.each { |row| table.row(*row) }
397
+ add_truncated(table, rows)
404
398
  nodes << table
405
399
 
406
400
  table = Dashes::Table.new.
407
401
  max_width(max_width).
408
402
  spacing(:min, :min, :max).
409
403
  align(:right, :right, :left).
410
- row('Start'.colorize(:light_blue),
411
- 'End'.colorize(:light_blue),
412
- 'Conversions'.colorize(:light_green)).separator
404
+ row('Start', 'End', 'Conversions').
405
+ separator
413
406
  rows = []
414
407
  @site.conversions.aggregate(:label, :all.count).each do |label, count|
415
408
  ended = @site.conversions.count(label: label, :ended_at.not => nil)
416
409
  rows << [format(count), format(ended), label]
417
410
  end
418
- rows.sort_by { |r| r[1] }.reverse.each { |row| table.row(*row) }
411
+ add_truncated(table, rows)
419
412
  nodes << table
420
413
 
421
414
  table = Dashes::Table.new.
422
415
  max_width(max_width).
423
416
  spacing(:min, :min, :max).
424
417
  align(:right, :right, :left).
425
- row('Start'.colorize(:light_blue),
426
- 'End'.colorize(:light_blue),
427
- 'Experiments'.colorize(:light_green)).separator
418
+ row('Start', 'End', 'Experiments').
419
+ separator
428
420
  rows = []
429
421
  @site.experiments.aggregate(:label, :bucket, :all.count).each do |label, bucket, count|
430
422
  ended = @site.experiments.count(label: label, bucket: bucket, :ended_at.not => nil)
431
423
  rows << [format(count), format(ended), "#{label}: #{bucket}"]
432
424
  end
433
- rows.sort_by { |r| r[1] }.reverse.each { |row| table.row(*row) }
425
+ add_truncated(table, rows)
434
426
  nodes << table
435
427
 
436
428
  nodes.reject! do |node|
@@ -498,6 +490,15 @@ module Charted
498
490
  def format(num)
499
491
  num.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
500
492
  end
493
+
494
+ def add_truncated(table, rows)
495
+ rows = rows.sort_by { |r| r[1].to_i }.reverse
496
+ if rows.length > 12
497
+ rows = rows[0..11]
498
+ rows << ['...', '...', '...']
499
+ end
500
+ rows.each { |row| table.row(*row) }
501
+ end
501
502
  end
502
503
 
503
504
  class ExitError < RuntimeError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charted
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: .
11
11
  cert_chain: []
12
- date: 2013-03-17 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -107,22 +107,6 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: colorize
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
110
  - !ruby/object:Gem::Dependency
127
111
  name: dashes
128
112
  requirement: !ruby/object:Gem::Requirement