ofc_y_axis_base.php 2.2 KB

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