Skip to content

Commit

Permalink
fix: pie label 显示优化 (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Mar 28, 2022
1 parent 85a727c commit 08f1f8d
Show file tree
Hide file tree
Showing 8 changed files with 557 additions and 210 deletions.
63 changes: 22 additions & 41 deletions packages/f2/src/components/pieLabel/pieLabeView.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
import { jsx } from '../../jsx';

export default (props, context) => {
const {
sidePadding,
// adjustOffset,
lineStyle,
anchorStyle,
labels,
label1OffsetY,
label2OffsetY,
triggerRef,
} = props;

const defaultTextAttrs = {
x: 0,
y: 0,
fontSize: '24px',
lineHeight: '24px',
fill: '#808080',
};
export default (props) => {
const { lineStyle, anchorStyle, labels, label1OffsetY, label2OffsetY, triggerRef } = props;

return (
<group ref={triggerRef}>
{labels.map((label) => {
const { y, fill, _inflection, _anchor, origin, label1, label2 } = label;
const lastPoint = {
x: label._side === 'left' ? sidePadding : context.width - sidePadding,
y,
};
const { origin, anchor, side, color, label1, label2, points } = label;
const end = points[points.length - 1];

const textAttrs = {
textAlign: label._side === 'left' ? 'left' : 'right',
x: label._side === 'left' ? sidePadding : context.width - sidePadding,
};
const points = [_anchor, _inflection, lastPoint];
return (
<group>
{/* 锚点 */}
<circle
attrs={{
r: 2,
x: _anchor.x,
y: _anchor.y,
fill,
r: '4px',
x: anchor.x,
y: anchor.y,
fill: color,
...anchorStyle,
}}
/>
{/* 线 */}
<polyline
attrs={{
points,
lineWidth: 1,
stroke: fill,
lineWidth: '2px',
stroke: color,
...lineStyle,
}}
/>
{/* label1 顶部 */}
<text
className="click"
attrs={{
...defaultTextAttrs,
x: end.x,
y: end.y + label1OffsetY,
fontSize: '24px',
lineHeight: '24px',
fill: color,
textBaseline: 'bottom',
y: y + label1OffsetY,
...textAttrs,
textAlign: side === 'left' ? 'left' : 'right',
...label1,
}}
data={origin}
Expand All @@ -71,10 +49,13 @@ export default (props, context) => {
<text
className="click"
attrs={{
...defaultTextAttrs,
x: end.x,
y: end.y + label2OffsetY,
fontSize: '24px',
lineHeight: '24px',
fill: '#808080',
textBaseline: 'top',
y: y + label2OffsetY,
...textAttrs,
textAlign: side === 'left' ? 'left' : 'right',
...label2,
}}
data={origin}
Expand Down
Loading

0 comments on commit 08f1f8d

Please sign in to comment.