Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
c7ec8961
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看板
提交
c7ec8961
编写于
2月 13, 2019
作者:
J
Jason Park
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add layout feature
上级
7271b346
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
213 addition
and
138 deletion
+213
-138
src/backend/controllers/tracers.js
src/backend/controllers/tracers.js
+1
-1
src/backend/tracers/js/worker.js
src/backend/tracers/js/worker.js
+1
-1
src/frontend/apis/index.js
src/frontend/apis/index.js
+4
-4
src/frontend/components/App/index.jsx
src/frontend/components/App/index.jsx
+23
-11
src/frontend/components/CodeEditor/index.jsx
src/frontend/components/CodeEditor/index.jsx
+1
-1
src/frontend/components/FoldableAceEditor/index.jsx
src/frontend/components/FoldableAceEditor/index.jsx
+5
-1
src/frontend/components/Player/index.jsx
src/frontend/components/Player/index.jsx
+11
-10
src/frontend/components/ResizableContainer/index.jsx
src/frontend/components/ResizableContainer/index.jsx
+4
-3
src/frontend/components/VisualizationViewer/index.jsx
src/frontend/components/VisualizationViewer/index.jsx
+30
-53
src/frontend/components/VisualizationViewer/stylesheet.scss
src/frontend/components/VisualizationViewer/stylesheet.scss
+5
-1
src/frontend/core/datas/index.js
src/frontend/core/datas/index.js
+0
-7
src/frontend/core/layouts/HorizontalLayout.js
src/frontend/core/layouts/HorizontalLayout.js
+6
-0
src/frontend/core/layouts/Layout.jsx
src/frontend/core/layouts/Layout.jsx
+55
-0
src/frontend/core/layouts/VerticalLayout.js
src/frontend/core/layouts/VerticalLayout.js
+6
-0
src/frontend/core/layouts/index.js
src/frontend/core/layouts/index.js
+3
-0
src/frontend/core/renderers/GraphRenderer/index.jsx
src/frontend/core/renderers/GraphRenderer/index.jsx
+3
-3
src/frontend/core/renderers/LogRenderer/index.jsx
src/frontend/core/renderers/LogRenderer/index.jsx
+3
-3
src/frontend/core/tracers/Array1DTracer.js
src/frontend/core/tracers/Array1DTracer.js
+10
-10
src/frontend/core/tracers/Array2DTracer.js
src/frontend/core/tracers/Array2DTracer.js
+3
-3
src/frontend/core/tracers/ChartTracer.js
src/frontend/core/tracers/ChartTracer.js
+10
-0
src/frontend/core/tracers/GraphTracer.js
src/frontend/core/tracers/GraphTracer.js
+10
-10
src/frontend/core/tracers/LogTracer.js
src/frontend/core/tracers/LogTracer.js
+3
-3
src/frontend/core/tracers/MarkdownTracer.js
src/frontend/core/tracers/MarkdownTracer.js
+3
-3
src/frontend/core/tracers/Tracer.jsx
src/frontend/core/tracers/Tracer.jsx
+6
-10
src/frontend/core/tracers/index.js
src/frontend/core/tracers/index.js
+7
-0
未找到文件。
src/backend/controllers/tracers.js
浏览文件 @
c7ec8961
...
...
@@ -38,7 +38,7 @@ const trace = lang => (req, res, next) => {
}).
finally
(()
=>
clearTimeout
(
timer
));
})
.
then
(()
=>
new
Promise
((
resolve
,
reject
)
=>
{
const
visualizationPath
=
path
.
resolve
(
tempPath
,
'
traces
.json
'
);
const
visualizationPath
=
path
.
resolve
(
tempPath
,
'
visualization
.json
'
);
res
.
sendFile
(
visualizationPath
,
err
=>
{
if
(
err
)
return
reject
(
new
Error
(
'
Visualization Not Found
'
));
resolve
();
...
...
src/backend/tracers/js/worker.js
浏览文件 @
c7ec8961
...
...
@@ -10,5 +10,5 @@ onmessage = e => {
const
lines
=
e
.
data
.
split
(
'
\n
'
).
map
((
line
,
i
)
=>
line
.
replace
(
/
(\.\s
*delay
\s
*
)\(\s
*
\)
/g
,
`$1(
${
i
}
)`
));
const
code
=
lines
.
join
(
'
\n
'
);
sandbox
(
code
);
postMessage
(
AlgorithmVisualizer
.
Tracer
.
trace
s
);
postMessage
(
AlgorithmVisualizer
.
Commander
.
command
s
);
};
src/frontend/apis/index.js
浏览文件 @
c7ec8961
...
...
@@ -69,11 +69,11 @@ const GitHubApi = {
const
TracerApi
=
{
md
:
({
code
})
=>
Promise
.
resolve
([{
tracerKey
:
'
0-MarkdownTracer-M
arkdown
'
,
method
:
'
construct
'
,
args
:
[
'
Markdown
Tracer
'
,
'
Markdown
'
],
key
:
'
m
arkdown
'
,
method
:
'
MarkdownTracer
'
,
args
:
[
'
Markdown
'
],
},
{
tracerKey
:
'
0-MarkdownTracer-M
arkdown
'
,
key
:
'
m
arkdown
'
,
method
:
'
set
'
,
args
:
[
code
],
}]),
...
...
src/frontend/components/App/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -27,13 +27,16 @@ class App extends BaseComponent {
super
(
props
);
this
.
state
=
{
navigatorOpened
:
true
,
workspaceVisibles
:
[
true
,
true
,
true
]
,
workspaceWeights
:
[
1
,
2
,
2
],
};
this
.
codeEditorRef
=
React
.
createRef
();
this
.
ignoreHistoryBlock
=
this
.
ignoreHistoryBlock
.
bind
(
this
);
this
.
handleClickTitleBar
=
this
.
handleClickTitleBar
.
bind
(
this
);
this
.
loadScratchPapers
=
this
.
loadScratchPapers
.
bind
(
this
);
this
.
handleChangeWorkspaceWeights
=
this
.
handleChangeWorkspaceWeights
.
bind
(
this
);
}
componentDidMount
()
{
...
...
@@ -161,7 +164,7 @@ class App extends BaseComponent {
login
:
undefined
,
gistId
,
title
:
'
Untitled
'
,
files
:
[
CONTRIBUTING_MD
,
createUserFile
(
'
traces
.json
'
,
JSON
.
stringify
(
content
))],
files
:
[
CONTRIBUTING_MD
,
createUserFile
(
'
visualization
.json
'
,
JSON
.
stringify
(
content
))],
});
});
}
else
if
(
gistId
===
'
new
'
)
{
...
...
@@ -182,7 +185,10 @@ class App extends BaseComponent {
return
Promise
.
resolve
();
};
fetch
()
.
then
(()
=>
this
.
selectDefaultTab
())
.
then
(()
=>
{
this
.
selectDefaultTab
();
return
null
;
// to suppress unnecessary bluebird warning
})
.
catch
(
error
=>
{
this
.
handleError
(
error
);
this
.
props
.
history
.
push
(
'
/
'
);
...
...
@@ -204,15 +210,22 @@ class App extends BaseComponent {
this
.
codeEditorRef
.
current
.
getWrappedInstance
().
handleResize
();
}
toggleNavigatorOpened
(
navigatorOpened
=
!
this
.
state
.
navigatorOpened
)
{
this
.
setState
({
navigatorOpened
});
toggleNavigatorOpened
(
navigatorOpened
=
!
this
.
state
.
workspaceVisibles
[
0
])
{
const
workspaceVisibles
=
[...
this
.
state
.
workspaceVisibles
];
workspaceVisibles
[
0
]
=
navigatorOpened
;
this
.
setState
({
workspaceVisibles
});
}
render
()
{
const
{
navigatorOpened
,
workspaceWeights
}
=
this
.
state
;
handleClickTitleBar
()
{
this
.
toggleNavigatorOpened
();
}
render
()
{
const
{
workspaceVisibles
,
workspaceWeights
}
=
this
.
state
;
const
{
titles
,
description
,
saved
}
=
this
.
props
.
current
;
const
title
=
`
${
saved
?
''
:
'
(Unsaved)
'
}${
titles
.
join
(
'
-
'
)}
`
;
const
[
navigatorOpened
]
=
workspaceVisibles
;
return
(
<
div
className
=
{
styles
.
app
}
>
...
...
@@ -220,12 +233,11 @@ class App extends BaseComponent {
<
title
>
{
title
}
</
title
>
<
meta
name
=
"description"
content
=
{
description
}
/>
</
Helmet
>
<
Header
className
=
{
styles
.
header
}
onClickTitleBar
=
{
()
=>
this
.
toggleNavigatorOpened
()
}
navigatorOpened
=
{
navigatorOpened
}
loadScratchPapers
=
{
()
=>
this
.
loadScratchPapers
()
}
<
Header
className
=
{
styles
.
header
}
onClickTitleBar
=
{
this
.
handleClickTitleBar
}
navigatorOpened
=
{
navigatorOpened
}
loadScratchPapers
=
{
this
.
loadScratchPapers
}
ignoreHistoryBlock
=
{
this
.
ignoreHistoryBlock
}
/>
<
ResizableContainer
className
=
{
styles
.
workspace
}
horizontal
weights
=
{
workspaceWeights
}
visibles
=
{
[
navigatorOpened
,
true
,
true
]
}
onChangeWeights
=
{
weights
=>
this
.
handleChangeWorkspaceWeights
(
weights
)
}
>
visibles
=
{
workspaceVisibles
}
onChangeWeights
=
{
this
.
handleChangeWorkspaceWeights
}
>
<
Navigator
/>
<
VisualizationViewer
className
=
{
styles
.
visualization_viewer
}
/>
<
TabContainer
className
=
{
styles
.
editor_tab_container
}
>
...
...
src/frontend/components/CodeEditor/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -17,7 +17,7 @@ class CodeEditor extends React.Component {
}
handleResize
()
{
this
.
aceEditorRef
.
current
.
editor
.
resize
();
this
.
aceEditorRef
.
current
.
getWrappedInstance
()
.
resize
();
}
render
()
{
...
...
src/frontend/components/FoldableAceEditor/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -11,7 +11,7 @@ import 'brace/theme/tomorrow_night_eighties';
import
'
brace/ext/searchbox
'
;
import
{
actions
}
from
'
/reducers
'
;
@
connect
(({
current
})
=>
({
current
}),
actions
)
@
connect
(({
current
})
=>
({
current
}),
actions
,
null
,
{
withRef
:
true
}
)
class
FoldableAceEditor
extends
AceEditor
{
componentDidMount
()
{
super
.
componentDidMount
();
...
...
@@ -40,6 +40,10 @@ class FoldableAceEditor extends AceEditor {
}
}
}
resize
()
{
this
.
editor
.
resize
();
}
}
export
default
FoldableAceEditor
;
src/frontend/components/Player/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -41,22 +41,23 @@ class Player extends BaseComponent {
}
}
reset
(
trace
s
=
[])
{
reset
(
command
s
=
[])
{
const
chunks
=
[{
trace
s
:
[],
command
s
:
[],
lineNumber
:
undefined
,
}];
while
(
traces
.
length
)
{
const
trace
=
traces
.
shift
();
if
(
trace
.
method
===
'
delay
'
)
{
const
[
lineNumber
]
=
trace
.
args
;
while
(
commands
.
length
)
{
const
command
=
commands
.
shift
();
const
{
key
,
method
,
args
}
=
command
;
if
(
key
===
null
&&
method
===
'
delay
'
)
{
const
[
lineNumber
]
=
args
;
chunks
[
chunks
.
length
-
1
].
lineNumber
=
lineNumber
;
chunks
.
push
({
trace
s
:
[],
command
s
:
[],
lineNumber
:
undefined
,
});
}
else
{
chunks
[
chunks
.
length
-
1
].
traces
.
push
(
trace
);
chunks
[
chunks
.
length
-
1
].
commands
.
push
(
command
);
}
}
this
.
props
.
setChunks
(
chunks
);
...
...
@@ -76,10 +77,10 @@ class Player extends BaseComponent {
const
ext
=
extension
(
file
.
name
);
if
(
ext
in
TracerApi
)
{
TracerApi
[
ext
]({
code
:
file
.
content
},
undefined
,
this
.
tracerApiSource
.
token
)
.
then
(
trace
s
=>
{
.
then
(
command
s
=>
{
this
.
tracerApiSource
=
null
;
this
.
setState
({
building
:
false
});
this
.
reset
(
trace
s
);
this
.
reset
(
command
s
);
this
.
next
();
})
.
catch
(
error
=>
{
...
...
src/frontend/components/ResizableContainer/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -16,7 +16,7 @@ class ResizableContainer extends React.Component {
let
totalWeight
=
0
;
let
subtotalWeight
=
0
;
weights
.
forEach
((
weight
,
i
)
=>
{
if
(
!
visibles
[
i
])
return
;
if
(
visibles
&&
!
visibles
[
i
])
return
;
totalWeight
+=
weight
;
if
(
i
<
index
)
subtotalWeight
+=
weight
;
});
...
...
@@ -34,9 +34,10 @@ class ResizableContainer extends React.Component {
const
elements
=
[];
let
lastIndex
=
-
1
;
const
totalWeight
=
weights
.
filter
((
weight
,
i
)
=>
visibles
[
i
]).
reduce
((
sumWeight
,
weight
)
=>
sumWeight
+
weight
,
0
);
const
totalWeight
=
weights
.
filter
((
weight
,
i
)
=>
!
visibles
||
visibles
[
i
])
.
reduce
((
sumWeight
,
weight
)
=>
sumWeight
+
weight
,
0
);
children
.
forEach
((
child
,
i
)
=>
{
if
(
visibles
[
i
])
{
if
(
!
visibles
||
visibles
[
i
])
{
if
(
~
lastIndex
)
{
const
prevIndex
=
lastIndex
;
elements
.
push
(
...
...
src/frontend/components/VisualizationViewer/index.jsx
浏览文件 @
c7ec8961
import
React
from
'
react
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
classes
}
from
'
/common/util
'
;
import
{
BaseComponent
,
ResizableContainer
}
from
'
/components
'
;
import
{
BaseComponent
}
from
'
/components
'
;
import
{
actions
}
from
'
/reducers
'
;
import
styles
from
'
./stylesheet.scss
'
;
import
{
Array1DData
,
Array2DData
,
ChartData
,
Data
,
GraphData
,
LogData
,
MarkdownData
}
from
'
/core/datas
'
;
import
*
as
TracerClasses
from
'
/core/tracers
'
;
import
*
as
LayoutClasses
from
'
/core/layouts
'
;
import
{
classes
}
from
'
/common/util
'
;
@
connect
(({
player
})
=>
({
player
}),
actions
)
class
VisualizationViewer
extends
BaseComponent
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
dataWeights
:
{},
};
this
.
reset
();
}
this
.
datas
=
[];
reset
()
{
this
.
root
=
null
;
this
.
objects
=
{};
}
componentDidMount
()
{
...
...
@@ -36,19 +38,11 @@ class VisualizationViewer extends BaseComponent {
if
(
cursor
>
oldCursor
)
{
applyingChunks
=
chunks
.
slice
(
oldCursor
,
cursor
);
}
else
{
this
.
datas
=
[]
;
this
.
reset
()
;
applyingChunks
=
chunks
.
slice
(
0
,
cursor
);
}
applyingChunks
.
forEach
(
chunk
=>
this
.
applyChunk
(
chunk
));
const
dataWeights
=
chunks
===
oldChunks
?
{
...
this
.
state
.
dataWeights
}
:
{};
this
.
datas
.
forEach
(
data
=>
{
if
(
!
(
data
.
tracerKey
in
dataWeights
))
{
dataWeights
[
data
.
tracerKey
]
=
1
;
}
});
this
.
setState
({
dataWeights
});
const
lastChunk
=
applyingChunks
[
applyingChunks
.
length
-
1
];
if
(
lastChunk
&&
lastChunk
.
lineNumber
!==
undefined
)
{
this
.
props
.
setLineIndicator
({
lineNumber
:
lastChunk
.
lineNumber
,
cursor
});
...
...
@@ -57,29 +51,24 @@ class VisualizationViewer extends BaseComponent {
}
}
addTracer
(
className
,
tracerKey
,
title
)
{
const
DataClass
=
{
Tracer
:
Data
,
MarkdownTracer
:
MarkdownData
,
LogTracer
:
LogData
,
Array2DTracer
:
Array2DData
,
Array1DTracer
:
Array1DData
,
ChartTracer
:
ChartData
,
GraphTracer
:
GraphData
,
}[
className
];
const
data
=
new
DataClass
(
tracerKey
,
title
,
this
.
datas
);
this
.
datas
.
push
(
data
);
}
applyTrace
(
trace
)
{
const
{
tracerKey
,
method
,
args
}
=
trace
;
applyCommand
(
command
)
{
const
{
key
,
method
,
args
}
=
command
;
try
{
if
(
method
===
'
construct
'
)
{
const
[
className
,
title
]
=
args
;
this
.
addTracer
(
className
,
tracerKey
,
title
);
if
(
key
===
null
&&
method
===
'
setRoot
'
)
{
const
[
root
]
=
args
;
this
.
root
=
this
.
objects
[
root
];
}
else
if
(
method
===
'
destroy
'
)
{
delete
this
.
objects
[
key
];
}
else
if
(
method
in
LayoutClasses
)
{
const
[
children
]
=
args
;
const
LayoutClass
=
LayoutClasses
[
method
];
this
.
objects
[
key
]
=
new
LayoutClass
(
key
,
key
=>
this
.
objects
[
key
],
children
);
}
else
if
(
method
in
TracerClasses
)
{
const
[
title
]
=
args
;
const
TracerClass
=
TracerClasses
[
method
];
this
.
objects
[
key
]
=
new
TracerClass
(
key
,
key
=>
this
.
objects
[
key
],
title
);
}
else
{
const
data
=
this
.
datas
.
find
(
data
=>
data
.
tracerKey
===
tracerKey
);
data
[
method
](...
args
);
this
.
objects
[
key
][
method
](...
args
);
}
}
catch
(
error
)
{
this
.
handleError
(
error
);
...
...
@@ -87,30 +76,18 @@ class VisualizationViewer extends BaseComponent {
}
applyChunk
(
chunk
)
{
chunk
.
traces
.
forEach
(
trace
=>
this
.
applyTrace
(
trace
));
}
handleChangeWeights
(
weights
)
{
const
dataWeights
=
{};
weights
.
forEach
((
weight
,
i
)
=>
{
dataWeights
[
this
.
datas
[
i
].
tracerKey
]
=
weight
;
});
this
.
setState
({
dataWeights
});
chunk
.
commands
.
forEach
(
command
=>
this
.
applyCommand
(
command
));
}
render
()
{
const
{
className
}
=
this
.
props
;
const
{
dataWeights
}
=
this
.
state
;
return
(
<
ResizableContainer
className
=
{
classes
(
styles
.
visualization_viewer
,
className
)
}
weights
=
{
this
.
datas
.
map
(
data
=>
dataWeights
[
data
.
tracerKey
])
}
visibles
=
{
this
.
datas
.
map
(()
=>
true
)
}
onChangeWeights
=
{
weights
=>
this
.
handleChangeWeights
(
weights
)
}
>
<
div
className
=
{
classes
(
styles
.
visualization_viewer
,
className
)
}
>
{
this
.
datas
.
map
(
data
=>
data
.
render
()
)
this
.
root
&&
this
.
root
.
render
(
)
}
</
ResizableContainer
>
</
div
>
);
}
}
...
...
src/frontend/components/VisualizationViewer/stylesheet.scss
浏览文件 @
c7ec8961
@import
"~/common/stylesheet/index"
;
.visualization_viewer
{
}
\ No newline at end of file
flex
:
1
;
display
:
flex
;
flex-direction
:
column
;
align-items
:
stretch
;
}
src/frontend/core/datas/index.js
已删除
100644 → 0
浏览文件 @
7271b346
export
{
default
as
Data
}
from
'
./Data
'
;
export
{
default
as
MarkdownData
}
from
'
./MarkdownData
'
;
export
{
default
as
LogData
}
from
'
./LogData
'
;
export
{
default
as
Array2DData
}
from
'
./Array2DData
'
;
export
{
default
as
Array1DData
}
from
'
./Array1DData
'
;
export
{
default
as
ChartData
}
from
'
./ChartData
'
;
export
{
default
as
GraphData
}
from
'
./GraphData
'
;
src/frontend/core/layouts/HorizontalLayout.js
0 → 100644
浏览文件 @
c7ec8961
import
{
Layout
}
from
'
/core/layouts
'
;
class
HorizontalLayout
extends
Layout
{
}
export
default
HorizontalLayout
;
src/frontend/core/layouts/Layout.jsx
0 → 100644
浏览文件 @
c7ec8961
import
React
from
'
react
'
;
import
{
ResizableContainer
}
from
'
/components
'
;
import
{
HorizontalLayout
}
from
'
/core/layouts
'
;
class
Layout
{
constructor
(
key
,
getObject
,
children
)
{
this
.
key
=
key
;
this
.
getObject
=
getObject
;
this
.
children
=
children
.
map
(
key
=>
this
.
getObject
(
key
));
this
.
weights
=
children
.
map
(()
=>
1
);
this
.
ref
=
React
.
createRef
();
this
.
handleChangeWeights
=
this
.
handleChangeWeights
.
bind
(
this
);
}
add
(
key
,
index
=
this
.
children
.
length
)
{
const
child
=
this
.
getObject
(
key
);
this
.
children
.
splice
(
index
,
0
,
child
);
this
.
weights
.
splice
(
index
,
0
,
1
);
}
remove
(
key
)
{
const
child
=
this
.
getObject
(
key
);
const
index
=
this
.
children
.
indexOf
(
child
);
if
(
~
index
)
{
this
.
children
.
splice
(
index
,
1
);
this
.
weights
.
splice
(
index
,
1
);
}
}
removeAll
()
{
this
.
children
=
[];
this
.
weights
=
[];
}
handleChangeWeights
(
weights
)
{
this
.
weights
.
splice
(
0
,
this
.
weights
.
length
,
...
weights
);
this
.
ref
.
current
.
forceUpdate
();
}
render
()
{
const
horizontal
=
this
instanceof
HorizontalLayout
;
return
(
<
ResizableContainer
key
=
{
this
.
key
}
ref
=
{
this
.
ref
}
weights
=
{
this
.
weights
}
horizontal
=
{
horizontal
}
onChangeWeights
=
{
this
.
handleChangeWeights
}
>
{
this
.
children
.
map
(
tracer
=>
tracer
&&
tracer
.
render
())
}
</
ResizableContainer
>
);
}
}
export
default
Layout
;
src/frontend/core/layouts/VerticalLayout.js
0 → 100644
浏览文件 @
c7ec8961
import
{
Layout
}
from
'
/core/layouts
'
;
class
VerticalLayout
extends
Layout
{
}
export
default
VerticalLayout
;
src/frontend/core/layouts/index.js
0 → 100644
浏览文件 @
c7ec8961
export
{
default
as
Layout
}
from
'
./Layout
'
;
export
{
default
as
HorizontalLayout
}
from
'
./HorizontalLayout
'
;
export
{
default
as
VerticalLayout
}
from
'
./VerticalLayout
'
;
src/frontend/core/renderers/GraphRenderer/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -7,7 +7,7 @@ class GraphRenderer extends Renderer {
constructor
(
props
)
{
super
(
props
);
this
.
element
=
React
.
createRef
();
this
.
element
Ref
=
React
.
createRef
();
this
.
selectedNode
=
null
;
this
.
togglePan
(
true
);
...
...
@@ -35,7 +35,7 @@ class GraphRenderer extends Renderer {
}
computeCoords
(
e
)
{
const
svg
=
this
.
element
.
current
;
const
svg
=
this
.
element
Ref
.
current
;
const
s
=
svg
.
createSVGPoint
();
s
.
x
=
e
.
clientX
;
s
.
y
=
e
.
clientY
;
...
...
@@ -53,7 +53,7 @@ class GraphRenderer extends Renderer {
baseHeight
*
this
.
zoom
,
];
return
(
<
svg
className
=
{
styles
.
graph
}
viewBox
=
{
viewBox
}
ref
=
{
this
.
element
}
>
<
svg
className
=
{
styles
.
graph
}
viewBox
=
{
viewBox
}
ref
=
{
this
.
element
Ref
}
>
<
defs
>
<
marker
id
=
"markerArrow"
markerWidth
=
"4"
markerHeight
=
"4"
refX
=
"2"
refY
=
"2"
orient
=
"auto"
>
<
path
d
=
"M0,0 L0,4 L4,2 L0,0"
className
=
{
styles
.
arrow
}
/>
...
...
src/frontend/core/renderers/LogRenderer/index.jsx
浏览文件 @
c7ec8961
...
...
@@ -6,12 +6,12 @@ class LogRenderer extends Renderer {
constructor
(
props
)
{
super
(
props
);
this
.
element
=
React
.
createRef
();
this
.
element
Ref
=
React
.
createRef
();
}
componentDidUpdate
(
prevProps
,
prevState
,
snapshot
)
{
super
.
componentDidUpdate
(
prevProps
,
prevState
,
snapshot
);
const
div
=
this
.
element
.
current
;
const
div
=
this
.
element
Ref
.
current
;
div
.
scrollTop
=
div
.
scrollHeight
;
}
...
...
@@ -19,7 +19,7 @@ class LogRenderer extends Renderer {
const
{
log
}
=
this
.
props
.
data
;
return
(
<
div
className
=
{
styles
.
log
}
ref
=
{
this
.
element
}
dangerouslySetInnerHTML
=
{
{
__html
:
log
}
}
/>
<
div
className
=
{
styles
.
log
}
ref
=
{
this
.
element
Ref
}
dangerouslySetInnerHTML
=
{
{
__html
:
log
}
}
/>
);
}
}
...
...
src/frontend/core/
datas/Array1DData
.js
→
src/frontend/core/
tracers/Array1DTracer
.js
浏览文件 @
c7ec8961
import
{
Array2D
Data
}
from
'
/core/data
s
'
;
import
{
Array2D
Tracer
}
from
'
/core/tracer
s
'
;
import
{
Array1DRenderer
}
from
'
/core/renderers
'
;
class
Array1D
Data
extends
Array2DData
{
class
Array1D
Tracer
extends
Array2DTracer
{
getRendererClass
()
{
return
Array1DRenderer
;
}
init
()
{
super
.
init
();
this
.
chart
Data
=
null
;
this
.
chart
Tracer
=
null
;
}
set
(
array1d
=
[])
{
const
array2d
=
[
array1d
];
super
.
set
(
array2d
);
this
.
syncChart
Data
();
this
.
syncChart
Tracer
();
}
patch
(
x
,
v
)
{
...
...
@@ -33,14 +33,14 @@ class Array1DData extends Array2DData {
super
.
deselect
(
0
,
sx
,
0
,
ex
);
}
chart
(
tracerK
ey
)
{
this
.
chart
Data
=
tracerKey
?
this
.
findData
(
tracerK
ey
)
:
null
;
this
.
syncChart
Data
();
chart
(
k
ey
)
{
this
.
chart
Tracer
=
key
?
this
.
getObject
(
k
ey
)
:
null
;
this
.
syncChart
Tracer
();
}
syncChart
Data
()
{
if
(
this
.
chart
Data
)
this
.
chartData
.
data
=
this
.
data
;
syncChart
Tracer
()
{
if
(
this
.
chart
Tracer
)
this
.
chartTracer
.
data
=
this
.
data
;
}
}
export
default
Array1D
Data
;
export
default
Array1D
Tracer
;
src/frontend/core/
datas/Array2DData
.js
→
src/frontend/core/
tracers/Array2DTracer
.js
浏览文件 @
c7ec8961
import
{
Data
}
from
'
/core/data
s
'
;
import
{
Tracer
}
from
'
/core/tracer
s
'
;
import
{
Array2DRenderer
}
from
'
/core/renderers
'
;
class
Element
{
...
...
@@ -9,7 +9,7 @@ class Element {
}
}
class
Array2D
Data
extends
Data
{
class
Array2D
Tracer
extends
Tracer
{
getRendererClass
()
{
return
Array2DRenderer
;
}
...
...
@@ -62,4 +62,4 @@ class Array2DData extends Data {
}
}
export
default
Array2D
Data
;
export
default
Array2D
Tracer
;
src/frontend/core/
datas/ChartData
.js
→
src/frontend/core/
tracers/ChartTracer
.js
浏览文件 @
c7ec8961
import
{
Array1D
Data
}
from
'
/core/data
s
'
;
import
{
Array1D
Tracer
}
from
'
/core/tracer
s
'
;
import
{
ChartRenderer
}
from
'
/core/renderers
'
;
class
Chart
Data
extends
Array1DData
{
class
Chart
Tracer
extends
Array1DTracer
{
getRendererClass
()
{
return
ChartRenderer
;
}
}
export
default
Chart
Data
;
export
default
Chart
Tracer
;
src/frontend/core/
datas/GraphData
.js
→
src/frontend/core/
tracers/GraphTracer
.js
浏览文件 @
c7ec8961
import
{
Data
}
from
'
/core/data
s
'
;
import
{
Tracer
}
from
'
/core/tracer
s
'
;
import
{
distance
}
from
'
/common/util
'
;
import
{
GraphRenderer
}
from
'
/core/renderers
'
;
class
Graph
Data
extends
Data
{
class
Graph
Tracer
extends
Tracer
{
getRendererClass
()
{
return
GraphRenderer
;
}
...
...
@@ -21,7 +21,7 @@ class GraphData extends Data {
this
.
isDirected
=
true
;
this
.
isWeighted
=
false
;
this
.
callLayout
=
{
method
:
this
.
layoutCircle
,
args
:
[]
};
this
.
log
Data
=
null
;
this
.
log
Tracer
=
null
;
}
set
(
array2d
=
[])
{
...
...
@@ -230,8 +230,8 @@ class GraphData extends Data {
const
node
=
this
.
findNode
(
target
);
if
(
weight
!==
undefined
)
node
.
weight
=
weight
;
node
.
visitedCount
+=
visit
?
1
:
-
1
;
if
(
this
.
log
Data
)
{
this
.
log
Data
.
println
(
visit
?
(
source
||
''
)
+
'
->
'
+
target
:
(
source
||
''
)
+
'
<-
'
+
target
);
if
(
this
.
log
Tracer
)
{
this
.
log
Tracer
.
println
(
visit
?
(
source
||
''
)
+
'
->
'
+
target
:
(
source
||
''
)
+
'
<-
'
+
target
);
}
}
...
...
@@ -248,14 +248,14 @@ class GraphData extends Data {
if
(
edge
)
edge
.
selectedCount
+=
select
?
1
:
-
1
;
const
node
=
this
.
findNode
(
target
);
node
.
selectedCount
+=
select
?
1
:
-
1
;
if
(
this
.
log
Data
)
{
this
.
log
Data
.
println
(
select
?
(
source
||
''
)
+
'
=>
'
+
target
:
(
source
||
''
)
+
'
<=
'
+
target
);
if
(
this
.
log
Tracer
)
{
this
.
log
Tracer
.
println
(
select
?
(
source
||
''
)
+
'
=>
'
+
target
:
(
source
||
''
)
+
'
<=
'
+
target
);
}
}
log
(
tracerK
ey
)
{
this
.
log
Data
=
tracerKey
?
this
.
findData
(
tracerK
ey
)
:
null
;
log
(
k
ey
)
{
this
.
log
Tracer
=
key
?
this
.
getObject
(
k
ey
)
:
null
;
}
}
export
default
Graph
Data
;
export
default
Graph
Tracer
;
src/frontend/core/
datas/LogData
.js
→
src/frontend/core/
tracers/LogTracer
.js
浏览文件 @
c7ec8961
import
{
sprintf
}
from
'
sprintf-js
'
;
import
{
Data
}
from
'
/core/data
s
'
;
import
{
Tracer
}
from
'
/core/tracer
s
'
;
import
{
LogRenderer
}
from
'
/core/renderers
'
;
class
Log
Data
extends
Data
{
class
Log
Tracer
extends
Tracer
{
getRendererClass
()
{
return
LogRenderer
;
}
...
...
@@ -25,4 +25,4 @@ class LogData extends Data {
}
}
export
default
Log
Data
;
export
default
Log
Tracer
;
src/frontend/core/
datas/MarkdownData
.js
→
src/frontend/core/
tracers/MarkdownTracer
.js
浏览文件 @
c7ec8961
import
{
Data
}
from
'
/core/data
s
'
;
import
{
Tracer
}
from
'
/core/tracer
s
'
;
import
{
MarkdownRenderer
}
from
'
/core/renderers
'
;
class
Markdown
Data
extends
Data
{
class
Markdown
Tracer
extends
Tracer
{
getRendererClass
()
{
return
MarkdownRenderer
;
}
...
...
@@ -12,4 +12,4 @@ class MarkdownData extends Data {
}
}
export
default
Markdown
Data
;
export
default
Markdown
Tracer
;
src/frontend/core/
datas/Data
.jsx
→
src/frontend/core/
tracers/Tracer
.jsx
浏览文件 @
c7ec8961
import
React
from
'
react
'
;
import
{
Renderer
}
from
'
/core/renderers
'
;
class
Data
{
constructor
(
tracerKey
,
title
,
datas
)
{
this
.
tracerKey
=
tracerKey
;
class
Tracer
{
constructor
(
key
,
getObject
,
title
=
this
.
constructor
.
name
)
{
this
.
key
=
key
;
this
.
getObject
=
getObject
;
this
.
title
=
title
;
this
.
datas
=
datas
;
this
.
init
();
this
.
reset
();
}
findData
(
tracerKey
)
{
return
this
.
datas
.
find
(
data
=>
data
.
tracerKey
===
tracerKey
);
}
getRendererClass
()
{
return
Renderer
;
}
...
...
@@ -24,7 +20,7 @@ class Data {
render
()
{
const
RendererClass
=
this
.
getRendererClass
();
return
(
<
RendererClass
key
=
{
this
.
tracerK
ey
}
title
=
{
this
.
title
}
data
=
{
this
}
/>
<
RendererClass
key
=
{
this
.
k
ey
}
title
=
{
this
.
title
}
data
=
{
this
}
/>
);
}
...
...
@@ -36,4 +32,4 @@ class Data {
}
}
export
default
Data
;
export
default
Tracer
;
src/frontend/core/tracers/index.js
0 → 100644
浏览文件 @
c7ec8961
export
{
default
as
Tracer
}
from
'
./Tracer
'
;
export
{
default
as
MarkdownTracer
}
from
'
./MarkdownTracer
'
;
export
{
default
as
LogTracer
}
from
'
./LogTracer
'
;
export
{
default
as
Array2DTracer
}
from
'
./Array2DTracer
'
;
export
{
default
as
Array1DTracer
}
from
'
./Array1DTracer
'
;
export
{
default
as
ChartTracer
}
from
'
./ChartTracer
'
;
export
{
default
as
GraphTracer
}
from
'
./GraphTracer
'
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录