Skip to content

Commit

Permalink
Cleanup trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
cgriego committed Apr 21, 2010
1 parent ac15b5a commit b4a5f8f
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions lib/gchart.rb
Expand Up @@ -10,7 +10,7 @@ class Gchart
include GchartInfo

def self.url
"http://chart.apis.google.com/chart?"
"http://chart.apis.google.com/chart?"
end

def self.types
Expand All @@ -19,7 +19,7 @@ def self.types

def self.simple_chars
@simple_chars ||= ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
end
end

def self.chars
@chars ||= simple_chars + ['-', '.']
Expand All @@ -37,16 +37,16 @@ def self.default_filename
:title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass,
:range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors

attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines
attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines

attr_accessor :min_value, :max_value

types.each do |type|
instance_eval <<-DYNCLASSMETH
def #{type}(options = {})
# Start with theme defaults if a theme is set
theme = options[:theme]
options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options
options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options
# # Extract the format and optional filename, then clean the hash
format = options[:format] || 'url'
options[:filename] ||= default_filename
Expand Down Expand Up @@ -85,12 +85,12 @@ def initialize(options={})
# Sets the CSS class selector when chart is exported as image tag
@klass = options[:class] || false
# set the options value if definable
options.each do |attribute, value|
options.each do |attribute, value|
send("#{attribute}=", value) if self.respond_to?("#{attribute}=")
end
end


def self.supported_types
self.class.types.join(' ')
end
Expand All @@ -100,15 +100,15 @@ def self.supported_types
def size=(size='300x200')
@width, @height = size.split("x").map { |dimension| dimension.to_i }
end

def size=(size='300x200')
@width, @height = size.split("x").map { |dimension| dimension.to_i }
end

def size
"#{width}x#{height}"
end

def dimensions
# TODO: maybe others?
[:line_xy, :scatter].include?(type) ? 2 : 1
Expand Down Expand Up @@ -147,7 +147,7 @@ def graph_bg=(options)
@chart_angle = options[:angle]
end
end

def max_value=(max_v)
if max_v =~ /false/
@max_value = false
Expand All @@ -172,14 +172,14 @@ def full_data_range(ds)
ds.each_with_index do |mds, mds_index|
mds[:min_value] ||= min_value
mds[:max_value] ||= max_value

