diff --git a/demo/ts/components/victory-axis-demo.tsx b/demo/ts/components/victory-axis-demo.tsx index 03d1a13cc..123ffcf30 100644 --- a/demo/ts/components/victory-axis-demo.tsx +++ b/demo/ts/components/victory-axis-demo.tsx @@ -269,6 +269,14 @@ export default class VictoryAxisDemo extends React.Component< "Mariners\nSEA", ]} /> + + ); diff --git a/packages/victory-axis/CHANGELOG.md b/packages/victory-axis/CHANGELOG.md index 05c15f0c0..2e3596c40 100644 --- a/packages/victory-axis/CHANGELOG.md +++ b/packages/victory-axis/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-axis +## 36.6.13 + ## 36.6.12 ## 36.6.11 diff --git a/packages/victory-axis/src/helper-methods.tsx b/packages/victory-axis/src/helper-methods.tsx index 03f4838c0..6821fce11 100644 --- a/packages/victory-axis/src/helper-methods.tsx +++ b/packages/victory-axis/src/helper-methods.tsx @@ -595,7 +595,8 @@ export const getBaseProps = (props, fallbackProps) => { ? { [otherAxis]: props.scale[otherAxis] } : undefined, }; - return ticks.reduce((childProps, tickValue, index) => { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + return (ticks as number[]).reduce((childProps, tickValue, index) => { const tick = stringTicks ? stringTicks[index] : tickValue; const text = tickFormat(tickValue, index, ticks); const styles = getEvaluatedStyles( diff --git a/packages/victory-core/src/victory-util/axis.tsx b/packages/victory-core/src/victory-util/axis.tsx index d79111229..9b47978bb 100644 --- a/packages/victory-core/src/victory-util/axis.tsx +++ b/packages/victory-core/src/victory-util/axis.tsx @@ -181,6 +181,11 @@ function getStringTicks(props) { function getTickArray(props) { const { tickValues, tickFormat } = props; + + if (tickValues?.length === 0) { + return []; + } + const axis = getAxis(props); const stringMap = props.stringMap && props.stringMap[axis]; const getTicksFromFormat = () => { @@ -276,6 +281,11 @@ function downsampleTicks(ticks: number[], tickCount: number) { export function getTicks(props, scale: D3Scale, filterZero = false) { const { tickCount } = props; const tickArray = getTickArray(props); + + if (tickArray?.length === 0) { + return [""]; + } + const tickValues = tickArray ? tickArray.map((v) => v.value) : undefined; if (tickValues) { return downsampleTicks(tickValues, tickCount); @@ -307,7 +317,10 @@ export function getTicks(props, scale: D3Scale, filterZero = false) { function getDomainFromData(props, axis) { const { polar, startAngle = 0, endAngle = 360 } = props; const tickArray = getTickArray(props); - const tickValues = tickArray ? tickArray.map((v) => v.value) : undefined; + const tickValues = + tickArray && tickArray?.length !== 0 + ? tickArray.map((v) => v.value) + : undefined; if (!Array.isArray(tickValues)) { return undefined; } diff --git a/stories/victory-axis.stories.js b/stories/victory-axis.stories.js index d6d5a696f..5a4c3b812 100644 --- a/stories/victory-axis.stories.js +++ b/stories/victory-axis.stories.js @@ -133,6 +133,13 @@ export const TickValues = () => { + + + ); };