derailed-ziya 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/History.txt +0 -0
  2. data/Manifest.txt +405 -0
  3. data/README.txt +232 -0
  4. data/Rakefile +44 -0
  5. data/bin/ziyafy +53 -0
  6. data/charts/AC_RunActiveContent.js +292 -0
  7. data/charts/charts.swf +0 -0
  8. data/charts/charts_library/ar3d.swf +0 -0
  9. data/charts/charts_library/arno.swf +0 -0
  10. data/charts/charts_library/ars3.swf +0 -0
  11. data/charts/charts_library/arst.swf +0 -0
  12. data/charts/charts_library/brfl.swf +0 -0
  13. data/charts/charts_library/brno.swf +0 -0
  14. data/charts/charts_library/brst.swf +0 -0
  15. data/charts/charts_library/buno.swf +0 -0
  16. data/charts/charts_library/cl3d.swf +0 -0
  17. data/charts/charts_library/clfl.swf +0 -0
  18. data/charts/charts_library/clno.swf +0 -0
  19. data/charts/charts_library/clp3.swf +0 -0
  20. data/charts/charts_library/cls3.swf +0 -0
  21. data/charts/charts_library/clst.swf +0 -0
  22. data/charts/charts_library/cnno.swf +0 -0
  23. data/charts/charts_library/dono.swf +0 -0
  24. data/charts/charts_library/lnno.swf +0 -0
  25. data/charts/charts_library/mxno.swf +0 -0
  26. data/charts/charts_library/pi3d.swf +0 -0
  27. data/charts/charts_library/pino.swf +0 -0
  28. data/charts/charts_library/pono.swf +0 -0
  29. data/charts/charts_library/scno.swf +0 -0
  30. data/charts/full_screen.swf +0 -0
  31. data/charts/scripts/output_jpg.php +23 -0
  32. data/charts/sliders/black.swf +0 -0
  33. data/charts/sliders/preview_handle_1.swf +0 -0
  34. data/charts/sliders/preview_handle_2.swf +0 -0
  35. data/gauges/designs/circle.yml +18 -0
  36. data/gauges/designs/signal.yml +14 -0
  37. data/gauges/designs/thermo.yml +119 -0
  38. data/gauges/designs/title.yml +11 -0
  39. data/gauges/gauge.swf +0 -0
  40. data/lib/ziya/charts/area.rb +18 -0
  41. data/lib/ziya/charts/area_threed.rb +16 -0
  42. data/lib/ziya/charts/bar.rb +16 -0
  43. data/lib/ziya/charts/base.rb +510 -0
  44. data/lib/ziya/charts/bubble.rb +18 -0
  45. data/lib/ziya/charts/candle_stick.rb +16 -0
  46. data/lib/ziya/charts/column.rb +16 -0
  47. data/lib/ziya/charts/column_threed.rb +16 -0
  48. data/lib/ziya/charts/donut.rb +18 -0
  49. data/lib/ziya/charts/floating_bar.rb +16 -0
  50. data/lib/ziya/charts/floating_column.rb +16 -0
  51. data/lib/ziya/charts/line.rb +16 -0
  52. data/lib/ziya/charts/mixed.rb +16 -0
  53. data/lib/ziya/charts/parallel_threed_column.rb +16 -0
  54. data/lib/ziya/charts/pie.rb +16 -0
  55. data/lib/ziya/charts/pie_threed.rb +16 -0
  56. data/lib/ziya/charts/polar.rb +16 -0
  57. data/lib/ziya/charts/scatter.rb +16 -0
  58. data/lib/ziya/charts/stacked_area.rb +16 -0
  59. data/lib/ziya/charts/stacked_bar.rb +16 -0
  60. data/lib/ziya/charts/stacked_column.rb +16 -0
  61. data/lib/ziya/charts/stacked_threed_area.rb +16 -0
  62. data/lib/ziya/charts/stacked_threed_column.rb +16 -0
  63. data/lib/ziya/components/area.rb +17 -0
  64. data/lib/ziya/components/axis_category.rb +17 -0
  65. data/lib/ziya/components/axis_ticks.rb +35 -0
  66. data/lib/ziya/components/axis_value.rb +16 -0
  67. data/lib/ziya/components/base.rb +142 -0
  68. data/lib/ziya/components/bevel.rb +15 -0
  69. data/lib/ziya/components/blur.rb +13 -0
  70. data/lib/ziya/components/chart_border.rb +14 -0
  71. data/lib/ziya/components/chart_grid_h.rb +26 -0
  72. data/lib/ziya/components/chart_grid_v.rb +27 -0
  73. data/lib/ziya/components/chart_guide.rb +16 -0
  74. data/lib/ziya/components/chart_label.rb +16 -0
  75. data/lib/ziya/components/chart_pref.rb +22 -0
  76. data/lib/ziya/components/chart_rect.rb +37 -0
  77. data/lib/ziya/components/chart_transition.rb +25 -0
  78. data/lib/ziya/components/circle.rb +16 -0
  79. data/lib/ziya/components/context_menu.rb +15 -0
  80. data/lib/ziya/components/draw.rb +47 -0
  81. data/lib/ziya/components/draw_base.rb +10 -0
  82. data/lib/ziya/components/filter.rb +26 -0
  83. data/lib/ziya/components/glow.rb +14 -0
  84. data/lib/ziya/components/image.rb +17 -0
  85. data/lib/ziya/components/legend.rb +18 -0
  86. data/lib/ziya/components/line.rb +16 -0
  87. data/lib/ziya/components/link.rb +29 -0
  88. data/lib/ziya/components/link_data.rb +18 -0
  89. data/lib/ziya/components/rect.rb +18 -0
  90. data/lib/ziya/components/scroll.rb +26 -0
  91. data/lib/ziya/components/series.rb +16 -0
  92. data/lib/ziya/components/series_color.rb +35 -0
  93. data/lib/ziya/components/series_explode.rb +38 -0
  94. data/lib/ziya/components/shadow.rb +14 -0
  95. data/lib/ziya/components/text.rb +17 -0
  96. data/lib/ziya/components/update.rb +19 -0
  97. data/lib/ziya/gauges/base.rb +172 -0
  98. data/lib/ziya/gauges/radial.rb +18 -0
  99. data/lib/ziya/gauges/signal.rb +138 -0
  100. data/lib/ziya/gauges/support/area.rb +13 -0
  101. data/lib/ziya/gauges/support/base.rb +33 -0
  102. data/lib/ziya/gauges/support/circle.rb +14 -0
  103. data/lib/ziya/gauges/support/design.rb +5 -0
  104. data/lib/ziya/gauges/support/image.rb +12 -0
  105. data/lib/ziya/gauges/support/line.rb +12 -0
  106. data/lib/ziya/gauges/support/link.rb +24 -0
  107. data/lib/ziya/gauges/support/move.rb +15 -0
  108. data/lib/ziya/gauges/support/point.rb +12 -0
  109. data/lib/ziya/gauges/support/polygon.rb +13 -0
  110. data/lib/ziya/gauges/support/radial_base.rb +21 -0
  111. data/lib/ziya/gauges/support/radial_numbers.rb +41 -0
  112. data/lib/ziya/gauges/support/radial_ticks.rb +29 -0
  113. data/lib/ziya/gauges/support/rect.rb +14 -0
  114. data/lib/ziya/gauges/support/rotate.rb +15 -0
  115. data/lib/ziya/gauges/support/scale.rb +15 -0
  116. data/lib/ziya/gauges/support/text.rb +21 -0
  117. data/lib/ziya/gauges/support/update.rb +12 -0
  118. data/lib/ziya/gauges/thermo.rb +121 -0
  119. data/lib/ziya/helpers/base_helper.rb +70 -0
  120. data/lib/ziya/utils/logger.rb +125 -0
  121. data/lib/ziya/utils/text.rb +39 -0
  122. data/lib/ziya/version.rb +15 -0
  123. data/lib/ziya/ziya_helper.rb +374 -0
  124. data/lib/ziya.rb +112 -0
  125. data/spec/charts/base_spec.rb +134 -0
  126. data/spec/charts/chart_type_spec.rb +63 -0
  127. data/spec/components/area_spec.rb +67 -0
  128. data/spec/components/draw_spec.rb +32 -0
  129. data/spec/components/filter_spec.rb +27 -0
  130. data/spec/components/link_spec.rb +22 -0
  131. data/spec/components/series.rb +18 -0
  132. data/spec/components/series_color_spec.rb +39 -0
  133. data/spec/components/series_explode.rb +39 -0
  134. data/spec/components/series_explode_spec.rb +39 -0
  135. data/spec/designs/circle.yml +7 -0
  136. data/spec/designs/crapping_out.yml +8 -0
  137. data/spec/designs/gauge_1.yml +43 -0
  138. data/spec/designs/gauge_2.yml +11 -0
  139. data/spec/designs/gauge_no_name.yml +43 -0
  140. data/spec/designs/gauge_raw.yml +5 -0
  141. data/spec/designs/thermo.yml +13 -0
  142. data/spec/gauges/base_spec.rb +90 -0
  143. data/spec/gauges/signal_spec.rb +36 -0
  144. data/spec/gauges/support/area_spec.rb +40 -0
  145. data/spec/gauges/support/circle_spec.rb +78 -0
  146. data/spec/gauges/support/image_spec.rb +35 -0
  147. data/spec/gauges/support/line_spec.rb +34 -0
  148. data/spec/gauges/support/link_spec.rb +35 -0
  149. data/spec/gauges/support/move_spec.rb +45 -0
  150. data/spec/gauges/support/polygon_spec.rb +36 -0
  151. data/spec/gauges/support/radial_numbers_spec.rb +35 -0
  152. data/spec/gauges/support/radial_ticks_spec.rb +30 -0
  153. data/spec/gauges/support/rotate_spec.rb +45 -0
  154. data/spec/gauges/support/scale_spec.rb +46 -0
  155. data/spec/gauges/support/text_spec.rb +40 -0
  156. data/spec/gauges/thermo_spec.rb +49 -0
  157. data/spec/helpers/base_helper_spec.rb +36 -0
  158. data/spec/spec_helper.rb +10 -0
  159. data/spec/test_helpers/gauge_2_helper.rb +17 -0
  160. data/spec/themes/default/fred.yml +6 -0
  161. data/spec/themes/default/line_chart.yml +6 -0
  162. data/spec/utils/logger_spec.rb +55 -0
  163. data/spec/utils/text_spec.rb +33 -0
  164. data/spec/ziya_helper_spec.rb +117 -0
  165. data/spec/ziya_spec.rb +19 -0
  166. data/tasks/ann.rake +76 -0
  167. data/tasks/annotations.rake +22 -0
  168. data/tasks/doc.rake +48 -0
  169. data/tasks/gem.rake +110 -0
  170. data/tasks/manifest.rake +49 -0
  171. data/tasks/post_load.rake +26 -0
  172. data/tasks/rubyforge.rake +57 -0
  173. data/tasks/setup.rb +227 -0
  174. data/tasks/spec.rake +61 -0
  175. data/tasks/svn.rake +44 -0
  176. data/tasks/test.rake +38 -0
  177. metadata +468 -0
