dyi 1.1.0 → 1.1.1

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/CHANGES CHANGED
@@ -1,14 +1,20 @@
1
1
  = DYI Changelog
2
2
 
3
- == Version 1.1.0
3
+ == Version 1.1.1 / 2012-02-02
4
+ * Minor Enhancements
5
+ * Adds a String parsing to CsvReader.
6
+ * Spports metadata.
7
+ * Adds `title' and `description' attribute to DYI::Element.
8
+
9
+ == Version 1.1.0 / 2012-01-06
4
10
  * Major Enhancements
5
- * Add DYI::Util module
11
+ * Adds DYI::Util module
6
12
  * Can draw a toroid.
7
- * Add properties of PieChart.
8
- * Support namespace on XML output.
9
- * Support Inline-XML mode.
13
+ * Adds properties of PieChart.
14
+ * Supports namespace on XML output.
15
+ * Supports Inline-XML mode.
10
16
 
11
- == Version 1.0.3
17
+ == Version 1.0.3 / 2011-11-27
12
18
  * Bug Fixes
13
19
  * DataReader is not working properly in Ruby 1.9.
14
20
  * A ECMAScript function dose not work properly.
@@ -25,20 +31,20 @@
25
31
  == Version 1.0.0 / 2011-09-05
26
32
 
27
33
  * Major Enhancements
28
- * Support events on SVG.
29
- * Support animations on SVG.
30
- * Support scripts (ex. ECMAScript) on SVG.
31
- * Support hyperlinks on SVG.
32
- * Support a SVG file that includes style-sheet (ex. CSS, XLST).
33
- * Support PNG output. (Needs rsvg-convert)
34
- * Support raster image handling (ex. PNG, JPEG) on SVG.
35
- * Add Pie-Chart options.
36
- * Modify the handling of Reader classes.
34
+ * Supports events on SVG.
35
+ * Supports animations on SVG.
36
+ * Supports scripts (ex. ECMAScript) on SVG.
37
+ * Supports hyperlinks on SVG.
38
+ * Supports a SVG file that includes style-sheet (ex. CSS, XLST).
39
+ * Supports PNG output. (Needs rsvg-convert)
40
+ * Supports raster image handling (ex. PNG, JPEG) on SVG.
41
+ * Adds Pie-Chart options.
42
+ * Modifies the handling of Reader classes.
37
43
 
38
44
  == Version 0.0.2 / 2011-09-05
39
45
 
40
46
  * Minor Enhancements
41
- * Modify header comments of output file.
47
+ * Modifies header comments of output file.
42
48
 
43
49
  * Bug Fixes
44
50
  * A path is not drawn correctly.
data/lib/dyi.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -19,9 +19,13 @@
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with DYI. If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
-
22
+ # Root namespace of DYI.
23
23
  module DYI
24
- VERSION = '1.1.0'
24
+
25
+ # DYI program version
26
+ VERSION = '1.1.1'
27
+
28
+ # URL of DYI Project
25
29
  URL = 'http://sourceforge.net/projects/dyi/'
26
30
  end
27
31
 
data/lib/dyi/canvas.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -19,16 +19,68 @@
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with DYI. If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
- module DYI #:nodoc:
22
+ module DYI
23
23
 
24
+ # The body of Vector-Image. This class is a container for all graphical
25
+ # elements that make up the image.
26
+ # @since 0.0.0
24
27
  class Canvas < GraphicalElement
28
+
29
+ # @private
25
30
  IMPLEMENT_ATTRIBUTES = [:view_box, :preserve_aspect_ratio]
26
- attr_length :width, :height
31
+
32
+ # Returns width of the vector-image on user unit.
33
+ # @attribute width
34
+ # @return [Length] width of vector-image on user unit
35
+ attr_length :width
36
+
37
+ # Returns heigth of the vector-image on user unit.
38
+ # @attribute height
39
+ # @return [Length] heigth of vector-image on user unit
40
+ attr_length :height
41
+
42
+ # Returns the value of the view_box.
43
+ # @attribute view_box
44
+ # @return [String]
45
+
46
+ # Returns the value of the preserve_aspect_ratio.
47
+ # @attribute preserve_aspect_ratio
48
+ # @return [String] the value of preserve_aspect_ratio
27
49
  attr_reader *IMPLEMENT_ATTRIBUTES
50
+
51
+ # Returns an array of child elements.
52
+ # @return [Array<Element>] an array of child elements
28
53
  attr_reader :child_elements
54
+
55
+ # Returns hash of event listners.
56
+ # @return [Hash] hash of event listners
57
+ # @since 1.0.0
58
+ attr_reader :event_listeners
59
+
60
+ # Returns an array of stylesheets.
61
+ # @return [Array<Stylesheet::Style>] an array of stylesheets
62
+ # @since 1.0.0
63
+ attr_reader :stylesheets
64
+
65
+ # Returns an array of scripts.
66
+ # @return [Array<Script::SimpleScript>] an array of scripts
29
67
  # @since 1.0.0
30
- attr_reader :event_listeners, :stylesheets, :scripts
68
+ attr_reader :scripts
69
+
70
+ # Returns a metadata object that the image has.
71
+ # @return [Object] a metadata object that the image has.
72
+ # @since 1.1.1
73
+ attr_accessor :metadata
31
74
 
75
+ # @param [Length] width width of the canvas on user unit
76
+ # @param [Length] height height of the canvas on user unit
77
+ # @param [Length] real_width width of the image. When this value
78
+ # is nil, uses a value that equals value of width parameter.
79
+ # @param [Length] real_height height of the image. When this value
80
+ # is nil, uses a value that equals value of height parameter.
81
+ # @param [String] preserve_aspect_ratio value that indicates
82
+ # whether or not to force uniform scaling
83
+ # @option options [String] :css_class CSS class of body element
32
84
  def initialize(width, height,
33
85
  real_width = nil, real_height = nil,
34
86
  preserve_aspect_ratio='none', options={})
@@ -47,60 +99,93 @@ module DYI #:nodoc:
47
99
  self.real_height = real_height
48
100
  end
49
101
 
102
+ # Returns width of the image.
103
+ # @return [Length] width of the image
50
104
  def real_width
51
105
  @real_width || width
52
106
  end
53
107
 
108
+ # Sets width of the image.
109
+ # @param [Length] width width of the image
54
110
  def real_width=(width)
55
111
  @real_width = Length.new_or_nil(width)
56
112
  end
57
113
 
114
+ # Returns height of the image.
115
+ # @return [Length] height of the image
58
116
  def real_height
59
117
  @real_height || height
60
118
  end
61
119
 
120
+ # Sets height of the image.
121
+ # @param [Length] height height of the image
62
122
  def real_height=(height)
63
123
  @real_height = Length.new_or_nil(height)
64
124
  end
65
125
 
66
- # This method is depricated; use Canvas#root_element?
67
- # @deprecated
126
+ # @deprecated Use {#root_element?} instead.
68
127
  def root_node?
69
128
  msg = [__FILE__, __LINE__, ' waring']
70
- msg << ' DYI::Canvas#root_node? is depricated; use DYI::Canvas#root_element?'
129
+ msg << ' DYI::Canvas#root_node? is deprecated; use DYI::Canvas#root_element?'
71
130
  warn(msg.join(':'))
72
131
  true
73
132
  end
74
133
 
134
+ # Returns whether this instance is root element of the shape.
135
+ # @return [Boolean] always true.
75
136
  # @since 1.0.0
76
137
  def root_element?
77
138
  true
78
139
  end
79
140
 
80
- # Returns the canvas where the shape is drawn
81
- # @return [Canvas] the canvas where the shape is drawn
141
+ # Returns the canvas where the shape is drawn.
142
+ # @return [Canvas] itself
82
143
  # @since 1.0.0
83
144
  def canvas
84
145
  self
85
146
  end
86
147
 
148
+ # Writes image on io object.
149
+ # @param [Formatter::Base] formatter an object that defines the image format
150
+ # @param [IO] io an io to be written
151
+ # @since 1.0.0
87
152
  def write_as(formatter, io=$>)
88
153
  formatter.write_canvas(self, io)
89
154
  end
90
155
 
