Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
47456544
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,发现更多精彩内容 >>
提交
47456544
编写于
9月 25, 2015
作者:
P
pah100
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix topology bug
上级
d2f2dcf2
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
122 addition
and
59 deletion
+122
-59
src/model/Component.js
src/model/Component.js
+4
-1
src/model/Global.js
src/model/Global.js
+21
-11
src/util/component.js
src/util/component.js
+50
-34
test/ut/spec/model/Component.js
test/ut/spec/model/Component.js
+47
-13
未找到文件。
src/model/Component.js
浏览文件 @
47456544
...
...
@@ -97,7 +97,10 @@ define(function(require) {
zrUtil
.
each
(
ComponentModel
.
getClassesByMainType
(
componentType
),
function
(
Clazz
)
{
arrayPush
.
apply
(
deps
,
Clazz
.
prototype
.
dependencies
||
[]);
});
return
deps
;
// Ensure main type
return
zrUtil
.
map
(
deps
,
function
(
type
)
{
return
ComponentModel
.
parseComponentType
(
type
).
main
;
});
}
return
ComponentModel
;
...
...
src/model/Global.js
浏览文件 @
47456544
...
...
@@ -97,7 +97,7 @@ define(function (require) {
var
option
=
this
.
option
;
var
componentsMap
=
this
.
_componentsMap
;
var
componen
tTypes
=
[];
var
newCp
tTypes
=
[];
// 如果不存在对应的 component model 则直接 merge
zrUtil
.
each
(
newOption
,
function
(
componentOption
,
componentType
)
{
...
...
@@ -112,13 +112,16 @@ define(function (require) {
}
}
else
{
componen
tTypes
.
push
(
componentType
);
newCp
tTypes
.
push
(
componentType
);
}
});
// FIXME 这里 componentTypes 是新的 Option,在依赖处理上是否会有问题
// FIXME OPTION 同步是否要改回原来的
ComponentModel
.
topologicalTravel
(
componentTypes
,
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
(
newCptTypes
,
ComponentModel
.
getAllClassMainTypes
(),
visitComponent
,
this
);
function
visitComponent
(
componentType
,
dependencies
)
{
var
newCptOptionList
=
newOption
[
componentType
];
// Normalize
...
...
@@ -158,7 +161,7 @@ define(function (require) {
this
.
_componentsIdMap
[
componentModel
.
uid
]
=
componentModel
;
}
}
}
,
this
);
}
// Backup data
zrUtil
.
each
(
componentsMap
,
function
(
components
,
componentType
)
{
...
...
@@ -177,7 +180,10 @@ define(function (require) {
// Use determinSubType only when there is no existComponent.
:
ComponentModel
.
determineSubType
(
componentType
,
newCptOption
);
return
newCptOption
.
type
=
subType
;
// Dont make option.type === undefined, otherwise some problem will occur in merge.
subType
&&
(
newCptOption
.
type
=
subType
);
return
subType
;
},
/**
...
...
@@ -373,11 +379,15 @@ define(function (require) {
componentTypes
.
push
(
componentType
);
});
ComponentModel
.
topologicalTravel
(
componentTypes
,
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
(
componentTypes
,
ComponentModel
.
getAllClassMainTypes
(),
function
(
componentType
,
dependencies
)
{
zrUtil
.
each
(
componentsMap
[
componentType
],
function
(
component
)
{
component
.
restoreData
();
});
});
}
);
},
/**
...
...
src/util/component.js
浏览文件 @
47456544
...
...
@@ -123,10 +123,8 @@ define(function(require) {
var
obj
=
storage
[
componentType
.
main
];
if
(
obj
&&
obj
[
IS_CONTAINER
])
{
zrUtil
.
each
(
obj
,
function
(
ComponentClass
,
componentType
)
{
if
(
componentType
!==
IS_CONTAINER
)
{
result
.
push
(
ComponentClass
);
}
zrUtil
.
each
(
obj
,
function
(
o
,
type
)
{
type
!==
IS_CONTAINER
&&
result
.
push
(
o
);
});
}
else
{
...
...
@@ -142,6 +140,17 @@ define(function(require) {
return
!!
storage
[
componentType
.
main
];
};
/**
* @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
*/
entity
.
getAllClassMainTypes
=
function
()
{
var
types
=
[];
zrUtil
.
each
(
storage
,
function
(
obj
,
type
)
{
types
.
push
(
type
);
});
return
types
;
};
entity
.
parseComponentType
=
parseComponentType
;
function
makeContainer
(
componentType
)
{
...
...
@@ -187,10 +196,9 @@ define(function(require) {
if
(
!
type
)
{
var
componentTypeMain
=
parseComponentType
(
componentType
).
main
;
var
Clazz
=
storage
[
componentTypeMain
];
Clazz
&&
Clazz
[
IS_CONTAINER
]
&&
subTypeDefaulters
[
componentTypeMain
]
&&
subTypeDefaulters
[
componentTypeMain
](
option
);
if
(
Clazz
&&
Clazz
[
IS_CONTAINER
]
&&
subTypeDefaulters
[
componentTypeMain
])
{
type
=
subTypeDefaulters
[
componentTypeMain
](
option
);
}
}
return
type
;
};
...
...
@@ -201,34 +209,42 @@ define(function(require) {
/**
* Topological travel on Activity Network (Activity On Vertices).
* Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
*
* If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
*
* If there are circle dependenceis, just ignore them.
*
*/
util
.
enableTopologicalTravel
=
function
(
entity
,
dependencyGetter
)
{
/**
* @public
* @param {Array.<string>}
componentTyp
eList Target Component type list.
* @param {Array.<string>}
targetNam
eList Target Component type list.
* Can be ['aa', 'bb', 'aa.xx']
* @param {Array.<string>} fullNameList By which we can build dependency graph.
* @param {Function} callback Params: componentType, dependencies.
* @param {Object} context Scope of callback.
*/
entity
.
topologicalTravel
=
function
(
componentTyp
eList
,
callback
,
context
)
{
if
(
!
componentTyp
eList
.
length
)
{
entity
.
topologicalTravel
=
function
(
targetNameList
,
fullNam
eList
,
callback
,
context
)
{
if
(
!
targetNam
eList
.
length
)
{
return
;
}
var
result
=
makeDepndencyGraph
(
componentTypeList
);
var
result
=
makeDepndencyGraph
(
fullNameList
);
var
graph
=
result
.
graph
;
var
stack
=
result
.
noEntryList
;
if
(
!
stack
.
length
)
{
throw
new
Error
(
'
Circle exists in dependency graph.
'
);
}
var
targetNameSet
=
{};
zrUtil
.
each
(
targetNameList
,
function
(
name
)
{
targetNameSet
[
name
]
=
true
;
});
while
(
stack
.
length
)
{
var
currComponentType
=
stack
.
pop
();
var
currVertex
=
graph
[
currComponentType
];
if
(
targetNameSet
[
currComponentType
])
{
callback
.
call
(
context
,
currComponentType
,
currVertex
.
originalDeps
.
slice
());
}
zrUtil
.
each
(
currVertex
.
successor
,
removeEdge
);
}
...
...
@@ -249,28 +265,28 @@ define(function(require) {
* entryCount: {number}
* }
*/
function
makeDepndencyGraph
(
componentTyp
eList
)
{
function
makeDepndencyGraph
(
fullNam
eList
)
{
var
graph
=
{};
var
noEntryList
=
[];
zrUtil
.
each
(
componentTypeList
,
function
(
componentTyp
e
)
{
zrUtil
.
each
(
fullNameList
,
function
(
nam
e
)
{
var
thisItem
=
createDependencyGraphItem
(
graph
,
componentTyp
e
);
var
originalDeps
=
thisItem
.
originalDeps
=
dependencyGetter
(
componentTyp
e
);
var
thisItem
=
createDependencyGraphItem
(
graph
,
nam
e
);
var
originalDeps
=
thisItem
.
originalDeps
=
dependencyGetter
(
nam
e
);
var
availableDeps
=
getAvailableDependencies
(
originalDeps
,
componentTyp
eList
);
var
availableDeps
=
getAvailableDependencies
(
originalDeps
,
fullNam
eList
);
thisItem
.
entryCount
=
availableDeps
.
length
;
if
(
thisItem
.
entryCount
===
0
)
{
noEntryList
.
push
(
componentTyp
e
);
noEntryList
.
push
(
nam
e
);
}
zrUtil
.
each
(
availableDeps
,
function
(
dep
ComponentTyp
e
)
{
if
(
zrUtil
.
indexOf
(
thisItem
.
predecessor
,
dep
ComponentTyp
e
)
<
0
)
{
thisItem
.
predecessor
.
push
(
dep
ComponentTyp
e
);
zrUtil
.
each
(
availableDeps
,
function
(
dep
endentNam
e
)
{
if
(
zrUtil
.
indexOf
(
thisItem
.
predecessor
,
dep
endentNam
e
)
<
0
)
{
thisItem
.
predecessor
.
push
(
dep
endentNam
e
);
}
var
thatItem
=
createDependencyGraphItem
(
graph
,
dep
ComponentTyp
e
);
if
(
zrUtil
.
indexOf
(
thatItem
.
successor
,
dep
ComponentTyp
e
)
<
0
)
{
thatItem
.
successor
.
push
(
componentTyp
e
);
var
thatItem
=
createDependencyGraphItem
(
graph
,
dep
endentNam
e
);
if
(
zrUtil
.
indexOf
(
thatItem
.
successor
,
dep
endentNam
e
)
<
0
)
{
thatItem
.
successor
.
push
(
nam
e
);
}
});
});
...
...
@@ -278,17 +294,17 @@ define(function(require) {
return
{
graph
:
graph
,
noEntryList
:
noEntryList
};
}
function
createDependencyGraphItem
(
graph
,
componentTyp
e
)
{
if
(
!
graph
[
componentTyp
e
])
{
graph
[
componentTyp
e
]
=
{
predecessor
:
[],
successor
:
[]};
function
createDependencyGraphItem
(
graph
,
nam
e
)
{
if
(
!
graph
[
nam
e
])
{
graph
[
nam
e
]
=
{
predecessor
:
[],
successor
:
[]};
}
return
graph
[
componentTyp
e
];
return
graph
[
nam
e
];
}
function
getAvailableDependencies
(
originalDeps
,
componentTyp
eList
)
{
function
getAvailableDependencies
(
originalDeps
,
fullNam
eList
)
{
var
availableDeps
=
[];
zrUtil
.
each
(
originalDeps
,
function
(
dep
)
{
zrUtil
.
indexOf
(
componentTyp
eList
,
dep
)
>=
0
&&
availableDeps
.
push
(
dep
);
zrUtil
.
indexOf
(
fullNam
eList
,
dep
)
>=
0
&&
availableDeps
.
push
(
dep
);
});
return
availableDeps
;
}
...
...
test/ut/spec/model/Component.js
浏览文件 @
47456544
...
...
@@ -23,7 +23,8 @@ describe('Component', function() {
ComponentModel
.
extend
({
type
:
'
a1
'
});
ComponentModel
.
extend
({
type
:
'
a2
'
});
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
],
function
(
componentType
,
dependencies
)
{
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a2
'
,
[]],
[
'
a1
'
,
[]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]]]);
...
...
@@ -32,8 +33,9 @@ describe('Component', function() {
testCase
(
'
topologicalTravel_a1IsAbsent
'
,
function
(
ComponentModel
)
{
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a2
'
});
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a2
'
],
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a2
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a2
'
,
[]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]]]);
...
...
@@ -43,8 +45,9 @@ describe('Component', function() {
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a1
'
});
ComponentModel
.
extend
({
type
:
'
a2
'
});
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
var
result
=
[];
ComponentModel
.
topologicalTravel
([],
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
([],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([]);
...
...
@@ -54,11 +57,12 @@ describe('Component', function() {
ComponentModel
.
extend
({
type
:
'
a2
'
});
ComponentModel
.
extend
({
type
:
'
a1
'
});
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a2
'
]});
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
a1
'
,
'
a2
'
,
'
m1
'
],
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
([
'
a1
'
,
'
a2
'
,
'
m1
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a
2
'
,
[]],
[
'
m1
'
,
[
'
a2
'
]],
[
'
a1
'
,
[
]]]);
expect
(
result
).
toEqual
([[
'
a
1
'
,
[]],
[
'
a2
'
,
[]],
[
'
m1
'
,
[
'
a2
'
]]]);
});
testCase
(
'
topologicalTravel_diamond
'
,
function
(
ComponentModel
)
{
...
...
@@ -66,8 +70,9 @@ describe('Component', function() {
ComponentModel
.
extend
({
type
:
'
a2
'
,
dependencies
:
[
'
a1
'
]});
ComponentModel
.
extend
({
type
:
'
a3
'
,
dependencies
:
[
'
a1
'
]});
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a2
'
,
'
a3
'
]});
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
,
'
a3
'
],
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
,
'
a3
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a1
'
,
[]],
[
'
a3
'
,
[
'
a1
'
]],
[
'
a2
'
,
[
'
a1
'
]],
[
'
m1
'
,
[
'
a2
'
,
'
a3
'
]]]);
...
...
@@ -76,31 +81,59 @@ describe('Component', function() {
testCase
(
'
topologicalTravel_loop
'
,
function
(
ComponentModel
)
{
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
m2
'
,
dependencies
:
[
'
m1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a1
'
,
dependencies
:
[
'
m2
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a1
'
,
dependencies
:
[
'
m2
'
,
'
a2
'
,
'
a3
'
]});
ComponentModel
.
extend
({
type
:
'
a2
'
});
expect
(
function
()
{
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
m2
'
,
'
a1
'
]);
}).
toThrowError
(
/Circl/
);
ComponentModel
.
extend
({
type
:
'
a3
'
});
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
m2
'
,
'
a1
'
,
'
a2
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a2
'
,
[]]]);
// expect(function () {
// ComponentModel.topologicalTravel(['m1', 'm2', 'a1'], allList);
// }).toThrowError(/Circl/);
});
testCase
(
'
topologicalTravel_multipleEchartsInstance
'
,
function
(
ComponentModel
)
{
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a1
'
});
ComponentModel
.
extend
({
type
:
'
a2
'
});
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
],
function
(
componentType
,
dependencies
)
{
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a2
'
,
[]],
[
'
a1
'
,
[]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]]]);
result
=
[];
ComponentModel
.
extend
({
type
:
'
m2
'
,
dependencies
:
[
'
a1
'
,
'
m1
'
]});
ComponentModel
.
topologicalTravel
([
'
m2
'
,
'
m1
'
,
'
a1
'
,
'
a2
'
],
function
(
componentType
,
dependencies
)
{
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
ComponentModel
.
topologicalTravel
([
'
m2
'
,
'
m1
'
,
'
a1
'
,
'
a2
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a2
'
,
[]],
[
'
a1
'
,
[]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]],
[
'
m2
'
,
[
'
a1
'
,
'
m1
'
]]]);
});
testCase
(
'
topologicalTravel_missingSomeNodeButHasDependencies
'
,
function
(
ComponentModel
)
{
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a2
'
,
dependencies
:
[
'
a3
'
]});
ComponentModel
.
extend
({
type
:
'
a3
'
});
ComponentModel
.
extend
({
type
:
'
a4
'
});
var
result
=
[];
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
ComponentModel
.
topologicalTravel
([
'
a3
'
,
'
m1
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a3
'
,
[]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]]]);
var
result
=
[];
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a3
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a3
'
,
[]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]]]);
});
testCase
(
'
topologicalTravel_subType
'
,
function
(
ComponentModel
)
{
ComponentModel
.
extend
({
type
:
'
m1
'
,
dependencies
:
[
'
a1
'
,
'
a2
'
]});
ComponentModel
.
extend
({
type
:
'
a1.aaa
'
,
dependencies
:
[
'
a2
'
]});
...
...
@@ -109,7 +142,8 @@ describe('Component', function() {
ComponentModel
.
extend
({
type
:
'
a3
'
});
ComponentModel
.
extend
({
type
:
'
a4
'
});
var
result
=
[];
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
,
'
a4
'
],
function
(
componentType
,
dependencies
)
{
var
allList
=
ComponentModel
.
getAllClassMainTypes
();
ComponentModel
.
topologicalTravel
([
'
m1
'
,
'
a1
'
,
'
a2
'
,
'
a4
'
],
allList
,
function
(
componentType
,
dependencies
)
{
result
.
push
([
componentType
,
dependencies
]);
});
expect
(
result
).
toEqual
([[
'
a4
'
,
[]],
[
'
a2
'
,[]],
[
'
a1
'
,
[
'
a2
'
,
'
a3
'
,
'
a4
'
]],
[
'
m1
'
,
[
'
a1
'
,
'
a2
'
]]]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录