PathMap.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /**
  2. * Map containing SVG paths needed by BpmnRenderer.
  3. */
  4. export default function PathMap() {
  5. /**
  6. * Contains a map of path elements
  7. *
  8. * <h1>Path definition</h1>
  9. * A parameterized path is defined like this:
  10. * <pre>
  11. * 'GATEWAY_PARALLEL': {
  12. * d: 'm {mx},{my} {e.x0},0 0,{e.x1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  13. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  14. * height: 17.5,
  15. * width: 17.5,
  16. * heightElements: [2.5, 7.5],
  17. * widthElements: [2.5, 7.5]
  18. * }
  19. * </pre>
  20. * <p>It's important to specify a correct <b>height and width</b> for the path as the scaling
  21. * is based on the ratio between the specified height and width in this object and the
  22. * height and width that is set as scale target (Note x,y coordinates will be scaled with
  23. * individual ratios).</p>
  24. * <p>The '<b>heightElements</b>' and '<b>widthElements</b>' array must contain the values that will be scaled.
  25. * The scaling is based on the computed ratios.
  26. * Coordinates on the y axis should be in the <b>heightElement</b>'s array, they will be scaled using
  27. * the computed ratio coefficient.
  28. * In the parameterized path the scaled values can be accessed through the 'e' object in {} brackets.
  29. * <ul>
  30. * <li>The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....</li>
  31. * <li>The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....</li>
  32. * </ul>
  33. * The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index.
  34. * </p>
  35. */
  36. this.pathMap = {
  37. 'EVENT_MESSAGE': {
  38. d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}',
  39. height: 36,
  40. width: 36,
  41. heightElements: [6, 14],
  42. widthElements: [10.5, 21]
  43. },
  44. 'EVENT_SIGNAL': {
  45. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
  46. height: 36,
  47. width: 36,
  48. heightElements: [18],
  49. widthElements: [10, 20]
  50. },
  51. 'EVENT_ESCALATION': {
  52. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
  53. height: 36,
  54. width: 36,
  55. heightElements: [20, 7],
  56. widthElements: [8]
  57. },
  58. 'EVENT_CONDITIONAL': {
  59. d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
  60. 'M {e.x2},{e.y3} l {e.x0},0 ' +
  61. 'M {e.x2},{e.y4} l {e.x0},0 ' +
  62. 'M {e.x2},{e.y5} l {e.x0},0 ' +
  63. 'M {e.x2},{e.y6} l {e.x0},0 ' +
  64. 'M {e.x2},{e.y7} l {e.x0},0 ' +
  65. 'M {e.x2},{e.y8} l {e.x0},0 ',
  66. height: 36,
  67. width: 36,
  68. heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
  69. widthElements: [10.5, 14.5, 12.5]
  70. },
  71. 'EVENT_LINK': {
  72. d: 'm {mx},{my} 0,{e.y0} -{e.x1},0 0,{e.y1} {e.x1},0 0,{e.y0} {e.x0},-{e.y2} -{e.x0},-{e.y2} z',
  73. height: 36,
  74. width: 36,
  75. heightElements: [4.4375, 6.75, 7.8125],
  76. widthElements: [9.84375, 13.5]
  77. },
  78. 'EVENT_ERROR': {
  79. d: 'm {mx},{my} {e.x0},-{e.y0} {e.x1},-{e.y1} {e.x2},{e.y2} {e.x3},-{e.y3} -{e.x4},{e.y4} -{e.x5},-{e.y5} z',
  80. height: 36,
  81. width: 36,
  82. heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
  83. widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
  84. },
  85. 'EVENT_CANCEL_45': {
  86. d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  87. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  88. height: 36,
  89. width: 36,
  90. heightElements: [4.75, 8.5],
  91. widthElements: [4.75, 8.5]
  92. },
  93. 'EVENT_COMPENSATION': {
  94. d: 'm {mx},{my} {e.x0},-{e.y0} 0,{e.y1} z m {e.x1},-{e.y2} {e.x2},-{e.y3} 0,{e.y1} -{e.x2},-{e.y3} z',
  95. height: 36,
  96. width: 36,
  97. heightElements: [6.5, 13, 0.4, 6.1],
  98. widthElements: [9, 9.3, 8.7]
  99. },
  100. 'EVENT_TIMER_WH': {
  101. d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
  102. height: 36,
  103. width: 36,
  104. heightElements: [10, 2],
  105. widthElements: [3, 7]
  106. },
  107. 'EVENT_TIMER_LINE': {
  108. d: 'M {mx},{my} ' +
  109. 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
  110. height: 36,
  111. width: 36,
  112. heightElements: [10, 3],
  113. widthElements: [0, 0]
  114. },
  115. 'EVENT_MULTIPLE': {
  116. d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
  117. height: 36,
  118. width: 36,
  119. heightElements: [6.28099, 12.56199],
  120. widthElements: [3.1405, 9.42149, 12.56198]
  121. },
  122. 'EVENT_PARALLEL_MULTIPLE': {
  123. d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  124. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  125. height: 36,
  126. width: 36,
  127. heightElements: [2.56228, 7.68683],
  128. widthElements: [2.56228, 7.68683]
  129. },
  130. 'GATEWAY_EXCLUSIVE': {
  131. d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
  132. '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
  133. '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
  134. height: 17.5,
  135. width: 17.5,
  136. heightElements: [8.5, 6.5312, -6.5312, -8.5],
  137. widthElements: [6.5, -6.5, 3, -3, 5, -5]
  138. },
  139. 'GATEWAY_PARALLEL': {
  140. d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  141. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  142. height: 30,
  143. width: 30,
  144. heightElements: [5, 12.5],
  145. widthElements: [5, 12.5]
  146. },
  147. 'GATEWAY_EVENT_BASED': {
  148. d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
  149. height: 11,
  150. width: 11,
  151. heightElements: [-6, 6, 12, -12],
  152. widthElements: [9, -3, -12]
  153. },
  154. 'GATEWAY_COMPLEX': {
  155. d:'m {mx},{my} 0,{e.y0} -{e.x0},-{e.y1} -{e.x1},{e.y2} {e.x0},{e.y1} -{e.x2},0 0,{e.y3} ' +
  156. '{e.x2},0 -{e.x0},{e.y1} l {e.x1},{e.y2} {e.x0},-{e.y1} 0,{e.y0} {e.x3},0 0,-{e.y0} {e.x0},{e.y1} ' +
  157. '{e.x1},-{e.y2} -{e.x0},-{e.y1} {e.x2},0 0,-{e.y3} -{e.x2},0 {e.x0},-{e.y1} -{e.x1},-{e.y2} ' +
  158. '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
  159. height: 17.125,
  160. width: 17.125,
  161. heightElements: [4.875, 3.4375, 2.125, 3],
  162. widthElements: [3.4375, 2.125, 4.875, 3]
  163. },
  164. 'DATA_OBJECT_PATH': {
  165. d:'m 0,0 {e.x1},0 {e.x0},{e.y0} 0,{e.y1} -{e.x2},0 0,-{e.y2} {e.x1},0 0,{e.y0} {e.x0},0',
  166. height: 61,
  167. width: 51,
  168. heightElements: [10, 50, 60],
  169. widthElements: [10, 40, 50, 60]
  170. },
  171. 'DATA_OBJECT_COLLECTION_PATH': {
  172. d:'m {mx}, {my} ' +
  173. 'm 0 15 l 0 -15 ' +
  174. 'm 4 15 l 0 -15 ' +
  175. 'm 4 15 l 0 -15 ',
  176. height: 61,
  177. width: 51,
  178. heightElements: [12],
  179. widthElements: [1, 6, 12, 15]
  180. },
  181. 'DATA_ARROW': {
  182. d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
  183. height: 61,
  184. width: 51,
  185. heightElements: [],
  186. widthElements: []
  187. },
  188. 'DATA_STORE': {
  189. d:'m {mx},{my} ' +
  190. 'l 0,{e.y2} ' +
  191. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  192. 'l 0,-{e.y2} ' +
  193. 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
  194. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  195. 'm -{e.x2},{e.y0}' +
  196. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
  197. 'm -{e.x2},{e.y0}' +
  198. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
  199. height: 61,
  200. width: 61,
  201. heightElements: [7, 10, 45],
  202. widthElements: [2, 58, 60]
  203. },
  204. 'TEXT_ANNOTATION': {
  205. d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
  206. height: 30,
  207. width: 10,
  208. heightElements: [30],
  209. widthElements: [10]
  210. },
  211. 'MARKER_SUB_PROCESS': {
  212. d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
  213. height: 10,
  214. width: 10,
  215. heightElements: [],
  216. widthElements: []
  217. },
  218. 'MARKER_PARALLEL': {
  219. d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
  220. height: 10,
  221. width: 10,
  222. heightElements: [],
  223. widthElements: []
  224. },
  225. 'MARKER_SEQUENTIAL': {
  226. d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
  227. height: 10,
  228. width: 10,
  229. heightElements: [],
  230. widthElements: []
  231. },
  232. 'MARKER_COMPENSATION': {
  233. d: 'm {mx},{my} 7,-5 0,10 z m 7.1,-0.3 6.9,-4.7 0,10 -6.9,-4.7 z',
  234. height: 10,
  235. width: 21,
  236. heightElements: [],
  237. widthElements: []
  238. },
  239. 'MARKER_LOOP': {
  240. d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
  241. '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
  242. '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
  243. 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
  244. height: 13.9,
  245. width: 13.7,
  246. heightElements: [],
  247. widthElements: []
  248. },
  249. 'MARKER_ADHOC': {
  250. d: 'm {mx},{my} m 0.84461,2.64411 c 1.05533,-1.23780996 2.64337,-2.07882 4.29653,-1.97997996 2.05163,0.0805 ' +
  251. '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
  252. '1.2775,-0.64078 1.7542,-1.17511 0,0.56023 0,1.12046 0,1.6807 -0.98706,0.96237996 -2.29792,1.62393996 ' +
  253. '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
  254. '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
  255. height: 4,
  256. width: 15,
  257. heightElements: [],
  258. widthElements: []
  259. },
  260. 'TASK_TYPE_SEND': {
  261. d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}',
  262. height: 14,
  263. width: 21,
  264. heightElements: [6, 14],
  265. widthElements: [10.5, 21]
  266. },
  267. 'TASK_TYPE_SCRIPT': {
  268. d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
  269. 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
  270. 'm -7,-12 l 5,0 ' +
  271. 'm -4.5,3 l 4.5,0 ' +
  272. 'm -3,3 l 5,0' +
  273. 'm -4,3 l 5,0',
  274. height: 15,
  275. width: 12.6,
  276. heightElements: [6, 14],
  277. widthElements: [10.5, 21]
  278. },
  279. 'TASK_TYPE_USER_1': {
  280. d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
  281. '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
  282. '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
  283. 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
  284. 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
  285. },
  286. 'TASK_TYPE_USER_2': {
  287. d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
  288. '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
  289. },
  290. 'TASK_TYPE_USER_3': {
  291. d: 'm {mx},{my} m -6.9,-3.80 c 0,0 2.25099998,-2.358 4.27399998,-1.177 2.024,1.181 4.221,1.537 ' +
  292. '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
  293. '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
  294. },
  295. 'TASK_TYPE_MANUAL': {
  296. d: 'm {mx},{my} c 0.234,-0.01 5.604,0.008 8.029,0.004 0.808,0 1.271,-0.172 1.417,-0.752 0.227,-0.898 ' +
  297. '-0.334,-1.314 -1.338,-1.316 -2.467,-0.01 -7.886,-0.004 -8.108,-0.004 -0.014,-0.079 0.016,-0.533 0,-0.61 ' +
  298. '0.195,-0.042 8.507,0.006 9.616,0.002 0.877,-0.007 1.35,-0.438 1.353,-1.208 0.003,-0.768 -0.479,-1.09 ' +
  299. '-1.35,-1.091 -2.968,-0.002 -9.619,-0.013 -9.619,-0.013 v -0.591 c 0,0 5.052,-0.016 7.225,-0.016 ' +
  300. '0.888,-0.002 1.354,-0.416 1.351,-1.193 -0.006,-0.761 -0.492,-1.196 -1.361,-1.196 -3.473,-0.005 ' +
  301. '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
  302. '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
  303. '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
  304. '-1.516,1.253 -1.882,2.19 -0.37000002,0.95 -0.17,2.01 -0.166,2.979 0.004,0.718 -0.27300002,1.345 ' +
  305. '-0.055,2.063 0.629,2.087 2.425,3.312 4.859,3.318 4.6179995,0.014 9.2379995,-0.139 13.8569995,-0.158 ' +
  306. '0.755,-0.004 1.171,-0.301 1.182,-1.033 0.012,-0.754 -0.423,-0.969 -1.183,-0.973 -1.778,-0.01 ' +
  307. '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
  308. },
  309. 'TASK_TYPE_INSTANTIATING_SEND': {
  310. d: 'm {mx},{my} l 0,8.4 l 12.6,0 l 0,-8.4 z l 6.3,3.6 l 6.3,-3.6'
  311. },
  312. 'TASK_TYPE_SERVICE': {
  313. d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
  314. '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
  315. '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
  316. 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
  317. '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
  318. '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
  319. 'h -2.241173 l 0.0042,1.63124 c -0.353763,0.0736 -0.705369,0.17977 -1.049785,0.32371 -0.344415,0.14437 ' +
  320. '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
  321. 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
  322. 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
  323. '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
  324. 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
  325. 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  326. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  327. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  328. },
  329. 'TASK_TYPE_SERVICE_FILL': {
  330. d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  331. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  332. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  333. },
  334. 'TASK_TYPE_BUSINESS_RULE_HEADER': {
  335. d: 'm {mx},{my} 0,4 20,0 0,-4 z'
  336. },
  337. 'TASK_TYPE_BUSINESS_RULE_MAIN': {
  338. d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
  339. 'm 0,8 l 20,0 ' +
  340. 'm -13,-4 l 0,8'
  341. },
  342. 'MESSAGE_FLOW_MARKER': {
  343. d: 'm {mx},{my} m -10.5 ,-7 l 0,14 l 21,0 l 0,-14 z l 10.5,6 l 10.5,-6'
  344. }
  345. };
  346. this.getRawPath = function getRawPath(pathId) {
  347. return this.pathMap[pathId].d;
  348. };
  349. /**
  350. * Scales the path to the given height and width.
  351. * <h1>Use case</h1>
  352. * <p>Use case is to scale the content of elements (event, gateways) based
  353. * on the element bounding box's size.
  354. * </p>
  355. * <h1>Why not transform</h1>
  356. * <p>Scaling a path with transform() will also scale the stroke and IE does not support
  357. * the option 'non-scaling-stroke' to prevent this.
  358. * Also there are use cases where only some parts of a path should be
  359. * scaled.</p>
  360. *
  361. * @param {string} pathId The ID of the path.
  362. * @param {Object} param <p>
  363. * Example param object scales the path to 60% size of the container (data.width, data.height).
  364. * <pre>
  365. * {
  366. * xScaleFactor: 0.6,
  367. * yScaleFactor:0.6,
  368. * containerWidth: data.width,
  369. * containerHeight: data.height,
  370. * position: {
  371. * mx: 0.46,
  372. * my: 0.2,
  373. * }
  374. * }
  375. * </pre>
  376. * <ul>
  377. * <li>targetpathwidth = xScaleFactor * containerWidth</li>
  378. * <li>targetpathheight = yScaleFactor * containerHeight</li>
  379. * <li>Position is used to set the starting coordinate of the path. M is computed:
  380. * <ul>
  381. * <li>position.x * containerWidth</li>
  382. * <li>position.y * containerHeight</li>
  383. * </ul>
  384. * Center of the container <pre> position: {
  385. * mx: 0.5,
  386. * my: 0.5,
  387. * }</pre>
  388. * Upper left corner of the container
  389. * <pre> position: {
  390. * mx: 0.0,
  391. * my: 0.0,
  392. * }</pre>
  393. * </li>
  394. * </ul>
  395. * </p>
  396. *
  397. */
  398. this.getScaledPath = function getScaledPath(pathId, param) {
  399. var rawPath = this.pathMap[pathId];
  400. // positioning
  401. // compute the start point of the path
  402. var mx, my;
  403. if (param.abspos) {
  404. mx = param.abspos.x;
  405. my = param.abspos.y;
  406. } else {
  407. mx = param.containerWidth * param.position.mx;
  408. my = param.containerHeight * param.position.my;
  409. }
  410. var coordinates = {}; // map for the scaled coordinates
  411. if (param.position) {
  412. // path
  413. var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
  414. var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
  415. // Apply height ratio
  416. for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
  417. coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
  418. }
  419. // Apply width ratio
  420. for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
  421. coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
  422. }
  423. }
  424. // Apply value to raw path
  425. var path = format(
  426. rawPath.d, {
  427. mx: mx,
  428. my: my,
  429. e: coordinates
  430. }
  431. );
  432. return path;
  433. };
  434. }
  435. // helpers //////////////////////
  436. // copied from https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js
  437. var tokenRegex = /\{([^}]+)\}/g,
  438. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g; // matches .xxxxx or ["xxxxx"] to run over object properties
  439. function replacer(all, key, obj) {
  440. var res = obj;
  441. key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
  442. name = name || quotedName;
  443. if (res) {
  444. if (name in res) {
  445. res = res[name];
  446. }
  447. typeof res == 'function' && isFunc && (res = res());
  448. }
  449. });
  450. res = (res == null || res == obj ? all : res) + '';
  451. return res;
  452. }
  453. function format(str, obj) {
  454. return String(str).replace(tokenRegex, function(all, key) {
  455. return replacer(all, key, obj);
  456. });
  457. }