if mds_index == 0 && type.to_s == 'bar'
# TODO: unless you specify a zero line (using chp or chds),
# the min_value of a bar chart is always 0.
#mds[:min_value] ||= mds[:data].first.to_a.compact.min
mds[:min_value] ||= 0
end
if (mds_index == 0 && type.to_s == 'bar' &&
if (mds_index == 0 && type.to_s == 'bar' &&
!grouped && mds[:data].first.is_a?(Array))
totals = []
mds[:data].each do |l|
Expand Down Expand Up @@ -214,26 +214,26 @@ def full_data_range(ds)
end
# return [min, max] unless (min.nil? || max.nil?)
# @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value
#
# if min_value.nil?
#
# if min_value.nil?
# min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0
# @min = (min_ds_value < 0) ? min_ds_value : 0
# else
# @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value
# @min = min_value == 'auto' ? ds.compact.map{|mds| mds.compact.min}.min || 0 : min_value
# end
# @axis_range = [[min,max]]
end

def dataset
if @dataset
@dataset
@dataset
else
@dataset = convert_dataset(data || [])
full_data_range(@dataset) # unless axis_range
@dataset
end
end

# Sets of data to handle multiple sets
def datasets
datasets = []
Expand All @@ -246,12 +246,12 @@ def datasets
end
datasets
end

def self.jstize(string)
# See discussion: http://github.com/mattetti/googlecharts/commit/9b5cfb93aa51aae06611057668e631cd515ec4f3#comment_51347
string.gsub(' ', '+').gsub(/\[|\{|\}|\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"}
# string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s.upcase}"}
end
end
# load all the custom aliases
require 'gchart/aliases'

Expand All @@ -275,8 +275,8 @@ def write

def image_tag
image = "<img"
image += " id=\"#{id}\"" if id
image += " class=\"#{klass}\"" if klass
image += " id=\"#{id}\"" if id
image += " class=\"#{klass}\"" if klass
image += " src=\"#{url_builder(:html)}\""
image += " width=\"#{width}\""
image += " height=\"#{height}\""
Expand All @@ -303,7 +303,7 @@ def jstize(string)
private

# The title size cannot be set without specifying a color.
# A dark key will be used for the title color if no color is specified
# A dark key will be used for the title color if no color is specified
def set_title
title_params = "chtt=#{title}"
unless (title_color.nil? && title_size.nil? )
Expand All @@ -325,7 +325,7 @@ def set_colors
@bg_type = fill_type(bg_type) || 's' if bg_color
@chart_type = fill_type(chart_type) || 's' if chart_color

"chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|')
"chf=" + {'bg' => fill_for(bg_type, bg_color, bg_angle), 'c' => fill_for(chart_type, chart_color, chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|')
end

# set bar, line colors
Expand Down Expand Up @@ -373,11 +373,11 @@ def set_range_markers

def set_range_marker(options)
orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r'
"#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}"
"#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}"
end

def fill_for(type=nil, color='', angle=nil)
unless type.nil?
unless type.nil?
case type
when 'lg'
angle ||= 0
Expand All @@ -393,7 +393,7 @@ def fill_for(type=nil, color='', angle=nil)
end
end

# A chart can have one or many legends.
# A chart can have one or many legends.
# Gchart.line(:legend => 'label')
# or
# Gchart.line(:legend => ['first label', 'last label'])
Expand All @@ -411,15 +411,15 @@ def set_legend
def set_line_thickness
"chls=#{thickness}"
end

def set_line_markers
"chm=#{new_markers}"
end

def set_grid_lines
"chg=#{grid_lines}"
end

def set_labels
if legend.is_a?(Array)
"chl=#{@legend.map{|label| "#{CGI::escape(label.to_s)}"}.join('|')}"
Expand Down Expand Up @@ -451,7 +451,7 @@ def set_axis_labels
end
end
count = labels_arr.length

"chxl=#{labels_arr.join('|')}"
end

Expand All @@ -460,7 +460,7 @@ def set_axis_labels
def set_axis_range
# a passed axis_range should look like:
# [[10,100]] or [[10,100,4]] or [[10,100], [20,300]]
# in the second example, 4 is the interval
# in the second example, 4 is the interval
if @calculated_axis_range
set = datasets
else
Expand Down Expand Up @@ -516,7 +516,7 @@ def fill_type(type)
'ls'
end
end

def number_visible
n = 0
dataset.each do |mds|
Expand All @@ -529,7 +529,7 @@ def number_visible
end
""
end

# Turns input into an array of axis hashes, dependent on the chart type
def convert_dataset(ds)
if dimensions == 2
Expand All @@ -549,7 +549,7 @@ def convert_dataset(ds)
end
ds
end

# just an alias
def axis_set
dataset
Expand All @@ -563,7 +563,7 @@ def convert_to_simple_value(number)
value.nil? ? "_" : value
end
end

def convert_to_extended_value(number)
if number.nil?
'__'
Expand All @@ -572,7 +572,7 @@ def convert_to_extended_value(number)
value.nil? ? "__" : value
end
end

def encode_scaled_dataset(chars, nil_char)
dsets = []
dataset.each do |ds|
Expand Down Expand Up @@ -603,7 +603,7 @@ def encode_scaled_dataset(chars, nil_char)
end

# http://code.google.com/apis/chart/#simple
# Simple encoding has a resolution of 62 different values.
# Simple encoding has a resolution of 62 different values.
# Allowing five pixels per data point, this is sufficient for line and bar charts up
# to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
def simple_encoding
Expand All @@ -628,7 +628,7 @@ def text_encoding
end

# http://code.google.com/apis/chart/#extended
# Extended encoding has a resolution of 4,096 different values
# Extended encoding has a resolution of 4,096 different values
# and is best used for large charts where a large data range is required.
def extended_encoding
"e" + number_visible + ":" + encode_scaled_dataset(self.class.ext_pairs, '__')
Expand All @@ -642,8 +642,8 @@ def query_builder(options="")
query_params = instance_variables.sort.map do |var|
case var.to_s
when '@data'
set_data unless data == []
# Set the graph size
set_data unless data == []
# Set the graph size
when '@width'
set_size unless width.nil? || height.nil?
when '@type'
Expand Down

0 comments on commit b4a5f8f

Please sign in to comment.