protected function render_graph_pre_init()
 {
     // Do some common work to this object
     $this->i['identifier_width'] = $this->max_count > 0 ? ($this->i['graph_left_end'] - $this->i['left_start']) / $this->max_count : 1;
     if (!$this->i['hide_graph_identifiers']) {
         $identifier_count = $this->test_result->test_result_buffer->get_count();
         $longest_string = pts_strings::find_longest_string($this->graph_identifiers);
         $this->i['identifier_size'] = $this->text_size_bounds($longest_string, $this->i['identifier_size'], $this->i['min_identifier_size'], $this->i['identifier_width'] - 4);
         if ($this->i['identifier_size'] <= $this->i['min_identifier_size']) {
             list($text_width, $text_height) = pts_svg_dom::estimate_text_dimensions($longest_string, $this->i['min_identifier_size'] + 0.5);
             $this->i['bottom_offset'] += $text_width;
             $this->update_graph_dimensions($this->i['graph_width'], $this->i['graph_height'] + $text_width);
             if ($text_height + 4 > $this->i['identifier_width'] && $identifier_count > 3) {
                 // Show the identifiers as frequently as they will fit
                 $this->i['display_select_identifiers'] = ceil(($text_height + 4) / $this->i['identifier_width']);
             }
         }
     }
     $max_value = 0;
     foreach ($this->test_result->test_result_buffer->buffer_items as &$buffer_item) {
         if (!is_array($buffer_item->get_result_value())) {
             $max_value = max($max_value, $buffer_item->get_result_value());
         } else {
             $max_value = max($max_value, max($buffer_item->get_result_value()));
         }
     }
     $max_value *= 1.25;
     // leave room at top of graph
     $this->i['graph_max_value'] = round($max_value, $max_value < 10 ? 1 : 0);
 }
 protected function render_graph_pre_init()
 {
     // Do some common work to this object
     $graph_identifiers_count = count($this->graph_identifiers);
     if ($graph_identifiers_count > 1) {
         $identifier_count = $graph_identifiers_count + 1;
     } else {
         $identifier_count = 0;
         foreach (array_keys($this->graph_data) as $i) {
             $identifier_count = max(count($this->graph_data[$i]) - 1, $identifier_count);
         }
     }
     $this->i['identifier_width'] = $identifier_count > 0 ? ($this->i['graph_left_end'] - $this->i['left_start']) / $identifier_count : 1;
     $longest_string = pts_strings::find_longest_string($this->graph_identifiers);
     $this->i['identifier_size'] = $this->text_size_bounds($longest_string, $this->i['identifier_size'], $this->i['min_identifier_size'], $this->i['identifier_width'] - 4);
     if ($this->i['identifier_size'] <= $this->i['min_identifier_size']) {
         list($text_width, $text_height) = pts_svg_dom::estimate_text_dimensions($longest_string, $this->i['min_identifier_size'] + 0.5);
         $this->i['bottom_offset'] += $text_width;
         $this->update_graph_dimensions($this->i['graph_width'], $this->i['graph_height'] + $text_width);
         if ($text_height + 4 > $this->i['identifier_width'] && $graph_identifiers_count > 3) {
             // Show the identifiers as frequently as they will fit
             $this->i['display_select_identifiers'] = ceil(($text_height + 4) / $this->i['identifier_width']);
         }
     }
     $max_value = 0;
     foreach ($this->graph_data as $dataset) {
         $data_max = max($dataset);
         $max_value = $max_value > $data_max ? $max_value : $data_max;
     }
     $max_value *= 1.25;
     // leave room at top of graph
     $this->i['graph_max_value'] = round($max_value, $max_value < 10 ? 1 : 0);
 }
 public function __construct($result_file)
 {
     $result_object = null;
     parent::__construct($result_object, $result_file);
     // System Identifiers
     if ($result_file->is_multi_way_comparison()) {
         // Multi way comparisons currently render the overview graph as blank
         $this->skip_graph = true;
         return;
     }
     $this->system_identifiers = $result_file->get_system_identifiers();
     if (count($this->system_identifiers) < 2) {
         // No point in generating this when there is only one identifier
         $this->skip_graph = true;
         return;
     }
     $result_objects = array();
     $test_titles = array();
     foreach ($result_file->get_result_objects() as $result_object) {
         if ($result_object->test_profile->get_display_format() == 'BAR_GRAPH') {
             array_push($result_objects, $result_object);
             array_push($test_titles, $result_object->test_profile->get_title());
             foreach ($result_object->test_result_buffer->buffer_items as &$buffer_item) {
                 pts_arrays::unique_push($this->graph_identifiers, $buffer_item->get_result_identifier());
             }
         }
     }
     $result_object_count = count($result_objects);
     if ($result_object_count < 3) {
         // No point in generating this if there aren't many tests
         $this->skip_graph = true;
         return;
     }
     $result_file->override_result_objects($result_objects);
     // Test Titles
     $this->i['identifier_size'] = 6.5;
     $this->i['graph_width'] = 1000;
     list($longest_title_width, $longest_title_height) = pts_svg_dom::estimate_text_dimensions(pts_strings::find_longest_string($test_titles), $this->i['identifier_size']);
     $this->i['left_start'] += 20;
     $this->graphs_per_row = min(count($this->system_identifiers) > 10 ? 6 : 10, floor(($this->i['graph_width'] - $this->i['left_start'] - $this->i['left_end_right']) / ($longest_title_width + 4)));
     $this->graph_item_width = floor(($this->i['graph_width'] - $this->i['left_start'] - $this->i['left_end_right']) / $this->graphs_per_row);
     $this->graph_row_count = ceil($result_object_count / $this->graphs_per_row);
     $this->i['top_start'] += 20 + count($this->system_identifiers) / 3 * $this->i['identifier_size'];
     $height = $this->i['top_start'] + $this->graph_row_count * ($this->graph_row_height + 15);
     $this->graph_title = $result_file->get_title();
     $this->graph_y_title = null;
     $this->i['graph_proportion'] = 'HIB';
     $this->i['show_background_lines'] = true;
     $this->update_graph_dimensions($this->i['graph_width'], $height, true);
     $this->result_file = $result_file;
     return true;
 }
 protected function render_graph_pre_init()
 {
     $this->i['min_time'] = strtotime(min($this->test_result->test_result_buffer->get_identifiers()));
     $this->i['max_time'] = strtotime(max($this->test_result->test_result_buffer->get_identifiers()));
     $this->i['spread_time'] = $this->i['max_time'] - $this->i['min_time'];
     // Do some common work to this object
     $graph_identifiers_count = count($this->graph_identifiers);
     $identifier_count = $graph_identifiers_count > 1 ? $graph_identifiers_count : count($this->graph_data[0]);
     $this->i['identifier_width'] = ($this->i['graph_left_end'] - $this->i['left_start']) / ($identifier_count + 1);
     $longest_string = pts_strings::find_longest_string($this->graph_identifiers);
     $this->i['identifier_size'] = $this->text_size_bounds($longest_string, $this->i['identifier_size'], $this->i['min_identifier_size'], $this->i['identifier_width'] - 4);
     if ($this->i['identifier_size'] <= $this->i['min_identifier_size']) {
         list($text_width, $text_height) = pts_svg_dom::estimate_text_dimensions($longest_string, $this->i['min_identifier_size'] + 0.5);
         $this->i['bottom_offset'] += $text_width;
         $this->update_graph_dimensions($this->i['graph_width'], $this->i['graph_height'] + $text_width);
         if ($text_height + 4 > $this->i['identifier_width'] && $graph_identifiers_count > 3) {
             // Show the identifiers as frequently as they will fit
             $this->i['display_select_identifiers'] = ceil(($text_height + 4) / $this->i['identifier_width']);
         }
     }
 }
 public function generate_display()
 {
     $bar_width = 580;
     $bar_height = 38;
     $heading_per_bar = 16;
     $title_bar_height = 35;
     $footer_bar_height = 14;
     $category_offsets = 0;
     $category_heights = 30;
     $categories = array();
     $border = 3;
     foreach ($this->bars as &$bar) {
         if ($bar['test_data']['h'] != null && !in_array($bar['test_data']['h'], $categories)) {
             array_push($categories, $bar['test_data']['h']);
         }
     }
     if (empty($this->keys)) {
         foreach ($this->bars as &$bar_index) {
             foreach (array_keys($bar_index['results']) as $result_identifier) {
                 if (!in_array($result_identifier, $this->keys)) {
                     array_push($this->keys, $result_identifier);
                 }
             }
         }
     }
     if (!empty($this->keys)) {
         list($longest_key_width, $key_line_height) = pts_svg_dom::estimate_text_dimensions(pts_strings::find_longest_string($this->keys), '', 10, true);
         $key_line_height += 18;
         $keys_per_line = max(floor($bar_width / max(1, $longest_key_width + 12)), 1);
         $title_key_offset = ceil(count($this->keys) / $keys_per_line) * $key_line_height;
     } else {
         $title_key_offset = 0;
     }
     $this->i['graph_width'] = $bar_width + $border * 2;
     $this->i['graph_height'] = ($bar_height + $heading_per_bar + $border) * count($this->bars) + $border + count($categories) * $category_heights + $title_bar_height + $title_key_offset + $footer_bar_height;
     $this->svg_dom = new pts_svg_dom(ceil($this->i['graph_width']), ceil($this->i['graph_height']));
     $text_color = '#e12128';
     $alt_text_color = '#646464';
     // Setup
     $start_x = $border;
     $end_x = $start_x + $bar_width;
     // Title bar
     $this->svg_dom->add_element('image', array('xlink:href' => 'https://openbenchmarking.org/static/images/ob-fulltext-183x32.png', 'x' => $end_x - 190, 'y' => 10, 'width' => 183, 'height' => 32));
     if (!empty($this->keys)) {
         $color_cache = array('e12128', '065695', '007400');
         for ($i = 0, $c = count($this->keys); $i < $c; $i++) {
             $component_x = $border + $i % $keys_per_line * ($longest_key_width + 10);
             $component_y = floor($i / $keys_per_line) * $key_line_height + $title_bar_height + 3;
             $key_color = self::color_cache('opc', $this->keys[$i], $color_cache);
             //$key_color = self::color_gradient('e12128', '065695', ($i / $c));
             $key_colors[$this->keys[$i]] = $key_color;
             $this->svg_dom->add_element('rect', array('x' => $component_x + 1, 'y' => $component_y, 'width' => 10, 'height' => 10, 'fill' => $key_color, 'stroke' => self::$c['color']['border'], 'stroke-width' => 1));
             $this->svg_dom->add_text_element($this->keys[$i], array('x' => $component_x + 15, 'y' => $component_y + 5, 'font-size' => 10, 'fill' => $key_color, 'text-anchor' => 'start'));
         }
     }
     $previous_category = null;
     foreach ($this->bars as $i => &$hmap) {
         $upper_y = $i * ($bar_height + $border + $heading_per_bar) + $border + $title_bar_height + $title_key_offset + $category_offsets + $heading_per_bar;
         if ($hmap['test_data']['h'] != null && $hmap['test_data']['h'] != $previous_category) {
             $this->svg_dom->add_text_element($hmap['test_data']['h'] . ' Tests', array('x' => $start_x + $bar_width / 2, 'y' => $upper_y, 'font-size' => 16, 'fill' => $text_color, 'text-anchor' => 'middle'));
             $category_offsets += $category_heights;
             $upper_y += $category_heights;
         }
         $previous_category = $hmap['test_data']['h'];
         $lower_y = $upper_y + $bar_height;
         $value_size = $bar_width / ($hmap['max_value'] - $hmap['min_value']);
         $prev_color = '#ffffff';
         $last_plot_x = $start_x;
         $this->svg_dom->add_text_element($hmap['test_data']['t'], array('x' => $start_x, 'y' => $upper_y, 'font-size' => 12, 'fill' => $text_color, 'text-anchor' => 'start'));
         $this->svg_dom->add_text_element($hmap['test_data']['a'], array('x' => $end_x, 'y' => $upper_y, 'font-size' => 10, 'fill' => $alt_text_color, 'text-anchor' => 'end'));
         if ($hmap['test_data']['p'] == 'LIB') {
             // Invert results
             $new_sections = array();
             foreach ($hmap['sections'] as $next_section => $next_section_value) {
                 $new_sections[$hmap['max_value'] - $next_section] = $next_section_value;
             }
             ksort($new_sections);
             $hmap['sections'] = $new_sections;
             foreach ($hmap['draw_lines'] as &$value) {
                 $value = $hmap['max_value'] - $value;
             }
             foreach ($hmap['results'] as &$value) {
                 $value = $hmap['max_value'] - $value;
             }
             sort($hmap['draw_lines']);
             $hmap['max_value'] -= $hmap['min_value'];
             $hmap['min_value'] = 0;
         }
         $prev_section = $hmap['min_value'];
         $max_section_value = max($hmap['sections']);
         /*
         for($i = $hmap['min_value']; $i <= $hmap['max_size'] && $hmap['bin_size'] > 0; $i += $hmap['bin_size'])
         {
         
         }
         */
         $color_weight = 0.61 - 0 / $max_section_value * 0.5;
         $background_color = self::color_gradient('#FFFFFF', '#000000', $color_weight);
         $this->svg_dom->add_element('rect', array('x' => $start_x, 'y' => $upper_y, 'width' => $bar_width, 'height' => $bar_height, 'fill' => $background_color));
         foreach ($hmap['sections'] as $next_section => $next_section_value) {
             $color_weight = 0.61 - $next_section_value / $max_section_value * 0.5;
             $color = self::color_gradient('#FFFFFF', '#000000', $color_weight);
             if ($next_section > $hmap['min_value']) {
                 $next_section = $next_section > $hmap['max_value'] ? $hmap['max_value'] : $next_section;
                 $plot_x = floor($last_plot_x + ($next_section - $prev_section) * $value_size);
                 $plot_x = $plot_x > $end_x ? $end_x : $plot_x;
                 if ($prev_color != $color || $color != $background_color) {
                     // don't uselessly paint background color, it's already painted
                     $this->svg_dom->draw_rectangle_gradient($last_plot_x, $upper_y, abs($plot_x - $last_plot_x), $bar_height, $prev_color, $color);
                 }
                 $last_plot_x = floor($plot_x - 0.6);
                 $prev_section = $next_section;
                 if ($next_section > $hmap['max_value']) {
                     break;
                 }
             }
             $prev_color = $color;
         }
         /*
         
         if($prev_color != $background_color && $plot_x < $end_x)
         {
         	$plot_x = $last_plot_x + $next_section + $hmap['bin_size'];
         	$plot_x = $plot_x > $end_x ? $end_x : $plot_x;
         	$this->svg_dom->draw_rectangle_gradient($last_plot_x, $upper_y, ceil($plot_x - $last_plot_x), $bar_height, $prev_color, $background_color);
         }
         if($last_plot_x < $end_x)
         {
         	// Fill in the blank
         	$this->svg_dom->add_element('rect', array('x' => $last_plot_x, 'y' => $upper_y, 'width' => ($end_x - $last_plot_x), 'height' => $bar_height, 'fill' => $prev_color));
         }
         */
         foreach ($hmap['draw_lines'] as $line_value) {
             $line_x = $start_x + ($line_value - $hmap['min_value']) * $value_size;
             $this->svg_dom->draw_svg_line($line_x, $upper_y, $line_x, $lower_y, self::$c['color']['border'], 1);
         }
         foreach ($hmap['results'] as $identifier => $value) {
             if (!isset($key_colors[$identifier])) {
                 continue;
             }
             $line_x = $start_x + ($value - $hmap['min_value']) * $value_size;
             if (false && $start_x + 10 < $line_x && $line_x < $end_x - 10) {
                 $this->svg_dom->draw_svg_line($line_x, $lower_y - 10, $line_x, $lower_y - 1, $key_colors[$identifier], 1);
                 $this->svg_dom->draw_svg_line($line_x, $lower_y + 10, $line_x, $lower_y + 1, $key_colors[$identifier], 1);
             }
             $this->svg_dom->draw_svg_line($line_x, $upper_y, $line_x, $lower_y, $key_colors[$identifier], 1);
         }
         $this->svg_dom->add_element('rect', array('x' => $start_x, 'y' => $upper_y, 'width' => $bar_width, 'height' => $bar_height, 'fill' => 'none', 'stroke' => self::$c['color']['border'], 'stroke-width' => 1));
     }
     // Footer
     $this->draw_arrow($start_x + 8, $lower_y + 8, $start_x + 1, $lower_y + 8, $alt_text_color, self::$c['color']['border'], 1);
     $this->svg_dom->add_text_element('Percentile Rank' . ($this->last_updated != null ? '; Data As Of ' . pts_strings::time_stamp_to_string($this->last_updated, 'j F Y') . ' For Trailing 200 Days' : null), array('x' => $start_x + 13, 'y' => $lower_y + 8, 'font-size' => 7, 'fill' => $alt_text_color, 'text-anchor' => 'start', 'dominant-baseline' => 'middle'));
     $this->svg_dom->add_text_element('OpenBenchmarking.org Performance Classification', array('x' => $end_x, 'y' => $lower_y + 8, 'font-size' => 7, 'fill' => $alt_text_color, 'text-anchor' => 'end', 'dominant-baseline' => 'middle'));
     return $this->svg_dom;
 }
 protected function text_string_height($string, $size)
 {
     $dimensions = pts_svg_dom::estimate_text_dimensions($string, $size);
     return $dimensions[1];
 }