MCPcopy
hub / github.com/antvis/Infographic / getBoundViewBox

Function getBoundViewBox

src/utils/padding.ts:70–91  ·  view source on GitHub ↗
(
  svg: SVGSVGElement,
  padding: ParsedPadding,
)

Source from the content-addressed store, hash-verified

68}
69
70export function getBoundViewBox(
71 svg: SVGSVGElement,
72 padding: ParsedPadding,
73): string {
74 const bbox = svg.getBBox();
75 const clientRect = svg.getBoundingClientRect();
76 const scaleX = clientRect.width > 0 ? bbox.width / clientRect.width : 1;
77 const scaleY = clientRect.height > 0 ? bbox.height / clientRect.height : 1;
78
79 const [topPx, rightPx, bottomPx, leftPx] = padding;
80 const topSvg = topPx * scaleY;
81 const rightSvg = rightPx * scaleX;
82 const bottomSvg = bottomPx * scaleY;
83 const leftSvg = leftPx * scaleX;
84
85 const newX = bbox.x - leftSvg;
86 const newY = bbox.y - topSvg;
87 const newWidth = bbox.width + leftSvg + rightSvg;
88 const newHeight = bbox.height + topSvg + bottomSvg;
89
90 return `${newX} ${newY} ${newWidth} ${newHeight}`;
91}
92
93function setSVGPaddingInBrowser(svg: SVGSVGElement, padding: ParsedPadding) {
94 const viewBox = getBoundViewBox(svg, padding);

Callers 2

updateOriginViewBoxMethod · 0.90
setSVGPaddingInBrowserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected