public static function render_graph_process(&$result_object, &$result_file = null, $save_as = false, $extra_attributes = null)
 {
     if (isset($extra_attributes['sort_result_buffer'])) {
         $result_object->test_result_buffer->sort_buffer_items();
     }
     if (isset($extra_attributes['reverse_result_buffer'])) {
         $result_object->test_result_buffer->buffer_values_reverse();
     }
     if (isset($extra_attributes['normalize_result_buffer'])) {
         if (isset($extra_attributes['highlight_graph_values']) && is_array($extra_attributes['highlight_graph_values']) && count($extra_attributes['highlight_graph_values']) == 1) {
             $normalize_against = $extra_attributes['highlight_graph_values'][0];
         } else {
             $normalize_against = false;
         }
         $result_object->normalize_buffer_values($normalize_against);
     }
     if ($result_file != null) {
         // Cache the redundant words on identifiers so it's not re-computed on every graph
         static $redundant_word_cache;
         if (!isset($redundant_word_cache[$result_file->get_title()])) {
             $redundant_word_cache[$result_file->get_title()] = pts_render::evaluate_redundant_identifier_words($result_file->get_system_identifiers());
         }
         if ($redundant_word_cache[$result_file->get_title()]) {
             $result_object->test_result_buffer->auto_shorten_buffer_identifiers($redundant_word_cache[$result_file->get_title()]);
         }
     }
     self::multi_way_compact($result_file, $result_object, $extra_attributes);
     $display_format = $result_object->test_profile->get_display_format();
     $bar_orientation = 'HORIZONTAL';
     // default to horizontal bar graph
     switch ($display_format) {
         case 'LINE_GRAPH':
             if (false && $result_object->test_result_buffer->get_count() > 5) {
                 // If there's too many lines close to each other, it's likely to look cluttered so turn it into horizontal range bar / box chart graph
                 $display_format = 'HORIZONTAL_BOX_PLOT';
                 $graph = new pts_HorizontalBoxPlotGraph($result_object, $result_file);
             } else {
                 $graph = new pts_LineGraph($result_object, $result_file);
             }
             break;
         case 'HORIZONTAL_BOX_PLOT':
             $graph = new pts_HorizontalBoxPlotGraph($result_object, $result_file);
             break;
         case 'BAR_ANALYZE_GRAPH':
         case 'BAR_GRAPH':
             if ($bar_orientation == 'VERTICAL') {
                 $graph = new pts_VerticalBarGraph($result_object, $result_file);
             } else {
                 $graph = new pts_HorizontalBarGraph($result_object, $result_file);
             }
             break;
         case 'PASS_FAIL':
             $graph = new pts_PassFailGraph($result_object, $result_file);
             break;
         case 'MULTI_PASS_FAIL':
             $graph = new pts_MultiPassFailGraph($result_object, $result_file);
             break;
         case 'TEST_COUNT_PASS':
             $graph = new pts_TestCountPassGraph($result_object, $result_file);
             break;
         case 'PIE_CHART':
             $graph = new pts_PieChart($result_object, $result_file);
             break;
         case 'IMAGE_COMPARISON':
             $graph = new pts_ImageComparisonGraph($result_object, $result_file);
             break;
         case 'FILLED_LINE_GRAPH':
             $graph = new pts_FilledLineGraph($result_object, $result_file);
             break;
         case 'SCATTER_PLOT':
             $graph = new pts_ScatterPlot($result_object, $result_file);
             break;
         default:
             if (isset($extra_attributes['graph_render_type'])) {
                 $requested_graph_type = $extra_attributes['graph_render_type'];
             } else {
                 if (defined('GRAPH_RENDER_TYPE')) {
                     $requested_graph_type = GRAPH_RENDER_TYPE;
                 } else {
                     $requested_graph_type = null;
                 }
             }
             switch ($requested_graph_type) {
                 case 'CANDLESTICK':
                     $graph = new pts_CandleStickGraph($result_object, $result_file);
                     break;
                 case 'LINE_GRAPH':
                     $graph = new pts_LineGraph($result_object, $result_file);
                     break;
                 case 'FILLED_LINE_GRAPH':
                     $graph = new pts_FilledLineGraph($result_object, $result_file);
                     break;
                 default:
                     if ($bar_orientation == 'VERTICAL') {
                         $graph = new pts_VerticalBarGraph($result_object, $result_file);
                     } else {
                         $graph = new pts_HorizontalBarGraph($result_object, $result_file);
                     }
                     break;
             }
             break;
     }
     if (isset($extra_attributes['regression_marker_threshold'])) {
         $graph->markResultRegressions($extra_attributes['regression_marker_threshold']);
     }
     if (isset($extra_attributes['set_alternate_view'])) {
         $graph->setAlternateView($extra_attributes['set_alternate_view']);
     }
     if (isset($extra_attributes['sort_result_buffer_values'])) {
         $result_object->test_result_buffer->buffer_values_sort();
         if ($result_object->test_profile->get_result_proportion() == 'HIB') {
             $result_object->test_result_buffer->buffer_values_reverse();
         }
     }
     if (isset($extra_attributes['highlight_graph_values'])) {
         $graph->highlight_values($extra_attributes['highlight_graph_values']);
     }
     if (isset($extra_attributes['force_simple_keys'])) {
         $graph->override_i_value('force_simple_keys', true);
     } else {
         if (PTS_IS_CLIENT && pts_client::read_env('GRAPH_HIGHLIGHT') != false) {
             $graph->highlight_values(pts_strings::comma_explode(pts_client::read_env('GRAPH_HIGHLIGHT')));
         }
     }
     switch ($display_format) {
         case 'LINE_GRAPH':
             if (isset($extra_attributes['no_overview_text']) && $graph instanceof pts_LineGraph) {
                 $graph->plot_overview_text = false;
             }
         case 'FILLED_LINE_GRAPH':
         case 'BAR_ANALYZE_GRAPH':
         case 'SCATTER_PLOT':
             //$graph->hideGraphIdentifiers();
             foreach ($result_object->test_result_buffer->get_buffer_items() as $buffer_item) {
                 $graph->loadGraphValues(pts_strings::comma_explode($buffer_item->get_result_value()), $buffer_item->get_result_identifier());
                 $graph->loadGraphRawValues(pts_strings::comma_explode($buffer_item->get_result_raw()));
             }
             $scale_special = $result_object->test_profile->get_result_scale_offset();
             if (!empty($scale_special) && count($ss = pts_strings::comma_explode($scale_special)) > 0) {
                 $graph->loadGraphIdentifiers($ss);
             }
             break;
         case 'HORIZONTAL_BOX_PLOT':
             // TODO: should be able to load pts_test_result_buffer_item objects more cleanly into pts_Graph
             $identifiers = array();
             $values = array();
             foreach ($result_object->test_result_buffer->get_buffer_items() as $buffer_item) {
                 array_push($identifiers, $buffer_item->get_result_identifier());
                 array_push($values, pts_strings::comma_explode($buffer_item->get_result_value()));
             }
             $graph->loadGraphIdentifiers($identifiers);
             $graph->loadGraphValues($values);
             break;
         default:
             // TODO: should be able to load pts_test_result_buffer_item objects more cleanly into pts_Graph
             $identifiers = array();
             $values = array();
             $raw_values = array();
             foreach ($result_object->test_result_buffer->get_buffer_items() as $buffer_item) {
                 array_push($identifiers, $buffer_item->get_result_identifier());
                 array_push($values, $buffer_item->get_result_value());
                 array_push($raw_values, $buffer_item->get_result_raw());
             }
             $graph->loadGraphIdentifiers($identifiers);
             $graph->loadGraphValues($values);
             $graph->loadGraphRawValues($raw_values);
             break;
     }
     self::report_test_notes_to_graph($graph, $result_object);
     return $graph;
 }
 public static function render_graph_process(&$result_object, &$result_file = null, $save_as = false, $extra_attributes = null)
 {
     if (isset($extra_attributes['sort_result_buffer'])) {
         $result_object->test_result_buffer->sort_buffer_items();
     }
     if (isset($extra_attributes['reverse_result_buffer'])) {
         $result_object->test_result_buffer->buffer_values_reverse();
     }
     if (isset($extra_attributes['normalize_result_buffer'])) {
         if (isset($extra_attributes['highlight_graph_values']) && is_array($extra_attributes['highlight_graph_values']) && count($extra_attributes['highlight_graph_values']) == 1) {
             $normalize_against = $extra_attributes['highlight_graph_values'][0];
         } else {
             $normalize_against = false;
         }
         $result_object->normalize_buffer_values($normalize_against);
     }
     if ($result_file != null) {
         // Cache the redundant words on identifiers so it's not re-computed on every graph
         static $redundant_word_cache;
         if (!isset($redundant_word_cache[$result_file->get_title()])) {
             $redundant_word_cache[$result_file->get_title()] = pts_render::evaluate_redundant_identifier_words($result_file->get_system_identifiers());
         }
         if ($redundant_word_cache[$result_file->get_title()]) {
             $result_object->test_result_buffer->auto_shorten_buffer_identifiers($redundant_word_cache[$result_file->get_title()]);
         }
         // COMPACT PROCESS
         if (!isset($extra_attributes['compact_to_scalar']) && $result_object->test_profile->get_display_format() == 'LINE_GRAPH' && $result_file->get_system_count() > 10) {
             // If there's too many lines being plotted on line graph, likely to look messy, so convert to scalar automatically
             $extra_attributes['compact_to_scalar'] = true;
         }
         // XXX: removed || $result_file->is_results_tracker() from below and should be added
         // Removing the command fixes cases like: 1210053-BY-MYRESULTS43
         $result_identifiers = $result_object->test_result_buffer->get_identifiers();
         if ($result_file->is_multi_way_comparison($result_identifiers, $extra_attributes) || isset($extra_attributes['compact_to_scalar']) || isset($extra_attributes['compact_scatter'])) {
             if ((isset($extra_attributes['compact_to_scalar']) || false && $result_file->is_multi_way_comparison($result_identifiers, $extra_attributes)) && in_array($result_object->test_profile->get_display_format(), array('FILLED_LINE_GRAPH'))) {
                 // Convert multi-way line graph into horizontal box plot
                 if (true) {
                     $result_object->test_profile->set_display_format('HORIZONTAL_BOX_PLOT');
                 }
                 /*	else // XXX commented out during PTS 6.0 development, TODO decide if to delete
                 					{
                 						// Turn a multi-way line graph into an averaged bar graph
                 						$buffer_items = $result_object->test_result_buffer->get_buffer_items();
                 						$result_object->test_result_buffer = new pts_test_result_buffer();
                 
                 						foreach($buffer_items as $buffer_item)
                 						{
                 							$values = pts_strings::comma_explode($buffer_item->get_result_value());
                 							$avg_value = pts_math::set_precision(array_sum($values) / count($values), 2);
                 							$j = null;
                 							if(count($values) > 2)
                 							{
                 								$j['min-result'] = min($values);
                 								$j['max-result'] = max($values);
                 
                 								if($j['min-result'] == $j['max-result'])
                 								{
                 									$json = null;
                 								}
                 							}
                 
                 							$result_object->test_result_buffer->add_test_result($buffer_item->get_result_identifier(), $avg_value, null, $j, $j['min-result'], $j['max-result']);
                 						}
                 
                 						$result_object->test_profile->set_display_format('BAR_GRAPH');
                 					} */
             }
             if ($result_object->test_profile->get_display_format() != 'PIE_CHART') {
                 $result_table = false;
                 pts_render::compact_result_file_test_object($result_object, $result_table, $result_file, $extra_attributes);
             }
         } else {
             if (in_array($result_object->test_profile->get_display_format(), array('LINE_GRAPH'))) {
                 // Check to see for line graphs if every result is an array of the same result (i.e. a flat line for every result).
                 // If all the results are just flat lines, you might as well convert it to a bar graph
                 $buffer_items = $result_object->test_result_buffer->get_buffer_items();
                 $all_values_are_flat = false;
                 $flat_values = array();
                 foreach ($buffer_items as $i => $buffer_item) {
                     $unique_in_buffer = array_unique(explode(',', $buffer_item->get_result_value()));
                     $all_values_are_flat = count($unique_in_buffer) == 1;
                     if ($all_values_are_flat == false) {
                         break;
                     }
                     $flat_values[$i] = array_pop($unique_in_buffer);
                 }
                 if ($all_values_are_flat) {
                     $result_object->test_result_buffer = new pts_test_result_buffer();
                     foreach ($buffer_items as $i => $buffer_item) {
                         $result_object->test_result_buffer->add_test_result($buffer_item->get_result_identifier(), $flat_values[$i]);
                     }
                     $result_object->test_profile->set_display_format('BAR_GRAPH');
                 }
             }
         }
     }
     $display_format = $result_object->test_profile->get_display_format();
     $bar_orientation = 'HORIZONTAL';
     // default to horizontal bar graph
     switch ($display_format) {
         case 'LINE_GRAPH':
             if (false && $result_object->test_result_buffer->get_count() > 5) {
                 // If there's too many lines close to each other, it's likely to look cluttered so turn it into horizontal range bar / box chart graph
                 $display_format = 'HORIZONTAL_BOX_PLOT';
                 $graph = new pts_HorizontalBoxPlotGraph($result_object, $result_file);
             } else {
                 $graph = new pts_LineGraph($result_object, $result_file);
             }
             break;
         case 'HORIZONTAL_BOX_PLOT':
             $graph = new pts_HorizontalBoxPlotGraph($result_object, $result_file);
             break;
         case 'BAR_ANALYZE_GRAPH':
         case 'BAR_GRAPH':
             if ($bar_orientation == 'VERTICAL') {
                 $graph = new pts_VerticalBarGraph($result_object, $result_file);
             } else {
                 $graph = new pts_HorizontalBarGraph($result_object, $result_file);
             }
             break;
         case 'PASS_FAIL':
             $graph = new pts_PassFailGraph($result_object, $result_file);
             break;
         case 'MULTI_PASS_FAIL':
             $graph = new pts_MultiPassFailGraph($result_object, $result_file);
             break;
         case 'TEST_COUNT_PASS':
             $graph = new pts_TestCountPassGraph($result_object, $result_file);
             break;
         case 'PIE_CHART':
             $graph = new pts_PieChart($result_object, $result_file);
             break;
         case 'IMAGE_COMPARISON':
             $graph = new pts_ImageComparisonGraph($result_object, $result_file);
             break;
         case 'SCATTER_PLOT':
             $graph = new pts_ScatterPlot($result_object, $result_file);
             break;
         default:
             if (isset($extra_attributes['graph_render_type'])) {
                 $requested_graph_type = $extra_attributes['graph_render_type'];
             } else {
                 if (defined('GRAPH_RENDER_TYPE')) {
                     $requested_graph_type = GRAPH_RENDER_TYPE;
                 } else {
                     $requested_graph_type = null;
                 }
             }
             switch ($requested_graph_type) {
                 case 'CANDLESTICK':
                     $graph = new pts_CandleStickGraph($result_object, $result_file);
                     break;
                 case 'LINE_GRAPH':
                     $graph = new pts_LineGraph($result_object, $result_file);
                     break;
                 default:
                     if ($bar_orientation == 'VERTICAL') {
                         $graph = new pts_VerticalBarGraph($result_object, $result_file);
                     } else {
                         $graph = new pts_HorizontalBarGraph($result_object, $result_file);
                     }
                     break;
             }
             break;
     }
     if (isset($extra_attributes['regression_marker_threshold'])) {
         $graph->markResultRegressions($extra_attributes['regression_marker_threshold']);
     }
     if (isset($extra_attributes['set_alternate_view'])) {
         $graph->setAlternateView($extra_attributes['set_alternate_view']);
     }
     if (isset($extra_attributes['sort_result_buffer_values'])) {
         $result_object->test_result_buffer->buffer_values_sort();
         if ($result_object->test_profile->get_result_proportion() == 'HIB') {
             $result_object->test_result_buffer->buffer_values_reverse();
         }
     }
     if (isset($extra_attributes['highlight_graph_values'])) {
         $graph->highlight_values($extra_attributes['highlight_graph_values']);
     }
     if (isset($extra_attributes['force_simple_keys'])) {
         $graph->override_i_value('force_simple_keys', true);
     } else {
         if (PTS_IS_CLIENT && pts_client::read_env('GRAPH_HIGHLIGHT') != false) {
             $graph->highlight_values(pts_strings::comma_explode(pts_client::read_env('GRAPH_HIGHLIGHT')));
         }
     }
     switch ($display_format) {
         case 'LINE_GRAPH':
             if (isset($extra_attributes['no_overview_text']) && $graph instanceof pts_LineGraph) {
                 $graph->plot_overview_text = false;
             }
         case 'BAR_ANALYZE_GRAPH':
         case 'SCATTER_PLOT':
             //$graph->hideGraphIdentifiers();
             foreach ($result_object->test_result_buffer->get_buffer_items() as $buffer_item) {
                 $graph->loadGraphValues(pts_strings::comma_explode($buffer_item->get_result_value()), $buffer_item->get_result_identifier());
                 $graph->loadGraphRawValues(pts_strings::comma_explode($buffer_item->get_result_raw()));
             }
             $scale_special = $result_object->test_profile->get_result_scale_offset();
             if (!empty($scale_special) && count($ss = pts_strings::comma_explode($scale_special)) > 0) {
                 $graph->loadGraphIdentifiers($ss);
             }
             break;
         case 'HORIZONTAL_BOX_PLOT':
             // TODO: should be able to load pts_test_result_buffer_item objects more cleanly into pts_Graph
             $identifiers = array();
             $values = array();
             foreach ($result_object->test_result_buffer->get_buffer_items() as $buffer_item) {
                 array_push($identifiers, $buffer_item->get_result_identifier());
                 array_push($values, pts_strings::comma_explode($buffer_item->get_result_value()));
             }
             $graph->loadGraphIdentifiers($identifiers);
             $graph->loadGraphValues($values);
             break;
         default:
             // TODO: should be able to load pts_test_result_buffer_item objects more cleanly into pts_Graph
             $identifiers = array();
             $values = array();
             $raw_values = array();
             foreach ($result_object->test_result_buffer->get_buffer_items() as $buffer_item) {
                 array_push($identifiers, $buffer_item->get_result_identifier());
                 array_push($values, $buffer_item->get_result_value());
                 array_push($raw_values, $buffer_item->get_result_raw());
             }
             $graph->loadGraphIdentifiers($identifiers);
             $graph->loadGraphValues($values);
             $graph->loadGraphRawValues($raw_values);
             break;
     }
     self::report_test_notes_to_graph($graph, $result_object);
     return $graph;
 }
 public function render_graph_dimensions()
 {
     parent::render_graph_dimensions();
     $longest_sub_identifier_width = $this->text_string_width('Min: ' . $this->i['graph_max_value'] . ' / Avg: XX / Max: ' . $this->i['graph_max_value'], $this->i['identifier_size']);
     $this->i['left_start'] = max($this->i['left_start'], $longest_sub_identifier_width);
 }