-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathSimpleVerticalArrow.tsx
More file actions
146 lines (138 loc) · 3.52 KB
/
Copy pathSimpleVerticalArrow.tsx
File metadata and controls
146 lines (138 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/** @jsxImportSource @antv/infographic-jsx */
import {
Bounds,
ComponentType,
Group,
Polygon,
Text,
} from '@antv/infographic-jsx';
import { Gap, ItemDesc, ItemLabel } from '../components';
import { FlexLayout } from '../layouts';
import { AlignLayout } from '../layouts/Align';
import { getItemProps } from '../utils';
import { registerItem } from './registry';
import type { BaseItemProps } from './types';
export interface SimpleVerticalArrowProps extends BaseItemProps {
height?: number;
/** 翻转方向 */
flipped?: boolean;
}
export const SimpleVerticalArrow: ComponentType<SimpleVerticalArrowProps> = (
props,
) => {
const [
{ indexes, datum, height = 140, themeColors, positionH = 'normal' },
restProps,
] = getItemProps(props, ['height']);
const textAlignHorizontal = positionH === 'normal' ? 'right' : 'left';
const label = (
<ItemLabel
indexes={indexes}
width={120}
fill={themeColors.colorText}
alignHorizontal={textAlignHorizontal}
alignVertical="center"
fontSize={14}
>
{datum.label}
</ItemLabel>
);
const desc = (
<ItemDesc
indexes={indexes}
width={120}
fill={themeColors.colorTextSecondary}
alignHorizontal={textAlignHorizontal}
alignVertical="top"
>
{datum.desc}
</ItemDesc>
);
const labelGap = 15;
const arrowWidth = 30;
const textWidth = 120;
const totalWidth = textWidth + labelGap + arrowWidth + labelGap + textWidth;
return (
<Group width={totalWidth} height={height} {...restProps}>
<FlexLayout flexDirection="row" alignItems="center">
{positionH === 'normal' ? (
<>
<FlexLayout flexDirection="column" alignItems="flex-end">
{label}
{desc}
</FlexLayout>
<Gap width={labelGap} />
</>
) : (
<>
<Gap width={textWidth + labelGap} />
</>
)}
<AlignLayout horizontal="center" vertical="center">
<VerticalArrow
width={arrowWidth}
height={height}
fill={themeColors.colorPrimary}
/>
<Text
width={arrowWidth}
height={height}
alignHorizontal="center"
alignVertical="center"
fill={themeColors.colorWhite}
fontWeight="bold"
fontSize={16}
>
{String(indexes[0] + 1)
.padStart(2, '0')
.slice(-2)}
</Text>
</AlignLayout>
{positionH === 'flipped' ? (
<>
<Gap width={labelGap} />
<FlexLayout flexDirection="column" alignItems="flex-start">
{label}
{desc}
</FlexLayout>
</>
) : (
<>
<Gap width={textWidth + labelGap} />
</>
)}
</FlexLayout>
</Group>
);
};
const VerticalArrow = (
props: Partial<Bounds> & { fill: string; size?: number },
) => {
const {
x = 0,
y = 0,
width = 30,
height = 100,
fill = '#1890FF',
size = 10,
} = props;
return (
<Polygon
width={width}
height={height}
points={[
{ x, y },
{ x: x + width / 2, y: y + size },
{ x: x + width, y },
{ x: x + width, y: y + height - size },
{ x: x + width / 2, y: y + height },
{ x, y: y + height - size },
]}
fill={fill}
/>
);
};
registerItem('simple-vertical-arrow', {
component: SimpleVerticalArrow,
composites: ['label', 'desc'],
});