package Node; # # Graph topology node - gene@ology.net # use strict; use base qw( Entity ); sub new { my $proto = shift; my $class = ref $proto || $proto; my %args = @_; my $self = Entity->new(); $self->{_data} = $args{'data'} || {}; $self->{_x} = $args{'x'} || 0; $self->{_y} = $args{'y'} || 0; $self->{_total} = $args{'total'} || 0; bless $self, $class; $self->_init( \%args ); return $self; } sub x { my $self = shift; $self->{_x} = shift if @_; return $self->{_x}; } sub y { my $self = shift; $self->{_y} = shift if @_; return $self->{_y}; } sub position { my $self = shift; if( @_ ) { $self->x( shift ); $self->y( shift ); } return $self->x, $self->y; } sub total { my $self = shift; $self->{_total} = shift if @_; return $self->{_total}; } sub data { my $self = shift; $self->{_data} = shift if @_; return $self->{_data}; } sub _init { my( $self, $args ) = @_; $self->name( $args->{'name'} ); $self->size( $args->{'size'} ); return; } # Convert the total vs. individual weights into a nice polar coordinate system # with highest gravity at the center and angle based on relative proximity - a # "pseudo energy shell". # * In truth, I use a random angle until I can figure-out how to calculate # `relative proximity'. :-\ # sub get_coord { my( $self, $max ) = @_; my $weight = $max - $self->total; # Here is the frightningly lame, random positioning. :-( my $angle = rand 360; # Apply the polar transformation. my $x = $weight * cos $angle; my $y = $weight * sin $angle; # printf "w=%d, m=%d, a=%.2f => x=%.2f, y=%.2f\n", $weight, $max, $angle, $x, $y; return $x + $max, $y + $max; # return $weight, $max/2; # One linear dimension. } #--------------------# 1;