lazy_high_charts 1.5.2 → 1.6.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 +5 -5
- data/.travis.yml +1 -2
- data/CHANGELOG.md +15 -1
- data/GEM_VERSION +1 -1
- data/Gemfile +1 -1
- data/README.md +80 -17
- data/lazy_high_charts.gemspec +1 -1
- data/lib/lazy_high_charts.rb +1 -1
- data/lib/lazy_high_charts/high_chart.rb +8 -7
- data/lib/lazy_high_charts/high_chart_globals.rb +29 -0
- data/lib/lazy_high_charts/layout_helper.rb +88 -44
- data/lib/lazy_high_charts/options_key_filter.rb +43 -25
- data/lib/tasks/high_charts.rake +22 -3
- data/spec/dummy_sinatra/app.rb +31 -7
- data/spec/high_chart_globals_spec.rb +51 -0
- data/spec/high_chart_spec.rb +32 -31
- data/spec/lazy_high_charts_spec.rb +57 -27
- data/spec/options_key_filter_spec.rb +5 -5
- data/spec/spec_helper.rb +1 -1
- metadata +21 -30
- data/vendor/assets/javascripts/highcharts/adapters/mootools-adapter.js +0 -13
- data/vendor/assets/javascripts/highcharts/adapters/prototype-adapter.js +0 -15
- data/vendor/assets/javascripts/highcharts/highcharts-more.js +0 -50
- data/vendor/assets/javascripts/highcharts/highcharts.js +0 -285
- data/vendor/assets/javascripts/highcharts/highstock.js +0 -353
- data/vendor/assets/javascripts/highcharts/modules/exporting.js +0 -22
- data/vendor/assets/javascripts/highcharts/stock/adapters/mootools-adapter.js +0 -13
- data/vendor/assets/javascripts/highcharts/stock/adapters/prototype-adapter.js +0 -15
- data/vendor/assets/javascripts/highcharts/stock/highcharts-more.js +0 -50
- data/vendor/assets/javascripts/highcharts/stock/modules/exporting.js +0 -22
@@ -1,39 +1,57 @@
|
|
1
|
-
#
|
2
1
|
# A way to filter certain keys of data provided to the LazyHighCharts#series method and the LazyHighCharts#options
|
3
2
|
#
|
4
|
-
# Add
|
5
|
-
# In the FILTER_MAP, the hash keys are methods, and the values are arrays of the hash keys the filter should be
|
6
|
-
# applied to
|
3
|
+
# Add keys and methods to the FILTER_MAP hash to have them applied to the options in a series
|
7
4
|
#
|
8
5
|
# Be careful that it is OK to filter the hash keys you specify for every key of the options or series hash
|
9
6
|
#
|
10
7
|
module LazyHighCharts
|
11
8
|
module OptionsKeyFilter
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
FILTER_MAP = {
|
10
|
+
:data => [:format_data],
|
11
|
+
:pointInterval => [:milliseconds],
|
12
|
+
:pointStart => [:date_to_js_code]
|
13
|
+
}
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
class << self
|
16
|
+
def filter options
|
17
|
+
{}.tap do |hash|
|
18
|
+
options.each do |key, value|
|
19
|
+
if value.is_a?(::Hash)
|
20
|
+
hash[key] = filter(value)
|
21
|
+
else
|
22
|
+
hash[key] = value
|
23
|
+
methods = Array(FILTER_MAP[key])
|
24
|
+
methods.each do |method_name|
|
25
|
+
hash[key] = send(method_name, hash[key])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
private
|
33
|
+
|
34
|
+
def milliseconds value
|
35
|
+
value * 1_000
|
36
|
+
end
|
37
|
+
|
38
|
+
def date_to_js_code date
|
39
|
+
"Date.UTC(#{date.year}, #{date.month - 1}, #{date.day})".js_code
|
40
|
+
end
|
41
|
+
|
42
|
+
def format_data(data)
|
43
|
+
data.map { |item| format_data_item(item) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def format_data_item(item)
|
47
|
+
if item.is_a?(::Array)
|
48
|
+
format_data item
|
49
|
+
elsif item.is_a?(DateTime)
|
50
|
+
date_to_js_code item
|
24
51
|
else
|
25
|
-
|
26
|
-
v = method.call(v) if matchers.include?(k)
|
27
|
-
end
|
52
|
+
item
|
28
53
|
end
|
29
|
-
[k, v]
|
30
54
|
end
|
31
|
-
Hash[new_options]
|
32
55
|
end
|
33
|
-
|
34
|
-
FILTER_MAP = {
|
35
|
-
method(:milliseconds) => [:pointInterval],
|
36
|
-
method(:date_to_js_code) => [:pointStart]
|
37
|
-
}
|
38
56
|
end
|
39
|
-
end
|
57
|
+
end
|
data/lib/tasks/high_charts.rake
CHANGED
@@ -15,10 +15,28 @@ namespace :highcharts do
|
|
15
15
|
say "Grabbing Core from Highcharts codebase..." do
|
16
16
|
sh "mkdir -p vendor/assets/javascripts/highcharts/modules/"
|
17
17
|
sh "mkdir -p vendor/assets/javascripts/highcharts/adapters/"
|
18
|
-
|
18
|
+
|
19
19
|
sh "curl -# http://code.highcharts.com/highcharts.js -L --compressed -o vendor/assets/javascripts/highcharts/highcharts.js"
|
20
|
+
sh "curl -# http://code.highcharts.com/highcharts-3d.js -L --compressed -o vendor/assets/javascripts/highcharts/highcharts-3d.js"
|
20
21
|
sh "curl -# http://code.highcharts.com/highcharts-more.js -L --compressed -o vendor/assets/javascripts/highcharts/highcharts-more.js"
|
22
|
+
|
23
|
+
# Modules
|
24
|
+
sh "curl -# http://code.highcharts.com/modules/accessibility.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/accessibility.js"
|
25
|
+
sh "curl -# http://code.highcharts.com/modules/annotations.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/annotations.js"
|
26
|
+
sh "curl -# http://code.highcharts.com/modules/boost.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/boost.js"
|
27
|
+
sh "curl -# http://code.highcharts.com/modules/broken-axis.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/broken-axis.js"
|
28
|
+
sh "curl -# http://code.highcharts.com/modules/canvas-tools.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/canvas-tools.js"
|
29
|
+
sh "curl -# http://code.highcharts.com/modules/data.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/data.js"
|
21
30
|
sh "curl -# http://code.highcharts.com/modules/exporting.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/exporting.js"
|
31
|
+
sh "curl -# http://code.highcharts.com/modules/export-data.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/export-data.js"
|
32
|
+
sh "curl -# http://code.highcharts.com/modules/drilldown.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/drilldown.js"
|
33
|
+
sh "curl -# http://code.highcharts.com/modules/funnel.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/funnel.js"
|
34
|
+
sh "curl -# http://code.highcharts.com/modules/heatmap.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/heatmap.js"
|
35
|
+
sh "curl -# http://code.highcharts.com/modules/no-data-to-display.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/no-data-to-display.js"
|
36
|
+
sh "curl -# http://code.highcharts.com/modules/offline-exporting.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/offline-exporting.js"
|
37
|
+
sh "curl -# http://code.highcharts.com/modules/solid-gauge.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/solid-gauge.js"
|
38
|
+
sh "curl -# http://code.highcharts.com/modules/treemap.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/treemap.js"
|
39
|
+
|
22
40
|
sh "curl -# http://code.highcharts.com/adapters/mootools-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/adapters/mootools-adapter.js"
|
23
41
|
sh "curl -# http://code.highcharts.com/adapters/prototype-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/adapters/prototype-adapter.js"
|
24
42
|
end
|
@@ -29,13 +47,14 @@ namespace :highcharts do
|
|
29
47
|
|
30
48
|
sh "mkdir -p vendor/assets/javascripts/highcharts/stock/modules/"
|
31
49
|
sh "mkdir -p vendor/assets/javascripts/highcharts/stock/adapters/"
|
32
|
-
|
50
|
+
|
33
51
|
sh "curl -# http://code.highcharts.com/stock/highstock.js -L --compressed -o vendor/assets/javascripts/highcharts/highstock.js"
|
34
52
|
sh "curl -# http://code.highcharts.com/stock/highcharts-more.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/highcharts-more.js"
|
35
53
|
sh "curl -# http://code.highcharts.com/stock/modules/exporting.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/modules/exporting.js"
|
54
|
+
sh "curl -# http://code.highcharts.com/stock/modules/funnel.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/modules/funnel.js"
|
36
55
|
sh "curl -# http://code.highcharts.com/stock/adapters/mootools-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/adapters/mootools-adapter.js"
|
37
56
|
sh "curl -# http://code.highcharts.com/stock/adapters/prototype-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/adapters/prototype-adapter.js"
|
38
57
|
end
|
39
58
|
end
|
40
59
|
|
41
|
-
end
|
60
|
+
end
|
data/spec/dummy_sinatra/app.rb
CHANGED
@@ -10,27 +10,51 @@ get '/' do
|
|
10
10
|
erb :index #, :layout => :layout
|
11
11
|
end
|
12
12
|
|
13
|
+
get '/dates' do
|
14
|
+
irregular_time_example()
|
15
|
+
erb :index
|
16
|
+
end
|
17
|
+
|
13
18
|
def highchart_example
|
14
19
|
# https://github.com/michelson/lazy_high_charts/wiki/Combination-Chart
|
15
20
|
@chart = LazyHighCharts::HighChart.new('graph') do |f|
|
16
21
|
f.title({ text: "Combination chart"})
|
17
|
-
f.options[:xAxis][:categories] =
|
22
|
+
f.options[:xAxis][:categories] =
|
18
23
|
['Apples', 'Oranges', 'Pears', 'Bananas', 'Plums']
|
19
24
|
f.labels(:items=>
|
20
|
-
[:html=>"Total fruit consumption",
|
25
|
+
[:html=>"Total fruit consumption",
|
21
26
|
:style=>{:left=>"40px", :top=>"8px", :color=>"black"} ])
|
22
27
|
f.series(:type=> 'column',:name=> 'Jane',:data=> [3, 2, 1, 3, 4])
|
23
28
|
f.series(:type=> 'column',:name=> 'John',:data=> [2, 3, 5, 7, 6])
|
24
29
|
f.series(:type=> 'column', :name=> 'Joe',:data=> [4, 3, 3, 9, 0])
|
25
|
-
f.series(:type=> 'spline',:name=> 'Average',
|
30
|
+
f.series(:type=> 'spline',:name=> 'Average',
|
26
31
|
:data=> [3, 2.67, 3, 6.33, 3.33])
|
27
|
-
f.series(:type=> '
|
32
|
+
f.series(:type=> 'column', :data=> [[DateTime.new(10), 100], [DateTime.new(20), 100]])
|
33
|
+
|
34
|
+
f.series(:type=> 'pie',:name=> 'Total consumption',
|
28
35
|
:data=> [
|
29
|
-
{:name=> 'Jane', :y=> 13, :color=> 'red'},
|
36
|
+
{:name=> 'Jane', :y=> 13, :color=> 'red'},
|
30
37
|
{:name=> 'John', :y=> 23,:color=> 'green'},
|
31
38
|
{:name=> 'Joe', :y=> 19,:color=> 'blue'}
|
32
39
|
],
|
33
40
|
:center=> [100, 80], :size=> 100, :showInLegend=> false)
|
34
41
|
end
|
35
|
-
|
36
|
-
|
42
|
+
end
|
43
|
+
|
44
|
+
def irregular_time_example()
|
45
|
+
@chart = LazyHighCharts::HighChart.new('graph') do |f|
|
46
|
+
f.title({ text: "Irregular Time Example"})
|
47
|
+
f.xAxis({type: 'datetime' })
|
48
|
+
f.series(:type=> 'spline', :data=> make_random_series(1))
|
49
|
+
f.series(:type=> 'spline', :data=> make_random_series(2))
|
50
|
+
f.series(:type=> 'spline', :data=> make_random_series(3))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def make_random_series(step)
|
55
|
+
data = []
|
56
|
+
for i in 0..10
|
57
|
+
data << [DateTime.new(i * step), (rand * 100).to_i]
|
58
|
+
end
|
59
|
+
data
|
60
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "HighChartGlobals" do
|
4
|
+
before(:each) do
|
5
|
+
@chart_globals = LazyHighCharts::HighChartGlobals.new do |chart|
|
6
|
+
chart.global( useUTC: false )
|
7
|
+
chart.chart(
|
8
|
+
backgroundColor: {
|
9
|
+
linearGradient: [0, 0, 500, 500],
|
10
|
+
stops: [
|
11
|
+
[0, "rgb(255, 255, 255)"],
|
12
|
+
[1, "rgb(240, 240, 255)"]
|
13
|
+
]
|
14
|
+
},
|
15
|
+
borderWidth: 2,
|
16
|
+
plotBackgroundColor: "rgba(255, 255, 255, .9)",
|
17
|
+
plotShadow: true,
|
18
|
+
plotBorderWidth: 1
|
19
|
+
)
|
20
|
+
chart.lang(
|
21
|
+
thousandsSep: ","
|
22
|
+
)
|
23
|
+
chart.colors([
|
24
|
+
"#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354"
|
25
|
+
])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# this is almost all flotomatic stuff
|
30
|
+
describe "initialization" do
|
31
|
+
|
32
|
+
it "should set options hash by default" do
|
33
|
+
@chart_globals.options.is_a?(Hash).should == true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should take a block and set attributes" do
|
37
|
+
@chart_globals.options[:lang][:thousandsSep].should == ","
|
38
|
+
@chart_globals.options[:global][:useUTC].should == false
|
39
|
+
@chart_globals.options[:chart][:backgroundColor][:linearGradient].should == [0, 0, 500, 500]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should override options" do
|
43
|
+
chart = LazyHighCharts::HighChartGlobals.new
|
44
|
+
chart.global({ useUTC: true })
|
45
|
+
chart.options[:global][:useUTC].should == true
|
46
|
+
chart.global({ useUTC: false })
|
47
|
+
chart.options[:global][:useUTC].should == false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/spec/high_chart_spec.rb
CHANGED
@@ -17,25 +17,25 @@ describe "HighChart" do
|
|
17
17
|
# this is almost all flotomatic stuff
|
18
18
|
describe "initialization" do
|
19
19
|
it "should take an optional 'placeholder' argument" do
|
20
|
-
LazyHighCharts::HighChart.new(@placeholder).placeholder.
|
21
|
-
LazyHighCharts::HighChart.new.placeholder.
|
20
|
+
expect(LazyHighCharts::HighChart.new(@placeholder).placeholder).to eq(@placeholder)
|
21
|
+
expect(LazyHighCharts::HighChart.new.placeholder).not_to eq(@placeholder)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "shouldn't generate a nil placeholder" do
|
25
|
-
LazyHighCharts::HighChart.new.placeholder.
|
25
|
+
expect(LazyHighCharts::HighChart.new.placeholder).not_to be_nil
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should generate different placeholders for different charts" do
|
29
29
|
a_different_placeholder = LazyHighCharts::HighChart.new.placeholder
|
30
|
-
LazyHighCharts::HighChart.new.placeholder.
|
30
|
+
expect(LazyHighCharts::HighChart.new.placeholder).not_to eq(a_different_placeholder)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should take an optional html_options argument (defaulting to 300px height)" do
|
34
|
-
LazyHighCharts::HighChart.new(@placeholder, @html_options).html_options.
|
34
|
+
expect(LazyHighCharts::HighChart.new(@placeholder, @html_options).html_options).to eq(@html_options)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should set options by default" do
|
38
|
-
LazyHighCharts::HighChart.new.options.
|
38
|
+
expect(LazyHighCharts::HighChart.new.options).to eq({
|
39
39
|
:title => {:text => nil},
|
40
40
|
:legend => {:layout => "vertical", :style => {}},
|
41
41
|
:xAxis => {},
|
@@ -44,27 +44,27 @@ describe "HighChart" do
|
|
44
44
|
:credits => {:enabled => false},
|
45
45
|
:plotOptions => {:areaspline => {}},
|
46
46
|
:chart => {:defaultSeriesType => "line", :renderTo => nil},
|
47
|
-
:subtitle => {}}
|
47
|
+
:subtitle => {}})
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should set data empty by default" do
|
51
|
-
LazyHighCharts::HighChart.new.series_data.
|
51
|
+
expect(LazyHighCharts::HighChart.new.series_data).to eq([])
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should take a block setting attributes" do
|
55
55
|
chart = LazyHighCharts::HighChart.new { |f| f.series_data = @data; f.options = @options }
|
56
|
-
chart.series_data.
|
57
|
-
chart.options.
|
56
|
+
expect(chart.series_data).to eq(@data)
|
57
|
+
expect(chart.options).to eq(@options)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should take a block setting attributes" do
|
61
61
|
chart = LazyHighCharts::HighChart.new { |f| f.options[:legend][:layout] = "horizontal" }
|
62
|
-
chart.options[:legend][:layout].
|
62
|
+
expect(chart.options[:legend][:layout]).to eq("horizontal")
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should take a block setting attributes" do
|
66
66
|
chart = LazyHighCharts::HighChart.new { |f| f.options[:range_selector] = {}; f.options[:range_selector][:selected] = 1 }
|
67
|
-
chart.options[:range_selector][:selected].
|
67
|
+
expect(chart.options[:range_selector][:selected]).to eq(1)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should change a block data without overriding options" do
|
@@ -77,11 +77,11 @@ describe "HighChart" do
|
|
77
77
|
f.options[:legend][:layout] = "horizontal"
|
78
78
|
f.options[:xAxis][:categories] = ["uno", "dos", "tres", "cuatro"]
|
79
79
|
end
|
80
|
-
chart.series_data.
|
81
|
-
chart.options[:legend][:layout].
|
82
|
-
chart.options[:xAxis][:categories].
|
83
|
-
chart.options[:chart][:defaultSeriesType].
|
84
|
-
chart.options[:chart][:inverted].
|
80
|
+
expect(chart.series_data).to eq([{:name => "John", :data => [3, 20]}, {:name => "Jane", :data => [1, 3]}])
|
81
|
+
expect(chart.options[:legend][:layout]).to eq("horizontal")
|
82
|
+
expect(chart.options[:xAxis][:categories]).to eq(["uno", "dos", "tres", "cuatro"])
|
83
|
+
expect(chart.options[:chart][:defaultSeriesType]).to eq("area")
|
84
|
+
expect(chart.options[:chart][:inverted]).to eq(true)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should change a block data with overriding entire options" do
|
@@ -93,12 +93,12 @@ describe "HighChart" do
|
|
93
93
|
f.xAxis(:categories => ["uno", "dos", "tres", "cuatro"], :labels => {:rotation => -45, :align => 'right'})
|
94
94
|
f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
|
95
95
|
end
|
96
|
-
chart.options[:xAxis][:categories].
|
97
|
-
chart.options[:xAxis][:labels][:rotation].
|
98
|
-
chart.options[:xAxis][:labels][:align].
|
99
|
-
chart.options[:chart][:defaultSeriesType].
|
100
|
-
chart.options[:chart][:renderTo].
|
101
|
-
chart.options[:chart][:inverted].
|
96
|
+
expect(chart.options[:xAxis][:categories]).to eq(["uno", "dos", "tres", "cuatro"])
|
97
|
+
expect(chart.options[:xAxis][:labels][:rotation]).to eq(-45)
|
98
|
+
expect(chart.options[:xAxis][:labels][:align]).to eq("right")
|
99
|
+
expect(chart.options[:chart][:defaultSeriesType]).to eq("spline")
|
100
|
+
expect(chart.options[:chart][:renderTo]).to eq("myRenderArea")
|
101
|
+
expect(chart.options[:chart][:inverted]).to eq(true)
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should have subtitles" do
|
@@ -111,7 +111,7 @@ describe "HighChart" do
|
|
111
111
|
f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
|
112
112
|
f.subtitle({:text => "Bar"})
|
113
113
|
end
|
114
|
-
chart.options[:subtitle][:text].
|
114
|
+
expect(chart.options[:subtitle][:text]).to eq("Bar")
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should override entire option by default when resetting it again' do
|
@@ -119,8 +119,8 @@ describe "HighChart" do
|
|
119
119
|
f.xAxis(categories: [3, 5, 7])
|
120
120
|
f.xAxis(title: {text: 'x title'})
|
121
121
|
end
|
122
|
-
chart.options[:xAxis][:categories].
|
123
|
-
chart.options[:xAxis][:title][:text].
|
122
|
+
expect(chart.options[:xAxis][:categories]).to eq(nil)
|
123
|
+
expect(chart.options[:xAxis][:title][:text]).to eq('x title')
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'should allow to build options step by step without overriding previously set values' do
|
@@ -128,8 +128,8 @@ describe "HighChart" do
|
|
128
128
|
f.xAxis!(categories: [3, 5, 7])
|
129
129
|
f.xAxis!(title: {text: 'x title'})
|
130
130
|
end
|
131
|
-
chart.options[:xAxis][:categories].
|
132
|
-
chart.options[:xAxis][:title][:text].
|
131
|
+
expect(chart.options[:xAxis][:categories]).to eq([3, 5, 7])
|
132
|
+
expect(chart.options[:xAxis][:title][:text]).to eq('x title')
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'should merge options and data into a full options hash' do
|
@@ -142,9 +142,10 @@ describe "HighChart" do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
json = chart.full_options
|
145
|
-
json.
|
146
|
-
json.
|
147
|
-
json.
|
145
|
+
expect(json).to match /\"series\"/
|
146
|
+
expect(json).to match /\"title\"/
|
147
|
+
expect(json).to match /\"tooltip\": { \"enabled\": true,\"formatter\"/
|
148
|
+
expect(json).to match /\"data\": \[ 29.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4 \]/
|
148
149
|
end
|
149
150
|
|
150
151
|
end
|
@@ -10,56 +10,86 @@ describe HighChartsHelper do
|
|
10
10
|
@chart = LazyHighCharts::HighChart.new(@placeholder)
|
11
11
|
@data = "data"
|
12
12
|
@options = "options"
|
13
|
+
@chart_globals = LazyHighCharts::HighChartGlobals.new do |chart|
|
14
|
+
chart.global({ useUTC: false })
|
15
|
+
chart.chart({
|
16
|
+
backgroundColor: {
|
17
|
+
linearGradient: [0, 0, 500, 500],
|
18
|
+
stops: [
|
19
|
+
[0, "rgb(255, 255, 255)"],
|
20
|
+
[1, "rgb(240, 240, 255)"]
|
21
|
+
]
|
22
|
+
},
|
23
|
+
borderWidth: 2,
|
24
|
+
plotBackgroundColor: "rgba(255, 255, 255, .9)",
|
25
|
+
plotShadow: true,
|
26
|
+
plotBorderWidth: 1
|
27
|
+
})
|
28
|
+
chart.lang({
|
29
|
+
thousandsSep: ","
|
30
|
+
})
|
31
|
+
chart.colors([
|
32
|
+
"#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354"
|
33
|
+
])
|
34
|
+
end
|
13
35
|
end
|
14
36
|
|
15
37
|
context "layout_helper" do
|
16
38
|
it "should return a div with an id of high_chart object" do
|
17
|
-
high_chart(@placeholder, @chart).
|
39
|
+
expect(high_chart(@placeholder, @chart)).to have_selector('div', :id => @placeholder)
|
18
40
|
end
|
19
41
|
|
20
42
|
it "should return a script" do
|
21
43
|
hc = LazyHighCharts::HighChart.new("placeholder")
|
22
|
-
high_chart(hc.placeholder, hc).
|
44
|
+
expect(high_chart(hc.placeholder, hc)).to have_selector('script')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "high_chart_globals" do
|
49
|
+
it "should return a script" do
|
50
|
+
high_chart_globals(@chart_globals).should have_selector('script')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should take a block and set attributes" do
|
54
|
+
high_chart_globals(@chart_globals).should match(/useUTC/)
|
55
|
+
high_chart_globals(@chart_globals).should match(/backgroundColor/)
|
56
|
+
high_chart_globals(@chart_globals).should match(/thousandsSep/)
|
23
57
|
end
|
24
58
|
end
|
25
59
|
|
26
60
|
context "high_chart_graph" do
|
27
61
|
describe "ready function" do
|
28
62
|
it "should be a javascript script" do
|
29
|
-
high_chart(@placeholder, @chart).
|
30
|
-
high_chart(@placeholder, @chart).
|
63
|
+
expect(high_chart(@placeholder, @chart)).to have_selector('script', :type => 'text/javascript')
|
64
|
+
expect(high_chart(@placeholder, @chart)).to match(/}\)\(\)/)
|
31
65
|
end
|
32
66
|
|
33
67
|
it "should assign to the onload event" do
|
34
|
-
high_chart(@placeholder, @chart).
|
35
|
-
end
|
36
|
-
it "should call any existing onload function" do
|
37
|
-
high_chart(@placeholder, @chart).should match(/onload = window.onload;/)
|
38
|
-
high_chart(@placeholder, @chart).should match(/if \(typeof onload == "function"\)\s*onload\(\)/)
|
68
|
+
expect(high_chart(@placeholder, @chart)).to include('window.addEventListener(\'load\', function() {')
|
39
69
|
end
|
40
70
|
end
|
41
71
|
describe "initialize HighChart" do
|
42
72
|
it "should set variables `chart` `options`" do
|
43
|
-
high_chart(@placeholder, @chart).
|
44
|
-
high_chart(@placeholder, @chart).
|
73
|
+
expect(high_chart(@placeholder, @chart)).to match(/var\s+options\s+=/)
|
74
|
+
expect(high_chart(@placeholder, @chart)).to match(/window.chart_placeholder\s=/)
|
45
75
|
end
|
46
76
|
it "should set Chart data" do
|
47
|
-
high_chart(@placeholder, @chart).
|
77
|
+
expect(high_chart(@placeholder, @chart)).to match(/window\.chart_placeholder\s=\snew\sHighcharts.Chart/)
|
48
78
|
end
|
49
79
|
|
50
80
|
it "should set chart renderTo" do
|
51
|
-
high_chart(@placeholder, @chart).
|
81
|
+
expect(high_chart(@placeholder, @chart)).to match(/"renderTo": "placeholder"/)
|
52
82
|
end
|
53
83
|
|
54
84
|
it "should set Chart Stock" do
|
55
|
-
high_stock(@placeholder, @chart).
|
85
|
+
expect(high_stock(@placeholder, @chart)).to match(/window\.chart_placeholder\s+=\s+new\s+Highcharts.StockChart/)
|
56
86
|
end
|
57
87
|
end
|
58
88
|
|
59
89
|
describe "HighChart Variable" do
|
60
90
|
it "should underscore chart_ variable" do
|
61
|
-
high_chart("place-holder", @chart).
|
62
|
-
high_chart("PlaceHolder", @chart).
|
91
|
+
expect(high_chart("place-holder", @chart)).to match(/window.chart_place_holder\s=/)
|
92
|
+
expect(high_chart("PlaceHolder", @chart)).to match(/window.chart_place_holder\s=/)
|
63
93
|
end
|
64
94
|
end
|
65
95
|
end
|
@@ -75,11 +105,11 @@ describe HighChartsHelper do
|
|
75
105
|
:data => [0, 1, 2, 3, 5, 6, 0, 7]
|
76
106
|
)
|
77
107
|
}
|
78
|
-
chart.options[:rangeSelector][:selected].
|
79
|
-
high_chart(@placeholder, chart).
|
80
|
-
high_chart(@placeholder, chart).
|
81
|
-
high_chart(@placeholder, chart).
|
82
|
-
high_chart(@placeholder, chart).
|
108
|
+
expect(chart.options[:rangeSelector][:selected]).to eq(1)
|
109
|
+
expect(high_chart(@placeholder, chart)).to match(/rangeSelector/)
|
110
|
+
expect(high_chart(@placeholder, chart)).to match(/xAxis/)
|
111
|
+
expect(high_chart(@placeholder, chart)).to match(/yAxis/)
|
112
|
+
expect(high_chart(@placeholder, chart)).to match(/series/)
|
83
113
|
|
84
114
|
end
|
85
115
|
|
@@ -88,7 +118,7 @@ describe HighChartsHelper do
|
|
88
118
|
chart = LazyHighCharts::HighChart.new { |f|
|
89
119
|
f.others(:foo => "bar")
|
90
120
|
}
|
91
|
-
high_chart(@placeholder, chart).
|
121
|
+
expect(high_chart(@placeholder, chart)).to match(/foo/)
|
92
122
|
end
|
93
123
|
|
94
124
|
it "should allow js code as attribute" do
|
@@ -96,7 +126,7 @@ describe HighChartsHelper do
|
|
96
126
|
f.options[:foo] = "function () { alert('hello') }".js_code
|
97
127
|
}
|
98
128
|
|
99
|
-
high_chart(@placeholder, chart).
|
129
|
+
expect(high_chart(@placeholder, chart)).to match(/"foo": function \(\) { alert\('hello'\) }/)
|
100
130
|
end
|
101
131
|
|
102
132
|
it "should convert keys to proper format" do
|
@@ -104,8 +134,8 @@ describe HighChartsHelper do
|
|
104
134
|
f.options[:foo_bar] = {:bar_foo => "someattrib"}
|
105
135
|
}
|
106
136
|
|
107
|
-
high_chart(@placeholder, chart).
|
108
|
-
high_chart(@placeholder, chart).
|
137
|
+
expect(high_chart(@placeholder, chart)).to match(/fooBar/)
|
138
|
+
expect(high_chart(@placeholder, chart)).to match(/barFoo/)
|
109
139
|
end
|
110
140
|
|
111
141
|
# issue #62 .js_code setting ignored
|
@@ -118,7 +148,7 @@ describe HighChartsHelper do
|
|
118
148
|
}
|
119
149
|
}])
|
120
150
|
}
|
121
|
-
high_chart(@placeholder, chart).
|
151
|
+
expect(high_chart(@placeholder, chart)).to match(/"formatter": function\(\) {return this.value \+ ' W';}/)
|
122
152
|
end
|
123
153
|
|
124
154
|
it "should support js_code in Individual data label for each point" do
|
@@ -135,7 +165,7 @@ describe HighChartsHelper do
|
|
135
165
|
:y => 54.4}
|
136
166
|
])
|
137
167
|
}
|
138
|
-
high_chart(@placeholder, chart).
|
168
|
+
expect(high_chart(@placeholder, chart)).to match(/"formatter": function\(\) {\ return this.x;\ }/)
|
139
169
|
end
|
140
170
|
|
141
171
|
end
|