Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
3dea90f8
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,体验更适合开发者的 AI 搜索 >>
提交
3dea90f8
编写于
3月 17, 2021
作者:
1
100pah
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: [tooltip] (1) keep support string tooltip on each component item. (2) some tiny refactor.
上级
438f4037
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
190 addition
and
80 deletion
+190
-80
src/component/axis/AxisBuilder.ts
src/component/axis/AxisBuilder.ts
+7
-26
src/component/graphic/install.ts
src/component/graphic/install.ts
+6
-18
src/component/legend/LegendView.ts
src/component/legend/LegendView.ts
+6
-17
src/component/toolbox/ToolboxView.ts
src/component/toolbox/ToolboxView.ts
+7
-13
src/util/graphic.ts
src/util/graphic.ts
+54
-2
src/util/innerStore.ts
src/util/innerStore.ts
+1
-0
src/util/types.ts
src/util/types.ts
+13
-1
test/runTest/actions/__meta__.json
test/runTest/actions/__meta__.json
+1
-1
test/tooltip-component.html
test/tooltip-component.html
+95
-2
未找到文件。
src/component/axis/AxisBuilder.ts
浏览文件 @
3dea90f8
...
...
@@ -50,14 +50,6 @@ type AxisEventData = {
[
key
in
AxisIndexKey
]?:
number
};
type
LabelFormatterParams
=
{
componentType
:
string
name
:
string
$vars
:
[
'
name
'
]
}
&
{
[
key
in
AxisIndexKey
]?:
number
};
type
AxisLabelText
=
graphic
.
Text
&
{
__fullText
:
string
__truncatedText
:
string
...
...
@@ -422,14 +414,6 @@ const builders: Record<'axisLine' | 'axisTickLabel' | 'axisName', AxisElementsBu
opt
.
nameTruncateMaxWidth
,
truncateOpt
.
maxWidth
,
axisNameAvailableWidth
);
const
mainType
=
axisModel
.
mainType
;
const
formatterParams
:
LabelFormatterParams
=
{
componentType
:
mainType
,
name
:
name
,
$vars
:
[
'
name
'
]
};
formatterParams
[
mainType
+
'
Index
'
as
AxisIndexKey
]
=
axisModel
.
componentIndex
;
const
textEl
=
new
graphic
.
Text
({
x
:
pos
[
0
],
y
:
pos
[
1
],
...
...
@@ -450,16 +434,13 @@ const builders: Record<'axisLine' | 'axisTickLabel' | 'axisName', AxisElementsBu
}),
z2
:
1
})
as
AxisLabelText
;
getECData
(
textEl
).
tooltipConfig
=
{
componentMainType
:
axisModel
.
mainType
,
componentIndex
:
axisModel
.
componentIndex
,
name
:
name
,
option
:
{
content
:
name
,
formatter
:
()
=>
name
,
formatterParams
:
formatterParams
}
};
graphic
.
setTooltipConfig
({
el
:
textEl
,
componentModel
:
axisModel
,
itemName
:
name
});
textEl
.
__fullText
=
name
;
// Id for animation
textEl
.
anid
=
'
name
'
;
...
...
src/component/graphic/install.ts
浏览文件 @
3dea90f8
...
...
@@ -520,24 +520,12 @@ class GraphicComponentView extends ComponentView {
elInner
.
__ecGraphicHeightOption
=
(
elOption
as
GraphicComponentGroupOption
).
height
;
setEventData
(
el
,
graphicModel
,
elOption
);
const
tooltipOption
=
elOption
.
tooltip
;
const
componentIndex
=
graphicModel
.
componentIndex
;
getECData
(
el
).
tooltipConfig
=
tooltipOption
?
{
componentMainType
:
graphicModel
.
mainType
,
componentIndex
:
componentIndex
,
name
:
el
.
name
,
option
:
zrUtil
.
defaults
({
content
:
el
.
name
,
formatterParams
:
{
componentType
:
'
graphic
'
,
graphicIndex
:
componentIndex
,
name
:
el
.
name
,
$vars
:
[
'
name
'
]
}
},
tooltipOption
)
}
:
null
;
graphicUtil
.
setTooltipConfig
({
el
:
el
,
componentModel
:
graphicModel
,
itemName
:
el
.
name
,
itemTooltipOption
:
elOption
.
tooltip
});
}
});
}
...
...
src/component/legend/LegendView.ts
浏览文件 @
3dea90f8
...
...
@@ -41,7 +41,6 @@ import Displayable, { DisplayableState } from 'zrender/src/graphic/Displayable';
import
{
PathStyleProps
}
from
'
zrender/src/graphic/Path
'
;
import
{
parse
,
stringify
}
from
'
zrender/src/tool/color
'
;
import
{
PatternObject
}
from
'
zrender/src/graphic/Pattern
'
;
import
{
getECData
}
from
'
../../util/innerStore
'
;
const
curry
=
zrUtil
.
curry
;
const
each
=
zrUtil
.
each
;
...
...
@@ -433,22 +432,12 @@ class LegendView extends ComponentView {
const
tooltipModel
=
itemModel
.
getModel
(
'
tooltip
'
)
as
Model
<
CommonTooltipOption
<
LegendTooltipFormatterParams
>>
;
if
(
tooltipModel
.
get
(
'
show
'
))
{
const
componentIndex
=
legendModel
.
componentIndex
;
const
formatterParams
:
LegendTooltipFormatterParams
=
{
componentType
:
'
legend
'
,
legendIndex
:
componentIndex
,
name
:
name
,
$vars
:
[
'
name
'
]
};
getECData
(
hitRect
).
tooltipConfig
=
{
componentMainType
:
legendModel
.
mainType
,
componentIndex
:
componentIndex
,
name
:
name
,
option
:
zrUtil
.
defaults
({
content
:
name
,
formatterParams
:
formatterParams
},
tooltipModel
.
option
)
};
graphic
.
setTooltipConfig
({
el
:
hitRect
,
componentModel
:
legendModel
,
itemName
:
name
,
itemTooltipOption
:
tooltipModel
.
option
});
}
itemGroup
.
add
(
hitRect
);
...
...
src/component/toolbox/ToolboxView.ts
浏览文件 @
3dea90f8
...
...
@@ -225,20 +225,14 @@ class ToolboxView extends ComponentView {
});
path
.
setTextContent
(
textContent
);
getECData
(
path
).
tooltipConfig
=
{
componentMainType
:
toolboxModel
.
mainType
,
componentIndex
:
toolboxModel
.
componentIndex
,
name
:
iconName
,
option
:
{
content
:
titlesMap
[
iconName
],
formatterParams
:
{
componentType
:
'
toolbox
'
,
name
:
iconName
,
title
:
titlesMap
[
iconName
],
$vars
:
[
'
name
'
,
'
title
'
]
}
graphic
.
setTooltipConfig
({
el
:
path
,
componentModel
:
toolboxModel
,
itemName
:
iconName
,
formatterParamsExtra
:
{
title
:
titlesMap
[
iconName
]
}
};
}
)
;
// graphic.enableHoverEmphasis(path);
...
...
src/util/graphic.ts
浏览文件 @
3dea90f8
...
...
@@ -53,7 +53,9 @@ import {
ZRRectLike
,
ZRStyleProps
,
PayloadAnimationPart
,
AnimationOption
AnimationOption
,
CommonTooltipOption
,
ComponentItemTooltipLabelFormatterParams
}
from
'
./types
'
;
import
{
extend
,
...
...
@@ -61,10 +63,15 @@ import {
map
,
defaults
,
isObject
,
retrieve2
retrieve2
,
isString
,
keys
,
each
,
hasOwn
}
from
'
zrender/src/core/util
'
;
import
{
AnimationEasing
}
from
'
zrender/src/animation/easing
'
;
import
{
getECData
}
from
'
./innerStore
'
;
import
ComponentModel
from
'
../model/Component
'
;
const
mathMax
=
Math
.
max
;
...
...
@@ -805,6 +812,51 @@ function nearZero(val: number) {
}
export
function
setTooltipConfig
(
opt
:
{
el
:
Element
,
componentModel
:
ComponentModel
,
itemName
:
string
,
itemTooltipOption
?:
string
|
CommonTooltipOption
<
unknown
>
formatterParamsExtra
?:
Dictionary
<
unknown
>
}):
void
{
const
itemTooltipOption
=
opt
.
itemTooltipOption
;
const
componentModel
=
opt
.
componentModel
;
const
itemName
=
opt
.
itemName
;
const
itemTooltipOptionObj
=
isString
(
itemTooltipOption
)
?
{
formatter
:
itemTooltipOption
}
:
itemTooltipOption
;
const
mainType
=
componentModel
.
mainType
;
const
componentIndex
=
componentModel
.
componentIndex
;
const
formatterParams
=
{
componentType
:
mainType
,
name
:
itemName
,
$vars
:
[
'
name
'
]
}
as
ComponentItemTooltipLabelFormatterParams
;
(
formatterParams
as
any
)[
mainType
+
'
Index
'
]
=
componentIndex
;
const
formatterParamsExtra
=
opt
.
formatterParamsExtra
;
if
(
formatterParamsExtra
)
{
each
(
keys
(
formatterParamsExtra
),
key
=>
{
if
(
!
hasOwn
(
formatterParams
,
key
))
{
formatterParams
[
key
]
=
formatterParamsExtra
[
key
];
formatterParams
.
$vars
.
push
(
key
);
}
});
}
getECData
(
opt
.
el
).
tooltipConfig
=
{
componentMainType
:
mainType
,
componentIndex
:
componentIndex
,
name
:
itemName
,
option
:
defaults
({
content
:
itemName
,
formatterParams
:
formatterParams
},
itemTooltipOptionObj
)
};
}
// Register built-in shapes. These shapes might be overwirtten
// by users, although we do not recommend that.
registerShape
(
'
circle
'
,
Circle
);
...
...
src/util/innerStore.ts
浏览文件 @
3dea90f8
...
...
@@ -35,6 +35,7 @@ export interface ECData {
focus
?:
InnerFocus
;
blurScope
?:
BlurScope
;
tooltipConfig
?:
{
// To make a tooltipConfig, seach `setTooltipConfig`.
// Used to find component tooltip option, which is used as
// the parent of tooltipConfig.option for cascading.
// If not provided, do not use component as its parent.
...
...
src/util/types.ts
浏览文件 @
3dea90f8
...
...
@@ -1348,8 +1348,20 @@ export interface CommonTooltipOption<FormatterParams> {
export
type
ComponentItemTooltipOption
<
T
>
=
CommonTooltipOption
<
T
>
&
{
// Default content HTML.
content
?:
string
;
formatterParams
?:
unknown
;
formatterParams
?:
ComponentItemTooltipLabelFormatterParams
;
};
export
type
ComponentItemTooltipLabelFormatterParams
=
{
componentType
:
string
name
:
string
// properies key array like ['name']
$vars
:
string
[]
}
&
{
[
key
in
`
${
ComponentMainType
}
Index`
]:
number
}
&
{
// Other properties
[
key
in
string
]:
unknown
};
/**
* Tooltip option configured on each series
...
...
test/runTest/actions/__meta__.json
浏览文件 @
3dea90f8
...
...
@@ -151,7 +151,7 @@
"tooltip-axisPointer"
:
20
,
"tooltip-axisPointer2"
:
1
,
"tooltip-cascade"
:
4
,
"tooltip-component"
:
4
,
"tooltip-component"
:
5
,
"tooltip-event"
:
1
,
"tooltip-link"
:
2
,
"tooltip-rich"
:
1
,
...
...
test/tooltip-component.html
浏览文件 @
3dea90f8
...
...
@@ -39,6 +39,7 @@ under the License.
<div
id=
"main0"
></div>
<div
id=
"main1"
></div>
<div
id=
"axis-and-toolbox"
></div>
<div
id=
"axis-and-toolbox-formatter"
></div>
<div
id=
"graphic-component-tooltip"
></div>
...
...
@@ -82,6 +83,10 @@ under the License.
}
}
// This item inherit legend.tootip.
},
{
name
:
'
only show "stringstring"
'
,
tooltip
:
'
stringstring
'
// This item inherit legend.tootip.
}]
},
series
:
{
...
...
@@ -96,6 +101,9 @@ under the License.
},
{
name
:
'
tooltip fontSize: 20 red formatter JSON
'
,
value
:
200
},
{
name
:
'
only show "stringstring"
'
,
value
:
200
}]
}
};
...
...
@@ -203,7 +211,8 @@ under the License.
option
=
{
tooltip
:
{
textStyle
:
{
fontSize
:
5
fontSize
:
5
,
color
:
'
red
'
}
},
toolbox
:
{
...
...
@@ -239,7 +248,8 @@ under the License.
var
chart
=
testHelper
.
create
(
echarts
,
'
axis-and-toolbox
'
,
{
title
:
[
'
Hover toolbox and axis name should show tooltip, fontSize: 20
'
,
'
Hover toolbox and axis name:
'
,
'
should show tooltip, fontSize: 20 red
'
,
'
check each **fontSize** and **color**
'
,
],
option
:
option
,
...
...
@@ -263,6 +273,70 @@ under the License.
color
:
'
red
'
}
},
toolbox
:
{
tooltip
:
{
confine
:
true
,
show
:
true
,
formatter
:
params
=>
{
return
'
<pre>
'
+
JSON
.
stringify
(
params
,
null
,
4
)
+
'
</pre>
'
;
},
textStyle
:
{
fontSize
:
20
}
},
feature
:
{
dataZoom
:
{},
magicType
:
{
type
:
[
'
line
'
,
'
bar
'
,
'
stack
'
,
'
tiled
'
]
}
}
},
xAxis
:
{
name
:
'
show tooltip
'
,
tooltip
:
{
formatter
:
params
=>
{
return
'
<pre>
'
+
JSON
.
stringify
(
params
,
null
,
4
)
+
'
</pre>
'
;
},
show
:
true
,
textStyle
:
{
fontSize
:
20
}
}
},
yAxis
:
{},
series
:
{
type
:
'
scatter
'
,
data
:
[
12
,
22
,
33
]
}
};
var
chart
=
testHelper
.
create
(
echarts
,
'
axis-and-toolbox-formatter
'
,
{
title
:
[
'
Hover toolbox and axis name:
'
,
'
should show tooltip, fontSize: 20 red, **params JSON**
'
,
'
check each **fontSize** and **color**
'
,
],
option
:
option
,
height
:
200
});
});
</script>
<script>
require
([
'
echarts
'
/*, 'map/js/china' */
],
function
(
echarts
)
{
var
option
;
option
=
{
tooltip
:
{
textStyle
:
{
fontSize
:
10
,
color
:
'
red
'
}
},
graphic
:
[{
tooltip
:
{
formatter
:
'
asdf
'
,
...
...
@@ -332,6 +406,25 @@ under the License.
style
:
{
fill
:
'
blue
'
}
},
{
tooltip
:
'
stringstring
'
,
type
:
'
rect
'
,
name
:
'
4nd
'
,
shape
:
{
y
:
20
,
x
:
550
,
width
:
40
,
height
:
40
},
textContent
:
{
style
:
{
text
:
'
show tooltip "stringstring"
\n
in fontSize: 10 red
'
}
},
textConfig
:
{
position
:
'
bottom
'
},
style
:
{
fill
:
'
blue
'
}
}]
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录