Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
1c7a1305
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,发现更多精彩内容 >>
提交
1c7a1305
编写于
6月 08, 2020
作者:
P
pissang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(label): rewrite the label shift algorithm in layout
上级
0089d9b2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
35 deletion
+71
-35
src/chart/pie/labelLayout.ts
src/chart/pie/labelLayout.ts
+4
-0
src/label/labelLayoutHelper.ts
src/label/labelLayoutHelper.ts
+67
-35
未找到文件。
src/chart/pie/labelLayout.ts
浏览文件 @
1c7a1305
...
...
@@ -61,6 +61,10 @@ function adjustSingleSide(
viewTop
:
number
,
farthestX
:
number
)
{
if
(
list
.
length
<
2
)
{
return
;
}
list
.
sort
(
function
(
a
,
b
)
{
return
a
.
y
-
b
.
y
;
});
...
...
src/label/labelLayoutHelper.ts
浏览文件 @
1c7a1305
...
...
@@ -99,7 +99,7 @@ function shiftLayout(
)
{
const
len
=
list
.
length
;
if
(
!
len
)
{
if
(
len
<
2
)
{
return
;
}
...
...
@@ -109,52 +109,84 @@ function shiftLayout(
let
lastPos
=
0
;
let
delta
;
const
shifts
=
[];
let
totalShifts
=
0
;
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
delta
=
list
[
i
].
rect
[
xyDim
]
-
lastPos
;
const
item
=
list
[
i
];
const
rect
=
item
.
rect
;
delta
=
rect
[
xyDim
]
-
lastPos
;
if
(
delta
<
0
)
{
shiftForward
(
i
,
len
,
-
delta
);
// shiftForward(i, len, -delta);
rect
[
xyDim
]
-=
delta
;
item
.
label
[
xyDim
]
-=
delta
;
}
lastPos
=
list
[
i
].
rect
[
xyDim
]
+
list
[
i
].
rect
[
sizeDim
];
const
shift
=
Math
.
max
(
-
delta
,
0
);
shifts
.
push
(
shift
);
totalShifts
+=
shift
;
lastPos
=
rect
[
xyDim
]
+
rect
[
sizeDim
];
}
// TODO bleedMargin?
if
(
maxBound
<
lastPos
)
{
shift
Backward
(
len
-
1
,
lastPos
-
maxBound
);
if
(
totalShifts
>
0
)
{
// Shift back to make the distribution more equally.
shift
List
(
-
totalShifts
/
len
,
0
,
len
);
}
function
shiftForward
(
start
:
number
,
end
:
number
,
delta
:
number
)
{
for
(
let
j
=
start
;
j
<
end
;
j
++
)
{
list
[
j
].
label
[
xyDim
]
+=
delta
;
const
rect
=
list
[
j
].
rect
;
rect
[
xyDim
]
+=
delta
;
if
(
j
>
start
&&
j
+
1
<
end
&&
!
list
[
j
+
1
].
rect
.
intersect
(
rect
))
{
// Shift the following so it can be more equaly distributed.
shiftBackward
(
j
,
delta
/
2
);
return
;
// TODO bleedMargin?
const
minGap
=
list
[
0
].
rect
[
xyDim
]
-
minBound
;
const
last
=
list
[
len
-
1
];
const
maxGap
=
maxBound
-
last
.
rect
[
xyDim
]
-
last
.
rect
[
sizeDim
];
// If ends exceed two bounds
handleBoundsGap
(
minGap
,
maxGap
,
1
);
handleBoundsGap
(
maxGap
,
minGap
,
-
1
);
function
handleBoundsGap
(
gapThisBound
:
number
,
gapOtherBound
:
number
,
moveDir
:
1
|
-
1
)
{
if
(
gapThisBound
<
0
)
{
// Move from other gap if can.
const
moveFromMaxGap
=
Math
.
min
(
gapOtherBound
,
-
gapThisBound
);
if
(
moveFromMaxGap
>
0
)
{
shiftList
(
moveFromMaxGap
*
moveDir
,
0
,
len
);
const
remained
=
moveFromMaxGap
+
gapThisBound
;
if
(
remained
<
0
)
{
squeezeGaps
(
-
remained
*
moveDir
);
}
}
else
{
squeezeGaps
(
-
gapThisBound
*
moveDir
);
}
}
shiftBackward
(
end
-
1
,
delta
/
2
);
}
function
shiftBackward
(
end
:
number
,
delta
:
number
)
{
for
(
let
j
=
end
;
j
>=
0
;
j
--
)
{
const
rect
=
list
[
j
].
rect
;
list
[
j
].
label
[
xyDim
]
-=
delta
;
rect
[
xyDim
]
-=
delta
;
function
shiftList
(
delta
:
number
,
start
:
number
,
end
:
number
)
{
for
(
let
i
=
start
;
i
<
end
;
i
++
)
{
const
item
=
list
[
i
];
const
rect
=
item
.
rect
;
rect
[
xyDim
]
+=
delta
;
item
.
label
[
xyDim
]
+=
delta
;
}
}
// const textSize = rect[sizeDim];
const
diffToMinBound
=
rect
[
xyDim
]
-
minBound
;
if
(
diffToMinBound
<
0
)
{
rect
[
xyDim
]
-=
diffToMinBound
;
list
[
j
].
label
[
xyDim
]
-=
diffToMinBound
;
}
// Squeeze gaps if the labels exceed margin.
function
squeezeGaps
(
delta
:
number
)
{
const
gaps
:
number
[]
=
[];
let
totalGaps
=
0
;
for
(
let
i
=
1
;
i
<
len
;
i
++
)
{
const
prevItemRect
=
list
[
i
-
1
].
rect
;
const
gap
=
Math
.
max
(
list
[
i
].
rect
[
xyDim
]
-
prevItemRect
[
xyDim
]
-
prevItemRect
[
sizeDim
],
0
);
gaps
.
push
(
gap
);
totalGaps
+=
gap
;
}
if
(
!
totalGaps
)
{
return
;
}
if
(
j
>
0
&&
!
rect
.
intersect
(
list
[
j
-
1
].
rect
))
{
break
;
}
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
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录