basis-processing 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,8 @@
1
- Basis provides a set of classes for easily plotting and transforming arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
1
+ **NOTE: Starting from version 0.5.1, Basis has been ported to Ruby 1.9.2, because of the kd-tree library dependency. There are no current plans of maintaining Basis compatibility with Ruby 1.8.x.**
2
+
3
+ **Basis** provides a set of classes for easily plotting and transforming arbitrary 2D coordinate systems by specifying their basis vectors. Originally developed to work with Ruby-Processing, it now supports any class which supports Processing-like semantics.
4
+
5
+ Starting from version 0.5.0, experimental support has been added for mouseover interactivity without (too much) extra effort on your part. This is still a work in progress, though.
2
6
 
3
7
  ## Installation
4
8
 
@@ -18,11 +22,6 @@ To use Basis functionality in your code, it is enough to:
18
22
 
19
23
  Here's some example code, which plots random points.
20
24
 
21
- require 'rubygems'
22
- Gem.clear_paths
23
- ENV['GEM_HOME'] = '/home/avishek/jruby/jruby-1.6.3/lib/ruby/gems/1.8'
24
- ENV['GEM_PATH'] = '/home/avishek/jruby/jruby-1.6.3/lib/ruby/gems/1.8'
25
-
26
25
  require 'basis_processing'
27
26
 
28
27
  class Demo < Processing::App
@@ -67,6 +66,7 @@ Here's some example code, which plots random points.
67
66
  points.each do |p|
68
67
  @screen.plot(p, :track => true) {|p| rect(p[:x], p[:y], 5, 5)}
69
68
  end
69
+ @index = @screen.build
70
70
  end
71
71
  end
72
72
 
@@ -83,9 +83,34 @@ it will connect the point with the x-axis. If you omit `:bar => true` or don't s
83
83
  If you omit the block at the end of the call, Basis will plot the point using a circle. Use the block to customise how you wish to represent the point graphically.
84
84
  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.
85
85
 
86
- Version 0.5.0 introduces experimental support for mouseover interactivity without extra effort on your part. To allow interactions to happen, you must specify ':track => true' while plotting a point, as in the line below:
86
+ ## Running the Code (with extra notes for versions >= 0.5.1)
87
+
88
+ Running the code is as simple as typing:
89
+
90
+ `rp5 run demo.rb`
91
+
92
+ If you're not using the Gems-in-a-Jar approach, you might have to use:
93
+
94
+ `rp5 run --jruby demo.rb`
95
+
96
+ The reason for the `--jruby` switch is to force Ruby-Processing to use the installed version of JRuby, instead of it's own jruby-complete.jar
97
+
98
+ Additionally, starting with version 0.5.1, you will have to specify the environment variable JRUBY_OPTS to force JRuby to use the 1.9 version of the interpreter, like so:
99
+
100
+ `export JRUBY_OPTS=--1.9`
101
+
102
+ ## Notes on Interactivity
103
+
104
+ Experimental support exists for mouseover interactivity without (too much) extra effort on your part. To allow interactions to happen, you must specify ':track => true' while plotting a point, as in the line below:
87
105
 
88
106
  @screen.plot(p, :track => true) {|p| rect(p[:x], p[:y], 5, 5)}
89
107
 
90
- To actually enable interactivity, you must 'include' the Interactive module in your sketch class, as in the demonstration code above. Interactivity is a work in progress at the moment.
108
+ To actually enable interactivity, you must do a few things:
109
+
110
+ * 'include' the Interactive module in your sketch class, as in the demonstration code above.
111
+ * Build the data sample index from the data, by calling `@index = @screen.build`.
112
+ * `@highlight_block` specifies what to plot when the data point is hovered upon.
113
+ * `@passive_block` specifies what to plot when the data point is **not** being hovered on.
114
+
115
+ Interactivity is a work in progress at the moment; some of the above steps may change or be removed.
91
116
 
data/basis.gemspec CHANGED
@@ -1,6 +1,7 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "basis-processing"
3
- s.version = "0.5.0"
3
+ s.version = "0.5.1"
4
+ s.add_dependency('knnball', '>= 0.0.6')
4
5
  s.author = "Avishek Sen Gupta"
5
6
  s.email = "avishek.sen.gupta@gmail.com"
6
7
  s.homepage = "http://avishek.net/blog"
