File: calAxestype3d.pm

package info (click to toggle)
calamaris 2.99.4.0-11
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 808 kB
  • ctags: 118
  • sloc: perl: 7,512; sh: 217; makefile: 37
file content (800 lines) | stat: -rw-r--r-- 23,381 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
#==========================================================================
# Module: calamaris::calAxestype3d.pm
#
# Copyright
#
# calAxestype3d.pm Copyright (c) 2004 Michael Pophal based on
# GD::Graph Copyright (c) 1999 Martien Verbruggen.
# (http://search.cpan.org/~mverb/GDGraph-1.43/Graph.pm)
#
# All rights reserved. This package is free software; you can redistribute
# it and/or modify it under the same terms as Perl itself.
#
# Acknowledgements
#
# Thanks to Martien Verbruggen's ingenious tool GD::Graph, which is basically
# the same, except some small changes needed for calamaris.
#==========================================================================
#
# Adapted to calamaris by: (c) 2004 Michael Pophal
#
# Based on:
#          GD::Graph::axestype3d.pm,v 1.21 2000/04/15 08:59:36 mgjv
#          http://search.cpan.org/~mverb/GDGraph-1.43/Graph.pm
#          Copyright (c) 1995-1998 Martien Verbruggen
#
#--------------------------------------------------------------------------
#
#   Name:
#       calamaris::calAxestype3d.pm
#
# $Id: calAxestype3d.pm,v 3.2 2004/09/15 21:02:13 cord Exp $
#
#--------------------------------------------------------------------------
# Date		Modification				         Author
# -------------------------------------------------------------------------
# 2004AUG30 Adapted to calamaris				 staehler
#==========================================================================
package calamaris::calAxestype3d;

use strict;
 
use lib '/usr/local';
use GD::Graph;
use calamaris::calAxestype;
use GD::Graph::utils qw(:all);
use GD::Graph::colour qw(:colours);
use Carp;

@calamaris::calAxestype3d::ISA = qw(calamaris::calAxestype);
$calamaris::calAxestype3d::VERSION = '0.63';

# Commented inheritance from GD::Graph::axestype unless otherwise noted.

use constant PI => 4 * atan2(1,1);

my %Defaults = (
	depth_3d           => 20,
	'3d_shading'       => 1,

	# the rest are inherited
);

# Inherit _has_default 


# Can't inherit initialise, because %Defaults is referenced file-
# specific, not class specific.
sub initialise
{
	my $self = shift;

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

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

	return $rc;
} # end initialise

# PUBLIC
# Inherit plot
# Inherit set
# Inherit setup_text
# Inherit set_x_label_font
# Inherit set_y_label_font
# Inherit set_x_axis_font
# Inherit set_y_axis_font
# Inherit set_legend
# Inherit set_legend_font



