Flowchart.js SVG渲染在弹出窗口中搞砸了

时间:2018-03-02 10:31:10

标签: javascript svg rendering raphael flowchart

我使用flowchart.js库来获取流程图的SVG渲染。 我需要在带有动态引导面板的弹出窗口中包含流程图渲染,但结果搞砸了(框上的标签和小渲染:

enter image description here

我的代码是:

<div class="panel panel-default">   
  <div class="panel-body">      
    <div id="diagram"></div>    
    </div> 
</div>

<script type="text/javascript">

    $(document).ready(function () {
        var diagram = flowchart.parse('st=>start: Start:>http://www.google.com[blank]\n' +
            'e=>end:>http://www.google.com\n' +
            'op1=>operation: My Operation\n' +
            'op2=>operation: Stuff|current\n' +
            'sub1=>subroutine: My Subroutine\n' +
            'cond=>condition: Yes \n' + // use cond(align-next=no) to disable vertical align of symbols below
            'or No?\n:>http://www.google.com\n' +
            'c2=>condition: Good idea|rejected\n' +
            'io=>inputoutput: catch something...|request\n' +
            '\n' +
            'st->op1(right)->cond\n' +
            'cond(yes, right)->c2\n' + // conditions can also be redirected like cond(yes, bottom) or cond(yes, right)
            'cond(no)->sub1(left)->op1\n' + // the other symbols too...
            'c2(true)->io->e\n' +
            'c2(false)->op2->e'  //allow for true and false in conditionals
        );
        diagram.drawSVG('diagram');

    });
</script>

如何处理?

非常感谢

1 个答案:

答案 0 :(得分:2)

此代码可以正常工作:

<html>

<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowchart/1.8.0/flowchart.min.js"></script>
</head>

<body>

<div class="panel panel-default">   
  <div class="panel-body">      
    <div id="diagram"></div>    
    </div> 
</div>

<script type="text/javascript">

    $(document).ready(function () {
        var diagram = flowchart.parse('st=>start: Start:>http://www.google.com[blank]\n' +
            'e=>end:>http://www.google.com\n' +
            'op1=>operation: My Operation\n' +
            'op2=>operation: Stuff|current\n' +
            'sub1=>subroutine: My Subroutine\n' +
            'cond=>condition: Yes \n' + // use cond(align-next=no) to disable vertical align of symbols below
            'or No?\n:>http://www.google.com\n' +
            'c2=>condition: Good idea|rejected\n' +
            'io=>inputoutput: catch something...|request\n' +
            '\n' +
            'st->op1(right)->cond\n' +
            'cond(yes, right)->c2\n' + // conditions can also be redirected like cond(yes, bottom) or cond(yes, right)
            'cond(no)->sub1(left)->op1\n' + // the other symbols too...
            'c2(true)->io->e\n' +
            'c2(false)->op2->e'  //allow for true and false in conditionals
        );
        diagram.drawSVG('diagram');

    });
</script>

</body>
</html>

输出:

flowchart.js

也许您正在混合不兼容的版本,或者您的问题中缺少一些重要信息。