Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
52b2c282
Commit
52b2c282
authored
Jan 09, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed the analyze rule
parent
9be1c436
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
19 deletions
+68
-19
dev.html
demo/dev.html
+8
-8
layout.js
src/module/layout.js
+60
-11
No files found.
demo/dev.html
View file @
52b2c282
...
@@ -42,13 +42,13 @@
...
@@ -42,13 +42,13 @@
minder
.
execCommand
(
"rendernode"
,
_root
);
minder
.
execCommand
(
"rendernode"
,
_root
);
//模拟生成一个初始图
//模拟生成一个初始图
for
(
var
j
=
0
;
j
<
20
;
j
++
){
//
for(var j=0;j
<
20
;
j
++
){
var
appendSide
=
Math
.
random
()
>
0.5
?
"left"
:
"right"
;
//
var appendSide = Math.random()>0.5?"left":"right";
var
layerArray
=
_root
.
getData
(
"layer"
+
appendSide
);
//
var layerArray = _root.getData("layer"+appendSide);
var
layer
=
parseInt
(
Math
.
random
()
*
layerArray
.
length
);
//
var layer = parseInt(Math.random()*layerArray.length);
var
layerData
=
layerArray
[
layer
];
//
var layerData = layerArray[layer];
var
root
=
layerData
[
parseInt
(
Math
.
random
()
*
layerData
.
length
)]
//
var root = layerData[parseInt(Math.random()*layerData.length)]
minder
.
execCommand
(
"createchildnode"
,
root
);
//
minder.execCommand("createchildnode",root);
}
//
}
</script>
</script>
</html>
</html>
\ No newline at end of file
src/module/layout.js
View file @
52b2c282
...
@@ -48,6 +48,9 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -48,6 +48,9 @@ KityMinder.registerModule( "LayoutModule", function () {
}
while
(
parent
);
}
while
(
parent
);
return
true
;
return
true
;
}
}
};
var
updateBranchWidth
=
function
(
node
,
appendSide
)
{
};
};
var
reAnalyze
=
function
(
km
,
layerArray
,
appendSide
)
{
var
reAnalyze
=
function
(
km
,
layerArray
,
appendSide
)
{
for
(
var
lv
=
0
;
lv
<
layerArray
.
length
;
lv
++
)
{
for
(
var
lv
=
0
;
lv
<
layerArray
.
length
;
lv
++
)
{
...
@@ -67,6 +70,19 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -67,6 +70,19 @@ KityMinder.registerModule( "LayoutModule", function () {
}
}
}
}
};
};
var
getX
=
function
(
node
)
{
var
parent
=
node
.
getParent
();
var
parentX
=
parent
.
getData
(
"x"
);
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
var
side
=
node
.
getData
(
"appendside"
);
if
(
side
===
"left"
)
{
node
.
setData
(
"x"
,
parentX
-
parentWidth
-
50
);
}
else
{
node
.
setData
(
"x"
,
parentX
+
parentWidth
+
50
);
}
};
var
createChildNode
=
function
(
km
,
parent
,
index
)
{
var
createChildNode
=
function
(
km
,
parent
,
index
)
{
var
root
=
km
.
getRoot
();
var
root
=
km
.
getRoot
();
var
appendSide
=
parent
.
getData
(
"appendside"
);
var
appendSide
=
parent
.
getData
(
"appendside"
);
...
@@ -76,16 +92,6 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -76,16 +92,6 @@ KityMinder.registerModule( "LayoutModule", function () {
_node
.
setData
(
"appendside"
,
appendSide
);
_node
.
setData
(
"appendside"
,
appendSide
);
if
(
parent
===
root
)
{
var
childCount
=
parent
.
getChildren
().
length
;
console
.
log
(
childCount
);
if
(
isOdd
(
parseInt
(
childCount
/
5
)
)
)
{
root
.
setData
(
"appendside"
,
"left"
);
}
else
{
root
.
setData
(
"appendside"
,
"right"
);
}
}
var
parentX
=
parent
.
getData
(
"x"
);
var
parentX
=
parent
.
getData
(
"x"
);
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
...
@@ -145,6 +151,20 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -145,6 +151,20 @@ KityMinder.registerModule( "LayoutModule", function () {
}
}
layerData
.
splice
(
insertPos
,
0
,
_node
);
layerData
.
splice
(
insertPos
,
0
,
_node
);
if
(
parent
===
root
)
{
var
leftCount
=
parent
.
getData
(
"layerleft"
);
var
rightCount
=
parent
.
getData
(
"layerright"
);
leftCount
=
leftCount
[
1
]
?
leftCount
[
1
].
length
:
0
;
rightCount
=
rightCount
[
1
]
?
rightCount
[
1
].
length
:
0
;
console
.
log
(
leftCount
,
rightCount
);
if
(
rightCount
>
leftCount
&&
rightCount
>
1
)
{
parent
.
setData
(
"appendside"
,
"left"
);
}
else
{
parent
.
setData
(
"appendside"
,
"right"
);
}
}
var
reAnal
=
updateBranchHeight
(
_node
,
appendSide
,
root
,
true
);
var
reAnal
=
updateBranchHeight
(
_node
,
appendSide
,
root
,
true
);
//判断是重绘全部还是只是添加节点
//判断是重绘全部还是只是添加节点
if
(
reAnal
)
{
if
(
reAnal
)
{
...
@@ -167,7 +187,11 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -167,7 +187,11 @@ KityMinder.registerModule( "LayoutModule", function () {
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
sibling
)
{
execute
:
function
(
km
,
sibling
)
{
var
root
=
km
.
getRoot
();
var
parent
=
sibling
.
getParent
();
var
parent
=
sibling
.
getParent
();
if
(
parent
===
root
)
{
parent
.
setData
(
"appendside"
,
sibling
.
getData
(
"appendside"
)
);
}
var
index
=
sibling
.
getIndex
()
+
1
;
var
index
=
sibling
.
getIndex
()
+
1
;
if
(
parent
)
{
if
(
parent
)
{
return
createChildNode
(
km
,
parent
,
index
);
return
createChildNode
(
km
,
parent
,
index
);
...
@@ -218,11 +242,36 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -218,11 +242,36 @@ KityMinder.registerModule( "LayoutModule", function () {
}
}
};
};
}
)()
);
}
)()
);
var
UpdateNodeCommand
=
kity
.
createClass
(
"UpdateNodeCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
,
node
,
feature
)
{
var
_root
=
km
.
getRoot
();
var
rerender
=
false
;
for
(
var
key
in
feature
)
{
node
.
setData
(
"key"
,
feature
[
key
]
);
if
(
key
===
"text"
)
{
rerender
=
true
;
}
}
if
(
rerender
)
{
km
.
execCommand
(
"rendernode"
,
node
);
node
.
preTraverse
(
function
(
subnode
)
{
subnode
.
setData
(
"x"
,
getX
(
subnode
)
);
km
.
execCommand
(
"rendernode"
,
subnode
);
}
);
}
}
};
}
)()
);
return
{
return
{
"commands"
:
{
"commands"
:
{
"createchildnode"
:
CreateChildNodeCommand
,
"createchildnode"
:
CreateChildNodeCommand
,
"createsiblingnode"
:
CreateSiblingNodeCommand
,
"createsiblingnode"
:
CreateSiblingNodeCommand
,
"removenode"
:
RemoveNodeCommand
"removenode"
:
RemoveNodeCommand
,
"updatenode"
:
UpdateNodeCommand
},
},
"events"
:
{
"events"
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment