vislite 1.2.1-alpha.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +283 -279
- package/README.md +197 -175
- package/lib/Buffer/index.es.js +1 -1
- package/lib/Buffer/index.es.min.js +1 -1
- package/lib/Canvas/index.es.js +1 -1
- package/lib/Canvas/index.es.min.js +1 -1
- package/lib/Cardinal/index.es.js +1 -1
- package/lib/Cardinal/index.es.min.js +1 -1
- package/lib/Eoap/index.es.js +1 -1
- package/lib/Eoap/index.es.min.js +1 -1
- package/lib/Hermite/index.es.js +1 -1
- package/lib/Hermite/index.es.min.js +1 -1
- package/lib/Matrix4/index.es.js +1 -1
- package/lib/Matrix4/index.es.min.js +1 -1
- package/lib/Mercator/index.es.js +1 -1
- package/lib/Mercator/index.es.min.js +1 -1
- package/lib/RawCanvas/index.es.js +1 -1
- package/lib/RawCanvas/index.es.min.js +1 -1
- package/lib/SVG/index.es.js +1 -1
- package/lib/SVG/index.es.min.js +1 -1
- package/lib/Shader/index.es.js +1 -1
- package/lib/Shader/index.es.min.js +1 -1
- package/lib/Texture/index.es.js +1 -1
- package/lib/Texture/index.es.min.js +1 -1
- package/lib/TreeLayout/index.es.js +6 -1
- package/lib/TreeLayout/index.es.min.js +2 -2
- package/lib/animation/index.es.js +1 -1
- package/lib/animation/index.es.min.js +1 -1
- package/lib/assemble/index.es.js +1 -1
- package/lib/assemble/index.es.min.js +1 -1
- package/lib/getLoopColors/index.es.js +1 -1
- package/lib/getLoopColors/index.es.min.js +1 -1
- package/lib/getWebGLContext/index.es.js +1 -1
- package/lib/getWebGLContext/index.es.min.js +1 -1
- package/lib/index.umd.js +6 -1
- package/lib/index.umd.min.js +2 -2
- package/lib/initOption/index.es.js +1 -1
- package/lib/initOption/index.es.min.js +1 -1
- package/lib/mergeOption/index.es.js +1 -1
- package/lib/mergeOption/index.es.min.js +1 -1
- package/lib/move/index.es.js +1 -1
- package/lib/move/index.es.min.js +1 -1
- package/lib/rotate/index.es.js +1 -1
- package/lib/rotate/index.es.min.js +1 -1
- package/lib/ruler/index.es.js +1 -1
- package/lib/ruler/index.es.min.js +1 -1
- package/lib/scale/index.es.js +1 -1
- package/lib/scale/index.es.min.js +1 -1
- package/lib/throttle/index.es.js +1 -1
- package/lib/throttle/index.es.min.js +1 -1
- package/package/animation/index.ts +1 -1
- package/package/throttle/index.ts +1 -1
- package/package.json +4 -5
- package/src/common/canvas/default.ts +2 -2
- package/src/common/canvas/gradient.ts +1 -1
- package/src/common/canvas/painter.ts +2 -2
- package/src/common/svg/gradient.ts +1 -1
- package/src/common/tree/toInnerTree.ts +61 -59
- package/src/common/type.ts +1 -1
- package/src/layout/TreeLayout.ts +194 -188
- package/types/Tree.d.ts +74 -69
- package/types/TreeLayout.d.ts +59 -54
- package/types/animation.d.ts +1 -1
- package/types/throttle.d.ts +1 -1
- package/types/throttleOption.d.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* throttle of VISLite JavaScript Library v1.2.1
|
|
2
|
+
* throttle of VISLite JavaScript Library v1.2.1
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*/
|
|
5
5
|
function t(t,e){var n={time:200,keep:!1,opportunity:"end"};if(e)for(var p in e)n[p]=e[p];var r,i=!1,o=!1,a=!1;return function(){const e=this;if(r=arguments,i)o=!0,a=!0;else{"end"!=n.opportunity&&t.apply(e,r),i=!0;var p=setInterval((()=>{o?n.keep||t.apply(e,r):("begin"!=n.opportunity&&(a||"end"==n.opportunity)&&t.apply(e,r),i=!1,a=!1,clearInterval(p)),o=!1}),n.time)}}}export{t as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vislite",
|
|
3
|
-
"version": "1.2.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "灵活、快速、简单的数据可视化交互式跨端前端库",
|
|
5
5
|
"main": "./lib/index.umd.min.js",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"jsdelivr": "./lib/index.umd.min.js",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"scripts": {
|
|
11
|
-
"init": "npm install &&
|
|
11
|
+
"init": "npm install && oipage-cli --copy ./node_modules/pageby/dist/pageby.min.js ./docs/js/min/pageby.min.js",
|
|
12
12
|
"dev": "webpack serve --config ./build/webpack.config.js",
|
|
13
|
-
"build": "
|
|
13
|
+
"build": "oipage-cli --delete ./lib && node ./build/pkg.js",
|
|
14
14
|
"test": "karma start ./build/karma.config.js",
|
|
15
15
|
"lint": "eslint src/**/*.ts --fix"
|
|
16
16
|
},
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"@types/jasmine": "^4.3.1",
|
|
57
57
|
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
58
58
|
"@typescript-eslint/parser": "^6.14.0",
|
|
59
|
-
"devby": "^0.4.6",
|
|
60
59
|
"eslint": "^8.56.0",
|
|
61
60
|
"karma": "^6.3.10",
|
|
62
61
|
"karma-chrome-launcher": "^3.1.0",
|
|
@@ -73,6 +72,6 @@
|
|
|
73
72
|
"webpack-dev-server": "^4.7.4"
|
|
74
73
|
},
|
|
75
74
|
"dependencies": {
|
|
76
|
-
"
|
|
75
|
+
"oipage": "^0.1.0"
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -2,7 +2,7 @@ import type { arcCapType } from '../../../types/painterConfig'
|
|
|
2
2
|
|
|
3
3
|
export default function (type?: string) {
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const special = {
|
|
6
6
|
// 文字大小
|
|
7
7
|
"fontSize": 16,
|
|
8
8
|
|
|
@@ -22,7 +22,7 @@ export default function (type?: string) {
|
|
|
22
22
|
"arcEndCap": <arcCapType>'butt'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const init = {
|
|
26
26
|
// 填充色或图案
|
|
27
27
|
"fillStyle": 'black',
|
|
28
28
|
|
|
@@ -411,13 +411,13 @@ class Painter {
|
|
|
411
411
|
install(methods: {
|
|
412
412
|
[key: string]: Function
|
|
413
413
|
}): any {
|
|
414
|
-
for (
|
|
414
|
+
for (const key in methods) {
|
|
415
415
|
|
|
416
416
|
if (key in this) {
|
|
417
417
|
throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.")
|
|
418
418
|
} else {
|
|
419
419
|
(this as any)[key] = (...args: any) => {
|
|
420
|
-
|
|
420
|
+
const value = methods[key].apply(this, args)
|
|
421
421
|
if (value != void 0) return value
|
|
422
422
|
return this
|
|
423
423
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { initDefs } from './config'
|
|
2
2
|
import { toNode, setAttribute } from "./tool"
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const enhanceGradient = function (gradient: SVGElement, gradientId: string) {
|
|
5
5
|
const enhanceGradient = {
|
|
6
6
|
"value": function () {
|
|
7
7
|
return "url(#" + gradientId + ")";
|
|
@@ -1,60 +1,62 @@
|
|
|
1
|
-
import type { default as TreeConfigType, rootType, childrenType, idType } from '../../../types/TreeConfig'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 根据配置的层次关系(配置的id,child,root)把原始数据变成内部结构,方便后期位置计算
|
|
5
|
-
*
|
|
6
|
-
* tempTree[id] = {
|
|
7
|
-
* "data": 原始数据,
|
|
8
|
-
* "pid": 父亲ID,
|
|
9
|
-
* "id": 唯一标识ID,
|
|
10
|
-
* "show": boolean,
|
|
11
|
-
* "isOpen": boolean,
|
|
12
|
-
* "children": [cid1、cid2、...]
|
|
13
|
-
* }
|
|
14
|
-
*/
|
|
15
|
-
export default (initTree: any, config: TreeConfigType) => {
|
|
16
|
-
const tempTree: {
|
|
17
|
-
[key: string]: any
|
|
18
|
-
} = {}
|
|
19
|
-
|
|
20
|
-
// 根结点
|
|
21
|
-
const temp = (config.root as rootType)(initTree)
|
|
22
|
-
let id: number | string, rid: number | string
|
|
23
|
-
id = rid = (config.id as idType)(temp)
|
|
24
|
-
tempTree[id] = {
|
|
25
|
-
"data": temp,
|
|
26
|
-
"pid": null,
|
|
27
|
-
"id": id,
|
|
28
|
-
"isOpen": true,
|
|
29
|
-
"show": true,
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
tempTree[id
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import type { default as TreeConfigType, rootType, childrenType, idType } from '../../../types/TreeConfig'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 根据配置的层次关系(配置的id,child,root)把原始数据变成内部结构,方便后期位置计算
|
|
5
|
+
*
|
|
6
|
+
* tempTree[id] = {
|
|
7
|
+
* "data": 原始数据,
|
|
8
|
+
* "pid": 父亲ID,
|
|
9
|
+
* "id": 唯一标识ID,
|
|
10
|
+
* "show": boolean,
|
|
11
|
+
* "isOpen": boolean,
|
|
12
|
+
* "children": [cid1、cid2、...]
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export default (initTree: any, config: TreeConfigType) => {
|
|
16
|
+
const tempTree: {
|
|
17
|
+
[key: string]: any
|
|
18
|
+
} = {}
|
|
19
|
+
|
|
20
|
+
// 根结点
|
|
21
|
+
const temp = (config.root as rootType)(initTree)
|
|
22
|
+
let id: number | string, rid: number | string
|
|
23
|
+
id = rid = (config.id as idType)(temp)
|
|
24
|
+
tempTree[id] = {
|
|
25
|
+
"data": temp,
|
|
26
|
+
"pid": null,
|
|
27
|
+
"id": id,
|
|
28
|
+
"isOpen": true,
|
|
29
|
+
"show": true,
|
|
30
|
+
"deg": 0,
|
|
31
|
+
"children": []
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let num: number = 1
|
|
35
|
+
|
|
36
|
+
// 根据传递的原始数据,生成内部统一结构
|
|
37
|
+
; (function createTree(pdata: any, pid: number | string) {
|
|
38
|
+
const children = (config.children as childrenType)(pdata, initTree)
|
|
39
|
+
num += children ? children.length : 0
|
|
40
|
+
for (let flag = 0; children && flag < children.length; flag++) {
|
|
41
|
+
id = (config.id as idType)(children[flag])
|
|
42
|
+
tempTree[pid].children.push(id);
|
|
43
|
+
tempTree[id] = {
|
|
44
|
+
"data": children[flag],
|
|
45
|
+
"pid": pid,
|
|
46
|
+
"id": id,
|
|
47
|
+
"isOpen": true,
|
|
48
|
+
"show": true,
|
|
49
|
+
"deg": 0,
|
|
50
|
+
"children": []
|
|
51
|
+
}
|
|
52
|
+
createTree(children[flag], id)
|
|
53
|
+
}
|
|
54
|
+
})(temp, id)
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
rid,
|
|
58
|
+
value: tempTree,
|
|
59
|
+
num
|
|
60
|
+
}
|
|
61
|
+
|
|
60
62
|
}
|
package/src/common/type.ts
CHANGED
package/src/layout/TreeLayout.ts
CHANGED
|
@@ -1,189 +1,195 @@
|
|
|
1
|
-
import type TreeLayoutType from '../../types/TreeLayout'
|
|
2
|
-
import type { TreeResultType } from '../../types/Tree'
|
|
3
|
-
import type TreeOptionType from '../../types/TreeOption'
|
|
4
|
-
|
|
5
|
-
import Tree from '../common/tree/index'
|
|
6
|
-
import { initOption } from '../common/option'
|
|
7
|
-
import { animation } from "
|
|
8
|
-
import rotate from '../rotate'
|
|
9
|
-
|
|
10
|
-
class TreeLayout extends Tree implements TreeLayoutType {
|
|
11
|
-
readonly name: string = 'TreeLayout'
|
|
12
|
-
|
|
13
|
-
private __option = {
|
|
14
|
-
offsetX: 0,
|
|
15
|
-
offsetY: 0,
|
|
16
|
-
duration: 500,
|
|
17
|
-
type: "plain",
|
|
18
|
-
direction: "LR",
|
|
19
|
-
x: 100,
|
|
20
|
-
y: 100,
|
|
21
|
-
width: 100,
|
|
22
|
-
height: 100,
|
|
23
|
-
radius: 100
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private __rback: (tree: TreeResultType) => void
|
|
27
|
-
private __oralTree: any
|
|
28
|
-
private __preTree: TreeResultType | null
|
|
29
|
-
|
|
30
|
-
private __noOpens = {}
|
|
31
|
-
|
|
32
|
-
setOption(option: TreeOptionType) {
|
|
33
|
-
initOption(option, this.__option)
|
|
34
|
-
return this
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
use(initTree: any, noOpens = {}) {
|
|
38
|
-
const tree = super.use(initTree, noOpens)
|
|
39
|
-
|
|
40
|
-
// 校对偏差
|
|
41
|
-
if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
|
|
42
|
-
for (const key in tree.node) {
|
|
43
|
-
if (!tree.node[key].show) {
|
|
44
|
-
|
|
45
|
-
let deep = 0, pid = key
|
|
46
|
-
do {
|
|
47
|
-
pid = tree.node[pid].pid
|
|
48
|
-
deep++
|
|
49
|
-
} while (!tree.node[pid].show)
|
|
50
|
-
|
|
51
|
-
tree.node[key].left += this.__option.offsetX * deep
|
|
52
|
-
tree.node[key].top += this.__option.offsetY * deep
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (this.__option.type == 'rect') {
|
|
58
|
-
if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
|
|
59
|
-
|
|
60
|
-
const perW = this.__option.height / tree.size
|
|
61
|
-
const perD = this.__option.width / (tree.deep - 1)
|
|
62
|
-
|
|
63
|
-
const balanceW = this.__option.y - this.__option.height * 0.5
|
|
64
|
-
const flag = this.__option.direction == 'LR' ? 1 : -1
|
|
65
|
-
|
|
66
|
-
for (const key in tree.node) {
|
|
67
|
-
if (tree.deep == 1) {
|
|
68
|
-
tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag
|
|
69
|
-
tree.node[key].top = this.__option.y
|
|
70
|
-
} else {
|
|
71
|
-
tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag
|
|
72
|
-
tree.node[key].top = tree.node[key].top * perW + balanceW
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
|
|
76
|
-
|
|
77
|
-
const perW = this.__option.width / tree.size
|
|
78
|
-
const perD = this.__option.height / (tree.deep - 1)
|
|
79
|
-
|
|
80
|
-
const balanceW = this.__option.x - this.__option.width * 0.5
|
|
81
|
-
const flag = this.__option.direction == 'TB' ? 1 : -1
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
tree.node[key].
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
tree.node[key].top
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
1
|
+
import type TreeLayoutType from '../../types/TreeLayout'
|
|
2
|
+
import type { TreeResultType } from '../../types/Tree'
|
|
3
|
+
import type TreeOptionType from '../../types/TreeOption'
|
|
4
|
+
|
|
5
|
+
import Tree from '../common/tree/index'
|
|
6
|
+
import { initOption } from '../common/option'
|
|
7
|
+
import { animation } from "oipage/corejs/animation/index"
|
|
8
|
+
import rotate from '../rotate'
|
|
9
|
+
|
|
10
|
+
class TreeLayout extends Tree implements TreeLayoutType {
|
|
11
|
+
readonly name: string = 'TreeLayout'
|
|
12
|
+
|
|
13
|
+
private __option = {
|
|
14
|
+
offsetX: 0,
|
|
15
|
+
offsetY: 0,
|
|
16
|
+
duration: 500,
|
|
17
|
+
type: "plain",
|
|
18
|
+
direction: "LR",
|
|
19
|
+
x: 100,
|
|
20
|
+
y: 100,
|
|
21
|
+
width: 100,
|
|
22
|
+
height: 100,
|
|
23
|
+
radius: 100
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private __rback: (tree: TreeResultType) => void
|
|
27
|
+
private __oralTree: any
|
|
28
|
+
private __preTree: TreeResultType | null
|
|
29
|
+
|
|
30
|
+
private __noOpens = {}
|
|
31
|
+
|
|
32
|
+
setOption(option: TreeOptionType) {
|
|
33
|
+
initOption(option, this.__option)
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
use(initTree: any, noOpens = {}) {
|
|
38
|
+
const tree = super.use(initTree, noOpens)
|
|
39
|
+
|
|
40
|
+
// 校对偏差
|
|
41
|
+
if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
|
|
42
|
+
for (const key in tree.node) {
|
|
43
|
+
if (!tree.node[key].show) {
|
|
44
|
+
|
|
45
|
+
let deep = 0, pid = key
|
|
46
|
+
do {
|
|
47
|
+
pid = tree.node[pid].pid
|
|
48
|
+
deep++
|
|
49
|
+
} while (!tree.node[pid].show)
|
|
50
|
+
|
|
51
|
+
tree.node[key].left += this.__option.offsetX * deep
|
|
52
|
+
tree.node[key].top += this.__option.offsetY * deep
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.__option.type == 'rect') {
|
|
58
|
+
if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
|
|
59
|
+
|
|
60
|
+
const perW = this.__option.height / tree.size
|
|
61
|
+
const perD = this.__option.width / (tree.deep - 1)
|
|
62
|
+
|
|
63
|
+
const balanceW = this.__option.y - this.__option.height * 0.5
|
|
64
|
+
const flag = this.__option.direction == 'LR' ? 1 : -1
|
|
65
|
+
|
|
66
|
+
for (const key in tree.node) {
|
|
67
|
+
if (tree.deep == 1) {
|
|
68
|
+
tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag
|
|
69
|
+
tree.node[key].top = this.__option.y
|
|
70
|
+
} else {
|
|
71
|
+
tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag
|
|
72
|
+
tree.node[key].top = tree.node[key].top * perW + balanceW
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
|
|
76
|
+
|
|
77
|
+
const perW = this.__option.width / tree.size
|
|
78
|
+
const perD = this.__option.height / (tree.deep - 1)
|
|
79
|
+
|
|
80
|
+
const balanceW = this.__option.x - this.__option.width * 0.5
|
|
81
|
+
const flag = this.__option.direction == 'TB' ? 1 : -1
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
for (const key in tree.node) {
|
|
86
|
+
tree.node[key].deg = this.__option.direction == 'TB' ? Math.PI * 0.5 : Math.PI * -0.5
|
|
87
|
+
|
|
88
|
+
if (tree.deep == 1) {
|
|
89
|
+
tree.node[key].left = this.__option.x
|
|
90
|
+
tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag
|
|
91
|
+
} else {
|
|
92
|
+
const left = tree.node[key].left
|
|
93
|
+
tree.node[key].left = tree.node[key].top * perW + balanceW
|
|
94
|
+
tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
} else if (this.__option.type == 'circle') {
|
|
101
|
+
const cx = this.__option.x, cy = this.__option.y
|
|
102
|
+
const deg = Math.PI * 2 / tree.size
|
|
103
|
+
const per = this.__option.radius / (tree.deep - 1)
|
|
104
|
+
|
|
105
|
+
for (const key in tree.node) {
|
|
106
|
+
if (tree.node[key].left == 0.5) {
|
|
107
|
+
tree.node[key].left = cx
|
|
108
|
+
tree.node[key].top = cy
|
|
109
|
+
} else {
|
|
110
|
+
const position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy)
|
|
111
|
+
|
|
112
|
+
tree.node[key].deg = deg * tree.node[key].top
|
|
113
|
+
tree.node[key].left = position[0]
|
|
114
|
+
tree.node[key].top = position[1]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return tree
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
bind(initTree: any, renderBack: (tree: TreeResultType) => void, noOpens = {}) {
|
|
123
|
+
this.__rback = renderBack
|
|
124
|
+
this.__oralTree = initTree
|
|
125
|
+
this.__noOpens = noOpens
|
|
126
|
+
|
|
127
|
+
this.__preTree = this.use(this.__oralTree, this.__noOpens)
|
|
128
|
+
this.__rback(this.__preTree)
|
|
129
|
+
|
|
130
|
+
return this
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
unbind() {
|
|
134
|
+
this.__rback = () => null
|
|
135
|
+
this.__oralTree = null
|
|
136
|
+
this.__preTree = null
|
|
137
|
+
this.__noOpens = {}
|
|
138
|
+
return this
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
doUpdate() {
|
|
142
|
+
const newTree = this.use(this.__oralTree, this.__noOpens)
|
|
143
|
+
|
|
144
|
+
const cacheTree = JSON.parse(JSON.stringify(newTree))
|
|
145
|
+
|
|
146
|
+
animation((deep) => {
|
|
147
|
+
|
|
148
|
+
if (this.__preTree) {
|
|
149
|
+
for (const key in cacheTree.node) {
|
|
150
|
+
if (newTree.node[key].show || this.__preTree.node[key].show) {
|
|
151
|
+
cacheTree.node[key].show = true
|
|
152
|
+
|
|
153
|
+
cacheTree.node[key].left = this.__preTree.node[key].left + (newTree.node[key].left - this.__preTree.node[key].left) * deep
|
|
154
|
+
cacheTree.node[key].top = this.__preTree.node[key].top + (newTree.node[key].top - this.__preTree.node[key].top) * deep
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
this.__rback(cacheTree)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
}, this.__option.duration, () => {
|
|
162
|
+
this.__preTree = newTree
|
|
163
|
+
this.__rback(this.__preTree)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
return this
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
closeNode(id: string) {
|
|
170
|
+
if (!this.__preTree) return this
|
|
171
|
+
this.__noOpens[id] = true
|
|
172
|
+
|
|
173
|
+
this.doUpdate()
|
|
174
|
+
return this
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
openNode(id: string) {
|
|
178
|
+
if (!this.__preTree) return this
|
|
179
|
+
this.__noOpens[id] = false
|
|
180
|
+
|
|
181
|
+
this.doUpdate()
|
|
182
|
+
return this
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
toggleNode(id: string) {
|
|
186
|
+
if (!this.__preTree) return this
|
|
187
|
+
this.__noOpens[id] = !this.__noOpens[id]
|
|
188
|
+
|
|
189
|
+
this.doUpdate()
|
|
190
|
+
return this
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
189
195
|
export default TreeLayout
|