PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
PHP | 137 lines | 94 code | 19 blank | 24 comment | 13 complexity | 9557f7c7ffafcb8537856244863a971d 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) 2008 - 2012, Phoronix Media
  6. Copyright (C) 2008 - 2012, Michael Larabel
  7. pts_VerticalBarGraph.php: The vertical bar graph object that extends pts_Graph.php
  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_VerticalBarGraph extends pts_Graph
  20. {
  21. public function __construct(&$result_object, &$result_file = null)
  22. {
  23. parent::__construct($result_object, $result_file);
  24. if($result_file != null && $result_file instanceof pts_result_file)
  25. {
  26. $this->is_multi_way_comparison = $result_file->is_multi_way_comparison();
  27. }
  28. $this->i['min_identifier_size'] = 6;
  29. $this->i['identifier_width'] = -1;
  30. }
  31. protected function render_graph_pre_init()
  32. {
  33. // Do some common work to this object
  34. $identifier_count = count($this->graph_identifiers);
  35. $this->i['identifier_width'] = floor(($this->i['graph_left_end'] - $this->i['left_start']) / $identifier_count);
  36. $longest_string = pts_strings::find_longest_string($this->graph_identifiers);
  37. $width = $this->i['identifier_width'] - 4;
  38. $this->i['identifier_size'] = $this->text_size_bounds($longest_string, $this->i['identifier_size'], $this->i['min_identifier_size'], $width);
  39. if($this->i['identifier_size'] <= $this->i['min_identifier_size'])
  40. {
  41. $this->update_graph_dimensions($this->i['graph_width'], $this->i['graph_height'] + $this->text_string_width($longest_string, 9));
  42. }
  43. }
  44. protected function render_graph_identifiers()
  45. {
  46. $px_from_top_end = $this->i['graph_top_end'] + 5;
  47. $this->svg_dom->draw_svg_line($this->i['left_start'] + $this->i['identifier_width'], $this->i['graph_top_end'], $this->i['graph_left_end'] - ($this->i['graph_width'] % $this->i['identifier_width']), $this->i['graph_top_end'], self::$c['color']['notches'], 10, array('stroke-dasharray' => '1,' . ($this->i['identifier_width'] - 1)));
  48. foreach(array_keys($this->graph_identifiers) as $i)
  49. {
  50. $px_bound_left = $this->i['left_start'] + ($this->i['identifier_width'] * $i);
  51. $px_bound_right = $px_bound_left + $this->i['identifier_width'];
  52. if($i == (count($this->graph_identifiers) - 1) && $px_bound_right != $this->i['graph_left_end'])
  53. {
  54. $px_bound_right = $this->i['graph_left_end'];
  55. }
  56. if($this->i['identifier_size'] <= $this->i['min_identifier_size'])
  57. {
  58. $x = $px_bound_left + ceil($this->i['identifier_width'] / 2);
  59. $this->svg_dom->add_text_element($this->graph_identifiers[$i], array('x' => $x, 'y' => $px_from_top_end, 'font-size' => 9, 'fill' => self::$c['color']['headers'], 'text-anchor' => 'start', 'dominant-baseline' => 'middle', 'transform' => 'rotate(90 ' . $x . ' ' . $px_from_top_end . ')'));
  60. }
  61. else
  62. {
  63. $x = $px_bound_left + (($px_bound_right - $px_bound_left) * 0.5);
  64. $this->svg_dom->add_text_element($this->graph_identifiers[$i], array('x' => $x, 'y' => ($px_from_top_end - 3), 'font-size' => $this->i['identifier_size'], 'fill' => self::$c['color']['headers'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
  65. }
  66. }
  67. }
  68. protected function render_graph_bars()
  69. {
  70. $bar_count = count($this->graph_data);
  71. $separator_width = ($a = (8 - (floor($bar_count / 2) * 2))) > 0 ? $a : 0;
  72. $bar_width = floor(($this->i['identifier_width'] - $separator_width - ($bar_count * $separator_width)) / $bar_count);
  73. for($i_o = 0; $i_o < $bar_count; $i_o++)
  74. {
  75. $paint_color = $this->get_paint_color((isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null));
  76. foreach(array_keys($this->graph_data[$i_o]) as $i)
  77. {
  78. $value = pts_math::set_precision($this->graph_data[$i_o][$i], 2);
  79. $graph_size = round(($value / $this->i['graph_max_value']) * ($this->i['graph_top_end'] - $this->i['top_start']));
  80. $value_plot_top = max($this->i['graph_top_end'] + 1 - $graph_size, 1);
  81. $px_bound_left = $this->i['left_start'] + ($this->i['identifier_width'] * $i) + ($bar_width * $i_o) + ($separator_width * ($i_o + 1));
  82. $px_bound_right = $px_bound_left + $bar_width;
  83. $title_tooltip = $this->graph_identifiers[$i] . ': ' . $value;
  84. $run_std_deviation = isset($this->graph_data_raw[$i_o][$i]) ? pts_math::standard_deviation(pts_strings::colon_explode($this->graph_data_raw[$i_o][$i])) : 0;
  85. if($run_std_deviation > 0)
  86. {
  87. $title_tooltip .= ' || ' . pts_math::set_precision($run_std_deviation, 1) . ' STD';
  88. }
  89. $this->svg_dom->add_element('rect', array('x' => ($px_bound_left + 1), 'y' => $value_plot_top, 'width' => $bar_width, 'height' => ($this->i['graph_top_end'] - $value_plot_top), 'fill' => (in_array($this->graph_identifiers[$i], $this->value_highlights) ? self::$c['color']['alert'] : $paint_color), 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1, 'xlink:title' => $title_tooltip));
  90. if(($px_bound_right - $px_bound_left) < 15)
  91. {
  92. // The bars are too skinny to be able to plot anything on them
  93. continue;
  94. }
  95. $x = $px_bound_left + (($px_bound_right - $px_bound_left) / 2);
  96. if($graph_size > 18)
  97. {
  98. $this->svg_dom->add_text_element($value, array('x' => $x, 'y' => ($value_plot_top + 2), 'font-size' => floor(self::$c['size']['bars'] * 0.9), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
  99. }
  100. else
  101. {
  102. // Make things more compact
  103. $this->svg_dom->add_text_element($value, array('x' => $x, 'y' => ($value_plot_top + 2), 'font-size' => floor(self::$c['size']['bars'] * 0.6), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
  104. }
  105. }
  106. }
  107. // write a new line along the bottom since the draw_rectangle_with_border above had written on top of it
  108. $this->svg_dom->draw_svg_line($this->i['left_start'], $this->i['graph_top_end'], $this->i['graph_left_end'], $this->i['graph_top_end'], self::$c['color']['notches'], 1);
  109. }
  110. protected function render_graph_result()
  111. {
  112. $this->render_graph_bars();
  113. }
  114. }
  115. ?>