Class: SVG::Graph::Pie Deprecated

Inherits:
Graph
  • Object
show all
Defined in:
lib/SVG/Graph/Pie.rb

Overview

Deprecated.

Removed at 4.0.0

Create presentation quality SVG pie graphs easily

Synopsis

require 'SVG/Graph/Pie'

fields = %w(Jan Feb Mar)
data_sales_02 = [12, 45, 21]

graph = SVG::Graph::Pie.new({
	:height => 500,

:width => 300, :fields => fields,

})

graph.add_data({
	:data => data_sales_02,

:title => 'Sales 2002',

})

print "Content-type: image/svg+xml\r\n\r\n"
print graph.burn();

Description

This object aims to allow you to easily create high quality SVG pie graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, display percent on pie chart, title, subtitle etc.

Examples

www.germane-software/repositories/public/SVG/test/single.rb

See also

  • SVG::Graph::Graph

  • SVG::Graph::BarHorizontal

  • SVG::Graph::Bar

  • SVG::Graph::Line

  • SVG::Graph::Plot

  • SVG::Graph::TimeSeries

Author

Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>

Copyright 2004 Sean E. Russell This software is available under the Ruby license

Since:

  • 0.5.0

Instance Attribute Summary collapse

Attributes inherited from Graph

#add_popups, #font_size, #graph_subtitle, #graph_title, #height, #key, #key_font_size, #key_position, #min_scale_value, #no_css, #rotate_x_labels, #rotate_y_labels, #scale_divisions, #scale_integers, #show_data_values, #show_graph_subtitle, #show_graph_title, #show_x_guidelines, #show_x_labels, #show_x_title, #show_y_guidelines, #show_y_labels, #show_y_title, #stagger_x_labels, #stagger_y_labels, #step_include_first_x_label, #step_x_labels, #style_sheet, #subtitle_font_size, #title_font_size, #width, #x_label_font_size, #x_title, #x_title_font_size, #y_label_font_size, #y_title, #y_title_font_size, #y_title_text_direction

Instance Method Summary collapse

Methods inherited from Graph

#burn, #clear_data, #initialize

Constructor Details

This class inherits a constructor from SVG::Graph::Graph

Instance Attribute Details

#datapoint_font_sizeObject

The font size of the data point labels



142
143
144
# File 'lib/SVG/Graph/Pie.rb', line 142

def datapoint_font_size
  @datapoint_font_size
end

#expand_gapObject

The amount of space between expanded wedges



140
141
142
# File 'lib/SVG/Graph/Pie.rb', line 140

def expand_gap
  @expand_gap
end

#expand_greatestObject

If true, expand the largest pie wedge



138
139
140
# File 'lib/SVG/Graph/Pie.rb', line 138

def expand_greatest
  @expand_greatest
end

#expandedObject

If true, “explode” the pie (put space between the wedges)



136
137
138
# File 'lib/SVG/Graph/Pie.rb', line 136

def expanded
  @expanded
end

#shadow_offsetObject

Sets the offset of the shadow from the pie chart



121
122
123
# File 'lib/SVG/Graph/Pie.rb', line 121

def shadow_offset
  @shadow_offset
end

#show_actual_valuesObject

If true, display the actual field values in the data labels



125
126
127
# File 'lib/SVG/Graph/Pie.rb', line 125

def show_actual_values
  @show_actual_values
end

#show_data_labelsObject

If true, display the data labels on the chart



123
124
125
# File 'lib/SVG/Graph/Pie.rb', line 123

def show_data_labels
  @show_data_labels
end

#show_key_actual_valuesObject

If true, display the actual value of the field in the key



132
133
134
# File 'lib/SVG/Graph/Pie.rb', line 132

def show_key_actual_values
  @show_key_actual_values
end

#show_key_data_labelsObject

If true, display the labels in the key



130
131
132
# File 'lib/SVG/Graph/Pie.rb', line 130

def show_key_data_labels
  @show_key_data_labels
end

#show_key_percentObject

If true, display the percentage value of the wedges in the key



134
135
136
# File 'lib/SVG/Graph/Pie.rb', line 134

def show_key_percent
  @show_key_percent
end

#show_percentObject

If true, display the percentage value of each pie wedge in the data labels



128
129
130
# File 'lib/SVG/Graph/Pie.rb', line 128

def show_percent
  @show_percent
end

#show_shadowObject

If true, displays a drop shadow for the chart



119
120
121
# File 'lib/SVG/Graph/Pie.rb', line 119

def show_shadow
  @show_shadow
end

Instance Method Details

#add_data(arg) ⇒ Object

Adds a data set to the graph.

graph.add_data( { :data => [1,2,3,4] } )

Note that the :title is not necessary. If multiple data sets are added to the graph, the pie chart will display the sums of the data. EG:

graph.add_data( { :data => [1,2,3,4] } )
graph.add_data( { :data => [2,3,5,9] } )

is the same as:

graph.add_data( { :data => [3,5,8,13] } )


111
112
113
114
115
116
# File 'lib/SVG/Graph/Pie.rb', line 111

def add_data arg
  arg[:data].each_index {|idx|
    @data[idx] = 0 unless @data[idx]
    @data[idx] += arg[:data][idx]
  }
end

#set_defaultsObject

Defaults are those set by Graph::initialize, and

show_shadow

true

shadow_offset

10

show_data_labels

false

show_actual_values

false

show_percent

true

show_key_data_labels

true

show_key_actual_values

true

show_key_percent

false

expanded

false

expand_greatest

false

expand_gap

10

show_x_labels

false

show_y_labels

false

datapoint_font_size

12



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/SVG/Graph/Pie.rb', line 73

def set_defaults
  init_with(
    :show_shadow		        => true,
    :shadow_offset	        => 10, 
    
    :show_data_labels	      => false,
    :show_actual_values     => false,
    :show_percent		        => true,

    :show_key_data_labels	  => true,
    :show_key_actual_values => true,
    :show_key_percent		    => false,
    
    :expanded				        => false,
    :expand_greatest		    => false,
    :expand_gap             => 10,
    
    :show_x_labels          => false,
    :show_y_labels          => false,
    :datapoint_font_size    => 12
  )
  @data = []
end