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
0ca54e93
Commit
0ca54e93
authored
Feb 17, 2014
by
techird
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
https://github.com/kitygraph/kityminder
into gh-pages
parents
5a0ef155
29ab0dab
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
190 additions
and
80 deletions
+190
-80
node.js
src/core/node.js
+20
-2
editor.js
src/module/editor.js
+41
-31
editor.receiver.js
src/module/editor.receiver.js
+22
-31
editor.selection.js
src/module/editor.selection.js
+4
-4
icon.js
src/module/icon.js
+93
-9
select.js
src/module/select.js
+7
-1
zoom.js
src/module/zoom.js
+3
-2
No files found.
src/core/node.js
View file @
0ca54e93
...
@@ -19,6 +19,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
...
@@ -19,6 +19,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
this
.
_createBgGroup
();
this
.
_createBgGroup
();
this
.
_createContGroup
();
this
.
_createContGroup
();
this
.
_createIconShape
();
this
.
_createTextShape
();
this
.
_createTextShape
();
},
},
_createGroup
:
function
(
type
)
{
_createGroup
:
function
(
type
)
{
...
@@ -33,7 +34,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
...
@@ -33,7 +34,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
this
.
_createGroup
(
'contrc'
);
this
.
_createGroup
(
'contrc'
);
},
},
_createTextShape
:
function
()
{
_createTextShape
:
function
()
{
this
.
getContRc
().
appendShape
(
new
kity
.
Text
(
this
.
getData
(
'text'
)
||
''
)
);
var
textShape
=
new
kity
.
Text
(
this
.
getData
(
'text'
)
||
''
);
textShape
.
setAttr
(
'_nodeTextShape'
,
true
);
this
.
getContRc
().
appendShape
(
textShape
);
},
_createIconShape
:
function
()
{
var
g
=
new
kity
.
Group
();
this
.
getContRc
().
appendShape
(
g
);
this
.
_iconRc
=
g
;
},
},
getContRc
:
function
()
{
getContRc
:
function
()
{
var
groups
=
this
.
rc
.
getShapesByType
(
'group'
),
var
groups
=
this
.
rc
.
getShapesByType
(
'group'
),
...
@@ -57,6 +65,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
...
@@ -57,6 +65,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
}
);
}
);
return
result
;
return
result
;
},
},
getIconRc
:
function
()
{
return
this
.
_iconRc
;
},
setPoint
:
function
(
x
,
y
)
{
setPoint
:
function
(
x
,
y
)
{
this
.
setData
(
'point'
,
{
this
.
setData
(
'point'
,
{
x
:
x
,
x
:
x
,
...
@@ -292,7 +303,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
...
@@ -292,7 +303,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
},
},
getTextShape
:
function
()
{
getTextShape
:
function
()
{
return
this
.
getContRc
().
getShapesByType
(
'text'
)[
0
];
var
textShape
;
utils
.
each
(
this
.
getContRc
().
getShapesByType
(
'text'
),
function
(
i
,
t
){
if
(
t
.
getAttr
(
'_nodeTextShape'
)){
textShape
=
t
;
return
false
;
}
});
return
textShape
;
},
},
isSelected
:
function
()
{
isSelected
:
function
()
{
return
this
.
getTmpData
(
'highlight'
)
===
true
;
return
this
.
getTmpData
(
'highlight'
)
===
true
;
...
...
src/module/editor.js
View file @
0ca54e93
KityMinder
.
registerModule
(
"TextEditModule"
,
function
()
{
KityMinder
.
registerModule
(
"TextEditModule"
,
function
()
{
var
km
=
this
;
var
sel
=
new
Minder
.
Selection
();
var
sel
=
new
Minder
.
Selection
();
var
receiver
=
new
Minder
.
Receiver
(
this
);
var
receiver
=
new
Minder
.
Receiver
(
this
);
var
range
=
new
Minder
.
Range
();
var
range
=
new
Minder
.
Range
();
this
.
receiver
=
receiver
;
this
.
receiver
=
receiver
;
...
@@ -9,61 +10,70 @@ KityMinder.registerModule( "TextEditModule", function () {
...
@@ -9,61 +10,70 @@ KityMinder.registerModule( "TextEditModule", function () {
var
oneTime
=
0
;
var
oneTime
=
0
;
var
lastEvtPosition
,
dir
=
1
;
var
lastEvtPosition
,
dir
=
1
;
return
{
return
{
//插入光标
//插入光标
"init"
:
function
()
{
"init"
:
function
()
{
this
.
getPaper
().
addShape
(
sel
);
this
.
getPaper
().
addShape
(
sel
);
},
},
"events"
:
{
"events"
:
{
'beforemousedown'
:
function
(
e
)
{
'beforemousedown'
:
function
(
e
)
{
sel
.
setHide
();
sel
.
setHide
();
var
node
=
e
.
getTargetNode
();
var
node
=
e
.
getTargetNode
();
if
(
node
)
{
if
(
node
)
{
var
textShape
=
node
.
getTextShape
();
var
textShape
=
node
.
getTextShape
();
textShape
.
setStyle
(
'cursor'
,
'default'
);
textShape
.
setStyle
(
'cursor'
,
'default'
);
if
(
this
.
isSingleSelect
()
&&
node
.
isSelected
()
)
{
// 进入编辑模式条件:
// 1. 点击的节点是唯一选中的
// 2. 点击的区域是文字区域
if
(
this
.
isSingleSelect
()
&&
node
.
isSelected
()
&&
textShape
==
e
.
kityEvent
.
targetShape
)
{
sel
.
collapse
();
sel
.
collapse
();
node
.
getTextShape
().
setStyle
(
'cursor'
,
'text'
);
node
.
getTextShape
().
setStyle
(
'cursor'
,
'text'
);
receiver
.
setTextEditStatus
(
true
)
receiver
.
setTextEditStatus
(
true
)
.
setSelection
(
sel
)
.
setSelection
(
sel
)
.
setKityMinder
(
this
)
.
setKityMinder
(
this
)
.
setMinderNode
(
node
)
.
setMinderNode
(
node
)
.
setTextShape
(
textShape
)
.
setTextShape
(
textShape
)
.
setBaseOffset
()
.
setBaseOffset
()
.
setContainerStyle
()
.
setContainerStyle
()
.
setSelectionHeight
()
.
setSelectionHeight
()
.
setCurrentIndex
(
e
.
getPosition
()
)
.
setCurrentIndex
(
e
.
getPosition
()
)
.
updateSelection
()
.
updateSelection
()
.
setRange
(
range
);
.
setRange
(
range
);
mouseDownStatus
=
true
;
mouseDownStatus
=
true
;
lastEvtPosition
=
e
.
getPosition
();
lastEvtPosition
=
e
.
getPosition
();
}
}
}
}
},
},
'mouseup'
:
function
(
e
)
{
'mouseup'
:
function
(
e
){
if
(
!
sel
.
collapsed
){
receiver
.
updateRange
(
range
)
}
mouseDownStatus
=
false
;
mouseDownStatus
=
false
;
oneTime
=
0
;
oneTime
=
0
;
},
},
'mousemove'
:
function
(
e
)
{
'beforemousemove'
:
function
(
e
){
if
(
mouseDownStatus
)
{
if
(
mouseDownStatus
){
e
.
stopPropagationImmediately
();
setTimeout
(
function
(){
var
offset
=
e
.
getPosition
();
var
offset
=
e
.
getPosition
();
dir
=
offset
.
x
>
lastEvtPosition
.
x
?
1
:
(
offset
.
x
<
lastEvtPosition
.
x
?
-
1
:
dir
);
dir
=
offset
.
x
>
lastEvtPosition
.
x
?
1
:
(
offset
.
x
<
lastEvtPosition
.
x
?
-
1
:
dir
);
receiver
.
updateSelectionByMousePosition
(
offset
,
dir
)
receiver
.
updateSelectionByMousePosition
(
offset
,
dir
)
.
updateSelectionShow
(
dir
);
.
updateSelectionShow
(
dir
);
sel
.
stroke
(
'none'
,
0
);
sel
.
stroke
(
'none'
,
0
);
lastEvtPosition
=
e
.
getPosition
();
lastEvtPosition
=
e
.
getPosition
();
},
100
)
}
}
},
},
'restoreScene'
:
function
()
{
'restoreScene'
:
function
()
{
sel
.
setHide
();
sel
.
setHide
();
},
},
'stopTextEdit'
:
function
()
{
'stopTextEdit'
:
function
()
{
sel
.
setHide
();
sel
.
setHide
();
}
}
...
...
src/module/editor.receiver.js
View file @
0ca54e93
...
@@ -205,55 +205,42 @@ Minder.Receiver = kity.createClass('Receiver',{
...
@@ -205,55 +205,42 @@ Minder.Receiver = kity.createClass('Receiver',{
this
.
selection
.
setHeight
(
this
.
getTextShapeHeight
());
this
.
selection
.
setHeight
(
this
.
getTextShapeHeight
());
return
this
;
return
this
;
},
},
getIndexByMousePosition
:
function
(
offset
,
dir
){
updateSelectionByMousePosition
:
function
(
offset
,
dir
){
var
me
=
this
;
var
me
=
this
;
var
currentIndex
;
var
hadChanged
=
false
;
utils
.
each
(
this
.
textData
,
function
(
i
,
v
){
utils
.
each
(
this
.
textData
,
function
(
i
,
v
){
//点击开始之前
//点击开始之前
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
){
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
){
currentIndex
=
0
;
me
.
selection
.
setStartOffset
(
0
)
;
return
false
;
return
false
;
}
}
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
){
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
){
currentIndex
=
me
.
textData
.
length
;
me
.
selection
.
setEndOffset
(
me
.
textData
.
length
)
;
return
false
;
return
false
;
}
}
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
){
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
){
currentIndex
=
i
+
(
dir
==
-
1
?
0
:
1
);
return
false
;
}
});
return
currentIndex
;
},
updateSelectionByMousePosition
:
function
(
offset
,
dir
){
var
currentIndex
=
this
.
getIndexByMousePosition
(
offset
,
dir
);
if
(
me
.
index
==
i
){
me
.
selection
.
setEndOffset
(
i
+
(
dir
==
1
?
1
:
0
))
if
(
currentIndex
==
0
){
}
else
if
(
i
>
me
.
index
){
this
.
selection
.
setStartOffset
(
0
)
me
.
selection
.
setEndOffset
(
i
+
(
dir
==
1
?
1
:
0
))
}
else
if
(
currentIndex
==
this
.
textData
.
length
){
this
.
selection
.
setEndOffset
(
currentIndex
)
}
else
{
if
(
currentIndex
>
this
.
index
){
this
.
selection
.
setEndOffset
(
currentIndex
)
}
else
if
(
currentIndex
<
this
.
index
){
this
.
selection
.
setStartOffset
(
currentIndex
)
}
else
{
}
else
{
this
.
selection
.
collapse
()
me
.
selection
.
setStartOffset
(
i
+
(
dir
==
1
?
1
:
0
))
}
}
}
return
false
;
}
});
return
this
;
return
this
;
},
},
updateSelectionShow
:
function
(
dir
){
updateSelectionShow
:
function
(){
var
startOffset
=
this
.
textData
[
this
.
selection
.
startOffset
],
var
startOffset
=
this
.
textData
[
this
.
selection
.
startOffset
],
endOffset
=
this
.
textData
[
this
.
selection
.
endOffset
],
endOffset
=
this
.
textData
[
this
.
selection
.
endOffset
],
width
=
0
;
width
=
0
;
if
(
this
.
selection
.
isC
ollapsed
){
if
(
this
.
selection
.
c
ollapsed
){
this
.
selection
.
updateShow
(
startOffset
,
0
);
this
.
selection
.
updateShow
(
startOffset
,
0
);
return
this
;
return
this
;
...
@@ -268,7 +255,11 @@ Minder.Receiver = kity.createClass('Receiver',{
...
@@ -268,7 +255,11 @@ Minder.Receiver = kity.createClass('Receiver',{
this
.
selection
.
updateShow
(
startOffset
,
width
);
this
.
selection
.
updateShow
(
startOffset
,
width
);
return
this
;
return
this
;
},
},
updateNativeRange
:
function
(){
updateRange
:
function
(
range
){
var
node
=
this
.
container
.
firstChild
;
range
.
setStart
(
node
,
this
.
selection
.
startOffset
);
range
.
setEnd
(
node
,
this
.
selection
.
endOffset
);
range
.
select
();
return
this
;
}
}
});
});
\ No newline at end of file
src/module/editor.selection.js
View file @
0ca54e93
...
@@ -10,7 +10,7 @@ Minder.Selection = kity.createClass( 'Selection', {
...
@@ -10,7 +10,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this
.
fill
(
'#99C8FF'
);
this
.
fill
(
'#99C8FF'
);
this
.
setHide
();
this
.
setHide
();
this
.
timer
=
null
;
this
.
timer
=
null
;
this
.
isC
ollapsed
=
true
;
this
.
c
ollapsed
=
true
;
this
.
startOffset
=
this
.
endOffset
=
0
;
this
.
startOffset
=
this
.
endOffset
=
0
;
this
.
setOpacity
(
0.5
)
this
.
setOpacity
(
0.5
)
},
},
...
@@ -18,7 +18,7 @@ Minder.Selection = kity.createClass( 'Selection', {
...
@@ -18,7 +18,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this
.
stroke
(
'blue'
,
1
);
this
.
stroke
(
'blue'
,
1
);
this
.
width
=
1
;
this
.
width
=
1
;
this
.
isC
ollapsed
=
true
;
this
.
c
ollapsed
=
true
;
if
(
toEnd
){
if
(
toEnd
){
this
.
startOffset
=
this
.
endOffset
this
.
startOffset
=
this
.
endOffset
}
else
{
}
else
{
...
@@ -36,7 +36,7 @@ Minder.Selection = kity.createClass( 'Selection', {
...
@@ -36,7 +36,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this
.
collapse
();
this
.
collapse
();
return
this
;
return
this
;
}
}
this
.
isC
ollapsed
=
false
;
this
.
c
ollapsed
=
false
;
this
.
stroke
(
'none'
);
this
.
stroke
(
'none'
);
return
this
;
return
this
;
},
},
...
@@ -50,7 +50,7 @@ Minder.Selection = kity.createClass( 'Selection', {
...
@@ -50,7 +50,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this
.
collapse
();
this
.
collapse
();
return
this
;
return
this
;
}
}
this
.
isC
ollapsed
=
false
;
this
.
c
ollapsed
=
false
;
this
.
stroke
(
'none'
);
this
.
stroke
(
'none'
);
return
this
;
return
this
;
},
},
...
...
src/module/icon.js
View file @
0ca54e93
KityMinder
.
registerModule
(
"IconModule"
,
function
()
{
KityMinder
.
registerModule
(
"IconModule"
,
function
()
{
var
renderPriorityIcon
=
function
(
node
,
val
)
{
var
colors
=
[
""
,
"red"
,
"blue"
,
"green"
,
"orange"
,
"purple"
];
var
_bg
=
new
kity
.
Rect
().
fill
(
colors
[
val
]
).
setRadius
(
3
).
setWidth
(
20
).
setHeight
(
20
);
var
_number
=
new
kity
.
Text
().
setContent
(
val
).
fill
(
"white"
).
setSize
(
12
);
var
_rc
=
new
kity
.
Group
();
_rc
.
addShapes
(
[
_bg
,
_number
]
);
node
.
getIconRc
().
addShape
(
_rc
);
_number
.
setTransform
(
new
kity
.
Matrix
().
translate
(
6
,
15
)
);
};
var
renderProgressIcon
=
function
(
node
,
val
,
left
)
{
var
_rc
=
new
kity
.
Group
();
var
_bg
=
new
kity
.
Circle
().
setRadius
(
8
).
fill
(
"white"
).
stroke
(
new
kity
.
Pen
(
"blue"
,
2
)
);
var
_percent
,
d
;
if
(
val
<
5
)
{
_percent
=
new
kity
.
Path
();
d
=
_percent
.
getDrawer
();
d
.
moveTo
(
0
,
0
).
lineTo
(
6
,
0
);
}
else
_percent
=
new
kity
.
Group
();
_rc
.
addShapes
(
[
_bg
,
_percent
]
);
node
.
getIconRc
().
addShape
(
_rc
);
_rc
.
setTransform
(
new
kity
.
Matrix
().
translate
(
left
,
10
)
);
_percent
.
setTransform
(
10
,
10
);
switch
(
val
)
{
case
1
:
break
;
case
2
:
d
.
carcTo
(
6
,
0
,
-
6
);
break
;
case
3
:
d
.
carcTo
(
6
,
-
6
,
0
);
break
;
case
4
:
d
.
carcTo
(
6
,
0
,
6
,
1
,
0
);
break
;
case
5
:
_percent
.
addShape
(
new
kity
.
Circle
().
setRadius
(
6
).
fill
(
"blue"
)
);
break
;
}
if
(
val
<
5
)
d
.
close
();
_percent
.
fill
(
"blue"
);
};
var
ChangeIconCommand
=
kity
.
createClass
(
"AddIconCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
,
iconType
,
value
)
{
var
nodes
=
km
.
getSelectedNodes
();
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
nodes
[
i
].
setData
(
iconType
,
value
);
km
.
updateLayout
(
nodes
[
i
]
);
}
}
};
}
)()
);
var
RemoveIconCommand
=
kity
.
createClass
(
"RemoveIconCommand"
,
(
function
()
{
return
{
base
:
Command
,
execute
:
function
(
km
,
iconType
)
{
var
nodes
=
km
.
getSelectedNodes
();
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
nodes
[
i
].
setData
(
iconType
,
null
);
km
.
updateLayout
(
nodes
[
i
]
);
}
}
};
}
)()
);
return
{
return
{
"commands"
:
{
"commands"
:
{
"changeicon"
:
ChangeIconCommand
,
"removeicon"
:
RemoveIconCommand
},
},
"events"
:
{
"events"
:
{
"RenderNode"
:
function
(
e
)
{
var
node
=
e
.
node
;
var
iconRc
=
node
.
getIconRc
();
var
PriorityIconVal
=
node
.
getData
(
"PriorityIcon"
);
var
ProgressIconVal
=
node
.
getData
(
"ProgressIcon"
);
//依次排布图标、文字
iconRc
.
setTransform
(
new
kity
.
Matrix
().
translate
(
0
,
-
20
)
);
iconRc
.
clear
();
var
PriorityIconWidth
=
0
;
if
(
PriorityIconVal
)
{
renderPriorityIcon
(
node
,
PriorityIconVal
);
PriorityIconWidth
=
22
;
}
if
(
ProgressIconVal
)
{
renderProgressIcon
(
node
,
ProgressIconVal
,
PriorityIconWidth
+
10
);
}
var
iconWidth
=
iconRc
.
getWidth
();
var
textShape
=
node
.
getTextShape
();
if
(
iconWidth
)
textShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
iconWidth
+
5
,
0
)
);
}
}
}
};
};
}
);
}
);
\ No newline at end of file
src/module/select.js
View file @
0ca54e93
...
@@ -87,7 +87,13 @@ KityMinder.registerModule( "Select", function () {
...
@@ -87,7 +87,13 @@ KityMinder.registerModule( "Select", function () {
}
}
},
},
mousemove
:
marqueeActivator
.
selectMove
,
mousemove
:
marqueeActivator
.
selectMove
,
mouseup
:
marqueeActivator
.
selectEnd
mouseup
:
function
(
e
)
{
var
clickNode
=
e
.
getTargetNode
();
if
(
clickNode
&&
clickNode
.
isSelected
()
&&
!
this
.
isSingleSelect
()
)
{
this
.
select
(
clickNode
,
true
);
}
marqueeActivator
.
selectEnd
(
e
);
}
}
}
};
};
}
);
}
);
\ No newline at end of file
src/module/zoom.js
View file @
0ca54e93
KityMinder
.
registerModule
(
'Zoom'
,
function
()
{
KityMinder
.
registerModule
(
'Zoom'
,
function
()
{
/*
return {
return {
events: {
events: {
'mousewheel': function ( e ) {
'mousewheel': function ( e ) {
...
@@ -18,5 +18,6 @@ KityMinder.registerModule( 'Zoom', function () {
...
@@ -18,5 +18,6 @@ KityMinder.registerModule( 'Zoom', function () {
this._zoom = 1;
this._zoom = 1;
}
}
}
}
};
};*/
return
{};
}
);
}
);
\ 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