@easyv/charts 1.3.10 → 1.3.12

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.
@@ -146,7 +146,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
146
146
  var showHead, headUrl, headWidth, headHeight, headTranslate;
147
147
 
148
148
  if (headDecorate) {
149
- showHead = headDecorate.show, headUrl = headDecorate.url, headWidth = headDecorate.size.width, headHeight = headDecorate.size.height, headTranslate = headDecorate.headTranslate;
149
+ showHead = headDecorate.show, headUrl = headDecorate.url, headWidth = headDecorate.size.width, headHeight = headDecorate.size.height, headTranslate = headDecorate.translate;
150
150
  }
151
151
 
152
152
  if (isNaN(positionX)) return null;
@@ -83,7 +83,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
83
83
 
84
84
  var positionX = xScaler(x) - step / 2 + seriesStart + index * seriesStep;
85
85
  if (isNaN(positionX)) return null;
86
- var position = positionX + seriesWidth / 2;
86
+ var position = positionX + (config.line ? step : seriesWidth) / 2;
87
87
  var labelPosition = isVertical ? getVerticalLabel({
88
88
  position: _position,
89
89
  y: y,
@@ -26,8 +26,7 @@ var _server = require("react-dom/server");
26
26
 
27
27
  var _svgPoints = require("svg-points");
28
28
 
29
- var _excluded = ["backgroundSize"],
30
- _excluded2 = ["vote", "value"];
29
+ var _excluded = ["backgroundSize"];
31
30
 
32
31
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
33
32
 
@@ -821,43 +820,61 @@ exports.sortPie = sortPie;
821
820
  var getDataWithPercent = function getDataWithPercent() {
822
821
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
823
822
  var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
824
- var digits = Math.pow(10, precision);
825
- var targetSeats = digits * 100;
826
- var total = (0, _d3v.sum)(data, function (d) {
827
- return d.value;
828
- }) || 1;
829
- var votesPerQuota = data.map(function (d, index) {
830
- return _objectSpread(_objectSpread({}, d), {}, {
831
- vote: Math.round(d.value / total * digits * 100),
832
- index: index
823
+ var objData = [];
824
+
825
+ function getPercentWithPrecision(valueList, idx, precision) {
826
+ if (!valueList[idx]) {
827
+ return 0;
828
+ }
829
+
830
+ var sum = valueList.reduce(function (acc, val) {
831
+ return acc + val.data.y;
832
+ }, 0);
833
+
834
+ if (sum === 0) {
835
+ return 0;
836
+ }
837
+
838
+ var digits = Math.pow(10, precision);
839
+ var votesPerQuota = valueList.map(function (val) {
840
+ return val.data.y / sum * digits * 100;
833
841
  });
834
- });
835
- var currentSum = (0, _d3v.sum)(votesPerQuota, function (d) {
836
- return d.vote;
837
- });
838
- var remainder = targetSeats - currentSum;
839
- votesPerQuota.sort(function (_ref25, _ref26) {
840
- var a = _ref25.value;
841
- var b = _ref26.value;
842
- return a % total - b % total;
843
- });
844
- var tmp = votesPerQuota.map(function (_ref27, index) {
845
- var vote = _ref27.vote,
846
- value = _ref27.value,
847
- data = (0, _objectWithoutProperties2["default"])(_ref27, _excluded2);
848
-
849
- var obj = _objectSpread(_objectSpread({}, data), {}, {
850
- value: value,
851
- percent: (0, _utils2.toFixed)((vote + (value && value != 0 ? remainder : 0)) / digits, precision)
842
+ var targetSeats = digits * 100;
843
+ var seats = votesPerQuota.map(function (votes) {
844
+ return Math.floor(votes);
845
+ });
846
+ var currentSum = seats.reduce(function (acc, val) {
847
+ return acc + val;
848
+ }, 0);
849
+ var remainder = votesPerQuota.map(function (votes, idx) {
850
+ return votes - seats[idx];
852
851
  });
853
852
 
854
- if (value && value != 0) {
855
- remainder = 0;
853
+ while (currentSum < targetSeats) {
854
+ var max = Number.NEGATIVE_INFINITY;
855
+ var maxId = null;
856
+
857
+ for (var i = 0, len = remainder.length; i < len; ++i) {
858
+ if (remainder[i] > max) {
859
+ max = remainder[i];
860
+ maxId = i;
861
+ }
862
+ }
863
+
864
+ ++seats[maxId];
865
+ remainder[maxId] = 0;
866
+ ++currentSum;
856
867
  }
857
868
 
858
- return obj;
869
+ return seats[idx] / digits;
870
+ }
871
+
872
+ data.forEach(function (d, i) {
873
+ objData.push(_objectSpread(_objectSpread({}, d), {}, {
874
+ percent: getPercentWithPrecision(data, i, precision)
875
+ }));
859
876
  });
860
- return tmp;
877
+ return objData;
861
878
  };
862
879
 
863
880
  exports.getDataWithPercent = getDataWithPercent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -122,7 +122,7 @@ export default memo(
122
122
  headUrl = headDecorate.url,
123
123
  headWidth = headDecorate.size.width,
124
124
  headHeight = headDecorate.size.height,
125
- headTranslate = headDecorate.headTranslate;
125
+ headTranslate = headDecorate.translate;
126
126
  }
127
127
 
128
128
  if (isNaN(positionX)) return null;
@@ -33,7 +33,6 @@ export default memo(
33
33
  paddingInner,
34
34
  paddingOuter,
35
35
  });
36
-
37
36
  const isVertical = direction === 'vertical';
38
37
  const _position = label.position;
39
38
  return (
@@ -57,7 +56,7 @@ export default memo(
57
56
  xScaler(x) - step / 2 + seriesStart + index * seriesStep;
58
57
 
59
58
  if (isNaN(positionX)) return null;
60
- const position = positionX + seriesWidth / 2;
59
+ const position = positionX + (config.line?step:seriesWidth) / 2;
61
60
  const labelPosition = isVertical
62
61
  ? getVerticalLabel({
63
62
  position: _position,
@@ -655,36 +655,53 @@ const sortPie = (data, order) => {
655
655
  // };
656
656
 
657
657
  const getDataWithPercent = (data = [], precision = 0) => {
658
- const digits = Math.pow(10, precision);
659
- const targetSeats = digits * 100;
660
-
661
- const total = sum(data, (d) => d.value) || 1;
662
-
663
- const votesPerQuota = data.map((d, index) => ({
664
- ...d,
665
- vote: Math.round((d.value / total) * digits * 100),
666
- index,
667
- }));
668
- const currentSum = sum(votesPerQuota, (d) => d.vote);
669
-
670
- let remainder = targetSeats - currentSum;
671
- votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
672
-
673
- const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {
674
- let obj = {
675
- ...data,
676
- value,
677
- percent: toFixed(
678
- (vote + (value && value != 0 ? remainder : 0)) / digits,
679
- precision
680
- ),
681
- };
682
- if (value && value != 0) {
683
- remainder = 0;
658
+ let objData = [];
659
+ function getPercentWithPrecision(valueList, idx, precision) {
660
+ if (!valueList[idx]) {
661
+ return 0;
662
+ }
663
+ const sum = valueList.reduce( function (acc, val) {
664
+ return acc + val.data.y;
665
+ }, 0);
666
+ if (sum === 0) {
667
+ return 0;
684
668
  }
685
- return obj;
669
+ const digits = Math.pow(10, precision);
670
+ const votesPerQuota = valueList.map(function (val) {
671
+ return val.data.y / sum * digits * 100;
672
+ });
673
+ const targetSeats = digits * 100;
674
+ const seats = votesPerQuota.map(function (votes) {
675
+ return Math.floor(votes);
676
+ });
677
+ let currentSum = seats.reduce( function (acc, val) {
678
+ return acc + val;
679
+ }, 0);
680
+ const remainder = votesPerQuota.map(function (votes, idx) {
681
+ return votes - seats[idx];
682
+ });
683
+ while (currentSum < targetSeats) {
684
+ let max = Number.NEGATIVE_INFINITY;
685
+ let maxId = null;
686
+ for (let i = 0, len = remainder.length; i < len; ++i) {
687
+ if (remainder[i] > max) {
688
+ max = remainder[i];
689
+ maxId = i;
690
+ }
691
+ }
692
+ ++seats[maxId];
693
+ remainder[maxId] = 0;
694
+ ++currentSum;
695
+ }
696
+ return seats[idx] / digits;
697
+ }
698
+ data.forEach((d, i) => {
699
+ objData.push({
700
+ ...d,
701
+ percent: getPercentWithPrecision(data, i, precision)
702
+ })
686
703
  });
687
- return tmp;
704
+ return objData
688
705
  };
689
706
 
690
707
  const excludeTypes = ['array', 'object', 'group', 'modal', 'colors'];