Module: Ziya::HtmlHelpers::Charts

Includes:
Base
Included in:
Charts::Base, Charts::Support::Draw, YamlHelpers::Charts
Defined in:
lib/ziya/html_helpers/charts.rb

Overview

Generates necessary html flash tag to support ZiYa

TODO – Rewrite to use content tag block instead…

Author: Fernand Galiana

Instance Method Summary collapse

Methods included from Base

#escape_chars, #escape_once, #escape_url, #mime, #plugin_url, #setup_movie_size, #setup_wmode, #tag_options, #ziya_tag

Instance Method Details

#_ziya_chart(url, swf_path, swf_file, options) ⇒ Object

generated the object and embed tag necessary for the flash movie



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ziya/html_helpers/charts.rb', line 152

def _ziya_chart( url, swf_path, swf_file, options )
  # Setup options for opaque mode
  setup_wmode( options )      
  
  # setup width and height
  setup_movie_size( options )
  
  color_param  = ziya_tag( 'param', {:name => 'bgcolor', :value => options[:bgcolor]}, true )
  color_param += ziya_tag( 'param', {:name  => "wmode", :value => options[:wmode]}, true )

  xml_swf_path = gen_swf_path( swf_path, options[:swf_path], url )
  xml_swf_path << "&amp;timestamp=#{Time.now.to_i}" if options[:cache] == false
  xml_swf_path << "&amp;timeout=#{options[:timeout]}" if options[:timeout]
  xml_swf_path << "&amp;stage_width=#{options[:width]}&amp;stage_height=#{options[:height]}" if options[:use_stage] == true 
  
  tags = <<-TAGS
  <object codebase="#{codebase}" classid="#{class_id}" id="#{options[:id]}" height="#{options[:height]}" width="#{options[:width]}">
    <param name="scale"             value="noscale"/>
    <param name="salign"            value="#{options[:salign]}"/>            
    <param name="bgcolor"           value="#{options[:bgcolor]}"/>
    <param name="wmode"             value="#{options[:wmode]}"/>                                  
    <param name="movie"             value="#{options[:asset_url]}/#{swf_file}"/>
    <param name="Flashvars"         value="#{xml_swf_path}&amp;chart_id=#{options[:id]}"/>
    <param name="menu"              value="true"/>
    <param name="allowFullScreen"   value="true"/>
    <param name="allowScriptAccess" value="#{options[:script_access]}"/>            
    <param name="quality"           value="high"/>
    <param name="play"              value="true"/>                        
    <param name="devicefont"        value="false"/>
      <embed scale="noscale" 
        allowfullscreen   = "true" 
        allowscriptaccess = "#{options[:script_access]}" 
        bgcolor           = "#{options[:bgcolor]}" 
        devicefont        = "false" 
        flashvars         = "#{xml_swf_path}&amp;chart_id=#{options[:id]}" 
        menu              = "true" 
        name              = "#{options[:id]}" 
        play              = "true" 
        pluginspage       = "#{plugin_url}" 
        quality           = "high" 
        salign            = "#{options[:salign]}" 
        src               = "#{options[:asset_url]}/#{swf_file}" 
        type              = "#{mime}" 
        wmode             = "#{options[:wmode]}" 
        align             = "#{options[:align]}" 
        height            = "#{options[:height]}" 
        width             = "#{options[:width]}"/>            
   </object>        
  TAGS
end

#chart_pathObject



142
# File 'lib/ziya/html_helpers/charts.rb', line 142

def chart_path()         "/charts"; end

#charts_swfObject



141
# File 'lib/ziya/html_helpers/charts.rb', line 141

def charts_swf()         "#{charts_swf_base}&xml_source=%s"; end

#charts_swf_baseObject



140
# File 'lib/ziya/html_helpers/charts.rb', line 140

def charts_swf_base()    "library_path=%s/charts_library"; end

#class_idObject



143
# File 'lib/ziya/html_helpers/charts.rb', line 143

def class_id()           "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" end

#codebaseObject



144
# File 'lib/ziya/html_helpers/charts.rb', line 144

def codebase()           "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2"; end

#composite_base_urlObject

Const accessors…



138
# File 'lib/ziya/html_helpers/charts.rb', line 138

def composite_base_url() "%s/charts.swf?library_path=%s/charts_library" end

#composite_urlObject



139
# File 'lib/ziya/html_helpers/charts.rb', line 139

def composite_url()      "#{composite_base_url}&xml_source=%s" end

#default_chart_optionsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ziya/html_helpers/charts.rb', line 32

def default_chart_options
  { 
    :width          => "400",
    :height         => "300",
    :bgcolor        => "ffffff",
    :wmode          => "opaque",
    :menu           => true,
    :full_screen    => true,
    :align          => "l",
    :salign         => "tl",
    :scale          => "noscale",
    :use_cache      => false,
    :timeout        => nil,
    :retry          => 2,
    :use_stage      => false,                  
    :id             => "ziya_chart",
    :swf_path       => chart_path,
    :asset_url      => chart_path
  }
