ziya 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/Manifest.txt +74 -28
  2. data/README.txt +91 -14
  3. data/Rakefile +1 -1
  4. data/bin/ziyafy +2 -0
  5. data/charts/AC_RunActiveContent.js +292 -0
  6. data/charts/charts.swf +0 -0
  7. data/charts/charts_library/ar3d.swf +0 -0
  8. data/charts/charts_library/arno.swf +0 -0
  9. data/charts/charts_library/ars3.swf +0 -0
  10. data/charts/charts_library/arst.swf +0 -0
  11. data/charts/charts_library/brfl.swf +0 -0
  12. data/charts/charts_library/brno.swf +0 -0
  13. data/charts/charts_library/brst.swf +0 -0
  14. data/charts/charts_library/buno.swf +0 -0
  15. data/charts/charts_library/cl3d.swf +0 -0
  16. data/charts/charts_library/clfl.swf +0 -0
  17. data/charts/charts_library/clno.swf +0 -0
  18. data/charts/charts_library/clp3.swf +0 -0
  19. data/charts/charts_library/cls3.swf +0 -0
  20. data/charts/charts_library/clst.swf +0 -0
  21. data/charts/charts_library/cnno.swf +0 -0
  22. data/charts/charts_library/lnno.swf +0 -0
  23. data/charts/charts_library/mxno.swf +0 -0
  24. data/charts/charts_library/pi3d.swf +0 -0
  25. data/charts/charts_library/pino.swf +0 -0
  26. data/charts/charts_library/pono.swf +0 -0
  27. data/charts/charts_library/scno.swf +0 -0
  28. data/charts/full_screen.swf +0 -0
  29. data/charts/sliders/black.swf +0 -0
  30. data/charts/sliders/preview_handle_1.swf +0 -0
  31. data/charts/sliders/preview_handle_2.swf +0 -0
  32. data/fred.rb +36 -0
  33. data/gauges/designs/circle.yml +18 -0
  34. data/gauges/designs/signal.yml +14 -0
  35. data/gauges/designs/thermo.yml +119 -0
  36. data/gauges/designs/title.yml +11 -0
  37. data/gauges/gauge.swf +0 -0
  38. data/lib/ziya.rb +17 -5
  39. data/lib/ziya/charts/area.rb +6 -1
  40. data/lib/ziya/charts/area_threed.rb +16 -0
  41. data/lib/ziya/charts/bar.rb +8 -3
  42. data/lib/ziya/charts/base.rb +210 -153
  43. data/lib/ziya/charts/bubble.rb +18 -0
  44. data/lib/ziya/charts/candle_stick.rb +6 -1
  45. data/lib/ziya/charts/column.rb +7 -2
  46. data/lib/ziya/charts/column_threed.rb +6 -1
  47. data/lib/ziya/charts/floating_bar.rb +6 -1
  48. data/lib/ziya/charts/floating_column.rb +7 -2
  49. data/lib/ziya/charts/line.rb +7 -2
  50. data/lib/ziya/charts/mixed.rb +5 -0
  51. data/lib/ziya/charts/parallel_threed_column.rb +6 -1
  52. data/lib/ziya/charts/pie.rb +7 -2
  53. data/lib/ziya/charts/pie_threed.rb +7 -2
  54. data/lib/ziya/charts/polar.rb +6 -1
  55. data/lib/ziya/charts/scatter.rb +6 -1
  56. data/lib/ziya/charts/stacked_area.rb +5 -0
  57. data/lib/ziya/charts/stacked_bar.rb +5 -0
  58. data/lib/ziya/charts/stacked_column.rb +7 -2
  59. data/lib/ziya/charts/stacked_threed_area.rb +16 -0
  60. data/lib/ziya/charts/stacked_threed_column.rb +6 -1
  61. data/lib/ziya/components/area.rb +5 -2
  62. data/lib/ziya/components/axis_category.rb +8 -60
  63. data/lib/ziya/components/axis_ticks.rb +25 -27
  64. data/lib/ziya/components/axis_value.rb +5 -48
  65. data/lib/ziya/components/base.rb +59 -17
  66. data/lib/ziya/components/bevel.rb +15 -0
  67. data/lib/ziya/components/blur.rb +13 -0
  68. data/lib/ziya/components/chart_border.rb +4 -23
  69. data/lib/ziya/components/chart_grid_h.rb +17 -19
  70. data/lib/ziya/components/chart_grid_v.rb +18 -19
  71. data/lib/ziya/components/chart_guide.rb +16 -0
  72. data/lib/ziya/components/chart_label.rb +16 -0
  73. data/lib/ziya/components/chart_pref.rb +12 -12
  74. data/lib/ziya/components/chart_rect.rb +27 -26
  75. data/lib/ziya/components/chart_transition.rb +15 -16
  76. data/lib/ziya/components/circle.rb +5 -2
  77. data/lib/ziya/components/draw.rb +12 -11
  78. data/lib/ziya/components/draw_base.rb +10 -0
  79. data/lib/ziya/components/filter.rb +26 -0
  80. data/lib/ziya/components/glow.rb +14 -0
  81. data/lib/ziya/components/image.rb +5 -1
  82. data/lib/ziya/components/legend.rb +18 -0
  83. data/lib/ziya/components/line.rb +6 -2
  84. data/lib/ziya/components/link.rb +9 -9
  85. data/lib/ziya/components/link_data.rb +9 -10
  86. data/lib/ziya/components/rect.rb +7 -2
  87. data/lib/ziya/components/scroll.rb +26 -0
  88. data/lib/ziya/components/shadow.rb +14 -0
  89. data/lib/ziya/components/text.rb +5 -1
  90. data/lib/ziya/components/update.rb +19 -0
  91. data/lib/ziya/gauges/base.rb +172 -0
  92. data/lib/ziya/gauges/radial.rb +18 -0
  93. data/lib/ziya/gauges/signal.rb +138 -0
  94. data/lib/ziya/gauges/support/area.rb +13 -0
  95. data/lib/ziya/gauges/support/base.rb +33 -0
  96. data/lib/ziya/gauges/support/circle.rb +14 -0
  97. data/lib/ziya/gauges/support/design.rb +5 -0
  98. data/lib/ziya/gauges/support/image.rb +12 -0
  99. data/lib/ziya/gauges/support/line.rb +12 -0
  100. data/lib/ziya/gauges/support/link.rb +24 -0
  101. data/lib/ziya/gauges/support/move.rb +15 -0
  102. data/lib/ziya/gauges/support/point.rb +12 -0
  103. data/lib/ziya/gauges/support/polygon.rb +13 -0
  104. data/lib/ziya/gauges/support/radial_base.rb +21 -0
  105. data/lib/ziya/gauges/support/radial_numbers.rb +41 -0
  106. data/lib/ziya/gauges/support/radial_ticks.rb +29 -0
  107. data/lib/ziya/gauges/support/rect.rb +14 -0
  108. data/lib/ziya/gauges/support/rotate.rb +15 -0
  109. data/lib/ziya/gauges/support/scale.rb +15 -0
  110. data/lib/ziya/gauges/support/text.rb +21 -0
  111. data/lib/ziya/gauges/support/update.rb +12 -0
  112. data/lib/ziya/gauges/thermo.rb +121 -0
  113. data/lib/ziya/helpers/base_helper.rb +39 -6
  114. data/lib/ziya/utils/text.rb +6 -0
  115. data/lib/ziya/version.rb +1 -1
  116. data/lib/ziya/ziya_helper.rb +289 -62
  117. data/spec/charts/base_spec.rb +35 -21
  118. data/spec/charts/chart_type_spec.rb +24 -3
  119. data/spec/components/area_spec.rb +9 -2
  120. data/spec/components/draw_spec.rb +1 -2
  121. data/spec/components/filter_spec.rb +27 -0
  122. data/spec/components/link_spec.rb +1 -2
  123. data/spec/components/series_color_spec.rb +1 -2
  124. data/spec/components/series_explode_spec.rb +1 -2
  125. data/spec/components/series_switch_spec.rb +1 -2
  126. data/spec/designs/circle.yml +7 -0
  127. data/spec/designs/crapping_out.yml +8 -0
  128. data/spec/designs/gauge_1.yml +43 -0
  129. data/spec/designs/gauge_2.yml +11 -0
  130. data/spec/designs/gauge_no_name.yml +43 -0
  131. data/spec/designs/gauge_raw.yml +5 -0
  132. data/spec/designs/thermo.yml +13 -0
  133. data/spec/gauges/base_spec.rb +90 -0
  134. data/spec/gauges/signal_spec.rb +36 -0
  135. data/spec/gauges/support/area_spec.rb +40 -0
  136. data/spec/gauges/support/circle_spec.rb +78 -0
  137. data/spec/gauges/support/image_spec.rb +35 -0
  138. data/spec/gauges/support/line_spec.rb +34 -0
  139. data/spec/gauges/support/link_spec.rb +35 -0
  140. data/spec/gauges/support/move_spec.rb +45 -0
  141. data/spec/gauges/support/polygon_spec.rb +36 -0
  142. data/spec/gauges/support/radial_numbers_spec.rb +35 -0
  143. data/spec/gauges/support/radial_ticks_spec.rb +30 -0
  144. data/spec/gauges/support/rotate_spec.rb +45 -0
  145. data/spec/gauges/support/scale_spec.rb +46 -0
  146. data/spec/gauges/support/text_spec.rb +40 -0
  147. data/spec/gauges/thermo_spec.rb +49 -0
  148. data/spec/helpers/base_helper_spec.rb +20 -6
  149. data/spec/spec_helper.rb +4 -1
  150. data/spec/test_helpers/gauge_2_helper.rb +17 -0
  151. data/spec/utils/logger_spec.rb +1 -3
  152. data/spec/utils/text_spec.rb +1 -2
  153. data/spec/ziya_helper_spec.rb +88 -11
  154. data/spec/ziya_spec.rb +1 -1
  155. data/tasks/gem.rake +1 -1
  156. metadata +79 -32
  157. data/charts/themes/commando/bar_chart.yml +0 -9
  158. data/charts/themes/commando/base_chart.yml +0 -65
  159. data/charts/themes/commando/column_chart.yml +0 -13
  160. data/charts/themes/commando/column_threed_chart.yml +0 -25
  161. data/charts/themes/commando/parallel_threed_column_chart.yml +0 -17
  162. data/charts/themes/commando/pie_chart.yml +0 -22
  163. data/charts/themes/commando/pie_threed_chart.yml +0 -28
  164. data/charts/themes/commando/polar_chart.yml +0 -11
  165. data/charts/themes/commando/stacked_bar_chart.yml +0 -9
  166. data/charts/themes/commando/stacked_column_chart.yml +0 -14
  167. data/charts/themes/commando/stacked_threed_column_chart.yml +0 -17
  168. data/charts/themes/default/bar_chart.yml +0 -3
  169. data/charts/themes/default/base_chart.yml +0 -67
  170. data/charts/themes/default/column_chart.yml +0 -13
  171. data/charts/themes/default/column_threed_chart.yml +0 -25
  172. data/charts/themes/default/parallel_threed_column_chart.yml +0 -17
  173. data/charts/themes/default/pie_chart.yml +0 -29
  174. data/charts/themes/default/pie_threed_chart.yml +0 -28
  175. data/charts/themes/default/polar_chart.yml +0 -12
  176. data/charts/themes/default/stacked_bar_chart.yml +0 -3
  177. data/charts/themes/default/stacked_column_chart.yml +0 -14
  178. data/charts/themes/default/stacked_threed_column_chart.yml +0 -17
  179. data/charts/themes/default/test.yml +0 -4
  180. data/lib/ziya/components/chart_value.rb +0 -71
  181. data/lib/ziya/components/legend_label.rb +0 -18
  182. data/lib/ziya/components/legend_rect.rb +0 -19
  183. data/lib/ziya/components/legend_transition.rb +0 -18
  184. data/lib/ziya/components/live_update.rb +0 -21
