Skip to content

Commit

Permalink
Merge pull request #2379 from FormidableLabs/ts-migrate/victory-axis
Browse files Browse the repository at this point in the history
TS migrate: victory-axis
  • Loading branch information
ramenhog authored Jul 25, 2022
2 parents ee5ad80 + b819b45 commit a311c29
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 48 deletions.
8 changes: 8 additions & 0 deletions packages/victory-axis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"peerDependencies": {
"react": ">=16.6.0"
},
"devDependencies": {
"victory-axis": "*",
"victory-chart": "*"
},
"scripts": {
"### THESE SCRIPTS ARE GENERATED ###": "true",
"### DO NOT MODIFY THESE MANUALLY ###": "true",
Expand Down Expand Up @@ -151,6 +155,7 @@
"dependencies": [
"types:create",
"../victory-core:types:create",
"../victory-chart:types:create",
"../victory-vendor:types:create",
"../victory-voronoi:types:create"
],
Expand Down Expand Up @@ -203,6 +208,7 @@
"output": [],
"dependencies": [
"../victory-core:types:create",
"../victory-chart:types:create",
"../victory-vendor:types:create",
"../victory-voronoi:types:create"
],
Expand Down Expand Up @@ -233,6 +239,7 @@
"output": [],
"dependencies": [
"../victory-core:types:create",
"../victory-chart:types:create",
"../victory-vendor:types:create",
"../victory-voronoi:types:create"
],
Expand All @@ -251,6 +258,7 @@
"output": [],
"dependencies": [
"build:lib:cjs",
"../victory-chart:build:lib:cjs",
"../victory-vendor:build:lib:cjs",
"../victory-voronoi:build:lib:cjs"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getStyleObject = (props) => {
: specificAxisStyle || generalAxisStyle;
};

export const getStyles = (props, styleObject) => {
export const getStyles = (props, styleObject?) => {
const style = props.style || {};
styleObject = styleObject || {};
const parentStyleProps = { height: "100%", width: "100%" };
Expand Down Expand Up @@ -552,7 +552,6 @@ export const getBaseProps = (props, fallbackProps) => {
anchors,
domain,
stringTicks,
name,
} = calculatedValues;
const otherAxis = axis === "x" ? "y" : "x";
const { width, height, standalone, theme, polar, padding, horizontal } =
Expand Down Expand Up @@ -585,7 +584,6 @@ export const getBaseProps = (props, fallbackProps) => {
height,
padding,
domain,
name,
},
sharedProps,
),
Expand All @@ -608,7 +606,7 @@ export const getBaseProps = (props, fallbackProps) => {
const tickLayout = {
position: getTickPosition(styles, orientation, isVertical),
transform: getTickTransform(
scale[axis](tickValue),
scale[axis]?.(tickValue),
globalTransform,
isVertical,
),
Expand All @@ -619,9 +617,9 @@ export const getBaseProps = (props, fallbackProps) => {
transform: {
x: isVertical
? -gridOffset.x + globalTransform.x
: scale[axis](tickValue) + globalTransform.x,
: scale[axis]?.(tickValue) + globalTransform.x,
y: isVertical
? scale[axis](tickValue) + globalTransform.y
? scale[axis]?.(tickValue) + globalTransform.y
: gridOffset.y + globalTransform.y,
},
};
Expand Down
37 changes: 0 additions & 37 deletions packages/victory-axis/src/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/victory-axis/src/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/victory-axis/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./victory-axis";
20 changes: 20 additions & 0 deletions packages/victory-axis/src/victory-axis.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";
import { VictoryAxis } from "victory-axis";
import { VictoryChart } from "victory-chart";
import { render, screen } from "@testing-library/react";

describe("components/victory-axis", () => {
it("should render two axes by default", () => {
const chartProps = {
defaultAxes: {
independent: <VictoryAxis data-testid="axis" />,
dependent: <VictoryAxis data-testid="axis" dependentAxis />,
},
};
render(<VictoryChart {...chartProps} />);

const axes = screen.getAllByTestId("axis");

expect(axes).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import {
addEvents,
Axis,
UserProps,
DomainPropType,
EventPropTypeInterface,
OrientationTypes,
VictoryAxisCommonProps,
VictoryCommonProps,
VictorySingleLabelableProps,
EventsMixinClass,
} from "victory-core";
import { getBaseProps, getStyles } from "./helper-methods";

Expand All @@ -32,7 +39,31 @@ const options = {
],
};

class VictoryAxis extends React.Component {
export type VictoryAxisTTargetType =
| "axis"
| "axisLabel"
| "grid"
| "ticks"
| "tickLabels"
| "parent";

export interface VictoryAxisProps
extends VictoryAxisCommonProps,
VictoryCommonProps,
VictorySingleLabelableProps {
crossAxis?: boolean;
domain?: DomainPropType;
events?: EventPropTypeInterface<VictoryAxisTTargetType, number | string>[];
fixLabelOverlap?: boolean;
offsetX?: number;
offsetY?: number;
orientation?: OrientationTypes;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface VictoryAxisBase extends EventsMixinClass<VictoryAxisProps> {}

class VictoryAxisBase extends React.Component<VictoryAxisProps> {
static animationWhitelist = [
"style",
"domain",
Expand Down Expand Up @@ -143,7 +174,7 @@ class VictoryAxis extends React.Component {

static getDomain = Axis.getDomain;
static getAxis = Axis.getAxis;
static getStyles = (props) => getStyles(props, fallbackProps.style);
static getStyles = (props) => getStyles(props);
static getBaseProps = (props) => getBaseProps(props, fallbackProps);
static expectedComponents = [
"axisComponent",
Expand Down Expand Up @@ -291,4 +322,4 @@ class VictoryAxis extends React.Component {
}
}

export default addEvents(VictoryAxis, options);
export const VictoryAxis = addEvents(VictoryAxisBase, options);
8 changes: 7 additions & 1 deletion packages/victory-core/src/victory-util/add-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const defaultComponents: NonNullable<MixinOptions["components"]> = [
export type MixinOptions = {
components?: Array<{
name: string;
index?: string;
index?: string | number;
}>;
};

Expand All @@ -64,6 +64,12 @@ export interface EventsMixinClass<TProps> {
getEventState: typeof Events.getEventState;
renderContinuousData(props: TProps);
animateComponent(props: TProps, defaultAnimationWhitelist);
getComponentProps(
component: React.ReactElement,
type: string,
index: number,
): TProps;
dataKeys: string[];
}

/**
Expand Down
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a311c29

Please sign in to comment.