(layout, img)
| 394 | } |
| 395 | |
| 396 | function imageToBBox(layout, img) { |
| 397 | var bbox = {}; |
| 398 | // these will be pixels from the bottom of the plot and will be manipulated |
| 399 | // below to be compatible with the SVG bounding box |
| 400 | var x0; |
| 401 | var x1; |
| 402 | var y0; |
| 403 | var y1; |
| 404 | switch(img.xanchor) { |
| 405 | case 'left': |
| 406 | x0 = mapAROCoordToPixel(layout, 'xref', img, 'x', undefined, true); |
| 407 | x1 = mapAROCoordToPixel(layout, 'xref', img, 'x', img.sizex, true); |
| 408 | break; |
| 409 | case 'right': |
| 410 | x0 = mapAROCoordToPixel(layout, 'xref', img, 'x', -img.sizex, true); |
| 411 | x1 = mapAROCoordToPixel(layout, 'xref', img, 'x', undefined, true); |
| 412 | break; |
| 413 | case 'center': |
| 414 | x0 = mapAROCoordToPixel(layout, 'xref', img, 'x', -img.sizex * 0.5, true); |
| 415 | x1 = mapAROCoordToPixel(layout, 'xref', img, 'x', img.sizex * 0.5, true); |
| 416 | break; |
| 417 | default: |
| 418 | throw 'Bad xanchor: ' + img.xanchor; |
| 419 | } |
| 420 | switch(img.yanchor) { |
| 421 | case 'bottom': |
| 422 | y0 = mapAROCoordToPixel(layout, 'yref', img, 'y', undefined, true); |
| 423 | y1 = mapAROCoordToPixel(layout, 'yref', img, 'y', img.sizey, true); |
| 424 | break; |
| 425 | case 'top': |
| 426 | y0 = mapAROCoordToPixel(layout, 'yref', img, 'y', -img.sizey, true); |
| 427 | y1 = mapAROCoordToPixel(layout, 'yref', img, 'y', undefined, true); |
| 428 | break; |
| 429 | case 'middle': |
| 430 | y0 = mapAROCoordToPixel(layout, 'yref', img, 'y', -img.sizey * 0.5, true); |
| 431 | y1 = mapAROCoordToPixel(layout, 'yref', img, 'y', img.sizey * 0.5, true); |
| 432 | break; |
| 433 | default: |
| 434 | throw 'Bad yanchor: ' + img.yanchor; |
| 435 | } |
| 436 | bbox.x = x0; |
| 437 | bbox.width = x1 - x0; |
| 438 | // done this way because the pixel value of y1 will be smaller than the |
| 439 | // pixel value x0 if y1 > y0 (because of how SVG draws relative to the top |
| 440 | // of the screen) |
| 441 | bbox.y = y1; |
| 442 | bbox.height = y0 - y1; |
| 443 | return bbox; |
| 444 | } |
| 445 | |
| 446 | function coordsEq(a, b) { |
| 447 | if(a && b) { |
no test coverage detected
searching dependent graphs…