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
94f12382
Commit
94f12382
authored
Jan 17, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构了layout相关的内容
parent
0f1ab1e3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
279 additions
and
350 deletions
+279
-350
dev.html
demo/dev.html
+6
-0
dev.php
dist/dev.php
+1
-7
minder.command.js
src/core/minder.command.js
+1
-1
minder.js
src/core/minder.js
+8
-0
minder.select.js
src/core/minder.select.js
+30
-29
layout.default.js
src/module/layout.default.js
+218
-301
layout.js
src/module/layout.js
+15
-12
No files found.
demo/dev.html
View file @
94f12382
...
@@ -16,5 +16,11 @@
...
@@ -16,5 +16,11 @@
<script>
<script>
minder
=
KM
.
createMinder
(
kityminder
);
minder
=
KM
.
createMinder
(
kityminder
);
minder
.
execCommand
(
"switchlayout"
,
"default"
);
minder
.
execCommand
(
"switchlayout"
,
"default"
);
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
</script>
</script>
</html>
</html>
\ No newline at end of file
dist/dev.php
View file @
94f12382
...
@@ -13,18 +13,12 @@ $dependency = Array(
...
@@ -13,18 +13,12 @@ $dependency = Array(
'src/core/minder.module.js'
,
'src/core/minder.module.js'
,
'src/core/minder.command.js'
,
'src/core/minder.command.js'
,
'src/core/minder.node.js'
,
'src/core/minder.node.js'
,
'src/core/minder.select.js'
,
'src/module/history.js'
,
'src/module/history.js'
,
'src/module/icon.js'
,
'src/module/icon.js'
,
'src/module/layout.js'
,
'src/module/layout.js'
,
'src/module/layout.default.js'
,
'src/module/layout.default.js'
,
'src/module/layout.green.js'
,
'src/module/layout.green.js'
,
'src/module/mouse.js'
,
'src/core/minder.select.js'
,
'src/module/keyboard.js'
,
'src/module/editor.js'
,
'src/module/editor.cursor.js'
,
'src/module/editor.range.js'
,
'src/module/editor.receiver.js'
);
);
$content
=
""
;
$content
=
""
;
...
...
src/core/minder.command.js
View file @
94f12382
...
@@ -24,7 +24,7 @@ kity.extendClass( Minder, {
...
@@ -24,7 +24,7 @@ kity.extendClass( Minder, {
execCommand
:
function
(
name
)
{
execCommand
:
function
(
name
)
{
name
=
name
.
toLowerCase
();
name
=
name
.
toLowerCase
();
var
cmdArgs
=
utils
.
argsToArray
(
arguments
,
1
),
var
cmdArgs
=
Utils
.
argsToArray
(
arguments
,
1
),
cmd
,
stoped
,
result
,
eventParams
;
cmd
,
stoped
,
result
,
eventParams
;
var
me
=
this
;
var
me
=
this
;
cmd
=
this
.
_getCommand
(
name
);
cmd
=
this
.
_getCommand
(
name
);
...
...
src/core/minder.js
View file @
94f12382
...
@@ -15,6 +15,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
...
@@ -15,6 +15,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor
:
function
(
options
)
{
constructor
:
function
(
options
)
{
this
.
_options
=
Utils
.
extend
(
window
.
KITYMINDER_CONFIG
||
{},
MinderDefaultOptions
,
options
);
this
.
_options
=
Utils
.
extend
(
window
.
KITYMINDER_CONFIG
||
{},
MinderDefaultOptions
,
options
);
this
.
_layoutStyles
=
{};
this
.
_layoutStyles
=
{};
this
.
_currentStyle
=
""
;
this
.
_initEvents
();
this
.
_initEvents
();
this
.
_initMinder
();
this
.
_initMinder
();
this
.
_initSelection
();
this
.
_initSelection
();
...
@@ -54,6 +55,13 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
...
@@ -54,6 +55,13 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
getLayoutStyle
:
function
(
name
)
{
getLayoutStyle
:
function
(
name
)
{
return
this
.
_layoutStyles
[
name
];
return
this
.
_layoutStyles
[
name
];
},
},
getCurrentStyle
:
function
()
{
return
this
.
_currentStyle
;
},
setCurrentStyle
:
function
(
name
)
{
this
.
_currentStyle
=
name
;
return
name
;
},
getRenderTarget
:
function
()
{
getRenderTarget
:
function
()
{
return
this
.
_renderTarget
;
return
this
.
_renderTarget
;
}
}
...
...
src/core/minder.select.js
View file @
94f12382
// 选区管理
// 选区管理
kity
.
extendClass
(
Minder
,
function
()
{
kity
.
extendClass
(
Minder
,
function
()
{
function
highlightNode
(
km
,
node
)
{
function
highlightNode
(
km
,
node
)
{
node
.
setData
(
"highlight"
,
true
);
node
.
setData
(
"highlight"
,
true
);
km
.
renderNode
(
node
);
km
.
renderNode
(
node
);
}
}
function
unhighlightNode
(
km
,
node
){
function
unhighlightNode
(
km
,
node
)
{
node
.
setData
(
"highlight"
,
false
);
node
.
setData
(
"highlight"
,
false
);
km
.
renderNode
(
node
);
km
.
renderNode
(
node
);
}
}
...
@@ -14,52 +15,52 @@ kity.extendClass( Minder, function(){
...
@@ -14,52 +15,52 @@ kity.extendClass( Minder, function(){
},
},
getSelectedNodes
:
function
()
{
getSelectedNodes
:
function
()
{
//如果没有选中节点,默认是root节点
//如果没有选中节点,默认是root节点
if
(
this
.
_selectedNodes
.
length
==
0
)
{
if
(
this
.
_selectedNodes
.
length
===
0
)
{
this
.
_selectedNodes
.
push
(
this
.
getRoot
())
this
.
_selectedNodes
.
push
(
this
.
getRoot
()
);
}
}
//不能克隆返回,会对当前选区操作,从而影响querycommand
//不能克隆返回,会对当前选区操作,从而影响querycommand
return
this
.
_selectedNodes
;
return
this
.
_selectedNodes
;
},
},
getSelectedNode
:
function
()
{
getSelectedNode
:
function
()
{
return
this
.
getSelectedNodes
()[
0
]
return
this
.
getSelectedNodes
()[
0
];
},
},
removeAllSelectedNodes
:
function
()
{
removeAllSelectedNodes
:
function
()
{
utils
.
each
(
this
.
getSelectedNodes
(),
function
(
i
,
n
)
{
Utils
.
each
(
this
.
getSelectedNodes
(),
function
(
i
,
n
)
{
unhighlightNode
(
this
,
n
);
unhighlightNode
(
this
,
n
);
});
}
);
this
.
_selectedNodes
=
[]
this
.
_selectedNodes
=
[]
;
},
},
select
:
function
(
nodes
)
{
select
:
function
(
nodes
)
{
this
.
removeAllSelectedNodes
();
this
.
removeAllSelectedNodes
();
var
me
=
this
;
var
me
=
this
;
utils
.
each
(
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
],
function
(
i
,
n
)
{
utils
.
each
(
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
],
function
(
i
,
n
)
{
me
.
_selectedNodes
.
push
(
n
);
me
.
_selectedNodes
.
push
(
n
);
highlightNode
(
this
,
n
)
highlightNode
(
this
,
n
);
});
}
);
return
this
;
return
this
;
},
},
isNodeSelected
:
function
(
node
)
{
isNodeSelected
:
function
(
node
)
{
return
node
.
getData
(
'highlight'
)
===
true
return
node
.
getData
(
'highlight'
)
===
true
},
},
//当前选区中的节点在给定的节点范围内的保留选中状态,没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
//当前选区中的节点在给定的节点范围内的保留选中状态,没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect
:
function
(
nodes
)
{
toggleSelect
:
function
(
nodes
)
{
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
var
selectedNodes
=
this
.
getSelectedNodes
().
slice
(
0
);
var
selectedNodes
=
this
.
getSelectedNodes
().
slice
(
0
);
this
.
removeAllSelectedNodes
();
this
.
removeAllSelectedNodes
();
for
(
var
i
=
0
,
n
;
n
=
selectedNodes
[
i
];)
{
for
(
var
i
=
0
,
n
;
n
=
selectedNodes
[
i
];
)
{
var
index
=
utils
.
indexOf
(
nodes
,
n
);
var
index
=
utils
.
indexOf
(
nodes
,
n
);
if
(
index
!=
-
1
)
{
if
(
index
!=
-
1
)
{
nodes
.
push
(
n
);
nodes
.
push
(
n
);
i
++
;
i
++
;
}
else
{
}
else
{
unhighlightNode
(
this
,
n
);
unhighlightNode
(
this
,
n
);
selectedNodes
.
splice
(
i
,
1
)
selectedNodes
.
splice
(
i
,
1
)
}
}
}
}
var
me
=
this
;
var
me
=
this
;
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
highlightNode
(
me
,
n
)
highlightNode
(
me
,
n
)
});
}
);
this
.
_selectedNodes
=
nodes
;
this
.
_selectedNodes
=
nodes
;
}
}
}
}
...
...
src/module/layout.default.js
View file @
94f12382
KityMinder
.
registerModule
(
"LayoutDefault"
,
function
()
{
KityMinder
.
registerModule
(
"LayoutDefault"
,
function
()
{
var
defaultHeight
=
35
;
var
_target
=
this
.
getRenderTarget
();
var
_target
=
this
.
getRenderTarget
();
var
minderWidth
=
_target
.
clientWidth
;
var
minderWidth
=
_target
.
clientWidth
;
var
minderHeight
=
_target
.
clientHeight
;
var
minderHeight
=
_target
.
clientHeight
;
var
minder
=
this
;
var
ConnectBezier
=
kity
.
createClass
(
"ConnectBezier"
,
(
function
()
{
var
ConnectBezier
=
kity
.
createClass
(
"ConnectBezier"
,
(
function
()
{
function
mid
(
a
,
b
)
{
function
mid
(
a
,
b
)
{
return
(
a
+
b
)
/
2
;
return
(
a
+
b
)
/
2
;
...
@@ -137,292 +136,200 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -137,292 +136,200 @@ KityMinder.registerModule( "LayoutDefault", function () {
}
}
};
};
}
)()
);
}
)()
);
var
nodeDefautStyle
=
{
var
updateConnect
=
function
(
minder
,
nodes
,
action
)
{
radius
:
10
,
switch
(
action
)
{
fill
:
"skyblue"
,
case
"rendernode"
:
stroke
:
"orange"
,
(
function
()
{
color
:
"black"
,
if
(
!
(
nodes
instanceof
Array
)
)
{
padding
:
[
5
,
10
,
5
,
10
],
nodes
=
[
nodes
];
fontSize
:
20
,
}
margin
:
[
0
,
10
,
10
,
50
]
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
var
curnode
=
nodes
[
i
];
if
(
!
curnode
.
getParent
()
)
{
return
false
;
}
else
{
var
parent
=
curnode
.
getParent
();
var
connectExist
=
curnode
.
getData
(
"connect"
);
if
(
connectExist
)
{
connectExist
.
updateConnection
();
}
else
{
var
_connect
=
new
ConnectBezier
(
parent
.
getRenderContainer
(),
curnode
.
getRenderContainer
()
);
var
nodeD
=
curnode
.
getData
(
"style"
);
_connect
.
stroke
(
new
kity
.
Pen
(
nodeD
.
stroke
,
nodeD
.
strokeWidth
)
);
curnode
.
setData
(
"connect"
,
_connect
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
}
}
}
}
)();
break
;
case
"removenode"
:
(
function
()
{
if
(
(
nodes
instanceof
Array
)
===
false
)
{
nodes
=
[
nodes
];
}
function
removeConnect
(
node
)
{
var
connect
=
node
.
_connect
;
if
(
connect
&&
connect
.
remove
)
{
connect
.
remove
();
}
}
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
nodes
[
i
].
traverse
(
removeConnect
);
}
}
)();
}
};
};
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
var
updateBranchHeight
=
function
(
node
,
appendSide
,
root
,
isAdd
,
oldParent
)
{
return
{
var
siblings
=
(
function
()
{
constructor
:
function
(
node
)
{
if
(
!
isAdd
)
{
var
txt
=
new
kity
.
Text
();
return
oldParent
.
getChildren
();
var
rect
=
new
kity
.
Rect
();
}
else
if
(
parent
===
root
)
{
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
return
root
.
getData
(
"layer"
+
appendSide
)[
1
];
node
.
setData
(
"style"
,
Utils
.
extend
(
ND
,
node
.
getData
(
"style"
)
)
);
}
else
{
var
_style
=
node
.
getData
(
"style"
);
return
node
.
getParent
().
getChildren
();
var
container
=
node
.
getRenderContainer
();
}
container
.
addShapes
(
[
rect
,
txt
]
);
}
)();
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
parent
=
isAdd
?
node
.
getParent
()
:
oldParent
;
var
_txtHeight
=
txt
.
getHeight
();
node
.
setData
(
"branchheight"
,
defaultHeight
+
10
);
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
if
(
isAdd
)
{
var
_rectWidth
=
_style
.
padding
[
1
]
+
_style
.
padding
[
3
]
+
txt
.
getWidth
();
var
add
=
(
(
siblings
.
length
===
1
&&
node
.
getParent
()
!==
root
)
?
0
:
(
defaultHeight
+
10
)
);
var
_rectHeight
=
_style
.
padding
[
0
]
+
_style
.
padding
[
2
]
+
_txtHeight
;
while
(
parent
||
(
parent
===
root
)
)
{
rect
.
fill
(
_style
.
fill
).
stroke
(
_style
.
stroke
).
setRadius
(
_style
.
radius
).
setWidth
(
_rectWidth
).
setHeight
(
_rectHeight
);
var
branchheight
=
parent
.
getData
(
appendSide
+
"Height"
)
||
parent
.
getData
(
"branchheight"
)
||
0
;
if
(
node
.
highlight
)
{
if
(
parent
===
root
)
{
rect
.
stroke
(
new
kity
.
Pen
(
"white"
,
3
)
);
parent
.
setData
(
appendSide
+
"Height"
,
branchheight
+
add
);
}
else
{
parent
.
setData
(
"branchheight"
,
branchheight
+
add
);
}
}
parent
=
parent
.
getParent
();
}
if
(
siblings
.
length
===
1
)
{
return
false
;
}
else
{
return
true
;
}
}
};
}
)()
);
var
root
=
this
.
getRoot
();
//更新连线
var
updateConnect
=
function
(
minder
,
node
,
action
)
{
var
_style
=
node
.
getData
(
"style"
);
if
(
!
node
.
getParent
()
)
return
false
;
var
start
=
node
.
getParent
().
getRenderContainer
();
var
end
=
node
.
getRenderContainer
();
var
_connect
=
node
.
getData
(
"connect"
);
if
(
action
===
"remove"
)
{
_connect
.
remove
();
}
else
{
}
else
{
var
dec
=
node
.
getData
(
"branchheight"
);
if
(
_connect
)
_connect
.
updateConnection
();
do
{
else
{
var
branchheight2
=
parent
.
getData
(
appendSide
+
"Height"
)
||
parent
.
getData
(
"branchheight"
)
||
0
;
_connect
=
new
ConnectBezier
(
start
,
end
);
if
(
parent
===
root
)
{
node
.
setData
(
"connect"
,
_connect
);
parent
.
setData
(
appendSide
+
"Height"
,
branchheight2
-
dec
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
}
else
{
_connect
.
stroke
(
_style
.
stroke
);
parent
.
setData
(
"branchheight"
,
branchheight2
-
dec
);
}
}
parent
=
parent
.
getParent
();
}
while
(
parent
);
return
true
;
}
}
};
};
//求并集
var
reAnalyze
=
function
(
km
,
layerArray
,
appendSide
)
{
var
uSet
=
function
(
a
,
b
)
{
for
(
var
lv
=
0
;
lv
<
layerArray
.
length
;
lv
++
)
{
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
var
lvData
=
layerArray
[
lv
];
var
idx
=
b
.
indexOf
(
a
[
i
]
);
for
(
var
i
=
0
;
i
<
lvData
.
length
;
i
++
)
{
if
(
idx
!==
-
1
)
{
var
children
=
(
lv
===
0
?
layerArray
[
1
]
:
lvData
[
i
].
getChildren
()
);
b
.
splice
(
idx
,
1
);
if
(
!
children
||
children
.
length
===
0
)
continue
;
var
branchheight
=
lvData
[
i
].
getData
(
appendSide
+
"Height"
)
||
lvData
[
i
].
getData
(
"branchheight"
);
var
sY
=
lvData
[
i
].
getData
(
"y"
)
+
(
children
[
0
].
getData
(
"branchheight"
)
-
branchheight
)
/
2
;
for
(
var
j
=
0
;
j
<
children
.
length
;
j
++
)
{
children
[
j
].
setData
(
"y"
,
sY
);
var
part1
=
(
children
[
j
].
getData
(
"branchheight"
)
-
10
)
/
2
+
10
;
var
part2
=
(
children
[
j
+
1
]
?
(
children
[
j
+
1
].
getData
(
"branchheight"
)
-
10
)
/
2
:
0
);
sY
+=
(
part1
+
part2
);
}
km
.
renderNodes
(
children
);
}
}
}
}
return
a
.
concat
(
b
);
};
};
//绘制node
var
createChildNode
=
function
(
km
,
parent
,
index
)
{
var
drawNode
=
function
(
node
)
{
var
root
=
km
.
getRoot
();
var
container
=
node
.
getRenderContainer
();
var
appendSide
=
parent
.
getData
(
"appendside"
);
container
.
clear
();
var
_node
=
new
MinderNode
();
var
shape
=
new
MinderNodeShape
(
node
);
_node
.
setData
(
"branchheight"
,
0
);
updateConnect
(
minder
,
node
);
parent
.
insertChild
(
_node
,
index
);
};
//调整node的位置
_node
.
setData
(
"appendside"
,
appendSide
);
var
translateNode
=
function
(
node
)
{
var
_style
=
node
.
_style
;
var
parentX
=
parent
.
getData
(
"x"
);
var
nodeShape
=
node
.
getRenderContainer
();
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
var
align
=
node
.
getData
(
"align"
);
if
(
parent
.
getData
(
"align"
)
===
"center"
)
parentWidth
=
parentWidth
/
2
;
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectWidth
=
nodeShape
.
getWidth
();
switch
(
appendSide
)
{
switch
(
align
)
{
case
"left"
:
_node
.
setData
(
"x"
,
parentX
-
parentWidth
-
50
);
_node
.
setData
(
"align"
,
"right"
);
break
;
case
"right"
:
case
"right"
:
_node
.
setData
(
"x"
,
parentX
+
parentWidth
+
50
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
_node
.
setData
(
"align"
,
"left"
);
break
;
case
"center"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
break
;
default
:
default
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
break
;
}
}
updateConnect
(
minder
,
node
);
};
var
layer
=
parent
.
getData
(
"layer"
)
+
1
;
//以某个节点为seed对整体高度进行更改计算
var
layerArray
=
root
.
getData
(
"layer"
+
appendSide
);
var
updateLayoutVertical
=
function
(
node
,
parent
,
action
)
{
layerArray
[
layer
]
=
layerArray
[
layer
]
||
[];
var
effectSet
=
[];
//用于返回受影响的节点集
var
layerData
=
layerArray
[
layer
];
if
(
!
parent
)
{
var
insertPos
=
0
;
return
[
node
];
_node
.
setData
(
"layer"
,
layer
);
}
var
_style
=
node
.
getData
(
"style"
);
//遍历层级链
var
marginTop
=
_style
.
margin
[
0
],
var
getIndexList
=
function
(
node
)
{
marginBottom
=
_style
.
margin
[
2
];
var
indexList
=
[];
var
appendside
=
node
.
getData
(
"appendside"
);
var
parent
=
node
;
var
branchheight
=
node
.
getData
(
"branchheight"
)
||
node
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
do
{
var
countY
=
function
(
node
,
appendside
)
{
indexList
.
push
(
parent
.
getIndex
()
);
var
centerY
=
node
.
getData
(
"y"
);
parent
=
parent
.
getParent
();
var
nodeBranchHeight
=
node
.
getData
(
appendside
+
"Height"
)
||
node
.
getData
(
"branchheight"
);
}
while
(
parent
);
var
nodeChildren
=
node
.
getData
(
appendside
+
"List"
)
||
node
.
getChildren
();
return
indexList
.
reverse
();
if
(
node
===
root
)
{
};
console
.
log
(
nodeChildren
);
//比较两个层级链的大小
var
indexLarger
=
function
(
List1
,
List2
)
{
var
larger
=
true
;
for
(
var
i
=
0
;
i
<
List1
.
length
;
i
++
)
{
if
(
List1
[
i
]
==
List2
[
i
]
)
{
continue
;
}
if
(
List1
[
i
]
<
List2
[
i
]
)
{
larger
=
false
;
}
break
;
}
}
return
larger
;
var
sY
=
centerY
-
nodeBranchHeight
/
2
;
for
(
var
i
=
0
;
i
<
nodeChildren
.
length
;
i
++
)
{
var
childBranchHeight
=
nodeChildren
[
i
].
getData
(
"branchheight"
);
nodeChildren
[
i
].
setData
(
"y"
,
sY
+
marginTop
+
childBranchHeight
/
2
);
sY
+=
childBranchHeight
;
}
return
nodeChildren
;
};
};
//选定合适的位置插入节点
if
(
action
!==
"remove"
)
{
for
(
var
l
=
layerData
.
length
-
1
;
l
>=
0
;
l
--
)
{
node
.
setData
(
"branchheight"
,
branchheight
);
var
nodeIndexList
=
getIndexList
(
_node
);
if
(
!
indexLarger
(
getIndexList
(
layerData
[
l
]
),
nodeIndexList
)
)
{
insertPos
=
l
+
1
;
break
;
}
}
}
var
siblings
=
parent
.
getData
(
appendside
+
"List"
)
||
parent
.
getChildren
();
layerData
.
splice
(
insertPos
,
0
,
_node
);
var
getActualHeight
=
function
(
node
,
appendside
)
{
var
sum
=
0
;
if
(
parent
===
root
)
{
var
children
=
node
.
getData
(
appendside
+
"List"
)
||
node
.
getChildren
();
var
leftCount
=
parent
.
getData
(
"layerleft"
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
rightCount
=
parent
.
getData
(
"layerright"
);
sum
+=
children
[
i
].
getData
(
"branchheight"
);
leftCount
=
leftCount
[
1
]
?
leftCount
[
1
].
length
:
0
;
rightCount
=
rightCount
[
1
]
?
rightCount
[
1
].
length
:
0
;
if
(
rightCount
>
leftCount
&&
rightCount
>
1
)
{
parent
.
setData
(
"appendside"
,
"left"
);
}
else
{
parent
.
setData
(
"appendside"
,
"right"
);
}
}
}
return
sum
;
};
//方案:
//增加节点时:1.节点和大于1
//删除节点时:1.剩余节点和大于等于1
if
(
(
action
===
"remove"
&&
siblings
.
length
>
0
)
||
siblings
.
length
>
1
)
{
//更新branchheight
var
prt
=
parent
;
do
{
var
minH
=
prt
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
actualH
=
getActualHeight
(
prt
,
appendside
);
var
branchH
=
(
minH
>
actualH
?
minH
:
actualH
);
var
reAnal
=
updateBranchHeight
(
_node
,
appendSide
,
root
,
true
);
if
(
prt
.
getParent
()
)
{
//判断是重绘全部还是只是添加节点
prt
.
setData
(
"branchheight"
,
branchH
);
if
(
reAnal
)
{
}
else
{
reAnalyze
(
km
,
layerArray
,
appendSide
);
prt
.
setData
(
appendside
+
"Height"
,
branchH
);
}
else
{
}
_node
.
setData
(
"y"
,
_node
.
getParent
().
getData
(
"y"
)
);
prt
=
prt
.
getParent
();
km
.
renderNode
(
_node
);
}
while
(
prt
);
//遍历
var
effectRange
=
[
root
];
var
_buffer
=
effectRange
;
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
countY
(
_buffer
[
0
],
appendside
)
);
effectSet
.
push
(
_buffer
[
0
]
);
_buffer
.
shift
();
}
}
else
if
(
action
!==
"remove"
)
{
node
.
setData
(
"y"
,
parent
.
getData
(
"y"
)
);
effectSet
=
[
node
];
}
}
return
_node
;
return
effectSet
;
};
};
var
setX
=
function
(
node
)
{
//以某个节点为seed对水平方向进行调整
var
parent
=
node
.
getParent
();
var
updateLayoutHorizon
=
function
(
node
)
{
if
(
!
parent
)
return
false
;
var
effectSet
=
[];
var
parentX
=
parent
.
getData
(
"x"
);
if
(
!
node
.
getParent
()
)
{
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
return
[
node
];
if
(
parent
.
getData
(
"align"
)
===
"center"
)
{
parentWidth
=
parentWidth
/
2
;
}
var
side
=
node
.
getData
(
"appendside"
);
if
(
side
===
"left"
)
{
node
.
setData
(
"x"
,
parentX
-
parentWidth
-
50
);
}
else
{
node
.
setData
(
"x"
,
parentX
+
parentWidth
+
50
);
}
}
node
.
preTraverse
(
function
(
n
)
{
var
_style
=
n
.
getData
(
"style"
);
var
parent
=
node
.
getParent
();
var
_parentStyle
=
parent
.
getData
(
"style"
);
var
parentX
=
parent
.
getData
(
"x"
);
var
parentAlign
=
parent
.
getData
(
"align"
);
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
if
(
parentAlign
===
"center"
)
parentWidth
=
parentWidth
/
2
;
var
selfAppendSide
=
n
.
getData
(
"appendside"
);
if
(
selfAppendSide
===
"right"
)
n
.
setData
(
"x"
,
parentX
+
parentWidth
+
_style
.
margin
[
3
]
+
_parentStyle
.
margin
[
1
]
);
else
n
.
setData
(
"x"
,
parentX
-
parentWidth
-
_style
.
margin
[
3
]
-
_parentStyle
.
margin
[
1
]
);
effectSet
.
push
(
n
);
}
);
return
effectSet
;
};
};
var
_style
=
{
var
_style
=
{
renderNode
:
function
(
node
)
{
renderNode
:
function
(
node
)
{
var
km
=
this
;
drawNode
(
node
);
var
styledefault
=
{
var
set1
=
updateLayoutHorizon
(
node
);
radius
:
10
,
var
set2
=
updateLayoutVertical
(
node
,
node
.
getParent
(),
"append"
);
fill
:
"yellow"
,
//获取水平方向和垂直方向受影响的点的并集然后进行统一translate
stroke
:
"orange"
,
var
set
=
uSet
(
set1
,
set2
);
color
:
"black"
,
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
padding
:
[
5
,
10
,
5
,
10
],
translateNode
(
set
[
i
]
);
fontSize
:
20
};
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
return
{
constructor
:
function
(
container
)
{
this
.
rect
=
new
kity
.
Rect
();
this
.
text
=
new
kity
.
Text
();
this
.
shape
=
new
kity
.
Group
();
this
.
shape
.
addShapes
(
[
this
.
rect
,
this
.
text
]
);
container
.
addShape
(
this
.
shape
,
"nodeShape"
);
},
highlight
:
function
()
{
this
.
rect
.
stroke
(
new
kity
.
Pen
(
"white"
,
3
)
);
},
unhighlight
:
function
()
{
this
.
rect
.
stroke
(
this
.
NormalInfo
);
}
};
}
)()
);
var
kR
=
node
.
getRenderContainer
();
var
nodeShape
=
node
.
getData
(
"nodeshape"
)
||
new
MinderNodeShape
(
kR
);
node
.
setData
(
"nodeshape"
,
nodeShape
);
var
nd
=
JSON
.
parse
(
JSON
.
stringify
(
styledefault
)
);
var
nodeD
=
Utils
.
extend
(
nd
,
node
.
getData
(
"style"
)
);
node
.
setData
(
"style"
,
nodeD
);
var
_style
=
nodeD
;
nodeShape
.
text
.
setContent
(
node
.
getData
(
"text"
)
||
"Node"
)
.
setSize
(
nodeD
.
fontSize
)
.
fill
(
nodeD
.
color
);
var
txtWidth
=
nodeShape
.
text
.
getWidth
();
var
txtHeight
=
nodeShape
.
text
.
getHeight
();
var
_padding
=
_style
.
padding
;
var
_rectWidth
=
txtWidth
+
_padding
[
1
]
+
_padding
[
3
];
var
_rectHeight
=
txtHeight
+
_padding
[
0
]
+
_padding
[
2
];
nodeShape
.
text
.
setX
(
_padding
[
3
]
).
setY
(
_padding
[
0
]
+
txtHeight
);
nodeShape
.
NormalInfo
=
new
kity
.
Pen
(
_style
.
stroke
,
_style
.
strokeWidth
);
nodeShape
.
rect
.
setWidth
(
_rectWidth
).
setHeight
(
_rectHeight
).
stroke
(
nodeShape
.
NormalInfo
).
fill
(
_style
.
fill
).
setRadius
(
_style
.
radius
);
switch
(
node
.
getData
(
"align"
)
)
{
case
"center"
:
nodeShape
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
case
"right"
:
nodeShape
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
default
:
nodeShape
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
}
}
if
(
node
.
getData
(
"highlight"
)
)
{
nodeShape
.
highlight
();
}
else
{
nodeShape
.
unhighlight
();
}
updateConnect
(
this
,
node
,
"rendernode"
);
},
},
initStyle
:
function
()
{
initStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
var
_root
=
this
.
getRoot
();
...
@@ -433,70 +340,80 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -433,70 +340,80 @@ KityMinder.registerModule( "LayoutDefault", function () {
stroke
:
"orange"
,
stroke
:
"orange"
,
color
:
"black"
,
color
:
"black"
,
padding
:
[
10
,
10
,
10
,
10
],
padding
:
[
10
,
10
,
10
,
10
],
fontSize
:
30
fontSize
:
30
,
margin
:
[
0
,
0
,
0
,
0
]
}
);
}
);
_root
.
setData
(
"x"
,
minderWidth
/
2
);
_root
.
setData
(
"x"
,
minderWidth
/
2
);
_root
.
setData
(
"y"
,
minderHeight
/
2
);
_root
.
setData
(
"y"
,
minderHeight
/
2
);
_root
.
setData
(
"layer"
,
0
);
_root
.
setData
(
"layer"
,
0
);
_root
.
setData
(
"align"
,
"center"
);
_root
.
setData
(
"align"
,
"center"
);
_root
.
setData
(
"text"
,
"I am the root"
);
_root
.
setData
(
"text"
,
"I am the root"
);
//标记左子树和右子树的元素
_root
.
setData
(
"layerleft"
,
[
[
_root
]
]
);
_root
.
setData
(
"layerright"
,
[
[
_root
]
]
);
_root
.
setData
(
"indexList"
,
[
0
]
);
_root
.
setData
(
"leftHeight"
,
0
);
_root
.
setData
(
"rightHeight"
,
0
);
//标记根节点以及添加子树的方向
_root
.
setData
(
"appendside"
,
"right"
);
_root
.
setData
(
"appendside"
,
"right"
);
_root
.
preTraverse
(
function
(
node
)
{
var
children
=
_root
.
getChildren
();
minder
.
renderNode
(
node
);
_root
.
setData
(
"leftList"
,
[]
);
}
);
_root
.
setData
(
"rightList"
,
[]
);
},
createChildNode
:
function
(
parent
)
{
minder
.
renderNode
(
_root
);
return
createChildNode
(
this
,
parent
);
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
_root
.
setData
(
"leftHeight"
,
_rootRenderContainer
.
getHeight
()
);
_root
.
setData
(
"rightHeight"
,
_rootRenderContainer
.
getHeight
()
);
//如果是从其他style切过来的,需要重新布局
if
(
children
.
length
!==
0
)
{
var
leftList
=
_root
.
getData
(
"leftList"
);
var
rightList
=
_root
.
getData
(
"rightList"
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
if
(
i
%
2
===
0
)
{
rightList
.
push
(
children
[
i
]
);
children
[
i
].
setData
(
"appendside"
,
"right"
);
}
else
{
leftList
.
push
(
children
[
i
]
);
children
[
i
].
setData
(
"appendside"
,
"left"
);
}
}
}
},
},
createSiblingNode
:
function
(
sibling
)
{
appendChildNode
:
function
(
parent
,
node
)
{
var
root
=
this
.
getRoot
();
var
appendside
=
parent
.
getData
(
"appendside"
);
var
parent
=
sibling
.
getParent
();
if
(
parent
===
root
)
{
if
(
parent
===
root
)
{
parent
.
setData
(
"appendside"
,
sibling
.
getData
(
"appendside"
)
);
var
leftList
=
parent
.
getData
(
"leftList"
);
var
rightList
=
parent
.
getData
(
"rightList"
);
var
sibling
=
parent
.
getChildren
();
if
(
sibling
.
length
>=
2
&&
rightList
.
length
>
leftList
.
length
)
{
appendside
=
"left"
;
}
else
{
appendside
=
"right"
;
}
parent
.
setData
(
"appendside"
,
appendside
);
node
.
setData
(
"appendside"
,
appendside
);
parent
.
getData
(
appendside
+
"List"
).
push
(
node
);
}
}
var
index
=
sibling
.
getIndex
()
+
1
;
if
(
appendside
===
"left"
)
{
if
(
parent
)
{
node
.
setData
(
"align"
,
"right"
);
return
createChildNode
(
this
,
parent
,
index
);
}
else
{
}
else
{
return
false
;
node
.
setData
(
"align"
,
"left"
)
;
}
}
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
parent
.
appendChild
(
node
);
this
.
renderNode
(
node
);
//this.select( node );
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
parent
=
sibling
.
getParent
();
var
index
=
sibling
.
getIndex
()
+
1
;
parent
.
appendChild
(
node
,
index
);
this
.
renderNode
(
node
);
},
},
removeNode
:
function
(
nodes
)
{
removeNode
:
function
(
nodes
)
{
var
root
=
this
.
getRoot
();
var
root
=
this
.
getRoot
();
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
var
parent
=
nodes
[
i
].
getParent
();
var
parent
=
nodes
[
i
].
getParent
();
if
(
parent
)
{
if
(
parent
)
{
var
appendSide
=
nodes
[
i
].
getData
(
"appendside"
);
var
layer
=
nodes
[
i
].
getData
(
"layer"
);
parent
.
removeChild
(
nodes
[
i
]
);
parent
.
removeChild
(
nodes
[
i
]
);
var
layerArray
=
root
.
getData
(
"layer"
+
appendSide
);
var
layerData
=
layerArray
[
layer
];
//移除层结构中的node
for
(
var
j
=
0
;
j
<
layerData
.
length
;
j
++
)
{
if
(
layerData
[
j
]
===
nodes
[
i
]
)
{
layerData
.
splice
(
j
,
1
);
break
;
}
}
var
reAnal
=
updateBranchHeight
(
nodes
[
i
],
appendSide
,
root
,
false
,
parent
);
if
(
reAnal
)
{
reAnalyze
(
this
,
layerArray
,
appendSide
);
}
}
}
}
}
updateConnect
(
this
,
nodes
,
"removenode"
);
this
.
setContentChanged
(
true
);
}
}
};
};
this
.
addLayoutStyle
(
"default"
,
_style
);
this
.
addLayoutStyle
(
"default"
,
_style
);
...
...
src/module/layout.js
View file @
94f12382
...
@@ -7,8 +7,8 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -7,8 +7,8 @@ KityMinder.registerModule( "LayoutModule", function () {
if
(
!
_style
)
return
false
;
if
(
!
_style
)
return
false
;
km
.
renderNode
=
_style
.
renderNode
;
km
.
renderNode
=
_style
.
renderNode
;
km
.
initStyle
=
_style
.
initStyle
;
km
.
initStyle
=
_style
.
initStyle
;
km
.
createChildNode
=
_style
.
create
ChildNode
;
km
.
appendChildNode
=
_style
.
append
ChildNode
;
km
.
createSiblingNode
=
_style
.
create
SiblingNode
;
km
.
appendSiblingNode
=
_style
.
append
SiblingNode
;
km
.
removeNode
=
_style
.
removeNode
;
km
.
removeNode
=
_style
.
removeNode
;
//清空节点上附加的数据
//清空节点上附加的数据
var
_root
=
km
.
getRoot
();
var
_root
=
km
.
getRoot
();
...
@@ -21,35 +21,38 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -21,35 +21,38 @@ KityMinder.registerModule( "LayoutModule", function () {
}
}
};
};
}
)()
);
}
)()
);
var
CreateChildNodeCommand
=
kity
.
createClass
(
"Create
ChildNodeCommand"
,
(
function
()
{
var
AppendChildNodeCommand
=
kity
.
createClass
(
"Append
ChildNodeCommand"
,
(
function
()
{
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
parent
)
{
execute
:
function
(
km
,
node
)
{
return
km
.
createChildNode
(
parent
);
var
parent
=
km
.
getSelectedNode
();
return
km
.
appendChildNode
(
parent
,
node
);
}
}
};
};
}
)()
);
}
)()
);
var
CreateSiblingNodeCommand
=
kity
.
createClass
(
"Create
SiblingNodeCommand"
,
(
function
()
{
var
AppendSiblingNodeCommand
=
kity
.
createClass
(
"Append
SiblingNodeCommand"
,
(
function
()
{
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
sibling
)
{
execute
:
function
(
km
,
node
)
{
return
km
.
createSiblingNode
(
sibling
);
var
sibling
=
km
.
getSelectedNode
();
return
km
.
appendSiblingNode
(
sibling
.
getParent
(),
node
);
}
}
};
};
}
)()
);
}
)()
);
var
RemoveNodeCommand
=
kity
.
createClass
(
"RemoveNodeCommand"
,
(
function
()
{
var
RemoveNodeCommand
=
kity
.
createClass
(
"RemoveNodeCommand"
,
(
function
()
{
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
node
)
{
execute
:
function
(
km
,
node
s
)
{
km
.
removeNode
(
node
);
km
.
removeNode
(
node
s
);
}
}
};
};
}
)()
);
}
)()
);
return
{
return
{
"commands"
:
{
"commands"
:
{
"
createchildnode"
:
Create
ChildNodeCommand
,
"
appendchildnode"
:
Append
ChildNodeCommand
,
"
createsiblingnode"
:
Create
SiblingNodeCommand
,
"
appendsiblingnode"
:
Append
SiblingNodeCommand
,
"removenode"
:
RemoveNodeCommand
,
"removenode"
:
RemoveNodeCommand
,
"switchlayout"
:
SwitchLayoutCommand
"switchlayout"
:
SwitchLayoutCommand
}
}
...
...
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