@@ -0,0 +1,510 @@
1
+ # -----------------------------------------------------------------------------
2
+ # == Ziya::Charts::Base
3
+ #
4
+ # Charts mother ship
5
+ #
6
+ # TODO !! Match helpers with chart class name
7
+ # TODO !! Add accessor for specifying refresh look and data links on comps
8
+ #
9
+ # Author:: Fernand Galiana
10
+ # Date:: Dec 15th, 2006
11
+ # -----------------------------------------------------------------------------
12
+ require 'ziya/helpers/base_helper'
13
+ require 'yaml'
14
+
15
+ # TODO Figure out the equiv require_dep for merb if any ??
16
+ # TODO Refact and clean up.
17
+ module Ziya::Charts
18
+ # The mother ship of all charts. This class figures out how to generate the
19
+ # correct xml to render the chart on the client side. This class handles loading
20
+ # style sheets and chart helper for the helper directory specified during
21
+ # initialization.
22
+ class Base
23
+ # blee blee
24
+ include Ziya::Helpers::BaseHelper
25
+
26
+ # =========================================================================
27
+ protected
28
+ # defines the various chart components
29
+ def self.declare_components # :nodoc:
30
+ @components = [
31
+ :axis_category, :axis_ticks, :axis_value,
32
+ :chart_rect, :chart_border, :chart_grid_h, :chart_grid_v,
33
+ :chart_transition, :chart_label, :chart_guide, :legend,
34
+ :filter, :draw,
35
+ :series_color, :series, :series_explode,
36
+ :chart_pref, :scroll,
37
+ :update, :link_data, :link, :context_menu]
38
+ @components.each { |a| attr_accessor a }
39
+ end
40
+ declare_components
41
+
42
+ # =========================================================================
43
+ public
44
+
45
+ attr_accessor :license, :id, :theme, :options, :size # :nodoc:
46
+ attr_reader :type # :nodoc:
47
+
48
+ # create a new chart.
49
+ # <tt>:license</tt>:: the XML/SWF charts license
50
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
51
+ # NOTE: If chart_id is specified the framework will attempt to load the chart styles
52
+ # from public/themes/theme_name/chart_id.yml
53
+ def initialize( license=nil, chart_id=nil )
54
+ @id = chart_id
55
+ @license = license
56
+ @options = {}
57
+ @series_desc = []
58
+ @theme = default_theme
59
+ @render_mode = Base.all_styles
60
+ initialize_components
61
+ load_helpers( Ziya.helpers_dir ) if Ziya.helpers_dir
62
+ end
63
+
64
+ # class component accessor...
65
+ def self.components # :nodoc:
66
+ @components
67
+ end
68
+
69
+ # don't render stylesheets just gen code for chart stylesheet and data
70
+ def self.data_only() 1; end
71
+
72
+ # renders everything
73
+ def self.all_styles() 0; end
74
+
75
+ # -------------------------------------------------------------------------
76
+ # Default ZiYa theme
77
+ def default_theme # :nodoc:
78
+ File.join( Ziya.themes_dir, %w[default] )
79
+ end
80
+
81
+ # -------------------------------------------------------------------------
82
+ # Load up ERB style helpers
83
+ def load_helpers( helper_dir ) # :nodoc:
84
+ Dir.foreach(helper_dir) do |helper_file|
85
+ next unless helper_file =~ /^([a-z][a-z_]*_helper).rb$/
86
+ Ziya.logger.debug( ">>> ZiYa loading custom helper `#{$1}" )
87
+ require_dependency File.join(helper_dir, $1)
88
+ helper_module_name = "Ziya::" + $1.gsub(/(^|_)(.)/) { $2.upcase }
89
+ # helper_module_name = $1.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
90
+ # if Ziya::Helpers.const_defined?(helper_module_name)
91
+ Ziya.logger.debug( "Include module #{helper_module_name}")
92
+ Ziya::Charts::Base.class_eval("include #{helper_module_name}")
93
+ # end
94
+ end
95
+ end
96
+
97
+ # Add chart components such as x and y axis labels, data points and chart
98
+ # labels.
99
+ #
100
+ # Example:
101
+ # my_chart = Ziya::Charts::Bar.new
102
+ # my_chart.add( :axis_category_text, ['2004', '2005', '2006'] )
103
+ # my_chart.add( :series, 'series A', [ 10, 20, 30], [ '10 dogs', '20 cats', '30 rats'] )
104
+ # my_chart.add( :axis_value_label, [ 'my dogs', 'my cats', 'my rats'] )
105
+ # my_chart.add( :user_data, :mykey, "Fred" )
106
+ #
107
+ # This will display a bar chart with x axis ticks my dogs, my cats, my fox and
108
+ # y axis values 2004, 2005, 2006. The labels on the bars will read 10 dogs,
109
+ # 20 cats, 30 rats
110
+ #
111
+ # The <tt>args</tt> must contain certain keys for the chart
112
+ # to be display correctly. The keys are defined as follows:
113
+ # <tt>:axis_category_text</tt>:: Array of strings representing the x/y axis
114
+ # ticks dependending on the chart type. This
115
+ # value is required.
116
+ # <tt>:axis_category_label</tt>:: Array of strings representing the x axis
117
+ # labels. This is supported only for Scatter and Bubble charts.
118
+ # This value is optional. Specify nil for no label change.
119
+ # <tt>:series</tt>:: Specifies the series name and chart data points.
120
+ # The series name will be used to display chart legends.
121
+ # You must have at least one of these tag defined.
122
+ # You may also specify an array of strings to identifies the
123
+ # custom labels that will be used on top of the chart
124
+ # elements
125
+ # <tt>:axis_value_label</tt>:: Array of strings representing the ticks on the x/y
126
+ # axis depending on the chart type. This is symmetrical
127
+ # to the <tt>axis_category_label</tt> tag for the opposite
128
+ # chart axis. Specify nil for no label change.
129
+ # <tt>:user_data</tt>:: Used to make user data available to the ERB templates in
130
+ # the chart stylesheet yaml file. You must specify a key symbol
131
+ # and an ad-hoc value. The key will be used with the @options
132
+ # hash to access the user data.
133
+ # <tt>:composites</tt>:: Embeds multiple charts within the given chart via the draw image component.
134
+ # <tt>:chart_types</tt>:: Specify the chart types per series. This option should
135
+ # only be used with Mixed Charts !!
136
+ # <tt>:theme</tt>:: Specify the use of a given theme
137
+ #
138
+ def add( *args )
139
+ # TODO Validation categories = series, series = labels, etc...
140
+ directive = args.shift
141
+ case directive
142
+ when :axis_category_text
143
+ categories = args.first.is_a?(Array) ? args.shift : []
144
+ raise ArgumentError, "Must specify an array of categories" if categories.empty?
145
+ categories.insert( 0, nil )
146
+ @options[directive] = categories
147
+ when :axis_category_label
148
+ labels = args.first.is_a?(Array) ? args.shift : []
149
+ raise ArgumentError, "Must specify an array of category labels" if labels.empty?
150
+ @options[directive] = labels
151
+ when :composites
152
+ composites = args.first.is_a?(Array) ? args.shift: []
153
+ raise ArgumentError, "Must specify an array of urls for the composite chart(s)" if composites.empty?
154
+ @options[directive] = composites
155
+ when :axis_value_label
156
+ values = args.first.is_a?(Array) ? args.shift : []
157
+ raise ArgumentError, "Must specify an array of values" if values.empty?
158
+ @options[directive] = values
159
+ when :series
160
+ legend = args.first.is_a?(String) ? args.shift : ""
161
+ if args.first.is_a?( Array )
162
+ points = args.shift || []
163
+ raise ArgumentError, "Must specify an array of data points" if points.empty?
164
+ points.insert( 0, legend )
165
+ @series_desc << points
166
+ else
167
+ raise ArgumentError, "Must specify an array of data points"
168
+ end
169
+ when :user_data
170
+ key = args.first.is_a?(Symbol) ? args.shift : ""
171
+ raise ArgumentError, "Must specify a key" if key.to_s.empty?
172
+ value = args.shift
173
+ # raise ArgumentError, "Must specify a value" if value.empty?
174
+ @options[key] = value
175
+ when :styles
176
+ styles = args.first.is_a?(String) ? args.shift : ""
177
+ raise ArgumentError, "Must specify a set of styles" if styles.to_s.empty?
178
+ @options[directive] = styles
179
+ when :chart_types
180
+ types = args.first.is_a?(Array) ? args.shift : []
181
+ raise ArgumentError, "Must specify a set of chart types" if types.to_s.empty?
182
+ @options[directive] = types
183
+ when :theme
184
+ theme = args.first.is_a?(String) ? args.shift : ""
185
+ raise ArgumentError, "Must specify a theme name" if theme.to_s.empty?
186
+ @theme = "#{Ziya.themes_dir}/#{theme}"
187
+ when :mode
188
+ @render_mode = args.first.is_a?(Integer) ? args.shift : -1
189
+ raise ArgumentError, "Must specify a valid generation mode" if @render_mode == -1
190
+ else raise ArgumentError, "Invalid directive must be one of " +
191
+ ":axis_category_text, :axis_value, :series, :user_data"
192
+ end
193
+ end
194
+
195
+ # spews the graph specification to a string
196
+ # <tt>:partial</tt>:: You can specify this option to only update parts of the charts
197
+ # that have actually changed. This is useful for live update and
198
+ # link update where you may not need to redraw the whole chart.
199
+ def to_s( options={} )
200
+ @partial = options[:partial] || false
201
+ @xml = Builder::XmlMarkup.new
202
+ # Forces utf8 encoding on xml stream
203
+ @xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
204
+ @xml.chart do
205
+ @xml.license( @license ) unless @license.nil?
206
+ if render_parents?
207
+ if !@type.nil?
208
+ @xml.chart_type( @type )
209
+ elsif @options[:chart_types].is_a? Array and ! @options[:chart_types].empty?
210
+ @xml.chart_type do
211
+ @options[:chart_types].each { |type| @xml.string( type ) }
212
+ end
213
+ end
214
+ end
215
+ setup_lnf
216
+ setup_series
217
+ end
218
+ @xml.to_s.gsub( /<to_s\/>/, '' )
219
+ end
220
+ # dumps the chart design to xml for client side consumption
221
+ alias to_xml to_s
222
+
223
+ # =========================================================================
224
+ private
225
+
226
+ # -------------------------------------------------------------------------
227
+ # Inflate object state based on object hierarchy
228
+ def setup_state( state )
229
+ override = self.class.name == state.class.name
230
+ Base.components.each do |comp|
231
+ instance_eval "#{comp}.merge( state.#{comp}, override ) unless state.#{comp}.nil?"
232
+ end
233
+ end
234
+
235
+ # -------------------------------------------------------------------------
236
+ # Load yaml file associated with class if any
237
+ def inflate( clazz, theme, instance=nil )
238
+ class_name = underscore(clazz.to_s.gsub( /Ziya::Charts/, '' )).gsub( /\//, '' )
239
+ class_name += '_chart' unless class_name.match( /.?_chart$/ )
240
+ begin
241
+ file_name = "#{theme}/#{class_name}"
242
+ file_name = "#{theme}/#{instance}" unless instance.nil?
243
+ Ziya.logger.debug ">>> Ziya attempt to load style sheet file '#{file_name}"
244
+ yml = IO.read( "#{file_name}.yml" )
245
+ # Ziya.logger.debug( yml )
246
+ load = YAML::load( erb_render( yml ) )
247
+ Ziya.logger.info ">>> ZiYa [loading styles] -- #{file_name}.yml"
248
+ return load
249
+ rescue SystemCallError => boom
250
+ ; # ignore if no style file...
251
+ rescue => bang
252
+ Ziya.logger.error ">>> ZiYa -- Error encountered loading file `#{file_name} -- #{bang}"
253
+ bang.backtrace.each { |l| Ziya.logger.error( l ) }
254
+ end
255
+ nil
256
+ end
257
+
258
+ # -------------------------------------------------------------------------
259
+ # Parse erb template if any
260
+ def erb_render(fixture_content)
261
+ b = binding
262
+ ERB.new(fixture_content).result b
263
+ end
264
+
265
+ # -------------------------------------------------------------------------
266
+ # Generates xml element for given data set
267
+ # TODO Lame ! Refact...
268
+ def gen_data_points( series_name, labels=nil )
269
+ values = @options[series_name]
270
+ labels.insert( 0, nil ) if labels
271
+ @xml.row do
272
+ if values.respond_to? :each
273
+ values.each do |c|
274
+ if c.nil?
275
+ @xml.null
276
+ elsif c.instance_of? String
277
+ if labels and !labels.empty?
278
+ label = labels.shift
279
+ if label
280
+ @xml.string( :label => label ) { |x| x.text!( c ) }
281
+ else
282
+ @xml.string( c )
283
+ end
284
+ else
285
+ @xml.string( c )
286
+ end
287
+ elsif c.respond_to? :zero?
288
+ if labels and !labels.empty?
289
+ label = labels.shift
290
+ if label
291
+ @xml.number( :label => label ) { |x| x.text!( c.to_s ) }
292
+ else
293
+ @xml.number( c )
294
+ end
295
+ else
296
+ @xml.number( c )
297
+ end
298
+ end
299
+ end
300
+ else
301
+ @xml.string( values )
302
+ end
303
+ end
304
+ end
305
+
306
+ # # -------------------------------------------------------------------------
307
+ # # Generates custom axis values
308
+ # def gen_axis_value_text( values )
309
+ # return if values.nil? or values.empty?
310
+ # @xml.axis_value_text do
311
+ # values.each { |v| @xml.string( v ) }
312
+ # end
313
+ # end
314
+
315
+ # # -------------------------------------------------------------------------
316
+ # # Check if the series are named
317
+ # def named_series?( names )
318
+ # names.each do |name|
319
+ # next unless name.to_s.index( 'series_' )
320
+ # return @options[name][0].instance_of?(String) if @options[name] and !@options[name].empty?
321
+ # end
322
+ # false
323
+ # end
324
+
325
+ # # -------------------------------------------------------------------------
326
+ # # Check if the options have custom labels ie :label_xxx tag
327
+ # def has_labels( names )
328
+ # names.each do |name|
329
+ # next unless name.to_s.index( 'labels_' )
330
+ # return @options[name].size if @options[name] and !@options[name].empty?
331
+ # end
332
+ # 0
333
+ # end
334
+
335
+ # # -------------------------------------------------------------------------
336
+ # # Generates custom labels
337
+ # def gen_labels( series_name, is_default=false )
338
+ # cltn = @options[series_name]
339
+ # cltn.insert( 0, nil ) unless is_default
340
+ # @xml.row do
341
+ # cltn.each { |c| ((c.nil? or c.to_s.empty?) ? @xml.null : @xml.string( c )) }
342
+ # end
343
+ # end
344
+
345
+ # # ------------------------------------------------------------------------
346
+ # # Generates default series labels
347
+ # def gen_default_labels( size )
348
+ # labels = []
349
+ # size.times { |i| labels << nil }
350
+ # @xml.row do
351
+ # labels.each { |c| @xml.null }
352
+ # end
353
+ # end
354
+
355
+ # ------------------------------------------------------------------------
356
+ # generates chart data row
357
+ # TODO Validate options !!
358
+ def gen_row_data( value, opts=nil )
359
+ if value.instance_of? String
360
+ gen_string_data( value, opts )
361
+ elsif value.respond_to? :zero?
362
+ gen_number_data( value, opts )
363
+ end
364
+ end
365
+
366
+ # -------------------------------------------------------------------------
367
+ # generates string chart_value
368
+ def gen_string_data( value, opts )
369
+ if opts
370
+ @xml.string( opts ) { |x| x.text!( value ) }
371
+ else
372
+ @xml.string( value )
373
+ end
374
+ end
375
+
376
+ # -------------------------------------------------------------------------
377
+ # generates number chart_value
378
+ def gen_number_data( value, opts )
379
+ if opts
380
+ @xml.number( opts ) { |x| x.text!( value.to_s ) }
381
+ else
382
+ @xml.number( value )
383
+ end
384
+ end
385
+
386
+ # -------------------------------------------------------------------------
387
+ # generates chart data points
388
+ # BOZO !! Check args on hash
389
+ def gen_chart_data( series )
390
+ @xml.row do
391
+ series.each do |row|
392
+ if row.nil?
393
+ @xml.null
394
+ elsif row.instance_of? Hash
395
+ value = row.delete( :value )
396
+ gen_row_data( value, row )
397
+ else
398
+ gen_row_data( row )
399
+ end
400
+ end
401
+ end
402
+ end
403
+
404
+ # -------------------------------------------------------------------------
405
+ # Lay down graph data points and labels if any
406
+ # TODO Validate series sizes/label sizes
407
+ def setup_series
408
+ raise "You must specify an axis_category_text with your series." if !@series_desc.empty? and ! @options[:axis_category_text]
409
+
410
+ if @options[:axis_category_text]
411
+ @xml.chart_data do
412
+ gen_data_points( :axis_category_text )
413
+ # render xml for each series
414
+ @series_desc.each do |series|
415
+ gen_chart_data( series )
416
+ end
417
+ end
418
+ end
419
+
420
+ # display category labels if any
421
+ if @options[:axis_category_label]
422
+ @xml.axis_category_label do
423
+ @options[:axis_category_label].each do |label|
424
+ label ? @xml.string( label ) : @xml.null
425
+ end
426
+ end
427
+ end
428
+
429
+ # display axis value labels if any
430
+ if @options[:axis_value_label]
431
+ @xml.axis_value_label do
432
+ @options[:axis_value_label].each do |label|
433
+ label ? @xml.string( label ) : @xml.null
434
+ end
435
+ end
436
+ end
437
+
438
+ end
439
+
440
+ # -------------------------------------------------------------------------
441
+ # Walk up class hierarchy to find chart inheritance classes
442
+ def ancestors
443
+ ancestors = self.class.ancestors.reverse
444
+ allow = false
445
+ ancestors.map do |k|
446
+ allow = true if k == Ziya::Charts::Base
447
+ k if allow
448
+ end.compact!
449
+ end
450
+
451
+ # -------------------------------------------------------------------------
452
+ # Check if we should do the all monty or just render the instance styles
453
+ def render_parents?
454
+ (@render_mode == Base.all_styles)
455
+ end
456
+
457
+ # -------------------------------------------------------------------------
458
+ # Load up look and feel data
459
+ def load_lnf
460
+ unless @partial
461
+ ancestors.each do |super_class|
462
+ o = nil
463
+ if ( super_class == self.class )
464
+ # Load class instance prefs
465
+ o = inflate( super_class, theme ) if render_parents?
466
+ setup_state( o ) unless o.nil?
467
+ # Now load instance prefs if any
468
+ unless id.nil?
469
+ o = inflate( super_class, theme, id )
470
+ setup_state( o ) unless o.nil?
471
+ end
472
+ else
473
+ o = inflate( super_class, theme, nil ) if render_parents?
474
+ setup_state( o ) unless o.nil?
475
+ end
476
+ end
477
+ end
478
+ # Additional styles specified ? if so load them
479
+ unless @options[:styles].nil?
480
+ o = YAML::load( erb_render( @options[:styles] ) )
481
+ setup_state( o ) unless o.nil?
482
+ end
483
+ end
484
+
485
+ # -------------------------------------------------------------------------
486
+ # Generates xml for look and feel data
487
+ def setup_lnf
488
+ load_lnf
489
+ unless @partial
490
+ Base.components.each do |comp|
491
+ next unless self.send( comp ).configured? # => Don't include non configured components
492
+ if comp == :draw
493
+ instance_eval "#{comp}.flatten( @xml, @options[:composites] )"
494
+ else
495
+ instance_eval "#{comp}.flatten( @xml )"
496
+ end
497
+ end
498
+ end
499
+ end
500
+
501
+ # -------------------------------------------------------------------------
502
+ def initialize_components
503
+ # Setup instance vars
504
+ Base.components.each do |comp|
505
+ instance_var = lambda { |v| self.instance_eval{ instance_variable_set "@#{comp}", v } }
506
+ instance_var.call(Ziya::Components.const_get(classify(comp)).new)
507
+ end
508
+ end
509
+ end
510
+ end
@@ -0,0 +1,18 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for bubble chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ require 'ziya/charts/base'
7
+
8
+ module Ziya::Charts
9
+ class Bubble < Base
10
+ # Creates a bubble chart
11
+ # <tt>:license</tt>:: the XML/SWF charts license
12
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
13
+ def initialize( license=nil, chart_id=nil )
14
+ super( license, chart_id )
15
+ @type = "bubble"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for candlestick chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class CandleStick < Base
8
+ # Creates a candlestick chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "candlestick"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for a Column chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class Column < Base
8
+ # Creates a column chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "column"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for 3D column chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class ColumnThreed < Base
8
+ # Creates a 3D Column chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "3d column"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for donut chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ require 'ziya/charts/base'
7
+
8
+ module Ziya::Charts
9
+ class Donut < Base
10
+ # Creates a donut chart
11
+ # <tt>:license</tt>:: the XML/SWF charts license
12
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
13
+ def initialize( license=nil, chart_id=nil )
14
+ super( license, chart_id )
15
+ @type = "donut"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for floating bar chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class FloatingBar < Base
8
+ # Creates a floating bar chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "floating bar"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for a floating column chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class FloatingColumn < Base
8
+ # Creates a floating column chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "floating column"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for a line chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class Line < Base
8
+ # Creates a line chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "line"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for mixed chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class Mixed < Base
8
+ # Creates a mixed chart ie comosed of different chart types ie line + column
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = nil
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Generates necessary xml for parallel 3D column chart
3
+ #
4
+ # Author: Fernand
5
+ # -----------------------------------------------------------------------------
6
+ module Ziya::Charts
7
+ class ParallelThreedColumn < Base
8
+ # Creates a parallel column 3D chart
9
+ # <tt>:license</tt>:: the XML/SWF charts license
10
+ # <tt>:chart_id</tt>:: the name of the chart style sheet.
11
+ def initialize( license=nil, chart_id=nil )
12
+ super( license, chart_id )
13
+ @type = "parallel 3d column"
14
+ end
15
+ end
16
+ end