Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
62563461
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,发现更多精彩内容 >>
提交
62563461
编写于
7月 02, 2020
作者:
P
pissang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(label): optimize layout on pie.
上级
b26b5d52
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
29 deletion
+41
-29
src/label/labelLayoutHelper.ts
src/label/labelLayoutHelper.ts
+37
-23
test/pie-label-mobile.html
test/pie-label-mobile.html
+4
-6
未找到文件。
src/label/labelLayoutHelper.ts
浏览文件 @
62563461
...
...
@@ -95,7 +95,8 @@ function shiftLayout(
xyDim
:
'
x
'
|
'
y
'
,
sizeDim
:
'
width
'
|
'
height
'
,
minBound
:
number
,
maxBound
:
number
maxBound
:
number
,
balanceShift
:
boolean
)
{
const
len
=
list
.
length
;
...
...
@@ -129,7 +130,7 @@ function shiftLayout(
lastPos
=
rect
[
xyDim
]
+
rect
[
sizeDim
];
}
if
(
totalShifts
>
0
)
{
if
(
totalShifts
>
0
&&
balanceShift
)
{
// Shift back to make the distribution more equally.
shiftList
(
-
totalShifts
/
len
,
0
,
len
);
}
...
...
@@ -137,16 +138,19 @@ function shiftLayout(
// TODO bleedMargin?
const
first
=
list
[
0
];
const
last
=
list
[
len
-
1
];
let
minGap
=
first
.
rect
[
xyDim
]
-
minBound
;
let
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
let
minGap
:
number
;
let
maxGap
:
number
;
updateMinMaxGap
();
// If ends exceed two bounds
handleBoundsGap
(
minGap
,
maxGap
,
1
);
handleBoundsGap
(
maxGap
,
minGap
,
-
1
);
// If ends exceed two bounds, squeeze at most 80%, then take the gap of two bounds.
minGap
<
0
&&
squeezeGaps
(
-
minGap
,
0.8
);
maxGap
<
0
&&
squeezeGaps
(
maxGap
,
0.8
);
updateMinMaxGap
();
takeBoundsGap
(
minGap
,
maxGap
,
1
);
takeBoundsGap
(
maxGap
,
minGap
,
-
1
);
// Handle bailout when there is not enough space.
minGap
=
first
.
rect
[
xyDim
]
-
minBound
;
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
updateMinMaxGap
();
if
(
minGap
<
0
)
{
squeezeWhenBailout
(
-
minGap
);
...
...
@@ -155,7 +159,12 @@ function shiftLayout(
squeezeWhenBailout
(
maxGap
);
}
function
handleBoundsGap
(
gapThisBound
:
number
,
gapOtherBound
:
number
,
moveDir
:
1
|
-
1
)
{
function
updateMinMaxGap
()
{
minGap
=
first
.
rect
[
xyDim
]
-
minBound
;
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
}
function
takeBoundsGap
(
gapThisBound
:
number
,
gapOtherBound
:
number
,
moveDir
:
1
|
-
1
)
{
if
(
gapThisBound
<
0
)
{
// Move from other gap if can.
const
moveFromMaxGap
=
Math
.
min
(
gapOtherBound
,
-
gapThisBound
);
...
...
@@ -163,11 +172,11 @@ function shiftLayout(
shiftList
(
moveFromMaxGap
*
moveDir
,
0
,
len
);
const
remained
=
moveFromMaxGap
+
gapThisBound
;
if
(
remained
<
0
)
{
squeezeGaps
(
-
remained
*
moveDir
);
squeezeGaps
(
-
remained
*
moveDir
,
1
);
}
}
else
{
squeezeGaps
(
-
gapThisBound
*
moveDir
);
squeezeGaps
(
-
gapThisBound
*
moveDir
,
1
);
}
}
}
...
...
@@ -185,7 +194,7 @@ function shiftLayout(
}
// Squeeze gaps if the labels exceed margin.
function
squeezeGaps
(
delta
:
number
)
{
function
squeezeGaps
(
delta
:
number
,
maxSqeezePercent
:
number
)
{
const
gaps
:
number
[]
=
[];
let
totalGaps
=
0
;
for
(
let
i
=
1
;
i
<
len
;
i
++
)
{
...
...
@@ -198,14 +207,12 @@ function shiftLayout(
return
;
}
if
(
Math
.
abs
(
delta
)
>
totalGaps
)
{
delta
=
totalGaps
*
(
delta
<
0
?
-
1
:
1
);
}
const
squeezePercent
=
Math
.
min
(
Math
.
abs
(
delta
)
/
totalGaps
,
maxSqeezePercent
);
if
(
delta
>
0
)
{
for
(
let
i
=
0
;
i
<
len
-
1
;
i
++
)
{
// Distribute the shift delta to all gaps.
const
movement
=
gaps
[
i
]
/
totalGaps
*
delta
;
const
movement
=
gaps
[
i
]
*
squeezePercent
;
// Forward
shiftList
(
movement
,
0
,
i
+
1
);
}
...
...
@@ -214,8 +221,8 @@ function shiftLayout(
// Backward
for
(
let
i
=
len
-
1
;
i
>
0
;
i
--
)
{
// Distribute the shift delta to all gaps.
const
movement
=
gaps
[
i
-
1
]
/
totalGaps
*
delta
;
shiftList
(
movement
,
i
,
len
);
const
movement
=
gaps
[
i
-
1
]
*
squeezePercent
;
shiftList
(
-
movement
,
i
,
len
);
}
}
}
...
...
@@ -256,9 +263,14 @@ function shiftLayout(
export
function
shiftLayoutOnX
(
list
:
Pick
<
LabelLayoutInfo
,
'
rect
'
|
'
label
'
>
[],
leftBound
:
number
,
rightBound
:
number
rightBound
:
number
,
// If average the shifts on all labels and add them to 0
// TODO: Not sure if should enable it.
// Pros: The angle of lines will distribute more equally
// Cons: In some layout. It may not what user wanted. like in pie. the label of last sector is usually changed unexpectedly.
balanceShift
?:
boolean
):
boolean
{
return
shiftLayout
(
list
,
'
x
'
,
'
width
'
,
leftBound
,
rightBound
);
return
shiftLayout
(
list
,
'
x
'
,
'
width
'
,
leftBound
,
rightBound
,
balanceShift
);
}
/**
...
...
@@ -267,9 +279,11 @@ export function shiftLayoutOnX(
export
function
shiftLayoutOnY
(
list
:
Pick
<
LabelLayoutInfo
,
'
rect
'
|
'
label
'
>
[],
topBound
:
number
,
bottomBound
:
number
bottomBound
:
number
,
// If average the shifts on all labels and add them to 0
balanceShift
?:
boolean
):
boolean
{
return
shiftLayout
(
list
,
'
y
'
,
'
height
'
,
topBound
,
bottomBound
);
return
shiftLayout
(
list
,
'
y
'
,
'
height
'
,
topBound
,
bottomBound
,
balanceShift
);
}
export
function
hideOverlap
(
labelList
:
LabelLayoutInfo
[])
{
...
...
test/pie-label-mobile.html
浏览文件 @
62563461
...
...
@@ -133,12 +133,10 @@ under the License.
const
isLeft
=
params
.
labelRect
.
x
<
chart
.
getWidth
()
/
2
;
const
points
=
params
.
labelLinePoints
;
// Update the end point.
if
(
isLeft
)
{
points
[
2
][
0
]
=
params
.
labelRect
.
x
;
}
else
{
points
[
2
][
0
]
=
params
.
labelRect
.
x
+
params
.
labelRect
.
width
;
}
points
[
2
][
0
]
=
isLeft
?
params
.
labelRect
.
x
:
params
.
labelRect
.
x
+
params
.
labelRect
.
width
;
return
{
labelLinePoints
:
points
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录