rails_highcharts 0.0.1.beta1 → 0.0.1.beta2
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.
- data/README.md +42 -80
- data/app/helpers/rails_highcharts/rails_highcharts_helper.rb +41 -0
- data/lib/generators/rails_highcharts/install_generator.rb +5 -1
- data/lib/generators/rails_highcharts/media/javascripts/excanvas.compiled.js +35 -0
- data/lib/rails_highcharts/engine.rb +7 -1
- data/lib/rails_highcharts/rails_highcharts.rb +83 -0
- data/lib/rails_highcharts/version.rb +1 -1
- data/lib/rails_highcharts.rb +3 -329
- data/spec/rails_highcharts_helper_spec.rb +51 -0
- data/spec/rails_highcharts_spec.rb +120 -0
- data/spec/spec_helper.rb +21 -0
- metadata +57 -5
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Highcharts for Rails 3
|
2
2
|
=========================================================================
|
3
3
|
|
4
|
-
__modify from: [
|
4
|
+
__modify from: [lazy-high-charts](https://github.com/michelson/lazy_high_charts "lazy-high-charts"), with Highcharts v2.1.5 and Rails 3__
|
5
5
|
|
6
6
|
__use: [Highcharts](http://highcharts.com/ "Highcharts")__
|
7
7
|
|
@@ -16,91 +16,53 @@ Rails3.0.8+/Ruby1.8.7+
|
|
16
16
|
gem 'rails_highcharts'
|
17
17
|
|
18
18
|
rails g rails_highcharts:install
|
19
|
-
|
20
|
-
in footer layout
|
21
|
-
|
22
|
-
$(document).ready(function(){
|
23
|
-
<%= javascript_include_tag :highcharts %>
|
24
|
-
<%= yield :javascript %>
|
25
|
-
});
|
26
|
-
|
27
|
-
in our controller:
|
28
|
-
|
29
|
-
# Create a pie chart
|
30
|
-
browser_data = [
|
31
|
-
{:name => 'Safari', :y => 3.57, :identifier => 'applewebkit'},
|
32
|
-
{:name => 'Firefox', :y => 22.32, :identifier => 'gecko'},
|
33
|
-
{:name => 'Internet Explorer', :y => 56.9, :identifier => 'msie'},
|
34
|
-
{:name => 'Other', :y => 17.21}
|
35
|
-
]
|
36
19
|
|
37
|
-
|
20
|
+
Usage in Controller:
|
38
21
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
browser[:sliced] = true
|
43
|
-
|
44
|
-
# some browsers will match more than one identifier, stop looking as soon as one is found
|
45
|
-
break;
|
22
|
+
@h = HighChart.new('graph') do |f|
|
23
|
+
f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
|
24
|
+
f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
|
46
25
|
end
|
47
|
-
|
26
|
+
|
27
|
+
Without overriding entire option , (only change a specific option index):
|
48
28
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
29
|
+
@h = HighChart.new('graph') do |f|
|
30
|
+
.....
|
31
|
+
f.options[:chart][:defaultSeriesType] = "area"
|
32
|
+
f.options[:chart][:inverted] = true
|
33
|
+
f.options[:legend][:layout] = "horizontal"
|
34
|
+
f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
|
35
|
+
......
|
36
|
+
|
37
|
+
Overriding entire option:
|
54
38
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
39
|
+
@h = HighChart.new('graph') do |f|
|
40
|
+
.....
|
41
|
+
f.x_axis(:categories => @days.reverse! , :labels=>{:rotation=>-45 , :align => 'right'})
|
42
|
+
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
43
|
+
.....
|
44
|
+
|
45
|
+
Usage in layout:
|
46
|
+
|
47
|
+
<%= javascript_include_tag :highcharts %>
|
48
|
+
<!--[if IE]> <%= javascript_include_tag :ie_high_charts %> <![endif]-->
|
49
|
+
|
50
|
+
Usage in view:
|
60
51
|
|
61
|
-
@
|
62
|
-
|
63
|
-
|
64
|
-
:renderTo => "pie-chart-container",
|
65
|
-
:margin => [50, 30, 0, 30]
|
66
|
-
},
|
67
|
-
:credits => {
|
68
|
-
:enabled => true,
|
69
|
-
:href => 'http://marketshare.hitslink.com/browser-market-share.aspx?qprid=3',
|
70
|
-
:text => 'Data provided by NETMARKETSHARE'
|
71
|
-
},
|
72
|
-
:plotOptions => {
|
73
|
-
:pie => {
|
74
|
-
:dataLabels => {
|
75
|
-
:formatter => pie_label_formatter,
|
76
|
-
:style => {
|
77
|
-
:textShadow => '#000000 1px 1px 2px'
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
},
|
82
|
-
:series => [
|
83
|
-
{
|
84
|
-
:type => 'pie',
|
85
|
-
:data => browser_data
|
86
|
-
}
|
87
|
-
],
|
88
|
-
:subtitle => {
|
89
|
-
:text => 'January 2010'
|
90
|
-
},
|
91
|
-
:title => {
|
92
|
-
:text => 'Browser Market Share'
|
93
|
-
},
|
94
|
-
:tooltip => {
|
95
|
-
:formatter => pie_tooltip_formatter
|
96
|
-
},
|
97
|
-
})
|
52
|
+
<%= high_chart("my_id", @h) %>
|
53
|
+
|
54
|
+
Passing formatting options in the view to the helper block , because all the helper options declared in the controller are converted in strict/valid json (quoted key); so we need to extend the json object with some js.
|
98
55
|
|
99
|
-
|
56
|
+
<% high_chart("my_id", @h) do |c| %>
|
57
|
+
<%= "options.tooltip.formatter = function() { return '<b>HEY!!!'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +' units';}" %>
|
58
|
+
<%= "options.xAxis.labels.formatter = function() { return 'ho';}" %>
|
59
|
+
<%= "options.yAxis.labels.formatter = function() { return 'hey';}" %>
|
60
|
+
<%end %>
|
61
|
+
|
62
|
+
Option reference:
|
100
63
|
|
101
|
-
|
102
|
-
|
64
|
+
http://www.highcharts.com/ref/
|
65
|
+
|
66
|
+
HighCharts License:
|
103
67
|
|
104
|
-
|
105
|
-
<%= @pie_chart %>
|
106
|
-
<% end %>
|
68
|
+
http://www.highcharts.com/license
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RailsHighchartsHelper
|
2
|
+
# ActiveSupport::JSON.unquote_hash_key_identifiers = false
|
3
|
+
def high_chart(placeholder, object , &block)
|
4
|
+
object.html_options.merge!({:id=>placeholder})
|
5
|
+
object.options[:chart][:renderTo] = placeholder
|
6
|
+
high_graph(placeholder, object, &block).concat(content_tag("div", "", object.html_options))
|
7
|
+
end
|
8
|
+
|
9
|
+
def high_graph(placeholder, object, &block)
|
10
|
+
graph =<<-EOJS
|
11
|
+
<script type="text/javascript">
|
12
|
+
jQuery(function() {
|
13
|
+
// 1. Define JSON options
|
14
|
+
var options = { chart: #{object.options[:chart].to_json},
|
15
|
+
title: #{object.options[:title].to_json},
|
16
|
+
legend: #{object.options[:legend].to_json},
|
17
|
+
xAxis: #{object.options[:x_axis].to_json},
|
18
|
+
yAxis: #{object.options[:y_axis].to_json},
|
19
|
+
tooltip: #{object.options[:tooltip].to_json},
|
20
|
+
credits: #{object.options[:credits].to_json},
|
21
|
+
plotOptions: #{object.options[:plot_options].to_json},
|
22
|
+
series: #{object.data.to_json},
|
23
|
+
subtitle: #{object.options[:subtitle].to_json}
|
24
|
+
};
|
25
|
+
|
26
|
+
// 2. Add callbacks (non-JSON compliant)
|
27
|
+
#{capture(&block) if block_given?}
|
28
|
+
// 3. Build the chart
|
29
|
+
var chart = new Highcharts.Chart(options);
|
30
|
+
});
|
31
|
+
</script>
|
32
|
+
EOJS
|
33
|
+
if defined?(raw) && Rails.version.to_i >= 3
|
34
|
+
return raw(graph)
|
35
|
+
else
|
36
|
+
return graph unless block_given?
|
37
|
+
concat graph
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end #RailsHighchartsHelper
|
@@ -13,7 +13,11 @@ module RailsHighcharts
|
|
13
13
|
source_root File.expand_path('../media', __FILE__)
|
14
14
|
desc "Copies media files to main project"
|
15
15
|
def copy_media_files
|
16
|
-
|
16
|
+
js_files = %w|highcharts.js excanvas.compiled.js|
|
17
|
+
|
18
|
+
js_files.each do |js|
|
19
|
+
copy_file "../media/javascripts/#{js}", "public/javascripts/highcharts/#{js}"
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// Copyright 2006 Google Inc.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
document.createElement("canvas").getContext||(function(){var s=Math,j=s.round,F=s.sin,G=s.cos,V=s.abs,W=s.sqrt,k=10,v=k/2;function X(){return this.context_||(this.context_=new H(this))}var L=Array.prototype.slice;function Y(b,a){var c=L.call(arguments,2);return function(){return b.apply(a,c.concat(L.call(arguments)))}}var M={init:function(b){if(/MSIE/.test(navigator.userAgent)&&!window.opera){var a=b||document;a.createElement("canvas");a.attachEvent("onreadystatechange",Y(this.init_,this,a))}},init_:function(b){b.namespaces.g_vml_||
|
15
|
+
b.namespaces.add("g_vml_","urn:schemas-microsoft-com:vml","#default#VML");b.namespaces.g_o_||b.namespaces.add("g_o_","urn:schemas-microsoft-com:office:office","#default#VML");if(!b.styleSheets.ex_canvas_){var a=b.createStyleSheet();a.owningElement.id="ex_canvas_";a.cssText="canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}g_vml_\\:*{behavior:url(#default#VML)}g_o_\\:*{behavior:url(#default#VML)}"}var c=b.getElementsByTagName("canvas"),d=0;for(;d<c.length;d++)this.initElement(c[d])},
|
16
|
+
initElement:function(b){if(!b.getContext){b.getContext=X;b.innerHTML="";b.attachEvent("onpropertychange",Z);b.attachEvent("onresize",$);var a=b.attributes;if(a.width&&a.width.specified)b.style.width=a.width.nodeValue+"px";else b.width=b.clientWidth;if(a.height&&a.height.specified)b.style.height=a.height.nodeValue+"px";else b.height=b.clientHeight}return b}};function Z(b){var a=b.srcElement;switch(b.propertyName){case "width":a.style.width=a.attributes.width.nodeValue+"px";a.getContext().clearRect();
|
17
|
+
break;case "height":a.style.height=a.attributes.height.nodeValue+"px";a.getContext().clearRect();break}}function $(b){var a=b.srcElement;if(a.firstChild){a.firstChild.style.width=a.clientWidth+"px";a.firstChild.style.height=a.clientHeight+"px"}}M.init();var N=[],B=0;for(;B<16;B++){var C=0;for(;C<16;C++)N[B*16+C]=B.toString(16)+C.toString(16)}function I(){return[[1,0,0],[0,1,0],[0,0,1]]}function y(b,a){var c=I(),d=0;for(;d<3;d++){var f=0;for(;f<3;f++){var h=0,g=0;for(;g<3;g++)h+=b[d][g]*a[g][f];c[d][f]=
|
18
|
+
h}}return c}function O(b,a){a.fillStyle=b.fillStyle;a.lineCap=b.lineCap;a.lineJoin=b.lineJoin;a.lineWidth=b.lineWidth;a.miterLimit=b.miterLimit;a.shadowBlur=b.shadowBlur;a.shadowColor=b.shadowColor;a.shadowOffsetX=b.shadowOffsetX;a.shadowOffsetY=b.shadowOffsetY;a.strokeStyle=b.strokeStyle;a.globalAlpha=b.globalAlpha;a.arcScaleX_=b.arcScaleX_;a.arcScaleY_=b.arcScaleY_;a.lineScale_=b.lineScale_}function P(b){var a,c=1;b=String(b);if(b.substring(0,3)=="rgb"){var d=b.indexOf("(",3),f=b.indexOf(")",d+
|
19
|
+
1),h=b.substring(d+1,f).split(",");a="#";var g=0;for(;g<3;g++)a+=N[Number(h[g])];if(h.length==4&&b.substr(3,1)=="a")c=h[3]}else a=b;return{color:a,alpha:c}}function aa(b){switch(b){case "butt":return"flat";case "round":return"round";case "square":default:return"square"}}function H(b){this.m_=I();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.fillStyle=this.strokeStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=k*1;this.globalAlpha=1;this.canvas=b;
|
20
|
+
var a=b.ownerDocument.createElement("div");a.style.width=b.clientWidth+"px";a.style.height=b.clientHeight+"px";a.style.overflow="hidden";a.style.position="absolute";b.appendChild(a);this.element_=a;this.lineScale_=this.arcScaleY_=this.arcScaleX_=1}var i=H.prototype;i.clearRect=function(){this.element_.innerHTML=""};i.beginPath=function(){this.currentPath_=[]};i.moveTo=function(b,a){var c=this.getCoords_(b,a);this.currentPath_.push({type:"moveTo",x:c.x,y:c.y});this.currentX_=c.x;this.currentY_=c.y};
|
21
|
+
i.lineTo=function(b,a){var c=this.getCoords_(b,a);this.currentPath_.push({type:"lineTo",x:c.x,y:c.y});this.currentX_=c.x;this.currentY_=c.y};i.bezierCurveTo=function(b,a,c,d,f,h){var g=this.getCoords_(f,h),l=this.getCoords_(b,a),e=this.getCoords_(c,d);Q(this,l,e,g)};function Q(b,a,c,d){b.currentPath_.push({type:"bezierCurveTo",cp1x:a.x,cp1y:a.y,cp2x:c.x,cp2y:c.y,x:d.x,y:d.y});b.currentX_=d.x;b.currentY_=d.y}i.quadraticCurveTo=function(b,a,c,d){var f=this.getCoords_(b,a),h=this.getCoords_(c,d),g={x:this.currentX_+
|
22
|
+
0.6666666666666666*(f.x-this.currentX_),y:this.currentY_+0.6666666666666666*(f.y-this.currentY_)};Q(this,g,{x:g.x+(h.x-this.currentX_)/3,y:g.y+(h.y-this.currentY_)/3},h)};i.arc=function(b,a,c,d,f,h){c*=k;var g=h?"at":"wa",l=b+G(d)*c-v,e=a+F(d)*c-v,m=b+G(f)*c-v,r=a+F(f)*c-v;if(l==m&&!h)l+=0.125;var n=this.getCoords_(b,a),o=this.getCoords_(l,e),q=this.getCoords_(m,r);this.currentPath_.push({type:g,x:n.x,y:n.y,radius:c,xStart:o.x,yStart:o.y,xEnd:q.x,yEnd:q.y})};i.rect=function(b,a,c,d){this.moveTo(b,
|
23
|
+
a);this.lineTo(b+c,a);this.lineTo(b+c,a+d);this.lineTo(b,a+d);this.closePath()};i.strokeRect=function(b,a,c,d){var f=this.currentPath_;this.beginPath();this.moveTo(b,a);this.lineTo(b+c,a);this.lineTo(b+c,a+d);this.lineTo(b,a+d);this.closePath();this.stroke();this.currentPath_=f};i.fillRect=function(b,a,c,d){var f=this.currentPath_;this.beginPath();this.moveTo(b,a);this.lineTo(b+c,a);this.lineTo(b+c,a+d);this.lineTo(b,a+d);this.closePath();this.fill();this.currentPath_=f};i.createLinearGradient=function(b,
|
24
|
+
a,c,d){var f=new D("gradient");f.x0_=b;f.y0_=a;f.x1_=c;f.y1_=d;return f};i.createRadialGradient=function(b,a,c,d,f,h){var g=new D("gradientradial");g.x0_=b;g.y0_=a;g.r0_=c;g.x1_=d;g.y1_=f;g.r1_=h;return g};i.drawImage=function(b){var a,c,d,f,h,g,l,e,m=b.runtimeStyle.width,r=b.runtimeStyle.height;b.runtimeStyle.width="auto";b.runtimeStyle.height="auto";var n=b.width,o=b.height;b.runtimeStyle.width=m;b.runtimeStyle.height=r;if(arguments.length==3){a=arguments[1];c=arguments[2];h=g=0;l=d=n;e=f=o}else if(arguments.length==
|
25
|
+
5){a=arguments[1];c=arguments[2];d=arguments[3];f=arguments[4];h=g=0;l=n;e=o}else if(arguments.length==9){h=arguments[1];g=arguments[2];l=arguments[3];e=arguments[4];a=arguments[5];c=arguments[6];d=arguments[7];f=arguments[8]}else throw Error("Invalid number of arguments");var q=this.getCoords_(a,c),t=[];t.push(" <g_vml_:group",' coordsize="',k*10,",",k*10,'"',' coordorigin="0,0"',' style="width:',10,"px;height:",10,"px;position:absolute;");if(this.m_[0][0]!=1||this.m_[0][1]){var E=[];E.push("M11=",
|
26
|
+
this.m_[0][0],",","M12=",this.m_[1][0],",","M21=",this.m_[0][1],",","M22=",this.m_[1][1],",","Dx=",j(q.x/k),",","Dy=",j(q.y/k),"");var p=q,z=this.getCoords_(a+d,c),w=this.getCoords_(a,c+f),x=this.getCoords_(a+d,c+f);p.x=s.max(p.x,z.x,w.x,x.x);p.y=s.max(p.y,z.y,w.y,x.y);t.push("padding:0 ",j(p.x/k),"px ",j(p.y/k),"px 0;filter:progid:DXImageTransform.Microsoft.Matrix(",E.join(""),", sizingmethod='clip');")}else t.push("top:",j(q.y/k),"px;left:",j(q.x/k),"px;");t.push(' ">','<g_vml_:image src="',b.src,
|
27
|
+
'"',' style="width:',k*d,"px;"," height:",k*f,'px;"',' cropleft="',h/n,'"',' croptop="',g/o,'"',' cropright="',(n-h-l)/n,'"',' cropbottom="',(o-g-e)/o,'"'," />","</g_vml_:group>");this.element_.insertAdjacentHTML("BeforeEnd",t.join(""))};i.stroke=function(b){var a=[],c=P(b?this.fillStyle:this.strokeStyle),d=c.color,f=c.alpha*this.globalAlpha;a.push("<g_vml_:shape",' filled="',!!b,'"',' style="position:absolute;width:',10,"px;height:",10,'px;"',' coordorigin="0 0" coordsize="',k*10," ",k*10,'"',' stroked="',
|
28
|
+
!b,'"',' path="');var h={x:null,y:null},g={x:null,y:null},l=0;for(;l<this.currentPath_.length;l++){var e=this.currentPath_[l];switch(e.type){case "moveTo":a.push(" m ",j(e.x),",",j(e.y));break;case "lineTo":a.push(" l ",j(e.x),",",j(e.y));break;case "close":a.push(" x ");e=null;break;case "bezierCurveTo":a.push(" c ",j(e.cp1x),",",j(e.cp1y),",",j(e.cp2x),",",j(e.cp2y),",",j(e.x),",",j(e.y));break;case "at":case "wa":a.push(" ",e.type," ",j(e.x-this.arcScaleX_*e.radius),",",j(e.y-this.arcScaleY_*e.radius),
|
29
|
+
" ",j(e.x+this.arcScaleX_*e.radius),",",j(e.y+this.arcScaleY_*e.radius)," ",j(e.xStart),",",j(e.yStart)," ",j(e.xEnd),",",j(e.yEnd));break}if(e){if(h.x==null||e.x<h.x)h.x=e.x;if(g.x==null||e.x>g.x)g.x=e.x;if(h.y==null||e.y<h.y)h.y=e.y;if(g.y==null||e.y>g.y)g.y=e.y}}a.push(' ">');if(b)if(typeof this.fillStyle=="object"){var m=this.fillStyle,r=0,n={x:0,y:0},o=0,q=1;if(m.type_=="gradient"){var t=m.x1_/this.arcScaleX_,E=m.y1_/this.arcScaleY_,p=this.getCoords_(m.x0_/this.arcScaleX_,m.y0_/this.arcScaleY_),
|
30
|
+
z=this.getCoords_(t,E);r=Math.atan2(z.x-p.x,z.y-p.y)*180/Math.PI;if(r<0)r+=360;if(r<1.0E-6)r=0}else{var p=this.getCoords_(m.x0_,m.y0_),w=g.x-h.x,x=g.y-h.y;n={x:(p.x-h.x)/w,y:(p.y-h.y)/x};w/=this.arcScaleX_*k;x/=this.arcScaleY_*k;var R=s.max(w,x);o=2*m.r0_/R;q=2*m.r1_/R-o}var u=m.colors_;u.sort(function(ba,ca){return ba.offset-ca.offset});var J=u.length,da=u[0].color,ea=u[J-1].color,fa=u[0].alpha*this.globalAlpha,ga=u[J-1].alpha*this.globalAlpha,S=[],l=0;for(;l<J;l++){var T=u[l];S.push(T.offset*q+
|
31
|
+
o+" "+T.color)}a.push('<g_vml_:fill type="',m.type_,'"',' method="none" focus="100%"',' color="',da,'"',' color2="',ea,'"',' colors="',S.join(","),'"',' opacity="',ga,'"',' g_o_:opacity2="',fa,'"',' angle="',r,'"',' focusposition="',n.x,",",n.y,'" />')}else a.push('<g_vml_:fill color="',d,'" opacity="',f,'" />');else{var K=this.lineScale_*this.lineWidth;if(K<1)f*=K;a.push("<g_vml_:stroke",' opacity="',f,'"',' joinstyle="',this.lineJoin,'"',' miterlimit="',this.miterLimit,'"',' endcap="',aa(this.lineCap),
|
32
|
+
'"',' weight="',K,'px"',' color="',d,'" />')}a.push("</g_vml_:shape>");this.element_.insertAdjacentHTML("beforeEnd",a.join(""))};i.fill=function(){this.stroke(true)};i.closePath=function(){this.currentPath_.push({type:"close"})};i.getCoords_=function(b,a){var c=this.m_;return{x:k*(b*c[0][0]+a*c[1][0]+c[2][0])-v,y:k*(b*c[0][1]+a*c[1][1]+c[2][1])-v}};i.save=function(){var b={};O(this,b);this.aStack_.push(b);this.mStack_.push(this.m_);this.m_=y(I(),this.m_)};i.restore=function(){O(this.aStack_.pop(),
|
33
|
+
this);this.m_=this.mStack_.pop()};function ha(b){var a=0;for(;a<3;a++){var c=0;for(;c<2;c++)if(!isFinite(b[a][c])||isNaN(b[a][c]))return false}return true}function A(b,a,c){if(!!ha(a)){b.m_=a;if(c)b.lineScale_=W(V(a[0][0]*a[1][1]-a[0][1]*a[1][0]))}}i.translate=function(b,a){A(this,y([[1,0,0],[0,1,0],[b,a,1]],this.m_),false)};i.rotate=function(b){var a=G(b),c=F(b);A(this,y([[a,c,0],[-c,a,0],[0,0,1]],this.m_),false)};i.scale=function(b,a){this.arcScaleX_*=b;this.arcScaleY_*=a;A(this,y([[b,0,0],[0,a,
|
34
|
+
0],[0,0,1]],this.m_),true)};i.transform=function(b,a,c,d,f,h){A(this,y([[b,a,0],[c,d,0],[f,h,1]],this.m_),true)};i.setTransform=function(b,a,c,d,f,h){A(this,[[b,a,0],[c,d,0],[f,h,1]],true)};i.clip=function(){};i.arcTo=function(){};i.createPattern=function(){return new U};function D(b){this.type_=b;this.r1_=this.y1_=this.x1_=this.r0_=this.y0_=this.x0_=0;this.colors_=[]}D.prototype.addColorStop=function(b,a){a=P(a);this.colors_.push({offset:b,color:a.color,alpha:a.alpha})};function U(){}G_vmlCanvasManager=
|
35
|
+
M;CanvasRenderingContext2D=H;CanvasGradient=D;CanvasPattern=U})();
|
@@ -1,13 +1,19 @@
|
|
1
1
|
require 'rails'
|
2
|
+
require File.dirname(__FILE__) + "/../../app/helpers/rails_highcharts/rails_highcharts_helper"
|
2
3
|
|
3
4
|
module RailsHighcharts
|
4
5
|
class Engine < Rails::Engine
|
5
6
|
|
7
|
+
config.to_prepare do
|
8
|
+
ApplicationController.helper(RailsHighchartsHelper)
|
9
|
+
end
|
10
|
+
|
6
11
|
# ========================================
|
7
12
|
# = javascript_include_tag :highcharts =
|
8
13
|
# ========================================
|
9
14
|
config.before_initialize do
|
10
|
-
config.action_view.javascript_expansions[:highcharts]
|
15
|
+
config.action_view.javascript_expansions[:highcharts] = %w|highcharts/highcharts.js|
|
16
|
+
config.action_view.javascript_expansions[:ie_high_charts] = %w|highcharts/excanvas.compiled.js|
|
11
17
|
end
|
12
18
|
|
13
19
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class RailsHighcharts
|
2
|
+
|
3
|
+
CANVAS_DEFAULT_HTML_OPTIONS = {:style => "height: 300px, width:615px" }
|
4
|
+
SERIES_OPTIONS = %w(lines points bars shadowSize colors)
|
5
|
+
|
6
|
+
attr_accessor :data, :options, :placeholder, :html_options
|
7
|
+
alias :canvas :placeholder
|
8
|
+
alias :canvas= :placeholder=
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(canvas = nil, html_opts = {})
|
12
|
+
|
13
|
+
@collection_filter = nil
|
14
|
+
self.tap do |high_chart|
|
15
|
+
high_chart.data ||= []
|
16
|
+
high_chart.options ||= {}
|
17
|
+
high_chart.defaults_options
|
18
|
+
high_chart.html_options = html_opts.reverse_merge(CANVAS_DEFAULT_HTML_OPTIONS)
|
19
|
+
high_chart.canvas = canvas if canvas
|
20
|
+
yield high_chart if block_given?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
|
25
|
+
|
26
|
+
def defaults_options
|
27
|
+
self.title({ :text=>"example test title from plugin"})
|
28
|
+
self.legend({:layout=>"vertical", :style=>{:position=>'absolute', :bottom=>'auto', :left=>'150px', :top=>'150px'}, :borderWidth=> 1, :backgroundColor=>'#FFFFFF'})
|
29
|
+
self.x_axis({:categories => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
30
|
+
:plotBands => [{ :from=> 6.0,:to=> 6.5,:color=> 'rgba(68, 170, 213, .2)'}],
|
31
|
+
:labels =>{ :align=>'right',:rotation=>45 }
|
32
|
+
})
|
33
|
+
self.y_axis({:title=> {:text=> 'Fruit units'}, :labels=>{:align=>'right'} })
|
34
|
+
self.tooltip({ :enabled=>true })
|
35
|
+
self.credits({:enabled => false})
|
36
|
+
self.plot_options({ :areaspline => {:fillOpacity => 0.5}})
|
37
|
+
self.chart({:defaultSeriesType=>"areaspline" , :renderTo => nil})
|
38
|
+
self.subtitle({})
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Pass other methods through to the javascript high_chart object.
|
43
|
+
#
|
44
|
+
# For instance: <tt>high_chart.grid(:color => "#699")</tt>
|
45
|
+
#
|
46
|
+
def method_missing(meth, opts = {})
|
47
|
+
merge_options meth, opts
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add a simple series to the graph:
|
51
|
+
#
|
52
|
+
# data = [[0,5], [1,5], [2,5]]
|
53
|
+
# @high_chart.series :name=>'Updated', :data=>data
|
54
|
+
# @high_chart.series :name=>'Updated', :data=>[5, 1, 6, 1, 5, 4, 9]
|
55
|
+
#
|
56
|
+
def series(opts = {})
|
57
|
+
@data ||= []
|
58
|
+
if opts.blank?
|
59
|
+
@data << series_options.merge(:name => label, :data => d)
|
60
|
+
else
|
61
|
+
@data << opts.merge(:name => opts[:name], :data => opts[:data])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def series_options
|
67
|
+
@options.reject {|k,v| SERIES_OPTIONS.include?(k.to_s) == false}
|
68
|
+
end
|
69
|
+
|
70
|
+
def merge_options(name, opts)
|
71
|
+
@options.merge! name => opts
|
72
|
+
end
|
73
|
+
|
74
|
+
def arguments_to_options(args)
|
75
|
+
if args.blank?
|
76
|
+
{:show => true}
|
77
|
+
elsif args.is_a? Array
|
78
|
+
args.first
|
79
|
+
else
|
80
|
+
args
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end #RailsHighcharts
|
data/lib/rails_highcharts.rb
CHANGED
@@ -2,334 +2,8 @@ require "rails"
|
|
2
2
|
require "rails_highcharts/engine"
|
3
3
|
require "rails_highcharts/version"
|
4
4
|
require "rails_highcharts/hash_extend"
|
5
|
+
require "rails_highcharts/rails_highcharts"
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
@@types = ['area', 'areaspline', 'bar', 'column', 'line', 'pie', 'scatter', 'spline']
|
9
|
-
@@date_format = "<strong>%A</strong><br /> %m/%d/%Y"
|
10
|
-
|
11
|
-
attr_accessor :chart, :colors, :credits, :labels, :lang, :legend, :plotOptions, :point,
|
12
|
-
:series, :subtitle, :symbols, :title, :toolbar, :tooltip, :x_axis, :y_axis
|
13
|
-
|
14
|
-
def self.method_missing(m, options={})
|
15
|
-
format = options[:format] || 'jquery'
|
16
|
-
options.delete(:format)
|
17
|
-
|
18
|
-
# create the chart and return it in the format requested
|
19
|
-
if @@types.include?(m.to_s)
|
20
|
-
chart = new(options.merge!({:type => m}))
|
21
|
-
chart.send(format)
|
22
|
-
else
|
23
|
-
"#{m} is not a supported chart format, please use one of the following: #{supported_types}."
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(options={})
|
28
|
-
# override highcharts defaults
|
29
|
-
@credits = {
|
30
|
-
:enabled => false
|
31
|
-
}
|
32
|
-
@legend = {
|
33
|
-
:layout => 'vertical',
|
34
|
-
:style => {
|
35
|
-
:left => 'auto',
|
36
|
-
:bottom => 'auto',
|
37
|
-
:right => '50px',
|
38
|
-
:top => '75px'
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
# IE7 displays 'null' without this
|
43
|
-
@title = {
|
44
|
-
:text => ""
|
45
|
-
}
|
46
|
-
@x_axis = {
|
47
|
-
:title => {
|
48
|
-
:text => ""
|
49
|
-
}
|
50
|
-
}
|
51
|
-
@y_axis = {
|
52
|
-
:title => {
|
53
|
-
:text => ""
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
# define defaults based on chart type
|
58
|
-
case options[:type].to_s
|
59
|
-
when 'area'
|
60
|
-
@chart = {
|
61
|
-
:defaultSeriesType => 'area',
|
62
|
-
:margin => [50, 200, 60, 80]
|
63
|
-
}
|
64
|
-
when 'areaspline'
|
65
|
-
@chart = {
|
66
|
-
:defaultSeriesType => 'areaspline',
|
67
|
-
:margin => [50, 200, 60, 80]
|
68
|
-
}
|
69
|
-
when 'bar'
|
70
|
-
@chart = {
|
71
|
-
:inverted => true,
|
72
|
-
:defaultSeriesType => 'bar',
|
73
|
-
:margin => [50, 50, 50, 100]
|
74
|
-
}
|
75
|
-
@plotOptions = {
|
76
|
-
:bar => {
|
77
|
-
:showInLegend => false,
|
78
|
-
:dataLabels => {
|
79
|
-
:y => -5,
|
80
|
-
:enabled => true,
|
81
|
-
:color => '#666666'
|
82
|
-
}
|
83
|
-
}
|
84
|
-
}
|
85
|
-
when 'column'
|
86
|
-
@chart = {
|
87
|
-
:defaultSeriesType => 'column',
|
88
|
-
:margin => [50, 50, 50, 100]
|
89
|
-
}
|
90
|
-
@plotOptions = {
|
91
|
-
:column => {
|
92
|
-
:showInLegend => false
|
93
|
-
}
|
94
|
-
}
|
95
|
-
when 'line'
|
96
|
-
@chart = {
|
97
|
-
:defaultSeriesType => 'line',
|
98
|
-
:margin => [50, 200, 60, 80]
|
99
|
-
}
|
100
|
-
when 'pie'
|
101
|
-
@chart = {
|
102
|
-
:margin => [10, 10, 10, 10]
|
103
|
-
}
|
104
|
-
@plotOptions = {
|
105
|
-
:pie => {
|
106
|
-
:dataLabels => {
|
107
|
-
:enabled => true,
|
108
|
-
:color => 'white',
|
109
|
-
:style => {:font => '10pt Helvetica'}
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
when 'scatter'
|
114
|
-
@chart = {
|
115
|
-
:defaultSeriesType => 'scatter',
|
116
|
-
:margin => [50, 200, 60, 80]
|
117
|
-
}
|
118
|
-
@plotOptions = {
|
119
|
-
:scatter => {
|
120
|
-
:marker => {
|
121
|
-
:radius => 5,
|
122
|
-
:states => {
|
123
|
-
:hover => {
|
124
|
-
:enabled => true,
|
125
|
-
:lineColor => '#666666'
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
when 'spline'
|
132
|
-
@chart = {
|
133
|
-
:defaultSeriesType => 'spline',
|
134
|
-
:margin => [50, 200, 60, 80]
|
135
|
-
}
|
136
|
-
end
|
137
|
-
|
138
|
-
# set the options from provided hash
|
139
|
-
options.each do |attribute, value|
|
140
|
-
if value.is_a?(Hash)
|
141
|
-
# if provided a hash attempt to merge with defaults, otherwise just override defaults
|
142
|
-
send("#{attribute}=", (send(attribute) || {}).merge_recursive(value)) if self.respond_to?("#{attribute}=")
|
143
|
-
else
|
144
|
-
send("#{attribute.to_s}=", value) if self.respond_to?("#{attribute}=")
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def self.supported_types
|
150
|
-
@@types.join(' ')
|
151
|
-
end
|
152
|
-
|
153
|
-
def jquery
|
154
|
-
query_params = instance_variables.sort.map do |var|
|
155
|
-
case var.to_s
|
156
|
-
|
157
|
-
when '@chart'
|
158
|
-
set_chart
|
159
|
-
when '@colors'
|
160
|
-
set_colors if @colors.is_a?(Array)
|
161
|
-
when '@credits'
|
162
|
-
set_credits
|
163
|
-
when '@labels'
|
164
|
-
set_labels
|
165
|
-
when '@lang'
|
166
|
-
set_lang
|
167
|
-
when '@legend'
|
168
|
-
set_legend
|
169
|
-
when '@plotOptions'
|
170
|
-
set_plotOptions
|
171
|
-
when '@point'
|
172
|
-
set_point
|
173
|
-
when '@series'
|
174
|
-
set_series
|
175
|
-
when '@subtitle'
|
176
|
-
set_subtitle
|
177
|
-
when '@symbols'
|
178
|
-
set_symbols
|
179
|
-
when '@title'
|
180
|
-
set_title
|
181
|
-
when '@toolbar'
|
182
|
-
set_toolbar
|
183
|
-
when '@tooltip'
|
184
|
-
set_tooltip
|
185
|
-
when '@x_axis'
|
186
|
-
set_x_axis
|
187
|
-
when '@y_axis'
|
188
|
-
set_y_axis
|
189
|
-
end
|
190
|
-
end.compact
|
191
|
-
|
192
|
-
"var chart = new Highcharts.Chart({
|
193
|
-
#{query_params.join(",\n")}
|
194
|
-
});"
|
195
|
-
end
|
196
|
-
|
197
|
-
private
|
198
|
-
def set_chart
|
199
|
-
"chart: {
|
200
|
-
#{concatenate_attributes(@chart)}
|
201
|
-
}"
|
202
|
-
end
|
203
|
-
|
204
|
-
def set_colors
|
205
|
-
"colors: [#{@colors.join(", ")}]"
|
206
|
-
end
|
207
|
-
|
208
|
-
def set_credits
|
209
|
-
"credits: {
|
210
|
-
#{concatenate_attributes(@credits)}
|
211
|
-
}"
|
212
|
-
end
|
213
|
-
|
214
|
-
def set_labels
|
215
|
-
"labels: {
|
216
|
-
#{concatenate_attributes(@labels)}
|
217
|
-
}"
|
218
|
-
end
|
219
|
-
|
220
|
-
def set_lang
|
221
|
-
"lang: {
|
222
|
-
#{concatenate_attributes(@lang)}
|
223
|
-
}"
|
224
|
-
end
|
225
|
-
|
226
|
-
def set_legend
|
227
|
-
"legend: {
|
228
|
-
#{concatenate_attributes(@legend)}
|
229
|
-
}"
|
230
|
-
end
|
231
|
-
|
232
|
-
def set_plotOptions
|
233
|
-
"plotOptions: {
|
234
|
-
#{concatenate_attributes(@plotOptions)}
|
235
|
-
}"
|
236
|
-
end
|
237
|
-
|
238
|
-
def set_point
|
239
|
-
"point: {
|
240
|
-
#{concatenate_attributes(@point)}
|
241
|
-
}"
|
242
|
-
end
|
243
|
-
|
244
|
-
def set_series
|
245
|
-
attrs = Array.new
|
246
|
-
@series.each do |series_hash|
|
247
|
-
ser = Array.new
|
248
|
-
series_hash.each do |key, value|
|
249
|
-
if key == 'data'
|
250
|
-
ser << "[#{concatenate_attributes(value)}]"
|
251
|
-
else
|
252
|
-
ser << "#{key}: #{typed_print(value)}"
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
attrs << "{#{ser.join(",\n")}}";
|
257
|
-
end
|
258
|
-
|
259
|
-
"series: [
|
260
|
-
#{attrs.join(",\n") + "\n"}
|
261
|
-
]"
|
262
|
-
end
|
263
|
-
|
264
|
-
def set_subtitle
|
265
|
-
"subtitle: {
|
266
|
-
#{concatenate_attributes(@subtitle)}
|
267
|
-
}"
|
268
|
-
end
|
269
|
-
|
270
|
-
def set_symbols
|
271
|
-
"symbols: [#{@symbols.join(", ")}]"
|
272
|
-
end
|
273
|
-
|
274
|
-
def set_title
|
275
|
-
"title: {
|
276
|
-
#{concatenate_attributes(@title)}
|
277
|
-
}"
|
278
|
-
end
|
279
|
-
|
280
|
-
def set_toolbar
|
281
|
-
"toolbar: {
|
282
|
-
#{concatenate_attributes(@toolbar)}
|
283
|
-
}"
|
284
|
-
end
|
285
|
-
|
286
|
-
def set_tooltip
|
287
|
-
"tooltip: {
|
288
|
-
#{concatenate_attributes(@tooltip)}
|
289
|
-
}"
|
290
|
-
end
|
291
|
-
|
292
|
-
def set_x_axis
|
293
|
-
"xAxis: {
|
294
|
-
#{concatenate_attributes(@x_axis)}
|
295
|
-
}"
|
296
|
-
end
|
297
|
-
|
298
|
-
def set_y_axis
|
299
|
-
"yAxis: {
|
300
|
-
#{concatenate_attributes(@y_axis)}
|
301
|
-
}"
|
302
|
-
end
|
303
|
-
|
304
|
-
# generic method that accepts a hash and concatenates its key/value pairs
|
305
|
-
def concatenate_attributes(attr)
|
306
|
-
attrs = Array.new
|
307
|
-
attr.each do |key, value|
|
308
|
-
if value.is_a?(Hash)
|
309
|
-
attrs << "#{key}: {#{concatenate_attributes(value)}}"
|
310
|
-
else
|
311
|
-
attrs << "#{key}: #{typed_print(value)}"
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
attrs.join(",\n") + "\n"
|
316
|
-
end
|
317
|
-
|
318
|
-
# method determines if value needs to be surrounded in single quotes
|
319
|
-
def typed_print(string)
|
320
|
-
if string.is_a?(Hash)
|
321
|
-
values = Array.new
|
322
|
-
string.each { |key, value| values << "#{key}: #{typed_print(value)}"}
|
323
|
-
"{" + values.join(", ") + "}"
|
324
|
-
elsif string.is_a?(Array)
|
325
|
-
"[" + string.map { |e| typed_print(e) } .join(", ") + "]"
|
326
|
-
elsif string.is_a?(Date)
|
327
|
-
"'#{string.strftime(@@date_format)}'"
|
328
|
-
elsif string.is_a?(String) && string != 'null' && string.strip[0..7] != 'function'
|
329
|
-
"'" + string.gsub(/['"\\\x0]/,'\\\\\0') + "'"
|
330
|
-
else
|
331
|
-
string
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
7
|
+
module RailsHighcharts
|
8
|
+
# ... ...
|
335
9
|
end #RailsHighcharts
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
describe RailsHighchartsHelper do
|
6
|
+
include RailsHighchartsHelper
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@class = "stylin"
|
10
|
+
@placeholder = "placeholder"
|
11
|
+
@chart = RailsHighcharts.new(@placeholder)
|
12
|
+
@data = "data"
|
13
|
+
@options = "options"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "high_chart_helper" do
|
17
|
+
it "should return a div with an id of high_chart object" do
|
18
|
+
hc = RailsHighcharts.new("placeholder", :class => 'stylin')
|
19
|
+
high_chart(hc.placeholder, hc).should have_selector('div', :id => hc.placeholder, :class => 'stylin')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a script" do
|
23
|
+
hc = RailsHighcharts.new("placeholder")
|
24
|
+
high_chart(hc.placeholder, hc).should have_selector('script')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "high_chart_graph" do
|
29
|
+
describe "ready function" do
|
30
|
+
it "should be a javascript script" do
|
31
|
+
high_chart(@placeholder, @chart).should have_selector('script', :type => 'text/javascript')
|
32
|
+
high_chart(@placeholder, @chart).should match(/\}\s*\)\s*;/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should generate generate ready function (no conflict with prototype)" do
|
36
|
+
high_chart(@placeholder, @chart).should match(/jQuery\(function\(\)\s*\{/)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
describe "initialize HighChart" do
|
40
|
+
it "should set Chart data" do
|
41
|
+
high_chart(@placeholder, @chart).should match(/var\s+chart\s+=\s+new\s+Highcharts.Chart/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set chart renderTo" do
|
45
|
+
high_chart(@placeholder, @chart).should match(/\"renderTo\":\"placeholder\"/)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
Record = Struct.new(:frequency, :amplitude)
|
4
|
+
|
5
|
+
|
6
|
+
describe "HighChart" do
|
7
|
+
before(:each) do
|
8
|
+
@collection = [Record.new(1,15), Record.new(2,30), Record.new(4,40)]
|
9
|
+
@data = [ [1,15], [2,30], [4,40]]
|
10
|
+
|
11
|
+
@placeholder = "placeholder"
|
12
|
+
@html_options = {:class => "stylin"}
|
13
|
+
@options = {:bars => {:show => true}}
|
14
|
+
|
15
|
+
@flot = RailsHighcharts.new(@placeholder, @html_options) {|chart| chart.options = @options }
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
# this is almost all flotomatic stuff
|
21
|
+
describe "initialization" do
|
22
|
+
it "should take an optional 'placeholder' argument" do
|
23
|
+
RailsHighcharts.new(@placeholder).placeholder.should == @placeholder
|
24
|
+
RailsHighcharts.new.placeholder.should == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should take an optional html_options argument (defaulting to 300px height)" do
|
28
|
+
RailsHighcharts.new(@html_options).placeholder.should == @html_options
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set options by default" do
|
32
|
+
RailsHighcharts.new.options.should == {
|
33
|
+
:subtitle=>{},
|
34
|
+
:chart=>{:renderTo=>nil, :defaultSeriesType=>"areaspline"},
|
35
|
+
:plot_options=>{:areaspline=>{:fillOpacity=>0.5}},
|
36
|
+
:legend=>{
|
37
|
+
:borderWidth=>1,
|
38
|
+
:backgroundColor=>"#FFFFFF",
|
39
|
+
:layout=>"vertical",
|
40
|
+
:style=>{:top=>"150px",
|
41
|
+
:left=>"150px", :position=>"absolute", :bottom=>"auto"}
|
42
|
+
},
|
43
|
+
:tooltip=>{:enabled=>true},
|
44
|
+
:x_axis=>{
|
45
|
+
:categories=>["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
46
|
+
:plotBands=>[{:to=>6.5, :from=>6.0, :color=>"rgba(68, 170, 213, .2)"}],
|
47
|
+
:labels=>{:align=>"right", :rotation=>45}},
|
48
|
+
:y_axis=>{:title=>{:text=>"Fruit units"},
|
49
|
+
:labels=>{:align=>"right"}},
|
50
|
+
:title=>{:text=>"example test title from plugin"},
|
51
|
+
:credits=>{:enabled=>false}
|
52
|
+
}
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set data empty by default" do
|
57
|
+
RailsHighcharts.new.data.should == []
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should take a block setting attributes" do
|
61
|
+
chart = RailsHighcharts.new {|f| f.data = @data ; f.options = @options }
|
62
|
+
chart.data.should == @data
|
63
|
+
chart.options.should == @options
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should take a block setting attributes" do
|
67
|
+
chart = RailsHighcharts.new {|f| f.options[:legend][:layout] = "horizontal" }
|
68
|
+
chart.options[:legend][:layout].should == "horizontal"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should change a block data without overriding options" do
|
72
|
+
chart = RailsHighcharts.new('graph') do |f|
|
73
|
+
f.series(:name=>'John', :data=>[3, 20])
|
74
|
+
f.series(:name=>'Jane',:data=> [1, 3] )
|
75
|
+
# without overriding
|
76
|
+
f.options[:chart][:defaultSeriesType] = "area"
|
77
|
+
f.options[:chart][:inverted] = true
|
78
|
+
f.options[:legend][:layout] = "horizontal"
|
79
|
+
f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
|
80
|
+
end
|
81
|
+
chart.data.should == [{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
|
82
|
+
chart.options[:legend][:layout].should == "horizontal"
|
83
|
+
chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
|
84
|
+
chart.options[:chart][:defaultSeriesType].should == "area"
|
85
|
+
chart.options[:chart][:inverted].should == true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should change a block data with overriding entire options" do
|
89
|
+
chart = RailsHighcharts.new('graph') do |f|
|
90
|
+
f.series(:name=>'John', :data=>[3, 20])
|
91
|
+
f.series(:name=>'Jane', :data=>[1, 3] )
|
92
|
+
f.title({ :text=>"example test title from controller"})
|
93
|
+
# without overriding
|
94
|
+
f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
|
95
|
+
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
96
|
+
end
|
97
|
+
chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
|
98
|
+
chart.options[:x_axis][:labels][:rotation].should == -45
|
99
|
+
chart.options[:x_axis][:labels][:align].should == "right"
|
100
|
+
chart.options[:chart][:defaultSeriesType].should == "spline"
|
101
|
+
chart.options[:chart][:renderTo].should == "myRenderArea"
|
102
|
+
chart.options[:chart][:inverted].should == true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should have subtitles" do
|
106
|
+
chart = RailsHighcharts.new('graph') do |f|
|
107
|
+
f.series(:name=>'John',:data=> [3, 20])
|
108
|
+
f.series(:name=>'Jane', :data=>[1, 3] )
|
109
|
+
f.title({ :text=>"example test title from controller"})
|
110
|
+
# without overriding
|
111
|
+
f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
|
112
|
+
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
113
|
+
f.subtitle({:text=>"Bar"})
|
114
|
+
end
|
115
|
+
chart.options[:subtitle][:text].should == "Bar"
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rails'
|
4
|
+
require 'active_support'
|
5
|
+
require 'actionpack'
|
6
|
+
require 'activerecord'
|
7
|
+
|
8
|
+
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/rails_highcharts/rails_highcharts'))
|
10
|
+
require File.dirname(__FILE__) + "/../app/helpers/rails_highcharts/rails_highcharts_helper"
|
11
|
+
|
12
|
+
require 'webrat'
|
13
|
+
|
14
|
+
Rspec.configure do |config|
|
15
|
+
config.include ActionView::Helpers
|
16
|
+
config.include Webrat::Matchers
|
17
|
+
end
|
18
|
+
|
19
|
+
module HighChartsHelper
|
20
|
+
include ActionView::Helpers::TagHelper
|
21
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_highcharts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196399
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 1
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.0.1.
|
11
|
+
- 2
|
12
|
+
version: 0.0.1.beta2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- AlexZhang
|
@@ -36,6 +36,50 @@ dependencies:
|
|
36
36
|
version: 3.0.8
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 2
|
50
|
+
- 0
|
51
|
+
version: "2.0"
|
52
|
+
type: :development
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rspec-rails
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 2
|
65
|
+
- 0
|
66
|
+
version: "2.0"
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webrat
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
39
83
|
description: Highcharts for Rails 3
|
40
84
|
email:
|
41
85
|
- blackanger.z@gmail.com
|
@@ -49,12 +93,18 @@ files:
|
|
49
93
|
- Gemfile
|
50
94
|
- Rakefile
|
51
95
|
- README.md
|
96
|
+
- app/helpers/rails_highcharts/rails_highcharts_helper.rb
|
52
97
|
- lib/generators/rails_highcharts/install_generator.rb
|
98
|
+
- lib/generators/rails_highcharts/media/javascripts/excanvas.compiled.js
|
53
99
|
- lib/generators/rails_highcharts/media/javascripts/highcharts.js
|
54
100
|
- lib/rails_highcharts/engine.rb
|
55
101
|
- lib/rails_highcharts/hash_extend.rb
|
102
|
+
- lib/rails_highcharts/rails_highcharts.rb
|
56
103
|
- lib/rails_highcharts/version.rb
|
57
104
|
- lib/rails_highcharts.rb
|
105
|
+
- spec/rails_highcharts_helper_spec.rb
|
106
|
+
- spec/rails_highcharts_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
58
108
|
has_rdoc: true
|
59
109
|
homepage: ""
|
60
110
|
licenses: []
|
@@ -91,5 +141,7 @@ rubygems_version: 1.6.2
|
|
91
141
|
signing_key:
|
92
142
|
specification_version: 3
|
93
143
|
summary: Highcharts for Rails 3
|
94
|
-
test_files:
|
95
|
-
|
144
|
+
test_files:
|
145
|
+
- spec/rails_highcharts_helper_spec.rb
|
146
|
+
- spec/rails_highcharts_spec.rb
|
147
|
+
- spec/spec_helper.rb
|