@@ -0,0 +1,15 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Create an animation to scale a component
3
+ #
4
+ # Author:: Fernand Galiana
5
+ # -----------------------------------------------------------------------------
6
+ require 'ziya/gauges/support/base'
7
+
8
+ module Ziya::Gauges::Support
9
+ class Scale < Base
10
+ has_attribute :x, :y, :start_scale, :end_scale, :step, :direction,
11
+ :shake_span, :shake_frequency, :shake_snap,
12
+ :shadow_alpha, :shadow_x_offset, :shadow_y_offset,
13
+ :components
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Draws text for a gauge
3
+ #
4
+ # Author:: Fernand Galiana
5
+ # -----------------------------------------------------------------------------
6
+ require 'ziya/gauges/support/base'
7
+
8
+ module Ziya::Gauges::Support
9
+ class Text < Base
10
+ has_attribute :x, :y, :width, :height, :rotation, :font, :bold, :size, :align,
11
+ :color, :alpha, :text
12
+
13
+ def flatten( xml )
14
+ opts = options
15
+ txt = opts.delete( :text )
16
+ xml.text( opts ) do
17
+ xml.text! txt.to_s
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Draws a rectangle for a gauge
3
+ #
4
+ # Author:: Fernand Galiana
5
+ # -----------------------------------------------------------------------------
6
+ require 'ziya/gauges/support/base'
7
+
8
+ module Ziya::Gauges::Support
9
+ class Update < Base
10
+ has_attribute :url, :delay, :delay_type, :stop_sound, :retry, :timeout
11
+ end
12
+ end
@@ -0,0 +1,121 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Thermometer gauge
3
+ #
4
+ # TODO Need to figure out ordering different than alpha
5
+ #
6
+ # Author: Fernand
7
+ # -----------------------------------------------------------------------------
8
+ module Ziya::Gauges
9
+ class Thermo < Base
10
+
11
+ # creates a thermometer gauge.
12
+ # <tt>license</tt> the xml/swf gauge license key
13
+ # <tt>design_id</tt> the name of the design file containing components
14
+ # to override default design.
15
+ def initialize( license, design_id="thermo" )
16
+ super( license, design_id )
17
+ end
18
+
19
+ # -----------------------------------------------------------------------
20
+ # provides for overiding basic functionality
21
+ #
22
+ # <tt>title</tt>:: String representing gauge title or null for none.
23
+ # <tt>gauge_color</tt>:: Legend color
24
+ # <tt>legend_color</tt>:: Gauge color
25
+ # <tt>due_point</tt>:: Set temperature level
26
+ def set_preferences( opts={} )
27
+ super( opts )
28
+ options[:end_scale] = normalize_and_scale( options[:due_point] )
29
+ end
30
+
31
+ # =========================================================================
32
+ protected
33
+
34
+ # -------------------------------------------------------------------------
35
+ # setup thermometer default options
36
+ def default_options
37
+ {
38
+ :x => 20,
39
+ :y => 20,
40
+ :due_point => 40,
41
+ :gauge_color => "ff0000",
42
+ :legend_color => "cc0000",
43
+ :title => "weather"
44
+ }
45
+ end
46
+
47
+ # =========================================================================
48
+ private
49
+
50
+ # -----------------------------------------------------------------------
51
+ # converts temp is F to a %
52
+ def normalize_and_scale( due_point )
53
+ return 100 if due_point > 120
54
+ return 0 if due_point < 20
55
+ due_point - 20
56
+ end
57
+
58
+ # -----------------------------------------------------------------------
59
+ # draws farenheit scale
60
+ def draw_farenheit_scale( start_temp, end_temp )
61
+ i = start_temp
62
+ buff = []
63
+ count = 0
64
+ x = options[:x] + 60
65
+ y = options[:y] + 153
66
+ while( i <= end_temp ) do
67
+ line = Ziya::Gauges::Support::Line.new(
68
+ :x1 => x,
69
+ :y1 => y-i,
70
+ :x2 => x+8,
71
+ :y2 => y-i,
72
+ :thickness => 2 )
73
+ buff << "#{indent}#{line.to_comp_yaml( "linef_#{count}", 2 )}"
74
+ text = Ziya::Gauges::Support::Text.new(
75
+ :x => x+8,
76
+ :y => (y-8)-i,
77
+ :width => 100,
78
+ :align => 'left',
79
+ :size => 10,
80
+ :color => 'aaaaaa',
81
+ :text => i.to_s )
82
+ buff << "#{indent}#{text.to_comp_yaml( "textf_#{count}", 2 )}"
83
+ i += 20
84
+ count += 1
85
+ end
86
+ buff.join( "\n" )
87
+ end
88
+
89
+ # -----------------------------------------------------------------------
90
+ # draws celsius scale
91
+ def draw_celsius_scale( start_temp, end_temp )
92
+ i = start_temp
93
+ ratio = 1.7
94
+ buff = []
95
+ count = 0
96
+ x = options[:x] + 10
97
+ y = options[:y] + 118
98
+ while( i <= end_temp ) do
99
+ line = Ziya::Gauges::Support::Line.new(
100
+ :x1 => x,
101
+ :y1 => y-(i*ratio),
102
+ :x2 => x+8,
103
+ :y2 => y-(i*ratio),
104
+ :thickness => 2 )
105
+ buff << "#{indent}#{line.to_comp_yaml( "linec_#{count}", 2 )}"
106
+ text = Ziya::Gauges::Support::Text.new(
107
+ :x => x - 20,
108
+ :y => (y-8)-(i*ratio),
109
+ :width => 20,
110
+ :align => 'right',
111
+ :size => 10,
112
+ :color => 'aaaaaa',
113
+ :text => i.to_s )
114
+ buff << "#{indent}#{text.to_comp_yaml( "text_c_#{count}", 2 )}"
115
+ i += 10
116
+ count += 1
117
+ end
118
+ buff.join( "\n" )
119
+ end
120
+ end
121
+ end
@@ -1,11 +1,42 @@
1
1
  require "ziya/utils/text"
