highcharts 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  ## Information
2
2
 
3
- Highcharts Gem to allow for easily extending other classes in your application to create highchart's json
3
+ Highcharts Gem to allow for easily extending other classes in your application to create highchart's json. Highcharts the javascript library is located here: http://www.highcharts.com/ (this library is not affiliated with Highcharts in anyway, it helps ruby developers use the Highcharts javascript library)
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,11 +8,24 @@ Highcharts Gem to allow for easily extending other classes in your application t
8
8
 
9
9
  ## Using
10
10
 
11
- do a include in your class, example below:
11
+ do an include in your class, example below:
12
12
 
13
- class Object
14
- include Highcharts::Charting
15
- end
13
+ class Object
14
+ include Highcharts::Charting
15
+ end
16
+
17
+ you can call a couple other methods:
18
+
19
+ Object.new.x_choices (all possible choices this gem can provide)
20
+ Object.new.style_choices (all possible style choices highcharts provides)
21
+ Object.new.humanize_categories (provides human readable category labels for datetimes)
22
+
23
+ ## Roadmap
24
+
25
+ - Give examples of html forms
26
+ - Give examples of javascript functions
27
+ - Provide function to include highcharts javascript automatically at any version within html
28
+ - Provide function to include javascript functions for this data model automatically
16
29
 
17
30
  ## Contributing
18
31
 
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_runtime_dependency 'activesupport', '~>3.1.1'
19
+ s.add_runtime_dependency 'ice_cube', '0.7.7'
20
20
  end
@@ -1,12 +1,16 @@
1
1
  require "highcharts/version"
2
2
 
3
+ require 'ice_cube'
4
+ require 'time'
5
+ require 'date'
6
+
3
7
  module Highcharts
4
8
  module Charting
5
- attr_accessor :title, :subtitle, :drilldown, :start, :end, :style, :x, :y, :maximum, :minimum, :sla, :series, :categories
9
+ attr_accessor :title, :subtitle, :drilldown, :start, :end, :style, :x, :y, :maximum, :minimum, :sla, :series, :categories, :color
6
10
 
7
11
  def initialize(user_supplied_hash={})
8
12
  standard_hash = { title:"", subtitle:"", drilldown:"", start:"", end:"", style:"",
9
- x:"", y:"", maximum:"", minimum:"", sla:9999999, series:[], categories:[] }
13
+ x:"", y:"", maximum:"", minimum:"", sla:0, series:[], categories:[], color:"" }
10
14
 
11
15
  user_supplied_hash = standard_hash.merge(user_supplied_hash)
12
16
 
@@ -17,81 +21,67 @@ module Highcharts
17
21
  end
18
22
  end
19
23
 
20
- def self.get_x_axis_choices
21
- return [ "month", "week", "day" ]
24
+ def self.x_choices
25
+ return [ "year", "month", "week", "day", "hour", "minute", "second" ]
22
26
  end
23
27
 
24
- def self.get_style_choices
28
+ def self.style_choices
25
29
  return [ "line", "spline", "area", "areaspline", "column", "bar", "pie", "scatter" ]
26
30
  end
27
31
 
28
32
  def to_hc
29
33
  hc_hash = {}
30
34
 
31
- hc_hash.store(:categories,@categories)
32
- hc_hash.store(:drilldown,@drilldown)
33
- hc_hash.store(:start,@start)
34
- hc_hash.store(:end,@end)
35
- hc_hash.store(:maximum,@maximum)
36
- hc_hash.store(:minimum,@minimum)
37
- hc_hash.store(:series,@series)
38
- hc_hash.store(:sla,@sla)
39
- hc_hash.store(:style,@style)
40
- hc_hash.store(:subtitle,@subtitle)
41
- hc_hash.store(:title,@title)
42
- hc_hash.store(:x,@x)
43
- hc_hash.store(:y,@y)
44
-
45
- return hc_hash
46
- end
47
-
48
- #Need to fix this to include hours also
49
- def self.transform_x_axis(x_axis)
50
- case x_axis
51
- when 'month'
52
- return 31
53
- when 'week'
54
- return 7
55
- when 'day'
56
- return 1
57
- else
58
- return x_axis
35
+ self.instance_variables.each do |variable|
36
+ v = variable.to_s[1,variable.length]
37
+ hc_hash.store(v,self.send(v))
59
38
  end
