diff options
| author | Sergio Cambra <[email protected]> | 2013-03-14 14:04:17 +0100 |
|---|---|---|
| committer | Sergio Cambra <[email protected]> | 2013-03-14 14:04:17 +0100 |
| commit | d7fa44f2bf454c4077a1fb985a777f2ec32bd695 (patch) | |
| tree | 9578ab5b2d254c828d3742e02545e79caf6fa12b | |
| parent | 61488b068f220a32f4c5ab50a4108e61caa4d7aa (diff) | |
| download | caxlsx-d7fa44f2bf454c4077a1fb985a777f2ec32bd695.tar.gz caxlsx-d7fa44f2bf454c4077a1fb985a777f2ec32bd695.zip | |
add lineChart (2D) and show_marker to LineSeries (for 2D line chart)
| -rw-r--r-- | lib/axlsx/drawing/line_3D_chart.rb | 47 | ||||
| -rw-r--r-- | lib/axlsx/drawing/line_chart.rb | 87 | ||||
| -rw-r--r-- | lib/axlsx/drawing/line_series.rb | 11 |
3 files changed, 99 insertions, 46 deletions
diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb index b843f48e..627cfe83 100644 --- a/lib/axlsx/drawing/line_3D_chart.rb +++ b/lib/axlsx/drawing/line_3D_chart.rb @@ -19,29 +19,12 @@ module Axlsx # @see Chart#add_series # @see Series # @see Package#serialize - class Line3DChart < Chart - - # the category axis - # @return [CatAxis] - attr_reader :catAxis - - # the category axis - # @return [ValAxis] - attr_reader :valAxis - - # the category axis - # @return [Axis] - attr_reader :serAxis + class Line3DChart < LineChart # space between bar or column clusters, as a percentage of the bar or column width. # @return [String] attr_reader :gapDepth - #grouping for a column, line, or area chart. - # must be one of [:percentStacked, :clustered, :standard, :stacked] - # @return [Symbol] - attr_reader :grouping - # validation regex for gap amount percent GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/ @@ -60,25 +43,9 @@ module Axlsx # @see Chart # @see View3D def initialize(frame, options={}) - @vary_colors = false @gapDepth = nil - @grouping = :standard - @catAxId = rand(8 ** 8) - @valAxId = rand(8 ** 8) - @serAxId = rand(8 ** 8) - @catAxis = CatAxis.new(@catAxId, @valAxId) - @valAxis = ValAxis.new(@valAxId, @catAxId) - @serAxis = SerAxis.new(@serAxId, @valAxId) super(frame, options) - @series_type = LineSeries @view_3D = View3D.new({:perspective=>30}.merge(options)) - @d_lbls = nil - end - - # @see grouping - def grouping=(v) - RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :standard, :stacked], v - @grouping = v end # @see gapDepth @@ -92,19 +59,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') super(str) do |str_inner| - str_inner << '<c:line3DChart>' - str_inner << '<c:grouping val="' << grouping.to_s << '"/>' - str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>' - @series.each { |ser| ser.to_xml_string(str_inner) } - @d_lbls.to_xml_string(str) if @d_lbls str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil? - str_inner << '<c:axId val="' << @catAxId.to_s << '"/>' - str_inner << '<c:axId val="' << @valAxId.to_s << '"/>' - str_inner << '<c:axId val="' << @serAxId.to_s << '"/>' - str_inner << '</c:line3DChart>' - @catAxis.to_xml_string str_inner - @valAxis.to_xml_string str_inner - @serAxis.to_xml_string str_inner end end end diff --git a/lib/axlsx/drawing/line_chart.rb b/lib/axlsx/drawing/line_chart.rb new file mode 100644 index 00000000..e926fb79 --- /dev/null +++ b/lib/axlsx/drawing/line_chart.rb @@ -0,0 +1,87 @@ +# encoding: UTF-8 +module Axlsx + + # The LineChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet. + # @example Creating a chart + # # This example creates a line in a single sheet. + # require "rubygems" # if that is your preferred way to manage gems! + # require "axlsx" + # + # p = Axlsx::Package.new + # ws = p.workbook.add_worksheet + # ws.add_row ["This is a chart with no data in the sheet"] + # + # chart = ws.add_chart(Axlsx::LineChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets") + # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"] + # + # @see Worksheet#add_chart + # @see Worksheet#add_row + # @see Chart#add_series + # @see Series + # @see Package#serialize + class LineChart < Chart + + # the category axis + # @return [CatAxis] + attr_reader :catAxis + + # the category axis + # @return [ValAxis] + attr_reader :valAxis + + # the category axis + # @return [Axis] + attr_reader :serAxis + + # must be one of [:percentStacked, :clustered, :standard, :stacked] + # @return [Symbol] + attr_reader :grouping + + # Creates a new line chart object + # @param [GraphicFrame] frame The workbook that owns this chart. + # @option options [Cell, String] title + # @option options [Boolean] show_legend + # @option options [Symbol] grouping + # @see Chart + def initialize(frame, options={}) + @vary_colors = false + @grouping = :standard + @catAxId = rand(8 ** 8) + @valAxId = rand(8 ** 8) + @serAxId = rand(8 ** 8) + @catAxis = CatAxis.new(@catAxId, @valAxId) + @valAxis = ValAxis.new(@valAxId, @catAxId) + @serAxis = SerAxis.new(@serAxId, @valAxId) + super(frame, options) + @series_type = LineSeries + @d_lbls = nil + end + + # @see grouping + def grouping=(v) + RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :standard, :stacked], v + @grouping = v + end + + # Serializes the object + # @param [String] str + # @return [String] + def to_xml_string(str = '') + super(str) do |str_inner| + str_inner << "<c:#{self.class.name.camelcase(:lower)}>" + str_inner << '<c:grouping val="' << grouping.to_s << '"/>' + str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>' + @series.each { |ser| ser.to_xml_string(str_inner) } + @d_lbls.to_xml_string(str) if @d_lbls + yield str_inner + str_inner << '<c:axId val="' << @catAxId.to_s << '"/>' + str_inner << '<c:axId val="' << @valAxId.to_s << '"/>' + str_inner << '<c:axId val="' << @serAxId.to_s << '"/>' + str_inner << "</c:#{self.class.name.camelcase(:lower)}>" + @catAxis.to_xml_string str_inner + @valAxis.to_xml_string str_inner + @serAxis.to_xml_string str_inner + end + end + end +end diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index 017822ed..f70bdb49 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -19,6 +19,10 @@ module Axlsx # @return [String] attr_reader :color + # show markers on values + # @return [Boolean] + attr_reader :show_marker + # Creates a new series # @option options [Array, SimpleTypedList] data # @option options [Array, SimpleTypedList] labels @@ -35,11 +39,18 @@ module Axlsx @color = v end + # @see show_marker + def show_marker=(v) + Axlsx::validate_boolean(v) + @show_marker = v + end + # Serializes the object # @param [String] str # @return [String] def to_xml_string(str = '') super(str) do + str << '<c:marker><c:symbol val="none"/></c:marker>' unless @show_marker if color str << '<c:spPr><a:solidFill>' str << '<a:srgbClr val="' << color << '"/>' |
