Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
9e4c3b69
I
incubator-echarts
项目概览
半栈学徒
/
incubator-echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
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,发现更多精彩内容 >>
提交
9e4c3b69
编写于
2月 15, 2019
作者:
S
sushuang
提交者:
abigale Li
2月 15, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: Remove nest, which is not needed.
上级
34ee4b42
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
179 deletion
+60
-179
src/chart/sankey/sankeyLayout.js
src/chart/sankey/sankeyLayout.js
+17
-19
src/chart/themeRiver/ThemeRiverSeries.js
src/chart/themeRiver/ThemeRiverSeries.js
+18
-33
src/util/model.js
src/util/model.js
+25
-0
src/util/nest.js
src/util/nest.js
+0
-127
未找到文件。
src/chart/sankey/sankeyLayout.js
浏览文件 @
9e4c3b69
...
@@ -23,8 +23,8 @@
...
@@ -23,8 +23,8 @@
*/
*/
import
*
as
layout
from
'
../../util/layout
'
;
import
*
as
layout
from
'
../../util/layout
'
;
import
nest
from
'
../../util/nest
'
;
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
import
{
groupData
}
from
'
../../util/model
'
;
import
{
__DEV__
}
from
'
../../config
'
;
import
{
__DEV__
}
from
'
../../config
'
;
export
default
function
(
ecModel
,
api
,
payload
)
{
export
default
function
(
ecModel
,
api
,
payload
)
{
...
@@ -230,15 +230,7 @@ function scaleNodeBreadths(nodes, kx, orient) {
...
@@ -230,15 +230,7 @@ function scaleNodeBreadths(nodes, kx, orient) {
* @param {number} iterations the number of iterations for the algorithm
* @param {number} iterations the number of iterations for the algorithm
*/
*/
function
computeNodeDepths
(
nodes
,
edges
,
height
,
width
,
nodeGap
,
iterations
,
orient
)
{
function
computeNodeDepths
(
nodes
,
edges
,
height
,
width
,
nodeGap
,
iterations
,
orient
)
{
var
nodesByBreadth
=
nest
()
var
nodesByBreadth
=
prepareNodesByBreadth
(
nodes
,
orient
);
.
key
(
getKeyFunction
(
orient
))
.
sortKeys
(
function
(
a
,
b
)
{
return
a
-
b
;
})
.
entries
(
nodes
)
.
map
(
function
(
d
)
{
return
d
.
values
;
});
initializeNodeDepth
(
nodes
,
nodesByBreadth
,
edges
,
height
,
width
,
nodeGap
,
orient
);
initializeNodeDepth
(
nodes
,
nodesByBreadth
,
edges
,
height
,
width
,
nodeGap
,
orient
);
resolveCollisions
(
nodesByBreadth
,
nodeGap
,
height
,
width
,
orient
);
resolveCollisions
(
nodesByBreadth
,
nodeGap
,
height
,
width
,
orient
);
...
@@ -254,15 +246,21 @@ function computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, ori
...
@@ -254,15 +246,21 @@ function computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, ori
}
}
}
}
function
getKeyFunction
(
orient
)
{
function
prepareNodesByBreadth
(
nodes
,
orient
)
{
if
(
orient
===
'
vertical
'
)
{
var
nodesByBreadth
=
[];
return
function
(
d
)
{
var
keyAttr
=
orient
===
'
vertical
'
?
'
y
'
:
'
x
'
;
return
d
.
getLayout
().
y
;
};
var
groupResult
=
groupData
(
nodes
,
function
(
node
)
{
}
return
node
.
getLayout
()[
keyAttr
];
return
function
(
d
)
{
});
return
d
.
getLayout
().
x
;
groupResult
.
keys
.
sort
(
function
(
a
,
b
)
{
};
return
a
-
b
;
});
zrUtil
.
each
(
groupResult
.
keys
,
function
(
key
)
{
nodesByBreadth
.
push
(
groupResult
.
buckets
.
get
(
key
));
});
return
nodesByBreadth
;
}
}
/**
/**
...
...
src/chart/themeRiver/ThemeRiverSeries.js
浏览文件 @
9e4c3b69
...
@@ -27,8 +27,8 @@ import createDimensions from '../../data/helper/createDimensions';
...
@@ -27,8 +27,8 @@ import createDimensions from '../../data/helper/createDimensions';
import
{
getDimensionTypeByAxis
}
from
'
../../data/helper/dimensionHelper
'
;
import
{
getDimensionTypeByAxis
}
from
'
../../data/helper/dimensionHelper
'
;
import
List
from
'
../../data/List
'
;
import
List
from
'
../../data/List
'
;
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
import
{
groupData
}
from
'
../../util/model
'
;
import
{
encodeHTML
}
from
'
../../util/format
'
;
import
{
encodeHTML
}
from
'
../../util/format
'
;
import
nest
from
'
../../util/nest
'
;
var
DATA_NAME_INDEX
=
2
;
var
DATA_NAME_INDEX
=
2
;
...
@@ -69,18 +69,12 @@ var ThemeRiverSeries = SeriesModel.extend({
...
@@ -69,18 +69,12 @@ var ThemeRiverSeries = SeriesModel.extend({
var
rawDataLength
=
data
.
length
;
var
rawDataLength
=
data
.
length
;
// grouped data by name
// grouped data by name
var
dataByName
=
nest
()
var
groupResult
=
groupData
(
data
,
function
(
item
)
{
.
key
(
function
(
dataItem
)
{
return
item
[
2
];
return
dataItem
[
2
];
});
})
var
layData
=
[];
.
entries
(
data
);
groupResult
.
buckets
.
each
(
function
(
items
,
key
)
{
layData
.
push
({
name
:
key
,
dataList
:
items
});
// data group in each layer
var
layData
=
zrUtil
.
map
(
dataByName
,
function
(
d
)
{
return
{
name
:
d
.
key
,
dataList
:
d
.
values
};
});
});
var
layerNum
=
layData
.
length
;
var
layerNum
=
layData
.
length
;
...
@@ -201,29 +195,20 @@ var ThemeRiverSeries = SeriesModel.extend({
...
@@ -201,29 +195,20 @@ var ThemeRiverSeries = SeriesModel.extend({
for
(
var
i
=
0
;
i
<
lenCount
;
++
i
)
{
for
(
var
i
=
0
;
i
<
lenCount
;
++
i
)
{
indexArr
[
i
]
=
i
;
indexArr
[
i
]
=
i
;
}
}
// data group by name
var
dataByName
=
nest
()
.
key
(
function
(
index
)
{
return
data
.
get
(
'
name
'
,
index
);
})
.
entries
(
indexArr
);
var
layerSeries
=
zrUtil
.
map
(
dataByName
,
function
(
d
)
{
return
{
name
:
d
.
key
,
indices
:
d
.
values
};
});
var
timeDim
=
data
.
mapDimension
(
'
single
'
);
var
timeDim
=
data
.
mapDimension
(
'
single
'
);
for
(
var
j
=
0
;
j
<
layerSeries
.
length
;
++
j
)
{
// data group by name
layerSeries
[
j
].
indices
.
sort
(
comparer
);
var
groupResult
=
groupData
(
indexArr
,
function
(
index
)
{
}
return
data
.
get
(
'
name
'
,
index
);
});
function
comparer
(
index1
,
index2
)
{
var
layerSeries
=
[];
return
data
.
get
(
timeDim
,
index1
)
-
data
.
get
(
timeDim
,
index2
);
groupResult
.
buckets
.
each
(
function
(
items
,
key
)
{
}
items
.
sort
(
function
(
index1
,
index2
)
{
return
data
.
get
(
timeDim
,
index1
)
-
data
.
get
(
timeDim
,
index2
);
});
layerSeries
.
push
({
name
:
key
,
indices
:
items
});
});
return
layerSeries
;
return
layerSeries
;
},
},
...
...
src/util/model.js
浏览文件 @
9e4c3b69
...
@@ -534,3 +534,28 @@ export function getTooltipRenderMode(renderModeOption) {
...
@@ -534,3 +534,28 @@ export function getTooltipRenderMode(renderModeOption) {
return
renderModeOption
||
'
html
'
;
return
renderModeOption
||
'
html
'
;
}
}
}
}
/**
* Group a list by key.
*
* @param {Array} array
* @param {Function} getKey
* param {*} Array item
* return {string} key
* @return {Object} Result
* {Array}: keys,
* {module:zrender/core/util/HashMap} buckets: {key -> Array}
*/
export
function
groupData
(
array
,
getKey
)
{
var
buckets
=
zrUtil
.
createHashMap
();
var
keys
=
[];
zrUtil
.
each
(
array
,
function
(
item
)
{
var
key
=
getKey
(
item
);
(
buckets
.
get
(
key
)
||
(
keys
.
push
(
key
),
buckets
.
set
(
key
,
[]))
).
push
(
item
);
});
return
{
keys
:
keys
,
buckets
:
buckets
};
}
src/util/nest.js
已删除
100644 → 0
浏览文件 @
34ee4b42
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* The implementation references to d3.js. The use of the source
* code of this file is also subject to the terms and consitions
* of its license (BSD-3Clause, see <echarts/src/licenses/LICENSE-d3>).
*/
import
*
as
zrUtil
from
'
zrender/src/core/util
'
;
/**
* nest helper used to group by the array.
* can specified the keys and sort the keys.
*/
export
default
function
nest
()
{
var
keysFunction
=
[];
var
sortKeysFunction
=
[];
/**
* map an Array into the mapObject.
* @param {Array} array
* @param {number} depth
*/
function
map
(
array
,
depth
)
{
if
(
depth
>=
keysFunction
.
length
)
{
return
array
;
}
var
i
=
-
1
;
var
n
=
array
.
length
;
var
keyFunction
=
keysFunction
[
depth
++
];
var
mapObject
=
{};
var
valuesByKey
=
{};
while
(
++
i
<
n
)
{
var
keyValue
=
keyFunction
(
array
[
i
]);
var
values
=
valuesByKey
[
keyValue
];
if
(
values
)
{
values
.
push
(
array
[
i
]);
}
else
{
valuesByKey
[
keyValue
]
=
[
array
[
i
]];
}
}
zrUtil
.
each
(
valuesByKey
,
function
(
value
,
key
)
{
mapObject
[
key
]
=
map
(
value
,
depth
);
});
return
mapObject
;
}
/**
* transform the Map Object to multidimensional Array
* @param {Object} map
* @param {number} depth
*/
function
entriesMap
(
mapObject
,
depth
)
{
if
(
depth
>=
keysFunction
.
length
)
{
return
mapObject
;
}
var
array
=
[];
var
sortKeyFunction
=
sortKeysFunction
[
depth
++
];
zrUtil
.
each
(
mapObject
,
function
(
value
,
key
)
{
array
.
push
({
key
:
key
,
values
:
entriesMap
(
value
,
depth
)
});
});
if
(
sortKeyFunction
)
{
return
array
.
sort
(
function
(
a
,
b
)
{
return
sortKeyFunction
(
a
.
key
,
b
.
key
);
});
}
return
array
;
}
return
{
/**
* specified the key to groupby the arrays.
* users can specified one more keys.
* @param {Function} d
*/
key
:
function
(
d
)
{
keysFunction
.
push
(
d
);
return
this
;
},
/**
* specified the comparator to sort the keys
* @param {Function} order
*/
sortKeys
:
function
(
order
)
{
sortKeysFunction
[
keysFunction
.
length
-
1
]
=
order
;
return
this
;
},
/**
* the array to be grouped by.
* @param {Array} array
*/
entries
:
function
(
array
)
{
return
entriesMap
(
map
(
array
,
0
),
0
);
}
};
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录