Skip to content

Commit

Permalink
fix: allow empty tick values
Browse files Browse the repository at this point in the history
  • Loading branch information
Makeen Sabree committed Nov 7, 2023
1 parent 1b3a66e commit 2620ef7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions demo/ts/components/victory-axis-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ export default class VictoryAxisDemo extends React.Component<
"Mariners\nSEA",
]}
/>

<VictoryAxis
label="Empty Values"
padding={{ top: 40, bottom: 40, left: 40, right: 90 }}
orientation="right"
style={styleOverrides}
tickValues={[]}
/>
</div>
</div>
);
Expand Down
12 changes: 11 additions & 1 deletion packages/victory-core/src/victory-util/axis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 2620ef7

Please sign in to comment.