├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── css ├── custom.css └── vtree.css ├── dist └── vtree.js ├── index.html ├── package.json ├── src ├── decorator │ └── linkName.js ├── layout │ ├── array.js │ └── tree.js ├── node │ ├── README.md │ ├── array.js │ ├── dummy.js │ ├── node.js │ ├── string.js │ ├── table.js │ └── util.js ├── reader │ ├── object.js │ └── test │ │ └── object_reader_test.js ├── util.js └── vtree.js ├── test.html ├── vtree.jpg └── webpack.config.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "node": true, 5 | "es6": true, 6 | "mocha": true 7 | }, 8 | 9 | "ecmaFeatures": { 10 | "modules": true 11 | }, 12 | 13 | "parserOptions": { 14 | "sourceType": "module" 15 | }, 16 | 17 | "extends": "eslint:recommended", 18 | 19 | "rules": { 20 | "no-undef": 2, 21 | "no-console": 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | lib/ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | JSON to Tree Diagram Converter 2 | ============================== 3 | 4 | > For Yakusugi 5 | 6 | This tool converts JSON strings into tree diagrams. For example, it is used to show AST(Abstract Syntax Tree) as tree diagrams for debugging. In that case, of course, you need to translate AST into JSON. 7 | 8 | 9 | [Online JSON to Tree Diagram Converter](http://vanya.jp.net/vtree/) 10 | 11 | 12 | ![Screenshot](https://github.com/ivan111/vtree/raw/master/vtree.jpg) 13 | -------------------------------------------------------------------------------- /css/custom.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 3 | background-color: #f8f9fa; 4 | display: flex; 5 | align-items: center; 6 | min-height: 100vh; 7 | } 8 | 9 | .container { 10 | max-width: 1030px; 11 | width: 100%; 12 | background-color: #ffffff; 13 | border-radius: 8px; 14 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.14); 15 | padding: 2rem; 16 | margin: 0 auto; 17 | } 18 | 19 | header { 20 | margin-bottom: 2rem; 21 | } 22 | 23 | button { 24 | width: 100%; 25 | } 26 | 27 | textarea { 28 | resize: none; 29 | } 30 | 31 | footer { 32 | margin-top: 3rem; 33 | } -------------------------------------------------------------------------------- /css/vtree.css: -------------------------------------------------------------------------------- 1 | svg.vtree { 2 | overflow: hidden; 3 | background: #ffffff; 4 | -webkit-box-shadow: 4px 4px 8px rgba(0,0,0,0.5); 5 | -moz-box-shadow : 4px 4px 8px rgba(0,0,0,0.5); 6 | box-shadow : 4px 4px 8px rgba(0,0,0,0.5); 7 | } 8 | -------------------------------------------------------------------------------- /dist/vtree.js: -------------------------------------------------------------------------------- 1 | var VTree = 2 | /******/ (function(modules) { // webpackBootstrap 3 | /******/ // The module cache 4 | /******/ var installedModules = {}; 5 | /******/ 6 | /******/ // The require function 7 | /******/ function __webpack_require__(moduleId) { 8 | /******/ 9 | /******/ // Check if module is in cache 10 | /******/ if(installedModules[moduleId]) { 11 | /******/ return installedModules[moduleId].exports; 12 | /******/ } 13 | /******/ // Create a new module (and put it into the cache) 14 | /******/ var module = installedModules[moduleId] = { 15 | /******/ i: moduleId, 16 | /******/ l: false, 17 | /******/ exports: {} 18 | /******/ }; 19 | /******/ 20 | /******/ // Execute the module function 21 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 | /******/ 23 | /******/ // Flag the module as loaded 24 | /******/ module.l = true; 25 | /******/ 26 | /******/ // Return the exports of the module 27 | /******/ return module.exports; 28 | /******/ } 29 | /******/ 30 | /******/ 31 | /******/ // expose the modules object (__webpack_modules__) 32 | /******/ __webpack_require__.m = modules; 33 | /******/ 34 | /******/ // expose the module cache 35 | /******/ __webpack_require__.c = installedModules; 36 | /******/ 37 | /******/ // define getter function for harmony exports 38 | /******/ __webpack_require__.d = function(exports, name, getter) { 39 | /******/ if(!__webpack_require__.o(exports, name)) { 40 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 41 | /******/ } 42 | /******/ }; 43 | /******/ 44 | /******/ // define __esModule on exports 45 | /******/ __webpack_require__.r = function(exports) { 46 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 47 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 48 | /******/ } 49 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 50 | /******/ }; 51 | /******/ 52 | /******/ // create a fake namespace object 53 | /******/ // mode & 1: value is a module id, require it 54 | /******/ // mode & 2: merge all properties of value into the ns 55 | /******/ // mode & 4: return value when already ns object 56 | /******/ // mode & 8|1: behave like require 57 | /******/ __webpack_require__.t = function(value, mode) { 58 | /******/ if(mode & 1) value = __webpack_require__(value); 59 | /******/ if(mode & 8) return value; 60 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 61 | /******/ var ns = Object.create(null); 62 | /******/ __webpack_require__.r(ns); 63 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 64 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 65 | /******/ return ns; 66 | /******/ }; 67 | /******/ 68 | /******/ // getDefaultExport function for compatibility with non-harmony modules 69 | /******/ __webpack_require__.n = function(module) { 70 | /******/ var getter = module && module.__esModule ? 71 | /******/ function getDefault() { return module['default']; } : 72 | /******/ function getModuleExports() { return module; }; 73 | /******/ __webpack_require__.d(getter, 'a', getter); 74 | /******/ return getter; 75 | /******/ }; 76 | /******/ 77 | /******/ // Object.prototype.hasOwnProperty.call 78 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 79 | /******/ 80 | /******/ // __webpack_public_path__ 81 | /******/ __webpack_require__.p = ""; 82 | /******/ 83 | /******/ 84 | /******/ // Load entry module and return exports 85 | /******/ return __webpack_require__(__webpack_require__.s = "./src/vtree.js"); 86 | /******/ }) 87 | /************************************************************************/ 88 | /******/ ({ 89 | 90 | /***/ "./src/decorator/linkName.js": 91 | /*!***********************************!*\ 92 | !*** ./src/decorator/linkName.js ***! 93 | \***********************************/ 94 | /*! no static exports found */ 95 | /***/ (function(module, exports, __webpack_require__) { 96 | 97 | "use strict"; 98 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar pad = 4;\n\nvar LinkNameDecorator = function () {\n function LinkNameDecorator(linkName) {\n _classCallCheck(this, LinkNameDecorator);\n\n this.linkName = linkName;\n }\n\n _createClass(LinkNameDecorator, [{\n key: 'render',\n value: function render(g, oldG, width) {\n var t = g.append('text').text(this.linkName);\n\n var b = t.node().getBBox();\n var textW = Math.ceil(b.width);\n var textH = Math.ceil(b.height);\n\n var textTotalW = textW + pad * 2;\n\n var newW = width;\n\n if (textTotalW > width) {\n newW = textTotalW;\n }\n\n var textTotalH = textH + pad;\n\n var dw = newW - width;\n var dh = textTotalH;\n var dx = Math.round(dw / 2);\n var dy = textTotalH;\n\n t.attr('x', Math.round(newW / 2)).attr('y', textH).attr('text-anchor', 'middle');\n\n return { dx: dx, dy: dy, dw: dw, dh: dh };\n }\n }]);\n\n return LinkNameDecorator;\n}();\n\nexports.default = LinkNameDecorator;\n\n//# sourceURL=webpack://VTree/./src/decorator/linkName.js?"); 99 | 100 | /***/ }), 101 | 102 | /***/ "./src/layout/array.js": 103 | /*!*****************************!*\ 104 | !*** ./src/layout/array.js ***! 105 | \*****************************/ 106 | /*! no static exports found */ 107 | /***/ (function(module, exports, __webpack_require__) { 108 | 109 | "use strict"; 110 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n/* global d3 */\n\nvar DURATION = 1000;\n\nvar diagonal = d3.svg.diagonal();\n\nvar ArrayLayout = function () {\n function ArrayLayout() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n _classCallCheck(this, ArrayLayout);\n\n this.hideLinks = options.hideLinks;\n }\n\n _createClass(ArrayLayout, [{\n key: 'layout',\n value: function layout(node) {\n calcChildrenWidth(node);\n calcTotalSize(node);\n\n _layout(node);\n }\n }, {\n key: 'renderLinks',\n value: function renderLinks(node) {\n if (!this.hideLinks) {\n _renderLinks(node);\n }\n }\n }]);\n\n return ArrayLayout;\n}();\n\nexports.default = ArrayLayout;\n\n\nfunction _layout(node) {\n if (node.children.length === 0) {\n return;\n }\n\n var x = -Math.round(node.childrenWidth / 2);\n var y = 0;\n\n node.children.forEach(function (child) {\n child.x = x + Math.round(child.totalWidth / 2) - Math.round(child.width / 2);\n child.y = y;\n\n child.g.transition().duration(DURATION).attr('transform', 'translate(' + child.x + ',' + child.y + ')');\n\n x += child.totalWidth + node.margin;\n });\n}\n\nfunction _renderLinks(node) {\n if (node.children.length === 0) {\n return;\n }\n\n var h = node.children[0].linkY;\n\n node.children.forEach(function (child) {\n h = Math.min(h, child.linkY);\n });\n\n var orig = { x: 0, y: 0 };\n\n var i, src, dst;\n\n for (i = 0; i < node.children.length; i++) {\n if (i === 0) {\n continue;\n }\n\n var prev = node.children[i - 1];\n var child = node.children[i];\n\n src = {\n x: prev.x + prev.linkX,\n y: prev.y + h\n };\n\n dst = {\n x: child.x + child.linkX,\n y: child.y + h\n };\n\n var link = node.g.insert('path', ':first-child').attr('class', 'vtree-link').attr('d', function () {\n return diagonal({ source: orig, target: orig });\n });\n\n link.transition().duration(DURATION).attr('d', function () {\n return diagonal({ source: src, target: dst });\n });\n }\n}\n\nfunction calcChildrenWidth(node) {\n if (node.children.length === 0) {\n node.childrenWidth = 0;\n\n return;\n }\n\n var w = 0;\n\n node.children.forEach(function (child) {\n w += child.totalWidth;\n });\n\n w += (node.children.length - 1) * node.margin;\n\n node.childrenWidth = w;\n}\n\nfunction calcTotalSize(node) {\n if (node.children.length === 0) {\n node.totalWidth = node.width;\n node.totalHeight = node.height;\n\n return;\n }\n\n node.totalWidth = Math.max(node.width, node.childrenWidth);\n\n var maxChildH = 0;\n\n node.children.forEach(function (child) {\n maxChildH = Math.max(maxChildH, child.totalHeight);\n });\n\n node.totalHeight = maxChildH;\n}\n\n//# sourceURL=webpack://VTree/./src/layout/array.js?"); 111 | 112 | /***/ }), 113 | 114 | /***/ "./src/layout/tree.js": 115 | /*!****************************!*\ 116 | !*** ./src/layout/tree.js ***! 117 | \****************************/ 118 | /*! no static exports found */ 119 | /***/ (function(module, exports, __webpack_require__) { 120 | 121 | "use strict"; 122 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* global d3 */\n\nvar _array = __webpack_require__(/*! ../node/array.js */ \"./src/node/array.js\");\n\nvar _array2 = _interopRequireDefault(_array);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar MARGIN = 10;\nvar HEIGHT = 50;\nvar DURATION = 1000;\n\nvar diagonal = d3.svg.diagonal();\n\nvar TreeLayout = function () {\n function TreeLayout() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n _classCallCheck(this, TreeLayout);\n\n this.height = options.height || HEIGHT;\n }\n\n _createClass(TreeLayout, [{\n key: 'layout',\n value: function layout(node) {\n calcChildrenWidth(node);\n calcTotalSize(node, this.height);\n\n _layout(node, this.height);\n }\n }, {\n key: 'renderLinks',\n value: function renderLinks(node) {\n _renderLinks(node);\n }\n }]);\n\n return TreeLayout;\n}();\n\nexports.default = TreeLayout;\n\n\nfunction _layout(node, height) {\n if (node.children.length === 0) {\n return;\n }\n\n var x = Math.round(node.width / 2) - Math.round(node.childrenWidth / 2);\n var y = node.height + height;\n\n node.children.forEach(function (child) {\n child.x = x + Math.round(child.totalWidth / 2) - Math.round(child.width / 2);\n child.y = y;\n\n child.g.transition().duration(DURATION).attr('transform', 'translate(' + child.x + ',' + child.y + ')');\n\n x += child.totalWidth + MARGIN;\n });\n}\n\nfunction _renderLinks(node) {\n var src = {\n x: node.linkX,\n y: node.linkY\n };\n\n node.children.forEach(function (child) {\n var dst = {\n x: child.x + child.linkX,\n y: child.y + child.linkY\n };\n\n if (child.constructor === _array2.default) {\n if (child.children.length !== 0) {\n var gc = child.children[0];\n dst.x += gc.x + gc.linkX;\n dst.y += gc.y + gc.linkY;\n }\n }\n\n var link = node.g.insert('path', ':first-child').attr('class', 'vtree-link').attr('d', function () {\n return diagonal({ source: src, target: src });\n });\n\n link.transition().duration(DURATION).attr('d', function () {\n return diagonal({ source: src, target: dst });\n });\n });\n}\n\nfunction calcChildrenWidth(node) {\n if (node.children.length === 0) {\n node.childrenWidth = 0;\n\n return;\n }\n\n var w = 0;\n\n node.children.forEach(function (child) {\n w += child.totalWidth;\n });\n\n w += (node.children.length - 1) * MARGIN;\n\n node.childrenWidth = w;\n}\n\nfunction calcTotalSize(node, height) {\n if (node.children.length === 0) {\n node.totalWidth = node.width;\n node.totalHeight = node.height;\n\n return;\n }\n\n node.totalWidth = Math.max(node.width, node.childrenWidth);\n\n var maxChildH = 0;\n\n node.children.forEach(function (child) {\n maxChildH = Math.max(maxChildH, child.totalHeight);\n });\n\n node.totalHeight = node.height + height + maxChildH;\n}\n\n//# sourceURL=webpack://VTree/./src/layout/tree.js?"); 123 | 124 | /***/ }), 125 | 126 | /***/ "./src/node/array.js": 127 | /*!***************************!*\ 128 | !*** ./src/node/array.js ***! 129 | \***************************/ 130 | /*! no static exports found */ 131 | /***/ (function(module, exports, __webpack_require__) { 132 | 133 | "use strict"; 134 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _node = __webpack_require__(/*! ./node.js */ \"./src/node/node.js\");\n\nvar _node2 = _interopRequireDefault(_node);\n\nvar _array = __webpack_require__(/*! ../layout/array.js */ \"./src/layout/array.js\");\n\nvar _array2 = _interopRequireDefault(_array);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar defaultLayout = new _array2.default();\n\nvar MARGIN = 10;\n\nvar ArrayNode = function (_Node) {\n _inherits(ArrayNode, _Node);\n\n function ArrayNode(nodes, layout) {\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n\n _classCallCheck(this, ArrayNode);\n\n if (!layout) {\n layout = defaultLayout;\n }\n\n var _this = _possibleConstructorReturn(this, (ArrayNode.__proto__ || Object.getPrototypeOf(ArrayNode)).call(this, null, nodes, layout));\n\n _this.width = 0;\n _this.height = 0;\n\n _this.linkX = 0;\n _this.linkY = 0;\n\n _this.margin = options.margin || MARGIN;\n return _this;\n }\n\n _createClass(ArrayNode, [{\n key: '_render',\n value: function _render() {}\n }]);\n\n return ArrayNode;\n}(_node2.default);\n\nexports.default = ArrayNode;\n\n//# sourceURL=webpack://VTree/./src/node/array.js?"); 135 | 136 | /***/ }), 137 | 138 | /***/ "./src/node/dummy.js": 139 | /*!***************************!*\ 140 | !*** ./src/node/dummy.js ***! 141 | \***************************/ 142 | /*! no static exports found */ 143 | /***/ (function(module, exports, __webpack_require__) { 144 | 145 | "use strict"; 146 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _node = __webpack_require__(/*! ./node.js */ \"./src/node/node.js\");\n\nvar _node2 = _interopRequireDefault(_node);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar DummyNode = function (_Node) {\n _inherits(DummyNode, _Node);\n\n function DummyNode(child) {\n _classCallCheck(this, DummyNode);\n\n var _this = _possibleConstructorReturn(this, (DummyNode.__proto__ || Object.getPrototypeOf(DummyNode)).call(this, null, [child]));\n\n _this.r = 4;\n return _this;\n }\n\n _createClass(DummyNode, [{\n key: '_render',\n value: function _render(g) {\n g.append('circle').attr('cx', this.r).attr('cy', this.r).attr('r', this.r);\n\n this.width = this.r * 2;\n this.height = this.r * 2;\n\n this.linkX = this.r;\n this.linkY = this.r;\n }\n }]);\n\n return DummyNode;\n}(_node2.default);\n\nexports.default = DummyNode;\n\n//# sourceURL=webpack://VTree/./src/node/dummy.js?"); 147 | 148 | /***/ }), 149 | 150 | /***/ "./src/node/node.js": 151 | /*!**************************!*\ 152 | !*** ./src/node/node.js ***! 153 | \**************************/ 154 | /*! no static exports found */ 155 | /***/ (function(module, exports, __webpack_require__) { 156 | 157 | "use strict"; 158 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n/**\n * Node\n *\n * A tree consists of nodes and links.\n * A node consists of the following fields:\n *\n * - id : auto increment ID.\n * - data : data which may be displayed.\n * The data format is determined by the renderer.\n * - children : children of the node\n */\n\nvar curMaxId = 0;\n\nvar Node = function () {\n function Node(data, children, layout) {\n _classCallCheck(this, Node);\n\n this.id = ++curMaxId;\n this.data = data;\n this.children = children;\n\n if (layout) {\n this.layout = layout;\n }\n\n this.width = 0;\n this.height = 0;\n\n this.decorators = [];\n }\n\n _createClass(Node, [{\n key: 'render',\n value: function render(g) {\n var _this = this;\n\n if (this.decorators.length === 0) {\n this._render(g);\n return;\n }\n\n var prevG = g.append('g');\n this._render(prevG);\n\n this.decorators.forEach(function (decorator) {\n var newG = g.append('g');\n\n var dbbox = decorator.render(newG, prevG, _this.width, _this.height);\n\n if (dbbox.dw || dbbox.dh) {\n _this.width += dbbox.dw;\n _this.height += dbbox.dh;\n }\n\n if (dbbox.dx || dbbox.dy) {\n prevG.attr('transform', 'translate(' + dbbox.dx + ',' + dbbox.dy + ')');\n\n _this.linkX += dbbox.dx;\n _this.linkY += dbbox.dy;\n }\n\n prevG = newG;\n });\n }\n }, {\n key: '_render',\n value: function _render() {\n throw new Error('[no overwride errror] _render is not implemented.');\n }\n }]);\n\n return Node;\n}();\n\nexports.default = Node;\n\n//# sourceURL=webpack://VTree/./src/node/node.js?"); 159 | 160 | /***/ }), 161 | 162 | /***/ "./src/node/string.js": 163 | /*!****************************!*\ 164 | !*** ./src/node/string.js ***! 165 | \****************************/ 166 | /*! no static exports found */ 167 | /***/ (function(module, exports, __webpack_require__) { 168 | 169 | "use strict"; 170 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _node = __webpack_require__(/*! ./node.js */ \"./src/node/node.js\");\n\nvar _node2 = _interopRequireDefault(_node);\n\nvar _util = __webpack_require__(/*! ./util.js */ \"./src/node/util.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar StringNode = function (_Node) {\n _inherits(StringNode, _Node);\n\n function StringNode(data) {\n _classCallCheck(this, StringNode);\n\n var _this = _possibleConstructorReturn(this, (StringNode.__proto__ || Object.getPrototypeOf(StringNode)).call(this, data, []));\n\n _this.textPad = 4;\n return _this;\n }\n\n _createClass(StringNode, [{\n key: '_render',\n value: function _render(g) {\n var bbox = (0, _util.appendRectText)(g, 0, 0, this.data, this.textPad);\n\n this.width = bbox.width;\n this.height = bbox.height;\n\n this.linkX = Math.round(this.width / 2);\n this.linkY = Math.round(this.height / 2);\n }\n }]);\n\n return StringNode;\n}(_node2.default);\n\nexports.default = StringNode;\n\n//# sourceURL=webpack://VTree/./src/node/string.js?"); 171 | 172 | /***/ }), 173 | 174 | /***/ "./src/node/table.js": 175 | /*!***************************!*\ 176 | !*** ./src/node/table.js ***! 177 | \***************************/ 178 | /*! no static exports found */ 179 | /***/ (function(module, exports, __webpack_require__) { 180 | 181 | "use strict"; 182 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _node = __webpack_require__(/*! ./node.js */ \"./src/node/node.js\");\n\nvar _node2 = _interopRequireDefault(_node);\n\nvar _util = __webpack_require__(/*! ./util.js */ \"./src/node/util.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar TableNode = function (_Node) {\n _inherits(TableNode, _Node);\n\n function TableNode(data, children) {\n _classCallCheck(this, TableNode);\n\n var _this = _possibleConstructorReturn(this, (TableNode.__proto__ || Object.getPrototypeOf(TableNode)).call(this, data, children));\n\n _this.textPad = 4;\n return _this;\n }\n\n _createClass(TableNode, [{\n key: '_render',\n value: function _render(g) {\n if (this.data.length === 0 || this.data[0].length === 0) {\n return;\n }\n\n var tbl = this.renderCells(g);\n var size = this.layoutCells(tbl);\n\n this.width = size.width;\n this.height = size.height;\n\n this.linkX = Math.round(this.width / 2);\n this.linkY = Math.round(this.height / 2);\n }\n }, {\n key: 'renderCells',\n value: function renderCells(g) {\n var _this2 = this;\n\n var tbl = [];\n\n this.data.forEach(function (row) {\n var tblRow = [];\n\n row.forEach(function (col) {\n var colG = g.append('g');\n var bbox = (0, _util.appendRectText)(colG, 0, 0, col, _this2.textPad);\n\n tblRow.push({\n g: colG,\n bbox: bbox\n });\n });\n\n tbl.push(tblRow);\n });\n\n return tbl;\n }\n }, {\n key: 'layoutCells',\n value: function layoutCells(tbl) {\n var maxW = this.calcMaxWidths(tbl);\n var maxH = this.calcMaxHeights(tbl);\n\n var x = 0;\n var y = 0;\n\n tbl.forEach(function (row, rowI) {\n x = 0;\n\n row.forEach(function (col, colI) {\n col.g.attr('transform', 'translate(' + x + ',' + y + ')');\n col.g.select('rect').attr('width', maxW[colI]).attr('height', maxH[rowI]);\n\n x += maxW[colI];\n });\n\n y += maxH[rowI];\n });\n\n return { width: x, height: y };\n }\n }, {\n key: 'calcMaxWidths',\n value: function calcMaxWidths(tbl) {\n var maxW = [];\n var colI, rowI;\n\n for (colI = 0; colI < tbl[0].length; colI++) {\n var w = 0;\n\n for (rowI = 0; rowI < tbl.length; rowI++) {\n w = Math.max(w, tbl[rowI][colI].bbox.width);\n }\n\n maxW.push(w);\n }\n\n return maxW;\n }\n }, {\n key: 'calcMaxHeights',\n value: function calcMaxHeights(tbl) {\n var maxH = [];\n\n tbl.forEach(function (row) {\n var h = 0;\n\n row.forEach(function (col) {\n h = Math.max(h, col.bbox.height);\n });\n\n maxH.push(h);\n });\n\n return maxH;\n }\n }]);\n\n return TableNode;\n}(_node2.default);\n\nexports.default = TableNode;\n\n//# sourceURL=webpack://VTree/./src/node/table.js?"); 183 | 184 | /***/ }), 185 | 186 | /***/ "./src/node/util.js": 187 | /*!**************************!*\ 188 | !*** ./src/node/util.js ***! 189 | \**************************/ 190 | /*! no static exports found */ 191 | /***/ (function(module, exports, __webpack_require__) { 192 | 193 | "use strict"; 194 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nexports.appendRectText = appendRectText;\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar MAX_LEN = 32;\n\nvar BBox = exports.BBox = function BBox() {\n var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n var width = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;\n var height = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;\n\n _classCallCheck(this, BBox);\n\n this.x = x;\n this.y = y;\n this.width = width;\n this.height = height;\n};\n\nfunction appendRectText(g, x, y, text, pad) {\n if (typeof text === 'string' && text.length > MAX_LEN) {\n text = text.substr(0, MAX_LEN) + '...';\n }\n\n var rect = g.append('rect').attr('class', getClassName(text));\n\n var t = g.append('text').text(text);\n\n var b = t.node().getBBox();\n var w = Math.ceil(b.width);\n var h = Math.ceil(b.height);\n\n t.attr('x', x + pad).attr('y', y + pad + h);\n\n var bbox = new BBox(x, y, w + pad * 2, h + pad * 2);\n\n rect.attr('x', bbox.x).attr('y', bbox.y).attr('width', bbox.width).attr('height', bbox.height);\n\n return bbox;\n}\n\nfunction getClassName(d) {\n var name = '';\n var type = typeof d === 'undefined' ? 'undefined' : _typeof(d);\n\n if (d === null) {\n return 'null-text';\n } else if (type === 'string') {\n name = 'string-text';\n } else if (type === 'number') {\n name = 'number-text';\n } else if (type === 'boolean') {\n name = 'boolean-text';\n } else {\n name = 'unknown-text';\n }\n\n return name;\n}\n\n//# sourceURL=webpack://VTree/./src/node/util.js?"); 195 | 196 | /***/ }), 197 | 198 | /***/ "./src/reader/object.js": 199 | /*!******************************!*\ 200 | !*** ./src/reader/object.js ***! 201 | \******************************/ 202 | /*! no static exports found */ 203 | /***/ (function(module, exports, __webpack_require__) { 204 | 205 | "use strict"; 206 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _string = __webpack_require__(/*! ../node/string.js */ \"./src/node/string.js\");\n\nvar _string2 = _interopRequireDefault(_string);\n\nvar _array = __webpack_require__(/*! ../node/array.js */ \"./src/node/array.js\");\n\nvar _array2 = _interopRequireDefault(_array);\n\nvar _table = __webpack_require__(/*! ../node/table.js */ \"./src/node/table.js\");\n\nvar _table2 = _interopRequireDefault(_table);\n\nvar _dummy = __webpack_require__(/*! ../node/dummy.js */ \"./src/node/dummy.js\");\n\nvar _dummy2 = _interopRequireDefault(_dummy);\n\nvar _linkName = __webpack_require__(/*! ../decorator/linkName.js */ \"./src/decorator/linkName.js\");\n\nvar _linkName2 = _interopRequireDefault(_linkName);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar ObjectReader = function () {\n function ObjectReader() {\n _classCallCheck(this, ObjectReader);\n }\n\n _createClass(ObjectReader, [{\n key: 'read',\n value: function read(obj) {\n return obj2node(obj, '');\n }\n }]);\n\n return ObjectReader;\n}();\n\nexports.default = ObjectReader;\n\n\nfunction obj2node(obj, linkName) {\n var node;\n\n if (isPrimitive(obj)) {\n node = new _string2.default(obj);\n } else if (Array.isArray(obj)) {\n var nodes = [];\n\n obj.forEach(function (item, i) {\n if (Array.isArray(item)) {\n node = new _dummy2.default(obj2node(item, ''));\n node.decorators.push(new _linkName2.default(linkName + '[' + i + ']'));\n nodes.push(node);\n } else {\n node = obj2node(item, linkName + '[' + i + ']');\n nodes.push(node);\n }\n });\n\n // empty array\n if (nodes.length === 0) {\n node = obj2node(null, linkName + '[]');\n nodes.push(node);\n }\n\n node = new _array2.default(nodes);\n } else {\n var name;\n var tbl = [];\n var children = [];\n\n for (name in obj) {\n if (!Object.prototype.hasOwnProperty.call(obj, name)) {\n continue;\n }\n\n var data = obj[name];\n\n if (isPrimitive(data)) {\n tbl.push([name, data]);\n } else {\n children.push(obj2node(data, name));\n }\n }\n\n if (tbl.length === 0) {\n node = new _table2.default([[' ', ' ']], children);\n } else {\n node = new _table2.default(tbl, children);\n }\n }\n\n if (linkName !== '' && node.constructor !== _array2.default) {\n node.decorators.push(new _linkName2.default(linkName));\n }\n\n return node;\n}\n\nfunction isPrimitive(d) {\n var type = typeof d === 'undefined' ? 'undefined' : _typeof(d);\n\n if (d === null || type === 'string' || type === 'number' || type === 'boolean') {\n return true;\n }\n\n return false;\n}\n\n//# sourceURL=webpack://VTree/./src/reader/object.js?"); 207 | 208 | /***/ }), 209 | 210 | /***/ "./src/util.js": 211 | /*!*********************!*\ 212 | !*** ./src/util.js ***! 213 | \*********************/ 214 | /*! no static exports found */ 215 | /***/ (function(module, exports, __webpack_require__) { 216 | 217 | "use strict"; 218 | eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.visitBefore = visitBefore;\nexports.visitAfter = visitAfter;\nfunction visitBefore(node, callback) {\n var nodes = [node];\n\n while (nodes.length !== 0) {\n node = nodes.pop();\n\n callback(node);\n\n var children = node.children;\n\n if (children) {\n var n = children.length;\n\n while (--n >= 0) {\n nodes.push(children[n]);\n }\n }\n }\n}\n\nfunction visitAfter(node, callback) {\n var nodes = [node];\n var nodes2 = [];\n\n while (nodes.length !== 0) {\n node = nodes.pop();\n\n nodes2.push(node);\n\n var children = node.children;\n\n if (children) {\n var i = -1;\n var n = children.length;\n\n while (++i < n) {\n nodes.push(children[i]);\n }\n }\n }\n\n while (nodes2.length !== 0) {\n node = nodes2.pop();\n\n callback(node);\n }\n}\n\n//# sourceURL=webpack://VTree/./src/util.js?"); 219 | 220 | /***/ }), 221 | 222 | /***/ "./src/vtree.js": 223 | /*!**********************!*\ 224 | !*** ./src/vtree.js ***! 225 | \**********************/ 226 | /*! no static exports found */ 227 | /***/ (function(module, exports, __webpack_require__) { 228 | 229 | "use strict"; 230 | eval("\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* global d3 */\n\nvar _node = __webpack_require__(/*! ./node/node.js */ \"./src/node/node.js\");\n\nvar _node2 = _interopRequireDefault(_node);\n\nvar _string = __webpack_require__(/*! ./node/string.js */ \"./src/node/string.js\");\n\nvar _string2 = _interopRequireDefault(_string);\n\nvar _table = __webpack_require__(/*! ./node/table.js */ \"./src/node/table.js\");\n\nvar _table2 = _interopRequireDefault(_table);\n\nvar _array = __webpack_require__(/*! ./node/array.js */ \"./src/node/array.js\");\n\nvar _array2 = _interopRequireDefault(_array);\n\nvar _tree = __webpack_require__(/*! ./layout/tree.js */ \"./src/layout/tree.js\");\n\nvar _tree2 = _interopRequireDefault(_tree);\n\nvar _array3 = __webpack_require__(/*! ./layout/array.js */ \"./src/layout/array.js\");\n\nvar _array4 = _interopRequireDefault(_array3);\n\nvar _object = __webpack_require__(/*! ./reader/object.js */ \"./src/reader/object.js\");\n\nvar _object2 = _interopRequireDefault(_object);\n\nvar _util = __webpack_require__(/*! ./util.js */ \"./src/util.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar WIDTH = 960;\nvar HEIGHT = 800;\nvar MARGIN = 20;\n\nvar DEFAULT_TREE_LAYOUT_HEIGHT = 50;\nvar DEBUG_TREE_LAYOUT_HEIGHT = 100;\n\nvar style = '\\n.vtree-node text { font: 14px sans-serif; }\\n.vtree-link { fill: none; stroke: #888; stroke-width: 2px; }\\n.vtree-table { stroke-width: 2px; stroke: steelblue; }\\npath.vtree-table { fill: white; }\\ng.vtree-node rect { fill: white; stroke: black; stroke-width: 1px; }\\ng.vtree-node rect.number-text { fill: #d8f0ed; }\\ng.vtree-node rect.string-text { fill: #e7f0db; }\\ng.vtree-node rect.boolean-text { fill: #e1d8f0; }\\ng.vtree-node rect.null-text { fill: #888; }\\n';\n\nvar VTree = function () {\n function VTree(container) {\n var _this = this;\n\n _classCallCheck(this, VTree);\n\n this.root = new _array2.default([], new _array4.default({ hideLinks: true }));\n this.defaultLayout = new _tree2.default({ height: DEFAULT_TREE_LAYOUT_HEIGHT });\n this.container = container;\n this._width = WIDTH;\n this._height = HEIGHT;\n this._debug = false;\n\n this.d3 = {};\n\n this.d3.container = d3.select(this.container);\n\n this.d3.zoomListener = d3.behavior.zoom().scaleExtent([0.1, 10]).on('zoom', function () {\n var e = d3.event;\n\n if (_this.d3.g) {\n _this.d3.g.attr('transform', 'translate(' + e.translate + ')scale(' + e.scale + ')');\n }\n });\n\n this.d3.svg = this.d3.container.append('svg').attr('class', 'vtree').attr('width', this._width).attr('height', this._height).call(this.d3.zoomListener);\n }\n\n _createClass(VTree, [{\n key: 'width',\n value: function width(_width) {\n if (arguments.length === 0) {\n return this._width;\n }\n\n this._width = _width;\n\n this.d3.container.select('svg').attr('width', _width);\n\n return this;\n }\n }, {\n key: 'height',\n value: function height(_height) {\n if (arguments.length === 0) {\n return this._height;\n }\n\n this._height = _height;\n\n this.d3.container.select('svg').attr('height', _height);\n\n return this;\n }\n }, {\n key: 'debug',\n value: function debug(_debug) {\n if (arguments.length === 0) {\n return this._debug;\n }\n\n if (_debug) {\n this.defaultLayout.height = DEBUG_TREE_LAYOUT_HEIGHT;\n } else {\n this.defaultLayout.height = DEFAULT_TREE_LAYOUT_HEIGHT;\n }\n\n this._debug = _debug;\n\n return this;\n }\n }, {\n key: 'data',\n value: function data(_data) {\n if (Array.isArray(_data)) {\n this.root.children = _data;\n } else {\n this.root.children = [_data];\n }\n\n return this;\n }\n }, {\n key: 'createSvgString',\n value: function createSvgString() {\n var svg = this.d3.svg.node();\n var serializer = new XMLSerializer();\n var source = serializer.serializeToString(svg);\n\n if (!source.match(/^]+xmlns=\"http:\\/\\/www\\.w3\\.org\\/2000\\/svg\"/)) {\n source = source.replace(/^]+\"http:\\/\\/www\\.w3\\.org\\/1999\\/xlink\"/)) {\n source = source.replace(/^ 2 | 3 | 4 | 5 | 6 | 7 | 8 | Online JSON to Tree Diagram Converter 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 65 | 66 | 69 | 70 |
71 | 72 |
73 |

Online JSON to Tree Diagram Converter

74 |
75 | 76 |
77 | 78 | 79 |
80 | 81 |
82 | 83 |
84 | 85 |
86 | 87 |
88 | 89 |
90 | 91 |
92 | 93 |
94 |

If you want to export the diagram as a svg file, copy the following text into a text editor and save the file with a .svg extension.

95 | 96 |
97 | 98 |
99 | Created Date: 2014-07-27, Modified Date: 2018-11-01 100 |
101 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vtree", 3 | "version": "0.3.0", 4 | "description": "display json data in a tree diagram.", 5 | "main": "build/vtree.js", 6 | "scripts": { 7 | "build": "webpack" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/ivan111/vtree.git" 12 | }, 13 | "keywords": [ 14 | "json", 15 | "tree" 16 | ], 17 | "author": "ivan111", 18 | "license": "Apache License Version 2", 19 | "bugs": { 20 | "url": "https://github.com/ivan111/vtree/issues" 21 | }, 22 | "homepage": "https://github.com/ivan111/vtree#readme", 23 | "devDependencies": { 24 | "babel-core": "^6.23.1", 25 | "babel-loader": "^7", 26 | "babel-preset-es2015": "^6.22.0", 27 | "eslint": "^5.8.0", 28 | "eslint-loader": "^2.1.1", 29 | "webpack": "^4.23.1", 30 | "webpack-cli": "^3.1.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/decorator/linkName.js: -------------------------------------------------------------------------------- 1 | const pad = 4; 2 | 3 | export default class LinkNameDecorator { 4 | constructor(linkName) { 5 | this.linkName = linkName; 6 | } 7 | 8 | render(g, oldG, width) { 9 | const t = g.append('text') 10 | .text(this.linkName); 11 | 12 | const b = t.node().getBBox(); 13 | const textW = Math.ceil(b.width); 14 | const textH = Math.ceil(b.height); 15 | 16 | const textTotalW = textW + pad * 2; 17 | 18 | var newW = width; 19 | 20 | if (textTotalW > width) { 21 | newW = textTotalW; 22 | } 23 | 24 | const textTotalH = textH + pad; 25 | 26 | const dw = newW - width; 27 | const dh = textTotalH; 28 | const dx = Math.round(dw / 2); 29 | const dy = textTotalH; 30 | 31 | t 32 | .attr('x', Math.round(newW / 2)) 33 | .attr('y', textH) 34 | .attr('text-anchor', 'middle'); 35 | 36 | return { dx, dy, dw, dh }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/layout/array.js: -------------------------------------------------------------------------------- 1 | /* global d3 */ 2 | 3 | const DURATION = 1000; 4 | 5 | const diagonal = d3.svg.diagonal(); 6 | 7 | 8 | export default class ArrayLayout { 9 | constructor(options={}) { 10 | this.hideLinks = options.hideLinks; 11 | } 12 | 13 | layout(node) { 14 | calcChildrenWidth(node); 15 | calcTotalSize(node); 16 | 17 | layout(node); 18 | } 19 | 20 | renderLinks(node) { 21 | if (!this.hideLinks) { 22 | renderLinks(node); 23 | } 24 | } 25 | } 26 | 27 | 28 | function layout(node) { 29 | if (node.children.length === 0) { 30 | return; 31 | } 32 | 33 | var x = -Math.round(node.childrenWidth / 2); 34 | const y = 0; 35 | 36 | node.children.forEach((child) => { 37 | child.x = x + Math.round(child.totalWidth / 2) - Math.round(child.width / 2); 38 | child.y = y; 39 | 40 | child.g 41 | .transition() 42 | .duration(DURATION) 43 | .attr('transform', `translate(${child.x},${child.y})`); 44 | 45 | x += child.totalWidth + node.margin; 46 | }); 47 | } 48 | 49 | 50 | function renderLinks(node) { 51 | if (node.children.length === 0) { 52 | return; 53 | } 54 | 55 | var h = node.children[0].linkY; 56 | 57 | node.children.forEach((child) => { 58 | h = Math.min(h, child.linkY); 59 | }); 60 | 61 | const orig = { x: 0, y: 0 }; 62 | 63 | var i, src, dst; 64 | 65 | for (i = 0; i < node.children.length; i++) { 66 | if (i === 0) { 67 | continue; 68 | } 69 | 70 | const prev = node.children[i - 1]; 71 | const child = node.children[i]; 72 | 73 | src = { 74 | x: prev.x + prev.linkX, 75 | y: prev.y + h 76 | }; 77 | 78 | dst = { 79 | x: child.x + child.linkX, 80 | y: child.y + h 81 | }; 82 | 83 | const link = node.g.insert('path', ':first-child') 84 | .attr('class', 'vtree-link') 85 | .attr('d', function () { 86 | return diagonal({ source: orig, target: orig }); 87 | }); 88 | 89 | link 90 | .transition() 91 | .duration(DURATION) 92 | .attr('d', function () { 93 | return diagonal({ source: src, target: dst }); 94 | }); 95 | } 96 | } 97 | 98 | 99 | function calcChildrenWidth(node) { 100 | if (node.children.length === 0) { 101 | node.childrenWidth = 0; 102 | 103 | return; 104 | } 105 | 106 | var w = 0; 107 | 108 | node.children.forEach((child) => { 109 | w += child.totalWidth; 110 | }); 111 | 112 | w += (node.children.length - 1) * node.margin; 113 | 114 | node.childrenWidth = w; 115 | } 116 | 117 | 118 | function calcTotalSize(node) { 119 | if (node.children.length === 0) { 120 | node.totalWidth = node.width; 121 | node.totalHeight = node.height; 122 | 123 | return; 124 | } 125 | 126 | node.totalWidth = Math.max(node.width, node.childrenWidth); 127 | 128 | var maxChildH = 0; 129 | 130 | node.children.forEach((child) => { 131 | maxChildH = Math.max(maxChildH, child.totalHeight); 132 | }); 133 | 134 | node.totalHeight = maxChildH; 135 | } 136 | -------------------------------------------------------------------------------- /src/layout/tree.js: -------------------------------------------------------------------------------- 1 | /* global d3 */ 2 | 3 | import ArrayNode from '../node/array.js'; 4 | 5 | const MARGIN = 10; 6 | const HEIGHT = 50; 7 | const DURATION = 1000; 8 | 9 | const diagonal = d3.svg.diagonal(); 10 | 11 | 12 | export default class TreeLayout { 13 | constructor(options={}) { 14 | this.height = options.height || HEIGHT; 15 | } 16 | 17 | layout(node) { 18 | calcChildrenWidth(node); 19 | calcTotalSize(node, this.height); 20 | 21 | layout(node, this.height); 22 | } 23 | 24 | renderLinks(node) { 25 | renderLinks(node); 26 | } 27 | } 28 | 29 | 30 | function layout(node, height) { 31 | if (node.children.length === 0) { 32 | return; 33 | } 34 | 35 | var x = Math.round(node.width / 2) - Math.round(node.childrenWidth / 2); 36 | const y = node.height + height; 37 | 38 | node.children.forEach((child) => { 39 | child.x = x + Math.round(child.totalWidth / 2) - Math.round(child.width / 2); 40 | child.y = y; 41 | 42 | child.g 43 | .transition() 44 | .duration(DURATION) 45 | .attr('transform', `translate(${child.x},${child.y})`); 46 | 47 | x += child.totalWidth + MARGIN; 48 | }); 49 | } 50 | 51 | 52 | function renderLinks(node) { 53 | const src = { 54 | x: node.linkX, 55 | y: node.linkY 56 | }; 57 | 58 | node.children.forEach((child) => { 59 | const dst = { 60 | x: child.x + child.linkX, 61 | y: child.y + child.linkY 62 | }; 63 | 64 | if (child.constructor === ArrayNode) { 65 | if (child.children.length !== 0) { 66 | const gc = child.children[0] 67 | dst.x += gc.x + gc.linkX; 68 | dst.y += gc.y + gc.linkY; 69 | } 70 | } 71 | 72 | const link = node.g.insert('path', ':first-child') 73 | .attr('class', 'vtree-link') 74 | .attr('d', function () { 75 | return diagonal({ source: src, target: src }); 76 | }); 77 | 78 | link 79 | .transition() 80 | .duration(DURATION) 81 | .attr('d', function () { 82 | return diagonal({ source: src, target: dst }); 83 | }); 84 | }); 85 | } 86 | 87 | 88 | function calcChildrenWidth(node) { 89 | if (node.children.length === 0) { 90 | node.childrenWidth = 0; 91 | 92 | return; 93 | } 94 | 95 | var w = 0; 96 | 97 | node.children.forEach((child) => { 98 | w += child.totalWidth; 99 | }); 100 | 101 | w += (node.children.length - 1) * MARGIN; 102 | 103 | node.childrenWidth = w; 104 | } 105 | 106 | 107 | function calcTotalSize(node, height) { 108 | if (node.children.length === 0) { 109 | node.totalWidth = node.width; 110 | node.totalHeight = node.height; 111 | 112 | return; 113 | } 114 | 115 | node.totalWidth = Math.max(node.width, node.childrenWidth); 116 | 117 | var maxChildH = 0; 118 | 119 | node.children.forEach((child) => { 120 | maxChildH = Math.max(maxChildH, child.totalHeight); 121 | }); 122 | 123 | node.totalHeight = node.height + height + maxChildH; 124 | } 125 | -------------------------------------------------------------------------------- /src/node/README.md: -------------------------------------------------------------------------------- 1 | # How to make a custom node 2 | 3 | 1. extend the Node class 4 | 5 | ```js 6 | export default class MyNode extends Node { 7 | ... 8 | } 9 | ``` 10 | 11 | 2. create the constructor functio and call super in it. 12 | 13 | ```js 14 | constructor(data, children) { 15 | super(data, children); 16 | 17 | ... 18 | } 19 | ``` 20 | 21 | 3. write a custom \_render function. 22 | And set this.width, this.height, this.linkX and this.linkY in it. 23 | (linkX, linkY) is a link coord. 24 | 25 | ```js 26 | _render(g) { 27 | 28 | ... 29 | 30 | this.width = ...; 31 | this.height = ...; 32 | 33 | this.linkX = ...; 34 | this.linkY = ...; 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /src/node/array.js: -------------------------------------------------------------------------------- 1 | import Node from './node.js'; 2 | import ArrayLayout from '../layout/array.js'; 3 | 4 | const defaultLayout = new ArrayLayout(); 5 | 6 | const MARGIN = 10; 7 | 8 | 9 | export default class ArrayNode extends Node { 10 | constructor(nodes, layout, options={}) { 11 | if (!layout) { 12 | layout = defaultLayout; 13 | } 14 | 15 | super(null, nodes, layout); 16 | 17 | this.width = 0; 18 | this.height = 0; 19 | 20 | this.linkX = 0; 21 | this.linkY = 0; 22 | 23 | this.margin = options.margin || MARGIN; 24 | } 25 | 26 | _render() { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/node/dummy.js: -------------------------------------------------------------------------------- 1 | import Node from './node.js'; 2 | 3 | 4 | export default class DummyNode extends Node { 5 | constructor(child) { 6 | super(null, [child]); 7 | 8 | this.r = 4; 9 | } 10 | 11 | _render(g) { 12 | g.append('circle') 13 | .attr('cx', this.r) 14 | .attr('cy', this.r) 15 | .attr('r', this.r); 16 | 17 | this.width = this.r * 2; 18 | this.height = this.r * 2; 19 | 20 | this.linkX = this.r; 21 | this.linkY = this.r; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/node/node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Node 3 | * 4 | * A tree consists of nodes and links. 5 | * A node consists of the following fields: 6 | * 7 | * - id : auto increment ID. 8 | * - data : data which may be displayed. 9 | * The data format is determined by the renderer. 10 | * - children : children of the node 11 | */ 12 | 13 | 14 | var curMaxId = 0; 15 | 16 | export default class Node { 17 | constructor(data, children, layout) { 18 | this.id = ++curMaxId; 19 | this.data = data; 20 | this.children = children; 21 | 22 | if (layout) { 23 | this.layout = layout; 24 | } 25 | 26 | this.width = 0; 27 | this.height = 0; 28 | 29 | this.decorators = []; 30 | } 31 | 32 | render(g) { 33 | if (this.decorators.length === 0) { 34 | this._render(g); 35 | return; 36 | } 37 | 38 | var prevG = g.append('g'); 39 | this._render(prevG); 40 | 41 | this.decorators.forEach((decorator) => { 42 | const newG = g.append('g'); 43 | 44 | const dbbox = decorator.render(newG, prevG, this.width, this.height); 45 | 46 | if (dbbox.dw || dbbox.dh) { 47 | this.width += dbbox.dw; 48 | this.height += dbbox.dh; 49 | } 50 | 51 | if (dbbox.dx || dbbox.dy) { 52 | prevG.attr('transform', `translate(${dbbox.dx},${dbbox.dy})`); 53 | 54 | this.linkX += dbbox.dx; 55 | this.linkY += dbbox.dy; 56 | } 57 | 58 | prevG = newG; 59 | }); 60 | } 61 | 62 | _render() { 63 | throw new Error('[no overwride errror] _render is not implemented.'); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/node/string.js: -------------------------------------------------------------------------------- 1 | import Node from './node.js'; 2 | import { appendRectText } from './util.js'; 3 | 4 | 5 | export default class StringNode extends Node { 6 | constructor(data) { 7 | super(data, []); 8 | 9 | this.textPad = 4; 10 | } 11 | 12 | _render(g) { 13 | const bbox = appendRectText(g, 0, 0, this.data, this.textPad); 14 | 15 | this.width = bbox.width; 16 | this.height = bbox.height; 17 | 18 | this.linkX = Math.round(this.width / 2); 19 | this.linkY = Math.round(this.height / 2); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/node/table.js: -------------------------------------------------------------------------------- 1 | import Node from './node.js'; 2 | import { appendRectText } from './util.js'; 3 | 4 | 5 | export default class TableNode extends Node { 6 | constructor(data, children) { 7 | super(data, children); 8 | 9 | this.textPad = 4; 10 | } 11 | 12 | _render(g) { 13 | if (this.data.length === 0 || this.data[0].length === 0) { 14 | return; 15 | } 16 | 17 | const tbl = this.renderCells(g); 18 | const size = this.layoutCells(tbl); 19 | 20 | this.width = size.width; 21 | this.height = size.height; 22 | 23 | this.linkX = Math.round(this.width / 2); 24 | this.linkY = Math.round(this.height / 2); 25 | } 26 | 27 | renderCells(g) { 28 | const tbl = []; 29 | 30 | this.data.forEach((row) => { 31 | const tblRow = []; 32 | 33 | row.forEach((col) => { 34 | const colG = g.append('g'); 35 | const bbox = appendRectText(colG, 0, 0, col, this.textPad); 36 | 37 | tblRow.push({ 38 | g: colG, 39 | bbox: bbox 40 | }); 41 | }); 42 | 43 | tbl.push(tblRow); 44 | }); 45 | 46 | return tbl; 47 | } 48 | 49 | layoutCells(tbl) { 50 | const maxW = this.calcMaxWidths(tbl); 51 | const maxH = this.calcMaxHeights(tbl); 52 | 53 | var x = 0; 54 | var y = 0; 55 | 56 | tbl.forEach((row, rowI) => { 57 | x = 0; 58 | 59 | row.forEach((col, colI) => { 60 | col.g.attr('transform', `translate(${x},${y})`); 61 | col.g.select('rect') 62 | .attr('width', maxW[colI]) 63 | .attr('height', maxH[rowI]); 64 | 65 | x += maxW[colI]; 66 | }); 67 | 68 | y += maxH[rowI]; 69 | }); 70 | 71 | return { width: x, height: y }; 72 | } 73 | 74 | calcMaxWidths(tbl) { 75 | const maxW = []; 76 | var colI, rowI; 77 | 78 | for (colI = 0; colI < tbl[0].length; colI++) { 79 | var w = 0; 80 | 81 | for (rowI = 0; rowI < tbl.length; rowI++) { 82 | w = Math.max(w, tbl[rowI][colI].bbox.width); 83 | } 84 | 85 | maxW.push(w); 86 | } 87 | 88 | return maxW; 89 | } 90 | 91 | calcMaxHeights(tbl) { 92 | const maxH = []; 93 | 94 | tbl.forEach((row) => { 95 | var h = 0; 96 | 97 | row.forEach((col) => { 98 | h = Math.max(h, col.bbox.height); 99 | }); 100 | 101 | maxH.push(h); 102 | }); 103 | 104 | return maxH; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/node/util.js: -------------------------------------------------------------------------------- 1 | const MAX_LEN = 32; 2 | 3 | export class BBox { 4 | constructor(x=0, y=0, width=0, height=0) { 5 | this.x = x; 6 | this.y = y; 7 | this.width = width; 8 | this.height = height; 9 | } 10 | } 11 | 12 | 13 | export function appendRectText(g, x, y, text, pad) { 14 | if (typeof text === 'string' && text.length > MAX_LEN) { 15 | text = text.substr(0, MAX_LEN) + '...'; 16 | } 17 | 18 | const rect = g.append('rect') 19 | .attr('class', getClassName(text)); 20 | 21 | const t = g.append('text') 22 | .text(text); 23 | 24 | const b = t.node().getBBox(); 25 | const w = Math.ceil(b.width); 26 | const h = Math.ceil(b.height); 27 | 28 | t 29 | .attr('x', x + pad) 30 | .attr('y', y + pad + h); 31 | 32 | const bbox = new BBox(x, y, w + pad * 2, h + pad * 2); 33 | 34 | rect 35 | .attr('x', bbox.x) 36 | .attr('y', bbox.y) 37 | .attr('width', bbox.width) 38 | .attr('height', bbox.height); 39 | 40 | return bbox; 41 | } 42 | 43 | 44 | function getClassName(d) { 45 | var name = ''; 46 | const type = typeof d; 47 | 48 | if (d === null) { 49 | return 'null-text'; 50 | } else if (type === 'string') { 51 | name = 'string-text'; 52 | } else if (type === 'number') { 53 | name = 'number-text'; 54 | } else if (type === 'boolean') { 55 | name = 'boolean-text'; 56 | } else { 57 | name = 'unknown-text'; 58 | } 59 | 60 | return name; 61 | } 62 | -------------------------------------------------------------------------------- /src/reader/object.js: -------------------------------------------------------------------------------- 1 | import StringNode from '../node/string.js'; 2 | import ArrayNode from '../node/array.js'; 3 | import TableNode from '../node/table.js'; 4 | import DummyNode from '../node/dummy.js'; 5 | 6 | import LinkNameDecorator from '../decorator/linkName.js'; 7 | 8 | 9 | export default class ObjectReader { 10 | constructor() { 11 | } 12 | 13 | read(obj) { 14 | return obj2node(obj, ''); 15 | } 16 | } 17 | 18 | 19 | function obj2node(obj, linkName) { 20 | var node; 21 | 22 | if (isPrimitive(obj)) { 23 | node = new StringNode(obj); 24 | } else if (Array.isArray(obj)) { 25 | const nodes = []; 26 | 27 | obj.forEach((item, i) => { 28 | if (Array.isArray(item)) { 29 | node = new DummyNode(obj2node(item, '')); 30 | node.decorators.push(new LinkNameDecorator(`${linkName}[${i}]`)); 31 | nodes.push(node); 32 | } else { 33 | node = obj2node(item, `${linkName}[${i}]`); 34 | nodes.push(node); 35 | } 36 | }); 37 | 38 | // empty array 39 | if (nodes.length === 0) { 40 | node = obj2node(null, `${linkName}[]`); 41 | nodes.push(node); 42 | } 43 | 44 | node = new ArrayNode(nodes); 45 | } else { 46 | var name; 47 | var tbl = []; 48 | var children = []; 49 | 50 | for (name in obj) { 51 | if (!Object.prototype.hasOwnProperty.call(obj, name)) { 52 | continue; 53 | } 54 | 55 | var data = obj[name]; 56 | 57 | if (isPrimitive(data)) { 58 | tbl.push([name, data]); 59 | } else { 60 | children.push(obj2node(data, name)); 61 | } 62 | } 63 | 64 | if (tbl.length === 0) { 65 | node = new TableNode([[' ', ' ']], children); 66 | } else { 67 | node = new TableNode(tbl, children); 68 | } 69 | 70 | } 71 | 72 | if (linkName !== '' && node.constructor !== ArrayNode) { 73 | node.decorators.push(new LinkNameDecorator(linkName)); 74 | } 75 | 76 | return node; 77 | } 78 | 79 | 80 | function isPrimitive(d) { 81 | const type = typeof d; 82 | 83 | if (d === null || type === 'string' || type === 'number' || type === 'boolean') { 84 | return true; 85 | } 86 | 87 | return false; 88 | } 89 | -------------------------------------------------------------------------------- /src/reader/test/object_reader_test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | 3 | import Reader from '../object.js'; 4 | 5 | import StringNode from '../../node/string.js'; 6 | import ArrayNode from '../../node/array.js'; 7 | import TableNode from '../../node/table.js'; 8 | import DummyNode from '../../node/dummy.js'; 9 | 10 | import LinkNameDecorator from '../../decorator/linkName.js'; 11 | 12 | 13 | describe('test ObjectReader', function () { 14 | var r; 15 | 16 | beforeEach(function () { 17 | r = new Reader(); 18 | }); 19 | 20 | // read a primitive object 21 | 22 | it ('read a null', function () { 23 | var d = r.read(null); 24 | expect(d).to.be.instanceof(StringNode); 25 | expect(d.data).to.equal(null); 26 | expect(d.children).to.have.lengthOf(0); 27 | }); 28 | 29 | it ('read a boolean', function () { 30 | var d = r.read(true); 31 | expect(d).to.be.instanceof(StringNode); 32 | expect(d.data).to.equal(true); 33 | expect(d.children).to.have.lengthOf(0); 34 | 35 | d = r.read(false); 36 | expect(d).to.be.instanceof(StringNode); 37 | expect(d.data).to.equal(false); 38 | expect(d.children).to.have.lengthOf(0); 39 | }); 40 | 41 | it ('read a number', function () { 42 | var d = r.read(666); 43 | expect(d).to.be.instanceof(StringNode); 44 | expect(d.data).to.equal(666); 45 | expect(d.children).to.have.lengthOf(0); 46 | 47 | d = r.read(3.14); 48 | expect(d).to.be.instanceof(StringNode); 49 | expect(d.data).to.equal(3.14); 50 | expect(d.children).to.have.lengthOf(0); 51 | }); 52 | 53 | it ('read a string', function () { 54 | var d = r.read('JK business'); 55 | expect(d).to.be.instanceof(StringNode); 56 | expect(d.data).to.equal('JK business'); 57 | expect(d.children).to.have.lengthOf(0); 58 | 59 | d = r.read('お茶漬け'); 60 | expect(d).to.be.instanceof(StringNode); 61 | expect(d.data).to.equal('お茶漬け'); 62 | expect(d.children).to.have.lengthOf(0); 63 | }); 64 | 65 | // read a complex object 66 | 67 | it ('read an array', function () { 68 | var d = r.read([1, 2]); 69 | expect(d.data).to.equal(null); 70 | expect(d).to.be.instanceof(ArrayNode); 71 | expect(d.children).to.have.lengthOf(2); 72 | 73 | var c = d.children[0]; 74 | expect(c).to.be.instanceof(StringNode); 75 | expect(c.data).to.equal(1); 76 | expect(c.children).to.have.lengthOf(0); 77 | 78 | c = d.children[1]; 79 | expect(c).to.be.instanceof(StringNode); 80 | expect(c.data).to.equal(2); 81 | expect(c.children).to.have.lengthOf(0); 82 | }); 83 | 84 | it ('read a nested array', function () { 85 | var d = r.read([1, [2, 3]]); 86 | expect(d.data).to.equal(null); 87 | expect(d).to.be.instanceof(ArrayNode); 88 | expect(d.children).to.have.lengthOf(2); 89 | 90 | var c = d.children[0]; 91 | expect(c).to.be.instanceof(StringNode); 92 | expect(c.data).to.equal(1); 93 | expect(c.children).to.have.lengthOf(0); 94 | 95 | c = d.children[1]; 96 | expect(c).to.be.instanceof(DummyNode); 97 | expect(c.data).to.eql(null); 98 | expect(c.children).to.have.lengthOf(1); 99 | 100 | d = c.children[0]; 101 | expect(d).to.be.instanceof(ArrayNode); 102 | expect(d.data).to.equal(null); 103 | expect(d.children).to.have.lengthOf(2); 104 | 105 | c = d.children[0]; 106 | expect(c).to.be.instanceof(StringNode); 107 | expect(c.data).to.equal(2); 108 | expect(c.children).to.have.lengthOf(0); 109 | 110 | c = d.children[1]; 111 | expect(c).to.be.instanceof(StringNode); 112 | expect(c.data).to.equal(3); 113 | expect(c.children).to.have.lengthOf(0); 114 | }); 115 | 116 | it ('read an object', function () { 117 | var d = r.read({ 118 | x: 1, 119 | y: 2 120 | }); 121 | 122 | expect(d).to.be.instanceof(TableNode); 123 | expect(d.data).to.eql([['x', 1], ['y', 2]]); 124 | expect(d.children).to.have.lengthOf(0); 125 | }); 126 | 127 | it ('read a nested object', function () { 128 | var d = r.read({ 129 | name: { 130 | first: 'Bob', 131 | last: 'Bach' 132 | }, 133 | age: 24 134 | }); 135 | 136 | expect(d).to.be.instanceof(TableNode); 137 | expect(d.data).to.eql([['age', 24]]); 138 | expect(d.children).to.have.lengthOf(1); 139 | 140 | var c = d.children[0]; 141 | expect(c).to.be.instanceof(TableNode); 142 | expect(c.data).to.eql([['first', 'Bob'], ['last', 'Bach']]); 143 | expect(c.children).to.have.lengthOf(0); 144 | 145 | var deco = c.decorators[0]; 146 | expect(deco).to.be.instanceof(LinkNameDecorator); 147 | expect(deco.linkName).to.equal('name'); 148 | }); 149 | 150 | it ('read a nested object with no parent data', function () { 151 | var d = r.read({ 152 | name: { 153 | first: 'Bob', 154 | last: 'Bach' 155 | } 156 | }); 157 | 158 | expect(d).to.be.instanceof(TableNode); 159 | expect(d.data).to.eql([[' ', ' ']]); 160 | expect(d.children).to.have.lengthOf(1); 161 | 162 | var c = d.children[0]; 163 | expect(c).to.be.instanceof(TableNode); 164 | expect(c.data).to.eql([['first', 'Bob'], ['last', 'Bach']]); 165 | expect(c.children).to.have.lengthOf(0); 166 | 167 | var deco = c.decorators[0]; 168 | expect(deco).to.be.instanceof(LinkNameDecorator); 169 | expect(deco.linkName).to.equal('name'); 170 | }); 171 | 172 | it ('read an array containing an object', function () { 173 | var d = r.read([1, {val: 4}]); 174 | expect(d.data).to.equal(null); 175 | expect(d).to.be.instanceof(ArrayNode); 176 | expect(d.children).to.have.lengthOf(2); 177 | 178 | var c = d.children[0]; 179 | expect(c).to.be.instanceof(StringNode); 180 | expect(c.data).to.equal(1); 181 | expect(c.children).to.have.lengthOf(0); 182 | 183 | c = d.children[1]; 184 | expect(c).to.be.instanceof(TableNode); 185 | expect(c.data).to.eql([['val', 4]]); 186 | expect(c.children).to.have.lengthOf(0); 187 | }); 188 | 189 | it ('read an object containing an array', function () { 190 | var d = r.read({ 191 | name: 'Mike', 192 | vals: [2, 4] 193 | }); 194 | 195 | expect(d).to.be.instanceof(TableNode); 196 | expect(d.data).to.eql([['name', 'Mike']]); 197 | expect(d.children).to.have.lengthOf(1); 198 | 199 | var c = d.children[0]; 200 | expect(c).to.be.instanceof(ArrayNode); 201 | expect(c.data).to.equal(null); 202 | expect(c.children).to.have.lengthOf(2); 203 | 204 | d = c.children[0]; 205 | expect(d).to.be.instanceof(StringNode); 206 | expect(d.data).to.equal(2); 207 | expect(d.children).to.have.lengthOf(0); 208 | 209 | var deco = d.decorators[0]; 210 | expect(deco).to.be.instanceof(LinkNameDecorator); 211 | expect(deco.linkName).to.equal('vals[0]'); 212 | 213 | d = c.children[1]; 214 | expect(d).to.be.instanceof(StringNode); 215 | expect(d.data).to.equal(4); 216 | expect(d.children).to.have.lengthOf(0); 217 | 218 | deco = d.decorators[0]; 219 | expect(deco).to.be.instanceof(LinkNameDecorator); 220 | expect(deco.linkName).to.equal('vals[1]'); 221 | }); 222 | }); 223 | -------------------------------------------------------------------------------- /src/util.js: -------------------------------------------------------------------------------- 1 | export function visitBefore(node, callback) { 2 | const nodes = [node]; 3 | 4 | while (nodes.length !== 0) { 5 | node = nodes.pop(); 6 | 7 | callback(node); 8 | 9 | const children = node.children; 10 | 11 | if (children) { 12 | var n = children.length; 13 | 14 | while (--n >= 0) { 15 | nodes.push(children[n]); 16 | } 17 | } 18 | } 19 | } 20 | 21 | export function visitAfter(node, callback) { 22 | const nodes = [node]; 23 | const nodes2 = []; 24 | 25 | while (nodes.length !== 0) { 26 | node = nodes.pop(); 27 | 28 | nodes2.push(node); 29 | 30 | const children = node.children; 31 | 32 | if (children) { 33 | var i = -1; 34 | const n = children.length; 35 | 36 | while (++i < n) { 37 | nodes.push(children[i]); 38 | } 39 | } 40 | } 41 | 42 | while (nodes2.length !== 0) { 43 | node = nodes2.pop(); 44 | 45 | callback(node); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/vtree.js: -------------------------------------------------------------------------------- 1 | /* global d3 */ 2 | 3 | import Node from './node/node.js'; 4 | import StringNode from './node/string.js'; 5 | import TableNode from './node/table.js'; 6 | import ArrayNode from './node/array.js'; 7 | 8 | import TreeLayout from './layout/tree.js'; 9 | import ArrayLayout from './layout/array.js'; 10 | 11 | import ObjectReader from './reader/object.js'; 12 | 13 | import { visitAfter } from './util.js'; 14 | 15 | 16 | const WIDTH = 960; 17 | const HEIGHT = 800; 18 | const MARGIN = 20; 19 | 20 | const DEFAULT_TREE_LAYOUT_HEIGHT = 50; 21 | const DEBUG_TREE_LAYOUT_HEIGHT = 100; 22 | 23 | const style = ` 24 | .vtree-node text { font: 14px sans-serif; } 25 | .vtree-link { fill: none; stroke: #888; stroke-width: 2px; } 26 | .vtree-table { stroke-width: 2px; stroke: steelblue; } 27 | path.vtree-table { fill: white; } 28 | g.vtree-node rect { fill: white; stroke: black; stroke-width: 1px; } 29 | g.vtree-node rect.number-text { fill: #d8f0ed; } 30 | g.vtree-node rect.string-text { fill: #e7f0db; } 31 | g.vtree-node rect.boolean-text { fill: #e1d8f0; } 32 | g.vtree-node rect.null-text { fill: #888; } 33 | `; 34 | 35 | 36 | class VTree { 37 | constructor(container) { 38 | this.root = new ArrayNode([], new ArrayLayout({ hideLinks: true })); 39 | this.defaultLayout = new TreeLayout({height: DEFAULT_TREE_LAYOUT_HEIGHT}); 40 | this.container = container; 41 | this._width = WIDTH; 42 | this._height = HEIGHT; 43 | this._debug = false; 44 | 45 | this.d3 = {}; 46 | 47 | this.d3.container = d3.select(this.container); 48 | 49 | this.d3.zoomListener = d3.behavior.zoom() 50 | .scaleExtent([0.1, 10]) 51 | .on('zoom', () => { 52 | const e = d3.event; 53 | 54 | if (this.d3.g) { 55 | this.d3.g.attr('transform', `translate(${e.translate})scale(${e.scale})`); 56 | } 57 | }); 58 | 59 | this.d3.svg = this.d3.container.append('svg') 60 | .attr('class', 'vtree') 61 | .attr('width', this._width) 62 | .attr('height', this._height) 63 | .call(this.d3.zoomListener); 64 | } 65 | 66 | width(width) { 67 | if (arguments.length === 0) { 68 | return this._width; 69 | } 70 | 71 | this._width = width; 72 | 73 | this.d3.container.select('svg') 74 | .attr('width', width); 75 | 76 | return this; 77 | } 78 | 79 | height(height) { 80 | if (arguments.length === 0) { 81 | return this._height; 82 | } 83 | 84 | this._height = height; 85 | 86 | this.d3.container.select('svg') 87 | .attr('height', height); 88 | 89 | return this; 90 | } 91 | 92 | debug(debug) { 93 | if (arguments.length === 0) { 94 | return this._debug; 95 | } 96 | 97 | if (debug) { 98 | this.defaultLayout.height = DEBUG_TREE_LAYOUT_HEIGHT; 99 | } else { 100 | this.defaultLayout.height = DEFAULT_TREE_LAYOUT_HEIGHT; 101 | } 102 | 103 | this._debug = debug; 104 | 105 | return this; 106 | } 107 | 108 | data(data) { 109 | if (Array.isArray(data)) { 110 | this.root.children = data; 111 | } else { 112 | this.root.children = [data]; 113 | } 114 | 115 | return this; 116 | } 117 | 118 | createSvgString() { 119 | var svg = this.d3.svg.node(); 120 | var serializer = new XMLSerializer(); 121 | var source = serializer.serializeToString(svg); 122 | 123 | if (!source.match(/^]+xmlns="http:\/\/www\.w3\.org\/2000\/svg"/)) { 124 | source = source.replace(/^]+"http:\/\/www\.w3\.org\/1999\/xlink"/)) { 128 | source = source.replace(/^ { 181 | node.render(node.g); 182 | 183 | const layout = node.layout || this.defaultLayout; 184 | 185 | layout.layout(node); 186 | 187 | if (layout.renderLinks) { 188 | layout.renderLinks(node); 189 | } 190 | }); 191 | 192 | if (this._debug) { 193 | visitAfter(this.root, (node) => { 194 | this._debugDrawNodeInfo(node); 195 | }); 196 | } 197 | 198 | 199 | this.setRootPos(); 200 | 201 | return this; 202 | } 203 | 204 | setRootPos() { 205 | this.root.x = Math.round((this._width - this.root.width) / 2); 206 | this.root.y = Math.round((this._height - this.root.totalHeight) / 2); 207 | 208 | if (this.root.y < MARGIN) { 209 | this.root.y = MARGIN; 210 | } 211 | 212 | this.root.g.attr('transform', `translate(${this.root.x},${this.root.y})`); 213 | 214 | } 215 | 216 | _debugGetG() { 217 | if (!this._debug) { 218 | return; 219 | } 220 | 221 | var g = this.d3.svg.select('g.debug-info'); 222 | 223 | if (!g.empty()) { 224 | return g; 225 | } 226 | 227 | return this.d3.svg.append('g') 228 | .attr('class', 'debug-info'); 229 | } 230 | 231 | _debugDrawGrid() { 232 | if (!this._debug) { 233 | return; 234 | } 235 | 236 | const g = this._debugGetG(); 237 | 238 | g.append('line') 239 | .style('stroke', 'red') 240 | .attr('x1', this._width / 2) 241 | .attr('y1', 0) 242 | .attr('x2', this._width / 2) 243 | .attr('y2', this._height); 244 | 245 | g.append('line') 246 | .style('stroke', 'red') 247 | .attr('x1', 0) 248 | .attr('y1', this._height / 2) 249 | .attr('x2', this._width) 250 | .attr('y2', this._height / 2); 251 | } 252 | 253 | _debugDrawNodeInfo(node) { 254 | if (node.constructor === ArrayNode) { 255 | return; 256 | } 257 | 258 | // node rect 259 | node.g.append('rect') 260 | .style('fill', 'none') 261 | .style('stroke', 'tomato') 262 | .attr('x', -1) 263 | .attr('y', -1) 264 | .attr('width', node.width + 2) 265 | .attr('height', node.height + 2); 266 | 267 | // node total rect 268 | node.g.append('rect') 269 | .style('fill', 'none') 270 | .style('stroke', 'mediumpurple') 271 | .attr('x', (node.width - node.totalWidth) / 2) 272 | .attr('y', 0) 273 | .attr('width', node.totalWidth) 274 | .attr('height', node.totalHeight); 275 | 276 | // x, y 277 | const xy = node.g.append('text') 278 | .text(`x=${node.x} y=${node.y}`); 279 | 280 | const bbox = xy.node().getBBox(); 281 | var x = node.width / 2; 282 | var y = node.height + bbox.height + 2; 283 | 284 | xy 285 | .attr('x', x) 286 | .attr('y', y) 287 | .attr('text-anchor', 'middle'); 288 | 289 | y += bbox.height + 2; 290 | 291 | // width, height 292 | node.g.append('text') 293 | .text(`w=${node.width} h=${node.height}`) 294 | .attr('x', x) 295 | .attr('y', y) 296 | .attr('text-anchor', 'middle'); 297 | 298 | y += bbox.height + 2; 299 | 300 | // totalWidth, totalHeight 301 | node.g.append('text') 302 | .text(`tw=${node.totalWidth} th=${node.totalHeight}`) 303 | .attr('x', x) 304 | .attr('y', y) 305 | .attr('text-anchor', 'middle'); 306 | 307 | y += bbox.height + 2; 308 | 309 | // childrenWidth 310 | node.g.append('text') 311 | .text(`cw=${node.childrenWidth}`) 312 | .attr('x', x) 313 | .attr('y', y) 314 | .attr('text-anchor', 'middle'); 315 | } 316 | } 317 | 318 | 319 | VTree.node = {}; 320 | VTree.node.Node = Node; 321 | VTree.node.String = StringNode; 322 | VTree.node.Table = TableNode; 323 | VTree.node.Array = ArrayNode; 324 | 325 | VTree.layout = {}; 326 | VTree.layout.Tree = TreeLayout; 327 | VTree.layout.Array = ArrayLayout; 328 | 329 | VTree.reader = {}; 330 | VTree.reader.Object = ObjectReader; 331 | 332 | module.exports = VTree; 333 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | vtree tests 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 53 | 54 | 55 | 56 | 57 | 58 |
59 |
60 |

vtree tests

61 |
62 | 63 |
64 |
65 | null 66 |
67 |
68 | 69 |
70 | true 71 |
72 |
73 | 74 |
75 | 123 76 |
77 |
78 | 79 |
80 | "黄 飛鴻" 81 |
82 |
83 | 84 |
85 | [1234.56789, "ABCDE"] 86 |
87 |
88 | 89 |
90 | { "key": "value" } 91 |
92 |
93 |
94 | 95 |
96 |
97 | {"name": "=" ,"children": [{"name": "id=range"},{"name": "class=range"}]} 98 |
99 |
100 | 101 |
102 | { 103 | "array": [ 104 | 1, 105 | 2, 106 | 3 107 | ], 108 | "boolean": true, 109 | "null": null, 110 | "number": 123, 111 | "object": { 112 | "a": "b", 113 | "c": "d", 114 | "e": "f" 115 | }, 116 | "string": "Hello World" 117 | } 118 |
119 |
120 | 121 |
122 | { 123 | "type": "Feature", 124 | "geometry": { 125 | "type": "Point", 126 | "coordinates": [125.6, 10.1] 127 | }, 128 | "properties": { 129 | "name": "Dinagat Islands" 130 | } 131 | } 132 |
133 |
134 |
135 | 136 |
137 |
138 | {"employees":[ 139 | {"firstName":"John", "lastName":"Doe"}, 140 | {"firstName":"Anna", "lastName":"Smith"}, 141 | {"firstName":"Peter", "lastName":"Jones"} 142 | ]} 143 |
144 |
145 | 146 |
147 | { 148 | "items": [ 149 | { 150 | "index": 1, 151 | "index_start_at": 56, 152 | "integer": 29, 153 | "float": 16.8278, 154 | "name": "Milton", 155 | "surname": "Jensen", 156 | "fullname": "Sheryl Winters", 157 | "email": "denise@weiss.na", 158 | "bool": false 159 | } 160 | ] 161 | } 162 |
163 |
164 | 165 |
166 | [1, [2, [3, 4]]] 167 |
168 |
169 |
170 | 171 |
172 |
173 | 174 |
175 |
176 | 177 |
178 | 179 |
180 |
181 |
182 | 183 |
184 |
185 | 201 |
202 |
203 | 204 |
205 | 242 |
243 |
244 |
245 | 246 |
247 |
248 | 249 |
250 |
251 | 252 |
253 | 254 |
255 |
256 |
257 | 258 |
259 |
260 | 337 |
338 |
339 | 340 |
341 | 342 |
343 |
344 |
345 |
346 | 347 | 348 | 349 | 350 | -------------------------------------------------------------------------------- /vtree.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivan111/vtree/008e1fe3d6a2694bd567bbdeccf9dcb7dd0ea985/vtree.jpg -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | const config = { 4 | mode: 'development', 5 | 6 | entry: './src/vtree.js', 7 | 8 | output: { 9 | path: path.join(__dirname, 'dist'), 10 | filename: 'vtree.js', 11 | library: 'VTree' 12 | }, 13 | 14 | module: { 15 | rules: [ 16 | { 17 | enforce: 'pre', 18 | test: /\.js$/, 19 | exclude: /node_modules/, 20 | loader: 'eslint-loader' 21 | }, 22 | { 23 | test: /\.js$/, 24 | exclude: /node_modules/, 25 | loader: 'babel-loader', 26 | query: { 27 | presets: ['es2015'] 28 | } 29 | } 30 | ] 31 | } 32 | } 33 | 34 | module.exports = config 35 | --------------------------------------------------------------------------------