1<?php
2
3/*
4	Phoronix Test Suite
5	URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
6	Copyright (C) 2008 - 2019, Phoronix Media
7	Copyright (C) 2008 - 2019, Michael Larabel
8	pts_PassFailGraph.php: An abstract graph object extending pts_Graph for showing results in a pass/fail scenario.
9
10	This program is free software; you can redistribute it and/or modify
11	it under the terms of the GNU General Public License as published by
12	the Free Software Foundation; either version 3 of the License, or
13	(at your option) any later version.
14
15	This program is distributed in the hope that it will be useful,
16	but WITHOUT ANY WARRANTY; without even the implied warranty of
17	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18	GNU General Public License for more details.
19
20	You should have received a copy of the GNU General Public License
21	along with this program. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24class pts_graph_passfail extends pts_graph_core
25{
26	public function __construct(&$result_object, &$result_file = null, $extra_attributes = null)
27	{
28		parent::__construct($result_object, $result_file, $extra_attributes);
29		$this->i['hide_y_title'] = true;
30		$this->i['graph_value_type'] = 'ABSTRACT';
31		$this->i['hide_graph_identifiers'] = true;
32		$this->i['iveland_view'] = true;
33	}
34	protected function render_graph_passfail()
35	{
36		$identifier_count = $this->test_result->test_result_buffer->get_count();
37		$vertical_border = 20;
38		$horizontal_border = 14;
39		$heading_height = 24;
40		$graph_width = $this->i['graph_left_end'] - $this->i['left_start'] - ($horizontal_border * 2);
41		$graph_height = $this->i['graph_top_end'] - $this->i['top_start'] - ($vertical_border * 2) - $heading_height;
42		$line_height = floor($graph_height / $identifier_count);
43
44		$fail_color = $this->get_paint_color('FAIL');
45		$pass_color = $this->get_paint_color('PASS');
46
47		$main_width = floor($graph_width * .24);
48		$main_font_size = self::$c['size']['bars'];
49		$main_greatest_length = $this->test_result->test_result_buffer->get_longest_identifier();
50
51		$width = $main_width - 8;
52		$height = $line_height - 4;
53		$main_font_size = $this->text_size_bounds($main_greatest_length, $main_font_size, 4, $width, $height);
54
55		if(($new_size = $this->text_string_width($main_greatest_length, $main_font_size)) < ($main_width - 12))
56		{
57			$main_width = $new_size + 10;
58		}
59
60		$identifiers_total_width = $graph_width - $main_width - 2;
61
62		$headings = pts_strings::comma_explode($this->i['graph_y_title']);
63		if(empty($headings))
64		{
65			$headings = array(' ');
66		}
67		$identifiers_width = floor($identifiers_total_width / count($headings));
68		$headings_font_size = self::$c['size']['bars'];
69		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))
70		{
71			$headings_font_size -= 0.5;
72		}
73
74		foreach(array_keys($this->test_result->test_result_buffer->buffer_items) as $j)
75		{
76			$results = array_reverse(pts_strings::comma_explode($this->test_result->test_result_buffer->buffer_items[$j]->get_result_value()));
77
78			$line_ttf_height = $this->text_string_height('AZ@![]()@|_', self::$c['size']['bars']);
79			for($i = 0; $i < count($headings) && $i < count($results); $i++)
80			{
81				$paint_color = $results[$i] == 'PASS' ? $pass_color : $fail_color;
82				$this_bottom_end = $this->i['top_start'] + $vertical_border + (($j + 1) * $line_height) + $heading_height + 1;
83
84				if($this_bottom_end >= $this->i['graph_top_end'] - $vertical_border)
85				{
86					$this_bottom_end = $this->i['graph_top_end'] - $vertical_border - 1;
87				}
88				else if($j == ($this->test_result->test_result_buffer->get_count() - 1) && $this_bottom_end < $this->i['graph_top_end'] - $vertical_border)
89				{
90					$this_bottom_end = $this->i['graph_top_end'] - $vertical_border - 1;
91				}
92
93				$x = $this->i['graph_left_end'] - $horizontal_border - ($i * $identifiers_width);
94				$y = $this->i['top_start'] + $vertical_border + ($j * $line_height) + $heading_height;
95
96				$this->svg_dom->add_element('rect', array('x' => ($x - $identifiers_width), 'y' => $y, 'width' => $identifiers_width, 'height' => ($this_bottom_end - $y), 'fill' => $paint_color, 'stroke' => self::$c['color']['border'], 'stroke-width' => 1));
97				$x = $this->i['graph_left_end'] - $horizontal_border - ($i * $identifiers_width) - ($identifiers_width * 0.5);
98				$y = $this->i['top_start'] + $vertical_border + ($j * $line_height) + $heading_height + ($line_height / 2) - ($line_ttf_height / 2);
99				$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'));
100			}
101		}
102
103		$headings = array_reverse($headings);
104		$line_ttf_height = $this->text_string_height('AZ@![]()@|_', $headings_font_size);
105		for($i = 0; $i < count($headings); $i++)
106		{
107			//$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']);
108			$x = $this->i['graph_left_end'] - $horizontal_border - ($i * $identifiers_width) - (0.5 * $identifiers_width);
109			$y = $this->i['top_start'] + $vertical_border + ($heading_height / 2) - ($line_ttf_height / 2);
110			$this->svg_dom->add_text_element($headings[$i], array('x' => $x, 'y' => $y, 'font-size' => $headings_font_size, 'fill' => self::$c['color']['headers'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
111		}
112
113		$line_ttf_height = $this->text_string_height('AZ@![]()@|_', $main_font_size);
114		foreach(array_keys($this->test_result->test_result_buffer->buffer_items) as $i)
115		{
116			//$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']);
117
118			$x = $this->i['left_start'] + $horizontal_border + $main_width;
119			$y = $this->i['top_start'] + $vertical_border + ($i * $line_height) + $heading_height + ($line_height / 2) - 2;
120			$this->svg_dom->add_text_element($this->test_result->test_result_buffer->buffer_items[$i]->get_result_identifier(), array('x' => $x, 'y' => $y, 'font-size' => $main_font_size, 'fill' => self::$c['color']['headers'], 'text-anchor' => 'end', 'dominant-baseline' => 'middle', 'font-weight' => 'bold'));
121		}
122
123		//$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']);
124		//$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']);
125		//$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']);
126		//$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']);
127	}
128	protected function render_graph_result()
129	{
130		$this->render_graph_passfail();
131	}
132}
133
134?>
135