dyi 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,10 @@
1
1
  = DYI Changelog
2
2
 
3
+ == Version 1.0.1 / 2011-09-28
4
+ * Bug Fixes
5
+ * A event listeners dose not work properly.
6
+ * CSS class name is not outputed properly.
7
+
3
8
  == Version 1.0.0 / 2011-09-05
4
9
 
5
10
  * Major Enhancements
data/README CHANGED
@@ -23,6 +23,11 @@ along with DYI. If not, see <http://www.gnu.org/licenses/>.
23
23
 
24
24
  == Support
25
25
 
26
- We plan to make up a mailing list for support of DYI ,but it is
27
- under construction.
28
- We're going to set up it in a few days.
26
+ We support DYI using SourceForge.net. URL of DYI Project is
27
+ "http://sourceforge.net/projects/dyi/". This page has a tracker
28
+ and forums.
29
+
30
+ We are also preparing the Japanese mailing list. More infomation
31
+ about the mailing list is indicated to
32
+ <http://open-dyi.org/contents.html#community> in Japanese,
33
+ including how to join it.
@@ -27,7 +27,7 @@ module DYI #:nodoc:
27
27
  attr_reader *IMPLEMENT_ATTRIBUTES
28
28
  attr_reader :child_elements
29
29
  # @since 1.0.0
30
- attr_reader :event_listeners, :stylesheets
30
+ attr_reader :event_listeners, :stylesheets, :scripts
31
31
 
