30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|
# File 'lib/statsample/graph/svgboxplot.rb', line 30
def draw_data
minvalue = min_value
fieldwidth = field_width
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
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
for dataset in @data
min=dataset[:data].min
max=dataset[:data].max
median=dataset[:vector].median
q1=dataset[:vector].percentil(25)
q3=dataset[:vector].percentil(75)
iqr=q3-q1
left = (fieldwidth * field_count)
top_wisk=(q3+iqr*1.5 < max) ? q3+iqr*1.5 : max
down_wisk= (q1-iqr*1.5 > min) ? q1-iqr*1.5 : min
top=@graph_height-((top_wisk-minvalue)*unit_size)
down=@graph_height-((down_wisk-minvalue)*unit_size)
median_bar=@graph_height-((median-minvalue)*unit_size)
middle= left+(bar_width / 2)
left_whis=left+(bar_width * 0.4)
rigth_whis=left+(bar_width*0.6)
left_rect= left+(bar_width * 0.25)
rigth_rect = left+ (bar_width * 0.75)
top_rect=@graph_height-((q3-minvalue)*unit_size)
height_rect=iqr*unit_size
path="M #{left_whis} #{top} H #{rigth_whis} M #{middle} #{top} V #{down} M #{left_whis} #{down} H #{rigth_whis} M #{left_rect} #{median_bar} H #{rigth_rect}"
if top_wisk!=max or down_wisk!=min
dataset[:vector].valid_data.each{|d|
if(d<down_wisk) or (d>top_wisk)
y_out=(@graph_height - (d -minvalue)*unit_size).to_s
@graph.add_element( "circle", {
"cx" => (middle).to_s,
"cy" => y_out,
"r" => "3",
"class" => "dataPoint#{field_count+1}"
})
@graph.add_element( "text", {
"x" => (middle+20).to_s,
"y" => y_out,
"class" => "dataPointLabel",
"style" => "#{style} stroke: #000;"
}).text = d.to_s end
}
end
@graph.add_element( "rect", { "x" => left_rect.to_s, "y" => top_rect.to_s, "width" => (bar_width / 2).to_s, "height" => (height_rect).to_s, "class" => "fill#{field_count+1}"})
@graph.add_element("path",{"d"=>path, "style"=>"stroke:black;stroke-width:2"})
field_count += 1
end
end
|