├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── config-overrides.js ├── demo.gif ├── demo.png ├── design ├── logo.png └── logo.psd ├── package.json ├── public ├── index.html ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── App.test.js ├── data │ └── data.js ├── index.css ├── index.js ├── libroot.js ├── logo.svg ├── reportWebVitals.js ├── setupTests.js └── treemap │ ├── TreeBox.js │ ├── canvas.js │ ├── interaction.js │ ├── layout.js │ ├── paint.js │ ├── transition.js │ └── viewport.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | 25 | .idea 26 | .eslintcache 27 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | design 4 | public -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ke Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # treebox 2 | 3 |  4 | 5 | Treebox is an interactive TreeMap visualization 6 | 7 | - weight-aware multi-level hierarchical treemap layout 8 | - click on a block to zoom in / "esc" to zoom out 9 | - smooth transition 10 | - uses canvas & requestAnimationFrame for performance 11 | - customize text / color / weight 12 | - fires events (so you can implement tooltip, etc.) 13 | - no dependency (5kb gzipped) 14 | - MIT license 15 | 16 | # DEMO 17 | 18 |  19 | 20 |  21 | 22 | # try it 23 | 24 | ```bash 25 | git clone https://github.com/KevinWang15/treebox 26 | cd treebox 27 | yarn install 28 | yarn start 29 | ``` 30 | 31 | # use it 32 | 33 | ```bash 34 | npm i @kevinwang15/treebox 35 | ``` 36 | 37 | ```javascript 38 | export function genData(layers = 4) { 39 | const result = []; 40 | 41 | for (let i = 0; i < 7; i++) { 42 | const children = layers - 1 > 0 ? genData(layers - 1) : null; 43 | result.push({ 44 | text: `${layers}-${i}`, 45 | color: ({ ctx, hovering, item, bounds }) => "red", 46 | children, 47 | weight: children ? null : Math.floor(10 * (1 + 2 * Math.random())), 48 | }); 49 | } 50 | 51 | return result; 52 | } 53 | ``` 54 | 55 | ```javascript 56 | import TreeBox from "@kevinwang15/treebox"; 57 | 58 | const pixelRatio = 2; 59 | 60 |