Skip to content

Commit

Permalink
fix(shape): Prevent when non-existed data.hide is given (#650)
Browse files Browse the repository at this point in the history
Add preventing condition to make sure calculating ratio value

Ref #623 
Close #650
  • Loading branch information
netil committed Nov 14, 2018
1 parent 76f3558 commit 6a72602
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions spec/internals/data-spec.js
Expand Up @@ -1523,6 +1523,8 @@ describe("DATA", () => {
["data1", 230, null, 300],
["data2", 198, 87, null]
];

args.data.hide = ["false-data"];
});

it("check for null data", done => {
Expand Down
17 changes: 9 additions & 8 deletions src/data/data.js
Expand Up @@ -795,18 +795,19 @@ extend(ChartInternal.prototype, {
let total = this.getTotalPerIndex();

if ($$.hiddenTargetIds.length) {
const hiddenSum = dataValues($$.hiddenTargetIds, false)
.reduce((acc, curr) => acc.map((v, i) => (isNumber(v) ? v : 0) + curr[i]));
let hiddenSum = dataValues($$.hiddenTargetIds, false);

total = total.map((v, i) => v - hiddenSum[i]);
}

d.ratio = 0;
if (hiddenSum.length) {
hiddenSum = hiddenSum
.reduce((acc, curr) => acc.map((v, i) => (isNumber(v) ? v : 0) + curr[i]));

if (isNumber(d.value) && total && total[d.index] > 0) {
d.ratio = d.value / total[d.index];
total = total.map((v, i) => v - hiddenSum[i]);
}
}

d.ratio = isNumber(d.value) && total && total[d.index] > 0 ?
d.value / total[d.index] : 0;

ratio = d.ratio;
} else if (type === "radar") {
ratio = (parseFloat(Math.max(d.value, 0)) / $$.maxValue) * config.radar_size_ratio;
Expand Down

0 comments on commit 6a72602

Please sign in to comment.