Skip to content

Commit

Permalink
refactor: only grab dependent axis when array is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
nlkluth committed Oct 15, 2024
1 parent 7866e09 commit 13881ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/victory-core/src/victory-util/wrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ describe("helpers/wrapper", () => {
"x",
),
).toEqual(["one", "two", "three"]);
expect(
Wrapper.getStringsFromCategories(
[<MockVictoryLine categories={["one", "z", "three"]} key="1" />],
"y",
),
).toEqual([]);
expect(
Wrapper.getStringsFromCategories(
[
Expand Down
9 changes: 7 additions & 2 deletions packages/victory-core/src/victory-util/wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ export function getChildStyle(child, index, calculatedProps, theme) {
};
}

function getDependentAxisCategories(categories: string[], axis: "x" | "y") {
const dependentAxis = "x";
return axis === dependentAxis ? categories : [];
}

export function getStringsFromCategories(childComponents, axis) {
const iteratee = (child) => {
const childProps = child.props || {};
Expand All @@ -365,7 +370,7 @@ export function getStringsFromCategories(childComponents, axis) {
const categories =
childProps.categories && !Array.isArray(childProps.categories)
? childProps.categories[axis]
: childProps.categories;
: getDependentAxisCategories(childProps.categories, axis);
const categoryStrings =
categories && categories.filter((val) => typeof val === "string");
return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
Expand Down Expand Up @@ -419,7 +424,7 @@ export function getCategoryAndAxisStringsFromChildren(
) {
const categories = isPlainObject(props.categories)
? props.categories[axis]
: props.categories;
: getDependentAxisCategories(props.categories, axis);
const axisComponent = Axis.getAxisComponent(childComponents, axis);
const axisStrings = axisComponent
? Data.getStringsFromAxes(axisComponent.props, axis)
Expand Down

0 comments on commit 13881ef

Please sign in to comment.