60
- end
61
-
62
- def self.difference_between_two_dates(start_time,end_time,x_axis)
63
- x_axis = Highcharts::Charting.transform_x_axis(x_axis)
64
39
 
65
- return ((Date.strptime(end_time) - Date.strptime(start_time)) / x_axis).to_i
40
+ return hc_hash
66
41
  end
67
42
 
68
- #Need to fix this to include hours also
69
- def self.create_array_of_dates(start_time,end_time,x_axis)
70
- old_x_axis = x_axis
71
- x_axis = Highcharts::Charting.transform_x_axis(x_axis)
72
-
73
- x_amount = Highcharts::Charting.difference_between_two_dates(start_time,end_time,x_axis)
74
-
75
- categories = Array.new
76
- categories << Time.parse(start_time+" 00:00:00")
77
- for range in 1..x_amount
78
- if old_x_axis == "month"
79
- categories << Time.parse(start_time+" 00:00:00") + range.month
80
- else
81
- categories << Time.parse(start_time+" 00:00:00") + (x_axis * range).days
82
- end
83
- end
84
-
85
- return categories
43
+ def create_array_of_dates
44
+ all_dates = IceCube::Schedule.new(Time.parse(@start), :end_time => Time.parse(@end))
45
+
46
+ rule = case @x
47
+ when "month"
48
+ IceCube::Rule.monthly
49
+ when "week"
50
+ IceCube::Rule.weekly
51
+ when "day"
52
+ IceCube::Rule.daily
53
+ when "hour"
54
+ IceCube::Rule.hourly
55
+ when "minute"
56
+ IceCube::Rule.minutely
57
+ when "second"
58
+ IceCube::Rule.secondly
59
+ end
60
+
61
+ all_dates.add_recurrence_rule rule
62
+ @categories = all_dates.all_occurrences
86
63
  end
87
64
 
88
- def fix_categories
89
- x = []
90
- @categories.each do |category|
91
- x << category.strftime("%m-%d")
65
+ def humanize_categories
66
+ label = case @x
67
+ when "month"
68
+ "%m-%Y"
69
+ when "week", "day"
70
+ "%m-%d"
71
+ when "hour"
72
+ "%I%p"
73
+ when "minute"
74
+ "%I:%M%p"
75
+ when "second"
76
+ "%I:%M:%S%p"
77
+ end
78
+
79
+ temp_categories = []
80
+ @categories.each do |date|
81
+ temp_categories << date.strftime(label)
92
82
  end
93
83
 
94
- @categories = x
84
+ @categories = temp_categories
95
85
  end
96
86
  end
97
87
  end
@@ -1,3 +1,3 @@
1
1
  module Highcharts
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,35 +1,38 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: highcharts
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Nick Willever
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: &82638030 !ruby/object:Gem::Requirement
12
+
13
+ date: 2012-02-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ice_cube
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 3.1.1
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.7.7
22
24
  type: :runtime
23
- prerelease: false
24
- version_requirements: *82638030
25
- description: This allows you to extend the charting module into your classes and then
26
- use it to create json for highcharts
27
- email:
25
+ version_requirements: *id001
26
+ description: This allows you to extend the charting module into your classes and then use it to create json for highcharts
27
+ email:
28
28
  - nickwillever@gmail.com
29
29
  executables: []
30
+
30
31
  extensions: []
32
+
31
33
  extra_rdoc_files: []
32
- files:
34
+
35
+ files:
33
36
  - .gitignore
34
37
  - Gemfile
35
38
  - README.markdown
@@ -37,28 +40,32 @@ files:
37
40
  - highcharts.gemspec
38
41
  - lib/highcharts.rb
39
42
  - lib/highcharts/version.rb
40
- homepage: ''
43
+ homepage: ""
41
44
  licenses: []
45
+
42
46
  post_install_message:
43
47
  rdoc_options: []
44
- require_paths:
48
+
49
+ require_paths:
45
50
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
51
+ required_ruby_version: !ruby/object:Gem::Requirement
47
52
  none: false
48
- requirements:
49
- - - ! '>='
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
58
  none: false
54
- requirements:
55
- - - ! '>='
56
- - !ruby/object:Gem::Version
57
- version: '0'
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
58
63
  requirements: []
64
+
59
65
  rubyforge_project:
60
- rubygems_version: 1.8.11
66
+ rubygems_version: 1.8.15
61
67
  signing_key:
62
68
  specification_version: 3
63
69
  summary: Provides an extendable class for charting with high charts
64
70
  test_files: []
71
+