Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
3dc7a61a
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看板
提交
3dc7a61a
编写于
5月 14, 2016
作者:
J
Jason Park
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refresh module only if data changed
上级
f2ddec83
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
16 deletion
+86
-16
js/module/graph.js
js/module/graph.js
+20
-15
js/module/weighted_graph.js
js/module/weighted_graph.js
+58
-0
js/tracer.js
js/tracer.js
+8
-1
未找到文件。
js/module/graph.js
浏览文件 @
3dc7a61a
var
s
=
null
,
graph
=
null
,
graphMode
=
"
default
"
;
var
s
=
null
,
graph
=
null
,
graphMode
=
null
;
function
GraphTracer
()
{
Tracer
.
call
(
this
,
GraphTracer
);
GraphTracer
.
graphMode
=
"
default
"
;
if
(
s
&&
graph
&&
graphMode
==
"
default
"
)
return
;
initSigma
();
function
GraphTracer
(
module
)
{
Tracer
.
call
(
this
,
module
||
GraphTracer
);
return
initGraph
(
this
.
module
);
}
GraphTracer
.
prototype
=
Object
.
create
(
Tracer
.
prototype
);
...
...
@@ -26,9 +26,8 @@ GraphTracer.prototype.reset = function () {
// Override
GraphTracer
.
prototype
.
setData
=
function
(
G
)
{
Tracer
.
prototype
.
setData
.
call
(
this
,
G
)
;
if
(
Tracer
.
prototype
.
setData
.
call
(
this
,
arguments
))
return
;
this
.
G
=
G
;
graph
.
clear
();
var
nodes
=
[];
var
edges
=
[];
...
...
@@ -73,11 +72,11 @@ Tracer.prototype.clear = function () {
};
Tracer
.
prototype
.
visit
=
function
(
targetNode
,
sourceNode
)
{
this
.
pushStep
({
type
:
'
visit
'
,
node
:
targetNode
,
parent
:
sourceNode
},
true
);
this
.
pushStep
({
type
:
'
visit
'
,
node
:
targetNode
,
Tracer
:
sourceNode
},
true
);
};
Tracer
.
prototype
.
leave
=
function
(
targetNode
,
sourceNode
)
{
this
.
pushStep
({
type
:
'
leave
'
,
node
:
targetNode
,
parent
:
sourceNode
},
true
);
this
.
pushStep
({
type
:
'
leave
'
,
node
:
targetNode
,
Tracer
:
sourceNode
},
true
);
};
GraphTracer
.
prototype
.
processStep
=
function
(
step
,
options
)
{
...
...
@@ -92,15 +91,15 @@ GraphTracer.prototype.processStep = function (step, options) {
var
node
=
graph
.
nodes
(
n
(
step
.
node
));
var
color
=
visit
?
graphColor
.
visited
:
graphColor
.
left
;
node
.
color
=
color
;
if
(
step
.
parent
!==
undefined
)
{
var
edgeId
=
e
(
step
.
parent
,
step
.
node
);
if
(
step
.
Tracer
!==
undefined
)
{
var
edgeId
=
e
(
step
.
Tracer
,
step
.
node
);
var
edge
=
graph
.
edges
(
edgeId
);
edge
.
color
=
color
;
graph
.
dropEdge
(
edgeId
).
addEdge
(
edge
);
}
var
parent
=
step
.
parent
;
if
(
parent
===
undefined
)
parent
=
''
;
printTrace
(
visit
?
parent
+
'
->
'
+
step
.
node
:
parent
+
'
<-
'
+
step
.
node
);
var
Tracer
=
step
.
Tracer
;
if
(
Tracer
===
undefined
)
Tracer
=
''
;
printTrace
(
visit
?
Tracer
+
'
->
'
+
step
.
node
:
Tracer
+
'
<-
'
+
step
.
node
);
break
;
}
};
...
...
@@ -187,7 +186,11 @@ var e = function (v1, v2) {
return
'
e
'
+
v1
+
'
_
'
+
v2
;
};
var
initSigma
=
function
()
{
var
initGraph
=
function
(
module
)
{
if
(
s
&&
graph
&&
graphMode
==
module
.
graphMode
)
return
false
;
graphMode
=
module
.
graphMode
;
$
(
'
.visualize_container
'
).
empty
();
s
=
new
sigma
({
renderer
:
{
container
:
$
(
'
.visualize_container
'
)[
0
],
...
...
@@ -256,4 +259,6 @@ var initSigma = function () {
});
};
sigma
.
plugins
.
dragNodes
(
s
,
s
.
renderers
[
0
]);
return
true
;
};
\ No newline at end of file
js/module/weighted_graph.js
0 → 100644
浏览文件 @
3dc7a61a
WeightedGraphTracer
.
graphMode
=
"
weighted
"
;
function
WeightedGraphTracer
(
module
)
{
if
(
GraphTracer
.
call
(
this
,
module
||
WeightedGraphTracer
))
{
initWeightedGraph
();
return
true
;
}
return
false
;
}
WeightedGraphTracer
.
prototype
=
Object
.
create
(
GraphTracer
.
prototype
);
WeightedGraphTracer
.
prototype
.
constructor
=
WeightedGraphTracer
;
// Override
WeightedGraphTracer
.
prototype
.
setData
=
function
(
G
)
{
if
(
Tracer
.
prototype
.
setData
.
call
(
this
,
arguments
))
return
;
graph
.
clear
();
var
nodes
=
[];
var
edges
=
[];
var
unitAngle
=
2
*
Math
.
PI
/
G
.
length
;
var
currentAngle
=
0
;
for
(
var
i
=
0
;
i
<
G
.
length
;
i
++
)
{
currentAngle
+=
unitAngle
;
nodes
.
push
({
id
:
n
(
i
),
label
:
''
+
i
,
x
:
.
5
+
Math
.
sin
(
currentAngle
)
/
2
,
y
:
.
5
+
Math
.
cos
(
currentAngle
)
/
2
,
size
:
1
,
color
:
graphColor
.
default
});
for
(
var
j
=
0
;
j
<
G
[
i
].
length
;
j
++
)
{
edges
.
push
({
id
:
e
(
i
,
G
[
i
][
j
]),
source
:
n
(
i
),
target
:
n
(
G
[
i
][
j
]),
color
:
graphColor
.
default
,
size
:
1
})
}
}
graph
.
read
({
nodes
:
nodes
,
edges
:
edges
});
s
.
camera
.
goTo
({
x
:
0
,
y
:
0
,
angle
:
0
,
ratio
:
1
});
this
.
refresh
();
};
var
initWeightedGraph
=
function
()
{
};
\ No newline at end of file
js/tracer.js
浏览文件 @
3dc7a61a
var
timer
=
null
;
var
lastModule
=
null
,
lastData
=
null
;
var
Tracer
=
function
(
module
)
{
this
.
module
=
module
;
...
...
@@ -6,6 +7,7 @@ var Tracer = function (module) {
this
.
pause
=
false
;
this
.
traceOptions
=
null
;
this
.
traceIndex
=
-
1
;
this
.
lastData
=
null
;
};
Tracer
.
prototype
.
resize
=
function
()
{
...
...
@@ -17,7 +19,12 @@ Tracer.prototype.reset = function () {
$
(
'
#tab_trace .wrapper
'
).
empty
();
};
Tracer
.
prototype
.
setData
=
function
()
{
Tracer
.
prototype
.
setData
=
function
(
arguments
)
{
var
data
=
JSON
.
stringify
(
arguments
);
if
(
lastModule
==
this
.
module
&&
lastData
==
data
)
return
true
;
lastModule
=
this
.
module
;
lastData
=
data
;
return
false
;
};
Tracer
.
prototype
.
pushStep
=
function
(
step
,
delay
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录