ofc2 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.
- data/.gitignore +1 -0
- data/CHANGES +44 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/MIT-LICENSE +18 -0
- data/README +29 -0
- data/Rakefile +3 -0
- data/TODO +6 -0
- data/assets/VERSION.txt +2 -0
- data/assets/open-flash-chart.swf +0 -0
- data/assets/swfobject.js +5 -0
- data/lib/ofc2.rb +298 -0
- data/lib/ofc2/version.rb +3 -0
- data/ofc2.gemspec +20 -0
- metadata +61 -0
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pkg
|
data/CHANGES
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[1.0] 23.01.2011
|
|
2
|
+
- moved to open-flash-chart-2-lug-wyrm-charmer version (http://teethgrinder.co.uk/open-flash-chart-2/downloads.php)
|
|
3
|
+
- added animation for charts
|
|
4
|
+
[1.0] rc-2 : 03.05.2009
|
|
5
|
+
- moved to open-flash-chart-2-ichor version (http://teethgrinder.co.uk/open-flash-chart-2/downloads.php)
|
|
6
|
+
- initialize methods has changed !!!
|
|
7
|
+
now use a hash eg. OFC2::SomeClass.new(:option => value, :option2 => other_value)
|
|
8
|
+
I find it more readable that old way.
|
|
9
|
+
- add radar charts http://openflashchart2.sentor.pl/chart_examples/radar
|
|
10
|
+
- remove pseudo horizontal stacked bar example
|
|
11
|
+
[0.9] rc-1 : 15.04.2009
|
|
12
|
+
- remove to_json method from OWJSON module
|
|
13
|
+
- remove remove require 'json' from plugin
|
|
14
|
+
- migrate sample application to rails 2.3
|
|
15
|
+
- remove gem 'json' from enviroment.rb
|
|
16
|
+
[0.8] rc-1 : 09.01.2009
|
|
17
|
+
- add shape drawning support, example is here:
|
|
18
|
+
http://openflashchart2.sentor.pl/chart_examples/mix_advanced_draw_shape
|
|
19
|
+
- add stacked bar keys support:
|
|
20
|
+
http://openflashchart2.sentor.pl/chart_examples/stacked_bar
|
|
21
|
+
- pseudo horizontal stacked bar, example:
|
|
22
|
+
http://openflashchart2.sentor.pl/chart_examples/mix_advanced_shapes
|
|
23
|
+
[0.7] rc-1 : 12.12.2008
|
|
24
|
+
- add Tooltip class, example is here:
|
|
25
|
+
http://openflashchart2.sentor.pl/chart_examples/mix_advanced_tooltip
|
|
26
|
+
[0.6] rc-1 : 11.12.2008
|
|
27
|
+
- now generating many inline chart on one page is possible
|
|
28
|
+
- moved to open-flash-chart-2-hyperion version
|
|
29
|
+
- remove spelling errors
|
|
30
|
+
- remove set_tooltip method, use instead set_tip or tip=
|
|
31
|
+
[0.5] beta-4
|
|
32
|
+
- methods are now generated by method_missing
|
|
33
|
+
[0.4] beta-3
|
|
34
|
+
- add ofc2_inline method to generate graph without url
|
|
35
|
+
- add instance variables getters, changes proposed by __Pavlo Masko__
|
|
36
|
+
[0.3] beta-2
|
|
37
|
+
- changed installation instructions
|
|
38
|
+
- add rake tasks to install/uninstall
|
|
39
|
+
[0.2] beta-1
|
|
40
|
+
- change README - add description, install section and info about contact
|
|
41
|
+
- make examples with basic charts
|
|
42
|
+
- compare plugin with php library and add missing class/methods
|
|
43
|
+
[0.1] alpha
|
|
44
|
+
- rewrite php library
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
2
|
+
a copy of this software and associated documentation files (the
|
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
7
|
+
the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be
|
|
10
|
+
included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
About
|
|
2
|
+
=====================================
|
|
3
|
+
open flash chart 2 plugin for rails applications
|
|
4
|
+
|
|
5
|
+
This library was ported from the open flash chart project's php code to be used with Ruby on Rails.
|
|
6
|
+
Visit the open flash chart project here - http://teethgrinder.co.uk/open-flash-chart-2/
|
|
7
|
+
|
|
8
|
+
NOTE:
|
|
9
|
+
sample application is using haml
|
|
10
|
+
gem install haml
|
|
11
|
+
|
|
12
|
+
If You use rails older that 2.3 probably you have to uncomment method to_json (vendor/plugins/open_flash_chart/lib/open_flash_chart.rb line 14)
|
|
13
|
+
and add gem 'json' in enviroment.rb
|
|
14
|
+
otherwise plugin will not work propertly
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Details
|
|
18
|
+
=====================================
|
|
19
|
+
Go to http://openflashchart2.heroku.com/ for details
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Help
|
|
23
|
+
=====================================
|
|
24
|
+
Looking for help?
|
|
25
|
+
try:
|
|
26
|
+
home page: http://openflashchart2.heroku.com/infos
|
|
27
|
+
or email to me: lisukorin [at] gmail [dot] com,
|
|
28
|
+
don't forget write 'open flash chart' in subject or my mail client will treat your message as spam.
|
|
29
|
+
|
data/Rakefile
ADDED
data/TODO
ADDED
data/assets/VERSION.txt
ADDED
|
Binary file
|
data/assets/swfobject.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
|
|
2
|
+
Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
|
|
3
|
+
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
|
4
|
+
*/
|
|
5
|
+
var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();
|
data/lib/ofc2.rb
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
module OFC2
|
|
2
|
+
|
|
3
|
+
# specjal module included in each class
|
|
4
|
+
# with that module we add to_hash method
|
|
5
|
+
# there is also a method_missing which allow user to set/get any instance variable
|
|
6
|
+
# if user try to get not setted instance variable it return nil and generate a warn
|
|
7
|
+
module OWJSON
|
|
8
|
+
# return a hash of instance values
|
|
9
|
+
def to_hash
|
|
10
|
+
self.instance_values
|
|
11
|
+
end
|
|
12
|
+
alias :to_h :to_hash
|
|
13
|
+
|
|
14
|
+
# if You use rails older that 2.3 probably you have to uncomment that method and add "config.gem 'json'" in config/enviroment.rb file
|
|
15
|
+
# otherwise to_json method will not work propertly
|
|
16
|
+
# # You can pass options to to_json method, but remember that they have no effects!!!
|
|
17
|
+
# # argument 'options' is for rails compability
|
|
18
|
+
# def to_json(options = {})
|
|
19
|
+
# to_hash.to_json
|
|
20
|
+
# end
|
|
21
|
+
|
|
22
|
+
# method_missing handle setting and getting instance variables
|
|
23
|
+
# You can set variable in two ways:
|
|
24
|
+
# 1. variable_name = value
|
|
25
|
+
# 1. set_variable_name(value)
|
|
26
|
+
# you can get only alredy setted variables, otherwise return nil
|
|
27
|
+
def method_missing(method_id, *arguments)
|
|
28
|
+
a = arguments[0] if arguments and arguments.size > 0
|
|
29
|
+
method = method_id.to_s
|
|
30
|
+
if method =~ /^(.*)(=)$/
|
|
31
|
+
self.instance_variable_set("@#{$1.gsub('_','__')}", a)
|
|
32
|
+
elsif method =~ /^(set_)(.*)$/
|
|
33
|
+
self.instance_variable_set("@#{$2.gsub('_','__')}", a)
|
|
34
|
+
elsif self.instance_variable_defined?("@#{method_id.to_s.gsub('_','__')}")
|
|
35
|
+
self.instance_variable_get("@#{method_id.to_s.gsub('_','__')}") # that will be return instance variable value or nil, handy
|
|
36
|
+
else
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Engine < Rails::Engine
|
|
43
|
+
initializer "ofc2" do |app|
|
|
44
|
+
ActionController::Base.send :include, OFC2::InstanceMethods
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module InstanceMethods
|
|
49
|
+
# generate a ofc object using Graph object, it's more handy than ofc2 method
|
|
50
|
+
# +width+ width for div
|
|
51
|
+
# +height+ height for div
|
|
52
|
+
# +graph+ a OFC2::Graph object
|
|
53
|
+
# +base+ uri for graph, default '/', not used in this method, go to ofc2 method for details
|
|
54
|
+
# +id+ id for div with graph, default Time.now.usec
|
|
55
|
+
# +swf_base+ uri for swf file, default '/'
|
|
56
|
+
def ofc2_inline(width, height, graph, id=Time.now.usec, swf_base='/', flash_attributes = {}, flash_params = {})
|
|
57
|
+
div_name = "flashcontent_#{id}"
|
|
58
|
+
<<-EOF
|
|
59
|
+
<div id="#{div_name}"></div>
|
|
60
|
+
<script type="text/javascript">
|
|
61
|
+
|
|
62
|
+
function #{div_name}_data(){
|
|
63
|
+
return '#{graph.render}';
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
swfobject.embedSWF(
|
|
67
|
+
'#{swf_base}open-flash-chart.swf', '#{div_name}',
|
|
68
|
+
'#{width}', '#{height}','9.0.0', 'expressInstall.swf',
|
|
69
|
+
{'get-data':'#{div_name}_data'}, #{flash_params.to_json}, #{flash_attributes.to_json} );
|
|
70
|
+
|
|
71
|
+
</script>
|
|
72
|
+
EOF
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# generate a ofc object using data from url
|
|
76
|
+
# +width+ width for div
|
|
77
|
+
# +height+ height for div
|
|
78
|
+
# +url+ an url which return data in json format, if you use url_for method to set url param the base param must be set to '' (empty string)
|
|
79
|
+
# +base+ uri for graph, default '/'
|
|
80
|
+
# +id+ id for div with graph, default Time.now.usec
|
|
81
|
+
# +swf_base+ uri for swf file, default '/'
|
|
82
|
+
def ofc2(width, height, url, base='/', id =Time.now.usec, swf_base='/', flash_attributes = {}, flash_params = {})
|
|
83
|
+
url = CGI::escape(url)
|
|
84
|
+
div_name = "flashcontent_#{id}"
|
|
85
|
+
<<-EOF
|
|
86
|
+
<div id='#{div_name}'></div>
|
|
87
|
+
<script type="text/javascript">
|
|
88
|
+
swfobject.embedSWF(
|
|
89
|
+
"#{swf_base}open-flash-chart.swf","#{div_name}",
|
|
90
|
+
"#{width}", "#{height}", "9.0.0", "expressInstall.swf",
|
|
91
|
+
{"data-file":"#{base}#{url}"}, #{flash_params.to_json}, #{flash_attributes.to_json} );
|
|
92
|
+
|
|
93
|
+
</script>
|
|
94
|
+
EOF
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
CLASSES = {
|
|
100
|
+
:animation =>{},
|
|
101
|
+
:dot =>{ :unavailable_variables => { :type => 'dot' } },
|
|
102
|
+
:solid_dot =>{ :unavailable_variables => { :type => 'solid-dot' } },
|
|
103
|
+
:hollow_dot =>{ :unavailable_variables => { :type => 'hollow-dot' } },
|
|
104
|
+
:star =>{ :unavailable_variables => { :type => 'star' } },
|
|
105
|
+
:bow => { :unavailable_variables => { :type => 'bow' } },
|
|
106
|
+
:anchor => { :unavailable_variables => { :type => 'anchor' } },
|
|
107
|
+
:title => { :default_variables => { :text => '', :style => "{font-size: 20px; color: #FF0F0F; text-align: center;}" } },
|
|
108
|
+
:line_style => { :default_variables => { :style => 'dash', :on => '', :off => '' } },
|
|
109
|
+
:line => {
|
|
110
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00' },
|
|
111
|
+
:unavailable_variables => { :type => "line" }
|
|
112
|
+
},
|
|
113
|
+
:area => {
|
|
114
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :fill => '#0000FF', :fill_alpha => 0.6, :loop => false},
|
|
115
|
+
:unavailable_variables => { :type => "area" }
|
|
116
|
+
},
|
|
117
|
+
:bar_stack_value => { :default_variables => { :value => 0, :colour => '#FF0000'} },
|
|
118
|
+
:bar_stack_key => { :default_variables => { :text => '', :colour => '#FF0000', :font_size => 12 } },
|
|
119
|
+
:bar_stack => {
|
|
120
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
121
|
+
:unavailable_variables => { :type => "bar_stack" }
|
|
122
|
+
},
|
|
123
|
+
:h_bar_value => { :default_variables => { :left => 0, :right => nil} },
|
|
124
|
+
:h_bar => {
|
|
125
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00'},
|
|
126
|
+
:unavailable_variables => { :type => "hbar" }
|
|
127
|
+
},
|
|
128
|
+
:bar_value => { :default_variables => { :top => 0, :bottom => nil, :colour => '#FF0000', :tip => '#val#' } },
|
|
129
|
+
:bar => {
|
|
130
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
131
|
+
:unavailable_variables => { :type => "bar" },
|
|
132
|
+
},
|
|
133
|
+
:bar_cylinder_outline => {
|
|
134
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
135
|
+
:unavailable_variables => { :type => "bar_cylinder_outline" },
|
|
136
|
+
},
|
|
137
|
+
:bar_cylinder => {
|
|
138
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
139
|
+
:unavailable_variables => { :type => "bar_cylinder" },
|
|
140
|
+
},
|
|
141
|
+
:bar_filled => {
|
|
142
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :outline_colour => '#00FF00', :alpha => 0.6},
|
|
143
|
+
:unavailable_variables => { :type => "bar_filled" },
|
|
144
|
+
},
|
|
145
|
+
:bar_sketch => {
|
|
146
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :outline_colour => '#00FF00', :alpha => 0.6, :offset => 4 },
|
|
147
|
+
:unavailable_variables => { :type => "bar_sketch" },
|
|
148
|
+
},
|
|
149
|
+
:bar_glass => {
|
|
150
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
151
|
+
:unavailable_variables => { :type => "bar_glass" },
|
|
152
|
+
},
|
|
153
|
+
:bar_round_glass => {
|
|
154
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
155
|
+
:unavailable_variables => { :type => "bar_round_glass" },
|
|
156
|
+
},
|
|
157
|
+
:bar_round => {
|
|
158
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
159
|
+
:unavailable_variables => { :type => "bar_round" },
|
|
160
|
+
},
|
|
161
|
+
:bar_dome => {
|
|
162
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
163
|
+
:unavailable_variables => { :type => "bar_dome" },
|
|
164
|
+
},
|
|
165
|
+
:bar3d => {
|
|
166
|
+
:default_variables => { :text => 'label text', :font_size => 10, :colour => '#00FF00', :alpha => 0.6 },
|
|
167
|
+
:unavailable_variables => { :type => "bar_3d" },
|
|
168
|
+
},
|
|
169
|
+
:pie_value => { },
|
|
170
|
+
:pie_fade => { :unavailable_variables => { :type => "fade" } },
|
|
171
|
+
:pie_bounce => {
|
|
172
|
+
:default_variables => { :distance => 5},
|
|
173
|
+
:unavailable_variables => { :type => "bounce" },
|
|
174
|
+
},
|
|
175
|
+
:pie => {
|
|
176
|
+
:default_variables => { :colours => [], :alpha => 0.6, :start_angle => 35, :tip => '#val#', :gradient_fill => false, :label_colour => '#0000FF', :no_labels => false, :on_click => ''},
|
|
177
|
+
:unavailable_variables => { :type => "pie" },
|
|
178
|
+
},
|
|
179
|
+
:y_axis => { },
|
|
180
|
+
:y_axis_right => { },
|
|
181
|
+
:y_legend => { :default_variables => { :text => "y legend", :style =>"{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}" } },
|
|
182
|
+
:y2_legend => { :default_variables => { :text => "y2 legend", :style =>"{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}" } },
|
|
183
|
+
:x_axis_label => { },
|
|
184
|
+
:x_axis_labels => { },
|
|
185
|
+
:x_axis => { },
|
|
186
|
+
:x_legend => { :default_variables => { :text => "y legend", :style =>"{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}" } },
|
|
187
|
+
:tooltip => { },
|
|
188
|
+
:ofc_menu_item => {
|
|
189
|
+
:default_variables => { :text => '', :javascript_function => '' },
|
|
190
|
+
:unavailable_variables => { :type => 'text' },
|
|
191
|
+
},
|
|
192
|
+
:ofc_menu_item_camera => {
|
|
193
|
+
:default_variables => { :text => '', :javascript_function => '' },
|
|
194
|
+
:unavailable_variables => { :type => 'camera-icon' },
|
|
195
|
+
},
|
|
196
|
+
:ofc_menu => {
|
|
197
|
+
:default_variables => { :colour => '', :outline__colour => '' },
|
|
198
|
+
:unavailable_variables => { :type => 'camera-icon' },
|
|
199
|
+
},
|
|
200
|
+
:scatter_value => { :default_variables => { :x => 0, :y => 0} },
|
|
201
|
+
:scatter => {
|
|
202
|
+
:default_variables => { :text => 'label', :colour => '#FF0000' },
|
|
203
|
+
:unavailable_variables => { :type => 'scatter' },
|
|
204
|
+
},
|
|
205
|
+
:scatter_line => {
|
|
206
|
+
:default_variables => { :text => 'label', :colour => '#FF0000', :stepgraph => 'horizontal'},
|
|
207
|
+
:unavailable_variables => { :type => 'scatter_line' },
|
|
208
|
+
},
|
|
209
|
+
:shape_point => { :default_variables => { :x => 0, :y => 0} },
|
|
210
|
+
:shape => {
|
|
211
|
+
:default_variables => { :colour => '#FF0000'},
|
|
212
|
+
:unavailable_variables => { :type => 'shape' },
|
|
213
|
+
},
|
|
214
|
+
:radar_axis_labels => { :default_variables => { :labels => [], :colour => '#FAFFAF'} },
|
|
215
|
+
:radar_spoke_labels => { :default_variables => { :labels => [], :colour => '#FAFFAF'} },
|
|
216
|
+
:radar_axis => { }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
CLASSES.each_key do |class_name|
|
|
220
|
+
_class_name =class_name.to_s.camelize
|
|
221
|
+
new_class = Class.new do
|
|
222
|
+
include OWJSON
|
|
223
|
+
|
|
224
|
+
def initialize( opts = {})
|
|
225
|
+
class_data = CLASSES[self.class.name.demodulize.underscore.to_sym]
|
|
226
|
+
|
|
227
|
+
class_data[:default_variables].each do |name, value|
|
|
228
|
+
# self.instance_variable_set("@#{name.to_s.gsub('_','__')}", value)
|
|
229
|
+
self.send("#{name}=", value)
|
|
230
|
+
end if class_data[:default_variables]
|
|
231
|
+
|
|
232
|
+
opts.each do |name, value|
|
|
233
|
+
# self.instance_variable_set("@#{name.to_s.gsub('_','__')}", value)
|
|
234
|
+
self.send("#{name}=", value)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
class_data[:unavailable_variables].each do |name, value|
|
|
238
|
+
# self.instance_variable_set("@#{name.to_s.gsub('_','__')}", value)
|
|
239
|
+
self.send("#{name}=", value)
|
|
240
|
+
end if class_data[:unavailable_variables]
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
const_set(_class_name, new_class)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
# +title+
|
|
250
|
+
# +x_axis+
|
|
251
|
+
# +y_axis+
|
|
252
|
+
# +y_axis_right+
|
|
253
|
+
# +x_legend+
|
|
254
|
+
# +y_legend+
|
|
255
|
+
# +bg_colour+
|
|
256
|
+
# +elements+
|
|
257
|
+
class Graph
|
|
258
|
+
include OWJSON
|
|
259
|
+
|
|
260
|
+
# it must be done in that way because method_missing method replace _ to __,
|
|
261
|
+
# maybe I add seccond parameter to handle with that
|
|
262
|
+
%w(radar_axis x_axis y_axis y_axis_right x_legend y_legend y2_legend bg_colour).each do |method|
|
|
263
|
+
define_method("set_#{method}") do |a|
|
|
264
|
+
self.instance_variable_set("@#{method}", a)
|
|
265
|
+
end
|
|
266
|
+
define_method("#{method}=") do |a|
|
|
267
|
+
self.instance_variable_set("@#{method}", a)
|
|
268
|
+
end
|
|
269
|
+
define_method("#{method}") do
|
|
270
|
+
self.instance_variable_get("@#{method}")
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def initialize(opts = {})
|
|
275
|
+
@title = Title.new(:text => "Graph" )
|
|
276
|
+
@elements = []
|
|
277
|
+
opts.each do |name, value|
|
|
278
|
+
self.send("#{name}=", value)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def add_element( e )
|
|
283
|
+
@elements << e
|
|
284
|
+
end
|
|
285
|
+
alias_method :<<, :add_element
|
|
286
|
+
|
|
287
|
+
def render
|
|
288
|
+
s = to_json
|
|
289
|
+
# about underscores
|
|
290
|
+
s.gsub!('___','') # that is for @___3d variable
|
|
291
|
+
s.gsub!('__','-') # that is for @smt__smt variables
|
|
292
|
+
# variables @smt_smt should go without changes
|
|
293
|
+
s
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
end
|
data/lib/ofc2/version.rb
ADDED
data/ofc2.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "ofc2/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "ofc2"
|
|
7
|
+
s.version = OFC2::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["Rafał Lisowski"]
|
|
10
|
+
s.email = ["lisukorin@gmail.com"]
|
|
11
|
+
s.homepage = "http://github.com/korin/open_flash_chart_2_plugin"
|
|
12
|
+
s.summary = %q{open flash chart 2 plugin for rails applications}
|
|
13
|
+
s.description = %q{This library was ported from the open flash chart project's php code to be used with Ruby on Rails.}
|
|
14
|
+
s.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
|
+
s.require_paths = ["lib"]
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ofc2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Rafał Lisowski
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-01-23 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: This library was ported from the open flash chart project's php code
|
|
15
|
+
to be used with Ruby on Rails.
|
|
16
|
+
email:
|
|
17
|
+
- lisukorin@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- .gitignore
|
|
23
|
+
- CHANGES
|
|
24
|
+
- Gemfile
|
|
25
|
+
- Gemfile.lock
|
|
26
|
+
- MIT-LICENSE
|
|
27
|
+
- README
|
|
28
|
+
- Rakefile
|
|
29
|
+
- TODO
|
|
30
|
+
- assets/VERSION.txt
|
|
31
|
+
- assets/open-flash-chart.swf
|
|
32
|
+
- assets/swfobject.js
|
|
33
|
+
- lib/ofc2.rb
|
|
34
|
+
- lib/ofc2/version.rb
|
|
35
|
+
- ofc2.gemspec
|
|
36
|
+
homepage: http://github.com/korin/open_flash_chart_2_plugin
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
post_install_message:
|
|
40
|
+
rdoc_options: []
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
none: false
|
|
45
|
+
requirements:
|
|
46
|
+
- - ! '>='
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubyforge_project:
|
|
57
|
+
rubygems_version: 1.8.10
|
|
58
|
+
signing_key:
|
|
59
|
+
specification_version: 3
|
|
60
|
+
summary: open flash chart 2 plugin for rails applications
|
|
61
|
+
test_files: []
|