{"version":3,"file":"setupGraphViewbox-a4603a92.js","sources":["../src/setupGraphViewbox.js"],"sourcesContent":["import { log } from './logger';\n\n/**\n * Applies d3 attributes\n *\n * @param {any} d3Elem D3 Element to apply the attributes onto\n * @param {[string, string][]} attrs Object.keys equivalent format of key to value mapping of attributes\n */\nconst d3Attrs = function (d3Elem, attrs) {\n for (let attr of attrs) {\n d3Elem.attr(attr[0], attr[1]);\n }\n};\n\n/**\n * Gives attributes for an SVG's size given arguments\n *\n * @param {number} height The height of the SVG\n * @param {number} width The width of the SVG\n * @param {boolean} useMaxWidth Whether or not to use max-width and set width to 100%\n * @returns {Map<'height' | 'width' | 'style', string>} Attributes for the SVG\n */\nexport const calculateSvgSizeAttrs = function (height, width, useMaxWidth) {\n let attrs = new Map();\n if (useMaxWidth) {\n attrs.set('width', '100%');\n attrs.set('style', `max-width: ${width}px;`);\n } else {\n attrs.set('height', height);\n attrs.set('width', width);\n }\n return attrs;\n};\n\n/**\n * Applies attributes from `calculateSvgSizeAttrs`\n *\n * @param {SVGSVGElement} svgElem The SVG Element to configure\n * @param {number} height The height of the SVG\n * @param {number} width The width of the SVG\n * @param {boolean} useMaxWidth Whether or not to use max-width and set width to 100%\n */\nexport const configureSvgSize = function (svgElem, height, width, useMaxWidth) {\n const attrs = calculateSvgSizeAttrs(height, width, useMaxWidth);\n d3Attrs(svgElem, attrs);\n};\nexport const setupGraphViewbox = function (graph, svgElem, padding, useMaxWidth) {\n const svgBounds = svgElem.node().getBBox();\n const sWidth = svgBounds.width;\n const sHeight = svgBounds.height;\n\n log.info(`SVG bounds: ${sWidth}x${sHeight}`, svgBounds);\n\n let width = 0;\n let height = 0;\n log.info(`Graph bounds: ${width}x${height}`, graph);\n\n // let tx = 0;\n // let ty = 0;\n // if (sWidth > width) {\n // tx = (sWidth - width) / 2 + padding;\n width = sWidth + padding * 2;\n // } else {\n // if (Math.abs(sWidth - width) >= 2 * padding + 1) {\n // width = width - padding;\n // }\n // }\n // if (sHeight > height) {\n // ty = (sHeight - height) / 2 + padding;\n height = sHeight + padding * 2;\n // }\n\n // width =\n log.info(`Calculated bounds: ${width}x${height}`);\n configureSvgSize(svgElem, height, width, useMaxWidth);\n\n // Ensure the viewBox includes the whole svgBounds area with extra space for padding\n // const vBox = `0 0 ${width} ${height}`;\n const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${\n svgBounds.width + 2 * padding\n } ${svgBounds.height + 2 * padding}`;\n\n svgElem.attr('viewBox', vBox);\n};\n"],"names":["d3Attrs","d3Elem","attrs","attr","calculateSvgSizeAttrs","height","width","useMaxWidth","configureSvgSize","svgElem","setupGraphViewbox","graph","padding","svgBounds","sWidth","sHeight","log","vBox"],"mappings":";AAQA,MAAMA,IAAU,SAAUC,GAAQC,GAAO;AACvC,WAASC,KAAQD;AACf,IAAAD,EAAO,KAAKE,EAAK,CAAC,GAAGA,EAAK,CAAC,CAAC;AAEhC,GAUaC,IAAwB,SAAUC,GAAQC,GAAOC,GAAa;AACzE,MAAIL,IAAQ,oBAAI;AAChB,SAAIK,KACFL,EAAM,IAAI,SAAS,MAAM,GACzBA,EAAM,IAAI,SAAS,cAAcI,MAAU,MAE3CJ,EAAM,IAAI,UAAUG,CAAM,GAC1BH,EAAM,IAAI,SAASI,CAAK,IAEnBJ;AACT,GAUaM,IAAmB,SAAUC,GAASJ,GAAQC,GAAOC,GAAa;AAC7E,QAAML,IAAQE,EAAsBC,GAAQC,GAAOC,CAAW;AAC9D,EAAAP,EAAQS,GAASP,CAAK;AACxB,GACaQ,IAAoB,SAAUC,GAAOF,GAASG,GAASL,GAAa;AAC/E,QAAMM,IAAYJ,EAAQ,KAAM,EAAC,QAAO,GAClCK,IAASD,EAAU,OACnBE,IAAUF,EAAU;AAE1B,EAAAG,EAAI,KAAK,eAAeF,KAAUC,KAAWF,CAAS;AAEtD,MAAIP,IAAQ,GACRD,IAAS;AACb,EAAAW,EAAI,KAAK,iBAAiBV,KAASD,KAAUM,CAAK,GAMlDL,IAAQQ,IAASF,IAAU,GAQ3BP,IAASU,IAAUH,IAAU,GAI7BI,EAAI,KAAK,sBAAsBV,KAASD,GAAQ,GAChDG,EAAiBC,GAASJ,GAAQC,GAAOC,CAAW;AAIpD,QAAMU,IAAO,GAAGJ,EAAU,IAAID,KAAWC,EAAU,IAAID,KACrDC,EAAU,QAAQ,IAAID,KACpBC,EAAU,SAAS,IAAID;AAE3B,EAAAH,EAAQ,KAAK,WAAWQ,CAAI;AAC9B;"}