Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
ff73e54a
A
algorithm-visualizer
项目概览
tianyazhichiC
/
algorithm-visualizer
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
algorithm-visualizer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ff73e54a
编写于
12月 03, 2018
作者:
J
Jason Park
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add updateNode(), removeNode(), updateEdge(), and removeEdge() in GraphTracer
上级
e2285892
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
53 addition
and
15 deletion
+53
-15
src/frontend/core/datas/GraphData.js
src/frontend/core/datas/GraphData.js
+36
-7
src/frontend/core/renderers/GraphRenderer/index.jsx
src/frontend/core/renderers/GraphRenderer/index.jsx
+13
-7
src/frontend/core/renderers/Renderer/index.jsx
src/frontend/core/renderers/Renderer/index.jsx
+4
-1
未找到文件。
src/frontend/core/datas/GraphData.js
浏览文件 @
ff73e54a
...
...
@@ -48,9 +48,26 @@ class GraphData extends Data {
this
.
isWeighted
=
isWeighted
;
}
addNode
(
id
,
weight
=
null
,
visitedCount
=
0
,
selectedCount
=
0
,
x
=
0
,
y
=
0
)
{
addNode
(
id
,
weight
=
null
,
x
=
0
,
y
=
0
,
visitedCount
=
0
,
selectedCount
=
0
)
{
if
(
this
.
findNode
(
id
))
return
;
this
.
nodes
.
push
({
id
,
weight
,
visitedCount
,
selectedCount
,
x
,
y
});
this
.
nodes
.
push
({
id
,
weight
,
x
,
y
,
visitedCount
,
selectedCount
});
this
.
layout
();
}
updateNode
(
id
,
weight
,
x
,
y
,
visitedCount
,
selectedCount
)
{
const
node
=
this
.
findNode
(
id
);
const
update
=
{
weight
,
x
,
y
,
visitedCount
,
selectedCount
};
Object
.
keys
(
update
).
forEach
(
key
=>
{
if
(
update
[
key
]
===
undefined
)
delete
update
[
key
];
});
Object
.
assign
(
node
,
update
);
}
removeNode
(
id
)
{
const
node
=
this
.
findNode
(
id
);
if
(
!
node
)
return
;
const
index
=
this
.
nodes
.
indexOf
(
node
);
this
.
nodes
.
splice
(
index
,
1
);
this
.
layout
();
}
...
...
@@ -60,9 +77,21 @@ class GraphData extends Data {
this
.
layout
();
}
updateNode
(
id
,
update
)
{
const
node
=
this
.
findNode
(
id
);
Object
.
assign
(
node
,
update
);
updateEdge
(
source
,
target
,
weight
,
visitedCount
,
selectedCount
)
{
const
edge
=
this
.
findEdge
(
source
,
target
);
const
update
=
{
weight
,
visitedCount
,
selectedCount
};
Object
.
keys
(
update
).
forEach
(
key
=>
{
if
(
update
[
key
]
===
undefined
)
delete
update
[
key
];
});
Object
.
assign
(
edge
,
update
);
}
removeEdge
(
source
,
target
)
{
const
edge
=
this
.
findEdge
(
source
,
target
);
if
(
!
edge
)
return
;
const
index
=
this
.
edges
.
indexOf
(
edge
);
this
.
edges
.
splice
(
index
,
1
);
this
.
layout
();
}
findNode
(
id
)
{
...
...
@@ -195,11 +224,11 @@ class GraphData extends Data {
this
.
visitOrLeave
(
false
,
target
,
source
,
weight
);
}
visitOrLeave
(
visit
,
target
,
source
=
null
,
weight
=
null
)
{
visitOrLeave
(
visit
,
target
,
source
=
null
,
weight
)
{
const
edge
=
this
.
findEdge
(
source
,
target
);
if
(
edge
)
edge
.
visitedCount
+=
visit
?
1
:
-
1
;
const
node
=
this
.
findNode
(
target
);
node
.
weight
=
weight
;
if
(
weight
!==
undefined
)
node
.
weight
=
weight
;
node
.
visitedCount
+=
visit
?
1
:
-
1
;
if
(
this
.
logData
)
{
this
.
logData
.
print
(
visit
?
(
source
||
''
)
+
'
->
'
+
target
:
(
source
||
''
)
+
'
<-
'
+
target
);
...
...
src/frontend/core/renderers/GraphRenderer/index.jsx
浏览文件 @
ff73e54a
...
...
@@ -21,8 +21,10 @@ class GraphRenderer extends Renderer {
handleMouseMove
(
e
)
{
if
(
this
.
selectedNode
)
{
const
coords
=
this
.
computeCoords
(
e
);
this
.
props
.
data
.
updateNode
(
this
.
selectedNode
.
id
,
coords
);
const
{
x
,
y
}
=
this
.
computeCoords
(
e
);
const
node
=
this
.
props
.
data
.
findNode
(
this
.
selectedNode
.
id
);
node
.
x
=
x
;
node
.
y
=
y
;
this
.
refresh
();
}
else
{
super
.
handleMouseMove
(
e
);
...
...
@@ -63,8 +65,11 @@ class GraphRenderer extends Renderer {
{
edges
.
sort
((
a
,
b
)
=>
a
.
visitedCount
-
b
.
visitedCount
).
map
(
edge
=>
{
const
{
source
,
target
,
weight
,
visitedCount
,
selectedCount
}
=
edge
;
const
{
x
:
sx
,
y
:
sy
}
=
this
.
props
.
data
.
findNode
(
source
);
let
{
x
:
ex
,
y
:
ey
}
=
this
.
props
.
data
.
findNode
(
target
);
const
sourceNode
=
this
.
props
.
data
.
findNode
(
source
);
const
targetNode
=
this
.
props
.
data
.
findNode
(
target
);
if
(
!
sourceNode
||
!
targetNode
)
return
undefined
;
const
{
x
:
sx
,
y
:
sy
}
=
sourceNode
;
let
{
x
:
ex
,
y
:
ey
}
=
targetNode
;
const
mx
=
(
sx
+
ex
)
/
2
;
const
my
=
(
sy
+
ey
)
/
2
;
const
dx
=
ex
-
sx
;
...
...
@@ -79,7 +84,8 @@ class GraphRenderer extends Renderer {
}
return
(
<
g
className
=
{
classes
(
styles
.
edge
,
selectedCount
&&
styles
.
selected
,
visitedCount
&&
styles
.
visited
)
}
key
=
{
`
${
source
}
-
${
target
}
`
}
>
<
g
className
=
{
classes
(
styles
.
edge
,
selectedCount
&&
styles
.
selected
,
visitedCount
&&
styles
.
visited
)
}
key
=
{
`
${
source
}
-
${
target
}
`
}
>
<
path
d
=
{
`M
${
sx
}
,
${
sy
}
L
${
ex
}
,
${
ey
}
`
}
className
=
{
classes
(
styles
.
line
,
isDirected
&&
styles
.
directed
)
}
/>
{
isWeighted
&&
...
...
@@ -96,8 +102,8 @@ class GraphRenderer extends Renderer {
nodes
.
map
(
node
=>
{
const
{
id
,
x
,
y
,
weight
,
visitedCount
,
selectedCount
}
=
node
;
return
(
<
g
className
=
{
classes
(
styles
.
node
,
selectedCount
&&
styles
.
selected
,
visitedCount
&&
styles
.
visited
)
}
key
=
{
id
}
transform
=
{
`translate(
${
x
}
,
${
y
}
)`
}
>
<
g
className
=
{
classes
(
styles
.
node
,
selectedCount
&&
styles
.
selected
,
visitedCount
&&
styles
.
visited
)
}
key
=
{
id
}
transform
=
{
`translate(
${
x
}
,
${
y
}
)`
}
>
<
circle
className
=
{
styles
.
circle
}
r
=
{
nodeRadius
}
/>
<
text
className
=
{
styles
.
id
}
>
{
id
}
</
text
>
{
...
...
src/frontend/core/renderers/Renderer/index.jsx
浏览文件 @
ff73e54a
...
...
@@ -58,7 +58,10 @@ class Renderer extends React.Component {
toString
(
value
)
{
switch
(
typeof
(
value
))
{
case
'
number
'
:
return
value
===
Infinity
?
'
∞
'
:
Number
.
isInteger
(
value
)
?
value
.
toString
()
:
value
.
toFixed
(
3
);
return
[
Number
.
POSITIVE_INFINITY
,
Number
.
MAX_SAFE_INTEGER
,
0x7fffffff
].
includes
(
value
)
?
'
∞
'
:
[
Number
.
NEGATIVE_INFINITY
,
Number
.
MIN_SAFE_INTEGER
,
-
0x80000000
].
includes
(
value
)
?
'
-∞
'
:
Number
.
isInteger
(
value
)
?
value
.
toString
()
:
value
.
toFixed
(
3
);
case
'
boolean
'
:
return
value
?
'
T
'
:
'
F
'
;
default
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录