Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
3b0df70d
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,体验更适合开发者的 AI 搜索 >>
提交
3b0df70d
编写于
9月 15, 2020
作者:
Z
zakwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(tooltip): add formatter cache to tooltip
上级
99ab1d7a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
162 addition
and
2 deletion
+162
-2
src/component/tooltip/TooltipModel.ts
src/component/tooltip/TooltipModel.ts
+5
-1
src/component/tooltip/TooltipView.ts
src/component/tooltip/TooltipView.ts
+29
-1
test/tooltip-formatter-cache.html
test/tooltip-formatter-cache.html
+128
-0
未找到文件。
src/component/tooltip/TooltipModel.ts
浏览文件 @
3b0df70d
...
...
@@ -66,6 +66,10 @@ export interface TooltipOption extends CommonTooltipOption<TopLevelFormatterPara
appendToBody
?:
boolean
order
?:
TooltipOrderMode
useFormatterCache
?:
boolean
hitFormatterCache
?:
(
key
:
string
,
cacheObj
:
any
)
=>
void
}
class
TooltipModel
extends
ComponentModel
<
TooltipOption
>
{
...
...
@@ -173,4 +177,4 @@ class TooltipModel extends ComponentModel<TooltipOption> {
ComponentModel
.
registerClass
(
TooltipModel
);
export
default
TooltipModel
;
\ No newline at end of file
export
default
TooltipModel
;
src/component/tooltip/TooltipView.ts
浏览文件 @
3b0df70d
...
...
@@ -154,6 +154,8 @@ class TooltipView extends ComponentView {
private
_lastDataByCoordSys
:
DataByCoordSys
[];
private
_tooltipFormatterCache
:
{[
propName
:
string
]:
any
}
init
(
ecModel
:
GlobalModel
,
api
:
ExtensionAPI
)
{
if
(
env
.
node
)
{
return
;
...
...
@@ -714,6 +716,17 @@ class TooltipView extends ComponentView {
});
}
private
_getTooltipCache
(
key
:
string
):
any
{
return
this
.
_tooltipFormatterCache
&&
this
.
_tooltipFormatterCache
[
key
];
}
private
_setTooltipCache
(
key
:
string
,
value
:
any
)
{
if
(
!
key
)
return
;
this
.
_tooltipFormatterCache
=
this
.
_tooltipFormatterCache
||
{};
this
.
_tooltipFormatterCache
[
key
]
=
value
;
}
private
_showTooltipContent
(
// Use Model<TooltipOption> insteadof TooltipModel because this model may be from series or other options.
// Instead of top level tooltip.
...
...
@@ -749,6 +762,18 @@ class TooltipView extends ComponentView {
html
=
formatUtil
.
formatTpl
(
formatter
,
params
,
true
);
}
else
if
(
zrUtil
.
isFunction
(
formatter
))
{
// formatter cache
let
formatterCache
=
null
as
any
;
let
key
:
string
;
const
useFormatterCache
=
tooltipModel
.
get
(
'
useFormatterCache
'
);
const
hitFormatterCache
=
tooltipModel
.
get
(
'
hitFormatterCache
'
);
if
(
useFormatterCache
&&
params
)
{
const
p
=
zrUtil
.
isArray
(
params
)
?
params
[
0
]
:
params
;
key
=
[
p
.
seriesId
,
p
.
componentIndex
,
p
.
seriesName
,
p
.
name
,
p
.
dataIndex
].
join
(
'
-
'
);
formatterCache
=
this
.
_getTooltipCache
(
key
);
}
const
callback
=
bind
(
function
(
cbTicket
:
string
,
html
:
string
)
{
if
(
cbTicket
===
this
.
_ticket
)
{
tooltipContent
.
setContent
(
html
,
markupStyleCreator
,
tooltipModel
,
nearPoint
.
color
,
positionExpr
);
...
...
@@ -758,7 +783,10 @@ class TooltipView extends ComponentView {
}
},
this
);
this
.
_ticket
=
asyncTicket
;
html
=
formatter
(
params
,
asyncTicket
,
callback
);
html
=
formatterCache
||
formatter
(
params
,
asyncTicket
,
callback
);
formatterCache
&&
zrUtil
.
isFunction
(
hitFormatterCache
)
&&
hitFormatterCache
(
key
,
formatterCache
);
key
&&
this
.
_setTooltipCache
(
key
,
html
);
}
tooltipContent
.
setContent
(
html
,
markupStyleCreator
,
tooltipModel
,
nearPoint
.
color
,
positionExpr
);
...
...
test/tooltip-formatter-cache.html
0 → 100644
浏览文件 @
3b0df70d
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
/>
<script
src=
"lib/esl.js"
></script>
<script
src=
"lib/config.js"
></script>
<script
src=
"lib/jquery.min.js"
></script>
<script
src=
"lib/facePrint.js"
></script>
<script
src=
"lib/testHelper.js"
></script>
<!-- <script src="ut/lib/canteen.js"></script> -->
<link
rel=
"stylesheet"
href=
"lib/reset.css"
/>
</head>
<body>
<style>
</style>
<div
id=
"main0"
></div>
<div
id=
"main1"
></div>
<div
id=
"main2"
></div>
<script>
require
([
'
echarts
'
/*, 'map/js/china' */
],
function
(
echarts
)
{
var
labelRight
=
{
position
:
'
right
'
};
var
option
=
{
title
:
{
text
:
'
toolsTip formatter trigger once test #12338
'
,
subtext
:
'
From ExcelHome
'
,
sublink
:
'
http://e.weibo.com/1341556070/AjwF2AgQm
'
},
tooltip
:
{
trigger
:
'
axis
'
,
axisPointer
:
{
// 坐标轴指示器log,坐标轴触发有效
type
:
'
shadow
'
// 默认为直线,可选为:'line' | 'shadow'
},
useFormatterCache
:
true
,
// 如果配置为true,formatter函数只触发一次
formatter
:
function
(
params
,
ticket
,
callback
)
{
console
.
log
(
'
hit formatter:
'
,
params
);
return
params
[
0
];
},
// call when hit cache, call after use formatterCache
hitFormatterCache
(
key
,
cache
)
{
console
.
log
(
'
hit cache:
'
,
key
,
cache
);
}
},
grid
:
{
top
:
80
,
bottom
:
30
},
xAxis
:
{
type
:
'
value
'
,
position
:
'
top
'
,
splitLine
:
{
lineStyle
:
{
type
:
'
dashed
'
}
}
},
yAxis
:
{
type
:
'
category
'
,
axisLine
:
{
show
:
false
},
axisLabel
:
{
show
:
false
},
axisTick
:
{
show
:
false
},
splitLine
:
{
show
:
false
},
data
:
[
'
ten
'
,
'
nine
'
,
'
eight
'
,
'
seven
'
,
'
six
'
,
'
five
'
,
'
four
'
,
'
three
'
,
'
two
'
,
'
one
'
]
},
series
:
[
{
name
:
'
生活费
'
,
type
:
'
bar
'
,
stack
:
'
总量
'
,
label
:
{
show
:
true
,
formatter
:
'
{b}
'
},
data
:
[
{
value
:
-
0.07
,
label
:
labelRight
},
{
value
:
-
0.09
,
label
:
labelRight
},
0.2
,
0.44
,
{
value
:
-
0.23
,
label
:
labelRight
},
0.08
,
{
value
:
-
0.17
,
label
:
labelRight
},
0.47
,
{
value
:
-
0.36
,
label
:
labelRight
},
0.18
]
}
]
};
var
chart
=
testHelper
.
create
(
echarts
,
'
main0
'
,
{
title
:
[
'
the toolTips.triggerOnce set "true"
'
,
'
Case from issue #12338
'
],
option
:
option
});
});
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录