Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
relation-graph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郭铭瑶
relation-graph
Commits
2227c5ee
Commit
2227c5ee
authored
Aug 20, 2021
by
郭铭瑶
🤘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge 节点同时固定位置,且展开菜单的节点也位置固定
parent
d02d2635
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
35 deletions
+46
-35
useD3.js
src/util/useD3.js
+46
-35
No files found.
src/util/useD3.js
View file @
2227c5ee
...
@@ -83,9 +83,9 @@ const defaultConfig = {
...
@@ -83,9 +83,9 @@ const defaultConfig = {
isHighLight
:
true
,
// 是否启动 鼠标 hover 到节点上高亮与节点有关的节点,其他无关节点透明的功能
isHighLight
:
true
,
// 是否启动 鼠标 hover 到节点上高亮与节点有关的节点,其他无关节点透明的功能
isScale
:
true
,
// 是否启用缩放平移zoom功能
isScale
:
true
,
// 是否启用缩放平移zoom功能
scaleExtent
:
[
0.6
,
1.5
],
// 缩放的比例尺
scaleExtent
:
[
0.6
,
1.5
],
// 缩放的比例尺
chargeStrength
:
-
1
00
,
// 万有引力
chargeStrength
:
-
3
00
,
// 万有引力
collide
:
80
,
// 碰撞力的大小 (节点之间的间距)
collide
:
80
,
// 碰撞力的大小 (节点之间的间距)
alphaDecay
:
0.
4
,
// 控制力学模拟衰减率
alphaDecay
:
0.
1
,
// 控制力学模拟衰减率
r
:
36
,
// 圈圈的半径 [30 - 45]
r
:
36
,
// 圈圈的半径 [30 - 45]
nodeColor
:
'skyblue'
,
// 圈圈节点背景颜色
nodeColor
:
'skyblue'
,
// 圈圈节点背景颜色
fontColor
:
'#2c3e50'
,
// 圈圈内文字的颜色
fontColor
:
'#2c3e50'
,
// 圈圈内文字的颜色
...
@@ -208,8 +208,8 @@ export default class RelationGraph {
...
@@ -208,8 +208,8 @@ export default class RelationGraph {
initLinks
()
{
initLinks
()
{
const
self
=
this
const
self
=
this
this
.
edges
&&
this
.
edges
.
remove
()
// 5.关系图添加线
// 5.关系图添加线
this
.
edges
&&
this
.
edges
.
remove
()
// 5.1 每条线是个容器,有线 和一个装文字的容器
// 5.1 每条线是个容器,有线 和一个装文字的容器
this
.
edges
=
this
.
relMap_g
this
.
edges
=
this
.
relMap_g
.
selectAll
(
'g.edge'
)
.
selectAll
(
'g.edge'
)
...
@@ -270,19 +270,24 @@ export default class RelationGraph {
...
@@ -270,19 +270,24 @@ export default class RelationGraph {
.
text
((
d
)
=>
d
.
name
)
.
text
((
d
)
=>
d
.
name
)
}
}
initCircles
()
{
initCircles
(
circleWrapper
)
{
const
self
=
this
const
self
=
this
this
.
circlesWrapper
&&
this
.
circlesWrapper
.
remove
()
// 给圈圈节点添加g便于后面添加menu
// 给圈圈节点添加g便于后面添加menu
this
.
circlesWrapper
=
this
.
relMap_g
if
(
circleWrapper
)
{
.
selectAll
(
'g.circle-wrapper'
)
this
.
circlesWrapper
=
circleWrapper
.
data
(
this
.
config
.
nodes
)
}
else
{
.
enter
()
this
.
circlesWrapper
=
this
.
relMap_g
.
append
(
'g'
)
.
selectAll
(
'g.circle-wrapper'
)
.
attr
(
'class'
,
'circle-wrapper'
)
.
data
(
this
.
config
.
nodes
)
.
enter
()
.
append
(
'g'
)
.
attr
(
'class'
,
'circle-wrapper'
)
.
raise
()
}
// 6.关系图添加用于显示圈圈的节点
// 6.关系图添加用于显示圈圈的节点
this
.
circles
&&
this
.
circles
.
remove
()
this
.
circles
=
this
.
circlesWrapper
this
.
circles
=
this
.
circlesWrapper
.
append
(
'circle'
)
.
append
(
'circle'
)
.
attr
(
'r'
,
this
.
config
.
r
)
.
attr
(
'r'
,
this
.
config
.
r
)
...
@@ -318,9 +323,9 @@ export default class RelationGraph {
...
@@ -318,9 +323,9 @@ export default class RelationGraph {
.
on
(
'click'
,
function
(
e
,
d
)
{
.
on
(
'click'
,
function
(
e
,
d
)
{
// self.tooltip.style('opacity', 0)
// self.tooltip.style('opacity', 0)
if
(
menu
&&
menu
.
curNodeData
==
d
)
{
if
(
menu
&&
menu
.
curNodeData
==
d
)
{
self
.
closeMenu
()
self
.
closeMenu
(
true
)
}
else
{
}
else
{
self
.
closeMenu
()
self
.
closeMenu
(
true
)
if
(
d
.
nodeLabel
===
'Subject'
)
{
if
(
d
.
nodeLabel
===
'Subject'
)
{
self
.
openMenu
(
this
,
d
)
self
.
openMenu
(
this
,
d
)
}
else
{
}
else
{
...
@@ -360,8 +365,8 @@ export default class RelationGraph {
...
@@ -360,8 +365,8 @@ export default class RelationGraph {
.
on
(
'end'
,
(
e
,
d
)
=>
{
.
on
(
'end'
,
(
e
,
d
)
=>
{
// 让alpha目标值值恢复为默认值0,停止力模型
// 让alpha目标值值恢复为默认值0,停止力模型
if
(
!
e
.
active
)
this
.
simulation
.
alphaTarget
(
0
)
if
(
!
e
.
active
)
this
.
simulation
.
alphaTarget
(
0
)
d
.
fx
=
null
d
.
fx
=
e
.
x
d
.
fy
=
null
d
.
fy
=
e
.
y
})
})
)
)
...
@@ -377,7 +382,7 @@ export default class RelationGraph {
...
@@ -377,7 +382,7 @@ export default class RelationGraph {
// simulation.force(name,[force])函数,添加某种力
// simulation.force(name,[force])函数,添加某种力
.
force
(
'link'
,
d3
.
forceLink
(
this
.
config
.
links
))
.
force
(
'link'
,
d3
.
forceLink
(
this
.
config
.
links
))
// 万有引力
// 万有引力
.
force
(
'charge'
,
d3
.
forceManyBody
().
strength
(
this
.
config
.
chargeStrength
))
//
.force('charge', d3.forceManyBody().strength(this.config.chargeStrength))
// d3.forceCenter()用指定的x坐标和y坐标创建一个新的居中力。
// d3.forceCenter()用指定的x坐标和y坐标创建一个新的居中力。
.
force
(
.
force
(
'center'
,
'center'
,
...
@@ -387,7 +392,7 @@ export default class RelationGraph {
...
@@ -387,7 +392,7 @@ export default class RelationGraph {
// 设置迭代次数,默认为1,迭代次数越多最终的布局效果越好,但是计算复杂度更高
// 设置迭代次数,默认为1,迭代次数越多最终的布局效果越好,但是计算复杂度更高
.
force
(
.
force
(
'collide'
,
'collide'
,
d3
.
forceCollide
(
this
.
config
.
collide
).
strength
(
0.
2
).
iterations
(
5
)
d3
.
forceCollide
(
this
.
config
.
collide
).
strength
(
0.
1
).
iterations
(
10
)
)
)
// 在计时器的每一帧中,仿真的alpha系数会不断削减,当alpha到达一个系数时,仿真将会停止,也就是alpha的目标系数alphaTarget,该值区间为[0,1]. 默认为0,
// 在计时器的每一帧中,仿真的alpha系数会不断削减,当alpha到达一个系数时,仿真将会停止,也就是alpha的目标系数alphaTarget,该值区间为[0,1]. 默认为0,
// 控制力学模拟衰减率,[0-1] ,设为0则不停止 , 默认0.0228,直到0.001
// 控制力学模拟衰减率,[0-1] ,设为0则不停止 , 默认0.0228,直到0.001
...
@@ -407,30 +412,32 @@ export default class RelationGraph {
...
@@ -407,30 +412,32 @@ export default class RelationGraph {
this
.
initLinks
()
this
.
initLinks
()
this
.
initCircles
()
const
updateNodes
=
this
.
relMap_g
const
{
x
=
this
.
config
.
width
/
2
,
y
=
this
.
config
.
height
/
2
}
=
.
selectAll
(
'g.circle-wrapper'
)
this
.
curActiveNode
||
{}
.
data
(
this
.
config
.
nodes
)
updateNodes
.
exit
().
remove
()
this
.
initCircles
(
updateNodes
.
enter
()
.
append
(
'g'
)
.
attr
(
'class'
,
'circle-wrapper'
)
.
merge
(
updateNodes
)
.
raise
()
)
this
.
simulation
this
.
simulation
.
nodes
(
this
.
config
.
nodes
)
.
nodes
(
this
.
config
.
nodes
)
.
force
(
'link'
,
d3
.
forceLink
(
this
.
config
.
links
))
.
force
(
'link'
,
d3
.
forceLink
(
this
.
config
.
links
))
.
force
(
'charge'
,
null
)
.
force
(
'charge'
,
null
)
.
force
(
'center'
,
d3
.
forceCenter
(
x
,
y
))
.
alpha
(
0.1
)
.
alpha
(
1
)
.
restart
()
.
restart
()
this
.
simulation
.
alphaTarget
(
0.3
).
restart
()
this
.
curActiveNode
.
fx
=
this
.
curActiveNode
.
x
this
.
curActiveNode
.
fy
=
this
.
curActiveNode
.
y
const
timer
=
setTimeout
(()
=>
{
this
.
simulation
.
alphaTarget
(
0
)
this
.
simulation
.
force
(
'link'
,
null
)
clearTimeout
(
timer
)
},
2000
)
}
}
openMenu
(
self
,
d
,
types
)
{
openMenu
(
self
,
d
,
types
)
{
this
.
clearFixedPosition
()
this
.
setCurNode
(
d
)
this
.
setCurNode
(
d
)
d
.
fx
=
d
.
x
d
.
fy
=
d
.
y
this
.
curActiveNode
=
d
this
.
curActiveNode
=
d
menu
=
new
RadialMenu
().
radius
(
38
).
thickness
(
30
).
appendTo
(
self
.
parentNode
)
menu
=
new
RadialMenu
().
radius
(
38
).
thickness
(
30
).
appendTo
(
self
.
parentNode
)
if
(
!
types
)
{
if
(
!
types
)
{
...
@@ -442,8 +449,12 @@ export default class RelationGraph {
...
@@ -442,8 +449,12 @@ export default class RelationGraph {
)
)
}
}
}
}
clearFixedPosition
()
{
closeMenu
()
{
this
.
curActiveNode
&&
(
this
.
curActiveNode
.
fx
=
null
)
this
.
curActiveNode
&&
(
this
.
curActiveNode
.
fy
=
null
)
}
closeMenu
(
needClearFixedPosition
)
{
needClearFixedPosition
&&
this
.
clearFixedPosition
()
if
(
menu
)
{
if
(
menu
)
{
menu
.
hide
()
menu
.
hide
()
menu
=
null
menu
=
null
...
@@ -466,8 +477,8 @@ export default class RelationGraph {
...
@@ -466,8 +477,8 @@ export default class RelationGraph {
}
}
})
})
)
)
.
on
(
'click'
,
()
=>
this
.
closeMenu
())
.
on
(
'dblclick.zoom'
,
null
)
// 取消双击放大
.
on
(
'dblclick.zoom'
,
null
)
// 取消双击放大
.
on
(
'click'
,
()
=>
this
.
closeMenu
())
// 3.defs <defs>标签的内容不会显示,只有调用的时候才显示
// 3.defs <defs>标签的内容不会显示,只有调用的时候才显示
this
.
defs
=
this
.
SVG
.
append
(
'defs'
)
this
.
defs
=
this
.
SVG
.
append
(
'defs'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment