Skip to content

Commit fbd1155

Browse files
authored
Merge pull request #1564 from FormidableLabs/bug/domain-padding
Bug/domain padding
2 parents 532e093 + 4929ea3 commit fbd1155

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

packages/victory-bar/src/helper-methods.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const getCalculatedValues = (props) => {
3030
y: Helpers.getRange(props, "y")
3131
};
3232
const domain = {
33-
x: Domain.getDomainFromProps(props, "x") || Domain.getDomainWithZero(props, "x"),
34-
y: Domain.getDomainFromProps(props, "y") || Domain.getDomainWithZero(props, "y")
33+
x: Domain.getDomainWithZero(props, "x"),
34+
y: Domain.getDomainWithZero(props, "y")
3535
};
3636
const scale = {
3737
x: Scale.getBaseScale(props, "x")

packages/victory-core/src/victory-util/domain.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable func-style */
22
/* eslint-disable no-use-before-define */
33
import React from "react";
4-
import { flatten, isPlainObject, sortedUniq, isFunction, includes } from "lodash";
4+
import { flatten, isPlainObject, sortedUniq, isFunction, includes, isDate } from "lodash";
55
import Data from "./data";
66
import Scale from "./scale";
77
import Helpers from "./helpers";
@@ -320,26 +320,30 @@ function getDomainWithZero(props, axis) {
320320
* Returns the maxDomain from props if it exists
321321
* @param {Object} props: the props object
322322
* @param {String} axis: the current axis
323-
* @returns {Number|undefined} the maxDomain based on props
323+
* @returns {Number|Date|undefined} the maxDomain based on props
324324
*/
325325
function getMaxFromProps(props, axis) {
326326
if (isPlainObject(props.maxDomain) && props.maxDomain[axis] !== undefined) {
327327
return props.maxDomain[axis];
328328
}
329-
return typeof props.maxDomain === "number" ? props.maxDomain : undefined;
329+
return typeof props.maxDomain === "number" || isDate(props.maxDomain)
330+
? props.maxDomain
331+
: undefined;
330332
}
331333

332334
/**
333335
* Returns the minDomain from props if it exists
334336
* @param {Object} props: the props object
335337
* @param {String} axis: the current axis
336-
* @returns {Number|undefined} the minDomain based on props
338+
* @returns {Number|Date|undefined} the minDomain based on props
337339
*/
338340
function getMinFromProps(props, axis) {
339341
if (isPlainObject(props.minDomain) && props.minDomain[axis] !== undefined) {
340342
return props.minDomain[axis];
341343
}
342-
return typeof props.minDomain === "number" ? props.minDomain : undefined;
344+
return typeof props.minDomain === "number" || isDate(props.minDomain)
345+
? props.minDomain
346+
: undefined;
343347
}
344348

345349
/**

packages/victory-core/src/victory-util/wrapper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export default {
4848
getDomain(props, axis, childComponents) {
4949
childComponents = childComponents || React.Children.toArray(props.children);
5050
const propsDomain = Domain.getDomainFromProps(props, axis);
51-
const minDomain = Domain.getMinFromProps(props, axis);
52-
const maxDomain = Domain.getMaxFromProps(props, axis);
5351
const domainPadding = this.getDefaultDomainPadding(props, axis, childComponents);
5452
let domain;
5553
if (propsDomain) {
5654
domain = propsDomain;
5755
} else {
56+
const minDomain = Domain.getMinFromProps(props, axis);
57+
const maxDomain = Domain.getMaxFromProps(props, axis);
5858
const dataset = (props.data || props.y) && Data.getData(props);
5959
const dataDomain = dataset ? Domain.getDomainFromData(props, axis, dataset) : [];
6060
const childDomain = this.getDomainFromChildren(props, axis, childComponents);

packages/victory-group/src/helper-methods.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable no-use-before-define */
33
import { assign } from "lodash";
44
import React from "react";
5-
import { Helpers, Scale, Data, Domain, Wrapper } from "victory-core";
5+
import { Helpers, Scale, Data, Wrapper } from "victory-core";
66

77
const fallbackProps = {
88
width: 450,
@@ -20,12 +20,8 @@ function getCalculatedProps(props, childComponents) {
2020
const categories = props.categories || Wrapper.getCategories(props, childComponents);
2121
const datasets = props.datasets || Wrapper.getDataFromChildren(props);
2222
const domain = {
23-
x:
24-
Domain.getDomainFromProps(props, "x") ||
25-
Wrapper.getDomain(assign({}, props, { categories }), "x", childComponents),
26-
y:
27-
Domain.getDomainFromProps(props, "y") ||
28-
Wrapper.getDomain(assign({}, props, { categories }), "y", childComponents)
23+
x: Wrapper.getDomain(assign({}, props, { categories }), "x", childComponents),
24+
y: Wrapper.getDomain(assign({}, props, { categories }), "y", childComponents)
2925
};
3026
const range = props.range || {
3127
x: Helpers.getRange(props, "x"),

packages/victory-stack/src/helper-methods.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable no-use-before-define */
33
import { assign, keys, orderBy } from "lodash";
44
import React from "react";
5-
import { Domain, Helpers, Scale, Wrapper } from "victory-core";
5+
import { Helpers, Scale, Wrapper } from "victory-core";
66

77
const fallbackProps = {
88
width: 450,
@@ -117,12 +117,8 @@ function getCalculatedProps(props, childComponents) {
117117
return React.cloneElement(c, { data: datasets[i] });
118118
});
119119
const domain = {
120-
x:
121-
Domain.getDomainFromProps(props, "x") ||
122-
Wrapper.getDomain(assign({}, props, { categories }), "x", children),
123-
y:
124-
Domain.getDomainFromProps(props, "y") ||
125-
Wrapper.getDomain(assign({}, props, { categories }), "y", children)
120+
x: Wrapper.getDomain(assign({}, props, { categories }), "x", children),
121+
y: Wrapper.getDomain(assign({}, props, { categories }), "y", children)
126122
};
127123
const range = props.range || {
128124
x: Helpers.getRange(props, "x"),

0 commit comments

Comments
 (0)