data/lib/demo.rb CHANGED
@@ -1,8 +1,3 @@
1
- require 'rubygems'
2
- Gem.clear_paths
3
- ENV['GEM_HOME'] = '/home/avishek/jruby/jruby-1.6.3/lib/ruby/gems/1.8'
4
- ENV['GEM_PATH'] = '/home/avishek/jruby/jruby-1.6.3/lib/ruby/gems/1.8'
5
-
6
1
  require 'basis_processing'
7
2
 
8
3
  class Demo < Processing::App
@@ -47,6 +42,7 @@ class Demo < Processing::App
47
42
  points.each do |p|
48
43
  @screen.plot(p, :track => true) {|p| rect(p[:x], p[:y], 5, 5)}
49
44
  end
45
+ @index = @screen.build
50
46
  end
51
47
  end
52
48
 
data/lib/interactive.rb CHANGED
@@ -1,16 +1,20 @@
1
1
  module Interactive
2
- attr :screen, :basis
2
+ attr :screen, :basis, :index
3
3
 
4
4
  def mouseMoved(p)
5
5
  p = {:x => p.getX(), :y => p.getY()}
6
6
  @old_points ||= []
7
- @points_to_highlight = []
8
- index = @screen.points.index do |i|
9
- onscreen_point = @screen.transformed(i)
10
- (p[:x] - onscreen_point[:x]).abs < 4.0 && (p[:y] - onscreen_point[:y]).abs < 4.0
7
+ @points_to_highlight ||= []
8
+ original_point = @screen.original(p)
9
+ closest_point = @index.nearest([original_point[:x], original_point[:y]])
10
+ closest = @screen.points[closest_point[:id]]
11
+ distance = (closest[:x] - original_point[:x])**2 + (closest[:y] - original_point[:y])**2
12
+ if distance > 1.0
13
+ @points_to_highlight = []
14
+ redraw
15
+ return
11
16
  end
12
- return if index == nil
13
- @points_to_highlight = [{:x => @screen.points[index][:x], :y => @screen.points[index][:y]}]
17
+ @points_to_highlight = [closest]
14
18
  redraw
15
19
  end
16
20
 
data/lib/screen.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'transform'
2
+ require 'knnball'
2
3
 
3
4
  class Screen
4
5
  attr_accessor :points
@@ -14,10 +15,16 @@ class Screen
14
15
  @basis = basis
15
16
  join = false
16
17
  @points = []
18
+ @data = []
19
+ end
20
+
21
+ def build
22
+ KnnBall.build(@data)
17
23
  end
18
24
 
19
25
  def plot(point, options = {:bar => false, :track => false}, &block)
20
26
  @points << point if options[:track]
27
+ @data << {:id => @points.count - 1, :point => [point[:x], point[:y]]}
21
28
  p = transformed(point)
22
29
  standard_x_axis_point = @transform.apply(@basis.standard_basis({:x => point[:x], :y => 0}))
23
30
  if (block)
metadata CHANGED
@@ -1,32 +1,34 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: basis-processing
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Avishek Sen Gupta
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-05 00:00:00 Z
19
- dependencies: []
20
-
21
- description: Basis provides a set of classes for easily plotting and transforming arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
12
+ date: 2011-10-06 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: knnball
16
+ requirement: &8267900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *8267900
25
+ description: Basis provides a set of classes for easily plotting and transforming
26
+ arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
22
27
  email: avishek.sen.gupta@gmail.com
23
28
  executables: []
24
-
25
29
  extensions: []
26
-
27
30
  extra_rdoc_files: []
28
-
29
- files:
31
+ files:
30
32
  - .gitignore
31
33
  - README
32
34
  - basis.gemspec
@@ -40,36 +42,27 @@ files:
40
42
  - lib/transform.rb
41
43
  homepage: http://avishek.net/blog
42
44
  licenses: []
43
-
44
45
  post_install_message:
45
46
  rdoc_options: []
46
-
47
- require_paths:
47
+ require_paths:
48
48
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
- version: "0"
58
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
56
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 3
64
- segments:
65
- - 0
66
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
67
61
  requirements: []
68
-
69
62
  rubyforge_project:
70
- rubygems_version: 1.7.2
63
+ rubygems_version: 1.8.6
71
64
  signing_key:
72
65
  specification_version: 3
73
- summary: Basis provides a set of classes for easily plotting and transforming arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
66
+ summary: Basis provides a set of classes for easily plotting and transforming arbitrary
67
+ 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
74
68
  test_files: []
75
-