Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
cd6b73bd
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看板
提交
cd6b73bd
编写于
5月 24, 2016
作者:
J
Jason Park
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some bugs in _setData method
上级
6292fc21
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
140 addition
and
127 deletion
+140
-127
js/module/array1d.js
js/module/array1d.js
+3
-3
js/module/array2d.js
js/module/array2d.js
+43
-41
js/module/directed_graph.js
js/module/directed_graph.js
+36
-28
js/module/tracer.js
js/module/tracer.js
+12
-5
js/module/tracer_manager.js
js/module/tracer_manager.js
+4
-7
js/module/undirected_graph.js
js/module/undirected_graph.js
+2
-2
js/module/weighted_directed_graph.js
js/module/weighted_directed_graph.js
+37
-37
js/module/weighted_undirected_graph.js
js/module/weighted_undirected_graph.js
+2
-2
js/script.js
js/script.js
+1
-2
未找到文件。
js/module/array1d.js
浏览文件 @
cd6b73bd
...
...
@@ -4,9 +4,6 @@ function Array1DTracer(module) {
Array1DTracer
.
prototype
=
$
.
extend
(
true
,
Object
.
create
(
Array2DTracer
.
prototype
),
{
constructor
:
Array1DTracer
,
_setData
:
function
(
D
)
{
return
Array2DTracer
.
prototype
.
_setData
.
call
(
this
,
[
D
]);
},
_notify
:
function
(
idx1
,
idx2
)
{
if
(
idx2
===
undefined
)
{
Array2DTracer
.
prototype
.
_notify
.
call
(
this
,
0
,
idx1
);
...
...
@@ -47,6 +44,9 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype),
});
});
Array2DTracer
.
prototype
.
_deselectSet
.
call
(
this
,
coords
);
},
setData
:
function
(
D
)
{
return
Array2DTracer
.
prototype
.
setData
.
call
(
this
,
[
D
]);
}
});
...
...
js/module/array2d.js
浏览文件 @
cd6b73bd
...
...
@@ -12,47 +12,6 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
this
.
$table
=
this
.
capsule
.
$table
=
$
(
'
<div class="mtbl-table">
'
);
this
.
$container
.
append
(
this
.
$table
);
},
resize
:
function
()
{
Tracer
.
prototype
.
resize
.
call
(
this
);
this
.
refresh
();
},
clear
:
function
()
{
Tracer
.
prototype
.
clear
.
call
(
this
);
this
.
clearColor
();
},
_setData
:
function
(
D
)
{
this
.
D
=
D
;
this
.
viewX
=
this
.
viewY
=
0
;
this
.
paddingH
=
6
;
this
.
paddingV
=
3
;
this
.
fontSize
=
16
;
if
(
Tracer
.
prototype
.
_setData
.
call
(
this
,
arguments
))
{
this
.
$table
.
find
(
'
.mtbl-row
'
).
each
(
function
(
i
)
{
$
(
this
).
children
().
each
(
function
(
j
)
{
$
(
this
).
text
(
D
[
i
][
j
]);
});
});
return
true
;
}
this
.
$table
.
empty
();
for
(
var
i
=
0
;
i
<
D
.
length
;
i
++
)
{
var
$row
=
$
(
'
<div class="mtbl-row">
'
);
this
.
$table
.
append
(
$row
);
for
(
var
j
=
0
;
j
<
D
[
i
].
length
;
j
++
)
{
var
$cell
=
$
(
'
<div class="mtbl-cell">
'
)
.
css
(
this
.
getCellCss
())
.
text
(
D
[
i
][
j
]);
$row
.
append
(
$cell
);
}
}
this
.
resize
();
return
false
;
},
_notify
:
function
(
x1
,
y1
,
x2
,
y2
)
{
var
second
=
x2
!==
undefined
&&
y2
!==
undefined
;
tm
.
pushStep
(
this
.
capsule
,
{
...
...
@@ -179,8 +138,51 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
this
.
paintColor
(
sx
,
sy
,
ex
,
ey
,
colorClass
,
addClass
);
}
break
;
default
:
Tracer
.
prototype
.
processStep
.
call
(
this
,
step
,
options
);
}
},
setData
:
function
(
D
)
{
this
.
D
=
D
;
this
.
viewX
=
this
.
viewY
=
0
;
this
.
paddingH
=
6
;
this
.
paddingV
=
3
;
this
.
fontSize
=
16
;
if
(
Tracer
.
prototype
.
setData
.
apply
(
this
,
arguments
))
{
this
.
$table
.
find
(
'
.mtbl-row
'
).
each
(
function
(
i
)
{
$
(
this
).
children
().
each
(
function
(
j
)
{
$
(
this
).
text
(
D
[
i
][
j
]);
});
});
return
true
;
}
this
.
$table
.
empty
();
for
(
var
i
=
0
;
i
<
D
.
length
;
i
++
)
{
var
$row
=
$
(
'
<div class="mtbl-row">
'
);
this
.
$table
.
append
(
$row
);
for
(
var
j
=
0
;
j
<
D
[
i
].
length
;
j
++
)
{
var
$cell
=
$
(
'
<div class="mtbl-cell">
'
)
.
css
(
this
.
getCellCss
())
.
text
(
D
[
i
][
j
]);
$row
.
append
(
$cell
);
}
}
this
.
resize
();
return
false
;
},
resize
:
function
()
{
Tracer
.
prototype
.
resize
.
call
(
this
);
this
.
refresh
();
},
clear
:
function
()
{
Tracer
.
prototype
.
clear
.
call
(
this
);
this
.
clearColor
();
},
getCellCss
:
function
()
{
return
{
padding
:
this
.
paddingV
.
toFixed
(
1
)
+
'
px
'
+
this
.
paddingH
.
toFixed
(
1
)
+
'
px
'
,
...
...
js/module/directed_graph.js
浏览文件 @
cd6b73bd
...
...
@@ -46,6 +46,39 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
this
.
graph
=
this
.
capsule
.
graph
=
this
.
s
.
graph
;
},
_setTreeData
:
function
(
G
,
root
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
setTreeData
'
,
arguments
:
arguments
});
},
_visit
:
function
(
target
,
source
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
visit
'
,
target
:
target
,
source
:
source
});
},
_leave
:
function
(
target
,
source
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
leave
'
,
target
:
target
,
source
:
source
});
},
processStep
:
function
(
step
,
options
)
{
switch
(
step
.
type
)
{
case
'
setTreeData
'
:
this
.
setTreeData
.
apply
(
this
,
step
.
arguments
);
break
;
case
'
visit
'
:
case
'
leave
'
:
var
visit
=
step
.
type
==
'
visit
'
;
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
var
color
=
visit
?
this
.
color
.
visited
:
this
.
color
.
left
;
targetNode
.
color
=
color
;
if
(
step
.
source
!==
undefined
)
{
var
edgeId
=
this
.
e
(
step
.
source
,
step
.
target
);
var
edge
=
this
.
graph
.
edges
(
edgeId
);
edge
.
color
=
color
;
this
.
graph
.
dropEdge
(
edgeId
).
addEdge
(
edge
);
}
var
source
=
step
.
source
;
if
(
source
===
undefined
)
source
=
''
;
break
;
default
:
Tracer
.
prototype
.
processStep
.
call
(
this
,
step
,
options
);
}
},
setTreeData
:
function
(
G
,
root
)
{
var
tracer
=
this
;
root
=
root
||
0
;
...
...
@@ -62,7 +95,7 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
};
getDepth
(
root
,
1
);
if
(
this
.
_setData
(
G
,
root
))
return
true
;
if
(
this
.
setData
.
apply
(
this
,
arguments
))
return
true
;
var
place
=
function
(
node
,
x
,
y
)
{
var
temp
=
tracer
.
graph
.
nodes
(
tracer
.
n
(
node
));
...
...
@@ -87,8 +120,8 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
this
.
refresh
();
},
_
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
_setData
.
call
(
this
,
arguments
))
return
true
;
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
setData
.
apply
(
this
,
arguments
))
return
true
;
this
.
graph
.
clear
();
var
nodes
=
[];
...
...
@@ -132,31 +165,6 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
return
false
;
},
_visit
:
function
(
target
,
source
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
visit
'
,
target
:
target
,
source
:
source
});
},
_leave
:
function
(
target
,
source
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
leave
'
,
target
:
target
,
source
:
source
});
},
processStep
:
function
(
step
,
options
)
{
switch
(
step
.
type
)
{
case
'
visit
'
:
case
'
leave
'
:
var
visit
=
step
.
type
==
'
visit
'
;
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
var
color
=
visit
?
this
.
color
.
visited
:
this
.
color
.
left
;
targetNode
.
color
=
color
;
if
(
step
.
source
!==
undefined
)
{
var
edgeId
=
this
.
e
(
step
.
source
,
step
.
target
);
var
edge
=
this
.
graph
.
edges
(
edgeId
);
edge
.
color
=
color
;
this
.
graph
.
dropEdge
(
edgeId
).
addEdge
(
edge
);
}
var
source
=
step
.
source
;
if
(
source
===
undefined
)
source
=
''
;
break
;
}
},
resize
:
function
()
{
Tracer
.
prototype
.
resize
.
call
(
this
);
...
...
js/module/tracer.js
浏览文件 @
cd6b73bd
...
...
@@ -7,11 +7,8 @@ var Tracer = function (module) {
};
Tracer
.
prototype
=
{
_setData
:
function
(
arguments
)
{
var
data
=
JSON
.
stringify
(
arguments
);
if
(
!
this
.
new
&&
this
.
lastData
==
data
)
return
true
;
this
.
capsule
.
lastData
=
data
;
return
false
;
_setData
:
function
()
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
setData
'
,
arguments
:
arguments
});
},
_clear
:
function
()
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
clear
'
});
...
...
@@ -21,11 +18,21 @@ Tracer.prototype = {
},
processStep
:
function
(
step
,
options
)
{
switch
(
step
.
type
)
{
case
'
setData
'
:
this
.
setData
.
apply
(
this
,
step
.
arguments
);
break
;
case
'
clear
'
:
this
.
clear
();
break
;
}
},
setData
:
function
()
{
var
data
=
JSON
.
stringify
(
arguments
);
if
(
!
this
.
new
&&
this
.
lastData
==
data
)
return
true
;
this
.
new
=
this
.
capsule
.
new
=
false
;
this
.
lastData
=
this
.
capsule
.
lastData
=
data
;
return
false
;
},
resize
:
function
()
{
},
refresh
:
function
()
{
...
...
js/module/tracer_manager.js
浏览文件 @
cd6b73bd
...
...
@@ -4,6 +4,7 @@ var stepLimit = 1e6;
var
TracerManager
=
function
()
{
this
.
pause
=
false
;
this
.
capsules
=
[];
this
.
interval
=
500
;
};
TracerManager
.
prototype
=
{
...
...
@@ -37,10 +38,7 @@ TracerManager.prototype = {
return
selectedCapsule
;
},
deallocateAll
:
function
()
{
this
.
interval
=
500
;
this
.
traces
=
[];
this
.
traceIndex
=
-
1
;
this
.
stepCnt
=
0
;
this
.
reset
();
$
.
each
(
this
.
capsules
,
function
(
i
,
capsule
)
{
capsule
.
allocated
=
false
;
});
...
...
@@ -82,9 +80,9 @@ TracerManager.prototype = {
},
reset
:
function
()
{
this
.
traces
=
[];
this
.
traceIndex
=
-
1
;
this
.
stepCnt
=
0
;
if
(
timer
)
clearTimeout
(
timer
);
$
(
'
#tab_trace .wrapper
'
).
empty
();
this
.
command
(
'
clear
'
);
},
pushStep
:
function
(
capsule
,
step
)
{
...
...
@@ -132,12 +130,11 @@ TracerManager.prototype = {
},
this
.
interval
);
},
prevStep
:
function
()
{
$
(
'
#tab_trace .wrapper
'
).
empty
();
this
.
command
(
'
clear
'
);
var
finalIndex
=
this
.
traceIndex
-
1
;
if
(
finalIndex
<
0
)
{
this
.
traceIndex
=
-
1
;
this
.
refresh
(
);
this
.
command
(
'
refresh
'
);
return
;
}
for
(
var
i
=
0
;
i
<
finalIndex
;
i
++
)
{
...
...
js/module/undirected_graph.js
浏览文件 @
cd6b73bd
...
...
@@ -19,8 +19,8 @@ UndirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGraphTrac
}
});
},
_
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
_setData
.
call
(
this
,
arguments
))
return
true
;
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
setData
.
apply
(
this
,
arguments
))
return
true
;
this
.
graph
.
clear
();
var
nodes
=
[];
...
...
js/module/weighted_directed_graph.js
浏览文件 @
cd6b73bd
...
...
@@ -29,8 +29,43 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
}
});
},
_setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
_setData
.
call
(
this
,
arguments
))
return
true
;
_weight
:
function
(
target
,
weight
,
delay
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
weight
'
,
target
:
target
,
weight
:
weight
},
delay
);
},
_visit
:
function
(
target
,
source
,
weight
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
visit
'
,
target
:
target
,
source
:
source
,
weight
:
weight
});
},
_leave
:
function
(
target
,
source
,
weight
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
leave
'
,
target
:
target
,
source
:
source
,
weight
:
weight
});
},
processStep
:
function
(
step
,
options
)
{
switch
(
step
.
type
)
{
case
'
weight
'
:
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
if
(
step
.
weight
!==
undefined
)
targetNode
.
weight
=
step
.
weight
;
break
;
case
'
visit
'
:
case
'
leave
'
:
var
visit
=
step
.
type
==
'
visit
'
;
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
var
color
=
visit
?
this
.
color
.
visited
:
this
.
color
.
left
;
targetNode
.
color
=
color
;
if
(
step
.
weight
!==
undefined
)
targetNode
.
weight
=
step
.
weight
;
if
(
step
.
source
!==
undefined
)
{
var
edgeId
=
this
.
e
(
step
.
source
,
step
.
target
);
var
edge
=
this
.
graph
.
edges
(
edgeId
);
edge
.
color
=
color
;
this
.
graph
.
dropEdge
(
edgeId
).
addEdge
(
edge
);
}
var
source
=
step
.
source
;
if
(
source
===
undefined
)
source
=
''
;
break
;
default
:
DirectedGraphTracer
.
prototype
.
processStep
.
call
(
this
,
step
,
options
);
}
},
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
setData
.
apply
(
this
,
arguments
))
return
true
;
this
.
graph
.
clear
();
var
nodes
=
[];
...
...
@@ -76,41 +111,6 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
return
false
;
},
_weight
:
function
(
target
,
weight
,
delay
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
weight
'
,
target
:
target
,
weight
:
weight
},
delay
);
},
_visit
:
function
(
target
,
source
,
weight
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
visit
'
,
target
:
target
,
source
:
source
,
weight
:
weight
});
},
_leave
:
function
(
target
,
source
,
weight
)
{
tm
.
pushStep
(
this
.
capsule
,
{
type
:
'
leave
'
,
target
:
target
,
source
:
source
,
weight
:
weight
});
},
processStep
:
function
(
step
,
options
)
{
switch
(
step
.
type
)
{
case
'
weight
'
:
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
if
(
step
.
weight
!==
undefined
)
targetNode
.
weight
=
step
.
weight
;
break
;
case
'
visit
'
:
case
'
leave
'
:
var
visit
=
step
.
type
==
'
visit
'
;
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
var
color
=
visit
?
this
.
color
.
visited
:
this
.
color
.
left
;
targetNode
.
color
=
color
;
if
(
step
.
weight
!==
undefined
)
targetNode
.
weight
=
step
.
weight
;
if
(
step
.
source
!==
undefined
)
{
var
edgeId
=
this
.
e
(
step
.
source
,
step
.
target
);
var
edge
=
this
.
graph
.
edges
(
edgeId
);
edge
.
color
=
color
;
this
.
graph
.
dropEdge
(
edgeId
).
addEdge
(
edge
);
}
var
source
=
step
.
source
;
if
(
source
===
undefined
)
source
=
''
;
break
;
default
:
DirectedGraphTracer
.
prototype
.
processStep
.
call
(
this
,
step
,
options
);
}
},
clear
:
function
()
{
DirectedGraphTracer
.
prototype
.
clear
.
call
(
this
);
...
...
js/module/weighted_undirected_graph.js
浏览文件 @
cd6b73bd
...
...
@@ -20,8 +20,8 @@ WeightedUndirectedGraphTracer.prototype = $.extend(true, Object.create(WeightedD
}
});
},
_
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
_setData
.
call
(
this
,
arguments
))
return
true
;
setData
:
function
(
G
)
{
if
(
Tracer
.
prototype
.
setData
.
apply
(
this
,
arguments
))
return
true
;
this
.
graph
.
clear
();
var
nodes
=
[];
...
...
js/script.js
浏览文件 @
cd6b73bd
...
...
@@ -41,7 +41,7 @@ dataEditor.on('change', function () {
}
catch
(
err
)
{
console
.
error
(
err
);
}
finally
{
tm
.
reset
();
tm
.
visualize
();
tm
.
removeUnallocated
();
}
});
...
...
@@ -218,7 +218,6 @@ $('#btn_run').click(function () {
try
{
tm
.
deallocateAll
();
eval
(
dataEditor
.
getValue
());
tm
.
reset
();
eval
(
codeEditor
.
getValue
());
tm
.
visualize
();
}
catch
(
err
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录