From 4df442b55ebb63e6a2171939af6000f7622337d5 Mon Sep 17 00:00:00 2001 From: Makeen Sabree Date: Tue, 7 Nov 2023 13:55:48 -0500 Subject: [PATCH 1/5] fix: allow empty tick values --- demo/ts/components/victory-axis-demo.tsx | 8 ++++++++ packages/victory-core/src/victory-util/axis.tsx | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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-core/src/victory-util/axis.tsx b/packages/victory-core/src/victory-util/axis.tsx index d79111229..993b4051f 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,7 @@ 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; } From 639cd95d5eb821c9d5bda5774acf41773b90228f Mon Sep 17 00:00:00 2001 From: Makeen Sabree Date: Tue, 7 Nov 2023 14:51:47 -0500 Subject: [PATCH 2/5] chore: format with prettier --- packages/victory-core/src/victory-util/axis.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/victory-core/src/victory-util/axis.tsx b/packages/victory-core/src/victory-util/axis.tsx index 993b4051f..9b47978bb 100644 --- a/packages/victory-core/src/victory-util/axis.tsx +++ b/packages/victory-core/src/victory-util/axis.tsx @@ -182,7 +182,7 @@ function getStringTicks(props) { function getTickArray(props) { const { tickValues, tickFormat } = props; - if(tickValues?.length === 0){ + if (tickValues?.length === 0) { return []; } @@ -282,8 +282,8 @@ export function getTicks(props, scale: D3Scale, filterZero = false) { const { tickCount } = props; const tickArray = getTickArray(props); - if(tickArray?.length === 0){ - return ['']; + if (tickArray?.length === 0) { + return [""]; } const tickValues = tickArray ? tickArray.map((v) => v.value) : undefined; @@ -317,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?.length !== 0 ? tickArray.map((v) => v.value) : undefined; + const tickValues = + tickArray && tickArray?.length !== 0 + ? tickArray.map((v) => v.value) + : undefined; if (!Array.isArray(tickValues)) { return undefined; } From c0d20271f47e0b5d88034f8b3f07a7c14fa7496f Mon Sep 17 00:00:00 2001 From: Makeen Sabree Date: Tue, 7 Nov 2023 16:14:39 -0500 Subject: [PATCH 3/5] fix: fix type check --- packages/victory-axis/src/helper-methods.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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( From 1bbdfe2f9ad807939b5638e00e2d3fdf5edecf7d Mon Sep 17 00:00:00 2001 From: Makeen Sabree Date: Sun, 12 Nov 2023 11:56:49 -0500 Subject: [PATCH 4/5] chore: update storybook to include example --- stories/victory-axis.stories.js | 7 +++++++ 1 file changed, 7 insertions(+) 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 = () => { + + + ); }; From ed4b2fafc736bae5d2d2501c011b3b553a506b47 Mon Sep 17 00:00:00 2001 From: Makeen Sabree Date: Wed, 15 Nov 2023 09:34:52 -0500 Subject: [PATCH 5/5] Adding changelog --- packages/victory-axis/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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