Class: Relyze::Graph::Edge

Inherits:
Object
  • Object
show all
Defined in:
C:/Program Files/Relyze/lib/relyze/core/graph.rb

Overview

A base class representing an edge in a graph.

Direct Known Subclasses

TCG::TCGEdge

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, lhs, rhs, data) ⇒ Edge

Initialize a new edge object.

Parameters:



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 670

def initialize( graph, lhs, rhs, data )
    @graph   = graph
    @lhs     = lhs
    @rhs     = rhs
    @name    = "%s - %s" % [ @lhs.name, @rhs.name ]
    @label   = nil
    @data    = data
    @display = {
        :points_x   => [],
        :points_y   => [],
        :edge_width => @graph.display.fetch( :edge_width, 2.0 ),
        :edge_color => @graph.display.fetch( :edge_color, '#000000' )
    }

    @lhs.edges << self

    if( @lhs != @rhs )
        @rhs.edges << self
    end
end

Instance Attribute Details

#dataObject (readonly)

A data [Object] to associate with this edge.



653
654
655
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 653

def data
  @data
end

#displayObject (readonly)

Hash

A hash of display properties for this edge.



656
657
658
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 656

def display
  @display
end

#graphObject (readonly)

Relyze::Graph::Graph

The graph this edge belongs to.



644
645
646
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 644

def graph
  @graph
end

#labelObject

String, nil

Gets this edge's label (if any).



662
663
664
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 662

def label
  @label
end

#lhsObject (readonly)

Relyze::Graph::Node

This edges left hand side node.



647
648
649
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 647

def lhs
  @lhs
end

#nameObject

String

Gets this edge's name.



659
660
661
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 659

def name
  @name
end

#rhsObject (readonly)

Relyze::Graph::Node

This edges right hand side node.



650
651
652
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 650

def rhs
  @rhs
end

Instance Method Details

#removenil

Remove this edge from the graph.

Returns:

  • (nil)


694
695
696
697
698
699
700
701
702
703
704
705
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 694

def remove
    @lhs.edges.delete( self )

    if( @lhs != @rhs )
        @rhs.edges.delete( self )
    end

    @lhs = nil
    @rhs = nil

    return nil
end

#to_dotString

Export this edge object as a DOT edge.

Returns:



762
763
764
765
766
767
768
769
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 762

def to_dot
    dot = "\t%s %s %s [color=\"%s\"" % [ @lhs.name, ( @graph.directed? ? '->' : '--' ), @rhs.name, @display[:edge_color] ]
    if( not @label.nil? )
        dot << ", label=\"%s\"" % @label.to_s
    end
    dot << "]\r\n"
    return dot
end

#to_sString

Get this edges text content. If a data object is available we use this to generate the content, otherwise this edges name is used.

Returns:

  • (String)

    This edges text content.



775
776
777
778
779
780
781
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 775

def to_s
    if( @data.nil? )
        return @name
    end

    return @data.respond_to?( :render ) ? @data.render : @data.to_s
end

#to_svgString

Export this edge object as a SVG element, suitable for embedding in HTML.

Returns:

  • (String)

    An SVG element.



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'C:/Program Files/Relyze/lib/relyze/core/graph.rb', line 710

def to_svg

    svg  = "<g class=\"relyze_graph_edge\" style=\"stroke:%s; fill:%s\">" % [ @display[:edge_color], @display[:edge_color] ]

    svg << "<title>%s</title>" % @name

    if( @graph.directed? )
        svg << "<defs>"
        svg << "\t<marker id=\"marker_arrow\" markerWidth=\"10\" markerHeight=\"10\" refX=\"10\" refY=\"5\" orient=\"auto\">"
        svg << "\t\t<path d=\"M2,2 L2,10 L10,6 L2,2\"/>"
        svg << "\t</marker>"
        svg << "</defs>"
    end

    svg << "\t<polyline points=\""

    @display[:points_x].each_index do | i |
        svg << "%f,%f " % [ @display[:points_x][i], @display[:points_y][i] ]
    end

    svg << "\" "

    svg << "style=\"fill:none; stroke-width:%f; " % [ @display[:edge_width] ]

    if( @graph.directed? )
        svg << "marker-end:url(#marker_arrow); "
    end

    svg << "\"/>"
    
    if( not @label.nil? )
        x1 = @display[:points_x][@display[:points_x].length-1]
        x2 = @display[:points_x][@display[:points_x].length-2]
        y1 = @display[:points_y][@display[:points_y].length-1]
        y2 = @display[:points_y][@display[:points_y].length-2]  
        x  = ( ( [x1,x2].max - [x1,x2].min ) / 2.0 ) + [x1,x2].min
        y  = ( ( [y1,y2].max - [y1,y2].min ) / 2.0 ) + [y1,y2].min
        svg << "<text text-anchor=\"middle\" x=\"%f\" y=\"%f\" " % [ x, y - (@graph.display[:font_size] * 2.0) ]
        svg << "style=\"font-family:%s;font-size:%dpt\"" % [ @graph.display[:font_name], @graph.display[:font_size] ]
        svg << ">"
        svg << "%s" % @graph.svg_escape( @label.to_s )
        svg << "</text>"
    end
    
    svg << "</g>"

    return svg
end
Tool" target="_parent">yard 0.9.20 (ruby-2.6.5).