├── .babelrc
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── README.md
├── assets
├── page.css
└── page.js
├── index.html
├── lib
└── d3-tree.js
├── package.json
├── test
├── d3-tree.test.js
├── helper.js
└── mocha.opts
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | presets: [
3 | 'env',
4 | 'stage-2'
5 | ],
6 | comments: false,
7 | env: {
8 | test: {
9 | plugins: [
10 | 'istanbul'
11 | ]
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | **/.*
2 | **/node_modules
3 | **/dist
4 | **/assets
5 | **/build
6 | **/test
7 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "node": true,
5 | "es6": true,
6 | "mocha": true
7 | },
8 | "plugins": [
9 | "mocha"
10 | ],
11 | // https://github.com/feross/eslint-config-standard
12 | "rules": {
13 | "accessor-pairs": 2,
14 | "block-scoped-var": 0,
15 | "brace-style": [2, "1tbs", { "allowSingleLine": true }],
16 | "camelcase": 0,
17 | "comma-dangle": [2, "never"],
18 | "comma-spacing": [2, { "before": false, "after": true }],
19 | "comma-style": [2, "last"],
20 | "complexity": 0,
21 | "consistent-return": 0,
22 | "consistent-this": 0,
23 | "curly": [2, "multi-line"],
24 | "default-case": 0,
25 | "dot-location": [2, "property"],
26 | "dot-notation": 0,
27 | "eol-last": 2,
28 | "eqeqeq": [2, "allow-null"],
29 | "func-names": 0,
30 | "func-style": 0,
31 | "generator-star-spacing": [2, "both"],
32 | "guard-for-in": 0,
33 | "handle-callback-err": [2, "^(err|error|anySpecificError)$" ],
34 | "indent": [2, 2],
35 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
36 | "linebreak-style": 0,
37 | "max-depth": 0,
38 | "max-len": 0,
39 | "max-nested-callbacks": 0,
40 | "max-params": 0,
41 | "max-statements": 0,
42 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
43 | "new-parens": 2,
44 | "no-alert": 0,
45 | "no-array-constructor": 2,
46 | "no-bitwise": 0,
47 | "no-caller": 2,
48 | "no-catch-shadow": 0,
49 | "no-cond-assign": 2,
50 | "no-console": 0,
51 | "no-constant-condition": 0,
52 | "no-continue": 0,
53 | "no-control-regex": 2,
54 | "no-debugger": 2,
55 | "no-delete-var": 2,
56 | "no-div-regex": 0,
57 | "no-dupe-args": 2,
58 | "no-dupe-keys": 2,
59 | "no-duplicate-case": 2,
60 | "no-else-return": 0,
61 | "no-empty": 0,
62 | "no-empty-character-class": 2,
63 | "no-eq-null": 0,
64 | "no-eval": 2,
65 | "no-ex-assign": 2,
66 | "no-extend-native": 2,
67 | "no-extra-bind": 2,
68 | "no-extra-boolean-cast": 2,
69 | "no-extra-semi": 0,
70 | "no-extra-strict": 0,
71 | "no-fallthrough": 2,
72 | "no-floating-decimal": 2,
73 | "no-func-assign": 2,
74 | "no-implied-eval": 2,
75 | "no-inline-comments": 0,
76 | "no-inner-declarations": [2, "functions"],
77 | "no-invalid-regexp": 2,
78 | "no-irregular-whitespace": 2,
79 | "no-iterator": 2,
80 | "no-label-var": 2,
81 | "no-labels": 2,
82 | "no-lone-blocks": 2,
83 | "no-lonely-if": 0,
84 | "no-loop-func": 0,
85 | "no-mixed-requires": 0,
86 | "no-mixed-spaces-and-tabs": [2, false],
87 | "no-multi-spaces": 2,
88 | "no-multi-str": 2,
89 | "no-multiple-empty-lines": [2, { "max": 1 }],
90 | "no-native-reassign": 2,
91 | "no-negated-in-lhs": 2,
92 | "no-nested-ternary": 0,
93 | "no-new": 0,
94 | "no-new-func": 2,
95 | "no-new-object": 2,
96 | "no-new-require": 2,
97 | "no-new-wrappers": 2,
98 | "no-obj-calls": 2,
99 | "no-octal": 2,
100 | "no-octal-escape": 2,
101 | "no-path-concat": 0,
102 | "no-plusplus": 0,
103 | "no-process-env": 0,
104 | "no-process-exit": 0,
105 | "no-proto": 2,
106 | "no-redeclare": 2,
107 | "no-regex-spaces": 2,
108 | "no-reserved-keys": 0,
109 | "no-restricted-modules": 0,
110 | "no-return-assign": 2,
111 | "no-script-url": 0,
112 | "no-self-compare": 2,
113 | "no-sequences": 2,
114 | "no-shadow": 0,
115 | "no-shadow-restricted-names": 2,
116 | "no-spaced-func": 2,
117 | "no-sparse-arrays": 2,
118 | "no-sync": 0,
119 | "no-ternary": 0,
120 | "no-throw-literal": 2,
121 | "no-trailing-spaces": 2,
122 | "no-undef": 2,
123 | "no-undef-init": 2,
124 | "no-undefined": 0,
125 | "no-underscore-dangle": 0,
126 | "no-unneeded-ternary": 2,
127 | "no-unreachable": 2,
128 | "no-unused-expressions": 0,
129 | "no-unused-vars": [2, { "vars": "all", "args": "none" }],
130 | "no-use-before-define": 0,
131 | "no-var": 0,
132 | "no-void": 0,
133 | "no-warning-comments": 0,
134 | "no-with": 2,
135 | "no-extra-parens": 0,
136 | "object-curly-spacing": 0,
137 | "one-var": [2, { "initialized": "never" }],
138 | "operator-assignment": 0,
139 | "operator-linebreak": [2, "after"],
140 | "padded-blocks": 0,
141 | "quote-props": 0,
142 | "quotes": [1, "single", "avoid-escape"],
143 | "radix": 2,
144 | "semi": [2, "always"],
145 | "semi-spacing": 0,
146 | "sort-vars": 0,
147 | "keyword-spacing": [2],
148 | "space-before-blocks": [2, "always"],
149 | "space-before-function-paren": 0,
150 | "space-in-parens": [2, "never"],
151 | "space-infix-ops": 2,
152 | "space-unary-ops": [2, { "words": true, "nonwords": false }],
153 | "spaced-comment": [2, "always"],
154 | "strict": 0,
155 | "use-isnan": 2,
156 | "valid-jsdoc": 0,
157 | "valid-typeof": 2,
158 | "vars-on-top": 0,
159 | "wrap-iife": [2, "any"],
160 | "wrap-regex": 0,
161 | "yoda": [2, "never"]
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | npm-debug.log
4 | .idea/*
5 | Thumbs.db
6 | .project
7 | coverage/
8 | screenshots/
9 | reports/
10 | build/
11 | dist/
12 | *.sw*
13 | *.un~
14 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .travis.yml
3 | .eslintrc
4 | .eslintignore
5 | coverage/
6 | screenshots/
7 | reports/
8 | assets/
9 | *.sw*
10 | *.un~
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | sudo: false
3 | node_js:
4 | - 12
5 | addons:
6 | apt:
7 | packages:
8 | - xvfb
9 | - libgconf-2-4
10 | install:
11 | - export DISPLAY=':99.0'
12 | - Xvfb :99 -screen 0 1366x768x24 > /dev/null 2>&1 &
13 | script:
14 | - npm i
15 | - npm run ci
16 | after_script:
17 | - npm i codecov && codecov
18 |
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 zhuyali
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | 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, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # d3-tree
2 |
3 | [![NPM version][npm-image]][npm-url]
4 | [![build status][travis-image]][travis-url]
5 | [![Test coverage][coveralls-image]][coveralls-url]
6 | [![node version][node-image]][node-url]
7 | [![npm download][download-image]][download-url]
8 |
9 | [npm-image]: https://img.shields.io/npm/v/d3-tree.svg
10 | [npm-url]: https://npmjs.org/package/d3-tree
11 | [travis-image]: https://img.shields.io/travis/zhuyali/d3-tree.svg
12 | [travis-url]: https://travis-ci.org/zhuyali/d3-tree
13 | [coveralls-image]: https://img.shields.io/coveralls/zhuyali/d3-tree.svg
14 | [coveralls-url]: https://coveralls.io/r/zhuyali/d3-tree?branch=master
15 | [node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg
16 | [node-url]: http://nodejs.org/download/
17 | [download-image]: https://img.shields.io/npm/dm/d3-tree.svg
18 | [download-url]: https://npmjs.org/package/d3-tree
19 |
20 | > tree view based on d3
21 |
22 | ## Installment
23 |
24 | ```bash
25 | $ npm i d3-tree --save-dev
26 | ```
27 |
28 |
29 |
30 | ## Contributors
31 |
32 | |[
xudafeng](https://github.com/xudafeng)
|[
zhuyali](https://github.com/zhuyali)
|[
zivyangll](https://github.com/zivyangll)
|[
SamuelZhaoY](https://github.com/SamuelZhaoY)
|
33 | | :---: | :---: | :---: | :---: |
34 |
35 |
36 | This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sat Jul 03 2021 23:20:45 GMT+0800`.
37 |
38 |
39 |
40 | ## License
41 |
42 | The MIT License (MIT)
43 |
--------------------------------------------------------------------------------
/assets/page.css:
--------------------------------------------------------------------------------
1 | body, html {
2 | overflow: hidden;
3 | }
4 |
5 | .d3-tree-node {
6 | fill: #fff;
7 | font-weight: normal;
8 | font-size: 14px;
9 | font-family: Lato,Helvetica Neue For Number,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;
10 | }
11 |
12 | .d3-tree-link {
13 | fill: none;
14 | stroke: #000;
15 | }
16 |
17 | #container svg {
18 | background: #fff;
19 | }
20 |
--------------------------------------------------------------------------------
/assets/page.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const D3Tree = require('../lib/d3-tree');
4 |
5 | const testImg = "https://avatars2.githubusercontent.com/u/9263023?s=200&v=4";
6 | const testImg2 = `[
7 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
8 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
9 | ]`
10 | const testImg3 = `[
11 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
12 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
13 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
14 | ]`
15 | const testImg4 = `[
16 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
17 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
18 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
19 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
20 | ]`
21 | const testImg5 = `[
22 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
23 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
24 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
25 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
26 | https://avatars2.githubusercontent.com/u/9263023?s=200&v=4
27 | ]`
28 | let data = {
29 | data: {
30 | image: testImg5,
31 | text: 'five images',
32 | },
33 | children: [{
34 | data: {
35 | image: testImg,
36 | text: null,
37 | },
38 | children: [{
39 | data: {
40 | image: testImg4,
41 | text: 'multi\nline中文\n中文中文中文中文\nmulti\nline中文\nline中文',
42 | },
43 | children: []
44 | }, {
45 | data: {
46 | image: testImg2,
47 | text: 'two images',
48 | },
49 | children: []
50 | }]
51 | }, {
52 | data: {
53 | image: null,
54 | text: 'test12',
55 | },
56 | children: []
57 | }, {
58 | data: {
59 | image: testImg3,
60 | text: 'three images',
61 | },
62 | children: []
63 | }]
64 | };
65 |
66 | var d3tree = window.d3tree = new D3Tree({
67 | selector: '#container',
68 | data: data,
69 | width: window.innerWidth,
70 | height: window.innerHeight,
71 | duration: 1000
72 | });
73 |
74 | d3tree.init();
75 |
76 | document.querySelector('#append').addEventListener('click', () => {
77 | data.children.push({
78 | image: testImg,
79 | text: 'new',
80 | children: []
81 | });
82 | data.children[0].children.push({
83 | image: testImg,
84 | text: 'new',
85 | children: []
86 | });
87 | d3tree.update(data);
88 | }, false);
89 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |