-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4169fd7
commit 79da7a5
Showing
2 changed files
with
16 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
module Grafico | ||
module Helpers | ||
GRAPH_TYPES = %w[LineGraph AreaGraph StackGraph StreamGraph BarGraph StackedBarGraph HorizontalBarGraph SparkLine SparkBar] | ||
|
||
def graph_tag(graph_type, element, data, options = {}) | ||
args = [] | ||
args << data.to_json | ||
args << options.to_json unless options.empty? | ||
javascript_tag "var #{options[:variable_name] || (element + graph_type)} = new Grafico.#{graph_type}($('#{element}'), #{args.join(',')});" | ||
end | ||
|
||
def line_graph_tag(element, data, options = {}) | ||
graph_tag 'LineGraph', element, data, options | ||
end | ||
|
||
def sparkline_tag(element, data, options = {}) | ||
graph_tag 'SparkLine', element, data, options | ||
def self.included(receiver) | ||
GRAPH_TYPES.each do |graph| | ||
receiver.instance_eval do | ||
define_method(:"#{graph.underscore}_tag") do |e, d, *opts| | ||
opts = opts.first || Hash.new | ||
graph_tag(graph, e, d, opts) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters