Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updating readme and highcharts methods

  • Loading branch information...
commit 4f771ebafe0b3d9cf520c12b1f9b07b546ae10b9 1 parent 77c2f77
@nictrix authored
Showing with 47 additions and 29 deletions.
  1. +8 −4 README.markdown
  2. +39 −25 lib/highcharts.rb
View
12 README.markdown
@@ -1,6 +1,6 @@
## Information
-Highcharts Gem to allow for easily extending other classes in your application to create highchart's json
+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)
## Installation
@@ -8,16 +8,20 @@ Highcharts Gem to allow for easily extending other classes in your application t
## Using
-do a include in your class, example below:
+do an include in your class, example below:
class Object
include Highcharts::Charting
end
+you can call a couple other methods:
+
+ Object.new.x_choices (all possible choices this gem can provide)
+ Object.new.style_choices (all possible style choices highcharts provides)
+ Object.new.humanize_categories (provides human readable category labels for datetimes)
+
## Roadmap
-- Use https://github.com/seejohnrun/ice_cube for times
-- Make the to_hc method more dynamic (don't call each attribute manually)
- Give examples of html forms
- Give examples of javascript functions
- Provide function to include highcharts javascript automatically at any version within html
View
64 lib/highcharts.rb
@@ -10,7 +10,7 @@ module Charting
def initialize(user_supplied_hash={})
standard_hash = { title:"", subtitle:"", drilldown:"", start:"", end:"", style:"",
- x:"", y:"", maximum:"", minimum:"", sla:0, series:[], categories:[] }
+ x:"", y:"", maximum:"", minimum:"", sla:0, series:[], categories:[], color:"" }
user_supplied_hash = standard_hash.merge(user_supplied_hash)
@@ -21,11 +21,11 @@ def initialize(user_supplied_hash={})
end
end
- def self.get_x_axis_choices
+ def self.x_choices
return [ "year", "month", "week", "day", "hour", "minute", "second" ]
end
- def self.get_style_choices
+ def self.style_choices
return [ "line", "spline", "area", "areaspline", "column", "bar", "pie", "scatter" ]
end
@@ -43,31 +43,45 @@ def to_hc
def create_array_of_dates
all_dates = IceCube::Schedule.new(Time.parse(@start), :end_time => Time.parse(@end))
- case @x
- when "month"
- all_dates.add_recurrence_rule IceCube::Rule.monthly
- rule = "%m-%Y"
- when "week"
- all_dates.add_recurrence_rule IceCube::Rule.weekly
- rule = "%m-%d"
- when "day"
- all_dates.add_recurrence_rule IceCube::Rule.daily
- rule = "%m-%d"
- when "hour"
- all_dates.add_recurrence_rule IceCube::Rule.hourly
- rule = "%I%p"
- when "minute"
- all_dates.add_recurrence_rule IceCube::Rule.minutely
- rule = "%I:%M%p"
- when "second"
- all_dates.add_recurrence_rule IceCube::Rule.secondly
- rule = "%I:%M:%S%p"
- end
+ rule = case @x
+ when "month"
+ IceCube::Rule.monthly
+ when "week"
+ IceCube::Rule.weekly
+ when "day"
+ IceCube::Rule.daily
+ when "hour"
+ IceCube::Rule.hourly
+ when "minute"
+ IceCube::Rule.minutely
+ when "second"
+ IceCube::Rule.secondly
+ end
+
+ all_dates.add_recurrence_rule rule
+ @categories = all_dates.all_occurrences
+ end
+
+ def humanize_categories
+ label = case @x
+ when "month"
+ "%m-%Y"
+ when "week", "day"
+ "%m-%d"
+ when "hour"
+ "%I%p"
+ when "minute"
+ "%I:%M%p"
+ when "second"
+ "%I:%M:%S%p"
+ end
- all_dates.all_occurrences.each do |date|
- @categories << date.strftime(rule)
+ temp_categories = []
+ @categories.each do |date|
+ temp_categories << date.strftime(label)
end
+ @categories = temp_categories
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.