anychart_xml_builder 0.0.3 → 0.0.4
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/Rakefile +1 -1
- data/anychart_xml_builder.gemspec +6 -3
- data/lib/anychart/{view_helpers.rb → anychart_helpers.rb} +0 -0
- data/lib/anychart_xml_builder.rb +2 -0
- data/lib/column_bar.rb +3 -3
- data/lib/pie.rb +169 -0
- data/test/test_anychart_xml_builder.rb +27 -1
- data/test/xml/sample_165.rb +63 -0
- metadata +6 -3
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
|
+
gem.version = "0.0.4"
|
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}
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{anychart_xml_builder}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
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{2010-
|
12
|
+
s.date = %q{2010-03-08}
|
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 = [
|
@@ -24,12 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.rdoc",
|
25
25
|
"Rakefile",
|
26
26
|
"anychart_xml_builder.gemspec",
|
27
|
-
"lib/anychart/
|
27
|
+
"lib/anychart/anychart_helpers.rb",
|
28
28
|
"lib/anychart_xml_builder.rb",
|
29
29
|
"lib/column_bar.rb",
|
30
30
|
"lib/init.rb",
|
31
|
+
"lib/pie.rb",
|
31
32
|
"test/helper.rb",
|
32
33
|
"test/test_anychart_xml_builder.rb",
|
34
|
+
"test/xml/sample_165.rb",
|
33
35
|
"test/xml/sample_71.rb"
|
34
36
|
]
|
35
37
|
s.homepage = %q{http://github.com/jduarte/anychart_xml_builder}
|
@@ -40,6 +42,7 @@ Gem::Specification.new do |s|
|
|
40
42
|
s.test_files = [
|
41
43
|
"test/helper.rb",
|
42
44
|
"test/test_anychart_xml_builder.rb",
|
45
|
+
"test/xml/sample_165.rb",
|
43
46
|
"test/xml/sample_71.rb"
|
44
47
|
]
|
45
48
|
|
File without changes
|
data/lib/anychart_xml_builder.rb
CHANGED
data/lib/column_bar.rb
CHANGED
@@ -74,10 +74,11 @@ module Anychart
|
|
74
74
|
xml.title(:enabled => "true") {
|
75
75
|
xml.text_ p[:chart][:title]
|
76
76
|
}
|
77
|
-
end
|
77
|
+
end # title
|
78
|
+
|
78
79
|
if p[:chart][:legend]
|
79
80
|
xml.legend(:enabled => "true", :position => "Right", :align => "Near") {
|
80
|
-
xml.format p[:chart][:legend]
|
81
|
+
xml.format p[:chart][:legend][:format] if p[:chart][:legend][:format]
|
81
82
|
xml.template {}
|
82
83
|
if p[:chart][:legend][:title]
|
83
84
|
xml.title(:enabled => "true") { p[:chart][:legend][:title] }
|
@@ -114,7 +115,6 @@ module Anychart
|
|
114
115
|
|
115
116
|
xml.data {
|
116
117
|
series = (p[:data][:series].kind_of?(Array) ? p[:data][:series] : [p[:data][:series]])
|
117
|
-
raise "Series incorrectas" if series.empty?
|
118
118
|
|
119
119
|
series.each do |serie|
|
120
120
|
xml.series(:name => serie[:name]) {
|
data/lib/pie.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
module Anychart
|
2
|
+
module XML
|
3
|
+
module Pie
|
4
|
+
## Options
|
5
|
+
#
|
6
|
+
# options = {:type => :doughnut,
|
7
|
+
# :tooltip => "${%Value}{scale:(1000)(1000)(1000)|( th)( mil)( bil),numDecimals:2}",
|
8
|
+
# :chart => {
|
9
|
+
# :title => "ACME Corp. apparel sales through different retail channels",
|
10
|
+
# :legend => true,
|
11
|
+
# :label => "{%YPercentOfSeries}{numDecimals:1}%",
|
12
|
+
# :marker => true
|
13
|
+
# },
|
14
|
+
# :data => {
|
15
|
+
# :series => [
|
16
|
+
# {:name => "Year 2003",
|
17
|
+
# :points => [ {:name => "Department Store", :value => "6371664"},
|
18
|
+
# {:name => "Discount Stores", :value => "7216301"},
|
19
|
+
# {:name => "Men's/Women's Stores", :value => "1486621"},
|
20
|
+
# {:name => "Juvenile Specialty Stores", :value => "786622"},
|
21
|
+
# {:name => "All other outlets", :value => "900000", :color => "DarkSeaGreen"}
|
22
|
+
# ]
|
23
|
+
# }
|
24
|
+
# ]
|
25
|
+
# }
|
26
|
+
# }
|
27
|
+
|
28
|
+
@@default_xml_options = {
|
29
|
+
:type => :pie, # :pie or :doughnut
|
30
|
+
:animation => true,
|
31
|
+
:tooltip => "{%Name} - ${%Value}", # "{%Name} - {%YValue}"
|
32
|
+
:chart => {
|
33
|
+
:title => false,
|
34
|
+
:legend => false, # if true or false: shows or not; if string shows with that String as legend -> format
|
35
|
+
:label => false, # label_settings -> format: {%YPercentOfSeries}{numDecimals:1}%
|
36
|
+
:marker => true # true or false
|
37
|
+
},
|
38
|
+
:data => {
|
39
|
+
:series => [
|
40
|
+
{:name => "Serie de omissao",
|
41
|
+
:points => [{:name => "X1", :value => "1"},{:name => "X2", :value => "2"}]
|
42
|
+
}
|
43
|
+
]
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
def self.xml(options={})
|
48
|
+
|
49
|
+
p = @@default_xml_options.merge(options)
|
50
|
+
|
51
|
+
validate_options(p)
|
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
|
+
|
59
|
+
xml.charts {
|
60
|
+
xml.chart(:plot_type => p[:type].to_s) {
|
61
|
+
|
62
|
+
xml.data_plot_settings(:enable_3d_mode => "false") {
|
63
|
+
xml.pie_series {
|
64
|
+
if p[:tooltip]
|
65
|
+
xml.tooltip_settings(:enabled => "True") {
|
66
|
+
xml.format p[:tooltip]
|
67
|
+
xml.position(:anchor => "CenterTop", :padding => "10") {}
|
68
|
+
}
|
69
|
+
else
|
70
|
+
xml.tooltip_settings(:enabled => "False") {}
|
71
|
+
end
|
72
|
+
|
73
|
+
# XML Labels que aparecem no interior da Pie/Doughnut
|
74
|
+
if p[:chart][:label]
|
75
|
+
xml.label_settings(:enabled => "true") {
|
76
|
+
xml.position(:anchor => "Center", :valign => "Center", :halign => "Center", :padding => "0") {}
|
77
|
+
xml.background(:enabled => "false") {}
|
78
|
+
xml.font(:size => "11", :color => "White") {
|
79
|
+
xml.effects {
|
80
|
+
xml.drop_shadow(:enabled => "true", :distance => "1", :opacity => "0.9", :blur_x => "2", :blur_y => "2") {}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
xml.format p[:chart][:label]
|
84
|
+
}
|
85
|
+
end # label_settings
|
86
|
+
|
87
|
+
if p[:chart][:marker]
|
88
|
+
xml.marker_settings(:enabled => "true") {
|
89
|
+
xml.marker(:type => "None") {}
|
90
|
+
xml.states {
|
91
|
+
xml.hover {
|
92
|
+
xml.marker(:type => "Circle", :anchor => "CenterTop")
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end # marker_settings
|
97
|
+
|
98
|
+
} # pie_series
|
99
|
+
|
100
|
+
} # data_plot_settings
|
101
|
+
|
102
|
+
xml.chart_settings {
|
103
|
+
if p[:chart][:title]
|
104
|
+
xml.title(:enabled => "true", :padding => "10") {
|
105
|
+
xml.text_ p[:chart][:title]
|
106
|
+
}
|
107
|
+
end # title
|
108
|
+
|
109
|
+
if p[:chart][:legend]
|
110
|
+
xml.legend(:enabled => "true", :position => "Right", :align => "Near", :ignore_auto_item => "true") {
|
111
|
+
xml.format p[:chart][:legend][:format] if p[:chart][:legend].kind_of?(Hash) and p[:chart][:legend][:format]
|
112
|
+
|
113
|
+
xml.template {}
|
114
|
+
|
115
|
+
if p[:chart][:legend].kind_of?(Hash) and p[:chart][:legend][:title]
|
116
|
+
xml.title(:enabled => "true") { p[:chart][:legend][:title] }
|
117
|
+
else
|
118
|
+
xml.title(:enabled => "false") {}
|
119
|
+
end
|
120
|
+
|
121
|
+
xml.columns_separator(:enabled => "false") { }
|
122
|
+
|
123
|
+
xml.items {
|
124
|
+
xml.item(:source => "Points") { }
|
125
|
+
}
|
126
|
+
|
127
|
+
xml.background {
|
128
|
+
xml.inside_margin(:left => "10", :right => "10") { }
|
129
|
+
}
|
130
|
+
}
|
131
|
+
end # legend
|
132
|
+
|
133
|
+
} # chart_settings
|
134
|
+
|
135
|
+
} # chart
|
136
|
+
|
137
|
+
xml.data {
|
138
|
+
series = (p[:data][:series].kind_of?(Array) ? p[:data][:series] : [p[:data][:series]])
|
139
|
+
|
140
|
+
series.each do |serie|
|
141
|
+
xml.series(:name => serie[:name], :type => "Pie") {
|
142
|
+
# Os varios pontos
|
143
|
+
serie[:points].each do |point|
|
144
|
+
pt = {:name => point[:name].to_s, :y => point[:value].to_s}
|
145
|
+
pt.merge!({:color => point[:color].to_s}) if point[:color]
|
146
|
+
xml.point(pt)
|
147
|
+
end
|
148
|
+
}
|
149
|
+
end # series
|
150
|
+
|
151
|
+
} # data
|
152
|
+
|
153
|
+
} # charts
|
154
|
+
|
155
|
+
} # anychart
|
156
|
+
end
|
157
|
+
|
158
|
+
builder.to_xml.gsub(/>[ \t\r\n]+</, '><')
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.validate_options(options)
|
162
|
+
raise "type must be :pie or :doughnut" unless options[:type] == :pie or options[:type] == :doughnut
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'xml/sample_71'
|
3
|
+
require 'xml/sample_165'
|
3
4
|
|
4
5
|
class TestAnychartXmlBuilder < Test::Unit::TestCase
|
5
6
|
should "create valid XML file like anychart/gallery/sample_71.xml" do
|
6
7
|
options = {:tooltip => "{%Name} - {%YValue}",
|
7
8
|
:chart => {
|
8
9
|
:title => "Multi-Series: with Simple Legend",
|
9
|
-
:legend => "{%Icon} {%Name} ({%Value})",
|
10
|
+
:legend => {:format => "{%Icon} {%Name} ({%Value})"},
|
10
11
|
:axes => {
|
11
12
|
:y => "{%Value}{numDecimals:0}"
|
12
13
|
}
|
@@ -28,4 +29,29 @@ class TestAnychartXmlBuilder < Test::Unit::TestCase
|
|
28
29
|
}
|
29
30
|
assert_equal(Sample71.xml.gsub(/>[ \t\r\n]+</, '><'), Anychart::XML::ColumnBar.xml(options))
|
30
31
|
end
|
32
|
+
|
33
|
+
should "create valid XML file like anychart/gallery/sample_165.xml" do
|
34
|
+
options = {:type => :doughnut,
|
35
|
+
:tooltip => "${%Value}{scale:(1000)(1000)(1000)|( th)( mil)( bil),numDecimals:2}",
|
36
|
+
:chart => {
|
37
|
+
:title => "ACME Corp. apparel sales through different retail channels",
|
38
|
+
:legend => true,
|
39
|
+
:label => "{%YPercentOfSeries}{numDecimals:1}%",
|
40
|
+
:marker => true
|
41
|
+
},
|
42
|
+
:data => {
|
43
|
+
:series => [
|
44
|
+
{:name => "Year 2003",
|
45
|
+
:points => [ {:name => "Department Store", :value => "6371664"},
|
46
|
+
{:name => "Discount Stores", :value => "7216301"},
|
47
|
+
{:name => "Men's/Women's Stores", :value => "1486621"},
|
48
|
+
{:name => "Juvenile Specialty Stores", :value => "786622"},
|
49
|
+
{:name => "All other outlets", :value => "900000", :color => "DarkSeaGreen"}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
54
|
+
}
|
55
|
+
assert_equal(Sample165.xml.gsub(/>[ \t\r\n]+</, '><'), Anychart::XML::Pie.xml(options))
|
56
|
+
end
|
31
57
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Sample165
|
2
|
+
def self.xml
|
3
|
+
"<?xml version=\"1.0\"?><anychart>
|
4
|
+
<settings>
|
5
|
+
<animation enabled=\"True\"/>
|
6
|
+
</settings>
|
7
|
+
<charts>
|
8
|
+
<chart plot_type=\"doughnut\">
|
9
|
+
<data_plot_settings enable_3d_mode=\"false\">
|
10
|
+
<pie_series>
|
11
|
+
<tooltip_settings enabled=\"true\">
|
12
|
+
<position anchor=\"CenterTop\" padding=\"10\"/>
|
13
|
+
<format>
|
14
|
+
${%Value}{scale:(1000)(1000)(1000)|( th)( mil)( bil),numDecimals:2}
|
15
|
+
</format>
|
16
|
+
</tooltip_settings>
|
17
|
+
<label_settings enabled=\"true\">
|
18
|
+
<position anchor=\"Center\" valign=\"Center\" halign=\"Center\" padding=\"0\"/>
|
19
|
+
<background enabled=\"false\"/>
|
20
|
+
<font size=\"11\" color=\"White\">
|
21
|
+
<effects>
|
22
|
+
<drop_shadow enabled=\"true\" distance=\"1\" opacity=\"0.9\" blur_x=\"2\" blur_y=\"2\"/>
|
23
|
+
</effects>
|
24
|
+
</font>
|
25
|
+
<format>{%YPercentOfSeries}{numDecimals:1}%</format>
|
26
|
+
</label_settings>
|
27
|
+
<marker_settings enabled=\"true\">
|
28
|
+
<marker type=\"None\"/>
|
29
|
+
<states>
|
30
|
+
<hover>
|
31
|
+
<marker type=\"Circle\" anchor=\"CenterTop\"/>
|
32
|
+
</hover>
|
33
|
+
</states>
|
34
|
+
</marker_settings>
|
35
|
+
</pie_series>
|
36
|
+
</data_plot_settings>
|
37
|
+
<data>
|
38
|
+
<series name=\"Year 2003\" type=\"Pie\">
|
39
|
+
<point name=\"Department Stores\" y=\"6371664\"/>
|
40
|
+
<point name=\"Discount Stores\" y=\"7216301\"/>
|
41
|
+
<point name=\"Men\"s/Women\"s Stores\" y=\"1486621\"/>
|
42
|
+
<point name=\"Juvenile Specialty Stores\" y=\"786622\"/>
|
43
|
+
<point name=\"All other outlets\" y=\"900000\" color=\"DarkSeaGreen\"/>
|
44
|
+
</series>
|
45
|
+
</data>
|
46
|
+
<chart_settings>
|
47
|
+
<title enabled=\"true\" padding=\"20\">
|
48
|
+
<text>
|
49
|
+
ACME Corp. apparel sales through different retail channels
|
50
|
+
</text>
|
51
|
+
</title>
|
52
|
+
<legend enabled=\"true\" ignore_auto_item=\"true\" position=\"Right\">
|
53
|
+
<title enabled=\"false\"/>
|
54
|
+
<items>
|
55
|
+
<item source=\"points\"/>
|
56
|
+
</items>
|
57
|
+
</legend>
|
58
|
+
</chart_settings>
|
59
|
+
</chart>
|
60
|
+
</charts>
|
61
|
+
</anychart>\n"
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anychart_xml_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jduarte
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-08 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -49,12 +49,14 @@ files:
|
|
49
49
|
- README.rdoc
|
50
50
|
- Rakefile
|
51
51
|
- anychart_xml_builder.gemspec
|
52
|
-
- lib/anychart/
|
52
|
+
- lib/anychart/anychart_helpers.rb
|
53
53
|
- lib/anychart_xml_builder.rb
|
54
54
|
- lib/column_bar.rb
|
55
55
|
- lib/init.rb
|
56
|
+
- lib/pie.rb
|
56
57
|
- test/helper.rb
|
57
58
|
- test/test_anychart_xml_builder.rb
|
59
|
+
- test/xml/sample_165.rb
|
58
60
|
- test/xml/sample_71.rb
|
59
61
|
has_rdoc: true
|
60
62
|
homepage: http://github.com/jduarte/anychart_xml_builder
|
@@ -87,4 +89,5 @@ summary: AnyChart (http://anychart.com/home/) XML Builders
|
|
87
89
|
test_files:
|
88
90
|
- test/helper.rb
|
89
91
|
- test/test_anychart_xml_builder.rb
|
92
|
+
- test/xml/sample_165.rb
|
90
93
|
- test/xml/sample_71.rb
|