diff --git a/.changeset/spotty-moons-enjoy.md b/.changeset/spotty-moons-enjoy.md
new file mode 100644
index 000000000..67ffee6d8
--- /dev/null
+++ b/.changeset/spotty-moons-enjoy.md
@@ -0,0 +1,5 @@
+---
+"victory-core": patch
+---
+
+fix categories array of strings
diff --git a/packages/victory-core/src/exports.test.ts b/packages/victory-core/src/exports.test.ts
index 4937f167c..a50f5c7a0 100644
--- a/packages/victory-core/src/exports.test.ts
+++ b/packages/victory-core/src/exports.test.ts
@@ -426,8 +426,8 @@ describe("victory-core", () => {
"getDomain": [Function],
"getDomainFromChildren": [Function],
"getScale": [Function],
- "getStringsFromCategories": [Function],
"getStringsFromChildren": [Function],
+ "getStringsFromChildrenCategories": [Function],
"getStringsFromData": [Function],
"getStyle": [Function],
"getWidth": [Function],
diff --git a/packages/victory-core/src/victory-util/wrapper.test.tsx b/packages/victory-core/src/victory-util/wrapper.test.tsx
index 1f6b2035e..c9c8d57ff 100644
--- a/packages/victory-core/src/victory-util/wrapper.test.tsx
+++ b/packages/victory-core/src/victory-util/wrapper.test.tsx
@@ -84,4 +84,59 @@ describe("helpers/wrapper", () => {
expect(Wrapper.getStringsFromData([])).toEqual({ x: [], y: [] });
});
});
+
+ describe("getStringsFromCategories", () => {
+ it("gets string from all options", () => {
+ expect(Wrapper.getStringsFromChildrenCategories([], "x")).toEqual([]);
+ expect(
+ Wrapper.getStringsFromChildrenCategories(
+ [],
+ "x",
+ ),
+ ).toEqual(["one", "two", "three"]);
+ expect(
+ Wrapper.getStringsFromChildrenCategories(
+ [],
+ "y",
+ ),
+ ).toEqual(["one", "two", "three"]);
+ expect(
+ Wrapper.getStringsFromChildrenCategories(
+ [
+ ,
+ ],
+ "x",
+ ),
+ ).toEqual(["one", "two", "three"]);
+ expect(
+ Wrapper.getStringsFromChildrenCategories(
+ [
+ ,
+ ,
+ ],
+ "x",
+ ),
+ ).toEqual(["one", "two", "three", "four", "five", "six"]);
+ expect(
+ Wrapper.getStringsFromChildrenCategories(
+ [
+ ,
+ ],
+ "x",
+ ),
+ ).toEqual([]);
+ });
+ });
});
diff --git a/packages/victory-core/src/victory-util/wrapper.tsx b/packages/victory-core/src/victory-util/wrapper.tsx
index 790af7abe..79520fae4 100644
--- a/packages/victory-core/src/victory-util/wrapper.tsx
+++ b/packages/victory-core/src/victory-util/wrapper.tsx
@@ -356,19 +356,13 @@ export function getChildStyle(child, index, calculatedProps, theme) {
};
}
-export function getStringsFromCategories(childComponents, axis) {
+export function getStringsFromChildrenCategories(childComponents, axis) {
const iteratee = (child) => {
- const childProps = child.props || {};
- if (!Domain.isDomainComponent(child) || !childProps.categories) {
+ if (!Domain.isDomainComponent(child)) {
return null;
}
- const categories =
- childProps.categories && !Array.isArray(childProps.categories)
- ? childProps.categories[axis]
- : childProps.props.categories;
- const categoryStrings =
- categories && categories.filter((val) => typeof val === "string");
- return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
+ const childProps = child.props || {};
+ return Data.getStringsFromCategories(childProps, axis);
};
return Helpers.reduceChildren(childComponents.slice(0), iteratee);
}
@@ -417,15 +411,14 @@ export function getCategoryAndAxisStringsFromChildren(
axis,
childComponents,
) {
- const categories = isPlainObject(props.categories)
- ? props.categories[axis]
- : props.categories;
+ const categories = Data.getStringsFromCategories(props, axis);
const axisComponent = Axis.getAxisComponent(childComponents, axis);
const axisStrings = axisComponent
? Data.getStringsFromAxes(axisComponent.props, axis)
: [];
- const categoryStrings =
- categories || getStringsFromCategories(childComponents, axis);
+ const categoryStrings = categories.length
+ ? categories
+ : getStringsFromChildrenCategories(childComponents, axis);
return uniq([...categoryStrings, ...axisStrings].flat());
}
@@ -445,15 +438,9 @@ export function getStringsFromChildren(props, childComponents) {
export function getCategories(props, childComponents, allStrings?) {
const xPropCategories =
- props.categories && !Array.isArray(props.categories)
- ? props.categories.x
- : props.categories;
-
+ props.categories && Data.getStringsFromCategories(props, "x");
const yPropCategories =
- props.categories && !Array.isArray(props.categories)
- ? props.categories.y
- : props.categories;
-
+ props.categories && Data.getStringsFromCategories(props, "y");
const fallbackRequired = !xPropCategories || !yPropCategories;
const fallbackProps = fallbackRequired