2
+ require "ziya/ziya_helper"
2
3
 
3
4
  module Ziya::Helpers
4
5
  module BaseHelper
5
- include Ziya::Utils::Text
6
+ include Ziya::Utils::Text, Ziya::Helper
7
+
8
+ # -------------------------------------------------------------------------
9
+ # generates a swf chart path from the given url. Used as helper to embed
10
+ # chart
11
+ def chart_url( url, swf_chart_dir="/charts" )
12
+ gen_composite_path( swf_chart_dir, url )
13
+ end
14
+
15
+ # -------------------------------------------------------------------------
16
+ # indent yaml content vy multiples of 2 spaces
17
+ def indent( multiple= 1 )
18
+ " " * multiple
19
+ end
20
+
21
+ # -------------------------------------------------------------------------
22
+ # YAML Convenience for gauge class
23
+ def gauge( class_name )
24
+ "--- #{clazz( class_name, 'Gauges' )}\n#{dials}"
25
+ end
6
26
 
7
- # =========================================================================
8
- # TODO Move to helper
27
+ # -------------------------------------------------------------------------
28
+ # YAML Convenience for gauge component declaration
29
+ def dial( comp_class, comp_name=nil )
30
+ clazz = clazz( comp_class, "Gauges::Support" )
31
+ comp_name ? "- :#{comp_name}: #{clazz}" : "- #{clazz}"
32
+ end
33
+
34
+ # -------------------------------------------------------------------------
35
+ # YAML dials declaration
36
+ def dials
37
+ "components: !omap"
38
+ end
39
+
9
40
  # -------------------------------------------------------------------------
10
41
  # YAML Convenience for component declaration
11
42
  def component( component_name )
@@ -18,19 +49,21 @@ module Ziya::Helpers
18
49
  def drawing( class_name )
19
50
  clazz( class_name, :Components )
20
51
  end
21
-
52
+ alias_method :filter_type, :drawing
53
+ alias_method :area , :drawing
54
+
22
55
  # -------------------------------------------------------------------------
23
56
  # YAML Convenience for chart class
24
57
  def chart( class_name )
25
58
  "--- #{clazz( class_name, :Charts )}"
26
59
  end
27
-
60
+
28
61
  # -------------------------------------------------------------------------
29
62
  # YAML Convenience for chart name setting
30
63
  def clazz( class_name, module_name=nil )
31
64
  buff = "!ruby/object:Ziya::"
32
65
  buff << "#{module_name}::" unless module_name.nil?
33
- buff << "#{camelize(class_name.to_s)}\n"
66
+ buff << "#{camelize(class_name.to_s)}"
34
67
  buff
35
68
  end
36
69
  end
@@ -29,5 +29,11 @@ module Ziya::Utils
29
29
  def classify(string)
30
30
  camelize(string.to_s.sub(/.*\./, ''))
31
31
  end
32
+
33
+ # strip out module name and return bare class name
34
+ def demodulize( clazz )
35
+ clazz.gsub( /^.*::/, '' )
36
+ end
37
+
32
38
  end
