basis-processing 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README +65 -1
- data/basis.gemspec +1 -1
- data/lib/demo-boxplot.rb +48 -0
- data/lib/screen.rb +1 -1
- metadata +4 -3
data/README
CHANGED
@@ -96,7 +96,9 @@ If you omit the block at the end of the call, Basis will plot the point using a
|
|
96
96
|
|
97
97
|
You can toggle the joining of the points with lines by setting the join attribute of Screen to on (joins points)/off (no joining). The default is false.
|
98
98
|
|
99
|
-
|
99
|
+
## Plotting markers inside/outside your custom basis
|
100
|
+
|
101
|
+
You now have more options for drawing markers for your data points on screen, either in the default basis (sans any transformation), or in the basis you've specified. If you're using your specified basis, all shapes you draw (rectangles, ellipses, etc.) will be draw as they'd appear in the custom basis.
|
100
102
|
|
101
103
|
For example, in the code below, we are specifying that all our drawing (in this case, a filled rectangle) will be drawn using the basis specified while defining the Screen object.
|
102
104
|
|
@@ -183,6 +185,68 @@ In the above code, the basis vectors are (1,1) and (-1,1). The @highlight_block
|
|
183
185
|
|
184
186
|
This will draw the highlighted rectangle unrotated. You can make use of the in_basis() and the outside_basis() methods to use one or the other. The default is to draw it in the default, untransformed, basis. For your convenience, the first two parameters passed to your block will be the original, and the mapped points, respectively.
|
185
187
|
|
188
|
+
## Plotting objects which are not points
|
189
|
+
|
190
|
+
Some graphical representations of data might require more than simply plotting a single point. For example, a box plot is a concise way of summarising the distribution of a dataset; it is drawn not as a single point, but as a combination of boxes and 'whiskers'. There is some support now in Basis to make this easier for you to do.
|
191
|
+
Consider the following code:
|
192
|
+
|
193
|
+
require 'rubygems'
|
194
|
+
Gem.clear_paths
|
195
|
+
ENV['GEM_HOME'] = '/home/avishek/jruby/jruby-1.6.4/lib/ruby/gems/1.8'
|
196
|
+
ENV['GEM_PATH'] = '/home/avishek/jruby/jruby-1.6.4/lib/ruby/gems/1.8'
|
197
|
+
|
198
|
+
require 'basis_processing'
|
199
|
+
|
200
|
+
class BoxPlotSketch < Processing::App
|
201
|
+
def setup
|
202
|
+
@screen_height = 900
|
203
|
+
@width = width
|
204
|
+
@height = height
|
205
|
+
no_loop
|
206
|
+
smooth
|
207
|
+
background(0,0,0)
|
208
|
+
color_mode(HSB, 1.0)
|
209
|
+
box = {:minimum => 20, :maximum => 70, :q1 => 30, :q2 => 40, :q3 => 50}
|
210
|
+
@x_unit_vector = {:x => 1.0, :y => 0.0}
|
211
|
+
@y_unit_vector = {:x => 0.0, :y => 1.0}
|
212
|
+
@screen_transform = Transform.new({:x => 5.0, :y => -5.0}, {:x => @width/2, :y => @screen_height})
|
213
|
+
x_range = ContinuousRange.new({:minimum => 0.0, :maximum => 80.0})
|
214
|
+
y_range = ContinuousRange.new({:minimum => 0.0, :maximum => box[:maximum]})
|
215
|
+
@c = CoordinateSystem.new(Axis.new(@x_unit_vector,x_range), Axis.new(@y_unit_vector,y_range), self, [[1,0],[0,1]])
|
216
|
+
@screen = Screen.new(@screen_transform, self, @c)
|
217
|
+
stroke(0.3,1,1)
|
218
|
+
no_fill
|
219
|
+
position = 20
|
220
|
+
box_width = 20
|
221
|
+
whisker_width = 10
|
222
|
+
@screen.plot(box) do |o,s|
|
223
|
+
s.in_basis do
|
224
|
+
rect(position - box_width/2, o[:q1], box_width, o[:q2] - o[:q1])
|
225
|
+
rect(position - box_width/2, o[:q2], box_width, o[:q3] - o[:q2])
|
226
|
+
line(position, o[:q3], position, o[:maximum])
|
227
|
+
line(position, o[:q1], position, o[:minimum])
|
228
|
+
line(position - whisker_width/2, o[:minimum], position + whisker_width/2, o[:minimum])
|
229
|
+
line(position - whisker_width/2, o[:maximum], position + whisker_width/2, o[:maximum])
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
@screen.draw_axes(10, 4)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
h = 1000
|
238
|
+
w = 1400
|
239
|
+
BoxPlotSketch.new(:title => "Box Plot", :width => w, :height => h)
|
240
|
+
|
241
|
+
The first interesting thing in the code above is that the box hash does not have any values for the keys :x, :y. In such a situation, where Basis cannot identify a valid point, it defers the entirety of the plotting to the block that is passed to plot(). If no block is specified, it does nothing else. At this point, it is not possible to interact with objects which are not points, like in the above example.
|
242
|
+
|
243
|
+
The other interesting thing about the above code will become evident if we specify a different set of basis vectors like so:
|
244
|
+
|
245
|
+
@x_unit_vector = {:x => 1.0, :y => 0.15}
|
246
|
+
@y_unit_vector = {:x => 0.2, :y => 1.0}
|
247
|
+
|
248
|
+
The box plot in this modified basis acquires the properties of skewness, rotation, etc. of the host coordinate system. This lets you get on with drawing the object without really worrying about the specific properties of the coordinate space you are plotting in.
|
249
|
+
|
186
250
|
## Convenience methods for setting up default CoordinateSystem
|
187
251
|
|
188
252
|
If you're doing a simple plot, with standard basis vectors with no transformations, you can use the convenience method in CoordinateSystem to set up a default system.
|
data/basis.gemspec
CHANGED
data/lib/demo-boxplot.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
Gem.clear_paths
|
3
|
+
ENV['GEM_HOME'] = '/home/avishek/jruby/jruby-1.6.4/lib/ruby/gems/1.8'
|
4
|
+
ENV['GEM_PATH'] = '/home/avishek/jruby/jruby-1.6.4/lib/ruby/gems/1.8'
|
5
|
+
|
6
|
+
require 'basis_processing'
|
7
|
+
|
8
|
+
class BoxPlotSketch < Processing::App
|
9
|
+
def setup
|
10
|
+
@screen_height = 900
|
11
|
+
@width = width
|
12
|
+
@height = height
|
13
|
+
no_loop
|
14
|
+
smooth
|
15
|
+
background(0,0,0)
|
16
|
+
color_mode(HSB, 1.0)
|
17
|
+
box = {:minimum => 20, :maximum => 70, :q1 => 30, :q2 => 40, :q3 => 50}
|
18
|
+
@x_unit_vector = {:x => 1.0, :y => 0.15}
|
19
|
+
@y_unit_vector = {:x => 0.2, :y => 1.0}
|
20
|
+
@screen_transform = Transform.new({:x => 5.0, :y => -5.0}, {:x => @width/2, :y => @screen_height})
|
21
|
+
x_range = ContinuousRange.new({:minimum => 0.0, :maximum => 80.0})
|
22
|
+
y_range = ContinuousRange.new({:minimum => 0.0, :maximum => 80.0})
|
23
|
+
@c = CoordinateSystem.new(Axis.new(@x_unit_vector,x_range), Axis.new(@y_unit_vector,y_range), self, [[1,0],[0,1]])
|
24
|
+
@screen = Screen.new(@screen_transform, self, @c)
|
25
|
+
stroke(0.3,1,1)
|
26
|
+
no_fill
|
27
|
+
position = 20
|
28
|
+
box_width = 20
|
29
|
+
whisker_width = 10
|
30
|
+
@screen.plot(box) do |o,s|
|
31
|
+
s.in_basis do
|
32
|
+
rect(position - box_width/2, o[:q1], box_width, o[:q2] - o[:q1])
|
33
|
+
rect(position - box_width/2, o[:q2], box_width, o[:q3] - o[:q2])
|
34
|
+
line(position, o[:q3], position, o[:maximum])
|
35
|
+
line(position, o[:q1], position, o[:minimum])
|
36
|
+
line(position - whisker_width/2, o[:minimum], position + whisker_width/2, o[:minimum])
|
37
|
+
line(position - whisker_width/2, o[:maximum], position + whisker_width/2, o[:maximum])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@screen.draw_axes(10, 4)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
h = 950
|
46
|
+
w = 1000
|
47
|
+
BoxPlotSketch.new(:title => "Box Plot", :width => w, :height => h)
|
48
|
+
|
data/lib/screen.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basis-processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-09 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: knnball
|
16
|
-
requirement: &
|
16
|
+
requirement: &9073420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.0.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9073420
|
25
25
|
description: Basis provides a set of classes for easily plotting and transforming
|
26
26
|
arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
|
27
27
|
email: avishek.sen.gupta@gmail.com
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/basis_processing.rb
|
36
36
|
- lib/cache.rb
|
37
37
|
- lib/coordinate_system.rb
|
38
|
+
- lib/demo-boxplot.rb
|
38
39
|
- lib/demo-rotated.rb
|
39
40
|
- lib/demo.rb
|
40
41
|
- lib/hash_vector.rb
|