fusioncharts-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +196 -0
- data/Rakefile +1 -0
- data/fusioncharts-rails.gemspec +27 -0
- data/lib/fusioncharts-rails.rb +4 -0
- data/lib/fusioncharts/rails.rb +5 -0
- data/lib/fusioncharts/rails/chart.rb +123 -0
- data/lib/fusioncharts/rails/version.rb +5 -0
- data/lib/templates/chart.erb +11 -0
- data/spec/chart_spec.rb +189 -0
- data/spec/spec_helper.rb +97 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8324958bdbd017e2ee8cdb65c07700ded0040187
|
4
|
+
data.tar.gz: e96f6ae45bd53c1ff7bf7f98c6d42b907e52f859
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c1715ac12c125797527b9f7d6947c4cde4c928fd773c2e94ed1aa72db967175719abb0f62e13d77a47ad755af8b76a3af51e2c5d0fdc63d8cbfca36e4bb1b63
|
7
|
+
data.tar.gz: b3d5935b124798d36297c14dc9bd09445b8663b95c0eeb7502e8dd5442c07620220abcab550a65be9d7fac05394948ad77988582d6d02ed6d4eec62f482e8d7b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Swaroop SM
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# Fusioncharts Rails
|
2
|
+
|
3
|
+
Rails plugin to build charts using FusionCharts. [http://www.fusioncharts.com](http://www.fusioncharts.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fusioncharts-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fusioncharts-rails
|
18
|
+
|
19
|
+
## Getting Started
|
20
|
+
You will have to download the latest fusioncharts library at [http://www.fusioncharts.com/download/](http://www.fusioncharts.com/download/). Once you have downloaded and extracted, copy the `javascript` files into `vendor/assets/javascripts/fusioncharts/`.
|
21
|
+
|
22
|
+
Require the following lines in the `app/assets/javascripts/application.js`
|
23
|
+
~~~
|
24
|
+
//= require fusioncharts/fusioncharts
|
25
|
+
//= require fusioncharts/fusioncharts.charts
|
26
|
+
//= require fusioncharts/themes/fusioncharts.theme.fint
|
27
|
+
~~~
|
28
|
+
|
29
|
+
## Usage Guide
|
30
|
+
|
31
|
+
### 1. Creating a chart:
|
32
|
+
Create the FusionCharts object in the controller action like the following:
|
33
|
+
|
34
|
+
~~~
|
35
|
+
|
36
|
+
#Filename: app/controllers/dashboard_controller.rb
|
37
|
+
|
38
|
+
class DashboardController < ApplicationController
|
39
|
+
|
40
|
+
def index
|
41
|
+
|
42
|
+
@chart = Fusioncharts::Chart.new({
|
43
|
+
width: "600",
|
44
|
+
height: "400",
|
45
|
+
type: "mscolumn2d",
|
46
|
+
renderAt: "chartContainer",
|
47
|
+
dataSource: {
|
48
|
+
chart: {
|
49
|
+
caption: "Comparison of Quarterly Revenue",
|
50
|
+
subCaption: "Harry's SuperMart",
|
51
|
+
xAxisname: "Quarter",
|
52
|
+
yAxisName: "Amount ($)",
|
53
|
+
numberPrefix: "$",
|
54
|
+
theme: "fint",
|
55
|
+
exportEnabled: "1",
|
56
|
+
},
|
57
|
+
categories: [{
|
58
|
+
category: [
|
59
|
+
{ label: "Q1" },
|
60
|
+
{ label: "Q2" },
|
61
|
+
{ label: "Q3" },
|
62
|
+
{ label: "Q4" }
|
63
|
+
]
|
64
|
+
}],
|
65
|
+
dataset: [
|
66
|
+
{
|
67
|
+
seriesname: "Previous Year",
|
68
|
+
data: [
|
69
|
+
{ value: "10000" },
|
70
|
+
{ value: "11500" },
|
71
|
+
{ value: "12500" },
|
72
|
+
{ value: "15000" }
|
73
|
+
]
|
74
|
+
},
|
75
|
+
{
|
76
|
+
seriesname: "Current Year",
|
77
|
+
data: [
|
78
|
+
{ value: "25400" },
|
79
|
+
{ value: "29800" },
|
80
|
+
{ value: "21800" },
|
81
|
+
{ value: "26800" }
|
82
|
+
]
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
})
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
~~~
|
93
|
+
|
94
|
+
### 2. Render the chart
|
95
|
+
In order to render the chart, you can use the `render` method in the specific view
|
96
|
+
|
97
|
+
~~~
|
98
|
+
|
99
|
+
<!-- Filename: app/views/dashboard/index.html.erb -->
|
100
|
+
|
101
|
+
<h3>My Chart</h3>
|
102
|
+
<div id="chartContainer"><%= @chart.render() %></div>
|
103
|
+
|
104
|
+
~~~
|
105
|
+
|
106
|
+
### 3. Note
|
107
|
+
- The `dataSource` method can take accept data which is one of the following formats:
|
108
|
+
- Valid Ruby Hash
|
109
|
+
- JSON String
|
110
|
+
- XML String
|
111
|
+
- Also look at [FusionCharts Export Handler](https://github.com/fusioncharts/rails-exporter) to understand how to import a chart to different image formats and to PDF.
|
112
|
+
|
113
|
+
## API Methods
|
114
|
+
|
115
|
+
### Set width of the chart.
|
116
|
+
~~~
|
117
|
+
@chart.width = 600
|
118
|
+
~~~
|
119
|
+
|
120
|
+
### Set height of the chart.
|
121
|
+
~~~
|
122
|
+
@chart.height = 400
|
123
|
+
~~~
|
124
|
+
|
125
|
+
### Set the chart type.
|
126
|
+
~~~
|
127
|
+
@chart.type = "column2d"
|
128
|
+
~~~
|
129
|
+
|
130
|
+
### Set the datasource format of the chart.
|
131
|
+
~~~
|
132
|
+
@chart.dataFormat = "json"
|
133
|
+
~~~
|
134
|
+
|
135
|
+
### Set the datasource format of the chart.
|
136
|
+
~~~
|
137
|
+
@chart.dataSource = {
|
138
|
+
chart: {
|
139
|
+
caption: "Comparison of Quarterly Revenue",
|
140
|
+
subCaption: "Harry's SuperMart",
|
141
|
+
xAxisname: "Quarter",
|
142
|
+
yAxisName: "Amount ($)",
|
143
|
+
numberPrefix: "$",
|
144
|
+
theme: "fint",
|
145
|
+
exportEnabled: "1",
|
146
|
+
},
|
147
|
+
categories: [{
|
148
|
+
category: [
|
149
|
+
{ label: "Q1" },
|
150
|
+
{ label: "Q2" },
|
151
|
+
{ label: "Q3" },
|
152
|
+
{ label: "Q4" }
|
153
|
+
]
|
154
|
+
}],
|
155
|
+
dataset: [
|
156
|
+
{
|
157
|
+
seriesname: "Previous Year",
|
158
|
+
data: [
|
159
|
+
{ value: "10000" },
|
160
|
+
{ value: "11500" },
|
161
|
+
{ value: "12500" },
|
162
|
+
{ value: "15000" }
|
163
|
+
]
|
164
|
+
},
|
165
|
+
{
|
166
|
+
seriesname: "Current Year",
|
167
|
+
data: [
|
168
|
+
{ value: "25400" },
|
169
|
+
{ value: "29800" },
|
170
|
+
{ value: "21800" },
|
171
|
+
{ value: "26800" }
|
172
|
+
]
|
173
|
+
}
|
174
|
+
]
|
175
|
+
}
|
176
|
+
~~~
|
177
|
+
|
178
|
+
### Set the url from where the datasource should be fetched. This must be a valid `json` data.
|
179
|
+
~~~
|
180
|
+
@chart.jsonUrl = "/data/chart.json"
|
181
|
+
~~~
|
182
|
+
|
183
|
+
### Set the url from where the datasource should be fetched. This must be a valid `xml` data.
|
184
|
+
~~~
|
185
|
+
@chart.xmlUrl = "/data/chart.xml"
|
186
|
+
~~~
|
187
|
+
|
188
|
+
### Set the DOM id where the chart should be rendered.
|
189
|
+
~~~
|
190
|
+
@chart.renderAt = "chartContainer"
|
191
|
+
~~~
|
192
|
+
|
193
|
+
### Render the chart.
|
194
|
+
~~~
|
195
|
+
@chart.render()
|
196
|
+
~~~
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fusioncharts/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fusioncharts-rails"
|
8
|
+
spec.version = Fusioncharts::Rails::VERSION
|
9
|
+
spec.authors = ["FusionCharts"]
|
10
|
+
spec.email = ["mail@labs.fusioncharts.com"]
|
11
|
+
spec.description = %q{Server Wrapper for rendering FusionCharts on Rails}
|
12
|
+
spec.summary = %q{Wrapper for fusioncharts}
|
13
|
+
spec.homepage = "https://github.com/fusioncharts/rails-wrapper"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rails", ">= 3.2"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module Fusioncharts
|
2
|
+
|
3
|
+
class Chart
|
4
|
+
|
5
|
+
include ::ActionView::Helpers::OutputSafetyHelper
|
6
|
+
|
7
|
+
attr_accessor :options
|
8
|
+
attr_reader :width, :height, :type, :renderAt, :dataSource, :dataFormat, :jsonUrl, :xmlUrl
|
9
|
+
|
10
|
+
# Constructor
|
11
|
+
def initialize(options=nil)
|
12
|
+
if options.nil?
|
13
|
+
@options = {}
|
14
|
+
else
|
15
|
+
@options = options
|
16
|
+
parse_options
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sets the width for a chart
|
21
|
+
def width=(width)
|
22
|
+
@width = width.to_s
|
23
|
+
|
24
|
+
setOption('width', @width)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sets the height for a chart
|
28
|
+
def height=(height)
|
29
|
+
@height = height.to_s
|
30
|
+
|
31
|
+
setOption('height', @height)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Set the type for a chart
|
35
|
+
def type=(type)
|
36
|
+
@type = type
|
37
|
+
|
38
|
+
setOption('type', @type)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sets the dataformat for a chart.
|
42
|
+
# Valid values are: json / xml
|
43
|
+
def dataFormat=(format)
|
44
|
+
@dataFormat = format
|
45
|
+
|
46
|
+
setOption('dataFormat', @dataFormat)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set the DOM id where the chart needs to be rendered
|
50
|
+
def renderAt=(id)
|
51
|
+
@renderAt = id
|
52
|
+
|
53
|
+
setOption('renderAt', @renderAt)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Set the datasource for the chart. It can take the followinf formats
|
57
|
+
# 1. Ruby Hash
|
58
|
+
# 2. XML string
|
59
|
+
# 3. JSON string
|
60
|
+
def dataSource=(dataSource)
|
61
|
+
@dataSource = dataSource
|
62
|
+
parse_datasource_json
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set the JSON url where data needs to be loaded
|
66
|
+
def jsonUrl=(url)
|
67
|
+
@jsonUrl = url
|
68
|
+
end
|
69
|
+
|
70
|
+
# Set the XML url where data needs to be loaded
|
71
|
+
def xmlUrl=(url)
|
72
|
+
@xmlUrl = url
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns where the chart needs to load XML data from a url
|
76
|
+
def xmlUrl?
|
77
|
+
self.xmlUrl ? true : false
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns where the chart needs to load JSON data from a url
|
81
|
+
def jsonUrl?
|
82
|
+
self.jsonUrl ? true : false
|
83
|
+
end
|
84
|
+
|
85
|
+
# Render the chart
|
86
|
+
def render
|
87
|
+
config = self.options.to_json
|
88
|
+
dataUrlFormat = self.jsonUrl? ? "json" : ( self.xmlUrl ? "xml" : nil )
|
89
|
+
template = File.read(File.expand_path("../../../templates/chart.erb", __FILE__))
|
90
|
+
renderer = ERB.new(template)
|
91
|
+
raw renderer.result(binding)
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
# Helper method to add property to the options hash
|
96
|
+
def setOption(key, value)
|
97
|
+
self.options[key] = value
|
98
|
+
|
99
|
+
return self
|
100
|
+
end
|
101
|
+
|
102
|
+
# Helper method to convert json string to Ruby hash
|
103
|
+
def parse_datasource_json
|
104
|
+
@dataFormat = "json" unless defined? @dataFormat
|
105
|
+
|
106
|
+
if !xmlUrl? or !jsonUrl?
|
107
|
+
@dataSource = JSON.parse(@dataSource) if @dataSource.is_a? String and @dataFormat == "json"
|
108
|
+
end
|
109
|
+
|
110
|
+
setOption('dataSource', @dataSource)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Helper method that converts the constructor params into instance variables
|
114
|
+
def parse_options
|
115
|
+
keys = @options.keys
|
116
|
+
|
117
|
+
keys.each{ |k| instance_variable_set "@#{k}".to_sym, @options[k] if self.respond_to? k }
|
118
|
+
parse_datasource_json
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
FusionCharts.ready(function() {
|
3
|
+
var _fc_chart = new FusionCharts(<%= config %>);
|
4
|
+
<% if(dataUrlFormat == 'json') %>
|
5
|
+
_fc_chart.setJSONUrl("<%= @jsonUrl %>")
|
6
|
+
<% elsif(dataUrlFormat == 'xml') %>
|
7
|
+
_fc_chart.setXMLUrl("<%= @xmlUrl %>")
|
8
|
+
<% end %>
|
9
|
+
_fc_chart.render();
|
10
|
+
});
|
11
|
+
</script>
|
data/spec/chart_spec.rb
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
describe Fusioncharts::Chart do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@dataSource = {
|
5
|
+
chart: {
|
6
|
+
caption: "Comparison of Quarterly Revenue",
|
7
|
+
subCaption: "Harry's SuperMart",
|
8
|
+
xAxisname: "Quarter",
|
9
|
+
yAxisName: "Amount ($)",
|
10
|
+
numberPrefix: "$",
|
11
|
+
theme: "fint",
|
12
|
+
exportEnabled: "1",
|
13
|
+
exportHandler: "/export",
|
14
|
+
exportAction: "save"
|
15
|
+
},
|
16
|
+
categories: [{
|
17
|
+
category: [
|
18
|
+
{ label: "Q1" },
|
19
|
+
{ label: "Q2" },
|
20
|
+
{ label: "Q3" },
|
21
|
+
{ label: "Q4" }
|
22
|
+
]
|
23
|
+
}],
|
24
|
+
dataset: [
|
25
|
+
{
|
26
|
+
seriesname: "Previous Year",
|
27
|
+
data: [
|
28
|
+
{ value: "10000" },
|
29
|
+
{ value: "11500" },
|
30
|
+
{ value: "12500" },
|
31
|
+
{ value: "15000" }
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
seriesname: "Current Year",
|
36
|
+
data: [
|
37
|
+
{ value: "25400" },
|
38
|
+
{ value: "29800" },
|
39
|
+
{ value: "21800" },
|
40
|
+
{ value: "26800" }
|
41
|
+
]
|
42
|
+
}
|
43
|
+
]
|
44
|
+
}
|
45
|
+
|
46
|
+
@options = {
|
47
|
+
width: "600",
|
48
|
+
height: "400",
|
49
|
+
type: "mscolumn2d",
|
50
|
+
renderAt: "chart",
|
51
|
+
dataFormat: "json",
|
52
|
+
dataSource: @dataSource
|
53
|
+
}
|
54
|
+
|
55
|
+
@options2 = {
|
56
|
+
width: "600",
|
57
|
+
height: "400",
|
58
|
+
type: "mscolumn2d",
|
59
|
+
renderAt: "chart",
|
60
|
+
dataFormat: "json"
|
61
|
+
}
|
62
|
+
|
63
|
+
@options3 = {
|
64
|
+
width: "600",
|
65
|
+
height: "400",
|
66
|
+
type: "mscolumn2d",
|
67
|
+
renderAt: "chart",
|
68
|
+
dataFormat: "json"
|
69
|
+
}
|
70
|
+
|
71
|
+
@options4 = {
|
72
|
+
width: "600",
|
73
|
+
height: "400",
|
74
|
+
type: "mscolumn2d",
|
75
|
+
renderAt: "chart",
|
76
|
+
dataFormat: "xml"
|
77
|
+
}
|
78
|
+
|
79
|
+
@options5 = {
|
80
|
+
width: "600",
|
81
|
+
height: "400",
|
82
|
+
type: "mscolumn2d",
|
83
|
+
renderAt: "chart",
|
84
|
+
dataFormat: "json"
|
85
|
+
}
|
86
|
+
|
87
|
+
@chart = Fusioncharts::Chart.new(@options)
|
88
|
+
@chart2 = Fusioncharts::Chart.new(@options2)
|
89
|
+
@chart3 = Fusioncharts::Chart.new(@options3)
|
90
|
+
@chart4 = Fusioncharts::Chart.new(@options4)
|
91
|
+
@chart5 = Fusioncharts::Chart.new(@options5)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be an instance of Chart" do
|
95
|
+
expect(@chart).to be_instance_of(Fusioncharts::Chart)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should initialize the options correctly" do
|
99
|
+
options = @chart.instance_variable_get(:@options)
|
100
|
+
|
101
|
+
expect(options).to eq(@options)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should set the width correctly" do
|
105
|
+
@chart.width = 800
|
106
|
+
|
107
|
+
expect(@chart.width).to eq("800")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should get the width correctly" do
|
111
|
+
expect(@chart.width).to eq("600")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should set the height correctly" do
|
115
|
+
@chart.height = 600
|
116
|
+
|
117
|
+
expect(@chart.height).to eq("600")
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should get the height correctly" do
|
121
|
+
expect(@chart.height).to eq("400")
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should set the chart type correctly" do
|
125
|
+
@chart.type = "mscolumn3d"
|
126
|
+
|
127
|
+
expect(@chart.type).to eq("mscolumn3d")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should get the correct chart type" do
|
131
|
+
expect(@chart.type).to eq("mscolumn2d")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should set the dataFormat correctly" do
|
135
|
+
@chart.dataFormat = "xml"
|
136
|
+
|
137
|
+
expect(@chart.dataFormat).to eq("xml")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should get the dataFormat correctly" do
|
141
|
+
expect(@chart.dataFormat).to eq("json")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should set renderAt correctly" do
|
145
|
+
@chart.renderAt = "chart-component"
|
146
|
+
|
147
|
+
expect(@chart.renderAt).to eq("chart-component")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should get renderAt correctly" do
|
151
|
+
expect(@chart.renderAt).to eq("chart")
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should set the datasource correctly" do
|
155
|
+
@chart2.dataSource = @dataSource
|
156
|
+
|
157
|
+
expect(@chart2.dataSource).to eq(@dataSource)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should get the dataSource correctly" do
|
161
|
+
expect(@chart.dataSource).to eq(@dataSource)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should set the json url correctly" do
|
165
|
+
@chart3.jsonUrl = "/data/chart.json"
|
166
|
+
|
167
|
+
expect(@chart3.jsonUrl).to eq("/data/chart.json")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should set the xml url correctly" do
|
171
|
+
@chart4.xmlUrl = "/data/chart.xml"
|
172
|
+
|
173
|
+
expect(@chart4.xmlUrl).to eq("/data/chart.xml")
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should return true for json url and false for xml url" do
|
177
|
+
@chart4.jsonUrl = "/data/chart.json"
|
178
|
+
|
179
|
+
expect(@chart4.jsonUrl?).to eq(true)
|
180
|
+
expect(@chart4.xmlUrl?).to eq(false)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should validate the datasource correctly when a json string is passed" do
|
184
|
+
@chart5.dataSource = '{"chart": {"caption": "Split of Visitors by Age Group","subCaption": "Last year","paletteColors": "#0075c2,#1aaf5d,#f2c500,#f45b00,#8e0000","bgColor": "#ffffff","showBorder": "0","use3DLighting": "0","showShadow": "0","enableSmartLabels": "0","startingAngle": "0","showPercentValues": "1","showPercentInTooltip": "0","decimals": "1","captionFontSize": "14","subcaptionFontSize": "14","subcaptionFontBold": "0","toolTipColor": "#ffffff","toolTipBorderThickness": "0","toolTipBgColor": "#000000","toolTipBgAlpha": "80","toolTipBorderRadius": "2","toolTipPadding": "5","showHoverEffect": "1","showLegend": "1","legendBgColor": "#ffffff","legendBorderAlpha": "0","legendShadow": "0","legendItemFontSize": "10","legendItemFontColor": "#666666","useDataPlotColorForLabels": "1"},"data": [{"label": "Teenage","value": "1250400"},{"label": "Adult","value": "1463300"},{"label": "Mid-age","value": "1050700"},{"label": "Senior","value": "491000"}]}'
|
185
|
+
|
186
|
+
expect(@chart5.dataSource.class).to eq(Hash)
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
|
18
|
+
require "active_support/core_ext"
|
19
|
+
require "action_view"
|
20
|
+
require "fusioncharts/rails/chart"
|
21
|
+
require 'simplecov'
|
22
|
+
|
23
|
+
SimpleCov.start
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
# rspec-expectations config goes here. You can use an alternate
|
27
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
28
|
+
# assertions if you prefer.
|
29
|
+
config.expect_with :rspec do |expectations|
|
30
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
31
|
+
# and `failure_message` of custom matchers include text for helper methods
|
32
|
+
# defined using `chain`, e.g.:
|
33
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
34
|
+
# # => "be bigger than 2 and smaller than 4"
|
35
|
+
# ...rather than:
|
36
|
+
# # => "be bigger than 2"
|
37
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
38
|
+
end
|
39
|
+
|
40
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
41
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
42
|
+
config.mock_with :rspec do |mocks|
|
43
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
44
|
+
# a real object. This is generally recommended, and will default to
|
45
|
+
# `true` in RSpec 4.
|
46
|
+
mocks.verify_partial_doubles = true
|
47
|
+
end
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
=begin
|
52
|
+
# These two settings work together to allow you to limit a spec run
|
53
|
+
# to individual examples or groups you care about by tagging them with
|
54
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
55
|
+
# get run.
|
56
|
+
config.filter_run :focus
|
57
|
+
config.run_all_when_everything_filtered = true
|
58
|
+
|
59
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
60
|
+
# For more details, see:
|
61
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
63
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
64
|
+
config.disable_monkey_patching!
|
65
|
+
|
66
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
67
|
+
# be too noisy due to issues in dependencies.
|
68
|
+
config.warnings = true
|
69
|
+
|
70
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
71
|
+
# file, and it's useful to allow more verbose output when running an
|
72
|
+
# individual spec file.
|
73
|
+
if config.files_to_run.one?
|
74
|
+
# Use the documentation formatter for detailed output,
|
75
|
+
# unless a formatter has already been configured
|
76
|
+
# (e.g. via a command-line flag).
|
77
|
+
config.default_formatter = 'doc'
|
78
|
+
end
|
79
|
+
|
80
|
+
# Print the 10 slowest examples and example groups at the
|
81
|
+
# end of the spec run, to help surface which specs are running
|
82
|
+
# particularly slow.
|
83
|
+
config.profile_examples = 10
|
84
|
+
|
85
|
+
# Run specs in random order to surface order dependencies. If you find an
|
86
|
+
# order dependency and want to debug it, you can fix the order by providing
|
87
|
+
# the seed, which is printed after each run.
|
88
|
+
# --seed 1234
|
89
|
+
config.order = :random
|
90
|
+
|
91
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
92
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
93
|
+
# test failures related to randomization by passing the same `--seed` value
|
94
|
+
# as the one that triggered the failure.
|
95
|
+
Kernel.srand config.seed
|
96
|
+
=end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fusioncharts-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FusionCharts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Server Wrapper for rendering FusionCharts on Rails
|
84
|
+
email:
|
85
|
+
- mail@labs.fusioncharts.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- fusioncharts-rails.gemspec
|
97
|
+
- lib/fusioncharts-rails.rb
|
98
|
+
- lib/fusioncharts/rails.rb
|
99
|
+
- lib/fusioncharts/rails/chart.rb
|
100
|
+
- lib/fusioncharts/rails/version.rb
|
101
|
+
- lib/templates/chart.erb
|
102
|
+
- spec/chart_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/fusioncharts/rails-wrapper
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.0.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Wrapper for fusioncharts
|
128
|
+
test_files:
|
129
|
+
- spec/chart_spec.rb
|
130
|
+
- spec/spec_helper.rb
|