How to generate mind Map with JavaScript
This article mainly explains "how to generate a mind map with JavaScript". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to generate a mind map with JavaScript".
First take a look at the contents of example.parse.js:
Var fs = require ('fs'); var parse = require ('.. / parse.markdown'); var transform = require ('.. / transform.headings'); var text = fs.readFileSync ('gtor.md',' utf-8'); var headings = parse (text); var root = transform (headings); console.log (root); fs.writeFileSync ('gtor.json', JSON.stringify (root))
Use nodejs named node example.parse.js to execute this code: the code reads the local file gtor.md that contains the mind map, parses and transforms to generate the local file gtor.json.
Then look at example.view.js and find that the author uses d3 to render UI.
D3.json ("gtor.json", function (error, data) {if (error) throw error; markmap ('svg#mindmap', data, {preset:' default', / / or colorful linkShape: 'diagonal' / / or bracket});})
If you directly double-click the index.html file in the examples folder to open it in the browser, a cross-domain error will occur and the local file gtor.json will not be accessible:
You must deploy this example to run on the server.
Start the server locally with the nodejs command line:
Node local.js
Then localhost:3000/mindmap can see the effect of mind mapping.
Thank you for your reading, the above is the content of "how to use JavaScript to generate mind map". After the study of this article, I believe you have a deeper understanding of how to use JavaScript to generate mind map, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!