Parent

Class Index

Quicksearch

Ziya::Maps::Base

Protected Class Methods

map_types() click to toggle source

===================================================================

    # File lib/ziya/maps/base.rb, line 18
18:       def self.map_types
19:         @map_types ||= [ 
20:           :australia, 
21:           :belgium, 
22:           :brazil, 
23:           :canada, 
24:           :europe, 
25:           :france, 
26:           :germany, 
27:           :italy, 
28:           :mexico, 
29:           :sweden, 
30:           :uk_ireland, 
31:           :us, 
32:           :us_canada, 
33:           :world ]
34:       end

Public Instance Methods

add( *args ) click to toggle source

Add chart components to a given chart.

The args must contain certain keys for the chart to be displayed correctly.

Directives

  • :series — Specifies the data points for the map. This must be a hash of region, data pairs. Where the data is also a hash of attributes such as :name, :data, :hover, :url and :target.
  • :range_colors — Specifies the map of ranges of data values from the series to a color on the map. The range may be an exact value such as 10 or an actual range in the form of 1 - 10. The color must be an hexadecimal value of the form ‘ff00ff’.
  • :point_colors — Specifies a map of valid color ranges to color the points on the map. Valid key/value pairs are a number or range for the key and an associated color.
  • :arc_colors — Specifies a map of valid color ranges to color the arcs on the map. Valid key/value pairs are a number or range for the key and an associated color.
  • :line_colors — Specifies a map of valid color ranges to color the lines on the map. Valid key/value pairs are a number or range for the key and an associated color.
  • :lines — Specifies a map of lines to plot on the map. These are key/value pairs. The value represent the name of the line to be displayed. The value is a hash of attributes as follows: :start, the geocode location of the point, :stop, the geocode location of the arc to end at :stroke, the thickness of the line and :data for the range value of the arc.
  • :arcs — Specifies a map of arcs to plot on the map. These are key/value pairs. The value represent the name of the arc to be displayed. The value is a hash of attributes as follows: :start, the geocode location of the point, :stop, the geocode location of the arc to end at and :data for the range value of the arc.
  • :points — Specifies a map of points to plot on the map. These are key/value pairs. The value represent the name of the point to be displayed. The value is a hash of attributes as follows: :loc for the geocode location of the point and :data for the range value of the point.
  • :theme — Specify the use of a given named theme. The named theme must reside in a directory named equaly under your application public/charts/themes.

Examples