32
32
  def initialize(width, height,
33
33
  real_width = nil, real_height = nil,
@@ -84,11 +84,6 @@ module DYI #:nodoc:
84
84
  self
85
85
  end
86
86
 
87
- # @since 1.0.0
88
- def event_listeners
89
- @event_listeners ||= {}
90
- end
91
-
92
87
  def write_as(formatter, io=$>)
93
88
  formatter.write_canvas(self, io)
94
89
  end
@@ -133,14 +128,21 @@ module DYI #:nodoc:
133
128
  @receive_event
134
129
  end
135
130
 
136
- # @since 1.0.0
137
- def scripts
138
- @init_script ? [@init_script].push(*@scripts) : @scripts
139
- end
140
-
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
141
139
  # @since 1.0.0
142
140
  def add_script(script_body, content_type = 'application/ecmascript')
143
- @scripts << Script::SimpleScript.new(script_body, content_type)
141
+ if script_body.respond_to?(:include_external_file?)
142
+ @scripts << script_body unless @scripts.include?(script_body)
143
+ else
144
+ @scripts << Script::SimpleScript.new(script_body, content_type)
145
+ end
144
146
  end
145
147
 
146
148
  # @since 1.0.0
@@ -169,24 +171,6 @@ module DYI #:nodoc:
169
171
  end
170
172
  end
171
173
 
172
- # @since 1.0.0
173
- def add_event_listener(event_name, event_listener)
174
- if event_listeners.key?(event_name)
175
- unless event_listeners[event_name].include?(event_listener)
176
- event_listeners[event_name] << event_listener
177
- end
178
- else
179
- event_listeners[event_name] = [event_listener]
180
- end
181
- end
182
-
183
- # @since 1.0.0
184
- def remove_event_listener(event_name, event_listener)
185
- if event_listeners.key?(event_name)
186
- event_listeners[event_name].delete(event_listener)
187
- end
188
- end
189
-
190
174
  private
191
175
 
192
176
  def get_formatter(format=nil) #:nodoc:
@@ -32,7 +32,7 @@ module DYI #:nodoc:
32
32
  # @return [Array] array of a struct
33
33
  # @since 1.0.0
34
34
  def records
35
- @records.dup
35
+ @records.clone
36
36
  end
37
37
 
38
38
  # @return [Integer] number of the records
@@ -70,7 +70,7 @@ module DYI #:nodoc:
70
70
 
71
71
  # @since 1.0.0
72
72
  def has_field?(field_name)
73
- @schema.members.include?(field_name.to_s)
73
+ @schema.members.include?(RUBY_VERSION >= '1.9' ? field_name.to_sym : field_name.to_s)
74
74
  end
75
75
 
76
76
  # @return [void]
@@ -265,8 +265,8 @@ module DYI #:nodoc:
265
265
  end
266
266
 
267
267
  def chart_color(index) #:nodoc:
268
- if data.has_field?(:color) && (color = data.records[index].color)
269
- color
268
+ if data.has_field?(:color)
269
+ color = Color.new_or_nil(data.records[index].color)
270
270
  end
271
271
  if color.nil? && respond_to?(:chart_colors) && chart_colors
272
272
  color = chart_colors[index]
@@ -29,7 +29,7 @@ module DYI #:nodoc:
29
29
 
30
30
  class CsvReader < ArrayReader
31
31
  def read(path, options={})
32
- options = options.dup
32
+ options = options.clone
33
33
  @date_format = options.delete(:date_format)
34
34
  @datetime_format = options.delete(:datetime_format)
35
35
  nkf_options =
@@ -56,7 +56,7 @@ module DYI #:nodoc:
56
56
  if type.is_a?(Symbol) || type.is_a?(String)
57
57
  case type.to_sym
58
58
  when :string
59
- value || ''
59
+ value
60
60
  when :number, :decimal
61
61
  value ? BigDecimal.new(value) : nil
62
62
  when :float
@@ -268,7 +268,6 @@ module DYI #:nodoc:
268
268
  format_string(format, record, toatal)
269
269
  end
270
270
  end
271
- require 'pp'
272
271
  max_lengths = legend_labels.inject(Array.new(formats.size, 0)) do |maxs, labels|
273
272
  (0...formats.size).each do |i|
274
273
  maxs[i] = labels[i].bytesize if maxs[i] < labels[i].bytesize
@@ -217,7 +217,7 @@ module DYI #:nodoc:
217
217
  # all other characters:: The character is copied to the result string
218
218
  # unchanged.
219
219
  def default_format=(fromat)
220
- @@default_format = fromat.dup
220
+ @@default_format = fromat.clone
221
221
  end
222
222
  end
223
223
  end
@@ -45,7 +45,7 @@ module DYI #:nodoc:
45
45
  Painting::IMPLEMENT_ATTRIBUTES.each do |painting_attr|
46
46
  define_method(painting_attr) {| | @painting.__send__(painting_attr)}
47
47
  define_method("#{painting_attr}=".to_sym) {|value|
48
- @painting = @painting.dup
48
+ @painting = @painting.clone
49
49
  @painting.__send__("#{painting_attr}=".to_sym, value)
50
50
  }
51
51
  end
@@ -158,7 +158,7 @@ module DYI #:nodoc:
158
158
  #:startdoc:
159
159
 
160
160
  def initialize(options={})
161
- options = options.dup
161
+ options = options.clone
162
162
  ALIAS_ATTRIBUTES.each do |key, value|
163
163
  options[value] = options.delete(key) if options.key?(key) && !options.key?(value)
164
164
  end
@@ -209,7 +209,7 @@ module DYI #:nodoc:
209
209
  #:startdoc:
210
210
 
211
211
  def initialize(options={})
212
- options = options.dup
212
+ options = options.clone
213
213
  ALIAS_ATTRIBUTES.each do |key, value|
214
214
  options[value] = options.delete(key) if options.key?(key) && !options.key?(value)
215
215
  end
@@ -143,10 +143,10 @@ module DYI #:nodoc:
143
143
  radius_y = ry
144
144
 
145
145
  shape = Shape::ShapeGroup.draw_on(canvas)
146
- top_painting = @painting.dup
146
+ top_painting = @painting.clone
147
147
  top_painting.fill = top_color
148
148
  Shape::Ellipse.create_on_center_radius(Coordinate.new(left_top_point) + [width.quo(2), 0], radius_x, radius_y, merge_option(:painting => top_painting)).draw_on(shape)
149
- body_painting = @painting.dup
149
+ body_painting = @painting.clone
150
150
  body_painting.fill = body_gradient(canvas)
151
151
  Shape::Path.draw(left_top_point, merge_option(:painting => body_painting)) {|path|
152
152
  path.rarc_to([width, 0], radius_x, radius_y, 0, false, false)
@@ -87,6 +87,7 @@ module DYI #:nodoc:
87
87
  CLASS_REGEXP = /\A[A-Z_a-z][\-0-9A-Z_a-z]*\z/
88
88
 
89
89
  def css_class=(css_class)
90
+ return @css_class = nil if css_class.nil?
90
91
  classes = css_class.to_s.split(/\s+/)
91
92
  classes.each do |c|
92
93
  if c.to_s !~ CLASS_REGEXP
@@ -97,7 +98,7 @@ module DYI #:nodoc:
97
98
  end
98
99
 
99
100
  def css_classes
100
- css_class.split(/\s+/)
101
+ css_class.to_s.split(/\s+/)
101
102
  end
102
103
 
103
104
  def add_css_class(css_class)
@@ -105,7 +106,7 @@ module DYI #:nodoc:
105
106
  raise ArgumentError, "`#{css_class}' is a illegal class-name"
106
107
  end
107
108
  unless css_classes.include?(css_class.to_s)
108
- @css_class += " #{css_class}"
109
+ @css_class = css_classes.push(scc_class).join(' ')
109
110
  css_class
110
111
  end
111
112
  nil
@@ -114,7 +115,7 @@ module DYI #:nodoc:
114
115
  def remove_css_class(css_class)
115
116
  classes = css_classes
116
117
  if classes.delete(css_class.to_s)
117
- @css_class = classes.join(' ')
118
+ @css_class = classes.empty? ? nil : classes.join(' ')
118
119
  css_class
119
120
  else
120
121
  nil
@@ -142,21 +143,24 @@ module DYI #:nodoc:
142
143
 
143
144
  # Associates the element with a event listener
144
145
  # @param [Symbol] event_name a event name
145
- # @param [Script::SimpleScript|String] event_listener a event listener
146
+ # @param [Script::SimpleScript] event_listener a event listener
146
147
  # @return [void]
147
148
  def add_event_listener(event_name, event_listener)
149
+ event_listener.related_to(DYI::Event.new(event_name, self))
148
150
  if event_listeners.key?(event_name)
149
151
  unless event_listeners[event_name].include?(event_listener)
150
152
  event_listeners[event_name] << event_listener
153
+ canvas.add_script(event_listener)
151
154
  end
152
155
  else
153
156
  event_listeners[event_name] = [event_listener]
157
+ canvas.add_script(event_listener)
154
158
  end
155
159
  end
156
160
 
157
161
  # Removes asociation with given event listener
158
162
  # @param [Symbol] event_name a event name
159
- # @param [Script::SimpleScript|String] event_listener a event listener
163
+ # @param [Script::SimpleScript] event_listener a event listener
160
164
  # @return [void]
161
165
  def remove_event_listener(event_name, event_listener)
162
166
  if event_listeners.key?(event_name)
@@ -43,9 +43,6 @@ module DYI
43
43
  # @return [GraphicalElement] an element to which the event applied
44
44
  attr_reader :target
45
45
 
46
- # @return [Array] a list of event listener
47
- attr_reader :listeners
48
-
49
46
  # @param [Symbol] event_name event name, one of followings: focusin,
50
47
  # focusout, click, mousedown, mouseup, mouseover,
51
48
  # mousemove, mouseout, load
@@ -57,7 +54,6 @@ module DYI
57
54
  raise ArgumentError, "`#{event_name}' is unknown event"
58
55
  end
59
56
  @event_name = event_name
60
- @listeners = []
61
57
  (@target = target).set_event(self)
62
58
  end
63
59
 
@@ -79,6 +75,21 @@ module DYI
79
75
  event_listener.unrelated_to(self)
80
76
  end
81
77
 
78
+ # @since 1.0.1
79
+ def ==(other)
80
+ event_name == other.event_name && target == other.target
81
+ end
82
+
83
+ # @since 1.0.1
84
+ def eql?(other)
85
+ self == other
86
+ end
87
+
88
+ # @since 1.0.1
89
+ def hash
90
+ event_name.hash ^ target.hash
91
+ end
92
+
82
93
  class << self
83
94
 
84
95
  # Creates a new focus-in event.
@@ -384,7 +384,7 @@ module DYI #:nodoc:
384
384
  def clip_path(io, shape) #:nodoc:
385
385
  if shape.respond_to?(:clipping) && shape.clipping
386
386
  shape.clipping.each_shapes do |shape, rule|
387
- s = shape.dup
387
+ s = shape.clone
388
388
  s.painting.fill = nil
389
389
  s.painting.stroke = nil
390
390
  s.write_as(self, io) {
@@ -67,7 +67,7 @@ module DYI #:nodoc:
67
67
  unless listeners.empty?
68
68
  methods = listeners.map do |listener|
69
69
  if listener.name
70
- "#{listener.name}(#{listener.arguments.join(',')})"
70
+ "#{listener.name}(evt)"
71
71
  end
72
72
  end
73
73
  attrs["on#{event_name}"] = methods.compact.join(';')
@@ -405,6 +405,17 @@ module DYI #:nodoc:
405
405
 
406
406
  # @since 1.0.0
407
407
  def write_node(shape, io, attrs, tag_name, &create_child_node)
408
+ shape.event_listeners.each do |event_name, listeners|
409
+ unless listeners.empty?
410
+ methods = listeners.inject([]) do |array, listener|
411
+ if listener.name
412
+ array << "#{listener.name}(evt)"
413
+ end
414
+ array
415
+ end
416
+ attrs["on#{event_name}"] = methods.join(';') unless methods.empty?
417
+ end
418
+ end
408
419
  if shape.anchor_href
409
420
  link_attrs = {:'xlink:href' => shape.anchor_href}
410
421
  link_attrs[:target] = shape.anchor_target if shape.anchor_target
@@ -535,7 +546,7 @@ module DYI #:nodoc:
535
546
  def common_attributes(shape) #:nodoc:
536
547
  attributes = {}
537
548
  create_style(shape, attributes)
538
- attributes[:class] = shape.css_class unless shape.css_class.empty?
549
+ attributes[:class] = shape.css_class if shape.css_class
539
550
  transform = create_transform(shape)
540
551
  attributes[:transform] = transform if transform
541
552
  attributes[:'clip-path'] = "url(##{shape.clipping.id})" if shape.clipping
@@ -392,7 +392,7 @@ module DYI #:nodoc:
392
392
  # +U+:: (unit placeholder) Placeholder '+U+' is replaced as a unit. If
393
393
  # the unit is user unit, '+U+' is replece as empty string.
394
394
  def default_format=(fromat)
395
- @@default_format = fromat.dup
395
+ @@default_format = fromat.clone
396
396
  end
397
397
  end
398
398
  end
@@ -28,7 +28,8 @@
28
28
 
29
29
  module DYI
30
30
  module Script
31
- # Module for using ECMAScript.
31
+ # Module for using ECMAScript. The script generated by this module comfirms
32
+ # to ECMAScript 5.1 (Ecma International Standard ECMA-262).
32
33
  module EcmaScript
33
34
 
34
35
  # This Module includes helper methods for generating a client-script.
@@ -227,7 +228,9 @@ module DYI
227
228
  # @param [Event] event an event that is related to
228
229
  # @return [void]
229
230
  def related_to(event)
230
- @events << event
231
+ unless @events.include?(event)
232
+ @events << event
233
+ end
231
234
  end
232
235
 
233
236
  # Removes the relation to an event.
@@ -243,13 +246,13 @@ module DYI
243
246
  super
244
247
  else
245
248
  parts = []
246
- parts << "setTimeout(function() {\n"
249
+ parts << "addEventListener(\"load\", function(evt) {\n"
247
250
  @events.each do |event|
248
251
  if event.event_name == :load
249
252
  parts << @body
250
253
  elsif
251
254
  if event.target.root_element?
252
- parts << ' document.rootElement.addEventListener("'
255
+ parts << ' document.documentElement.addEventListener("'
253
256
  else
254
257
  parts << ' document.getElementById("'
255
258
  parts << event.target.id
@@ -263,7 +266,7 @@ module DYI
263
266
  parts << " }, false);\n"
264
267
  end
265
268
  end
266
- parts << "}, 0);\n"
269
+ parts << "}, false);\n"
267
270
  parts.join
268
271
  end
269
272
  end
@@ -461,7 +461,7 @@ module DYI #:nodoc:
461
461
  end
462
462
 
463
463
  def points
464
- @points.dup
464
+ @points.clone
465
465
  end
466
466
 
467
467
  def undo
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yuo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-05 00:00:00 Z
18
+ date: 2011-09-28 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: " DYI is a 2D graphics library, very rich and expressive.\n DYI have been optimized for SVG format, but it is also possible\n to output other format; for example, EPS.\n"