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
60602081
Commit
60602081
authored
May 17, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
layout
parent
7497dff9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
444 additions
and
442 deletions
+444
-442
markers.js
dialogs/markers/markers.js
+2
-2
kityminder.config.js
kityminder.config.js
+23
-23
layout.js
src/adapter/layout.js
+33
-33
layout.bottom.js
src/module/layout.bottom.js
+275
-272
layout.js
src/module/layout.js
+111
-112
No files found.
dialogs/markers/markers.js
View file @
60602081
...
...
@@ -49,8 +49,8 @@
},
lang
));
}
this
.
root
().
html
(
html
);
var
valPri
=
km
.
queryCommandValue
(
"priority"
);
var
valPro
=
km
.
queryCommandValue
(
"progress"
);
var
valPri
=
km
.
queryCommandValue
(
"priority"
)
||
0
;
var
valPro
=
km
.
queryCommandValue
(
"progress"
)
||
0
;
$w
.
find
(
"li[type='priority']"
).
removeClass
(
"active"
);
$w
.
find
(
"li[type='priority'][value='"
+
valPri
+
"']"
).
addClass
(
"active"
);
$w
.
find
(
"li[type='progress']"
).
removeClass
(
"active"
);
...
...
kityminder.config.js
View file @
60602081
(
function
()
{
function
getKMBasePath
(
docUrl
,
confUrl
)
{
(
function
()
{
function
getKMBasePath
(
docUrl
,
confUrl
)
{
return
getBasePath
(
docUrl
||
self
.
document
.
URL
||
self
.
location
.
href
,
confUrl
||
getConfigFilePath
()
);
return
getBasePath
(
docUrl
||
self
.
document
.
URL
||
self
.
location
.
href
,
confUrl
||
getConfigFilePath
()
);
}
function
getConfigFilePath
()
{
var
configPath
=
document
.
getElementsByTagName
(
'script'
);
var
configPath
=
document
.
getElementsByTagName
(
'script'
);
return
configPath
[
configPath
.
length
-
1
].
src
;
return
configPath
[
configPath
.
length
-
1
].
src
;
}
function
getBasePath
(
docUrl
,
confUrl
)
{
function
getBasePath
(
docUrl
,
confUrl
)
{
var
basePath
=
confUrl
;
if
(
/^
(\/
|
\\\\)
/
.
test
(
confUrl
)
)
{
if
(
/^
(\/
|
\\\\)
/
.
test
(
confUrl
)
)
{
basePath
=
/^.+
?\w(\/
|
\\\\)
/
.
exec
(
docUrl
)[
0
]
+
confUrl
.
replace
(
/^
(\/
|
\\\\)
/
,
''
);
basePath
=
/^.+
?\w(\/
|
\\\\)
/
.
exec
(
docUrl
)[
0
]
+
confUrl
.
replace
(
/^
(\/
|
\\\\)
/
,
''
);
}
else
if
(
!
/^
[
a-z
]
+:/i
.
test
(
confUrl
)
)
{
}
else
if
(
!
/^
[
a-z
]
+:/i
.
test
(
confUrl
)
)
{
docUrl
=
docUrl
.
split
(
"#"
)[
0
].
split
(
"?"
)[
0
].
replace
(
/
[^\\\/]
+$/
,
''
);
docUrl
=
docUrl
.
split
(
"#"
)[
0
].
split
(
"?"
)[
0
].
replace
(
/
[^\\\/]
+$/
,
''
);
basePath
=
docUrl
+
""
+
confUrl
;
}
return
optimizationPath
(
basePath
);
return
optimizationPath
(
basePath
);
}
function
optimizationPath
(
path
)
{
function
optimizationPath
(
path
)
{
var
protocol
=
/^
[
a-z
]
+:
\/\/
/
.
exec
(
path
)[
0
],
var
protocol
=
/^
[
a-z
]
+:
\/\/
/
.
exec
(
path
)[
0
],
tmp
=
null
,
res
=
[];
path
=
path
.
replace
(
protocol
,
""
).
split
(
"?"
)[
0
].
split
(
"#"
)[
0
];
path
=
path
.
replace
(
protocol
,
""
).
split
(
"?"
)[
0
].
split
(
"#"
)[
0
];
path
=
path
.
replace
(
/
\\
/g
,
'/'
).
split
(
/
\/
/
);
path
=
path
.
replace
(
/
\\
/g
,
'/'
).
split
(
/
\/
/
);
path
[
path
.
length
-
1
]
=
""
;
path
[
path
.
length
-
1
]
=
""
;
while
(
path
.
length
)
{
while
(
path
.
length
)
{
if
(
(
tmp
=
path
.
shift
()
)
===
".."
)
{
if
(
(
tmp
=
path
.
shift
())
===
".."
)
{
res
.
pop
();
}
else
if
(
tmp
!==
"."
)
{
res
.
push
(
tmp
);
}
else
if
(
tmp
!==
"."
)
{
res
.
push
(
tmp
);
}
}
return
protocol
+
res
.
join
(
"/"
);
return
protocol
+
res
.
join
(
"/"
);
}
window
.
KITYMINDER_CONFIG
=
{
'KITYMINDER_HOME_URL'
:
getKMBasePath
(),
//定义工具栏
toolbars
:
[
'hand | zoom-in zoom zoom-out | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto | hyperlink unhyperlink image removeimage | markers resource | node | help'
'hand | zoom-in zoom zoom-out | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto |
switchlayout |
hyperlink unhyperlink image removeimage | markers resource | node | help'
]
//只读模式,默认是false
//readOnly: true
...
...
@@ -95,4 +95,4 @@
//,maxImageHeight: 200
//
};
}
)();
\ No newline at end of file
})();
\ No newline at end of file
src/adapter/layout.js
View file @
60602081
KM
.
registerToolbarUI
(
'switchlayout'
,
function
(
name
)
{
KM
.
registerToolbarUI
(
'switchlayout'
,
function
(
name
)
{
var
me
=
this
,
label
=
me
.
getLang
(
'tooltips.'
+
name
),
label
=
me
.
getLang
(
'tooltips.'
+
name
),
options
=
{
label
:
label
,
title
:
label
,
...
...
@@ -13,54 +12,55 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
enabledRecord
:
false
},
$combox
=
null
;
if
(
options
.
items
.
length
==
0
)
{
if
(
options
.
items
.
length
==
0
)
{
return
null
;
}
utils
.
each
(
options
.
items
,
function
(
i
,
item
)
{
options
.
items
[
i
]
=
me
.
getLang
(
'layout'
)[
item
];
}
);
utils
.
each
(
options
.
items
,
function
(
i
,
item
)
{
options
.
items
[
i
]
=
me
.
getLang
(
'layout'
)[
item
];
});
//实例化
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
var
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
me
.
execCommand
(
name
,
res
.
value
);
}
).
on
(
"beforeshow"
,
function
()
{
if
(
$combox
.
parent
().
length
===
0
)
{
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
me
.
execCommand
(
name
,
res
.
value
);
me
.
initStyle
();
}).
on
(
"beforeshow"
,
function
()
{
if
(
$combox
.
parent
().
length
===
0
)
{
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
));
}
}
);
});
//状态反射
me
.
on
(
'interactchange'
,
function
()
{
var
state
=
this
.
queryCommandState
(
name
),
value
=
this
.
queryCommandValue
(
name
);
me
.
on
(
'interactchange'
,
function
()
{
var
state
=
this
.
queryCommandState
(
name
),
value
=
this
.
queryCommandValue
(
name
);
//设置按钮状态
comboboxWidget
.
button
().
kmui
().
disabled
(
state
==
-
1
).
active
(
state
==
1
);
comboboxWidget
.
button
().
kmui
().
disabled
(
state
==
-
1
).
active
(
state
==
1
);
if
(
value
)
{
if
(
value
)
{
//设置label
value
=
value
.
replace
(
/
[
'"
]
/g
,
''
).
toLowerCase
().
split
(
/
[
'|"
]?\s
*,
\s
*
[\1]?
/
);
comboboxWidget
.
selectItemByLabel
(
value
);
value
=
value
.
replace
(
/
[
'"
]
/g
,
''
).
toLowerCase
().
split
(
/
[
'|"
]?\s
*,
\s
*
[\1]?
/
);
comboboxWidget
.
selectItemByLabel
(
value
);
}
}
);
});
var
data
=
[];
utils
.
each
(
me
.
getLayoutStyleItems
(),
function
(
i
,
v
)
{
data
.
push
(
{
label
:
me
.
getLang
(
'tooltips.'
+
name
)
+
' '
+
v
,
utils
.
each
(
me
.
getLayoutStyleItems
(),
function
(
i
,
v
)
{
data
.
push
({
label
:
me
.
getLang
(
'tooltips.'
+
name
)
+
' '
+
v
,
cmdName
:
'switchlayout'
,
exec
:
function
()
{
me
.
execCommand
(
'switchlayout'
,
v
);
me
.
execCommand
(
'switchlayout'
,
v
);
}
}
)
}
);
data
.
push
(
{
})
});
data
.
push
({
divider
:
1
}
);
me
.
addContextmenu
(
data
);
return
comboboxWidget
.
button
().
addClass
(
'kmui-combobox'
);
}
);
\ No newline at end of file
});
me
.
addContextmenu
(
data
);
return
comboboxWidget
.
button
().
addClass
(
'kmui-combobox'
);
});
\ No newline at end of file
src/module/layout.bottom.js
View file @
60602081
KityMinder
.
registerModule
(
"LayoutBottom"
,
function
()
{
KityMinder
.
registerModule
(
"LayoutBottom"
,
function
()
{
var
_target
=
this
.
getRenderTarget
();
function
getMinderSize
()
{
...
...
@@ -9,43 +9,43 @@ KityMinder.registerModule( "LayoutBottom", function () {
}
var
minder
=
this
;
//收缩-展开子树的节点
var
ShIcon
=
kity
.
createClass
(
"DefaultshIcon"
,
(
function
()
{
var
ShIcon
=
kity
.
createClass
(
"DefaultshIcon"
,
(
function
()
{
return
{
constructor
:
function
(
node
)
{
constructor
:
function
(
node
)
{
this
.
_show
=
false
;
this
.
_node
=
node
;
var
iconShape
=
this
.
shape
=
new
kity
.
Group
();
iconShape
.
class
=
"shicon"
;
iconShape
.
icon
=
this
;
var
rect
=
this
.
_rect
=
new
kity
.
Rect
().
fill
(
"white"
).
stroke
(
"gray"
).
setRadius
(
2
).
setWidth
(
10
).
setHeight
(
10
);
var
rect
=
this
.
_rect
=
new
kity
.
Rect
().
fill
(
"white"
).
stroke
(
"gray"
).
setRadius
(
2
).
setWidth
(
10
).
setHeight
(
10
);
var
plus
=
this
.
_plus
=
new
kity
.
Path
();
plus
.
getDrawer
()
.
moveTo
(
2
,
5
)
.
lineTo
(
8
,
5
)
.
moveTo
(
5
,
2
)
.
lineTo
(
5
,
8
);
plus
.
stroke
(
"gray"
);
.
moveTo
(
2
,
5
)
.
lineTo
(
8
,
5
)
.
moveTo
(
5
,
2
)
.
lineTo
(
5
,
8
);
plus
.
stroke
(
"gray"
);
var
dec
=
this
.
_dec
=
new
kity
.
Path
();
dec
.
getDrawer
()
.
moveTo
(
2
,
5
)
.
lineTo
(
8
,
5
);
dec
.
stroke
(
"gray"
);
if
(
node
.
getType
()
===
"main"
)
minder
.
getRenderContainer
().
addShape
(
iconShape
);
.
moveTo
(
2
,
5
)
.
lineTo
(
8
,
5
);
dec
.
stroke
(
"gray"
);
if
(
node
.
getType
()
===
"main"
)
minder
.
getRenderContainer
().
addShape
(
iconShape
);
else
{
node
.
getLayout
().
subgroup
.
addShape
(
iconShape
);
node
.
getLayout
().
subgroup
.
addShape
(
iconShape
);
}
iconShape
.
addShapes
(
[
rect
,
plus
,
dec
]
);
iconShape
.
addShapes
(
[
rect
,
plus
,
dec
]
);
this
.
update
();
this
.
switchState
();
},
switchState
:
function
()
{
if
(
!
this
.
_show
)
{
this
.
_plus
.
setOpacity
(
0
);
this
.
_dec
.
setOpacity
(
1
);
if
(
!
this
.
_show
)
{
this
.
_plus
.
setOpacity
(
0
);
this
.
_dec
.
setOpacity
(
1
);
this
.
_show
=
true
;
}
else
{
this
.
_plus
.
setOpacity
(
1
);
this
.
_dec
.
setOpacity
(
0
);
this
.
_plus
.
setOpacity
(
1
);
this
.
_dec
.
setOpacity
(
0
);
this
.
_show
=
false
;
}
return
this
.
_show
;
...
...
@@ -55,259 +55,259 @@ KityMinder.registerModule( "LayoutBottom", function () {
var
Layout
=
node
.
getLayout
();
var
nodeShape
=
node
.
getRenderContainer
();
var
nodeType
=
node
.
getType
();
var
nodeX
=
nodeShape
.
getRenderBox
().
closurePoints
[
1
].
x
+
5
;
var
nodeY
=
nodeShape
.
getRenderBox
().
closurePoints
[
0
].
y
;
this
.
shape
.
setTranslate
(
nodeX
,
nodeY
);
var
nodeX
=
nodeShape
.
getRenderBox
().
closurePoints
[
1
].
x
+
5
;
var
nodeY
=
nodeShape
.
getRenderBox
().
closurePoints
[
0
].
y
;
this
.
shape
.
setTranslate
(
nodeX
,
nodeY
);
},
remove
:
function
()
{
this
.
shape
.
remove
();
}
};
}
)()
);
}
)()
);
//样式的配置(包括颜色、字号等)
var
nodeStyles
=
{
"root"
:
{
color
:
'#430'
,
fill
:
'#e9df98'
,
fontSize
:
24
,
padding
:
[
15.5
,
25.5
,
15.5
,
25.5
],
margin
:
[
0
,
0
,
20
,
0
],
padding
:
[
15.5
,
25.5
,
15.5
,
25.5
],
margin
:
[
0
,
0
,
20
,
0
],
radius
:
0
,
highlight
:
'rgb(254, 219, 0)'
},
"main"
:
{
stroke
:
new
kity
.
Pen
(
"white"
,
2
).
setLineCap
(
"round"
).
setLineJoin
(
"round"
),
stroke
:
new
kity
.
Pen
(
"white"
,
2
).
setLineCap
(
"round"
).
setLineJoin
(
"round"
),
fill
:
'#A4c5c0'
,
color
:
"#333"
,
padding
:
[
6.5
,
20
,
6.5
,
20
],
padding
:
[
6.5
,
20
,
6.5
,
20
],
fontSize
:
16
,
margin
:
[
20
,
20
,
10
,
10
],
margin
:
[
20
,
20
,
10
,
10
],
radius
:
0
,
highlight
:
'rgb(254, 219, 0)'
},
"sub"
:
{
stroke
:
new
kity
.
Pen
(
"white"
,
2
).
setLineCap
(
"round"
).
setLineJoin
(
"round"
),
stroke
:
new
kity
.
Pen
(
"white"
,
2
).
setLineCap
(
"round"
).
setLineJoin
(
"round"
),
color
:
"#333"
,
fontSize
:
12
,
margin
:
[
10
,
10
,
10
,
30
],
padding
:
[
5
,
10
,
5.5
,
10
],
margin
:
[
10
,
10
,
10
,
30
],
padding
:
[
5
,
10
,
5.5
,
10
],
highlight
:
'rgb(254, 219, 0)'
,
fill
:
'rgb(231, 243, 255)'
}
};
//更新背景
var
updateBg
=
function
(
node
)
{
var
updateBg
=
function
(
node
)
{
var
nodeType
=
node
.
getType
();
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
Layout
=
node
.
getLayout
();
switch
(
node
.
getType
()
)
{
switch
(
node
.
getType
()
)
{
case
"root"
:
case
"main"
:
var
bg
=
node
.
getBgRc
().
clear
();
bg
.
addShape
(
Layout
.
bgShadow
=
new
kity
.
Rect
()
);
bg
.
addShape
(
Layout
.
bgRect
=
new
kity
.
Rect
()
);
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
).
setRadius
(
nodeStyle
.
radius
);
Layout
.
bgShadow
.
fill
(
'black'
).
setOpacity
(
0.2
).
setRadius
(
nodeStyle
.
radius
).
translate
(
3
,
5
);
bg
.
addShape
(
Layout
.
bgShadow
=
new
kity
.
Rect
()
);
bg
.
addShape
(
Layout
.
bgRect
=
new
kity
.
Rect
()
);
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
).
setRadius
(
nodeStyle
.
radius
);
Layout
.
bgShadow
.
fill
(
'black'
).
setOpacity
(
0.2
).
setRadius
(
nodeStyle
.
radius
).
translate
(
3
,
5
);
break
;
case
"sub"
:
var
bgRc
=
node
.
getBgRc
().
clear
();
bgRc
.
addShape
(
Layout
.
bgRect
=
new
kity
.
Rect
()
);
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
);
bgRc
.
addShape
(
Layout
.
bgRect
=
new
kity
.
Rect
()
);
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
);
break
;
default
:
break
;
}
};
//初始化样式
var
initLayout
=
function
(
node
)
{
var
initLayout
=
function
(
node
)
{
var
Layout
=
node
.
getLayout
();
var
nodeType
=
node
.
getType
();
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
nodeStyle
=
nodeStyles
[
nodeType
];
// var txtShape = node.getTextShape();
// txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 );
if
(
nodeType
===
"main"
)
{
if
(
nodeType
===
"main"
)
{
var
subgroup
=
Layout
.
subgroup
=
new
kity
.
Group
();
minder
.
getRenderContainer
().
addShape
(
subgroup
);
minder
.
getRenderContainer
().
addShape
(
subgroup
);
}
};
//根据内容调整节点尺寸
var
updateShapeByCont
=
function
(
node
)
{
var
updateShapeByCont
=
function
(
node
)
{
var
contRc
=
node
.
getContRc
();
var
nodeType
=
node
.
getType
();
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
_contRCWidth
=
contRc
.
getWidth
();
var
_contRCHeight
=
contRc
.
getHeight
();
var
Layout
=
node
.
getLayout
();
switch
(
nodeType
)
{
switch
(
nodeType
)
{
case
"root"
:
case
"main"
:
var
width
=
_contRCWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
],
height
=
_contRCHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
];
Layout
.
bgRect
.
setWidth
(
width
).
setHeight
(
height
);
Layout
.
bgShadow
.
setWidth
(
width
).
setHeight
(
height
);
var
width
=
_contRCWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
],
height
=
_contRCHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
];
Layout
.
bgRect
.
setWidth
(
width
).
setHeight
(
height
);
Layout
.
bgShadow
.
setWidth
(
width
).
setHeight
(
height
);
break
;
case
"sub"
:
width
=
_contRCWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
];
height
=
_contRCHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
];
Layout
.
bgRect
.
setWidth
(
width
).
setHeight
(
height
);
width
=
_contRCWidth
+
nodeStyle
.
padding
[
1
]
+
nodeStyle
.
padding
[
3
];
height
=
_contRCHeight
+
nodeStyle
.
padding
[
0
]
+
nodeStyle
.
padding
[
2
];
Layout
.
bgRect
.
setWidth
(
width
).
setHeight
(
height
);
break
;
default
:
break
;
}
contRc
.
setTranslate
(
nodeStyle
.
padding
[
3
],
nodeStyle
.
padding
[
0
]
+
_contRCHeight
/
2
);
contRc
.
setTranslate
(
nodeStyle
.
padding
[
3
],
nodeStyle
.
padding
[
0
]
+
_contRCHeight
/
2
);
};
var
updateLayoutMain
=
function
()
{
var
_root
=
minder
.
getRoot
();
var
mainnodes
=
_root
.
getChildren
();
var
countMainWidth
=
function
(
node
)
{
var
countMainWidth
=
function
(
node
)
{
var
nLayout
=
node
.
getLayout
();
var
selfwidth
=
node
.
getRenderContainer
().
getWidth
()
+
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
main
.
margin
[
3
];
var
childwidth
=
nLayout
.
subgroup
.
getWidth
()
+
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
sub
.
margin
[
3
];
var
branchwidth
=
nLayout
.
branchwidth
=
(
selfwidth
>
childwidth
?
selfwidth
:
childwidth
);
var
selfwidth
=
node
.
getRenderContainer
().
getWidth
()
+
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
main
.
margin
[
3
];
var
childwidth
=
nLayout
.
subgroup
.
getWidth
()
+
nodeStyles
.
main
.
margin
[
1
]
+
nodeStyles
.
sub
.
margin
[
3
];
var
branchwidth
=
nLayout
.
branchwidth
=
(
selfwidth
>
childwidth
?
selfwidth
:
childwidth
);
return
branchwidth
;
};
var
rootLayout
=
_root
.
getLayout
();
var
rootbranchwidth
=
0
;
for
(
var
j
=
0
;
j
<
mainnodes
.
length
;
j
++
)
{
rootbranchwidth
+=
countMainWidth
(
mainnodes
[
j
]
);
for
(
var
j
=
0
;
j
<
mainnodes
.
length
;
j
++
)
{
rootbranchwidth
+=
countMainWidth
(
mainnodes
[
j
]
);
}
var
sX
=
rootLayout
.
x
-
rootbranchwidth
/
2
;
for
(
var
k
=
0
;
k
<
mainnodes
.
length
;
k
++
)
{
var
mLayout
=
mainnodes
[
k
].
getLayout
();
mLayout
.
x
=
sX
+
nodeStyles
.
main
.
margin
[
3
]
+
5
;
for
(
var
k
=
0
;
k
<
mainnodes
.
length
;
k
++
)
{
var
mLayout
=
mainnodes
[
k
].
getLayout
();
mLayout
.
x
=
sX
+
nodeStyles
.
main
.
margin
[
3
]
+
5
;
sX
+=
mLayout
.
branchwidth
;
}
return
mainnodes
;
};
var
updateLayoutAll
=
function
(
node
,
parent
,
action
)
{
var
updateLayoutAll
=
function
(
node
,
parent
,
action
)
{
var
effectSet
=
[];
var
nodeType
=
node
.
getType
();
var
Layout
=
node
.
getLayout
();
var
_root
=
minder
.
getRoot
();
var
rootLayout
=
_root
.
getLayout
();
if
(
nodeType
===
"root"
)
{
if
(
nodeType
===
"root"
)
{
Layout
.
x
=
getMinderSize
().
width
/
2
;
Layout
.
y
=
100
;
Layout
.
align
=
"center"
;
effectSet
.
push
(
node
);
effectSet
.
push
(
node
);
var
children
=
node
.
getChildren
();
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
childLayout
=
children
[
i
].
getLayout
();
childLayout
.
y
=
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
root
.
margin
[
2
]
+
nodeStyles
.
main
.
margin
[
0
];
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
childLayout
=
children
[
i
].
getLayout
();
childLayout
.
y
=
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
root
.
margin
[
2
]
+
nodeStyles
.
main
.
margin
[
0
];
}
effectSet
=
effectSet
.
concat
(
children
);
}
else
if
(
nodeType
===
"main"
)
{
effectSet
=
effectSet
.
concat
(
children
);
}
else
if
(
nodeType
===
"main"
)
{
Layout
.
align
=
"left"
;
if
(
action
===
"append"
||
action
===
"contract"
)
{
Layout
.
y
=
rootLayout
.
y
+
_root
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
root
.
margin
[
2
]
+
nodeStyles
.
main
.
margin
[
0
];
if
(
action
===
"append"
||
action
===
"contract"
)
{
Layout
.
y
=
rootLayout
.
y
+
_root
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
root
.
margin
[
2
]
+
nodeStyles
.
main
.
margin
[
0
];
}
effectSet
=
updateLayoutMain
();
}
else
{
Layout
.
align
=
"left"
;
var
parentLayout
=
parent
.
getLayout
();
if
(
action
===
"append"
)
{
if
(
parent
.
getType
()
===
"main"
)
{
Layout
.
x
=
nodeStyles
.
sub
.
margin
[
3
];
if
(
action
===
"append"
)
{
if
(
parent
.
getType
()
===
"main"
)
{
Layout
.
x
=
nodeStyles
.
sub
.
margin
[
3
];
}
else
{
Layout
.
x
=
parentLayout
.
x
+
nodeStyles
.
sub
.
margin
[
3
];
Layout
.
x
=
parentLayout
.
x
+
nodeStyles
.
sub
.
margin
[
3
];
}
}
if
(
action
===
"append"
||
action
===
"contract"
)
{
Layout
.
branchheight
=
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
sub
.
margin
[
0
]
+
nodeStyles
.
sub
.
margin
[
2
];
if
(
action
===
"append"
||
action
===
"contract"
)
{
Layout
.
branchheight
=
node
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
sub
.
margin
[
0
]
+
nodeStyles
.
sub
.
margin
[
2
];
}
var
prt
=
parent
;
if
(
action
===
"change"
)
{
if
(
action
===
"change"
)
{
prt
=
node
;
}
//自底向上更新branchheight
while
(
prt
.
getType
()
!==
"main"
)
{
while
(
prt
.
getType
()
!==
"main"
)
{
var
c
=
prt
.
getChildren
();
var
prtLayout
=
prt
.
getLayout
();
var
branchHeight
=
prt
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
sub
.
margin
[
0
]
+
nodeStyles
.
sub
.
margin
[
2
];
for
(
var
i1
=
0
;
i1
<
c
.
length
;
i1
++
)
{
branchHeight
+=
c
[
i1
].
getLayout
().
branchheight
;
var
branchHeight
=
prt
.
getRenderContainer
().
getHeight
()
+
nodeStyles
.
sub
.
margin
[
0
]
+
nodeStyles
.
sub
.
margin
[
2
];
for
(
var
i1
=
0
;
i1
<
c
.
length
;
i1
++
)
{
branchHeight
+=
c
[
i1
].
getLayout
().
branchheight
;
}
prtLayout
.
branchheight
=
branchHeight
;
prt
=
prt
.
getParent
();
}
//自顶向下更新y
var
_buffer
=
[
prt
];
while
(
_buffer
.
length
!==
0
)
{
var
childrenC
=
_buffer
[
0
].
getChildren
();
_buffer
=
_buffer
.
concat
(
childrenC
);
var
_buffer0Layout
=
_buffer
[
0
].
getLayout
();
var
_buffer0Style
=
nodeStyles
[
_buffer
[
0
].
getType
()
];
var
_buffer
=
[
prt
];
while
(
_buffer
.
length
!==
0
)
{
var
childrenC
=
_buffer
[
0
].
getChildren
();
_buffer
=
_buffer
.
concat
(
childrenC
);
var
_buffer0Layout
=
_buffer
[
0
].
getLayout
();
var
_buffer0Style
=
nodeStyles
[
_buffer
[
0
].
getType
()
];
var
sY
;
if
(
_buffer
[
0
].
getType
()
===
"main"
)
sY
=
0
;
else
sY
=
_buffer0Layout
.
y
+
_buffer
[
0
].
getRenderContainer
().
getHeight
()
+
_buffer0Style
.
margin
[
2
];
for
(
var
s
=
0
;
s
<
childrenC
.
length
;
s
++
)
{
var
childLayoutC
=
childrenC
[
s
].
getLayout
();
var
childStyleC
=
nodeStyles
[
childrenC
[
s
].
getType
()
];
childLayoutC
.
y
=
sY
+
childStyleC
.
margin
[
0
];
if
(
_buffer
[
0
].
getType
()
===
"main"
)
sY
=
0
;
else
sY
=
_buffer0Layout
.
y
+
_buffer
[
0
].
getRenderContainer
().
getHeight
()
+
_buffer0Style
.
margin
[
2
];
for
(
var
s
=
0
;
s
<
childrenC
.
length
;
s
++
)
{
var
childLayoutC
=
childrenC
[
s
].
getLayout
();
var
childStyleC
=
nodeStyles
[
childrenC
[
s
].
getType
()
];
childLayoutC
.
y
=
sY
+
childStyleC
.
margin
[
0
];
sY
+=
childLayoutC
.
branchheight
;
}
effectSet
.
push
(
_buffer
[
0
]
);
effectSet
.
push
(
_buffer
[
0
]
);
_buffer
.
shift
();
}
}
return
effectSet
;
};
var
translateNode
=
function
(
node
)
{
var
translateNode
=
function
(
node
)
{
var
Layout
=
node
.
getLayout
();
var
nodeShape
=
node
.
getRenderContainer
();
var
align
=
Layout
.
align
;
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectWidth
=
nodeShape
.
getWidth
();
switch
(
align
)
{
switch
(
align
)
{
case
"right"
:
nodeShape
.
setTranslate
(
Layout
.
x
-
_rectWidth
,
Layout
.
y
);
nodeShape
.
setTranslate
(
Layout
.
x
-
_rectWidth
,
Layout
.
y
);
break
;
case
"center"
:
nodeShape
.
setTranslate
(
Layout
.
x
-
_rectWidth
/
2
,
Layout
.
y
);
nodeShape
.
setTranslate
(
Layout
.
x
-
_rectWidth
/
2
,
Layout
.
y
);
break
;
default
:
nodeShape
.
setTranslate
(
Layout
.
x
,
Layout
.
y
);
nodeShape
.
setTranslate
(
Layout
.
x
,
Layout
.
y
);
break
;
}
if
(
node
.
getType
()
===
"main"
)
{
Layout
.
subgroup
.
setTranslate
(
Layout
.
x
,
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
);
if
(
node
.
getType
()
===
"main"
)
{
Layout
.
subgroup
.
setTranslate
(
Layout
.
x
,
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
);
}
node
.
setPoint
(
Layout
.
x
,
Layout
.
y
);
node
.
setPoint
(
Layout
.
x
,
Layout
.
y
);
};
var
updateConnectAndshIcon
=
function
(
node
)
{
var
updateConnectAndshIcon
=
function
(
node
)
{
var
nodeType
=
node
.
getType
();
var
Layout
=
node
.
getLayout
();
var
nodeStyle
=
nodeStyles
[
node
.
getType
()
];
var
nodeStyle
=
nodeStyles
[
node
.
getType
()
];
var
connect
;
var
_root
=
minder
.
getRoot
();
var
_rootLayout
=
_root
.
getLayout
();
//更新连线
if
(
nodeType
===
"main"
)
{
if
(
!
Layout
.
connect
)
{
if
(
nodeType
===
"main"
)
{
if
(
!
Layout
.
connect
)
{
connect
=
Layout
.
connect
=
new
kity
.
Path
();
minder
.
getRenderContainer
().
addShape
(
connect
);
minder
.
getRenderContainer
().
addShape
(
connect
);
}
connect
=
Layout
.
connect
;
var
sX
=
_rootLayout
.
x
;
var
sY
=
_rootLayout
.
y
+
_root
.
getRenderContainer
().
getHeight
();
var
transX
=
Layout
.
x
+
node
.
getRenderContainer
().
getWidth
()
/
2
;
var
transY
=
sY
+
nodeStyles
.
root
.
margin
[
2
];
var
transY
=
sY
+
nodeStyles
.
root
.
margin
[
2
];
connect
.
getDrawer
().
clear
()
.
moveTo
(
sX
,
sY
)
.
lineTo
(
sX
,
transY
)
.
lineTo
(
transX
,
transY
)
.
lineTo
(
transX
,
Layout
.
y
);
connect
.
stroke
(
nodeStyles
.
main
.
stroke
);
}
else
if
(
nodeType
===
"sub"
)
{
.
moveTo
(
sX
,
sY
)
.
lineTo
(
sX
,
transY
)
.
lineTo
(
transX
,
transY
)
.
lineTo
(
transX
,
Layout
.
y
);
connect
.
stroke
(
nodeStyles
.
main
.
stroke
);
}
else
if
(
nodeType
===
"sub"
)
{
var
parent
=
node
.
getParent
();
var
parentLayout
=
parent
.
getLayout
();
if
(
!
Layout
.
connect
)
{
if
(
!
Layout
.
connect
)
{
connect
=
Layout
.
connect
=
new
kity
.
Path
();
Layout
.
subgroup
.
addShape
(
connect
);
Layout
.
subgroup
.
addShape
(
connect
);
}
connect
=
Layout
.
connect
;
var
ssX
,
ssY
;
if
(
parent
.
getType
()
===
"main"
)
{
if
(
parent
.
getType
()
===
"main"
)
{
ssX
=
10
;
ssY
=
0
;
}
else
{
...
...
@@ -316,15 +316,15 @@ KityMinder.registerModule( "LayoutBottom", function () {
}
var
transsY
=
Layout
.
y
+
node
.
getRenderContainer
().
getHeight
()
/
2
;
connect
.
getDrawer
().
clear
()
.
moveTo
(
ssX
,
ssY
)
.
lineTo
(
ssX
,
transsY
)
.
lineTo
(
Layout
.
x
,
transsY
);
connect
.
stroke
(
nodeStyles
.
sub
.
stroke
);
.
moveTo
(
ssX
,
ssY
)
.
lineTo
(
ssX
,
transsY
)
.
lineTo
(
Layout
.
x
,
transsY
);
connect
.
stroke
(
nodeStyles
.
sub
.
stroke
);
}
//更新收放icon
if
(
nodeType
!==
"root"
&&
node
.
getChildren
().
length
!==
0
)
{
if
(
!
Layout
.
shicon
)
{
Layout
.
shicon
=
new
ShIcon
(
node
);
if
(
nodeType
!==
"root"
&&
node
.
getChildren
().
length
!==
0
)
{
if
(
!
Layout
.
shicon
)
{
Layout
.
shicon
=
new
ShIcon
(
node
);
}
Layout
.
shicon
.
update
();
}
...
...
@@ -333,123 +333,126 @@ KityMinder.registerModule( "LayoutBottom", function () {
getCurrentLayoutStyle
:
function
()
{
return
nodeStyles
;
},
highlightNode
:
function
(
node
)
{
highlightNode
:
function
(
node
)
{
var
highlight
=
node
.
isHighlight
();
var
nodeType
=
node
.
getType
();
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
nodeStyle
=
nodeStyles
[
nodeType
];
var
Layout
=
node
.
getLayout
();
switch
(
nodeType
)
{
switch
(
nodeType
)
{
case
"root"
:
case
"main"
:
case
"sub"
:
if
(
highlight
)
{
Layout
.
bgRect
.
fill
(
nodeStyle
.
highlight
);
if
(
highlight
)
{
Layout
.
bgRect
.
fill
(
nodeStyle
.
highlight
);
}
else
{
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
);
Layout
.
bgRect
.
fill
(
nodeStyle
.
fill
);
}
break
;
default
:
break
;
}
},
updateLayout
:
function
(
node
)
{
updateLayout
:
function
(
node
)
{
node
.
getContRc
().
clear
();
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeLeft"
,
{
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeLeft"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeCenter"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeCenter"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeRight"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeRight"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeBottom"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeBottom"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeTop"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeTop"
,
{
node
:
node
},
false
)
);
updateShapeByCont
(
node
);
var
set
=
updateLayoutAll
(
node
,
node
.
getParent
(),
"change"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
},
false
)
);
updateShapeByCont
(
node
);
var
set
=
updateLayoutAll
(
node
,
node
.
getParent
(),
"change"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
if
(
node
.
getType
()
===
"sub"
)
{
if
(
node
.
getType
()
===
"sub"
)
{
var
set1
=
updateLayoutMain
();
for
(
var
j
=
0
;
j
<
set1
.
length
;
j
++
)
{
translateNode
(
set1
[
j
]
);
updateConnectAndshIcon
(
set1
[
j
]
);
for
(
var
j
=
0
;
j
<
set1
.
length
;
j
++
)
{
translateNode
(
set1
[
j
]
);
updateConnectAndshIcon
(
set1
[
j
]
);
}
}
},
initStyle
:
function
()
{
var
_root
=
minder
.
getRoot
();
minder
.
handelNodeInsert
(
_root
);
minder
.
handelNodeInsert
(
_root
);
//设置root的align
_root
.
getLayout
().
align
=
"center"
;
updateBg
(
_root
);
initLayout
(
_root
);
updateBg
(
_root
);
initLayout
(
_root
);
_root
.
getContRc
().
clear
();
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeLeft"
,
{
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeLeft"
,
{
node
:
_root
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeCenter"
,
{
node
:
_root
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeRight"
,
{
node
:
_root
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeBottom"
,
{
node
:
_root
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeTop"
,
{
node
:
_root
},
false
)
);
updateShapeByCont
(
_root
);
updateLayoutAll
(
_root
);
translateNode
(
_root
);
var
_buffer
=
[
_root
];
var
_cleanbuffer
=
[];
},
false
));
// this._firePharse(new MinderEvent("RenderNodeCenter", {
// node: _root
// }, false));
// this._firePharse(new MinderEvent("RenderNodeRight", {
// node: _root
// }, false));
// this._firePharse(new MinderEvent("RenderNodeBottom", {
// node: _root
// }, false));
// this._firePharse(new MinderEvent("RenderNodeTop", {
// node: _root
// }, false));
// this._firePharse(new MinderEvent("RenderNode", {
// node: _root
// }, false));
// updateShapeByCont(_root);
// updateLayoutAll(_root);
// translateNode(_root);
// var _buffer = [_root];
// var _cleanbuffer = [];
//打散结构
while
(
_buffer
.
length
!==
0
)
{
var
children
=
_buffer
[
0
].
getChildren
();
_buffer
=
_buffer
.
concat
(
children
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
children
[
i
].
getLayout
().
parent
=
_buffer
[
0
];
}
_buffer
[
0
].
clearChildren
();
if
(
_buffer
[
0
]
!==
_root
)
_cleanbuffer
.
push
(
_buffer
[
0
]
);
_buffer
.
shift
();
}
//重组结构
for
(
var
j
=
0
;
j
<
_cleanbuffer
.
length
;
j
++
)
{
this
.
appendChildNode
(
_cleanbuffer
[
j
].
getLayout
().
parent
,
_cleanbuffer
[
j
]
);
}
// while (_buffer.length !== 0
) {
// var children = _buffer[0
].getChildren();
// _buffer = _buffer.concat(children
);
// for (var i = 0; i < children.length; i++
) {
// children[i].getLayout().parent = _buffer[0
];
//
}
// _buffer[0
].clearChildren();
// if (_buffer[0] !== _root) _cleanbuffer.push(_buffer[0]
);
//
_buffer.shift();
//
}
//
//
重组结构
// for (var j = 0; j < _cleanbuffer.length; j++
) {
// this.appendChildNode(_cleanbuffer[j].getLayout().parent, _cleanbuffer[j]
);
//
}
},
appendChildNode
:
function
(
parent
,
node
,
focus
,
sibling
)
{
appendChildNode
:
function
(
parent
,
node
,
focus
,
sibling
)
{
node
.
clearLayout
();
var
parentLayout
=
parent
.
getLayout
();
var
expand
=
parent
.
getData
(
"expand"
);
var
expand
=
parent
.
getData
(
"expand"
);
//设置分支类型
if
(
parent
.
getType
()
===
"root"
)
{
node
.
setType
(
"main"
);
node
.
setData
(
"expand"
,
true
);
minder
.
handelNodeInsert
(
node
);
if
(
parent
.
getType
()
===
"root"
)
{
node
.
setType
(
"main"
);
node
.
setData
(
"expand"
,
true
);
minder
.
handelNodeInsert
(
node
);
}
else
{
node
.
setType
(
"sub"
);
node
.
setType
(
"sub"
);
//将节点加入到main分支的subgroup中
parentLayout
.
subgroup
.
addShape
(
node
.
getRenderContainer
()
);
parentLayout
.
subgroup
.
addShape
(
node
.
getRenderContainer
()
);
node
.
getLayout
().
subgroup
=
parentLayout
.
subgroup
;
}
if
(
sibling
)
{
parent
.
insertChild
(
node
,
sibling
.
getIndex
()
+
1
);
if
(
sibling
)
{
parent
.
insertChild
(
node
,
sibling
.
getIndex
()
+
1
);
}
else
{
parent
.
appendChild
(
node
);
parent
.
appendChild
(
node
);
}
//计算位置等流程
updateBg
(
node
);
initLayout
(
node
);
updateBg
(
node
);
initLayout
(
node
);
// this._fire( new MinderEvent( "beforeRenderNode", {
// node: node
// }, false ) );
...
...
@@ -457,129 +460,129 @@ KityMinder.registerModule( "LayoutBottom", function () {
// node: node
// }, false ) );
node
.
getRenderContainer
().
clear
();
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeLeft"
,
{
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeLeft"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeCenter"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeCenter"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeRight"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeRight"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeBottom"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeBottom"
,
{
node
:
node
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeTop"
,
{
},
false
)
);
this
.
_firePharse
(
new
MinderEvent
(
"RenderNodeTop"
,
{
node
:
node
},
false
)
);
updateShapeByCont
(
node
);
var
set
=
updateLayoutAll
(
node
,
parent
,
"append"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
},
false
)
);
updateShapeByCont
(
node
);
var
set
=
updateLayoutAll
(
node
,
parent
,
"append"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
if
(
node
.
getType
()
===
"sub"
)
{
if
(
node
.
getType
()
===
"sub"
)
{
var
set1
=
updateLayoutMain
();
for
(
var
j
=
0
;
j
<
set1
.
length
;
j
++
)
{
translateNode
(
set1
[
j
]
);
updateConnectAndshIcon
(
set1
[
j
]
);
for
(
var
j
=
0
;
j
<
set1
.
length
;
j
++
)
{
translateNode
(
set1
[
j
]
);
updateConnectAndshIcon
(
set1
[
j
]
);
}
}
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
parent
=
sibling
.
getParent
();
this
.
appendChildNode
(
parent
,
node
,
sibling
);
this
.
appendChildNode
(
parent
,
node
,
sibling
);
},
removeNode
:
function
(
nodes
)
{
while
(
nodes
.
length
!==
0
)
{
var
parent
=
nodes
[
0
].
getParent
();
if
(
!
parent
)
{
nodes
.
splice
(
0
,
1
);
removeNode
:
function
(
nodes
)
{
while
(
nodes
.
length
!==
0
)
{
var
parent
=
nodes
[
0
].
getParent
();
if
(
!
parent
)
{
nodes
.
splice
(
0
,
1
);
return
false
;
}
var
nodeLayout
=
nodes
[
0
].
getLayout
();
parent
.
removeChild
(
nodes
[
0
]
);
if
(
parent
.
getType
()
!==
"root"
&&
parent
.
getChildren
().
length
===
0
)
{
var
nodeLayout
=
nodes
[
0
].
getLayout
();
parent
.
removeChild
(
nodes
[
0
]
);
if
(
parent
.
getType
()
!==
"root"
&&
parent
.
getChildren
().
length
===
0
)
{
var
prtLayout
=
parent
.
getLayout
();
prtLayout
.
shicon
.
remove
();
prtLayout
.
shicon
=
null
;
}
var
set
=
updateLayoutAll
(
nodes
[
0
],
parent
,
"remove"
);
for
(
var
j
=
0
;
j
<
set
.
length
;
j
++
)
{
translateNode
(
set
[
j
]
);
updateConnectAndshIcon
(
set
[
j
]
);
var
set
=
updateLayoutAll
(
nodes
[
0
],
parent
,
"remove"
);
for
(
var
j
=
0
;
j
<
set
.
length
;
j
++
)
{
translateNode
(
set
[
j
]
);
updateConnectAndshIcon
(
set
[
j
]
);
}
var
set1
=
updateLayoutMain
();
for
(
var
k
=
0
;
k
<
set1
.
length
;
k
++
)
{
translateNode
(
set1
[
k
]
);
updateConnectAndshIcon
(
set1
[
k
]
);
for
(
var
k
=
0
;
k
<
set1
.
length
;
k
++
)
{
translateNode
(
set1
[
k
]
);
updateConnectAndshIcon
(
set1
[
k
]
);
}
var
_buffer
=
[
nodes
[
0
]
];
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
var
_buffer
=
[
nodes
[
0
]
];
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
try
{
_buffer
[
0
].
getRenderContainer
().
remove
();
var
Layout
=
_buffer
[
0
].
getLayout
();
_buffer
[
0
].
getRenderContainer
().
remove
();
var
Layout
=
_buffer
[
0
].
getLayout
();
Layout
.
connect
.
remove
();
Layout
.
shicon
.
remove
();
}
catch
(
error
)
{
console
.
log
(
"isRemoved"
);
}
catch
(
error
)
{
console
.
log
(
"isRemoved"
);
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var
idx
=
nodes
.
indexOf
(
_buffer
[
0
]
);
if
(
idx
!==
-
1
)
{
nodes
.
splice
(
idx
,
1
);
var
idx
=
nodes
.
indexOf
(
_buffer
[
0
]
);
if
(
idx
!==
-
1
)
{
nodes
.
splice
(
idx
,
1
);
}
_buffer
.
shift
();
}
}
},
expandNode
:
function
(
ico
)
{
expandNode
:
function
(
ico
)
{
var
isExpand
,
node
;
if
(
ico
instanceof
MinderNode
)
{
if
(
ico
instanceof
MinderNode
)
{
node
=
ico
;
isExpand
=
node
.
getLayout
().
shicon
.
switchState
();
}
else
{
isExpand
=
ico
.
icon
.
switchState
();
node
=
ico
.
icon
.
_node
;
}
node
.
setData
(
"expand"
,
isExpand
);
node
.
setData
(
"expand"
,
isExpand
);
var
_buffer
=
node
.
getChildren
();
var
_cleanbuffer
=
[];
while
(
_buffer
.
length
!==
0
)
{
var
Layout
=
_buffer
[
0
].
getLayout
();
if
(
isExpand
)
{
var
parent
=
_buffer
[
0
].
getParent
();
while
(
_buffer
.
length
!==
0
)
{
var
Layout
=
_buffer
[
0
].
getLayout
();
if
(
isExpand
)
{
var
parent
=
_buffer
[
0
].
getParent
();
Layout
.
parent
=
parent
;
_cleanbuffer
.
push
(
_buffer
[
0
]
);
_cleanbuffer
.
push
(
_buffer
[
0
]
);
Layout
.
connect
=
null
;
Layout
.
shicon
=
null
;
}
else
{
try
{
_buffer
[
0
].
getRenderContainer
().
remove
();
_buffer
[
0
].
getRenderContainer
().
remove
();
Layout
.
connect
.
remove
();
if
(
Layout
.
shicon
)
Layout
.
shicon
.
remove
();
}
catch
(
error
)
{}
if
(
Layout
.
shicon
)
Layout
.
shicon
.
remove
();
}
catch
(
error
)
{}
}
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
.
shift
();
}
if
(
isExpand
)
{
if
(
isExpand
)
{
node
.
clearChildren
();
for
(
var
j
=
0
;
j
<
_cleanbuffer
.
length
;
j
++
)
{
_cleanbuffer
[
j
].
clearChildren
();
minder
.
appendChildNode
(
_cleanbuffer
[
j
].
getLayout
().
parent
,
_cleanbuffer
[
j
]
);
for
(
var
j
=
0
;
j
<
_cleanbuffer
.
length
;
j
++
)
{
_cleanbuffer
[
j
].
clearChildren
();
minder
.
appendChildNode
(
_cleanbuffer
[
j
].
getLayout
().
parent
,
_cleanbuffer
[
j
]
);
}
}
var
set
=
[];
if
(
!
isExpand
)
set
=
updateLayoutAll
(
node
,
node
.
getParent
(),
"contract"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
if
(
!
isExpand
)
set
=
updateLayoutAll
(
node
,
node
.
getParent
(),
"contract"
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
}
};
this
.
addLayoutStyle
(
"bottom"
,
_style
);
this
.
addLayoutStyle
(
"bottom"
,
_style
);
return
{};
}
);
\ No newline at end of file
});
\ No newline at end of file
src/module/layout.js
View file @
60602081
KityMinder
.
registerModule
(
"LayoutModule"
,
function
()
{
KityMinder
.
registerModule
(
"LayoutModule"
,
function
()
{
var
me
=
this
;
var
clearPaper
=
function
()
{
me
.
_rc
.
remove
();
me
.
_rc
=
new
kity
.
Group
();
me
.
_paper
.
addShape
(
this
.
_rc
);
me
.
_paper
.
addShape
(
this
.
_rc
);
};
kity
.
extendClass
(
Minder
,
{
addLayoutStyle
:
function
(
name
,
style
)
{
if
(
!
this
.
_layoutStyles
)
this
.
_layoutStyles
=
{};
this
.
_layoutStyles
[
name
]
=
style
;
kity
.
extendClass
(
Minder
,
{
addLayoutStyle
:
function
(
name
,
style
)
{
if
(
!
this
.
_layoutStyles
)
this
.
_layoutStyles
=
{};
this
.
_layoutStyles
[
name
]
=
style
;
},
getLayoutStyle
:
function
(
name
)
{
return
this
.
_layoutStyles
[
name
];
getLayoutStyle
:
function
(
name
)
{
return
this
.
_layoutStyles
[
name
];
},
getLayoutStyleItems
:
function
()
{
var
items
=
[];
for
(
var
key
in
this
.
_layoutStyles
)
{
items
.
push
(
key
);
for
(
var
key
in
this
.
_layoutStyles
)
{
items
.
push
(
key
);
}
return
items
;
},
getCurrentStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
return
"default"
;
//_root.getData( "currentstyle"
);
return
_root
.
getData
(
"currentstyle"
);
},
setCurrentStyle
:
function
(
name
)
{
setCurrentStyle
:
function
(
name
)
{
var
_root
=
this
.
getRoot
();
_root
.
setData
(
"currentstyle"
,
name
);
_root
.
setData
(
"currentstyle"
,
name
);
return
name
;
},
getCurrentLayoutStyle
:
function
()
{
var
curStyle
=
this
.
getCurrentStyle
();
return
this
.
getLayoutStyle
(
curStyle
).
getCurrentLayoutStyle
.
call
(
this
);
return
this
.
getLayoutStyle
(
curStyle
).
getCurrentLayoutStyle
.
call
(
this
);
},
highlightNode
:
function
(
node
)
{
highlightNode
:
function
(
node
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
highlightNode
.
call
(
this
,
node
);
this
.
getLayoutStyle
(
curStyle
).
highlightNode
.
call
(
this
,
node
);
},
initStyle
:
function
()
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
_rc
.
remove
();
var
transform
=
this
.
_rc
.
transform
;
this
.
_rc
=
new
kity
.
Group
();
this
.
_paper
.
addShape
(
this
.
_rc
);
this
.
_paper
.
addShape
(
this
.
_rc
);
this
.
_rc
.
transform
=
transform
;
this
.
_rc
.
_applyTransform
();
var
_root
=
this
.
getRoot
();
_root
.
preTraverse
(
function
(
n
)
{
_root
.
preTraverse
(
function
(
n
)
{
n
.
clearLayout
();
}
);
this
.
getLayoutStyle
(
curStyle
).
initStyle
.
call
(
this
);
this
.
fire
(
'afterinitstyle'
);
});
this
.
getLayoutStyle
(
curStyle
).
initStyle
.
call
(
this
);
this
.
fire
(
'afterinitstyle'
);
},
appendChildNode
:
function
(
parent
,
node
,
focus
,
index
)
{
appendChildNode
:
function
(
parent
,
node
,
focus
,
index
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
appendChildNode
.
call
(
this
,
parent
,
node
,
focus
,
index
);
this
.
getLayoutStyle
(
curStyle
).
appendChildNode
.
call
(
this
,
parent
,
node
,
focus
,
index
);
},
appendSiblingNode
:
function
(
sibling
,
node
,
focus
)
{
appendSiblingNode
:
function
(
sibling
,
node
,
focus
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
appendSiblingNode
.
call
(
this
,
sibling
,
node
,
focus
);
this
.
getLayoutStyle
(
curStyle
).
appendSiblingNode
.
call
(
this
,
sibling
,
node
,
focus
);
},
removeNode
:
function
(
nodes
)
{
removeNode
:
function
(
nodes
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
removeNode
.
call
(
this
,
nodes
);
this
.
getLayoutStyle
(
curStyle
).
removeNode
.
call
(
this
,
nodes
);
},
updateLayout
:
function
(
node
)
{
updateLayout
:
function
(
node
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
updateLayout
.
call
(
this
,
node
);
this
.
getLayoutStyle
(
curStyle
).
updateLayout
.
call
(
this
,
node
);
},
expandNode
:
function
(
ico
)
{
expandNode
:
function
(
ico
)
{
var
curStyle
=
this
.
getCurrentStyle
();
this
.
getLayoutStyle
(
curStyle
).
expandNode
.
call
(
this
,
ico
);
this
.
getLayoutStyle
(
curStyle
).
expandNode
.
call
(
this
,
ico
);
}
}
);
kity
.
extendClass
(
MinderNode
,
{
setLayout
:
function
(
k
,
v
)
{
if
(
this
.
_layout
===
undefined
)
{
});
kity
.
extendClass
(
MinderNode
,
{
setLayout
:
function
(
k
,
v
)
{
if
(
this
.
_layout
===
undefined
)
{
this
.
_layout
=
{};
}
var
_pros
=
this
.
getLayout
();
Utils
.
extend
(
_pros
,
{
Utils
.
extend
(
_pros
,
{
k
:
v
}
);
});
this
.
_layout
=
_pros
;
},
getLayout
:
function
(
k
)
{
if
(
k
===
undefined
)
{
getLayout
:
function
(
k
)
{
if
(
k
===
undefined
)
{
return
this
.
_layout
;
}
return
this
.
_layout
[
k
];
return
this
.
_layout
[
k
];
},
clearLayout
:
function
()
{
this
.
_layout
=
{};
}
}
);
var
switchLayout
=
function
(
km
,
style
)
{
});
var
switchLayout
=
function
(
km
,
style
)
{
var
_root
=
km
.
getRoot
();
_root
.
preTraverse
(
function
(
n
)
{
_root
.
preTraverse
(
function
(
n
)
{
n
.
setPoint
();
n
.
getBgRc
().
clear
();
}
);
km
.
setCurrentStyle
(
style
);
});
km
.
setCurrentStyle
(
style
);
//km.initStyle();
return
style
;
};
var
SwitchLayoutCommand
=
kity
.
createClass
(
"SwitchLayoutCommand"
,
(
function
()
{
var
SwitchLayoutCommand
=
kity
.
createClass
(
"SwitchLayoutCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
switchLayout
,
queryValue
:
function
(
km
)
{
queryValue
:
function
(
km
)
{
return
km
.
getCurrentStyle
();
}
};
}
)()
);
var
AppendChildNodeCommand
=
kity
.
createClass
(
"AppendChildNodeCommand"
,
(
function
()
{
}
)()
);
var
AppendChildNodeCommand
=
kity
.
createClass
(
"AppendChildNodeCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
,
node
,
focus
,
silbling
)
{
execute
:
function
(
km
,
node
,
focus
,
silbling
)
{
var
parent
=
km
.
getSelectedNode
();
if
(
!
parent
)
{
if
(
!
parent
)
{
return
null
;
}
if
(
parent
.
getType
()
!==
"root"
&&
parent
.
getChildren
().
length
!==
0
&&
!
parent
.
isExpanded
()
)
{
km
.
expandNode
(
parent
);
if
(
parent
.
getType
()
!==
"root"
&&
parent
.
getChildren
().
length
!==
0
&&
!
parent
.
isExpanded
()
)
{
km
.
expandNode
(
parent
);
}
parent
.
expand
();
km
.
appendChildNode
(
parent
,
node
,
focus
,
silbling
);
km
.
select
(
node
,
true
);
km
.
appendChildNode
(
parent
,
node
,
focus
,
silbling
);
km
.
select
(
node
,
true
);
return
node
;
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
)
{
if
(
!
selectedNode
)
{
return
-
1
;
}
else
{
return
0
;
}
}
};
}
)()
);
var
AppendSiblingNodeCommand
=
kity
.
createClass
(
"AppendSiblingNodeCommand"
,
(
function
()
{
}
)()
);
var
AppendSiblingNodeCommand
=
kity
.
createClass
(
"AppendSiblingNodeCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
,
node
,
focus
)
{
execute
:
function
(
km
,
node
,
focus
)
{
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
)
{
if
(
!
selectedNode
)
{
return
null
;
}
if
(
selectedNode
.
isRoot
()
)
{
node
.
setType
(
"main"
);
km
.
appendChildNode
(
selectedNode
,
node
,
focus
);
if
(
selectedNode
.
isRoot
()
)
{
node
.
setType
(
"main"
);
km
.
appendChildNode
(
selectedNode
,
node
,
focus
);
}
else
{
km
.
appendSiblingNode
(
selectedNode
,
node
,
focus
);
km
.
appendSiblingNode
(
selectedNode
,
node
,
focus
);
}
km
.
select
(
node
,
true
);
km
.
select
(
node
,
true
);
return
node
;
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
selectedNodes
=
km
.
getSelectedNodes
();
//没选中节点和单选root的时候返回不可执行
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
()
)
)
{
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
())
)
{
return
-
1
;
}
else
{
return
0
;
}
}
};
}
)()
);
var
RemoveNodeCommand
=
kity
.
createClass
(
"RemoveNodeCommand"
,
(
function
()
{
}
)()
);
var
RemoveNodeCommand
=
kity
.
createClass
(
"RemoveNodeCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
)
{
execute
:
function
(
km
)
{
if
(
km
.
getRoot
().
children
.
length
==
0
)
{
if
(
km
.
getRoot
().
children
.
length
==
0
)
{
return
;
}
var
selectedNodes
=
km
.
getSelectedNodes
();
var
_root
=
km
.
getRoot
();
var
_buffer
=
[];
for
(
var
i
=
0
;
i
<
selectedNodes
.
length
;
i
++
)
{
_buffer
.
push
(
selectedNodes
[
i
]
);
for
(
var
i
=
0
;
i
<
selectedNodes
.
length
;
i
++
)
{
_buffer
.
push
(
selectedNodes
[
i
]
);
}
do
{
var
parent
=
_buffer
[
0
].
getParent
();
if
(
parent
&&
_buffer
.
indexOf
(
parent
)
===
-
1
)
_buffer
.
push
(
parent
);
var
parent
=
_buffer
[
0
].
getParent
();
if
(
parent
&&
_buffer
.
indexOf
(
parent
)
===
-
1
)
_buffer
.
push
(
parent
);
_buffer
.
shift
();
}
while
(
_buffer
.
length
>
1
);
km
.
removeNode
(
selectedNodes
);
km
.
select
(
_buffer
[
0
]
);
}
while
(
_buffer
.
length
>
1
);
km
.
removeNode
(
selectedNodes
);
km
.
select
(
_buffer
[
0
]
);
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
selectedNodes
=
km
.
getSelectedNodes
();
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
()
)
)
{
if
(
selectedNodes
.
length
===
0
||
(
selectedNodes
.
length
===
1
&&
selectedNodes
[
0
]
===
km
.
getRoot
())
)
{
return
-
1
;
}
else
{
return
0
;
}
}
};
}
)()
);
var
EditNodeCommand
=
kity
.
createClass
(
"EditNodeCommand"
,
(
function
()
{
}
)()
);
var
EditNodeCommand
=
kity
.
createClass
(
"EditNodeCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
)
{
execute
:
function
(
km
)
{
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
)
{
if
(
!
selectedNode
)
{
return
null
;
}
km
.
select
(
selectedNode
,
true
);
km
.
textEditNode
(
selectedNode
);
km
.
select
(
selectedNode
,
true
);
km
.
textEditNode
(
selectedNode
);
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
)
{
if
(
!
selectedNode
)
{
return
-
1
;
}
else
{
return
0
;
...
...
@@ -228,7 +228,7 @@ KityMinder.registerModule( "LayoutModule", function () {
return
false
;
}
};
}
)()
);
}
)()
);
return
{
"commands"
:
{
...
...
@@ -240,47 +240,46 @@ KityMinder.registerModule( "LayoutModule", function () {
},
"events"
:
{
"ready"
:
function
()
{
this
.
setDefaultOptions
(
'layoutstyle'
,
this
.
getLayoutStyleItems
()
);
switchLayout
(
this
,
this
.
getOptions
(
'defaultlayoutstyle'
)
);
this
.
setDefaultOptions
(
'layoutstyle'
,
this
.
getLayoutStyleItems
());
switchLayout
(
this
,
this
.
getOptions
(
'defaultlayoutstyle'
));
},
"click"
:
function
(
e
)
{
"click"
:
function
(
e
)
{
var
ico
=
e
.
kityEvent
.
targetShape
&&
e
.
kityEvent
.
targetShape
.
container
;
if
(
ico
&&
ico
.
class
===
"shicon"
)
{
this
.
expandNode
(
ico
);
this
.
fire
(
'contentchange'
);
if
(
ico
&&
ico
.
class
===
"shicon"
)
{
this
.
expandNode
(
ico
);
this
.
fire
(
'contentchange'
);
}
},
"resize"
:
function
(
e
)
{
clearTimeout
(
this
.
_lastStyleResetTimeout
);
this
.
_lastStyleResetTimeout
=
setTimeout
(
function
()
{
this
.
updateLayout
(
this
.
getRoot
()
);
}.
bind
(
this
),
100
);
"resize"
:
function
(
e
)
{
clearTimeout
(
this
.
_lastStyleResetTimeout
);
this
.
_lastStyleResetTimeout
=
setTimeout
(
function
()
{
this
.
updateLayout
(
this
.
getRoot
()
);
}.
bind
(
this
),
100
);
},
"import"
:
function
(
e
)
{
"import"
:
function
(
e
)
{
this
.
initStyle
();
}
},
'contextmenu'
:
[
{
label
:
this
.
getLang
(
'node.appendsiblingnode'
),
'contextmenu'
:
[{
label
:
this
.
getLang
(
'node.appendsiblingnode'
),
exec
:
function
()
{
this
.
execCommand
(
'appendsiblingnode'
,
new
MinderNode
(
this
.
getLang
(
'topic'
)
)
)
this
.
execCommand
(
'appendsiblingnode'
,
new
MinderNode
(
this
.
getLang
(
'topic'
))
)
},
cmdName
:
'appendsiblingnode'
},
{
label
:
this
.
getLang
(
'node.appendchildnode'
),
label
:
this
.
getLang
(
'node.appendchildnode'
),
exec
:
function
()
{
this
.
execCommand
(
'appendchildnode'
,
new
MinderNode
(
this
.
getLang
(
'topic'
)
)
)
this
.
execCommand
(
'appendchildnode'
,
new
MinderNode
(
this
.
getLang
(
'topic'
))
)
},
cmdName
:
'appendchildnode'
},
{
label
:
this
.
getLang
(
'node.editnode'
),
label
:
this
.
getLang
(
'node.editnode'
),
exec
:
function
()
{
this
.
execCommand
(
'editnode'
,
null
);
this
.
execCommand
(
'editnode'
,
null
);
},
cmdName
:
'editnode'
},
{
label
:
this
.
getLang
(
'node.removenode'
),
label
:
this
.
getLang
(
'node.removenode'
),
cmdName
:
'removenode'
},
{
divider
:
1
...
...
@@ -301,4 +300,4 @@ KityMinder.registerModule( "LayoutModule", function () {
}
}
};
}
);
\ No newline at end of file
});
\ No newline at end of file
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