Update SVG library to latest stable (0.6.1) (#3056).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2642 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-03-30 19:58:17 +00:00
parent 8d6d9a80d2
commit c9c269abf7
7 changed files with 2550 additions and 2519 deletions

View File

@ -96,37 +96,48 @@ module SVG
end
def draw_data
fieldwidth = field_width
maxvalue = max_value
minvalue = min_value
fieldwidth = field_width
fieldheight = (@graph_height.to_f - font_size*2*top_font) /
unit_size = (@graph_height.to_f - font_size*2*top_font) /
(get_y_labels.max - get_y_labels.min)
bargap = bar_gap ? (fieldwidth < 10 ? fieldwidth / 2 : 10) : 0
subbar_width = fieldwidth - bargap
subbar_width /= @data.length if stack == :side
x_mod = (@graph_width-bargap)/2 - (stack==:side ? subbar_width/2 : 0)
# Y1
p2 = @graph_height
# to X2
bar_width = fieldwidth - bargap
bar_width /= @data.length if stack == :side
x_mod = (@graph_width-bargap)/2 - (stack==:side ? bar_width/2 : 0)
bottom = @graph_height
field_count = 0
@config[:fields].each_index { |i|
dataset_count = 0
for dataset in @data
# X1
p1 = (fieldwidth * field_count)
# to Y2
p3 = @graph_height - ((dataset[:data][i] - minvalue) * fieldheight)
p1 += subbar_width * dataset_count if stack == :side
@graph.add_element( "path", {
"class" => "fill#{dataset_count+1}",
"d" => "M#{p1} #{p2} V#{p3} h#{subbar_width} V#{p2} Z"
# cases (assume 0 = +ve):
# value min length
# +ve +ve value - min
# +ve -ve value - 0
# -ve -ve value.abs - 0
value = dataset[:data][i]
left = (fieldwidth * field_count)
length = (value.abs - (minvalue > 0 ? minvalue : 0)) * unit_size
# top is 0 if value is negative
top = bottom - (((value < 0 ? 0 : value) - minvalue) * unit_size)
left += bar_width * dataset_count if stack == :side
@graph.add_element( "rect", {
"x" => left.to_s,
"y" => top.to_s,
"width" => bar_width.to_s,
"height" => length.to_s,
"class" => "fill#{dataset_count+1}"
})
make_datapoint_text(
p1 + subbar_width/2.0,
p3 - 6,
dataset[:data][i].to_s)
make_datapoint_text(left + bar_width/2.0, top - 6, value.to_s)
dataset_count += 1
end
field_count += 1

View File

@ -43,18 +43,17 @@ module SVG
protected
def max_value
return @data.collect{|x| x[:data].max}.max
@data.collect{|x| x[:data].max}.max
end
def min_value
min = 0
if (min_scale_value.nil? == false) then
min = min_scale_value
else
if min_scale_value.nil?
min = @data.collect{|x| x[:data].min}.min
min = min > 0 ? 0 : min
else
min = min_scale_value
end
return min
end

View File

@ -103,28 +103,41 @@ module SVG
def draw_data
minvalue = min_value
fieldheight = field_height
fieldwidth = (@graph_width.to_f - font_size*2*right_font ) /
unit_size = (@graph_width.to_f - font_size*2*right_font ) /
(get_x_labels.max - get_x_labels.min )
bargap = bar_gap ? (fieldheight < 10 ? fieldheight / 2 : 10) : 0
subbar_height = fieldheight - bargap
subbar_height /= @data.length if stack == :side
bar_height = fieldheight - bargap
bar_height /= @data.length if stack == :side
y_mod = (bar_height / 2) + (font_size / 2)
field_count = 1
y_mod = (subbar_height / 2) + (font_size / 2)
@config[:fields].each_index { |i|
dataset_count = 0
for dataset in @data
y = @graph_height - (fieldheight * field_count)
y += (subbar_height * dataset_count) if stack == :side
x = (dataset[:data][i] - minvalue) * fieldwidth
value = dataset[:data][i]
@graph.add_element( "path", {
"d" => "M0 #{y} H#{x} v#{subbar_height} H0 Z",
top = @graph_height - (fieldheight * field_count)
top += (bar_height * dataset_count) if stack == :side
# cases (assume 0 = +ve):
# value min length left
# +ve +ve value.abs - min minvalue.abs
# +ve -ve value.abs - 0 minvalue.abs
# -ve -ve value.abs - 0 minvalue.abs + value
length = (value.abs - (minvalue > 0 ? minvalue : 0)) * unit_size
left = (minvalue.abs + (value < 0 ? value : 0)) * unit_size
@graph.add_element( "rect", {
"x" => left.to_s,
"y" => top.to_s,
"width" => length.to_s,
"height" => bar_height.to_s,
"class" => "fill#{dataset_count+1}"
})
make_datapoint_text(
x+5, y+y_mod, dataset[:data][i], "text-anchor: start; "
left+length+5, top+y_mod, value, "text-anchor: start; "
)
dataset_count += 1
end

View File

@ -110,7 +110,7 @@ module SVG
:show_y_guidelines => true,
:show_data_values => true,
:min_scale_value => 0,
# :min_scale_value => 0,
:show_x_labels => true,
:stagger_x_labels => false,
@ -137,14 +137,14 @@ module SVG
:key => true,
:key_position => :right, # bottom or right
:font_size =>10,
:title_font_size =>12,
:font_size =>12,
:title_font_size =>16,
:subtitle_font_size =>14,
:x_label_font_size =>11,
:x_label_font_size =>12,
:x_title_font_size =>14,
:y_label_font_size =>11,
:y_label_font_size =>12,
:y_title_font_size =>14,
:key_font_size => 9,
:key_font_size =>10,
:no_css =>false,
:add_popups =>false,
@ -392,7 +392,7 @@ module SVG
@border_right = 7
if key and key_position == :right
val = keys.max { |a,b| a.length <=> b.length }
@border_right += val.length * key_font_size * 0.7
@border_right += val.length * key_font_size * 0.6
@border_right += KEY_BOX_SIZE
@border_right += 10 # Some padding around the box
end
@ -421,7 +421,7 @@ module SVG
t.attributes["style"] = "fill: #000; "+
(x+txt_width > width ? "text-anchor: end;" : "text-anchor: start;")
t.text = label.to_s
t.attributes["id"] = t.id.to_s
t.attributes["id"] = t.object_id.to_s
@foreground.add_element( "circle", {
"cx" => x.to_s,
@ -429,9 +429,9 @@ module SVG
"r" => "10",
"style" => "opacity: 0",
"onmouseover" =>
"document.getElementById(#{t.id}).setAttribute('visibility', 'visible' )",
"document.getElementById(#{t.object_id}).setAttribute('visibility', 'visible' )",
"onmouseout" =>
"document.getElementById(#{t.id}).setAttribute('visibility', 'hidden' )",
"document.getElementById(#{t.object_id}).setAttribute('visibility', 'hidden' )",
})
end
@ -446,11 +446,11 @@ module SVG
@border_bottom += 10
end
if show_x_labels
max_x_label_height_px = rotate_x_labels ?
max_x_label_height_px = (not rotate_x_labels) ?
x_label_font_size :
get_x_labels.max{|a,b|
a.length<=>b.length
}.length * x_label_font_size * 0.6 :
x_label_font_size
a.to_s.length<=>b.to_s.length
}.to_s.length * x_label_font_size * 0.6
@border_bottom += max_x_label_height_px
@border_bottom += max_x_label_height_px + 10 if stagger_x_labels
end
@ -723,7 +723,7 @@ module SVG
})
group.add_element( "text", {
"x" => (KEY_BOX_SIZE + 5).to_s,
"y" => (y_offset + KEY_BOX_SIZE - 2).to_s,
"y" => (y_offset + KEY_BOX_SIZE).to_s,
"class" => "keyText"
}).text = key_name.to_s
key_count += 1
@ -737,10 +737,11 @@ module SVG
x_offset = @border_left + 20
y_offset = @border_top + @graph_height + 5
if show_x_labels
max_x_label_height_px = rotate_x_labels ?
max_x_label_height_px = (not rotate_x_labels) ?
x_label_font_size :
get_x_labels.max{|a,b|
a.length<=>b.length
}.length * x_label_font_size :
a.to_s.length<=>b.to_s.length
}.to_s.length * x_label_font_size * 0.6
x_label_font_size
y_offset += max_x_label_height_px
y_offset += max_x_label_height_px + 5 if stagger_x_labels
@ -883,41 +884,41 @@ module SVG
fill:#ffffff;
}
.graphBackground{
fill:#f5f5f5;
fill:#f0f0f0;
}
/* graphs titles */
.mainTitle{
text-anchor: middle;
fill: #555555;
fill: #000000;
font-size: #{title_font_size}px;
font-family: "Verdana", sans-serif;
font-weight: bold;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.subTitle{
text-anchor: middle;
fill: #999999;
font-size: #{subtitle_font_size}px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.axis{
stroke: #666666;
stroke: #000000;
stroke-width: 1px;
}
.guideLines{
stroke: #666666;
stroke-width: 1px;
stroke-dasharray:2,2,2;
stroke-dasharray: 5 5;
}
.xAxisLabels{
text-anchor: middle;
fill: #000000;
font-size: #{x_label_font_size}px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
@ -925,7 +926,7 @@ module SVG
text-anchor: end;
fill: #000000;
font-size: #{y_label_font_size}px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
@ -933,7 +934,7 @@ module SVG
text-anchor: middle;
fill: #ff0000;
font-size: #{x_title_font_size}px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
@ -941,7 +942,7 @@ module SVG
fill: #ff0000;
text-anchor: middle;
font-size: #{y_title_font_size}px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
@ -949,7 +950,7 @@ module SVG
fill: #000000;
text-anchor:middle;
font-size: 10px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
@ -965,7 +966,7 @@ module SVG
fill: #000000;
text-anchor:start;
font-size: #{key_font_size}px;
font-family: "Verdana", sans-serif;
font-family: "Arial", sans-serif;
font-weight: normal;
}
/* End copy for external style sheet */

View File

@ -222,6 +222,7 @@ module SVG
y_start = radius-(Math.cos(radians) * radius)
radians = (prev_percent+percent) * rad_mult
x_end = radius+(Math.sin(radians) * radius)
x_end -= 0.00001 if @data.length == 1
y_end = radius-(Math.cos(radians) * radius)
path = "M#{radius},#{radius} L#{x_start},#{y_start} "+
"A#{radius},#{radius} "+
@ -257,7 +258,7 @@ module SVG
ty = -(Math.cos(radians) * expand_gap)
translate = "translate( #{tx} #{ty} )"
wedge.attributes["transform"] = translate
clear.attributes["transform"] = translate
clear.attributes["transform"] = translate if clear
end
if show_shadow

View File

@ -88,11 +88,13 @@ module SVG
class Plot < Graph
# In addition to the defaults set by Graph::initialize, sets
# [show_data_values] true
# [show_data_points] true
# [area_fill] false
# [stacked] false
def set_defaults
init_with(
:show_data_values => true,
:show_data_points => true,
:area_fill => false,
:stacked => false
@ -238,7 +240,11 @@ module SVG
def field_height
values = get_y_values
max = @data.collect{|x| x[:data][Y].max }.max
if values.length == 1
dx = values[-1]
else
dx = (max - values[-1]).to_f / (values[-1] - values[-2])
end
(@graph_height.to_f - font_size*2*top_font) /
(values.length + dx - top_align)
end
@ -290,7 +296,7 @@ module SVG
})
add_popup(x, y, format( x_points[idx], y_points[idx] )) if add_popups
end
make_datapoint_text( x, y-6, y_points[idx] )
make_datapoint_text( x, y-6, y_points[idx] ) if show_data_values
}
end
line += 1

View File

@ -145,7 +145,7 @@ module SVG
def add_data data
@data = [] unless @data
raise "No data provided by #{conf.inspect}" unless data[:data] and
raise "No data provided by #{@data.inspect}" unless data[:data] and
data[:data].kind_of? Array
raise "Data supplied must be x,y pairs! "+
"The data provided contained an odd set of "+
@ -191,13 +191,13 @@ module SVG
rv = []
min, max, scale_division = x_range
if timescale_divisions
timescale_divisions =~ /(\d+) ?(days|weeks|months|years|hours|minutes|seconds)?/
division_units = $2 ? $2 : "days"
timescale_divisions =~ /(\d+) ?(day|week|month|year|hour|minute|second)?/
division_units = $2 ? $2 : "day"
amount = $1.to_i
if amount
step = nil
case division_units
when "months"
when "month"
cur = min
while cur < max
rv << cur
@ -209,7 +209,7 @@ module SVG
end
cur = Time.local(*arr).to_i
end
when "years"
when "year"
cur = min
while cur < max
rv << cur
@ -217,15 +217,15 @@ module SVG
arr[5] += amount
cur = Time.local(*arr).to_i
end
when "weeks"
when "week"
step = 7 * 24 * 60 * 60 * amount
when "days"
when "day"
step = 24 * 60 * 60 * amount
when "hours"
when "hour"
step = 60 * 60 * amount
when "minutes"
when "minute"
step = 60 * amount
when "seconds"
when "second"
step = amount
end
min.step( max, step ) {|v| rv << v} if step