Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Data from Domain #1827

Merged
merged 39 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bbbfdbf
use minDomain to restrict _x/_y/_y0/_y1 values for VictoryBar
jhumbug Apr 22, 2021
91d9a95
use absolute value when comparing minY/minX to x/y values
jhumbug Apr 22, 2021
831d798
added _x1 in case it exists
jhumbug Apr 22, 2021
4eb0046
clean up
jhumbug Apr 22, 2021
9c36284
revert bar specific min/max domain editing
jhumbug Apr 23, 2021
328f8b6
first pass global format data from domain in data util
jhumbug Apr 23, 2021
49e69a4
clean up
jhumbug Apr 23, 2021
a24b4c6
updates to getting domain
jhumbug Apr 26, 2021
78f223a
cleanup
jhumbug Apr 26, 2021
7e8cffd
don't allow chart types with interpolation (line and area) to unset p…
jhumbug Apr 26, 2021
0a477a2
null points instead of undefined
jhumbug Apr 26, 2021
f2b6a89
added formatDataFromDomain to candlestick helper methods for dealing …
jhumbug Apr 27, 2021
af1da23
clean up candlestick helper
jhumbug Apr 27, 2021
2765212
added formatDataFromDomain to errorbar helper methods for formatting …
jhumbug Apr 27, 2021
26d8267
filter out out of bounds points in box plot
jhumbug Apr 27, 2021
2e78b62
clean up data util
jhumbug Apr 27, 2021
824d30a
linter cleanup
jhumbug Apr 27, 2021
3f6aa27
use _min/_max for box plot domain points filter
jhumbug Apr 27, 2021
7914e44
filter nulled x/y value datasets in VictoryStack to prevent errors
jhumbug Apr 29, 2021
dae5ebe
exit format data from domain if .x or .y doesn't exist
jhumbug Apr 29, 2021
509bd15
don't alter candlestick data points unless entire dataset is outside …
jhumbug Apr 29, 2021
81dcb6c
if domain x/y isn't defined, get it from the props if able
jhumbug Apr 29, 2021
91507fb
linter fix
jhumbug Apr 29, 2021
9788cda
no min or max domains are available, return dataset without altering
jhumbug Apr 30, 2021
3a213b8
clean up, only clamp baselines, null _x/_y values
jhumbug Apr 30, 2021
8598561
don't use abs val when determining to null value
jhumbug Apr 30, 2021
c4132a0
move my formatDataFromDomain call to getData to ensure the chart type…
jhumbug Apr 30, 2021
e957614
deal with _x outside domain in candlestick
jhumbug Apr 30, 2021
f2b26df
fix value assignment and remove array value check
jhumbug Apr 30, 2021
259c1d9
refactor box plot if statements
jhumbug Apr 30, 2021
eb6a8e9
simply _x check on candlestick
jhumbug Apr 30, 2021
8d6c314
refactor formatDataFromDomain
jhumbug Apr 30, 2021
9894742
combined an if statement
jhumbug Apr 30, 2021
ff6754b
force animations to complete before starting new ones
boygirl May 3, 2021
3a902a1
filter on x outside of domain in box plot
jhumbug May 3, 2021
681b396
moved formatDomainFromData call into individual chart types as needed
jhumbug May 4, 2021
fd2a400
added domain specific stories to various chart types
jhumbug May 4, 2021
2d30a53
filter out undefined values before assigning altered data points back…
jhumbug May 4, 2021
3a74b05
null voronoi data points outside of domain
jhumbug May 4, 2021
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
12 changes: 12 additions & 0 deletions packages/victory-box-plot/src/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,20 @@ const getBaseProps = (props, fallbackProps) => {
}
};
const boxScale = scale.y;
const [minDomainY, maxDomainY] = domain.y;
return data.reduce((acc, datum, index) => {
const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;

// if all y points are out of bound of the domain, filter out this datum
const { _min, _max } = datum;
const underMin = (val) => val < minDomainY;
jhumbug marked this conversation as resolved.
Show resolved Hide resolved
const overMax = (val) => val > maxDomainY;
const exists = (val) => val !== undefined;
let yOutOfBounds;
if (exists(_min) && exists(_max) && underMin(_min) && underMin(_max)) yOutOfBounds = true;
if (exists(_min) && exists(_max) && overMax(_min) && overMax(_max)) yOutOfBounds = true;
if (yOutOfBounds) return acc;

const positions = {
x: horizontal ? scale.y(datum._y) : scale.x(datum._x),
y: horizontal ? scale.x(datum._x) : scale.y(datum._y),
Expand Down
27 changes: 23 additions & 4 deletions packages/victory-candlestick/src/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ const getStyles = (props, style, defaultStyles = {}) => {
};
};

// This method will edit or remove candlestick data points that fall outside of the desired domain
// eslint-disable-next-line complexity
const formatDataFromDomain = (datum, domainY) => {
const [minDomainY, maxDomainY] = domainY;
let { _low, _open, _close, _high } = datum;

// if all values fall outside of domain, null the data point
if (_low < minDomainY && _open < minDomainY && _close < minDomainY && _high < minDomainY)
_low = _open = _close = _high = null;
if (_low > maxDomainY && _open > maxDomainY && _close > maxDomainY && _high > maxDomainY)
_low = _open = _close = _high = null;

return Object.assign({}, datum, { _low, _open, _close, _high });
};

const getCalculatedValues = (props) => {
const { polar } = props;
const defaultStyle = Helpers.getDefaultStyles(props, "candlestick");
Expand Down Expand Up @@ -321,13 +336,17 @@ const getBaseProps = (props, fallbackProps) => {
}
};

// eslint-disable-next-line complexity
return data.reduce((childProps, datum, index) => {
const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;
const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
const high = scale.y(datum._high);
const close = scale.y(datum._close);
const open = scale.y(datum._open);
const low = scale.y(datum._low);
datum = formatDataFromDomain(datum, domain.y);
const { _low, _open, _close, _high } = datum;
const high = scale.y(_high);
const close = scale.y(_close);
const open = scale.y(_open);
const low = scale.y(_low);

const dataStyle = getDataStyles(datum, style.data, props);
const dataProps = {
x,
Expand Down
62 changes: 61 additions & 1 deletion packages/victory-core/src/victory-util/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
includes
} from "lodash";
import Helpers from "./helpers";
import Domain from "./domain";
import Collection from "./collection";
import Scale from "./scale";
import Immutable from "./immutable";
Expand Down Expand Up @@ -91,6 +92,64 @@ function cleanData(dataset, props) {
});
}

// This method will remove data points that fall outside of the desired domain (non-continuous charts only)
function formatDataFromDomain(dataset, props) {
// domain for checking data points that are outside of the bounds
// symbol to determine chart types with a single y value point
// interpolation for determining chart types with continuous data points that shouldn't be altered
// errorX/Y for determining chart types with error whiskers that shouldn't be altered here
const { domain, symbol, interpolation, errorX, errorY } = props;
jhumbug marked this conversation as resolved.
Show resolved Hide resolved

if (interpolation || errorX || errorY) return dataset;

const minDomainX =
!domain || !domain.x ? Domain.getMinFromProps(props, "x") : Collection.getMinValue(domain.x);
const maxDomainX =
!domain || !domain.x ? Domain.getMaxFromProps(props, "x") : Collection.getMaxValue(domain.x);
const minDomainY =
!domain || !domain.y ? Domain.getMinFromProps(props, "y") : Collection.getMinValue(domain.y);
const maxDomainY =
!domain || !domain.y ? Domain.getMaxFromProps(props, "y") : Collection.getMaxValue(domain.y);

jhumbug marked this conversation as resolved.
Show resolved Hide resolved
const exists = (val) => val !== undefined;

// eslint-disable-next-line complexity
return dataset.map((datum) => {
let { _x, _y, _y0, _y1 } = datum;

// don't alter data points if _y is an array of values
if (Array.isArray(_y)) return datum;

// single x point less than min domain
if (exists(_x) && _x < minDomainX) _x = null;
jhumbug marked this conversation as resolved.
Show resolved Hide resolved
// single x point greater than max domain
if (exists(_x) && _x > maxDomainX) _x = null;

// single y point less than min domain
if (exists(_y) && !exists(_y0) && _y < minDomainY) {
if (exists(symbol)) _y = null;
jhumbug marked this conversation as resolved.
Show resolved Hide resolved
else _y = minDomainY;
}
// single y point greater than max domain
if (exists(_y) && !exists(_y0) && _y > maxDomainY) {
if (exists(symbol)) _y = null;
else _y = maxDomainY;
jhumbug marked this conversation as resolved.
Show resolved Hide resolved
}

// multiple y points all less than min domain
if (exists(_y0) && exists(_y1) && _y0 < minDomainY && _y1 < minDomainY) _y = _y0 = _y1 = null;
// multiple y points all greather than max domain
if (exists(_y0) && exists(_y1) && _y0 > maxDomainY && _y1 > maxDomainY) _y = _y0 = _y1 = null;

// multiple y points with lower point only below min
if (exists(_y0) && exists(_y1) && _y0 < minDomainY && _y1 >= minDomainY) _y0 = minDomainY;
// multiple y points with upper point only above max
if (exists(_y0) && exists(_y1) && _y0 <= maxDomainY && _y1 > maxDomainY) _y1 = maxDomainY;

return assign({}, datum, { _x, _y, _y0, _y1 });
});
}

// Returns a data accessor given an eventKey prop
function getEventKey(key) {
// creates a data accessor function
Expand Down Expand Up @@ -236,7 +295,8 @@ function formatData(dataset, props, expectedKeys) {

const sortedData = sortData(data, props.sortKey, props.sortOrder);
const cleanedData = cleanData(sortedData, props);
return addEventKeys(props, cleanedData);
const domainFormattedData = formatDataFromDomain(cleanedData, props);
return addEventKeys(props, domainFormattedData);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/victory-errorbar/src/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ const getDomain = (props, axis) => {
return Domain.createDomainFunction(getDomainFromData)(props, axis);
};

// This method will edit or remove errorbar data points that fall outside of the desired domain
const formatDataFromDomain = (datum, domain) => {
const [minDomainX, maxDomainX] = domain.x;
const [minDomainY, maxDomainY] = domain.y;

let { _x, _y } = datum;

// if either x or y center point is outside of the domain, null the entire data point
if (_x < minDomainX || _x > maxDomainX || _y < minDomainY || _y > maxDomainY) _x = _y = null;

return Object.assign({}, datum, { _x, _y });
};

const getCalculatedValues = (props) => {
const defaultStyles = Helpers.getDefaultStyles(props, "errorbar");
const style = Helpers.getStyles(props.style, defaultStyles) || {};
Expand Down Expand Up @@ -169,6 +182,7 @@ const getBaseProps = (props, fallbackProps) => {
return data.reduce((childProps, datum, index) => {
const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;
const { x, y } = Helpers.scalePoint(assign({}, props, { scale }), datum);
datum = formatDataFromDomain(datum, domain);
const errorX = getErrors(props, datum, "x");
const errorY = getErrors(props, datum, "y");
const dataProps = {
Expand Down
5 changes: 4 additions & 1 deletion packages/victory-stack/src/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ function addLayoutData(props, datasets, index) {

function stackData(props, childComponents) {
const dataFromChildren = Wrapper.getDataFromChildren(props, childComponents);
const datasets = fillData(props, dataFromChildren);
const filterNullChildData = dataFromChildren.map((dataset) =>
dataset.filter((datum) => datum._x !== null && datum._y !== null)
);
const datasets = fillData(props, filterNullChildData);
return datasets.map((d, i) => addLayoutData(props, datasets, i));
}

Expand Down