Method: Statsample::Graph::Scatterplot#rubyvis_panel
- Defined in:
- lib/statsample/graph/scatterplot.rb
permalink #rubyvis_panel ⇒ Object
Returns a Rubyvis panel with scatterplot
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/statsample/graph/scatterplot.rb', line 120 def rubyvis_panel # :nodoc: that=self #p @v1.map {|v| v} @minimum_x||=@v1.min @maximum_x||=@v1.max @minimum_y||=@v2.min @maximum_y||=@v2.max colors=Rubyvis::Colors.category10 margin_hor=margin_left + margin_right margin_vert=margin_top + margin_bottom x=Rubyvis::Scale.linear(@minimum_x, @maximum_x).range(0, width - margin_hor) y=Rubyvis::Scale.linear(@minimum_y, @maximum_y).range(0, height - margin_vert) @x_scale=x @y_scale=y vis=Rubyvis::Panel.new do |pan| pan.width width - margin_hor pan.height height - margin_vert pan.bottom margin_bottom pan.left margin_left pan.right margin_right pan.top margin_top # X axis pan.rule do data y.ticks bottom y stroke_style {|d| d!=0 ? "#eee" : "#000"} label(:anchor=>'left') do visible {|d| d!=0 and d < that.width} text y.tick_format end end # Y axis pan.rule do data x.ticks left x stroke_style {|d| d!=0 ? "#eee" : "#000"} label(:anchor=>'bottom') do visible {|d| d>0 and d < that.height} text x.tick_format end end # Add lines on median add_line_median(pan) if line_median pan.panel do data(that.data) dot do left {|d| x[d[:x]]} bottom {|d| y[d[:y]]} fill_style {|v| alpha=(that.dot_alpha-0.3<=0) ? 0.1 : that.dot_alpha-0.3 if that.groups colors.scale(that.groups[index]).alpha(alpha) else colors.scale(0).alpha(alpha) end } stroke_style {|v| if that.groups colors.scale(that.groups[parent.index]).alpha(that.dot_alpha) else colors.scale(0).alpha(that.dot_alpha) end } shape_radius 2 end end end vis end |