Best Phoronix-test-suite code snippet using pts_svg_dom.add_element
pts_graph_core.php
Source:pts_graph_core.php
...549 $this->svg_dom = new pts_svg_dom(ceil($this->i['graph_width']), ceil($this->i['graph_height']));550 // Background Color551 if($this->i['iveland_view'] || self::$c['graph']['border'])552 {553 $this->svg_dom->add_element('rect', array('x' => 0, 'y' => 0, 'width' => $this->i['graph_width'], 'height' => $this->i['graph_height'], 'fill' => self::$c['color']['background'], 'stroke' => self::$c['color']['border'], 'stroke-width' => 2));554 }555 else556 {557 $this->svg_dom->add_element('rect', array('x' => 0, 'y' => 0, 'width' => $this->i['graph_width'], 'height' => $this->i['graph_height'], 'fill' => self::$c['color']['background']));558 }559 if($this->i['iveland_view'] == false && ($sub_title_count = count($this->graph_sub_titles)) > 1)560 {561 $this->i['top_start'] += (($sub_title_count - 1) * (self::$c['size']['sub_headers'] + 4));562 }563 }564 protected function render_graph_heading($with_version = true)565 {566 $href = null;567 if($this->test_identifier != null)568 {569 $href = 'http://openbenchmarking.org/test/' . $this->test_identifier;570 }571 // Default to NORMAL572 if($this->i['iveland_view'])573 {574 $this->svg_dom->add_element('rect', array('x' => 0, 'y' => 0, 'width' => $this->i['graph_width'], 'height' => $this->i['top_heading_height'], 'fill' => self::$c['color']['main_headers']));575 if(isset($this->graph_title[36]))576 {577 // If it's a long string make sure it won't run over the side...578 while(self::text_string_width($this->graph_title, self::$c['size']['headers']) > ($this->i['graph_left_end'] - 20))579 {580 self::$c['size']['headers'] -= 0.5;581 }582 }583 $this->svg_dom->add_text_element($this->graph_title, array('x' => 6, 'y' => (self::$c['size']['headers'] + 2), 'font-size' => self::$c['size']['headers'], 'fill' => self::$c['color']['background'], 'text-anchor' => 'start', 'xlink:show' => 'new', 'xlink:href' => $href, 'font-weight' => 'bold'));584 foreach($this->graph_sub_titles as $i => $sub_title)585 {586 $vertical_offset = 12 + self::$c['size']['headers'] + (($i + 1) * (self::$c['size']['sub_headers'] - 4));587 $sub_title_size = self::$c['size']['sub_headers'];588 if(isset($sub_title[69]))589 {590 while(self::text_string_width($sub_title, $sub_title_size) > ($this->i['graph_left_end'] - 20))591 $sub_title_size -= 0.5;592 }593 $this->svg_dom->add_text_element($sub_title, array('x' => 6, 'y' => $vertical_offset, 'font-size' => $sub_title_size, 'font-weight' => 'bold', 'fill' => self::$c['color']['background'], 'text-anchor' => 'start'));594 }595 // SVG version of PTS thanks to https://gist.github.com/xorgy/65c6d0e87757dbb56a75596 $this->svg_dom->add_element('path', array('d' => 'm74 22v9m-5-16v16m-5-28v28m-23-2h12.5c2.485281 0 4.5-2.014719 4.5-4.5s-2.014719-4.5-4.5-4.5h-8c-2.485281 0-4.5-2.014719-4.5-4.5s2.014719-4.5 4.5-4.5h12.5m-21 5h-11m11 13h-2c-4.970563 0-9-4.029437-9-9v-20m-24 40v-20c0-4.970563 4.0294373-9 9-9 4.970563 0 9 4.029437 9 9s-4.029437 9-9 9h-9', 'stroke' => '#ffffff', 'stroke-width' => 4, 'fill' => 'none', 'transform' => 'translate(' . ceil($this->i['graph_left_end'] - 77) . ',' . (ceil($this->i['top_heading_height'] / 40 + 2)) . ')'));597 }598 else599 {600 $this->svg_dom->add_text_element($this->graph_title, array('x' => round($this->i['graph_left_end'] / 2), 'y' => (self::$c['size']['headers'] + 2), 'font-size' => self::$c['size']['headers'], 'fill' => self::$c['color']['main_headers'], 'text-anchor' => 'middle', 'xlink:show' => 'new', 'xlink:href' => $href));601 foreach($this->graph_sub_titles as $i => $sub_title)602 {603 $this->svg_dom->add_text_element($sub_title, array('x' => round($this->i['graph_left_end'] / 2), 'y' => (31 + (($i + 1) * 18)), 'font-size' => self::$c['size']['sub_headers'], 'fill' => self::$c['color']['main_headers'], 'text-anchor' => 'middle'));604 }605 if($with_version)606 {607 $this->svg_dom->add_text_element($this->i['graph_version'], array('x' => $this->i['graph_left_end'] , 'y' => ($this->i['top_start'] - 3), 'font-size' => 7, 'fill' => self::$c['color']['body_light'], 'text-anchor' => 'end', 'xlink:show' => 'new', 'xlink:href' => 'http://www.phoronix-test-suite.com/'));608 }609 }610 }611 protected function render_graph_post()612 {613 if($this->i['iveland_view'])614 {615 $bottom_heading_start = $this->i['graph_top_end'] + $this->i['bottom_offset'] + 22;616 $this->svg_dom->add_element('rect', array('x' => 0, 'y' => $bottom_heading_start, 'width' => $this->i['graph_width'], 'height' => ($this->i['graph_height'] - $bottom_heading_start), 'fill' => self::$c['color']['main_headers']));617 $this->svg_dom->add_text_element($this->i['graph_version'], array('x' => $this->i['graph_left_end'], 'y' => ($bottom_heading_start + self::$c['size']['key'] + 3), 'font-size' => self::$c['size']['key'], 'fill' => self::$c['color']['background'], 'text-anchor' => 'end', 'xlink:show' => 'new', 'xlink:href' => 'http://www.phoronix-test-suite.com/'));618 if(isset($this->d['link_alternate_view']) && $this->d['link_alternate_view'])619 {620 // add SVG version: https://gist.github.com/xorgy/169a65e29a3c2cc41e7f621 $a = $this->svg_dom->make_a($this->d['link_alternate_view']);622 $g = $this->svg_dom->make_g(array('transform' => 'translate(' . 4 . ',' . ($bottom_heading_start + 1) . ')', 'width' => 10, 'height' => 16), $a);623 $this->svg_dom->add_element('path', array('d' => 'M5 0v6.5L0 11l3-3-3-3.5L5 0', 'fill' => '#038bb8'), $g);624 $this->svg_dom->add_element('path', array('d' => 'M5 0v6.5l5 4.5-3-3 3-3.5L5 0', 'fill' => '#25b3e8'), $g);625 $this->svg_dom->add_element('path', array('d' => 'M5 16V9l5-4.5V11l-5 5', 'fill' => '#e4f4fd'), $g);626 $this->svg_dom->add_element('path', array('d' => 'M5 16V9L0 4.5V11l5 5', 'fill' => '#65cbf4'), $g);627 }628 if(!empty($this->i['notes']))629 {630 $estimated_height = 0;631 foreach($this->i['notes'] as $i => $note_r)632 {633 $this->svg_dom->add_textarea_element(($i + 1) . '. ' . $note_r['note'], array('x' => 5, 'y' => ($bottom_heading_start + (self::$c['size']['key'] * 2) + 8 + $estimated_height), 'font-size' => (self::$c['size']['key'] - 1), 'fill' => self::$c['color']['background'], 'text-anchor' => 'start', 'xlink:title' => $note_r['hover-title']), $estimated_height);634 }635 }636 }637 }638 protected function render_graph_base($left_start, $top_start, $left_end, $top_end)639 {640 if($this->i['graph_orientation'] == 'HORIZONTAL' || $this->i['iveland_view'])641 {642 $g = $this->svg_dom->make_g(array('stroke' => self::$c['color']['notches'], 'stroke-width' => 1));643 $this->svg_dom->add_element('line', array('x1' => $left_start, 'y1' => $top_start, 'x2' => $left_start, 'y2' => ($top_end + 1)), $g);644 $this->svg_dom->add_element('line', array('x1' => $left_start, 'y1' => $top_end, 'x2' => ($left_end + 1), 'y2' => $top_end), $g);645 if(!empty(self::$c['text']['watermark']))646 {647 $this->svg_dom->add_text_element(self::$c['text']['watermark'], array('x' => $left_end, 'y' => ($top_start - 5), 'font-size' => 8, 'fill' => self::$c['color']['text'], 'text-anchor' => 'end', 'xlink:show' => 'new', 'xlink:href' => self::$c['text']['watermark_url']));648 }649 }650 else651 {652 $this->svg_dom->add_element('rect', array('x' => $left_start, 'y' => $top_start, 'width' => ($left_end - $left_start), 'height' => ($top_end - $top_start), 'fill' => self::$c['color']['body'], 'stroke' => self::$c['color']['notches'], 'stroke-width' => 1));653 if(self::$c['text']['watermark'] != null)654 {655 $this->svg_dom->add_text_element(self::$c['text']['watermark'], array('x' => ($left_end - 2), 'y' => ($top_start + 12), 'font-size' => 10, 'fill' => self::$c['color']['text'], 'text-anchor' => 'end', 'xlink:show' => 'new', 'xlink:href' => self::$c['text']['watermark_url']));656 }657 }658 if(!empty($this->graph_y_title) && $this->i['hide_y_title'] == false)659 {660 $str = $this->graph_y_title;661 $offset = 0;662 if($this->i['graph_proportion'] != null)663 {664 $proportion = null;665 switch($this->i['graph_proportion'])666 {667 case 'LIB':668 $proportion = 'Less Is Better';669 $offset += 12;670 if($this->i['graph_orientation'] == 'HORIZONTAL')671 {672 $this->draw_arrow($left_start, $top_start - 8, $left_start + 9, $top_start - 8, self::$c['color']['text'], self::$c['color']['body_light'], 1);673 }674 else675 {676 $this->draw_arrow($left_start + 4, $top_start - 4, $left_start + 4, $top_start - 11, self::$c['color']['text'], self::$c['color']['body_light'], 1);677 }678 break;679 case 'HIB':680 $proportion = 'More Is Better';681 $offset += 12;682 if($this->i['graph_orientation'] == 'HORIZONTAL')683 {684 $this->draw_arrow($left_start + 9, $top_start - 8, $left_start, $top_start - 8, self::$c['color']['text'], self::$c['color']['body_light'], 1);685 }686 else687 {688 $this->draw_arrow($left_start + 4, $top_start - 11, $left_start + 4, $top_start - 4, self::$c['color']['text'], self::$c['color']['body_light'], 1);689 }690 break;691 }692 if($proportion)693 {694 if($str)695 {696 $str .= ', ';697 }698 $str .= $proportion;699 }700 }701 $this->svg_dom->add_text_element($str, array('x' => ($left_start + $offset), 'y' => ($top_start - 5), 'font-size' => 8, 'fill' => self::$c['color']['text'], 'text-anchor' => 'start'));702 }703 }704 protected function render_graph_value_ticks($left_start, $top_start, $left_end, $top_end, $show_numbers = true)705 {706 $increment = round($this->i['graph_max_value'] / $this->i['mark_count'], $this->i['graph_max_value'] < 10 ? 4 : 2);707 if($this->i['graph_orientation'] == 'HORIZONTAL')708 {709 $tick_width = round(($left_end - $left_start) / $this->i['mark_count']);710 $display_value = 0;711 $g = $this->svg_dom->make_g(array('font-size' => self::$c['size']['tick_mark'], 'fill' => self::$c['color']['text'], 'text-anchor' => 'middle'));712 $g_lines = $this->svg_dom->make_g(array('stroke' => self::$c['color']['body'], 'stroke-width' => 1));713 for($i = 0; $i < $this->i['mark_count']; $i++)714 {715 $px_from_left = $left_start + ($tick_width * $i);716 if($i != 0)717 {718 $show_numbers && $this->svg_dom->add_text_element($display_value, array('x' => $px_from_left + 2, 'y' => ($top_end + 5 + self::$c['size']['tick_mark'])), $g);719 $this->svg_dom->add_element('line', array('x1' => ($px_from_left + 2), 'y1' => ($top_start), 'x2' => ($px_from_left + 2), 'y2' => ($top_end - 5), 'stroke-dasharray' => '5,5'), $g_lines);720 $this->svg_dom->add_element('line', array('x1' => ($px_from_left + 2), 'y1' => ($top_end - 4), 'x2' => ($px_from_left + 2), 'y2' => ($top_end + 5)), $g_lines);721 }722 $display_value += $increment;723 }724 }725 else726 {727 $tick_width = round(($top_end - $top_start) / $this->i['mark_count']);728 $px_from_left_start = $left_start - 5;729 $px_from_left_end = $left_start + 5;730 $display_value = 0;731 $g_lines = $this->svg_dom->make_g(array('stroke' => self::$c['color']['notches'], 'stroke-width' => 1, 'stroke-dasharray' => '5,5'));732 $g_lines_2 = $this->svg_dom->make_g(array('stroke' => self::$c['color']['notches'], 'stroke-width' => 1));733 $g_background_lines = $this->svg_dom->make_g(array('stroke' => self::$c['color']['body_light'], 'stroke-width' => 1, 'stroke-dasharray' => '5,5'));734 $g_text = $this->svg_dom->make_g(array('font-size' => self::$c['size']['tick_mark'], 'fill' => self::$c['color']['text'], 'text-anchor' => 'end'));735 for($i = 0; $i < $this->i['mark_count']; $i++)736 {737 $px_from_top = round($top_end - ($tick_width * $i));738 if($i != 0)739 {740 $show_numbers && $this->svg_dom->add_text_element($display_value, array('x' => ($px_from_left_start - 4), 'y' => round($px_from_top + (self::$c['size']['tick_mark'] / 2))), $g_text);741 if($this->i['show_background_lines'])742 {743 $this->svg_dom->add_element('line', array('x1' => ($px_from_left_end + 6), 'y1' => ($px_from_top + 1), 'x2' => ($this->i['graph_left_end']), 'y2' => ($px_from_top + 1)), $g_background_lines);744 }745 $this->svg_dom->add_element('line', array('x1' => ($left_start), 'y1' => ($px_from_top + 1), 'x2' => ($left_end), 'y2' => ($px_from_top + 1)), $g_lines);746 $this->svg_dom->add_element('line', array('x1' => ($left_start - 4), 'y1' => ($px_from_top + 1), 'x2' => ($left_start + 4), 'y2' => ($px_from_top + 1)), $g_lines_2);747 }748 $display_value += $increment;749 }750 }751 }752 protected function render_graph_identifiers()753 {754 return;755 }756 protected function render_graph_result()757 {758 return;759 }760 protected function graph_key_height()761 {762 if((count($this->results) < 2 || $this->i['show_graph_key'] == false) && !$this->is_multi_way_comparison) // TODO likely should be OR763 {764 return 0;765 }766 $this->i['key_line_height'] = 16;767 $ak = array_keys($this->results);768 $this->i['key_item_width'] = 20 + self::text_string_width(pts_strings::find_longest_string($ak), self::$c['size']['key']);769 $this->i['keys_per_line'] = max(1, floor(($this->i['graph_left_end'] - $this->i['left_start']) / $this->i['key_item_width']));770 return ceil(count($this->results) / $this->i['keys_per_line']) * $this->i['key_line_height'];771 }772 protected function render_graph_key()773 {774 if($this->i['key_line_height'] == 0)775 {776 return;777 }778 $y = $this->i['top_start'] - $this->graph_key_height() - 7;779 $i = 0;780 $g_rect = $this->svg_dom->make_g(array('stroke' => self::$c['color']['notches'], 'stroke-width' => 1));781 $g_text = $this->svg_dom->make_g(array('font-size' => self::$c['size']['key'], 'text-anchor' => 'start', 'font-weight' => 'bold'));782 if(!is_array($this->results))783 {784 return false;785 }786 foreach(array_keys($this->results) as $title)787 {788 if(!empty($title))789 {790 $this_color = $this->get_paint_color($title);791 if($i != 0 && $i % $this->i['keys_per_line'] == 0)792 {793 $y += $this->i['key_line_height'];794 }795 $x = $this->i['left_start'] + 13 + ($this->i['key_item_width'] * ($i % $this->i['keys_per_line']));796 $this->svg_dom->add_element('rect', array('x' => ($x - 13), 'y' => ($y - 5), 'width' => 10, 'height' => 10, 'fill' => $this_color), $g_rect);797 $this->svg_dom->add_text_element($title, array('x' => $x, 'y' => ($y + 4), 'fill' => $this_color), $g_text);798 $i++;799 }800 }801 }802 protected function draw_arrow($tip_x1, $tip_y1, $tail_x1, $tail_y1, $background_color, $border_color = null, $border_width = 0)803 {804 $is_vertical = ($tip_x1 == $tail_x1);805 if($is_vertical)806 {807 // Vertical arrow808 $arrow_length = sqrt(pow(($tail_x1 - $tip_x1), 2) + pow(($tail_y1 - $tip_y1), 2));809 $arrow_length_half = $arrow_length / 2;810 $arrow_points = array(811 $tip_x1 . ',' . $tip_y1,812 ($tail_x1 + $arrow_length_half) . ',' . $tail_y1,813 ($tail_x1 - $arrow_length_half) . ',' . $tail_y1814 );815 }816 else817 {818 // Horizontal arrow819 $arrow_length = sqrt(pow(($tail_x1 - $tip_x1), 2) + pow(($tail_y1 - $tip_y1), 2));820 $arrow_length_half = $arrow_length / 2;821 $arrow_points = array(822 $tip_x1 . ',' . $tip_y1,823 $tail_x1 . ',' . ($tail_y1 + $arrow_length_half),824 $tail_x1 . ',' . ($tail_y1 - $arrow_length_half)825 );826 }827 $this->svg_dom->add_element('polygon', array('points' => implode(' ', $arrow_points), 'fill' => $background_color, 'stroke' => $border_color, 'stroke-width' => $border_width));828 }829 protected static function text_string_width($string, $size)830 {831 $dimensions = pts_svg_dom::estimate_text_dimensions($string, $size);832 return $dimensions[0];833 }834 protected static function text_string_height($string, $size)835 {836 $dimensions = pts_svg_dom::estimate_text_dimensions($string, $size);837 return $dimensions[1];838 }839 protected function note_display_height()840 {841 // This basically figures out how many lines of notes there are times the size of the font key......
add_element
Using AI Code Generation
1require_once 'pts_svg_dom.php';2$svg = new pts_svg_dom();3$svg->add_element('rect', array('x' => 10, 'y' => 10, 'width' => 100, 'height' => 100, 'fill' => 'red'));4$svg->add_element('rect', array('x' => 110, 'y' => 110, 'width' => 100, 'height' => 100, 'fill' => 'blue'));5$svg->add_element('rect', array('x' => 210, 'y' => 210, 'width' => 100, 'height' => 100, 'fill' => 'green'));6$svg->add_element('rect', array('x' => 310, 'y' => 310, 'width' => 100, 'height' => 100, 'fill' => 'yellow'));7$svg->add_element('rect', array('x' => 410, 'y' => 410, 'width' => 100, 'height' => 100, 'fill' => 'pink'));8$svg->add_element('rect', array('x' => 510, 'y' => 510, 'width' => 100, 'height' => 100, 'fill' => 'brown'));9$svg->add_element('rect', array('x' => 610, 'y' => 610, 'width' => 100, 'height' => 100, 'fill' => 'purple'));10$svg->add_element('rect', array('x' => 710, 'y' => 710, 'width' => 100, 'height' => 100, 'fill' => 'orange'));11$svg->add_element('rect', array('x' => 810, 'y' => 810, 'width' => 100, 'height' => 100, 'fill' => 'black'));12$svg->add_element('rect', array('x' => 910, 'y' => 910, 'width' => 100, 'height' => 100, 'fill' => 'white'));13$svg->add_element('rect', array('x' => 1010, 'y' => 1010, 'width' => 100, 'height' => 100, 'fill'
add_element
Using AI Code Generation
1$svg_dom = new pts_svg_dom();2$svg_dom->add_element('circle',array('cx'=>'50','cy'=>'50','r'=>'40','stroke'=>'green','stroke-width'=>'4','fill'=>'yellow'));3$svg_dom->add_element('rect',array('x'=>'50','y'=>'50','width'=>'100','height'=>'100','style'=>'fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)'));4$svg_dom->add_element('text',array('x'=>'50','y'=>'50','font-size'=>'20','fill'=>'red'),"Hello World");5$svg_dom->add_element('line',array('x1'=>'0','y1'=>'0','x2'=>'200','y2'=>'200','style'=>'stroke:rgb(255,0,0);stroke-width:2'));6$svg_dom->add_element('ellipse',array('cx'=>'50','cy'=>'50','rx'=>'30','ry'=>'40','style'=>'fill:rgb(0,255,0);stroke-width:3;stroke:rgb(0,0,0)'));7$svg_dom->add_element('polygon',array('points'=>'200,10 250,190 160,210','style'=>'fill:lime;stroke:purple;stroke-width:1'));8$svg_dom->add_element('polyline',array('points'=>'5,20 20,40 40,20 80,60','style'=>'fill:none;stroke:blue;stroke-width:3'));9echo $svg_dom->get_svg_dom();10<rect x="50" y="50" width="100" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)"/>
add_element
Using AI Code Generation
1require_once("pts_svg_dom.php");2$svg = new pts_svg_dom();3$svg->add_element("line", array("x1" => 10, "y1" => 10, "x2" => 100, "y2" => 100, "style" => "stroke:rgb(255,0,0);stroke-width:2"));4$svg->output_svg("2.svg");5require_once("pts_svg_dom.php");6$svg = new pts_svg_dom();7$svg->add_element("rect", array("x" => 10, "y" => 10, "width" => 100, "height" => 100, "style" => "fill:rgb(255,0,0);stroke-width:2;stroke:rgb(0,0,0)"));8$svg->output_svg("3.svg");9require_once("pts_svg_dom.php");10$svg = new pts_svg_dom();11$svg->add_element("circle", array("cx" => 50, "cy" => 50, "r" => 40, "style" => "fill:rgb(255,0,0);stroke-width:2;stroke:rgb(0,0,0)"));12$svg->output_svg("4.svg");13require_once("pts_svg_dom.php");14$svg = new pts_svg_dom();15$svg->add_element("ellipse", array("cx" => 50, "cy" => 50, "rx" => 40, "ry" => 20, "style" => "fill:rgb(255,0,0);stroke-width:2;stroke:rgb(0,0,0)"));16$svg->output_svg("5.svg");
add_element
Using AI Code Generation
1$svg = new pts_svg_dom();2$svg->add_element('circle', array('cx' => 200, 'cy' => 200, 'r' => 100, 'fill' => 'red'));3header('Content-type: image/svg+xml');4echo $svg->get_svg();5$svg = new pts_svg_dom();6$svg->add_element('circle', array('cx' => 200, 'cy' => 200, 'r' => 100, 'fill' => 'red'));7$svg->add_element('circle', array('cx' => 200, 'cy' => 200, 'r' => 50, 'fill' => 'green'));8header('Content-type: image/svg+xml');9echo $svg->get_svg();10$svg = new pts_svg_dom();11$svg->add_element('circle', array('cx' => 200, 'cy' => 200, 'r' => 100, 'fill' => 'red'));12$svg->add_element('circle', array('cx' => 200, 'cy' => 200, 'r' => 50, 'fill' => 'green'));13$svg->add_element('circle', array('cx'
add_element
Using AI Code Generation
1require_once 'pts_svg_dom.php';2$svg = new pts_svg_dom();3$svg->add_element('rect', array(4'stroke-linecap'=>'round'));5header('Content-type: image/svg+xml');6echo $svg->output();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with add_element on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!