Class: Writexlsx::Shape
- Inherits:
-
Object
- Object
- Writexlsx::Shape
- Defined in:
- lib/write_xlsx/shape.rb
Overview
Shape - A class for writing Excel shapes.
Used in conjunction with Excel::Writer::XLSX.
Copyright 2000-2012, John McNamara, [email protected] Converted to ruby by Hideo NAKAMURA, [email protected]
Instance Attribute Summary collapse
-
#connect ⇒ Object
readonly
Returns the value of attribute connect.
-
#editAs ⇒ Object
readonly
Returns the value of attribute editAs.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#end_index ⇒ Object
readonly
Returns the value of attribute end_index.
-
#fill ⇒ Object
readonly
Returns the value of attribute fill.
-
#flip_h ⇒ Object
readonly
Returns the value of attribute flip_h.
-
#flip_v ⇒ Object
readonly
Returns the value of attribute flip_v.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rotation ⇒ Object
readonly
Returns the value of attribute rotation.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#start_index ⇒ Object
readonly
Returns the value of attribute start_index.
-
#tx_box ⇒ Object
readonly
Returns the value of attribute tx_box.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
-
#adjustments=(args) ⇒ Object
Set the shape adjustments array (as a reference).
-
#get_palette_color(index) ⇒ Object
Convert from an Excel internal colour index to a XML style #RRGGBB index based on the default or user defined values in the Workbook palette.
-
#initialize(properties = {}) ⇒ Shape
constructor
A new instance of Shape.
- #set_properties(properties) ⇒ Object
Constructor Details
#initialize(properties = {}) ⇒ Shape
Returns a new instance of Shape.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/write_xlsx/shape.rb', line 19 def initialize(properties = {}) @writer = Package::XMLWriterSimple.new @name = nil @type = 'rect' # Is a Connector shape. 1/0 Value is a hash lookup from type. @connect = 0 # Is a Drawing. Always 0, since a single shape never fills an entire sheet. @drawing = 0 # OneCell or Absolute: options to move and/or size with cells. @editAs = '' # Auto-incremented, unless supplied by user. @id = 0 # Shape text (usually centered on shape geometry). @text = 0 # Shape stencil mode. A copy (child) is created when inserted. # The link to parent is broken. @stencil = 1 # Index to _shapes array when inserted. @element = -1 # Shape ID of starting connection, if any. @start = nil # Shape vertex, starts at 0, numbered clockwise from 12 o'clock. @start_index = nil @end = nil @end_index = nil # Number and size of adjustments for shapes (usually connectors). @adjustments = [] # Start and end sides. t)op, b)ottom, l)eft, or r)ight. @start_side = '' @end_side = '' # Flip shape Horizontally. eg. arrow left to arrow right. @flip_h = 0 # Flip shape Vertically. eg. up arrow to down arrow. @flip_v = 0 # shape rotation (in degrees 0-360). @rotation = 0 # An alternate way to create a text box, because Excel allows it. # It is just a rectangle with text. @tx_box = 0 # Shape outline colour, or 0 for noFill (default black). @line = '000000' # Line type: dash, sysDot, dashDot, lgDash, lgDashDot, lgDashDotDot. @line_type = '' # Line weight (integer). @line_weight = 1 # Shape fill colour, or 0 for noFill (default noFill). @fill = 0 # Formatting for shape text, if any. @format = {} # copy of colour palette table from Workbook.pm. @palette = [] # Vertical alignment: t, ctr, b. @valign = 'ctr' # Alignment: l, ctr, r, just @align = 'ctr' @x_offset = 0 @y_offset = 0 # Scale factors, which also may be set when the shape is inserted. @scale_x = 1 @scale_y = 1 # Default size, which can be modified and/or scaled. @width = 50 @height = 50 # Initial assignment. May be modified when prepared. @column_start = 0 @row_start = 0 @x1 = 0 @y1 = 0 @column_end = 0 @row_end = 0 @x2 = 0 @y2 = 0 @x_abs = 0 @y_abs = 0 set_properties(properties) end |
Instance Attribute Details
#connect ⇒ Object (readonly)
Returns the value of attribute connect.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def connect @connect end |
#editAs ⇒ Object (readonly)
Returns the value of attribute editAs.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def editAs @editAs end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def end @end end |
#end_index ⇒ Object (readonly)
Returns the value of attribute end_index.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def end_index @end_index end |
#fill ⇒ Object (readonly)
Returns the value of attribute fill.
16 17 18 |
# File 'lib/write_xlsx/shape.rb', line 16 def fill @fill end |
#flip_h ⇒ Object (readonly)
Returns the value of attribute flip_h.
16 17 18 |
# File 'lib/write_xlsx/shape.rb', line 16 def flip_h @flip_h end |
#flip_v ⇒ Object (readonly)
Returns the value of attribute flip_v.
16 17 18 |
# File 'lib/write_xlsx/shape.rb', line 16 def flip_v @flip_v end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/write_xlsx/shape.rb', line 17 def name @name end |
#rotation ⇒ Object (readonly)
Returns the value of attribute rotation.
16 17 18 |
# File 'lib/write_xlsx/shape.rb', line 16 def rotation @rotation end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def start @start end |
#start_index ⇒ Object (readonly)
Returns the value of attribute start_index.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def start_index @start_index end |
#tx_box ⇒ Object (readonly)
Returns the value of attribute tx_box.
16 17 18 |
# File 'lib/write_xlsx/shape.rb', line 16 def tx_box @tx_box end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/write_xlsx/shape.rb', line 15 def type @type end |
Instance Method Details
#[](attr) ⇒ Object
150 151 152 |
# File 'lib/write_xlsx/shape.rb', line 150 def [](attr) self.instance_variable_get("@#{attr}") end |
#[]=(attr, value) ⇒ Object
154 155 156 |
# File 'lib/write_xlsx/shape.rb', line 154 def []=(attr, value) self.instance_variable_set("@#{attr}", value) end |
#adjustments=(args) ⇒ Object
Set the shape adjustments array (as a reference).
146 147 148 |
# File 'lib/write_xlsx/shape.rb', line 146 def adjustments=(args) @adjustments = *args end |
#get_palette_color(index) ⇒ Object
Convert from an Excel internal colour index to a XML style #RRGGBB index based on the default or user defined values in the Workbook palette. Note: This version doesn’t add an alpha channel.
162 163 164 165 166 167 168 169 170 |
# File 'lib/write_xlsx/shape.rb', line 162 def get_palette_color(index) # Adjust the colour index. idx = index - 8 # Palette is passed in from the Workbook class. rgb = @palette[idx] sprintf("%02X%02X%02X", *rgb) end |
#set_properties(properties) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/write_xlsx/shape.rb', line 125 def set_properties(properties) # Override default properties with passed arguments properties.each do |key, value| # Strip leading "-" from Tk style properties e.g. -color => 'red'. k = key.to_s.sub(/^-/, '') self.instance_variable_set("@#{key}", value) =begin if key.to_s == 'format' @format = value elsif value.respond_to?(:coerce) eval "@#{k} = #{value}" else eval "@#{k} = %!#{value}!" end =end end end |