Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
a3d29cf6
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,发现更多精彩内容 >>
提交
a3d29cf6
编写于
7月 14, 2020
作者:
1
100pah
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: add test case for id duplicated.
上级
32a4b662
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
90 addition
and
21 deletion
+90
-21
src/model/Global.ts
src/model/Global.ts
+1
-1
src/util/model.ts
src/util/model.ts
+19
-13
test/lib/testHelper.js
test/lib/testHelper.js
+14
-5
test/option-replaceMerge.html
test/option-replaceMerge.html
+56
-2
未找到文件。
src/model/Global.ts
浏览文件 @
a3d29cf6
...
...
@@ -384,7 +384,7 @@ class GlobalModel extends Model<ECUnitOption> {
let
metNonInner
=
false
;
for
(
let
i
=
realLen
-
1
;
i
>=
0
;
i
--
)
{
// Remove options with inner id.
if
(
opts
[
i
]
&&
!
modelUtil
.
is
IdInner
(
opts
[
i
]))
{
if
(
opts
[
i
]
&&
!
modelUtil
.
is
ComponentIdInternal
(
opts
[
i
]))
{
metNonInner
=
true
;
}
else
{
...
...
src/util/model.ts
浏览文件 @
a3d29cf6
...
...
@@ -56,6 +56,8 @@ import { isNumeric } from './number';
*/
const
DUMMY_COMPONENT_NAME_PREFIX
=
'
series
\
0
'
;
const
INTERNAL_COMPONENT_ID_PREFIX
=
'
\
0_ec_
\
0
'
;
/**
* If value is not array, then translate it to array.
* @param {*} value
...
...
@@ -242,8 +244,8 @@ function mappingToExistsInNormalMerge<T extends MappingExistingItem>(
// Can not match when both ids existing but different.
&&
existing
&&
(
existing
.
id
==
null
||
cmptOption
.
id
==
null
)
&&
!
is
IdInner
(
cmptOption
)
&&
!
is
IdInner
(
existing
)
&&
!
is
ComponentIdInternal
(
cmptOption
)
&&
!
is
ComponentIdInternal
(
existing
)
&&
keyExistAndEqual
(
'
name
'
,
existing
,
cmptOption
)
)
{
result
[
i
].
newOption
=
cmptOption
;
...
...
@@ -264,7 +266,7 @@ function mappingToExistsInNormalMerge<T extends MappingExistingItem>(
* Mapping to exists for merge.
* The mode "replaceMerge" means that:
* (1) Only the id mapped components will be merged.
* (2) Other existing components (except in
ner
compoonets) will be removed.
* (2) Other existing components (except in
ternal
compoonets) will be removed.
* (3) Other new options will be used to create new component.
* (4) The index of the existing compoents will not be modified.
* That means their might be "hole" after the removal.
...
...
@@ -286,20 +288,20 @@ function mappingToExistsInReplaceMerge<T extends MappingExistingItem>(
// contains elided items, which will be ommited.
for
(
let
index
=
0
;
index
<
existings
.
length
;
index
++
)
{
const
existing
=
existings
[
index
];
let
in
ner
Existing
:
T
;
let
in
ternal
Existing
:
T
;
// Because of replaceMerge, `existing` may be null/undefined.
if
(
existing
)
{
if
(
is
IdInner
(
existing
))
{
// in
ner
components should not be removed.
in
ner
Existing
=
existing
;
if
(
is
ComponentIdInternal
(
existing
))
{
// in
ternal
components should not be removed.
in
ternal
Existing
=
existing
;
}
// Input with in
ner
id is allowed for convenience of some internal usage.
// Input with in
ternal
id is allowed for convenience of some internal usage.
// When `existing` is rawOption (see `OptionManager`#`mergeOption`), id might be empty.
if
(
existing
.
id
!=
null
)
{
existingIdIdxMap
.
set
(
existing
.
id
,
index
);
}
}
result
.
push
({
existing
:
in
ner
Existing
});
result
.
push
({
existing
:
in
ternal
Existing
});
}
// Mapping by id if specified.
...
...
@@ -350,7 +352,7 @@ function mappingByIndexFinally<T extends MappingExistingItem>(
return
;
}
// Find the first place that not mapped by id and not in
ner
component (consider the "hole").
// Find the first place that not mapped by id and not in
ternal
component (consider the "hole").
let
resultItem
;
while
(
// Be `!resultItem` only when `nextIdx >= mappingResult.length`.
...
...
@@ -368,7 +370,7 @@ function mappingByIndexFinally<T extends MappingExistingItem>(
&&
!
keyExistAndEqual
(
'
id
'
,
cmptOption
,
resultItem
.
existing
)
)
||
resultItem
.
newOption
||
is
IdInner
(
resultItem
.
existing
)
||
is
ComponentIdInternal
(
resultItem
.
existing
)
)
)
{
nextIdx
++
;
...
...
@@ -414,6 +416,7 @@ function makeIdAndName(
each
(
mapResult
,
function
(
item
)
{
const
opt
=
item
.
newOption
;
// Force ensure id not duplicated.
assert
(
!
opt
||
opt
.
id
==
null
||
!
idMap
.
get
(
opt
.
id
)
||
idMap
.
get
(
opt
.
id
)
===
item
,
'
id duplicates:
'
+
(
opt
&&
opt
.
id
)
...
...
@@ -511,12 +514,15 @@ export function isNameSpecified(componentModel: ComponentModel): boolean {
* @param {Object} cmptOption
* @return {boolean}
*/
export
function
is
IdInner
(
cmptOption
:
MappingExistingItem
):
boolean
{
export
function
is
ComponentIdInternal
(
cmptOption
:
MappingExistingItem
):
boolean
{
return
cmptOption
&&
cmptOption
.
id
!=
null
&&
makeComparableKey
(
cmptOption
.
id
).
indexOf
(
'
\
0_ec_
\
0
'
)
===
0
;
&&
makeComparableKey
(
cmptOption
.
id
).
indexOf
(
INTERNAL_COMPONENT_ID_PREFIX
)
===
0
;
}
export
function
makeInternalComponentId
(
idSuffix
:
string
)
{
return
INTERNAL_COMPONENT_ID_PREFIX
+
idSuffix
;
}
export
function
setComponentTypeToKeyInfo
(
mappingResult
:
MappingResult
<
MappingExistingItem
&
{
subType
?:
ComponentSubType
}
>
,
...
...
test/lib/testHelper.js
浏览文件 @
a3d29cf6
...
...
@@ -275,10 +275,19 @@
* `testHelper.printAssert` can be called multiple times for one chart instance.
* For each call, one result (fail or pass) will be printed.
*
* @param chart
{EChartsInstance
}
* @param chart
OrDomId {EChartsInstance | string
}
* @param checkFn {Function} param: a function `assert`.
*/
testHelper
.
printAssert
=
function
(
chart
,
checkerFn
)
{
testHelper
.
printAssert
=
function
(
chartOrDomId
,
checkerFn
)
{
var
hostDOMEl
;
var
chart
;
if
(
typeof
chartOrDomId
===
'
string
'
)
{
hostDOMEl
=
document
.
getElementById
(
chartOrDomId
);
}
else
{
chart
=
chartOrDomId
;
hostDOMEl
=
chartOrDomId
.
getDom
();
}
var
failErr
;
function
assert
(
cond
)
{
if
(
!
cond
)
{
...
...
@@ -292,7 +301,7 @@
console
.
error
(
err
);
failErr
=
err
;
}
var
printAssertRecord
=
chart
.
__printAssertRecord
||
(
chart
.
__printAssertRecord
=
[]);
var
printAssertRecord
=
hostDOMEl
.
__printAssertRecord
||
(
hostDOMEl
.
__printAssertRecord
=
[]);
var
resultDom
=
document
.
createElement
(
'
div
'
);
resultDom
.
innerHTML
=
failErr
?
'
checked: Fail
'
:
'
checked: Pass
'
;
...
...
@@ -305,12 +314,12 @@
'
color:
'
+
(
failErr
?
'
red
'
:
'
green
'
)
+
'
;
'
,
].
join
(
''
);
printAssertRecord
.
push
(
resultDom
);
chart
.
getDom
()
.
appendChild
(
resultDom
);
hostDOMEl
.
appendChild
(
resultDom
);
relayoutResult
();
function
relayoutResult
()
{
var
chartHeight
=
chart
.
getHeight
()
;
var
chartHeight
=
chart
?
chart
.
getHeight
()
:
hostDOMEl
.
offsetHeight
;
var
lineHeight
=
Math
.
min
(
fontSize
+
10
,
(
chartHeight
-
20
)
/
printAssertRecord
.
length
);
for
(
var
i
=
0
;
i
<
printAssertRecord
.
length
;
i
++
)
{
var
record
=
printAssertRecord
[
i
];
...
...
test/option-replaceMerge.html
浏览文件 @
a3d29cf6
...
...
@@ -44,11 +44,12 @@ under the License.
<div
id=
"main_replaceMerge_add_new_id"
></div>
<div
id=
"main_replaceMerge_add_find_hole"
></div>
<div
id=
"main_normalMerge_add_find_hole"
></div>
<div
id=
"main_replaceMerge_in
ner
_and_other_cmpt_not_effect"
></div>
<div
id=
"main_replaceMerge_in
ternal
_and_other_cmpt_not_effect"
></div>
<div
id=
"main_replaceMerge_remove_all"
></div>
<div
id=
"main_replaceMerge_reproduce_by_getOption_src"
></div>
<div
id=
"main_replaceMerge_reproduce_by_getOption_tar"
></div>
<div
id=
"main_replaceMerge_if_not_declared_in_option"
></div>
<div
id=
"main_throw_error_when_id_duplicated"
></div>
...
...
@@ -627,7 +628,7 @@ under the License.
}]
};
var
chart
=
testHelper
.
create
(
echarts
,
'
main_replaceMerge_in
ner
_and_other_cmpt_not_effect
'
,
{
var
chart
=
testHelper
.
create
(
echarts
,
'
main_replaceMerge_in
ternal
_and_other_cmpt_not_effect
'
,
{
title
:
[
'
replaceMerge: inner not effect
'
,
'
click "setOption": a dataZoom.slider added
'
,
...
...
@@ -1004,6 +1005,59 @@ under the License.
<script>
require
([
'
echarts
'
],
function
(
echarts
)
{
var
option
;
option
=
{
xAxis
:
[{
type
:
'
category
'
}],
yAxis
:
[{
}],
series
:
[{
id
:
'
sb0
'
,
type
:
'
line
'
,
data
:
[[
11
,
22
],
[
33
,
44
]]
},
{
type
:
'
line
'
,
data
:
[[
11111
,
52
],
[
21133
,
74
]]
},
{
id
:
'
sb0
'
,
type
:
'
line
'
,
data
:
[[
222233
,
1432
],
[
111154
,
1552
]]
}]
};
testHelper
.
printAssert
(
'
main_throw_error_when_id_duplicated
'
,
function
(
assert
)
{
try
{
var
chart
=
testHelper
.
create
(
echarts
,
'
main_throw_error_when_id_duplicated
'
,
{
title
:
[
'
Check throw error when id duplicated
'
,
'
Should show **checked: Pass**
'
],
option
:
option
,
height
:
100
,
});
assert
(
false
);
}
catch
(
err
)
{
assert
(
true
);
}
});
});
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录