# ----------------------------------------------------------
# Sub: init_graph
#
# Args: (None)
#
# Description: 
# Override GD::Graph::init_graph to add 3d shading colors, 
# if requested
#
# [From GD::Graph]
# Initialise the graph output canvas, setting colours (and 
# getting back index numbers for them) setting the graph to 
# transparent, and interlaced, putting a logo (if defined) 
# on there.
# ----------------------------------------------------------
# Date      Modification                              Author
# ----------------------------------------------------------
# 20Aug2000 Added to support 3d graph extensions          JW
# ----------------------------------------------------------
sub init_graph {
	my $self = shift;

	# Sets up the canvas and color palette
	$self->SUPER::init_graph( @_ );	

	# Now create highlights and showdows for each color
	# in the palette
	if( $self->{'3d_shading'} ) {
		$self->{'3d_highlights'} = [];
		$self->{'3d_shadows'} = [];
		$self->{'3d_highlights'}[$self->{bgci}] = $self->set_clr( $self->_brighten( _rgb($self->{bgclr}) ) );
		$self->{'3d_shadows'}[$self->{bgci}]    = $self->set_clr( $self->_darken( _rgb($self->{bgclr}) ) );

		$self->{'3d_highlights'}[$self->{fgci}] = $self->set_clr( $self->_brighten( _rgb($self->{fgclr}) ) );
		$self->{'3d_shadows'}[$self->{fgci}]    = $self->set_clr( $self->_darken( _rgb($self->{fgclr}) ) );

		$self->{'3d_highlights'}[$self->{tci}] = $self->set_clr( $self->_brighten( _rgb($self->{textclr}) ) );
		$self->{'3d_shadows'}[$self->{tci}]    = $self->set_clr( $self->_darken( _rgb($self->{textclr}) ) );

		$self->{'3d_highlights'}[$self->{lci}] = $self->set_clr( $self->_brighten( _rgb($self->{labelclr}) ) );
		$self->{'3d_shadows'}[$self->{lci}]    = $self->set_clr( $self->_darken( _rgb($self->{labelclr}) ) );

		$self->{'3d_highlights'}[$self->{alci}] = $self->set_clr( $self->_brighten( _rgb($self->{axislabelclr}) ) );
		$self->{'3d_shadows'}[$self->{alci}]    = $self->set_clr( $self->_darken( _rgb($self->{axislabelclr}) ) );

		$self->{'3d_highlights'}[$self->{acci}] = $self->set_clr( $self->_brighten( _rgb($self->{accentclr}) ) );
		$self->{'3d_shadows'}[$self->{acci}]    = $self->set_clr( $self->_darken( _rgb($self->{accentclr}) ) );

		$self->{'3d_highlights'}[$self->{valuesci}] = $self->set_clr( $self->_brighten( _rgb($self->{valuesclr}) ) );
		$self->{'3d_shadows'}[$self->{valuesci}]    = $self->set_clr( $self->_darken( _rgb($self->{valuesclr}) ) );

		$self->{'3d_highlights'}[$self->{legendci}] = $self->set_clr( $self->_brighten( _rgb($self->{legendclr}) ) );
		$self->{'3d_shadows'}[$self->{legendci}]    = $self->set_clr( $self->_darken( _rgb($self->{legendclr}) ) );

		if( $self->{boxclr} ) {
			$self->{'3d_highlights'}[$self->{boxci}] = $self->set_clr( $self->_brighten( _rgb($self->{boxclr}) ) );
			$self->{'3d_shadows'}[$self->{boxci}]    = $self->set_clr( $self->_darken( _rgb($self->{boxclr}) ) );
		} # end if
	} # end if

	return $self;
} # end init_graph


# PRIVATE

# ----------------------------------------------------------
# Sub: _brighten
#
# Args: $r, $g, $b
#	$r, $g, $b	The Red, Green, and Blue components of a color
#
# Description: Brightens the color by adding white
# ----------------------------------------------------------
# Date      Modification                              Author
# ----------------------------------------------------------
# 21AUG2000 Created to build 3d highlights table          JW
# ----------------------------------------------------------
sub _brighten {
	my $self = shift;
	my( $r, $g, $b ) = @_;
	my $p = ($r + $g + $b) / 70;
	$p = 3 if $p < 3;
	my $f = _max( $r / $p, _max( $g / $p, $b / $p ) );
	$r = _min( 255, int( $r + $f ) );
	$g = _min( 255, int( $g + $f ) );
	$b = _min( 255, int( $b + $f ) );
	return( $r, $g, $b );
} # end _brighten

# ----------------------------------------------------------
# Sub: _darken
#
# Args: $r, $g, $b
#	$r, $g, $b	The Red, Green, and Blue components of a color
#
# Description: Darkens the color by adding black
# ----------------------------------------------------------
# Date      Modification                              Author
# ----------------------------------------------------------
# 21AUG2000 Created to build 3d shadows table          JW
# ----------------------------------------------------------
sub _darken {
	my $self = shift;
	my( $r, $g, $b ) = @_;
	my $p = ($r + $g + $b) / 70;
	$p = 3 if $p < 3;
	my $f = _max( $r / $p, _max( $g / $p, $b / $p) );
	$r = _max( 0, int( $r - $f ) );
	$g = _max( 0, int( $g - $f ) );
	$b = _max( 0, int( $b - $f ) );
	return( $r, $g, $b );
} # end _darken


