(options, x2p, y2p)
| 303 | }; |
| 304 | |
| 305 | function convertPath(options, x2p, y2p) { |
| 306 | const pathIn = options.path; |
| 307 | const xSizemode = options.xsizemode; |
| 308 | const ySizemode = options.ysizemode; |
| 309 | const xAnchor = options.xanchor; |
| 310 | const yAnchor = options.yanchor; |
| 311 | const isArrayXref = Array.isArray(options.xref); |
| 312 | const isArrayYref = Array.isArray(options.yref); |
| 313 | var xVertexIndex = 0; |
| 314 | var yVertexIndex = 0; |
| 315 | |
| 316 | return pathIn.replace(constants.segmentRE, function(segment) { |
| 317 | var paramNumber = 0; |
| 318 | var segmentType = segment.charAt(0); |
| 319 | var xParams = constants.paramIsX[segmentType]; |
| 320 | var yParams = constants.paramIsY[segmentType]; |
| 321 | var nParams = constants.numParams[segmentType]; |
| 322 | const hasDrawnX = xParams.drawn !== undefined; |
| 323 | const hasDrawnY = yParams.drawn !== undefined; |
| 324 | |
| 325 | // Use vertex indices for array refs (same converter for all params in segment) |
| 326 | const segmentX2p = isArrayXref ? x2p[xVertexIndex] : x2p; |
| 327 | const segmentY2p = isArrayYref ? y2p[yVertexIndex] : y2p; |
| 328 | |
| 329 | var paramString = segment.slice(1).replace(constants.paramRE, function(param) { |
| 330 | if(xParams[paramNumber]) { |
| 331 | if(xSizemode === 'pixel') param = segmentX2p(xAnchor) + Number(param); |
| 332 | else param = segmentX2p(param); |
| 333 | } else if(yParams[paramNumber]) { |
| 334 | if(ySizemode === 'pixel') param = segmentY2p(yAnchor) - Number(param); |
| 335 | else param = segmentY2p(param); |
| 336 | } |
| 337 | paramNumber++; |
| 338 | |
| 339 | if(paramNumber > nParams) param = 'X'; |
| 340 | return param; |
| 341 | }); |
| 342 | |
| 343 | if(paramNumber > nParams) { |
| 344 | paramString = paramString.replace(/[\s,]*X.*/, ''); |
| 345 | Lib.log('Ignoring extra params in segment ' + segment); |
| 346 | } |
| 347 | |
| 348 | if(hasDrawnX) xVertexIndex++; |
| 349 | if(hasDrawnY) yVertexIndex++; |
| 350 | |
| 351 | return segmentType + paramString; |
| 352 | }); |
| 353 | } |
| 354 | |
| 355 | exports.getPixelShift = getPixelShift; |
| 356 | function getPixelShift(axis, shift) { |
no outgoing calls
no test coverage detected
searching dependent graphs…