summaryrefslogtreecommitdiff
path: root/t/f_ticks_1.t
blob: d4220f5822726412f9ea71326ea003d35b855e02 (plain)
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
#!/usr/bin/perl -w
#
# Testprogram for f_x_ticks
#
#======================================================================

BEGIN { unshift @INC, 'lib', '../lib'}
use strict;
use Chart::LinesPoints;
use File::Temp 0.19;
my $samples = File::Temp->newdir();

print "1..1\n";

my @x_values      = ();    # real x values
my @y_values      = ();    # real y values
my @x_plot_values = ();    # x values for plot
my @y_plot_values = ();    # y values for plot

my $graphic;
my $min_x = -15;           # random start
my $max_x = 10;            # random stop
my $min_y;
my $max_y;

my $x;
my $y;

#------------------------------------------------------------------------------------
# Start
#------------------------------------------------------------------------------------

$x = $min_x;
for ( my $idx = 0 ; $x <= $max_x ; $idx += 0.1 )
{
    $x = $min_x + $idx;
    $x_values[$idx] = $x;
    $y_values[$idx] = cos( ( $x - $min_x ) );
}

undef $min_y;
undef $max_y;
for ( my $idx = 0 ; $idx <= $#x_values ; $idx++ )
{
    $x_plot_values[$idx] = $x_values[$idx] + $min_x;
    $y_plot_values[$idx] = $y_values[$idx];
    if ( !defined($min_y) )
    {
        $min_y = $y_values[$idx];
    }
    else
    {
        $min_y = ( $min_y < $y_values[$idx] ) ? $min_y : $y_values[$idx];
    }
    if ( !defined($max_y) )
    {
        $max_y = $y_values[$idx];
    }
    else
    {
        $max_y = ( $max_y > $y_values[$idx] ) ? $max_y : $y_values[$idx];
    }
}

#------------------------------------------------------------------------------------
# Make it
#------------------------------------------------------------------------------------

$graphic = Chart::LinesPoints->new( 750, 600 );
$graphic->set( 'brush_size' => 2 );

$graphic->add_dataset(@x_plot_values);

$graphic->add_dataset(@y_plot_values);

$graphic->set( 'min_val' => $min_y );
$graphic->set( 'max_val' => $max_y );

#$graphic -> set ('y_ticks' => 11 );

#$graphic -> set ('skip_x_ticks' => 100);
$graphic->set( 'pt_size'         => 2 );
$graphic->set( 'grey_background' => 'true' );
$graphic->set( 'graph_border'    => 18 );
$graphic->set( 'title'           => "f_tick example for x and y values" );
$graphic->set( 'y_grid_lines'    => 'false' );
$graphic->set( 'x_grid_lines'    => 'false' );
$graphic->set( 'x_ticks'         => 'vertical' );
$graphic->set( 'legend'          => 'none' );
$graphic->set( 'x_label'         => 'some x-values' );
$graphic->set( 'y_label'         => 'f = cos(g(x))' );

# use a special function to convert the x values to HH:MM:SS
$graphic->set( 'f_x_tick' => \&convert_to_real_x );

if ( $graphic->can('png') )
{
    my $picture_file = "$samples/f_ticks_1.png";
    $graphic->png($picture_file);
}

print "ok 1\n";

exit(0);

sub convert_to_real_x
{
    my $plot_x = shift;

    my $result = sprintf "%6.1f", $plot_x - $min_x;
    return ($result);
}