Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
5239e3cf
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,发现更多精彩内容 >>
提交
5239e3cf
编写于
4月 30, 2020
作者:
P
pissang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: using state for all user interactions.
上级
7e84356b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
130 addition
and
158 deletion
+130
-158
src/chart/helper/Symbol.ts
src/chart/helper/Symbol.ts
+13
-44
src/chart/pie/PieSeries.ts
src/chart/pie/PieSeries.ts
+1
-1
src/chart/pie/PieView.ts
src/chart/pie/PieView.ts
+52
-90
src/util/LabelManager.ts
src/util/LabelManager.ts
+16
-1
src/util/graphic.ts
src/util/graphic.ts
+47
-22
src/util/layout.ts
src/util/layout.ts
+1
-0
未找到文件。
src/chart/helper/Symbol.ts
浏览文件 @
5239e3cf
...
...
@@ -111,19 +111,6 @@ class Symbol extends graphic.Group {
return
this
.
childAt
(
0
)
as
ECSymbol
;
}
/**
* Get scale(aka, current symbol size).
* Including the change caused by animation
*/
getScale
()
{
const
symbolPath
=
this
.
childAt
(
0
);
return
[
symbolPath
.
scaleX
,
symbolPath
.
scaleY
];
}
getOriginalScale
()
{
return
[
this
.
_scaleX
,
this
.
_scaleY
];
}
/**
* Highlight symbol
*/
...
...
@@ -291,11 +278,20 @@ class Symbol extends graphic.Group {
this
.
_scaleX
=
symbolSize
[
0
]
/
2
;
this
.
_scaleY
=
symbolSize
[
1
]
/
2
;
symbolPath
.
onStateChange
=
(
hoverAnimation
&&
seriesModel
.
isAnimationEnabled
()
)
?
onStateChange
:
null
;
graphic
.
enableHoverEmphasis
(
symbolPath
,
hoverItemStyle
);
symbolPath
.
ensureState
(
'
emphasis
'
).
style
=
hoverItemStyle
;
if
(
hoverAnimation
&&
seriesModel
.
isAnimationEnabled
())
{
const
scaleEmphasisState
=
this
.
ensureState
(
'
emphasis
'
);
const
scale
=
Math
.
max
(
1.1
,
3
/
this
.
_scaleY
+
1
);
scaleEmphasisState
.
scaleX
=
scale
;
scaleEmphasisState
.
scaleY
=
scale
;
}
else
{
this
.
states
.
emphasis
=
null
;
}
graphic
.
enableHoverEmphasis
(
this
);
}
fadeOut
(
cb
:
()
=>
void
,
opt
?:
{
...
...
@@ -330,33 +326,6 @@ class Symbol extends graphic.Group {
}
}
function
onStateChange
(
this
:
ECSymbol
,
fromState
:
DisplayState
,
toState
:
DisplayState
)
{
// Do not support this hover animation util some scenario required.
// Animation can only be supported in hover layer when using `el.incremetal`.
if
(
this
.
incremental
||
this
.
useHoverLayer
)
{
return
;
}
const
scale
=
(
this
.
parent
as
Symbol
).
getOriginalScale
();
if
(
toState
===
'
emphasis
'
)
{
const
ratio
=
scale
[
1
]
/
scale
[
0
];
const
emphasisOpt
=
{
scaleX
:
Math
.
max
(
scale
[
0
]
*
1.1
,
scale
[
0
]
+
3
),
scaleY
:
Math
.
max
(
scale
[
1
]
*
1.1
,
scale
[
1
]
+
3
*
ratio
)
};
// FIXME
// modify it after support stop specified animation.
// toState === fromState
// ? (this.stopAnimation(), this.attr(emphasisOpt))
this
.
animateTo
(
emphasisOpt
,
{
duration
:
400
,
easing
:
'
elasticOut
'
});
}
else
if
(
toState
===
'
normal
'
)
{
this
.
animateTo
({
scaleX
:
scale
[
0
],
scaleY
:
scale
[
1
]
},
{
duration
:
400
,
easing
:
'
elasticOut
'
});
}
}
function
driftSymbol
(
this
:
ECSymbol
,
dx
:
number
,
dy
:
number
)
{
this
.
parent
.
drift
(
dx
,
dy
);
...
...
src/chart/pie/PieSeries.ts
浏览文件 @
5239e3cf
...
...
@@ -222,7 +222,7 @@ class PieSeriesModel extends SeriesModel<PieSeriesOption> {
// 选中时扇区偏移量
selectedOffset
:
10
,
// 高亮扇区偏移量
hoverOffset
:
10
,
hoverOffset
:
5
,
// If use strategy to avoid label overlapping
avoidLabelOverlap
:
true
,
...
...
src/chart/pie/PieView.ts
浏览文件 @
5239e3cf
...
...
@@ -24,11 +24,10 @@ import * as graphic from '../../util/graphic';
import
ChartView
from
'
../../view/Chart
'
;
import
GlobalModel
from
'
../../model/Global
'
;
import
ExtensionAPI
from
'
../../ExtensionAPI
'
;
import
{
Payload
,
DisplayState
,
ECElement
,
ColorString
}
from
'
../../util/types
'
;
import
{
Payload
,
ColorString
}
from
'
../../util/types
'
;
import
List
from
'
../../data/List
'
;
import
PieSeriesModel
,
{
PieDataItemOption
}
from
'
./PieSeries
'
;
import
{
Dictionary
}
from
'
zrender/src/core/types
'
;
import
Element
from
'
zrender/src/Element
'
;
import
{
ElementAnimateConfig
}
from
'
zrender/src/Element
'
;
function
updateDataSelected
(
this
:
PiePiece
,
...
...
@@ -40,7 +39,6 @@ function updateDataSelected(
const
data
=
seriesModel
.
getData
();
const
dataIndex
=
graphic
.
getECData
(
this
).
dataIndex
;
const
name
=
data
.
getName
(
dataIndex
);
const
selectedOffset
=
seriesModel
.
get
(
'
selectedOffset
'
);
api
.
dispatchAction
({
type
:
'
pieToggleSelect
'
,
...
...
@@ -49,67 +47,38 @@ function updateDataSelected(
seriesId
:
seriesModel
.
id
});
const
animationCfg
:
ElementAnimateConfig
=
{
duration
:
seriesModel
.
get
(
'
animation
'
)
?
200
:
0
,
easing
:
'
cubicOut
'
};
data
.
each
(
function
(
idx
)
{
toggleItemSelected
(
data
.
getItemGraphicEl
(
idx
),
data
.
getItemLayout
(
idx
),
seriesModel
.
isSelected
(
data
.
getName
(
idx
)),
selectedOffset
,
hasAnimation
);
const
el
=
data
.
getItemGraphicEl
(
idx
);
el
.
toggleState
(
'
select
'
,
seriesModel
.
isSelected
(
data
.
getName
(
idx
)),
animationCfg
);
});
}
function
toggleItemSelected
(
el
:
Element
,
layout
:
Dictionary
<
any
>
,
// FIXME:TS make a type.
isSelected
:
boolean
,
selectedOffset
:
number
,
hasAnimation
:
boolean
):
void
{
const
midAngle
=
(
layout
.
startAngle
+
layout
.
endAngle
)
/
2
;
const
dx
=
Math
.
cos
(
midAngle
);
const
dy
=
Math
.
sin
(
midAngle
);
const
offset
=
isSelected
?
selectedOffset
:
0
;
const
obj
=
{
x
:
dx
*
offset
,
y
:
dy
*
offset
};
hasAnimation
// animateTo will stop revious animation like update transition
?
el
.
animate
()
.
when
(
200
,
obj
)
.
start
(
'
bounceOut
'
)
:
el
.
attr
(
obj
);
}
/**
* Piece of pie including Sector, Label, LabelLine
*/
class
PiePiece
extends
graphic
.
Group
{
class
PiePiece
extends
graphic
.
Sector
{
constructor
(
data
:
List
,
idx
:
number
)
{
super
();
const
sector
=
new
graphic
.
Sector
({
z2
:
2
});
this
.
z2
=
2
;
const
polyline
=
new
graphic
.
Polyline
();
const
text
=
new
graphic
.
Text
();
this
.
add
(
sector
);
this
.
add
(
polyline
);
sector
.
setTextContent
(
text
);
this
.
setTextGuideLine
(
polyline
);
this
.
setTextContent
(
text
);
this
.
updateData
(
data
,
idx
,
true
);
}
updateData
(
data
:
List
,
idx
:
number
,
firstCreate
?:
boolean
):
void
{
const
sector
=
this
.
childAt
(
0
)
as
graphic
.
Sector
;
const
sector
=
this
;
const
seriesModel
=
data
.
hostModel
as
PieSeriesModel
;
const
itemModel
=
data
.
getItemModel
<
PieDataItemOption
>
(
idx
);
...
...
@@ -161,53 +130,50 @@ class PiePiece extends graphic.Group {
const
sectorEmphasisState
=
sector
.
ensureState
(
'
emphasis
'
);
sectorEmphasisState
.
style
=
itemModel
.
getModel
([
'
emphasis
'
,
'
itemStyle
'
]).
getItemStyle
();
const
sectorSelectState
=
sector
.
ensureState
(
'
select
'
);
const
midAngle
=
(
layout
.
startAngle
+
layout
.
endAngle
)
/
2
;
const
offset
=
seriesModel
.
get
(
'
selectedOffset
'
);
const
dx
=
Math
.
cos
(
midAngle
)
*
offset
;
const
dy
=
Math
.
sin
(
midAngle
)
*
offset
;
sectorSelectState
.
x
=
dx
;
sectorSelectState
.
y
=
dy
;
sector
.
toggleState
(
'
select
'
,
seriesModel
.
isSelected
(
data
.
getName
(
idx
)),
{
duration
:
seriesModel
.
get
(
'
animation
'
)
?
200
:
0
,
easing
:
'
cubicOut
'
});
const
cursorStyle
=
itemModel
.
getShallow
(
'
cursor
'
);
cursorStyle
&&
sector
.
attr
(
'
cursor
'
,
cursorStyle
);
// Toggle selected
toggleItemSelected
(
this
,
data
.
getItemLayout
(
idx
),
seriesModel
.
isSelected
(
data
.
getName
(
idx
)),
seriesModel
.
get
(
'
selectedOffset
'
),
seriesModel
.
get
(
'
animation
'
)
);
// Label and text animation should be applied only for transition type animation when update
const
withAnimation
=
!
firstCreate
&&
animationTypeUpdate
===
'
transition
'
;
this
.
_updateLabel
(
data
,
idx
,
withAnimation
);
(
this
as
ECElement
).
onStateChange
=
(
itemModel
.
get
(
'
hoverAnimation
'
)
&&
seriesModel
.
isAnimationEnabled
())
?
function
(
fromState
:
DisplayState
,
toState
:
DisplayState
):
void
{
if
(
toState
===
'
emphasis
'
)
{
// Sector may has animation of updating data. Force to move to the last frame
// Or it may stopped on the wrong shape
sector
.
stopAnimation
(
true
);
sector
.
animateTo
({
shape
:
{
r
:
layout
.
r
+
seriesModel
.
get
(
'
hoverOffset
'
)
}
},
{
duration
:
300
,
easing
:
'
elasticOut
'
});
}
else
{
sector
.
stopAnimation
(
true
);
sector
.
animateTo
({
shape
:
{
r
:
layout
.
r
}
},
{
duration
:
300
,
easing
:
'
elasticOut
'
});
}
}
:
null
;
const
emphasisState
=
sector
.
ensureState
(
'
emphasis
'
);
emphasisState
.
shape
=
{
r
:
layout
.
r
+
itemModel
.
get
(
'
hoverAnimation
'
)
// TODO: Change a name.
?
seriesModel
.
get
(
'
hoverOffset
'
)
:
0
};
const
labelLine
=
sector
.
getTextGuideLine
();
const
labelText
=
sector
.
getTextContent
();
const
labelLineSelectState
=
labelLine
.
ensureState
(
'
select
'
);
const
labelTextSelectState
=
labelText
.
ensureState
(
'
select
'
);
labelLineSelectState
.
x
=
dx
;
labelLineSelectState
.
y
=
dy
;
labelTextSelectState
.
x
=
dx
;
labelTextSelectState
.
y
=
dy
;
graphic
.
enableHoverEmphasis
(
this
);
}
private
_updateLabel
(
data
:
List
,
idx
:
number
,
withAnimation
:
boolean
):
void
{
const
sector
=
this
.
childAt
(
0
)
;
const
labelLine
=
this
.
childAt
(
1
)
as
graphic
.
Polyline
;
const
labelText
=
sector
.
getTextContent
()
as
graphic
.
Text
;
const
sector
=
this
;
const
labelLine
=
sector
.
getTextGuideLine
()
;
const
labelText
=
sector
.
getTextContent
();
const
seriesModel
=
data
.
hostModel
;
const
itemModel
=
data
.
getItemModel
<
PieDataItemOption
>
(
idx
);
...
...
@@ -358,11 +324,9 @@ class PieView extends ChartView {
.
add
(
function
(
idx
)
{
const
piePiece
=
new
PiePiece
(
data
,
idx
);
// Default expansion animation
if
(
isFirstRender
&&
animationType
!==
'
scale
'
)
{
piePiece
.
eachChild
(
function
(
child
)
{
child
.
stopAnimation
(
true
);
});
}
// if (isFirstRender && animationType !== 'scale') {
// piePiece.stopAnimation(true);
// }
selectedMode
&&
piePiece
.
on
(
'
click
'
,
onSectorClick
);
...
...
@@ -375,11 +339,9 @@ class PieView extends ChartView {
graphic
.
clearStates
(
piePiece
);
if
(
!
isFirstRender
&&
animationTypeUpdate
!==
'
transition
'
)
{
piePiece
.
eachChild
(
function
(
child
)
{
child
.
stopAnimation
(
true
);
});
}
// if (!isFirstRender && animationTypeUpdate !== 'transition') {
// piePiece.stopAnimation(true);
// }
piePiece
.
updateData
(
data
,
newIdx
);
...
...
src/util/LabelManager.ts
浏览文件 @
5239e3cf
...
...
@@ -128,11 +128,20 @@ class LabelManager {
const
hostEl
=
label
.
__hostTarget
;
const
textConfig
=
hostEl
.
textConfig
||
{};
// TODO: If label is in other state.
const
labelTransform
=
label
.
getComputedTransform
();
const
labelRect
=
label
.
getBoundingRect
().
plain
();
BoundingRect
.
applyTransform
(
labelRect
,
labelRect
,
labelTransform
);
dummyTransformable
.
setLocalTransform
(
labelTransform
);
if
(
labelTransform
)
{
dummyTransformable
.
setLocalTransform
(
labelTransform
);
}
else
{
// Identity transform.
dummyTransformable
.
x
=
dummyTransformable
.
y
=
dummyTransformable
.
rotation
=
dummyTransformable
.
originX
=
dummyTransformable
.
originY
=
0
;
dummyTransformable
.
scaleX
=
dummyTransformable
.
scaleY
=
1
;
}
const
host
=
label
.
__hostTarget
;
let
hostRect
;
...
...
@@ -224,6 +233,8 @@ class LabelManager {
layoutOption
=
layoutOption
||
{};
if
(
hostEl
)
{
hostEl
.
setTextConfig
({
// Force to set local false.
local
:
false
,
// Ignore position and rotation config on the host el if x or y is changed.
position
:
(
layoutOption
.
x
!=
null
||
layoutOption
.
y
!=
null
)
?
null
:
defaultLabelAttr
.
attachedPos
,
...
...
@@ -347,6 +358,10 @@ class LabelManager {
}
}
}
updateLabelGuidLine
()
{
}
}
...
...
src/util/graphic.ts
浏览文件 @
5239e3cf
...
...
@@ -45,7 +45,7 @@ import IncrementalDisplayable from 'zrender/src/graphic/IncrementalDisplayable';
import
*
as
subPixelOptimizeUtil
from
'
zrender/src/graphic/helper/subPixelOptimize
'
;
import
{
Dictionary
}
from
'
zrender/src/core/types
'
;
import
LRU
from
'
zrender/src/core/LRU
'
;
import
Displayable
,
{
DisplayableProps
}
from
'
zrender/src/graphic/Displayable
'
;
import
Displayable
,
{
DisplayableProps
,
DisplayableState
}
from
'
zrender/src/graphic/Displayable
'
;
import
{
PatternObject
}
from
'
zrender/src/graphic/Pattern
'
;
import
{
GradientObject
}
from
'
zrender/src/graphic/Gradient
'
;
import
Element
,
{
ElementEvent
,
ElementTextConfig
}
from
'
zrender/src/Element
'
;
...
...
@@ -377,23 +377,12 @@ function singleEnterEmphasis(el: Element) {
if
(
!
el
.
states
.
emphasis
)
{
return
;
}
const
disp
=
el
as
Displayable
;
const
emphasisStyle
=
disp
.
states
.
emphasis
.
style
;
const
currentFill
=
disp
.
style
&&
disp
.
style
.
fill
;
const
currentStroke
=
disp
.
style
&&
disp
.
style
.
stroke
;
el
.
useState
(
'
emphasis
'
);
if
(
emphasisStyle
&&
(
currentFill
||
currentStroke
))
{
if
(
!
hasFillOrStroke
(
emphasisStyle
.
fill
))
{
disp
.
style
.
fill
=
liftColor
(
currentFill
);
}
if
(
!
hasFillOrStroke
(
emphasisStyle
.
stroke
))
{
disp
.
style
.
stroke
=
liftColor
(
currentStroke
);
}
disp
.
z2
+=
Z2_EMPHASIS_LIFT
;
}
el
.
useState
(
'
emphasis
'
,
true
,
{
duration
:
300
,
// TODO Configuration
easing
:
'
cubicOut
'
});
const
textContent
=
el
.
getTextContent
();
if
(
textContent
)
{
...
...
@@ -403,8 +392,10 @@ function singleEnterEmphasis(el: Element) {
}
function
singleEnterNormal
(
el
:
Element
)
{
el
.
clearStates
();
function
singleLeaveEmphasis
(
el
:
Element
)
{
el
.
removeState
(
'
emphasis
'
,
{
duration
:
300
});
(
el
as
ExtendedElement
).
__highlighted
=
false
;
}
...
...
@@ -452,6 +443,38 @@ export function clearStates(el: Element) {
}
}
function
elementStateProxy
(
this
:
Displayable
,
stateName
:
string
):
DisplayableState
{
let
state
=
this
.
states
[
stateName
];
if
(
stateName
===
'
emphasis
'
&&
this
.
style
)
{
const
currentFill
=
this
.
style
.
fill
;
const
currentStroke
=
this
.
style
.
stroke
;
if
(
currentFill
||
currentStroke
)
{
state
=
state
||
{};
// Apply default color lift
let
emphasisStyle
=
state
.
style
||
{};
let
cloned
=
false
;
if
(
!
hasFillOrStroke
(
emphasisStyle
.
fill
))
{
cloned
=
true
;
// Not modify the original value.
state
=
extend
({},
state
);
emphasisStyle
=
extend
({},
emphasisStyle
);
emphasisStyle
.
fill
=
liftColor
(
currentFill
);
}
if
(
!
hasFillOrStroke
(
emphasisStyle
.
stroke
))
{
if
(
!
cloned
)
{
state
=
extend
({},
state
);
emphasisStyle
=
extend
({},
emphasisStyle
);
}
emphasisStyle
.
stroke
=
liftColor
(
currentStroke
);
}
state
.
style
=
emphasisStyle
;
}
}
return
state
;
}
/**
* Set hover style (namely "emphasis style") of element.
* @param el Should not be `zrender/graphic/Group`.
...
...
@@ -462,6 +485,8 @@ export function enableElementHoverEmphasis(el: Displayable, hoverStl?: ZRStylePr
emphasisState
.
style
=
hoverStl
;
}
el
.
stateProxy
=
elementStateProxy
;
// FIXME
// It is not completely right to save "normal"/"emphasis" flag on elements.
// It probably should be saved on `data` of series. Consider the cases:
...
...
@@ -469,7 +494,7 @@ export function enableElementHoverEmphasis(el: Displayable, hoverStl?: ZRStylePr
// again by dataZoom.
// (2) call `setOption` and replace elements totally when they are highlighted.
if
((
el
as
ExtendedDisplayable
).
__highlighted
)
{
singleEnterNormal
(
el
);
// singleLeaveEmphasis
(el);
singleEnterEmphasis
(
el
);
}
}
...
...
@@ -485,7 +510,7 @@ export function leaveEmphasisWhenMouseOut(el: Element, e: ElementEvent) {
!
shouldSilent
(
el
,
e
)
// "emphasis" event highlight has higher priority than mouse highlight.
&&
!
(
el
as
ExtendedElement
).
__highByOuter
&&
traverseUpdateState
((
el
as
ExtendedElement
),
single
EnterNormal
);
&&
traverseUpdateState
((
el
as
ExtendedElement
),
single
LeaveEmphasis
);
}
export
function
enterEmphasis
(
el
:
Element
,
highlightDigit
?:
number
)
{
...
...
@@ -495,7 +520,7 @@ export function enterEmphasis(el: Element, highlightDigit?: number) {
export
function
leaveEmphasis
(
el
:
Element
,
highlightDigit
?:
number
)
{
!
((
el
as
ExtendedElement
).
__highByOuter
&=
~
(
1
<<
(
highlightDigit
||
0
)))
&&
traverseUpdateState
((
el
as
ExtendedElement
),
single
EnterNormal
);
&&
traverseUpdateState
((
el
as
ExtendedElement
),
single
LeaveEmphasis
);
}
function
shouldSilent
(
el
:
Element
,
e
:
ElementEvent
)
{
...
...
src/util/layout.ts
浏览文件 @
5239e3cf
...
...
@@ -116,6 +116,7 @@ function boxLayout(
child
.
x
=
x
;
child
.
y
=
y
;
child
.
markRedraw
();
orient
===
'
horizontal
'
?
(
x
=
nextX
+
gap
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录