@@ -205,18 +205,6 @@ function checkImagesLoaded() {
205205 }
206206}
207207
208- let beforePrintHandlers = [ ] ;
209-
210- window . addEventListener ( "beforeprint" , ( ) => {
211- beforePrintHandlers . forEach ( ( h ) => h ( ) ) ;
212- } ) ;
213-
214- let afterPrintHandlers = [ ] ;
215-
216- window . addEventListener ( "afterprint" , ( ) => {
217- afterPrintHandlers . forEach ( ( h ) => h ( ) ) ;
218- } ) ;
219-
220208// This is a butchery and I hate it and never want to touch it again.
221209function calcPinSize ( pin , cdiv , connector , pinfo ) {
222210 // Find the closest pin, to maximize the pin size for best readability,
@@ -229,31 +217,28 @@ function calcPinSize(pin, cdiv, connector, pinfo) {
229217 closest = distance ;
230218 }
231219 } ) ;
232- // Set the pin's size
233220 closest = Math . sqrt ( closest ) ;
221+ // Set the pin's size
234222 const divheight = cdiv . clientHeight ;
235223 const divwidth = cdiv . clientWidth ;
236- const mult = cdiv . querySelector ( "img" ) . naturalHeight / divheight ;
237- const newheight = ( closest / mult )
238- let pxheight = divheight * 0.08 ;
239- if ( newheight < pxheight ) {
240- pxheight = newheight ;
224+ const scale = divheight / cdiv . querySelector ( "img" ) . naturalHeight ;
225+ const newheight = closest * scale ;
226+ // Default height is 8% of div
227+ let pinsize = divheight * 0.08 ;
228+ if ( newheight < pinsize ) {
229+ pinsize = newheight ;
241230 }
242- const height = ( pxheight / divheight ) * 100 ;
243- const width = ( pxheight / divwidth ) * 100 ;
244- pin . pdiv . style . height = "calc(" + height + "%)" ;
245- pin . pdiv . style . width = "calc(" + width + "%)" ;
246- pin . pdiv . style . lineHeight = "calc(" + pxheight + "px - 0.21vw)" ;
231+ // Use percent for scaling when printing
232+ const height = ( pinsize / divheight ) * 100 ;
233+ const width = ( pinsize / divwidth ) * 100 ;
234+ pin . pdiv . style . height = height + "%" ;
235+ pin . pdiv . style . width = width + "%" ;
236+ // 0.5cqh achieves vertical centering, roughly
237+ pin . pdiv . style . lineHeight = ( height - 0.5 ) + "cqh" ;
238+ // When using a percent for margins, the width value is used even for top and bottom
247239 pin . pdiv . style . marginTop = "-" + ( width / 2 ) + "%" ;
248240 pin . pdiv . style . marginLeft = "-" + ( width / 2 ) + "%" ;
249- pin . pdiv . style . fontSize = ( pxheight * 0.5 ) + "px" ;
250- // Recalculate the size for printing.
251- beforePrintHandlers . push ( ( ) => {
252- pin . pdiv . style . fontSize = "calc(calc(" + width + "px * min(640, " + divwidth + ")) * 0.0055)" ;
253- } ) ;
254- afterPrintHandlers . push ( ( ) => {
255- pin . pdiv . style . fontSize = ( pxheight * 0.5 ) + "px" ;
256- } ) ;
241+ pin . pdiv . style . fontSize = ( height * 0.5 ) + "cqh" ;
257242}
258243
259244function findBounds ( pins , i ) {
@@ -327,6 +312,8 @@ function setupColorToggle(sdiv, columns) {
327312
328313function handleImageLoad ( connector , c , sdiv , img , columns ) {
329314 const cdiv = sdiv . querySelector ( ".connector-div" ) ;
315+ const cdc = sdiv . querySelector ( ".connector-div-container" ) ;
316+ cdc . style . aspectRatio = img . naturalWidth / img . naturalHeight ;
330317 const ptemplate = document . getElementById ( "pin-template" ) ;
331318 const pitemplate = document . getElementById ( "pin-info-template" ) ;
332319 const imgHeight = img . naturalHeight ;
0 commit comments