33
39
  end
@@ -1,6 +1,6 @@
1
1
  module Ziya
2
2
  module Version
3
- MAJOR = 1
3
+ MAJOR = 2
4
4
  MINOR = 0
5
5
  TINY = 0
6
6
 
@@ -10,84 +10,311 @@ require 'erb'
10
10
 
11
11
  module Ziya
12
12
  module Helper
13
- # const accessor...
14
- def xml_swf() "%s/charts.swf?library_path=%s/charts_library&xml_source=%s"; end
15
13
 
14
+ # -------------------------------------------------------------------------
15
+ # generates a javascript tag to include the js script to create object and
16
+ # embed tags
17
+ def ziya_javascript_include_tag
18
+ js = <<-JS
19
+ <script language="javascript" type="text/javascript">
20
+ AC_FL_RunContent = 0;
21
+ DetectFlashVer = 0;
22
+ </script>
23
+ <script src="/charts/AC_RunActiveContent.js" language="javascript"></script>
24
+ <script language="javascript" type="text/javascript">
25
+ var requiredMajorVersion = 9;
26
+ var requiredMinorVersion = 0;
27
+ var requiredRevision = 45;
28
+ </script>
29
+ JS
30
+ end
31
+
32
+ # generates necessary object and embed tags to display a flash movie on various
33
+ # browsers using javascript
34
+ def ziya_chart_js( url, chart_options={} )
35
+ options = { :width => "400",
36
+ :height => "300",
37
+ :bgcolor => "000000",
38
+ :wmode => "opaque",
39
+ :menu => true,
40
+ :full_screen => true,
41
+ :align => "l",
42
+ :salign => "tl",
43
+ :scale => "noscale",
44
+ :use_cache => false,
45
+ :timeout => nil,
46
+ :retry => 2,
47
+ :use_stage => false,
48
+ :id => "ziya_chart",
49
+ :swf_path => chart_path,
50
+ }.merge!(chart_options)
51
+
52
+ # Setup options for opaque mode
53
+ setup_wmode( options )
54
+
55
+ # setup width and height
56
+ setup_movie_size( options )
57
+
58
+ xml_swf_path = charts_swf % [options[:swf_path], escape_url(url)]
59
+ xml_swf_path << "&timestamp=#{Time.now.to_i}" if options[:cache] == false
60
+ xml_swf_path << "&timeout=#{options[:timeout]}&retry=#{options[:retry]}" if options[:timeout]
61
+ xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
62
+
63
+ js = <<-JS
64
+ <script language="javascript" type="text/javascript">
65
+ if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
66
+ alert( "This page requires AC_RunActiveContent.js." );
67
+ }
68
+ else {
69
+ var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
70
+ if( hasRightVersion ) {
71
+ AC_FL_RunContent(
72
+ 'codebase' , 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
73
+ 'width' , '#{options[:width]}',
74
+ 'height' , '#{options[:height]}',
75
+ 'scale' , '#{options[:scale]}',
76
+ 'salign' , '#{options[:salign]}',
77
+ 'bgcolor' , '#{options[:bgcolor]}',
78
+ 'wmode' , '#{options[:wmode]}',
79
+ 'movie' , '#{options[:swf_path]}/charts',
80
+ 'src' , '#{options[:swf_path]}/charts',
81
+ 'FlashVars' , '#{xml_swf_path}',
82
+ 'id' , '#{options[:id]}',
83
+ 'name' , '#{options[:id]}',
84
+ 'menu' , '#{options[:menu]}',
85
+ 'allowFullScreen' , '#{options[:full_screen]}',
86
+ 'allowScriptAccess','sameDomain',
87
+ 'quality' , 'high',
88
+ 'align' , '#{options[:align]}',
89
+ 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer',
90
+ 'play' , 'true',
91
+ 'devicefont' , 'false'
92
+ );
93
+ }
94
+ else {
95
+ var alternateContent = 'This content requires the Adobe Flash Player. '
96
+ + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
97
+ document.write(alternateContent);
98
+ }
99
+ }
100
+ </script>
101
+ JS
102
+ end
103
+
104
+ # -------------------------------------------------------------------------
105
+ # generates necessary html tags to display a gauge.
106
+ def ziya_gauge( url, gauge_options={} )
107
+ options = { :width => "200",
108
+ :height => "200",
109
+ :align => "middle",
110
+ :scale => "noscale",
111
+ :salign => "",
112
+ :class => "",
113
+ :id => "ziya_gauge",
114
+ :swf_path => gauge_path,
115
+ :use_cache => false,
116
+ :timeout => false,
117
+ :retry => 2,
118
+ :use_stage => false
119
+ }.merge!(gauge_options)
120
+
121
+ generate_old_style_flash_tag( url, gauges_swf, options )
122
+ end
123
+
16
124
  # -------------------------------------------------------------------------------------
