rubyvis 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/History.txt +9 -1
  2. data/Manifest.txt +9 -4
  3. data/README.txt +59 -8
  4. data/examples/antibiotics/antibiotics.rb +16 -8
  5. data/examples/area.rb +6 -49
  6. data/examples/bar_column_chart.rb +4 -0
  7. data/examples/crimea/{crimea.rb → crimea_data.rb} +0 -0
  8. data/examples/crimea/crimea_grouped_bar.rb +2 -2
  9. data/examples/crimea/crimea_line.rb +1 -1
  10. data/examples/dot.rb +7 -8
  11. data/examples/first.rb +4 -0
  12. data/examples/grouped_charts.rb +3 -0
  13. data/examples/line.rb +19 -61
  14. data/examples/line_and_step.rb +4 -0
  15. data/examples/nested_grid.rb +53 -0
  16. data/examples/scatterplot.rb +2 -0
  17. data/examples/second.rb +14 -2
  18. data/examples/third.rb +9 -6
  19. data/lib/rubyvis/color/color.rb +8 -6
  20. data/lib/rubyvis/color/colors.rb +4 -6
  21. data/lib/rubyvis/format/number.rb +2 -2
  22. data/lib/rubyvis/internals.rb +15 -3
  23. data/lib/rubyvis/javascript_behaviour.rb +20 -8
  24. data/lib/rubyvis/layout/stack.rb +13 -16
  25. data/lib/rubyvis/mark/anchor.rb +64 -2
  26. data/lib/rubyvis/mark/area.rb +4 -3
  27. data/lib/rubyvis/mark/bar.rb +51 -2
  28. data/lib/rubyvis/mark/dot.rb +88 -5
  29. data/lib/rubyvis/mark/label.rb +94 -3
  30. data/lib/rubyvis/mark/line.rb +3 -2
  31. data/lib/rubyvis/mark/panel.rb +1 -0
  32. data/lib/rubyvis/mark/rule.rb +2 -1
  33. data/lib/rubyvis/mark/wedge.rb +2 -1
  34. data/lib/rubyvis/mark.rb +419 -54
  35. data/lib/rubyvis/nest.rb +20 -20
  36. data/lib/rubyvis/scale/linear.rb +1 -1
  37. data/lib/rubyvis/scale/log.rb +1 -1
  38. data/lib/rubyvis/scale/ordinal.rb +120 -8
  39. data/lib/rubyvis/scale/quantitative.rb +159 -15
  40. data/lib/rubyvis/scale.rb +1 -1
  41. data/lib/rubyvis/scene/svg_area.rb +12 -12
  42. data/lib/rubyvis/scene/svg_line.rb +5 -5
  43. data/lib/rubyvis/scene/svg_panel.rb +1 -1
  44. data/lib/rubyvis/scene/svg_scene.rb +1 -1
  45. data/lib/rubyvis.rb +35 -6
  46. data/spec/anchor_spec.rb +15 -15
  47. data/web/Rakefile +34 -0
  48. data/web/build_site.rb +86 -0
  49. data/web/examples.haml +26 -0
  50. data/web/index.haml +97 -0
  51. data/web/style.css +82 -0
  52. data.tar.gz.sig +0 -0
  53. metadata +14 -9
  54. metadata.gz.sig +0 -0
  55. data/lib/rubyvis/label.rb +0 -1
  56. data/web/first.svg +0 -1
  57. data/web/index.html +0 -48
@@ -1,4 +1,5 @@
1
1
  module Rubyvis
2
+ # Alias for Rubyvis::Colors
2
3
  def self.Colors
3
4
  Rubyvis::Colors
4
5
  end
@@ -8,18 +9,15 @@ module Rubyvis
8
9
  scale
9
10
  end
10
11
  module Colors
11
- def pv
12
- Rubyvis
13
- end
14
12
  def self.category10(*arguments)
