@easyv/charts 1.0.72 → 1.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Band.js +6 -1
- package/lib/components/Line.js +18 -1
- package/lib/components/PieChart.js +14 -8
- package/lib/hooks/useAxes.js +4 -2
- package/lib/utils/index.js +28 -5
- package/package.json +2 -2
- package/src/components/Band.tsx +15 -4
- package/src/components/Line.js +18 -2
- package/src/components/PieChart.js +64 -60
- package/src/hooks/useAxes.js +12 -11
- package/src/utils/index.js +31 -10
package/lib/components/Band.js
CHANGED
|
@@ -89,7 +89,11 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
|
|
|
89
89
|
_ref3$config$paddingI = _ref3$config.paddingInner,
|
|
90
90
|
paddingOuter = _ref3$config$paddingI === void 0 ? 0 : _ref3$config$paddingI,
|
|
91
91
|
style = _ref3$config.style,
|
|
92
|
+
fillType = _ref3$config.fillType,
|
|
93
|
+
url = _ref3$config.url,
|
|
94
|
+
size = _ref3$config.size,
|
|
92
95
|
fill = _ref3$config.fill,
|
|
96
|
+
opacity = _ref3$config.opacity,
|
|
93
97
|
_ref3$config$highligh = _ref3$config.highlight,
|
|
94
98
|
showHighlight = _ref3$config$highligh.show,
|
|
95
99
|
extent = _ref3$config$highligh.extent,
|
|
@@ -152,7 +156,8 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
|
|
|
152
156
|
style: {
|
|
153
157
|
width: '100%',
|
|
154
158
|
height: '100%',
|
|
155
|
-
|
|
159
|
+
opacity: opacity,
|
|
160
|
+
background: fillType == 'pattern' ? "50% 50% / ".concat(size.width, "px ").concat(size.height, "px repeat ") + 'url(' + url + ')' : (0, _utils.getBandBackground)(pattern, extent === flag ? highlightFill : fill),
|
|
156
161
|
borderRadius: style == 'square' ? '0 0 0 0' : getBorderRadius({
|
|
157
162
|
isVertical: isVertical,
|
|
158
163
|
positive: y > 0,
|
package/lib/components/Line.js
CHANGED
|
@@ -45,9 +45,16 @@ var getLineData = function getLineData(data, connectNulls) {
|
|
|
45
45
|
|
|
46
46
|
var Area = function Area(_ref2) {
|
|
47
47
|
var data = _ref2.data,
|
|
48
|
+
config = _ref2.config,
|
|
48
49
|
_ref2$config = _ref2.config,
|
|
49
50
|
id = _ref2$config.id,
|
|
50
51
|
fill = _ref2$config.fill,
|
|
52
|
+
type = _ref2$config.type,
|
|
53
|
+
url = _ref2$config.url,
|
|
54
|
+
opacity = _ref2$config.opacity,
|
|
55
|
+
_ref2$config$size = _ref2$config.size,
|
|
56
|
+
patternW = _ref2$config$size.width,
|
|
57
|
+
patternH = _ref2$config$size.height,
|
|
51
58
|
curve = _ref2$config.curve,
|
|
52
59
|
tension = _ref2$config.tension,
|
|
53
60
|
xScaler = _ref2.xScaler,
|
|
@@ -76,7 +83,17 @@ var Area = function Area(_ref2) {
|
|
|
76
83
|
d: areaGen(data),
|
|
77
84
|
stroke: "none",
|
|
78
85
|
fill: 'url(#' + id + ')'
|
|
79
|
-
}), /*#__PURE__*/_react["default"].createElement("defs", null, /*#__PURE__*/_react["default"].createElement(
|
|
86
|
+
}), /*#__PURE__*/_react["default"].createElement("defs", null, type && type == 'pattern' ? /*#__PURE__*/_react["default"].createElement("pattern", {
|
|
87
|
+
id: id,
|
|
88
|
+
patternUnits: "userSpaceOnUse",
|
|
89
|
+
width: patternW,
|
|
90
|
+
height: patternH
|
|
91
|
+
}, url && /*#__PURE__*/_react["default"].createElement("image", {
|
|
92
|
+
opacity: opacity,
|
|
93
|
+
width: patternW,
|
|
94
|
+
height: patternH,
|
|
95
|
+
xlinkHref: window.appConfig.ASSETS_URL + url
|
|
96
|
+
})) : /*#__PURE__*/_react["default"].createElement(_.LinearGradient, {
|
|
80
97
|
id: id,
|
|
81
98
|
colors: area,
|
|
82
99
|
rotate: 0
|
|
@@ -625,7 +625,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
625
625
|
textAnchor: "middle",
|
|
626
626
|
style: _objectSpread(_objectSpread({}, categoryTextStyle), {}, {
|
|
627
627
|
fontWeight: categoryTextStyle.bold ? "bold" : "normal",
|
|
628
|
-
fontStyle: categoryTextStyle.italic ? "italic" : "normal"
|
|
628
|
+
fontStyle: categoryTextStyle.italic ? "italic" : "normal",
|
|
629
|
+
pointerEvents: "none"
|
|
629
630
|
}),
|
|
630
631
|
fill: categoryTextStyle.color
|
|
631
632
|
}, /*#__PURE__*/_react["default"].createElement("textPath", {
|
|
@@ -647,6 +648,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
647
648
|
}
|
|
648
649
|
}, /*#__PURE__*/_react["default"].createElement(Current, {
|
|
649
650
|
config: current,
|
|
651
|
+
width: width,
|
|
652
|
+
height: height,
|
|
650
653
|
data: _arcs,
|
|
651
654
|
currentIndex: +currentIndex
|
|
652
655
|
})))), decorate && /*#__PURE__*/_react["default"].createElement(_.ConicalGradient, {
|
|
@@ -691,6 +694,8 @@ var Current = function Current(_ref9) {
|
|
|
691
694
|
_ref9$config$value$su2 = _ref9$config$value$su.translate,
|
|
692
695
|
translateSuffixX = _ref9$config$value$su2.x,
|
|
693
696
|
translateSuffixY = _ref9$config$value$su2.y,
|
|
697
|
+
width = _ref9.width,
|
|
698
|
+
height = _ref9.height,
|
|
694
699
|
data = _ref9.data,
|
|
695
700
|
currentIndex = _ref9.currentIndex;
|
|
696
701
|
|
|
@@ -720,20 +725,21 @@ var Current = function Current(_ref9) {
|
|
|
720
725
|
nameList.push(nameTemp);
|
|
721
726
|
var foreignStyle = {
|
|
722
727
|
//foreignObject标签样式,
|
|
723
|
-
width:
|
|
724
|
-
height:
|
|
725
|
-
transform: "translate(-
|
|
728
|
+
width: width,
|
|
729
|
+
height: height,
|
|
730
|
+
transform: "translate(-".concat(width / 2, "px,-").concat(height / 2, "px)"),
|
|
731
|
+
pointerEvents: "none"
|
|
726
732
|
},
|
|
727
733
|
boxStyle = {
|
|
728
734
|
//弹性盒子样式,用于当前值的上下居中对齐等
|
|
729
|
-
width:
|
|
730
|
-
height:
|
|
735
|
+
width: width,
|
|
736
|
+
height: height,
|
|
731
737
|
display: "flex",
|
|
732
738
|
flexDirection: "column",
|
|
733
739
|
justifyContent: "center",
|
|
734
740
|
alignItems: "center"
|
|
735
741
|
};
|
|
736
|
-
return show && /*#__PURE__*/_react["default"].createElement(
|
|
742
|
+
return show && /*#__PURE__*/_react["default"].createElement("foreignObject", {
|
|
737
743
|
style: foreignStyle
|
|
738
744
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
739
745
|
style: boxStyle
|
|
@@ -767,7 +773,7 @@ var Current = function Current(_ref9) {
|
|
|
767
773
|
}, (0, _utils.getFontStyle)(percentFont)), {}, {
|
|
768
774
|
margin: gap / 2 + "px 0"
|
|
769
775
|
})
|
|
770
|
-
}, percent + '%')))
|
|
776
|
+
}, percent + '%')));
|
|
771
777
|
};
|
|
772
778
|
|
|
773
779
|
var Label = function Label(_ref10) {
|
package/lib/hooks/useAxes.js
CHANGED
|
@@ -45,7 +45,9 @@ var _default = function _default(_ref) {
|
|
|
45
45
|
var tmp = new Map();
|
|
46
46
|
var xAxisPositions = [];
|
|
47
47
|
axes.forEach(function (item) {
|
|
48
|
-
var
|
|
48
|
+
var _item$config$label$sh = item.config.label.showLast,
|
|
49
|
+
showLast = _item$config$label$sh === void 0 ? false : _item$config$label$sh,
|
|
50
|
+
type = item.type,
|
|
49
51
|
orientation = item.orientation,
|
|
50
52
|
ticks = item.ticks,
|
|
51
53
|
_item$tickCount = item.tickCount,
|
|
@@ -76,7 +78,7 @@ var _default = function _default(_ref) {
|
|
|
76
78
|
|
|
77
79
|
if (type === 'ordinal') {
|
|
78
80
|
if (carousel === false) {
|
|
79
|
-
_ticks = (0,
|
|
81
|
+
_ticks = (0, _utils.getTicksOfAxis)(_ticks, +tickCount, showLast);
|
|
80
82
|
}
|
|
81
83
|
} else {
|
|
82
84
|
if (auto === false) {
|
package/lib/utils/index.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.band = band;
|
|
9
|
-
exports.getDataWithPercent = exports.sortPie = exports.getDomPath = exports.filterChildren = exports.getChildren = exports.isValidHttpUrl = exports.getBandSeriesStepAndWidth = exports.getBandwidth = exports.getBandBackground = exports.getCurrentStack = exports.resetStacks = exports.seriesYOrZ = exports.dataYOrZ = exports.getStacks = exports.getColorList = exports.getIcon = exports.getTranslate2d = exports.getTranslate3d = exports.getMargin = exports.getFontStyle = exports.getMousePos = exports.identity = exports.getGridCoord = exports.getTickCoord = exports.getBreakWord = exports.dateFormat = void 0;
|
|
9
|
+
exports.getDataWithPercent = exports.sortPie = exports.getDomPath = exports.filterChildren = exports.getChildren = exports.isValidHttpUrl = exports.getBandSeriesStepAndWidth = exports.getBandwidth = exports.getBandBackground = exports.getCurrentStack = exports.resetStacks = exports.seriesYOrZ = exports.dataYOrZ = exports.getStacks = exports.getColorList = exports.getIcon = exports.getTranslate2d = exports.getTranslate3d = exports.getMargin = exports.getFontStyle = exports.getMousePos = exports.identity = exports.getGridCoord = exports.getTickCoord = exports.getTicksOfAxis = exports.getBreakWord = exports.dateFormat = void 0;
|
|
10
10
|
|
|
11
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
12
|
|
|
@@ -169,10 +169,33 @@ exports.dateFormat = dateFormat;
|
|
|
169
169
|
var getBreakWord = function getBreakWord(str, breakNumber) {
|
|
170
170
|
var re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
|
|
171
171
|
return str.match(re);
|
|
172
|
-
};
|
|
172
|
+
}; //x轴标签逻辑
|
|
173
|
+
|
|
173
174
|
|
|
174
175
|
exports.getBreakWord = getBreakWord;
|
|
175
176
|
|
|
177
|
+
var getTicksOfAxis = function getTicksOfAxis(domain, ticksCount, showLast) {
|
|
178
|
+
var len = domain.length;
|
|
179
|
+
if (ticksCount < 2 || ticksCount > len) return domain;
|
|
180
|
+
var step = Math.floor((len - ticksCount) / (ticksCount - 1));
|
|
181
|
+
var ticksArr = domain.filter(function (d, i) {
|
|
182
|
+
return i % (step + 1) === 0;
|
|
183
|
+
});
|
|
184
|
+
var Tlen = ticksArr.length;
|
|
185
|
+
var lastIndex = domain.findIndex(function (d) {
|
|
186
|
+
return d == ticksArr[Tlen - 1];
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (showLast) {
|
|
190
|
+
len % ticksCount == 0 || len - 1 - lastIndex >= Math.round(len / Tlen / 2) ? null : ticksArr.pop();
|
|
191
|
+
ticksArr.push(domain[len - 1]);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return ticksArr;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
exports.getTicksOfAxis = getTicksOfAxis;
|
|
198
|
+
|
|
176
199
|
var getTickCoord = function getTickCoord(_ref5) {
|
|
177
200
|
var orientation = _ref5.orientation,
|
|
178
201
|
coordinate = _ref5.coordinate,
|
|
@@ -768,8 +791,8 @@ exports.sortPie = sortPie;
|
|
|
768
791
|
var getDataWithPercent = function getDataWithPercent() {
|
|
769
792
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
770
793
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
771
|
-
var digits = Math.pow(10, precision);
|
|
772
|
-
|
|
794
|
+
var digits = Math.pow(10, precision);
|
|
795
|
+
var targetSeats = digits * 100;
|
|
773
796
|
var total = (0, _d3v.sum)(data, function (d) {
|
|
774
797
|
return d.value;
|
|
775
798
|
});
|
|
@@ -782,7 +805,7 @@ var getDataWithPercent = function getDataWithPercent() {
|
|
|
782
805
|
var currentSum = (0, _d3v.sum)(votesPerQuota, function (d) {
|
|
783
806
|
return d.vote;
|
|
784
807
|
});
|
|
785
|
-
var remainder =
|
|
808
|
+
var remainder = targetSeats - currentSum;
|
|
786
809
|
votesPerQuota.sort(function (_ref26, _ref27) {
|
|
787
810
|
var a = _ref26.value;
|
|
788
811
|
var b = _ref27.value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyv/charts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.75",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"load-styles": "^2.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@easyv/utils": "^0.0.
|
|
28
|
+
"@easyv/utils": "^0.0.33",
|
|
29
29
|
"d3v7": "npm:d3@^7.0.0",
|
|
30
30
|
"popmotion": "^9.3.6",
|
|
31
31
|
"react": "^17.0.2",
|
package/src/components/Band.tsx
CHANGED
|
@@ -76,7 +76,11 @@ export default memo(
|
|
|
76
76
|
seriesIntervalWidth: paddingInner = 0,
|
|
77
77
|
paddingInner: paddingOuter = 0,
|
|
78
78
|
style,
|
|
79
|
+
fillType,
|
|
80
|
+
url,
|
|
81
|
+
size,
|
|
79
82
|
fill,
|
|
83
|
+
opacity,
|
|
80
84
|
highlight: { show: showHighlight, extent, fill: highlightFill },
|
|
81
85
|
},
|
|
82
86
|
bandLength = 0,
|
|
@@ -136,10 +140,17 @@ export default memo(
|
|
|
136
140
|
style={{
|
|
137
141
|
width: '100%',
|
|
138
142
|
height: '100%',
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
opacity:opacity,
|
|
144
|
+
background:
|
|
145
|
+
fillType == 'pattern'
|
|
146
|
+
? `50% 50% / ${size.width}px ${size.height}px repeat ` +
|
|
147
|
+
'url(' +
|
|
148
|
+
url +
|
|
149
|
+
')'
|
|
150
|
+
: getBandBackground(
|
|
151
|
+
pattern,
|
|
152
|
+
extent === flag ? highlightFill : fill
|
|
153
|
+
),
|
|
143
154
|
borderRadius:
|
|
144
155
|
style == 'square'
|
|
145
156
|
? '0 0 0 0'
|
package/src/components/Line.js
CHANGED
|
@@ -17,7 +17,17 @@ const getLineData = (data, connectNulls) =>
|
|
|
17
17
|
|
|
18
18
|
const Area = ({
|
|
19
19
|
data,
|
|
20
|
-
config
|
|
20
|
+
config,
|
|
21
|
+
config: {
|
|
22
|
+
id,
|
|
23
|
+
fill,
|
|
24
|
+
type,
|
|
25
|
+
url,
|
|
26
|
+
opacity,
|
|
27
|
+
size: { width: patternW, height: patternH },
|
|
28
|
+
curve,
|
|
29
|
+
tension
|
|
30
|
+
},
|
|
21
31
|
xScaler,
|
|
22
32
|
yScaler,
|
|
23
33
|
}) => {
|
|
@@ -39,7 +49,13 @@ const Area = ({
|
|
|
39
49
|
<>
|
|
40
50
|
<path d={areaGen(data)} stroke='none' fill={'url(#' + id + ')'} />
|
|
41
51
|
<defs>
|
|
42
|
-
|
|
52
|
+
{type && type == 'pattern' ? (
|
|
53
|
+
<pattern id={id} patternUnits="userSpaceOnUse" width={patternW} height={patternH}>
|
|
54
|
+
{url && <image opacity={opacity} width={patternW} height={patternH} xlinkHref={window.appConfig.ASSETS_URL + url} />}
|
|
55
|
+
</pattern>
|
|
56
|
+
) : (
|
|
57
|
+
<LinearGradient id={id} colors={area} rotate={0} />
|
|
58
|
+
)}
|
|
43
59
|
</defs>
|
|
44
60
|
</>
|
|
45
61
|
);
|
|
@@ -572,7 +572,8 @@ const Component = memo(
|
|
|
572
572
|
style={{
|
|
573
573
|
...categoryTextStyle,
|
|
574
574
|
fontWeight:categoryTextStyle.bold?"bold":"normal",
|
|
575
|
-
fontStyle:categoryTextStyle.italic?"italic":"normal"
|
|
575
|
+
fontStyle:categoryTextStyle.italic?"italic":"normal",
|
|
576
|
+
pointerEvents:"none"
|
|
576
577
|
}}
|
|
577
578
|
fill={categoryTextStyle.color}
|
|
578
579
|
>
|
|
@@ -599,9 +600,11 @@ const Component = memo(
|
|
|
599
600
|
)}
|
|
600
601
|
{label && <Label config={label} arcs={_arcs} />}
|
|
601
602
|
{current && (
|
|
602
|
-
<g fillOpacity={y} style={{transform:"rotate("+(-rotate_)+"deg)"}}>
|
|
603
|
+
<g fillOpacity={y} style={{ transform:"rotate("+(-rotate_)+"deg)" }}>
|
|
603
604
|
<Current
|
|
604
605
|
config={current}
|
|
606
|
+
width={width}
|
|
607
|
+
height={height}
|
|
605
608
|
data={_arcs}
|
|
606
609
|
currentIndex={+currentIndex}
|
|
607
610
|
/>
|
|
@@ -649,6 +652,8 @@ const Current = ({
|
|
|
649
652
|
},
|
|
650
653
|
},
|
|
651
654
|
},
|
|
655
|
+
width,
|
|
656
|
+
height,
|
|
652
657
|
data,
|
|
653
658
|
currentIndex,
|
|
654
659
|
}) => {
|
|
@@ -671,13 +676,14 @@ const Current = ({
|
|
|
671
676
|
}
|
|
672
677
|
nameList.push(nameTemp)
|
|
673
678
|
let foreignStyle={ //foreignObject标签样式,
|
|
674
|
-
width
|
|
675
|
-
height
|
|
676
|
-
transform
|
|
679
|
+
width,
|
|
680
|
+
height,
|
|
681
|
+
transform:`translate(-${width/2}px,-${height/2}px)`,
|
|
682
|
+
pointerEvents:"none"
|
|
677
683
|
},
|
|
678
684
|
boxStyle={ //弹性盒子样式,用于当前值的上下居中对齐等
|
|
679
|
-
width
|
|
680
|
-
height
|
|
685
|
+
width,
|
|
686
|
+
height,
|
|
681
687
|
display:"flex",
|
|
682
688
|
flexDirection:"column",
|
|
683
689
|
justifyContent:"center",
|
|
@@ -686,59 +692,57 @@ const Current = ({
|
|
|
686
692
|
|
|
687
693
|
return (
|
|
688
694
|
show && (
|
|
689
|
-
|
|
690
|
-
<
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
{
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
</foreignObject>
|
|
741
|
-
</>
|
|
695
|
+
<foreignObject style={foreignStyle}>
|
|
696
|
+
<div style={boxStyle}>
|
|
697
|
+
{ //类目名称
|
|
698
|
+
showName && <div
|
|
699
|
+
style={{
|
|
700
|
+
...getFontStyle(nameFont),
|
|
701
|
+
margin:gap/2+"px 0",
|
|
702
|
+
display:"flex",
|
|
703
|
+
flexDirection:"column",
|
|
704
|
+
alignItems:"center"
|
|
705
|
+
}}>
|
|
706
|
+
{
|
|
707
|
+
nameList.map((d,i)=>{
|
|
708
|
+
return <span key={i}>{d}</span>
|
|
709
|
+
})
|
|
710
|
+
}
|
|
711
|
+
</div>
|
|
712
|
+
}
|
|
713
|
+
{ //真实值
|
|
714
|
+
showValue && <span
|
|
715
|
+
style={{
|
|
716
|
+
...getFontStyle(valueFont),
|
|
717
|
+
transform:"translate("+translateValueX+"px,"+translateValueY+"px)",
|
|
718
|
+
margin:gap/2+"px 0"
|
|
719
|
+
}}>
|
|
720
|
+
{value}
|
|
721
|
+
{showSuffix && text && (
|
|
722
|
+
<span
|
|
723
|
+
style={{
|
|
724
|
+
transform:"translate("+translateSuffixX+"px,"+translateSuffixY+"px)",
|
|
725
|
+
fontSize:fontSize
|
|
726
|
+
}}
|
|
727
|
+
>
|
|
728
|
+
{text}
|
|
729
|
+
</span>
|
|
730
|
+
)}
|
|
731
|
+
</span>
|
|
732
|
+
}
|
|
733
|
+
{ //百分比值
|
|
734
|
+
showPercent && <span
|
|
735
|
+
style={{
|
|
736
|
+
transform:"translate("+translatePercentX+"px,"+translatePercentY+"px)",
|
|
737
|
+
...getFontStyle(percentFont),
|
|
738
|
+
margin:gap/2+"px 0"
|
|
739
|
+
}}
|
|
740
|
+
>
|
|
741
|
+
{percent + '%'}
|
|
742
|
+
</span>
|
|
743
|
+
}
|
|
744
|
+
</div>
|
|
745
|
+
</foreignObject>
|
|
742
746
|
)
|
|
743
747
|
);
|
|
744
748
|
};
|
package/src/hooks/useAxes.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { scaleLinear, scaleLog, scaleTime, scaleUtc } from 'd3-scale';
|
|
3
|
-
import { band } from '../utils';
|
|
3
|
+
import { band, getTicksOfAxis } from '../utils';
|
|
4
4
|
import {
|
|
5
5
|
getYTicksByStep,
|
|
6
6
|
getYTicks,
|
|
7
|
-
getTicksOfAxis,
|
|
8
7
|
} from '@easyv/utils/lib/common/utils';
|
|
9
8
|
|
|
10
9
|
const scales = {
|
|
@@ -28,6 +27,7 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
28
27
|
const xAxisPositions = [];
|
|
29
28
|
axes.forEach((item) => {
|
|
30
29
|
const {
|
|
30
|
+
config: { label: { showLast = false } },
|
|
31
31
|
type,
|
|
32
32
|
orientation,
|
|
33
33
|
ticks,
|
|
@@ -41,19 +41,20 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
41
41
|
carousel,
|
|
42
42
|
config,
|
|
43
43
|
} = item;
|
|
44
|
+
|
|
44
45
|
const direction =
|
|
45
46
|
orientation === 'top' || orientation === 'bottom'
|
|
46
47
|
? 'horizontal'
|
|
47
48
|
: orientation === 'left' || orientation === 'right'
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
? 'vertical'
|
|
50
|
+
: '';
|
|
50
51
|
|
|
51
52
|
const length =
|
|
52
53
|
direction === 'horizontal'
|
|
53
54
|
? width
|
|
54
55
|
: direction === 'vertical'
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
? height
|
|
57
|
+
: 0;
|
|
57
58
|
|
|
58
59
|
const _paddingOuter = paddingOuter * length;
|
|
59
60
|
const start = _paddingOuter / 2;
|
|
@@ -63,8 +64,8 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
63
64
|
direction === 'horizontal'
|
|
64
65
|
? [start, end]
|
|
65
66
|
: direction === 'vertical'
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
? [end, start]
|
|
68
|
+
: [0, 0];
|
|
68
69
|
|
|
69
70
|
const scaler = scales[type]().domain(domain).range(range);
|
|
70
71
|
scaler.type = type;
|
|
@@ -74,13 +75,13 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
74
75
|
const allTicks = ticks
|
|
75
76
|
? ticks
|
|
76
77
|
: scaler.ticks
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
? scaler.ticks(tickCount)
|
|
79
|
+
: scaler.domain();
|
|
79
80
|
|
|
80
81
|
let _ticks = allTicks;
|
|
81
82
|
if (type === 'ordinal') {
|
|
82
83
|
if (carousel === false) {
|
|
83
|
-
_ticks = getTicksOfAxis(_ticks, +tickCount);
|
|
84
|
+
_ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
|
|
84
85
|
}
|
|
85
86
|
} else {
|
|
86
87
|
if (auto === false) {
|
package/src/utils/index.js
CHANGED
|
@@ -86,16 +86,16 @@ const getIcon = (type, icon) => {
|
|
|
86
86
|
case 'line':
|
|
87
87
|
return icon
|
|
88
88
|
? {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
...defaultLineIcon,
|
|
90
|
+
...icon,
|
|
91
|
+
}
|
|
92
92
|
: defaultLineIcon;
|
|
93
93
|
default:
|
|
94
94
|
return icon
|
|
95
95
|
? {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
...defaultIcon,
|
|
97
|
+
...icon,
|
|
98
|
+
}
|
|
99
99
|
: defaultIcon;
|
|
100
100
|
}
|
|
101
101
|
};
|
|
@@ -141,6 +141,26 @@ const getBreakWord = (str, breakNumber) => {
|
|
|
141
141
|
const re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
|
|
142
142
|
return str.match(re);
|
|
143
143
|
};
|
|
144
|
+
|
|
145
|
+
//x轴标签逻辑
|
|
146
|
+
|
|
147
|
+
const getTicksOfAxis = (domain, ticksCount, showLast) => {
|
|
148
|
+
|
|
149
|
+
let len = domain.length;
|
|
150
|
+
if (ticksCount < 2 || ticksCount > len) return domain;
|
|
151
|
+
let step = Math.floor((len - ticksCount) / (ticksCount - 1));
|
|
152
|
+
const ticksArr = domain.filter(function (d, i) {
|
|
153
|
+
return i % (step + 1) === 0;
|
|
154
|
+
});
|
|
155
|
+
let Tlen = ticksArr.length;
|
|
156
|
+
let lastIndex = domain.findIndex(d => d == ticksArr[Tlen - 1])
|
|
157
|
+
if (showLast) {
|
|
158
|
+
len % ticksCount == 0 || (len-1) - lastIndex >= Math.round(len / Tlen / 2) ? null : ticksArr.pop()
|
|
159
|
+
ticksArr.push(domain[len - 1])
|
|
160
|
+
}
|
|
161
|
+
return ticksArr
|
|
162
|
+
}
|
|
163
|
+
|
|
144
164
|
const getTickCoord = ({
|
|
145
165
|
orientation,
|
|
146
166
|
coordinate,
|
|
@@ -612,7 +632,7 @@ const sortPie = (data, order) => {
|
|
|
612
632
|
|
|
613
633
|
const getDataWithPercent = (data = [], precision = 0) => {
|
|
614
634
|
const digits = Math.pow(10, precision);
|
|
615
|
-
|
|
635
|
+
const targetSeats = digits * 100;
|
|
616
636
|
|
|
617
637
|
const total = sum(data, (d) => d.value);
|
|
618
638
|
|
|
@@ -623,16 +643,16 @@ const getDataWithPercent = (data = [], precision = 0) => {
|
|
|
623
643
|
}));
|
|
624
644
|
const currentSum = sum(votesPerQuota, (d) => d.vote);
|
|
625
645
|
|
|
626
|
-
let remainder =
|
|
646
|
+
let remainder = targetSeats - currentSum;
|
|
627
647
|
votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
|
|
628
648
|
|
|
629
649
|
const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {
|
|
630
|
-
let obj={
|
|
650
|
+
let obj = {
|
|
631
651
|
...data,
|
|
632
652
|
value,
|
|
633
653
|
percent: toFixed((vote + ((value && value != 0) ? remainder : 0)) / digits, precision),
|
|
634
654
|
};
|
|
635
|
-
if(value && value!=0){
|
|
655
|
+
if (value && value != 0) {
|
|
636
656
|
remainder = 0
|
|
637
657
|
}
|
|
638
658
|
return obj
|
|
@@ -643,6 +663,7 @@ const getDataWithPercent = (data = [], precision = 0) => {
|
|
|
643
663
|
export {
|
|
644
664
|
dateFormat,
|
|
645
665
|
getBreakWord,
|
|
666
|
+
getTicksOfAxis,
|
|
646
667
|
getTickCoord,
|
|
647
668
|
getGridCoord,
|
|
648
669
|
identity,
|