@easyv/charts 1.3.10 → 1.3.11
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/utils/index.js +50 -33
- package/package.json +1 -1
- package/src/utils/index.js +45 -28
package/lib/utils/index.js
CHANGED
|
@@ -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
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
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
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
var
|
|
842
|
-
|
|
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
|
-
|
|
855
|
-
|
|
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
|
|
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
|
|
877
|
+
return objData;
|
|
861
878
|
};
|
|
862
879
|
|
|
863
880
|
exports.getDataWithPercent = getDataWithPercent;
|
package/package.json
CHANGED
package/src/utils/index.js
CHANGED
|
@@ -655,36 +655,53 @@ const sortPie = (data, order) => {
|
|
|
655
655
|
// };
|
|
656
656
|
|
|
657
657
|
const getDataWithPercent = (data = [], precision = 0) => {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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
|
-
|
|
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
|
|
704
|
+
return objData
|
|
688
705
|
};
|
|
689
706
|
|
|
690
707
|
const excludeTypes = ['array', 'object', 'group', 'modal', 'colors'];
|