anychart_xml_builder 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/HELP_COMMIT ADDED
@@ -0,0 +1,4 @@
1
+ Alterar versao Rakefile
2
+ rake build
3
+ rake install
4
+ gem push pkg/...
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.version = "0.0.7"
7
+ gem.version = "0.0.8"
8
8
  gem.name = "anychart_xml_builder"
9
9
  gem.summary = %Q{AnyChart (http://anychart.com/home/) XML Builders}
10
10
  gem.description = %Q{This gem provides you the methods to easily generate the XML necessary for AnyChart}
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jduarte"]
12
- s.date = %q{2011-01-17}
12
+ s.date = %q{2011-01-22}
13
13
  s.description = %q{This gem provides you the methods to easily generate the XML necessary for AnyChart}
14
14
  s.email = %q{jose.fduarte@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/anychart/anychart_helpers.rb",
28
28
  "lib/anychart_xml_builder.rb",
29
29
  "lib/column_bar.rb",
30
+ "lib/line_bar.rb",
30
31
  "lib/init.rb",
31
32
  "lib/pie.rb",
32
33
  "lib/xml_sections/chart_title.rb",
@@ -10,59 +10,68 @@ module ActionView #:nodoc:
10
10
  end
11
11
 
12
12
  module InstanceMethods
13
+ rand = ActiveSupport::SecureRandom.hex
13
14
  @@default_options = {
14
15
  :anychart_swf_path => '/anychart/swf/AnyChart.swf',
15
16
  :anychart_swf_preloader => '/anychart/swf/Preloader.swf',
16
- :table_id => 'anychart_table_wrap',
17
- :td_id => "anychart_#{ActiveSupport::SecureRandom.hex}"
17
+ :wrap_id => "anychart_wrap_#{rand}",
18
+ :wrap_class => "anychart_wrap",
19
+ :id => "anychart_graph_#{rand}",
20
+ :class => "anychart_graph",
21
+ :chart_height => "100%",
22
+ :chart_width => "100%"
18
23
  }
19
24
 
20
25
  def anychart(xml, options={})
21
26
  opts = @@default_options.merge(options)
22
-
23
- "<table class='anychart_graph_wrap' cellpadding='0' cellspacing='0' style='width:100%;height:100%;'><tr>
24
- <td id='#{opts[:td_id]}' style='height:100%;width:100%;' colspan='2'>
25
- <noscript>
26
- <object id='chart'
27
- name='chart'
28
- classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
29
- width='100%'
30
- height='100%'
31
- codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'>
32
- <param name='movie' value='#{opts[:anychart_swf_preloader]}' />
33
- <param name='bgcolor' value='#FFFFFF' />
34
- <param name='allowScriptAccess' value='always' />
35
- <param name='flashvars' value='swfFile=#{opts[:anychart_swf_path]}&XMLFile=#{xml}' />
27
+
28
+ chart_height = opts[:chart_height].kind_of?(String) ? opts[:chart_height] : "#{opts[:chart_height]}px"
29
+ chart_width = opts[:chart_width].kind_of?(String) ? opts[:chart_width] : "#{opts[:chart_width]}px"
30
+
31
+
32
+ "<div class='#{opts[:wrap_class]}' id='#{opts[:wrap_id]}'>
33
+ <div class='#{opts[:class]}' id='#{opts[:id]}'>
34
+ <noscript>
35
+ <object id='obj_#{opts[:id]}'
36
+ name='obj_#{opts[:id]}'
37
+ classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
38
+ width='100%'
39
+ height='100%'
40
+ codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'>
41
+ <param name='movie' value='#{opts[:anychart_swf_preloader]}' />
42
+ <param name='bgcolor' value='#FFFFFF' />
43
+ <param name='allowScriptAccess' value='always' />
44
+ <param name='flashvars' value='swfFile=#{opts[:anychart_swf_path]}&XMLFile=#{xml}' />
36
45
 
37
- <embed type='application/x-shockwave-flash'
38
- pluginspage='http://www.adobe.com/go/getflashplayer'
39
- src='#{opts[:anychart_swf_preloader]}'
40
- width='100%'
41
- height='100%'
42
- id='chart'
43
- name='chart'
44
- bgColor='#FFFFFF'
45
- allowScriptAccess='always'
46
- flashvars='swfFile=#{opts[:anychart_swf_path]}&XMLFile=#{xml}' />
47
- </object>
48
- </noscript>
49
- <script type='text/javascript'>
50
- //<![CDATA[
51
- document.write('<center>');
52
- document.write('You need to have Adobe Flash Player 9 (or above) to view the chart.<br /><br />');
53
- document.write('<a href=\'http://www.adobe.com/go/getflashplayer\'><img border=\'0\' src=\'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\' /></a><br />');
54
- document.write('</center>');
55
- //]]>
56
- </script>
57
- </td></tr></table>
46
+ <embed type='application/x-shockwave-flash'
47
+ pluginspage='http://www.adobe.com/go/getflashplayer'
48
+ src='#{opts[:anychart_swf_preloader]}'
49
+ width='100%'
50
+ height='100%'
51
+ id='obj_#{opts[:id]}'
52
+ name='obj_#{opts[:id]}'
53
+ bgColor='#FFFFFF'
54
+ allowScriptAccess='always'
55
+ flashvars='swfFile=#{opts[:anychart_swf_path]}&XMLFile=#{xml}' />
56
+ </object>
57
+ </noscript>
58
+ <script type='text/javascript'>
59
+ //<![CDATA[
60
+ document.write('<center>');
61
+ document.write('You need to have Adobe Flash Player 9 (or above) to view the chart.<br /><br />');
62
+ document.write('<a href=\'http://www.adobe.com/go/getflashplayer\'><img border=\'0\' src=\'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\' /></a><br />');
63
+ document.write('</center>');
64
+ //]]>
65
+ </script>
66
+ </div>
67
+ </div>
58
68
  <script type='text/javascript' language='JavaScript'>
59
69
  //<![CDATA[
60
70
  var chartSample = new AnyChart('#{opts[:anychart_swf_path]}','#{opts[:anychart_swf_preloader]}');
61
- chartSample.width = '100%';
62
- chartSample.height = '100%';
71
+ chartSample.width = '#{chart_width}';
72
+ chartSample.height = '#{chart_height}';
63
73
  chartSample.setXMLFile('#{xml}');
64
- chartSample.write('#{opts[:td_id]}');
65
- //init();
74
+ chartSample.write('#{opts[:id]}');
66
75
  //]]>
67
76
  </script>".html_safe
68
77
  end
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  require 'column_bar'
9
9
  require 'pie'
10
+ require 'line_bar'
10
11
  require 'anychart_xml_builder'
11
12
 
12
13
 
data/lib/column_bar.rb CHANGED
@@ -80,22 +80,23 @@ module Anychart
80
80
  Anychart::XML.legend(xml,p) # legend
81
81
 
82
82
  xml.axes {
83
- if p[:chart][:axes][:y]
84
- xml.y_axis {
85
- xml.labels {
86
- xml.format p[:chart][:axes][:y]
83
+ if p[:chart][:axes].present?
84
+ if p[:chart][:axes][:y]
85
+ xml.y_axis {
86
+ xml.labels {
87
+ xml.format p[:chart][:axes][:y]
88
+ }
87
89
  }
88
- }
89
- end
90
-
91
- if p[:chart][:axes][:x]
92
- xml.y_axis {
93
- xml.labels {
94
- xml.format p[:chart][:axes][:x]
90
+ end
91
+
92
+ if p[:chart][:axes][:x]
93
+ xml.y_axis {
94
+ xml.labels {
95
+ xml.format p[:chart][:axes][:x]
96
+ }
95
97
  }
96
- }
98
+ end
97
99
  end
98
-
99
100
  }
100
101
  }
101
102
 
@@ -103,7 +104,7 @@ module Anychart
103
104
  series = (p[:data][:series].kind_of?(Array) ? p[:data][:series] : [p[:data][:series]])
104
105
 
105
106
  series.each do |serie|
106
- xml.series(:name => serie[:name]) {
107
+ xml.series(:name => serie[:name], :palette => "Default") {
107
108
  # Os varios pontos
108
109
  serie[:points].each do |point|
109
110
  xml.point(:name => point[:name].to_s, :y => point[:value].to_s)
data/lib/line_bar.rb ADDED
@@ -0,0 +1,140 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Anychart
4
+ module XML
5
+ module LineBar
6
+ ## Options
7
+ #
8
+ # :tooltip => "{%Name} - {%YValue}",
9
+ # :chart => {
10
+ # :title => "Multi-Series: with Simple Legend",
11
+ # :legend => {
12
+ # :format => "{%Icon} {%Name} ({%Value})",
13
+ # :position => "Bottom",
14
+ # :title => "lalala"
15
+ # },
16
+ # :axes => {
17
+ # :y => "{%Value}{numDecimals:0}"
18
+ # }
19
+ # },
20
+ # :data => {
21
+ # :series => [
22
+ # {:name => "Series 1",
23
+ # :points => [ {:name => "P1", :value => "12"},
24
+ # {:name => "P2", :value => "24"}
25
+ # ]
26
+ # },
27
+ # {:name => "Series 2",
28
+ # :points => [ {:name => "P1", :value => "23"},
29
+ # {:name => "P2", :value => "45"}
30
+ # ]
31
+ # }
32
+ # ]
33
+ # }
34
+
35
+ @@default_xml_options = {
36
+ :animation => true,
37
+ :tooltip => false, # "{%Name} - {%YValue}"
38
+ :chart => {
39
+ :title => false,
40
+ :legend => false,
41
+ :axes => {
42
+ :y => {
43
+ :title => "Tit Ax Y",
44
+ :format => "{%Value}{numDecimals:0}"
45
+ },
46
+ :x => {
47
+ :title => false
48
+ }
49
+ },
50
+ :data => {
51
+ :series => [
52
+ {
53
+ :name => "Serie de omissao",
54
+ :points => [{:name => "X1", :value => "1"},{:name => "X2", :value => "2"}]
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ }
60
+
61
+
62
+ def self.xml(options={})
63
+ p = @@default_xml_options.merge(options)
64
+
65
+ builder = Nokogiri::XML::Builder.new do |xml|
66
+ xml.anychart {
67
+ xml.settings {
68
+ xml.animation(:enabled => "True") if p[:animation]
69
+ }
70
+ xml.charts {
71
+ xml.chart(:plot_type => "CategorizedHorizontal") {
72
+ xml.data_plot_settings(:default_series_type => "Bar") {
73
+ xml.bar_series(:group_padding => "0.7") {
74
+ if p[:tooltip]
75
+ xml.tooltip_settings(:enabled => "True") {
76
+ xml.format p[:tooltip]
77
+ }
78
+ else
79
+ xml.tooltip_settings(:enabled => "False") {}
80
+ end
81
+ }
82
+ }
83
+
84
+ xml.chart_settings {
85
+ Anychart::XML.chart_title(xml,p) # title
86
+ Anychart::XML.legend(xml,p) # legend
87
+
88
+ xml.axes {
89
+ if p[:chart][:axes].present?
90
+ if p[:chart][:axes][:y].present?
91
+ xml.y_axis(:position => "Opposite") {
92
+ if p[:chart][:axes][:y][:title].present?
93
+ xml.title {
94
+ xml.text_ p[:chart][:axes][:y][:title]
95
+ }
96
+ else
97
+ xml.title(:enabled => "false")
98
+ end
99
+ xml.labels(:align => "Inside") {
100
+ xml.format p[:chart][:axes][:y][:format] || "{%Value}"
101
+ }
102
+ }
103
+ end
104
+
105
+ if p[:chart][:axes][:x]
106
+ xml.x_axis {
107
+ if p[:chart][:axes][:x][:title].present?
108
+ xml.title {
109
+ xml.text_ p[:chart][:axes][:x][:title]
110
+ }
111
+ else
112
+ xml.title(:enabled => "false")
113
+ end
114
+ }
115
+ end
116
+ end
117
+ }
118
+ }
119
+
120
+ xml.data {
121
+ series = (p[:data][:series].kind_of?(Array) ? p[:data][:series] : [p[:data][:series]])
122
+
123
+ series.each do |serie|
124
+ xml.series(:name => serie[:name], :palette => "Default") {
125
+ # Os varios pontos
126
+ serie[:points].each do |point|
127
+ xml.point(:name => point[:name].to_s, :y => point[:value].to_s)
128
+ end
129
+ }
130
+ end
131
+ }
132
+ }
133
+ }
134
+ }
135
+ end
136
+ builder.to_xml.gsub(/>[ \t\r\n]+</, '><')
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,3 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
1
3
  module Anychart
2
4
  module XML
3
5
  def self.chart_title(xml,p,opts={})
@@ -1,24 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ #<format>{%Icon} {%Name} ({%YValue})</format>
4
+ #<template/>
5
+ #−
6
+ #<title enabled="true">
7
+ #<text>Products Sales</text>
8
+ #</title>
9
+ #<columns_separator enabled="false"/>
10
+ #−
11
+ #<background>
12
+ #<inside_margin left="10" right="10"/>
13
+ #</background>
14
+ #−
15
+ #<items>
16
+ #<item source="Points"/>
17
+ #</items>
18
+
1
19
  module Anychart
2
20
  module XML
3
- def self.legend(xml,p,options={})
21
+ def self.legend(xml,p,options={})
4
22
  if p[:chart][:legend].present?
5
- legend_position = p[:chart][:legend][:position] || "Bottom"
6
- xml.legend(:enabled => "true", :position => legend_position, :align => "Near", :ignore_auto_item => "true") {
7
- xml.format(p[:chart][:legend][:format]) if p[:chart][:legend][:format].present?
23
+
24
+ position = p[:chart][:legend][:position] || "Bottom"
25
+ format = p[:chart][:legend][:format] || "{%Icon} {%Name} ({%YValue}"
26
+ title = p[:chart][:legend][:title] || "Legenda"
27
+ align = p[:chart][:legend][:align] || "Near"
28
+
29
+ xml.legend(:enabled => "true", :position => position, :align => align, :ignore_auto_item => "true") {
30
+ xml.format format
8
31
  xml.template {}
9
32
 
10
33
  if p[:chart][:legend][:title].present?
11
- xml.title(:enabled => "true") { p[:chart][:legend][:title] }
34
+ xml.title(:enabled => "true") {
35
+ xml.text_ title
36
+ }
12
37
  else
13
- xml.title(:enabled => "false") {}
38
+ xml.title(:enabled => "false") { }
14
39
  end
15
40
 
16
- xml.columns_separator(:enabled => "false") {}
41
+ xml.columns_separator(:enabled => "false") { }
17
42
  xml.background {
18
43
  xml.inside_margin(:left => "10", :right => "10") {}
19
44
  }
45
+ xml.items {
46
+ xml.item(:source => "Points")
47
+ }
20
48
  }
21
49
  end # legend
50
+
22
51
  end
23
52
  end
24
53
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - jduarte
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-17 00:00:00 +00:00
17
+ date: 2011-01-23 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -57,6 +57,7 @@ extra_rdoc_files:
57
57
  files:
58
58
  - .document
59
59
  - .project
60
+ - HELP_COMMIT
60
61
  - LICENSE
61
62
  - README.rdoc
62
63
  - Rakefile
@@ -65,6 +66,7 @@ files:
65
66
  - lib/anychart_xml_builder.rb
66
67
  - lib/column_bar.rb
67
68
  - lib/init.rb
69
+ - lib/line_bar.rb
68
70
  - lib/pie.rb
69
71
  - lib/xml_sections/chart_title.rb
70
72
  - lib/xml_sections/legend.rb