Colorize colorado and california on a US map

  my_map.add( :series, { :CO => { :name => "Colorado", :data => 1 }, :CA => { :name => "California", :data => 2 } )

     # File lib/ziya/maps/base.rb, line 161
161:     def add( *args )
162:       # TODO Validation categories = series, series = labels, etc...
163:       directive = args.shift
164:       case directive
165:         when :series
166:           if args.first.is_a?( Hash )
167:             points = args.shift || {}
168:             raise ArgumentError, "Must specify an hash of data points" if points.empty?
169:             @series = points
170:           else
171:             raise ArgumentError, "Must specify an hash of data points"
172:           end
173:         when :range_colors
174:           @range_colors = args.shift || {}
175:           raise ArgumentError, "You must specify a hash of data range/color pairs" if @range_colors.empty?          
176:         when :lines
177:           @lines = args.shift || {}
178:           raise ArgumentError, "You must specify a hash of lines attributes" if @lines.empty?
179:         when :line_colors
180:           @line_colors = args.shift || {}
181:           raise ArgumentError, "You must specify a hash of line range/color pairs" if @line_colors.empty?          
182:         when :arcs
183:           @arcs = args.shift || {}
184:           raise ArgumentError, "You must specify a hash of arcs attributes" if @arcs.empty?
185:         when :arc_colors
186:           @arc_colors = args.shift || {}
187:           raise ArgumentError, "You must specify a hash of arc range/color pairs" if @arc_colors.empty?          
188:         when :points
189:           @points = args.shift || {}
190:           raise ArgumentError, "You must specify a hash of points attributes" if @points.empty?
191:         when :point_colors
192:           @point_colors = args.shift || {}
193:           raise ArgumentError, "You must specify a hash of point range/color pairs" if @point_colors.empty?
194:         when :user_data
195:           key = args.first.is_a?(Symbol) ? args.shift : ""
196:           raise ArgumentError, "Must specify a key" if key.to_s.empty?
197:           value = args.shift
198:           # raise ArgumentError, "Must specify a value" if value.empty?
199:           @options[key] = value
200:         when :theme
201:           theme = args.first.is_a?(String) ? args.shift : ""
202:           raise ArgumentError, "Must specify a theme name" if theme.to_s.empty?          
203:           @theme = "#{Ziya.map_themes_dir}/#{theme}"
204:         else raise ArgumentError, "Invalid directive must be one of " + 
205:                                  ":series, :theme, :user_data"
206:       end 
207:     end
to_s() click to toggle source

spews the map specification to a string

     # File lib/ziya/maps/base.rb, line 210
210:     def to_s
211:       @xml = Builder::XmlMarkup.new
212:       # Forces utf8 encoding on xml stream
213:       @xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"    
214:       if map_type == :us
215:         @xml.us_states do
216:           setup_lnf
217:           setup_series
218:         end
219:       else
220:         @xml.countrydata do
221:           setup_lnf
222:           setup_series
223:         end         
224:       end
225:       @xml.to_s.gsub( /<to_s\/>/, '' )
226:     end
Also aliased as: to_xml
to_xml() click to toggle source

Alias for #to_s

secsequence

--- SEC00200

seccomment

--- ""

method_list

--- 
- methods: 
  - visibility: protected
    aref: M000028
    name: map_types
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/ziya/maps/base.rb, line 18</span>\n\
      18:       <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">map_types</span>\n\
      19:         <span class=\"ruby-ivar\">@map_types</span> <span class=\"ruby-operator\">||=</span> [ \n\
      20:           <span class=\"ruby-identifier\">:australia</span>, \n\
      21:           <span class=\"ruby-identifier\">:belgium</span>, \n\
      22:           <span class=\"ruby-identifier\">:brazil</span>, \n\
      23:           <span class=\"ruby-identifier\">:canada</span>, \n\
      24:           <span class=\"ruby-identifier\">:europe</span>, \n\
      25:           <span class=\"ruby-identifier\">:france</span>, \n\
      26:           <span class=\"ruby-identifier\">:germany</span>, \n\
      27:           <span class=\"ruby-identifier\">:italy</span>, \n\
      28:           <span class=\"ruby-identifier\">:mexico</span>, \n\
      29:           <span class=\"ruby-identifier\">:sweden</span>, \n\
      30:           <span class=\"ruby-identifier\">:uk_ireland</span>, \n\
      31:           <span class=\"ruby-identifier\">:us</span>, \n\
      32:           <span class=\"ruby-identifier\">:us_canada</span>, \n\
      33:           <span class=\"ruby-identifier\">:world</span> ]\n\
      34:       <span class=\"ruby-keyword kw\">end</span>"
    m_desc: <h6>===================================================================</h6>
    params: ()
  category: Class
  type: Protected
- methods: 
  - visibility: public
    aref: M000029
    name: add
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/ziya/maps/base.rb, line 161</span>\n\
      161:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">add</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">args</span> )\n\
      162:       <span class=\"ruby-comment cmt\"># TODO Validation categories = series, series = labels, etc...</span>\n\
      163:       <span class=\"ruby-identifier\">directive</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span>\n\
      164:       <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">directive</span>\n\
      165:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:series</span>\n\
      166:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">first</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">Hash</span> )\n\
      167:             <span class=\"ruby-identifier\">points</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      168:             <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;Must specify an hash of data points&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">points</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      169:             <span class=\"ruby-ivar\">@series</span> = <span class=\"ruby-identifier\">points</span>\n\
      170:           <span class=\"ruby-keyword kw\">else</span>\n\
      171:             <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;Must specify an hash of data points&quot;</span>\n\
      172:           <span class=\"ruby-keyword kw\">end</span>\n\
      173:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:range_colors</span>\n\
      174:           <span class=\"ruby-ivar\">@range_colors</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      175:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of data range/color pairs&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@range_colors</span>.<span class=\"ruby-identifier\">empty?</span>          \n\
      176:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:lines</span>\n\
      177:           <span class=\"ruby-ivar\">@lines</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      178:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of lines attributes&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@lines</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      179:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:line_colors</span>\n\
      180:           <span class=\"ruby-ivar\">@line_colors</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      181:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of line range/color pairs&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@line_colors</span>.<span class=\"ruby-identifier\">empty?</span>          \n\
      182:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:arcs</span>\n\
      183:           <span class=\"ruby-ivar\">@arcs</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      184:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of arcs attributes&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@arcs</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      185:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:arc_colors</span>\n\
      186:           <span class=\"ruby-ivar\">@arc_colors</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      187:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of arc range/color pairs&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@arc_colors</span>.<span class=\"ruby-identifier\">empty?</span>          \n\
      188:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:points</span>\n\
      189:           <span class=\"ruby-ivar\">@points</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      190:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of points attributes&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@points</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      191:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:point_colors</span>\n\
      192:           <span class=\"ruby-ivar\">@point_colors</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">||</span> {}\n\
      193:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;You must specify a hash of point range/color pairs&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@point_colors</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      194:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:user_data</span>\n\
      195:           <span class=\"ruby-identifier\">key</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">first</span>.<span class=\"ruby-identifier\">is_a?</span>(<span class=\"ruby-constant\">Symbol</span>) <span class=\"ruby-operator\">?</span> <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-value str\">&quot;&quot;</span>\n\
      196:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;Must specify a key&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">key</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      197:           <span class=\"ruby-identifier\">value</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span>\n\
      198:           <span class=\"ruby-comment cmt\"># raise ArgumentError, &quot;Must specify a value&quot; if value.empty?</span>\n\
      199:           <span class=\"ruby-ivar\">@options</span>[<span class=\"ruby-identifier\">key</span>] = <span class=\"ruby-identifier\">value</span>\n\
      200:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:theme</span>\n\
      201:           <span class=\"ruby-identifier\">theme</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">first</span>.<span class=\"ruby-identifier\">is_a?</span>(<span class=\"ruby-constant\">String</span>) <span class=\"ruby-operator\">?</span> <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-value str\">&quot;&quot;</span>\n\
      202:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;Must specify a theme name&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">theme</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">empty?</span>          \n\
      203:           <span class=\"ruby-ivar\">@theme</span> = <span class=\"ruby-node\">&quot;#{Ziya.map_themes_dir}/#{theme}&quot;</span>\n\
      204:         <span class=\"ruby-keyword kw\">else</span> <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">&quot;Invalid directive must be one of &quot;</span> <span class=\"ruby-operator\">+</span> \n\
      205:                                  <span class=\"ruby-value str\">&quot;:series, :theme, :user_data&quot;</span>\n\
      206:       <span class=\"ruby-keyword kw\">end</span> \n\
      207:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Add chart components to a given chart.
      </p>
      <p>
      The <tt>args</tt> must contain certain keys for the chart to be displayed
      correctly.
      </p>
      <h3>Directives</h3>
      <ul>
      <li><tt>:series</tt> &#8212; Specifies the data points for the map. This must
      be a hash of region, data pairs. Where the data is also a hash of
      attributes such as :name, :data, :hover, :url and :target.
      
      </li>
      <li><tt>:range_colors</tt> &#8212; Specifies the map of ranges of data values
      from the series to a color on the map. The range may be an exact value such
      as 10 or an actual range in the form of 1 - 10. The color must be an
      hexadecimal value of the form &#8216;ff00ff&#8217;.
      
      </li>
      <li><tt>:point_colors</tt> &#8212; Specifies a map of valid color ranges to
      color the points on the map. Valid key/value pairs are a number or range
      for the key and an associated color.
      
      </li>
      <li><tt>:arc_colors</tt> &#8212; Specifies a map of valid color ranges to color
      the arcs on the map. Valid key/value pairs are a number or range for the
      key and an associated color.
      
      </li>
      <li><tt>:line_colors</tt> &#8212; Specifies a map of valid color ranges to
      color the lines on the map. Valid key/value pairs are a number or range for
      the key and an associated color.
      
      </li>
      <li><tt>:lines</tt> &#8212; Specifies a map of lines to plot on the map. These
      are key/value pairs. The value represent the name of the line to be
      displayed. The value is a hash of attributes as follows: :start, the
      geocode location of the point, :stop, the geocode location of the arc to
      end at :stroke, the thickness of the line and :data for the range value of
      the arc.
      
      </li>
      <li><tt>:arcs</tt> &#8212; Specifies a map of arcs to plot on the map. These
      are key/value pairs. The value represent the name of the arc to be
      displayed. The value is a hash of attributes as follows: :start, the
      geocode location of the point, :stop, the geocode location of the arc to
      end at and :data for the range value of the arc.
      
      </li>
      <li><tt>:points</tt> &#8212; Specifies a map of points to plot on the map.
      These are key/value pairs. The value represent the name of the point to be
      displayed. The value is a hash of attributes as follows: :loc for the
      geocode location of the point and :data for the range value of the point.
      
      </li>
      <li><tt>:theme</tt> &#8212; Specify the use of a given named theme. The named
      theme must reside in a directory named equaly under your application
      public/charts/themes.
      
      </li>
      </ul>
      <h3>Examples</h3>
      <p>
      Colorize colorado and california on a US map
      </p>
      <pre>
        my_map.add( :series, { :CO =&gt; { :name =&gt; &quot;Colorado&quot;, :data =&gt; 1 }, :CA =&gt; { :name =&gt; &quot;California&quot;, :data =&gt; 2 } )
      </pre>
    params: ( *args )
  - visibility: public
    aref: M000030
    name: to_s
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/ziya/maps/base.rb, line 210</span>\n\
      210:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_s</span>\n\
      211:       <span class=\"ruby-ivar\">@xml</span> = <span class=\"ruby-constant\">Builder</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">XmlMarkup</span>.<span class=\"ruby-identifier\">new</span>\n\
      212:       <span class=\"ruby-comment cmt\"># Forces utf8 encoding on xml stream</span>\n\
      213:       <span class=\"ruby-ivar\">@xml</span>.<span class=\"ruby-identifier\">instruct!</span> <span class=\"ruby-identifier\">:xml</span>, <span class=\"ruby-identifier\">:version</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-value str\">&quot;1.0&quot;</span>, <span class=\"ruby-identifier\">:encoding</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-value str\">&quot;UTF-8&quot;</span>    \n\
      214:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">map_type</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">:us</span>\n\
      215:         <span class=\"ruby-ivar\">@xml</span>.<span class=\"ruby-identifier\">us_states</span> <span class=\"ruby-keyword kw\">do</span>\n\
      216:           <span class=\"ruby-identifier\">setup_lnf</span>\n\
      217:           <span class=\"ruby-identifier\">setup_series</span>\n\
      218:         <span class=\"ruby-keyword kw\">end</span>\n\
      219:       <span class=\"ruby-keyword kw\">else</span>\n\
      220:         <span class=\"ruby-ivar\">@xml</span>.<span class=\"ruby-identifier\">countrydata</span> <span class=\"ruby-keyword kw\">do</span>\n\
      221:           <span class=\"ruby-identifier\">setup_lnf</span>\n\
      222:           <span class=\"ruby-identifier\">setup_series</span>\n\
      223:         <span class=\"ruby-keyword kw\">end</span>         \n\
      224:       <span class=\"ruby-keyword kw\">end</span>\n\
      225:       <span class=\"ruby-ivar\">@xml</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">gsub</span>( <span class=\"ruby-regexp re\">/&lt;to_s\\/&gt;/</span>, <span class=\"ruby-value str\">''</span> )\n\
      226:     <span class=\"ruby-keyword kw\">end</span>"
    aka: 
    - aref: Base.html#M000031
      name: to_xml
    m_desc: |-
      <p>
      spews the map specification to a string
      </p>
    params: ()
  - visibility: public
    aref: M000031
    name: to_xml
    m_desc: |-
      <p>
      Alias for <a href="Base.html#M000030">#to_s</a>
      </p>
    params: ()
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.