Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
d73a4200
I
incubator-echarts
项目概览
x649585723
/
incubator-echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
incubator-echarts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d73a4200
编写于
3月 05, 2019
作者:
D
deqingli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sankey): change code style to reduce the size of code in sankeyLayout.js
上级
c8f5205b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
112 deletion
+58
-112
src/chart/sankey/sankeyLayout.js
src/chart/sankey/sankeyLayout.js
+58
-112
未找到文件。
src/chart/sankey/sankeyLayout.js
浏览文件 @
d73a4200
...
...
@@ -142,12 +142,9 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
maxNodeDepth
=
item
.
depth
;
}
node
.
setLayout
({
depth
:
isItemDepth
?
item
.
depth
:
x
},
true
);
if
(
orient
===
'
vertical
'
)
{
node
.
setLayout
({
dy
:
nodeWidth
},
true
);
}
else
{
node
.
setLayout
({
dx
:
nodeWidth
},
true
);
}
orient
===
'
vertical
'
?
node
.
setLayout
({
dy
:
nodeWidth
},
true
)
:
node
.
setLayout
({
dx
:
nodeWidth
},
true
);
for
(
var
edgeIdx
=
0
;
edgeIdx
<
node
.
outEdges
.
length
;
edgeIdx
++
)
{
var
edge
=
node
.
outEdges
[
edgeIdx
];
var
indexEdge
=
edges
.
indexOf
(
edge
);
...
...
@@ -174,7 +171,8 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
if
(
nodeAlign
&&
nodeAlign
!==
'
left
'
)
{
adjustNodeWithNodeAlign
(
nodes
,
nodeAlign
,
orient
,
maxDepth
);
}
var
kx
=
orient
===
'
vertical
'
?
(
height
-
nodeWidth
)
/
maxDepth
:
(
width
-
nodeWidth
)
/
maxDepth
;
var
kx
=
orient
===
'
vertical
'
?
(
height
-
nodeWidth
)
/
maxDepth
:
(
width
-
nodeWidth
)
/
maxDepth
;
scaleNodeBreadths
(
nodes
,
kx
,
orient
);
}
...
...
@@ -211,7 +209,7 @@ function adjustNodeWithNodeAlign(nodes, nodeAlign, orient, maxDepth) {
});
}
else
if
(
nodeAlign
===
'
justify
'
)
{
moveSinksRight
(
nodes
,
maxDepth
,
orient
);
moveSinksRight
(
nodes
,
maxDepth
);
}
}
...
...
@@ -219,11 +217,10 @@ function adjustNodeWithNodeAlign(nodes, nodeAlign, orient, maxDepth) {
* All the node without outEgdes are assigned maximum x-position and
* be aligned in the last column.
*
* @param {module:echarts/data/Graph~Node} nodes node of sankey view
* @param {number} x value (x-1) use to assign to node without outEdges
* as x-position
* @param {module:echarts/data/Graph~Node} nodes. node of sankey view.
* @param {number} maxDepth. use to assign to node without outEdges as x-position.
*/
function
moveSinksRight
(
nodes
,
maxDepth
,
orient
)
{
function
moveSinksRight
(
nodes
,
maxDepth
)
{
zrUtil
.
each
(
nodes
,
function
(
node
)
{
if
(
!
isNodeDepth
(
node
)
&&
!
node
.
outEdges
.
length
)
{
node
.
setLayout
({
depth
:
maxDepth
},
true
);
...
...
@@ -240,12 +237,8 @@ function moveSinksRight(nodes, maxDepth, orient) {
function
scaleNodeBreadths
(
nodes
,
kx
,
orient
)
{
zrUtil
.
each
(
nodes
,
function
(
node
)
{
var
nodeDepth
=
node
.
getLayout
().
depth
*
kx
;
if
(
orient
===
'
vertical
'
)
{
node
.
setLayout
({
y
:
nodeDepth
},
true
);
}
else
{
node
.
setLayout
({
x
:
nodeDepth
},
true
);
}
orient
===
'
vertical
'
?
node
.
setLayout
({
y
:
nodeDepth
},
true
)
:
node
.
setLayout
({
x
:
nodeDepth
},
true
);
});
}
...
...
@@ -304,31 +297,23 @@ function prepareNodesByBreadth(nodes, orient) {
* @param {number} nodeGap the vertical distance between two nodes
*/
function
initializeNodeDepth
(
nodesByBreadth
,
edges
,
height
,
width
,
nodeGap
,
orient
)
{
var
kyArray
=
[]
;
var
minKy
=
Infinity
;
zrUtil
.
each
(
nodesByBreadth
,
function
(
nodes
)
{
var
n
=
nodes
.
length
;
var
sum
=
0
;
var
ky
=
0
;
zrUtil
.
each
(
nodes
,
function
(
node
)
{
sum
+=
node
.
getLayout
().
value
;
});
if
(
orient
===
'
vertical
'
)
{
ky
=
(
width
-
(
n
-
1
)
*
nodeGap
)
/
sum
;
var
ky
=
orient
===
'
vertical
'
?
(
width
-
(
n
-
1
)
*
nodeGap
)
/
sum
:
(
height
-
(
n
-
1
)
*
nodeGap
)
/
sum
;
if
(
ky
<
minKy
)
{
minKy
=
ky
;
}
else
{
ky
=
(
height
-
(
n
-
1
)
*
nodeGap
)
/
sum
;
}
kyArray
.
push
(
ky
);
});
kyArray
.
sort
(
function
(
a
,
b
)
{
return
a
-
b
;
});
var
ky0
=
kyArray
[
0
];
zrUtil
.
each
(
nodesByBreadth
,
function
(
nodes
)
{
zrUtil
.
each
(
nodes
,
function
(
node
,
i
)
{
var
nodeDy
=
node
.
getLayout
().
value
*
ky0
;
var
nodeDy
=
node
.
getLayout
().
value
*
minKy
;
if
(
orient
===
'
vertical
'
)
{
node
.
setLayout
({
x
:
i
},
true
);
node
.
setLayout
({
dx
:
nodeDy
},
true
);
...
...
@@ -337,12 +322,11 @@ function initializeNodeDepth(nodesByBreadth, edges, height, width, nodeGap, orie
node
.
setLayout
({
y
:
i
},
true
);
node
.
setLayout
({
dy
:
nodeDy
},
true
);
}
});
});
zrUtil
.
each
(
edges
,
function
(
edge
)
{
var
edgeDy
=
+
edge
.
getValue
()
*
ky0
;
var
edgeDy
=
+
edge
.
getValue
()
*
minKy
;
edge
.
setLayout
({
dy
:
edgeDy
},
true
);
});
}
...
...
@@ -356,73 +340,44 @@ function initializeNodeDepth(nodesByBreadth, edges, height, width, nodeGap, orie
* @param {number} height the whole height of the area to draw the view
*/
function
resolveCollisions
(
nodesByBreadth
,
nodeGap
,
height
,
width
,
orient
)
{
var
keyAttr
=
orient
===
'
vertical
'
?
'
x
'
:
'
y
'
;
zrUtil
.
each
(
nodesByBreadth
,
function
(
nodes
)
{
nodes
.
sort
(
function
(
a
,
b
)
{
return
a
.
getLayout
()[
keyAttr
]
-
b
.
getLayout
()[
keyAttr
];
});
var
nodeX
;
var
node
;
var
dy
;
var
y0
=
0
;
var
n
=
nodes
.
length
;
var
i
;
if
(
orient
===
'
vertical
'
)
{
var
nodeX
;
nodes
.
sort
(
function
(
a
,
b
)
{
return
a
.
getLayout
().
x
-
b
.
getLayout
().
x
;
});
for
(
i
=
0
;
i
<
n
;
i
++
)
{
node
=
nodes
[
i
];
dy
=
y0
-
node
.
getLayout
().
x
;
if
(
dy
>
0
)
{
nodeX
=
node
.
getLayout
().
x
+
dy
;
node
.
setLayout
({
x
:
nodeX
},
true
);
}
y0
=
node
.
getLayout
().
x
+
node
.
getLayout
().
dx
+
nodeGap
;
}
// If the bottommost node goes outside the bounds, push it back up
dy
=
y0
-
nodeGap
-
width
;
var
nodeDyAttr
=
orient
===
'
vertical
'
?
'
dx
'
:
'
dy
'
;
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
node
=
nodes
[
i
];
dy
=
y0
-
node
.
getLayout
()[
keyAttr
];
if
(
dy
>
0
)
{
nodeX
=
node
.
getLayout
().
x
-
dy
;
node
.
setLayout
({
x
:
nodeX
},
true
);
y0
=
nodeX
;
for
(
i
=
n
-
2
;
i
>=
0
;
--
i
)
{
node
=
nodes
[
i
];
dy
=
node
.
getLayout
().
x
+
node
.
getLayout
().
dx
+
nodeGap
-
y0
;
if
(
dy
>
0
)
{
nodeX
=
node
.
getLayout
().
x
-
dy
;
node
.
setLayout
({
x
:
nodeX
},
true
);
}
y0
=
node
.
getLayout
().
x
;
}
nodeX
=
node
.
getLayout
()[
keyAttr
]
+
dy
;
orient
===
'
vertical
'
?
node
.
setLayout
({
x
:
nodeX
},
true
)
:
node
.
setLayout
({
y
:
nodeX
},
true
);
}
y0
=
node
.
getLayout
()[
keyAttr
]
+
node
.
getLayout
()[
nodeDyAttr
]
+
nodeGap
;
}
else
{
var
nodeY
;
nodes
.
sort
(
function
(
a
,
b
)
{
return
a
.
getLayout
().
y
-
b
.
getLayout
().
y
;
});
for
(
i
=
0
;
i
<
n
;
i
++
)
{
var
viewWidth
=
orient
===
'
vertical
'
?
width
:
height
;
// If the bottommost node goes outside the bounds, push it back up
dy
=
y0
-
nodeGap
-
viewWidth
;
if
(
dy
>
0
)
{
nodeX
=
node
.
getLayout
()[
keyAttr
]
-
dy
;
orient
===
'
vertical
'
?
node
.
setLayout
({
x
:
nodeX
},
true
)
:
node
.
setLayout
({
y
:
nodeX
},
true
);
y0
=
nodeX
;
for
(
i
=
n
-
2
;
i
>=
0
;
--
i
)
{
node
=
nodes
[
i
];
dy
=
y0
-
node
.
getLayout
().
y
;
dy
=
node
.
getLayout
()[
keyAttr
]
+
node
.
getLayout
()[
nodeDyAttr
]
+
nodeGap
-
y0
;
if
(
dy
>
0
)
{
nodeY
=
node
.
getLayout
().
y
+
dy
;
node
.
setLayout
({
y
:
nodeY
},
true
);
}
y0
=
node
.
getLayout
().
y
+
node
.
getLayout
().
dy
+
nodeGap
;
}
// If the bottommost node goes outside the bounds, push it back up
dy
=
y0
-
nodeGap
-
height
;
if
(
dy
>
0
)
{
nodeY
=
node
.
getLayout
().
y
-
dy
;
node
.
setLayout
({
y
:
nodeY
},
true
);
y0
=
nodeY
;
for
(
i
=
n
-
2
;
i
>=
0
;
--
i
)
{
node
=
nodes
[
i
];
dy
=
node
.
getLayout
().
y
+
node
.
getLayout
().
dy
+
nodeGap
-
y0
;
if
(
dy
>
0
)
{
nodeY
=
node
.
getLayout
().
y
-
dy
;
node
.
setLayout
({
y
:
nodeY
},
true
);
}
y0
=
node
.
getLayout
().
y
;
nodeX
=
node
.
getLayout
()[
keyAttr
]
-
dy
;
orient
===
'
vertical
'
?
node
.
setLayout
({
x
:
nodeX
},
true
)
:
node
.
setLayout
({
y
:
nodeX
},
true
);
}
y0
=
node
.
getLayout
()[
keyAttr
];
}
}
});
...
...
@@ -439,7 +394,8 @@ function relaxRightToLeft(nodesByBreadth, alpha, orient) {
zrUtil
.
each
(
nodesByBreadth
.
slice
().
reverse
(),
function
(
nodes
)
{
zrUtil
.
each
(
nodes
,
function
(
node
)
{
if
(
node
.
outEdges
.
length
)
{
var
y
=
sum
(
node
.
outEdges
,
weightedTarget
,
orient
)
/
sum
(
node
.
outEdges
,
getEdgeValue
,
orient
);
var
y
=
sum
(
node
.
outEdges
,
weightedTarget
,
orient
)
/
sum
(
node
.
outEdges
,
getEdgeValue
,
orient
);
if
(
orient
===
'
vertical
'
)
{
var
nodeX
=
node
.
getLayout
().
x
+
(
y
-
center
(
node
,
orient
))
*
alpha
;
node
.
setLayout
({
x
:
nodeX
},
true
);
...
...
@@ -462,10 +418,8 @@ function weightedSource(edge, orient) {
}
function
center
(
node
,
orient
)
{
if
(
orient
===
'
vertical
'
)
{
return
node
.
getLayout
().
x
+
node
.
getLayout
().
dx
/
2
;
}
return
node
.
getLayout
().
y
+
node
.
getLayout
().
dy
/
2
;
return
orient
===
'
vertical
'
?
node
.
getLayout
().
x
+
node
.
getLayout
().
dx
/
2
:
node
.
getLayout
().
y
+
node
.
getLayout
().
dy
/
2
;
}
function
getEdgeValue
(
edge
)
{
...
...
@@ -496,7 +450,8 @@ function relaxLeftToRight(nodesByBreadth, alpha, orient) {
zrUtil
.
each
(
nodesByBreadth
,
function
(
nodes
)
{
zrUtil
.
each
(
nodes
,
function
(
node
)
{
if
(
node
.
inEdges
.
length
)
{
var
y
=
sum
(
node
.
inEdges
,
weightedSource
,
orient
)
/
sum
(
node
.
inEdges
,
getEdgeValue
,
orient
);
var
y
=
sum
(
node
.
inEdges
,
weightedSource
,
orient
)
/
sum
(
node
.
inEdges
,
getEdgeValue
,
orient
);
if
(
orient
===
'
vertical
'
)
{
var
nodeX
=
node
.
getLayout
().
x
+
(
y
-
center
(
node
,
orient
))
*
alpha
;
node
.
setLayout
({
x
:
nodeX
},
true
);
...
...
@@ -516,23 +471,14 @@ function relaxLeftToRight(nodesByBreadth, alpha, orient) {
* @param {module:echarts/data/Graph~Node} nodes node of sankey view
*/
function
computeEdgeDepths
(
nodes
,
orient
)
{
var
keyAttr
=
orient
===
'
vertical
'
?
'
x
'
:
'
y
'
;
zrUtil
.
each
(
nodes
,
function
(
node
)
{
if
(
orient
===
'
vertical
'
)
{
node
.
outEdges
.
sort
(
function
(
a
,
b
)
{
return
a
.
node2
.
getLayout
().
x
-
b
.
node2
.
getLayout
().
x
;
});
node
.
inEdges
.
sort
(
function
(
a
,
b
)
{
return
a
.
node1
.
getLayout
().
x
-
b
.
node1
.
getLayout
().
x
;
});
}
else
{
node
.
outEdges
.
sort
(
function
(
a
,
b
)
{
return
a
.
node2
.
getLayout
().
y
-
b
.
node2
.
getLayout
().
y
;
});
node
.
inEdges
.
sort
(
function
(
a
,
b
)
{
return
a
.
node1
.
getLayout
().
y
-
b
.
node1
.
getLayout
().
y
;
});
}
node
.
outEdges
.
sort
(
function
(
a
,
b
)
{
return
a
.
node2
.
getLayout
()[
keyAttr
]
-
b
.
node2
.
getLayout
()[
keyAttr
];
});
node
.
inEdges
.
sort
(
function
(
a
,
b
)
{
return
a
.
node1
.
getLayout
()[
keyAttr
]
-
b
.
node1
.
getLayout
()[
keyAttr
];
});
});
zrUtil
.
each
(
nodes
,
function
(
node
)
{
var
sy
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录