15
- scale = pv.colors(
13
+ scale = Rubyvis.colors(
16
14
  "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
17
15
  "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf")
18
16
  scale.domain(*arguments) if arguments.size>0
19
17
  scale
20
18
  end
21
19
  def self.category19(*arguments)
22
- scale = pv.colors(
20
+ scale = Rubyvis.colors(
23
21
  "#9c9ede", "#7375b5", "#4a5584", "#cedb9c", "#b5cf6b",
24
22
  "#8ca252", "#637939", "#e7cb94", "#e7ba52", "#bd9e39",
25
23
  "#8c6d31", "#e7969c", "#d6616b", "#ad494a", "#843c39",
@@ -28,7 +26,7 @@ module Rubyvis
28
26
  scale
29
27
  end
30
28
  def self.category20(*arguments)
31
- scale = pv.colors(
29
+ scale = Rubyvis.colors(
32
30
  "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c",
33
31
  "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5",
34
32
  "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f",
@@ -69,10 +69,10 @@ module Rubyvis
69
69
  # two-element array is returned containing the minimum and the maximum.
70
70
  #
71
71
  # @function
72
- # @name pv.Format.number.prototype.fractionDigits
72
+ # @name Rubyvis.Format.number.prototype.fractionDigits
73
73
  # @param {number} [min] the minimum fraction digits.
74
74
  # @param {number} [max] the maximum fraction digits.
75
- # @returns {pv.Format.number} <tt>this</tt>, or the current fraction digits.
75
+ # @returns {Rubyvis.Format.number} <tt>this</tt>, or the current fraction digits.
76
76
 
77
77
  def fraction_digits(min=nil,max=nil)
78
78
  if (!min.nil?)
@@ -1,14 +1,25 @@
1
1
  module Rubyvis
2
2
  # :section: /pv-internals.js
3
3
  @@id=0
4
+ # Return a unique id each time
4
5
  def self.id
5
6
  @@id+=1
6
7
  end
8
+ # Return a value as a Proc.
7
9
  def self.functor(f)
8
10
  (f.is_a? Proc) ? f : lambda {f}
9
11
  end
12
+ ##
10
13
  # :section: /data/Arrays.js
11
-
14
+
15
+ ##
16
+ # A private variant of Array.map that supports the index property
17
+ #
18
+ # :call-seq:
19
+ # self.map(Array)
20
+ # self.map(array,proc)
21
+ #
22
+
12
23
  def self.map(array, f=nil)
13
24
  if f
14
25
  array.size.times.map {|i|
@@ -19,6 +30,7 @@ module Rubyvis
19
30
  array.dup
20
31
  end
21
32
  end
33
+
22
34
  def self.repeat(array, n=2)
23
35
  array*n
24
36
  end
@@ -47,7 +59,7 @@ module Rubyvis
47
59
  end
48
60
  def self.normalize(array,f=nil)
49
61
  norm=Rubyvis.map(array,f)
50
- sum=pv.sum(norm)
62
+ sum=Rubyvis.sum(norm)
51
63
  norm.map {|x| x.quo(sum)}
52
64
  end
53
65
  def self.o_index(i)
@@ -172,7 +184,7 @@ module Rubyvis
172
184
  Rubyvis.sum(array,f).quo(array.size)
173
185
  end
174
186
  def self.median(array,f=nil)
175
- return (array.length - 1).quo(2) if (f == pv.index)
187
+ return (array.length - 1).quo(2) if (f == Rubyvis.index)
176
188
  array = Rubyvis.map(array, f).sort
177
189
  return array[array.size.quo(2).floor] if (array.length % 2>0)
178
190
  i = array.size.quo(2);
@@ -1,15 +1,17 @@
1
1
  class TrueClass
2
+ # Return 1
2
3
  def to_i
3
4
  1
4
5
  end
5
6
  end
6
7
  class FalseClass
8
+ # Return 0
7
9
  def to_i
8
10
  0
9
11
  end
10
12
  end
11
13
 
12
-
14
+ # :stopdoc:
13
15
  unless Object.public_method_defined? :instance_exec
14
16
  class Object
15
17
  module InstanceExecHelper; end
@@ -31,16 +33,26 @@ unless Object.public_method_defined? :instance_exec
31
33
  ret
32
34
  end
33
35
  end
34
-
35
36
  end
37
+ # :startdoc:
38
+
36
39
  # Add javascript-like +apply+ and +call+ methods to Proc,
37
40
  # called +js_apply+ and +js_call+, respectivly.
38
-
39
41
  class Proc
40
- attr_accessor :order
41
- # Apply on javascript is very flexible. Can accept more or less
42
- # variables than explicitly defined parameters on lambda, so the method
43
- # adds or remove elements according to lambda arity
42
+ # Used on Rubyvis::Nest
43
+ attr_accessor :order # :nodoc:
44
+
45
+ # Emulation of +apply+ javascript method.
46
+ # +apply+ has this signature
47
+ # my_proc.apply(my_obj, args)
48
+ # where
49
+ # [+my_proc+] a proc
50
+ # [+my_obj+] object inside proc is eval'ed
51
+ # [args] array of arguments for proc
52
+ #
53
+ # +apply+ on javascript is very flexible. Can accept more or less
54
+ # variables than explicitly defined parameters on lambda, so this
55
+ # method adds or remove elements according to lambda arity
44
56
  #
45
57
  def js_apply(obj,args)
46
58
  arguments=args.dup
@@ -59,7 +71,7 @@ class Proc
59
71
  end
60
72
  end
61
73
  # Same as js_apply, but using explicit arguments
62
- def js_call(obj,*args)
74
+ def js_call(obj, *args)
63
75
  js_apply(obj,args)
64
76
  end
65
77
  end
@@ -18,21 +18,21 @@ module Rubyvis
18
18
  @values=nil
19
19
  @_x=lambda {return 0}
20
20
  @_y=lambda {return 0}
21
- @_values=pv.identity
21
+ @_values=Rubyvis.identity
22
22
  end
23
23
  def x(f)
24
- @_x=pv.functor(f)
24
+ @_x=Rubyvis.functor(f)
25
25
  return self
26
26
  end
27
27
  def y(f)
28
- @_y=pv.functor(f)
28
+ @_y=Rubyvis.functor(f)
29
29
  return self
30
30
  end
31
31
  def values(f=nil)
32
32
  if f.nil?
33
33
  @values
34
34
  else
35
- @_values=pv.functor(f)
35
+ @_values=Rubyvis.functor(f)
36
36
  return self
37
37
  end
38
38
  end
@@ -96,9 +96,9 @@ module Rubyvis
96
96
  _index=nil
97
97
  case (s.order)
98
98
  when "inside-out"
99
- max = dy.map {|v| pv.max.index(v) }
99
+ max = dy.map {|v| Rubyvis.max.index(v) }
100
100
  map = pv.range(n).sort {|a,b| return max[a] - max[b]}
101
- sums = dy.map {|v| pv.sum(v)}
101
+ sums = dy.map {|v| Rubyvis.sum(v)}
102
102
  top = 0
103
103
  bottom = 0
104
104
  tops = []
@@ -116,9 +116,9 @@ module Rubyvis
116
116
  _index = bottoms.reverse+tops
117
117
 
118
118
  when "reverse"
119
- _index = pv.range(n - 1, -1, -1)
119
+ _index = Rubyvis.range(n - 1, -1, -1)
120
120
  else
121
- _index = pv.range(n)
121
+ _index = Rubyvis.range(n)
122
122
  end
123
123
 
124
124
  #/* offset */
@@ -203,13 +203,10 @@ module Rubyvis
203
203
 
204
204
  def layer
205
205
  that=self
206
- value = Rubyvis::Mark.new().data(lambda { that.values[self.parent.index] })
207
- .top(proxy("t"))
208
- .left(proxy("l"))
209
- .right(proxy("r"))
210
- .bottom(proxy("b"))
211
- .width(proxy("w"))
212
- .height(proxy("h"))
206
+ value = Rubyvis::Mark.new().data(lambda { that.values[self.parent.index] }).top(proxy("t")).left(proxy("l")).right(proxy("r")).
207
+ bottom(proxy("b")).
208
+ width(proxy("w")).
209
+ height(proxy("h"))
213
210
 
214
211
  class << value
215
212
  def that=(v)
@@ -217,7 +214,7 @@ module Rubyvis
217
214
  end
218
215
  def add(type)
219
216
  that = @that
220
- that.add( pv.Panel ).data(lambda { that.layers() }).add(type).extend( self )
217
+ that.add( Rubyvis.Panel ).data(lambda { that.layers() }).add(type).extend( self )
221
218
  end
222
219
  end
223
220
  value.that=self
@@ -1,17 +1,79 @@
1
1
  module Rubyvis
2
+ # Alias por Rubyvis::Anchor.new(target)
2
3
  def self.Anchor(target)
3
4
  Rubyvis::Anchor.new(target)
4
5
  end
5
-
6
+ # Represents an anchor on a given mark. An anchor is itself a mark, but
7
+ # without a visual representation. It serves only to provide useful default
8
+ # properties that can be inherited by other marks. Each type of mark can define
9
+ # any number of named anchors for convenience. If the concrete mark type does
10
+ # not define an anchor implementation specifically, one will be inherited from
11
+ # the mark's parent class.
12
+ #
13
+ # For example, the bar mark provides anchors for its four sides: left,
14
+ # right, top and bottom. Adding a label to the top anchor of a bar,
15
+ #
16
+ # bar.anchor("top").add(Rubyvis::Label)
17
+ #
18
+ # will render a text label on the top edge of the bar; the top anchor defines
19
+ # the appropriate position properties (top and left), as well as text-rendering
20
+ # properties for convenience (text_align and text_baseline).
21
+ #
22
+ # <p>Note that anchors do not <i>inherit</i> from their targets; the positional
23
+ # properties are copied from the scene graph, which guarantees that the anchors
24
+ # are positioned correctly, even if the positional properties are not defined
25
+ # deterministically. (In addition, it also improves performance by avoiding
26
+ # re-evaluating expensive properties.) If you want the anchor to inherit from
27
+ # the target, use Mark#extend before adding. For example:
28
+ #
29
+ # bar.anchor("top").extend(bar).add(Rubyvis::Label)
30
+ #
31
+ # The anchor defines it's own positional properties, but other properties (such
32
+ # as the title property, say) can be inherited using the above idiom. Also note
33
+ # that you can override positional properties in the anchor for custom
34
+ # behavior.
6
35
  class Anchor < Mark
36
+ # List of properties common to all Anchors
7
37
  @properties=Mark.properties.dup
38
+
39
+ ##
40
+ # :attr: name
41
+ # The anchor name. The set of supported anchor names is dependent on the
42
+ # concrete mark type; see the mark type for details. For example, bars support
43
+ # left, right, top and bottom anchors.
44
+ #
45
+ # While anchor names are typically constants, the anchor name is a true
46
+ # property, which means you can specify a function to compute the anchor name
47
+ # dynamically. For instance, if you wanted to alternate top and bottom anchors, saying
48
+ #
49
+ # m.anchor(lambda {(index % 2) ? "top" : "bottom"}).add(Rubyvis::Dot)
50
+ #
51
+ # would have the desired effect.
52
+
53
+ #
8
54
  attr_accessor_dsl [:name, lambda {|d| d.to_s}]
9
-
55
+
56
+ # Create a new Anchor. Use Mark.add instead.
57
+
10
58
  def initialize(target)
11
59
  super()
12
60
  self.target=target
13
61
  self.parent=target.parent
14
62
  end
63
+
64
+ # Sets the prototype of this anchor to the specified mark. Any properties not
65
+ # defined on this mark may be inherited from the specified prototype mark, or
66
+ # its prototype, and so on. The prototype mark need not be the same type of
67
+ # mark as this mark. (Note that for inheritance to be useful, properties with
68
+ # the same name on different mark types should have equivalent meaning.)
69
+ #
70
+ # <p>This method differs slightly from the normal mark behavior in that the
71
+ # anchor's target is preserved.
72
+ #
73
+ # @param {Rubyvis::Mark} proto the new prototype.
74
+ # @returns {Rubyvis::Anchor} this anchor.
75
+ # @see Rubyvis.Mark#add
76
+
15
77
  def extend(proto)
16
78
  @proto=proto
17
79
  self
@@ -1,8 +1,10 @@
1
1
  module Rubyvis
2
+ # Alias for Rubyvis::Area
2
3
  def self.Area
3
4
  Rubyvis::Area
4
5
  end
5
- module AreaPrototype
6
+ # Provides methods pertinents to area like-marks.
7
+ module AreaPrototype
6
8
  def fixed
7
9
  {
8
10
  :line_width=> true,
@@ -15,7 +17,6 @@ module Rubyvis
15
17
  }
16
18
  end
17
19
  def area_build_instance(s)
18
-
19
20
  binds = self.binds
20
21
  # Handle fixed properties on secondary instances. */
21
22
  if (self.index!=0)
@@ -101,7 +102,7 @@ module Rubyvis
101
102
  class Area < Mark
102
103
  include AreaPrototype
103
104
  @properties=Mark.properties.dup
104
- attr_accessor_dsl :width, :height, :line_width, [:stroke_style, lambda {|d| pv.color(d)}], [:fill_style, lambda {|d| pv.color(d)}], :segmented, :interpolate, :tension
105
+ attr_accessor_dsl :width, :height, :line_width, [:stroke_style, lambda {|d| Rubyvis.color(d)}], [:fill_style, lambda {|d| Rubyvis.color(d)}], :segmented, :interpolate, :tension
105
106
  def type
106
107
  'area'
107
108
  end
@@ -1,15 +1,64 @@
1
1
  module Rubyvis
2
+ # Alias for Rubyvis::Bar
2
3
  def self.Bar
3
4
  Rubyvis::Bar
4
5
  end
6
+
7
+ # Represents a bar: an axis-aligned rectangle that can be stroked and
8
+ # filled. Bars are used for many chart types, including bar charts, histograms
9
+ # and Gantt charts. Bars can also be used as decorations, for example to draw a
10
+ # frame border around a panel; in fact, a panel is a special type (a subclass)
11
+ # of bar.
12
+ #
13
+ # Bars can be positioned in several ways. Most commonly, one of the four
14
+ # corners is fixed using two margins, and then the width and height properties
15
+ # determine the extent of the bar relative to this fixed location. For example,
16
+ # using the bottom and left properties fixes the bottom-left corner; the width
17
+ # then extends to the right, while the height extends to the top. As an
18
+ # alternative to the four corners, a bar can be positioned exclusively using
19
+ # margins; this is convenient as an inset from the containing panel, for
20
+ # example. See Mark for details on the prioritization of redundant
21
+ # positioning properties.
5
22
  class Bar < Mark
6
- def type
23
+
24
+ def type # :nodoc:
7
25
  "bar"
8
26
  end
9
27
 
10
28
  @properties=Mark.properties.dup
11
- attr_accessor_dsl :width, :height, :line_width, [:stroke_style, lambda {|d| pv.color(d)}], [:fill_style, lambda {|d| pv.color(d)}]
12
29
 
30
+
31
+ ##
32
+ # :attr: width
33
+ # The width of the bar, in pixels. If the left position is specified, the bar
34
+ # extends rightward from the left edge; if the right position is specified, the
35
+ # bar extends leftward from the right edge.
36
+
37
+ ##
38
+ # :attr: height
39
+ # The height of the bar, in pixels. If the bottom position is specified, the
40
+ # bar extends upward from the bottom edge; if the top position is specified,
41
+ # the bar extends downward from the top edge.
42
+
43
+ ##
44
+ # :attr: line_width
45
+ # The width of stroked lines, in pixels; used in conjunction with
46
+ # stroke_style to stroke the bar's border.
47
+
48
+ ##
49
+ # :attr: stroke_style
50
+ # The style of stroked lines; used in conjunction with line_width to
51
+ # stroke the bar's border. The default value of this property is null, meaning bars are not stroked by default.
52
+
53
+ ##
54
+ # :attr: fill_style
55
+ # The bar fill style; if non-null, the interior of the bar is filled with the
56
+ # specified color. The default value of this property is a categorical color.
57
+
58
+ attr_accessor_dsl :width, :height, :line_width, [:stroke_style, lambda {|d| Rubyvis.color(d)}], [:fill_style, lambda {|d| Rubyvis.color(d)}]
59
+
60
+ # Default properties for bars. By default, there is no stroke and the fill
61
+ # style is a categorical color.
13
62
  def self.defaults
14
63
  a=Rubyvis.Colors.category20()
15
64
  Bar.new.extend(Mark.defaults).line_width(1.5).fill_style( lambda {
@@ -1,24 +1,104 @@
1
1
  module Rubyvis
2
+ # Alias por Rubyvis::Dot
2
3
  def self.Dot
3
4
  Rubyvis::Dot
4
5
  end
6
+ # Represents a dot; a dot is simply a sized glyph centered at a given
7
+ # point that can also be stroked and filled. The <tt>size</tt> property is
8
+ # proportional to the area of the rendered glyph to encourage meaningful visual
9
+ # encodings. Dots can visually encode up to eight dimensions of data, though
10
+ # this may be unwise due to integrality. See Mark for details on the
11
+ # prioritization of redundant positioning properties.
5
12
  class Dot < Mark
13
+ # Type of mark
6
14
  def type
7
15
  "dot"
8
16
  end
9
17
 
10
18
  @properties=Mark.properties.dup
11
19
 
12
- attr_accessor_dsl :shape, :shape_angle, :shape_radius, :shape_size, :line_width, [:stroke_style, lambda {|d| pv.color(d)}], [:fill_style, lambda {|d| pv.color(d)}]
20
+ ##
21
+ # :attr: shape_size
22
+ # The size of the shape, in square pixels. Square pixels are used such that the
23
+ # area of the shape is linearly proportional to the value of the
24
+ # <tt>shapeSize</tt> property, facilitating representative encodings. This is
25
+ # an alternative to using shape_radius
26
+ #
13
27
 
28
+ ##
29
+ # :attr: shape_radius
30
+ # The radius of the shape, in pixels. This is an alternative to using
31
+ # shape_size
32
+ #
33
+
34
+ ##
35
+ # :attr: shape
36
+ # The shape name. Several shapes are supported:<ul>
37
+ #
38
+ # <li>cross
39
+ # <li>triangle
40
+ # <li>diamond
41
+ # <li>square
42
+ # <li>circle
43
+ # <li>tick
44
+ # <li>bar
45
+ #
46
+ # </ul>These shapes can be further changed using the angle() property;
47
+ # for instance, a cross can be turned into a plus by rotating. Similarly, the
48
+ # tick, which is vertical by default, can be rotated horizontally. Note that
49
+ # some shapes (cross and tick) do not have interior areas, and thus do not
50
+ # support fill style meaningfully.
51
+ #
52
+ # <p>Note: it may be more natural to use the Rule mark for
53
+ # horizontal and vertical ticks. The tick shape is only necessary if angled
54
+ # ticks are needed.
55
+
56
+ ##
57
+ # :attr: shape_angle
58
+ # The shape rotation angle, in radians. Used to rotate shapes, such as to turn
59
+ # a cross into a plus.
60
+
61
+ ##
62
+ # :attr: line_width
63
+ # The width of stroked lines, in pixels; used in conjunction with
64
+ # +stroke_style+ to stroke the dot's shape.
65
+
66
+ ##
67
+ # :attr: stroke_style
68
+ # The style of stroked lines; used in conjunction with +line_width+ to
69
+ # stroke the dot's shape. The default value of this property is a categorical color. See Rubyvis.color()
70
+
71
+ ##
72
+ # :attr: fill_style
73
+ # The fill style; if non-null, the interior of the dot is filled with the
74
+ # specified color. The default value of this property is null, meaning dots are
75
+ # not filled by default. See Rubyvis.color()
76
+
77
+ attr_accessor_dsl :shape, :shape_angle, :shape_radius, :shape_size, :line_width, [:stroke_style, lambda {|d| Rubyvis.color(d)}], [:fill_style, lambda {|d| Rubyvis.color(d)}]
78
+ # Default properties for dots. By default, there is no fill and the stroke
79
+ # style is a categorical color. The default shape is "circle" with radius 4.5.
14
80
  def self.defaults()
15
81
  a=Rubyvis::Colors.category10
16
82
  Dot.new().extend(Mark.defaults).shape("circle"). line_width(1.5). stroke_style(lambda {a.scale(self.parent.index)})
17
83
  end
18
-
84
+ # Constructs a new dot anchor with default properties. Dots support five
85
+ # different anchors:<ul>
86
+ #
87
+ # <li>top
88
+ # <li>left
89
+ # <li>center
90
+ # <li>bottom
91
+ # <li>right
92
+ #
93
+ # </ul>In addition to positioning properties (left, right, top bottom), the
94
+ # anchors support text rendering properties (text-align, text-baseline). Text is
95
+ # rendered to appear outside the dot. Note that this behavior is different from
96
+ # other mark anchors, which default to rendering text <i>inside</i> the mark.
97
+ #
98
+ # <p>For consistency with the other mark types, the anchor positions are
99
+ # defined in terms of their opposite edge. For example, the top anchor defines
100
+ # the bottom property, such that a bar added to the top anchor grows upward.
19
101
  def anchor(name)
20
-
21
-
22
102
  mark_anchor(name).left(lambda {
23
103
  s=scene.target[self.index]
24
104
  case self.name
@@ -66,7 +146,10 @@ module Rubyvis
66
146
 
67
147
  })
68
148
  end
69
- def build_implied(s)
149
+
150
+
151
+ # @private Sets radius based on size or vice versa.
152
+ def build_implied(s) # :nodoc:
70
153
  r = s.shape_radius
71
154
  z = s.shape_size
72
155
  if (r.nil?)
@@ -1,16 +1,107 @@
1
1
  module Rubyvis
2
+ # Alias for Rubyvis::Label
2
3
  def self.Label
3
4
  Rubyvis::Label
4
5
  end
5
-
6
+ # Represents a text label, allowing textual annotation of other marks or
7
+ # arbitrary text within the visualization. The character data must be plain
8
+ # text (unicode), though the text can be styled using the {@link #font}
9
+ # property. If rich text is needed, external HTML elements can be overlaid on
10
+ # the canvas by hand.
11
+ #
12
+ # <p>Labels are positioned using the box model, similarly to {@link Dot}. Thus,
13
+ # a label has no width or height, but merely a text anchor location. The text
14
+ # is positioned relative to this anchor location based on the
15
+ # text_align, text_baseline and text_margin properties.
16
+ # Furthermore, the text may be rotated using text_angle
6
17
  class Label < Mark
7
18
  @properties=Mark.properties.dup
8
- attr_accessor_dsl :text, :font, :text_angle, [:text_style, lambda {|d| pv.color(d)}], :text_align, :text_baseline, :text_margin, :text_decoration, :text_shadow
19
+
20
+ ##
21
+ # :attr: text
22
+ # The character data to render; a string. The default value of the text
23
+ # property is the identity function, meaning the label's associated datum will
24
+ # be rendered using its to_s()
25
+
26
+ ##
27
+ # :attr: font
28
+ # The font format, per the CSS Level 2 specification. The default font is "10px
29
+ # sans-serif", for consistency with the HTML 5 canvas element specification.
30
+ # Note that since text is not wrapped, any line-height property will be
31
+ # ignored. The other font-style, font-variant, font-weight, font-size and
32
+ # font-family properties are supported.
33
+ #
34
+ # @see {CSS2 fonts}[http://www.w3.org/TR/CSS2/fonts.html#font-shorthand]
35
+
36
+ ##
37
+ # :attr: text_angle
38
+ # The rotation angle, in radians. Text is rotated clockwise relative to the
39
+ # anchor location. For example, with the default left alignment, an angle of
40
+ # Math.PI / 2 causes text to proceed downwards. The default angle is zero.
41
+
42
+ ##
43
+ # :attr: text_style
44
+ # The text color. The name "text_style" is used for consistency with "fill_style"
45
+ # and "stroke_style", although it might be better to rename this property (and
46
+ # perhaps use the same name as "stroke_style"). The default color is black.
47
+ # See Rubyvis.color()
48
+
49
+ ##
50
+ # :attr: text_align
51
+ # The horizontal text alignment. One of:<ul>
52
+ #
53
+ # <li>left
54
+ # <li>center
55
+ # <li>right
56
+ #
57
+ # </ul>The default horizontal alignment is left.
58
+
59
+
60
+ ##
61
+ # :attr: text_baseline
62
+ # The vertical text alignment. One of:<ul>
63
+ #
64
+ # <li>top
65
+ # <li>middle
66
+ # <li>bottom
67
+ #
68
+ # </ul>The default vertical alignment is bottom.
69
+
70
+
71
+ ##
72
+ # :attr: text_margin
73
+ # The text margin; may be specified in pixels, or in font-dependent units (such
74
+ # as ".1ex"). The margin can be used to pad text away from its anchor location,
75
+ # in a direction dependent on the horizontal and vertical alignment
76
+ # properties. For example, if the text is left- and middle-aligned, the margin
77
+ # shifts the text to the right. The default margin is 3 pixels.
78
+
79
+
80
+ ##
81
+ # :attr: text_shadow
82
+ # A list of shadow effects to be applied to text, per the CSS Text Level 3
83
+ # text-shadow property. An example specification is "0.1em 0.1em 0.1em
84
+ # rgba(0,0,0,.5)"; the first length is the horizontal offset, the second the
85
+ # vertical offset, and the third the blur radius.
86
+ #
87
+ # See {CSS3 text}[http://www.w3.org/TR/css3-text/#text-shadow]
88
+
89
+ ##
90
+ # :attr: text_decoration
91
+ # A list of decoration to be applied to text, per the CSS Text Level 3
92
+ # text-decoration property. An example specification is "underline".
93
+ #
94
+ # See {CSS3 text}[http://www.w3.org/TR/css3-text/#text-decoration]
95
+
96
+
97
+ attr_accessor_dsl :text, :font, :text_angle, [:text_style, lambda {|d| Rubyvis.color(d)}], :text_align, :text_baseline, :text_margin, :text_decoration, :text_shadow
98
+ # Mark type
9
99
  def type
10
100
  'label'
11
101
  end
102
+ # Default properties for labels. See the individual properties for the default values.
12
103
  def self.defaults
13
- Label.new.extend(Mark.defaults).events('none').text(pv.identity).font("10px sans-serif" ).text_angle( 0 ).text_style( 'black' ).text_align( 'left' ).text_baseline( 'bottom' ).text_margin(3)
104
+ Label.new.extend(Mark.defaults).events('none').text(Rubyvis.identity).font("10px sans-serif" ).text_angle( 0 ).text_style( 'black' ).text_align( 'left' ).text_baseline( 'bottom' ).text_margin(3)
14
105
  end
15
106
  end
16
107
  end
@@ -1,8 +1,9 @@
1
1
  module Rubyvis
2
+ # Alias for Rubyvis::Line
2
3
  def self.Line
3
4
  Rubyvis::Line
4
5
  end
5
- module LinePrototype
6
+ module LinePrototype
6
7
  include AreaPrototype
7
8
  def line_anchor(name)
8
9
  anchor=area_anchor(name).text_align(lambda {|d|
@@ -17,7 +18,7 @@ module Rubyvis
17
18
  include AreaPrototype
18
19
  include LinePrototype
19
20
  @properties=Mark.properties.dup
20
- attr_accessor_dsl :line_width, :line_join, [:stroke_style, lambda {|d| pv.color(d)}], [:fill_style, lambda {|d| pv.color(d)}], :segmented, :interpolate, :eccentricity, :tension
21
+ attr_accessor_dsl :line_width, :line_join, [:stroke_style, lambda {|d| Rubyvis.color(d)}], [:fill_style, lambda {|d| Rubyvis.color(d)}], :segmented, :interpolate, :eccentricity, :tension
21
22
  def type
22
23
  "line"
23
24
  end
@@ -1,4 +1,5 @@
1
1
  module Rubyvis
2
+ # Alias for Rubyvis::Panel
2
3
  def self.Panel
3
4
  Rubyvis::Panel
4
5
  end