1 | <?php
|
---|
2 |
|
---|
3 | class y_axis_base
|
---|
4 | {
|
---|
5 | function y_axis_base(){}
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @param $s as integer, thickness of the Y axis line
|
---|
9 | */
|
---|
10 | function set_stroke( $s )
|
---|
11 | {
|
---|
12 | $this->stroke = $s;
|
---|
13 | }
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * @param $val as integer. The length of the ticks in pixels
|
---|
17 | */
|
---|
18 | function set_tick_length( $val )
|
---|
19 | {
|
---|
20 | $tmp = 'tick-length';
|
---|
21 | $this->$tmp = $val;
|
---|
22 | }
|
---|
23 |
|
---|
24 | function set_colours( $colour, $grid_colour )
|
---|
25 | {
|
---|
26 | $this->set_colour( $colour );
|
---|
27 | $this->set_grid_colour( $grid_colour );
|
---|
28 | }
|
---|
29 |
|
---|
30 | function set_colour( $colour )
|
---|
31 | {
|
---|
32 | $this->colour = $colour;
|
---|
33 | }
|
---|
34 |
|
---|
35 | function set_grid_colour( $colour )
|
---|
36 | {
|
---|
37 | $tmp = 'grid-colour';
|
---|
38 | $this->$tmp = $colour;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Set min and max values, also (optionally) set the steps value.
|
---|
43 | * You can reverse the chart by setting min larger than max, e.g. min = 10
|
---|
44 | * and max = 0.
|
---|
45 | *
|
---|
46 | * @param $min as integer
|
---|
47 | * @param $max as integer
|
---|
48 | * @param $steps as integer.
|
---|
49 | */
|
---|
50 | function set_range( $min, $max, $steps=1 )
|
---|
51 | {
|
---|
52 | $this->min = $min;
|
---|
53 | $this->max = $max;
|
---|
54 | $this->set_steps( $steps );
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Sugar for set_range
|
---|
59 | */
|
---|
60 | function range( $min, $max, $steps=1 )
|
---|
61 | {
|
---|
62 | $this->set_range( $min, $max, $steps );
|
---|
63 | return $this;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * @param $off as Boolean. If true the Y axis is nudged up half a step.
|
---|
68 | */
|
---|
69 | function set_offset( $off )
|
---|
70 | {
|
---|
71 | $this->offset = $off?1:0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * @param $y_axis_labels as an y_axis_labels object
|
---|
76 | * Use this to customize the labels (colour, font, etc...)
|
---|
77 | */
|
---|
78 | function set_labels( $y_axis_labels )
|
---|
79 | {
|
---|
80 | $this->labels = $y_axis_labels;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Pass in some text for each label. This can contain magic variables "#val#" which
|
---|
85 | * will get replaced with the value for that Y axis label. Useful for:
|
---|
86 | * - "£#val#"
|
---|
87 | * - "#val#%"
|
---|
88 | * - "#val# million"
|
---|
89 | *
|
---|
90 | * @param $text as string.
|
---|
91 | */
|
---|
92 | function set_label_text( $text )
|
---|
93 | {
|
---|
94 | $tmp = new y_axis_labels();
|
---|
95 | $tmp->set_text( $text );
|
---|
96 | $this->labels = $tmp;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * @param $steps as integer.
|
---|
101 | *
|
---|
102 | * Only show every $steps label, e.g. every 10th
|
---|
103 | */
|
---|
104 | function set_steps( $steps )
|
---|
105 | {
|
---|
106 | $this->steps = $steps;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Make the labels show vertical
|
---|
111 | */
|
---|
112 | function set_vertical()
|
---|
113 | {
|
---|
114 | $this->rotate = "vertical";
|
---|
115 | }
|
---|
116 | }
|
---|