summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Moal <[email protected]>2013-10-09 16:38:35 +0200
committerJean-Philippe Moal <[email protected]>2013-10-09 16:38:35 +0200
commit3171fa568618e9d75ead1994ed6e3be90b693a47 (patch)
tree2d7d5655f60386a70571eaa287f93045ae9c4317 /lib
parent3bf46a00d717d5e991166360bf4a2ece41cc3fbc (diff)
downloadcaxlsx-3171fa568618e9d75ead1994ed6e3be90b693a47.tar.gz
caxlsx-3171fa568618e9d75ead1994ed6e3be90b693a47.zip
Add support for bubble charts
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/drawing/bubble_chart.rb59
-rw-r--r--lib/axlsx/drawing/bubble_series.rb71
-rw-r--r--lib/axlsx/drawing/drawing.rb2
-rw-r--r--lib/axlsx/drawing/num_data_source.rb2
4 files changed, 133 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/bubble_chart.rb b/lib/axlsx/drawing/bubble_chart.rb
new file mode 100644
index 00000000..2f2c4595
--- /dev/null
+++ b/lib/axlsx/drawing/bubble_chart.rb
@@ -0,0 +1,59 @@
+# encoding: UTF-8
+module Axlsx
+
+ # The BubbleChart allows you to insert a bubble chart into your worksheet
+ # @see Worksheet#add_chart
+ # @see Chart#add_series
+ # @see README for an example
+ class BubbleChart < Chart
+
+ include Axlsx::OptionsParser
+
+ # the x value axis
+ # @return [ValAxis]
+ def x_val_axis
+ axes[:x_val_axis]
+ end
+ alias :xValAxis :x_val_axis
+
+ # the y value axis
+ # @return [ValAxis]
+ def y_val_axis
+ axes[:y_val_axis]
+ end
+ alias :yValAxis :y_val_axis
+
+ # Creates a new bubble chart
+ def initialize(frame, options={})
+ @vary_colors = 0
+
+ super(frame, options)
+ @series_type = BubbleSeries
+ @d_lbls = nil
+ parse_options options
+ end
+
+ # Serializes the object
+ # @param [String] str
+ # @return [String]
+ def to_xml_string(str = '')
+ super(str) do |str_inner|
+ str_inner << '<c:bubbleChart>'
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
+ @series.each { |ser| ser.to_xml_string(str_inner) }
+ d_lbls.to_xml_string(str_inner) if @d_lbls
+ axes.to_xml_string(str_inner, :ids => true)
+ str_inner << '</c:bubbleChart>'
+ axes.to_xml_string(str_inner)
+ end
+ str
+ end
+
+ # The axes for the bubble chart. BubbleChart has an x_val_axis and
+ # a y_val_axis
+ # @return [Axes]
+ def axes
+ @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
+ end
+ end
+end
diff --git a/lib/axlsx/drawing/bubble_series.rb b/lib/axlsx/drawing/bubble_series.rb
new file mode 100644
index 00000000..161a9a9e
--- /dev/null
+++ b/lib/axlsx/drawing/bubble_series.rb
@@ -0,0 +1,71 @@
+# encoding: UTF-8
+module Axlsx
+
+ # A BubbleSeries defines the x/y position and bubble size of data in the chart
+ # @note The recommended way to manage series is to use Chart#add_series
+ # @see Worksheet#add_chart
+ # @see Chart#add_series
+ # @see examples/example.rb
+ class BubbleSeries < Series
+
+ # The x data for this series.
+ # @return [AxDataSource]
+ attr_reader :xData
+
+ # The y data for this series.
+ # @return [NumDataSource]
+ attr_reader :yData
+
+ # The bubble size for this series.
+ # @return [NumDataSource]
+ attr_reader :bubbleSize
+
+ # The fill color for this series.
+ # Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.
+ # @return [String]
+ attr_reader :color
+
+ # Creates a new BubbleSeries
+ def initialize(chart, options={})
+ @xData, @yData, @bubbleSize = nil
+ super(chart, options)
+ @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
+ @yData = NumDataSource.new({:tag_name => :yVal, :data => options[:yData]}) unless options[:yData].nil?
+ @bubbleSize = NumDataSource.new({:tag_name => :bubbleSize, :data => options[:bubbleSize]}) unless options[:bubbleSize].nil?
+ end
+
+ # @see color
+ def color=(v)
+ @color = v
+ end
+
+ # Serializes the object
+ # @param [String] str
+ # @return [String]
+ def to_xml_string(str = '')
+ super(str) do |inner_str|
+ # needs to override the super color here to push in ln/and something else!
+ if color
+ str << '<c:spPr><a:solidFill>'
+ str << '<a:srgbClr val="' << color << '"/>'
+ str << '</a:solidFill>'
+ str << '<a:ln><a:solidFill>'
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
+ str << '</c:spPr>'
+ str << '<c:marker>'
+ str << '<c:spPr><a:solidFill>'
+ str << '<a:srgbClr val="' << color << '"/>'
+ str << '</a:solidFill>'
+ str << '<a:ln><a:solidFill>'
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
+ str << '</c:spPr>'
+ str << '</c:marker>'
+ end
+ @xData.to_xml_string(inner_str) unless @xData.nil?
+ @yData.to_xml_string(inner_str) unless @yData.nil?
+ @bubbleSize.to_xml_string(inner_str) unless @bubbleSize.nil?
+ end
+ str
+ end
+ end
+end
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb
index b5856909..e7fcba85 100644
--- a/lib/axlsx/drawing/drawing.rb
+++ b/lib/axlsx/drawing/drawing.rb
@@ -8,6 +8,7 @@ module Axlsx
require 'axlsx/drawing/bar_series.rb'
require 'axlsx/drawing/line_series.rb'
require 'axlsx/drawing/scatter_series.rb'
+ require 'axlsx/drawing/bubble_series.rb'
require 'axlsx/drawing/scaling.rb'
require 'axlsx/drawing/axis.rb'
@@ -37,6 +38,7 @@ module Axlsx
require 'axlsx/drawing/line_chart.rb'
require 'axlsx/drawing/line_3D_chart.rb'
require 'axlsx/drawing/scatter_chart.rb'
+ require 'axlsx/drawing/bubble_chart.rb'
require 'axlsx/drawing/picture_locking.rb'
require 'axlsx/drawing/pic.rb'
diff --git a/lib/axlsx/drawing/num_data_source.rb b/lib/axlsx/drawing/num_data_source.rb
index 14d53301..c52b0fa8 100644
--- a/lib/axlsx/drawing/num_data_source.rb
+++ b/lib/axlsx/drawing/num_data_source.rb
@@ -33,7 +33,7 @@ module Axlsx
# allowed element tag names
# @return [Array]
def self.allowed_tag_names
- [:yVal, :val]
+ [:yVal, :val, :bubbleSize]
end
# sets the tag name for this data source