Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
a7310d84
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,发现更多精彩内容 >>
提交
a7310d84
编写于
6月 08, 2020
作者:
P
pissang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(label): squeeze the labels then hide if there is no space.
上级
1c7a1305
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
10 deletion
+59
-10
src/label/LabelManager.ts
src/label/LabelManager.ts
+5
-3
src/label/labelLayoutHelper.ts
src/label/labelLayoutHelper.ts
+54
-7
未找到文件。
src/label/LabelManager.ts
浏览文件 @
a7310d84
...
...
@@ -285,6 +285,7 @@ class LabelManager {
layoutOption
=
layoutOption
||
{};
labelItem
.
computedLayoutOption
=
layoutOption
;
const
degreeToRadian
=
Math
.
PI
/
180
;
if
(
hostEl
)
{
hostEl
.
setTextConfig
({
// Force to set local false.
...
...
@@ -293,7 +294,8 @@ class LabelManager {
position
:
(
layoutOption
.
x
!=
null
||
layoutOption
.
y
!=
null
)
?
null
:
defaultLabelAttr
.
attachedPos
,
// Ignore rotation config on the host el if rotation is changed.
rotation
:
layoutOption
.
rotation
!=
null
?
layoutOption
.
rotation
:
defaultLabelAttr
.
attachedRot
,
rotation
:
layoutOption
.
rotate
!=
null
?
layoutOption
.
rotate
*
degreeToRadian
:
defaultLabelAttr
.
attachedRot
,
offset
:
[
layoutOption
.
dx
||
0
,
layoutOption
.
dy
||
0
]
});
}
...
...
@@ -317,8 +319,8 @@ class LabelManager {
label
.
setStyle
(
'
y
'
,
defaultLabelAttr
.
style
.
y
);
}
label
.
rotation
=
layoutOption
.
rotat
ion
!=
null
?
layoutOption
.
rotat
io
n
:
defaultLabelAttr
.
rotation
;
label
.
rotation
=
layoutOption
.
rotat
e
!=
null
?
layoutOption
.
rotat
e
*
degreeToRadia
n
:
defaultLabelAttr
.
rotation
;
for
(
let
k
=
0
;
k
<
LABEL_OPTION_TO_STYLE_KEYS
.
length
;
k
++
)
{
const
key
=
LABEL_OPTION_TO_STYLE_KEYS
[
k
];
...
...
src/label/labelLayoutHelper.ts
浏览文件 @
a7310d84
...
...
@@ -132,14 +132,26 @@ function shiftLayout(
}
// TODO bleedMargin?
const
minGap
=
list
[
0
].
rect
[
xyDim
]
-
minBound
;
const
first
=
list
[
0
]
;
const
last
=
list
[
len
-
1
];
const
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
let
minGap
=
first
.
rect
[
xyDim
]
-
minBound
;
let
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
// If ends exceed two bounds
handleBoundsGap
(
minGap
,
maxGap
,
1
);
handleBoundsGap
(
maxGap
,
minGap
,
-
1
);
// Handle bailout when there is not enough space.
minGap
=
first
.
rect
[
xyDim
]
-
minBound
;
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
if
(
minGap
<
0
)
{
squeezeWhenBailout
(
-
minGap
);
}
if
(
maxGap
<
0
)
{
squeezeWhenBailout
(
maxGap
);
}
function
handleBoundsGap
(
gapThisBound
:
number
,
gapOtherBound
:
number
,
moveDir
:
1
|
-
1
)
{
if
(
gapThisBound
<
0
)
{
// Move from other gap if can.
...
...
@@ -180,13 +192,48 @@ function shiftLayout(
return
;
}
if
(
Math
.
abs
(
delta
)
>
totalGaps
)
{
delta
=
totalGaps
*
(
delta
<
0
?
-
1
:
1
);
}
for
(
let
i
=
0
;
i
<
len
-
1
;
i
++
)
{
// Distribute the shift delta to all gaps.
// NOTE:
// it may overlap if remained gap is not enough for the total movements.
// aka totalGaps / delta is < 1. In this situation the label may move too much and cause overlap again.
// This is by design. Let the hideOverlap do the job instead of keep exceeding the bounds.
shiftList
(
gaps
[
i
]
/
totalGaps
*
delta
,
0
,
i
+
1
);
const
movement
=
gaps
[
i
]
/
totalGaps
*
delta
;
if
(
delta
>
0
)
{
// Forward
shiftList
(
movement
,
0
,
i
+
1
);
}
else
{
// Backward
shiftList
(
movement
,
len
-
i
-
1
,
len
);
}
}
}
/**
* Squeeze to allow overlap if there is no more space available.
* Let other overlapping strategy like hideOverlap do the job instead of keep exceeding the bounds.
*/
function
squeezeWhenBailout
(
delta
:
number
)
{
const
dir
=
delta
<
0
?
-
1
:
1
;
delta
=
Math
.
abs
(
delta
);
const
moveForEachLabel
=
Math
.
ceil
(
delta
/
(
len
-
1
));
for
(
let
i
=
0
;
i
<
len
-
1
;
i
++
)
{
if
(
dir
>
0
)
{
// Forward
shiftList
(
moveForEachLabel
,
0
,
i
+
1
);
}
else
{
// Backward
shiftList
(
-
moveForEachLabel
,
len
-
i
-
1
,
len
);
}
delta
-=
moveForEachLabel
;
if
(
delta
<=
0
)
{
return
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录