UNPKG

2.53 kBJavaScriptView Raw
1import { __assign } from "tslib";
2import { isFunction } from '@antv/util';
3import { jsx } from '@antv/f-engine';
4var Marker = function Marker(_a) {
5 var type = _a.type,
6 color = _a.color;
7 if (type === 'square') {
8 return jsx("rect", {
9 style: {
10 width: '12px',
11 height: '12px',
12 marginRight: '10px'
13 },
14 attrs: {
15 fill: color
16 }
17 });
18 }
19 if (type === 'line') {
20 return jsx("line", {
21 style: {
22 width: '19px',
23 marginRight: '10px'
24 },
25 attrs: {
26 stroke: color,
27 lineCap: 'round',
28 lineWidth: '4px'
29 }
30 });
31 }
32 return jsx("circle", {
33 style: {
34 width: '12px',
35 height: '12px',
36 marginRight: '10px',
37 fill: color
38 }
39 });
40};
41export default (function (props) {
42 var items = props.items,
43 itemWidth = props.itemWidth,
44 itemFormatter = props.itemFormatter,
45 style = props.style,
46 _a = props.marker,
47 marker = _a === void 0 ? 'circle' : _a,
48 // 图例标记默认为 circle
49 itemStyle = props.itemStyle,
50 nameStyle = props.nameStyle,
51 valueStyle = props.valueStyle,
52 valuePrefix = props.valuePrefix,
53 onClick = props.onClick;
54 var formatValue = function formatValue(value, valuePrefix) {
55 if (valuePrefix === void 0) {
56 valuePrefix = ': ';
57 }
58 return "".concat(valuePrefix).concat(value);
59 };
60 return jsx("group", {
61 style: __assign({
62 display: 'flex'
63 }, style)
64 }, items.map(function (item) {
65 var color = item.color,
66 name = item.name,
67 value = item.value,
68 filtered = item.filtered,
69 tickValue = item.tickValue;
70 var valueText = isFunction(itemFormatter) ? itemFormatter(value, tickValue) : value;
71 return jsx("group", {
72 className: "legend-item",
73 style: __assign({
74 width: itemWidth,
75 display: 'flex',
76 flexDirection: 'row',
77 alignItems: 'center',
78 justifyContent: 'flex-start',
79 //TODO: padding改为’12px‘ 就和原来一致了
80 padding: ['6px', '6px', '6px', 0]
81 }, itemStyle),
82 "data-item": item,
83 onClick: onClick
84 }, Marker({
85 color: filtered ? '#bfbfbf' : color,
86 type: marker
87 }), jsx("text", {
88 attrs: __assign({
89 fill: filtered ? '#bfbfbf' : '#808080',
90 text: name
91 }, nameStyle)
92 }), valueText ? jsx("text", {
93 attrs: __assign({
94 fill: '#808080',
95 text: formatValue(valueText, valuePrefix)
96 }, valueStyle)
97 }) : null);
98 }));
99});
\No newline at end of file