Click events not firing on v2.8.3
See original GitHub issueDescribe the bug Click events on a simple mermaid graph do not fire in v2.8.3. I have attached the full web page, but the core is a simple, two-node flowchart:
<div id="FirstLine" class="mermaid">
graph TB
FullFirstSquad-->StripedFirstSquad
click FullFirstSquad showFullFirstSquad "show details"
</div>
mermaid is initialized as below:
<script type="text/javascript">
function showFullFirstSquad(elemName) {
console.log('show ' + elemName);
}
mermaid.initialize({ startOnLoad: true, securityLevel: 'loose', logLevel: 1 });
</script>
mermaid draws the flowchart correctly but the “show details” text does not appear on mouse over, and the showFullFirstSquad() method is not called on click.
The problem seems to be due to calling the cb() method in webpackAPI.render. This is the code from the webpack:
if (typeof cb !== 'undefined') {
cb(svgCode, _diagrams_flowchart_flowDb__WEBPACK_IMPORTED_MODULE_8__["default"].bindFunctions);
//cb(svgCode, _diagrams_gantt_ganttDb__WEBPACK_IMPORTED_MODULE_14__["default"].bindFunctions);
} else {
_logger__WEBPACK_IMPORTED_MODULE_4__["logger"].warn('CB = undefined!');
}
This code corresponds to two lines in mermaidAPI.render() on lines 500 & 501. I have commented out the second call to cb, and if I do that, the “show details” text appears on mouse over, and a click calls the method. As best I can tell, the first call to cb sets up the mouseover and click event handlers correctly, then the second call wipes out the working click handlers. I am not 100% sure but the second call may completely redraw the svg too.
This is running on ubuntu in firefox 68.0.1.
The full page: index.txt
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (2 by maintainers)
Top GitHub Comments
I have debugged this a bit more. The svg code is inserted into the page twice, once by flowDB and once by ganttDB. The cb function that is called twice is an anonymous function passed in to mermaidAPI.render:
In the first call to cb() the svgCode as given by the parsing of the graph is set on the element.InnerHTML. The “callback” function is undefined and is not called. The bindFunctions method is called on the flowDB object. This object has two functions in its funs[] array, which it dutifully sets on the appropriate svg elements.
In the second call to cb() the same svgCode as given by the parsing of the graph is set on the element.InnerHTML. This wipes out the svg elements created in the first call, including their event bindings. The “callback” function is again undefined and is not called. The bindFunctions method is called on the ganttDB object. This object has zero functions in its funs[] array, so none get set.
I am unclear as to the bigger, architectural picture here, but it would seem that just on the basis of the innerHTML being set twice with the same svg code, something has gotten muddled. My first thought is that the different calls to cb() should be in a switch statement based on graphType, as with earlier calls to setConf() and draw(). My second thought is that there should be a factory based on graphType instead, returning only one object that would have these methods on it.
Hi guys, I have the next error with the click event when I try to run a function from some node from the mermaid diagram:
do you have any idea about that? my conf is the next:
package.json:
index.html:
main.ts: