meter

The Gravity PDF meter class.

Defined (1)

The class is defined in the following location(s).

/vendor/blueliquiddesigns/mpdf/classes/meter.php  
  1. class meter 
  2.  
  3. function __construct() 
  4.  
  5.  
  6. function makeSVG($tag, $type, $value, $max, $min, $optimum, $low, $high) 
  7. $svg = ''; 
  8. if ($tag == 'meter') { 
  9.  
  10. if ($type == '2') { 
  11. ///////////////////////////////////////////////////////////////////////////////////// 
  12. ///////// CUSTOM <meter type="2"> 
  13. ///////////////////////////////////////////////////////////////////////////////////// 
  14. $h = 10; 
  15. $w = 160; 
  16. $border_radius = 0.143; // Factor of Height 
  17.  
  18. $svg = '<?xml version="1.0" encoding="UTF-8"?> 
  19. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
  20. <svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g> 
  21.  
  22.  
  23. <defs> 
  24. <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  25. <stop offset="0%" stop-color="rgb(222, 222, 222)" /> 
  26. <stop offset="20%" stop-color="rgb(232, 232, 232)" /> 
  27. <stop offset="25%" stop-color="rgb(232, 232, 232)" /> 
  28. <stop offset="100%" stop-color="rgb(182, 182, 182)" /> 
  29. </linearGradient> 
  30.  
  31. </defs> 
  32. '; 
  33. $svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="#f4f4f4" stroke="none" />'; 
  34.  
  35. // LOW to HIGH region 
  36. //if ($low && $high && ($low != $min || $high != $max)) { 
  37. if ($low && $high) { 
  38. $barx = (($low - $min) / ($max - $min) ) * $w; 
  39. $barw = (($high - $low) / ($max - $min) ) * $w; 
  40. $svg .= '<rect x="' . $barx . '" y="0" width="' . $barw . '" height="' . $h . '" fill="url(#GrGRAY)" stroke="#888888" stroke-width="0.5px" />'; 
  41.  
  42. // OPTIMUM Marker (? AVERAGE) 
  43. if ($optimum) { 
  44. $barx = (($optimum - $min) / ($max - $min) ) * $w; 
  45. $barw = $h / 2; 
  46. $barcol = '#888888'; 
  47. $svg .= '<rect x="' . $barx . '" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />'; 
  48.  
  49. // VALUE Marker 
  50. if ($value) { 
  51. if ($min != $low && $value < $low) { 
  52. $col = 'orange'; 
  53. } else if ($max != $high && $value > $high) { 
  54. $col = 'orange'; 
  55. } else { 
  56. $col = '#008800'; 
  57. $cx = (($value - $min) / ($max - $min) ) * $w; 
  58. $cy = $h / 2; 
  59. $rx = $h / 3.5; 
  60. $ry = $h / 2.2; 
  61. $svg .= '<ellipse fill="' . $col . '" stroke="#000000" stroke-width="0.5px" cx="' . $cx . '" cy="' . $cy . '" rx="' . $rx . '" ry="' . $ry . '"/>'; 
  62.  
  63. // BoRDER 
  64. $svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="none" stroke="#888888" stroke-width="0.5px" />'; 
  65.  
  66. $svg .= '</g></svg>'; 
  67. } else if ($type == '3') { 
  68. ///////////////////////////////////////////////////////////////////////////////////// 
  69. ///////// CUSTOM <meter type="2"> 
  70. ///////////////////////////////////////////////////////////////////////////////////// 
  71. $h = 10; 
  72. $w = 100; 
  73. $border_radius = 0.143; // Factor of Height 
  74.  
  75. $svg = '<?xml version="1.0" encoding="UTF-8"?> 
  76. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
  77. <svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g> 
  78.  
  79.  
  80. <defs> 
  81. <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  82. <stop offset="0%" stop-color="rgb(222, 222, 222)" /> 
  83. <stop offset="20%" stop-color="rgb(232, 232, 232)" /> 
  84. <stop offset="25%" stop-color="rgb(232, 232, 232)" /> 
  85. <stop offset="100%" stop-color="rgb(182, 182, 182)" /> 
  86. </linearGradient> 
  87.  
  88. </defs> 
  89. '; 
  90. $svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="#f4f4f4" stroke="none" />'; 
  91.  
  92. // LOW to HIGH region 
  93. if ($low && $high && ($low != $min || $high != $max)) { 
  94. //if ($low && $high) { 
  95. $barx = (($low - $min) / ($max - $min) ) * $w; 
  96. $barw = (($high - $low) / ($max - $min) ) * $w; 
  97. $svg .= '<rect x="' . $barx . '" y="0" width="' . $barw . '" height="' . $h . '" fill="url(#GrGRAY)" stroke="#888888" stroke-width="0.5px" />'; 
  98.  
  99. // OPTIMUM Marker (? AVERAGE) 
  100. if ($optimum) { 
  101. $barx = (($optimum - $min) / ($max - $min) ) * $w; 
  102. $barw = $h / 2; 
  103. $barcol = '#888888'; 
  104. $svg .= '<rect x="' . $barx . '" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />'; 
  105.  
  106. // VALUE Marker 
  107. if ($value) { 
  108. if ($min != $low && $value < $low) { 
  109. $col = 'orange'; 
  110. } else if ($max != $high && $value > $high) { 
  111. $col = 'orange'; 
  112. } else { 
  113. $col = 'orange'; 
  114. $cx = (($value - $min) / ($max - $min) ) * $w; 
  115. $cy = $h / 2; 
  116. $rx = $h / 2.2; 
  117. $ry = $h / 2.2; 
  118. $svg .= '<ellipse fill="' . $col . '" stroke="#000000" stroke-width="0.5px" cx="' . $cx . '" cy="' . $cy . '" rx="' . $rx . '" ry="' . $ry . '"/>'; 
  119.  
  120. // BoRDER 
  121. $svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="none" stroke="#888888" stroke-width="0.5px" />'; 
  122.  
  123. $svg .= '</g></svg>'; 
  124. } else { 
  125. ///////////////////////////////////////////////////////////////////////////////////// 
  126. ///////// DEFAULT <meter> 
  127. ///////////////////////////////////////////////////////////////////////////////////// 
  128. $h = 10; 
  129. $w = 50; 
  130. $border_radius = 0.143; // Factor of Height 
  131.  
  132. $svg = '<?xml version="1.0" encoding="UTF-8"?> 
  133. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
  134. <svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g> 
  135.  
  136. <defs> 
  137. <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  138. <stop offset="0%" stop-color="rgb(222, 222, 222)" /> 
  139. <stop offset="20%" stop-color="rgb(232, 232, 232)" /> 
  140. <stop offset="25%" stop-color="rgb(232, 232, 232)" /> 
  141. <stop offset="100%" stop-color="rgb(182, 182, 182)" /> 
  142. </linearGradient> 
  143.  
  144. <linearGradient id="GrRED" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  145. <stop offset="0%" stop-color="rgb(255, 162, 162)" /> 
  146. <stop offset="20%" stop-color="rgb(255, 218, 218)" /> 
  147. <stop offset="25%" stop-color="rgb(255, 218, 218)" /> 
  148. <stop offset="100%" stop-color="rgb(255, 0, 0)" /> 
  149. </linearGradient> 
  150.  
  151. <linearGradient id="GrGREEN" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  152. <stop offset="0%" stop-color="rgb(102, 230, 102)" /> 
  153. <stop offset="20%" stop-color="rgb(218, 255, 218)" /> 
  154. <stop offset="25%" stop-color="rgb(218, 255, 218)" /> 
  155. <stop offset="100%" stop-color="rgb(0, 148, 0)" /> 
  156. </linearGradient> 
  157.  
  158. <linearGradient id="GrBLUE" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  159. <stop offset="0%" stop-color="rgb(102, 102, 230)" /> 
  160. <stop offset="20%" stop-color="rgb(238, 238, 238)" /> 
  161. <stop offset="25%" stop-color="rgb(238, 238, 238)" /> 
  162. <stop offset="100%" stop-color="rgb(0, 0, 128)" /> 
  163. </linearGradient> 
  164.  
  165. <linearGradient id="GrORANGE" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  166. <stop offset="0%" stop-color="rgb(255, 186, 0)" /> 
  167. <stop offset="20%" stop-color="rgb(255, 238, 168)" /> 
  168. <stop offset="25%" stop-color="rgb(255, 238, 168)" /> 
  169. <stop offset="100%" stop-color="rgb(255, 155, 0)" /> 
  170. </linearGradient> 
  171. </defs> 
  172.  
  173. <rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $w . '" height="' . $h . '" fill="url(#GrGRAY)" stroke="none" /> 
  174. '; 
  175.  
  176. if ($value) { 
  177. $barw = (($value - $min) / ($max - $min) ) * $w; 
  178. if ($optimum < $low) { 
  179. if ($value < $low) { 
  180. $barcol = 'url(#GrGREEN)'; 
  181. } else if ($value > $high) { 
  182. $barcol = 'url(#GrRED)'; 
  183. } else { 
  184. $barcol = 'url(#GrORANGE)'; 
  185. } else if ($optimum > $high) { 
  186. if ($value < $low) { 
  187. $barcol = 'url(#GrRED)'; 
  188. } else if ($value > $high) { 
  189. $barcol = 'url(#GrGREEN)'; 
  190. } else { 
  191. $barcol = 'url(#GrORANGE)'; 
  192. } else { 
  193. if ($value < $low) { 
  194. $barcol = 'url(#GrORANGE)'; 
  195. } else if ($value > $high) { 
  196. $barcol = 'url(#GrORANGE)'; 
  197. } else { 
  198. $barcol = 'url(#GrGREEN)'; 
  199. $svg .= '<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />'; 
  200.  
  201.  
  202. // Borders 
  203. //$svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$w.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />'; 
  204. if ($value) { 
  205. // $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />'; 
  206.  
  207.  
  208. $svg .= '</g></svg>'; 
  209. } else { // $tag == 'progress' 
  210. if ($type == '2') { 
  211. ///////////////////////////////////////////////////////////////////////////////////// 
  212. ///////// CUSTOM <progress type="2"> 
  213. ///////////////////////////////////////////////////////////////////////////////////// 
  214. } else { 
  215. ///////////////////////////////////////////////////////////////////////////////////// 
  216. ///////// DEFAULT <progress> 
  217. ///////////////////////////////////////////////////////////////////////////////////// 
  218. $h = 10; 
  219. $w = 100; 
  220. $border_radius = 0.143; // Factor of Height 
  221.  
  222. if ($value or $value === '0') { 
  223. $fill = 'url(#GrGRAY)'; 
  224. } else { 
  225. $fill = '#f8f8f8'; 
  226.  
  227. $svg = '<svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '"><g> 
  228.  
  229. <defs> 
  230. <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  231. <stop offset="0%" stop-color="rgb(222, 222, 222)" /> 
  232. <stop offset="20%" stop-color="rgb(232, 232, 232)" /> 
  233. <stop offset="25%" stop-color="rgb(232, 232, 232)" /> 
  234. <stop offset="100%" stop-color="rgb(182, 182, 182)" /> 
  235. </linearGradient> 
  236.  
  237. <linearGradient id="GrGREEN" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox"> 
  238. <stop offset="0%" stop-color="rgb(102, 230, 102)" /> 
  239. <stop offset="20%" stop-color="rgb(218, 255, 218)" /> 
  240. <stop offset="25%" stop-color="rgb(218, 255, 218)" /> 
  241. <stop offset="100%" stop-color="rgb(0, 148, 0)" /> 
  242. </linearGradient> 
  243.  
  244. </defs> 
  245.  
  246. <rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $w . '" height="' . $h . '" fill="' . $fill . '" stroke="none" /> 
  247. '; 
  248.  
  249. if ($value) { 
  250. $barw = (($value - $min) / ($max - $min) ) * $w; 
  251. $barcol = 'url(#GrGREEN)'; 
  252. $svg .= '<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />'; 
  253.  
  254.  
  255. // Borders 
  256. $svg .= '<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $w . '" height="' . $h . '" fill="none" stroke="#888888" stroke-width="0.5px" />'; 
  257. if ($value) { 
  258. // $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />'; 
  259.  
  260.  
  261. $svg .= '</g></svg>'; 
  262.  
  263. return $svg; 
  264.