GD-Graph3d

 view release on metacpan or  search on metacpan

lib/GD/Graph/lines3d.pm  view on Meta::CPAN

#==========================================================================
# Module: GD::Graph::lines3d
#
# Copyright (C) 1999,2001 Wadsack-Allen. All Rights Reserved.
#
# Based on GD::Graph::lines.pm,v 1.10 2000/04/15 mgjv
#          Copyright (c) 1995-1998 Martien Verbruggen
#
#--------------------------------------------------------------------------
# Date		Modification				                                 Author
# -------------------------------------------------------------------------
# 1999SEP18 Created 3D line chart class (this module)                   JAW
# 1999SEP19 Finished overwrite 1 style                                  JAW
# 1999SEP19 Polygon'd linewidth rendering                               JAW
# 2000SEP19 Converted to a GD::Graph class                              JAW
# 2000APR18 Modified for compatibility with GD::Graph 1.30              JAW
# 2000APR24 Fixed a lot of rendering bugs                               JAW
# 2000AUG19 Changed render code so lines have consitent width           JAW
# 2000AUG21 Added 3d shading                                            JAW
# 2000AUG24 Fixed shading top/botttom vs. postive/negative slope        JAW
# 2000SEP04 For single point "lines" made a short segment               JAW
# 2000OCT09 Fixed bug in rendering of legend                            JAW
#==========================================================================
# TODO
#		** The new mitred corners don't work well at data anomlies. Like
#		   the set (0,0,1,0,0,0,1,0,1) Looks really wrong!
#		* Write a draw_data_set that draws the line so they appear to pass 
#		  through one another. This means drawing a border edge at each 
#		  intersection of the data lines so the points of pass-through show.
#		  Probably want to draw all filled polygons, then run through the data 
#		  again finding intersections of line segments and drawing those edges.
#==========================================================================
package GD::Graph::lines3d;

use strict;
 
use GD;
use GD::Graph::axestype3d;
use Data::Dumper;

@GD::Graph::lines3d::ISA = qw( GD::Graph::axestype3d );
$GD::Graph::lines3d::VERSION = '0.63';

my $PI = 4 * atan2(1, 1);

my %Defaults = (
	# The depth of the line in their extrusion

	line_depth		=> 10,
);

sub initialise()
{
	my $self = shift;

	my $rc = $self->SUPER::initialise();

	while( my($key, $val) = each %Defaults ) { 
		$self->{$key} = $val 

		# *** [JAW]
		# Should we reset the depth_3d param based on the 
		# line_depth, numsets and overwrite parameters, here?
		#
	} # end while

	return $rc;
	
} # end initialize

sub set
{
	my $s = shift;
	my %args = @_;

	$s->{_set_error} = 0;

	for (keys %args) 
	{ 
		/^line_depth$/ and do 
		{
			$s->{line_depth} = $args{$_};

lib/GD/Graph/lines3d.pm  view on Meta::CPAN

		if( $mt != $mn ) {
			$this->{face}[2] = ($bn - $bt) / ($mt - $mn);
		} # end if
		$this->{face}[3] = $mt * $this->{face}[2] + $bt;
	} # end if


	# Make the top/bottom polygon
	my $poly = new GD::Polygon;
	if( ($ys-$ye)/($xe-$xs) > 1 ) {
		$poly->addPt( $prev->{face}[2], $prev->{face}[3] );
		$poly->addPt( $this->{face}[2], $this->{face}[3] );
		$poly->addPt( $this->{face}[2] + $self->{line_depth}, $this->{face}[3] - $self->{line_depth} );
		$poly->addPt( $prev->{face}[2] + $self->{line_depth}, $prev->{face}[3] - $self->{line_depth} );
		if( $self->{'3d_shading'} &&  $style == $clr ) {
			if( ($ys-$ye)/($xe-$xs) > 0 ) {
				$self->{graph}->filledPolygon( $poly, $self->{'3d_shadows'}[$clr] );
			} else {
				$self->{graph}->filledPolygon( $poly, $self->{'3d_highlights'}[$clr] );
			} # end if
		} else {
			$self->{graph}->filledPolygon( $poly, $style );
		} # end if
	} else {
		$poly->addPt( $prev->{face}[0], $prev->{face}[1] );
		$poly->addPt( $this->{face}[0], $this->{face}[1] );
		$poly->addPt( $this->{face}[0] + $self->{line_depth}, $this->{face}[1] - $self->{line_depth} );
		$poly->addPt( $prev->{face}[0] + $self->{line_depth}, $prev->{face}[1] - $self->{line_depth} );
		if( $self->{'3d_shading'} &&  $style == $clr ) {
			if( ($ys-$ye)/($xe-$xs) < 0 ) {
				$self->{graph}->filledPolygon( $poly, $self->{'3d_shadows'}[$clr] );
			} else {
				$self->{graph}->filledPolygon( $poly, $self->{'3d_highlights'}[$clr] );
			} # end if
		} else {
			$self->{graph}->filledPolygon( $poly, $style );
		} # end if
	} # end if
	$self->{graph}->polygon( $poly, $self->{fgci} );

	# *** This paints dashed and dotted patterns on the faces of
	#     the polygons. They don't look very good though. Would it
	#     be better to extrude the style as well as the lines?
	#     Otherwise could also be improved by using gdTiled instead of 
	#     gdStyled and making the tile a transform of the line style
	#     for each face. [JAW]

	# Make the face polygon
	$poly = new GD::Polygon;
	$poly->addPt( $prev->{face}[0], $prev->{face}[1] );
	$poly->addPt( $this->{face}[0], $this->{face}[1] );
	$poly->addPt( $this->{face}[2], $this->{face}[3] );
	$poly->addPt( $prev->{face}[2], $prev->{face}[3] );

	$self->{graph}->filledPolygon( $poly, $style );
	$self->{graph}->polygon( $poly, $self->{fgci} );

} # end draw line

# ----------------------------------------------------------
# Sub: draw_legend_marker
#
# Args: $dsn, $x, $y
#	$dsn	The dataset number to draw the marker for
#	$x  	The x position of the marker
#	$y  	The y position of the marker
#
# Description: Draws the legend marker for the specified 
# dataset number at the given coordinates
# ----------------------------------------------------------
# Date      Modification                              Author
# ----------------------------------------------------------
# 2000OCT06 Fixed rendering bugs                          JW
# ----------------------------------------------------------
sub draw_legend_marker
{
	my $self = shift;
	my ($n, $x, $y) = @_;

	my $ci = $self->set_clr($self->pick_data_clr($n));
	my $type = $self->pick_line_type($n);

	$y += int($self->{lg_el_height}/2);

	#  Joe Smith <jms@tardis.Tymnet.COM>
	local($self->{line_width}) = 2;    # Make these show up better

	$self->draw_line(
		{ coords => [$x, $y] }, 
		{ coords => [$x + $self->{legend_marker_width}, $y] }, 
		undef, 
		$type,
		$ci
	);

} # end draw_legend_marker

1;



( run in 2.197 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )