From e837822172aa714eeac35593393407c859dc0c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 7 Aug 2023 23:32:38 +0200 Subject: [PATCH] mermaid: fix broken zoom since update to v10 #608 --- static/js/theme.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/static/js/theme.js b/static/js/theme.js index 88a6f92b8b..84d0786dce 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -277,18 +277,23 @@ function initMermaid( update, attrs ) { var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) ); if( is_initialized ){ mermaid.initialize( Object.assign( { "securityLevel": "antiscript", "startOnLoad": false }, window.relearn.mermaidConfig, { theme: attrs.theme } ) ); - mermaid.run(); - // zoom for Mermaid - // https://github.com/mermaid-js/mermaid/issues/1860#issuecomment-1345440607 - var svgs = d3.selectAll( '.mermaid.zoom svg' ); - svgs.each( function(){ - var svg = d3.select( this ); - svg.html( '' + svg.html() + '' ); - var inner = svg.select( 'g' ); - var zoom = d3.zoom().on( 'zoom', function( e ){ - inner.attr( 'transform', e.transform); - }); - svg.call( zoom ); + mermaid.run({ + postRenderCallback: function(){ + // zoom for Mermaid + // https://github.com/mermaid-js/mermaid/issues/1860#issuecomment-1345440607 + var svgs = d3.selectAll( '.mermaid.zoom svg' ); + svgs.each( function(){ + var svg = d3.select( this ); + svg.html( '' + svg.html() + '' ); + var inner = svg.select( 'g' ); + var zoom = d3.zoom().on( 'zoom', function( e ){ + inner.attr( 'transform', e.transform); + }); + svg.call( zoom ); + }); + }, + querySelector: '.mermaid', + suppressErrors: true }); } if( update && search && search.length ){