17
- # Generates chart object tag with given url to fetch the xml data
18
- # -------------------------------------------------------------------------------------
125
+ # generates neccessary html tags to display a chart.
19
126
  def ziya_chart( url, chart_options = {} )
20
127
  options = { :width => "400",
21
128
  :height => "300",
22
- :align => "left",
23
- :class => "",
129
+ :tag_type => "embed",
130
+ :align => "l",
131
+ :salign => "tl",
132
+ :scale => "noscale",
133
+ :class => "",
24
134
  :id => "ziya_chart",
25
135
  :swf_path => chart_path,
26
- :cache => false,
136
+ :use_cache => false,
27
137
  :timeout => nil,
28
- :use_stage => true,
29
- :style => ""
138
+ :use_stage => false
30
139
  }.merge!(chart_options)
140
+
141
+ generate_flash_tag( url, charts_swf, "charts.swf", options )
142
+ end
143
+
144
+ # flash chart library path
145
+ def gen_composite_path( swf_chart_dir, url )
146
+ composite_url % [swf_chart_dir, swf_chart_dir, escape_url( url )]
147
+ end
148
+
149
+ # =========================================================================
150
+ # private
31
151
 
32
- # Escape url
33
- url = CGI.escape( url.gsub( /&amp;/, '&' ) )
152
+ # Const accessors...
153
+ def mime() "application/x-shockwave-flash"; end
154
+ def composite_url() "%s/charts.swf?library_path=%s/charts_library&xml_source=%s" end
155
+ def charts_swf() "library_path=%s/charts_library&xml_source=%s"; end
156
+ def plugin_url() "http://www.macromedia.com/go/getflashplayer"; end
157
+ def gauges_swf() "%s/gauge.swf?xml_source=%s"; end
158
+ def gauge_path() "/gauges"; end
159
+ def chart_path() "/charts"; end
160
+ def class_id() "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" end
161
+ def codebase() "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0"; end
34
162
 
