Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
e01e4565
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看板
提交
e01e4565
编写于
6月 19, 2016
作者:
J
Jason Park
提交者:
GitHub
6月 19, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #188 from nadr0/more-colors
added color customization
上级
c2b8c4c8
01192e41
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
57 addition
and
32 deletion
+57
-32
js/module/tracer/array2d.js
js/module/tracer/array2d.js
+12
-9
js/module/tracer/chart.js
js/module/tracer/chart.js
+6
-8
js/module/tracer/coordinate_system.js
js/module/tracer/coordinate_system.js
+2
-2
js/module/tracer/directed_graph.js
js/module/tracer/directed_graph.js
+10
-12
js/module/tracer/tracer.js
js/module/tracer/tracer.js
+26
-0
js/module/tracer/weighted_directed_graph.js
js/module/tracer/weighted_directed_graph.js
+1
-1
未找到文件。
js/module/tracer/array2d.js
浏览文件 @
e01e4565
...
...
@@ -14,10 +14,8 @@ class Array2DTracer extends Tracer {
constructor
(
name
)
{
super
(
name
);
this
.
colorClass
=
{
selected
:
'
selected
'
,
notified
:
'
notified
'
};
this
.
selectColor
=
'
#2962ff
'
;
this
.
notifyColor
=
'
#c51162
'
;
if
(
this
.
isNew
)
initView
(
this
);
}
...
...
@@ -25,6 +23,7 @@ class Array2DTracer extends Tracer {
_notify
(
x
,
y
,
v
)
{
this
.
manager
.
pushStep
(
this
.
capsule
,
{
type
:
'
notify
'
,
color
:
this
.
notifyColor
,
x
:
x
,
y
:
y
,
v
:
v
...
...
@@ -146,7 +145,8 @@ class Array2DTracer extends Tracer {
}
}
var
step
=
{
type
:
type
type
:
type
,
color
:
this
.
selectColor
};
$
.
extend
(
step
,
coord
);
this
.
manager
.
pushStep
(
this
.
capsule
,
step
);
...
...
@@ -163,7 +163,7 @@ class Array2DTracer extends Tracer {
case
'
denotify
'
:
case
'
select
'
:
case
'
deselect
'
:
var
colorClass
=
step
.
type
==
'
select
'
||
step
.
type
==
'
deselect
'
?
this
.
colorClass
.
selected
:
this
.
colorClass
.
notified
;
var
colorClass
=
step
.
color
;
var
addClass
=
step
.
type
==
'
select
'
||
step
.
type
==
'
notify
'
;
var
sx
=
step
.
sx
;
var
sy
=
step
.
sy
;
...
...
@@ -297,14 +297,17 @@ class Array2DTracer extends Tracer {
var
$row
=
this
.
$table
.
find
(
'
.mtbl-row
'
).
eq
(
i
);
for
(
var
j
=
sy
;
j
<=
ey
;
j
++
)
{
var
$col
=
$row
.
find
(
'
.mtbl-col
'
).
eq
(
j
);
if
(
addClass
)
$col
.
addClass
(
colorClass
)
;
else
$col
.
removeClass
(
colorClass
)
;
if
(
addClass
)
$col
[
0
].
style
.
backgroundColor
=
colorClass
;
else
$col
[
0
].
style
.
backgroundColor
=
""
;
}
}
}
clearColor
()
{
this
.
$table
.
find
(
'
.mtbl-col
'
).
removeClass
(
Object
.
keys
(
this
.
colorClass
).
join
(
'
'
));
var
divs
=
this
.
$table
.
find
(
'
.mtbl-col
'
);
for
(
var
i
=
0
;
i
<
divs
.
length
;
i
++
){
divs
[
i
].
style
.
backgroundColor
=
""
;
}
}
separate
(
x
,
y
)
{
...
...
js/module/tracer/chart.js
浏览文件 @
e01e4565
...
...
@@ -10,11 +10,9 @@ class ChartTracer extends Tracer {
constructor
(
name
)
{
super
(
name
);
this
.
color
=
{
selected
:
'
#2962ff
'
,
notified
:
'
#c51162
'
,
default
:
'
rgb(136, 136, 136)
'
};
this
.
selectColor
=
'
#2962ff
'
;
this
.
notifyColor
=
'
#c51162
'
;
this
.
defaultColor
=
'
rgb(136, 136, 136)
'
;
if
(
this
.
isNew
)
initView
(
this
);
}
...
...
@@ -27,7 +25,7 @@ class ChartTracer extends Tracer {
}
var
color
=
[];
for
(
var
i
=
0
;
i
<
C
.
length
;
i
++
)
color
.
push
(
this
.
color
.
default
);
for
(
var
i
=
0
;
i
<
C
.
length
;
i
++
)
color
.
push
(
this
.
defaultColor
);
this
.
chart
.
config
.
data
=
{
labels
:
C
.
map
(
String
),
datasets
:
[{
...
...
@@ -83,7 +81,7 @@ class ChartTracer extends Tracer {
case
'
denotify
'
:
case
'
select
'
:
case
'
deselect
'
:
let
color
=
step
.
type
==
'
notify
'
?
this
.
color
.
notified
:
step
.
type
==
'
select
'
?
this
.
color
.
selected
:
this
.
color
.
default
;
let
color
=
step
.
type
==
'
notify
'
?
this
.
notifyColor
:
step
.
type
==
'
select
'
?
this
.
selectColor
:
this
.
defaultColor
;
if
(
step
.
e
!==
undefined
)
for
(
var
i
=
step
.
s
;
i
<=
step
.
e
;
i
++
)
this
.
chart
.
config
.
data
.
datasets
[
0
].
backgroundColor
[
i
]
=
color
;
...
...
@@ -109,7 +107,7 @@ class ChartTracer extends Tracer {
if
(
data
.
datasets
.
length
)
{
const
backgroundColor
=
data
.
datasets
[
0
].
backgroundColor
;
for
(
let
i
=
0
;
i
<
backgroundColor
.
length
;
i
++
)
{
backgroundColor
[
i
]
=
this
.
color
.
default
;
backgroundColor
[
i
]
=
this
.
defaultColor
;
}
this
.
chart
.
update
();
}
...
...
js/module/tracer/coordinate_system.js
浏览文件 @
e01e4565
...
...
@@ -26,7 +26,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer {
y
:
C
[
i
][
1
],
label
:
''
+
i
,
size
:
1
,
color
:
this
.
color
.
default
color
:
this
.
defaultColor
});
this
.
graph
.
read
({
nodes
:
nodes
,
...
...
@@ -49,7 +49,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer {
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
;
var
color
=
visit
?
this
.
visitedColor
:
this
.
leftColor
;
targetNode
.
color
=
color
;
if
(
step
.
source
!==
undefined
)
{
var
edgeId
=
this
.
e
(
step
.
source
,
step
.
target
);
...
...
js/module/tracer/directed_graph.js
浏览文件 @
e01e4565
...
...
@@ -14,12 +14,10 @@ class DirectedGraphTracer extends Tracer {
constructor
(
name
)
{
super
(
name
);
this
.
color
=
{
selected
:
'
#2962ff
'
,
visited
:
'
#f50057
'
,
left
:
'
#616161
'
,
default
:
'
#bdbdbd
'
};
this
.
selectColor
=
'
#2962ff
'
;
this
.
visitedColor
=
'
#f50057
'
;
this
.
leftColor
=
'
#616161
'
;
this
.
defaultColor
=
'
#bdbdbd
'
;
if
(
this
.
isNew
)
initView
(
this
);
}
...
...
@@ -59,7 +57,7 @@ class DirectedGraphTracer extends Tracer {
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
;
var
color
=
visit
?
this
.
visitedColor
:
this
.
leftColor
;
targetNode
.
color
=
color
;
if
(
step
.
source
!==
undefined
)
{
var
edgeId
=
this
.
e
(
step
.
source
,
step
.
target
);
...
...
@@ -137,7 +135,7 @@ class DirectedGraphTracer extends Tracer {
x
:
.
5
+
Math
.
sin
(
currentAngle
)
/
2
,
y
:
.
5
+
Math
.
cos
(
currentAngle
)
/
2
,
size
:
1
,
color
:
this
.
color
.
default
,
color
:
this
.
defaultColor
,
weight
:
0
});
...
...
@@ -149,7 +147,7 @@ class DirectedGraphTracer extends Tracer {
id
:
this
.
e
(
i
,
j
),
source
:
this
.
n
(
i
),
target
:
this
.
n
(
j
),
color
:
this
.
color
.
default
,
color
:
this
.
defaultColor
,
size
:
1
,
weight
:
refineByType
(
value
)
});
...
...
@@ -162,7 +160,7 @@ class DirectedGraphTracer extends Tracer {
id
:
this
.
e
(
i
,
j
),
source
:
this
.
n
(
i
),
target
:
this
.
n
(
j
),
color
:
this
.
color
.
default
,
color
:
this
.
defaultColor
,
size
:
1
,
weight
:
refineByType
(
G
[
i
][
j
])
});
...
...
@@ -210,10 +208,10 @@ class DirectedGraphTracer extends Tracer {
var
tracer
=
this
;
this
.
graph
.
nodes
().
forEach
(
function
(
node
)
{
node
.
color
=
tracer
.
color
.
default
;
node
.
color
=
tracer
.
defaultColor
;
});
this
.
graph
.
edges
().
forEach
(
function
(
edge
)
{
edge
.
color
=
tracer
.
color
.
default
;
edge
.
color
=
tracer
.
defaultColor
;
});
}
...
...
js/module/tracer/tracer.js
浏览文件 @
e01e4565
...
...
@@ -15,6 +15,12 @@ class Tracer {
constructor
(
name
)
{
this
.
module
=
this
.
constructor
;
this
.
selectColor
;
this
.
notifyColor
;
this
.
defaultColor
;
this
.
leftColor
;
this
.
visitedColor
;
this
.
manager
=
app
.
getTracerManager
();
this
.
capsule
=
this
.
manager
.
allocate
(
this
);
$
.
extend
(
this
,
this
.
capsule
);
...
...
@@ -42,6 +48,26 @@ class Tracer {
return
this
;
}
_setSelectFillColor
(
c
)
{
this
.
selectColor
=
c
;
}
_setNotifyFillColor
(
c
)
{
this
.
notifyColor
=
c
;
}
_setDefaultFillColor
(
c
){
this
.
defaultColor
=
c
;
}
_setLeftFillColor
(
c
){
this
.
leftColor
=
c
;
}
_setVisitedFillColor
(
c
){
this
.
visitedColor
=
c
;
}
processStep
(
step
,
options
)
{
const
{
type
,
...
...
js/module/tracer/weighted_directed_graph.js
浏览文件 @
e01e4565
...
...
@@ -56,7 +56,7 @@ class WeightedDirectedGraphTracer extends DirectedGraphTracer {
case
'
leave
'
:
var
visit
=
step
.
type
==
'
visit
'
;
var
targetNode
=
this
.
graph
.
nodes
(
this
.
n
(
step
.
target
));
var
color
=
visit
?
step
.
weight
===
undefined
?
this
.
color
.
selected
:
this
.
color
.
visited
:
this
.
color
.
left
;
var
color
=
visit
?
step
.
weight
===
undefined
?
this
.
selectColor
:
this
.
visitedColor
:
this
.
leftColor
;
targetNode
.
color
=
color
;
if
(
step
.
weight
!==
undefined
)
targetNode
.
weight
=
refineByType
(
step
.
weight
);
if
(
step
.
source
!==
undefined
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录