Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added extra properties to label mark

  • Loading branch information...
commit 6e07d78f32188dd0fbe7a7130ef33c5c684b4142 1 parent 0bd9ef2
Claudio Bustos authored
2  README.txt
View
@@ -37,7 +37,7 @@ Using protovis examples[http://vis.stanford.edu/protovis/ex/] as reference
* Arc
* Matrix
-I try to maintain, when posible, complete compatibility with Javascript API, including camel case naming of functions. Johnson [http://github.com/jbarnette/johnson] - the lovely Javascript wrapper inside Ruby embrace - is our friend to test implementation of basic object.
+I try to maintain, when posible, complete compatibility with Javascript API, including camel case naming of functions.
User could use +pv+ freely, cause is defined as a global method which call Rubyvis.
2  lib/rubyvis/mark/label.rb
View
@@ -94,7 +94,7 @@ class Label < Mark
# See {CSS3 text}[http://www.w3.org/TR/css3-text/#text-decoration]
- attr_accessor_dsl :text, :font, :text_angle, [:text_style, lambda {|d| Rubyvis.color(d)}], :text_align, :text_baseline, :text_margin, :text_decoration, :text_shadow
+ attr_accessor_dsl :text, :font, :text_angle, [:text_style, lambda {|d| Rubyvis.color(d)}], :text_align, :text_baseline, :text_margin, :text_decoration, :text_shadow, :font_family, :font_style, :font_variant, :font_weight, :font_size
# Mark type
def type
'label'
9 lib/rubyvis/scene/svg_label.rb
View
@@ -41,7 +41,14 @@ def self.label(scenes)
"fill-opacity"=> fill.opacity==0 ? nil : fill.opacity,
"text-anchor"=> anchor
}, {
- "font"=> s.font, "text-shadow"=> s.text_shadow, "text-decoration"=> s.text_decoration})
+ "font"=> s.font,
+ "font-family"=> s.font_family.nil? ? nil : s.font_family,
+ "font-style"=> s.font_style.nil? ? nil: s.font_style,
+ "font-variant"=> s.font_variant.nil? ? nil : s.font_variant,
+ "font-weight"=> s.font_weight.nil? ? nil: s.font_weight,
+ "font-size"=> s.font_size.nil? ? nil: s.font_size,
+ "text-shadow"=> s.text_shadow,
+ "text-decoration"=> s.text_decoration})
e.text=s.text.frozen? ? s.text.dup : s.text
2  lib/rubyvis/sceneelement.rb
View
@@ -8,7 +8,7 @@ def initialize
end
include Enumerable
attr_accessor :visible
- attr_accessor :mark, :type, :child_index, :parent, :parent_index, :target, :defs, :data, :antialias, :line_width, :fill_style, :overflow, :width, :height, :top, :bottom, :left, :right, :title, :reverse, :stroke_style, :transform, :canvas, :_g, :events, :cursor, :children, :id, :segmented, :interpolate, :tension, :name, :text_baseline, :text_align, :text, :font, :text_angle, :text_style, :text_margin, :text_decoration, :text_shadow, :line_join, :eccentricity, :shape_size, :shape, :shape_angle, :shape_radius, :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :layers, :orient, :offset, :order,:url, :image_width, :image_height, :image, :_id, :nodes, :round, :links, :padding_left, :padding_right, :padding_top, :padding_bottom, :mode, :group, :depth, :breadth, :spacing, :rows, :cols, :_grid,:bands, :background_style, :positive_style, :negative_style,:directed, :_matrix
+ attr_accessor :mark, :type, :child_index, :parent, :parent_index, :target, :defs, :data, :antialias, :line_width, :fill_style, :overflow, :width, :height, :top, :bottom, :left, :right, :title, :reverse, :stroke_style, :transform, :canvas, :_g, :events, :cursor, :children, :id, :segmented, :interpolate, :tension, :name, :text_baseline, :text_align, :text, :font, :font_family, :font_style, :font_variant, :font_weight, :font_size, :text_angle, :text_style, :text_margin, :text_decoration, :text_shadow, :line_join, :eccentricity, :shape_size, :shape, :shape_angle, :shape_radius, :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :layers, :orient, :offset, :order,:url, :image_width, :image_height, :image, :_id, :nodes, :round, :links, :padding_left, :padding_right, :padding_top, :padding_bottom, :mode, :group, :depth, :breadth, :spacing, :rows, :cols, :_grid,:bands, :background_style, :positive_style, :negative_style,:directed, :_matrix
def []=(v,i)
if v.is_a? Numeric
28 spec/label_spec.rb
View
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
describe Rubyvis::Label do
it "should have correct properties" do
- props=[:antialias, :bottom, :cursor, :data, :events, :font, :id, :left, :reverse, :right, :text, :text_align, :text_angle, :text_baseline, :text_decoration, :text_margin, :text_shadow, :text_style, :title, :top, :visible].inject({}) {|ac, v| ac[v]=true; ac}
+ props=[:antialias, :bottom, :cursor, :data, :events, :font, :font_family, :font_style, :font_variant, :font_weight, :font_size, :id, :left, :reverse, :right, :text, :text_align, :text_angle, :text_baseline, :text_decoration, :text_margin, :text_shadow, :text_style, :title, :top, :visible].inject({}) {|ac, v| ac[v]=true; ac}
Rubyvis::Label.properties.should==props
end
@@ -18,24 +18,36 @@
context "on a Panel" do
before do
#Rubyvis.clear_document
- @h=100
- @w=200
- @vis = Rubyvis.Panel.new.width(@w).height(@h)
- @vis.add(pv.Bar).data([1,2]).width(20).height(lambda {|d| d * 80}).bottom(0).left(lambda {self.index * 25}).add(pv.Label)
+ @h=100
+ @w=200
+ @vis = Rubyvis.Panel.new.width(@w).height(@h)
+ @bar=@vis.add(pv.Bar).data([1,2]).width(20).height(lambda {|d| d * 80}).bottom(0).left(lambda {self.index * 25})
+ @label=@bar.add(pv.Label)
end
- it "should bould propertly" do
+ it "should bould properly with font_size" do
+ @label.font_size('20px')
+ @vis.render
+ s=@vis.to_svg
+ doc=Nokogiri::XML(s)
+ #p doc.at_xpath("//xmlns:text")
+ doc.at_xpath("//xmlns:text").attributes['style'].value.should=='font-size:20px'
+ end
+
+ it "should bould basic stuff properly " do
@vis.render
s=@vis.to_svg
#p s
#File.open("test.svg","w") {|f| f.puts s}
doc=Nokogiri::XML(s)
+ #p doc.at_xpath("//xmlns:text")
attribs=doc.xpath("//xmlns:text").map {|v|
[v.attributes['y'].value, v.attributes['transform'].value, v.text] }
attribs.should==[["-3","translate(0,100)","1"],["-3","translate(25,100)","2"]]
- end
+ end
+
end
-end
+end
0  web/Rakefile 100644 → 100755
View
File mode changed
0  web/build_site.rb 100644 → 100755
View
File mode changed
1  web/examples.haml 100644 → 100755
View
@@ -1,6 +1,7 @@
!!!
%html
%head
+ %meta{"http-equiv"=>"Content-Type", :content=>"text/html", :charset=>"UTF-8"}
%link{:type=>"text/css", :rel=>"stylesheet", :href=>"../style.css"}
%title="Rubyvis - Example: #{title}"
%body
1  web/index.haml 100644 → 100755
View
@@ -1,6 +1,7 @@
!!!
%html
%head
+ %meta{"http-equiv"=>"Content-Type", :content=>"text/html", :charset=>"UTF-8"}
%link{:type=>"text/css", :rel=>"stylesheet", :href=>"style.css"}
%title Rubyvis: Ruby version of Protovis
%body
0  web/style.css 100644 → 100755
View
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.