35
- # Set the wmode to opaque if a bgcolor is specified. If not set to
36
- # transparent mode unless user overrides it
37
- if options[:bgcolor]
38
- options[:wmode] = "opaque" unless options[:wmode]
39
- else
40
- options[:wmode] = "transparent" unless options[:wmode]
41
- options[:bgcolor] = "#FFFFFF"
163
+ # generates swf path
164
+ def gen_swf_path( path_directive, swf_dir, url )
165
+ path_directive % [swf_dir, escape_url( url )]
42
166
  end
43
- color_param = tag( 'param', {:name => 'bgcolor', :value => options[:bgcolor]}, true )
44
- color_param += tag( 'param', {:name => "wmode", :value => options[:wmode]}, true )
45
167
 
46
- # Check args for size option (Submitted by Sam Livingston-Gray)
47
- if options[:size] =~ /(\d+)x(\d+)/
48
- options[:width] = $1
49
- options[:height] = $2
50
- options.delete :size
168
+ def generate_old_style_flash_tag( url, swf_path, options )
169
+ # Setup options for opaque mode
170
+ setup_wmode( options )
171
+
172
+ # setup width and height
173
+ setup_movie_size( options )
174
+
175
+ color_param = tag( 'param', {:name => 'bgcolor', :value => options[:bgcolor]}, true )
176
+ color_param += tag( 'param', {:name => "wmode", :value => options[:wmode]}, true )
177
+
178
+ xml_swf_path = swf_path % [options[:swf_path], url]
179
+ xml_swf_path << "&timestamp=#{Time.now.to_i}" if options[:use_cache] == true
180
+ xml_swf_path << "&timeout=#{options[:timeout]}&retry=#{options[:retry]}" if options[:timeout] == true
181
+ xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
182
+ tags = <<-TAGS
183
+ <object codebase="#{codebase}" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="#{options[:id]}" height="#{options[:height]}" width="#{options[:width]}">
184
+ <param name="scale" value="noscale">
185
+ <param name="align" value="#{options[:align]}">
186
+ <param name="bgcolor" value="#{options[:bgcolor]}">
187
+ <param name="wmode" value="#{options[:wmode]}">
188
+ <param name="movie" value="#{xml_swf_path}">
189
+ <param name="menu" value="true">
190
+ <param name="allowFullScreen" value="true">
191
+ <param name="allowScriptAccess" value="sameDomain">
192
+ <param name="quality" value="high">
193
+ <param name="play" value="true">
194
+ <param name="devicefont" value="false">
195
+ <embed scale="noscale"
196
+ allowfullscreen="true"
197
+ allowscriptaccess="sameDomain"
198
+ bgcolor="#{options[:bgcolor]}"
199
+ devicefont="false"
200
+ src="#{xml_swf_path}"
201
+ menu="true"
202
+ name="#{options[:id]}"
203
+ play="true"
204
+ pluginspage="http://www.macromedia.com/go/getflashplayer"
205
+ quality="high"
206
+ salign="#{options[:salign]}"
207
+ src="#{xml_swf_path}"
208
+ type="application/x-shockwave-flash"
209
+ wmode="#{options[:wmode]}"
210
+ salign="#{options[:salign]}"
211
+ height="#{options[:height]}"
212
+ width="#{options[:width]}">
213
+ </object>
214
+ TAGS
215
+ end
216
+
217
+ # generated the object and embed tag necessary for the flash movie
218
+ def generate_flash_tag( url, swf_path, swf_file, options )
219
+ # Setup options for opaque mode
220
+ setup_wmode( options )
221
+
222
+ # setup width and height
223
+ setup_movie_size( options )
224
+
225
+ color_param = tag( 'param', {:name => 'bgcolor', :value => options[:bgcolor]}, true )
226
+ color_param += tag( 'param', {:name => "wmode", :value => options[:wmode]}, true )
227
+
228
+ xml_swf_path = gen_swf_path( swf_path, options[:swf_path], url )
229
+ xml_swf_path << "&timestamp=#{Time.now.to_i}" if options[:cache] == false
230
+ xml_swf_path << "&timeout=#{options[:timeout]}" if options[:timeout]
231
+ xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
232
+
233
+ # if options[:tag_type] == "object"
234
+ tags = <<-TAGS
235
+ <object codebase="#{codebase}" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="#{options[:id]}" height="#{options[:height]}" width="#{options[:width]}">
236
+ <param name="scale" value="noscale">
237
+ <param name="salign" value="#{options[:salign]}">
238
+ <param name="bgcolor" value="#{options[:bgcolor]}">
239
+ <param name="wmode" value="#{options[:wmode]}">
240
+ <param name="movie" value="#{options[:swf_path]}/#{swf_file}">
241
+ <param name="FlashVars" value="#{xml_swf_path}&chart_id=#{options[:id]}">
242
+ <param name="menu" value="true">
243
+ <param name="allowFullScreen" value="true">
244
+ <param name="allowScriptAccess" value="sameDomain">
245
+ <param name="quality" value="high">
246
+ <param name="play" value="true">
247
+ <param name="devicefont" value="false">
248
+ <embed scale="noscale"
249
+ allowfullscreen="true"
250
+ allowscriptaccess="sameDomain"
251
+ bgcolor="#{options[:bgcolor]}"
252
+ devicefont="false"
253
+ flashvars="#{xml_swf_path}"
254
+ menu="true"
255
+ name="#{options[:id]}"
256
+ play="true"
257
+ pluginspage="http://www.macromedia.com/go/getflashplayer"
258
+ quality="high"
259
+ salign="#{options[:salign]}"
260
+ src="#{options[:swf_path]}/#{swf_file}"
261
+ type="application/x-shockwave-flash"
262
+ wmode="#{options[:wmode]}"
263
+ align="#{options[:align]}"
264
+ height="#{options[:height]}"
265
+ width="#{options[:width]}"/>
266
+ </object>
267
+ TAGS
268
+ # else
269
+ # tags = <<-TAGS
270
+ # <embed scale="noscale"
271
+ # allowfullscreen="true"
272
+ # allowscriptaccess="sameDomain"
273
+ # bgcolor="#{options[:bgcolor]}"
274
+ # devicefont="false"
275
+ # flashvars="#{xml_swf_path}"
276
+ # menu="true"
277
+ # name="#{options[:id]}"
278
+ # play="true"
279
+ # pluginspage="http://www.macromedia.com/go/getflashplayer"
280
+ # quality="high"
281
+ # salign="#{options[:salign]}"
282
+ # src="#{options[:swf_path]}/#{swf_file}"
283
+ # type="application/x-shockwave-flash"
284
+ # wmode="#{options[:wmode]}"
285
+ # align="#{options[:align]}"
286
+ # height="#{options[:height]}"
287
+ # width="#{options[:width]}"/>
288
+ # TAGS
289
+ # end
290
+ tags
291
+ end
292
+
293
+ # escape url
294
+ def escape_url( url )
295
+ CGI.escape( url.gsub( /&amp;/, '&' ) )
51
296
  end
