{"id":2316,"date":"2017-11-11T14:11:43","date_gmt":"2017-11-11T06:11:43","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2316"},"modified":"2017-11-11T14:11:43","modified_gmt":"2017-11-11T06:11:43","slug":"js2flowchart-js-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2316","title":{"rendered":"js2flowchart.js \u6559\u7a0b"},"content":{"rendered":"<p>\n\t<a href=\"https:\/\/github.com\/Bogdan-Lyashenko\/js-code-to-svg-flowchart\" name=\"js-code-to-svg-flowchart\" target=\"_blank\" title=\"js-code-to-svg-flowchart\">js2flowchart.js<\/a>\u662f\u4e00\u4e2a\u53ef\u4ee5\u5c06\u4efb\u4f55<a href=\"https:\/\/www.xttblog.com\/?tag=javascript\" name=\"javascript\" target=\"_blank\" title=\"javascript\">JavaScript<\/a>\u4ee3\u7801\u8f6c\u6362\u6210\u6f02\u4eae\u7684<a href=\"https:\/\/www.xttblog.com\/?tag=SVG\" name=\"SVG\" target=\"_blank\" title=\"SVG\">SVG<\/a>\u6d41\u7a0b\u56fe\u7684\u53ef\u89c6\u5316\u5e93\u3002\u8be5\u63d2\u4ef6\u76ee\u524d\u5df2\u5f00\u6e90\u5230github\uff0c\u6709\u8d85\u8fc71300\u591a\u4e2astar\u3002\u672c\u6587\u4ecb\u7ecdjs2flowchart.js\u7684\u76f8\u5173\u6559\u7a0b\u3002\n<\/p>\n<h2>\n\tjs2flowchart\u80fd\u505a\u4ec0\u4e48\uff1f<br \/>\n<\/h2>\n<p>\n\tjs2flowchart\u4ee5\u60a8\u7684JS\u4ee3\u7801\u5e76\u8fd4\u56de<a href=\"https:\/\/www.xttblog.com\/?tag=SVG\" name=\"SVG\" target=\"_blank\" title=\"SVG\">SVG<\/a>\u6d41\u7a0b\u56fe\uff0c\u5728\u5ba2\u6237\u7aef\/\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\uff0c\u652f\u6301ES6\u3002\n<\/p>\n<p>\n\t\u4e3b\u8981\u7279\u70b9\uff1a\n<\/p>\n<ul>\n<li>\n\t\t\u5b9a\u4e49\u7684\u62bd\u8c61\u7ea7\u522b\u4ec5\u5448\u73b0\u5bfc\u5165\/\u5bfc\u51fa\uff0c\u7c7b\/\u51fd\u6570\u540d\u79f0\uff0c\u51fd\u6570\u4f9d\u8d56\u5173\u7cfb\u6765\u9010\u6b65\u5b66\u4e60\/\u89e3\u91ca\u4ee3\u7801\u3002\n\t<\/li>\n<li>\n\t\t\u81ea\u5b9a\u4e49\u62bd\u8c61\u5c42\u6b21\u652f\u6301\u521b\u5efa\u4f60\u81ea\u5df1\u7684\n\t<\/li>\n<li>\n\t\t\u6f14\u793a\u751f\u6210\u5668\u751f\u6210<a href=\"https:\/\/www.xttblog.com\/?tag=SVG\" name=\"SVG\" target=\"_blank\" title=\"SVG\">SVG<\/a>\u5217\u8868\u4ee5\u4fbf\u83b7\u53d6\u4e0d\u540c\u7684\u62bd\u8c61\u7ea7\u522b\n\t<\/li>\n<li>\n\t\t\u5b9a\u4e49\u6d41\u7a0b\u6811\u4fee\u9970\u7b26\u6765\u6620\u5c04\u4f17\u6240\u5468\u77e5\u7684API\uff0c\u6bd4\u5982ie [] .map\uff0c[] .forEach\uff0c[] .filter\u5230Loop\u7ed3\u6784\u7b49\u7b49\u3002\n\t<\/li>\n<li>\n\t\t\u9500\u6bc1\u4fee\u9970\u7b26\u6765\u66ff\u6362\u65b9\u6848\u4e2d\u7684\u4e00\u4e2a\u5f62\u72b6\u7684\u4ee3\u7801\u5757\n\t<\/li>\n<li>\n\t\t\u81ea\u5b9a\u4e49\u6d41\u7a0b\u6811\u4fee\u9970\u7b26\u652f\u6301\u521b\u5efa\u60a8\u81ea\u5df1\u7684\u4e00\u4e2a\n\t<\/li>\n<li>\n\t\t\u6d41\u6811\u5ffd\u7565\u8fc7\u6ee4\u5668\u5b8c\u5168\u7701\u7565\u4e00\u4e9b\u4ee3\u7801\u8282\u70b9\uff0c\u5373\u65e5\u5fd7\u884c\n\t<\/li>\n<li>\n\t\t\u91cd\u70b9\u8282\u70b9\u6216\u6574\u4e2a\u4ee3\u7801\u903b\u8f91\u5206\u652f\u6765\u7a81\u51fa\u91cd\u70b9\u90e8\u5206\u7684\u65b9\u6848\n\t<\/li>\n<li>\n\t\t\u6a21\u7cca\u8282\u70b9\u6216\u6574\u4e2a\u4ee3\u7801\u903b\u8f91\u5206\u652f\u6765\u9690\u85cf\u4e0d\u592a\u91cd\u8981\u7684\u4e1c\u897f\n\t<\/li>\n<li>\n\t\t\u5b9a\u4e49\u7684\u6837\u5f0f\u4e3b\u9898\u652f\u6301\u9009\u62e9\u4e00\u4e2a\u4f60\u559c\u6b22\u7684\n\t<\/li>\n<li>\n\t\t\u81ea\u5b9a\u4e49\u4e3b\u9898\u652f\u6301\u521b\u5efa\u81ea\u5df1\u7684\u4e00\u4e2a\u66f4\u9002\u5408\u60a8\u7684\u4e0a\u4e0b\u6587\u989c\u8272\n\t<\/li>\n<li>\n\t\t\u81ea\u5b9a\u4e49\u989c\u8272\u548c\u6837\u5f0f\u652f\u6301\u63d0\u4f9b\u65b9\u4fbf\u7684API\u6765\u66f4\u6539\u7279\u5b9a\u7684\u6837\u5f0f\uff0c\u800c\u65e0\u9700\u6837\u677f\n\t<\/li>\n<\/ul>\n<h2>\n\t\u5b89\u88c5<br \/>\n<\/h2>\n<p>\n\tjs2flowchart\u662f\u4e00\u4e2a\u4ece<a href=\"https:\/\/www.xttblog.com\/?tag=javascript\" name=\"javascript\" target=\"_blank\" title=\"javascript\">JavaScript<\/a>\u4ee3\u7801\u751f\u6210\u6f02\u4eae\u7684<a href=\"https:\/\/www.xttblog.com\/?tag=SVG\" name=\"SVG\" target=\"_blank\" title=\"SVG\">SVG<\/a>\u6d41\u7a0b\u56fe\u7684\u5de5\u5177\u3002\u4e0b\u9762\u6211\u4eec\u4f7f\u7528NPM\u6765\u8fdb\u884c\u5b89\u88c5\u5b83\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nyarn add js2flowchart<\/pre>\n<h2>\n\t\u57fa\u672c\u7528\u6cd5<br \/>\n<\/h2>\n<p>\n\t\u9996\u5148\u6211\u4eec\u6765\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684demo\u3002html\u4ee3\u7801\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;div&gt;\r\n  &lt;p id=&quot;svgImage&quot;&gt;&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;!-- \u4e1a\u4f59\u8349\uff1awww.xttblog.com --&gt;<\/pre>\n<p>\n\t\u5269\u4e0b\u7684\u5c31\u662f\u6700\u4e3b\u8981\u7684<a href=\"https:\/\/www.xttblog.com\/?tag=javascript\" name=\"javascript\" target=\"_blank\" title=\"javascript\">JavaScript<\/a>\u4ee3\u7801\u4e86\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nconst code = `\r\nfunction indexSearch(list, element) {\r\n  let currentIndex,\r\n    currentElement,\r\n    minIndex = 0,\r\n    maxIndex = list.length - 1;\r\n\r\n  while (minIndex &lt;= maxIndex) {\r\n    currentIndex = Math.floor(maxIndex + maxIndex) \/ 2;\r\n    currentElement = list[currentIndex];\r\n\r\n    if (currentElement === element) {\r\n      return currentIndex;\r\n    }\r\n\r\n    if (currentElement &lt; element) {\r\n      minIndex = currentIndex + 1;\r\n    }\r\n\r\n    if (currentElement &gt; element) {\r\n      maxIndex = currentIndex - 1;\r\n    }\r\n  }\r\n\r\n  return -1;\r\n}`;\r\n\r\nconst {createFlowTreeBuilder, createSVGRender} = js2flowchart;\r\n\r\nconst flowTreeBuilder = createFlowTreeBuilder(),\r\n    svgRender = createSVGRender();\r\n\r\nconst flowTree = flowTreeBuilder.build(code),\r\n    shapesTree = svgRender.buildShapesTree(flowTree);\r\n\r\nconst svg = shapesTree.print();\r\n\r\ndocument.getElementById(&#039;svgImage&#039;).innerHTML = svg;<\/pre>\n<p>\n\t\u6700\u540e\u7684\u8fd0\u884c\u6548\u679c\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u6839\u636e JavaScript \u4ee3\u7801\u751f\u6210\u6f02\u4eae\u7684 SVG \u6d41\u7a0b\u56fe\" src=\"http:\/\/img.bbs.csdn.net\/upload\/201711\/11\/1510380420_870288.png\" \/>\n<\/p>\n<p>\n\t\u53e6\u5916js2flowchart\u8fd8\u63d0\u4f9b\u4e86\u5f88\u591a\u5e38\u7528\u7684api\uff0c\u5efa\u8bae\u5927\u5bb6\u5230\u5b83\u7684\u5b98\u7f51\u8fdb\u884c\u6df1\u5165\u7684\u5b66\u4e60\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2316\">js2flowchart.js \u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>js2flowchart.js\u662f\u4e00\u4e2a\u53ef\u4ee5\u5c06\u4efb\u4f55JavaScript\u4ee3\u7801\u8f6c\u6362\u6210\u6f02\u4eae\u7684SVG\u6d41\u7a0b\u56fe\u7684\u53ef\u89c6\u5316\u5e93\u3002\u8be5\u63d2 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1106,52],"class_list":["post-2316","post","type-post","status-publish","format-standard","hentry","category-html5","tag-javascript","tag-svg"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2316"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2316\/revisions"}],"predecessor-version":[{"id":2317,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2316\/revisions\/2317"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}