# inherit check_data from GD::Graph

# [JAW] Setup boundaries as parent, the adjust for 3d extrusion
sub _setup_boundaries
{
	my $self = shift;

	$self->SUPER::_setup_boundaries();

	# adjust for top of 3-d extrusion
	$self->{top} += $self->{depth_3d};

	return $self->_set_error('Vertical size too small')
		if $self->{bottom} <= $self->{top};
	
	# adjust for right of 3-d extrusion
	$self->{right} -= $self->{depth_3d};

	return $self->_set_error('Horizontal size too small')	
		if $self->{right} <= $self->{left};

	return $self;
} # end _setup_boundaries

# [JAW] Determine 3d-extrusion depth, then call parent
sub setup_coords
{
	my $self = shift;

	# Calculate the 3d-depth of the graph
	# Note this sets a minimum depth of ~20 pixels
#	if (!defined $self->{x_tick_number}) {
		my $depth = _max( $self->{bar_depth}, $self->{line_depth} );
		if( $self->{overwrite} == 1 ) {
			$depth *= $self->{_data}->num_sets();
		} # end if
	   $self->{depth_3d} = _max( $depth, $self->{depth_3d} );
#	} # end if

	$self->SUPER::setup_coords();

	return $self;
} # end setup_coords

# Inherit create_y_labels
# Inherit get_x_axis_label_height
# Inherit create_x_labels
# inherit open_graph from GD::Graph
# Inherit draw_text