52
-
53
- xml_swf_path = xml_swf % [options[:swf_path], options[:swf_path], url ]
54
- xml_swf_path << "&timestamp=#{Time.now.to_i}" if options[:cache] == false
55
- xml_swf_path << "&timeout=#{options[:timeout]}" if options[:timeout]
56
- xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true
57
- content_tag( 'object',
58
- tag( 'param',
59
- {:name => "movie",
60
- :value => xml_swf_path}, true ) +
61
- tag( 'param',
62
- {:name => "quality",
63
- :value => "high"}, true ) +
64
- content_tag( 'embed', nil,
65
- :src => xml_swf_path,
66
- :quality => 'high',
67
- :bgcolor => options[:bgcolor],
68
- :wmode => options[:wmode],
69
- :width => options[:width],
70
- :height => options[:height],
71
- :name => options[:id],
72
- :swLiveConnect => "true",
73
- :type => "application/x-shockwave-flash",
74
- :pluginspage => "http://www.macromedia.com/go/getflashplayer") +
75
- color_param,
76
- :classid => class_id,
77
- :codebase => codebase,
78
- :data => xml_swf_path,
79
- :style => options[:style],
80
- :width => options[:width], :height => options[:height],
81
- :stage_width => options[:width], :stage_height => options[:height], :id => options[:id] )
82
- end
83
297
 
84
- # =========================================================================
85
- private
298
+ # setup up wmode
299
+ # Set the wmode to opaque if a bgcolor is specified. If not set to
300
+ # transparent mode unless user overrides it
301
+ def setup_wmode( options )
302
+ if options[:bgcolor]
303
+ options[:wmode] = "opaque" unless options[:wmode]
304
+ else
305
+ options[:wmode] = "transparent" unless options[:wmode]
306
+ options[:bgcolor] = "#FFFFFF"
307
+ end
308
+ end
86
309
 
87
- # Const accessors...
88
- def chart_path() "/charts"; end
89
- def class_id() "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" end
90
- def codebase() "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"; end
310
+ # Check args for size option in the format wXy (Submitted by Sam Livingston-Gray)
311
+ def setup_movie_size( options )
312
+ if options[:size] =~ /(\d+)x(\d+)/
313
+ options[:width] = $1
314
+ options[:height] = $2
315
+ options.delete :size
316
+ end
317
+ end
91
318
 
92
319
  # All this stolen form rails to make Ziya work with other fmks....
93
320
  def tag(name, options = nil, open = false, escape = true)