1 line
3.7 KiB
Plaintext
1 line
3.7 KiB
Plaintext
|
{"version":3,"file":"setupGraphViewbox-16a0ba81.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":[],"mappings":";AAQA,MAAM,UAAU,SAAU,QAAQ,OAAO;AACvC,WAAS,QAAQ,OAAO;AACtB,WAAO,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAAA,EAC7B;AACH;AAUO,MAAM,wBAAwB,SAAU,QAAQ,OAAO,aAAa;AACzE,MAAI,QAAQ,oBAAI;AAChB,MAAI,aAAa;AACf,UAAM,IAAI,SAAS,MAAM;AACzB,UAAM,IAAI,SAAS,cAAc,UAAU;AAAA,EAC/C,OAAS;AACL,UAAM,IAAI,UAAU,MAAM;AAC1B,UAAM,IAAI,SAAS,KAAK;AAAA,EACzB;AACD,SAAO;AACT;AAUY,MAAC,mBAAmB,SAAU,SAAS,QAAQ,OAAO,aAAa;AAC7E,QAAM,QAAQ,sBAAsB,QAAQ,OAAO,WAAW;AAC9D,UAAQ,SAAS,KAAK;AACxB;AACY,MAAC,oBAAoB,SAAU,OAAO,SAAS,SAAS,aAAa;AAC/E,QAAM,YAAY,QAAQ,KAAM,EAAC,QAAO;AACxC,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,UAAU;AAE1B,MAAI,KAAK,eAAe,UAAU,WAAW,SAAS;AAEtD,MAAI,QAAQ;AACZ,MAAI,SAAS;AACb,MAAI,KAAK,iBAAiB,SAAS,UAAU,KAAK;AAMlD,UAAQ,SAAS,UAAU;AAQ3B,WAAS,UAAU,UAAU;AAI7B,MAAI,KAAK,sBAAsB,SAAS,QAAQ;AAChD,mBAAiB,SAAS,QAAQ,OAAO,WAAW;AAIpD,QAAM,OAAO,GAAG,UAAU,IAAI,WAAW,UAAU,IAAI,WACrD,UAAU,QAAQ,IAAI,WACpB,UAAU,SAAS,IAAI;AAE3B,UAAQ,KAAK,WAAW,IAAI;AAC9B;"}
|