diff options
| author | Randy Morgan <[email protected]> | 2012-07-08 12:35:44 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-07-08 12:35:44 +0900 |
| commit | 7af812c429ffd2374f164fe2f1f4f19ba6cb5f64 (patch) | |
| tree | 271ae6dfd673b24d900fbf9df9ecb731cce002f0 | |
| parent | e121fe875ac8492dcd36ba71993e00b2eb4a9ed0 (diff) | |
| download | caxlsx-7af812c429ffd2374f164fe2f1f4f19ba6cb5f64.tar.gz caxlsx-7af812c429ffd2374f164fe2f1f4f19ba6cb5f64.zip | |
adding in axis line fill and patching view3d misname for line3DChart
| -rw-r--r-- | examples/chart_colors.rb | 21 | ||||
| -rw-r--r-- | lib/axlsx/drawing/axis.rb | 20 | ||||
| -rw-r--r-- | lib/axlsx/drawing/line_3D_chart.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_axis.rb | 8 |
4 files changed, 46 insertions, 5 deletions
diff --git a/examples/chart_colors.rb b/examples/chart_colors.rb index fac3b58e..8349076a 100644 --- a/examples/chart_colors.rb +++ b/examples/chart_colors.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -w -s # -*- coding: utf-8 -*- -# $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'axlsx' p = Axlsx::Package.new @@ -36,7 +36,7 @@ end sheet.add_row ["First", "Second", "Third", "Fourth"] sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"] sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart| - chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF'] + chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF', '000000'] end end @@ -45,7 +45,7 @@ end wb.add_worksheet(:name => "Line Chart") do |sheet| sheet.add_row ["First", 1, 5, 7, 9] sheet.add_row ["Second", 5, 2, 14, 9] - sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart| + sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 30) do |chart| chart.start_at 0, 2 chart.end_at 10, 15 chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000" @@ -53,6 +53,21 @@ wb.add_worksheet(:name => "Line Chart") do |sheet| end end +wb.add_worksheet(:name => 'Line Chart with Axis colors') do |sheet| + sheet.add_row ["First", 1, 5, 7, 9] + sheet.add_row ["Second", 5, 2, 14, 9] + sheet.add_chart(Axlsx::Line3DChart, :title => "example 7: Flat Line Chart", :rot_x => 0, :perspective => 0) do |chart| + chart.valAxis.color = "FFFF00" + chart.catAxis.color = "00FFFF" + chart.serAxis.delete = true + chart.start_at 0, 2 + chart.end_at 10, 15 + chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000" + chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"], :color => "00FF00" + end + +end + ##Generating A Scatter Chart wb.add_worksheet(:name => "Scatter Chart") do |sheet| diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb index 1da3e430..5706f4ad 100644 --- a/lib/axlsx/drawing/axis.rb +++ b/lib/axlsx/drawing/axis.rb @@ -3,6 +3,13 @@ module Axlsx # the access class defines common properties and values for a chart axis. class Axis + + + # the fill color to use in the axis shape properties. This should be a 6 character long hex string + # e.g. FF0000 for red + # @return [String] + attr_reader :color + # the id of the axis. # @return [Integer] attr_reader :ax_id @@ -70,7 +77,7 @@ module Axlsx @format_code = "General" @delete = @label_rotation = 0 @scaling = Scaling.new(:orientation=>:minMax) - @title = nil + @title = @color = nil self.ax_pos = :b self.tick_lbl_pos = :nextTo self.format_code = "General" @@ -81,6 +88,9 @@ module Axlsx end end + def color=(color_rgb) + @color = color_rgb + end # The position of the axis # must be one of [:l, :r, :t, :b] def ax_pos=(v) RestrictionValidator.validate "#{self.class}.ax_pos", [:l, :r, :b, :t], v; @ax_pos = v; end @@ -140,6 +150,7 @@ module Axlsx str << '<c:delete val="'<< @delete.to_s << '"/>' str << '<c:axPos val="' << @ax_pos.to_s << '"/>' str << '<c:majorGridlines>' + # TODO shape properties need to be extracted into a class if gridlines == false str << '<c:spPr>' str << '<a:ln>' @@ -153,6 +164,13 @@ module Axlsx str << '<c:majorTickMark val="none"/>' str << '<c:minorTickMark val="none"/>' str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>' + # TODO - this is also being used for series colors + # time to extract this into a class spPr - Shape Properties + if @color + str << '<c:spPr><a:ln><a:solidFill>' + str << '<a:srgbClr val="' << @color << '"/>' + str << '</a:solidFill></a:ln></c:spPr>' + end # some potential value in implementing this in full. Very detailed! str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>' str << '<c:crossAx val="' << @cross_ax.to_s << '"/>' diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb index 0f8a07f8..5fc3e7c2 100644 --- a/lib/axlsx/drawing/line_3D_chart.rb +++ b/lib/axlsx/drawing/line_3D_chart.rb @@ -70,7 +70,7 @@ module Axlsx @serAxis = SerAxis.new(@serAxId, @valAxId) super(frame, options) @series_type = LineSeries - @view3D = View3D.new({:perspective=>30}.merge(options)) + @view_3D = View3D.new({:perspective=>30}.merge(options)) end # @see grouping diff --git a/test/drawing/tc_axis.rb b/test/drawing/tc_axis.rb index 3c5484ea..807655d7 100644 --- a/test/drawing/tc_axis.rb +++ b/test/drawing/tc_axis.rb @@ -19,6 +19,14 @@ class TestAxis < Test::Unit::TestCase assert_equal('Foo', @axis.title.text) end + def test_color + @axis.color = "00FF00" + str = '<?xml version="1.0" encoding="UTF-8"?>' + str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">' + doc = Nokogiri::XML(@axis.to_xml_string(str)) + assert(doc.xpath("//a:srgbClr[@val='00FF00']")) + end + def test_cell_based_axis_title p = Axlsx::Package.new p.workbook.add_worksheet(:name=>'foosheet') do |sheet| |
