vislite 0.6.0 → 0.7.0-alpha.0
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 +9 -0
- package/README.md +4 -4
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +2 -2
- package/lib/Canvas/index.umd.min.js +2 -2
- package/lib/Cardinal/index.umd.js +2 -2
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +2 -2
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Geometry/index.umd.js +2 -2
- package/lib/Geometry/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +2 -2
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +2 -2
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +2 -2
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +2 -2
- package/lib/OralCanvas/index.es.min.js +2 -2
- package/lib/OralWebGL/index.es.js +2 -2
- package/lib/OralWebGL/index.es.min.js +2 -2
- package/lib/SVG/index.umd.js +2 -2
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +2 -2
- package/lib/Shader/index.umd.min.js +2 -2
- package/lib/Texture/index.umd.js +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +2 -2
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +2 -2
- package/lib/WebGL/index.umd.min.js +2 -2
- package/lib/animation/index.umd.js +2 -2
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +2 -2
- package/lib/formatColor/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +2 -2
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +2 -2
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +2 -2
- package/lib/index.umd.min.js +2 -2
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +2 -2
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +2 -2
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +2 -2
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +2 -2
- package/lib/throttle/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package.json +1 -1
- package/src/Canvas.ts +70 -70
- package/src/Eoap.ts +66 -66
- package/src/Geometry.ts +82 -82
- package/src/Matrix4/index.ts +84 -84
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/transform.ts +64 -64
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +24 -24
- package/src/WebGL.ts +66 -66
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +51 -51
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +29 -29
- package/src/common/canvas/index.ts +177 -177
- package/src/common/canvas/painter.ts +417 -417
- package/src/common/geometry/prism-horizontal.ts +35 -35
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/sphere-fragment.ts +40 -40
- package/src/common/geometry/tool/circle.ts +11 -11
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +186 -186
- package/src/common/svg/gradient.ts +63 -63
- package/src/common/svg/index.ts +5 -5
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/toInnerTree.ts +57 -57
- package/src/common/tree/toPlainTree.ts +132 -132
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/doDraw.ts +108 -108
- package/src/common/webgl/getColorFactory.ts +26 -26
- package/src/common/webgl/getShader.ts +48 -48
- package/src/common/webgl/getTexture.ts +11 -11
- package/src/common/webgl/getWebGLContext.ts +28 -28
- package/src/common/webgl/index.ts +224 -224
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- package/src/formatColor.ts +44 -44
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/layout/TreeLayout.ts +186 -186
- package/src/move.ts +7 -7
- package/src/resizeObserver.ts +37 -37
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +209 -209
- package/src/throttle.ts +52 -52
- package/src/viewHandler.ts +158 -158
- package/types/Canvas.d.ts +308 -308
- package/types/CanvasOption.d.ts +8 -8
- package/types/CanvasOpts.d.ts +9 -9
- package/types/Matrix4.d.ts +47 -47
- package/types/SVGConfig.d.ts +79 -76
- package/uni-app/ui-canvas.vue +9 -31
- package/.editorconfig +0 -19
- package/.eslintrc.js +0 -26
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { initDefs } from './config'
|
|
2
|
-
import { toNode, setAttribute } from "./tool"
|
|
3
|
-
|
|
4
|
-
// 线性渐变
|
|
5
|
-
export const linearGradient = function (el: SVGElement, x0: number, y0: number, x1: number, y1: number) {
|
|
6
|
-
|
|
7
|
-
const defs = initDefs(el)
|
|
8
|
-
const gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random()
|
|
9
|
-
|
|
10
|
-
const linearGradient = toNode("linearGradient")
|
|
11
|
-
defs.appendChild(linearGradient)
|
|
12
|
-
setAttribute(linearGradient, "id", gradientId)
|
|
13
|
-
setAttribute(linearGradient, "x1", x0 + "%")
|
|
14
|
-
setAttribute(linearGradient, "y1", y0 + "%")
|
|
15
|
-
setAttribute(linearGradient, "x2", x1 + "%")
|
|
16
|
-
setAttribute(linearGradient, "y2", y1 + "%")
|
|
17
|
-
|
|
18
|
-
const enhanceGradient = {
|
|
19
|
-
"value": function () {
|
|
20
|
-
return "url(#" + gradientId + ")";
|
|
21
|
-
},
|
|
22
|
-
"setColor": function (stop: number, color: string) {
|
|
23
|
-
|
|
24
|
-
const stopEl = toNode("stop")
|
|
25
|
-
linearGradient.appendChild(stopEl)
|
|
26
|
-
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
27
|
-
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
28
|
-
|
|
29
|
-
return enhanceGradient
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return enhanceGradient
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 环形渐变
|
|
36
|
-
export const radialGradient = function (el: SVGElement, cx: number, cy: number, r: number) {
|
|
37
|
-
|
|
38
|
-
const defs = initDefs(el)
|
|
39
|
-
const gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random()
|
|
40
|
-
|
|
41
|
-
const radialGradient = toNode("radialGradient")
|
|
42
|
-
defs.appendChild(radialGradient)
|
|
43
|
-
setAttribute(radialGradient, "id", gradientId)
|
|
44
|
-
setAttribute(radialGradient, "cx", cx + "%")
|
|
45
|
-
setAttribute(radialGradient, "cy", cy + "%")
|
|
46
|
-
setAttribute(radialGradient, "r", r + "%")
|
|
47
|
-
|
|
48
|
-
const enhanceGradient = {
|
|
49
|
-
"value": function () {
|
|
50
|
-
return "url(#" + gradientId + ")";
|
|
51
|
-
},
|
|
52
|
-
"setColor": function (stop: number, color: string) {
|
|
53
|
-
|
|
54
|
-
const stopEl = toNode("stop")
|
|
55
|
-
radialGradient.appendChild(stopEl)
|
|
56
|
-
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
57
|
-
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
58
|
-
|
|
59
|
-
return enhanceGradient
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return enhanceGradient
|
|
63
|
-
}
|
|
1
|
+
import { initDefs } from './config'
|
|
2
|
+
import { toNode, setAttribute } from "./tool"
|
|
3
|
+
|
|
4
|
+
// 线性渐变
|
|
5
|
+
export const linearGradient = function (el: SVGElement, x0: number, y0: number, x1: number, y1: number) {
|
|
6
|
+
|
|
7
|
+
const defs = initDefs(el)
|
|
8
|
+
const gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random()
|
|
9
|
+
|
|
10
|
+
const linearGradient = toNode("linearGradient")
|
|
11
|
+
defs.appendChild(linearGradient)
|
|
12
|
+
setAttribute(linearGradient, "id", gradientId)
|
|
13
|
+
setAttribute(linearGradient, "x1", x0 + "%")
|
|
14
|
+
setAttribute(linearGradient, "y1", y0 + "%")
|
|
15
|
+
setAttribute(linearGradient, "x2", x1 + "%")
|
|
16
|
+
setAttribute(linearGradient, "y2", y1 + "%")
|
|
17
|
+
|
|
18
|
+
const enhanceGradient = {
|
|
19
|
+
"value": function () {
|
|
20
|
+
return "url(#" + gradientId + ")";
|
|
21
|
+
},
|
|
22
|
+
"setColor": function (stop: number, color: string) {
|
|
23
|
+
|
|
24
|
+
const stopEl = toNode("stop")
|
|
25
|
+
linearGradient.appendChild(stopEl)
|
|
26
|
+
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
27
|
+
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
28
|
+
|
|
29
|
+
return enhanceGradient
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return enhanceGradient
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 环形渐变
|
|
36
|
+
export const radialGradient = function (el: SVGElement, cx: number, cy: number, r: number) {
|
|
37
|
+
|
|
38
|
+
const defs = initDefs(el)
|
|
39
|
+
const gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random()
|
|
40
|
+
|
|
41
|
+
const radialGradient = toNode("radialGradient")
|
|
42
|
+
defs.appendChild(radialGradient)
|
|
43
|
+
setAttribute(radialGradient, "id", gradientId)
|
|
44
|
+
setAttribute(radialGradient, "cx", cx + "%")
|
|
45
|
+
setAttribute(radialGradient, "cy", cy + "%")
|
|
46
|
+
setAttribute(radialGradient, "r", r + "%")
|
|
47
|
+
|
|
48
|
+
const enhanceGradient = {
|
|
49
|
+
"value": function () {
|
|
50
|
+
return "url(#" + gradientId + ")";
|
|
51
|
+
},
|
|
52
|
+
"setColor": function (stop: number, color: string) {
|
|
53
|
+
|
|
54
|
+
const stopEl = toNode("stop")
|
|
55
|
+
radialGradient.appendChild(stopEl)
|
|
56
|
+
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
57
|
+
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
58
|
+
|
|
59
|
+
return enhanceGradient
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return enhanceGradient
|
|
63
|
+
}
|
package/src/common/svg/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type SVGConfigType from "../../../types/SVGConfig"
|
|
1
|
+
import type { default as SVGConfigType, svgElType, svgBoardType } from "../../../types/SVGConfig"
|
|
2
2
|
import type { arcCapType, textAlignType, textBaselineType } from "../../../types/painterConfig"
|
|
3
3
|
|
|
4
4
|
import { initText, initCircle, initPath, initRect, initArc } from "./config"
|
|
@@ -86,7 +86,7 @@ class SVG {
|
|
|
86
86
|
// el可以是结点或字符串,字符串的话表示节点名称
|
|
87
87
|
// context可选,表示追加位置,可选,默认根svg
|
|
88
88
|
// 此外,和appendBoard等操作一样,执行后新加入的结点会自动变成应用节点
|
|
89
|
-
appendEl(el:
|
|
89
|
+
appendEl(el: svgElType, context?: SVGElement) {
|
|
90
90
|
context = context || this.__svg
|
|
91
91
|
|
|
92
92
|
if (typeof el == "string") el = toNode(el)
|
|
@@ -99,8 +99,8 @@ class SVG {
|
|
|
99
99
|
// 追加绘制板
|
|
100
100
|
// 参数和appendEl类似,只是el如果是字符串的话,表示需要绘制对应什么内容,
|
|
101
101
|
// 比如el = “arc”,表示画弧(不是路径arc),那么我们会创建path节点,因为我们是使用path实现的
|
|
102
|
-
appendBoard(el:
|
|
103
|
-
let _el = el
|
|
102
|
+
appendBoard(el: svgBoardType, context?: SVGElement) {
|
|
103
|
+
let _el: svgBoardType | string = el
|
|
104
104
|
|
|
105
105
|
if (typeof el == "string")
|
|
106
106
|
_el =
|
|
@@ -113,7 +113,7 @@ class SVG {
|
|
|
113
113
|
}[el] || ""
|
|
114
114
|
|
|
115
115
|
if (_el == "") throw new Error("Unsupported drawing method:" + el)
|
|
116
|
-
return this.appendEl(_el, context)
|
|
116
|
+
return this.appendEl(_el as svgElType, context)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
// 删除当前维护的节点
|
package/src/common/svg/tool.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import type SVGConfigType from '../../../types/SVGConfig'
|
|
2
|
-
|
|
3
|
-
import { XLINK_ATTRIBUTE } from "./dictionary"
|
|
4
|
-
|
|
5
|
-
// 新建节点
|
|
6
|
-
export function toNode(tagname: string) {
|
|
7
|
-
return document.createElementNS('http://www.w3.org/2000/svg', tagname)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// 设置属性
|
|
11
|
-
const _setAttribute = function (el: SVGElement, key: string, value: string | number) {
|
|
12
|
-
|
|
13
|
-
// 需要使用xlink命名空间的xml属性
|
|
14
|
-
if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
|
|
15
|
-
el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "")
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 否则
|
|
19
|
-
else {
|
|
20
|
-
el.setAttribute(key, value + "")
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export const setAttribute = _setAttribute
|
|
24
|
-
|
|
25
|
-
// 获取属性
|
|
26
|
-
export function getAttribute(el: SVGElement, key: string) {
|
|
27
|
-
if (XLINK_ATTRIBUTE.indexOf(key) > -1) key = 'xlink:' + key
|
|
28
|
-
return el.getAttribute(key)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function full(el: SVGElement, config: SVGConfigType) {
|
|
32
|
-
_setAttribute(el, "stroke", config.strokeStyle)
|
|
33
|
-
_setAttribute(el, "fill", config.fillStyle)
|
|
34
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function fill(el: SVGElement, config: SVGConfigType) {
|
|
38
|
-
_setAttribute(el, "fill", config.fillStyle)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function stroke(el: SVGElement, config: SVGConfigType) {
|
|
42
|
-
_setAttribute(el, "stroke", config.strokeStyle)
|
|
43
|
-
_setAttribute(el, "fill", "none")
|
|
44
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
1
|
+
import type SVGConfigType from '../../../types/SVGConfig'
|
|
2
|
+
|
|
3
|
+
import { XLINK_ATTRIBUTE } from "./dictionary"
|
|
4
|
+
|
|
5
|
+
// 新建节点
|
|
6
|
+
export function toNode(tagname: string) {
|
|
7
|
+
return document.createElementNS('http://www.w3.org/2000/svg', tagname)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 设置属性
|
|
11
|
+
const _setAttribute = function (el: SVGElement, key: string, value: string | number) {
|
|
12
|
+
|
|
13
|
+
// 需要使用xlink命名空间的xml属性
|
|
14
|
+
if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
|
|
15
|
+
el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 否则
|
|
19
|
+
else {
|
|
20
|
+
el.setAttribute(key, value + "")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const setAttribute = _setAttribute
|
|
24
|
+
|
|
25
|
+
// 获取属性
|
|
26
|
+
export function getAttribute(el: SVGElement, key: string) {
|
|
27
|
+
if (XLINK_ATTRIBUTE.indexOf(key) > -1) key = 'xlink:' + key
|
|
28
|
+
return el.getAttribute(key)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function full(el: SVGElement, config: SVGConfigType) {
|
|
32
|
+
_setAttribute(el, "stroke", config.strokeStyle)
|
|
33
|
+
_setAttribute(el, "fill", config.fillStyle)
|
|
34
|
+
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function fill(el: SVGElement, config: SVGConfigType) {
|
|
38
|
+
_setAttribute(el, "fill", config.fillStyle)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function stroke(el: SVGElement, config: SVGConfigType) {
|
|
42
|
+
_setAttribute(el, "stroke", config.strokeStyle)
|
|
43
|
+
_setAttribute(el, "fill", "none")
|
|
44
|
+
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
45
45
|
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import type TreeConfigType 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
|
-
|
|
18
|
-
// 根结点
|
|
19
|
-
const temp = config.root(initTree)
|
|
20
|
-
let id: number | string, rid: number | string
|
|
21
|
-
id = rid = config.id(temp)
|
|
22
|
-
tempTree[id] = {
|
|
23
|
-
"data": temp,
|
|
24
|
-
"pid": null,
|
|
25
|
-
"id": id,
|
|
26
|
-
"isOpen": true,
|
|
27
|
-
"show": true,
|
|
28
|
-
"children": []
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let num: number = 1
|
|
32
|
-
|
|
33
|
-
// 根据传递的原始数据,生成内部统一结构
|
|
34
|
-
; (function createTree(pdata: any, pid: number | string) {
|
|
35
|
-
const children = config.children(pdata, initTree)
|
|
36
|
-
num += children ? children.length : 0
|
|
37
|
-
for (let flag = 0; children && flag < children.length; flag++) {
|
|
38
|
-
id = config.id(children[flag])
|
|
39
|
-
tempTree[pid].children.push(id);
|
|
40
|
-
tempTree[id] = {
|
|
41
|
-
"data": children[flag],
|
|
42
|
-
"pid": pid,
|
|
43
|
-
"id": id,
|
|
44
|
-
"isOpen": true,
|
|
45
|
-
"show": true,
|
|
46
|
-
"children": []
|
|
47
|
-
}
|
|
48
|
-
createTree(children[flag], id)
|
|
49
|
-
}
|
|
50
|
-
})(temp, id)
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
rid,
|
|
54
|
-
value: tempTree,
|
|
55
|
-
num
|
|
56
|
-
}
|
|
57
|
-
|
|
1
|
+
import type TreeConfigType 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
|
+
|
|
18
|
+
// 根结点
|
|
19
|
+
const temp = config.root(initTree)
|
|
20
|
+
let id: number | string, rid: number | string
|
|
21
|
+
id = rid = config.id(temp)
|
|
22
|
+
tempTree[id] = {
|
|
23
|
+
"data": temp,
|
|
24
|
+
"pid": null,
|
|
25
|
+
"id": id,
|
|
26
|
+
"isOpen": true,
|
|
27
|
+
"show": true,
|
|
28
|
+
"children": []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let num: number = 1
|
|
32
|
+
|
|
33
|
+
// 根据传递的原始数据,生成内部统一结构
|
|
34
|
+
; (function createTree(pdata: any, pid: number | string) {
|
|
35
|
+
const children = config.children(pdata, initTree)
|
|
36
|
+
num += children ? children.length : 0
|
|
37
|
+
for (let flag = 0; children && flag < children.length; flag++) {
|
|
38
|
+
id = config.id(children[flag])
|
|
39
|
+
tempTree[pid].children.push(id);
|
|
40
|
+
tempTree[id] = {
|
|
41
|
+
"data": children[flag],
|
|
42
|
+
"pid": pid,
|
|
43
|
+
"id": id,
|
|
44
|
+
"isOpen": true,
|
|
45
|
+
"show": true,
|
|
46
|
+
"children": []
|
|
47
|
+
}
|
|
48
|
+
createTree(children[flag], id)
|
|
49
|
+
}
|
|
50
|
+
})(temp, id)
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
rid,
|
|
54
|
+
value: tempTree,
|
|
55
|
+
num
|
|
56
|
+
}
|
|
57
|
+
|
|
58
58
|
}
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import type TreeConfigType from '../../../types/TreeConfig'
|
|
2
|
-
|
|
3
|
-
import toInnerTree from './toInnerTree'
|
|
4
|
-
|
|
5
|
-
// 可以传递任意格式的树原始数据
|
|
6
|
-
// 只要配置对应的解析方法即可
|
|
7
|
-
export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
8
|
-
const treeData = toInnerTree(initTree, config)
|
|
9
|
-
|
|
10
|
-
const alltreedata = treeData.value // 维护的树
|
|
11
|
-
const rootid = treeData.rid // 根结点ID
|
|
12
|
-
|
|
13
|
-
if (treeData.num == 1) {
|
|
14
|
-
alltreedata[rootid].left = 0.5
|
|
15
|
-
alltreedata[rootid].top = 0.5
|
|
16
|
-
alltreedata[rootid].show = true
|
|
17
|
-
return {
|
|
18
|
-
deep: 1,
|
|
19
|
-
node: alltreedata,
|
|
20
|
-
root: rootid,
|
|
21
|
-
size: 1
|
|
22
|
-
}
|
|
23
|
-
} else {
|
|
24
|
-
|
|
25
|
-
const beforeDis = []
|
|
26
|
-
let size = 0, maxDeep = 0
|
|
27
|
-
|
|
28
|
-
if (noOpens[rootid]) {
|
|
29
|
-
alltreedata[rootid].left = 0.5
|
|
30
|
-
alltreedata[rootid].top = 0.5
|
|
31
|
-
alltreedata[rootid].show = true
|
|
32
|
-
|
|
33
|
-
size = 1
|
|
34
|
-
} else {
|
|
35
|
-
; (function positionCalc(pNode, deep) {
|
|
36
|
-
|
|
37
|
-
if (deep > maxDeep) maxDeep = deep
|
|
38
|
-
|
|
39
|
-
let flag: number = 0
|
|
40
|
-
if (!noOpens[pNode.id]) {
|
|
41
|
-
|
|
42
|
-
for (flag = 0; flag < pNode.children.length; flag++)
|
|
43
|
-
|
|
44
|
-
// 因为全部的子结点的位置确定了,父结点的y位置就是子结点的中间位置
|
|
45
|
-
// 因此有子结点的,先计算子结点
|
|
46
|
-
positionCalc(alltreedata[pNode.children[flag]], deep + 1)
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// left的位置比较简单,deep从0开始编号
|
|
51
|
-
// 比如deep=0,第一层,left=0+0.5=0.5,也就是根结点
|
|
52
|
-
alltreedata[pNode.id].left = deep + 0.5
|
|
53
|
-
if (flag == 0) {
|
|
54
|
-
|
|
55
|
-
// beforeDis是一个数组,用以记录每一层此刻top下边缘(每一层是从上到下)
|
|
56
|
-
// 比如一层的第一个,top值最小可以取top=0.5
|
|
57
|
-
// 为了方便计算,beforeDis[deep] == undefined的时候表示现在准备计算的是这层的第一个结点
|
|
58
|
-
// 因此设置最低上边缘为-0.5
|
|
59
|
-
if (beforeDis[deep] == void 0) beforeDis[deep] = -0.5
|
|
60
|
-
// 父边缘同意的进行初始化
|
|
61
|
-
if (beforeDis[deep - 1] == void 0) beforeDis[deep - 1] = -0.5
|
|
62
|
-
|
|
63
|
-
// 添加的新结点top值第一种求法:本层上边缘+1(比如上边缘是-0.5,那么top最小是top=-0.5+1=0.5)
|
|
64
|
-
alltreedata[pNode.id].top = beforeDis[deep] + 1
|
|
65
|
-
|
|
66
|
-
const pTop = beforeDis[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
67
|
-
// 计算的原则是:如果第一种可行,选择第一种,否则必须选择第二种
|
|
68
|
-
// 判断第一种是否可行的方法就是:如果第一种计算后确定的孩子上边缘不对导致孩子和孩子的前兄弟重合就是可行的
|
|
69
|
-
if (pTop - 1 < beforeDis[deep - 1])
|
|
70
|
-
// 必须保证父亲结点和父亲的前一个兄弟保存1的距离,至少
|
|
71
|
-
// 添加的新结点top值的第二种求法:根据孩子取孩子结点的中心top
|
|
72
|
-
alltreedata[pNode.id].top = beforeDis[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
73
|
-
|
|
74
|
-
} else {
|
|
75
|
-
|
|
76
|
-
// 此刻flag!=0
|
|
77
|
-
// 意味着结点有孩子,那么问题就解决了,直接取孩子的中间即可
|
|
78
|
-
// 其实,flag==0的分支计算的就是孩子,是没有孩子的叶结点,那是关键
|
|
79
|
-
alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 因为计算孩子的时候
|
|
83
|
-
// 无法掌握父辈兄弟的情况
|
|
84
|
-
// 可能会出现父亲和兄弟重叠问题
|
|
85
|
-
if (alltreedata[pNode.id].top <= beforeDis[deep]) {
|
|
86
|
-
const needUp = beforeDis[deep] + 1 - alltreedata[pNode.id].top
|
|
87
|
-
(function doUp(_pid: number | string, _deep: number) {
|
|
88
|
-
alltreedata[_pid].top += needUp;
|
|
89
|
-
if (beforeDis[_deep] < alltreedata[_pid].top) beforeDis[_deep] = alltreedata[_pid].top
|
|
90
|
-
|
|
91
|
-
for (let _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
|
|
92
|
-
doUp(alltreedata[_pid].children[_flag], _deep + 1)
|
|
93
|
-
}
|
|
94
|
-
})(pNode.id, deep)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 计算好一个结点后,需要更新此刻该层的上边缘
|
|
98
|
-
beforeDis[deep] = alltreedata[pNode.id].top
|
|
99
|
-
|
|
100
|
-
// size在每次计算一个结点后更新,是为了最终绘图的时候知道树有多宽(此处应该叫高)
|
|
101
|
-
if (alltreedata[pNode.id].top + 0.5 > size) size = alltreedata[pNode.id].top + 0.5
|
|
102
|
-
|
|
103
|
-
})(alltreedata[rootid], 0)
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
// 对于不显示的,需要标记一下
|
|
107
|
-
for (const key in noOpens) {
|
|
108
|
-
if (noOpens[key]) {
|
|
109
|
-
alltreedata[key].isOpen = false
|
|
110
|
-
; (function updateHidden(pid, left, top) {
|
|
111
|
-
for (let index = 0; index < alltreedata[pid].children.length; index++) {
|
|
112
|
-
alltreedata[alltreedata[pid].children[index]].left = left
|
|
113
|
-
alltreedata[alltreedata[pid].children[index]].top = top
|
|
114
|
-
alltreedata[alltreedata[pid].children[index]].show = false
|
|
115
|
-
|
|
116
|
-
updateHidden(alltreedata[pid].children[index], left, top)
|
|
117
|
-
}
|
|
118
|
-
})(key, alltreedata[key].left, alltreedata[key].top)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 传递的参数分别表示:记录了位置信息的树结点集合、根结点ID和树的宽
|
|
123
|
-
return {
|
|
124
|
-
"node": alltreedata,
|
|
125
|
-
"root": rootid,
|
|
126
|
-
"size": size,
|
|
127
|
-
"deep": maxDeep + 1
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
import type TreeConfigType from '../../../types/TreeConfig'
|
|
2
|
+
|
|
3
|
+
import toInnerTree from './toInnerTree'
|
|
4
|
+
|
|
5
|
+
// 可以传递任意格式的树原始数据
|
|
6
|
+
// 只要配置对应的解析方法即可
|
|
7
|
+
export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
8
|
+
const treeData = toInnerTree(initTree, config)
|
|
9
|
+
|
|
10
|
+
const alltreedata = treeData.value // 维护的树
|
|
11
|
+
const rootid = treeData.rid // 根结点ID
|
|
12
|
+
|
|
13
|
+
if (treeData.num == 1) {
|
|
14
|
+
alltreedata[rootid].left = 0.5
|
|
15
|
+
alltreedata[rootid].top = 0.5
|
|
16
|
+
alltreedata[rootid].show = true
|
|
17
|
+
return {
|
|
18
|
+
deep: 1,
|
|
19
|
+
node: alltreedata,
|
|
20
|
+
root: rootid,
|
|
21
|
+
size: 1
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
|
|
25
|
+
const beforeDis = []
|
|
26
|
+
let size = 0, maxDeep = 0
|
|
27
|
+
|
|
28
|
+
if (noOpens[rootid]) {
|
|
29
|
+
alltreedata[rootid].left = 0.5
|
|
30
|
+
alltreedata[rootid].top = 0.5
|
|
31
|
+
alltreedata[rootid].show = true
|
|
32
|
+
|
|
33
|
+
size = 1
|
|
34
|
+
} else {
|
|
35
|
+
; (function positionCalc(pNode, deep) {
|
|
36
|
+
|
|
37
|
+
if (deep > maxDeep) maxDeep = deep
|
|
38
|
+
|
|
39
|
+
let flag: number = 0
|
|
40
|
+
if (!noOpens[pNode.id]) {
|
|
41
|
+
|
|
42
|
+
for (flag = 0; flag < pNode.children.length; flag++)
|
|
43
|
+
|
|
44
|
+
// 因为全部的子结点的位置确定了,父结点的y位置就是子结点的中间位置
|
|
45
|
+
// 因此有子结点的,先计算子结点
|
|
46
|
+
positionCalc(alltreedata[pNode.children[flag]], deep + 1)
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// left的位置比较简单,deep从0开始编号
|
|
51
|
+
// 比如deep=0,第一层,left=0+0.5=0.5,也就是根结点
|
|
52
|
+
alltreedata[pNode.id].left = deep + 0.5
|
|
53
|
+
if (flag == 0) {
|
|
54
|
+
|
|
55
|
+
// beforeDis是一个数组,用以记录每一层此刻top下边缘(每一层是从上到下)
|
|
56
|
+
// 比如一层的第一个,top值最小可以取top=0.5
|
|
57
|
+
// 为了方便计算,beforeDis[deep] == undefined的时候表示现在准备计算的是这层的第一个结点
|
|
58
|
+
// 因此设置最低上边缘为-0.5
|
|
59
|
+
if (beforeDis[deep] == void 0) beforeDis[deep] = -0.5
|
|
60
|
+
// 父边缘同意的进行初始化
|
|
61
|
+
if (beforeDis[deep - 1] == void 0) beforeDis[deep - 1] = -0.5
|
|
62
|
+
|
|
63
|
+
// 添加的新结点top值第一种求法:本层上边缘+1(比如上边缘是-0.5,那么top最小是top=-0.5+1=0.5)
|
|
64
|
+
alltreedata[pNode.id].top = beforeDis[deep] + 1
|
|
65
|
+
|
|
66
|
+
const pTop = beforeDis[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
67
|
+
// 计算的原则是:如果第一种可行,选择第一种,否则必须选择第二种
|
|
68
|
+
// 判断第一种是否可行的方法就是:如果第一种计算后确定的孩子上边缘不对导致孩子和孩子的前兄弟重合就是可行的
|
|
69
|
+
if (pTop - 1 < beforeDis[deep - 1])
|
|
70
|
+
// 必须保证父亲结点和父亲的前一个兄弟保存1的距离,至少
|
|
71
|
+
// 添加的新结点top值的第二种求法:根据孩子取孩子结点的中心top
|
|
72
|
+
alltreedata[pNode.id].top = beforeDis[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
73
|
+
|
|
74
|
+
} else {
|
|
75
|
+
|
|
76
|
+
// 此刻flag!=0
|
|
77
|
+
// 意味着结点有孩子,那么问题就解决了,直接取孩子的中间即可
|
|
78
|
+
// 其实,flag==0的分支计算的就是孩子,是没有孩子的叶结点,那是关键
|
|
79
|
+
alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 因为计算孩子的时候
|
|
83
|
+
// 无法掌握父辈兄弟的情况
|
|
84
|
+
// 可能会出现父亲和兄弟重叠问题
|
|
85
|
+
if (alltreedata[pNode.id].top <= beforeDis[deep]) {
|
|
86
|
+
const needUp = beforeDis[deep] + 1 - alltreedata[pNode.id].top
|
|
87
|
+
(function doUp(_pid: number | string, _deep: number) {
|
|
88
|
+
alltreedata[_pid].top += needUp;
|
|
89
|
+
if (beforeDis[_deep] < alltreedata[_pid].top) beforeDis[_deep] = alltreedata[_pid].top
|
|
90
|
+
|
|
91
|
+
for (let _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
|
|
92
|
+
doUp(alltreedata[_pid].children[_flag], _deep + 1)
|
|
93
|
+
}
|
|
94
|
+
})(pNode.id, deep)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 计算好一个结点后,需要更新此刻该层的上边缘
|
|
98
|
+
beforeDis[deep] = alltreedata[pNode.id].top
|
|
99
|
+
|
|
100
|
+
// size在每次计算一个结点后更新,是为了最终绘图的时候知道树有多宽(此处应该叫高)
|
|
101
|
+
if (alltreedata[pNode.id].top + 0.5 > size) size = alltreedata[pNode.id].top + 0.5
|
|
102
|
+
|
|
103
|
+
})(alltreedata[rootid], 0)
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
// 对于不显示的,需要标记一下
|
|
107
|
+
for (const key in noOpens) {
|
|
108
|
+
if (noOpens[key]) {
|
|
109
|
+
alltreedata[key].isOpen = false
|
|
110
|
+
; (function updateHidden(pid, left, top) {
|
|
111
|
+
for (let index = 0; index < alltreedata[pid].children.length; index++) {
|
|
112
|
+
alltreedata[alltreedata[pid].children[index]].left = left
|
|
113
|
+
alltreedata[alltreedata[pid].children[index]].top = top
|
|
114
|
+
alltreedata[alltreedata[pid].children[index]].show = false
|
|
115
|
+
|
|
116
|
+
updateHidden(alltreedata[pid].children[index], left, top)
|
|
117
|
+
}
|
|
118
|
+
})(key, alltreedata[key].left, alltreedata[key].top)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 传递的参数分别表示:记录了位置信息的树结点集合、根结点ID和树的宽
|
|
123
|
+
return {
|
|
124
|
+
"node": alltreedata,
|
|
125
|
+
"root": rootid,
|
|
126
|
+
"size": size,
|
|
127
|
+
"deep": maxDeep + 1
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
133
|
}
|