# [JAW] Draws entire bounding cube for 3-d extrusion
sub draw_axes
{
	my $s = shift;
	my $g = $s->{graph};

	my ($l, $r, $b, $t) = 
		( $s->{left}, $s->{right}, $s->{bottom}, $s->{top} );
	my $depth = $s->{depth_3d};

	if ( $s->{box_axis} ) {
		# -- Draw a bounding box
		if( $s->{boxci} ) {
			# -- Fill the box with color
			# Back box
			$g->filledRectangle($l+$depth+1, $t-$depth+1, $r+$depth-1, $b-$depth-1, $s->{boxci});

			# Left side
			my $poly = new GD::Polygon;
			$poly->addPt( $l, $t );
			$poly->addPt( $l + $depth, $t - $depth );
			$poly->addPt( $l + $depth, $b - $depth );
			$poly->addPt( $l, $b );
			if( $s->{'3d_shading'} ) {
				$g->filledPolygon( $poly, $s->{'3d_shadows'}[$s->{boxci}] );
			} else {
				$g->filledPolygon( $poly, $s->{boxci} );
			} # end if

			# Bottom
			$poly = new GD::Polygon;
			$poly->addPt( $l, $b );
			$poly->addPt( $l + $depth, $b - $depth );
			$poly->addPt( $r + $depth, $b - $depth );
			$poly->addPt( $r, $b );
			if( $s->{'3d_shading'} ) {
				$g->filledPolygon( $poly, $s->{'3d_highlights'}[$s->{boxci}] );
			} else {
				$g->filledPolygon( $poly, $s->{boxci} );
			} # end if
		} # end if

		# -- Draw the box frame
		
		# Back box
		$g->rectangle($l+$depth, $t-$depth, $r+$depth, $b-$depth, $s->{fgci});
		
		# Connecting frame
		$g->line($l, $t, $l + $depth, $t - $depth, $s->{fgci});
		$g->line($r, $t, $r + $depth, $t - $depth, $s->{fgci});
		$g->line($l, $b, $l + $depth, $b - $depth, $s->{fgci});
		$g->line($r, $b, $r + $depth, $b - $depth, $s->{fgci});

		# Front box
		$g->rectangle($l, $t, $r, $b, $s->{fgci});

	} else {
		if( $s->{boxci} ) {
			# -- Fill the background box with color
			# Back box
			$g->filledRectangle($l+$depth+1, $t-$depth+1, $r+$depth-1, $b-$depth-1, $s->{boxci});

			# Left side
			my $poly = new GD::Polygon;
			$poly->addPt( $l, $t );
			$poly->addPt( $l + $depth, $t - $depth );
			$poly->addPt( $l + $depth, $b - $depth );
			$poly->addPt( $l, $b );
			if( $s->{'3d_shading'} ) {
				$g->filledPolygon( $poly, $s->{'3d_shadows'}[$s->{boxci}] );
			} else {
				$g->filledPolygon( $poly, $s->{boxci} );
			} # end if

			# Bottom
			$poly = new GD::Polygon;
			$poly->addPt( $l, $b );
			$poly->addPt( $l + $depth, $b - $depth );
			$poly->addPt( $r + $depth, $b - $depth );
			$poly->addPt( $r, $b );
			if( $s->{'3d_shading'} ) {
				$g->filledPolygon( $poly, $s->{'3d_highlights'}[$s->{boxci}] );
			} else {
				$g->filledPolygon( $poly, $s->{boxci} );
			} # end if
		} # end if
		# -- Draw the frame only for back & sides
		
		# Back box
		$g->rectangle($l + $depth, $t - $depth, $r + $depth, $b - $depth, $s->{fgci});

		# Y axis
		my $poly = new GD::Polygon;
		$poly->addPt( $l, $t );
		$poly->addPt( $l, $b );
		$poly->addPt( $l + $depth, $b - $depth );
		$poly->addPt( $l + $depth, $t - $depth );
		$g->polygon( $poly, $s->{fgci} );
		
		# X axis
		if( !$s->{zero_axis_only} ) {
			$poly = new GD::Polygon;
			$poly->addPt( $l, $b );
			$poly->addPt( $r, $b );
			$poly->addPt( $r + $depth, $b - $depth );
			$poly->addPt( $l + $depth, $b - $depth );
			$g->polygon( $poly, $s->{fgci} );
		} # end if
		
		# Second Y axis
		if( $s->{two_axes} ){
			$poly = new GD::Polygon;
			$poly->addPt( $r, $b );
			$poly->addPt( $r, $t );
			$poly->addPt( $r + $depth, $t - $depth );
			$poly->addPt( $r + $depth, $b - $depth );
			$g->polygon( $poly, $s->{fgci} );
		} # end if
	} # end if

	# Zero axis
	if ($s->{zero_axis} or $s->{zero_axis_only})	{
		my ($x, $y) = $s->val_to_pixel(0, 0, 1);
		my $poly = new GD::Polygon;
		$poly->addPt( $l, $y );
		$poly->addPt( $r, $y );
		$poly->addPt( $r + $depth, $y - $depth );
		$poly->addPt( $l + $depth, $y - $depth);
		$g->polygon( $poly, $s->{fgci} );
	} # end if
	
} # end draw_axes

# [JAW] Draws ticks and values for y axes in 3d extrusion
# Modified from MVERB source
sub draw_y_ticks
{
	my $self = shift;

	for my $t (0 .. $self->{y_tick_number}) 
	{
		for my $a (1 .. ($self->{two_axes} + 1)) 
		{
			my $value = $self->{y_values}[$a][$t];
			my $label = $self->{y_labels}[$a][$t];
			
			my ($x, $y) = $self->val_to_pixel(0, $value, $a);
			$x = ($a == 1) ? $self->{left} : $self->{right};

			# CONTRIB Jeremy Wadsack
			# Draw on the back of the extrusion
			$x += $self->{depth_3d};
			$y -= $self->{depth_3d};

			if ($self->{y_long_ticks}) 
			{
				$self->{graph}->line( 
					$x, $y, 
					$x + $self->{right} - $self->{left}, $y, 
					$self->{fgci} 
				) unless ($a-1);
				# CONTRIB Jeremy Wadsack
				# Draw conector ticks
				$self->{graph}->line( $x - $self->{depth_3d}, 
				                      $y + $self->{depth_3d},
				                      $x, 
				                      $y, 
				                      $self->{fgci} 
				) unless ($a-1);
			} 
			else 
			{
				$self->{graph}->line( 
					$x, $y, 
					$x + (3 - 2 * $a) * $self->{y_tick_length}, $y, 
					$self->{fgci} 
				);
				# CONTRIB Jeremy Wadsack
				# Draw conector ticks
				$self->{graph}->line( $x - $self->{depth_3d}, 
				                      $y + $self->{depth_3d},
				                      $x - $self->{depth_3d} + (3 - 2 * $a) * $self->{y_tick_length}, 
				                      $y + $self->{depth_3d} - (3 - 2 * $a) * $self->{y_tick_length},
				                      $self->{fgci} 
				);
			}

			next 
				if $t % ($self->{y_label_skip}) || ! $self->{y_plot_values};

			$self->{gdta_y_axis}->set_text($label);
			$self->{gdta_y_axis}->set_align('center', 
				$a == 1 ? 'right' : 'left');
			$x -= (3 - 2 * $a) * $self->{axis_space};
			
			# CONTRIB Jeremy Wadsack
			# Subtract 3-d extrusion width from left axis label
			# (it was added for ticks)
			$x -= (2 - $a) * $self->{depth_3d};

			# CONTRIB Jeremy Wadsack
			# Add 3-d extrusion height to label
			# (it was subtracted for ticks)
			$y += $self->{depth_3d};

			$self->{gdta_y_axis}->draw($x, $y);
			
		} # end foreach
	} # end foreach

	return $self;

} # end draw_y_ticks

# [JAW] Darws ticks and values for x axes wih 3d extrusion
# Modified from MVERB source
sub draw_x_ticks
{
	my $self = shift;

	for (my $i = 0; $i < $self->{_data}->num_points; $i++) 
	{
		my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1);

		$y = $self->{bottom} unless $self->{zero_axis_only};

		# CONTRIB  Damon Brodie for x_tick_offset
		next if (!$self->{x_all_ticks} and 
				($i - $self->{x_tick_offset}) % $self->{x_label_skip} and 
				$i != $self->{_data}->num_points - 1 
			);

		# CONTRIB Jeremy Wadsack
		# Draw on the back of the extrusion
		$x += $self->{depth_3d};
		$y -= $self->{depth_3d};

		if ($self->{x_ticks})
		{
			if ($self->{x_long_ticks})
			{
				# CONTRIB Jeremy Wadsack
				# Move up by 3d depth
				$self->{graph}->line( $x, 
				                      $self->{bottom} - $self->{depth_3d}, 
				                      $x, 
				                      $self->{top} - $self->{depth_3d},
				                      $self->{fgci});
				# CONTRIB Jeremy Wadsack
				# Draw conector ticks
				$self->{graph}->line( $x - $self->{depth_3d}, 
				                      $y + $self->{depth_3d},
				                      $x, 
				                      $y, 
				                      $self->{fgci} 
				);
			}
			else
			{
				$self->{graph}->line( $x, $y, $x, $y - $self->{x_tick_length}, $self->{fgci} );
				# CONTRIB Jeremy Wadsack
				# Draw conector ticks
				$self->{graph}->line( $x - $self->{depth_3d}, 
				                      $y + $self->{depth_3d},
				                      $x - $self->{depth_3d} + $self->{x_tick_length}, 
				                      $y + $self->{depth_3d} - $self->{x_tick_length},
				                      $self->{fgci} 
				);
			}
		}

		# CONTRIB Damon Brodie for x_tick_offset
		next if 
			($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and 
			$i != $self->{_data}->num_points - 1;

		$self->{gdta_x_axis}->set_text($self->{_data}->get_x($i));

		# CONTRIB Jeremy Wadsack
		# Subtract 3-d extrusion width from left label
		# Add 3-d extrusion height to left label
		# (they were changed for ticks)
		$x -= $self->{depth_3d};
		$y += $self->{depth_3d};

		my $yt = $y + $self->{axis_space};

		if ($self->{x_labels_vertical})
		{
			$self->{gdta_x_axis}->set_align('center', 'right');
			$self->{gdta_x_axis}->draw($x, $yt, PI/2);
		}
		else
		{
			$self->{gdta_x_axis}->set_align('top', 'center');
			$self->{gdta_x_axis}->draw($x, $yt);
		}
		
	} # end for

	return $self;

} # end draw_x_ticks


# CONTRIB Scott Prahl
# Assume x array contains equally spaced x-values
# and generate an appropriate axis
#
####
# 'True' numerical X axis addition 
# From: Gary Deschaines
#
# These modification to draw_x_ticks_number pass x-tick values to the
# val_to_pixel subroutine instead of x-tick indices when ture[sic] numerical
# x-axis mode is detected.  Also, x_tick_offset and x_label_skip are
# processed differently when true numerical x-axis mode is detected to
# allow labeled major x-tick marks and un-labeled minor x-tick marks.
#
# For example:
#
#      x_tick_number =>  14,
#      x_ticks       =>   1,
#      x_long_ticks  =>   1,
#      x_tick_length =>  -4,
#      x_min_value   => 100,
#      x_max_value   => 800,
#      x_tick_offset =>   2,
#      x_label_skip  =>   2,
#
#
#      ~         ~    ~    ~    ~    ~    ~    ~    ~    ~    ~    ~         ~
#      |         |    |    |    |    |    |    |    |    |    |    |         |
#   1 -|         |    |    |    |    |    |    |    |    |    |    |         |
#      |         |    |    |    |    |    |    |    |    |    |    |         |
#   0 _|_________|____|____|____|____|____|____|____|____|____|____|_________|
#                |    |    |    |    |    |    |    |    |    |    |
#               200       300       400       500       600       700
####
# [JAW] Added commented items for 3d rendering
# Based on MVERB source
sub draw_x_ticks_number
{
	my $self = shift;

	for my $i (0 .. $self->{x_tick_number})
	{
		my ($value, $x, $y);

 		if (defined($self->{x_min_value}) && defined($self->{x_max_value}))
 		{
			next if ($i - $self->{x_tick_offset}) < 0;
 			next if ($i + $self->{x_tick_offset}) > $self->{x_tick_number};
 			$value = $self->{x_values}[$i];
 			($x, $y) = $self->val_to_pixel($value, 0, 1);
 		}
 		else
 		{
			$value = ($self->{_data}->num_points - 1)
						* ($self->{x_values}[$i] - $self->{true_x_min})
						/ ($self->{true_x_max} - $self->{true_x_min});
 			($x, $y) = $self->val_to_pixel($value + 1, 0, 1);
 		}

		$y = $self->{bottom} unless $self->{zero_axis_only};

		# Draw on the back of the extrusion
		$x += $self->{depth_3d};
		$y -= $self->{depth_3d};

		if ($self->{x_ticks})
		{
			if ($self->{x_long_ticks})
			{
				# XXX This mod needs to be done everywhere ticks are
				# drawn
				if ( $self->{x_tick_length} >= 0 ) 
				{
					# Move up by 3d depth
					$self->{graph}->line( $x,
					                      $self->{bottom} - $self->{depth_3d}, 
												 $x, 
												 $self->{top} - $self->{depth_3d}, 
												 $self->{fgci});
				} 
				else 
				{
					$self->{graph}->line(
						$x, $self->{bottom} - $self->{x_tick_length}, 
						$x, $self->{top}, $self->{fgci});
				}
				# CONTRIB Jeremy Wadsack
				# Draw conector ticks
				$self->{graph}->line( $x - $self->{depth_3d}, 
				                      $y + $self->{depth_3d},
				                      $x, 
				                      $y, 
				                      $self->{fgci} 
				);
			}
			else
			{
				$self->{graph}->line($x, $y, 
					$x, $y - $self->{x_tick_length}, $self->{fgci} );
				# CONTRIB Jeremy Wadsack
				# Draw conector ticks
				$self->{graph}->line( $x - $self->{depth_3d}, 
				                      $y + $self->{depth_3d},
				                      $x, - $self->{depth_3d} + $self->{tick_length}, 
				                      $y, + $self->{depth_3d} - $self->{tick_length},
				                      $self->{fgci} 
				);
			} # end if -- x_long_ticks
		} # end if -- x_ticks

		# If we have to skip labels, we'll do it here.
		# Make sure to always draw the last one.
		next if $i % $self->{x_label_skip} && $i != $self->{x_tick_number};

		$self->{gdta_x_axis}->set_text($self->{x_labels}[$i]);

		# CONTRIB Jeremy Wadsack
		# Subtract 3-d extrusion width from left label
		# Add 3-d extrusion height to left label
		# (they were changed for ticks)
		$x -= $self->{depth_3d};
		$y += $self->{depth_3d};

		if ($self->{x_labels_vertical})
		{
			$self->{gdta_x_axis}->set_align('center', 'right');
			my $yt = $y + $self->{text_space}/2;
			$self->{gdta_x_axis}->draw($x, $yt, PI/2);
		}
		else
		{
			$self->{gdta_x_axis}->set_align('top', 'center');
			my $yt = $y + $self->{text_space}/2;
			$self->{gdta_x_axis}->draw($x, $yt);
		} # end if
	} # end for

	return $self;
	
} # end draw_x_tick_number