156
+ # Saves as image file.
157
+ # @param [String] file_name a name of an image file
158
+ # @param [Symbol] format an image format. When this parameter is nil, saves
159
+ # as SVG. This method supports following values: :svg, :eps, :xaml, :png
160
+ # @option options [Integer] :indent indent of XML output. Defualt to 2
161
+ # @since 1.0.0
91
162
  def save(file_name, format=nil, options={})
92
163
  get_formatter(format, options).save(file_name)
93
164
  end
94
165
 
166
+ # Puts in io.
167
+ # @param [Symbol] format an image format. When this parameter is nil, saves
168
+ # as SVG. This method supports following values: :svg, :eps, :xaml, :png
169
+ # @param [IO] io an io to be written
170
+ # @option options [Integer] :indent indent of XML output. Defualt to 2
171
+ # @since 1.0.0
95
172
  def puts_in_io(format=nil, io=$>, options={})
96
173
  get_formatter(format, options).puts(io)
97
174
  end
98
175
 
176
+ # Returns data that means the image.
177
+ # @param [Symbol] format an image format. When this parameter is nil, saves
178
+ # as SVG. This method supports following values: :svg, :eps, :xaml, :png
179
+ # @option options [Integer] :indent indent of XML output. Defualt to 2
180
+ # @return [String] data that means the image
181
+ # @since 1.0.0
99
182
  def string(format=nil, options={})
100
183
  get_formatter(format, options).string
101
184
  end
102
185
 
103
- def attributes #:nodoc:
186
+ # Returns optional attributes.
187
+ # @return [Hash] optional attributes
188
+ def attributes
104
189
  IMPLEMENT_ATTRIBUTES.inject({}) do |hash, attribute|
105
190
  variable_name = '@' + attribute.to_s.split(/(?=[A-Z])/).map{|str| str.downcase}.join('_')
106
191
  value = instance_variable_get(variable_name)
@@ -109,33 +194,33 @@ module DYI #:nodoc:
109
194
  end
110
195
  end
111
196
 
112
- # Create a new id for a descendant element
197
+ # Create a new id for a descendant element.
113
198
  # @return [String] new id for a descendant element
114
199
  # @since 1.0.0
115
200
  def publish_shape_id
116
201
  'elm%04d' % (@seed_of_id += 1)
117
202
  end
118
203
 
204
+ # Sets event to the image.
205
+ # @param [Event] event an event that is set to this image
119
206
  # @since 1.0.0
120
207
  def set_event(event)
121
208
  super
122
209
  @receive_event = true
123
210
  end
124
211
 
125
- # @return [Boolean] whether event is set to the shape
212
+ # Returns whether an event is set to the shape.
213
+ # @return [Boolean] true if an event set to the shape, false otherwise.
126
214
  # @since 1.0.0
127
215
  def receive_event?
128
216
  @receive_event
129
217
  end
130
218
 
131
- # @overload add_script(script)
132
- # Registers a script object with this canvas
133
- # @param [Script::SimpleScript] script a script that is registered
134
- # @overload add_script(script_body, content_type='application/ecmascript')
135
- # Registers a script. Create a script object and Registers it with this
136
- # canvas.
137
- # @param [String] script_body a string that is script body
138
- # @param [String] content_type a content-type of the script
219
+ # Registers a script with the image.
220
+ # @param [String, Script::SimpleScript] script_body a string that is a
221
+ # script body or a script object that is registered
222
+ # @param [String] content_type a content-type of the script. If parameter
223
+ # `script_body' is {Script::SimpleScript} object, this parameter is ignored
139
224
  # @since 1.0.0
140
225
  def add_script(script_body, content_type = 'application/ecmascript')
141
226
  if script_body.respond_to?(:include_external_file?)
@@ -145,21 +230,33 @@ module DYI #:nodoc:
145
230
  end
146
231
  end
147
232
 
233
+ # Registers a reference to a script file with the image.
234
+ # @param [String] reference_path a file path of a script file
235
+ # @param [String] content_type a content-type of the script
148
236
  # @since 1.0.0
149
237
  def reference_script_file(reference_path, content_type = 'application/ecmascript')
150
238
  @scripts << Script::ScriptReference.new(reference_path, content_type)
151
239
  end
152
240
 
241
+ # Registers a stylesheet with the image.
242
+ # @param [String] style_body a string that is a stylesheet body
243
+ # @param [String] content_type a content-type of the stylesheet
153
244
  # @since 1.0.0
154
245
  def add_stylesheet(style_body, content_type = 'text/css')
155
246
  @stylesheets << Stylesheet::Style.new(style_body, content_type)
156
247
  end
157
248
 
249
+ # Registers a reference to a stylesheet file with the image.
250
+ # @param [String] reference_path a file path of a stylesheet file
251
+ # @param [String] content_type a content-type of the stylesheet
158
252
  # @since 1.0.0
159
253
  def reference_stylesheet_file(reference_path, content_type = 'text/css')
160
254
  @stylesheets << Stylesheet::StyleReference.new(reference_path, content_type)
161
255
  end
162
256
 
257
+ # Registers a script with the image for initialization.
258
+ # @param [String] script_body a string that is a script body for
259
+ # initialization
163
260
  # @since 1.0.0
164
261
  def add_initialize_script(script_body)
165
262
  if @init_script
@@ -172,7 +269,7 @@ module DYI #:nodoc:
172
269
 
173
270
  private
174
271
 
175
- def get_formatter(format=nil, options={}) #:nodoc:
272
+ def get_formatter(format=nil, options={})
176
273
  case format
177
274
  when :svg, nil
178
275
  options[:indent] = 2 unless options.key?(:indent)
@@ -51,7 +51,6 @@ module DYI #:nodoc:
51
51
  @records.clear
52
52
  end
53
53
 
54
- # @return [void]
55
54
  # @since 1.0.0
56
55
  def values_each(&block)
57
56
  @records.each do |record|
@@ -73,7 +72,6 @@ module DYI #:nodoc:
73
72
  @schema.members.include?(RUBY_VERSION >= '1.9' ? field_name.to_sym : field_name.to_s)
74
73
  end
75
74
 
76
- # @return [void]
77
75
  # @since 1.0.0
78
76
  def each(&block)
79
77
  @records.each(&block)
@@ -83,6 +81,14 @@ module DYI #:nodoc:
83
81
  @records = []
84
82
  end
85
83
 
84
+ # Loads array-of-array and sets data.
85
+ # @param [Array<Array>] array_of_array two dimensional array
86
+ # @option options [Range] :row_range a range of rows
87
+ # @option options [Range] :column_range a range of columns
88
+ # @option options [Array<Symbol>] :schema array of field names
89
+ # @option options [Array<Symbol>] :data_types array of field data types
90
+ # @option options [Boolean] :transposed whether the array-of-array is
91
+ # transposed
86
92
  def read(array_of_array, options={})
87
93
  clear_data
88
94
  row_range = options[:row_range] || (0..-1)
@@ -183,6 +189,10 @@ module DYI #:nodoc:
183
189
  end
184
190
 
185
191
  class << self
192
+ # Create a new instance of ArrayReader, loading array-of-array.
193
+ # @param (see #read)
194
+ # @option (see #read)
195
+ # @return [ArrayReader] a new instance of ArrayReader
186
196
  def read(array_of_array, options={})
187
197
  new.read(array_of_array, options)
188
198
  end
@@ -29,7 +29,6 @@ module DYI #:nodoc:
29
29
  # Difines a read property.
30
30
  # @param [Symbol] name the property name
31
31
  # @param [Hash] settings settings of the property
32
- # @return [void]
33
32
  def opt_reader(name, settings = {})
34
33
  name = name.to_sym
35
34
  getter_name = settings[:type] == :boolean ? name.to_s.gsub(/^(.*[^=\?])[=\?]*$/, '\1?') : name
@@ -47,7 +46,6 @@ module DYI #:nodoc:
47
46
  # Difines a write property.
48
47
  # @param [Symbol] name the property name
49
48
  # @param [Hash] settings settings of the property
50
- # @return [void]
51
49
  def opt_writer(name, settings = {})
52
50
  name = name.to_sym
53
51
  setter_name = name.to_s.gsub(/^(.*[^=\?])[=\?]*$/, '\1=')
@@ -184,7 +182,6 @@ module DYI #:nodoc:
184
182
  # Difines a read-write property.
