highcharts 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +33 -0
- data/Rakefile +1 -0
- data/highcharts.gemspec +20 -0
- data/lib/highcharts.rb +97 -0
- data/lib/highcharts/version.rb +3 -0
- metadata +64 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
## Information
|
2
|
+
|
3
|
+
Highcharts Gem to allow for easily extending other classes in your application to create highchart's json
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install highcharts
|
8
|
+
|
9
|
+
## Using
|
10
|
+
|
11
|
+
do a include in your class, example below:
|
12
|
+
|
13
|
+
class Object
|
14
|
+
include Highcharts::Charting
|
15
|
+
end
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
- Fork the project and do your work in a topic branch.
|
20
|
+
- Rebase your branch to make sure everything is up to date.
|
21
|
+
- Commit your changes and send a pull request.
|
22
|
+
|
23
|
+
## Copyright
|
24
|
+
|
25
|
+
(The MIT License)
|
26
|
+
|
27
|
+
Copyright © 2011 nictrix (Nick Willever)
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
30
|
+
|
31
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
32
|
+
|
33
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/highcharts.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "highcharts/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "highcharts"
|
7
|
+
s.version = Highcharts::VERSION
|
8
|
+
s.authors = ["Nick Willever"]
|
9
|
+
s.email = ["nickwillever@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Provides an extendable class for charting with high charts}
|
12
|
+
s.description = %q{This allows you to extend the charting module into your classes and then use it to create json for highcharts}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'activesupport', '~>3.0.5'
|
20
|
+
end
|
data/lib/highcharts.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "highcharts/version"
|
2
|
+
|
3
|
+
module Highcharts
|
4
|
+
module Charting
|
5
|
+
attr_accessor :title, :subtitle, :drilldown, :start, :end, :style, :x, :y, :maximum, :minimum, :sla, :series, :categories
|
6
|
+
|
7
|
+
def initialize(user_supplied_hash={})
|
8
|
+
standard_hash = { title:"", subtitle:"", drilldown:"", start:"", end:"", style:"",
|
9
|
+
x:"", y:"", maximum:"", minimum:"", sla:9999999, series:[], categories:[] }
|
10
|
+
|
11
|
+
user_supplied_hash = standard_hash.merge(user_supplied_hash)
|
12
|
+
|
13
|
+
user_supplied_hash.each do |key,value|
|
14
|
+
self.instance_variable_set("@#{key}", value)
|
15
|
+
self.class.send(:define_method, key, proc{self.instance_variable_get("@#{key}")})
|
16
|
+
self.class.send(:define_method, "#{key}=", proc{|x| self.instance_variable_set("@#{key}", x)})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.get_x_axis_choices
|
21
|
+
return [ "month", "week", "day" ]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_style_choices
|
25
|
+
return [ "line", "spline", "area", "areaspline", "column", "bar", "pie", "scatter" ]
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_hc
|
29
|
+
hc_hash = {}
|
30
|
+
|
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
|
59
|
+
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
|
+
|
65
|
+
return ((Date.strptime(end_time) - Date.strptime(start_time)) / x_axis).to_i
|
66
|
+
end
|
67
|
+
|
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
|
86
|
+
end
|
87
|
+
|
88
|
+
def fix_categories
|
89
|
+
x = []
|
90
|
+
@categories.each do |category|
|
91
|
+
x << category.strftime("%m-%d")
|
92
|
+
end
|
93
|
+
|
94
|
+
@categories = x
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: highcharts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Willever
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &78406480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *78406480
|
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:
|
28
|
+
- nickwillever@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- README.markdown
|
36
|
+
- Rakefile
|
37
|
+
- highcharts.gemspec
|
38
|
+
- lib/highcharts.rb
|
39
|
+
- lib/highcharts/version.rb
|
40
|
+
homepage: ''
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.11
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Provides an extendable class for charting with high charts
|
64
|
+
test_files: []
|