# Inherit draw_ticks
# Inherit draw_data
# Inherit draw_data_set
# Inherit set_max_min
# Inherit get_max_y
# Inherit get_min_y
# Inherit get_max_min_y_all
# Inherit _get_bottom
# Inherit val_to_pixel
# Inherit setup_legend


# [JW] Override draw_legend and reverse the drawing order
# if cumulate is enabled so legend matches data on chart
sub draw_legend
{
	my $self = shift;

	return unless defined $self->{legend};

	my $xl = $self->{lg_xs} + $self->{legend_spacing};
	my $y  = $self->{lg_ys} + $self->{legend_spacing} - 1;

	# If there's a frame, offset by the size and margin
	$xl += $self->{legend_frame_margin} + $self->{legend_frame_size} if $self->{legend_frame_size};
	$y += $self->{legend_frame_margin} + $self->{legend_frame_size} if $self->{legend_frame_size};

	my $i = 0;
	my $row = 1;
	my $x = $xl;	# start position of current element
	my @legends = @{$self->{legend}};
	my $i_step = 1;
	
	# If we are working in cumulate mode, then reverse the drawing order
	if( $self->{cumulate} ) {
		@legends = reverse @legends;
		$i = scalar(@legends);
		$i = $self->{_data}->num_sets if $self->{_data}->num_sets < $i;
		$i++;
		$i_step = -1;
	} # end if
	
	foreach my $legend (@legends)
	{
		$i += $i_step;

		# Legend for Pie goes over first set, and all points
		# Works in either direction
		last if $i > $self->{_data}->num_sets;
		last if $i < 1;

		my $xe = $x;	# position within an element

		next unless defined($legend) && $legend ne "";

		$self->draw_legend_marker($i, $xe, $y);

		$xe += $self->{legend_marker_width} + $self->{legend_spacing};
		my $ys = int($y + $self->{lg_el_height}/2 - $self->{lgfh}/2);

		$self->{gdta_legend}->set_text($legend);
		$self->{gdta_legend}->draw($xe, $ys);

		$x += $self->{lg_el_width};

		if (++$row > $self->{lg_cols})
		{
			$row = 1;
			$y += $self->{lg_el_height};
			$x = $xl;
		}
	}
	
	# If there's a frame, draw it now
	if( $self->{legend_frame_size} ) {
		$x = $self->{lg_xs} + $self->{legend_spacing};
		$y = $self->{lg_ys} + $self->{legend_spacing} - 1;
		
		for $i ( 0 .. $self->{legend_frame_size} - 1 ) {
			$self->{graph}->rectangle(
				$x + $i,
				$y + $i, 
				$x + $self->{lg_x_size} + 2 * $self->{legend_frame_margin} - $i - 1,
				$y + $self->{lg_y_size} + 2 * $self->{legend_frame_margin} - $i - 1,
				$self->{acci},
			);
		} # end for
	} # end if
	
}



# Inherit draw_legend_marker

1;