end

#gen_composite_path(swf_chart_dir, url, chart_id = null) ⇒ Object

genereates composite chart urls



123
124
125
126
127
128
129
130
131
132
# File 'lib/ziya/html_helpers/charts.rb', line 123

def gen_composite_path( swf_chart_dir, url, chart_id=null )
  buff = ""
  if url
    buff = composite_url % [swf_chart_dir, swf_chart_dir, escape_url( url )] 
  else
    buff = composite_base_url % [swf_chart_dir, "/charts" ]
  end
  buff << "&chart_id=#{chart_id}" if chart_id
  buff
end

#gen_swf_path(path_directive, swf_dir, url) ⇒ Object

generates swf path



147
148
149
# File 'lib/ziya/html_helpers/charts.rb', line 147

def gen_swf_path( path_directive, swf_dir, url )
  path_directive % [swf_dir, escape_url( url )]        
end

#ziya_chart(url, chart_options = {}) ⇒ Object

generates neccessary html tags to display a chart.



113
114
115
116
117
118
119
120
# File 'lib/ziya/html_helpers/charts.rb', line 113

def ziya_chart( url, chart_options = {} )
  options = default_chart_options.merge( chart_options )

  flash_vars = url ? charts_swf : charts_swf_base
  buff       = _ziya_chart( url, flash_vars, "charts.swf", options )
       
  (respond_to? :raw) ? raw( buff ) : buff     
end

#ziya_chart_js(url, chart_options = {}) ⇒ Object

generates necessary object and embed tags to display a flash movie on various browsers using javascript



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ziya/html_helpers/charts.rb', line 55

def ziya_chart_js( url, chart_options={} )
  options = default_chart_options.merge( chart_options )

  # Setup options for opaque mode
  setup_wmode( options )      
  
  # setup width and height
  setup_movie_size( options )
  
  flash_vars   = url ? charts_swf : charts_swf_base
  xml_swf_path = flash_vars % [options[:swf_path], escape_url(url)]
  xml_swf_path << "&chart_id=#{options[:id]}"
  xml_swf_path << "&timestamp=#{Time.now.to_i}" if options[:cache] == false
  xml_swf_path << "&timeout=#{options[:timeout]}&retry=#{options[:retry]}" if options[:timeout]
  xml_swf_path << "&stage_width=#{options[:width]}&stage_height=#{options[:height]}" if options[:use_stage] == true 
  
  js = <<-JS
    <script language="javascript" type="text/javascript">
    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
      alert( "This page requires AC_RunActiveContent.js." );
    } 
    else {
      var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
      if( hasRightVersion ) { 
        AC_FL_RunContent(
          'codebase'         , 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',
          'width'            , '#{options[:width]}',
          'height'           , '#{options[:height]}',
          'scale'            , '#{options[:scale]}',
          'salign'           , '#{options[:salign]}',
          'bgcolor'          , '#{options[:bgcolor]}',
          'wmode'            , '#{options[:wmode]}',
          'movie'            , '#{options[:swf_path]}/charts',
          'src'              , '#{options[:swf_path]}/charts',
          'FlashVars'        , '#{xml_swf_path}', 
          'id'               , '#{options[:id]}',
          'name'             , '#{options[:id]}',
          'menu'             , '#{options[:menu]}',
          'allowFullScreen'  , '#{options[:full_screen]}',
          'allowScriptAccess','sameDomain',
          'quality'          , 'high',
          'align'            , '#{options[:align]}',
          'pluginspage'      , 'http://www.macromedia.com/go/getflashplayer',
          'play'             , 'true',
          'devicefont'       , 'false'
        ); 
      } 
      else { 
        var alternateContent = 'This content requires the Adobe Flash Player. '
        + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
        document.write(alternateContent); 
      }
    }
    </script>
  JS
end

#ziya_javascript_include_tag(opts = {}) ⇒ Object

generates a javascript tag to include the js script to create object and embed tags



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ziya/html_helpers/charts.rb', line 12

def ziya_javascript_include_tag( opts={} )
  options = { :swf_path   => chart_path,
              :major_vers => 9,
              :minor_vers => 0,
              :req_vers   => 45 }.merge!( opts )
  
  js = <<-JS
    <script language="javascript" type="text/javascript">
      AC_FL_RunContent = 0;
      DetectFlashVer = 0;
    </script>
    <script src="#{options[:swf_path]}/AC_RunActiveContent.js" language="javascript"></script>
    <script language="javascript" type="text/javascript">
      var requiredMajorVersion = #{options[:major_vers]};
      var requiredMinorVersion = #{options[:minor_vers]};
      var requiredRevision = #{options[:req_vers]};
    </script>
   JS
end