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

Clean domain method #317

Merged
merged 17 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/components/victory-area-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default class App extends React.Component {
style={style} animate={{duration: 1000}}
data={this.state.areaTransitionData}
theme={VictoryTheme.material}
domainPadding={100}
containerComponent={
<VictoryContainer
title="Area Chart"
Expand Down Expand Up @@ -271,6 +270,7 @@ export default class App extends React.Component {
<VictoryChart
style={style}
theme={VictoryTheme.material}
scale={{x: "linear", y: "log"}}
>
<VictoryArea
style={style} animate={{duration: 1000}}
Expand Down
5 changes: 4 additions & 1 deletion demo/components/victory-line-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ export default class App extends React.Component {
]}
/>

<VictoryChart
scale={{x: "linear", y: "log"}}
>
<VictoryLine
style={{parent: parentStyle}}
scale={{x: "linear", y: "log"}}
/>
</VictoryChart>

<VictoryLine
style={{parent: parentStyle}}
Expand Down
3 changes: 2 additions & 1 deletion src/components/victory-axis/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default {
} else if (props.tickValues) {
domain = Domain.getDomainFromTickValues(props);
}
return domain ? Domain.padDomain(domain, props, inherentAxis) : undefined;
const paddedDomain = Domain.padDomain(domain, props, inherentAxis);
return domain ? Domain.cleanDomain(paddedDomain, props) : undefined;
},

// exposed for use by VictoryChart
Expand Down
2 changes: 1 addition & 1 deletion src/components/victory-candlestick/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default {
}
domain = [min, max];
}
return Domain.padDomain(domain, props, axis);
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
},

isTransparent(attr) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/victory-errorbar/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default {
}
const dataset = this.getErrorData(props);
const domain = this.getDomainFromData(props, axis, dataset);
return Domain.padDomain(domain, props, axis);
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
},

getDomainFromData(props, axis, dataset) {
Expand Down
28 changes: 26 additions & 2 deletions src/helpers/domain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { flatten, includes, isPlainObject } from "lodash";
import Data from "./data";
import Axis from "./axis";
import Scale from "./scale";
import { Helpers, Collection } from "victory-core";

export default {
Expand All @@ -15,7 +16,30 @@ export default {
}
const dataset = Data.getData(props);
const domain = this.getDomainFromData(props, axis, dataset);
return this.padDomain(domain, props, axis);
return this.cleanDomain(this.padDomain(domain, props, axis), props);
},

cleanDomain(domain, props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify this method if you add an axis argument

// Some scale types break when certain data is supplies. This method will
// remove data points that break scales. So far this method only removes
// zeroes for log scales
// TODO other cases?
const scaleType = {
x: Scale.getScaleType(props, "x"),
y: Scale.getScaleType(props, "y")
};

if (scaleType.x !== "log" && scaleType.y !== "log") {
return domain;
}

const rules = (dom, axis) => {
const domainOne = dom[0] === 0 ? 1 / Number.MAX_SAFE_INTEGER : dom[0];
const domainTwo = dom[1] === 0 ? -Math.abs(1 / Number.MAX_SAFE_INTEGER) : dom[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful with the logic around having one of these be negative and the other positive. The domain is not always [min, max]

return scaleType[axis] === "log" ? [domainOne, domainTwo] : dom;
};

return rules(domain, "x") && rules(domain, "y");
},

getDomainWithZero(props, axis) {
Expand All @@ -36,7 +60,7 @@ export default {
}
const dataset = Data.getData(props);
const domain = ensureZero(this.getDomainFromData(props, axis, dataset));
return this.padDomain(domain, props, axis);
return this.cleanDomain(this.padDomain(domain, props, axis), props);
},

getDomainFromProps(props, axis) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
return propsDomain;
}
childComponents = childComponents || React.Children.toArray(props.children);
return this.getDomainFromChildren(props, axis, childComponents);
return Domain.cleanDomain(this.getDomainFromChildren(props, axis, childComponents), props);
},

setAnimationState(nextProps) {
Expand Down