From 61a5ebb5d532a6fdaaa94b470aa39bdc14b392c4 Mon Sep 17 00:00:00 2001 From: Miguel Vazquez Date: Mon, 8 Jul 2013 15:49:09 +0200 Subject: [PATCH] Allow arbitrary params in SVG objects --- lib/bio/graphics/mini_feature.rb | 5 +++-- lib/bio/graphics/page.rb | 5 +++-- lib/bio/graphics/svgee.rb | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/bio/graphics/mini_feature.rb b/lib/bio/graphics/mini_feature.rb index 55c80b4..27d8a83 100644 --- a/lib/bio/graphics/mini_feature.rb +++ b/lib/bio/graphics/mini_feature.rb @@ -5,7 +5,7 @@ class Graphics #A Bio::Graphics::MiniFeature object represents a single genomic feature (e.g. a gene, transcript, exon, start codon, etc), it is a lightweight object that #holds the minimum information needed to do the render. class MiniFeature - attr_accessor :start, :end, :strand, :exons, :utrs, :block_gaps, :segment_height, :id + attr_accessor :start, :end, :strand, :exons, :utrs, :block_gaps, :segment_height, :id, :params #Creates a new MiniFeature # #== args @@ -41,8 +41,9 @@ def initialize(args) @block_gaps = [] @id = args[:id] @segment_height = args[:segment_height] + @params = args[:params] end end end -end \ No newline at end of file +end diff --git a/lib/bio/graphics/page.rb b/lib/bio/graphics/page.rb index 64017a5..9153f46 100644 --- a/lib/bio/graphics/page.rb +++ b/lib/bio/graphics/page.rb @@ -358,7 +358,8 @@ def draw_features(track) :exons => f.exons, :utrs => f.utrs, :block_gaps => f.block_gaps, - :height => track.feature_height + :height => track.feature_height, + :params => f.params }.merge!(track.args)) if f.id @@ -398,4 +399,4 @@ def write(file) end end end -end \ No newline at end of file +end diff --git a/lib/bio/graphics/svgee.rb b/lib/bio/graphics/svgee.rb index 5f9cf3c..bc37860 100644 --- a/lib/bio/graphics/svgee.rb +++ b/lib/bio/graphics/svgee.rb @@ -81,7 +81,10 @@ def text_tag(a = {}) end def common_attributes(a={}) - %{stroke="#{a[:stroke]}" stroke-width="#{a[:stroke_width]}" style="#{a[:style]}"} + param_str = "" + a[:params].each{|k,v| param_str << %{ #{k}="#{v}"}} if a[:params] + + %{stroke="#{a[:stroke]}" stroke-width="#{a[:stroke_width]}" style="#{a[:style]}"} + param_str end def method_missing(primitive, args={}) #only used to dynamically select the primitive type.. @@ -142,4 +145,4 @@ def draw s.add_primitive(prim) #add one of the returned, updated Primitive objects s.draw -=end \ No newline at end of file +=end