Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #252 from FormidableLabs/bug/single-point-domains
Browse files Browse the repository at this point in the history
change single point domain logic
  • Loading branch information
boygirl authored Jun 9, 2017
2 parents a7ab41e + 075dd80 commit f088cfd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/victory-util/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,23 @@ export default {

const min = Collection.getMinValue(allData);
const max = Collection.getMaxValue(allData);
// TODO: is this the correct behavior, or should we just error. How do we
// handle charts with just one data point?
let domain;
if (min === max) {
const adjustedMax = max === 0 ? 1 : max;
return [0, adjustedMax];
domain = this.getSinglePointDomain(max);
}
const domain = [min, max];
domain = [min, max];
const angularRange = Math.abs((props.startAngle || 0) - (props.endAngle || 360));
return props.polar && axis === "x" && angularRange === 360 ?
this.getSymmetricDomain(domain, allData) : domain;
},

getSinglePointDomain(val) {
const verySmallNumber = 1 / Number.MAX_SAFE_INTEGER;
const adjustedMin = val instanceof Date ? new Date(val - 1) : val - verySmallNumber;
const adjustedMax = val instanceof Date ? new Date(val + 1) : val + verySmallNumber;
return [adjustedMin, adjustedMax];
},

getSymmetricDomain(domain, data) {
const processedData = sortedUniq(data.sort((a, b) => a - b));
const step = processedData[1] - processedData[0];
Expand Down Expand Up @@ -214,11 +219,8 @@ export default {
// use greatest min / max
const domainMin = cumulativeMin < 0 ? cumulativeMin : Collection.getMinValue(globalDomain);
const domainMax = Collection.getMaxValue(globalDomain, ...cumulativeMaxArray);
// TODO: is this the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (domainMin === domainMax) {
const adjustedMax = domainMax === 0 ? 1 : domainMax;
return [0, adjustedMax];
return this.getSinglePointDomain(domainMax);
}
return [domainMin, domainMax];
},
Expand Down

0 comments on commit f088cfd

Please sign in to comment.