185
183
  # @param [Symbol] name the property name
186
184
  # @param [Hash] settings settings of the property
187
- # @return [void]
188
185
  def opt_accessor(name, settings = {})
189
186
  opt_reader(name, settings)
190
187
  opt_writer(name, settings)
@@ -24,11 +24,33 @@ require 'date'
24
24
  require 'bigdecimal'
25
25
  require 'nkf'
26
26
 
27
- module DYI #:nodoc:
28
- module Chart #:nodoc:
27
+ module DYI
28
+ module Chart
29
29
 
30
+ # CsvReader class provides a interface to CSV file and data for a chart
31
+ # object.
30
32
  class CsvReader < ArrayReader
31
- def read(path, options={})
33
+
34
+ # @private
35
+ alias __org_read__ read
36
+
37
+ # Parses CSV data and sets data.
38
+ # @param [String] csv CSV data
39
+ # @option (see ArrayReader#read)
40
+ # @option options [String] :date_format date format string of CSV data,
41
+ # parsing a date string in CSV at +Date#strptime+
42
+ # @option options [String] :datetime_format date-time format string of CSV
43
+ # data, parsing a date-time string in CSV at +DateTime#strptime+
44
+ # @option options [Symbol] :encode encoding of CSV data as the following:
45
+ # +:utf8+ (default), +:sjis+, +:euc+, +:jis+ (ISO-2022-JP), +:utf16+
46
+ # (UTF-16BE)
47
+ # @option options [String] :col_sep a separator of columns, default to
48
+ # <tt>","</tt>
49
+ # @option options [String] :row_sep a separator of rows, default to
50
+ # +:auto+ which means that a separetor is <tt>"\r\n"</tt>, <tt>"\n"</tt>,
51
+ # or <tt>"\r"</tt> sequence
52
+ # @since 1.1.1
53
+ def parse(csv, options={})
32
54
  options = options.clone
33
55
  @date_format = options.delete(:date_format)
34
56
  @datetime_format = options.delete(:datetime_format)
@@ -43,11 +65,18 @@ module DYI #:nodoc:
43
65
  end
44
66
  parsed_array =
45
67
  if RUBY_VERSION >= '1.9'
46
- CSV.parse(nkf_options ? NKF.nkf(nkf_options, IO.read(path)) : IO.read(path), :col_sep => options[:col_sep] || ',', :row_sep => options[:row_sep] || :auto)
68
+ CSV.parse(nkf_options ? NKF.nkf(nkf_options, csv) : csv, :col_sep => options[:col_sep] || ',', :row_sep => options[:row_sep] || :auto)
47
69
  else
48
- CSV.parse(nkf_options ? NKF.nkf(nkf_options, IO.read(path)) : IO.read(path), options[:col_sep], options[:row_sep])
70
+ CSV.parse(nkf_options ? NKF.nkf(nkf_options, csv) : csv, options[:col_sep], options[:row_sep])
49
71
  end
50
- super(parsed_array, options)
72
+ __org_read__(parsed_array, options)
73
+ end
74
+
75
+ # Parses CSV file and sets data.
76
+ # @param [String] path a path of the CSV file
77
+ # @option (see #parse)
78
+ def read(path, options={})
79
+ parse(IO.read(path), options)
51
80
  end
52
81
 
53
82
  private
@@ -80,9 +109,23 @@ module DYI #:nodoc:
80
109
  end
81
110
 
82
111
  class << self
112
+ # Parses CSV file and creates instance of CsvReader.
113
+ # @param (see #read)
114
+ # @option (see #read)
115
+ # @return [CsvReader] a new instance of CsvReader
116
+ # @see ArrayReader.read
83
117
  def read(path, options={})
84
118
  new.read(path, options)
85
119
  end
120
+
121
+ # Parses CSV data and creates instance of CsvReader.
122
+ # @param (see #parse)
123
+ # @option (see #parse)
124
+ # @return [CsvReader] a new instance of CsvReader
125
+ # @see ArrayReader.read
126
+ def parse(path, options={})
127
+ new.parse(path, options)
128
+ end
86
129
  end
87
130
  end
88
131
  end