PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/phoronix-test-suite/pts-core/objects/pts_Graph/pts_TestCountPassGraph.php

#
PHP | 127 lines | 89 code | 18 blank | 20 comment | 12 complexity | 4e265d6af13f9243fc9e831dfaadfca3 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. Phoronix Test Suite
  4. URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
  5. Copyright (C) 2009 - 2012, Phoronix Media
  6. Copyright (C) 2009 - 2012, Michael Larabel
  7. pts_PassFailGraph.php: An abstract graph object extending pts_Graph for showing results in a pass/fail scenario.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. class pts_TestCountPassGraph extends pts_Graph
  20. {
  21. public function __construct(&$result_object, &$result_file = null)
  22. {
  23. parent::__construct($result_object, $result_file);
  24. $this->i['hide_y_title'] = true;
  25. $this->i['graph_value_type'] = 'ABSTRACT';
  26. $this->i['hide_graph_identifiers'] = true;
  27. }
  28. protected function render_graph_passcount()
  29. {
  30. $identifier_count = count($this->graph_identifiers);
  31. $vertical_border = 20;
  32. $horizontal_border = 14;
  33. $heading_height = 24;
  34. $graph_width = $this->i['graph_left_end'] - $this->i['left_start'] - ($horizontal_border * 2);
  35. $graph_height = $this->i['graph_top_end'] - $this->i['top_start'] - ($vertical_border * 2) - $heading_height;
  36. $line_height = floor($graph_height / $identifier_count);
  37. $paint_color = $this->get_paint_color('PASS_COUNT');
  38. $main_width = floor($graph_width * .24);
  39. $main_font_size = self::$c['size']['bars'];
  40. $main_greatest_length = pts_strings::find_longest_string($this->graph_identifiers);
  41. $width = $main_width - 8;
  42. $height = $line_height - 4;
  43. $main_font_size = $this->text_size_bounds($main_greatest_length, $main_font_size, 4, $width, $height);
  44. if(($new_size = $this->text_string_width($main_greatest_length, $main_font_size)) < ($main_width - 12))
  45. {
  46. $main_width = $new_size + 10;
  47. }
  48. $identifiers_total_width = $graph_width - $main_width - 2;
  49. $headings = pts_strings::comma_explode($this->graph_y_title);
  50. $identifiers_width = floor($identifiers_total_width / count($headings));
  51. $headings_font_size = self::$c['size']['bars'];
  52. while(($this->text_string_width(pts_strings::find_longest_string($headings), $headings_font_size) > ($identifiers_width - 2)) || $this->text_string_height($this->i['graph_max_value'], $headings_font_size) > ($line_height - 4))
  53. {
  54. $headings_font_size -= 0.5;
  55. }
  56. for($j = 0; $j < count($this->graph_data[0]); $j++)
  57. {
  58. $results = array_reverse(pts_strings::comma_explode($this->graph_data[0][$j]));
  59. $line_ttf_height = $this->text_string_height('AZ@![]()@|_', self::$c['size']['bars']);
  60. for($i = 0; $i < count($headings) && $i < count($results); $i++)
  61. {
  62. $this_bottom_end = $this->i['top_start'] + $vertical_border + (($j + 1) * $line_height) + $heading_height + 1;
  63. if($this_bottom_end >= $this->i['graph_top_end'] - $vertical_border)
  64. {
  65. $this_bottom_end = $this->i['graph_top_end'] - $vertical_border - 1;
  66. }
  67. else if($j == (count($this->graph_data[0]) - 1) && $this_bottom_end < $this->i['graph_top_end'] - $vertical_border)
  68. {
  69. $this_bottom_end = $this->i['graph_top_end'] - $vertical_border - 1;
  70. }
  71. $x = $this->i['graph_left_end'] - $horizontal_border - ($i * $identifiers_width);
  72. $y = $this->i['top_start'] + $vertical_border + ($j * $line_height) + $heading_height;
  73. $this->svg_dom->add_element('rect', array('x' => $x, 'y' => $y, 'width' => $identifiers_width, 'height' => ($this_bottom_end - $y), 'fill' => $paint_color));
  74. $x = $this->i['graph_left_end'] - $horizontal_border - ($i * $identifiers_width) - ($identifiers_width * 0.5);
  75. $y = $this->i['top_start'] + $vertical_border + ($j * $line_height) + $heading_height + ($line_height / 2) - ($line_ttf_height / 2);
  76. $this->svg_dom->add_text_element($results[$i], array('x' => $x, 'y' => $y, 'font-size' => self::$c['size']['bars'], 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
  77. }
  78. }
  79. $headings = array_reverse($headings);
  80. $line_ttf_height = $this->text_string_height('AZ@![]()@|_', $headings_font_size);
  81. for($i = 0; $i < count($headings); $i++)
  82. {
  83. $this->svg_dom->draw_svg_line($this->i['graph_left_end'] - $horizontal_border - (($i + 1) * $identifiers_width), $this->i['top_start'] + $vertical_border, $this->i['graph_left_end'] - $horizontal_border - (($i + 1) * $identifiers_width), $this->i['graph_top_end'] - $vertical_border, self::$c['color']['body_light']);
  84. $x = $this->i['graph_left_end'] - $horizontal_border - ($i * $identifiers_width) - ($identifiers_width * 0.5);
  85. $y = $this->i['top_start'] + $vertical_border + ($heading_height / 2) - ($line_ttf_height / 2);
  86. $this->svg_dom->add_text_element($headings[$i], array('x' => 0.5, 'y' => 0, 'font-size' => $headings_font_size, 'fill' => self::$c['color']['headers'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
  87. }
  88. $line_ttf_height = $this->text_string_height('AZ@![]()@|_', $main_font_size);
  89. for($i = 0; $i < count($this->graph_identifiers); $i++)
  90. {
  91. $this->svg_dom->draw_svg_line($this->i['left_start'] + $horizontal_border, $this->i['top_start'] + $vertical_border + ($i * $line_height) + $heading_height, $this->i['graph_left_end'] - $horizontal_border, $this->i['top_start'] + $vertical_border + ($i * $line_height) + $heading_height, self::$c['color']['body_light']);
  92. $x = $this->i['left_start'] + $horizontal_border + $main_width;
  93. $y = $this->i['top_start'] + $vertical_border + ($i * $line_height) + $heading_height + ($line_height / 2) - 2;
  94. $this->svg_dom->add_text_element($this->graph_identifiers[$i], array('x' => $x, 'y' => $y, 'font-size' => $main_font_size, 'fill' => self::$c['color']['headers'], 'text-anchor' => 'end', 'dominant-baseline' => 'middle'));
  95. }
  96. $this->svg_dom->draw_svg_line($this->i['left_start'] + $horizontal_border, $this->i['top_start'] + $vertical_border, $this->i['graph_left_end'] - $horizontal_border, $this->i['top_start'] + $vertical_border, self::$c['color']['body_light']);
  97. $this->svg_dom->draw_svg_line($this->i['left_start'] + $horizontal_border, $this->i['top_start'] + $vertical_border, $this->i['left_start'] + $horizontal_border, $this->i['graph_top_end'] - $vertical_border, self::$c['color']['body_light']);
  98. $this->svg_dom->draw_svg_line($this->i['graph_left_end'] - $horizontal_border, $this->i['top_start'] + $vertical_border, $this->i['graph_left_end'] - $horizontal_border, $this->i['graph_top_end'] - $vertical_border, self::$c['color']['body_light']);
  99. $this->svg_dom->draw_svg_line($this->i['left_start'] + $horizontal_border, $this->i['graph_top_end'] - $vertical_border, $this->i['graph_left_end'] - $horizontal_border, $this->i['graph_top_end'] - $vertical_border, self::$c['color']['body_light']);
  100. }
  101. protected function render_graph_result()
  102. {
  103. $this->render_graph_passcount();
  104. }
  105. }
  106. ?>