anychart_xml_builder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.project ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>aaa</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ </natures>
11
+ </projectDescription>
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jduarte
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = anychart_xml_builder
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 jduarte. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.version = "0.0.1"
8
+ gem.name = "anychart_xml_builder"
9
+ gem.summary = %Q{AnyChart (http://anychart.com/home/) XML Builders}
10
+ gem.description = %Q{This gem provides you the methods to easily generate the XML necessary for AnyChart}
11
+ gem.email = "jose.fduarte@gmail.com"
12
+ gem.homepage = "http://github.com/jduarte/anychart_xml_builder"
13
+ gem.authors = ["jduarte"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ gem.add_dependency "nokogiri", ">= 1.4.1"
16
+
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "anychart_xml_builder #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{anychart_xml_builder}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jduarte"]
12
+ s.date = %q{2010-02-19}
13
+ s.description = %q{This gem provides you the methods to easily generate the XML necessary for AnyChart}
14
+ s.email = %q{jose.fduarte@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".project",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "anychart_xml_builder.gemspec",
27
+ "lib/anychart_xml_builder.rb",
28
+ "lib/column_bar.rb",
29
+ "test/helper.rb",
30
+ "test/test_anychart_xml_builder.rb",
31
+ "test/xml/sample_71.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/jduarte/anychart_xml_builder}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{AnyChart (http://anychart.com/home/) XML Builders}
38
+ s.test_files = [
39
+ "test/helper.rb",
40
+ "test/test_anychart_xml_builder.rb",
41
+ "test/xml/sample_71.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,8 @@
1
+ require 'nokogiri'
2
+ require 'column_bar'
3
+
4
+ module Anychart
5
+ module XML
6
+
7
+ end
8
+ end
data/lib/column_bar.rb ADDED
@@ -0,0 +1,136 @@
1
+ module Anychart
2
+ module XML
3
+ module ColumnBar
4
+ ## Options
5
+ #
6
+ # :tooltip => "{%Name} - {%YValue}",
7
+ # :chart => {
8
+ # :title => "Multi-Series: with Simple Legend",
9
+ # :legend => "{%Icon} {%Name} ({%Value})",
10
+ # :axes => {
11
+ # :y => "{%Value}{numDecimals:0}"
12
+ # }
13
+ # },
14
+ # :data => {
15
+ # :series => [
16
+ # {:name => "Series 1",
17
+ # :points => [ {:name => "P1", :value => "12"},
18
+ # {:name => "P2", :value => "24"}
19
+ # ]
20
+ # },
21
+ # {:name => "Series 2",
22
+ # :points => [ {:name => "P1", :value => "23"},
23
+ # {:name => "P2", :value => "45"}
24
+ # ]
25
+ # }
26
+ # ]
27
+ # }
28
+
29
+ @@default_xml_options = {
30
+ :animation => true,
31
+ :tooltip => false, # "{%Name} - {%YValue}"
32
+ :chart => {
33
+ :title => false,
34
+ :legend => false,
35
+ :axes => {
36
+ :y => "{%Value}{numDecimals:0}",
37
+ :x => false
38
+ }
39
+ },
40
+ :data => {
41
+ :series => [
42
+ {:name => "Serie de omissao",
43
+ :points => [{:name => "X1", :value => "1"},{:name => "X2", :value => "2"}]
44
+ }
45
+ ]
46
+ }
47
+ }
48
+
49
+
50
+ def self.xml(options={})
51
+ p = @@default_xml_options.merge(options)
52
+
53
+ builder = Nokogiri::XML::Builder.new do |xml|
54
+ xml.anychart {
55
+ xml.settings {
56
+ xml.animation(:enabled => "True") if p[:animation]
57
+ }
58
+ xml.charts {
59
+ xml.chart(:plot_type => "CategorizedVertical") {
60
+ xml.data_plot_settings(:default_series_type => "Bar") {
61
+ xml.bar_series(:point_padding => "0.2", :group_padding => "1") {
62
+ if p[:tooltip]
63
+ xml.tooltip_settings(:enabled => "True") {
64
+ xml.format p[:tooltip]
65
+ }
66
+ else
67
+ xml.tooltip_settings(:enabled => "False") {}
68
+ end
69
+ }
70
+ }
71
+
72
+ xml.chart_settings {
73
+ if p[:chart][:title]
74
+ xml.title(:enabled => "true") {
75
+ xml.text_ p[:chart][:title]
76
+ }
77
+ end
78
+ if p[:chart][:legend]
79
+ xml.legend(:enabled => "true", :position => "Right", :align => "Near") {
80
+ xml.format p[:chart][:legend]
81
+ xml.template {}
82
+ if p[:chart][:legend][:title]
83
+ xml.title(:enabled => "true") { p[:chart][:legend][:title] }
84
+ else
85
+ xml.title(:enabled => "false") {}
86
+ end
87
+
88
+ xml.columns_separator(:enabled => "false") {}
89
+ xml.background {
90
+ xml.inside_margin(:left => "10", :right => "10") {}
91
+ }
92
+ }
93
+ end
94
+
95
+ xml.axes {
96
+ if p[:chart][:axes][:y]
97
+ xml.y_axis {
98
+ xml.labels {
99
+ xml.format p[:chart][:axes][:y]
100
+ }
101
+ }
102
+ end
103
+
104
+ if p[:chart][:axes][:x]
105
+ xml.y_axis {
106
+ xml.labels {
107
+ xml.format p[:chart][:axes][:x]
108
+ }
109
+ }
110
+ end
111
+
112
+ }
113
+ }
114
+
115
+ xml.data {
116
+ series = (p[:data][:series].kind_of?(Array) ? p[:data][:series] : [p[:data][:series]])
117
+ raise "Series incorrectas" if series.empty?
118
+
119
+ series.each do |serie|
120
+ xml.series(:name => serie[:name]) {
121
+ # Os varios pontos
122
+ serie[:points].each do |point|
123
+ xml.point(:name => point[:name].to_s, :y => point[:value].to_s)
124
+ end
125
+ }
126
+ end
127
+ }
128
+ }
129
+ }
130
+ }
131
+ end
132
+ builder.to_xml.gsub(/>[ \t\r\n]+</, '><')
133
+ end
134
+ end
135
+ end
136
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'anychart_xml_builder'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+ require 'xml/sample_71'
3
+
4
+ class TestAnychartXmlBuilder < Test::Unit::TestCase
5
+ should "create valid XML file like anychart/gallery/sample_71.xml" do
6
+ assert_equal(Sample71.xml.gsub(/>[ \t\r\n]+</, '><'), Anychart::XML::ColumnBar.xml(:tooltip => "{%Name} - {%YValue}",
7
+ :chart => {
8
+ :title => "Multi-Series: with Simple Legend",
9
+ :legend => "{%Icon} {%Name} ({%Value})",
10
+ :axes => {
11
+ :y => "{%Value}{numDecimals:0}"
12
+ }
13
+ },
14
+ :data => {
15
+ :series => [
16
+ {:name => "Series 1",
17
+ :points => [ {:name => "P1", :value => "12"},
18
+ {:name => "P2", :value => "24"}
19
+ ]
20
+ },
21
+ {:name => "Series 2",
22
+ :points => [ {:name => "P1", :value => "23"},
23
+ {:name => "P2", :value => "45"}
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ ))
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ class Sample71
2
+ def self.xml
3
+ "<?xml version=\"1.0\"?><anychart>
4
+ <settings>
5
+ <animation enabled=\"True\"/>
6
+ </settings>
7
+ <charts>
8
+ <chart plot_type=\"CategorizedVertical\">
9
+ <data_plot_settings default_series_type=\"Bar\">
10
+ <bar_series group_padding=\"1\" point_padding=\"0.2\">
11
+ <tooltip_settings enabled=\"True\">
12
+ <format>{%Name} - {%YValue}</format>
13
+ </tooltip_settings>
14
+ </bar_series>
15
+ </data_plot_settings>
16
+ <chart_settings>
17
+ <title enabled=\"true\">
18
+ <text>Multi-Series: with Simple Legend</text>
19
+ </title>
20
+ <legend align=\"Near\" position=\"Right\" enabled=\"true\">
21
+ <format>{%Icon} {%Name} ({%Value})</format>
22
+ <template/>
23
+ <title enabled=\"false\"/>
24
+ <columns_separator enabled=\"false\"/>
25
+ <background>
26
+ <inside_margin left=\"10\" right=\"10\"/>
27
+ </background>
28
+ </legend>
29
+ <axes>
30
+ <y_axis>
31
+ <labels>
32
+ <format>{%Value}{numDecimals:0}</format>
33
+ </labels>
34
+ </y_axis>
35
+ </axes>
36
+ </chart_settings>
37
+ <data>
38
+ <series name=\"Series 1\">
39
+ <point name=\"P1\" y=\"12\"/>
40
+ <point name=\"P2\" y=\"24\"/>
41
+ </series>
42
+
43
+ <series name=\"Series 2\">
44
+ <point name=\"P1\" y=\"23\"/>
45
+ <point name=\"P2\" y=\"45\"/>
46
+ </series>
47
+ </data>
48
+ </chart>
49
+ </charts>
50
+ </anychart>\n"
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anychart_xml_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jduarte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-19 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.1
34
+ version:
35
+ description: This gem provides you the methods to easily generate the XML necessary for AnyChart
36
+ email: jose.fduarte@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - .project
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - anychart_xml_builder.gemspec
52
+ - lib/anychart_xml_builder.rb
53
+ - lib/column_bar.rb
54
+ - test/helper.rb
55
+ - test/test_anychart_xml_builder.rb
56
+ - test/xml/sample_71.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/jduarte/anychart_xml_builder
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: AnyChart (http://anychart.com/home/) XML Builders
85
+ test_files:
86
+ - test/helper.rb
87
+ - test/test_anychart_xml_builder.rb
88
+ - test/xml/sample_71.rb