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

Feature/blacklist with regex #1278

Merged
merged 3 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion packages/victory-core/src/victory-util/prop-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/
import { isFunction, find } from "lodash";
import { isFunction, find, isRegExp } from "lodash";
import Log from "./log";
import PropTypes from "prop-types";

Expand Down Expand Up @@ -209,5 +209,15 @@ export default {
return new Error(`Length of data and ${propName} arrays must match.`);
}
return undefined;
}),

/**
* Check that the value is a regular expression
*/
regExp: makeChainable((props, propName, componentName) => {
if (props[propName] && !isRegExp(props[propName])) {
return new Error(`\`${propName}\` in \`${componentName}\` must be a regular expression.`);
}
return undefined;
})
};
2 changes: 1 addition & 1 deletion packages/victory-voronoi-container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ _example:_ `radius={25}`

### voronoiBlacklist

`type: array[string]`
`type: array[string || regex]`

The `voronoiBlacklist` prop is used to specify a list of components to ignore when calculating a shared voronoi diagram. Components with a `name` prop matching an element in the `voronoiBlacklist` array will be ignored by `VictoryVoronoiContainer`. Ignored components will never be flagged as active, and will not contribute date to shared tooltips or labels.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from "prop-types";
import React from "react";
import { defaults, isFunction, pick } from "lodash";
import { VictoryTooltip } from "victory-tooltip";
import { VictoryContainer, Helpers, TextSize } from "victory-core";
import { VictoryContainer, Helpers, TextSize, PropTypes as CustomPropTypes } from "victory-core";
import VoronoiHelpers from "./voronoi-helpers";

export const voronoiContainerMixin = (base) =>
Expand All @@ -18,7 +18,9 @@ export const voronoiContainerMixin = (base) =>
onActivated: PropTypes.func,
onDeactivated: PropTypes.func,
radius: PropTypes.number,
voronoiBlacklist: PropTypes.arrayOf(PropTypes.string),
voronoiBlacklist: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, CustomPropTypes.regExp])
),
voronoiDimension: PropTypes.oneOf(["x", "y"]),
voronoiPadding: PropTypes.number
};
Expand Down
17 changes: 15 additions & 2 deletions packages/victory-voronoi-container/src/voronoi-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Selection, Data, Helpers } from "victory-core";
import { assign, throttle, isFunction, isEmpty, groupBy, keys, includes } from "lodash";
import {
assign,
throttle,
isFunction,
isEmpty,
groupBy,
keys,
includes,
isString,
isRegExp
} from "lodash";
import isEqual from "react-fast-compare";
import { voronoi as d3Voronoi } from "d3-voronoi";
import React from "react";
Expand Down Expand Up @@ -54,7 +64,10 @@ const VoronoiHelpers = {
const childProps = child.props || {};
const name = childProps.name || childName;
const blacklist = props.voronoiBlacklist || [];
if (!Data.isDataComponent(child) || includes(blacklist, name)) {
const blacklistStr = blacklist.filter(isString);
const blacklistRegExp = blacklist.filter(isRegExp);
const isRegExpMatch = blacklistRegExp.some((regExp) => regExp.test(name));
if (!Data.isDataComponent(child) || includes(blacklistStr, name) || isRegExpMatch) {
return null;
}
const getChildData =
Expand Down