From d9ece4a8b1a83410ef6a0b297a14ff8b5bc61f80 Mon Sep 17 00:00:00 2001 From: Aike van den Brink <17004429+aikewoody@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:59:12 +0100 Subject: [PATCH 01/29] documentation: fix small grammar mistake (#2503) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23a527242..afc1ace6c 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,6 @@ Please see the [Contributing guide](CONTRIBUTING.md). ## Maintenance Status -**Active:** Formidable is actively working on this project, and we expect to continue for work for the foreseeable future. Bug reports, feature requests and pull requests are welcome. +**Active:** Formidable is actively working on this project, and we expect to continue to work for the foreseeable future. Bug reports, feature requests and pull requests are welcome. [react]: https://facebook.github.io/react/ From 8ce3ef6a3045de2eed45a9e4e6a62021109cd37b Mon Sep 17 00:00:00 2001 From: Gwyneth Rose Date: Mon, 8 Jan 2024 14:16:02 -0700 Subject: [PATCH 02/29] =?UTF-8?q?Fixed=20issue=20where=20VictoryChart=20wo?= =?UTF-8?q?uld=20throw=20an=20unhandled=20exception=20whe=E2=80=A6=20(#253?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: grose --- .changeset/green-parents-argue.md | 6 ++++++ packages/victory-chart/src/helper-methods.tsx | 15 +++++++-------- packages/victory-core/src/victory-util/helpers.ts | 8 +++++--- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 .changeset/green-parents-argue.md diff --git a/.changeset/green-parents-argue.md b/.changeset/green-parents-argue.md new file mode 100644 index 000000000..5caabf365 --- /dev/null +++ b/.changeset/green-parents-argue.md @@ -0,0 +1,6 @@ +--- +"victory-chart": patch +"victory-core": patch +--- + +Fixed issue where VictoryChart would throw an unhandled exception when passed non-element children (fixes #2391) diff --git a/packages/victory-chart/src/helper-methods.tsx b/packages/victory-chart/src/helper-methods.tsx index b6f3b0f33..08fd4bfc9 100644 --- a/packages/victory-chart/src/helper-methods.tsx +++ b/packages/victory-chart/src/helper-methods.tsx @@ -133,7 +133,7 @@ export function getChildren(props, childComponents, calculatedProps) { const { origin, horizontal } = calculatedProps; const parentName = props.name || "chart"; - return childComponents.map((child, index) => { + return childComponents.filter(React.isValidElement).map((child, index) => { const role = child.type && child.type.role; const style = Array.isArray(child.props.style) ? child.props.style @@ -161,11 +161,10 @@ export function getChildren(props, childComponents, calculatedProps) { } export const getChildComponents = (props, defaultAxes?) => { - const childComponents = React.Children.toArray(props.children); - let newChildComponents = [...childComponents]; + let childComponents = React.Children.toArray(props.children); if (childComponents.length === 0) { - newChildComponents.push(defaultAxes.independent, defaultAxes.dependent); + childComponents.push(defaultAxes.independent, defaultAxes.dependent); } else { const axisComponents = { dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"), @@ -179,18 +178,18 @@ export const getChildComponents = (props, defaultAxes?) => { axisComponents.dependent.length === 0 && axisComponents.independent.length === 0 ) { - newChildComponents = props.prependDefaultAxes + childComponents = props.prependDefaultAxes ? [defaultAxes.independent, defaultAxes.dependent].concat( - newChildComponents, + childComponents, ) - : newChildComponents.concat([ + : childComponents.concat([ defaultAxes.independent, defaultAxes.dependent, ]); } } - return newChildComponents; + return childComponents; }; const getDomain = (props, axis, childComponents) => { diff --git a/packages/victory-core/src/victory-util/helpers.ts b/packages/victory-core/src/victory-util/helpers.ts index e1b06cf50..0b61e1b99 100644 --- a/packages/victory-core/src/victory-util/helpers.ts +++ b/packages/victory-core/src/victory-util/helpers.ts @@ -1,5 +1,5 @@ /* eslint-disable no-use-before-define */ -import React from "react"; +import React, { isValidElement } from "react"; import { defaults, isFunction, property, pick, assign, keys } from "lodash"; import { CallbackArgs } from "../types/callbacks"; import { ValueOrAccessor } from "../types/prop-types"; @@ -301,8 +301,10 @@ export function reduceChildren< return memo; }, initialMemo); }; - const childNames = children.map((c, i) => i); - return traverseChildren(children, childNames); + + const validChildren = children.filter(isValidElement); + const childNames = validChildren.map((c, i) => i); + return traverseChildren(validChildren, childNames); } /** From 583e837a9443ce77b56c9e7810920a481f7189e5 Mon Sep 17 00:00:00 2001 From: alisongs <100587292+alisongs@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:04:40 +0000 Subject: [PATCH 03/29] add missing size prop to symbol type in victory-legend (#2523) Co-authored-by: Charlie Brown --- .changeset/warm-rocks-rest.md | 5 +++++ packages/victory-legend/src/index.d.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/warm-rocks-rest.md diff --git a/.changeset/warm-rocks-rest.md b/.changeset/warm-rocks-rest.md new file mode 100644 index 000000000..c50bfb056 --- /dev/null +++ b/.changeset/warm-rocks-rest.md @@ -0,0 +1,5 @@ +--- +"victory-legend": patch +--- + +Add missing size property to TS definitions diff --git a/packages/victory-legend/src/index.d.ts b/packages/victory-legend/src/index.d.ts index c36eefdf4..66f048a88 100644 --- a/packages/victory-legend/src/index.d.ts +++ b/packages/victory-legend/src/index.d.ts @@ -31,6 +31,7 @@ export interface VictoryLegendProps }; symbol?: { fill?: string; + size?: number; type?: string; }; }>; From e7393a9997f7fb7cffdb942e4e4af099b7756276 Mon Sep 17 00:00:00 2001 From: Joey Mezzacappa <20446836+jmezzacappa@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:10:48 -0500 Subject: [PATCH 04/29] Fix label measurement after SSR hydration mismatch (#2626) Co-authored-by: Charlie Brown --- .changeset/tender-insects-rest.md | 5 +++++ packages/victory-core/src/victory-util/textsize.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/tender-insects-rest.md diff --git a/.changeset/tender-insects-rest.md b/.changeset/tender-insects-rest.md new file mode 100644 index 000000000..a6f73b7b6 --- /dev/null +++ b/.changeset/tender-insects-rest.md @@ -0,0 +1,5 @@ +--- +"victory-core": patch +--- + +Fix text label measurements after SSR hydration mismatch diff --git a/packages/victory-core/src/victory-util/textsize.ts b/packages/victory-core/src/victory-util/textsize.ts index 68b1d070c..4e1009e11 100644 --- a/packages/victory-core/src/victory-util/textsize.ts +++ b/packages/victory-core/src/victory-util/textsize.ts @@ -297,7 +297,11 @@ const styleToKeyComponent = (style) => { const _measureDimensionsInternal = memoize( (text: string | string[], style?: TextSizeStyleInterface) => { - const containerElement = _getMeasurementContainer(); + let containerElement = _getMeasurementContainer(); + if (!containerElement.isConnected) { + _getMeasurementContainer.cache.clear?.(); + containerElement = _getMeasurementContainer(); + } const lines = _splitToLines(text); let heightAcc = 0; From 238972daf39aa60802fd804777cae27037ef894e Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Tue, 9 Jan 2024 05:20:20 -0600 Subject: [PATCH 05/29] Remove v37 experimental code (#2697) --- .changeset/slimy-guests-accept.md | 8 + .../victory-turbo-component-re-write.md | 24 -- .../victory-bar/src/v37/victory-bar-v1.tsx | 129 -------- .../victory-bar/src/v37/victory-bar-v2.tsx | 96 ------ .../src/v37/victory-bar.stories.tsx | 28 -- .../victory-bar/src/v37/victory-bar.test.tsx | 278 ------------------ .../victory-chart/src/v37/victory-chart.tsx | 91 ------ packages/victory-core/src/v37/clone.tsx | 30 -- packages/victory-core/src/v37/index.tsx | 4 - .../src/v37/victory-state/defaults.ts | 2 - .../victory-state/helpers/get-axis-data.ts | 14 - .../victory-state/helpers/get-data.test.ts | 169 ----------- .../src/v37/victory-state/helpers/get-data.ts | 78 ----- .../victory-state/helpers/get-domain.test.ts | 98 ------ .../v37/victory-state/helpers/get-domain.ts | 62 ---- .../victory-state/helpers/get-range.test.ts | 27 -- .../v37/victory-state/helpers/get-range.ts | 39 --- .../victory-state/helpers/get-scale.test.ts | 61 ---- .../v37/victory-state/helpers/get-scale.ts | 67 ----- .../src/v37/victory-state/index.ts | 3 - .../src/v37/victory-state/types.ts | 32 -- .../victory-state/victory-provider.test.ts | 44 --- .../v37/victory-state/victory-provider.tsx | 152 ---------- .../victory-state/with-victory-provider.tsx | 53 ---- .../victory-core/src/v37/with-container.tsx | 38 --- .../src/v37/with-normalized-props.test.tsx | 56 ---- .../src/v37/with-normalized-props.tsx | 43 --- .../src/v37/victory-line.stories.tsx | 30 -- .../victory-line/src/v37/victory-line.tsx | 84 ------ 29 files changed, 8 insertions(+), 1832 deletions(-) create mode 100644 .changeset/slimy-guests-accept.md delete mode 100644 .github/ISSUE_TEMPLATE/victory-turbo-component-re-write.md delete mode 100644 packages/victory-bar/src/v37/victory-bar-v1.tsx delete mode 100644 packages/victory-bar/src/v37/victory-bar-v2.tsx delete mode 100644 packages/victory-bar/src/v37/victory-bar.stories.tsx delete mode 100644 packages/victory-bar/src/v37/victory-bar.test.tsx delete mode 100644 packages/victory-chart/src/v37/victory-chart.tsx delete mode 100644 packages/victory-core/src/v37/clone.tsx delete mode 100644 packages/victory-core/src/v37/index.tsx delete mode 100644 packages/victory-core/src/v37/victory-state/defaults.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-axis-data.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-data.test.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-data.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-domain.test.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-domain.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-range.test.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-range.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-scale.test.ts delete mode 100644 packages/victory-core/src/v37/victory-state/helpers/get-scale.ts delete mode 100644 packages/victory-core/src/v37/victory-state/index.ts delete mode 100644 packages/victory-core/src/v37/victory-state/types.ts delete mode 100644 packages/victory-core/src/v37/victory-state/victory-provider.test.ts delete mode 100644 packages/victory-core/src/v37/victory-state/victory-provider.tsx delete mode 100644 packages/victory-core/src/v37/victory-state/with-victory-provider.tsx delete mode 100644 packages/victory-core/src/v37/with-container.tsx delete mode 100644 packages/victory-core/src/v37/with-normalized-props.test.tsx delete mode 100644 packages/victory-core/src/v37/with-normalized-props.tsx delete mode 100644 packages/victory-line/src/v37/victory-line.stories.tsx delete mode 100644 packages/victory-line/src/v37/victory-line.tsx diff --git a/.changeset/slimy-guests-accept.md b/.changeset/slimy-guests-accept.md new file mode 100644 index 000000000..dea8131a2 --- /dev/null +++ b/.changeset/slimy-guests-accept.md @@ -0,0 +1,8 @@ +--- +"victory-bar": minor +"victory-chart": minor +"victory-core": minor +"victory-line": minor +--- + +Remove v37 experimental code diff --git a/.github/ISSUE_TEMPLATE/victory-turbo-component-re-write.md b/.github/ISSUE_TEMPLATE/victory-turbo-component-re-write.md deleted file mode 100644 index d5557b7f9..000000000 --- a/.github/ISSUE_TEMPLATE/victory-turbo-component-re-write.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -name: Victory Turbo component re-write -about: This is a template for all victory turbo components -title: Victory [component] v37 -labels: turbo -assignees: '' - ---- - -## Implementation Notes -- New components should live inside a nested directory (currently v37). These components should not make changes to existing functionality. -- The victory event system will be excluded for now until we have more clarity on how Victory wants to handle events. -- [Add other notes here] - -## Checklist -- [ ] Basic data rendering as a standalone component -- [ ] Basic data rendering inside a `VictoryChart` -- [ ] Basic data rendering inside a `VictoryGroup` (if applicable) -- [ ] Basic data rendering inside a `VictoryStack` (if applicable) -- [ ] Styling with existing victory theme and inline styles -- [ ] Transitions -- [ ] Basic events like zoom and tooltips -- [ ] Copy existing tests, excluding events and helper methods -- [ ] Add documentation and tests for any API changes diff --git a/packages/victory-bar/src/v37/victory-bar-v1.tsx b/packages/victory-bar/src/v37/victory-bar-v1.tsx deleted file mode 100644 index 943d2871d..000000000 --- a/packages/victory-bar/src/v37/victory-bar-v1.tsx +++ /dev/null @@ -1,129 +0,0 @@ -/* eslint-disable react/no-multi-comp */ -import * as React from "react"; -import { - Datum, - NumberOrCallback, - VictoryCommonProps, - VictoryContainer, - VictoryDatableProps, -} from "victory-core"; -import { - useData, - useDomain, - useScale, - VictoryProvider, - VictoryProviderProps, -} from "victory-core/es/v37"; -import Bar from "../bar"; -import { getBarPosition } from "../helper-methods"; - -// This is a demo component that uses VictoryProvider to access calculated props and state. -// This component does not include events, animations, or styling. -// To test out, swap out the VictoryBar export in ./index.js and run `pnpm run storybook:server`. - -const defaultProps: VictoryProviderProps = { - data: [ - { x: 1, y: 1 }, - { x: 2, y: 2 }, - { x: 3, y: 3 }, - { x: 4, y: 4 }, - ], - height: 300, - includeZero: true, - padding: 50, - sortOrder: "ascending" as const, - width: 450, -}; - -export type VictoryBarAlignmentType = "start" | "middle" | "end"; -export interface VictoryBarProps - extends VictoryCommonProps, - VictoryDatableProps { - alignment?: VictoryBarAlignmentType; - barRatio?: number; - barWidth?: NumberOrCallback; - cornerRadius?: - | NumberOrCallback - | { - top?: NumberOrCallback; - topLeft?: NumberOrCallback; - topRight?: NumberOrCallback; - bottom?: NumberOrCallback; - bottomLeft?: NumberOrCallback; - bottomRight?: NumberOrCallback; - }; - dataComponent?: React.ReactElement; - groupComponent?: React.ReactElement; - horizontal?: boolean; -} - -// TODO: This would be a shared helper that allows us to access context values in the base component -export function withContainer( - WrappedComponent: (props: Props) => React.ReactElement, - initialProviderProps: Partial = {}, -) { - return (props: Props) => { - const providerProps = { - ...initialProviderProps, - ...props, - }; - const { standalone = true, containerComponent = } = - props; - if (standalone) { - return ( - - {React.cloneElement( - containerComponent, - providerProps, - , - )} - - ); - } - return ( - - - - ); - }; -} - -function VictoryBar({ - dataComponent = , - groupComponent = , - alignment, - barRatio, - barWidth, - cornerRadius, - horizontal = false, -}: VictoryBarProps) { - const scale = useScale(); - const data = useData(); - const domain = useDomain(); - - const children = data.map((datum: Datum, i: number) => { - const { x, y, x0, y0 } = getBarPosition( - { domain, scale, horizontal }, - datum, - ); - const dataProps = { - index: i, - key: `bar-${i}`, - alignment, - barRatio, - barWidth, - cornerRadius, - scale, - data, - x, - y, - x0, - y0, - datum, - }; - return React.cloneElement(dataComponent, dataProps); - }); - return React.cloneElement(groupComponent, {}, children); -} - -export default withContainer(VictoryBar, defaultProps); diff --git a/packages/victory-bar/src/v37/victory-bar-v2.tsx b/packages/victory-bar/src/v37/victory-bar-v2.tsx deleted file mode 100644 index d8fd5b53e..000000000 --- a/packages/victory-bar/src/v37/victory-bar-v2.tsx +++ /dev/null @@ -1,96 +0,0 @@ -/* eslint-disable react/no-multi-comp */ -import * as React from "react"; -import { Datum, NumberOrCallback } from "victory-core"; -import { - useData, - useDomain, - useScale, - useVictoryProviderSync, - VictoryCalculatedStateProps, - withContainer, -} from "victory-core/es/v37"; - -import Bar from "../bar"; -import { BarProps } from ".."; -import { getBarPosition } from "../helper-methods"; - -export type VictoryBarAlignmentType = "start" | "middle" | "end"; -export interface VictoryBarProps extends VictoryCalculatedStateProps { - alignment?: VictoryBarAlignmentType; - barRatio?: number; - barWidth?: NumberOrCallback; - cornerRadius?: - | NumberOrCallback - | { - top?: NumberOrCallback; - topLeft?: NumberOrCallback; - topRight?: NumberOrCallback; - bottom?: NumberOrCallback; - bottomLeft?: NumberOrCallback; - bottomRight?: NumberOrCallback; - }; - data?: Datum[]; - dataComponent?: React.ReactElement; - groupComponent?: React.ReactElement; - horizontal?: boolean; -} - -function VictoryBar({ - alignment = "middle", - barRatio, - barWidth, - cornerRadius, - data = [ - { x: 1, y: 1 }, - { x: 2, y: 2 }, - { x: 3, y: 3 }, - { x: 4, y: 4 }, - ], - dataComponent = , - groupComponent = , - includeZero = true, - horizontal = false, - sortOrder = "ascending", - ...props -}: VictoryBarProps) { - // Typescript works best when we provide defaults in the destructured - // component props. However, I am anticipating confusion about which props - // we will need to pass back up to the provider vs. the props that are only - // used in this component. - useVictoryProviderSync({ - data, - includeZero, - sortOrder, - ...props, - }); - const scale = useScale(); - const domain = useDomain(); - - // TODO: Do we need to get this from context? - const formattedData = useData(); - - const barPositionProps = { domain, scale, horizontal }; - - const children = formattedData.map((datum: Datum, i: number) => { - const { x, y, y0 } = getBarPosition(barPositionProps, datum); - const dataProps: BarProps & { key: string } = { - index: i, - key: `bar-${i}`, - alignment, - barRatio, - barWidth, - cornerRadius, - scale, - data, - x, - y, - y0, - datum, - }; - return React.cloneElement(dataComponent, dataProps); - }); - return React.cloneElement(groupComponent, {}, children); -} - -// @ts-expect-error we need to work out what props this withContainer wrapper accepts -export default withContainer(VictoryBar); diff --git a/packages/victory-bar/src/v37/victory-bar.stories.tsx b/packages/victory-bar/src/v37/victory-bar.stories.tsx deleted file mode 100644 index fd6820448..000000000 --- a/packages/victory-bar/src/v37/victory-bar.stories.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/* eslint-disable react/no-multi-comp */ -import * as React from "react"; -import VictoryBar from "./victory-bar-v2"; -import VictoryChart from "victory-chart/es/v37/victory-chart"; - -export default { - title: "v37/VictoryBar", - parameters: { - chromatic: { disableSnapshot: true }, - }, - component: VictoryBar, -}; - -export const Demo = (props) => { - return ; -}; - -Demo.args = { - barRatio: 0.5, -}; - -export const WithChart = (props) => { - return ( - - - - ); -}; diff --git a/packages/victory-bar/src/v37/victory-bar.test.tsx b/packages/victory-bar/src/v37/victory-bar.test.tsx deleted file mode 100644 index a20a62a67..000000000 --- a/packages/victory-bar/src/v37/victory-bar.test.tsx +++ /dev/null @@ -1,278 +0,0 @@ -import * as React from "react"; -import { render, fireEvent, screen } from "@testing-library/react"; -import { range } from "lodash"; -import { VictoryChart } from "victory-chart"; -import { Bar, VictoryBar } from "victory-bar"; -import { isBar, getBarHeight } from "../../../../test/helpers"; - -describe("components/victory-bar", () => { - describe("default component rendering", () => { - it("attaches safe user props to the container component", () => { - render( - , - ); - - const container = screen.getByTestId("victory-bar"); - expect(screen.getByLabelText("Chart")).toBeDefined(); - expect(container).not.toHaveAttribute("unsafe-prop"); - expect(container.tagName).toEqual("svg"); - }); - - it("attaches safe user props to the group component if the component is rendered inside a VictoryChart", () => { - render( - , - { wrapper: VictoryChart }, - ); - - const container = screen.getByTestId("victory-bar"); - expect(screen.getByLabelText("Chart")).toBeDefined(); - expect(container).not.toHaveAttribute("unsafe-prop"); - expect(container.tagName).toEqual("g"); - }); - - it("renders an svg with the correct width and height", () => { - const { container } = render(); - const svg = container.querySelector("svg"); - expect(svg!.getAttribute("style")).toContain("width: 100%; height: 100%"); - }); - - it("renders an svg with the correct viewBox", () => { - const { container } = render(); - const svg = container.querySelector("svg"); - const viewBoxValue = `0 0 ${450} ${300}`; - expect(svg!.getAttribute("viewBox")).toEqual(viewBoxValue); - }); - - it("renders 4 bars", () => { - const { container } = render(); - const bars = container.querySelectorAll("path"); - expect(bars.length).toEqual(4); - }); - - it("renders each bar as a rectangle", () => { - const { container } = render(); - const barCommandStrings = Array.from( - container.querySelectorAll("path"), - ).map((bar) => bar.getAttribute("d")); - barCommandStrings.forEach((commandString) => { - expect(isBar(commandString)).toBeTruthy(); - }); - }); - }); - - describe("rendering data", () => { - it("renders bars for {x, y} shaped data (default)", () => { - const data = range(10).map((i) => ({ x: i, y: i })); - const { container } = render(); - const bars = container.querySelectorAll("path"); - expect(bars.length).toEqual(10); - }); - - it("renders ordered bars when sortKey is passed", () => { - const data = range(5) - .map((i) => ({ x: i, y: i })) - .reverse(); - const { container } = render(); - const barHeight = Array.from(container.querySelectorAll("path")).map( - (bar) => { - const commandString = bar.getAttribute("d"); - return getBarHeight(commandString); - }, - ); - - const ascendingBars = [...barHeight].sort((a, b) => a - b); - - expect(barHeight).toEqual(ascendingBars); - }); - - it("renders reverse ordered bars when sortOrder is descending", () => { - const data = range(5) - .map((i) => ({ x: i, y: i })) - .reverse(); - const { container } = render( - , - ); - const barHeight = Array.from(container.querySelectorAll("path")).map( - (bar) => { - const commandString = bar.getAttribute("d"); - return getBarHeight(commandString); - }, - ); - const descendingBars = [...barHeight].sort((a, b) => b - a); - - expect(barHeight).toEqual(descendingBars); - }); - - it("renders bars for array-shaped data", () => { - const data = range(20).map((i) => [i, i]); - const { container } = render(); - const bars = container.querySelectorAll("path"); - expect(bars).toHaveLength(20); - }); - - it("renders bars for deeply-nested data", () => { - const data = range(8).map((i) => ({ a: { b: [{ x: i, y: i }] } })); - const { container } = render( - , - ); - const bars = container.querySelectorAll("path"); - expect(bars).toHaveLength(8); - }); - - it("renders bars values with null accessor", () => { - const data = range(8); - const { container } = render( - // @ts-expect-error null is not assignable to DataGetterType - , - ); - const bars = container.querySelectorAll("path"); - expect(bars).toHaveLength(8); - }); - - it("renders bars with appropriate relative heights", () => { - const { container } = render( - , - ); - const bars = Array.from(container.querySelectorAll("path")); - const heights = bars.map((bar) => { - const commandString = bar.getAttribute("d"); - return getBarHeight(commandString); - }); - - expect(Math.trunc(heights[1] / 2)).toEqual(Math.trunc(heights[0])); - expect(((heights[2] / 3) * 2).toFixed(3)).toEqual(heights[1].toFixed(3)); - }); - - it("does not render data with null x or y values", () => { - const data = [ - { x: 1, y: 2 }, - { x: null, y: 4 }, - { x: 5, y: null }, - ]; - const { container } = render(); - expect(container.querySelectorAll("path")).toHaveLength(1); - }); - }); - - describe.skip("event handling", () => { - const clickHandler = jest.fn(); - - beforeEach(() => { - clickHandler.mockReset(); - }); - - it("attaches an event to the parent svg", () => { - const { container } = render( - , - ); - const bar = container.querySelector("path"); - fireEvent.click(bar!); - - expect(clickHandler).toHaveBeenCalled(); - }); - - it("attaches an event to data", () => { - const data = [ - { x: 0, y: 0, label: "0" }, - { x: 1, y: 1, label: "1" }, - { x: 2, y: 2, label: "2" }, - ]; - const { container } = render( - , - ); - const bars = container.querySelectorAll("path"); - bars.forEach((bar, index) => { - clickHandler.mockReset(); - fireEvent.click(bar); - expect(clickHandler).toHaveBeenCalled(); - - const barContext = clickHandler.mock.calls[0][1]; - expect(barContext.datum.x).toEqual(data[index].x); - }); - }); - - it("attaches an event to a label", () => { - const data = [ - { x: 0, y: 0, label: "label 0" }, - { x: 1, y: 1, label: "label 1" }, - { x: 2, y: 2, label: "label 2" }, - ]; - - render( - datum.label} - events={[ - { - target: "labels", - eventHandlers: { onClick: clickHandler }, - }, - ]} - />, - ); - const label = screen.getByText("label 1"); - - fireEvent.click(label); - - expect(clickHandler).toHaveBeenCalled(); - }); - }); - - describe("accessibility", () => { - it("adds an aria role to each bar in the series", () => { - const data = range(10).map((y, x) => ({ x, y })); - render(); - const presentationElements = screen.getAllByRole("presentation"); - expect(presentationElements).toHaveLength(11); // bars plus container - }); - - it("applies aria-label and tabIndex to the Bar primitive", () => { - const data = range(5, 11).map((y, x) => ({ y, x })); - const { container } = render( - `x: ${datum.x}`} - tabIndex={({ index }) => (index as number) + 1} - /> - } - />, - ); - - container.querySelectorAll("path").forEach((bar, index) => { - expect(parseInt(bar.getAttribute("tabindex")!)).toEqual(index + 1); - expect(bar.getAttribute("aria-label")).toEqual(`x: ${data[index].x}`); - }); - }); - }); -}); diff --git a/packages/victory-chart/src/v37/victory-chart.tsx b/packages/victory-chart/src/v37/victory-chart.tsx deleted file mode 100644 index 6864d6ba5..000000000 --- a/packages/victory-chart/src/v37/victory-chart.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import * as React from "react"; -import { - CategoryPropType, - DomainPropType, - EventPropTypeInterface, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryStyleInterface, - VictoryStyleObject, -} from "victory-core"; -import { - withContainer, - useDomain, - useScale, - useData, -} from "victory-core/es/v37"; -import { AxesType } from ".."; -import { VictoryAxis, VictoryAxisProps } from "victory-axis"; - -interface VictoryChartProps extends VictoryCommonProps { - backgroundComponent?: React.ReactElement; - categories?: CategoryPropType; - children?: React.ReactNode | React.ReactNode[]; - desc?: string; - defaultAxes?: AxesType; - defaultPolarAxes?: AxesType; - domain?: DomainPropType; - endAngle?: number; - eventKey?: StringOrNumberOrCallback; - events?: EventPropTypeInterface< - string, - string[] | number[] | string | number - >[]; - innerRadius?: number; - prependDefaultAxes?: boolean; - startAngle?: number; - style?: Pick & { - background?: VictoryStyleObject; - }; - title?: string; -} - -const DEFAULT_AXES = { - independent: , - dependent: , -}; - -// TODO: This does not accept data -const VictoryChart = ({ - defaultAxes = DEFAULT_AXES, - groupComponent = , - children, -}: VictoryChartProps) => { - const scale = useScale(); - const data = useData(); - const domain = useDomain(); - - const axes = React.useMemo(() => { - const { dependent, independent } = { - ...defaultAxes, - ...DEFAULT_AXES, - }; - const axisProps: VictoryAxisProps = { - data, - domain, - // @ts-expect-error we need to fix this scale type - scale, - standalone: false, - }; - return [ - React.cloneElement(dependent, { ...axisProps, key: "dependent-axis" }), - React.cloneElement(independent, { - ...axisProps, - key: "independent-axis", - }), - ]; - }, [defaultAxes, domain, scale, data]); - - const childComponents = React.Children.map(children, (child, index) => { - // @ts-expect-error Why is this throwing a type error? - return React.cloneElement(child, { - key: `child-${index}`, - index, - standalone: false, - }); - }); - - return React.cloneElement(groupComponent, {}, axes, childComponents); -}; - -export default withContainer(VictoryChart); diff --git a/packages/victory-core/src/v37/clone.tsx b/packages/victory-core/src/v37/clone.tsx deleted file mode 100644 index 8b3346c4c..000000000 --- a/packages/victory-core/src/v37/clone.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from "react"; - -/** - * Syntax sugar for `React.cloneElement`, so that we can use JSX instead - * - * @example - * // Before: - * const children = React.cloneElement(props.groupComponent, { prop2 }, props.children); - * return React.cloneElement(props.containerComponent, { prop1 }, children); - * - * // After: - * return ( - * - * - * {props.children} - * - * - * ); - */ -export const Clone = ( - props: React.PropsWithChildren< - { - element: React.ReactElement; - children?: React.ReactNode | React.ReactNode[]; - } & TProps - >, -) => { - const { children, element, ...rest } = props; - return React.cloneElement(element, rest as unknown as TProps, children); -}; diff --git a/packages/victory-core/src/v37/index.tsx b/packages/victory-core/src/v37/index.tsx deleted file mode 100644 index 6b054e46f..000000000 --- a/packages/victory-core/src/v37/index.tsx +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./victory-state"; -export * from "./clone"; -export * from "./with-normalized-props"; -export * from "./with-container"; diff --git a/packages/victory-core/src/v37/victory-state/defaults.ts b/packages/victory-core/src/v37/victory-state/defaults.ts deleted file mode 100644 index 69c125fd3..000000000 --- a/packages/victory-core/src/v37/victory-state/defaults.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const DEFAULT_HEIGHT = 300; -export const DEFAULT_WIDTH = 450; diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-axis-data.ts b/packages/victory-core/src/v37/victory-state/helpers/get-axis-data.ts deleted file mode 100644 index 0e66fc75b..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-axis-data.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AxisType, Datum, DomainValue } from "../../../types/prop-types"; -import { isKeyValueObject } from "../../../victory-util/type-helpers"; - -export function getAxisData(data: Datum[], axis: AxisType) { - return data.reduce((acc, datum) => { - if (isKeyValueObject(datum)) { - const value = datum[axis]; - if (value && typeof value !== "string") { - acc.push(value); - } - } - return acc; - }, [] as DomainValue[]); -} diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-data.test.ts b/packages/victory-core/src/v37/victory-state/helpers/get-data.test.ts deleted file mode 100644 index 065d8cd5a..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-data.test.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { range } from "lodash"; -import { getData } from "victory-core/lib/v37/victory-state/helpers/get-data"; - -describe("getData", () => { - it("returns an empty array if no data is passed in", () => { - expect(getData()).toEqual([]); - }); - - it("returns formatted data", () => { - const data = [ - { x: "kittens", y: 3 }, - { x: "cats", y: 5 }, - ]; - expect(getData({ data })).toMatchInlineSnapshot(` - Array [ - Object { - "_x": 1, - "_y": 3, - "x": "kittens", - "xName": "kittens", - "y": 3, - }, - Object { - "_x": 2, - "_y": 5, - "x": "cats", - "xName": "cats", - "y": 5, - }, - ] - `); - }); - - it("accepts date values", () => { - const data = [ - { - x: new Date(Date.UTC(2022, 0, 1)), - y: 10, - }, - { - x: new Date(Date.UTC(2022, 0, 2)), - y: 20, - }, - ]; - expect(getData({ data })).toMatchInlineSnapshot(` - Array [ - Object { - "_x": 2022-01-01T00:00:00.000Z, - "_y": 10, - "x": 2022-01-01T00:00:00.000Z, - "y": 10, - }, - Object { - "_x": 2022-01-02T00:00:00.000Z, - "_y": 20, - "x": 2022-01-02T00:00:00.000Z, - "y": 20, - }, - ] - `); - }); - - it("filters data with null x and y values", () => { - const data = [ - { - x: null, - y: 1, - }, - { - y: 2, - x: null, - }, - { - x: 3, - y: 3, - }, - ]; - expect(getData({ data })).toHaveLength(1); - }); - - it("returns formatted data witfh accessors", () => { - const data = [ - { one: "kittens", two: 3 }, - { one: "cats", two: 5 }, - ]; - expect(getData({ data, x: "one", y: "two" })).toMatchInlineSnapshot(` - Array [ - Object { - "_x": 1, - "_y": 3, - "one": "kittens", - "two": 3, - "x": "kittens", - "xName": "kittens", - "y": 3, - }, - Object { - "_x": 2, - "_y": 5, - "one": "cats", - "two": 5, - "x": "cats", - "xName": "cats", - "y": 5, - }, - ] - `); - }); - - it("does not sort data by default", () => { - const data = [ - { x: 2, y: 2 }, - { x: 1, y: 3 }, - { x: 3, y: 1 }, - ]; - - expect(getData({ data })).toEqual([ - { _x: 2, x: 2, _y: 2, y: 2 }, - { _x: 1, x: 1, _y: 3, y: 3 }, - { _x: 3, x: 3, _y: 1, y: 1 }, - ]); - }); - - it("sorts data according to sort key", () => { - const data = [ - { x: 1, y: 1, order: 2 }, - { x: 3, y: 3, order: 1 }, - { x: 2, y: 2, order: 3 }, - ]; - - expect(getData({ data, sortKey: "order" })).toEqual([ - { _x: 3, x: 3, _y: 3, y: 3, order: 1 }, - { _x: 1, x: 1, _y: 1, y: 1, order: 2 }, - { _x: 2, x: 2, _y: 2, y: 2, order: 3 }, - ]); - }); - - it("sorts data according to sort key and sort order", () => { - const data = [ - { x: 1, y: 1, order: 2 }, - { x: 3, y: 3, order: 1 }, - { x: 2, y: 2, order: 3 }, - ]; - - expect( - getData({ data, sortKey: "order", sortOrder: "descending" }), - ).toEqual([ - { _x: 2, x: 2, _y: 2, y: 2, order: 3 }, - { _x: 1, x: 1, _y: 1, y: 1, order: 2 }, - { _x: 3, x: 3, _y: 3, y: 3, order: 1 }, - ]); - }); - - it("formats deeply nested data", () => { - const data = range(8).map((i) => ({ a: { b: [{ x: i, y: i }] } })); - - expect(getData({ data, x: "a.b[0].x", y: "a.b[0].y" })).toHaveLength(8); - }); - - it("formats data from a range", () => { - const data = range(3); - - expect(getData({ data })).toEqual([ - { _x: 0, x: 0, _y: 0, y: 0 }, - { _x: 1, x: 1, _y: 1, y: 1 }, - { _x: 2, x: 2, _y: 2, y: 2 }, - ]); - }); -}); diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-data.ts b/packages/victory-core/src/v37/victory-state/helpers/get-data.ts deleted file mode 100644 index d5ff4b013..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-data.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { get, isNil, orderBy } from "lodash"; -import { Datum, DatumValue } from "../../../types/prop-types"; -import { isKeyValueObject } from "../../../victory-util/type-helpers"; -import { VictoryProviderProps } from "../types"; - -type DataProps = Pick< - VictoryProviderProps, - "data" | "x" | "y" | "sortKey" | "sortOrder" | "samples" ->; - -export interface FormattedDatum { - x: DatumValue; - y: DatumValue; - _x: number | Date; - _y: number | Date; - xName?: string; - yName?: string; - [key: string]: DatumValue; -} - -function getValue(datum: Datum, key: string): DatumValue { - if (typeof datum === "object") { - return get(datum, key); - } - return datum; -} - -function getNumericValue(value: DatumValue, fallback: number): number | Date { - if (typeof value === "number" || value instanceof Date) { - return value; - } - return fallback; -} - -export function getData({ - x: xAccessor = "x", - y: yAccessor = "y", - sortKey, - sortOrder = "ascending", - data = [], -}: DataProps = {}): FormattedDatum[] { - const formattedData = data.reduce((nonNullData, datum, index) => { - const x = getValue(datum, xAccessor); - const y = getValue(datum, yAccessor); - if (isNil(x) || isNil(y)) { - return nonNullData; - } - const _x = getNumericValue(x, index + 1); - const _y = getNumericValue(y, index + 1); - - // TODO: Get this value if it is different - const xName = typeof x === "string" ? x : undefined; - const yName = typeof y === "string" ? y : undefined; - - const additionalProperties = isKeyValueObject(datum) ? datum : {}; - - return [ - ...nonNullData, - { - x, - y, - _x, - _y, - // Only set these properties if they exist - ...(xName ? { xName } : {}), - ...(yName ? { yName } : {}), - ...additionalProperties, - }, - ]; - }, [] as FormattedDatum[]); - - if (sortKey) { - const order = sortOrder === "descending" ? "desc" : "asc"; - return orderBy(formattedData, sortKey, order); - } - - return formattedData; -} diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-domain.test.ts b/packages/victory-core/src/v37/victory-state/helpers/get-domain.test.ts deleted file mode 100644 index 4dce72fbf..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-domain.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { getDomain } from "victory-core/lib/v37/victory-state/helpers/get-domain"; - -describe("getDomain", () => { - it("returns a default domain if no data is provided", () => { - expect(getDomain({}, "x")).toEqual([0, 1]); - expect(getDomain({}, "y")).toEqual([0, 1]); - }); - - it("gets the domain from props", () => { - expect(getDomain({ domain: [0, 1] }, "x")).toEqual([0, 1]); - expect(getDomain({ domain: [0, 1] }, "y")).toEqual([0, 1]); - }); - - it("gets the domain from props for x and y", () => { - expect(getDomain({ domain: { x: [0, 1] } }, "x")).toEqual([0, 1]); - expect(getDomain({ domain: { y: [1, 2] } }, "y")).toEqual([1, 2]); - }); - - it("gets the domain from data if props don't exist for a particular axis", () => { - expect( - getDomain( - { - domain: { y: [1, 2] }, - data: [ - { x: 1, y: 3 }, - { x: 3, y: 5 }, - ], - }, - "x", - ), - ).toEqual([1, 3]); - }); - - it("gets the domain from data with dates", () => { - expect( - getDomain( - { - domain: { y: [1, 2] }, - data: [ - { x: new Date(2022, 0, 10), y: 1 }, - { x: new Date(2022, 0, 1), y: 2 }, - ], - }, - "x", - ), - ).toEqual([new Date(2022, 0, 1), new Date(2022, 0, 10)]); - }); - - it("returns a domain from minDomain and maxDomain if both are defined", () => { - const props = { minDomain: 1, maxDomain: 10 }; - expect(getDomain(props, "x")).toEqual([1, 10]); - }); - - it("returns a domain from minDoman and maxDomain if both are defined for x and y", () => { - const props = { - minDomain: { x: 1, y: 2 }, - maxDomain: { x: 10, y: 20 }, - }; - expect(getDomain(props, "x")).toEqual([1, 10]); - }); - - describe("with zero", () => { - it("ensures that the domain includes zero for the dependent axis", () => { - const props = { - data: [ - { x: 1, y: 3 }, - { x: 3, y: 5 }, - ], - includeZero: true, - }; - expect(getDomain(props, "y")).toEqual([0, 5]); - }); - - it("allows minimum domain values less than zero", () => { - const props = { - data: [ - { x: 1, y: -3 }, - { x: 3, y: 5 }, - ], - includeZero: true, - }; - expect(getDomain(props, "y")).toEqual([-3, 5]); - }); - - // TODO: Investigate this more - // Why is y0 different for each x/y value? Could minDomain be used instead? - it.skip("allows explicit y0 values in props.data to set the minimum domain", () => { - const props = { - data: [ - { x: 1, y: 3, y0: 2 }, - { x: 3, y: 5, y0: 3 }, - ], - includeZero: true, - }; - expect(getDomain(props, "y")).toEqual([2, 5]); - }); - }); -}); diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-domain.ts b/packages/victory-core/src/v37/victory-state/helpers/get-domain.ts deleted file mode 100644 index 4315a6983..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-domain.ts +++ /dev/null @@ -1,62 +0,0 @@ -import * as d3Array from "victory-vendor/d3-array"; -import { getAxisData } from "./get-axis-data"; -import { - getValueForAxis, - isDate, - isTuple, -} from "../../../victory-util/type-helpers"; -import { VictoryProviderProps } from "../types"; -import { - Tuple, - AxisType, - DomainTuple, - DomainValue, -} from "../../../types/prop-types"; - -type DomainProps = Pick< - VictoryProviderProps, - "data" | "domain" | "maxDomain" | "minDomain" | "includeZero" ->; - -// TODO: What should this default value be? -const DEFAULT_MIN = 0; -const DEFAULT_MAX = 1; - -function getDomainFromMinMax( - min: number = DEFAULT_MIN, - max: number = DEFAULT_MAX, -): Tuple { - // TODO: Victoy currently has some really specific logic in getDomainFromMinMax - // that adds or subtracts a very small number from each domain to avoid the min - // and max being the same value. This has resulted in some weird behavior in the - // past, so we should revisit this. - return [min, max]; -} - -export function getDomain( - { data = [], includeZero, ...props }: DomainProps, - axis: AxisType, -): DomainTuple { - const domainFromProps = getValueForAxis(props.domain, axis); - const axisData = getAxisData(data, axis); - - if (includeZero && axis === "y") { - axisData.push(0); - } - - if (isTuple(domainFromProps)) { - return domainFromProps; - } - - const [min, max] = d3Array.extent(axisData) as DomainTuple | Tuple; - - const minDomain = getValueForAxis(props.minDomain, axis) || min; - const maxDomain = getValueForAxis(props.maxDomain, axis) || max; - - if (isDate(minDomain) && isDate(maxDomain)) { - return [min, max] as Tuple; - } - - // TODO: There might be an edge case here where we have mixed types - return getDomainFromMinMax(minDomain as number, maxDomain as number); -} diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-range.test.ts b/packages/victory-core/src/v37/victory-state/helpers/get-range.test.ts deleted file mode 100644 index db24edce7..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-range.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { getRange } from "victory-core/lib/v37/victory-state/helpers/get-range"; - -describe("getRange", () => { - it("returns a range from props", () => { - const props = { - range: [0, 1], - }; - expect(getRange(props, "x")).toEqual([0, 1]); - }); - - it("returns a range based on props and axis", () => { - const props = { - width: 100, - height: 200, - padding: 0, - }; - const x = getRange(props, "x"); - expect(Array.isArray(x)).toBe(true); - expect(x).toHaveLength(2); - expect(x).toEqual([0, 100]); - - const y = getRange(props, "y"); - expect(Array.isArray(y)).toBe(true); - expect(y).toHaveLength(2); - expect(y).toEqual([200, 0]); - }); -}); diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-range.ts b/packages/victory-core/src/v37/victory-state/helpers/get-range.ts deleted file mode 100644 index 917d3dabe..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-range.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { AxisType, Padding, RangeTuple } from "../../../types/prop-types"; -import { getPadding } from "../../../victory-util/helpers"; -import { getValueForAxis, isTuple } from "../../../victory-util/type-helpers"; -import { VictoryProviderProps } from "../types"; - -type RangeProps = Pick< - VictoryProviderProps, - "range" | "padding" | "height" | "width" ->; - -// TODO: Should we store these defaults somewhere? -const DEFAULT_HEIGHT = 300; -const DEFAULT_WIDTH = 450; - -// TODO: This does not include polar range -export function getRange( - { - range, - height = DEFAULT_HEIGHT, - width = DEFAULT_WIDTH, - ...props - }: RangeProps, - axis: AxisType, -) { - const rangeFromProps = getValueForAxis(range, axis); - - if (isTuple(rangeFromProps)) { - return rangeFromProps; - } - - // TODO: Convert this to TS - const padding = getPadding({ padding: props.padding }) as Padding; - const rangeForAxis = { - x: [padding.left, width - padding.right], - y: [height - padding.top, padding.bottom], - }; - - return rangeForAxis[axis]; -} diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-scale.test.ts b/packages/victory-core/src/v37/victory-state/helpers/get-scale.test.ts deleted file mode 100644 index 578c1d7b3..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-scale.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as d3Scale from "victory-vendor/d3-scale"; -import { getScale } from "victory-core/lib/v37/victory-state/helpers/get-scale"; - -describe("getScale", () => { - it("gets the d3 scale from props", () => { - expect(getScale({ scale: d3Scale.scaleLog }, "x")).toEqual( - d3Scale.scaleLog, - ); - }); - - it("gets the d3 scale from props for an axis", () => { - expect(getScale({ scale: { x: d3Scale.scaleLog } }, "x")).toEqual( - d3Scale.scaleLog, - ); - }); - - it("returns a default scale when data is provided", () => { - const props = { - data: [{ x: 0, y: 1 }], - }; - const scale = getScale(props, "x"); - expect(scale).toBeInstanceOf(Function); - // Scale should be d3Scale.scaleLinear - expect(scale().domain()).toEqual(d3Scale.scaleLinear().domain()); - expect(scale().range()).toEqual(d3Scale.scaleLinear().range()); - }); - - it("returns a default scale when nothing is provided", () => { - const scale = getScale({}, "x"); - expect(scale).toBeInstanceOf(Function); - // Scale should be d3Scale.scaleLinear - expect(scale().domain()).toEqual(d3Scale.scaleLinear().domain()); - expect(scale().range()).toEqual(d3Scale.scaleLinear().range()); - }); - - it("returns a scale when a single scale string is provided in props", () => { - const scale = getScale({ scale: "log" }, "x"); - expect(scale).toBeInstanceOf(Function); - // Scale should be d3Scale.scaleLog - expect(scale().domain()).toEqual(d3Scale.scaleLog().domain()); - expect(scale().range()).toEqual(d3Scale.scaleLog().range()); - }); - - it("returns a scale when a scale string is provided in props for an axis", () => { - const scale = getScale({ scale: { x: "log" } }, "x"); - expect(scale).toBeInstanceOf(Function); - // Scale should be d3Scale.scaleLog - expect(scale().domain()).toEqual(d3Scale.scaleLog().domain()); - expect(scale().range()).toEqual(d3Scale.scaleLog().range()); - }); - - it("returns a time scale when data contains dates", () => { - const props = { - data: [{ x: new Date("2016-01-13"), y: 1 }], - }; - const scale = getScale(props, "x"); - expect(scale).toBeInstanceOf(Function); - expect(scale().domain()).toEqual(d3Scale.scaleTime().domain()); - expect(scale().range()).toEqual(d3Scale.scaleTime().range()); - }); -}); diff --git a/packages/victory-core/src/v37/victory-state/helpers/get-scale.ts b/packages/victory-core/src/v37/victory-state/helpers/get-scale.ts deleted file mode 100644 index ad5220575..000000000 --- a/packages/victory-core/src/v37/victory-state/helpers/get-scale.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - scaleLinear, - scaleTime, - scaleLog, - scaleSqrt, -} from "victory-vendor/d3-scale"; -import { AxisType, D3ScaleFn, ScalePropType } from "../../../types/prop-types"; -import * as Collection from "../../../victory-util/collection"; -import { - getValueForAxis, - isFunction, -} from "../../../victory-util/type-helpers"; -import { VictoryProviderProps } from "../types"; -import { getAxisData } from "./get-axis-data"; - -type Scale = ScalePropType | D3ScaleFn; - -type ScaleProps = Pick; - -const DEFAULT_SCALE = scaleLinear; - -function isD3Scale(scale?: unknown): scale is D3ScaleFn { - return ( - isFunction(scale) && - isFunction(scale().copy) && - isFunction(scale().domain) && - isFunction(scale().range) - ); -} - -function getD3ScaleFromString(scale: ScalePropType): D3ScaleFn { - switch (scale) { - case "linear": - return scaleLinear; - case "time": - return scaleTime; - case "log": - return scaleLog; - case "sqrt": - return scaleSqrt; - default: - return DEFAULT_SCALE; - } -} - -export function getScale( - { data = [], ...props }: ScaleProps, - axis: AxisType, -): D3ScaleFn { - const scale = getValueForAxis(props.scale, axis); - - if (isD3Scale(scale)) { - return scale; - } - - if (typeof scale === "string") { - return getD3ScaleFromString(scale); - } - - const axisData = getAxisData(data, axis); - - if (Collection.containsDates(axisData)) { - return scaleTime; - } - - return DEFAULT_SCALE; -} diff --git a/packages/victory-core/src/v37/victory-state/index.ts b/packages/victory-core/src/v37/victory-state/index.ts deleted file mode 100644 index 7d809bc43..000000000 --- a/packages/victory-core/src/v37/victory-state/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./victory-provider"; -export * from "./types"; -export * from "./with-victory-provider"; diff --git a/packages/victory-core/src/v37/victory-state/types.ts b/packages/victory-core/src/v37/victory-state/types.ts deleted file mode 100644 index 2501b0df8..000000000 --- a/packages/victory-core/src/v37/victory-state/types.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - D3ScaleFn, - Datum, - DomainTuple, - RangeTuple, - ScalePropType, - ValueOrAxes, -} from "../../types/prop-types"; -import { PaddingProps } from "../../victory-theme/types"; - -// These are all the props that are used to calculate data, domain, range, and scale -export interface VictoryCalculatedStateProps { - data?: Datum[]; - domain?: ValueOrAxes; - height?: number; - includeZero?: boolean; - maxDomain?: ValueOrAxes; - minDomain?: ValueOrAxes; - padding?: PaddingProps; - range?: ValueOrAxes; - samples?: number; - scale?: ValueOrAxes; - sortKey?: string; - sortOrder?: "ascending" | "descending"; - width?: number; - x?: string; - y?: string; -} - -export interface VictoryProviderProps extends VictoryCalculatedStateProps { - children?: React.ReactNode; -} diff --git a/packages/victory-core/src/v37/victory-state/victory-provider.test.ts b/packages/victory-core/src/v37/victory-state/victory-provider.test.ts deleted file mode 100644 index b4515d6f6..000000000 --- a/packages/victory-core/src/v37/victory-state/victory-provider.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { useVictoryContext, VictoryProvider } from "victory-core/lib/v37"; -import { act, renderHook } from "@testing-library/react-hooks"; - -describe("Victory Provider", () => { - it("returns default values", () => { - const { result } = renderHook(() => useVictoryContext((c) => c), { - wrapper: VictoryProvider, - }); - - expect(result.current.data).toHaveLength(0); - - // @ts-expect-error I have no idea why x and y do not exist on this type - const { x, y } = result.current.scale; - expect(x.domain()).toEqual([0, 1]); - expect(y.domain()).toEqual([0, 1]); - expect(x.range()).toEqual([0, 450]); - expect(y.range()).toEqual([300, 0]); - }); - - it.skip("syncs the child props with the provider state", () => { - const { result } = renderHook(() => useVictoryContext((c) => c), { - wrapper: VictoryProvider, - }); - - act(() => { - result.current.updateChildProps(Symbol("chart-1"), { - data: [ - { x: 1, y: 1 }, - { x: 2, y: 2 }, - ], - }); - }); - act(() => { - result.current.updateChildProps(Symbol("chart-2"), { - data: [ - { x: 3, y: 3 }, - { x: 4, y: 4 }, - ], - }); - }); - - expect(result.current.domain).toEqual({ x: [1, 4], y: [1, 4] }); - }); -}); diff --git a/packages/victory-core/src/v37/victory-state/victory-provider.tsx b/packages/victory-core/src/v37/victory-state/victory-provider.tsx deleted file mode 100644 index 31507a12f..000000000 --- a/packages/victory-core/src/v37/victory-state/victory-provider.tsx +++ /dev/null @@ -1,152 +0,0 @@ -import * as React from "react"; -import { createContext, useContext } from "react"; -import { D3ScaleFn, DomainTuple, ForAxes } from "../../types/prop-types"; -import { FormattedDatum, getData } from "./helpers/get-data"; -import { getDomain } from "./helpers/get-domain"; -import { getRange } from "./helpers/get-range"; -import { getScale } from "./helpers/get-scale"; -import { VictoryCalculatedStateProps, VictoryProviderProps } from "./types"; - -type ScaleType = Required>; -type DomainType = Required>; - -export interface ContextType { - data: FormattedDatum[]; - scale: ScaleType; - domain: DomainType; - updateChildProps: (id: symbol, props: VictoryProviderProps | null) => void; -} - -const VictoryContext = createContext(null); - -type CollectedProps = { [id: symbol]: VictoryCalculatedStateProps }; - -function useNormalizedProps(): ContextType { - const [collectedProps, setCollectedProps] = React.useState( - {}, - ); - - const updateChildProps = React.useCallback( - (id: symbol, newProps: VictoryCalculatedStateProps | null) => { - setCollectedProps((prev) => { - const result = { ...prev }; - if (newProps === null) { - delete result[id]; - } else { - result[id] = newProps; - } - return result; - }); - }, - [], - ); - - // TEMP: combine all props into a single result: - // TODO: instead, we should intelligently aggregate all these props - const props = Object.values( - collectedProps, - ).reduce( - (result, childProps) => Object.assign(result, childProps), - {}, - ); - - const data = React.useMemo(() => { - return getData(props); - }, [props]); - - const domain = React.useMemo(() => { - return { - x: getDomain(props, "x"), - y: getDomain(props, "y"), - }; - }, [props]); - - const range = React.useMemo( - () => ({ - x: getRange(props, "x"), - y: getRange(props, "y"), - }), - [props], - ); - - const scale = React.useMemo(() => { - const xBaseScaleFn = getScale(props, "x"); - const yBaseScaleFn = getScale(props, "y"); - - // @ts-expect-error: This is a valid scale function - const xScaleFn = xBaseScaleFn().domain(domain.x).range(range.x); - // @ts-expect-error: This is a valid scale function - const yScaleFn = yBaseScaleFn().domain(domain.y).range(range.y); - - return { - x: xScaleFn, - y: yScaleFn, - }; - }, [props, domain, range]); - - const normalizedProps = React.useMemo( - () => ({ - scale, - data, - domain, - updateChildProps, - }), - [scale, data, domain, updateChildProps], - ); - - return normalizedProps; -} - -export function VictoryProvider({ - children, - // Disabled due to TODO below which will require this obj. spread - // eslint-disable-next-line @typescript-eslint/no-unused-vars - ...providerProps -}: VictoryProviderProps) { - const value = useNormalizedProps(); - - // TODO: sync the providerProps - - return ( - {children} - ); -} - -export function useVictoryContextMaybe( - selector: (value: ContextType | null) => T, -): T { - const context = useContext(VictoryContext); - return selector(context); -} - -export function useVictoryContext(selector: (value: ContextType) => T): T { - const context = useContext(VictoryContext); - if (!context) { - throw new Error("useVictoryContext must be used within a VictoryProvider"); - } - return selector(context); -} - -export function useScale() { - return useVictoryContext((value) => value.scale); -} - -export function useData() { - return useVictoryContext((value) => value.data); -} - -export function useDomain() { - return useVictoryContext((value) => value.domain); -} - -// This function keeps props in sync betwen the VictoryProvider and child components -export function useVictoryProviderSync(props: VictoryCalculatedStateProps) { - const updateChildProps = useVictoryContext((value) => value.updateChildProps); - const [myId] = React.useState(() => - Symbol("UniqueIdFor(VictoryProviderChild)"), - ); - - React.useEffect(() => { - updateChildProps(myId, props); - }, [updateChildProps, props, myId]); -} diff --git a/packages/victory-core/src/v37/victory-state/with-victory-provider.tsx b/packages/victory-core/src/v37/victory-state/with-victory-provider.tsx deleted file mode 100644 index 273efc6df..000000000 --- a/packages/victory-core/src/v37/victory-state/with-victory-provider.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import * as React from "react"; -import { useVictoryContextMaybe, VictoryProvider } from "./victory-provider"; -import { VictoryCommonProps } from "../../victory-util/common-props"; -import { Clone } from "../clone"; -import { VictoryProviderProps } from "./types"; - -/* eslint-disable react/prop-types */ - -/** - * Ensures the component is wrapped by a VictoryProvider, if not already. - */ -export function withVictoryProvider< - TComp extends React.FC, - TProps extends React.PropsWithChildren, ->(Comp: TComp): TComp { - const WithVictoryProvider = React.memo((props: TProps) => { - const updateChildProps = useVictoryContextMaybe( - (value) => value?.updateChildProps, - ); - const hasParentProvider = !!updateChildProps; - - React.useEffect(() => { - if (!hasParentProvider) return; - - const id = Symbol("WithVictoryProvider"); - updateChildProps(id, props as VictoryProviderProps); - // eslint-disable-next-line consistent-return - return () => updateChildProps(id, null); - }); - - // @ts-expect-error "TProps not assignable to LibraryManagedAttributes" - let result = {props.children}; - - if (!hasParentProvider) { - // Wrap with a parent Provider: - result = ( - - - {result} - - - ); - } - return result; - }); - const name = Comp.displayName || Comp.name; - WithVictoryProvider.displayName = name - ? `WithVictoryProvider(${name})` - : "WithVictoryProvider"; - - // @ts-expect-error "WithVictoryProvider does not overlap with TComp" - return WithVictoryProvider as TComp; -} diff --git a/packages/victory-core/src/v37/with-container.tsx b/packages/victory-core/src/v37/with-container.tsx deleted file mode 100644 index e9028c62e..000000000 --- a/packages/victory-core/src/v37/with-container.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import React from "react"; -import { VictoryProvider, VictoryProviderProps } from "./victory-state"; -import { VictoryContainer } from "../victory-container/victory-container"; -import { VictoryCommonProps } from "../victory-util/common-props"; - -const defaultProviderProps = { - width: 450, - height: 300, - padding: 50, - data: [], -}; - -export function withContainer( - WrappedComponent: React.FC, - initialProviderProps: Partial = {}, -): React.FC { - return (props: Props) => { - const providerProps = { - ...defaultProviderProps, - ...initialProviderProps, - ...props, - }; - const { standalone = true, containerComponent = } = - props; - if (standalone) { - return ( - - {React.cloneElement( - containerComponent, - providerProps, - , - )} - - ); - } - return ; - }; -} diff --git a/packages/victory-core/src/v37/with-normalized-props.test.tsx b/packages/victory-core/src/v37/with-normalized-props.test.tsx deleted file mode 100644 index 4cdd627d1..000000000 --- a/packages/victory-core/src/v37/with-normalized-props.test.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { VictoryCommonProps } from "victory-core"; -import { withNormalizedProps } from "victory-core/lib/v37/with-normalized-props"; -import PropTypes from "prop-types"; -import React from "react"; - -it("withNormalizedProps", () => { - type MyProps = VictoryCommonProps & { foo: "FOO"; bar: "BAR"; baz?: "BAZ" }; - const MyCompRaw = (props: MyProps) => { - return ( - - {[ - props.foo.toUpperCase(), - props.bar.toUpperCase(), - // @ts-expect-error "baz is possibly undefined" - props.baz.toUpperCase(), - ].join("\n")} - - ); - }; - const MyComp = withNormalizedProps( - { - displayName: "MyComp", - defaultProps: { bar: "BAR" }, - }, - MyCompRaw, - ); - - MyComp.propTypes = { - bar: PropTypes.oneOf(["BAR" as const]).isRequired, - baz: PropTypes.oneOf(["BAZ" as const]), - foo: PropTypes.oneOf(["FOO" as const]).isRequired, - }; - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - function testTypes() { - ; - ; - ; - - // All should error: - // @ts-expect-error Invalid props - ; - // @ts-expect-error Invalid props - ; - // @ts-expect-error Invalid props - ; - // @ts-expect-error Invalid props - ; - // @ts-expect-error Invalid props - ; - // @ts-expect-error Invalid props - ; - // @ts-expect-error Invalid props - ; - } -}); diff --git a/packages/victory-core/src/v37/with-normalized-props.tsx b/packages/victory-core/src/v37/with-normalized-props.tsx deleted file mode 100644 index 19231139f..000000000 --- a/packages/victory-core/src/v37/with-normalized-props.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { VictoryCommonProps } from "../victory-util/common-props"; -import React from "react"; -import { - useVictoryContext, - VictoryProviderProps, - withVictoryProvider, -} from "./victory-state"; - -type FC = (props: TProps) => JSX.Element; - -export function withNormalizedProps< - TProps extends React.PropsWithChildren, - TDefaultPropKeys extends keyof TProps, ->( - config: { - displayName: string; - propTypes?: React.WeakValidationMap>; - defaultProps: Pick; - /** @deprecated */ - initialProviderProps?: Partial; - }, - WrappedComponent: React.FC, -) { - WrappedComponent.displayName = config.displayName; - const WithNormalizedProps: FC = withVictoryProvider< - FC, - TProps - >((props: TProps) => { - const normalizedProps = useVictoryContext((v) => v); - - return ( - - {props.children} - - ); - }); - - return Object.assign(WithNormalizedProps, { - displayName: `WithNormalizedProps(${config.displayName}`, - defaultProps: config.defaultProps, - propTypes: config.propTypes, - }); -} diff --git a/packages/victory-line/src/v37/victory-line.stories.tsx b/packages/victory-line/src/v37/victory-line.stories.tsx deleted file mode 100644 index c2888cb45..000000000 --- a/packages/victory-line/src/v37/victory-line.stories.tsx +++ /dev/null @@ -1,30 +0,0 @@ -/* eslint-disable react/no-multi-comp */ -/* eslint-disable no-magic-numbers */ -import * as React from "react"; -import { VictoryLine } from "./victory-line"; -import VictoryChart from "victory-chart/es/v37/victory-chart"; -import { getData } from "../../../../stories/data"; - -export default { - title: "v37/VictoryLine", - parameters: { - chromatic: { disableSnapshot: true }, - }, - component: VictoryLine, -}; - -export const Demo = (props) => { - return ; -}; - -Demo.args = { - lineRatio: 0.5, -}; - -export const WithChart = (props) => { - return ( - - - - ); -}; diff --git a/packages/victory-line/src/v37/victory-line.tsx b/packages/victory-line/src/v37/victory-line.tsx deleted file mode 100644 index 78b85a38d..000000000 --- a/packages/victory-line/src/v37/victory-line.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import PropTypes from "prop-types"; -import React from "react"; -import { Curve, CurveProps } from "../curve"; -import { - InterpolationPropType, - VictoryClipContainer, - VictoryClipContainerProps, - VictoryCommonProps, - VictoryContainer, - VictoryDatableProps, - VictoryLabel, - VictoryLabelableProps, - VictoryLabelProps, - VictoryStyleInterface, - VictoryTheme, -} from "victory-core"; -import { withNormalizedProps, Clone } from "victory-core/es/v37"; - -export interface VictoryLineProps - extends VictoryCommonProps, - VictoryDatableProps, - VictoryLabelableProps { - // eslint-disable-next-line @typescript-eslint/ban-types - interpolation?: InterpolationPropType | Function; - samples?: number; - style?: VictoryStyleInterface; - animate?: boolean; -} - -export const VictoryLine = withNormalizedProps( - { - displayName: "VictoryLine", - propTypes: { - interpolation: PropTypes.oneOfType([ - PropTypes.oneOf([ - "basis", - "bundle", - "cardinal", - "catmullRom", - "linear", - "monotoneX", - "monotoneY", - "natural", - "step", - "stepAfter", - "stepBefore", - ] as const), - PropTypes.func, - ]), - }, - defaultProps: { - width: 450, - height: 300, - padding: 50, - data: [ - { x: 1, y: 1 }, - { x: 2, y: 2 }, - { x: 3, y: 3 }, - { x: 4, y: 4 }, - ], - containerComponent: , - dataComponent: () as React.ReactElement, - interpolation: "linear", - labelComponent: ( - - ) as React.ReactElement, - groupComponent: ( - - ) as React.ReactElement, - samples: 50, - sortKey: "x", - sortOrder: "ascending", - standalone: true, - theme: VictoryTheme.grayscale, - }, - }, - (props: VictoryLineProps) => { - return ( - - - - ); - }, -); From 4b3b417e478d44821e1ed8d837e32d23ed40dceb Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Tue, 9 Jan 2024 05:20:33 -0600 Subject: [PATCH 06/29] Correctly type props in Victory Primitives (#2695) --- .changeset/clean-needles-grow.md | 5 +++ .../src/victory-primitives/circle.tsx | 38 +++++++++++------- .../src/victory-primitives/clip-path.tsx | 14 +------ .../src/victory-primitives/line.tsx | 39 +++++++++++------- .../src/victory-primitives/path.tsx | 40 +++++++++++-------- .../src/victory-primitives/rect.tsx | 39 +++++++++++------- .../src/victory-primitives/text.tsx | 23 ++++++----- .../src/victory-primitives/tspan.tsx | 19 +++++++-- .../src/victory-util/user-props.ts | 16 +------- 9 files changed, 133 insertions(+), 100 deletions(-) create mode 100644 .changeset/clean-needles-grow.md diff --git a/.changeset/clean-needles-grow.md b/.changeset/clean-needles-grow.md new file mode 100644 index 000000000..393f7dcc9 --- /dev/null +++ b/.changeset/clean-needles-grow.md @@ -0,0 +1,5 @@ +--- +"victory-core": patch +--- + +Correctly type props in Victory Primitives diff --git a/packages/victory-core/src/victory-primitives/circle.tsx b/packages/victory-core/src/victory-primitives/circle.tsx index 6ab394c1e..2d9f45897 100644 --- a/packages/victory-core/src/victory-primitives/circle.tsx +++ b/packages/victory-core/src/victory-primitives/circle.tsx @@ -1,16 +1,26 @@ -import React from "react"; +import React, { forwardRef } from "react"; +import { evaluateProp } from "../victory-util/helpers"; import { VictoryPrimitiveShapeProps } from "./types"; -export const Circle = (props: VictoryPrimitiveShapeProps) => { - // eslint-disable-next-line react/prop-types - const { desc, ...rest } = props; - return desc ? ( - // @ts-expect-error FIXME: "id cannot be a number" - - {desc} - - ) : ( - // @ts-expect-error FIXME: "id cannot be a number" - - ); -}; +export const Circle = forwardRef( + (props, ref) => { + /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- + * origin conflicts with the SVG element's origin attribute + */ + const { desc, id, tabIndex, origin, ...rest } = props; + + const svgProps: React.SVGProps = { + vectorEffect: "non-scaling-stroke", + id: evaluateProp(id, props)?.toString(), + tabIndex: evaluateProp(tabIndex, props), + ...rest, + }; + return desc ? ( + + {desc} + + ) : ( + + ); + }, +); diff --git a/packages/victory-core/src/victory-primitives/clip-path.tsx b/packages/victory-core/src/victory-primitives/clip-path.tsx index 57a62205c..708feb60e 100644 --- a/packages/victory-core/src/victory-primitives/clip-path.tsx +++ b/packages/victory-core/src/victory-primitives/clip-path.tsx @@ -1,5 +1,4 @@ import React from "react"; -import PropTypes from "prop-types"; import { VictoryCommonPrimitiveProps } from "../victory-util/common-props"; export interface ClipPathProps extends VictoryCommonPrimitiveProps { @@ -9,17 +8,6 @@ export interface ClipPathProps extends VictoryCommonPrimitiveProps { export const ClipPath = (props: ClipPathProps) => ( - { - // @ts-expect-error FIXME: "id cannot be a number" - {props.children} - } + {{props.children}} ); - -ClipPath.propTypes = { - children: PropTypes.oneOfType([ - PropTypes.arrayOf(PropTypes.node), - PropTypes.node, - ]), - clipId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), -}; diff --git a/packages/victory-core/src/victory-primitives/line.tsx b/packages/victory-core/src/victory-primitives/line.tsx index b62689406..51e876179 100644 --- a/packages/victory-core/src/victory-primitives/line.tsx +++ b/packages/victory-core/src/victory-primitives/line.tsx @@ -1,16 +1,27 @@ -import React from "react"; +import React, { forwardRef } from "react"; +import { evaluateProp } from "../victory-util/helpers"; import { VictoryPrimitiveShapeProps } from "./types"; -export const Line = (props: VictoryPrimitiveShapeProps) => { - // eslint-disable-next-line react/prop-types - const { desc, ...rest } = props; - return desc ? ( - // @ts-expect-error FIXME: "id cannot be a number" - - {desc} - - ) : ( - // @ts-expect-error FIXME: "id cannot be a number" - - ); -}; +export const Line = forwardRef( + (props, ref) => { + /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- + * origin conflicts with the SVG element's origin attribute + */ + const { desc, id, tabIndex, origin, ...rest } = props; + + const svgProps: React.SVGProps = { + vectorEffect: "non-scaling-stroke", + id: evaluateProp(id, props)?.toString(), + tabIndex: evaluateProp(tabIndex, props), + ...rest, + }; + + return desc ? ( + + {desc} + + ) : ( + + ); + }, +); diff --git a/packages/victory-core/src/victory-primitives/path.tsx b/packages/victory-core/src/victory-primitives/path.tsx index c32f7aa13..98f3577f0 100644 --- a/packages/victory-core/src/victory-primitives/path.tsx +++ b/packages/victory-core/src/victory-primitives/path.tsx @@ -1,20 +1,26 @@ import React, { forwardRef } from "react"; +import { evaluateProp } from "../victory-util/helpers"; import { VictoryPrimitiveShapeProps } from "./types"; -// eslint-disable-next-line prefer-arrow-callback -export const Path = forwardRef(function Path( - props: VictoryPrimitiveShapeProps, - ref, -) { - // eslint-disable-next-line react/prop-types - const { desc, ...rest } = props; - return desc ? ( - // @ts-expect-error FIXME: "id cannot be a number" - - {desc} - - ) : ( - // @ts-expect-error FIXME: "id cannot be a number" - - ); -}); +export const Path = forwardRef( + (props, ref) => { + /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- + * origin conflicts with the SVG element's origin attribute + */ + const { desc, id, tabIndex, origin, ...rest } = props; + + const svgProps: React.SVGProps = { + id: evaluateProp(id, props)?.toString(), + tabIndex: evaluateProp(tabIndex, props), + ...rest, + }; + + return desc ? ( + + {desc} + + ) : ( + + ); + }, +); diff --git a/packages/victory-core/src/victory-primitives/rect.tsx b/packages/victory-core/src/victory-primitives/rect.tsx index 7db46bbbd..d4f688cbc 100644 --- a/packages/victory-core/src/victory-primitives/rect.tsx +++ b/packages/victory-core/src/victory-primitives/rect.tsx @@ -1,16 +1,27 @@ -import React from "react"; +import React, { forwardRef } from "react"; +import { evaluateProp } from "../victory-util/helpers"; import { VictoryPrimitiveShapeProps } from "./types"; -export const Rect = (props: VictoryPrimitiveShapeProps) => { - // eslint-disable-next-line react/prop-types - const { desc, ...rest } = props; - return desc ? ( - // @ts-expect-error FIXME: "id cannot be a number" - - {desc} - - ) : ( - // @ts-expect-error FIXME: "id cannot be a number" - - ); -}; +export const Rect = forwardRef( + (props, ref) => { + /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- + * origin conflicts with the SVG element's origin attribute + */ + const { desc, id, tabIndex, origin, ...rest } = props; + + const svgProps: React.SVGProps = { + vectorEffect: "non-scaling-stroke", + id: evaluateProp(id, props)?.toString(), + tabIndex: evaluateProp(tabIndex, props), + ...rest, + }; + + return desc ? ( + + {desc} + + ) : ( + + ); + }, +); diff --git a/packages/victory-core/src/victory-primitives/text.tsx b/packages/victory-core/src/victory-primitives/text.tsx index c617b3d16..301055ec2 100644 --- a/packages/victory-core/src/victory-primitives/text.tsx +++ b/packages/victory-core/src/victory-primitives/text.tsx @@ -1,5 +1,5 @@ import React from "react"; -import PropTypes from "prop-types"; +import { evaluateProp } from "../victory-util/helpers"; import { VictoryCommonPrimitiveProps } from "../victory-util/common-props"; export interface TextProps extends VictoryCommonPrimitiveProps { @@ -9,19 +9,22 @@ export interface TextProps extends VictoryCommonPrimitiveProps { } export const Text = (props: TextProps) => { - const { children, title, desc, ...rest } = props; + /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- + * origin conflicts with the SVG element's origin attribute + */ + const { children, desc, id, origin, tabIndex, title, ...rest } = props; + + const svgProps: React.SVGProps = { + id: evaluateProp(id, props)?.toString(), + tabIndex: evaluateProp(tabIndex, props), + ...rest, + }; + return ( - // @ts-expect-error FIXME: "id cannot be a number" - + {title && {title}} {desc && {desc}} {children} ); }; - -Text.propTypes = { - children: PropTypes.node, - desc: PropTypes.string, - title: PropTypes.string, -}; diff --git a/packages/victory-core/src/victory-primitives/tspan.tsx b/packages/victory-core/src/victory-primitives/tspan.tsx index 13ea27fae..48936dd60 100644 --- a/packages/victory-core/src/victory-primitives/tspan.tsx +++ b/packages/victory-core/src/victory-primitives/tspan.tsx @@ -1,7 +1,18 @@ import React from "react"; +import { evaluateProp } from "../victory-util/helpers"; import { VictoryCommonPrimitiveProps } from "../victory-util/common-props"; -export const TSpan = (props: VictoryCommonPrimitiveProps) => ( - // @ts-expect-error FIXME: "id cannot be a number" - -); +export const TSpan = (props: VictoryCommonPrimitiveProps) => { + /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- + * origin conflicts with the SVG element's origin attribute + */ + const { desc, id, tabIndex, origin, ...rest } = props; + + const svgProps: React.SVGProps = { + id: evaluateProp(id, props)?.toString(), + tabIndex: evaluateProp(tabIndex, props), + ...rest, + }; + + return ; +}; diff --git a/packages/victory-core/src/victory-util/user-props.ts b/packages/victory-core/src/victory-util/user-props.ts index dd75b5df3..2e86ca01a 100644 --- a/packages/victory-core/src/victory-util/user-props.ts +++ b/packages/victory-core/src/victory-util/user-props.ts @@ -1,4 +1,5 @@ import * as React from "react"; +import { evaluateProp } from "./helpers"; /* USER_PROPS_SAFELIST is to contain any string deemed safe for user props. @@ -54,19 +55,6 @@ const testIfSafeProp = (key: string): key is SafeAttribute => { return false; }; -/** - * Gets the value from props if a function value is provided - * @param {any} value: maybe function value - * @param {Object} props: props object - * @returns {any} newValue - */ -const getValue = (value, props) => { - if (typeof value === "function") { - return value(props); - } - return value; -}; - /** * getSafeUserProps - function that takes in a props object and removes any * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST @@ -83,7 +71,7 @@ export const getSafeUserProps = ( Object.entries(propsToFilter) .filter(([key]) => testIfSafeProp(key)) .map(([key, value]) => { - return [key, getValue(value, props)]; + return [key, evaluateProp(value, props)]; }), ); }; From 491d0fdb34a72b8b3bb1890561c75cf12fcef834 Mon Sep 17 00:00:00 2001 From: victory-ci <67923435+victory-ci@users.noreply.github.com> Date: Tue, 9 Jan 2024 06:20:06 -0600 Subject: [PATCH 07/29] Version Packages (#2682) Co-authored-by: github-actions[bot] --- .changeset/eleven-waves-attend.md | 17 -- .changeset/green-parents-argue.md | 6 - .changeset/slimy-guests-accept.md | 8 - .changeset/tender-insects-rest.md | 5 - .changeset/warm-rocks-rest.md | 5 - packages/victory-area/CHANGELOG.md | 6 + packages/victory-area/package.json | 6 +- packages/victory-axis/CHANGELOG.md | 2 + packages/victory-axis/package.json | 4 +- packages/victory-bar/CHANGELOG.md | 10 + packages/victory-bar/package.json | 6 +- packages/victory-box-plot/CHANGELOG.md | 2 + packages/victory-box-plot/package.json | 8 +- packages/victory-brush-container/CHANGELOG.md | 2 + packages/victory-brush-container/package.json | 4 +- packages/victory-brush-line/CHANGELOG.md | 2 + packages/victory-brush-line/package.json | 4 +- packages/victory-candlestick/CHANGELOG.md | 6 + packages/victory-candlestick/package.json | 6 +- packages/victory-canvas/CHANGELOG.md | 2 + packages/victory-canvas/package.json | 6 +- packages/victory-chart/CHANGELOG.md | 12 + packages/victory-chart/package.json | 10 +- packages/victory-core/CHANGELOG.md | 14 ++ packages/victory-core/package.json | 4 +- .../victory-create-container/CHANGELOG.md | 2 + .../victory-create-container/package.json | 14 +- .../victory-cursor-container/CHANGELOG.md | 2 + .../victory-cursor-container/package.json | 4 +- packages/victory-errorbar/CHANGELOG.md | 6 + packages/victory-errorbar/package.json | 4 +- packages/victory-group/CHANGELOG.md | 6 + packages/victory-group/package.json | 6 +- packages/victory-histogram/CHANGELOG.md | 2 + packages/victory-histogram/package.json | 8 +- packages/victory-legend/CHANGELOG.md | 6 + packages/victory-legend/package.json | 4 +- packages/victory-line/CHANGELOG.md | 10 + packages/victory-line/package.json | 6 +- packages/victory-native/CHANGELOG.md | 6 + packages/victory-native/package.json | 56 ++--- packages/victory-pie/CHANGELOG.md | 6 + packages/victory-pie/package.json | 6 +- packages/victory-polar-axis/CHANGELOG.md | 2 + packages/victory-polar-axis/package.json | 4 +- packages/victory-scatter/CHANGELOG.md | 2 + packages/victory-scatter/package.json | 4 +- .../victory-selection-container/CHANGELOG.md | 2 + .../victory-selection-container/package.json | 6 +- packages/victory-shared-events/CHANGELOG.md | 2 + packages/victory-shared-events/package.json | 4 +- packages/victory-stack/CHANGELOG.md | 6 + packages/victory-stack/package.json | 6 +- packages/victory-tooltip/CHANGELOG.md | 6 + packages/victory-tooltip/package.json | 4 +- packages/victory-vendor/CHANGELOG.md | 2 + packages/victory-vendor/package.json | 2 +- .../victory-voronoi-container/CHANGELOG.md | 2 + .../victory-voronoi-container/package.json | 6 +- packages/victory-voronoi/CHANGELOG.md | 6 + packages/victory-voronoi/package.json | 4 +- packages/victory-zoom-container/CHANGELOG.md | 2 + packages/victory-zoom-container/package.json | 4 +- packages/victory/CHANGELOG.md | 2 + packages/victory/package.json | 56 ++--- pnpm-lock.yaml | 206 +++++++++--------- 66 files changed, 374 insertions(+), 277 deletions(-) delete mode 100644 .changeset/eleven-waves-attend.md delete mode 100644 .changeset/green-parents-argue.md delete mode 100644 .changeset/slimy-guests-accept.md delete mode 100644 .changeset/tender-insects-rest.md delete mode 100644 .changeset/warm-rocks-rest.md diff --git a/.changeset/eleven-waves-attend.md b/.changeset/eleven-waves-attend.md deleted file mode 100644 index 177529684..000000000 --- a/.changeset/eleven-waves-attend.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -"victory-area": patch -"victory-bar": patch -"victory-candlestick": patch -"victory-chart": patch -"victory-core": patch -"victory-errorbar": patch -"victory-group": patch -"victory-line": patch -"victory-native": patch -"victory-pie": patch -"victory-stack": patch -"victory-tooltip": patch -"victory-voronoi": patch ---- - -Remove usage of defaultProps from components diff --git a/.changeset/green-parents-argue.md b/.changeset/green-parents-argue.md deleted file mode 100644 index 5caabf365..000000000 --- a/.changeset/green-parents-argue.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"victory-chart": patch -"victory-core": patch ---- - -Fixed issue where VictoryChart would throw an unhandled exception when passed non-element children (fixes #2391) diff --git a/.changeset/slimy-guests-accept.md b/.changeset/slimy-guests-accept.md deleted file mode 100644 index dea8131a2..000000000 --- a/.changeset/slimy-guests-accept.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"victory-bar": minor -"victory-chart": minor -"victory-core": minor -"victory-line": minor ---- - -Remove v37 experimental code diff --git a/.changeset/tender-insects-rest.md b/.changeset/tender-insects-rest.md deleted file mode 100644 index a6f73b7b6..000000000 --- a/.changeset/tender-insects-rest.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-core": patch ---- - -Fix text label measurements after SSR hydration mismatch diff --git a/.changeset/warm-rocks-rest.md b/.changeset/warm-rocks-rest.md deleted file mode 100644 index c50bfb056..000000000 --- a/.changeset/warm-rocks-rest.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-legend": patch ---- - -Add missing size property to TS definitions diff --git a/packages/victory-area/CHANGELOG.md b/packages/victory-area/CHANGELOG.md index 6293d48d7..be38004c6 100644 --- a/packages/victory-area/CHANGELOG.md +++ b/packages/victory-area/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-area +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-area/package.json b/packages/victory-area/package.json index 2e0f300e6..bca1a91cf 100644 --- a/packages/victory-area/package.json +++ b/packages/victory-area/package.json @@ -1,6 +1,6 @@ { "name": "victory-area", - "version": "36.7.0", + "version": "36.8.0", "description": "Area Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0", - "victory-vendor": "^36.7.0" + "victory-core": "^36.8.0", + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-axis/CHANGELOG.md b/packages/victory-axis/CHANGELOG.md index 42e94879c..790ad0b75 100644 --- a/packages/victory-axis/CHANGELOG.md +++ b/packages/victory-axis/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-axis +## 36.8.0 + ## 36.7.0 ### Patch Changes diff --git a/packages/victory-axis/package.json b/packages/victory-axis/package.json index cd472252e..189c49deb 100644 --- a/packages/victory-axis/package.json +++ b/packages/victory-axis/package.json @@ -1,6 +1,6 @@ { "name": "victory-axis", - "version": "36.7.0", + "version": "36.8.0", "description": "Axis Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-bar/CHANGELOG.md b/packages/victory-bar/CHANGELOG.md index a278ec8c3..332e78549 100644 --- a/packages/victory-bar/CHANGELOG.md +++ b/packages/victory-bar/CHANGELOG.md @@ -1,5 +1,15 @@ # victory-bar +## 36.8.0 + +### Minor Changes + +- Remove v37 experimental code ([#2697](https://github.com/FormidableLabs/victory/pull/2697)) + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ### Minor Changes diff --git a/packages/victory-bar/package.json b/packages/victory-bar/package.json index d4544007c..e931ae8d4 100644 --- a/packages/victory-bar/package.json +++ b/packages/victory-bar/package.json @@ -1,6 +1,6 @@ { "name": "victory-bar", - "version": "36.7.0", + "version": "36.8.0", "description": "Bar Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0", - "victory-vendor": "^36.7.0" + "victory-core": "^36.8.0", + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-box-plot/CHANGELOG.md b/packages/victory-box-plot/CHANGELOG.md index ce51a936d..b797e84c5 100644 --- a/packages/victory-box-plot/CHANGELOG.md +++ b/packages/victory-box-plot/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-box-plot +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-box-plot/package.json b/packages/victory-box-plot/package.json index 9d24a5d18..dc86f9f72 100644 --- a/packages/victory-box-plot/package.json +++ b/packages/victory-box-plot/package.json @@ -1,6 +1,6 @@ { "name": "victory-box-plot", - "version": "36.7.0", + "version": "36.8.0", "description": "Box Plot Component for Victory", "keywords": [ "data visualization", @@ -22,15 +22,15 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0", - "victory-vendor": "^36.7.0" + "victory-core": "^36.8.0", + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { "victory-box-plot": "*", - "victory-chart": "^36.7.0" + "victory-chart": "^36.8.0" }, "publishConfig": { "provenance": true diff --git a/packages/victory-brush-container/CHANGELOG.md b/packages/victory-brush-container/CHANGELOG.md index 9812869a0..96488481b 100644 --- a/packages/victory-brush-container/CHANGELOG.md +++ b/packages/victory-brush-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-brush-container +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-brush-container/package.json b/packages/victory-brush-container/package.json index ab8cdc286..56d3719cb 100644 --- a/packages/victory-brush-container/package.json +++ b/packages/victory-brush-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-brush-container", - "version": "36.7.0", + "version": "36.8.0", "description": "Interactive Brush Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-brush-line/CHANGELOG.md b/packages/victory-brush-line/CHANGELOG.md index 56e7e330a..37d4ae8d6 100644 --- a/packages/victory-brush-line/CHANGELOG.md +++ b/packages/victory-brush-line/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-brush-line +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-brush-line/package.json b/packages/victory-brush-line/package.json index 9c5a611cb..eb3bef026 100644 --- a/packages/victory-brush-line/package.json +++ b/packages/victory-brush-line/package.json @@ -1,6 +1,6 @@ { "name": "victory-brush-line", - "version": "36.7.0", + "version": "36.8.0", "description": "Interactive Brush Line Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-candlestick/CHANGELOG.md b/packages/victory-candlestick/CHANGELOG.md index 88f88e953..91b66e296 100644 --- a/packages/victory-candlestick/CHANGELOG.md +++ b/packages/victory-candlestick/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-candlestick +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-candlestick/package.json b/packages/victory-candlestick/package.json index 684c814ff..da87b402f 100644 --- a/packages/victory-candlestick/package.json +++ b/packages/victory-candlestick/package.json @@ -1,6 +1,6 @@ { "name": "victory-candlestick", - "version": "36.7.0", + "version": "36.8.0", "description": "Candlestick Component for Victory", "keywords": [ "data visualization", @@ -22,13 +22,13 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { - "victory-chart": "^36.7.0" + "victory-chart": "^36.8.0" }, "publishConfig": { "provenance": true diff --git a/packages/victory-canvas/CHANGELOG.md b/packages/victory-canvas/CHANGELOG.md index deeaf34f7..288e6509b 100644 --- a/packages/victory-canvas/CHANGELOG.md +++ b/packages/victory-canvas/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-canvas +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-canvas/package.json b/packages/victory-canvas/package.json index 4d6006da0..ccb6b8f31 100644 --- a/packages/victory-canvas/package.json +++ b/packages/victory-canvas/package.json @@ -1,6 +1,6 @@ { "name": "victory-canvas", - "version": "36.7.0", + "version": "36.8.0", "description": "HTML5 Canvas Components for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-bar": "^36.7.0", - "victory-core": "^36.7.0" + "victory-bar": "^36.8.0", + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-chart/CHANGELOG.md b/packages/victory-chart/CHANGELOG.md index ffe3e4d27..582cc0db2 100644 --- a/packages/victory-chart/CHANGELOG.md +++ b/packages/victory-chart/CHANGELOG.md @@ -1,5 +1,17 @@ # victory-chart +## 36.8.0 + +### Minor Changes + +- Remove v37 experimental code ([#2697](https://github.com/FormidableLabs/victory/pull/2697)) + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + +* Fixed issue where VictoryChart would throw an unhandled exception when passed non-element children (fixes [#2391](https://github.com/FormidableLabs/victory/issues/2391)) ([#2536](https://github.com/FormidableLabs/victory/pull/2536)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-chart/package.json b/packages/victory-chart/package.json index c9cdaf48c..c2b5b8cb9 100644 --- a/packages/victory-chart/package.json +++ b/packages/victory-chart/package.json @@ -1,6 +1,6 @@ { "name": "victory-chart", - "version": "36.7.0", + "version": "36.8.0", "description": "Chart Component for Victory", "keywords": [ "data visualization", @@ -23,10 +23,10 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-axis": "^36.7.0", - "victory-core": "^36.7.0", - "victory-polar-axis": "^36.7.0", - "victory-shared-events": "^36.7.0" + "victory-axis": "^36.8.0", + "victory-core": "^36.8.0", + "victory-polar-axis": "^36.8.0", + "victory-shared-events": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-core/CHANGELOG.md b/packages/victory-core/CHANGELOG.md index 0eeeecf6a..87e465732 100644 --- a/packages/victory-core/CHANGELOG.md +++ b/packages/victory-core/CHANGELOG.md @@ -1,5 +1,19 @@ # victory-core +## 36.8.0 + +### Minor Changes + +- Remove v37 experimental code ([#2697](https://github.com/FormidableLabs/victory/pull/2697)) + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + +* Fixed issue where VictoryChart would throw an unhandled exception when passed non-element children (fixes [#2391](https://github.com/FormidableLabs/victory/issues/2391)) ([#2536](https://github.com/FormidableLabs/victory/pull/2536)) + +- Fix text label measurements after SSR hydration mismatch ([#2626](https://github.com/FormidableLabs/victory/pull/2626)) + ## 36.7.0 ### Minor Changes diff --git a/packages/victory-core/package.json b/packages/victory-core/package.json index fa799a56f..821557054 100644 --- a/packages/victory-core/package.json +++ b/packages/victory-core/package.json @@ -1,6 +1,6 @@ { "name": "victory-core", - "version": "36.7.0", + "version": "36.8.0", "description": "Victory Core", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.21", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-vendor": "^36.7.0" + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-create-container/CHANGELOG.md b/packages/victory-create-container/CHANGELOG.md index bef914543..9a2fffeee 100644 --- a/packages/victory-create-container/CHANGELOG.md +++ b/packages/victory-create-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-create-container +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-create-container/package.json b/packages/victory-create-container/package.json index 6d4e2165d..4af9e73a0 100644 --- a/packages/victory-create-container/package.json +++ b/packages/victory-create-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-create-container", - "version": "36.7.0", + "version": "36.8.0", "description": "Container Helper for Victory", "keywords": [ "data visualization", @@ -21,12 +21,12 @@ "license": "MIT", "dependencies": { "lodash": "^4.17.19", - "victory-brush-container": "^36.7.0", - "victory-core": "^36.7.0", - "victory-cursor-container": "^36.7.0", - "victory-selection-container": "^36.7.0", - "victory-voronoi-container": "^36.7.0", - "victory-zoom-container": "^36.7.0" + "victory-brush-container": "^36.8.0", + "victory-core": "^36.8.0", + "victory-cursor-container": "^36.8.0", + "victory-selection-container": "^36.8.0", + "victory-voronoi-container": "^36.8.0", + "victory-zoom-container": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-cursor-container/CHANGELOG.md b/packages/victory-cursor-container/CHANGELOG.md index 0940ddea2..e656a5760 100644 --- a/packages/victory-cursor-container/CHANGELOG.md +++ b/packages/victory-cursor-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-cursor-container +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-cursor-container/package.json b/packages/victory-cursor-container/package.json index 789fac55d..03033f43c 100644 --- a/packages/victory-cursor-container/package.json +++ b/packages/victory-cursor-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-cursor-container", - "version": "36.7.0", + "version": "36.8.0", "description": "Interactive Cursor Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-errorbar/CHANGELOG.md b/packages/victory-errorbar/CHANGELOG.md index afc8b3bca..ba8f0e6c2 100644 --- a/packages/victory-errorbar/CHANGELOG.md +++ b/packages/victory-errorbar/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-errorbar +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-errorbar/package.json b/packages/victory-errorbar/package.json index 3c9b68fb9..f21fd680d 100644 --- a/packages/victory-errorbar/package.json +++ b/packages/victory-errorbar/package.json @@ -1,6 +1,6 @@ { "name": "victory-errorbar", - "version": "36.7.0", + "version": "36.8.0", "description": "Error Bar Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-group/CHANGELOG.md b/packages/victory-group/CHANGELOG.md index 7bcdf758f..430b2e2fd 100644 --- a/packages/victory-group/CHANGELOG.md +++ b/packages/victory-group/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-group +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-group/package.json b/packages/victory-group/package.json index 482006c74..678706780 100644 --- a/packages/victory-group/package.json +++ b/packages/victory-group/package.json @@ -1,6 +1,6 @@ { "name": "victory-group", - "version": "36.7.0", + "version": "36.8.0", "description": "Group Layout Component for Victory", "keywords": [ "data visualization", @@ -23,8 +23,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.7.0", - "victory-shared-events": "^36.7.0" + "victory-core": "^36.8.0", + "victory-shared-events": "^36.8.0" }, "devDependencies": { "victory-bar": "*", diff --git a/packages/victory-histogram/CHANGELOG.md b/packages/victory-histogram/CHANGELOG.md index a9616ff9e..d15f1c244 100644 --- a/packages/victory-histogram/CHANGELOG.md +++ b/packages/victory-histogram/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-histogram +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-histogram/package.json b/packages/victory-histogram/package.json index c01b4f077..8cf65f8eb 100644 --- a/packages/victory-histogram/package.json +++ b/packages/victory-histogram/package.json @@ -1,6 +1,6 @@ { "name": "victory-histogram", - "version": "36.7.0", + "version": "36.8.0", "description": "Histogram Component for Victory", "keywords": [ "data visualization", @@ -23,9 +23,9 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-bar": "^36.7.0", - "victory-core": "^36.7.0", - "victory-vendor": "^36.7.0" + "victory-bar": "^36.8.0", + "victory-core": "^36.8.0", + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-legend/CHANGELOG.md b/packages/victory-legend/CHANGELOG.md index e126bc4f3..e6c606c1a 100644 --- a/packages/victory-legend/CHANGELOG.md +++ b/packages/victory-legend/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-legend +## 36.8.0 + +### Patch Changes + +- Add missing size property to TS definitions ([#2523](https://github.com/FormidableLabs/victory/pull/2523)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-legend/package.json b/packages/victory-legend/package.json index f2ef745e5..00de49b61 100644 --- a/packages/victory-legend/package.json +++ b/packages/victory-legend/package.json @@ -1,6 +1,6 @@ { "name": "victory-legend", - "version": "36.7.0", + "version": "36.8.0", "description": "Legend Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-line/CHANGELOG.md b/packages/victory-line/CHANGELOG.md index a549b11cd..84169293a 100644 --- a/packages/victory-line/CHANGELOG.md +++ b/packages/victory-line/CHANGELOG.md @@ -1,5 +1,15 @@ # victory-line +## 36.8.0 + +### Minor Changes + +- Remove v37 experimental code ([#2697](https://github.com/FormidableLabs/victory/pull/2697)) + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-line/package.json b/packages/victory-line/package.json index c74bf0a67..fb3f975c8 100644 --- a/packages/victory-line/package.json +++ b/packages/victory-line/package.json @@ -1,6 +1,6 @@ { "name": "victory-line", - "version": "36.7.0", + "version": "36.8.0", "description": "Line Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0", - "victory-vendor": "^36.7.0" + "victory-core": "^36.8.0", + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-native/CHANGELOG.md b/packages/victory-native/CHANGELOG.md index b4a3bac13..121fb7d58 100644 --- a/packages/victory-native/CHANGELOG.md +++ b/packages/victory-native/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-native +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-native/package.json b/packages/victory-native/package.json index 8affbf268..15a5e2c27 100644 --- a/packages/victory-native/package.json +++ b/packages/victory-native/package.json @@ -1,6 +1,6 @@ { "name": "victory-native", - "version": "36.7.0", + "version": "36.8.0", "description": "Native Port for Victory", "keywords": [ "data visualization", @@ -27,33 +27,33 @@ "lodash": "^4.17.21", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory": "^36.7.0", - "victory-area": "^36.7.0", - "victory-axis": "^36.7.0", - "victory-bar": "^36.7.0", - "victory-box-plot": "^36.7.0", - "victory-brush-container": "^36.7.0", - "victory-brush-line": "^36.7.0", - "victory-candlestick": "^36.7.0", - "victory-chart": "^36.7.0", - "victory-core": "^36.7.0", - "victory-create-container": "^36.7.0", - "victory-cursor-container": "^36.7.0", - "victory-errorbar": "^36.7.0", - "victory-group": "^36.7.0", - "victory-histogram": "^36.7.0", - "victory-legend": "^36.7.0", - "victory-line": "^36.7.0", - "victory-pie": "^36.7.0", - "victory-polar-axis": "^36.7.0", - "victory-scatter": "^36.7.0", - "victory-selection-container": "^36.7.0", - "victory-shared-events": "^36.7.0", - "victory-stack": "^36.7.0", - "victory-tooltip": "^36.7.0", - "victory-voronoi": "^36.7.0", - "victory-voronoi-container": "^36.7.0", - "victory-zoom-container": "^36.7.0" + "victory": "^36.8.0", + "victory-area": "^36.8.0", + "victory-axis": "^36.8.0", + "victory-bar": "^36.8.0", + "victory-box-plot": "^36.8.0", + "victory-brush-container": "^36.8.0", + "victory-brush-line": "^36.8.0", + "victory-candlestick": "^36.8.0", + "victory-chart": "^36.8.0", + "victory-core": "^36.8.0", + "victory-create-container": "^36.8.0", + "victory-cursor-container": "^36.8.0", + "victory-errorbar": "^36.8.0", + "victory-group": "^36.8.0", + "victory-histogram": "^36.8.0", + "victory-legend": "^36.8.0", + "victory-line": "^36.8.0", + "victory-pie": "^36.8.0", + "victory-polar-axis": "^36.8.0", + "victory-scatter": "^36.8.0", + "victory-selection-container": "^36.8.0", + "victory-shared-events": "^36.8.0", + "victory-stack": "^36.8.0", + "victory-tooltip": "^36.8.0", + "victory-voronoi": "^36.8.0", + "victory-voronoi-container": "^36.8.0", + "victory-zoom-container": "^36.8.0" }, "devDependencies": { "@babel/core": "^7.18.9", diff --git a/packages/victory-pie/CHANGELOG.md b/packages/victory-pie/CHANGELOG.md index 23b2563cb..b395c4d26 100644 --- a/packages/victory-pie/CHANGELOG.md +++ b/packages/victory-pie/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-pie +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-pie/package.json b/packages/victory-pie/package.json index 5c7605b0b..bd71bbfd0 100644 --- a/packages/victory-pie/package.json +++ b/packages/victory-pie/package.json @@ -1,6 +1,6 @@ { "name": "victory-pie", - "version": "36.7.0", + "version": "36.8.0", "description": "Pie Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0", - "victory-vendor": "^36.7.0" + "victory-core": "^36.8.0", + "victory-vendor": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-polar-axis/CHANGELOG.md b/packages/victory-polar-axis/CHANGELOG.md index 7c00fc30d..a1c59a5fb 100644 --- a/packages/victory-polar-axis/CHANGELOG.md +++ b/packages/victory-polar-axis/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-polar-axis +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-polar-axis/package.json b/packages/victory-polar-axis/package.json index f2e46a9c0..0d9ca9bdf 100644 --- a/packages/victory-polar-axis/package.json +++ b/packages/victory-polar-axis/package.json @@ -1,6 +1,6 @@ { "name": "victory-polar-axis", - "version": "36.7.0", + "version": "36.8.0", "description": "Polar Axis Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-scatter/CHANGELOG.md b/packages/victory-scatter/CHANGELOG.md index 724f16274..2e2664ca7 100644 --- a/packages/victory-scatter/CHANGELOG.md +++ b/packages/victory-scatter/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-scatter +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-scatter/package.json b/packages/victory-scatter/package.json index bf2eb62d5..705cade59 100644 --- a/packages/victory-scatter/package.json +++ b/packages/victory-scatter/package.json @@ -1,6 +1,6 @@ { "name": "victory-scatter", - "version": "36.7.0", + "version": "36.8.0", "description": "Scatter Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-selection-container/CHANGELOG.md b/packages/victory-selection-container/CHANGELOG.md index 1b572fd69..888617127 100644 --- a/packages/victory-selection-container/CHANGELOG.md +++ b/packages/victory-selection-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-selection-container +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-selection-container/package.json b/packages/victory-selection-container/package.json index 32bdbfe47..dcb1e9a1a 100644 --- a/packages/victory-selection-container/package.json +++ b/packages/victory-selection-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-selection-container", - "version": "36.7.0", + "version": "36.8.0", "description": "Interactive Selection Component for Victory", "keywords": [ "data visualization", @@ -22,13 +22,13 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { - "victory-bar": "^36.7.0" + "victory-bar": "^36.8.0" }, "publishConfig": { "provenance": true diff --git a/packages/victory-shared-events/CHANGELOG.md b/packages/victory-shared-events/CHANGELOG.md index 42d441315..ccc7abf73 100644 --- a/packages/victory-shared-events/CHANGELOG.md +++ b/packages/victory-shared-events/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-shared-events +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-shared-events/package.json b/packages/victory-shared-events/package.json index 404f8ff82..f23ff2ef9 100644 --- a/packages/victory-shared-events/package.json +++ b/packages/victory-shared-events/package.json @@ -1,6 +1,6 @@ { "name": "victory-shared-events", - "version": "36.7.0", + "version": "36.8.0", "description": "Shared Event Helper for Victory", "keywords": [ "data visualization", @@ -24,7 +24,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-stack/CHANGELOG.md b/packages/victory-stack/CHANGELOG.md index ff783de77..25be091a3 100644 --- a/packages/victory-stack/CHANGELOG.md +++ b/packages/victory-stack/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-stack +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-stack/package.json b/packages/victory-stack/package.json index 33a9c8335..d703e8765 100644 --- a/packages/victory-stack/package.json +++ b/packages/victory-stack/package.json @@ -1,6 +1,6 @@ { "name": "victory-stack", - "version": "36.7.0", + "version": "36.8.0", "description": "Stack Layout Component for Victory", "keywords": [ "data visualization", @@ -23,8 +23,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.7.0", - "victory-shared-events": "^36.7.0" + "victory-core": "^36.8.0", + "victory-shared-events": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-tooltip/CHANGELOG.md b/packages/victory-tooltip/CHANGELOG.md index 52e5c52e4..57dcb8ee0 100644 --- a/packages/victory-tooltip/CHANGELOG.md +++ b/packages/victory-tooltip/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-tooltip +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-tooltip/package.json b/packages/victory-tooltip/package.json index 5f875f7a3..2f919da68 100644 --- a/packages/victory-tooltip/package.json +++ b/packages/victory-tooltip/package.json @@ -1,6 +1,6 @@ { "name": "victory-tooltip", - "version": "36.7.0", + "version": "36.8.0", "description": "Tooltip Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-vendor/CHANGELOG.md b/packages/victory-vendor/CHANGELOG.md index cc07993b9..ac4cc4b59 100644 --- a/packages/victory-vendor/CHANGELOG.md +++ b/packages/victory-vendor/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-vendor +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-vendor/package.json b/packages/victory-vendor/package.json index abe628844..3b71ec0f0 100644 --- a/packages/victory-vendor/package.json +++ b/packages/victory-vendor/package.json @@ -1,6 +1,6 @@ { "name": "victory-vendor", - "version": "36.7.0", + "version": "36.8.0", "description": "Vendored dependencies for Victory", "keywords": [ "data visualization", diff --git a/packages/victory-voronoi-container/CHANGELOG.md b/packages/victory-voronoi-container/CHANGELOG.md index a5f36c071..e1c5a6fec 100644 --- a/packages/victory-voronoi-container/CHANGELOG.md +++ b/packages/victory-voronoi-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-voronoi-container +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-voronoi-container/package.json b/packages/victory-voronoi-container/package.json index 84ed5df08..ac0939345 100644 --- a/packages/victory-voronoi-container/package.json +++ b/packages/victory-voronoi-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-voronoi-container", - "version": "36.7.0", + "version": "36.8.0", "description": "Interactive Voronoi Mouseover Component for Victory", "keywords": [ "data visualization", @@ -24,8 +24,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.7.0", - "victory-tooltip": "^36.7.0" + "victory-core": "^36.8.0", + "victory-tooltip": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-voronoi/CHANGELOG.md b/packages/victory-voronoi/CHANGELOG.md index 59c607aaa..0b074de82 100644 --- a/packages/victory-voronoi/CHANGELOG.md +++ b/packages/victory-voronoi/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-voronoi +## 36.8.0 + +### Patch Changes + +- Remove usage of defaultProps from components ([#2679](https://github.com/FormidableLabs/victory/pull/2679)) + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-voronoi/package.json b/packages/victory-voronoi/package.json index 0a88e5fcf..76eef1dfd 100644 --- a/packages/victory-voronoi/package.json +++ b/packages/victory-voronoi/package.json @@ -1,6 +1,6 @@ { "name": "victory-voronoi", - "version": "36.7.0", + "version": "36.8.0", "description": "Voronoi Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "d3-voronoi": "^1.1.4", "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-zoom-container/CHANGELOG.md b/packages/victory-zoom-container/CHANGELOG.md index ef05f1f0c..31acec254 100644 --- a/packages/victory-zoom-container/CHANGELOG.md +++ b/packages/victory-zoom-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-zoom-container +## 36.8.0 + ## 36.7.0 ## 36.6.12 diff --git a/packages/victory-zoom-container/package.json b/packages/victory-zoom-container/package.json index bcc60980f..683b473bb 100644 --- a/packages/victory-zoom-container/package.json +++ b/packages/victory-zoom-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-zoom-container", - "version": "36.7.0", + "version": "36.8.0", "description": "Interactive Zoom Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.7.0" + "victory-core": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory/CHANGELOG.md b/packages/victory/CHANGELOG.md index 73cde00a3..47893f81b 100644 --- a/packages/victory/CHANGELOG.md +++ b/packages/victory/CHANGELOG.md @@ -1,5 +1,7 @@ # victory +## 36.8.0 + ## 36.7.0 ### Patch Changes diff --git a/packages/victory/package.json b/packages/victory/package.json index 7a475d923..08f9acbc9 100644 --- a/packages/victory/package.json +++ b/packages/victory/package.json @@ -1,6 +1,6 @@ { "name": "victory", - "version": "36.7.0", + "version": "36.8.0", "description": "Data viz for React", "keywords": [ "data visualization", @@ -21,33 +21,33 @@ "author": "Formidable", "license": "MIT", "dependencies": { - "victory-area": "^36.7.0", - "victory-axis": "^36.7.0", - "victory-bar": "^36.7.0", - "victory-box-plot": "^36.7.0", - "victory-brush-container": "^36.7.0", - "victory-brush-line": "^36.7.0", - "victory-candlestick": "^36.7.0", - "victory-canvas": "^36.7.0", - "victory-chart": "^36.7.0", - "victory-core": "^36.7.0", - "victory-create-container": "^36.7.0", - "victory-cursor-container": "^36.7.0", - "victory-errorbar": "^36.7.0", - "victory-group": "^36.7.0", - "victory-histogram": "^36.7.0", - "victory-legend": "^36.7.0", - "victory-line": "^36.7.0", - "victory-pie": "^36.7.0", - "victory-polar-axis": "^36.7.0", - "victory-scatter": "^36.7.0", - "victory-selection-container": "^36.7.0", - "victory-shared-events": "^36.7.0", - "victory-stack": "^36.7.0", - "victory-tooltip": "^36.7.0", - "victory-voronoi": "^36.7.0", - "victory-voronoi-container": "^36.7.0", - "victory-zoom-container": "^36.7.0" + "victory-area": "^36.8.0", + "victory-axis": "^36.8.0", + "victory-bar": "^36.8.0", + "victory-box-plot": "^36.8.0", + "victory-brush-container": "^36.8.0", + "victory-brush-line": "^36.8.0", + "victory-candlestick": "^36.8.0", + "victory-canvas": "^36.8.0", + "victory-chart": "^36.8.0", + "victory-core": "^36.8.0", + "victory-create-container": "^36.8.0", + "victory-cursor-container": "^36.8.0", + "victory-errorbar": "^36.8.0", + "victory-group": "^36.8.0", + "victory-histogram": "^36.8.0", + "victory-legend": "^36.8.0", + "victory-line": "^36.8.0", + "victory-pie": "^36.8.0", + "victory-polar-axis": "^36.8.0", + "victory-scatter": "^36.8.0", + "victory-selection-container": "^36.8.0", + "victory-shared-events": "^36.8.0", + "victory-stack": "^36.8.0", + "victory-tooltip": "^36.8.0", + "victory-voronoi": "^36.8.0", + "victory-voronoi-container": "^36.8.0", + "victory-zoom-container": "^36.8.0" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 41ce74fd6..74d3b2a9f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,33 +194,33 @@ importers: packages/victory: specifiers: victory: '*' - victory-area: ^36.7.0 - victory-axis: ^36.7.0 - victory-bar: ^36.7.0 - victory-box-plot: ^36.7.0 - victory-brush-container: ^36.7.0 - victory-brush-line: ^36.7.0 - victory-candlestick: ^36.7.0 - victory-canvas: ^36.7.0 - victory-chart: ^36.7.0 - victory-core: ^36.7.0 - victory-create-container: ^36.7.0 - victory-cursor-container: ^36.7.0 - victory-errorbar: ^36.7.0 - victory-group: ^36.7.0 - victory-histogram: ^36.7.0 - victory-legend: ^36.7.0 - victory-line: ^36.7.0 - victory-pie: ^36.7.0 - victory-polar-axis: ^36.7.0 - victory-scatter: ^36.7.0 - victory-selection-container: ^36.7.0 - victory-shared-events: ^36.7.0 - victory-stack: ^36.7.0 - victory-tooltip: ^36.7.0 - victory-voronoi: ^36.7.0 - victory-voronoi-container: ^36.7.0 - victory-zoom-container: ^36.7.0 + victory-area: ^36.8.0 + victory-axis: ^36.8.0 + victory-bar: ^36.8.0 + victory-box-plot: ^36.8.0 + victory-brush-container: ^36.8.0 + victory-brush-line: ^36.8.0 + victory-candlestick: ^36.8.0 + victory-canvas: ^36.8.0 + victory-chart: ^36.8.0 + victory-core: ^36.8.0 + victory-create-container: ^36.8.0 + victory-cursor-container: ^36.8.0 + victory-errorbar: ^36.8.0 + victory-group: ^36.8.0 + victory-histogram: ^36.8.0 + victory-legend: ^36.8.0 + victory-line: ^36.8.0 + victory-pie: ^36.8.0 + victory-polar-axis: ^36.8.0 + victory-scatter: ^36.8.0 + victory-selection-container: ^36.8.0 + victory-shared-events: ^36.8.0 + victory-stack: ^36.8.0 + victory-tooltip: ^36.8.0 + victory-voronoi: ^36.8.0 + victory-voronoi-container: ^36.8.0 + victory-zoom-container: ^36.8.0 dependencies: victory-area: link:../victory-area victory-axis: link:../victory-axis @@ -258,8 +258,8 @@ importers: prop-types: ^15.8.1 victory-area: '*' victory-chart: '*' - victory-core: ^36.7.0 - victory-vendor: ^36.7.0 + victory-core: ^36.8.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -275,7 +275,7 @@ importers: prop-types: ^15.8.1 victory-axis: '*' victory-chart: '*' - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -290,8 +290,8 @@ importers: prop-types: ^15.8.1 victory-bar: '*' victory-chart: '*' - victory-core: ^36.7.0 - victory-vendor: ^36.7.0 + victory-core: ^36.8.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -306,9 +306,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-box-plot: '*' - victory-chart: ^36.7.0 - victory-core: ^36.7.0 - victory-vendor: ^36.7.0 + victory-chart: ^36.8.0 + victory-core: ^36.8.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -324,7 +324,7 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-brush-container: '*' - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -338,7 +338,7 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -349,8 +349,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-chart: ^36.7.0 - victory-core: ^36.7.0 + victory-chart: ^36.8.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -362,8 +362,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-bar: ^36.7.0 - victory-core: ^36.7.0 + victory-bar: ^36.8.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -375,12 +375,12 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-axis: ^36.7.0 + victory-axis: ^36.8.0 victory-chart: '*' - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-line: '*' - victory-polar-axis: ^36.7.0 - victory-shared-events: ^36.7.0 + victory-polar-axis: ^36.8.0 + victory-shared-events: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -402,7 +402,7 @@ importers: victory-bar: '*' victory-core: '*' victory-line: '*' - victory-vendor: ^36.7.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -417,12 +417,12 @@ importers: packages/victory-create-container: specifiers: lodash: ^4.17.19 - victory-brush-container: ^36.7.0 - victory-core: ^36.7.0 - victory-cursor-container: ^36.7.0 - victory-selection-container: ^36.7.0 - victory-voronoi-container: ^36.7.0 - victory-zoom-container: ^36.7.0 + victory-brush-container: ^36.8.0 + victory-core: ^36.8.0 + victory-cursor-container: ^36.8.0 + victory-selection-container: ^36.8.0 + victory-voronoi-container: ^36.8.0 + victory-zoom-container: ^36.8.0 dependencies: lodash: 4.17.21 victory-brush-container: link:../victory-brush-container @@ -436,7 +436,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -446,7 +446,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-errorbar: '*' dependencies: lodash: 4.17.21 @@ -461,9 +461,9 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-bar: '*' - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-group: '*' - victory-shared-events: ^36.7.0 + victory-shared-events: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -479,9 +479,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-bar: ^36.7.0 - victory-core: ^36.7.0 - victory-vendor: ^36.7.0 + victory-bar: ^36.8.0 + victory-core: ^36.8.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -494,7 +494,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -505,9 +505,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-chart: '*' - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-line: '*' - victory-vendor: ^36.7.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -526,33 +526,33 @@ importers: react-native: ^0.65.1 react-native-gesture-handler: ^1.10.3 react-native-svg: ^12.4.3 - victory: ^36.7.0 - victory-area: ^36.7.0 - victory-axis: ^36.7.0 - victory-bar: ^36.7.0 - victory-box-plot: ^36.7.0 - victory-brush-container: ^36.7.0 - victory-brush-line: ^36.7.0 - victory-candlestick: ^36.7.0 - victory-chart: ^36.7.0 - victory-core: ^36.7.0 - victory-create-container: ^36.7.0 - victory-cursor-container: ^36.7.0 - victory-errorbar: ^36.7.0 - victory-group: ^36.7.0 - victory-histogram: ^36.7.0 - victory-legend: ^36.7.0 - victory-line: ^36.7.0 - victory-pie: ^36.7.0 - victory-polar-axis: ^36.7.0 - victory-scatter: ^36.7.0 - victory-selection-container: ^36.7.0 - victory-shared-events: ^36.7.0 - victory-stack: ^36.7.0 - victory-tooltip: ^36.7.0 - victory-voronoi: ^36.7.0 - victory-voronoi-container: ^36.7.0 - victory-zoom-container: ^36.7.0 + victory: ^36.8.0 + victory-area: ^36.8.0 + victory-axis: ^36.8.0 + victory-bar: ^36.8.0 + victory-box-plot: ^36.8.0 + victory-brush-container: ^36.8.0 + victory-brush-line: ^36.8.0 + victory-candlestick: ^36.8.0 + victory-chart: ^36.8.0 + victory-core: ^36.8.0 + victory-create-container: ^36.8.0 + victory-cursor-container: ^36.8.0 + victory-errorbar: ^36.8.0 + victory-group: ^36.8.0 + victory-histogram: ^36.8.0 + victory-legend: ^36.8.0 + victory-line: ^36.8.0 + victory-pie: ^36.8.0 + victory-polar-axis: ^36.8.0 + victory-scatter: ^36.8.0 + victory-selection-container: ^36.8.0 + victory-shared-events: ^36.8.0 + victory-stack: ^36.8.0 + victory-tooltip: ^36.8.0 + victory-voronoi: ^36.8.0 + victory-voronoi-container: ^36.8.0 + victory-zoom-container: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -594,9 +594,9 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-pie: '*' - victory-vendor: ^36.7.0 + victory-vendor: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -609,7 +609,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -619,7 +619,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-scatter: '*' dependencies: lodash: 4.17.21 @@ -632,8 +632,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-bar: ^36.7.0 - victory-core: ^36.7.0 + victory-bar: ^36.8.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -647,7 +647,7 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: json-stringify-safe: 5.0.1 lodash: 4.17.21 @@ -661,9 +661,9 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-bar: '*' - victory-core: ^36.7.0 + victory-core: ^36.8.0 victory-histogram: '*' - victory-shared-events: ^36.7.0 + victory-shared-events: ^36.8.0 victory-stack: '*' dependencies: lodash: 4.17.21 @@ -680,7 +680,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -740,7 +740,7 @@ importers: d3-voronoi: ^1.1.4 lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: d3-voronoi: 1.1.4 lodash: 4.17.21 @@ -753,8 +753,8 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.7.0 - victory-tooltip: ^36.7.0 + victory-core: ^36.8.0 + victory-tooltip: ^36.8.0 dependencies: delaunay-find: 0.0.6 lodash: 4.17.21 @@ -767,7 +767,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.7.0 + victory-core: ^36.8.0 dependencies: lodash: 4.17.21 prop-types: 15.8.1 From d8ae39a89c9a9789ca51151eb8842c64380a2bcb Mon Sep 17 00:00:00 2001 From: victory-ci <67923435+victory-ci@users.noreply.github.com> Date: Tue, 9 Jan 2024 06:41:40 -0600 Subject: [PATCH 08/29] Version Packages (#2703) Co-authored-by: github-actions[bot] --- .changeset/clean-needles-grow.md | 5 - packages/victory-area/CHANGELOG.md | 2 + packages/victory-area/package.json | 6 +- packages/victory-axis/CHANGELOG.md | 2 + packages/victory-axis/package.json | 4 +- packages/victory-bar/CHANGELOG.md | 2 + packages/victory-bar/package.json | 6 +- packages/victory-box-plot/CHANGELOG.md | 2 + packages/victory-box-plot/package.json | 8 +- packages/victory-brush-container/CHANGELOG.md | 2 + packages/victory-brush-container/package.json | 4 +- packages/victory-brush-line/CHANGELOG.md | 2 + packages/victory-brush-line/package.json | 4 +- packages/victory-candlestick/CHANGELOG.md | 2 + packages/victory-candlestick/package.json | 6 +- packages/victory-canvas/CHANGELOG.md | 2 + packages/victory-canvas/package.json | 6 +- packages/victory-chart/CHANGELOG.md | 2 + packages/victory-chart/package.json | 10 +- packages/victory-core/CHANGELOG.md | 6 + packages/victory-core/package.json | 4 +- .../victory-create-container/CHANGELOG.md | 2 + .../victory-create-container/package.json | 14 +- .../victory-cursor-container/CHANGELOG.md | 2 + .../victory-cursor-container/package.json | 4 +- packages/victory-errorbar/CHANGELOG.md | 2 + packages/victory-errorbar/package.json | 4 +- packages/victory-group/CHANGELOG.md | 2 + packages/victory-group/package.json | 6 +- packages/victory-histogram/CHANGELOG.md | 2 + packages/victory-histogram/package.json | 8 +- packages/victory-legend/CHANGELOG.md | 2 + packages/victory-legend/package.json | 4 +- packages/victory-line/CHANGELOG.md | 2 + packages/victory-line/package.json | 6 +- packages/victory-native/CHANGELOG.md | 2 + packages/victory-native/package.json | 56 ++--- packages/victory-pie/CHANGELOG.md | 2 + packages/victory-pie/package.json | 6 +- packages/victory-polar-axis/CHANGELOG.md | 2 + packages/victory-polar-axis/package.json | 4 +- packages/victory-scatter/CHANGELOG.md | 2 + packages/victory-scatter/package.json | 4 +- .../victory-selection-container/CHANGELOG.md | 2 + .../victory-selection-container/package.json | 6 +- packages/victory-shared-events/CHANGELOG.md | 2 + packages/victory-shared-events/package.json | 4 +- packages/victory-stack/CHANGELOG.md | 2 + packages/victory-stack/package.json | 6 +- packages/victory-tooltip/CHANGELOG.md | 2 + packages/victory-tooltip/package.json | 4 +- packages/victory-vendor/CHANGELOG.md | 2 + packages/victory-vendor/package.json | 2 +- .../victory-voronoi-container/CHANGELOG.md | 2 + .../victory-voronoi-container/package.json | 6 +- packages/victory-voronoi/CHANGELOG.md | 2 + packages/victory-voronoi/package.json | 4 +- packages/victory-zoom-container/CHANGELOG.md | 2 + packages/victory-zoom-container/package.json | 4 +- packages/victory/CHANGELOG.md | 2 + packages/victory/package.json | 56 ++--- pnpm-lock.yaml | 206 +++++++++--------- 62 files changed, 300 insertions(+), 241 deletions(-) delete mode 100644 .changeset/clean-needles-grow.md diff --git a/.changeset/clean-needles-grow.md b/.changeset/clean-needles-grow.md deleted file mode 100644 index 393f7dcc9..000000000 --- a/.changeset/clean-needles-grow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-core": patch ---- - -Correctly type props in Victory Primitives diff --git a/packages/victory-area/CHANGELOG.md b/packages/victory-area/CHANGELOG.md index be38004c6..f0b091061 100644 --- a/packages/victory-area/CHANGELOG.md +++ b/packages/victory-area/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-area +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-area/package.json b/packages/victory-area/package.json index bca1a91cf..ddcf1db95 100644 --- a/packages/victory-area/package.json +++ b/packages/victory-area/package.json @@ -1,6 +1,6 @@ { "name": "victory-area", - "version": "36.8.0", + "version": "36.8.1", "description": "Area Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0", - "victory-vendor": "^36.8.0" + "victory-core": "^36.8.1", + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-axis/CHANGELOG.md b/packages/victory-axis/CHANGELOG.md index 790ad0b75..d4633d26a 100644 --- a/packages/victory-axis/CHANGELOG.md +++ b/packages/victory-axis/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-axis +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-axis/package.json b/packages/victory-axis/package.json index 189c49deb..9faed546f 100644 --- a/packages/victory-axis/package.json +++ b/packages/victory-axis/package.json @@ -1,6 +1,6 @@ { "name": "victory-axis", - "version": "36.8.0", + "version": "36.8.1", "description": "Axis Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-bar/CHANGELOG.md b/packages/victory-bar/CHANGELOG.md index 332e78549..15ee7172d 100644 --- a/packages/victory-bar/CHANGELOG.md +++ b/packages/victory-bar/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-bar +## 36.8.1 + ## 36.8.0 ### Minor Changes diff --git a/packages/victory-bar/package.json b/packages/victory-bar/package.json index e931ae8d4..ae8980e04 100644 --- a/packages/victory-bar/package.json +++ b/packages/victory-bar/package.json @@ -1,6 +1,6 @@ { "name": "victory-bar", - "version": "36.8.0", + "version": "36.8.1", "description": "Bar Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0", - "victory-vendor": "^36.8.0" + "victory-core": "^36.8.1", + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-box-plot/CHANGELOG.md b/packages/victory-box-plot/CHANGELOG.md index b797e84c5..2dd66f287 100644 --- a/packages/victory-box-plot/CHANGELOG.md +++ b/packages/victory-box-plot/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-box-plot +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-box-plot/package.json b/packages/victory-box-plot/package.json index dc86f9f72..a106babbd 100644 --- a/packages/victory-box-plot/package.json +++ b/packages/victory-box-plot/package.json @@ -1,6 +1,6 @@ { "name": "victory-box-plot", - "version": "36.8.0", + "version": "36.8.1", "description": "Box Plot Component for Victory", "keywords": [ "data visualization", @@ -22,15 +22,15 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0", - "victory-vendor": "^36.8.0" + "victory-core": "^36.8.1", + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { "victory-box-plot": "*", - "victory-chart": "^36.8.0" + "victory-chart": "^36.8.1" }, "publishConfig": { "provenance": true diff --git a/packages/victory-brush-container/CHANGELOG.md b/packages/victory-brush-container/CHANGELOG.md index 96488481b..95d7add9e 100644 --- a/packages/victory-brush-container/CHANGELOG.md +++ b/packages/victory-brush-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-brush-container +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-brush-container/package.json b/packages/victory-brush-container/package.json index 56d3719cb..3d8c5628a 100644 --- a/packages/victory-brush-container/package.json +++ b/packages/victory-brush-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-brush-container", - "version": "36.8.0", + "version": "36.8.1", "description": "Interactive Brush Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-brush-line/CHANGELOG.md b/packages/victory-brush-line/CHANGELOG.md index 37d4ae8d6..b3ee0f0c7 100644 --- a/packages/victory-brush-line/CHANGELOG.md +++ b/packages/victory-brush-line/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-brush-line +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-brush-line/package.json b/packages/victory-brush-line/package.json index eb3bef026..cd17ef62d 100644 --- a/packages/victory-brush-line/package.json +++ b/packages/victory-brush-line/package.json @@ -1,6 +1,6 @@ { "name": "victory-brush-line", - "version": "36.8.0", + "version": "36.8.1", "description": "Interactive Brush Line Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-candlestick/CHANGELOG.md b/packages/victory-candlestick/CHANGELOG.md index 91b66e296..44f054bb8 100644 --- a/packages/victory-candlestick/CHANGELOG.md +++ b/packages/victory-candlestick/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-candlestick +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-candlestick/package.json b/packages/victory-candlestick/package.json index da87b402f..424f15a7e 100644 --- a/packages/victory-candlestick/package.json +++ b/packages/victory-candlestick/package.json @@ -1,6 +1,6 @@ { "name": "victory-candlestick", - "version": "36.8.0", + "version": "36.8.1", "description": "Candlestick Component for Victory", "keywords": [ "data visualization", @@ -22,13 +22,13 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { - "victory-chart": "^36.8.0" + "victory-chart": "^36.8.1" }, "publishConfig": { "provenance": true diff --git a/packages/victory-canvas/CHANGELOG.md b/packages/victory-canvas/CHANGELOG.md index 288e6509b..14f6869b1 100644 --- a/packages/victory-canvas/CHANGELOG.md +++ b/packages/victory-canvas/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-canvas +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-canvas/package.json b/packages/victory-canvas/package.json index ccb6b8f31..a1a0a29c3 100644 --- a/packages/victory-canvas/package.json +++ b/packages/victory-canvas/package.json @@ -1,6 +1,6 @@ { "name": "victory-canvas", - "version": "36.8.0", + "version": "36.8.1", "description": "HTML5 Canvas Components for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-bar": "^36.8.0", - "victory-core": "^36.8.0" + "victory-bar": "^36.8.1", + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-chart/CHANGELOG.md b/packages/victory-chart/CHANGELOG.md index 582cc0db2..bdaaff88e 100644 --- a/packages/victory-chart/CHANGELOG.md +++ b/packages/victory-chart/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-chart +## 36.8.1 + ## 36.8.0 ### Minor Changes diff --git a/packages/victory-chart/package.json b/packages/victory-chart/package.json index c2b5b8cb9..6df2219e3 100644 --- a/packages/victory-chart/package.json +++ b/packages/victory-chart/package.json @@ -1,6 +1,6 @@ { "name": "victory-chart", - "version": "36.8.0", + "version": "36.8.1", "description": "Chart Component for Victory", "keywords": [ "data visualization", @@ -23,10 +23,10 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-axis": "^36.8.0", - "victory-core": "^36.8.0", - "victory-polar-axis": "^36.8.0", - "victory-shared-events": "^36.8.0" + "victory-axis": "^36.8.1", + "victory-core": "^36.8.1", + "victory-polar-axis": "^36.8.1", + "victory-shared-events": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-core/CHANGELOG.md b/packages/victory-core/CHANGELOG.md index 87e465732..46c4a108c 100644 --- a/packages/victory-core/CHANGELOG.md +++ b/packages/victory-core/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-core +## 36.8.1 + +### Patch Changes + +- Correctly type props in Victory Primitives ([#2695](https://github.com/FormidableLabs/victory/pull/2695)) + ## 36.8.0 ### Minor Changes diff --git a/packages/victory-core/package.json b/packages/victory-core/package.json index 821557054..7bf913bd0 100644 --- a/packages/victory-core/package.json +++ b/packages/victory-core/package.json @@ -1,6 +1,6 @@ { "name": "victory-core", - "version": "36.8.0", + "version": "36.8.1", "description": "Victory Core", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.21", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-vendor": "^36.8.0" + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-create-container/CHANGELOG.md b/packages/victory-create-container/CHANGELOG.md index 9a2fffeee..2d0d03901 100644 --- a/packages/victory-create-container/CHANGELOG.md +++ b/packages/victory-create-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-create-container +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-create-container/package.json b/packages/victory-create-container/package.json index 4af9e73a0..baf2d4eb5 100644 --- a/packages/victory-create-container/package.json +++ b/packages/victory-create-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-create-container", - "version": "36.8.0", + "version": "36.8.1", "description": "Container Helper for Victory", "keywords": [ "data visualization", @@ -21,12 +21,12 @@ "license": "MIT", "dependencies": { "lodash": "^4.17.19", - "victory-brush-container": "^36.8.0", - "victory-core": "^36.8.0", - "victory-cursor-container": "^36.8.0", - "victory-selection-container": "^36.8.0", - "victory-voronoi-container": "^36.8.0", - "victory-zoom-container": "^36.8.0" + "victory-brush-container": "^36.8.1", + "victory-core": "^36.8.1", + "victory-cursor-container": "^36.8.1", + "victory-selection-container": "^36.8.1", + "victory-voronoi-container": "^36.8.1", + "victory-zoom-container": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-cursor-container/CHANGELOG.md b/packages/victory-cursor-container/CHANGELOG.md index e656a5760..f86f08198 100644 --- a/packages/victory-cursor-container/CHANGELOG.md +++ b/packages/victory-cursor-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-cursor-container +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-cursor-container/package.json b/packages/victory-cursor-container/package.json index 03033f43c..33e2356a4 100644 --- a/packages/victory-cursor-container/package.json +++ b/packages/victory-cursor-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-cursor-container", - "version": "36.8.0", + "version": "36.8.1", "description": "Interactive Cursor Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-errorbar/CHANGELOG.md b/packages/victory-errorbar/CHANGELOG.md index ba8f0e6c2..8417e94e4 100644 --- a/packages/victory-errorbar/CHANGELOG.md +++ b/packages/victory-errorbar/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-errorbar +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-errorbar/package.json b/packages/victory-errorbar/package.json index f21fd680d..da02628e8 100644 --- a/packages/victory-errorbar/package.json +++ b/packages/victory-errorbar/package.json @@ -1,6 +1,6 @@ { "name": "victory-errorbar", - "version": "36.8.0", + "version": "36.8.1", "description": "Error Bar Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-group/CHANGELOG.md b/packages/victory-group/CHANGELOG.md index 430b2e2fd..5f7ea3ba4 100644 --- a/packages/victory-group/CHANGELOG.md +++ b/packages/victory-group/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-group +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-group/package.json b/packages/victory-group/package.json index 678706780..0d329cdfa 100644 --- a/packages/victory-group/package.json +++ b/packages/victory-group/package.json @@ -1,6 +1,6 @@ { "name": "victory-group", - "version": "36.8.0", + "version": "36.8.1", "description": "Group Layout Component for Victory", "keywords": [ "data visualization", @@ -23,8 +23,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.0", - "victory-shared-events": "^36.8.0" + "victory-core": "^36.8.1", + "victory-shared-events": "^36.8.1" }, "devDependencies": { "victory-bar": "*", diff --git a/packages/victory-histogram/CHANGELOG.md b/packages/victory-histogram/CHANGELOG.md index d15f1c244..eac650651 100644 --- a/packages/victory-histogram/CHANGELOG.md +++ b/packages/victory-histogram/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-histogram +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-histogram/package.json b/packages/victory-histogram/package.json index 8cf65f8eb..3d993dd65 100644 --- a/packages/victory-histogram/package.json +++ b/packages/victory-histogram/package.json @@ -1,6 +1,6 @@ { "name": "victory-histogram", - "version": "36.8.0", + "version": "36.8.1", "description": "Histogram Component for Victory", "keywords": [ "data visualization", @@ -23,9 +23,9 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-bar": "^36.8.0", - "victory-core": "^36.8.0", - "victory-vendor": "^36.8.0" + "victory-bar": "^36.8.1", + "victory-core": "^36.8.1", + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-legend/CHANGELOG.md b/packages/victory-legend/CHANGELOG.md index e6c606c1a..6604064d9 100644 --- a/packages/victory-legend/CHANGELOG.md +++ b/packages/victory-legend/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-legend +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-legend/package.json b/packages/victory-legend/package.json index 00de49b61..6c88c6f57 100644 --- a/packages/victory-legend/package.json +++ b/packages/victory-legend/package.json @@ -1,6 +1,6 @@ { "name": "victory-legend", - "version": "36.8.0", + "version": "36.8.1", "description": "Legend Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-line/CHANGELOG.md b/packages/victory-line/CHANGELOG.md index 84169293a..b6f716c72 100644 --- a/packages/victory-line/CHANGELOG.md +++ b/packages/victory-line/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-line +## 36.8.1 + ## 36.8.0 ### Minor Changes diff --git a/packages/victory-line/package.json b/packages/victory-line/package.json index fb3f975c8..3a24c62e5 100644 --- a/packages/victory-line/package.json +++ b/packages/victory-line/package.json @@ -1,6 +1,6 @@ { "name": "victory-line", - "version": "36.8.0", + "version": "36.8.1", "description": "Line Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0", - "victory-vendor": "^36.8.0" + "victory-core": "^36.8.1", + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-native/CHANGELOG.md b/packages/victory-native/CHANGELOG.md index 121fb7d58..d37f69ef6 100644 --- a/packages/victory-native/CHANGELOG.md +++ b/packages/victory-native/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-native +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-native/package.json b/packages/victory-native/package.json index 15a5e2c27..d898fd134 100644 --- a/packages/victory-native/package.json +++ b/packages/victory-native/package.json @@ -1,6 +1,6 @@ { "name": "victory-native", - "version": "36.8.0", + "version": "36.8.1", "description": "Native Port for Victory", "keywords": [ "data visualization", @@ -27,33 +27,33 @@ "lodash": "^4.17.21", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory": "^36.8.0", - "victory-area": "^36.8.0", - "victory-axis": "^36.8.0", - "victory-bar": "^36.8.0", - "victory-box-plot": "^36.8.0", - "victory-brush-container": "^36.8.0", - "victory-brush-line": "^36.8.0", - "victory-candlestick": "^36.8.0", - "victory-chart": "^36.8.0", - "victory-core": "^36.8.0", - "victory-create-container": "^36.8.0", - "victory-cursor-container": "^36.8.0", - "victory-errorbar": "^36.8.0", - "victory-group": "^36.8.0", - "victory-histogram": "^36.8.0", - "victory-legend": "^36.8.0", - "victory-line": "^36.8.0", - "victory-pie": "^36.8.0", - "victory-polar-axis": "^36.8.0", - "victory-scatter": "^36.8.0", - "victory-selection-container": "^36.8.0", - "victory-shared-events": "^36.8.0", - "victory-stack": "^36.8.0", - "victory-tooltip": "^36.8.0", - "victory-voronoi": "^36.8.0", - "victory-voronoi-container": "^36.8.0", - "victory-zoom-container": "^36.8.0" + "victory": "^36.8.1", + "victory-area": "^36.8.1", + "victory-axis": "^36.8.1", + "victory-bar": "^36.8.1", + "victory-box-plot": "^36.8.1", + "victory-brush-container": "^36.8.1", + "victory-brush-line": "^36.8.1", + "victory-candlestick": "^36.8.1", + "victory-chart": "^36.8.1", + "victory-core": "^36.8.1", + "victory-create-container": "^36.8.1", + "victory-cursor-container": "^36.8.1", + "victory-errorbar": "^36.8.1", + "victory-group": "^36.8.1", + "victory-histogram": "^36.8.1", + "victory-legend": "^36.8.1", + "victory-line": "^36.8.1", + "victory-pie": "^36.8.1", + "victory-polar-axis": "^36.8.1", + "victory-scatter": "^36.8.1", + "victory-selection-container": "^36.8.1", + "victory-shared-events": "^36.8.1", + "victory-stack": "^36.8.1", + "victory-tooltip": "^36.8.1", + "victory-voronoi": "^36.8.1", + "victory-voronoi-container": "^36.8.1", + "victory-zoom-container": "^36.8.1" }, "devDependencies": { "@babel/core": "^7.18.9", diff --git a/packages/victory-pie/CHANGELOG.md b/packages/victory-pie/CHANGELOG.md index b395c4d26..526807525 100644 --- a/packages/victory-pie/CHANGELOG.md +++ b/packages/victory-pie/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-pie +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-pie/package.json b/packages/victory-pie/package.json index bd71bbfd0..3297dd467 100644 --- a/packages/victory-pie/package.json +++ b/packages/victory-pie/package.json @@ -1,6 +1,6 @@ { "name": "victory-pie", - "version": "36.8.0", + "version": "36.8.1", "description": "Pie Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0", - "victory-vendor": "^36.8.0" + "victory-core": "^36.8.1", + "victory-vendor": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-polar-axis/CHANGELOG.md b/packages/victory-polar-axis/CHANGELOG.md index a1c59a5fb..aeb01a6a8 100644 --- a/packages/victory-polar-axis/CHANGELOG.md +++ b/packages/victory-polar-axis/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-polar-axis +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-polar-axis/package.json b/packages/victory-polar-axis/package.json index 0d9ca9bdf..ab8f4e2a1 100644 --- a/packages/victory-polar-axis/package.json +++ b/packages/victory-polar-axis/package.json @@ -1,6 +1,6 @@ { "name": "victory-polar-axis", - "version": "36.8.0", + "version": "36.8.1", "description": "Polar Axis Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-scatter/CHANGELOG.md b/packages/victory-scatter/CHANGELOG.md index 2e2664ca7..4e9f41412 100644 --- a/packages/victory-scatter/CHANGELOG.md +++ b/packages/victory-scatter/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-scatter +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-scatter/package.json b/packages/victory-scatter/package.json index 705cade59..bfcd48507 100644 --- a/packages/victory-scatter/package.json +++ b/packages/victory-scatter/package.json @@ -1,6 +1,6 @@ { "name": "victory-scatter", - "version": "36.8.0", + "version": "36.8.1", "description": "Scatter Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-selection-container/CHANGELOG.md b/packages/victory-selection-container/CHANGELOG.md index 888617127..2d5d939cc 100644 --- a/packages/victory-selection-container/CHANGELOG.md +++ b/packages/victory-selection-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-selection-container +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-selection-container/package.json b/packages/victory-selection-container/package.json index dcb1e9a1a..8c1206e1e 100644 --- a/packages/victory-selection-container/package.json +++ b/packages/victory-selection-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-selection-container", - "version": "36.8.0", + "version": "36.8.1", "description": "Interactive Selection Component for Victory", "keywords": [ "data visualization", @@ -22,13 +22,13 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { - "victory-bar": "^36.8.0" + "victory-bar": "^36.8.1" }, "publishConfig": { "provenance": true diff --git a/packages/victory-shared-events/CHANGELOG.md b/packages/victory-shared-events/CHANGELOG.md index ccc7abf73..e66791a52 100644 --- a/packages/victory-shared-events/CHANGELOG.md +++ b/packages/victory-shared-events/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-shared-events +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-shared-events/package.json b/packages/victory-shared-events/package.json index f23ff2ef9..046f2269f 100644 --- a/packages/victory-shared-events/package.json +++ b/packages/victory-shared-events/package.json @@ -1,6 +1,6 @@ { "name": "victory-shared-events", - "version": "36.8.0", + "version": "36.8.1", "description": "Shared Event Helper for Victory", "keywords": [ "data visualization", @@ -24,7 +24,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-stack/CHANGELOG.md b/packages/victory-stack/CHANGELOG.md index 25be091a3..f2d2fd513 100644 --- a/packages/victory-stack/CHANGELOG.md +++ b/packages/victory-stack/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-stack +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-stack/package.json b/packages/victory-stack/package.json index d703e8765..567e70746 100644 --- a/packages/victory-stack/package.json +++ b/packages/victory-stack/package.json @@ -1,6 +1,6 @@ { "name": "victory-stack", - "version": "36.8.0", + "version": "36.8.1", "description": "Stack Layout Component for Victory", "keywords": [ "data visualization", @@ -23,8 +23,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.0", - "victory-shared-events": "^36.8.0" + "victory-core": "^36.8.1", + "victory-shared-events": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-tooltip/CHANGELOG.md b/packages/victory-tooltip/CHANGELOG.md index 57dcb8ee0..484bc910b 100644 --- a/packages/victory-tooltip/CHANGELOG.md +++ b/packages/victory-tooltip/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-tooltip +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-tooltip/package.json b/packages/victory-tooltip/package.json index 2f919da68..ab95bc984 100644 --- a/packages/victory-tooltip/package.json +++ b/packages/victory-tooltip/package.json @@ -1,6 +1,6 @@ { "name": "victory-tooltip", - "version": "36.8.0", + "version": "36.8.1", "description": "Tooltip Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-vendor/CHANGELOG.md b/packages/victory-vendor/CHANGELOG.md index ac4cc4b59..05ddc9111 100644 --- a/packages/victory-vendor/CHANGELOG.md +++ b/packages/victory-vendor/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-vendor +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-vendor/package.json b/packages/victory-vendor/package.json index 3b71ec0f0..816525ec6 100644 --- a/packages/victory-vendor/package.json +++ b/packages/victory-vendor/package.json @@ -1,6 +1,6 @@ { "name": "victory-vendor", - "version": "36.8.0", + "version": "36.8.1", "description": "Vendored dependencies for Victory", "keywords": [ "data visualization", diff --git a/packages/victory-voronoi-container/CHANGELOG.md b/packages/victory-voronoi-container/CHANGELOG.md index e1c5a6fec..56c1192f7 100644 --- a/packages/victory-voronoi-container/CHANGELOG.md +++ b/packages/victory-voronoi-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-voronoi-container +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-voronoi-container/package.json b/packages/victory-voronoi-container/package.json index ac0939345..7233d5c03 100644 --- a/packages/victory-voronoi-container/package.json +++ b/packages/victory-voronoi-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-voronoi-container", - "version": "36.8.0", + "version": "36.8.1", "description": "Interactive Voronoi Mouseover Component for Victory", "keywords": [ "data visualization", @@ -24,8 +24,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.0", - "victory-tooltip": "^36.8.0" + "victory-core": "^36.8.1", + "victory-tooltip": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-voronoi/CHANGELOG.md b/packages/victory-voronoi/CHANGELOG.md index 0b074de82..2cb2c6948 100644 --- a/packages/victory-voronoi/CHANGELOG.md +++ b/packages/victory-voronoi/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-voronoi +## 36.8.1 + ## 36.8.0 ### Patch Changes diff --git a/packages/victory-voronoi/package.json b/packages/victory-voronoi/package.json index 76eef1dfd..3e0b3c51b 100644 --- a/packages/victory-voronoi/package.json +++ b/packages/victory-voronoi/package.json @@ -1,6 +1,6 @@ { "name": "victory-voronoi", - "version": "36.8.0", + "version": "36.8.1", "description": "Voronoi Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "d3-voronoi": "^1.1.4", "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-zoom-container/CHANGELOG.md b/packages/victory-zoom-container/CHANGELOG.md index 31acec254..ee9d4862f 100644 --- a/packages/victory-zoom-container/CHANGELOG.md +++ b/packages/victory-zoom-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-zoom-container +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory-zoom-container/package.json b/packages/victory-zoom-container/package.json index 683b473bb..544cd7a4e 100644 --- a/packages/victory-zoom-container/package.json +++ b/packages/victory-zoom-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-zoom-container", - "version": "36.8.0", + "version": "36.8.1", "description": "Interactive Zoom Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.0" + "victory-core": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory/CHANGELOG.md b/packages/victory/CHANGELOG.md index 47893f81b..0f6774877 100644 --- a/packages/victory/CHANGELOG.md +++ b/packages/victory/CHANGELOG.md @@ -1,5 +1,7 @@ # victory +## 36.8.1 + ## 36.8.0 ## 36.7.0 diff --git a/packages/victory/package.json b/packages/victory/package.json index 08f9acbc9..6a87556dd 100644 --- a/packages/victory/package.json +++ b/packages/victory/package.json @@ -1,6 +1,6 @@ { "name": "victory", - "version": "36.8.0", + "version": "36.8.1", "description": "Data viz for React", "keywords": [ "data visualization", @@ -21,33 +21,33 @@ "author": "Formidable", "license": "MIT", "dependencies": { - "victory-area": "^36.8.0", - "victory-axis": "^36.8.0", - "victory-bar": "^36.8.0", - "victory-box-plot": "^36.8.0", - "victory-brush-container": "^36.8.0", - "victory-brush-line": "^36.8.0", - "victory-candlestick": "^36.8.0", - "victory-canvas": "^36.8.0", - "victory-chart": "^36.8.0", - "victory-core": "^36.8.0", - "victory-create-container": "^36.8.0", - "victory-cursor-container": "^36.8.0", - "victory-errorbar": "^36.8.0", - "victory-group": "^36.8.0", - "victory-histogram": "^36.8.0", - "victory-legend": "^36.8.0", - "victory-line": "^36.8.0", - "victory-pie": "^36.8.0", - "victory-polar-axis": "^36.8.0", - "victory-scatter": "^36.8.0", - "victory-selection-container": "^36.8.0", - "victory-shared-events": "^36.8.0", - "victory-stack": "^36.8.0", - "victory-tooltip": "^36.8.0", - "victory-voronoi": "^36.8.0", - "victory-voronoi-container": "^36.8.0", - "victory-zoom-container": "^36.8.0" + "victory-area": "^36.8.1", + "victory-axis": "^36.8.1", + "victory-bar": "^36.8.1", + "victory-box-plot": "^36.8.1", + "victory-brush-container": "^36.8.1", + "victory-brush-line": "^36.8.1", + "victory-candlestick": "^36.8.1", + "victory-canvas": "^36.8.1", + "victory-chart": "^36.8.1", + "victory-core": "^36.8.1", + "victory-create-container": "^36.8.1", + "victory-cursor-container": "^36.8.1", + "victory-errorbar": "^36.8.1", + "victory-group": "^36.8.1", + "victory-histogram": "^36.8.1", + "victory-legend": "^36.8.1", + "victory-line": "^36.8.1", + "victory-pie": "^36.8.1", + "victory-polar-axis": "^36.8.1", + "victory-scatter": "^36.8.1", + "victory-selection-container": "^36.8.1", + "victory-shared-events": "^36.8.1", + "victory-stack": "^36.8.1", + "victory-tooltip": "^36.8.1", + "victory-voronoi": "^36.8.1", + "victory-voronoi-container": "^36.8.1", + "victory-zoom-container": "^36.8.1" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 74d3b2a9f..c6e67ab54 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,33 +194,33 @@ importers: packages/victory: specifiers: victory: '*' - victory-area: ^36.8.0 - victory-axis: ^36.8.0 - victory-bar: ^36.8.0 - victory-box-plot: ^36.8.0 - victory-brush-container: ^36.8.0 - victory-brush-line: ^36.8.0 - victory-candlestick: ^36.8.0 - victory-canvas: ^36.8.0 - victory-chart: ^36.8.0 - victory-core: ^36.8.0 - victory-create-container: ^36.8.0 - victory-cursor-container: ^36.8.0 - victory-errorbar: ^36.8.0 - victory-group: ^36.8.0 - victory-histogram: ^36.8.0 - victory-legend: ^36.8.0 - victory-line: ^36.8.0 - victory-pie: ^36.8.0 - victory-polar-axis: ^36.8.0 - victory-scatter: ^36.8.0 - victory-selection-container: ^36.8.0 - victory-shared-events: ^36.8.0 - victory-stack: ^36.8.0 - victory-tooltip: ^36.8.0 - victory-voronoi: ^36.8.0 - victory-voronoi-container: ^36.8.0 - victory-zoom-container: ^36.8.0 + victory-area: ^36.8.1 + victory-axis: ^36.8.1 + victory-bar: ^36.8.1 + victory-box-plot: ^36.8.1 + victory-brush-container: ^36.8.1 + victory-brush-line: ^36.8.1 + victory-candlestick: ^36.8.1 + victory-canvas: ^36.8.1 + victory-chart: ^36.8.1 + victory-core: ^36.8.1 + victory-create-container: ^36.8.1 + victory-cursor-container: ^36.8.1 + victory-errorbar: ^36.8.1 + victory-group: ^36.8.1 + victory-histogram: ^36.8.1 + victory-legend: ^36.8.1 + victory-line: ^36.8.1 + victory-pie: ^36.8.1 + victory-polar-axis: ^36.8.1 + victory-scatter: ^36.8.1 + victory-selection-container: ^36.8.1 + victory-shared-events: ^36.8.1 + victory-stack: ^36.8.1 + victory-tooltip: ^36.8.1 + victory-voronoi: ^36.8.1 + victory-voronoi-container: ^36.8.1 + victory-zoom-container: ^36.8.1 dependencies: victory-area: link:../victory-area victory-axis: link:../victory-axis @@ -258,8 +258,8 @@ importers: prop-types: ^15.8.1 victory-area: '*' victory-chart: '*' - victory-core: ^36.8.0 - victory-vendor: ^36.8.0 + victory-core: ^36.8.1 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -275,7 +275,7 @@ importers: prop-types: ^15.8.1 victory-axis: '*' victory-chart: '*' - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -290,8 +290,8 @@ importers: prop-types: ^15.8.1 victory-bar: '*' victory-chart: '*' - victory-core: ^36.8.0 - victory-vendor: ^36.8.0 + victory-core: ^36.8.1 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -306,9 +306,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-box-plot: '*' - victory-chart: ^36.8.0 - victory-core: ^36.8.0 - victory-vendor: ^36.8.0 + victory-chart: ^36.8.1 + victory-core: ^36.8.1 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -324,7 +324,7 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-brush-container: '*' - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -338,7 +338,7 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -349,8 +349,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-chart: ^36.8.0 - victory-core: ^36.8.0 + victory-chart: ^36.8.1 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -362,8 +362,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-bar: ^36.8.0 - victory-core: ^36.8.0 + victory-bar: ^36.8.1 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -375,12 +375,12 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-axis: ^36.8.0 + victory-axis: ^36.8.1 victory-chart: '*' - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-line: '*' - victory-polar-axis: ^36.8.0 - victory-shared-events: ^36.8.0 + victory-polar-axis: ^36.8.1 + victory-shared-events: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -402,7 +402,7 @@ importers: victory-bar: '*' victory-core: '*' victory-line: '*' - victory-vendor: ^36.8.0 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -417,12 +417,12 @@ importers: packages/victory-create-container: specifiers: lodash: ^4.17.19 - victory-brush-container: ^36.8.0 - victory-core: ^36.8.0 - victory-cursor-container: ^36.8.0 - victory-selection-container: ^36.8.0 - victory-voronoi-container: ^36.8.0 - victory-zoom-container: ^36.8.0 + victory-brush-container: ^36.8.1 + victory-core: ^36.8.1 + victory-cursor-container: ^36.8.1 + victory-selection-container: ^36.8.1 + victory-voronoi-container: ^36.8.1 + victory-zoom-container: ^36.8.1 dependencies: lodash: 4.17.21 victory-brush-container: link:../victory-brush-container @@ -436,7 +436,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -446,7 +446,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-errorbar: '*' dependencies: lodash: 4.17.21 @@ -461,9 +461,9 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-bar: '*' - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-group: '*' - victory-shared-events: ^36.8.0 + victory-shared-events: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -479,9 +479,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-bar: ^36.8.0 - victory-core: ^36.8.0 - victory-vendor: ^36.8.0 + victory-bar: ^36.8.1 + victory-core: ^36.8.1 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -494,7 +494,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -505,9 +505,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-chart: '*' - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-line: '*' - victory-vendor: ^36.8.0 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -526,33 +526,33 @@ importers: react-native: ^0.65.1 react-native-gesture-handler: ^1.10.3 react-native-svg: ^12.4.3 - victory: ^36.8.0 - victory-area: ^36.8.0 - victory-axis: ^36.8.0 - victory-bar: ^36.8.0 - victory-box-plot: ^36.8.0 - victory-brush-container: ^36.8.0 - victory-brush-line: ^36.8.0 - victory-candlestick: ^36.8.0 - victory-chart: ^36.8.0 - victory-core: ^36.8.0 - victory-create-container: ^36.8.0 - victory-cursor-container: ^36.8.0 - victory-errorbar: ^36.8.0 - victory-group: ^36.8.0 - victory-histogram: ^36.8.0 - victory-legend: ^36.8.0 - victory-line: ^36.8.0 - victory-pie: ^36.8.0 - victory-polar-axis: ^36.8.0 - victory-scatter: ^36.8.0 - victory-selection-container: ^36.8.0 - victory-shared-events: ^36.8.0 - victory-stack: ^36.8.0 - victory-tooltip: ^36.8.0 - victory-voronoi: ^36.8.0 - victory-voronoi-container: ^36.8.0 - victory-zoom-container: ^36.8.0 + victory: ^36.8.1 + victory-area: ^36.8.1 + victory-axis: ^36.8.1 + victory-bar: ^36.8.1 + victory-box-plot: ^36.8.1 + victory-brush-container: ^36.8.1 + victory-brush-line: ^36.8.1 + victory-candlestick: ^36.8.1 + victory-chart: ^36.8.1 + victory-core: ^36.8.1 + victory-create-container: ^36.8.1 + victory-cursor-container: ^36.8.1 + victory-errorbar: ^36.8.1 + victory-group: ^36.8.1 + victory-histogram: ^36.8.1 + victory-legend: ^36.8.1 + victory-line: ^36.8.1 + victory-pie: ^36.8.1 + victory-polar-axis: ^36.8.1 + victory-scatter: ^36.8.1 + victory-selection-container: ^36.8.1 + victory-shared-events: ^36.8.1 + victory-stack: ^36.8.1 + victory-tooltip: ^36.8.1 + victory-voronoi: ^36.8.1 + victory-voronoi-container: ^36.8.1 + victory-zoom-container: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -594,9 +594,9 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-pie: '*' - victory-vendor: ^36.8.0 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -609,7 +609,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -619,7 +619,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-scatter: '*' dependencies: lodash: 4.17.21 @@ -632,8 +632,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-bar: ^36.8.0 - victory-core: ^36.8.0 + victory-bar: ^36.8.1 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -647,7 +647,7 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: json-stringify-safe: 5.0.1 lodash: 4.17.21 @@ -661,9 +661,9 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-bar: '*' - victory-core: ^36.8.0 + victory-core: ^36.8.1 victory-histogram: '*' - victory-shared-events: ^36.8.0 + victory-shared-events: ^36.8.1 victory-stack: '*' dependencies: lodash: 4.17.21 @@ -680,7 +680,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -740,7 +740,7 @@ importers: d3-voronoi: ^1.1.4 lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: d3-voronoi: 1.1.4 lodash: 4.17.21 @@ -753,8 +753,8 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.8.0 - victory-tooltip: ^36.8.0 + victory-core: ^36.8.1 + victory-tooltip: ^36.8.1 dependencies: delaunay-find: 0.0.6 lodash: 4.17.21 @@ -767,7 +767,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.0 + victory-core: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 From c4be363e8eec39c246b75c2e0e6da30734c35ba6 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Wed, 10 Jan 2024 12:22:17 +0000 Subject: [PATCH 09/29] Migrate victory-selection-container to TS (#2706) --- .changeset/orange-items-cross.md | 5 ++ .../victory-selection-container/package.json | 3 +- .../src/index.d.ts | 41 ----------- .../victory-selection-container/src/index.js | 5 -- .../victory-selection-container/src/index.ts | 2 + ...ers.test.js => selection-helpers.test.tsx} | 16 +---- ...ction-helpers.js => selection-helpers.tsx} | 57 ++++++++-------- ...ner.js => victory-selection-container.tsx} | 68 ++++++++++++------- pnpm-lock.yaml | 2 + 9 files changed, 86 insertions(+), 113 deletions(-) create mode 100644 .changeset/orange-items-cross.md delete mode 100644 packages/victory-selection-container/src/index.d.ts delete mode 100644 packages/victory-selection-container/src/index.js create mode 100644 packages/victory-selection-container/src/index.ts rename packages/victory-selection-container/src/{selection-helpers.test.js => selection-helpers.test.tsx} (82%) rename packages/victory-selection-container/src/{selection-helpers.js => selection-helpers.tsx} (89%) rename packages/victory-selection-container/src/{victory-selection-container.js => victory-selection-container.tsx} (60%) diff --git a/.changeset/orange-items-cross.md b/.changeset/orange-items-cross.md new file mode 100644 index 000000000..9aceb3dc4 --- /dev/null +++ b/.changeset/orange-items-cross.md @@ -0,0 +1,5 @@ +--- +"victory-selection-container": patch +--- + +Migrated victory-selection-container to TypeScript diff --git a/packages/victory-selection-container/package.json b/packages/victory-selection-container/package.json index 8c1206e1e..6e339830e 100644 --- a/packages/victory-selection-container/package.json +++ b/packages/victory-selection-container/package.json @@ -28,7 +28,8 @@ "react": ">=16.6.0" }, "devDependencies": { - "victory-bar": "^36.8.1" + "victory-bar": "^36.8.1", + "victory-selection-container": "*" }, "publishConfig": { "provenance": true diff --git a/packages/victory-selection-container/src/index.d.ts b/packages/victory-selection-container/src/index.d.ts deleted file mode 100644 index 1c97bee19..000000000 --- a/packages/victory-selection-container/src/index.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -import * as React from "react"; -import { VictoryContainerProps } from "victory-core"; - -interface PointsInterface { - childName?: string | string[]; - eventKey?: string | number; - data?: any; -} - -interface VictorySelectionContainerProps extends VictoryContainerProps { - activateSelectedData?: boolean; - allowSelection?: boolean; - disable?: boolean; - onSelection?: ( - points: PointsInterface[], - bounds: { x: number | Date; y: number | Date }[], - props: VictorySelectionContainerProps, - ) => void; - onSelectionCleared?: (props: VictorySelectionContainerProps) => void; - selectionBlacklist?: string[]; - selectionComponent?: React.ReactElement; - selectionDimension?: "x" | "y"; - selectionStyle?: React.CSSProperties; -} - -export class VictorySelectionContainer extends React.Component< - VictorySelectionContainerProps, - any -> {} - -export const SelectionHelpers: { - getDimension(props: any): any; - getDatasets(props: any): any; - filterDatasets(props: any, datasets: any, bounds: any): any; - getSelectedData(props: any, dataset: any): any; - onMouseDown(evt: any, targetProps: any): any; - onMouseMove(evt: any, targetProps: any): any; - onMouseUp(evt: any, targetProps: any): any; -}; - -export const selectionContainerMixin: (base: Function) => Function; diff --git a/packages/victory-selection-container/src/index.js b/packages/victory-selection-container/src/index.js deleted file mode 100644 index 1cf2803a5..000000000 --- a/packages/victory-selection-container/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { - selectionContainerMixin, - default as VictorySelectionContainer, -} from "./victory-selection-container"; -export { default as SelectionHelpers } from "./selection-helpers"; diff --git a/packages/victory-selection-container/src/index.ts b/packages/victory-selection-container/src/index.ts new file mode 100644 index 000000000..b779c7988 --- /dev/null +++ b/packages/victory-selection-container/src/index.ts @@ -0,0 +1,2 @@ +export * from "./victory-selection-container"; +export * from "./selection-helpers"; diff --git a/packages/victory-selection-container/src/selection-helpers.test.js b/packages/victory-selection-container/src/selection-helpers.test.tsx similarity index 82% rename from packages/victory-selection-container/src/selection-helpers.test.js rename to packages/victory-selection-container/src/selection-helpers.test.tsx index f3a885e4c..a7ce54b73 100644 --- a/packages/victory-selection-container/src/selection-helpers.test.js +++ b/packages/victory-selection-container/src/selection-helpers.test.tsx @@ -1,7 +1,7 @@ import { assign } from "lodash"; import React from "react"; import { VictoryBar } from "victory-bar"; -import SelectionHelpers from "victory-selection-container/lib/selection-helpers"; +import { SelectionHelpers } from "victory-selection-container"; import * as d3Scale from "victory-vendor/d3-scale"; const scale = { x: d3Scale.scaleLinear(), y: d3Scale.scaleLinear() }; @@ -47,12 +47,7 @@ describe("helpers/selection", () => { }, ]; const props = { scale, x1: 0, y1: 0, x2: 0.5, y2: 0.5 }; - const bounds = { x: [0, 1], y: [10, 15] }; - const filteredData = SelectionHelpers.filterDatasets( - props, - datasets, - bounds, - ); + const filteredData = SelectionHelpers.filterDatasets(props, datasets); expect(filteredData).toBeNull(); }); @@ -63,13 +58,8 @@ describe("helpers/selection", () => { ]; const childName = "a"; const datasets = [{ childName, data }]; - const bounds = { x: [0, 1], y: [0, 10] }; const props = { scale, x1: 0, y1: 0, x2: 0.5, y2: 0.5 }; - const filteredData = SelectionHelpers.filterDatasets( - props, - datasets, - bounds, - ); + const filteredData = SelectionHelpers.filterDatasets(props, datasets); const expected = { eventKey: [0], data: [data[0]] }; expect(filteredData).toEqual([assign({ childName }, expected)]); }); diff --git a/packages/victory-selection-container/src/selection-helpers.js b/packages/victory-selection-container/src/selection-helpers.tsx similarity index 89% rename from packages/victory-selection-container/src/selection-helpers.js rename to packages/victory-selection-container/src/selection-helpers.tsx index a3e998381..466c08ceb 100644 --- a/packages/victory-selection-container/src/selection-helpers.js +++ b/packages/victory-selection-container/src/selection-helpers.tsx @@ -1,15 +1,17 @@ -import { Selection, Data, Helpers } from "victory-core"; +import { Selection, Data, Helpers, Datum } from "victory-core"; import { assign, defaults, throttle, isFunction, includes } from "lodash"; import React from "react"; -const SelectionHelpers = { +const ON_MOUSE_MOVE_THROTTLE_MS = 16; + +class SelectionHelpersClass { getDimension(props) { const { horizontal, selectionDimension } = props; if (!horizontal || !selectionDimension) { return selectionDimension; } return selectionDimension === "x" ? "y" : "x"; - }, + } getDatasets(props) { if (props.data) { @@ -38,11 +40,11 @@ const SelectionHelpers = { iteratee, props, ); - }, + } - filterDatasets(props, datasets, bounds) { + filterDatasets(props, datasets) { const filtered = datasets.reduce((memo, dataset) => { - const selectedData = this.getSelectedData(props, dataset.data, bounds); + const selectedData = this.getSelectedData(props, dataset.data); memo = selectedData ? memo.concat({ childName: dataset.childName, @@ -53,7 +55,7 @@ const SelectionHelpers = { return memo; }, []); return filtered.length ? filtered : null; - }, + } getSelectedData(props, dataset) { const { x1, y1, x2, y2 } = props; @@ -66,8 +68,8 @@ const SelectionHelpers = { scaledPoint.y <= Math.max(y1, y2) ); }; - const eventKey = []; - const data = []; + const eventKey: number[] = []; + const data: Datum[] = []; let count = 0; for (let index = 0, len = dataset.length; index < len; index++) { const datum = dataset[index]; @@ -78,10 +80,9 @@ const SelectionHelpers = { } } return count > 0 ? { eventKey, data } : null; - }, + } - // eslint-disable-next-line complexity, max-statements - onMouseDown(evt, targetProps) { + onMouseDown = (evt, targetProps) => { evt.preventDefault(); const { activateSelectedData, allowSelection, polar, selectedData } = targetProps; @@ -126,9 +127,9 @@ const SelectionHelpers = { : []; return parentMutation.concat(...dataMutation); - }, + }; - onMouseMove(evt, targetProps) { + private handleMouseMove = (evt, targetProps) => { const { allowSelection, select, polar } = targetProps; const dimension = this.getDimension(targetProps); if (!allowSelection || !select) { @@ -150,9 +151,14 @@ const SelectionHelpers = { return { x2, y2, parentSVG }; }, }; - }, + }; + + onMouseMove = throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, { + leading: true, + trailing: false, + }); - onMouseUp(evt, targetProps) { + onMouseUp = (evt, targetProps) => { const { activateSelectedData, allowSelection, x2, y2 } = targetProps; if (!allowSelection) { return null; @@ -169,7 +175,7 @@ const SelectionHelpers = { } const datasets = this.getDatasets(targetProps); const bounds = Selection.getBounds(targetProps); - const selectedData = this.filterDatasets(targetProps, datasets, bounds); + const selectedData = this.filterDatasets(targetProps, datasets); const mutatedProps = { selectedData, datasets, @@ -209,16 +215,7 @@ const SelectionHelpers = { : []; return parentMutation.concat(dataMutation); - }, -}; - -export default { - ...SelectionHelpers, - onMouseDown: SelectionHelpers.onMouseDown.bind(SelectionHelpers), - onMouseUp: SelectionHelpers.onMouseUp.bind(SelectionHelpers), - onMouseMove: throttle( - SelectionHelpers.onMouseMove.bind(SelectionHelpers), - 16, // eslint-disable-line no-magic-numbers - { leading: true, trailing: false }, - ), -}; + }; +} + +export const SelectionHelpers = new SelectionHelpersClass(); diff --git a/packages/victory-selection-container/src/victory-selection-container.js b/packages/victory-selection-container/src/victory-selection-container.tsx similarity index 60% rename from packages/victory-selection-container/src/victory-selection-container.js rename to packages/victory-selection-container/src/victory-selection-container.tsx index 0f3f6b35e..5fcb322a4 100644 --- a/packages/victory-selection-container/src/victory-selection-container.js +++ b/packages/victory-selection-container/src/victory-selection-container.tsx @@ -1,23 +1,45 @@ -import PropTypes from "prop-types"; import React from "react"; -import { VictoryContainer, Rect } from "victory-core"; -import SelectionHelpers from "./selection-helpers"; +import { + Datum, + Rect, + VictoryContainer, + VictoryContainerProps, +} from "victory-core"; +import { SelectionHelpers } from "./selection-helpers"; -export const selectionContainerMixin = (base) => - class VictorySelectionContainer extends base { +export interface VictorySelectionContainerProps extends VictoryContainerProps { + activateSelectedData?: boolean; + allowSelection?: boolean; + disable?: boolean; + onSelection?: ( + points: { + childName?: string | string[]; + eventKey?: string | number; + data?: Datum[]; + }[], + bounds: { + x: number | Date; + y: number | Date; + }[], + props: VictorySelectionContainerProps, + ) => void; + horizontal?: boolean; + onSelectionCleared?: (props: VictorySelectionContainerProps) => void; + selectionBlacklist?: string[]; + selectionComponent?: React.ReactElement; + selectionDimension?: "x" | "y"; + selectionStyle?: React.CSSProperties; +} + +type ComponentClass = { new (props: TProps): React.Component }; + +export function selectionContainerMixin< + TBase extends ComponentClass, + TProps extends VictorySelectionContainerProps, +>(Base: TBase) { + // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." + return class VictorySelectionContainer extends Base { static displayName = "VictorySelectionContainer"; - static propTypes = { - ...VictoryContainer.propTypes, - activateSelectedData: PropTypes.bool, - allowSelection: PropTypes.bool, - disable: PropTypes.bool, - onSelection: PropTypes.func, - onSelectionCleared: PropTypes.func, - selectionBlacklist: PropTypes.arrayOf(PropTypes.string), - selectionComponent: PropTypes.element, - selectionDimension: PropTypes.oneOf(["x", "y"]), - selectionStyle: PropTypes.object, - }; static defaultProps = { ...VictoryContainer.defaultProps, activateSelectedData: true, @@ -30,7 +52,7 @@ export const selectionContainerMixin = (base) => }, }; - static defaultEvents = (props) => { + static defaultEvents = (props: TProps) => { return [ { target: "parent", @@ -90,12 +112,12 @@ export const selectionContainerMixin = (base) => } // Overrides method in VictoryContainer - getChildren(props) { + getChildren(props: TProps) { return [...React.Children.toArray(props.children), this.getRect(props)]; } }; +} -export default selectionContainerMixin(VictoryContainer); -// @ts-expect-error IMPORTANT: when converting this file to TypeScript, you must export the type as well: -// export const VictorySelectionContainer = selectionContainerMixin(VictoryContainer); -// export type VictorySelectionContainer = typeof VictorySelectionContainer; +export const VictorySelectionContainer = + selectionContainerMixin(VictoryContainer); +export type VictorySelectionContainer = typeof VictorySelectionContainer; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6e67ab54..2426bbec0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -634,12 +634,14 @@ importers: prop-types: ^15.8.1 victory-bar: ^36.8.1 victory-core: ^36.8.1 + victory-selection-container: '*' dependencies: lodash: 4.17.21 prop-types: 15.8.1 victory-core: link:../victory-core devDependencies: victory-bar: link:../victory-bar + victory-selection-container: 'link:' packages/victory-shared-events: specifiers: From 8dae5bbdc8a308f26f05f8178146984362eaa247 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Wed, 10 Jan 2024 06:40:39 -0600 Subject: [PATCH 10/29] Use parallel builds in workflow for improved CI times (#2705) --- .github/workflows/ci.yml | 60 ++++++++++++++++++++++++++++++++++++---- package.json | 6 ---- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43fa7bb23..052057f75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,8 @@ on: - main jobs: - test: - name: Check Code + build: runs-on: ubuntu-latest - env: - DISPLAY: :99.0 strategy: matrix: node-version: [16.x, 18.x] @@ -34,5 +31,56 @@ jobs: - name: Build libraries and distributions ${{ matrix.node-version }} run: pnpm build - - name: Check Code ${{ matrix.node-version }} - run: pnpm check:ci + format: + needs: [build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + with: + node-version: 18.x + + - name: Format + run: pnpm format + + lint: + needs: [build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + with: + node-version: 18.x + + - name: Lint + run: pnpm lint + + types: + needs: [build] + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16.x, 18.x] + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + with: + node-version: ${{ matrix.node-version }} + + - name: Types Check ${{ matrix.node-version }} + run: pnpm types:check + + test: + needs: [build] + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16.x, 18.x] + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + with: + node-version: ${{ matrix.node-version }} + + - name: Test ${{ matrix.node-version }} + run: pnpm jest diff --git a/package.json b/package.json index 90920854d..f4a5bc523 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,6 @@ "start": "concurrently --raw \"pnpm:build:lib:esm --watch\" \"webpack serve --config ./config/webpack/demo/webpack.config.dev.js --static demo/js --entry ./demo/js/app\"", "start:ts": "concurrently --raw \"pnpm:build:typescript --watch\" \"webpack serve --config ./config/webpack/demo/webpack.config.dev.js --static demo/ts --entry ./demo/ts/app\"", "check": "wireit", - "check:ci": "wireit", "check:debug": "cross-env WIREIT_PARALLEL=1 pnpm check", "clean:build": "rimraf coverage \"packages/*/{dist,es,lib}\"", "clean:cache": "wireit", @@ -183,11 +182,6 @@ "types:check" ] }, - "check:ci": { - "dependencies": [ - "check" - ] - }, "build": { "dependencies": [ "./packages/victory-native:build", From 9dff1f3ee5ab3ba78bc6e627d20c78d1069a7285 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Thu, 11 Jan 2024 13:33:46 +0000 Subject: [PATCH 11/29] Migrate victory-bar to TypeScript (#2709) --- .changeset/young-squids-lay.md | 5 + ...elper-methods.js => bar-helper-methods.ts} | 47 ++++++-- .../src/{bar.test.js => bar.test.tsx} | 0 packages/victory-bar/src/{bar.js => bar.tsx} | 74 ++++++------ .../src/geometry-helper-methods.js | 113 ------------------ ...est.js => geometry-helper-methods.test.ts} | 0 .../src/geometry-helper-methods.ts | 103 ++++++++++++++++ .../{helper-methods.js => helper-methods.ts} | 4 +- packages/victory-bar/src/index.d.ts | 73 ----------- .../victory-bar/src/{index.js => index.ts} | 4 +- ...lper-methods.js => path-helper-methods.ts} | 19 +-- ...ctory-bar.test.js => victory-bar.test.tsx} | 13 +- .../src/{victory-bar.js => victory-bar.tsx} | 89 +++++++++----- 13 files changed, 262 insertions(+), 282 deletions(-) create mode 100644 .changeset/young-squids-lay.md rename packages/victory-bar/src/{bar-helper-methods.js => bar-helper-methods.ts} (58%) rename packages/victory-bar/src/{bar.test.js => bar.test.tsx} (100%) rename packages/victory-bar/src/{bar.js => bar.tsx} (61%) delete mode 100644 packages/victory-bar/src/geometry-helper-methods.js rename packages/victory-bar/src/{geometry-helper-methods.test.js => geometry-helper-methods.test.ts} (100%) create mode 100644 packages/victory-bar/src/geometry-helper-methods.ts rename packages/victory-bar/src/{helper-methods.js => helper-methods.ts} (96%) delete mode 100644 packages/victory-bar/src/index.d.ts rename packages/victory-bar/src/{index.js => index.ts} (75%) rename packages/victory-bar/src/{path-helper-methods.js => path-helper-methods.ts} (97%) rename packages/victory-bar/src/{victory-bar.test.js => victory-bar.test.tsx} (95%) rename packages/victory-bar/src/{victory-bar.js => victory-bar.tsx} (52%) diff --git a/.changeset/young-squids-lay.md b/.changeset/young-squids-lay.md new file mode 100644 index 000000000..22c0c3a63 --- /dev/null +++ b/.changeset/young-squids-lay.md @@ -0,0 +1,5 @@ +--- +"victory-bar": patch +--- + +Migrate victory-bar to TypeScript diff --git a/packages/victory-bar/src/bar-helper-methods.js b/packages/victory-bar/src/bar-helper-methods.ts similarity index 58% rename from packages/victory-bar/src/bar-helper-methods.js rename to packages/victory-bar/src/bar-helper-methods.ts index 9a349b6b2..c4ffc81c5 100644 --- a/packages/victory-bar/src/bar-helper-methods.js +++ b/packages/victory-bar/src/bar-helper-methods.ts @@ -1,8 +1,18 @@ import { assign, isNil, isPlainObject } from "lodash"; -import { Helpers } from "victory-core"; +import { Helpers, VictoryStyleObject } from "victory-core"; +import { BarProps } from "./bar"; +import { + VictoryBarCornerRadiusObject, + VictoryBarCornerRadiusKey, +} from "./victory-bar"; -export const getBarWidth = (barWidth, props) => { - const { scale, data, defaultBarWidth, style } = props; +const DEFAULT_BAR_WIDTH = 8; + +export const getBarWidth = ( + barWidth: BarProps["barWidth"], + props: BarProps, +) => { + const { scale, data, style } = props; if (barWidth) { return Helpers.evaluateProp(barWidth, props); } else if (style.width) { @@ -13,18 +23,24 @@ export const getBarWidth = (barWidth, props) => { const bars = data.length + 2; const barRatio = props.barRatio || 0.5; const defaultWidth = - barRatio * (data.length < 2 ? defaultBarWidth : extent / bars); + barRatio * (data.length < 2 ? DEFAULT_BAR_WIDTH : extent / bars); return Math.max(1, defaultWidth); }; -const getCornerRadiusFromObject = (cornerRadius, props) => { - const realCornerRadius = { +const getCornerRadiusFromObject = ( + cornerRadius: VictoryBarCornerRadiusObject, + props: BarProps, +) => { + const realCornerRadius: VictoryBarCornerRadiusObject = { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 0, }; - const updateCornerRadius = (corner, fallback) => { + const updateCornerRadius = ( + corner: VictoryBarCornerRadiusKey, + fallback: "top" | "bottom", + ) => { if (!isNil(cornerRadius[corner])) { realCornerRadius[corner] = Helpers.evaluateProp( cornerRadius[corner], @@ -44,8 +60,17 @@ const getCornerRadiusFromObject = (cornerRadius, props) => { return realCornerRadius; }; -export const getCornerRadius = (cornerRadius, props) => { - const realCornerRadius = { +function isCornerRadiusObject( + cornerRadius: BarProps["cornerRadius"], +): cornerRadius is VictoryBarCornerRadiusObject { + return isPlainObject(cornerRadius); +} + +export const getCornerRadius = ( + cornerRadius: BarProps["cornerRadius"], + props: BarProps, +) => { + const realCornerRadius: VictoryBarCornerRadiusObject = { topLeft: 0, topRight: 0, bottomLeft: 0, @@ -54,7 +79,7 @@ export const getCornerRadius = (cornerRadius, props) => { if (!cornerRadius) { return realCornerRadius; } - if (isPlainObject(cornerRadius)) { + if (isCornerRadiusObject(cornerRadius)) { return getCornerRadiusFromObject(cornerRadius, props); } realCornerRadius.topLeft = Helpers.evaluateProp(cornerRadius, props); @@ -62,7 +87,7 @@ export const getCornerRadius = (cornerRadius, props) => { return realCornerRadius; }; -export const getStyle = (style = {}, props) => { +export const getStyle = (style: VictoryStyleObject = {}, props: BarProps) => { if (props.disableInlineStyles) { return {}; } diff --git a/packages/victory-bar/src/bar.test.js b/packages/victory-bar/src/bar.test.tsx similarity index 100% rename from packages/victory-bar/src/bar.test.js rename to packages/victory-bar/src/bar.test.tsx diff --git a/packages/victory-bar/src/bar.js b/packages/victory-bar/src/bar.tsx similarity index 61% rename from packages/victory-bar/src/bar.js rename to packages/victory-bar/src/bar.tsx index 20024ad83..fb81248ed 100644 --- a/packages/victory-bar/src/bar.js +++ b/packages/victory-bar/src/bar.tsx @@ -1,11 +1,36 @@ +/* eslint-disable react/prop-types */ import { assign } from "lodash"; -import PropTypes from "prop-types"; import React, { forwardRef } from "react"; -import { CommonProps, Helpers, Path } from "victory-core"; +import { + Helpers, + NumberOrCallback, + Path, + VictoryCommonPrimitiveProps, +} from "victory-core"; import { getStyle, getBarWidth, getCornerRadius } from "./bar-helper-methods"; import { getPolarBarPath, getBarPath } from "./path-helper-methods"; +import { + VictoryBarAlignmentType, + VictoryBarCornerRadiusObject, +} from "./victory-bar"; -const evaluateProps = (props) => { +export interface BarProps extends VictoryCommonPrimitiveProps { + alignment?: VictoryBarAlignmentType; + barOffset?: number[]; + barRatio?: number; + barWidth?: NumberOrCallback; + cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject; + datum?: any; + getPath?: (x: number, y: number, props: any) => string; + horizontal?: boolean; + pathComponent?: React.ReactElement; + width?: number; + x?: number; + y?: number; + y0?: number; +} + +const evaluateProps = (props: BarProps) => { /** * Potential evaluated props of following must be evaluated in this order: * 1) `style` @@ -41,14 +66,17 @@ const evaluateProps = (props) => { }); }; -const defaultProps = { - defaultBarWidth: 8, +const defaultProps: Partial = { pathComponent: , role: "presentation", shapeRendering: "auto", }; + // eslint-disable-next-line prefer-arrow-callback -const Bar = forwardRef(function Bar(props, ref) { +export const Bar = forwardRef(function Bar( + props, + ref, +) { props = evaluateProps({ ...defaultProps, ...props }); const { polar, origin, style, barWidth, cornerRadius } = props; @@ -57,6 +85,11 @@ const Bar = forwardRef(function Bar(props, ref) { : getBarPath(props, barWidth, cornerRadius); const defaultTransform = polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined; + + if (!props.pathComponent) { + return null; + } + return React.cloneElement(props.pathComponent, { ...props.events, "aria-label": props.ariaLabel, @@ -73,32 +106,3 @@ const Bar = forwardRef(function Bar(props, ref) { ref, }); }); - -Bar.propTypes = { - ...CommonProps.primitiveProps, - alignment: PropTypes.oneOf(["start", "middle", "end"]), - barRatio: PropTypes.number, - barWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - cornerRadius: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.func, - PropTypes.shape({ - top: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - }), - ]), - datum: PropTypes.object, - getPath: PropTypes.func, - horizontal: PropTypes.bool, - pathComponent: PropTypes.element, - width: PropTypes.number, - x: PropTypes.number, - y: PropTypes.number, - y0: PropTypes.number, -}; - -export default Bar; diff --git a/packages/victory-bar/src/geometry-helper-methods.js b/packages/victory-bar/src/geometry-helper-methods.js deleted file mode 100644 index 03a42b856..000000000 --- a/packages/victory-bar/src/geometry-helper-methods.js +++ /dev/null @@ -1,113 +0,0 @@ -/** - * A point in the 2d plane - * @param {number} x - x coordinate - * @param {number} y - y coordinate - * @returns {object} - point object - */ -const point = function (x, y) { - return { - x, - y, - distance(p1) { - return Math.sqrt(Math.pow(this.x - p1.x, 2) + Math.pow(this.y - p1.y, 2)); - }, - // vector addition in 2d plane - add(p1) { - return point(this.x + p1.x, this.y + p1.y); - }, - // vector subtraction in 2d - // returns p0 - p1 - subtract(p1) { - return point(this.x - p1.x, this.y - p1.y); - }, - // multiply a 2d point by a scalar - scalarMult(n) { - return point(this.x * n, this.y * n); - }, - scalarDivide(n) { - if (n === 0) { - throw new Error("Division by 0 error"); - } - return point(this.x / n, this.y / n); - }, - equals(p1) { - return this.x === p1.x && this.y === p1.y; - }, - }; -}; - -/** - * A circle in the 2d plane - * @param {point} center - center of circle - * @param {number} radius - radius of circle - * @returns {object} - point object - */ -const circle = function (center, radius) { - return { - center, - radius, - hasIntersection(circle1) { - const P0 = this.center; - const P1 = circle1.center; - const r0 = this.radius; - const r1 = circle1.radius; - const d = P0.distance(P1); - - if (d > r0 + r1) { - return false; // separate circles - } - if (d < Math.abs(r0 - r1)) { - return false; // one circle contains another - } - return true; - }, - equals(circle1) { - const P0 = this.center; - const P1 = circle1.center; - const r0 = this.radius; - const r1 = circle1.radius; - return r0 === r1 && P0.equals(P1); - }, - // Source: http://paulbourke.net/geometry/circlesphere/ - // "Intersection of two circles" by Paul Bourke - // Left-most point is returned as 0th element of array - // Right-most point is returned as 1st elemennt of array - intersection(circle1) { - // eslint-disable-line max-statements - const P0 = this.center; - const P1 = circle1.center; - const r0 = this.radius; - const r1 = circle1.radius; - const d = P0.distance(P1); - if (!this.hasIntersection(circle1) || this.equals(circle1)) { - return []; - } - const a = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d); - const h = Math.sqrt(Math.pow(r0, 2) - Math.pow(a, 2)); - const P2 = P0.add(P1.subtract(P0).scalarMult(a).scalarDivide(d)); - const { x: x0, y: y0 } = P0; - const { x: x1, y: y1 } = P1; - const { x: x2, y: y2 } = P2; - const P3s = [ - point(x2 - (h * (y1 - y0)) / d, y2 + (h * (x1 - x0)) / d), - point(x2 + (h * (y1 - y0)) / d, y2 - (h * (x1 - x0)) / d), - ]; - P3s.sort((Point1, Point2) => Point1.x - Point2.x); - return P3s; - }, - solveX(y) { - const sqrt = Math.sqrt( - Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2), - ); - return [this.center.x - sqrt, this.center.x + sqrt]; - }, - solveY(x) { - const sqrt = Math.sqrt( - Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2), - ); - return [this.center.y - sqrt, this.center.y + sqrt]; - }, - }; -}; - -export { circle, point }; diff --git a/packages/victory-bar/src/geometry-helper-methods.test.js b/packages/victory-bar/src/geometry-helper-methods.test.ts similarity index 100% rename from packages/victory-bar/src/geometry-helper-methods.test.js rename to packages/victory-bar/src/geometry-helper-methods.test.ts diff --git a/packages/victory-bar/src/geometry-helper-methods.ts b/packages/victory-bar/src/geometry-helper-methods.ts new file mode 100644 index 000000000..a56af403f --- /dev/null +++ b/packages/victory-bar/src/geometry-helper-methods.ts @@ -0,0 +1,103 @@ +/** + * A point in the 2d plane + */ +export const point = (x: number, y: number) => ({ + x, + y, + distance(p1: { x: number; y: number }) { + return Math.sqrt(Math.pow(this.x - p1.x, 2) + Math.pow(this.y - p1.y, 2)); + }, + // vector addition in 2d plane + add(p1: { x: number; y: number }) { + return point(this.x + p1.x, this.y + p1.y); + }, + // vector subtraction in 2d + // returns p0 - p1 + subtract(p1: { x: number; y: number }) { + return point(this.x - p1.x, this.y - p1.y); + }, + // multiply a 2d point by a scalar + scalarMult(n: number) { + return point(this.x * n, this.y * n); + }, + scalarDivide(n: number) { + if (n === 0) { + throw new Error("Division by 0 error"); + } + return point(this.x / n, this.y / n); + }, + equals(p1: { x: number; y: number }) { + return this.x === p1.x && this.y === p1.y; + }, +}); + +type Center = ReturnType; + +/** + * A circle in the 2d plane + */ +export const circle = (center: Center, radius: number) => ({ + center, + radius, + hasIntersection(circle1: { center: Center; radius: number }) { + const P0 = this.center; + const P1 = circle1.center; + const r0 = this.radius; + const r1 = circle1.radius; + const d = P0.distance(P1); + + if (d > r0 + r1) { + return false; // separate circles + } + if (d < Math.abs(r0 - r1)) { + return false; // one circle contains another + } + return true; + }, + equals(circle1: { center: Center; radius: number }) { + const P0 = this.center; + const P1 = circle1.center; + const r0 = this.radius; + const r1 = circle1.radius; + return r0 === r1 && P0.equals(P1); + }, + // Source: http://paulbourke.net/geometry/circlesphere/ + // "Intersection of two circles" by Paul Bourke + // Left-most point is returned as 0th element of array + // Right-most point is returned as 1st elemennt of array + intersection(circle1: { center: Center; radius: number }) { + // eslint-disable-line max-statements + const P0 = this.center; + const P1 = circle1.center; + const r0 = this.radius; + const r1 = circle1.radius; + const d = P0.distance(P1); + if (!this.hasIntersection(circle1) || this.equals(circle1)) { + return []; + } + const a = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d); + const h = Math.sqrt(Math.pow(r0, 2) - Math.pow(a, 2)); + const P2 = P0.add(P1.subtract(P0).scalarMult(a).scalarDivide(d)); + const { x: x0, y: y0 } = P0; + const { x: x1, y: y1 } = P1; + const { x: x2, y: y2 } = P2; + const P3s = [ + point(x2 - (h * (y1 - y0)) / d, y2 + (h * (x1 - x0)) / d), + point(x2 + (h * (y1 - y0)) / d, y2 - (h * (x1 - x0)) / d), + ]; + P3s.sort((Point1, Point2) => Point1.x - Point2.x); + return P3s; + }, + solveX(y: number) { + const sqrt = Math.sqrt( + Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2), + ); + return [this.center.x - sqrt, this.center.x + sqrt]; + }, + solveY(x: number) { + const sqrt = Math.sqrt( + Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2), + ); + return [this.center.y - sqrt, this.center.y + sqrt]; + }, +}); diff --git a/packages/victory-bar/src/helper-methods.js b/packages/victory-bar/src/helper-methods.ts similarity index 96% rename from packages/victory-bar/src/helper-methods.js rename to packages/victory-bar/src/helper-methods.ts index 5c1fe1ff5..70ba0eea7 100644 --- a/packages/victory-bar/src/helper-methods.js +++ b/packages/victory-bar/src/helper-methods.ts @@ -15,8 +15,8 @@ export const getBarPosition = (props, datum) => { ? 1 / Number.MAX_SAFE_INTEGER : 0; let defaultMin = defaultZero; - const minY = Collection.getMinValue(props.domain[axis]); - const maxY = Collection.getMaxValue(props.domain[axis]); + const minY = Collection.getMinValue(props.domain[axis]) as number; + const maxY = Collection.getMaxValue(props.domain[axis]) as number; if (minY < 0 && maxY <= 0) { defaultMin = maxY; diff --git a/packages/victory-bar/src/index.d.ts b/packages/victory-bar/src/index.d.ts deleted file mode 100644 index d730a4beb..000000000 --- a/packages/victory-bar/src/index.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import * as React from "react"; -import { - EventPropTypeInterface, - NumberOrCallback, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryCommonPrimitiveProps, - VictoryDatableProps, - VictoryMultiLabelableProps, - VictoryStyleInterface, -} from "victory-core"; - -export type VictoryBarTTargetType = "data" | "labels" | "parent"; -export type VictoryBarAlignmentType = "start" | "middle" | "end"; - -export interface VictoryBarProps - extends VictoryCommonProps, - VictoryDatableProps, - VictoryMultiLabelableProps { - alignment?: VictoryBarAlignmentType; - barRatio?: number; - barWidth?: NumberOrCallback; - cornerRadius?: - | NumberOrCallback - | { - top?: NumberOrCallback; - topLeft?: NumberOrCallback; - topRight?: NumberOrCallback; - bottom?: NumberOrCallback; - bottomLeft?: NumberOrCallback; - bottomRight?: NumberOrCallback; - }; - events?: EventPropTypeInterface< - VictoryBarTTargetType, - number | string | number[] | string[] - >[]; - eventKey?: StringOrNumberOrCallback; - horizontal?: boolean; - style?: VictoryStyleInterface; -} - -/** - * Draw SVG bar charts with React. VictoryBar is a composable component, so it doesn"t include axes - * Check out VictoryChart for complete bar charts and more. - */ -export class VictoryBar extends React.Component {} - -export interface BarProps extends VictoryCommonPrimitiveProps { - alignment?: VictoryBarAlignmentType; - barOffset?: number[]; - barRatio?: number; - barWidth?: NumberOrCallback; - cornerRadius?: - | NumberOrCallback - | { - top?: NumberOrCallback; - topLeft?: NumberOrCallback; - topRight?: NumberOrCallback; - bottom?: NumberOrCallback; - bottomLeft?: NumberOrCallback; - bottomRight?: NumberOrCallback; - }; - datum?: any; - getPath?: Function; - horizontal?: boolean; - pathComponent?: React.ReactElement; - width?: number; - x?: number; - y?: number; - y0?: number; -} - -export class Bar extends React.Component {} diff --git a/packages/victory-bar/src/index.js b/packages/victory-bar/src/index.ts similarity index 75% rename from packages/victory-bar/src/index.js rename to packages/victory-bar/src/index.ts index 5aef82765..203f42079 100644 --- a/packages/victory-bar/src/index.js +++ b/packages/victory-bar/src/index.ts @@ -1,5 +1,5 @@ -export { default as VictoryBar } from "./victory-bar"; -export { default as Bar } from "./bar"; +export * from "./victory-bar"; +export * from "./bar"; export { getBarPosition } from "./helper-methods"; export { getVerticalBarPath, diff --git a/packages/victory-bar/src/path-helper-methods.js b/packages/victory-bar/src/path-helper-methods.ts similarity index 97% rename from packages/victory-bar/src/path-helper-methods.js rename to packages/victory-bar/src/path-helper-methods.ts index 79d8106a0..bf9169230 100644 --- a/packages/victory-bar/src/path-helper-methods.js +++ b/packages/victory-bar/src/path-helper-methods.ts @@ -24,7 +24,7 @@ const getPosition = (props, width) => { }; }; -const getAngle = (props, index) => { +const getAngle = (props, index: number) => { const { data, scale } = props; const x = data[index]._x1 === undefined ? "_x" : "_x1"; return scale.x(data[index][x]); @@ -38,7 +38,7 @@ const getAngularWidth = (props, width) => { return (width / (2 * Math.PI * r)) * angularRange; }; -const transformAngle = (angle) => { +const transformAngle = (angle: number) => { return -1 * angle + Math.PI / 2; }; @@ -48,7 +48,7 @@ export const getCustomBarPath = (props, width) => { return getPath(propsWithCalculatedValues); }; -const getStartAngle = (props, index) => { +const getStartAngle = (props, index: number) => { const { data, scale, alignment } = props; const currentAngle = getAngle(props, index); const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]); @@ -64,7 +64,7 @@ const getStartAngle = (props, index) => { return (currentAngle + previousAngle) / 2; }; -const getEndAngle = (props, index) => { +const getEndAngle = (props, index: number) => { const { data, scale, alignment } = props; const currentAngle = getAngle(props, index); const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]); @@ -268,26 +268,29 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => { end = getEndAngle(props, index); } - const getPath = (edge) => { - const pathFunction = d3Shape + const getPath = (edge): string => { + const pathFunction: any = d3Shape .arc() .innerRadius(r1) .outerRadius(r2) .startAngle(transformAngle(start)) .endAngle(transformAngle(end)) .cornerRadius(cornerRadius[edge]); + return pathFunction(); }; const getPathData = (edge) => { const rightPath = getPath(`${edge}Right`); - const rightMoves = rightPath.match(/[A-Z]/g); + const rightMoves: string[] = rightPath.match(/[A-Z]/g) || []; const rightCoords = rightPath.split(/[A-Z]/).slice(1); const rightMiddle = rightMoves.indexOf("L"); + const leftPath = getPath(`${edge}Left`); - const leftMoves = leftPath.match(/[A-Z]/g); + const leftMoves: string[] = leftPath.match(/[A-Z]/g) || []; const leftCoords = leftPath.split(/[A-Z]/).slice(1); const leftMiddle = leftMoves.indexOf("L"); + return { rightMoves, rightCoords, diff --git a/packages/victory-bar/src/victory-bar.test.js b/packages/victory-bar/src/victory-bar.test.tsx similarity index 95% rename from packages/victory-bar/src/victory-bar.test.js rename to packages/victory-bar/src/victory-bar.test.tsx index ef7f971b0..beb0369d2 100644 --- a/packages/victory-bar/src/victory-bar.test.js +++ b/packages/victory-bar/src/victory-bar.test.tsx @@ -41,14 +41,14 @@ describe("components/victory-bar", () => { it("renders an svg with the correct width and height", () => { const { container } = render(); const svg = container.querySelector("svg"); - expect(svg.getAttribute("style")).toContain("width: 100%; height: 100%"); + expect(svg?.getAttribute("style")).toContain("width: 100%; height: 100%"); }); it("renders an svg with the correct viewBox", () => { const { container } = render(); const svg = container.querySelector("svg"); const viewBoxValue = `0 0 ${450} ${300}`; - expect(svg.getAttribute("viewBox")).toEqual(viewBoxValue); + expect(svg?.getAttribute("viewBox")).toEqual(viewBoxValue); }); it("renders 4 bars", () => { @@ -130,6 +130,7 @@ describe("components/victory-bar", () => { it("renders bars values with null accessor", () => { const data = range(8); const { container } = render( + // @ts-expect-error "'null' is not assignable to 'x'" , ); const bars = container.querySelectorAll("path"); @@ -152,7 +153,7 @@ describe("components/victory-bar", () => { return getBarHeight(commandString); }); - expect(Math.trunc(heights[1] / 2)).toEqual(Math.trunc(heights[0], 0.5)); + expect(Math.trunc(heights[1] / 2)).toEqual(Math.trunc(heights[0])); expect(((heights[2] / 3) * 2).toFixed(3)).toEqual(heights[1].toFixed(3)); }); @@ -186,7 +187,7 @@ describe("components/victory-bar", () => { />, ); const bar = container.querySelector("path"); - fireEvent.click(bar); + fireEvent.click(bar!); expect(clickHandler).toHaveBeenCalled(); }); @@ -262,14 +263,14 @@ describe("components/victory-bar", () => { dataComponent={ `x: ${datum.x}`} - tabIndex={({ index }) => index + 1} + tabIndex={({ index }) => (index as number) + 1} /> } />, ); container.querySelectorAll("path").forEach((bar, index) => { - expect(parseInt(bar.getAttribute("tabindex"))).toEqual(index + 1); + expect(parseInt(bar.getAttribute("tabindex")!)).toEqual(index + 1); expect(bar.getAttribute("aria-label")).toEqual(`x: ${data[index].x}`); }); }); diff --git a/packages/victory-bar/src/victory-bar.js b/packages/victory-bar/src/victory-bar.tsx similarity index 52% rename from packages/victory-bar/src/victory-bar.js rename to packages/victory-bar/src/victory-bar.tsx index a42531a32..f2638bba0 100644 --- a/packages/victory-bar/src/victory-bar.js +++ b/packages/victory-bar/src/victory-bar.tsx @@ -1,19 +1,58 @@ -import PropTypes from "prop-types"; import React from "react"; import { getBaseProps } from "./helper-methods"; -import Bar from "./bar"; +import { Bar } from "./bar"; import { Helpers, VictoryLabel, VictoryContainer, VictoryTheme, - CommonProps, addEvents, Data, Domain, UserProps, + EventPropTypeInterface, + NumberOrCallback, + StringOrNumberOrCallback, + VictoryCommonProps, + VictoryDatableProps, + VictoryMultiLabelableProps, + VictoryStyleInterface, + EventsMixinClass, } from "victory-core"; +export type VictoryBarCornerRadiusKey = + | "top" + | "bottom" + | "topLeft" + | "topRight" + | "bottomLeft" + | "bottomRight"; + +export type VictoryBarCornerRadiusObject = Partial< + Record +>; + +export type VictoryBarTTargetType = "data" | "labels" | "parent"; + +export type VictoryBarAlignmentType = "start" | "middle" | "end"; + +export interface VictoryBarProps + extends VictoryCommonProps, + VictoryDatableProps, + VictoryMultiLabelableProps { + alignment?: VictoryBarAlignmentType; + barRatio?: number; + barWidth?: NumberOrCallback; + cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject; + events?: EventPropTypeInterface< + VictoryBarTTargetType, + number | string | number[] | string[] + >[]; + eventKey?: StringOrNumberOrCallback; + horizontal?: boolean; + style?: VictoryStyleInterface; +} + const fallbackProps = { width: 450, height: 300, @@ -27,8 +66,15 @@ const defaultData = [ { x: 4, y: 4 }, ]; -class VictoryBar extends React.Component { - static animationWhitelist = [ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface VictoryBarBase extends EventsMixinClass {} + +/** + * Draw SVG bar charts with React. VictoryBar is a composable component, so it doesn"t include axes + * Check out VictoryChart for complete bar charts and more. + */ +class VictoryBarBase extends React.Component { + static animationWhitelist: (keyof VictoryBarProps)[] = [ "data", "domain", "height", @@ -58,29 +104,7 @@ class VictoryBar extends React.Component { }, }; - static propTypes = { - ...CommonProps.baseProps, - ...CommonProps.dataProps, - alignment: PropTypes.oneOf(["start", "middle", "end"]), - barRatio: PropTypes.number, - barWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - cornerRadius: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.func, - PropTypes.shape({ - top: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - }), - ]), - getPath: PropTypes.func, - horizontal: PropTypes.bool, - }; - - static defaultProps = { + static defaultProps: VictoryBarProps = { containerComponent: , data: defaultData, dataComponent: , @@ -94,8 +118,9 @@ class VictoryBar extends React.Component { static getDomain = Domain.getDomainWithZero; static getData = Data.getData; - static getBaseProps = (props) => getBaseProps(props, fallbackProps); - static expectedComponents = [ + static getBaseProps = (props: VictoryBarProps) => + getBaseProps(props, fallbackProps); + static expectedComponents: (keyof VictoryBarProps)[] = [ "dataComponent", "labelComponent", "groupComponent", @@ -107,7 +132,7 @@ class VictoryBar extends React.Component { return !!this.props.animate; } - render() { + render(): React.ReactElement { const { animationWhitelist, role } = VictoryBar; const props = Helpers.modifyProps(this.props, fallbackProps, role); @@ -125,4 +150,4 @@ class VictoryBar extends React.Component { } } -export default addEvents(VictoryBar); +export const VictoryBar = addEvents(VictoryBarBase); From b6ceae1bfc3f49a025937360b4084f379c90effc Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Fri, 12 Jan 2024 13:26:22 +0000 Subject: [PATCH 12/29] Migrate victory-canvas to TypeScript (#2710) --- .changeset/beige-flowers-confess.md | 5 + .../src/{canvas-bar.js => canvas-bar.tsx} | 92 ++++++++----------- packages/victory-canvas/src/canvas-curve.js | 40 -------- packages/victory-canvas/src/canvas-curve.tsx | 46 ++++++++++ packages/victory-canvas/src/canvas-group.js | 71 -------------- packages/victory-canvas/src/canvas-group.tsx | 60 ++++++++++++ .../src/{canvas-point.js => canvas-point.tsx} | 46 ++++++---- ...anvas-context.js => use-canvas-context.ts} | 10 +- packages/victory-canvas/src/index.d.ts | 73 --------------- packages/victory-canvas/src/index.js | 5 - packages/victory-canvas/src/index.ts | 5 + 11 files changed, 190 insertions(+), 263 deletions(-) create mode 100644 .changeset/beige-flowers-confess.md rename packages/victory-canvas/src/{canvas-bar.js => canvas-bar.tsx} (51%) delete mode 100644 packages/victory-canvas/src/canvas-curve.js create mode 100644 packages/victory-canvas/src/canvas-curve.tsx delete mode 100644 packages/victory-canvas/src/canvas-group.js create mode 100644 packages/victory-canvas/src/canvas-group.tsx rename packages/victory-canvas/src/{canvas-point.js => canvas-point.tsx} (63%) rename packages/victory-canvas/src/hooks/{use-canvas-context.js => use-canvas-context.ts} (54%) delete mode 100644 packages/victory-canvas/src/index.d.ts delete mode 100644 packages/victory-canvas/src/index.js create mode 100644 packages/victory-canvas/src/index.ts diff --git a/.changeset/beige-flowers-confess.md b/.changeset/beige-flowers-confess.md new file mode 100644 index 000000000..8f935c9d7 --- /dev/null +++ b/.changeset/beige-flowers-confess.md @@ -0,0 +1,5 @@ +--- +"victory-canvas": patch +--- + +Migrate victory-canvas to TypeScript diff --git a/packages/victory-canvas/src/canvas-bar.js b/packages/victory-canvas/src/canvas-bar.tsx similarity index 51% rename from packages/victory-canvas/src/canvas-bar.js rename to packages/victory-canvas/src/canvas-bar.tsx index 238a0b563..cdb24ec18 100644 --- a/packages/victory-canvas/src/canvas-bar.js +++ b/packages/victory-canvas/src/canvas-bar.tsx @@ -1,7 +1,9 @@ import { assign } from "lodash"; -import PropTypes from "prop-types"; import React from "react"; import { + BarProps, + VictoryBarAlignmentType, + VictoryBarCornerRadiusObject, getBarPath, getBarWidth, getCornerRadius, @@ -9,30 +11,41 @@ import { getStyle, } from "victory-bar"; import { useCanvasContext } from "./hooks/use-canvas-context"; -import { CommonProps } from "victory-core"; - -const evaluateProps = (props) => { +import { NumberOrCallback, VictoryCommonPrimitiveProps } from "victory-core"; + +export interface CanvasBarProps extends VictoryCommonPrimitiveProps { + alignment?: VictoryBarAlignmentType; + barOffset?: number[]; + barRatio?: number; + barWidth?: NumberOrCallback; + cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject; + datum?: any; + getPath?: (x: number, y: number, size: number) => string; + horizontal?: boolean; + width?: number; + x?: number; + y?: number; + y0?: number; +} + +const evaluateProps = (props: CanvasBarProps) => { /** * Potential evaluated props of following must be evaluated in this order: * 1) `style` * 2) `barWidth` * 3) `cornerRadius` */ - const style = getStyle(props.style, props); + const style = getStyle(props.style, props as BarProps); const barWidth = getBarWidth(props.barWidth, assign({}, props, { style })); const cornerRadius = getCornerRadius( props.cornerRadius, assign({}, props, { style, barWidth }), ); - - return assign({}, props, { - style, - barWidth, - cornerRadius, - }); + const modifiedProps = assign({}, props, { style, barWidth, cornerRadius }); + return modifiedProps; }; -export const usePreviousValue = (value) => { +const usePreviousValue = (value) => { const ref = React.useRef(); React.useEffect(() => { ref.current = value; @@ -40,30 +53,30 @@ export const usePreviousValue = (value) => { return ref.current; }; -const CanvasBar = (initialProps) => { +export const CanvasBar = (props: CanvasBarProps) => { const { canvasRef } = useCanvasContext(); - const props = evaluateProps(initialProps); - const { polar, style, barWidth, cornerRadius, origin } = props; + const modifiedProps = evaluateProps(props); + const { polar, style, barWidth, cornerRadius, origin } = modifiedProps; const path2d = React.useMemo(() => { const p = polar - ? getPolarBarPath(props, cornerRadius) - : getBarPath(props, barWidth, cornerRadius); + ? getPolarBarPath(modifiedProps, cornerRadius) + : getBarPath(modifiedProps, barWidth, cornerRadius); return new Path2D(p); - }, [polar, barWidth, cornerRadius, props]); + }, [polar, barWidth, cornerRadius, modifiedProps]); const previousPath = usePreviousValue(path2d); const draw = React.useCallback( - (ctx, path) => { + (ctx: CanvasRenderingContext2D, path: Path2D) => { ctx.fillStyle = style.fill; ctx.strokeStyle = style.stroke; ctx.globalAlpha = style.fillOpacity; ctx.lineWidth = style.strokeWidth; if (polar) { - ctx.translate(origin.x, origin.y); + ctx.translate(origin?.x || 0, origin?.y || 0); } ctx.fill(path); ctx.setTransform(1, 0, 0, 1, 0, 0); @@ -73,11 +86,12 @@ const CanvasBar = (initialProps) => { // This will clear the previous bar without clearing the entire canvas const clearPreviousPath = React.useCallback( - (ctx) => { + (ctx: CanvasRenderingContext2D) => { if (previousPath) { ctx.save(); // This ensures that the entire shape is erased - ctx.lineWidth = style.strokeWidth + 2; + const strokeWidth = (style.strokeWidth as number) || 0; + ctx.lineWidth = strokeWidth + 2; ctx.globalCompositeOperation = "destination-out"; draw(ctx, previousPath); @@ -90,8 +104,8 @@ const CanvasBar = (initialProps) => { ); React.useEffect(() => { - const ctx = canvasRef.current.getContext("2d"); - + const ctx = canvasRef.current?.getContext("2d"); + if (!ctx) return; clearPreviousPath(ctx); draw(ctx, path2d); }, [ @@ -100,38 +114,10 @@ const CanvasBar = (initialProps) => { polar, barWidth, cornerRadius, - props, + modifiedProps, path2d, clearPreviousPath, ]); return null; }; - -CanvasBar.propTypes = { - ...CommonProps.primitiveProps, - alignment: PropTypes.oneOf(["start", "middle", "end"]), - barRatio: PropTypes.number, - barWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - cornerRadius: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.func, - PropTypes.shape({ - top: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - }), - ]), - datum: PropTypes.object, - getPath: PropTypes.func, - horizontal: PropTypes.bool, - width: PropTypes.number, - x: PropTypes.number, - y: PropTypes.number, - y0: PropTypes.number, -}; - -export default CanvasBar; diff --git a/packages/victory-canvas/src/canvas-curve.js b/packages/victory-canvas/src/canvas-curve.js deleted file mode 100644 index 0bb4dbe1f..000000000 --- a/packages/victory-canvas/src/canvas-curve.js +++ /dev/null @@ -1,40 +0,0 @@ -import PropTypes from "prop-types"; -import React from "react"; -import { CommonProps, LineHelpers } from "victory-core"; -import { useCanvasContext } from "./hooks/use-canvas-context"; - -const CanvasCurve = (props) => { - const { canvasRef, clear, clip } = useCanvasContext(); - const { style, data } = props; - const { stroke, strokeWidth } = style; - - const draw = React.useCallback( - (ctx) => { - const line = LineHelpers.getLineFunction(props); - ctx.strokeStyle = stroke; - ctx.lineWidth = strokeWidth; - line.context(ctx)(data); - ctx.stroke(); - }, - [data, props, stroke, strokeWidth], - ); - - React.useEffect(() => { - const ctx = canvasRef.current.getContext("2d"); - clear(ctx); - draw(ctx); - clip(ctx); - }, [canvasRef, draw, clear, clip]); - - return null; -}; - -CanvasCurve.propTypes = { - ...CommonProps.primitiveProps, - interpolation: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - openCurve: PropTypes.bool, - origin: PropTypes.object, - polar: PropTypes.bool, -}; - -export default CanvasCurve; diff --git a/packages/victory-canvas/src/canvas-curve.tsx b/packages/victory-canvas/src/canvas-curve.tsx new file mode 100644 index 000000000..7a8e19f91 --- /dev/null +++ b/packages/victory-canvas/src/canvas-curve.tsx @@ -0,0 +1,46 @@ +import React from "react"; +import { + LineHelpers, + NumberOrCallback, + StringOrCallback, + VictoryCommonPrimitiveProps, +} from "victory-core"; +import { useCanvasContext } from "./hooks/use-canvas-context"; +import { LineRadial } from "../../victory-vendor/d3-shape"; + +export interface CanvasCurveProps extends VictoryCommonPrimitiveProps { + ariaLabel?: StringOrCallback; + // eslint-disable-next-line @typescript-eslint/ban-types + interpolation?: string | Function; + openCurve?: boolean; + tabIndex?: NumberOrCallback; +} + +export const CanvasCurve = (props: CanvasCurveProps) => { + const { canvasRef, clear, clip } = useCanvasContext(); + const { style, data } = props; + const { stroke, strokeWidth } = style; + + const draw = React.useCallback( + (ctx: CanvasRenderingContext2D) => { + const line = LineHelpers.getLineFunction(props) as LineRadial< + [number, number] + >; + ctx.strokeStyle = stroke; + ctx.lineWidth = strokeWidth; + line.context(ctx)(data); + ctx.stroke(); + }, + [data, props, stroke, strokeWidth], + ); + + React.useEffect(() => { + const ctx = canvasRef.current?.getContext("2d"); + if (!ctx) return; + clear(ctx); + draw(ctx); + clip(ctx); + }, [canvasRef, draw, clear, clip]); + + return null; +}; diff --git a/packages/victory-canvas/src/canvas-group.js b/packages/victory-canvas/src/canvas-group.js deleted file mode 100644 index a89f17cd0..000000000 --- a/packages/victory-canvas/src/canvas-group.js +++ /dev/null @@ -1,71 +0,0 @@ -import React from "react"; -import { CanvasContext } from "./hooks/use-canvas-context"; -import PropTypes from "prop-types"; -import { PropTypes as CustomPropTypes } from "victory-core"; - -const CanvasGroup = (props) => { - const canvasRef = React.useRef(); - const { children, width, height, clipWidth, padding } = props; - - const clear = React.useCallback( - (ctx) => { - return ctx.clearRect(0, 0, width, height); - }, - [width, height], - ); - - // This needs to be called in the child component to ensure it is called after the - // shape is drawn - const clip = React.useCallback( - (ctx) => { - const maxClipWidth = width - padding.right - padding.left; - ctx.clearRect( - width - padding.right, - 0, - (maxClipWidth - clipWidth) * -1, - height, - ); - }, - [width, height, padding, clipWidth], - ); - - return ( - - - - - {children} - - ); -}; - -CanvasGroup.propTypes = { - "aria-label": PropTypes.string, - children: PropTypes.oneOfType([ - PropTypes.arrayOf(PropTypes.node), - PropTypes.node, - ]), - className: PropTypes.string, - clipWidth: CustomPropTypes.nonNegative, - height: PropTypes.number, - padding: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - top: PropTypes.number, - bottom: PropTypes.number, - left: PropTypes.number, - right: PropTypes.number, - }), - ]), - width: PropTypes.number, -}; -CanvasGroup.role = "container"; -CanvasGroup.displayName = "CanvasGroup"; - -export default CanvasGroup; diff --git a/packages/victory-canvas/src/canvas-group.tsx b/packages/victory-canvas/src/canvas-group.tsx new file mode 100644 index 000000000..c83bcb04e --- /dev/null +++ b/packages/victory-canvas/src/canvas-group.tsx @@ -0,0 +1,60 @@ +import React from "react"; +import { CanvasContext } from "./hooks/use-canvas-context"; +import { PaddingProps } from "victory-core"; + +export interface CanvasGroupProps { + children?: React.ReactNode | React.ReactNode[]; + clipWidth?: number; + height?: number; + padding?: PaddingProps; + width?: number; +} + +export const CanvasGroup = (props: CanvasGroupProps) => { + const canvasRef = React.useRef(null); + const { children, width = 0, height = 0, clipWidth, padding } = props; + + const clear = React.useCallback( + (ctx: CanvasRenderingContext2D) => { + return ctx.clearRect(0, 0, width, height); + }, + [width, height], + ); + + // This needs to be called in the child component to ensure it is called after the + // shape is drawn + const clip = React.useCallback( + (ctx: CanvasRenderingContext2D) => { + const paddingRight = + typeof padding === "number" ? padding : padding?.right || 0; + const paddingLeft = + typeof padding === "number" ? padding : padding?.left || 0; + + const maxClipWidth = width - paddingRight - paddingLeft; + ctx.clearRect( + width - paddingRight, + 0, + clipWidth ? (maxClipWidth - clipWidth) * -1 : 0, + height, + ); + }, + [width, height, padding, clipWidth], + ); + + return ( + + + + + {children} + + ); +}; + +CanvasGroup.role = "container"; diff --git a/packages/victory-canvas/src/canvas-point.js b/packages/victory-canvas/src/canvas-point.tsx similarity index 63% rename from packages/victory-canvas/src/canvas-point.js rename to packages/victory-canvas/src/canvas-point.tsx index 7b71fdbe8..41708b50b 100644 --- a/packages/victory-canvas/src/canvas-point.js +++ b/packages/victory-canvas/src/canvas-point.tsx @@ -1,9 +1,24 @@ import React from "react"; -import PropTypes from "prop-types"; import { assign } from "lodash"; -import { Helpers, CommonProps, PointPathHelpers } from "victory-core"; +import { + Helpers, + PointPathHelpers, + ScatterSymbolType, + VictoryCommonPrimitiveProps, +} from "victory-core"; import { useCanvasContext } from "./hooks/use-canvas-context"; +export interface CanvasPointProps extends VictoryCommonPrimitiveProps { + datum?: any; + getPath?: (x: number, y: number, size: number) => string; + // eslint-disable-next-line @typescript-eslint/ban-types + size?: number | Function; + // eslint-disable-next-line @typescript-eslint/ban-types + symbol?: ScatterSymbolType | Function; + x?: number; + y?: number; +} + const getPath = (props) => { const { x, y, size, symbol } = props; if (props.getPath) { @@ -27,7 +42,7 @@ const getPath = (props) => { return symbolFunction(x, y, size); }; -const evaluateProps = (props) => { +const evaluateProps = (props: CanvasPointProps) => { /** * Potential evaluated props are: * `size` @@ -45,37 +60,28 @@ const evaluateProps = (props) => { }); }; -const CanvasPoint = (initialProps) => { +export const CanvasPoint = (props: CanvasPointProps) => { const { canvasRef } = useCanvasContext(); - const props = evaluateProps(initialProps); + const modifiedProps = evaluateProps(props); const draw = React.useCallback( - (ctx) => { - const { style } = props; - const path = getPath(props); + (ctx: CanvasRenderingContext2D) => { + const { style } = modifiedProps; + const path = getPath(modifiedProps); ctx.fillStyle = style.fill; // eslint-disable-next-line no-undef const path2d = new Path2D(path); ctx.fill(path2d); }, - [props], + [modifiedProps], ); React.useEffect(() => { - const ctx = canvasRef.current.getContext("2d"); + const ctx = canvasRef.current?.getContext("2d"); + if (!ctx) return; draw(ctx); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return null; }; - -CanvasPoint.propTypes = { - ...CommonProps.primitiveProps, - datum: PropTypes.object, - size: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - x: PropTypes.number, - y: PropTypes.number, -}; - -export default CanvasPoint; diff --git a/packages/victory-canvas/src/hooks/use-canvas-context.js b/packages/victory-canvas/src/hooks/use-canvas-context.ts similarity index 54% rename from packages/victory-canvas/src/hooks/use-canvas-context.js rename to packages/victory-canvas/src/hooks/use-canvas-context.ts index e93b23ab8..93f40bd93 100644 --- a/packages/victory-canvas/src/hooks/use-canvas-context.js +++ b/packages/victory-canvas/src/hooks/use-canvas-context.ts @@ -1,6 +1,14 @@ import React from "react"; -export const CanvasContext = React.createContext(); +export type CanvasContextValue = { + canvasRef: React.RefObject; + clear: (ctx: CanvasRenderingContext2D) => void; + clip: (ctx: CanvasRenderingContext2D) => void; +}; + +export const CanvasContext = React.createContext< + CanvasContextValue | undefined +>(undefined); export const useCanvasContext = () => { const context = React.useContext(CanvasContext); diff --git a/packages/victory-canvas/src/index.d.ts b/packages/victory-canvas/src/index.d.ts deleted file mode 100644 index 7459c09ff..000000000 --- a/packages/victory-canvas/src/index.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { VictoryBarAlignmentType } from "victory-bar"; -import { - VictoryCommonPrimitiveProps, - NumberOrCallback, - StringOrCallback, - ScatterSymbolType, - PaddingProps, -} from "victory-core"; -import * as React from "react"; - -export interface CanvasBarProps extends VictoryCommonPrimitiveProps { - alignment?: VictoryBarAlignmentType; - barOffset?: number[]; - barRatio?: number; - barWidth?: NumberOrCallback; - cornerRadius?: - | NumberOrCallback - | { - top?: NumberOrCallback; - topLeft?: NumberOrCallback; - topRight?: NumberOrCallback; - bottom?: NumberOrCallback; - bottomLeft?: NumberOrCallback; - bottomRight?: NumberOrCallback; - }; - datum?: any; - getPath?: Function; - horizontal?: boolean; - width?: number; - x?: number; - y?: number; - y0?: number; -} - -export class CanvasBar extends React.Component {} - -export interface CanvasCurveProps extends VictoryCommonPrimitiveProps { - ariaLabel?: StringOrCallback; - interpolation?: string | Function; - openCurve?: boolean; - tabIndex?: NumberOrCallback; -} - -export class CanvasCurve extends React.Component {} - -export interface CanvasPointProps extends VictoryCommonPrimitiveProps { - datum?: any; - getPath?: (x: number, y: number, size: number) => string; - size?: number | Function; - symbol?: ScatterSymbolType | Function; - x?: number; - y?: number; -} - -export class CanvasPoint extends React.Component {} - -export interface CanvasGroupProps { - children?: React.ReactNode | React.ReactNode[]; - clipWidth?: number; - height?: number; - padding?: PaddingProps; - width?: number; -} - -export class CanvasGroup extends React.Component {} - -export interface CanvasContextValue { - canvasRef: React.RefObject; - clear(ctx: CanvasRenderingContext2D): void; - clip(ctx: CanvasRenderingContext2D): void; -} - -export const useCanvasContext: () => CanvasContextValue; diff --git a/packages/victory-canvas/src/index.js b/packages/victory-canvas/src/index.js deleted file mode 100644 index a2d4bed68..000000000 --- a/packages/victory-canvas/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as CanvasBar } from "./canvas-bar"; -export { default as CanvasGroup } from "./canvas-group"; -export { default as CanvasCurve } from "./canvas-curve"; -export { default as CanvasPoint } from "./canvas-point"; -export { useCanvasContext } from "./hooks/use-canvas-context"; diff --git a/packages/victory-canvas/src/index.ts b/packages/victory-canvas/src/index.ts new file mode 100644 index 000000000..e68329729 --- /dev/null +++ b/packages/victory-canvas/src/index.ts @@ -0,0 +1,5 @@ +export * from "./canvas-bar"; +export * from "./canvas-group"; +export * from "./canvas-curve"; +export * from "./canvas-point"; +export { useCanvasContext } from "./hooks/use-canvas-context"; From cb630fa30cecfc11da97d45a9d46772109562971 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Fri, 12 Jan 2024 15:14:32 +0000 Subject: [PATCH 13/29] Migrate victory-legend to TypeScript (#2712) --- .changeset/orange-mirrors-swim.md | 6 + .../src/victory-util/add-events.tsx | 19 +- packages/victory-legend/package.json | 3 + .../{helper-methods.js => helper-methods.ts} | 4 +- packages/victory-legend/src/index.d.ts | 59 ----- packages/victory-legend/src/index.js | 1 - packages/victory-legend/src/index.ts | 1 + packages/victory-legend/src/victory-legend.js | 240 ------------------ ...legend.test.js => victory-legend.test.tsx} | 0 .../victory-legend/src/victory-legend.tsx | 194 ++++++++++++++ pnpm-lock.yaml | 3 + 11 files changed, 223 insertions(+), 307 deletions(-) create mode 100644 .changeset/orange-mirrors-swim.md rename packages/victory-legend/src/{helper-methods.js => helper-methods.ts} (98%) delete mode 100644 packages/victory-legend/src/index.d.ts delete mode 100644 packages/victory-legend/src/index.js create mode 100644 packages/victory-legend/src/index.ts delete mode 100644 packages/victory-legend/src/victory-legend.js rename packages/victory-legend/src/{victory-legend.test.js => victory-legend.test.tsx} (100%) create mode 100644 packages/victory-legend/src/victory-legend.tsx diff --git a/.changeset/orange-mirrors-swim.md b/.changeset/orange-mirrors-swim.md new file mode 100644 index 000000000..e319b93b7 --- /dev/null +++ b/.changeset/orange-mirrors-swim.md @@ -0,0 +1,6 @@ +--- +"victory-core": patch +"victory-legend": patch +--- + +Migrate victory-legend to TypeScript diff --git a/packages/victory-core/src/victory-util/add-events.tsx b/packages/victory-core/src/victory-util/add-events.tsx index 40cece210..f67a07d1f 100644 --- a/packages/victory-core/src/victory-util/add-events.tsx +++ b/packages/victory-core/src/victory-util/add-events.tsx @@ -68,9 +68,9 @@ export interface EventsMixinClass { defaultAnimationWhitelist: string[], ): React.ReactElement; getComponentProps( - component: React.ReactElement, + component: React.ReactNode, type: string, - index: number, + index: string | number, ): TProps; dataKeys: string[]; } @@ -352,7 +352,11 @@ export function addEvents< return props.events; } - getComponentProps(component, type, index) { + getComponentProps( + component: React.ReactNode, + type: string, + index: string | number, + ) { const name = this.props.name || WrappedComponent.role; const key = (this.dataKeys && this.dataKeys[index]) || index; const id = `${name}-${type}-${key}`; @@ -365,13 +369,18 @@ export function addEvents< return undefined; } + const currentProps = + component && typeof component === "object" && "props" in component + ? component.props + : undefined; + if (this.hasEvents) { const baseEvents = this.getEvents(this.props, type, key); const componentProps = defaults( { index, key: id }, this.getEventState(key, type), this.getSharedEventState(key, type), - component.props, + currentProps, baseProps, { id }, ); @@ -385,7 +394,7 @@ export function addEvents< return assign({}, componentProps, { events }); } - return defaults({ index, key: id }, component.props, baseProps, { id }); + return defaults({ index, key: id }, currentProps, baseProps, { id }); } renderContainer(component, children) { diff --git a/packages/victory-legend/package.json b/packages/victory-legend/package.json index 6c88c6f57..86ae99e50 100644 --- a/packages/victory-legend/package.json +++ b/packages/victory-legend/package.json @@ -27,6 +27,9 @@ "peerDependencies": { "react": ">=16.6.0" }, + "devDependencies": { + "victory-legend": "*" + }, "publishConfig": { "provenance": true }, diff --git a/packages/victory-legend/src/helper-methods.js b/packages/victory-legend/src/helper-methods.ts similarity index 98% rename from packages/victory-legend/src/helper-methods.js rename to packages/victory-legend/src/helper-methods.ts index 98d92ab5a..1747edaf3 100644 --- a/packages/victory-legend/src/helper-methods.js +++ b/packages/victory-legend/src/helper-methods.ts @@ -86,7 +86,7 @@ const getColumnWidths = (props, data) => { : gutter || 0; const dataByColumn = groupBy(data, "column"); const columns = keys(dataByColumn); - return columns.reduce((memo, curr, index) => { + return columns.reduce((memo, curr, index) => { const lengths = dataByColumn[curr].map((d) => { return d.textSize.width + d.size + d.symbolSpacer + gutterWidth; }); @@ -102,7 +102,7 @@ const getRowHeights = (props, data) => { ? (gutter.top || 0) + (gutter.bottom || 0) : gutter || 0; const dataByRow = groupBy(data, "row"); - return keys(dataByRow).reduce((memo, curr, index) => { + return keys(dataByRow).reduce((memo, curr, index) => { const rows = dataByRow[curr]; const lengths = rows.map((d) => { return d.textSize.height + d.symbolSpacer + gutterHeight; diff --git a/packages/victory-legend/src/index.d.ts b/packages/victory-legend/src/index.d.ts deleted file mode 100644 index 66f048a88..000000000 --- a/packages/victory-legend/src/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as React from "react"; -import { - BlockProps, - ColorScalePropType, - EventPropTypeInterface, - OrientationTypes, - PaddingProps, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryDatableProps, - VictorySingleLabelableProps, - VictoryStyleInterface, - VictoryLabelStyleObject, -} from "victory-core"; - -export type VictoryLegendTTargetType = "data" | "labels" | "parent"; -export type VictoryLegendOrientationType = "horizontal" | "vertical"; - -export interface VictoryLegendProps - extends VictoryCommonProps, - VictoryDatableProps, - VictorySingleLabelableProps { - borderComponent?: React.ReactElement; - borderPadding?: PaddingProps; - centerTitle?: boolean; - colorScale?: ColorScalePropType; - data?: Array<{ - name?: string; - labels?: { - fill?: string; - }; - symbol?: { - fill?: string; - size?: number; - type?: string; - }; - }>; - dataComponent?: React.ReactElement; - eventKey?: StringOrNumberOrCallback | string[]; - events?: EventPropTypeInterface< - VictoryLegendTTargetType, - StringOrNumberOrCallback - >[]; - gutter?: number | { left: number; right: number }; - itemsPerRow?: number; - orientation?: VictoryLegendOrientationType; - rowGutter?: number | Omit; - style?: VictoryStyleInterface & { - title?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - }; - symbolSpacer?: number; - title?: string | string[]; - titleComponent?: React.ReactElement; - titleOrientation?: OrientationTypes; - x?: number; - y?: number; -} - -export class VictoryLegend extends React.Component {} diff --git a/packages/victory-legend/src/index.js b/packages/victory-legend/src/index.js deleted file mode 100644 index 33893adcf..000000000 --- a/packages/victory-legend/src/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as VictoryLegend } from "./victory-legend"; diff --git a/packages/victory-legend/src/index.ts b/packages/victory-legend/src/index.ts new file mode 100644 index 000000000..04641851b --- /dev/null +++ b/packages/victory-legend/src/index.ts @@ -0,0 +1 @@ +export * from "./victory-legend"; diff --git a/packages/victory-legend/src/victory-legend.js b/packages/victory-legend/src/victory-legend.js deleted file mode 100644 index 0a0b94bac..000000000 --- a/packages/victory-legend/src/victory-legend.js +++ /dev/null @@ -1,240 +0,0 @@ -import React from "react"; -import PropTypes from "prop-types"; -import { getBaseProps, getDimensions } from "./helper-methods"; -import { - PropTypes as CustomPropTypes, - addEvents, - Helpers, - VictoryLabel, - VictoryContainer, - VictoryTheme, - Point, - Border, -} from "victory-core"; - -const fallbackProps = { - orientation: "vertical", - titleOrientation: "top", - width: 450, - height: 300, - x: 0, - y: 0, -}; - -const defaultLegendData = [{ name: "Series 1" }, { name: "Series 2" }]; - -class VictoryLegend extends React.Component { - static displayName = "VictoryLegend"; - - static role = "legend"; - - static propTypes = { - borderComponent: PropTypes.element, - borderPadding: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - top: PropTypes.number, - bottom: PropTypes.number, - left: PropTypes.number, - right: PropTypes.number, - }), - ]), - centerTitle: PropTypes.bool, - colorScale: PropTypes.oneOfType([ - PropTypes.arrayOf(PropTypes.string), - PropTypes.oneOf([ - "grayscale", - "qualitative", - "heatmap", - "warm", - "cool", - "red", - "green", - "blue", - ]), - ]), - containerComponent: PropTypes.element, - data: PropTypes.arrayOf( - PropTypes.shape({ - name: PropTypes.string.isRequired, - label: PropTypes.object, - symbol: PropTypes.object, - }), - ), - dataComponent: PropTypes.element, - eventKey: PropTypes.oneOfType([ - PropTypes.func, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - ]), - events: PropTypes.arrayOf( - PropTypes.shape({ - target: PropTypes.oneOf(["data", "labels", "parent"]), - eventKey: PropTypes.oneOfType([ - PropTypes.array, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - ]), - eventHandlers: PropTypes.object, - }), - ), - externalEventMutations: PropTypes.arrayOf( - PropTypes.shape({ - callback: PropTypes.func, - childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), - eventKey: PropTypes.oneOfType([ - PropTypes.array, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - ]), - mutation: PropTypes.func, - target: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), - }), - ), - groupComponent: PropTypes.element, - gutter: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - left: PropTypes.number, - right: PropTypes.number, - }), - ]), - height: CustomPropTypes.nonNegative, - itemsPerRow: CustomPropTypes.nonNegative, - labelComponent: PropTypes.element, - name: PropTypes.string, - orientation: PropTypes.oneOf(["horizontal", "vertical"]), - padding: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - top: PropTypes.number, - bottom: PropTypes.number, - left: PropTypes.number, - right: PropTypes.number, - }), - ]), - rowGutter: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - top: PropTypes.number, - bottom: PropTypes.number, - }), - ]), - sharedEvents: PropTypes.shape({ - events: PropTypes.array, - getEventState: PropTypes.func, - }), - standalone: PropTypes.bool, - style: PropTypes.shape({ - border: PropTypes.object, - data: PropTypes.object, - labels: PropTypes.object, - parent: PropTypes.object, - title: PropTypes.object, - }), - symbolSpacer: PropTypes.number, - theme: PropTypes.object, - title: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), - titleComponent: PropTypes.element, - titleOrientation: PropTypes.oneOf(["top", "bottom", "left", "right"]), - width: CustomPropTypes.nonNegative, - x: CustomPropTypes.nonNegative, - y: CustomPropTypes.nonNegative, - }; - - static defaultProps = { - borderComponent: , - data: defaultLegendData, - containerComponent: , - dataComponent: , - groupComponent: , - labelComponent: , - standalone: true, - theme: VictoryTheme.grayscale, - titleComponent: , - }; - - static getBaseProps = (props) => getBaseProps(props, fallbackProps); - static getDimensions = (props) => getDimensions(props, fallbackProps); - static expectedComponents = [ - "borderComponent", - "containerComponent", - "dataComponent", - "groupComponent", - "labelComponent", - "titleComponent", - ]; - - renderChildren(props) { - const { dataComponent, labelComponent, title } = props; - const dataComponents = this.dataKeys - .map((_dataKey, index) => { - if (_dataKey === "all") { - return undefined; - } - const dataProps = this.getComponentProps(dataComponent, "data", index); - return React.cloneElement(dataComponent, dataProps); - }) - .filter(Boolean); - - const labelComponents = this.dataKeys - .map((_dataKey, index) => { - if (_dataKey === "all") { - return undefined; - } - const labelProps = this.getComponentProps( - labelComponent, - "labels", - index, - ); - if (labelProps.text !== undefined && labelProps.text !== null) { - return React.cloneElement(labelComponent, labelProps); - } - return undefined; - }) - .filter(Boolean); - const borderProps = this.getComponentProps( - props.borderComponent, - "border", - "all", - ); - const borderComponent = React.cloneElement( - props.borderComponent, - borderProps, - ); - if (title) { - const titleProps = this.getComponentProps(props.title, "title", "all"); - const titleComponent = React.cloneElement( - props.titleComponent, - titleProps, - ); - return [ - borderComponent, - ...dataComponents, - titleComponent, - ...labelComponents, - ]; - } - return [borderComponent, ...dataComponents, ...labelComponents]; - } - - render() { - const { role } = this.constructor; - const props = Helpers.modifyProps(this.props, fallbackProps, role); - const children = [this.renderChildren(props)]; - return props.standalone - ? this.renderContainer(props.containerComponent, children) - : React.cloneElement(props.groupComponent, {}, children); - } -} - -export default addEvents(VictoryLegend); diff --git a/packages/victory-legend/src/victory-legend.test.js b/packages/victory-legend/src/victory-legend.test.tsx similarity index 100% rename from packages/victory-legend/src/victory-legend.test.js rename to packages/victory-legend/src/victory-legend.test.tsx diff --git a/packages/victory-legend/src/victory-legend.tsx b/packages/victory-legend/src/victory-legend.tsx new file mode 100644 index 000000000..6b9b97974 --- /dev/null +++ b/packages/victory-legend/src/victory-legend.tsx @@ -0,0 +1,194 @@ +import React from "react"; +import { getBaseProps, getDimensions } from "./helper-methods"; +import { + addEvents, + Helpers, + VictoryLabel, + VictoryContainer, + VictoryTheme, + Point, + Border, + BlockProps, + ColorScalePropType, + EventPropTypeInterface, + OrientationTypes, + PaddingProps, + StringOrNumberOrCallback, + VictoryCommonProps, + VictoryDatableProps, + VictorySingleLabelableProps, + VictoryStyleInterface, + VictoryLabelStyleObject, + EventsMixinClass, +} from "victory-core"; + +export type VictoryLegendTTargetType = "data" | "labels" | "parent"; + +export type VictoryLegendOrientationType = "horizontal" | "vertical"; + +export interface VictoryLegendProps + extends VictoryCommonProps, + VictoryDatableProps, + VictorySingleLabelableProps { + borderComponent?: React.ReactElement; + borderPadding?: PaddingProps; + centerTitle?: boolean; + colorScale?: ColorScalePropType; + dataComponent?: React.ReactElement; + eventKey?: StringOrNumberOrCallback | string[]; + events?: EventPropTypeInterface< + VictoryLegendTTargetType, + StringOrNumberOrCallback + >[]; + gutter?: number | { left: number; right: number }; + itemsPerRow?: number; + orientation?: VictoryLegendOrientationType; + rowGutter?: number | Omit; + style?: VictoryStyleInterface & { + title?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + }; + symbolSpacer?: number; + title?: string | string[]; + titleComponent?: React.ReactElement; + titleOrientation?: OrientationTypes; +} + +const fallbackProps = { + orientation: "vertical", + titleOrientation: "top", + width: 450, + height: 300, + x: 0, + y: 0, +}; + +const defaultLegendData = [{ name: "Series 1" }, { name: "Series 2" }]; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface VictoryLegendBase extends EventsMixinClass {} + +class VictoryLegendBase extends React.Component { + static displayName = "VictoryLegend"; + + static role = "legend"; + + static defaultProps = { + borderComponent: , + data: defaultLegendData, + containerComponent: , + dataComponent: , + groupComponent: , + labelComponent: , + standalone: true, + theme: VictoryTheme.grayscale, + titleComponent: , + }; + + static getBaseProps = (props: VictoryLegendProps) => + getBaseProps(props, fallbackProps); + + static getDimensions = (props: VictoryLegendProps) => + getDimensions(props, fallbackProps); + + static expectedComponents = [ + "borderComponent", + "containerComponent", + "dataComponent", + "groupComponent", + "labelComponent", + "titleComponent", + ]; + + renderChildren(props: VictoryLegendProps) { + const { dataComponent, labelComponent, title } = props; + + const children: React.ReactElement[] = []; + + if (props.borderComponent) { + const borderProps = this.getComponentProps( + props.borderComponent, + "border", + "all", + ); + const borderComponent = React.cloneElement( + props.borderComponent, + borderProps, + ); + + children.push(borderComponent); + } + + if (dataComponent) { + const dataComponents = this.dataKeys + .map((_dataKey, index) => { + if (_dataKey === "all") { + return undefined; + } + const dataProps = this.getComponentProps( + dataComponent, + "data", + index, + ); + return React.cloneElement(dataComponent, dataProps); + }) + .filter( + (comp: React.ReactElement | undefined): comp is React.ReactElement => + comp !== undefined, + ); + + children.push(...dataComponents); + } + + if (title && props.titleComponent) { + const titleProps = this.getComponentProps(title, "title", "all"); + const titleComponent = React.cloneElement( + props.titleComponent, + titleProps, + ); + + children.push(titleComponent); + } + + if (labelComponent) { + const labelComponents = this.dataKeys + .map((_dataKey, index) => { + if (_dataKey === "all") { + return undefined; + } + const labelProps = this.getComponentProps( + labelComponent, + "labels", + index, + ); + if ( + (labelProps as any).text !== undefined && + (labelProps as any).text !== null + ) { + return React.cloneElement(labelComponent, labelProps); + } + return undefined; + }) + .filter( + (comp: React.ReactElement | undefined): comp is React.ReactElement => + comp !== undefined, + ); + + children.push(...labelComponents); + } + + return children; + } + + render(): React.ReactElement { + // @ts-expect-error Property 'role' does not exist on type 'Function'. + // Ref: https://github.com/microsoft/TypeScript/issues/32452 + const { role } = this.constructor; + const props = Helpers.modifyProps(this.props, fallbackProps, role); + const children = this.renderChildren(props); + return props.standalone + ? this.renderContainer(props.containerComponent, children) + : React.cloneElement(props.groupComponent, {}, children); + } +} + +export const VictoryLegend = addEvents(VictoryLegendBase); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2426bbec0..7a059dcf9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -495,10 +495,13 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-core: ^36.8.1 + victory-legend: '*' dependencies: lodash: 4.17.21 prop-types: 15.8.1 victory-core: link:../victory-core + devDependencies: + victory-legend: 'link:' packages/victory-line: specifiers: From 4556f3dd7c289922ad2e8cdcccccb75187dc0830 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Tue, 16 Jan 2024 14:50:23 +0000 Subject: [PATCH 14/29] Fix victory-group animation (#2717) --- .changeset/seven-brooms-destroy.md | 5 +++++ packages/victory-group/src/victory-group.tsx | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .changeset/seven-brooms-destroy.md diff --git a/.changeset/seven-brooms-destroy.md b/.changeset/seven-brooms-destroy.md new file mode 100644 index 000000000..b12063f1d --- /dev/null +++ b/.changeset/seven-brooms-destroy.md @@ -0,0 +1,5 @@ +--- +"victory-group": patch +--- + +Fix victory-group animation diff --git a/packages/victory-group/src/victory-group.tsx b/packages/victory-group/src/victory-group.tsx index f81cba9ec..7d587e00c 100644 --- a/packages/victory-group/src/victory-group.tsx +++ b/packages/victory-group/src/victory-group.tsx @@ -67,8 +67,11 @@ const VictoryGroupBase: React.FC = (initialProps) => { const role = VictoryGroup?.role; const { getAnimationProps, setAnimationState, getProps } = Hooks.useAnimationState(); - initialProps = { ...defaultProps, ...initialProps }; - const props = getProps(initialProps); + const propsWithDefaults = React.useMemo( + () => ({ ...defaultProps, ...initialProps }), + [initialProps], + ); + const props = getProps(propsWithDefaults); const modifiedProps = Helpers.modifyProps(props, fallbackProps, role); const { @@ -132,8 +135,8 @@ const VictoryGroupBase: React.FC = (initialProps) => { ]); const userProps = React.useMemo( - () => UserProps.getSafeUserProps(initialProps), - [initialProps], + () => UserProps.getSafeUserProps(propsWithDefaults), + [propsWithDefaults], ); const container = React.useMemo(() => { @@ -160,16 +163,16 @@ const VictoryGroupBase: React.FC = (initialProps) => { return Wrapper.getAllEvents(props); }, [props]); - const previousProps = Hooks.usePreviousProps(initialProps); + const previousProps = Hooks.usePreviousProps(propsWithDefaults); React.useEffect(() => { // This is called before dismount to keep state in sync return () => { - if (initialProps.animate) { + if (propsWithDefaults.animate) { setAnimationState(previousProps, props); } }; - }, [setAnimationState, previousProps, initialProps, props]); + }, [setAnimationState, previousProps, propsWithDefaults, props]); if (!isEmpty(events)) { return ( From ab8d636431dc6171f9fbbd38d55843c294daf403 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Tue, 16 Jan 2024 15:24:57 +0000 Subject: [PATCH 15/29] Assign merged props to a const instead of modifying initialProps (#2718) --- .changeset/angry-pens-provide.md | 7 +++++++ packages/victory-chart/src/victory-chart.tsx | 19 ++++++++++-------- .../src/helpers/wrap-core-component.js | 4 ++-- packages/victory-stack/src/victory-stack.tsx | 20 ++++++++++--------- 4 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 .changeset/angry-pens-provide.md diff --git a/.changeset/angry-pens-provide.md b/.changeset/angry-pens-provide.md new file mode 100644 index 000000000..39d6fb9b2 --- /dev/null +++ b/.changeset/angry-pens-provide.md @@ -0,0 +1,7 @@ +--- +"victory-chart": patch +"victory-native": patch +"victory-stack": patch +--- + +Assign merged props to a const instead of modifying initialProps diff --git a/packages/victory-chart/src/victory-chart.tsx b/packages/victory-chart/src/victory-chart.tsx index f4a10c605..f42f4fd30 100644 --- a/packages/victory-chart/src/victory-chart.tsx +++ b/packages/victory-chart/src/victory-chart.tsx @@ -53,11 +53,14 @@ const defaultProps = { }; const VictoryChartImpl: React.FC = (initialProps) => { - initialProps = { ...defaultProps, ...initialProps }; + const propsWithDefaults = React.useMemo( + () => ({ ...defaultProps, ...initialProps }), + [initialProps], + ); const role = "chart"; const { getAnimationProps, setAnimationState, getProps } = Hooks.useAnimationState(); - const props = getProps(initialProps); + const props = getProps(propsWithDefaults); const modifiedProps = Helpers.modifyProps(props, fallbackProps, role); const { @@ -154,7 +157,7 @@ const VictoryChartImpl: React.FC = (initialProps) => { {}, containerComponent.props, containerProps, - UserProps.getSafeUserProps(initialProps), + UserProps.getSafeUserProps(propsWithDefaults), ); return React.cloneElement(containerComponent, defaultContainerProps); } @@ -164,23 +167,23 @@ const VictoryChartImpl: React.FC = (initialProps) => { standalone, containerComponent, containerProps, - initialProps, + propsWithDefaults, ]); const events = React.useMemo(() => { return Wrapper.getAllEvents(props); }, [props]); - const previousProps = Hooks.usePreviousProps(initialProps); + const previousProps = Hooks.usePreviousProps(propsWithDefaults); React.useEffect(() => { // This is called before dismount to keep state in sync return () => { - if (initialProps.animate) { - setAnimationState(previousProps, initialProps); + if (propsWithDefaults.animate) { + setAnimationState(previousProps, propsWithDefaults); } }; - }, [setAnimationState, previousProps, initialProps]); + }, [setAnimationState, previousProps, propsWithDefaults]); if (!isEmpty(events)) { return ( diff --git a/packages/victory-native/src/helpers/wrap-core-component.js b/packages/victory-native/src/helpers/wrap-core-component.js index a0dec81d7..49a58031c 100644 --- a/packages/victory-native/src/helpers/wrap-core-component.js +++ b/packages/victory-native/src/helpers/wrap-core-component.js @@ -8,8 +8,8 @@ import React from "react"; */ export const wrapCoreComponent = ({ Component, defaultProps }) => { const WrappedComponent = (props) => { - props = { ...defaultProps, ...props }; - return ; + const propsWithDefaults = { ...defaultProps, ...props }; + return ; }; /** diff --git a/packages/victory-stack/src/victory-stack.tsx b/packages/victory-stack/src/victory-stack.tsx index 376a7807c..fff347769 100644 --- a/packages/victory-stack/src/victory-stack.tsx +++ b/packages/victory-stack/src/victory-stack.tsx @@ -61,13 +61,15 @@ const defaultProps = { }; const VictoryStackBase = (initialProps: VictoryStackProps) => { - // eslint-disable-next-line no-use-before-define const { role } = VictoryStack; - initialProps = { ...defaultProps, ...initialProps }; + const propsWithDefaults = React.useMemo( + () => ({ ...defaultProps, ...initialProps }), + [initialProps], + ); const { setAnimationState, getAnimationProps, getProps } = Hooks.useAnimationState(); - const props = getProps(initialProps); + const props = getProps(propsWithDefaults); const modifiedProps = Helpers.modifyProps(props, fallbackProps, role); const { @@ -134,8 +136,8 @@ const VictoryStackBase = (initialProps: VictoryStackProps) => { name, ]); const userProps = React.useMemo( - () => UserProps.getSafeUserProps(initialProps), - [initialProps], + () => UserProps.getSafeUserProps(propsWithDefaults), + [propsWithDefaults], ); const container = React.useMemo(() => { @@ -161,16 +163,16 @@ const VictoryStackBase = (initialProps: VictoryStackProps) => { return Wrapper.getAllEvents(props); }, [props]); - const previousProps = Hooks.usePreviousProps(initialProps); + const previousProps = Hooks.usePreviousProps(propsWithDefaults); React.useEffect(() => { // This is called before dismount to keep state in sync return () => { - if (initialProps.animate) { - setAnimationState(previousProps, initialProps); + if (propsWithDefaults.animate) { + setAnimationState(previousProps, propsWithDefaults); } }; - }, [setAnimationState, previousProps, initialProps]); + }, [setAnimationState, previousProps, propsWithDefaults]); if (!isEmpty(events)) { return ( From 786f9536dfaf7cea6eca5798f3fbb387880cb80f Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Tue, 16 Jan 2024 09:51:56 -0600 Subject: [PATCH 16/29] Migrate polar axis to typescript (#2713) --- .changeset/spotty-apples-carry.md | 5 + .../{helper-methods.js => helper-methods.ts} | 133 +++++++++++++----- packages/victory-polar-axis/src/index.js | 1 - packages/victory-polar-axis/src/index.ts | 2 + .../src/{index.d.ts => types.ts} | 17 --- ...y-polar-axis.js => victory-polar-axis.tsx} | 126 ++++------------- 6 files changed, 131 insertions(+), 153 deletions(-) create mode 100644 .changeset/spotty-apples-carry.md rename packages/victory-polar-axis/src/{helper-methods.js => helper-methods.ts} (79%) delete mode 100644 packages/victory-polar-axis/src/index.js create mode 100644 packages/victory-polar-axis/src/index.ts rename packages/victory-polar-axis/src/{index.d.ts => types.ts} (53%) rename packages/victory-polar-axis/src/{victory-polar-axis.js => victory-polar-axis.tsx} (61%) diff --git a/.changeset/spotty-apples-carry.md b/.changeset/spotty-apples-carry.md new file mode 100644 index 000000000..fb9454f2a --- /dev/null +++ b/.changeset/spotty-apples-carry.md @@ -0,0 +1,5 @@ +--- +"victory-polar-axis": patch +--- + +Migrate polar axis to typescript diff --git a/packages/victory-polar-axis/src/helper-methods.js b/packages/victory-polar-axis/src/helper-methods.ts similarity index 79% rename from packages/victory-polar-axis/src/helper-methods.js rename to packages/victory-polar-axis/src/helper-methods.ts index b64e4cf67..43f298bc3 100644 --- a/packages/victory-polar-axis/src/helper-methods.js +++ b/packages/victory-polar-axis/src/helper-methods.ts @@ -1,11 +1,12 @@ import { assign, uniqBy, defaults } from "lodash"; import { Helpers, LabelHelpers, Scale, Axis } from "victory-core"; +import { VictoryPolarAxisProps } from "./types"; -const getPosition = (r, angle, axis) => { +const getPosition = (r: number, angle: number, axis?: string) => { return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle); }; -const getAxisType = (props) => { +const getAxisType = (props: VictoryPolarAxisProps) => { const typicalType = props.dependentAxis ? "radial" : "angular"; const invertedType = typicalType === "angular" ? "radial" : "angular"; return props.horizontal ? invertedType : typicalType; @@ -24,7 +25,7 @@ const getEvaluatedStyles = (style, props) => { }; }; -const getStyleObject = (props) => { +const getStyleObject = (props: VictoryPolarAxisProps) => { const { theme = {}, dependentAxis } = props; const generalAxisStyle = (theme.polarAxis && theme.polarAxis.style) || @@ -34,8 +35,7 @@ const getStyleObject = (props) => { : "polarIndependentAxis"; const standardAxisType = dependentAxis ? "dependentAxis" : "independentAxis"; const specificAxisStyle = - (theme[polarAxisType] && theme[polarAxisType].style) || - (theme[standardAxisType] && theme[standardAxisType].style); + theme?.[polarAxisType]?.style || theme?.[standardAxisType]?.style; const mergeStyles = () => { const styleNamespaces = [ @@ -49,8 +49,8 @@ const getStyleObject = (props) => { return styleNamespaces.reduce((memo, curr) => { memo[curr] = defaults( {}, - specificAxisStyle[curr], - generalAxisStyle[curr], + specificAxisStyle?.[curr], + generalAxisStyle?.[curr], ); return memo; }, {}); @@ -61,13 +61,20 @@ const getStyleObject = (props) => { : specificAxisStyle || generalAxisStyle; }; -const getRadius = (props) => { +const getRadius = (props: VictoryPolarAxisProps) => { const { left, right, top, bottom } = Helpers.getPadding(props); const { width, height } = props; + + if (width === undefined || height === undefined) { + throw new Error( + "VictoryPolarAxis: width and height properties are required for standalone axes.", + ); + } + return Math.min(width - left - right, height - top - bottom) / 2; }; -const getRange = (props, axis) => { +const getRange = (props: VictoryPolarAxisProps, axis) => { // Return the range from props if one is given. if (props.range && props.range[axis]) { return props.range[axis]; @@ -84,8 +91,7 @@ const getRange = (props, axis) => { return [props.innerRadius || 0, radius]; }; -// exposed for use by VictoryChart (necessary?) -export const getScale = (props) => { +export const getScale = (props: VictoryPolarAxisProps) => { const axis = Axis.getAxis(props); const scale = Scale.getBaseScale(props, axis); const domain = Axis.getDomain(props, axis) || scale.domain(); @@ -95,7 +101,7 @@ export const getScale = (props) => { return scale; }; -export const getStyles = (props, styleObject) => { +export const getStyles = (props: VictoryPolarAxisProps, styleObject) => { if (props.disableInlineStyles) { return {}; } @@ -112,7 +118,11 @@ export const getStyles = (props, styleObject) => { }; }; -const getAxisAngle = (props) => { +const getAxisAngle = (props: { + axisAngle?: number; + dependentAxis?: boolean; + startAngle?: number; +}) => { const { axisAngle, startAngle, dependentAxis } = props; const axis = Axis.getAxis(props); const axisValue = Axis.getAxisValue(props, axis); @@ -122,8 +132,22 @@ const getAxisAngle = (props) => { return Helpers.radiansToDegrees(axisValue); }; -// eslint-disable-next-line max-params -const getTickProps = (props, calculatedValues, tickValue, index) => { +const getTickProps = ( + props: VictoryPolarAxisProps, + calculatedValues: { + axisType: string; + radius: number; + scale: any; + style: any; + stringTicks: any; + ticks: any; + tickFormat: any; + origin: { x: number; y: number }; + }, + tickValue, + index, + // eslint-disable-next-line max-params +) => { const { axisType, radius, @@ -147,8 +171,7 @@ const getTickProps = (props, calculatedValues, tickValue, index) => { axisType, text, }); - const axisAngle = - axisType === "radial" ? getAxisAngle(props, scale) : undefined; + const axisAngle = axisType === "radial" ? getAxisAngle(props) : undefined; const tickPadding = tickStyle.padding || tickStyle.size || 0; const padAngle = Helpers.degreesToRadians(90 - axisAngle); const tickAngle = @@ -190,8 +213,22 @@ const getTickProps = (props, calculatedValues, tickValue, index) => { }; }; -// eslint-disable-next-line max-params -const getTickLabelProps = (props, calculatedValues, tickValue, index) => { +const getTickLabelProps = ( + props: VictoryPolarAxisProps, + calculatedValues: { + axisType: string; + radius: number; + tickFormat: any; + style: any; + scale: any; + ticks: any; + stringTicks: any; + origin: { x: number; y: number }; + }, + tickValue, + index, + // eslint-disable-next-line max-params +) => { const { axisType, radius, @@ -216,14 +253,12 @@ const getTickLabelProps = (props, calculatedValues, tickValue, index) => { axisType, }); const { tickLabelComponent } = props; - const labelPlacement = - tickLabelComponent.props && tickLabelComponent.props.labelPlacement - ? tickLabelComponent.props.labelPlacement - : props.labelPlacement; + const labelPlacement = tickLabelComponent?.props.labelPlacement + ? tickLabelComponent.props.labelPlacement + : props.labelPlacement; const tickPadding = labelStyle.padding || 0; const angularPadding = 0; // TODO: do some geometry - const axisAngle = - axisType === "radial" ? getAxisAngle(props, scale) : undefined; + const axisAngle = axisType === "radial" ? getAxisAngle(props) : undefined; const labelAngle = axisType === "angular" ? Helpers.radiansToDegrees(scale(tickValue)) @@ -255,8 +290,22 @@ const getTickLabelProps = (props, calculatedValues, tickValue, index) => { }; }; -// eslint-disable-next-line max-params -const getGridProps = (props, calculatedValues, tickValue, index) => { +const getGridProps = ( + props: VictoryPolarAxisProps, + calculatedValues: { + axisType: string; + radius: number; + style: any; + scale: any; + stringTicks: any; + ticks: any; + tickFormat: any; + origin: { x: number; y: number }; + }, + tickValue, + index, + // eslint-disable-next-line max-params +) => { const { axisType, radius, @@ -304,19 +353,25 @@ const getGridProps = (props, calculatedValues, tickValue, index) => { }; }; -const getAxisLabelProps = (props, calculatedValues) => { - const { axisType, radius, style, scale, origin } = calculatedValues; +const getAxisLabelProps = ( + props: VictoryPolarAxisProps, + calculatedValues: { + axisType: string; + radius: number; + style: any; + origin: { x: number; y: number }; + }, +) => { + const { axisType, radius, style, origin } = calculatedValues; const { axisLabelComponent } = props; if (axisType !== "radial") { return {}; } - const labelPlacement = - axisLabelComponent.props && axisLabelComponent.props.labelPlacement - ? axisLabelComponent.props.labelPlacement - : props.labelPlacement; + const labelPlacement = axisLabelComponent?.props.labelPlacement + ? axisLabelComponent.props.labelPlacement + : props.labelPlacement; const labelStyle = (style && style.axisLabel) || {}; - const axisAngle = - axisType === "radial" ? getAxisAngle(props, scale) : undefined; + const axisAngle = axisType === "radial" ? getAxisAngle(props) : undefined; const textAngle = labelStyle.angle === undefined ? LabelHelpers.getPolarAngle( @@ -353,11 +408,11 @@ const getAxisLabelProps = (props, calculatedValues) => { }; const getAxisProps = (modifiedProps, calculatedValues) => { - const { style, axisType, radius, scale, origin } = calculatedValues; + const { style, axisType, radius, origin } = calculatedValues; const { startAngle, endAngle, innerRadius = 0 } = modifiedProps; const axisAngle = axisType === "radial" - ? Helpers.degreesToRadians(getAxisAngle(modifiedProps, scale)) + ? Helpers.degreesToRadians(getAxisAngle(modifiedProps)) : undefined; return axisType === "radial" ? { @@ -377,7 +432,7 @@ const getAxisProps = (modifiedProps, calculatedValues) => { }; }; -const getCalculatedValues = (props) => { +const getCalculatedValues = (props: VictoryPolarAxisProps) => { props = assign({ polar: true }, props); const defaultStyles = getStyleObject(props); const style = getStyles(props, defaultStyles); @@ -410,7 +465,7 @@ const getCalculatedValues = (props) => { }; }; -export const getBaseProps = (props, fallbackProps) => { +export const getBaseProps = (props: VictoryPolarAxisProps, fallbackProps) => { props = Axis.modifyProps(props, fallbackProps); const calculatedValues = getCalculatedValues(props); const { style, scale, ticks, domain } = calculatedValues; diff --git a/packages/victory-polar-axis/src/index.js b/packages/victory-polar-axis/src/index.js deleted file mode 100644 index 54c2ed257..000000000 --- a/packages/victory-polar-axis/src/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as VictoryPolarAxis } from "./victory-polar-axis"; diff --git a/packages/victory-polar-axis/src/index.ts b/packages/victory-polar-axis/src/index.ts new file mode 100644 index 000000000..515d42481 --- /dev/null +++ b/packages/victory-polar-axis/src/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./victory-polar-axis"; diff --git a/packages/victory-polar-axis/src/index.d.ts b/packages/victory-polar-axis/src/types.ts similarity index 53% rename from packages/victory-polar-axis/src/index.d.ts rename to packages/victory-polar-axis/src/types.ts index a712f25cd..d5c794b80 100644 --- a/packages/victory-polar-axis/src/index.d.ts +++ b/packages/victory-polar-axis/src/types.ts @@ -1,15 +1,3 @@ -// Definitions by: Alexey Svetliakov -// snerks -// Krzysztof Cebula -// Vitaliy Polyanskiy -// James Lismore -// Stack Builders -// Esteban Ibarra -// Dominic Lee -// Dave Vedder -// Alec Flett - -import * as React from "react"; import { DomainPropType, EventPropTypeInterface, @@ -46,8 +34,3 @@ export interface VictoryPolarAxisProps labelPlacement?: LabelOrientationType; startAngle?: number; } - -export class VictoryPolarAxis extends React.Component< - VictoryPolarAxisProps, - any -> {} diff --git a/packages/victory-polar-axis/src/victory-polar-axis.js b/packages/victory-polar-axis/src/victory-polar-axis.tsx similarity index 61% rename from packages/victory-polar-axis/src/victory-polar-axis.js rename to packages/victory-polar-axis/src/victory-polar-axis.tsx index 83b9a1ecc..ff5b48bf8 100644 --- a/packages/victory-polar-axis/src/victory-polar-axis.js +++ b/packages/victory-polar-axis/src/victory-polar-axis.tsx @@ -1,37 +1,29 @@ import React from "react"; -import PropTypes from "prop-types"; import { assign, isEmpty } from "lodash"; import { - PropTypes as CustomPropTypes, VictoryLabel, - CommonProps, VictoryContainer, VictoryTheme, LineSegment, addEvents, Arc, Axis, + EventsMixinClass, } from "victory-core"; import { getScale, getStyles, getBaseProps } from "./helper-methods"; +import { VictoryPolarAxisProps } from "./types"; -const fallbackProps = { +const fallbackProps: Partial = { width: 450, height: 300, padding: 50, }; -const options = { - components: [ - { name: "axis", index: 0 }, - { name: "axisLabel", index: 0 }, - { name: "grid" }, - { name: "parent", index: "parent" }, - { name: "ticks" }, - { name: "tickLabels" }, - ], -}; +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface VictoryPolarAxisBase + extends EventsMixinClass {} -class VictoryPolarAxis extends React.Component { +class VictoryPolarAxisBase extends React.Component { static animationWhitelist = [ "style", "domain", @@ -56,75 +48,6 @@ class VictoryPolarAxis extends React.Component { }, }; - static propTypes = { - ...CommonProps.baseProps, - axisAngle: PropTypes.number, - axisComponent: PropTypes.element, - axisLabelComponent: PropTypes.element, - axisValue: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - PropTypes.object, - ]), - categories: PropTypes.oneOfType([ - PropTypes.arrayOf(PropTypes.string), - PropTypes.shape({ - x: PropTypes.arrayOf(PropTypes.string), - y: PropTypes.arrayOf(PropTypes.string), - }), - ]), - circularAxisComponent: PropTypes.element, - circularGridComponent: PropTypes.element, - containerComponent: PropTypes.element, - dependentAxis: PropTypes.bool, - disableInlineStyles: PropTypes.bool, - endAngle: PropTypes.number, - events: PropTypes.arrayOf( - PropTypes.shape({ - target: PropTypes.oneOf([ - "axis", - "axisLabel", - "grid", - "ticks", - "tickLabels", - ]), - eventKey: PropTypes.oneOfType([ - PropTypes.array, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - ]), - eventHandlers: PropTypes.object, - }), - ), - gridComponent: PropTypes.element, - innerRadius: CustomPropTypes.nonNegative, - labelPlacement: PropTypes.oneOf(["parallel", "perpendicular", "vertical"]), - startAngle: PropTypes.number, - stringMap: PropTypes.object, - style: PropTypes.shape({ - parent: PropTypes.object, - axis: PropTypes.object, - axisLabel: PropTypes.object, - grid: PropTypes.object, - ticks: PropTypes.object, - tickLabels: PropTypes.object, - }), - tickComponent: PropTypes.element, - tickCount: CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.greaterThanZero, - ]), - tickFormat: PropTypes.oneOfType([ - PropTypes.func, - CustomPropTypes.homogeneousArray, - ]), - tickLabelComponent: PropTypes.element, - tickValues: CustomPropTypes.homogeneousArray, - }; - static defaultProps = { axisComponent: , axisLabelComponent: , @@ -158,16 +81,16 @@ class VictoryPolarAxis extends React.Component { "circularGridComponent", ]; - renderAxisLine(props) { + renderAxisLine(props: VictoryPolarAxisProps) { const { dependentAxis } = props; const axisComponent = dependentAxis ? props.axisComponent : props.circularAxisComponent; const axisProps = this.getComponentProps(axisComponent, "axis", 0); - return React.cloneElement(axisComponent, axisProps); + return React.cloneElement(axisComponent!, axisProps); } - renderLabel(props) { + renderLabel(props: VictoryPolarAxisProps) { const { axisLabelComponent, dependentAxis, label } = props; if (!label || !dependentAxis) { return null; @@ -177,10 +100,10 @@ class VictoryPolarAxis extends React.Component { "axisLabel", 0, ); - return React.cloneElement(axisLabelComponent, axisLabelProps); + return React.cloneElement(axisLabelComponent!, axisLabelProps); } - renderAxis(props) { + renderAxis(props: VictoryPolarAxisProps) { const { tickComponent, tickLabelComponent, name } = props; const shouldRender = (componentProps) => { const { style = {}, events = {} } = componentProps; @@ -199,7 +122,7 @@ class VictoryPolarAxis extends React.Component { { key: `${name}-tick-${key}` }, this.getComponentProps(tickComponent, "ticks", index), ); - const TickComponent = React.cloneElement(tickComponent, tickProps); + const TickComponent = React.cloneElement(tickComponent!, tickProps); return shouldRender(TickComponent.props) ? TickComponent : undefined; }) .filter(Boolean); @@ -210,7 +133,7 @@ class VictoryPolarAxis extends React.Component { { key: `${name}-grid-${key}` }, this.getComponentProps(gridComponent, "grid", index), ); - const GridComponent = React.cloneElement(gridComponent, gridProps); + const GridComponent = React.cloneElement(gridComponent!, gridProps); return shouldRender(GridComponent.props) ? GridComponent : undefined; }) .filter(Boolean); @@ -220,7 +143,7 @@ class VictoryPolarAxis extends React.Component { { key: `${name}-tick-${key}` }, this.getComponentProps(tickLabelComponent, "tickLabels", index), ); - return React.cloneElement(tickLabelComponent, tickLabelProps); + return React.cloneElement(tickLabelComponent!, tickLabelProps); }); const axis = this.renderAxisLine(props); const axisLabel = this.renderLabel(props); @@ -235,16 +158,16 @@ class VictoryPolarAxis extends React.Component { } // Overridden in victory-native - renderGroup(props, children) { + renderGroup(props: VictoryPolarAxisProps, children: React.ReactNode) { const { groupComponent } = props; - return React.cloneElement(groupComponent, {}, children); + return React.cloneElement(groupComponent!, {}, children); } shouldAnimate() { return !!this.props.animate; } - render() { + render(): React.ReactElement { const { animationWhitelist } = VictoryPolarAxis; const props = Axis.modifyProps(this.props, fallbackProps); @@ -258,4 +181,15 @@ class VictoryPolarAxis extends React.Component { } } -export default addEvents(VictoryPolarAxis, options); +const options = { + components: [ + { name: "axis", index: 0 }, + { name: "axisLabel", index: 0 }, + { name: "grid" }, + { name: "parent", index: "parent" }, + { name: "ticks" }, + { name: "tickLabels" }, + ], +}; + +export const VictoryPolarAxis = addEvents(VictoryPolarAxisBase, options); From 3073fa02f0e5eccb449668230ab12191db203aa7 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Tue, 16 Jan 2024 16:18:30 +0000 Subject: [PATCH 17/29] Migrate victory-candlestick to TypeScript (#2716) --- .changeset/nine-cups-complain.md | 5 + packages/victory-candlestick/package.json | 12 +- .../src/{candle.test.js => candle.test.tsx} | 4 +- .../src/{candle.js => candle.tsx} | 77 +++-- ...methods.test.js => helper-methods.test.ts} | 0 .../{helper-methods.js => helper-methods.ts} | 21 +- packages/victory-candlestick/src/index.d.ts | 110 ------- packages/victory-candlestick/src/index.js | 2 - packages/victory-candlestick/src/index.ts | 2 + .../src/victory-candlestick.js | 308 ------------------ ...k.test.js => victory-candlestick.test.tsx} | 15 +- .../src/victory-candlestick.tsx | 305 +++++++++++++++++ pnpm-lock.yaml | 4 + 13 files changed, 395 insertions(+), 470 deletions(-) create mode 100644 .changeset/nine-cups-complain.md rename packages/victory-candlestick/src/{candle.test.js => candle.test.tsx} (95%) rename packages/victory-candlestick/src/{candle.js => candle.tsx} (70%) rename packages/victory-candlestick/src/{helper-methods.test.js => helper-methods.test.ts} (100%) rename packages/victory-candlestick/src/{helper-methods.js => helper-methods.ts} (96%) delete mode 100644 packages/victory-candlestick/src/index.d.ts delete mode 100644 packages/victory-candlestick/src/index.js create mode 100644 packages/victory-candlestick/src/index.ts delete mode 100644 packages/victory-candlestick/src/victory-candlestick.js rename packages/victory-candlestick/src/{victory-candlestick.test.js => victory-candlestick.test.tsx} (94%) create mode 100644 packages/victory-candlestick/src/victory-candlestick.tsx diff --git a/.changeset/nine-cups-complain.md b/.changeset/nine-cups-complain.md new file mode 100644 index 000000000..346da3210 --- /dev/null +++ b/.changeset/nine-cups-complain.md @@ -0,0 +1,5 @@ +--- +"victory-candlestick": patch +--- + +Migrate victory-candlestick to TypeScript diff --git a/packages/victory-candlestick/package.json b/packages/victory-candlestick/package.json index 424f15a7e..c10952f60 100644 --- a/packages/victory-candlestick/package.json +++ b/packages/victory-candlestick/package.json @@ -28,7 +28,9 @@ "react": ">=16.6.0" }, "devDependencies": { - "victory-chart": "^36.8.1" + "victory-vendor": "^36.8.1", + "victory-chart": "^36.8.1", + "victory-candlestick": "*" }, "publishConfig": { "provenance": true @@ -174,8 +176,8 @@ "dependencies": [ "types:create", "../victory-core:types:create", - "../victory-chart:types:create", "../victory-vendor:types:create", + "../victory-chart:types:create", "../victory-voronoi:types:create" ], "output": [], @@ -240,8 +242,8 @@ "output": [], "dependencies": [ "../victory-core:types:create", - "../victory-chart:types:create", "../victory-vendor:types:create", + "../victory-chart:types:create", "../victory-voronoi:types:create" ], "packageLocks": [ @@ -258,8 +260,8 @@ "output": [], "dependencies": [ "../victory-core:types:create", - "../victory-chart:types:create", "../victory-vendor:types:create", + "../victory-chart:types:create", "../victory-voronoi:types:create" ], "packageLocks": [ @@ -277,8 +279,8 @@ "output": [], "dependencies": [ "build:lib:cjs", - "../victory-chart:build:lib:cjs", "../victory-vendor:build:lib:cjs", + "../victory-chart:build:lib:cjs", "../victory-voronoi:build:lib:cjs" ], "packageLocks": [ diff --git a/packages/victory-candlestick/src/candle.test.js b/packages/victory-candlestick/src/candle.test.tsx similarity index 95% rename from packages/victory-candlestick/src/candle.test.js rename to packages/victory-candlestick/src/candle.test.tsx index 523942ac7..b39cc5c13 100644 --- a/packages/victory-candlestick/src/candle.test.js +++ b/packages/victory-candlestick/src/candle.test.tsx @@ -50,7 +50,7 @@ describe("victory-primitives/candle", () => { wicks.forEach((wick, i) => { const [x1, x2, y1, y2] = ["x1", "x2", "y1", "y2"].map((prop) => - parseInt(wick.getAttribute(prop)), + parseInt(wick.getAttribute(prop) || ""), ); expect(values[i]).toMatchObject({ x1, x2, y1, y2 }); }); @@ -60,7 +60,7 @@ describe("victory-primitives/candle", () => { const { container } = renderCandle(); const rect = container.querySelector("rect"); const [width, height, x, y] = ["width", "height", "x", "y"].map((prop) => - rect.getAttribute(prop), + rect?.getAttribute(prop), ); // width = style.width || 0.5 * (width - 2 * padding) / data.length; diff --git a/packages/victory-candlestick/src/candle.js b/packages/victory-candlestick/src/candle.tsx similarity index 70% rename from packages/victory-candlestick/src/candle.js rename to packages/victory-candlestick/src/candle.tsx index ba8d591d2..adf51f1de 100644 --- a/packages/victory-candlestick/src/candle.js +++ b/packages/victory-candlestick/src/candle.tsx @@ -1,10 +1,34 @@ -/* eslint no-magic-numbers: ["error", { "ignore": [0, 0.5, 1, 2] }]*/ import React from "react"; -import PropTypes from "prop-types"; -import { Helpers, CommonProps, Line, Rect } from "victory-core"; +import { + Helpers, + Line, + NumberOrCallback, + Rect, + VictoryCommonPrimitiveProps, + VictoryStyleObject, +} from "victory-core"; import { assign, defaults, isFunction } from "lodash"; -const getCandleWidth = (candleWidth, props) => { +export interface CandleProps extends VictoryCommonPrimitiveProps { + candleRatio?: number; + candleWidth?: NumberOrCallback; + close?: number; + datum?: any; + groupComponent?: React.ReactElement; + high?: number; + lineComponent?: React.ReactElement; + low?: number; + open?: number; + rectComponent?: React.ReactElement; + wickStrokeWidth?: number; + width?: number; + x?: number; +} + +const getCandleWidth = ( + candleWidth: CandleProps["candleWidth"], + props: CandleProps, +) => { const { style } = props; if (candleWidth) { return isFunction(candleWidth) @@ -16,7 +40,7 @@ const getCandleWidth = (candleWidth, props) => { return candleWidth; }; -const getCandleProps = (props, style) => { +const getCandleProps = (props, style: VictoryStyleObject) => { const { id, x, close, open, horizontal, candleWidth } = props; const candleLength = Math.abs(close - open); return { @@ -29,7 +53,7 @@ const getCandleProps = (props, style) => { }; }; -const getHighWickProps = (props, style) => { +const getHighWickProps = (props, style: VictoryStyleObject) => { const { horizontal, high, open, close, x, id } = props; return { key: `${id}-highWick`, @@ -41,7 +65,7 @@ const getHighWickProps = (props, style) => { }; }; -const getLowWickProps = (props, style) => { +const getLowWickProps = (props, style: VictoryStyleObject) => { const { horizontal, low, open, close, x, id } = props; return { key: `${id}-lowWick`, @@ -89,7 +113,7 @@ const evaluateProps = (props) => { }); }; -const defaultProps = { +const defaultProps: Partial = { groupComponent: , lineComponent: , rectComponent: , @@ -97,8 +121,8 @@ const defaultProps = { shapeRendering: "auto", }; -const Candle = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Candle = (props: CandleProps) => { + const modifiedProps = evaluateProps({ ...defaultProps, ...props }); const { ariaLabel, events, @@ -114,7 +138,7 @@ const Candle = (props) => { style, desc, tabIndex, - } = props; + } = modifiedProps; const wickStyle = defaults({ strokeWidth: wickStrokeWidth }, style); const sharedProps = { ...events, @@ -127,9 +151,15 @@ const Candle = (props) => { desc, tabIndex, }; - const candleProps = assign(getCandleProps(props, style), sharedProps); - const highWickProps = assign(getHighWickProps(props, wickStyle), sharedProps); - const lowWickProps = assign(getLowWickProps(props, wickStyle), sharedProps); + const candleProps = assign(getCandleProps(modifiedProps, style), sharedProps); + const highWickProps = assign( + getHighWickProps(modifiedProps, wickStyle), + sharedProps, + ); + const lowWickProps = assign( + getLowWickProps(modifiedProps, wickStyle), + sharedProps, + ); return React.cloneElement(groupComponent, {}, [ React.cloneElement(rectComponent, candleProps), @@ -137,22 +167,3 @@ const Candle = (props) => { React.cloneElement(lineComponent, lowWickProps), ]); }; - -Candle.propTypes = { - ...CommonProps.primitiveProps, - candleRatio: PropTypes.number, - candleWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - close: PropTypes.number, - datum: PropTypes.object, - groupComponent: PropTypes.element, - high: PropTypes.number, - lineComponent: PropTypes.element, - low: PropTypes.number, - open: PropTypes.number, - rectComponent: PropTypes.element, - wickStrokeWidth: PropTypes.number, - width: PropTypes.number, - x: PropTypes.number, -}; - -export default Candle; diff --git a/packages/victory-candlestick/src/helper-methods.test.js b/packages/victory-candlestick/src/helper-methods.test.ts similarity index 100% rename from packages/victory-candlestick/src/helper-methods.test.js rename to packages/victory-candlestick/src/helper-methods.test.ts diff --git a/packages/victory-candlestick/src/helper-methods.js b/packages/victory-candlestick/src/helper-methods.ts similarity index 96% rename from packages/victory-candlestick/src/helper-methods.js rename to packages/victory-candlestick/src/helper-methods.ts index e20cebd5e..128bc9e20 100644 --- a/packages/victory-candlestick/src/helper-methods.js +++ b/packages/victory-candlestick/src/helper-methods.ts @@ -6,10 +6,13 @@ import { Data, LabelHelpers, Collection, + VictoryStyleObject, } from "victory-core"; const TYPES = ["close", "open", "high", "low"]; +const DEFAULT_CANDLE_WIDTH = 8; + export const getData = (props) => { const accessorTypes = ["x", "high", "low", "close", "open"]; return Data.formatData(props.data, props, accessorTypes); @@ -58,7 +61,15 @@ const getLabelStyle = (props, styleObject, namespace) => { return defaults({}, tooltipTheme.style, baseStyle); }; -const getStyles = (props, style, defaultStyles = {}) => { +const getStyles = ( + props, + style, + defaultStyles: { + parent?: any; + labels?: any; + data?: any; + } = {}, +) => { if (props.disableInlineStyles) { return {}; } @@ -207,8 +218,8 @@ const getText = (props, type) => { return Array.isArray(labelProp) ? labelProp[index] : labelProp; }; -const getCandleWidth = (props, style) => { - const { data, candleWidth, scale, defaultCandleWidth } = props; +const getCandleWidth = (props, style?: VictoryStyleObject) => { + const { data, candleWidth, scale } = props; if (candleWidth) { return isFunction(candleWidth) ? Helpers.evaluateProp(candleWidth, props) @@ -221,7 +232,7 @@ const getCandleWidth = (props, style) => { const candles = data.length + 2; const candleRatio = props.candleRatio || 0.5; const defaultWidth = - candleRatio * (data.length < 2 ? defaultCandleWidth : extent / candles); + candleRatio * (data.length < 2 ? DEFAULT_CANDLE_WIDTH : extent / candles); return Math.max(1, defaultWidth); }; @@ -281,7 +292,7 @@ const calculatePlotValues = (props) => { /* eslint-enable complexity*/ /* eslint-disable max-params*/ -const getLabelProps = (props, text, style, type) => { +const getLabelProps = (props, text, style, type?: string) => { const { x, high, diff --git a/packages/victory-candlestick/src/index.d.ts b/packages/victory-candlestick/src/index.d.ts deleted file mode 100644 index d840bdf12..000000000 --- a/packages/victory-candlestick/src/index.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import * as React from "react"; -import { - EventPropTypeInterface, - OrientationTypes, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryCommonPrimitiveProps, - VictoryDatableProps, - VictoryStyleObject, - VictoryLabelStyleObject, - VictoryLabelableProps, - VictoryMultiLabelableProps, -} from "victory-core"; - -export interface VictoryCandlestickStyleInterface { - close?: VictoryStyleObject; - closeLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - data?: VictoryStyleObject; - high?: VictoryStyleObject; - highLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - labels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - low?: VictoryStyleObject; - lowLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - open?: VictoryStyleObject; - openLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - parent?: VictoryStyleObject; -} - -export type VictoryCandlestickLabelsType = - | (string | number)[] - | boolean - | ((datum: any) => number); - -export interface VictoryCandlestickProps - extends Omit, - VictoryDatableProps, - VictoryLabelableProps, - VictoryMultiLabelableProps { - candleColors?: { - positive?: string; - negative?: string; - }; - candleRatio?: number; - candleWidth?: number | Function; - close?: StringOrNumberOrCallback | string[]; - closeLabelComponent?: React.ReactElement; - closeLabels?: VictoryCandlestickLabelsType; - eventKey?: StringOrNumberOrCallback | string[]; - events?: EventPropTypeInterface< - | "data" - | "labels" - | "open" - | "openLabels" - | "close" - | "closeLabels" - | "low" - | "lowLabels" - | "high" - | "highLabels", - StringOrNumberOrCallback | string[] - >[]; - high?: StringOrNumberOrCallback | string[]; - highLabelComponenet?: React.ReactElement; - highLabels?: VictoryCandlestickLabelsType; - labelOrientation?: - | OrientationTypes - | { - open?: OrientationTypes; - close?: OrientationTypes; - low?: OrientationTypes; - high?: OrientationTypes; - }; - low?: StringOrNumberOrCallback | string[]; - lowLabelComponent?: React.ReactElement; - lowLabels?: VictoryCandlestickLabelsType; - open?: StringOrNumberOrCallback | string[]; - openLabelComponent?: React.ReactElement; - openLabels?: VictoryCandlestickLabelsType; - size?: number; - style?: VictoryCandlestickStyleInterface; - wickStrokeWidth?: number; -} - -/** - * VictoryCandlestick renders a dataset as a series of candlesticks. - * VictoryCandlestick can be composed with VictoryChart to create candlestick charts. - */ - -export class VictoryCandlestick extends React.Component< - VictoryCandlestickProps, - any -> {} - -export interface CandleProps extends VictoryCommonPrimitiveProps { - candleRatio?: number; - candleWidth?: number | Function; - close?: number; - datum?: any; - groupComponent?: React.ReactElement; - high?: number; - lineComponent?: React.ReactElement; - low?: number; - open?: number; - rectComponent?: React.ReactElement; - wickStrokeWidth?: number; - width?: number; - x?: number; -} - -export class Candle extends React.Component {} diff --git a/packages/victory-candlestick/src/index.js b/packages/victory-candlestick/src/index.js deleted file mode 100644 index 27746185c..000000000 --- a/packages/victory-candlestick/src/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as VictoryCandlestick } from "./victory-candlestick"; -export { default as Candle } from "./candle"; diff --git a/packages/victory-candlestick/src/index.ts b/packages/victory-candlestick/src/index.ts new file mode 100644 index 000000000..63f66ba9d --- /dev/null +++ b/packages/victory-candlestick/src/index.ts @@ -0,0 +1,2 @@ +export * from "./victory-candlestick"; +export * from "./candle"; diff --git a/packages/victory-candlestick/src/victory-candlestick.js b/packages/victory-candlestick/src/victory-candlestick.js deleted file mode 100644 index c10e9a0b2..000000000 --- a/packages/victory-candlestick/src/victory-candlestick.js +++ /dev/null @@ -1,308 +0,0 @@ -import PropTypes from "prop-types"; -import React from "react"; -import { - PropTypes as CustomPropTypes, - Helpers, - VictoryLabel, - addEvents, - VictoryContainer, - VictoryTheme, - DefaultTransitions, - CommonProps, - UserProps, -} from "victory-core"; -import { isNil, flatten } from "lodash"; -import Candle from "./candle"; -import { getDomain, getData, getBaseProps } from "./helper-methods"; - -/* eslint-disable no-magic-numbers */ -const fallbackProps = { - width: 450, - height: 300, - padding: 50, - candleColors: { - positive: "#ffffff", - negative: "#252525", - }, -}; - -const options = { - components: [ - { name: "lowLabels" }, - { name: "highLabels" }, - { name: "openLabels" }, - { name: "closeLabels" }, - { name: "labels" }, - { name: "data" }, - { name: "parent", index: "parent" }, - ], -}; - -const defaultData = [ - { x: new Date(2016, 6, 1), open: 5, close: 10, high: 15, low: 0 }, - { x: new Date(2016, 6, 2), open: 10, close: 15, high: 20, low: 5 }, - { x: new Date(2016, 6, 3), open: 15, close: 20, high: 25, low: 10 }, - { x: new Date(2016, 6, 4), open: 20, close: 25, high: 30, low: 15 }, - { x: new Date(2016, 6, 5), open: 25, close: 30, high: 35, low: 20 }, - { x: new Date(2016, 6, 6), open: 30, close: 35, high: 40, low: 25 }, - { x: new Date(2016, 6, 7), open: 35, close: 40, high: 45, low: 30 }, - { x: new Date(2016, 6, 8), open: 40, close: 45, high: 50, low: 35 }, -]; -/* eslint-enable no-magic-numbers */ -const datumHasXandY = (datum) => { - return !isNil(datum._x) && !isNil(datum._y); -}; - -class VictoryCandlestick extends React.Component { - static animationWhitelist = [ - "data", - "domain", - "height", - "padding", - "samples", - "size", - "style", - "width", - ]; - - static displayName = "VictoryCandlestick"; - static role = "candlestick"; - static defaultTransitions = DefaultTransitions.discreteTransitions(); - - static propTypes = { - ...CommonProps.baseProps, - ...CommonProps.dataProps, - candleColors: PropTypes.shape({ - positive: PropTypes.string, - negative: PropTypes.string, - }), - candleRatio: PropTypes.number, - candleWidth: PropTypes.oneOfType([PropTypes.func, PropTypes.number]), - close: PropTypes.oneOfType([ - PropTypes.func, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - PropTypes.arrayOf(PropTypes.string), - ]), - closeLabelComponent: PropTypes.element, - closeLabels: PropTypes.oneOfType([ - PropTypes.func, - PropTypes.array, - PropTypes.bool, - ]), - events: PropTypes.arrayOf( - PropTypes.shape({ - target: PropTypes.oneOf([ - "data", - "labels", - "open", - "openLabels", - "close", - "closeLabels", - "low", - "lowLabels", - "high", - "highLabels", - ]), - eventKey: PropTypes.oneOfType([ - PropTypes.array, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - ]), - eventHandlers: PropTypes.object, - }), - ), - high: PropTypes.oneOfType([ - PropTypes.func, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - PropTypes.arrayOf(PropTypes.string), - ]), - highLabelComponent: PropTypes.element, - highLabels: PropTypes.oneOfType([ - PropTypes.func, - PropTypes.array, - PropTypes.bool, - ]), - labelOrientation: PropTypes.oneOfType([ - PropTypes.oneOf(["top", "bottom", "left", "right"]), - PropTypes.shape({ - open: PropTypes.oneOf(["top", "bottom", "left", "right"]), - close: PropTypes.oneOf(["top", "bottom", "left", "right"]), - low: PropTypes.oneOf(["top", "bottom", "left", "right"]), - high: PropTypes.oneOf(["top", "bottom", "left", "right"]), - }), - ]), - low: PropTypes.oneOfType([ - PropTypes.func, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - PropTypes.arrayOf(PropTypes.string), - ]), - lowLabelComponent: PropTypes.element, - lowLabels: PropTypes.oneOfType([ - PropTypes.func, - PropTypes.array, - PropTypes.bool, - ]), - open: PropTypes.oneOfType([ - PropTypes.func, - CustomPropTypes.allOfType([ - CustomPropTypes.integer, - CustomPropTypes.nonNegative, - ]), - PropTypes.string, - PropTypes.arrayOf(PropTypes.string), - ]), - openLabelComponent: PropTypes.element, - openLabels: PropTypes.oneOfType([ - PropTypes.func, - PropTypes.array, - PropTypes.bool, - ]), - style: PropTypes.shape({ - data: PropTypes.object, - labels: PropTypes.object, - close: PropTypes.object, - closeLabels: PropTypes.object, - open: PropTypes.object, - openLabels: PropTypes.object, - high: PropTypes.object, - highLabels: PropTypes.object, - low: PropTypes.object, - lowLabels: PropTypes.object, - }), - wickStrokeWidth: PropTypes.number, - }; - - static defaultProps = { - defaultCandleWidth: 8, - containerComponent: , - data: defaultData, - dataComponent: , - groupComponent: , - labelComponent: , - highLabelComponent: , - lowLabelComponent: , - openLabelComponent: , - closeLabelComponent: , - samples: 50, - sortOrder: "ascending", - standalone: true, - theme: VictoryTheme.grayscale, - }; - - static getDomain = getDomain; - static getData = getData; - static getBaseProps = (props) => getBaseProps(props, fallbackProps); - static expectedComponents = [ - "openLabelComponent", - "closeLabelComponent", - "highLabelComponent", - "lowLabelComponent", - "dataComponent", - "labelComponent", - "groupComponent", - "containerComponent", - ]; - - // Overridden in native versions - shouldAnimate() { - return !!this.props.animate; - } - - shouldRenderDatum(datum) { - return ( - !isNil(datum._x) && - !isNil(datum._high) && - !isNil(datum._low) && - !isNil(datum._close) && - !isNil(datum._open) - ); - } - - renderCandleData(props, shouldRenderDatum = datumHasXandY) { - const { dataComponent, labelComponent, groupComponent } = props; - const types = ["close", "open", "low", "high"]; - - const dataComponents = this.dataKeys.reduce( - (validDataComponents, _dataKey, index) => { - const dataProps = this.getComponentProps(dataComponent, "data", index); - if (shouldRenderDatum(dataProps.datum)) { - validDataComponents.push( - React.cloneElement(dataComponent, dataProps), - ); - } - return validDataComponents; - }, - [], - ); - - const labelComponents = flatten( - types.map((type) => { - const components = this.dataKeys.map((key, index) => { - const name = `${type}Labels`; - const baseComponent = props[`${type}LabelComponent`]; - const labelProps = this.getComponentProps(baseComponent, name, index); - if (labelProps.text !== undefined && labelProps.text !== null) { - return React.cloneElement(baseComponent, labelProps); - } - return undefined; - }); - return components.filter(Boolean); - }), - ); - - const labelsComponents = this.dataKeys - .map((_dataKey, index) => { - const labelProps = this.getComponentProps( - labelComponent, - "labels", - index, - ); - if (labelProps.text !== undefined && labelProps.text !== null) { - return React.cloneElement(labelComponent, labelProps); - } - return undefined; - }) - .filter(Boolean); - - const children = [ - ...dataComponents, - ...labelComponents, - ...labelsComponents, - ]; - return this.renderContainer(groupComponent, children); - } - - render() { - const { animationWhitelist, role } = VictoryCandlestick; - const props = Helpers.modifyProps(this.props, fallbackProps, role); - - if (this.shouldAnimate()) { - return this.animateComponent(props, animationWhitelist); - } - - const children = this.renderCandleData(props, this.shouldRenderDatum); - - const component = props.standalone - ? this.renderContainer(props.containerComponent, children) - : children; - - return UserProps.withSafeUserProps(component, props); - } -} - -export default addEvents(VictoryCandlestick, options); diff --git a/packages/victory-candlestick/src/victory-candlestick.test.js b/packages/victory-candlestick/src/victory-candlestick.test.tsx similarity index 94% rename from packages/victory-candlestick/src/victory-candlestick.test.js rename to packages/victory-candlestick/src/victory-candlestick.test.tsx index c3e6601d1..178285e37 100644 --- a/packages/victory-candlestick/src/victory-candlestick.test.js +++ b/packages/victory-candlestick/src/victory-candlestick.test.tsx @@ -47,14 +47,14 @@ describe("components/victory-candlestick", () => { it("renders an svg with the correct width and height", () => { const { container } = render(); const svg = container.querySelector("svg"); - expect(svg.getAttribute("style")).toContain("width: 100%; height: 100%"); + expect(svg?.getAttribute("style")).toContain("width: 100%; height: 100%"); }); it("renders an svg with the correct viewBox", () => { const { container } = render(); const svg = container.querySelector("svg"); const viewBoxValue = `0 0 ${450} ${300}`; - expect(svg.getAttribute("viewBox")).toEqual(viewBoxValue); + expect(svg?.getAttribute("viewBox")).toEqual(viewBoxValue); }); it("renders 8 points", () => { @@ -100,7 +100,9 @@ describe("components/victory-candlestick", () => { , ); const candles = container.querySelectorAll("rect"); - const xValues = Array.from(candles).map((bar) => bar.getAttribute("x")); + const xValues = Array.from(candles).map((bar) => + Number(bar.getAttribute("x")), + ); const xValuesAscending = [...xValues].sort((a, b) => a - b); expect(xValues).toEqual(xValuesAscending); }); @@ -113,7 +115,9 @@ describe("components/victory-candlestick", () => { , ); const candles = container.querySelectorAll("rect"); - const xValues = Array.from(candles).map((bar) => bar.getAttribute("x")); + const xValues = Array.from(candles).map((bar) => + Number(bar.getAttribute("x")), + ); const xValuesDescending = [...xValues].sort((a, b) => b - a); expect(xValues).toEqual(xValuesDescending); }); @@ -155,6 +159,7 @@ describe("components/victory-candlestick", () => { it("renders data values with null accessor", () => { const data = range(10); const { container } = render( + // @ts-expect-error "'null' is not assignable to 'x'" { ariaLabel={({ datum }) => `open ${datum.open}, close ${datum.close}` } - tabIndex={({ index }) => index + 5} + tabIndex={({ index }) => Number(index) + 5} /> } />, diff --git a/packages/victory-candlestick/src/victory-candlestick.tsx b/packages/victory-candlestick/src/victory-candlestick.tsx new file mode 100644 index 000000000..73fead7da --- /dev/null +++ b/packages/victory-candlestick/src/victory-candlestick.tsx @@ -0,0 +1,305 @@ +import React from "react"; +import { + Helpers, + VictoryLabel, + addEvents, + VictoryContainer, + VictoryTheme, + DefaultTransitions, + UserProps, + StringOrNumberOrCallback, + EventPropTypeInterface, + OrientationTypes, + VictoryCommonProps, + VictoryDatableProps, + VictoryLabelStyleObject, + VictoryLabelableProps, + VictoryMultiLabelableProps, + VictoryStyleObject, + NumberOrCallback, + EventsMixinClass, +} from "victory-core"; +import { isNil } from "lodash"; +import { Candle } from "./candle"; +import { getDomain, getData, getBaseProps } from "./helper-methods"; + +export interface VictoryCandlestickStyleInterface { + close?: VictoryStyleObject; + closeLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + data?: VictoryStyleObject; + high?: VictoryStyleObject; + highLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + labels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + low?: VictoryStyleObject; + lowLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + open?: VictoryStyleObject; + openLabels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + parent?: VictoryStyleObject; +} + +export type VictoryCandlestickLabelsType = + | (string | number)[] + | boolean + | ((datum: any) => number); + +export interface VictoryCandlestickProps + extends Omit, + VictoryDatableProps, + VictoryLabelableProps, + VictoryMultiLabelableProps { + candleColors?: { + positive?: string; + negative?: string; + }; + candleRatio?: number; + candleWidth?: NumberOrCallback; + close?: StringOrNumberOrCallback | string[]; + closeLabelComponent?: React.ReactElement; + closeLabels?: VictoryCandlestickLabelsType; + eventKey?: StringOrNumberOrCallback | string[]; + events?: EventPropTypeInterface< + | "data" + | "labels" + | "open" + | "openLabels" + | "close" + | "closeLabels" + | "low" + | "lowLabels" + | "high" + | "highLabels", + StringOrNumberOrCallback | string[] + >[]; + high?: StringOrNumberOrCallback | string[]; + highLabelComponent?: React.ReactElement; + highLabels?: VictoryCandlestickLabelsType; + labelOrientation?: + | OrientationTypes + | { + open?: OrientationTypes; + close?: OrientationTypes; + low?: OrientationTypes; + high?: OrientationTypes; + }; + low?: StringOrNumberOrCallback | string[]; + lowLabelComponent?: React.ReactElement; + lowLabels?: VictoryCandlestickLabelsType; + open?: StringOrNumberOrCallback | string[]; + openLabelComponent?: React.ReactElement; + openLabels?: VictoryCandlestickLabelsType; + size?: number; + style?: VictoryCandlestickStyleInterface; + wickStrokeWidth?: number; +} + +/* eslint-disable no-magic-numbers */ +const fallbackProps = { + width: 450, + height: 300, + padding: 50, + candleColors: { + positive: "#ffffff", + negative: "#252525", + }, +}; + +const options = { + components: [ + { name: "lowLabels" }, + { name: "highLabels" }, + { name: "openLabels" }, + { name: "closeLabels" }, + { name: "labels" }, + { name: "data" }, + { name: "parent", index: "parent" }, + ], +}; + +const defaultData = [ + { x: new Date(2016, 6, 1), open: 5, close: 10, high: 15, low: 0 }, + { x: new Date(2016, 6, 2), open: 10, close: 15, high: 20, low: 5 }, + { x: new Date(2016, 6, 3), open: 15, close: 20, high: 25, low: 10 }, + { x: new Date(2016, 6, 4), open: 20, close: 25, high: 30, low: 15 }, + { x: new Date(2016, 6, 5), open: 25, close: 30, high: 35, low: 20 }, + { x: new Date(2016, 6, 6), open: 30, close: 35, high: 40, low: 25 }, + { x: new Date(2016, 6, 7), open: 35, close: 40, high: 45, low: 30 }, + { x: new Date(2016, 6, 8), open: 40, close: 45, high: 50, low: 35 }, +]; +/* eslint-enable no-magic-numbers */ +const datumHasXandY = (datum) => { + return !isNil(datum._x) && !isNil(datum._y); +}; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface VictoryCandlestickBase + extends EventsMixinClass {} + +/** + * VictoryCandlestick renders a dataset as a series of candlesticks. + * VictoryCandlestick can be composed with VictoryChart to create candlestick charts. + */ +class VictoryCandlestickBase extends React.Component { + static animationWhitelist = [ + "data", + "domain", + "height", + "padding", + "samples", + "size", + "style", + "width", + ]; + + static displayName = "VictoryCandlestick"; + static role = "candlestick"; + static defaultTransitions = DefaultTransitions.discreteTransitions(); + + static defaultProps: VictoryCandlestickProps = { + containerComponent: , + data: defaultData, + dataComponent: , + groupComponent: , + labelComponent: , + highLabelComponent: , + lowLabelComponent: , + openLabelComponent: , + closeLabelComponent: , + samples: 50, + sortOrder: "ascending", + standalone: true, + theme: VictoryTheme.grayscale, + }; + + static getDomain = getDomain; + static getData = getData; + static getBaseProps = (props: VictoryCandlestickProps) => + getBaseProps(props, fallbackProps); + static expectedComponents = [ + "openLabelComponent", + "closeLabelComponent", + "highLabelComponent", + "lowLabelComponent", + "dataComponent", + "labelComponent", + "groupComponent", + "containerComponent", + ]; + + // Overridden in native versions + shouldAnimate() { + return !!this.props.animate; + } + + shouldRenderDatum = (datum) => { + return ( + !isNil(datum._x) && + !isNil(datum._high) && + !isNil(datum._low) && + !isNil(datum._close) && + !isNil(datum._open) + ); + }; + + renderCandleData( + props: VictoryCandlestickProps, + shouldRenderDatum = datumHasXandY, + ) { + const { dataComponent, labelComponent, groupComponent } = props; + const types = ["close", "open", "low", "high"]; + + if (!groupComponent) { + throw new Error("VictoryCandlestick expects a groupComponent prop"); + } + + const children: React.ReactElement[] = []; + + if (dataComponent) { + const dataComponents = this.dataKeys.reduce( + (validDataComponents, _dataKey, index) => { + const dataProps = this.getComponentProps( + dataComponent, + "data", + index, + ); + if (shouldRenderDatum((dataProps as any).datum)) { + validDataComponents.push( + React.cloneElement(dataComponent, dataProps), + ); + } + return validDataComponents; + }, + [], + ); + + children.push(...dataComponents); + } + + const labelComponents = types.flatMap((type) => + this.dataKeys + .map((key, index) => { + const name = `${type}Labels`; + const baseComponent: React.ReactElement = + props[`${type}LabelComponent`]; + const labelProps = this.getComponentProps(baseComponent, name, index); + if ( + (labelProps as any).text !== undefined && + (labelProps as any).text !== null + ) { + return React.cloneElement(baseComponent, labelProps); + } + return undefined; + }) + .filter( + (comp: React.ReactElement | undefined): comp is React.ReactElement => + comp !== undefined, + ), + ); + + children.push(...labelComponents); + + if (labelComponent) { + const labelsComponents = this.dataKeys + .map((_dataKey, index) => { + const labelProps = this.getComponentProps( + labelComponent, + "labels", + index, + ); + if ( + (labelProps as any).text !== undefined && + (labelProps as any).text !== null + ) { + return React.cloneElement(labelComponent, labelProps); + } + return undefined; + }) + .filter( + (comp: React.ReactElement | undefined): comp is React.ReactElement => + comp !== undefined, + ); + + children.push(...labelsComponents); + } + + return this.renderContainer(groupComponent, children); + } + + render(): React.ReactElement { + const { animationWhitelist, role } = VictoryCandlestick; + const props = Helpers.modifyProps(this.props, fallbackProps, role); + + if (this.shouldAnimate()) { + return this.animateComponent(props, animationWhitelist); + } + + const children = this.renderCandleData(props, this.shouldRenderDatum); + + const component = props.standalone + ? this.renderContainer(props.containerComponent, children) + : children; + + return UserProps.withSafeUserProps(component, props); + } +} + +export const VictoryCandlestick = addEvents(VictoryCandlestickBase, options); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a059dcf9..a18a57562 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -349,14 +349,18 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 + victory-candlestick: '*' victory-chart: ^36.8.1 victory-core: ^36.8.1 + victory-vendor: ^36.8.1 dependencies: lodash: 4.17.21 prop-types: 15.8.1 victory-core: link:../victory-core devDependencies: + victory-candlestick: 'link:' victory-chart: link:../victory-chart + victory-vendor: link:../victory-vendor packages/victory-canvas: specifiers: From 8854c1616181a28b0df4db46cd2dd59ea1e18af6 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Tue, 16 Jan 2024 12:15:16 -0600 Subject: [PATCH 18/29] Fix the label background position when using dy fns (#2720) --- .changeset/moody-mayflies-attack.md | 5 +++ .../src/victory-label/victory-label.tsx | 2 +- stories/victory-label.stories.js | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/moody-mayflies-attack.md diff --git a/.changeset/moody-mayflies-attack.md b/.changeset/moody-mayflies-attack.md new file mode 100644 index 000000000..997e98d8c --- /dev/null +++ b/.changeset/moody-mayflies-attack.md @@ -0,0 +1,5 @@ +--- +"victory-core": patch +--- + +Fix the label background position when using dy fns diff --git a/packages/victory-core/src/victory-label/victory-label.tsx b/packages/victory-core/src/victory-label/victory-label.tsx index 3b671a6a9..41dcbe9a9 100644 --- a/packages/victory-core/src/victory-label/victory-label.tsx +++ b/packages/victory-core/src/victory-label/victory-label.tsx @@ -508,7 +508,7 @@ const getCalculatedProps = (props: T) => { verticalAnchor, dx, dy, - originalDy: props.dy, + originalDy: Helpers.evaluateProp(props.dy, props), transform, x, y, diff --git a/stories/victory-label.stories.js b/stories/victory-label.stories.js index 66b094861..20c9752e4 100644 --- a/stories/victory-label.stories.js +++ b/stories/victory-label.stories.js @@ -581,6 +581,38 @@ export const BackgroundStyles = () => { /> } /> + (datum.y > 0 ? -5 : 8)} + verticalAnchor="end" + backgroundPadding={{ top: 5, right: 5, bottom: 5, left: 5 }} + backgroundStyle={{ fill: "plum", stroke: "#000000" }} + text={[ + "Victory is awesome.", + "background styles", + "work with dy functions", + ]} + /> + } + /> + (datum.y > 0 ? -5 : 8)} + verticalAnchor="end" + backgroundPadding={{ top: 5, right: 5, bottom: 5, left: 5 }} + backgroundStyle={{ fill: "thistle", stroke: "#000000" }} + text={[ + "Victory is awesome.", + "background styles", + "work with dx functions", + ]} + /> + } + /> ); }; From d7675fec66568110c2a83eb524a9889e024e859e Mon Sep 17 00:00:00 2001 From: victory-ci <67923435+victory-ci@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:27:30 -0600 Subject: [PATCH 19/29] Version Packages (#2707) Co-authored-by: github-actions[bot] --- .changeset/angry-pens-provide.md | 7 - .changeset/beige-flowers-confess.md | 5 - .changeset/moody-mayflies-attack.md | 5 - .changeset/nine-cups-complain.md | 5 - .changeset/orange-items-cross.md | 5 - .changeset/orange-mirrors-swim.md | 6 - .changeset/seven-brooms-destroy.md | 5 - .changeset/spotty-apples-carry.md | 5 - .changeset/young-squids-lay.md | 5 - packages/victory-area/CHANGELOG.md | 2 + packages/victory-area/package.json | 6 +- packages/victory-axis/CHANGELOG.md | 2 + packages/victory-axis/package.json | 4 +- packages/victory-bar/CHANGELOG.md | 6 + packages/victory-bar/package.json | 6 +- packages/victory-box-plot/CHANGELOG.md | 2 + packages/victory-box-plot/package.json | 8 +- packages/victory-brush-container/CHANGELOG.md | 2 + packages/victory-brush-container/package.json | 4 +- packages/victory-brush-line/CHANGELOG.md | 2 + packages/victory-brush-line/package.json | 4 +- packages/victory-candlestick/CHANGELOG.md | 6 + packages/victory-candlestick/package.json | 8 +- packages/victory-canvas/CHANGELOG.md | 6 + packages/victory-canvas/package.json | 6 +- packages/victory-chart/CHANGELOG.md | 6 + packages/victory-chart/package.json | 10 +- packages/victory-core/CHANGELOG.md | 8 + packages/victory-core/package.json | 4 +- .../victory-create-container/CHANGELOG.md | 2 + .../victory-create-container/package.json | 14 +- .../victory-cursor-container/CHANGELOG.md | 2 + .../victory-cursor-container/package.json | 4 +- packages/victory-errorbar/CHANGELOG.md | 2 + packages/victory-errorbar/package.json | 4 +- packages/victory-group/CHANGELOG.md | 6 + packages/victory-group/package.json | 6 +- packages/victory-histogram/CHANGELOG.md | 2 + packages/victory-histogram/package.json | 8 +- packages/victory-legend/CHANGELOG.md | 6 + packages/victory-legend/package.json | 4 +- packages/victory-line/CHANGELOG.md | 2 + packages/victory-line/package.json | 6 +- packages/victory-native/CHANGELOG.md | 6 + packages/victory-native/package.json | 56 ++--- packages/victory-pie/CHANGELOG.md | 2 + packages/victory-pie/package.json | 6 +- packages/victory-polar-axis/CHANGELOG.md | 6 + packages/victory-polar-axis/package.json | 4 +- packages/victory-scatter/CHANGELOG.md | 2 + packages/victory-scatter/package.json | 4 +- .../victory-selection-container/CHANGELOG.md | 6 + .../victory-selection-container/package.json | 6 +- packages/victory-shared-events/CHANGELOG.md | 2 + packages/victory-shared-events/package.json | 4 +- packages/victory-stack/CHANGELOG.md | 6 + packages/victory-stack/package.json | 6 +- packages/victory-tooltip/CHANGELOG.md | 2 + packages/victory-tooltip/package.json | 4 +- packages/victory-vendor/CHANGELOG.md | 2 + packages/victory-vendor/package.json | 2 +- .../victory-voronoi-container/CHANGELOG.md | 2 + .../victory-voronoi-container/package.json | 6 +- packages/victory-voronoi/CHANGELOG.md | 2 + packages/victory-voronoi/package.json | 4 +- packages/victory-zoom-container/CHANGELOG.md | 2 + packages/victory-zoom-container/package.json | 4 +- packages/victory/CHANGELOG.md | 2 + packages/victory/package.json | 56 ++--- pnpm-lock.yaml | 208 +++++++++--------- 70 files changed, 344 insertions(+), 286 deletions(-) delete mode 100644 .changeset/angry-pens-provide.md delete mode 100644 .changeset/beige-flowers-confess.md delete mode 100644 .changeset/moody-mayflies-attack.md delete mode 100644 .changeset/nine-cups-complain.md delete mode 100644 .changeset/orange-items-cross.md delete mode 100644 .changeset/orange-mirrors-swim.md delete mode 100644 .changeset/seven-brooms-destroy.md delete mode 100644 .changeset/spotty-apples-carry.md delete mode 100644 .changeset/young-squids-lay.md diff --git a/.changeset/angry-pens-provide.md b/.changeset/angry-pens-provide.md deleted file mode 100644 index 39d6fb9b2..000000000 --- a/.changeset/angry-pens-provide.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"victory-chart": patch -"victory-native": patch -"victory-stack": patch ---- - -Assign merged props to a const instead of modifying initialProps diff --git a/.changeset/beige-flowers-confess.md b/.changeset/beige-flowers-confess.md deleted file mode 100644 index 8f935c9d7..000000000 --- a/.changeset/beige-flowers-confess.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-canvas": patch ---- - -Migrate victory-canvas to TypeScript diff --git a/.changeset/moody-mayflies-attack.md b/.changeset/moody-mayflies-attack.md deleted file mode 100644 index 997e98d8c..000000000 --- a/.changeset/moody-mayflies-attack.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-core": patch ---- - -Fix the label background position when using dy fns diff --git a/.changeset/nine-cups-complain.md b/.changeset/nine-cups-complain.md deleted file mode 100644 index 346da3210..000000000 --- a/.changeset/nine-cups-complain.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-candlestick": patch ---- - -Migrate victory-candlestick to TypeScript diff --git a/.changeset/orange-items-cross.md b/.changeset/orange-items-cross.md deleted file mode 100644 index 9aceb3dc4..000000000 --- a/.changeset/orange-items-cross.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-selection-container": patch ---- - -Migrated victory-selection-container to TypeScript diff --git a/.changeset/orange-mirrors-swim.md b/.changeset/orange-mirrors-swim.md deleted file mode 100644 index e319b93b7..000000000 --- a/.changeset/orange-mirrors-swim.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"victory-core": patch -"victory-legend": patch ---- - -Migrate victory-legend to TypeScript diff --git a/.changeset/seven-brooms-destroy.md b/.changeset/seven-brooms-destroy.md deleted file mode 100644 index b12063f1d..000000000 --- a/.changeset/seven-brooms-destroy.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-group": patch ---- - -Fix victory-group animation diff --git a/.changeset/spotty-apples-carry.md b/.changeset/spotty-apples-carry.md deleted file mode 100644 index fb9454f2a..000000000 --- a/.changeset/spotty-apples-carry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-polar-axis": patch ---- - -Migrate polar axis to typescript diff --git a/.changeset/young-squids-lay.md b/.changeset/young-squids-lay.md deleted file mode 100644 index 22c0c3a63..000000000 --- a/.changeset/young-squids-lay.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"victory-bar": patch ---- - -Migrate victory-bar to TypeScript diff --git a/packages/victory-area/CHANGELOG.md b/packages/victory-area/CHANGELOG.md index f0b091061..6700d0592 100644 --- a/packages/victory-area/CHANGELOG.md +++ b/packages/victory-area/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-area +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-area/package.json b/packages/victory-area/package.json index ddcf1db95..c8aaa47d6 100644 --- a/packages/victory-area/package.json +++ b/packages/victory-area/package.json @@ -1,6 +1,6 @@ { "name": "victory-area", - "version": "36.8.1", + "version": "36.8.2", "description": "Area Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1", - "victory-vendor": "^36.8.1" + "victory-core": "^36.8.2", + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-axis/CHANGELOG.md b/packages/victory-axis/CHANGELOG.md index d4633d26a..3d6fd1f9d 100644 --- a/packages/victory-axis/CHANGELOG.md +++ b/packages/victory-axis/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-axis +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-axis/package.json b/packages/victory-axis/package.json index 9faed546f..70a5df117 100644 --- a/packages/victory-axis/package.json +++ b/packages/victory-axis/package.json @@ -1,6 +1,6 @@ { "name": "victory-axis", - "version": "36.8.1", + "version": "36.8.2", "description": "Axis Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-bar/CHANGELOG.md b/packages/victory-bar/CHANGELOG.md index 15ee7172d..dfb724fcc 100644 --- a/packages/victory-bar/CHANGELOG.md +++ b/packages/victory-bar/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-bar +## 36.8.2 + +### Patch Changes + +- Migrate victory-bar to TypeScript ([#2709](https://github.com/FormidableLabs/victory/pull/2709)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-bar/package.json b/packages/victory-bar/package.json index ae8980e04..0148dc071 100644 --- a/packages/victory-bar/package.json +++ b/packages/victory-bar/package.json @@ -1,6 +1,6 @@ { "name": "victory-bar", - "version": "36.8.1", + "version": "36.8.2", "description": "Bar Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1", - "victory-vendor": "^36.8.1" + "victory-core": "^36.8.2", + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-box-plot/CHANGELOG.md b/packages/victory-box-plot/CHANGELOG.md index 2dd66f287..14db9e94e 100644 --- a/packages/victory-box-plot/CHANGELOG.md +++ b/packages/victory-box-plot/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-box-plot +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-box-plot/package.json b/packages/victory-box-plot/package.json index a106babbd..b8165e5d0 100644 --- a/packages/victory-box-plot/package.json +++ b/packages/victory-box-plot/package.json @@ -1,6 +1,6 @@ { "name": "victory-box-plot", - "version": "36.8.1", + "version": "36.8.2", "description": "Box Plot Component for Victory", "keywords": [ "data visualization", @@ -22,15 +22,15 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1", - "victory-vendor": "^36.8.1" + "victory-core": "^36.8.2", + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { "victory-box-plot": "*", - "victory-chart": "^36.8.1" + "victory-chart": "^36.8.2" }, "publishConfig": { "provenance": true diff --git a/packages/victory-brush-container/CHANGELOG.md b/packages/victory-brush-container/CHANGELOG.md index 95d7add9e..3da7a704a 100644 --- a/packages/victory-brush-container/CHANGELOG.md +++ b/packages/victory-brush-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-brush-container +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-brush-container/package.json b/packages/victory-brush-container/package.json index 3d8c5628a..7cc56a6b0 100644 --- a/packages/victory-brush-container/package.json +++ b/packages/victory-brush-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-brush-container", - "version": "36.8.1", + "version": "36.8.2", "description": "Interactive Brush Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-brush-line/CHANGELOG.md b/packages/victory-brush-line/CHANGELOG.md index b3ee0f0c7..4457f4ea4 100644 --- a/packages/victory-brush-line/CHANGELOG.md +++ b/packages/victory-brush-line/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-brush-line +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-brush-line/package.json b/packages/victory-brush-line/package.json index cd17ef62d..bc37bbcd4 100644 --- a/packages/victory-brush-line/package.json +++ b/packages/victory-brush-line/package.json @@ -1,6 +1,6 @@ { "name": "victory-brush-line", - "version": "36.8.1", + "version": "36.8.2", "description": "Interactive Brush Line Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-candlestick/CHANGELOG.md b/packages/victory-candlestick/CHANGELOG.md index 44f054bb8..5774fd4c3 100644 --- a/packages/victory-candlestick/CHANGELOG.md +++ b/packages/victory-candlestick/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-candlestick +## 36.8.2 + +### Patch Changes + +- Migrate victory-candlestick to TypeScript ([#2716](https://github.com/FormidableLabs/victory/pull/2716)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-candlestick/package.json b/packages/victory-candlestick/package.json index c10952f60..b29e5c23b 100644 --- a/packages/victory-candlestick/package.json +++ b/packages/victory-candlestick/package.json @@ -1,6 +1,6 @@ { "name": "victory-candlestick", - "version": "36.8.1", + "version": "36.8.2", "description": "Candlestick Component for Victory", "keywords": [ "data visualization", @@ -22,14 +22,14 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { - "victory-vendor": "^36.8.1", - "victory-chart": "^36.8.1", + "victory-vendor": "^36.8.2", + "victory-chart": "^36.8.2", "victory-candlestick": "*" }, "publishConfig": { diff --git a/packages/victory-canvas/CHANGELOG.md b/packages/victory-canvas/CHANGELOG.md index 14f6869b1..c3766b56e 100644 --- a/packages/victory-canvas/CHANGELOG.md +++ b/packages/victory-canvas/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-canvas +## 36.8.2 + +### Patch Changes + +- Migrate victory-canvas to TypeScript ([#2710](https://github.com/FormidableLabs/victory/pull/2710)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-canvas/package.json b/packages/victory-canvas/package.json index a1a0a29c3..4dd6513b1 100644 --- a/packages/victory-canvas/package.json +++ b/packages/victory-canvas/package.json @@ -1,6 +1,6 @@ { "name": "victory-canvas", - "version": "36.8.1", + "version": "36.8.2", "description": "HTML5 Canvas Components for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-bar": "^36.8.1", - "victory-core": "^36.8.1" + "victory-bar": "^36.8.2", + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-chart/CHANGELOG.md b/packages/victory-chart/CHANGELOG.md index bdaaff88e..e2ceb16a3 100644 --- a/packages/victory-chart/CHANGELOG.md +++ b/packages/victory-chart/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-chart +## 36.8.2 + +### Patch Changes + +- Assign merged props to a const instead of modifying initialProps ([#2718](https://github.com/FormidableLabs/victory/pull/2718)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-chart/package.json b/packages/victory-chart/package.json index 6df2219e3..74fd2e380 100644 --- a/packages/victory-chart/package.json +++ b/packages/victory-chart/package.json @@ -1,6 +1,6 @@ { "name": "victory-chart", - "version": "36.8.1", + "version": "36.8.2", "description": "Chart Component for Victory", "keywords": [ "data visualization", @@ -23,10 +23,10 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-axis": "^36.8.1", - "victory-core": "^36.8.1", - "victory-polar-axis": "^36.8.1", - "victory-shared-events": "^36.8.1" + "victory-axis": "^36.8.2", + "victory-core": "^36.8.2", + "victory-polar-axis": "^36.8.2", + "victory-shared-events": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-core/CHANGELOG.md b/packages/victory-core/CHANGELOG.md index 46c4a108c..d1144f992 100644 --- a/packages/victory-core/CHANGELOG.md +++ b/packages/victory-core/CHANGELOG.md @@ -1,5 +1,13 @@ # victory-core +## 36.8.2 + +### Patch Changes + +- Fix the label background position when using dy fns ([#2720](https://github.com/FormidableLabs/victory/pull/2720)) + +* Migrate victory-legend to TypeScript ([#2712](https://github.com/FormidableLabs/victory/pull/2712)) + ## 36.8.1 ### Patch Changes diff --git a/packages/victory-core/package.json b/packages/victory-core/package.json index 7bf913bd0..eb043f2eb 100644 --- a/packages/victory-core/package.json +++ b/packages/victory-core/package.json @@ -1,6 +1,6 @@ { "name": "victory-core", - "version": "36.8.1", + "version": "36.8.2", "description": "Victory Core", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "lodash": "^4.17.21", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-vendor": "^36.8.1" + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-create-container/CHANGELOG.md b/packages/victory-create-container/CHANGELOG.md index 2d0d03901..c6a26a217 100644 --- a/packages/victory-create-container/CHANGELOG.md +++ b/packages/victory-create-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-create-container +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-create-container/package.json b/packages/victory-create-container/package.json index baf2d4eb5..95c258124 100644 --- a/packages/victory-create-container/package.json +++ b/packages/victory-create-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-create-container", - "version": "36.8.1", + "version": "36.8.2", "description": "Container Helper for Victory", "keywords": [ "data visualization", @@ -21,12 +21,12 @@ "license": "MIT", "dependencies": { "lodash": "^4.17.19", - "victory-brush-container": "^36.8.1", - "victory-core": "^36.8.1", - "victory-cursor-container": "^36.8.1", - "victory-selection-container": "^36.8.1", - "victory-voronoi-container": "^36.8.1", - "victory-zoom-container": "^36.8.1" + "victory-brush-container": "^36.8.2", + "victory-core": "^36.8.2", + "victory-cursor-container": "^36.8.2", + "victory-selection-container": "^36.8.2", + "victory-voronoi-container": "^36.8.2", + "victory-zoom-container": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-cursor-container/CHANGELOG.md b/packages/victory-cursor-container/CHANGELOG.md index f86f08198..46dcaa182 100644 --- a/packages/victory-cursor-container/CHANGELOG.md +++ b/packages/victory-cursor-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-cursor-container +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-cursor-container/package.json b/packages/victory-cursor-container/package.json index 33e2356a4..18448603b 100644 --- a/packages/victory-cursor-container/package.json +++ b/packages/victory-cursor-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-cursor-container", - "version": "36.8.1", + "version": "36.8.2", "description": "Interactive Cursor Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-errorbar/CHANGELOG.md b/packages/victory-errorbar/CHANGELOG.md index 8417e94e4..960e99da1 100644 --- a/packages/victory-errorbar/CHANGELOG.md +++ b/packages/victory-errorbar/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-errorbar +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-errorbar/package.json b/packages/victory-errorbar/package.json index da02628e8..60e18c211 100644 --- a/packages/victory-errorbar/package.json +++ b/packages/victory-errorbar/package.json @@ -1,6 +1,6 @@ { "name": "victory-errorbar", - "version": "36.8.1", + "version": "36.8.2", "description": "Error Bar Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-group/CHANGELOG.md b/packages/victory-group/CHANGELOG.md index 5f7ea3ba4..3e0287b80 100644 --- a/packages/victory-group/CHANGELOG.md +++ b/packages/victory-group/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-group +## 36.8.2 + +### Patch Changes + +- Fix victory-group animation ([#2717](https://github.com/FormidableLabs/victory/pull/2717)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-group/package.json b/packages/victory-group/package.json index 0d329cdfa..13a3e35a8 100644 --- a/packages/victory-group/package.json +++ b/packages/victory-group/package.json @@ -1,6 +1,6 @@ { "name": "victory-group", - "version": "36.8.1", + "version": "36.8.2", "description": "Group Layout Component for Victory", "keywords": [ "data visualization", @@ -23,8 +23,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.1", - "victory-shared-events": "^36.8.1" + "victory-core": "^36.8.2", + "victory-shared-events": "^36.8.2" }, "devDependencies": { "victory-bar": "*", diff --git a/packages/victory-histogram/CHANGELOG.md b/packages/victory-histogram/CHANGELOG.md index eac650651..1a985e7c4 100644 --- a/packages/victory-histogram/CHANGELOG.md +++ b/packages/victory-histogram/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-histogram +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-histogram/package.json b/packages/victory-histogram/package.json index 3d993dd65..cf7895f77 100644 --- a/packages/victory-histogram/package.json +++ b/packages/victory-histogram/package.json @@ -1,6 +1,6 @@ { "name": "victory-histogram", - "version": "36.8.1", + "version": "36.8.2", "description": "Histogram Component for Victory", "keywords": [ "data visualization", @@ -23,9 +23,9 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-bar": "^36.8.1", - "victory-core": "^36.8.1", - "victory-vendor": "^36.8.1" + "victory-bar": "^36.8.2", + "victory-core": "^36.8.2", + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-legend/CHANGELOG.md b/packages/victory-legend/CHANGELOG.md index 6604064d9..244c29c15 100644 --- a/packages/victory-legend/CHANGELOG.md +++ b/packages/victory-legend/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-legend +## 36.8.2 + +### Patch Changes + +- Migrate victory-legend to TypeScript ([#2712](https://github.com/FormidableLabs/victory/pull/2712)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-legend/package.json b/packages/victory-legend/package.json index 86ae99e50..868c8a0d1 100644 --- a/packages/victory-legend/package.json +++ b/packages/victory-legend/package.json @@ -1,6 +1,6 @@ { "name": "victory-legend", - "version": "36.8.1", + "version": "36.8.2", "description": "Legend Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-line/CHANGELOG.md b/packages/victory-line/CHANGELOG.md index b6f716c72..e204ab6a8 100644 --- a/packages/victory-line/CHANGELOG.md +++ b/packages/victory-line/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-line +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-line/package.json b/packages/victory-line/package.json index 3a24c62e5..355ddabfb 100644 --- a/packages/victory-line/package.json +++ b/packages/victory-line/package.json @@ -1,6 +1,6 @@ { "name": "victory-line", - "version": "36.8.1", + "version": "36.8.2", "description": "Line Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1", - "victory-vendor": "^36.8.1" + "victory-core": "^36.8.2", + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-native/CHANGELOG.md b/packages/victory-native/CHANGELOG.md index d37f69ef6..3d3201c8f 100644 --- a/packages/victory-native/CHANGELOG.md +++ b/packages/victory-native/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-native +## 36.8.2 + +### Patch Changes + +- Assign merged props to a const instead of modifying initialProps ([#2718](https://github.com/FormidableLabs/victory/pull/2718)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-native/package.json b/packages/victory-native/package.json index d898fd134..5c5500511 100644 --- a/packages/victory-native/package.json +++ b/packages/victory-native/package.json @@ -1,6 +1,6 @@ { "name": "victory-native", - "version": "36.8.1", + "version": "36.8.2", "description": "Native Port for Victory", "keywords": [ "data visualization", @@ -27,33 +27,33 @@ "lodash": "^4.17.21", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory": "^36.8.1", - "victory-area": "^36.8.1", - "victory-axis": "^36.8.1", - "victory-bar": "^36.8.1", - "victory-box-plot": "^36.8.1", - "victory-brush-container": "^36.8.1", - "victory-brush-line": "^36.8.1", - "victory-candlestick": "^36.8.1", - "victory-chart": "^36.8.1", - "victory-core": "^36.8.1", - "victory-create-container": "^36.8.1", - "victory-cursor-container": "^36.8.1", - "victory-errorbar": "^36.8.1", - "victory-group": "^36.8.1", - "victory-histogram": "^36.8.1", - "victory-legend": "^36.8.1", - "victory-line": "^36.8.1", - "victory-pie": "^36.8.1", - "victory-polar-axis": "^36.8.1", - "victory-scatter": "^36.8.1", - "victory-selection-container": "^36.8.1", - "victory-shared-events": "^36.8.1", - "victory-stack": "^36.8.1", - "victory-tooltip": "^36.8.1", - "victory-voronoi": "^36.8.1", - "victory-voronoi-container": "^36.8.1", - "victory-zoom-container": "^36.8.1" + "victory": "^36.8.2", + "victory-area": "^36.8.2", + "victory-axis": "^36.8.2", + "victory-bar": "^36.8.2", + "victory-box-plot": "^36.8.2", + "victory-brush-container": "^36.8.2", + "victory-brush-line": "^36.8.2", + "victory-candlestick": "^36.8.2", + "victory-chart": "^36.8.2", + "victory-core": "^36.8.2", + "victory-create-container": "^36.8.2", + "victory-cursor-container": "^36.8.2", + "victory-errorbar": "^36.8.2", + "victory-group": "^36.8.2", + "victory-histogram": "^36.8.2", + "victory-legend": "^36.8.2", + "victory-line": "^36.8.2", + "victory-pie": "^36.8.2", + "victory-polar-axis": "^36.8.2", + "victory-scatter": "^36.8.2", + "victory-selection-container": "^36.8.2", + "victory-shared-events": "^36.8.2", + "victory-stack": "^36.8.2", + "victory-tooltip": "^36.8.2", + "victory-voronoi": "^36.8.2", + "victory-voronoi-container": "^36.8.2", + "victory-zoom-container": "^36.8.2" }, "devDependencies": { "@babel/core": "^7.18.9", diff --git a/packages/victory-pie/CHANGELOG.md b/packages/victory-pie/CHANGELOG.md index 526807525..a1b275412 100644 --- a/packages/victory-pie/CHANGELOG.md +++ b/packages/victory-pie/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-pie +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-pie/package.json b/packages/victory-pie/package.json index 3297dd467..b95137eea 100644 --- a/packages/victory-pie/package.json +++ b/packages/victory-pie/package.json @@ -1,6 +1,6 @@ { "name": "victory-pie", - "version": "36.8.1", + "version": "36.8.2", "description": "Pie Component for Victory", "keywords": [ "data visualization", @@ -22,8 +22,8 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1", - "victory-vendor": "^36.8.1" + "victory-core": "^36.8.2", + "victory-vendor": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-polar-axis/CHANGELOG.md b/packages/victory-polar-axis/CHANGELOG.md index aeb01a6a8..f5b6f1368 100644 --- a/packages/victory-polar-axis/CHANGELOG.md +++ b/packages/victory-polar-axis/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-polar-axis +## 36.8.2 + +### Patch Changes + +- Migrate polar axis to typescript ([#2713](https://github.com/FormidableLabs/victory/pull/2713)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-polar-axis/package.json b/packages/victory-polar-axis/package.json index ab8f4e2a1..eb97214d7 100644 --- a/packages/victory-polar-axis/package.json +++ b/packages/victory-polar-axis/package.json @@ -1,6 +1,6 @@ { "name": "victory-polar-axis", - "version": "36.8.1", + "version": "36.8.2", "description": "Polar Axis Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-scatter/CHANGELOG.md b/packages/victory-scatter/CHANGELOG.md index 4e9f41412..717b1bd67 100644 --- a/packages/victory-scatter/CHANGELOG.md +++ b/packages/victory-scatter/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-scatter +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-scatter/package.json b/packages/victory-scatter/package.json index bfcd48507..cb7223f7a 100644 --- a/packages/victory-scatter/package.json +++ b/packages/victory-scatter/package.json @@ -1,6 +1,6 @@ { "name": "victory-scatter", - "version": "36.8.1", + "version": "36.8.2", "description": "Scatter Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-selection-container/CHANGELOG.md b/packages/victory-selection-container/CHANGELOG.md index 2d5d939cc..1c8e14506 100644 --- a/packages/victory-selection-container/CHANGELOG.md +++ b/packages/victory-selection-container/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-selection-container +## 36.8.2 + +### Patch Changes + +- Migrated victory-selection-container to TypeScript ([#2706](https://github.com/FormidableLabs/victory/pull/2706)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-selection-container/package.json b/packages/victory-selection-container/package.json index 6e339830e..54ff282d6 100644 --- a/packages/victory-selection-container/package.json +++ b/packages/victory-selection-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-selection-container", - "version": "36.8.1", + "version": "36.8.2", "description": "Interactive Selection Component for Victory", "keywords": [ "data visualization", @@ -22,13 +22,13 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" }, "devDependencies": { - "victory-bar": "^36.8.1", + "victory-bar": "^36.8.2", "victory-selection-container": "*" }, "publishConfig": { diff --git a/packages/victory-shared-events/CHANGELOG.md b/packages/victory-shared-events/CHANGELOG.md index e66791a52..1d5ad51d7 100644 --- a/packages/victory-shared-events/CHANGELOG.md +++ b/packages/victory-shared-events/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-shared-events +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-shared-events/package.json b/packages/victory-shared-events/package.json index 046f2269f..6d1ed62ad 100644 --- a/packages/victory-shared-events/package.json +++ b/packages/victory-shared-events/package.json @@ -1,6 +1,6 @@ { "name": "victory-shared-events", - "version": "36.8.1", + "version": "36.8.2", "description": "Shared Event Helper for Victory", "keywords": [ "data visualization", @@ -24,7 +24,7 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-stack/CHANGELOG.md b/packages/victory-stack/CHANGELOG.md index f2d2fd513..070a98991 100644 --- a/packages/victory-stack/CHANGELOG.md +++ b/packages/victory-stack/CHANGELOG.md @@ -1,5 +1,11 @@ # victory-stack +## 36.8.2 + +### Patch Changes + +- Assign merged props to a const instead of modifying initialProps ([#2718](https://github.com/FormidableLabs/victory/pull/2718)) + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-stack/package.json b/packages/victory-stack/package.json index 567e70746..5f039d060 100644 --- a/packages/victory-stack/package.json +++ b/packages/victory-stack/package.json @@ -1,6 +1,6 @@ { "name": "victory-stack", - "version": "36.8.1", + "version": "36.8.2", "description": "Stack Layout Component for Victory", "keywords": [ "data visualization", @@ -23,8 +23,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.1", - "victory-shared-events": "^36.8.1" + "victory-core": "^36.8.2", + "victory-shared-events": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-tooltip/CHANGELOG.md b/packages/victory-tooltip/CHANGELOG.md index 484bc910b..84c7896ab 100644 --- a/packages/victory-tooltip/CHANGELOG.md +++ b/packages/victory-tooltip/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-tooltip +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-tooltip/package.json b/packages/victory-tooltip/package.json index ab95bc984..55310c9e5 100644 --- a/packages/victory-tooltip/package.json +++ b/packages/victory-tooltip/package.json @@ -1,6 +1,6 @@ { "name": "victory-tooltip", - "version": "36.8.1", + "version": "36.8.2", "description": "Tooltip Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-vendor/CHANGELOG.md b/packages/victory-vendor/CHANGELOG.md index 05ddc9111..24220a774 100644 --- a/packages/victory-vendor/CHANGELOG.md +++ b/packages/victory-vendor/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-vendor +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-vendor/package.json b/packages/victory-vendor/package.json index 816525ec6..50e6f4c02 100644 --- a/packages/victory-vendor/package.json +++ b/packages/victory-vendor/package.json @@ -1,6 +1,6 @@ { "name": "victory-vendor", - "version": "36.8.1", + "version": "36.8.2", "description": "Vendored dependencies for Victory", "keywords": [ "data visualization", diff --git a/packages/victory-voronoi-container/CHANGELOG.md b/packages/victory-voronoi-container/CHANGELOG.md index 56c1192f7..1430a1319 100644 --- a/packages/victory-voronoi-container/CHANGELOG.md +++ b/packages/victory-voronoi-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-voronoi-container +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-voronoi-container/package.json b/packages/victory-voronoi-container/package.json index 7233d5c03..edec6cb15 100644 --- a/packages/victory-voronoi-container/package.json +++ b/packages/victory-voronoi-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-voronoi-container", - "version": "36.8.1", + "version": "36.8.2", "description": "Interactive Voronoi Mouseover Component for Victory", "keywords": [ "data visualization", @@ -24,8 +24,8 @@ "lodash": "^4.17.19", "prop-types": "^15.8.1", "react-fast-compare": "^3.2.0", - "victory-core": "^36.8.1", - "victory-tooltip": "^36.8.1" + "victory-core": "^36.8.2", + "victory-tooltip": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-voronoi/CHANGELOG.md b/packages/victory-voronoi/CHANGELOG.md index 2cb2c6948..55f2dbee4 100644 --- a/packages/victory-voronoi/CHANGELOG.md +++ b/packages/victory-voronoi/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-voronoi +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-voronoi/package.json b/packages/victory-voronoi/package.json index 3e0b3c51b..c2726ea12 100644 --- a/packages/victory-voronoi/package.json +++ b/packages/victory-voronoi/package.json @@ -1,6 +1,6 @@ { "name": "victory-voronoi", - "version": "36.8.1", + "version": "36.8.2", "description": "Voronoi Component for Victory", "keywords": [ "data visualization", @@ -23,7 +23,7 @@ "d3-voronoi": "^1.1.4", "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory-zoom-container/CHANGELOG.md b/packages/victory-zoom-container/CHANGELOG.md index ee9d4862f..801312812 100644 --- a/packages/victory-zoom-container/CHANGELOG.md +++ b/packages/victory-zoom-container/CHANGELOG.md @@ -1,5 +1,7 @@ # victory-zoom-container +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory-zoom-container/package.json b/packages/victory-zoom-container/package.json index 544cd7a4e..0c44479e2 100644 --- a/packages/victory-zoom-container/package.json +++ b/packages/victory-zoom-container/package.json @@ -1,6 +1,6 @@ { "name": "victory-zoom-container", - "version": "36.8.1", + "version": "36.8.2", "description": "Interactive Zoom Component for Victory", "keywords": [ "data visualization", @@ -22,7 +22,7 @@ "dependencies": { "lodash": "^4.17.19", "prop-types": "^15.8.1", - "victory-core": "^36.8.1" + "victory-core": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/packages/victory/CHANGELOG.md b/packages/victory/CHANGELOG.md index 0f6774877..a4be026bd 100644 --- a/packages/victory/CHANGELOG.md +++ b/packages/victory/CHANGELOG.md @@ -1,5 +1,7 @@ # victory +## 36.8.2 + ## 36.8.1 ## 36.8.0 diff --git a/packages/victory/package.json b/packages/victory/package.json index 6a87556dd..920f5529f 100644 --- a/packages/victory/package.json +++ b/packages/victory/package.json @@ -1,6 +1,6 @@ { "name": "victory", - "version": "36.8.1", + "version": "36.8.2", "description": "Data viz for React", "keywords": [ "data visualization", @@ -21,33 +21,33 @@ "author": "Formidable", "license": "MIT", "dependencies": { - "victory-area": "^36.8.1", - "victory-axis": "^36.8.1", - "victory-bar": "^36.8.1", - "victory-box-plot": "^36.8.1", - "victory-brush-container": "^36.8.1", - "victory-brush-line": "^36.8.1", - "victory-candlestick": "^36.8.1", - "victory-canvas": "^36.8.1", - "victory-chart": "^36.8.1", - "victory-core": "^36.8.1", - "victory-create-container": "^36.8.1", - "victory-cursor-container": "^36.8.1", - "victory-errorbar": "^36.8.1", - "victory-group": "^36.8.1", - "victory-histogram": "^36.8.1", - "victory-legend": "^36.8.1", - "victory-line": "^36.8.1", - "victory-pie": "^36.8.1", - "victory-polar-axis": "^36.8.1", - "victory-scatter": "^36.8.1", - "victory-selection-container": "^36.8.1", - "victory-shared-events": "^36.8.1", - "victory-stack": "^36.8.1", - "victory-tooltip": "^36.8.1", - "victory-voronoi": "^36.8.1", - "victory-voronoi-container": "^36.8.1", - "victory-zoom-container": "^36.8.1" + "victory-area": "^36.8.2", + "victory-axis": "^36.8.2", + "victory-bar": "^36.8.2", + "victory-box-plot": "^36.8.2", + "victory-brush-container": "^36.8.2", + "victory-brush-line": "^36.8.2", + "victory-candlestick": "^36.8.2", + "victory-canvas": "^36.8.2", + "victory-chart": "^36.8.2", + "victory-core": "^36.8.2", + "victory-create-container": "^36.8.2", + "victory-cursor-container": "^36.8.2", + "victory-errorbar": "^36.8.2", + "victory-group": "^36.8.2", + "victory-histogram": "^36.8.2", + "victory-legend": "^36.8.2", + "victory-line": "^36.8.2", + "victory-pie": "^36.8.2", + "victory-polar-axis": "^36.8.2", + "victory-scatter": "^36.8.2", + "victory-selection-container": "^36.8.2", + "victory-shared-events": "^36.8.2", + "victory-stack": "^36.8.2", + "victory-tooltip": "^36.8.2", + "victory-voronoi": "^36.8.2", + "victory-voronoi-container": "^36.8.2", + "victory-zoom-container": "^36.8.2" }, "peerDependencies": { "react": ">=16.6.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a18a57562..54da5fd20 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,33 +194,33 @@ importers: packages/victory: specifiers: victory: '*' - victory-area: ^36.8.1 - victory-axis: ^36.8.1 - victory-bar: ^36.8.1 - victory-box-plot: ^36.8.1 - victory-brush-container: ^36.8.1 - victory-brush-line: ^36.8.1 - victory-candlestick: ^36.8.1 - victory-canvas: ^36.8.1 - victory-chart: ^36.8.1 - victory-core: ^36.8.1 - victory-create-container: ^36.8.1 - victory-cursor-container: ^36.8.1 - victory-errorbar: ^36.8.1 - victory-group: ^36.8.1 - victory-histogram: ^36.8.1 - victory-legend: ^36.8.1 - victory-line: ^36.8.1 - victory-pie: ^36.8.1 - victory-polar-axis: ^36.8.1 - victory-scatter: ^36.8.1 - victory-selection-container: ^36.8.1 - victory-shared-events: ^36.8.1 - victory-stack: ^36.8.1 - victory-tooltip: ^36.8.1 - victory-voronoi: ^36.8.1 - victory-voronoi-container: ^36.8.1 - victory-zoom-container: ^36.8.1 + victory-area: ^36.8.2 + victory-axis: ^36.8.2 + victory-bar: ^36.8.2 + victory-box-plot: ^36.8.2 + victory-brush-container: ^36.8.2 + victory-brush-line: ^36.8.2 + victory-candlestick: ^36.8.2 + victory-canvas: ^36.8.2 + victory-chart: ^36.8.2 + victory-core: ^36.8.2 + victory-create-container: ^36.8.2 + victory-cursor-container: ^36.8.2 + victory-errorbar: ^36.8.2 + victory-group: ^36.8.2 + victory-histogram: ^36.8.2 + victory-legend: ^36.8.2 + victory-line: ^36.8.2 + victory-pie: ^36.8.2 + victory-polar-axis: ^36.8.2 + victory-scatter: ^36.8.2 + victory-selection-container: ^36.8.2 + victory-shared-events: ^36.8.2 + victory-stack: ^36.8.2 + victory-tooltip: ^36.8.2 + victory-voronoi: ^36.8.2 + victory-voronoi-container: ^36.8.2 + victory-zoom-container: ^36.8.2 dependencies: victory-area: link:../victory-area victory-axis: link:../victory-axis @@ -258,8 +258,8 @@ importers: prop-types: ^15.8.1 victory-area: '*' victory-chart: '*' - victory-core: ^36.8.1 - victory-vendor: ^36.8.1 + victory-core: ^36.8.2 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -275,7 +275,7 @@ importers: prop-types: ^15.8.1 victory-axis: '*' victory-chart: '*' - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -290,8 +290,8 @@ importers: prop-types: ^15.8.1 victory-bar: '*' victory-chart: '*' - victory-core: ^36.8.1 - victory-vendor: ^36.8.1 + victory-core: ^36.8.2 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -306,9 +306,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-box-plot: '*' - victory-chart: ^36.8.1 - victory-core: ^36.8.1 - victory-vendor: ^36.8.1 + victory-chart: ^36.8.2 + victory-core: ^36.8.2 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -324,7 +324,7 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-brush-container: '*' - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -338,7 +338,7 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -350,9 +350,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-candlestick: '*' - victory-chart: ^36.8.1 - victory-core: ^36.8.1 - victory-vendor: ^36.8.1 + victory-chart: ^36.8.2 + victory-core: ^36.8.2 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -366,8 +366,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-bar: ^36.8.1 - victory-core: ^36.8.1 + victory-bar: ^36.8.2 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -379,12 +379,12 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-axis: ^36.8.1 + victory-axis: ^36.8.2 victory-chart: '*' - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-line: '*' - victory-polar-axis: ^36.8.1 - victory-shared-events: ^36.8.1 + victory-polar-axis: ^36.8.2 + victory-shared-events: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -406,7 +406,7 @@ importers: victory-bar: '*' victory-core: '*' victory-line: '*' - victory-vendor: ^36.8.1 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -421,12 +421,12 @@ importers: packages/victory-create-container: specifiers: lodash: ^4.17.19 - victory-brush-container: ^36.8.1 - victory-core: ^36.8.1 - victory-cursor-container: ^36.8.1 - victory-selection-container: ^36.8.1 - victory-voronoi-container: ^36.8.1 - victory-zoom-container: ^36.8.1 + victory-brush-container: ^36.8.2 + victory-core: ^36.8.2 + victory-cursor-container: ^36.8.2 + victory-selection-container: ^36.8.2 + victory-voronoi-container: ^36.8.2 + victory-zoom-container: ^36.8.2 dependencies: lodash: 4.17.21 victory-brush-container: link:../victory-brush-container @@ -440,7 +440,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -450,7 +450,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-errorbar: '*' dependencies: lodash: 4.17.21 @@ -465,9 +465,9 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-bar: '*' - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-group: '*' - victory-shared-events: ^36.8.1 + victory-shared-events: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -483,9 +483,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-bar: ^36.8.1 - victory-core: ^36.8.1 - victory-vendor: ^36.8.1 + victory-bar: ^36.8.2 + victory-core: ^36.8.2 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -498,7 +498,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-legend: '*' dependencies: lodash: 4.17.21 @@ -512,9 +512,9 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-chart: '*' - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-line: '*' - victory-vendor: ^36.8.1 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -533,33 +533,33 @@ importers: react-native: ^0.65.1 react-native-gesture-handler: ^1.10.3 react-native-svg: ^12.4.3 - victory: ^36.8.1 - victory-area: ^36.8.1 - victory-axis: ^36.8.1 - victory-bar: ^36.8.1 - victory-box-plot: ^36.8.1 - victory-brush-container: ^36.8.1 - victory-brush-line: ^36.8.1 - victory-candlestick: ^36.8.1 - victory-chart: ^36.8.1 - victory-core: ^36.8.1 - victory-create-container: ^36.8.1 - victory-cursor-container: ^36.8.1 - victory-errorbar: ^36.8.1 - victory-group: ^36.8.1 - victory-histogram: ^36.8.1 - victory-legend: ^36.8.1 - victory-line: ^36.8.1 - victory-pie: ^36.8.1 - victory-polar-axis: ^36.8.1 - victory-scatter: ^36.8.1 - victory-selection-container: ^36.8.1 - victory-shared-events: ^36.8.1 - victory-stack: ^36.8.1 - victory-tooltip: ^36.8.1 - victory-voronoi: ^36.8.1 - victory-voronoi-container: ^36.8.1 - victory-zoom-container: ^36.8.1 + victory: ^36.8.2 + victory-area: ^36.8.2 + victory-axis: ^36.8.2 + victory-bar: ^36.8.2 + victory-box-plot: ^36.8.2 + victory-brush-container: ^36.8.2 + victory-brush-line: ^36.8.2 + victory-candlestick: ^36.8.2 + victory-chart: ^36.8.2 + victory-core: ^36.8.2 + victory-create-container: ^36.8.2 + victory-cursor-container: ^36.8.2 + victory-errorbar: ^36.8.2 + victory-group: ^36.8.2 + victory-histogram: ^36.8.2 + victory-legend: ^36.8.2 + victory-line: ^36.8.2 + victory-pie: ^36.8.2 + victory-polar-axis: ^36.8.2 + victory-scatter: ^36.8.2 + victory-selection-container: ^36.8.2 + victory-shared-events: ^36.8.2 + victory-stack: ^36.8.2 + victory-tooltip: ^36.8.2 + victory-voronoi: ^36.8.2 + victory-voronoi-container: ^36.8.2 + victory-zoom-container: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -601,9 +601,9 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-pie: '*' - victory-vendor: ^36.8.1 + victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -616,7 +616,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -626,7 +626,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-scatter: '*' dependencies: lodash: 4.17.21 @@ -639,8 +639,8 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-bar: ^36.8.1 - victory-core: ^36.8.1 + victory-bar: ^36.8.2 + victory-core: ^36.8.2 victory-selection-container: '*' dependencies: lodash: 4.17.21 @@ -656,7 +656,7 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: json-stringify-safe: 5.0.1 lodash: 4.17.21 @@ -670,9 +670,9 @@ importers: prop-types: ^15.8.1 react-fast-compare: ^3.2.0 victory-bar: '*' - victory-core: ^36.8.1 + victory-core: ^36.8.2 victory-histogram: '*' - victory-shared-events: ^36.8.1 + victory-shared-events: ^36.8.2 victory-stack: '*' dependencies: lodash: 4.17.21 @@ -689,7 +689,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 @@ -749,7 +749,7 @@ importers: d3-voronoi: ^1.1.4 lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: d3-voronoi: 1.1.4 lodash: 4.17.21 @@ -762,8 +762,8 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 react-fast-compare: ^3.2.0 - victory-core: ^36.8.1 - victory-tooltip: ^36.8.1 + victory-core: ^36.8.2 + victory-tooltip: ^36.8.2 dependencies: delaunay-find: 0.0.6 lodash: 4.17.21 @@ -776,7 +776,7 @@ importers: specifiers: lodash: ^4.17.19 prop-types: ^15.8.1 - victory-core: ^36.8.1 + victory-core: ^36.8.2 dependencies: lodash: 4.17.21 prop-types: 15.8.1 From 0d54830e2c6cccfde106f07517802e2c913a5b02 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Wed, 17 Jan 2024 14:01:53 +0000 Subject: [PATCH 20/29] Migrate victory-histogram to TypeScript (#2719) --- .changeset/six-donuts-swim.md | 5 + packages/victory-histogram/package.json | 3 + .../{helper-methods.js => helper-methods.ts} | 99 +++++++++++-------- packages/victory-histogram/src/index.d.ts | 46 --------- packages/victory-histogram/src/index.js | 1 - packages/victory-histogram/src/index.ts | 1 + ...ram.test.js => victory-histogram.test.tsx} | 7 +- ...ory-histogram.js => victory-histogram.tsx} | 89 ++++++++++------- pnpm-lock.yaml | 3 + 9 files changed, 126 insertions(+), 128 deletions(-) create mode 100644 .changeset/six-donuts-swim.md rename packages/victory-histogram/src/{helper-methods.js => helper-methods.ts} (72%) delete mode 100644 packages/victory-histogram/src/index.d.ts delete mode 100644 packages/victory-histogram/src/index.js create mode 100644 packages/victory-histogram/src/index.ts rename packages/victory-histogram/src/{victory-histogram.test.js => victory-histogram.test.tsx} (96%) rename packages/victory-histogram/src/{victory-histogram.js => victory-histogram.tsx} (52%) diff --git a/.changeset/six-donuts-swim.md b/.changeset/six-donuts-swim.md new file mode 100644 index 000000000..a0145d8f0 --- /dev/null +++ b/.changeset/six-donuts-swim.md @@ -0,0 +1,5 @@ +--- +"victory-histogram": patch +--- + +Migrate victory-histogram to TypeScript diff --git a/packages/victory-histogram/package.json b/packages/victory-histogram/package.json index cf7895f77..be74435f3 100644 --- a/packages/victory-histogram/package.json +++ b/packages/victory-histogram/package.json @@ -27,6 +27,9 @@ "victory-core": "^36.8.2", "victory-vendor": "^36.8.2" }, + "devDependencies": { + "victory-histogram": "*" + }, "peerDependencies": { "react": ">=16.6.0" }, diff --git a/packages/victory-histogram/src/helper-methods.js b/packages/victory-histogram/src/helper-methods.ts similarity index 72% rename from packages/victory-histogram/src/helper-methods.js rename to packages/victory-histogram/src/helper-methods.ts index 0947ab540..1ca648105 100644 --- a/packages/victory-histogram/src/helper-methods.js +++ b/packages/victory-histogram/src/helper-methods.ts @@ -4,6 +4,7 @@ import { getBarPosition } from "victory-bar"; import isEqual from "react-fast-compare"; import * as d3Array from "victory-vendor/d3-array"; import * as d3Scale from "victory-vendor/d3-scale"; +import { VictoryHistogramProps } from "./victory-histogram"; const cacheLastValue = (func) => { let called = false; @@ -25,9 +26,14 @@ const cacheLastValue = (func) => { }; }; -const dataOrBinsContainDates = ({ data, bins, x }) => { +const dataOrBinsContainDates = ({ + data, + bins, + x, +}: Pick) => { const xAccessor = Helpers.createAccessor(x || "x"); - const dataIsDates = data.some((datum) => xAccessor(datum) instanceof Date); + const dataIsDates = + data?.some((datum) => xAccessor(datum) instanceof Date) || false; const binsHasDates = Array.isArray(bins) && bins.some((bin) => bin instanceof Date); @@ -39,7 +45,9 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => { const bin = d3Array.bin().value(xAccessor); const niceScale = ( - dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear() + (dataOrBinsContainsDates + ? d3Scale.scaleTime() + : d3Scale.scaleLinear()) as any ) .domain(d3Array.extent(data, xAccessor)) .nice(); @@ -61,8 +69,7 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => { if (dataOrBinsContainsDates) { bin.domain(niceScale.domain()); bin.thresholds(niceScale.ticks()); - - return bin; + return bin as unknown as d3Array.HistogramGeneratorDate; } bin.domain(niceScale.domain()); @@ -70,42 +77,52 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => { return bin; }; -export const getFormattedData = cacheLastValue(({ data = [], x, bins }) => { - if ((!data || !data.length) && !Array.isArray(bins)) { - return []; - } - const dataOrBinsContainsDates = dataOrBinsContainDates({ data, bins, x }); - const binFunc = getBinningFunc({ data, x, bins, dataOrBinsContainsDates }); - const foo = binFunc(data); - const binnedData = foo.filter(({ x0, x1 }) => { - if (dataOrBinsContainsDates) { - return new Date(x0).getTime() !== new Date(x1).getTime(); +export const getFormattedData = cacheLastValue( + ({ + data = [], + x, + bins, + }: Pick) => { + if ((!data || !data.length) && !Array.isArray(bins)) { + return []; } - - return x0 !== x1; - }); - - const formattedData = binnedData.map((bin) => { - const x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0; - const x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1; - - return { - x0, - x1, - x: dataOrBinsContainsDates - ? new Date((x0.getTime() + x1.getTime()) / 2) - : (x0 + x1) / 2, - y: bin.length, - binnedData: [...bin], - }; - }); - - return formattedData; -}); - -export const getData = (props) => { + const dataOrBinsContainsDates = dataOrBinsContainDates({ data, bins, x }); + const binFunc = getBinningFunc({ data, x, bins, dataOrBinsContainsDates }); + const foo = binFunc(data); + const binnedData = [...foo].filter(({ x0, x1 }) => { + if (x0 instanceof Date && x1 instanceof Date) { + return new Date(x0).getTime() !== new Date(x1).getTime(); + } + + return x0 !== x1; + }); + + const formattedData = binnedData.map((bin) => { + const x0 = dataOrBinsContainsDates + ? new Date(bin.x0 as Date) + : bin.x0 || 0; + const x1 = dataOrBinsContainsDates + ? new Date(bin.x1 as Date) + : bin.x1 || 0; + + return { + x0, + x1, + x: dataOrBinsContainsDates + ? new Date(((x0 as Date).getTime() + (x1 as Date).getTime()) / 2) + : ((x0 as number) + (x1 as number)) / 2, + y: bin.length, + binnedData: [...bin], + }; + }); + + return formattedData; + }, +); + +export const getData = (props: VictoryHistogramProps) => { const { bins, data, x } = props; - const dataIsPreformatted = data.some(({ _y }) => !isNil(_y)); + const dataIsPreformatted = data?.some(({ _y }) => !isNil(_y)); const formattedData = dataIsPreformatted ? data @@ -113,7 +130,7 @@ export const getData = (props) => { return Data.getData({ ...props, data: formattedData, x: "x" }); }; -export const getDomain = (props, axis) => { +export const getDomain = (props: VictoryHistogramProps, axis: "x" | "y") => { const data = getData(props); if (!data.length) { @@ -130,7 +147,7 @@ export const getDomain = (props, axis) => { ); } - return props.data.length + return props.data?.length ? Domain.getDomainWithZero({ ...props, data }, "y") : [0, 1]; }; diff --git a/packages/victory-histogram/src/index.d.ts b/packages/victory-histogram/src/index.d.ts deleted file mode 100644 index d270ecb3b..000000000 --- a/packages/victory-histogram/src/index.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import * as React from "react"; -import { - EventPropTypeInterface, - NumberOrCallback, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryDatableProps, - VictoryMultiLabelableProps, - VictoryStyleInterface, -} from "victory-core"; - -export type VictoryHistogramTargetType = "data" | "labels" | "parent"; - -export interface VictoryHistogramProps - extends Omit, - Omit, - VictoryMultiLabelableProps { - binSpacing?: number; - bins?: number | number[] | Date[]; - cornerRadius?: - | NumberOrCallback - | { - top?: NumberOrCallback; - topLeft?: NumberOrCallback; - topRight?: NumberOrCallback; - bottom?: NumberOrCallback; - bottomLeft?: NumberOrCallback; - bottomRight?: NumberOrCallback; - }; - events?: EventPropTypeInterface< - VictoryHistogramTargetType, - number | string | number[] | string[] - >[]; - eventKey?: StringOrNumberOrCallback; - horizontal?: boolean; - style?: VictoryStyleInterface; -} - -/** - * Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes - * Check out VictoryChart for complete histogram charts and more. - */ -export class VictoryHistogram extends React.Component< - VictoryHistogramProps, - any -> {} diff --git a/packages/victory-histogram/src/index.js b/packages/victory-histogram/src/index.js deleted file mode 100644 index b07699a1f..000000000 --- a/packages/victory-histogram/src/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as VictoryHistogram } from "./victory-histogram"; diff --git a/packages/victory-histogram/src/index.ts b/packages/victory-histogram/src/index.ts new file mode 100644 index 000000000..50988ea89 --- /dev/null +++ b/packages/victory-histogram/src/index.ts @@ -0,0 +1 @@ +export * from "./victory-histogram"; diff --git a/packages/victory-histogram/src/victory-histogram.test.js b/packages/victory-histogram/src/victory-histogram.test.tsx similarity index 96% rename from packages/victory-histogram/src/victory-histogram.test.js rename to packages/victory-histogram/src/victory-histogram.test.tsx index 253f2f6ad..4850914c7 100644 --- a/packages/victory-histogram/src/victory-histogram.test.js +++ b/packages/victory-histogram/src/victory-histogram.test.tsx @@ -21,14 +21,14 @@ describe("components/victory-histogram", () => { it("renders an svg with the correct width and height", () => { const { container } = render(); const svg = container.querySelector("svg"); - expect(svg.getAttribute("style")).toContain("width: 100%; height: 100%"); + expect(svg?.getAttribute("style")).toContain("width: 100%; height: 100%"); }); it("renders an svg with the correct viewBox", () => { const { container } = render(); const svg = container.querySelector("svg"); const viewBoxValue = `0 0 ${450} ${300}`; - expect(svg.getAttribute("viewBox")).toEqual(viewBoxValue); + expect(svg?.getAttribute("viewBox")).toEqual(viewBoxValue); }); it("renders 0 bars", () => { @@ -94,6 +94,7 @@ describe("components/victory-histogram", () => { render( } @@ -139,7 +140,7 @@ describe("components/victory-histogram", () => { />, ); const svg = container.querySelector("svg"); - fireEvent.click(svg); + fireEvent.click(svg!); expect(clickHandler).toHaveBeenCalled(); // the first argument is the standard event object diff --git a/packages/victory-histogram/src/victory-histogram.js b/packages/victory-histogram/src/victory-histogram.tsx similarity index 52% rename from packages/victory-histogram/src/victory-histogram.js rename to packages/victory-histogram/src/victory-histogram.tsx index 73d1a4ee9..2f2a3fc5b 100644 --- a/packages/victory-histogram/src/victory-histogram.js +++ b/packages/victory-histogram/src/victory-histogram.tsx @@ -1,15 +1,20 @@ import React from "react"; -import PropTypes from "prop-types"; import { Bar } from "victory-bar"; import { Helpers, VictoryLabel, VictoryContainer, VictoryTheme, - CommonProps, addEvents, - PropTypes as CustomPropTypes, UserProps, + EventPropTypeInterface, + NumberOrCallback, + StringOrNumberOrCallback, + VictoryCommonProps, + VictoryDatableProps, + VictoryMultiLabelableProps, + VictoryStyleInterface, + EventsMixinClass, } from "victory-core"; import { getBaseProps, @@ -18,7 +23,34 @@ import { getFormattedData, } from "./helper-methods"; -const fallbackProps = { +export type VictoryHistogramTargetType = "data" | "labels" | "parent"; + +export interface VictoryHistogramProps + extends Omit, + Omit, + VictoryMultiLabelableProps { + binSpacing?: number; + bins?: number | number[] | Date[]; + cornerRadius?: + | NumberOrCallback + | { + top?: NumberOrCallback; + topLeft?: NumberOrCallback; + topRight?: NumberOrCallback; + bottom?: NumberOrCallback; + bottomLeft?: NumberOrCallback; + bottomRight?: NumberOrCallback; + }; + events?: EventPropTypeInterface< + VictoryHistogramTargetType, + number | string | number[] | string[] + >[]; + eventKey?: StringOrNumberOrCallback; + horizontal?: boolean; + style?: VictoryStyleInterface; +} + +const fallbackProps: Partial = { width: 450, height: 300, padding: 50, @@ -26,7 +58,15 @@ const fallbackProps = { const defaultData = []; -export class VictoryHistogram extends React.Component { +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface VictoryHistogramBase + extends EventsMixinClass {} + +/** + * Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes + * Check out VictoryChart for complete histogram charts and more. + */ +class VictoryHistogramBase extends React.Component { static animationWhitelist = [ "data", "domain", @@ -59,33 +99,7 @@ export class VictoryHistogram extends React.Component { static getFormattedData = getFormattedData; - static propTypes = { - ...CommonProps.baseProps, - ...CommonProps.dataProps, - binSpacing: CustomPropTypes.nonNegative, - bins: PropTypes.oneOfType([ - PropTypes.arrayOf( - PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]), - ), - CustomPropTypes.nonNegative, - ]), - cornerRadius: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.func, - PropTypes.shape({ - top: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - topRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - bottomRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - }), - ]), - getPath: PropTypes.func, - horizontal: PropTypes.bool, - }; - - static defaultProps = { + static defaultProps: VictoryHistogramProps = { containerComponent: , data: defaultData, dataComponent: , @@ -99,8 +113,9 @@ export class VictoryHistogram extends React.Component { static getDomain = getDomain; static getData = getData; - static getBaseProps = (props) => getBaseProps(props, fallbackProps); - static expectedComponents = [ + static getBaseProps = (props: VictoryHistogramProps) => + getBaseProps(props, fallbackProps); + static expectedComponents: Partial[] = [ "dataComponent", "labelComponent", "groupComponent", @@ -112,8 +127,8 @@ export class VictoryHistogram extends React.Component { return !!this.props.animate; } - render() { - const { animationWhitelist, role } = VictoryHistogram; + render(): React.ReactElement { + const { animationWhitelist, role } = VictoryHistogramBase; const props = Helpers.modifyProps(this.props, fallbackProps, role); if (this.shouldAnimate()) { @@ -130,4 +145,4 @@ export class VictoryHistogram extends React.Component { } } -export default addEvents(VictoryHistogram); +export const VictoryHistogram = addEvents(VictoryHistogramBase); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 54da5fd20..fcde3ca40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -485,6 +485,7 @@ importers: react-fast-compare: ^3.2.0 victory-bar: ^36.8.2 victory-core: ^36.8.2 + victory-histogram: '*' victory-vendor: ^36.8.2 dependencies: lodash: 4.17.21 @@ -493,6 +494,8 @@ importers: victory-bar: link:../victory-bar victory-core: link:../victory-core victory-vendor: link:../victory-vendor + devDependencies: + victory-histogram: 'link:' packages/victory-legend: specifiers: From 8c1feea4b6182577e597e96f51c4784adcc9f902 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Wed, 17 Jan 2024 17:53:54 +0000 Subject: [PATCH 21/29] Refactor reassigned props (#2722) --- packages/victory-area/src/area.tsx | 4 +-- packages/victory-area/src/helper-methods.tsx | 10 ++++--- packages/victory-axis/src/helper-methods.tsx | 4 +-- packages/victory-bar/src/bar.tsx | 4 +-- packages/victory-bar/src/helper-methods.ts | 6 ++--- .../victory-box-plot/src/helper-methods.tsx | 10 ++++--- .../victory-candlestick/src/helper-methods.ts | 4 +-- packages/victory-chart/src/helper-methods.tsx | 6 ++--- .../src/victory-label/victory-label.tsx | 14 +++++----- .../src/victory-primitives/arc.tsx | 4 +-- .../src/victory-primitives/background.tsx | 4 +-- .../src/victory-primitives/border.tsx | 4 +-- .../src/victory-primitives/line-segment.tsx | 4 +-- .../src/victory-primitives/point.tsx | 4 +-- .../src/victory-primitives/whisker.tsx | 10 +++---- packages/victory-errorbar/src/error-bar.tsx | 6 +++-- .../victory-errorbar/src/helper-methods.tsx | 10 ++++--- packages/victory-group/src/helper-methods.tsx | 26 +++++++++---------- .../victory-histogram/src/helper-methods.ts | 10 ++++--- packages/victory-legend/src/helper-methods.ts | 24 +++++++++++------ packages/victory-line/src/curve.tsx | 4 +-- packages/victory-line/src/helper-methods.ts | 10 ++++--- packages/victory-pie/src/helper-methods.js | 4 +-- packages/victory-pie/src/slice.js | 4 +-- .../victory-polar-axis/src/helper-methods.ts | 11 +++++--- .../victory-scatter/src/helper-methods.tsx | 10 ++++--- packages/victory-tooltip/src/flyout.js | 4 +-- .../victory-voronoi/src/helper-methods.ts | 10 ++++--- packages/victory-voronoi/src/voronoi.js | 4 +-- 29 files changed, 136 insertions(+), 93 deletions(-) diff --git a/packages/victory-area/src/area.tsx b/packages/victory-area/src/area.tsx index 527de1ee7..be0f32f57 100644 --- a/packages/victory-area/src/area.tsx +++ b/packages/victory-area/src/area.tsx @@ -102,8 +102,8 @@ const defaultProps = { /** * The area primitive used by VictoryArea */ -export const Area: React.FC = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Area: React.FC = (initialProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const { ariaLabel, role, diff --git a/packages/victory-area/src/helper-methods.tsx b/packages/victory-area/src/helper-methods.tsx index 8e113c958..cf586e824 100644 --- a/packages/victory-area/src/helper-methods.tsx +++ b/packages/victory-area/src/helper-methods.tsx @@ -64,9 +64,13 @@ const getCalculatedValues = (props) => { return { style, data, scale, domain, origin }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "area"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "area", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { data, domain, diff --git a/packages/victory-axis/src/helper-methods.tsx b/packages/victory-axis/src/helper-methods.tsx index 097ba3b3e..1a7d9295c 100644 --- a/packages/victory-axis/src/helper-methods.tsx +++ b/packages/victory-axis/src/helper-methods.tsx @@ -543,8 +543,8 @@ const getCalculatedValues = (props) => { }; }; -export const getBaseProps = (props, fallbackProps) => { - props = Axis.modifyProps(props, fallbackProps); +export const getBaseProps = (initialProps, fallbackProps) => { + const props = Axis.modifyProps(initialProps, fallbackProps); const calculatedValues = getCalculatedValues(props); const { axis, diff --git a/packages/victory-bar/src/bar.tsx b/packages/victory-bar/src/bar.tsx index fb81248ed..fcdc68c3e 100644 --- a/packages/victory-bar/src/bar.tsx +++ b/packages/victory-bar/src/bar.tsx @@ -74,10 +74,10 @@ const defaultProps: Partial = { // eslint-disable-next-line prefer-arrow-callback export const Bar = forwardRef(function Bar( - props, + initialProps, ref, ) { - props = evaluateProps({ ...defaultProps, ...props }); + const props = evaluateProps({ ...defaultProps, ...initialProps }); const { polar, origin, style, barWidth, cornerRadius } = props; const path = polar diff --git a/packages/victory-bar/src/helper-methods.ts b/packages/victory-bar/src/helper-methods.ts index 70ba0eea7..0ef023075 100644 --- a/packages/victory-bar/src/helper-methods.ts +++ b/packages/victory-bar/src/helper-methods.ts @@ -65,9 +65,9 @@ const getCalculatedValues = (props) => { return { style, data, scale, domain, origin }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "bar"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "bar"); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { alignment, barRatio, diff --git a/packages/victory-box-plot/src/helper-methods.tsx b/packages/victory-box-plot/src/helper-methods.tsx index 21cfb8658..1938afd16 100644 --- a/packages/victory-box-plot/src/helper-methods.tsx +++ b/packages/victory-box-plot/src/helper-methods.tsx @@ -457,9 +457,13 @@ const isDatumOutOfBounds = (datum, domain) => { return yOutOfBounds || xOutOfBounds; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "boxplot"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "boxplot", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { groupComponent, width, diff --git a/packages/victory-candlestick/src/helper-methods.ts b/packages/victory-candlestick/src/helper-methods.ts index 128bc9e20..f83c4bf96 100644 --- a/packages/victory-candlestick/src/helper-methods.ts +++ b/packages/victory-candlestick/src/helper-methods.ts @@ -370,9 +370,9 @@ const getLabelProps = (props, text, style, type?: string) => { }; /* eslint-enable max-params*/ -export const getBaseProps = (props, fallbackProps) => { +export const getBaseProps = (initialProps, fallbackProps) => { // eslint-disable-line max-statements - props = Helpers.modifyProps(props, fallbackProps, "candlestick"); + const props = Helpers.modifyProps(initialProps, fallbackProps, "candlestick"); const calculatedValues = getCalculatedValues(props); const { data, style, scale, domain, origin, labelOrientation } = calculatedValues; diff --git a/packages/victory-chart/src/helper-methods.tsx b/packages/victory-chart/src/helper-methods.tsx index 08fd4bfc9..a2bde7e15 100644 --- a/packages/victory-chart/src/helper-methods.tsx +++ b/packages/victory-chart/src/helper-methods.tsx @@ -82,9 +82,9 @@ function getStyles(props) { }; } -export function getCalculatedProps(props, childComponents) { - const style = getStyles(props); - props = Helpers.modifyProps(props, fallbackProps, "chart"); +export function getCalculatedProps(initialProps, childComponents) { + const style = getStyles(initialProps); + const props = Helpers.modifyProps(initialProps, fallbackProps, "chart"); const { horizontal, polar } = props; const allStrings = Wrapper.getStringsFromChildren(props, childComponents); const categories = Wrapper.getCategories(props, childComponents, allStrings); diff --git a/packages/victory-core/src/victory-label/victory-label.tsx b/packages/victory-core/src/victory-label/victory-label.tsx index 41dcbe9a9..0e89f2c40 100644 --- a/packages/victory-core/src/victory-label/victory-label.tsx +++ b/packages/victory-core/src/victory-label/victory-label.tsx @@ -121,8 +121,10 @@ const getStyles = (style, props) => { }; } const getSingleStyle = (s) => { - s = s ? defaults({}, s, defaultStyles) : defaultStyles; - const baseStyles = Helpers.evaluateStyle(s, props); + const baseStyles = Helpers.evaluateStyle( + s ? defaults({}, s, defaultStyles) : defaultStyles, + props, + ); return assign({}, baseStyles, { fontSize: getFontSize(baseStyles) }); }; @@ -584,8 +586,8 @@ const defaultProps = { export const VictoryLabel: { role: string; defaultStyles: typeof defaultStyles; -} & React.FC = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +} & React.FC = (initialProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); if (props.text === null || props.text === undefined) { return null; @@ -596,7 +598,7 @@ export const VictoryLabel: { calculatedProps; const tspanValues = (text as string[]).map((line, i) => { - const currentStyle = getSingleValue(style!, i); + const currentStyle = getSingleValue(style, i); const capHeightPx = TextSize.convertLengthToPixels( `${capHeight}em`, currentStyle.fontSize as number, @@ -607,7 +609,7 @@ export const VictoryLabel: { fontSize: currentStyle.fontSize || defaultStyles.fontSize, capHeight: capHeightPx, text: line, - // @ts-expect-error TODO: This looks like a bug: + // TODO: This looks like a bug: textSize: TextSize.approximateTextSize(line, currentStyle), lineHeight: currentLineHeight, backgroundPadding: getSingleValue(backgroundPadding, i), diff --git a/packages/victory-core/src/victory-primitives/arc.tsx b/packages/victory-core/src/victory-primitives/arc.tsx index 39e69bb13..ef0621b23 100644 --- a/packages/victory-core/src/victory-primitives/arc.tsx +++ b/packages/victory-core/src/victory-primitives/arc.tsx @@ -68,8 +68,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const Arc = (props: ArcProps) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Arc = (initialProps: ArcProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); return React.cloneElement(props.pathComponent!, { ...props.events, diff --git a/packages/victory-core/src/victory-primitives/background.tsx b/packages/victory-core/src/victory-primitives/background.tsx index b9f073437..96692fbb7 100644 --- a/packages/victory-core/src/victory-primitives/background.tsx +++ b/packages/victory-core/src/victory-primitives/background.tsx @@ -37,8 +37,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const Background = (props: BackgroundProps) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Background = (initialProps: BackgroundProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); return props.polar ? React.cloneElement(props.circleComponent!, { diff --git a/packages/victory-core/src/victory-primitives/border.tsx b/packages/victory-core/src/victory-primitives/border.tsx index 6c34fc592..ba91bc46b 100644 --- a/packages/victory-core/src/victory-primitives/border.tsx +++ b/packages/victory-core/src/victory-primitives/border.tsx @@ -43,8 +43,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const Border = (props: BorderProps) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Border = (initialProps: BorderProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); return React.cloneElement(props.rectComponent!, { ...props.events, diff --git a/packages/victory-core/src/victory-primitives/line-segment.tsx b/packages/victory-core/src/victory-primitives/line-segment.tsx index d7d13e3d7..cc6bf2edb 100644 --- a/packages/victory-core/src/victory-primitives/line-segment.tsx +++ b/packages/victory-core/src/victory-primitives/line-segment.tsx @@ -44,8 +44,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const LineSegment = (props: LineSegmentProps) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const LineSegment = (initialProps: LineSegmentProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); return React.cloneElement(props.lineComponent!, { ...props.events, diff --git a/packages/victory-core/src/victory-primitives/point.tsx b/packages/victory-core/src/victory-primitives/point.tsx index 92adf21aa..9d0d85d69 100644 --- a/packages/victory-core/src/victory-primitives/point.tsx +++ b/packages/victory-core/src/victory-primitives/point.tsx @@ -72,8 +72,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const Point = (props: PointProps) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Point = (initialProps: PointProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const userProps = UserProps.getSafeUserProps(props); return React.cloneElement(props.pathComponent!, { diff --git a/packages/victory-core/src/victory-primitives/whisker.tsx b/packages/victory-core/src/victory-primitives/whisker.tsx index ddb610559..50ab98a9d 100644 --- a/packages/victory-core/src/victory-primitives/whisker.tsx +++ b/packages/victory-core/src/victory-primitives/whisker.tsx @@ -47,8 +47,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const Whisker = (props: WhiskerProps) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Whisker = (initialProps: WhiskerProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const { ariaLabel, groupComponent, @@ -77,9 +77,9 @@ export const Whisker = (props: WhiskerProps) => { shapeRendering, }; - return React.cloneElement(groupComponent!, {}, [ + return React.cloneElement(groupComponent, {}, [ React.cloneElement( - lineComponent!, + lineComponent, assign( { key: "major-whisker", "aria-label": ariaLabel }, baseProps, @@ -87,7 +87,7 @@ export const Whisker = (props: WhiskerProps) => { ), ), React.cloneElement( - lineComponent!, + lineComponent, assign( { key: "minor-whisker", "aria-label": ariaLabel }, baseProps, diff --git a/packages/victory-errorbar/src/error-bar.tsx b/packages/victory-errorbar/src/error-bar.tsx index b172fcb58..f430211f5 100644 --- a/packages/victory-errorbar/src/error-bar.tsx +++ b/packages/victory-errorbar/src/error-bar.tsx @@ -116,8 +116,10 @@ const defaultProps = { shapeRendering: "auto", }; -export const ErrorBar = (props: ErrorBarProps & typeof ErrorBar.default) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const ErrorBar = ( + initialProps: ErrorBarProps & typeof ErrorBar.default, +) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const { groupComponent } = props; const userProps = UserProps.getSafeUserProps(props); const { tabIndex, ariaLabel } = props; diff --git a/packages/victory-errorbar/src/helper-methods.tsx b/packages/victory-errorbar/src/helper-methods.tsx index 0a377d2f8..b77d9e561 100644 --- a/packages/victory-errorbar/src/helper-methods.tsx +++ b/packages/victory-errorbar/src/helper-methods.tsx @@ -165,9 +165,13 @@ const getLabelProps = (dataProps, text, style) => { return defaults({}, labelProps, Helpers.omit(tooltipTheme, ["style"])); }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "errorbar"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "errorbar", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { borderWidth, data, diff --git a/packages/victory-group/src/helper-methods.tsx b/packages/victory-group/src/helper-methods.tsx index 8e08cb703..28b979c65 100644 --- a/packages/victory-group/src/helper-methods.tsx +++ b/packages/victory-group/src/helper-methods.tsx @@ -12,9 +12,9 @@ const fallbackProps = { }; // eslint-disable-next-line max-statements -export function getCalculatedProps(props, childComponents) { +export function getCalculatedProps(initialProps, childComponents) { const role = "group"; - props = Helpers.modifyProps(props, fallbackProps, role); + const props = Helpers.modifyProps(initialProps, fallbackProps, role); const style = Wrapper.getStyle(props.theme, props.style, role); const { offset, colorScale, color, polar, horizontal } = props; const categories = @@ -188,24 +188,24 @@ function getDataWithOffset(props, defaultDataset = [], offset) { }); } -export function getChildren(props, childComponents?, calculatedProps?) { - props = Helpers.modifyProps(props, fallbackProps, "stack"); - childComponents = childComponents || React.Children.toArray(props.children); - calculatedProps = - calculatedProps || getCalculatedProps(props, childComponents); - const { datasets } = calculatedProps; +export function getChildren(initialProps, childComponents?, calculatedProps?) { + const props = Helpers.modifyProps(initialProps, fallbackProps, "stack"); + const children = childComponents || React.Children.toArray(props.children); + const newCalculatedProps = + calculatedProps || getCalculatedProps(props, children); + const { datasets } = newCalculatedProps; const { labelComponent, polar } = props; - const childProps = getChildProps(props, calculatedProps); + const childProps = getChildProps(props, newCalculatedProps); const parentName = props.name || "group"; - return childComponents.map((child, index) => { + return children.map((child, index) => { const role = child.type && child.type.role; const xOffset = polar - ? getPolarX0(props, calculatedProps, index, role) - : getX0(props, calculatedProps, index, role); + ? getPolarX0(props, newCalculatedProps, index, role) + : getX0(props, newCalculatedProps, index, role); const style = role === "voronoi" || role === "tooltip" || role === "label" ? child.props.style - : Wrapper.getChildStyle(child, index, calculatedProps); + : Wrapper.getChildStyle(child, index, newCalculatedProps); const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels; diff --git a/packages/victory-histogram/src/helper-methods.ts b/packages/victory-histogram/src/helper-methods.ts index 1ca648105..5c19c6ff7 100644 --- a/packages/victory-histogram/src/helper-methods.ts +++ b/packages/victory-histogram/src/helper-methods.ts @@ -181,9 +181,13 @@ const getCalculatedValues = (props) => { return { style, data, scale, domain }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "histogram"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "histogram", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { binSpacing, diff --git a/packages/victory-legend/src/helper-methods.ts b/packages/victory-legend/src/helper-methods.ts index 1747edaf3..928f04e93 100644 --- a/packages/victory-legend/src/helper-methods.ts +++ b/packages/victory-legend/src/helper-methods.ts @@ -205,9 +205,13 @@ const getBorderProps = (props, contentHeight, contentWidth) => { return { x, y, height, width, style: assign({ fill: "none" }, style.border) }; }; -export const getDimensions = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "legend"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getDimensions = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "legend", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { title, titleOrientation } = props; const groupedData = groupData(props); const columnWidths = getColumnWidths(props, groupedData); @@ -228,9 +232,13 @@ export const getDimensions = (props, fallbackProps) => { }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "legend"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "legend", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { data, standalone, @@ -265,7 +273,7 @@ export const getBaseProps = (props, fallbackProps) => { const { height, width } = getDimensions(props, fallbackProps); const borderProps = getBorderProps(props, height, width); const titleProps = getTitleProps(props, borderProps); - const initialProps = { + const initialChildProps = { parent: { data, standalone, @@ -307,5 +315,5 @@ export const getBaseProps = (props, fallbackProps) => { childProps[eventKey] = { data: dataProps, labels: labelProps }; return childProps; - }, initialProps); + }, initialChildProps); }; diff --git a/packages/victory-line/src/curve.tsx b/packages/victory-line/src/curve.tsx index 3c9a77114..13d1f1306 100644 --- a/packages/victory-line/src/curve.tsx +++ b/packages/victory-line/src/curve.tsx @@ -41,8 +41,8 @@ const defaultProps = { shapeRendering: "auto", }; -export const Curve: React.FC = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +export const Curve: React.FC = (initialProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const userProps = UserProps.getSafeUserProps(props); const { polar, origin } = props; const lineFunction = LineHelpers.getLineFunction(props); diff --git a/packages/victory-line/src/helper-methods.ts b/packages/victory-line/src/helper-methods.ts index 80062ef1f..824b9725e 100644 --- a/packages/victory-line/src/helper-methods.ts +++ b/packages/victory-line/src/helper-methods.ts @@ -33,9 +33,13 @@ const getCalculatedValues = (props) => { return { domain, data, scale, style, origin }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "line"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "line", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { data, domain, diff --git a/packages/victory-pie/src/helper-methods.js b/packages/victory-pie/src/helper-methods.js index 77836b5ea..91f28fdda 100644 --- a/packages/victory-pie/src/helper-methods.js +++ b/packages/victory-pie/src/helper-methods.js @@ -228,8 +228,8 @@ const getLabelProps = (text, dataProps, calculatedValues) => { return defaults({}, labelProps, Helpers.omit(tooltipTheme, ["style"])); }; -export const getBaseProps = (props, fallbackProps) => { - props = Helpers.modifyProps(props, fallbackProps, "pie"); +export const getBaseProps = (initialProps, fallbackProps) => { + const props = Helpers.modifyProps(initialProps, fallbackProps, "pie"); const calculatedValues = getCalculatedValues(props); const { slices, diff --git a/packages/victory-pie/src/slice.js b/packages/victory-pie/src/slice.js index cde7fe05b..1e1680bf9 100644 --- a/packages/victory-pie/src/slice.js +++ b/packages/victory-pie/src/slice.js @@ -74,8 +74,8 @@ const defaultProps = { shapeRendering: "auto", }; -const Slice = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +const Slice = (initialProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const defaultTransform = props.origin ? `translate(${props.origin.x}, ${props.origin.y})` : undefined; diff --git a/packages/victory-polar-axis/src/helper-methods.ts b/packages/victory-polar-axis/src/helper-methods.ts index 43f298bc3..697875ee4 100644 --- a/packages/victory-polar-axis/src/helper-methods.ts +++ b/packages/victory-polar-axis/src/helper-methods.ts @@ -432,8 +432,8 @@ const getAxisProps = (modifiedProps, calculatedValues) => { }; }; -const getCalculatedValues = (props: VictoryPolarAxisProps) => { - props = assign({ polar: true }, props); +const getCalculatedValues = (initialProps: VictoryPolarAxisProps) => { + const props = assign({ polar: true }, initialProps); const defaultStyles = getStyleObject(props); const style = getStyles(props, defaultStyles); const padding = Helpers.getPadding(props); @@ -465,8 +465,11 @@ const getCalculatedValues = (props: VictoryPolarAxisProps) => { }; }; -export const getBaseProps = (props: VictoryPolarAxisProps, fallbackProps) => { - props = Axis.modifyProps(props, fallbackProps); +export const getBaseProps = ( + initialProps: VictoryPolarAxisProps, + fallbackProps, +) => { + const props = Axis.modifyProps(initialProps, fallbackProps); const calculatedValues = getCalculatedValues(props); const { style, scale, ticks, domain } = calculatedValues; const { width, height, standalone, theme, name } = props; diff --git a/packages/victory-scatter/src/helper-methods.tsx b/packages/victory-scatter/src/helper-methods.tsx index 7c835c3c8..358efc78b 100644 --- a/packages/victory-scatter/src/helper-methods.tsx +++ b/packages/victory-scatter/src/helper-methods.tsx @@ -74,9 +74,13 @@ const getCalculatedValues = (props) => { return { domain, data, scale, style, origin, z }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "scatter"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "scatter", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { data, domain, diff --git a/packages/victory-tooltip/src/flyout.js b/packages/victory-tooltip/src/flyout.js index df5dc0fe7..d323439c8 100644 --- a/packages/victory-tooltip/src/flyout.js +++ b/packages/victory-tooltip/src/flyout.js @@ -91,8 +91,8 @@ const defaultProps = { shapeRendering: "auto", }; -const Flyout = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +const Flyout = (initialProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const userProps = UserProps.getSafeUserProps(props); return React.cloneElement(props.pathComponent, { diff --git a/packages/victory-voronoi/src/helper-methods.ts b/packages/victory-voronoi/src/helper-methods.ts index 32b01479b..c506edd24 100644 --- a/packages/victory-voronoi/src/helper-methods.ts +++ b/packages/victory-voronoi/src/helper-methods.ts @@ -75,9 +75,13 @@ const getCalculatedValues = (props) => { return { domain, data, scale, style, polygons, origin }; }; -export const getBaseProps = (props, fallbackProps) => { - const modifiedProps = Helpers.modifyProps(props, fallbackProps, "scatter"); - props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); +export const getBaseProps = (initialProps, fallbackProps) => { + const modifiedProps = Helpers.modifyProps( + initialProps, + fallbackProps, + "scatter", + ); + const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { data, domain, diff --git a/packages/victory-voronoi/src/voronoi.js b/packages/victory-voronoi/src/voronoi.js index af69f1910..2824d43cd 100644 --- a/packages/victory-voronoi/src/voronoi.js +++ b/packages/victory-voronoi/src/voronoi.js @@ -44,8 +44,8 @@ const defaultProps = { shapeRendering: "auto", }; -const Voronoi = (props) => { - props = evaluateProps({ ...defaultProps, ...props }); +const Voronoi = (initialProps) => { + const props = evaluateProps({ ...defaultProps, ...initialProps }); const { ariaLabel, From 699f62bc9c0e60d80b9a8dfd5f6b78f643206dd2 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Wed, 17 Jan 2024 18:03:00 -0600 Subject: [PATCH 22/29] Migrate line test to typescript (#2723) --- ...ory-line.test.js => victory-line.test.tsx} | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) rename packages/victory-line/src/{victory-line.test.js => victory-line.test.tsx} (88%) diff --git a/packages/victory-line/src/victory-line.test.js b/packages/victory-line/src/victory-line.test.tsx similarity index 88% rename from packages/victory-line/src/victory-line.test.js rename to packages/victory-line/src/victory-line.test.tsx index eb1a82060..3e4ba753a 100644 --- a/packages/victory-line/src/victory-line.test.js +++ b/packages/victory-line/src/victory-line.test.tsx @@ -5,6 +5,7 @@ import { VictoryChart } from "victory-chart"; import { Curve, VictoryLine } from "victory-line"; import { curveCatmullRom } from "victory-vendor/d3-shape"; import { calculateD3Path } from "../../../test/helpers"; +import { VictoryLineProps } from "./victory-line"; describe("components/victory-line", () => { describe("default component rendering", () => { @@ -42,7 +43,7 @@ describe("components/victory-line", () => { it("renders an svg with the correct viewBox", () => { const { container } = render(); const viewBoxValue = `0 0 ${450} ${300}`; - expect(container.querySelector("svg").getAttribute("viewBox")).toEqual( + expect(container.querySelector("svg")!.getAttribute("viewBox")).toEqual( viewBoxValue, ); }); @@ -71,7 +72,7 @@ describe("components/victory-line", () => { }); it("renders the correct d3Shape path", () => { - const props = { + const props: VictoryLineProps = { interpolation: "linear", scale: "linear", padding: 50, @@ -86,13 +87,13 @@ describe("components/victory-line", () => { const { container } = render(); - expect(container.querySelector("path").getAttribute("d")).toEqual( + expect(container.querySelector("path")!.getAttribute("d")).toEqual( calculateD3Path(props, "line", 0), ); }); it("renders the correct d3Shape path with custom interpolation string property", () => { - const props = { + const props: VictoryLineProps = { interpolation: "catmullRom", scale: "linear", padding: 50, @@ -107,13 +108,13 @@ describe("components/victory-line", () => { const { container } = render(); - expect(container.querySelector("path").getAttribute("d")).toEqual( + expect(container.querySelector("path")!.getAttribute("d")).toEqual( calculateD3Path(props, "line", 0), ); }); it("renders the correct d3Shape path with custom interpolation function", () => { - const props = { + const props: VictoryLineProps = { interpolation: curveCatmullRom, scale: "linear", padding: 50, @@ -128,7 +129,7 @@ describe("components/victory-line", () => { const { container } = render(); - expect(container.querySelector("path").getAttribute("d")).toEqual( + expect(container.querySelector("path")!.getAttribute("d")).toEqual( calculateD3Path(props, "line", 0), ); }); @@ -145,15 +146,6 @@ describe("components/victory-line", () => { expect(lines).toHaveLength(1); }); - it("renders data values with null accessor", () => { - const data = [1, 2, 3, 4]; - const { container } = render( - , - ); - const lines = container.querySelectorAll("path"); - expect(lines).toHaveLength(1); - }); - it("renders deeply nested data", () => { const data = [ { a: { b: [{ x: 1, y: 2 }] } }, @@ -181,7 +173,7 @@ describe("components/victory-line", () => { ); const line = container.querySelector("path"); - const renderedData = JSON.parse(line.getAttribute("data-json")); + const renderedData = JSON.parse(line!.getAttribute("data-json") || ""); expect(renderedData[0].t).toEqual(1); expect(renderedData[1].t).toEqual(0); @@ -202,7 +194,7 @@ describe("components/victory-line", () => { ); const line = container.querySelector("path"); - const renderedData = JSON.parse(line.getAttribute("data-json")).map( + const renderedData = JSON.parse(line!.getAttribute("data-json")!).map( ({ t }) => t, ); @@ -280,7 +272,7 @@ describe("components/victory-line", () => { it("adds an aria role to a line segment", () => { const { container } = render(); - expect(container.querySelector("path").getAttribute("role")).toEqual( + expect(container.querySelector("path")!.getAttribute("role")).toEqual( "presentation", ); }); @@ -313,7 +305,7 @@ describe("components/victory-line", () => { dataComponent={ - `data point ${data[2].x + 1}'s x value is ${data[2].x}` + `data point ${data![2].x + 1}'s x value is ${data![2].x}` } tabIndex={3} /> @@ -322,11 +314,11 @@ describe("components/victory-line", () => { ); const path = container.querySelector("path"); - expect(path.getAttribute("aria-label")).toEqual( + expect(path?.getAttribute("aria-label")).toEqual( `data point 3's x value is 2`, ); - expect(parseInt(path.getAttribute("tabindex"))).toEqual(3); + expect(parseInt(path!.getAttribute("tabindex")!)).toEqual(3); }); }); }); From bb87499cc95d9474c4cde1160b58042cad24fbc9 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Thu, 18 Jan 2024 14:50:50 +0000 Subject: [PATCH 23/29] Add no-param-reassign eslint rule and refactor occurrences (#2724) --- .changeset/silver-feet-doubt.md | 20 +++++++ .eslintrc.js | 1 + demo/js/components/performance.js | 8 +-- demo/js/components/selection-demo.js | 8 +-- demo/ts/components/selection-demo.tsx | 8 +-- packages/victory-axis/src/helper-methods.tsx | 7 ++- .../victory-bar/src/path-helper-methods.ts | 16 +++--- .../victory-box-plot/src/helper-methods.tsx | 4 +- .../victory-box-plot/src/victory-box-plot.tsx | 2 + .../src/brush-helpers.ts | 29 +++++----- .../src/victory-brush-container.tsx | 8 +-- .../src/victory-brush-line.tsx | 6 +- .../victory-candlestick/src/helper-methods.ts | 17 +++--- packages/victory-chart/src/helper-methods.tsx | 22 ++++---- .../src/victory-animation/util.ts | 8 ++- .../victory-animation/victory-animation.tsx | 5 +- .../src/victory-label/victory-label.tsx | 21 ++++--- .../src/victory-util/add-events.tsx | 19 ++++--- .../victory-core/src/victory-util/axis.tsx | 8 ++- .../victory-core/src/victory-util/data.ts | 20 ++++--- .../victory-core/src/victory-util/domain.ts | 30 +++++----- .../victory-core/src/victory-util/events.ts | 32 ++++------- .../victory-core/src/victory-util/helpers.ts | 10 ++-- .../src/victory-util/immutable.ts | 5 +- .../src/victory-util/label-helpers.ts | 16 ++---- .../src/victory-util/selection.ts | 5 +- .../victory-core/src/victory-util/timer.ts | 3 +- .../src/victory-util/transitions.ts | 53 ++++++++++-------- .../victory-core/src/victory-util/wrapper.tsx | 39 ++++++------- .../src/create-container.js | 4 +- .../victory-errorbar/src/helper-methods.tsx | 8 +-- packages/victory-legend/src/helper-methods.ts | 14 ++--- .../victory-polar-axis/src/helper-methods.ts | 6 +- .../src/selection-helpers.tsx | 11 ++-- .../src/victory-shared-events.js | 8 +-- packages/victory-stack/src/helper-methods.tsx | 56 +++++++++++-------- .../src/victory-voronoi-container.js | 6 +- stories/data.js | 24 +++----- stories/victory-axis.stories.js | 7 +-- stories/victory-box-plot.stories.js | 6 +- stories/victory-candlestick.stories.js | 7 +-- stories/victory-errorbar.stories.js | 3 +- stories/victory-polar-axis.stories.js | 7 +-- 43 files changed, 303 insertions(+), 294 deletions(-) create mode 100644 .changeset/silver-feet-doubt.md diff --git a/.changeset/silver-feet-doubt.md b/.changeset/silver-feet-doubt.md new file mode 100644 index 000000000..0479fc357 --- /dev/null +++ b/.changeset/silver-feet-doubt.md @@ -0,0 +1,20 @@ +--- +"victory-axis": patch +"victory-bar": patch +"victory-box-plot": patch +"victory-brush-container": patch +"victory-brush-line": patch +"victory-candlestick": patch +"victory-chart": patch +"victory-core": patch +"victory-create-container": patch +"victory-errorbar": patch +"victory-legend": patch +"victory-polar-axis": patch +"victory-selection-container": patch +"victory-shared-events": patch +"victory-stack": patch +"victory-voronoi-container": patch +--- + +Refactor param reassignments diff --git a/.eslintrc.js b/.eslintrc.js index 7751afbcc..07a74a44d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,6 +43,7 @@ module.exports = { "error", { ignore: [-1, 0, 0.5, 1, 2, 90, 180, 270, 360] }, ], + "no-param-reassign": "error", }, parser: "@babel/eslint-parser", parserOptions: { diff --git a/demo/js/components/performance.js b/demo/js/components/performance.js index fae354642..605941a6b 100644 --- a/demo/js/components/performance.js +++ b/demo/js/components/performance.js @@ -19,10 +19,10 @@ class App extends React.Component { } handleSelection(datasets) { - const points = datasets.reduce((memo, dataset) => { - memo = memo.concat(dataset.data); - return memo; - }, []); + const points = datasets.reduce( + (memo, dataset) => memo.concat(dataset.data), + [], + ); this.setState({ points }); } diff --git a/demo/js/components/selection-demo.js b/demo/js/components/selection-demo.js index 6492305ef..7e67f5d63 100644 --- a/demo/js/components/selection-demo.js +++ b/demo/js/components/selection-demo.js @@ -19,10 +19,10 @@ class App extends React.Component { } handleSelection(datasets) { - const points = datasets.reduce((memo, dataset) => { - memo = memo.concat(dataset.data); - return memo; - }, []); + const points = datasets.reduce( + (memo, dataset) => memo.concat(dataset.data), + [], + ); this.setState({ points }); } diff --git a/demo/ts/components/selection-demo.tsx b/demo/ts/components/selection-demo.tsx index 814797feb..4c986e597 100644 --- a/demo/ts/components/selection-demo.tsx +++ b/demo/ts/components/selection-demo.tsx @@ -30,10 +30,10 @@ export default class SelectionDemo extends React.Component< } handleSelection(datasets: DataSet[]) { - const points = datasets.reduce((memo: any, dataset: DataSet) => { - memo = memo.concat(dataset.data); - return memo; - }, []); + const points = datasets.reduce( + (memo: any, dataset: DataSet) => memo.concat(dataset.data), + [], + ); this.setState({ points }); } diff --git a/packages/victory-axis/src/helper-methods.tsx b/packages/victory-axis/src/helper-methods.tsx index 1a7d9295c..ca972d9c1 100644 --- a/packages/victory-axis/src/helper-methods.tsx +++ b/packages/victory-axis/src/helper-methods.tsx @@ -1,5 +1,6 @@ import { assign, defaults } from "lodash"; import { Helpers, Scale, Axis } from "victory-core"; +import { VictoryAxisProps } from "./victory-axis"; const orientationSign = { top: -1, @@ -61,9 +62,11 @@ const getStyleObject = (props) => { : specificAxisStyle || generalAxisStyle; }; -export const getStyles = (props, styleObject?) => { +export const getStyles = ( + props, + styleObject: VictoryAxisProps["style"] = {}, +) => { const style = props.style || {}; - styleObject = styleObject || {}; const parentStyleProps = { height: "100%", width: "100%" }; return { parent: defaults(style.parent, styleObject.parent, parentStyleProps), diff --git a/packages/victory-bar/src/path-helper-methods.ts b/packages/victory-bar/src/path-helper-methods.ts index bf9169230..e20629a9e 100644 --- a/packages/victory-bar/src/path-helper-methods.ts +++ b/packages/victory-bar/src/path-helper-methods.ts @@ -100,10 +100,10 @@ const mapPointsToPath = (coords, cornerRadius, direction) => { "L", `A ${bottomRightPath},`, ]; - const path = commands.reduce((acc, command, i) => { - acc += `${command} ${coords[i].x}, ${coords[i].y} \n`; - return acc; - }, ""); + const path = commands.reduce( + (acc, command, i) => `${acc}${command} ${coords[i].x}, ${coords[i].y} \n`, + "", + ); return `${path} z`; }; @@ -402,10 +402,10 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => { const topPath = getTopPath(); const bottomPath = getBottomPath(); const moves = [...topPath, ...bottomPath]; - const path = moves.reduce((memo, move) => { - memo += `${move.command} ${move.coords.join()}`; - return memo; - }, ""); + const path = moves.reduce( + (memo, move) => `${memo}${move.command} ${move.coords.join()}`, + "", + ); return `${path} z`; }; diff --git a/packages/victory-box-plot/src/helper-methods.tsx b/packages/victory-box-plot/src/helper-methods.tsx index 1938afd16..542664c3e 100644 --- a/packages/victory-box-plot/src/helper-methods.tsx +++ b/packages/victory-box-plot/src/helper-methods.tsx @@ -14,6 +14,7 @@ import { max as d3Max, quantile as d3Quantile, } from "victory-vendor/d3-array"; +import { VictoryBoxPlotProps } from "./victory-box-plot"; const TYPES = ["max", "min", "median", "q1", "q3"]; @@ -162,12 +163,11 @@ const getLabelStyle = (props, styleObject, namespace?) => { return defaults({}, tooltipTheme.style, baseStyle); }; -const getStyles = (props, styleObject) => { +const getStyles = (props, styleObject: VictoryBoxPlotProps["style"] = {}) => { if (props.disableInlineStyles) { return {}; } const style = props.style || {}; - styleObject = styleObject || {}; const parentStyles = { height: "100%", width: "100%" }; const labelStyles = defaults( {}, diff --git a/packages/victory-box-plot/src/victory-box-plot.tsx b/packages/victory-box-plot/src/victory-box-plot.tsx index 476f80b72..aeebd4969 100644 --- a/packages/victory-box-plot/src/victory-box-plot.tsx +++ b/packages/victory-box-plot/src/victory-box-plot.tsx @@ -77,6 +77,8 @@ export interface VictoryBoxPlotStyleInterface { q1Labels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; q3?: VictoryStyleObject; q3Labels?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; + boxes?: VictoryStyleObject; + whiskers?: VictoryStyleObject; } export interface VictoryBoxPlotLabelOrientationInterface { diff --git a/packages/victory-brush-container/src/brush-helpers.ts b/packages/victory-brush-container/src/brush-helpers.ts index aca928cd1..d9281826c 100644 --- a/packages/victory-brush-container/src/brush-helpers.ts +++ b/packages/victory-brush-container/src/brush-helpers.ts @@ -14,23 +14,23 @@ const Helpers = { withinBounds(point, bounds, padding?) { const { x1, x2, y1, y2 } = mapValues(bounds, Number); const { x, y } = mapValues(point, Number); - padding = padding ? padding / 2 : 0; + const paddingValue = padding ? padding / 2 : 0; return ( - x + padding >= Math.min(x1, x2) && - x - padding <= Math.max(x1, x2) && - y + padding >= Math.min(y1, y2) && - y - padding <= Math.max(y1, y2) + x + paddingValue >= Math.min(x1, x2) && + x - paddingValue <= Math.max(x1, x2) && + y + paddingValue >= Math.min(y1, y2) && + y - paddingValue <= Math.max(y1, y2) ); }, getDomainBox(props, fullDomain, selectedDomain?) { const brushDimension = this.getDimension(props); - fullDomain = defaults({}, fullDomain, props.domain); - selectedDomain = defaults({}, selectedDomain, fullDomain); - const fullCoords = Selection.getDomainCoordinates(props, fullDomain); + const fullDomainObject = defaults({}, fullDomain, props.domain); + const selectedDomainObject = defaults({}, selectedDomain, fullDomainObject); + const fullCoords = Selection.getDomainCoordinates(props, fullDomainObject); const selectedCoords = Selection.getDomainCoordinates( props, - selectedDomain, + selectedDomainObject, ); return { @@ -92,13 +92,10 @@ const Helpers = { getActiveHandles(point, props, domainBox) { const handles = this.getHandles(props, domainBox); const activeHandles = ["top", "bottom", "left", "right"].reduce( - (memo, opt) => { - memo = - handles[opt] && this.withinBounds(point, handles[opt]) - ? memo.concat(opt) - : memo; - return memo; - }, + (memo, opt) => + handles[opt] && this.withinBounds(point, handles[opt]) + ? memo.concat(opt) + : memo, [] as string[], ); return activeHandles.length && activeHandles; diff --git a/packages/victory-brush-container/src/victory-brush-container.tsx b/packages/victory-brush-container/src/victory-brush-container.tsx index 9ba40378b..b57f45195 100644 --- a/packages/victory-brush-container/src/victory-brush-container.tsx +++ b/packages/victory-brush-container/src/victory-brush-container.tsx @@ -199,17 +199,15 @@ export const brushContainerMixin = (base: TBase) => right: right && assign({ y: right.y1, x: right.x1 }, xProps), }; const handles = ["top", "bottom", "left", "right"].reduce( - (memo, curr) => { - memo = handleProps[curr] + (memo, curr) => + handleProps[curr] ? memo.concat( React.cloneElement( handleComponent, assign({ key: `${name}-handle-${curr}` }, handleProps[curr]), ), ) - : memo; - return memo; - }, + : memo, [] as React.ReactElement[], ); return handles.length ? handles : null; diff --git a/packages/victory-brush-line/src/victory-brush-line.tsx b/packages/victory-brush-line/src/victory-brush-line.tsx index 621064640..700ceb52e 100644 --- a/packages/victory-brush-line/src/victory-brush-line.tsx +++ b/packages/victory-brush-line/src/victory-brush-line.tsx @@ -517,8 +517,10 @@ export class VictoryBrushLine extends React.Component { getRectDimensions(props, brushWidth, domain?) { const { brushDomain } = props; const dimension = getDimension(props); - domain = domain || getBrushDomain(brushDomain, getFullDomain(props)); - const range = toRange(props, domain); + const range = toRange( + props, + domain || getBrushDomain(brushDomain, getFullDomain(props)), + ); const coordinates = dimension === "x" ? { diff --git a/packages/victory-candlestick/src/helper-methods.ts b/packages/victory-candlestick/src/helper-methods.ts index f83c4bf96..07c32ca4d 100644 --- a/packages/victory-candlestick/src/helper-methods.ts +++ b/packages/victory-candlestick/src/helper-methods.ts @@ -190,11 +190,14 @@ const isTransparent = (attr) => { return attr === "none" || attr === "transparent"; }; -const getDataStyles = (datum, style, props) => { +const getDataStyles = ( + datum, + style: { fill?: string; stroke?: string } = {}, + props, +) => { if (props.disableInlineStyles) { return {}; } - style = style || {}; const candleColor = datum._open > datum._close ? props.candleColors.negative @@ -416,14 +419,14 @@ export const getBaseProps = (initialProps, fallbackProps) => { return data.reduce((childProps, datum, index) => { const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index; const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x); - datum = formatDataFromDomain(datum, domain); - const { _low, _open, _close, _high } = datum; + const formattedDatum = formatDataFromDomain(datum, domain); + const { _low, _open, _close, _high } = formattedDatum; const high = scale.y(_high); const close = scale.y(_close); const open = scale.y(_open); const low = scale.y(_low); - const dataStyle = getDataStyles(datum, style.data, props); + const dataStyle = getDataStyles(formattedDatum, style.data, props); const dataProps = { x, high, @@ -432,7 +435,7 @@ export const getBaseProps = (initialProps, fallbackProps) => { candleRatio, scale, data, - datum, + datum: formattedDatum, groupComponent, index, style: dataStyle, @@ -454,7 +457,7 @@ export const getBaseProps = (initialProps, fallbackProps) => { }; if (labels) { - const text = LabelHelpers.getText(props, datum, index); + const text = LabelHelpers.getText(props, formattedDatum, index); if ( (text !== undefined && text !== null) || (labels && (events || sharedEvents)) diff --git a/packages/victory-chart/src/helper-methods.tsx b/packages/victory-chart/src/helper-methods.tsx index a2bde7e15..6805490ff 100644 --- a/packages/victory-chart/src/helper-methods.tsx +++ b/packages/victory-chart/src/helper-methods.tsx @@ -125,20 +125,20 @@ export function getCalculatedProps(initialProps, childComponents) { } export function getChildren(props, childComponents, calculatedProps) { - childComponents = childComponents || getChildComponents(props); - calculatedProps = - calculatedProps || getCalculatedProps(props, childComponents); - const baseStyle = calculatedProps.style.parent; + const children = childComponents || getChildComponents(props); + const newCalculatedProps = + calculatedProps || getCalculatedProps(props, children); + const baseStyle = newCalculatedProps.style.parent; const { height, polar, theme, width } = props; - const { origin, horizontal } = calculatedProps; + const { origin, horizontal } = newCalculatedProps; const parentName = props.name || "chart"; - return childComponents.filter(React.isValidElement).map((child, index) => { + return children.filter(React.isValidElement).map((child, index) => { const role = child.type && child.type.role; const style = Array.isArray(child.props.style) ? child.props.style : defaults({}, child.props.style, { parent: baseStyle }); - const childProps = getChildProps(child, props, calculatedProps); + const childProps = getChildProps(child, props, newCalculatedProps); const name = child.props.name || `${parentName}-${role}-${index}`; const newProps = defaults( { @@ -150,7 +150,7 @@ export function getChildren(props, childComponents, calculatedProps) { style, name, origin: polar ? origin : undefined, - padding: calculatedProps.padding, + padding: newCalculatedProps.padding, key: `${name}-key-${index}`, standalone: false, }, @@ -193,9 +193,9 @@ export const getChildComponents = (props, defaultAxes?) => { }; const getDomain = (props, axis, childComponents) => { - childComponents = childComponents || React.Children.toArray(props.children); - const domain = Wrapper.getDomain(props, axis, childComponents); - const axisComponent = Axis.getAxisComponent(childComponents, axis); + const children = childComponents || React.Children.toArray(props.children); + const domain = Wrapper.getDomain(props, axis, children); + const axisComponent = Axis.getAxisComponent(children, axis); const invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis; return invertDomain ? domain.concat().reverse() : domain; diff --git a/packages/victory-core/src/victory-animation/util.ts b/packages/victory-core/src/victory-animation/util.ts index ec78abef0..bb7509ca7 100644 --- a/packages/victory-core/src/victory-animation/util.ts +++ b/packages/victory-core/src/victory-animation/util.ts @@ -97,11 +97,11 @@ export const interpolateFunction = function (a, b) { * differs in that it uses our custom interpolators when interpolating the value of each property in * an object. This allows the correct interpolation of nested objects, including styles * - * @param {any} a - Start value. - * @param {any} b - End value. + * @param {any} startValue - Start value. + * @param {any} endValue - End value. * @returns {Function} An interpolation function. */ -export const interpolateObject = function (a, b) { +export const interpolateObject = function (startValue, endValue) { const interpolateTypes = (x, y) => { if (x === y || !isInterpolatable(x) || !isInterpolatable(y)) { return interpolateImmediate(x, y); @@ -126,6 +126,8 @@ export const interpolateObject = function (a, b) { const i = {}; const c = {}; + let a = startValue; + let b = endValue; let k; if (a === null || typeof a !== "object") { diff --git a/packages/victory-core/src/victory-animation/victory-animation.tsx b/packages/victory-core/src/victory-animation/victory-animation.tsx index d9f270db1..a411a468f 100644 --- a/packages/victory-core/src/victory-animation/victory-animation.tsx +++ b/packages/victory-core/src/victory-animation/victory-animation.tsx @@ -259,8 +259,9 @@ export class VictoryAnimation extends React.Component< step can generate imprecise values, sometimes greater than 1 if this happens set the state to 1 and return, cancelling the timer */ - duration = duration !== undefined ? duration : this.props.duration; - const step = duration ? elapsed / duration : 1; + const animationDuration = + duration !== undefined ? duration : this.props.duration; + const step = animationDuration ? elapsed / animationDuration : 1; if (step >= 1) { this.setState({ data: this.interpolator!(1), diff --git a/packages/victory-core/src/victory-label/victory-label.tsx b/packages/victory-core/src/victory-label/victory-label.tsx index 0e89f2c40..22bf2e56d 100644 --- a/packages/victory-core/src/victory-label/victory-label.tsx +++ b/packages/victory-core/src/victory-label/victory-label.tsx @@ -38,7 +38,7 @@ export interface VictoryLabelProps { capHeight?: StringOrNumberOrCallback; children?: StringOrNumberOrCallback; className?: string; - datum?: object; + datum?: Record; data?: any[]; desc?: string; direction?: string; @@ -322,21 +322,20 @@ const getInlineXOffset = (calculatedProps, textElements, index) => { const centerOffset = -totalWidth / 2; switch (textAnchor) { case "start": - return widths.reduce((memo, width, i) => { - memo = i < index ? memo + width : memo; - return memo; - }, 0); + return widths.reduce( + (memo, width, i) => (i < index ? memo + width : memo), + 0, + ); case "end": - return widths.reduce((memo, width, i) => { - memo = i > index ? memo - width : memo; - return memo; - }, 0); + return widths.reduce( + (memo, width, i) => (i > index ? memo - width : memo), + 0, + ); default: // middle return widths.reduce((memo, width, i) => { const offsetWidth = i < index ? width : 0; - memo = i === index ? memo + width / 2 : memo + offsetWidth; - return memo; + return i === index ? memo + width / 2 : memo + offsetWidth; }, centerOffset); } }; diff --git a/packages/victory-core/src/victory-util/add-events.tsx b/packages/victory-core/src/victory-util/add-events.tsx index f67a07d1f..d764cbdc0 100644 --- a/packages/victory-core/src/victory-util/add-events.tsx +++ b/packages/victory-core/src/victory-util/add-events.tsx @@ -270,12 +270,10 @@ export function addEvents< applyExternalMutations(props, externalMutations) { if (!isEmpty(externalMutations)) { const callbacks = props.externalEventMutations.reduce( - (memo, mutation) => { - memo = isFunction(mutation.callback) + (memo, mutation) => + isFunction(mutation.callback) ? memo.concat(mutation.callback) - : memo; - return memo; - }, + : memo, [] as Array<() => void>, ); const compiledCallbacks = callbacks.length @@ -327,9 +325,9 @@ export function addEvents< } getBaseProps(props, getSharedEventState): this["baseProps"] { - getSharedEventState = + const getSharedEventStateFunction = getSharedEventState || this.getSharedEventState.bind(this); - const sharedParentState = getSharedEventState("parent", "parent"); + const sharedParentState = getSharedEventStateFunction("parent", "parent"); const parentState = this.getEventState("parent", "parent"); const baseParentProps = defaults({}, parentState, sharedParentState); const parentPropsList = baseParentProps.parentControlledProps; @@ -437,6 +435,7 @@ export function addEvents< const { dataComponent, labelComponent, groupComponent } = props; const dataKeys = without(this.dataKeys, "all"); const labelComponents = dataKeys.reduce((memo, key) => { + let newMemo = memo; const labelProps = this.getComponentProps( labelComponent, "labels", @@ -447,9 +446,11 @@ export function addEvents< labelProps.text !== undefined && labelProps.text !== null ) { - memo = memo.concat(React.cloneElement(labelComponent!, labelProps)); + newMemo = newMemo.concat( + React.cloneElement(labelComponent!, labelProps), + ); } - return memo; + return newMemo; }, [] as React.ReactElement[]); const dataProps = this.getComponentProps(dataComponent, "data", "all"); diff --git a/packages/victory-core/src/victory-util/axis.tsx b/packages/victory-core/src/victory-util/axis.tsx index 9b47978bb..f201018ba 100644 --- a/packages/victory-core/src/victory-util/axis.tsx +++ b/packages/victory-core/src/victory-util/axis.tsx @@ -36,10 +36,14 @@ export function getAxis(props) { * @returns {Array} all axis components that pass the given predicate or [] */ export function findAxisComponents(childComponents, predicate?) { - predicate = predicate || identity; + const predicateFunction = predicate || identity; const findAxes = (children) => { return children.reduce((memo, child) => { - if (child.type && child.type.role === "axis" && predicate(child)) { + if ( + child.type && + child.type.role === "axis" && + predicateFunction(child) + ) { return memo.concat(child); } else if (child.props && child.props.children) { return memo.concat( diff --git a/packages/victory-core/src/victory-util/data.ts b/packages/victory-core/src/victory-util/data.ts index 66ee31f55..ed3298d74 100644 --- a/packages/victory-core/src/victory-util/data.ts +++ b/packages/victory-core/src/victory-util/data.ts @@ -58,11 +58,12 @@ function sortData(dataset, sortKey, sortOrder = "ascending") { } // Ensures previous VictoryLine api for sortKey prop stays consistent + let formattedSortKey = sortKey; if (sortKey === "x" || sortKey === "y") { - sortKey = `_${sortKey}`; + formattedSortKey = `_${sortKey}`; } const order = sortOrder === "ascending" ? "asc" : "desc"; - return orderBy(dataset, sortKey, order); + return orderBy(dataset, formattedSortKey, order); } // This method will remove data points that break certain scales. (log scale only) @@ -239,6 +240,9 @@ export function formatData( } const defaultKeys = ["x", "y", "y0"]; + // TODO: We shouldn’t mutate the expectedKeys param here, + // but we need to figure out why changing it causes regressions in tests. + // eslint-disable-next-line no-param-reassign expectedKeys = Array.isArray(expectedKeys) ? expectedKeys : defaultKeys; const createAccessor = (name) => { @@ -281,10 +285,10 @@ export function formatData( ? dataset : dataset.reduce((dataArr, datum, index) => { // eslint-disable-line complexity - datum = parseDatum(datum); - const fallbackValues = { x: index, y: datum }; + const parsedDatum = parseDatum(datum); + const fallbackValues = { x: index, y: parsedDatum }; const processedValues = expectedKeys!.reduce((memo, type) => { - const processedValue = accessor[type](datum); + const processedValue = accessor[type](parsedDatum); const value = processedValue !== undefined ? processedValue @@ -300,7 +304,7 @@ export function formatData( return memo; }, {}); - const formattedDatum = assign({}, processedValues, datum); + const formattedDatum = assign({}, processedValues, parsedDatum); if (!isEmpty(formattedDatum)) { dataArr.push(formattedDatum); } @@ -408,8 +412,8 @@ export function getStringsFromData(props, axis) { const sortedData = sortData(data, props.sortKey, props.sortOrder); const dataStrings = sortedData .reduce((dataArr, datum) => { - datum = parseDatum(datum); - dataArr.push(accessor(datum)); + const parsedDatum = parseDatum(datum); + dataArr.push(accessor(parsedDatum)); return dataArr; }, []) .filter((datum) => typeof datum === "string"); diff --git a/packages/victory-core/src/victory-util/domain.ts b/packages/victory-core/src/victory-util/domain.ts index 9d788d4a3..5891dff61 100644 --- a/packages/victory-core/src/victory-util/domain.ts +++ b/packages/victory-core/src/victory-util/domain.ts @@ -183,22 +183,22 @@ export function createDomainFunction( getDomainFromDataFunction?, formatDomainFunction?, ) { - getDomainFromDataFunction = isFunction(getDomainFromDataFunction) + const getDomainFromDataFn = isFunction(getDomainFromDataFunction) ? getDomainFromDataFunction : getDomainFromData; - formatDomainFunction = isFunction(formatDomainFunction) + const formatDomainFn = isFunction(formatDomainFunction) ? formatDomainFunction : formatDomain; return (props, axis) => { const propsDomain = getDomainFromProps(props, axis); if (propsDomain) { - return formatDomainFunction(propsDomain, props, axis); + return formatDomainFn(propsDomain, props, axis); } const categories = Data.getCategories(props, axis); const domain = categories ? getDomainFromCategories(props, axis, categories) - : getDomainFromDataFunction(props, axis); - return domain ? formatDomainFunction(domain, props, axis) : undefined; + : getDomainFromDataFn(props, axis); + return domain ? formatDomainFn(domain, props, axis) : undefined; }; } @@ -231,14 +231,14 @@ export function getDomain(props, axis) { * @returns {Array|undefined} returns a domain from categories or undefined */ export function getDomainFromCategories(props, axis, categories?) { - categories = categories || Data.getCategories(props, axis); + const categoriesArray = categories || Data.getCategories(props, axis); const { polar, startAngle = 0, endAngle = 360 } = props; - if (!categories) { + if (!categoriesArray) { return undefined; } const minDomain = getMinFromProps(props, axis); const maxDomain = getMaxFromProps(props, axis); - const stringArray = Collection.containsStrings(categories) + const stringArray = Collection.containsStrings(categoriesArray) ? Data.getStringsFromCategories(props, axis) : []; const stringMap = @@ -249,8 +249,8 @@ export function getDomainFromCategories(props, axis, categories?) { return memo; }, {}); const categoryValues = stringMap - ? categories.map((value) => stringMap[value]) - : categories; + ? categoriesArray.map((value) => stringMap[value]) + : categoriesArray; const min = minDomain !== undefined ? minDomain @@ -273,11 +273,11 @@ export function getDomainFromCategories(props, axis, categories?) { * @returns {Array} the domain based on data */ export function getDomainFromData(props, axis, dataset) { - dataset = dataset || Data.getData(props); + const datasetArray = dataset || Data.getData(props); const { polar, startAngle = 0, endAngle = 360 } = props; const minDomain = getMinFromProps(props, axis); const maxDomain = getMaxFromProps(props, axis); - if (dataset.length < 1) { + if (datasetArray.length < 1) { return minDomain !== undefined && maxDomain !== undefined ? getDomainFromMinMax(minDomain, maxDomain) : undefined; @@ -285,14 +285,14 @@ export function getDomainFromData(props, axis, dataset) { const min = minDomain !== undefined ? minDomain - : getExtremeFromData(dataset, axis, "min"); + : getExtremeFromData(datasetArray, axis, "min"); const max = maxDomain !== undefined ? maxDomain - : getExtremeFromData(dataset, axis, "max"); + : getExtremeFromData(datasetArray, axis, "max"); const domain = getDomainFromMinMax(min, max); return polar && axis === "x" && Math.abs(startAngle - endAngle) === 360 - ? getSymmetricDomain(domain, getFlatData(dataset, axis)) + ? getSymmetricDomain(domain, getFlatData(datasetArray, axis)) : domain; } diff --git a/packages/victory-core/src/victory-util/events.ts b/packages/victory-core/src/victory-util/events.ts index e0708e8ee..fee5c9047 100644 --- a/packages/victory-core/src/victory-util/events.ts +++ b/packages/victory-core/src/victory-util/events.ts @@ -137,12 +137,12 @@ export function getScopedEvents( // Mandatory usage: `getScopedEvents.bind(this)` // eslint-disable-next-line no-invalid-this - baseProps = baseProps || this.baseProps; + const newBaseProps = baseProps || this.baseProps; // returns the original base props or base state of a given target element const getTargetProps = (identifier, type) => { const { childName, target, key } = identifier; // eslint-disable-next-line no-invalid-this - const baseType = type === "props" ? baseProps : this.state || {}; + const baseType = type === "props" ? newBaseProps : this.state || {}; const base = childName === undefined || childName === null || !baseType[childName] ? baseType @@ -249,10 +249,10 @@ export function getScopedEvents( // Parses an array of event returns into a single state mutation const parseEventReturn = (eventReturn, eventKey) => { return Array.isArray(eventReturn) - ? eventReturn.reduce((memo, props) => { - memo = assign({}, memo, parseEvent(props, eventKey)); - return memo; - }, {}) + ? eventReturn.reduce( + (memo, props) => assign({}, memo, parseEvent(props, eventKey)), + {}, + ) : parseEvent(eventReturn, eventKey); }; @@ -347,13 +347,10 @@ export function getEventState( // eslint-disable-next-line max-params export function getExternalMutationsWithChildren( mutations, - baseProps, - baseState, + baseProps = {}, + baseState = {}, childNames, ) { - baseProps = baseProps || {}; - baseState = baseState || {}; - return childNames.reduce((memo, childName) => { const childState = baseState[childName]; const mutation = getExternalMutations( @@ -380,13 +377,10 @@ export function getExternalMutationsWithChildren( // eslint-disable-next-line max-params export function getExternalMutations( mutations, - baseProps, - baseState, + baseProps = {}, + baseState = {}, childName?, ) { - baseProps = baseProps || {}; - baseState = baseState || {}; - const eventKeys = keys(baseProps); return eventKeys.reduce((memo, eventKey) => { const keyState = baseState[eventKey] || {}; @@ -452,8 +446,7 @@ export function getExternalMutation( return false; }; - mutations = Array.isArray(mutations) ? mutations : [mutations]; - let scopedMutations = mutations; + let scopedMutations = Array.isArray(mutations) ? mutations : [mutations]; if (identifier.childName) { scopedMutations = mutations.filter((m) => filterMutations(m, "childName")); } @@ -491,10 +484,9 @@ export function getComponentEvents(props, components) { const componentEvents = isFunction(defaultEvents) ? defaultEvents(component.props) : defaultEvents; - memo = Array.isArray(componentEvents) + return Array.isArray(componentEvents) ? memo.concat(...componentEvents) : memo; - return memo; }, [] as ComponentEvent[]); return events && events.length ? events : undefined; } diff --git a/packages/victory-core/src/victory-util/helpers.ts b/packages/victory-core/src/victory-util/helpers.ts index 0b61e1b99..de0e31550 100644 --- a/packages/victory-core/src/victory-util/helpers.ts +++ b/packages/victory-core/src/victory-util/helpers.ts @@ -258,6 +258,7 @@ export function reduceChildren< ]; const traverseChildren = (childArray, names, parent?) => { return childArray.reduce((memo, child, index) => { + let newMemo = memo; const childRole = child.type && child.type.role; const childName = child.props.name || `${childRole}-${names[index]}`; if (child.props && child.props.children) { @@ -291,14 +292,14 @@ export function reduceChildren< childNames, child, ); - memo = combine(memo, nestedResults); + newMemo = combine(newMemo, nestedResults); } else { const result = iteratee(child, childName, parent); if (result) { - memo = combine(memo, result); + newMemo = combine(newMemo, result); } } - return memo; + return newMemo; }, initialMemo); }; @@ -320,8 +321,7 @@ export function isHorizontal(props) { return childArray.reduce((memo, child) => { const childProps = child.props || {}; if (memo || childProps.horizontal || !childProps.children) { - memo = memo || childProps.horizontal; - return memo; + return memo || childProps.horizontal; } return traverseChildren(React.Children.toArray(childProps.children)); }, false); diff --git a/packages/victory-core/src/victory-util/immutable.ts b/packages/victory-core/src/victory-util/immutable.ts index 15aa648a0..898b2cb75 100644 --- a/packages/victory-core/src/victory-util/immutable.ts +++ b/packages/victory-core/src/victory-util/immutable.ts @@ -31,10 +31,11 @@ export function shallowToJS(x, whitelist?: Record) { return isIterable(x) ? x.reduce( (result: any, curr: any, key: any) => { + let newCurr = curr; if (whitelist && whitelist[key]) { - curr = shallowToJS(curr); + newCurr = shallowToJS(curr); } - result[key] = curr; + result[key] = newCurr; return result; }, isList(x) ? [] : {}, diff --git a/packages/victory-core/src/victory-util/label-helpers.ts b/packages/victory-core/src/victory-util/label-helpers.ts index 8c1944cc3..86961795f 100644 --- a/packages/victory-core/src/victory-util/label-helpers.ts +++ b/packages/victory-core/src/victory-util/label-helpers.ts @@ -1,11 +1,11 @@ /* eslint-disable no-use-before-define */ +import { VictoryLabelProps } from "../victory-label/victory-label"; import * as Helpers from "./helpers"; import { defaults } from "lodash"; // Private Functions -function getVerticalAnchor(props, datum) { - datum = datum || {}; +function getVerticalAnchor(props, datum: VictoryLabelProps["datum"] = {}) { const sign = datum._y >= 0 ? 1 : -1; const labelStyle = (props.style && props.style.labels) || {}; if (datum.verticalAnchor || labelStyle.verticalAnchor) { @@ -16,8 +16,7 @@ function getVerticalAnchor(props, datum) { return "middle"; } -function getTextAnchor(props, datum) { - datum = datum || {}; +function getTextAnchor(props, datum: VictoryLabelProps["datum"] = {}) { const { style, horizontal } = props; const sign = datum._y >= 0 ? 1 : -1; const labelStyle = (style && style.labels) || {}; @@ -29,14 +28,12 @@ function getTextAnchor(props, datum) { return sign >= 0 ? "start" : "end"; } -function getAngle(props, datum) { - datum = datum || {}; +function getAngle(props, datum: VictoryLabelProps["datum"] = {}) { const labelStyle = (props.style && props.style.labels) || {}; return datum.angle === undefined ? labelStyle.angle : datum.angle; } -function getPadding(props, datum) { - datum = datum || {}; +function getPadding(props, datum: VictoryLabelProps["datum"] = {}) { const { horizontal, style } = props; const labelStyle = style.labels || {}; const defaultPadding = Helpers.evaluateProp(labelStyle.padding, props) || 0; @@ -109,8 +106,7 @@ function getPolarOrientation(degrees) { // Exported Functions -export function getText(props, datum, index) { - datum = datum || {}; +export function getText(props, datum: VictoryLabelProps["datum"] = {}, index) { if (datum.label !== undefined) { return datum.label; } diff --git a/packages/victory-core/src/victory-util/selection.ts b/packages/victory-core/src/victory-util/selection.ts index 763045acf..7eff62390 100644 --- a/packages/victory-core/src/victory-util/selection.ts +++ b/packages/victory-core/src/victory-util/selection.ts @@ -73,8 +73,9 @@ export function getSVGEventCoordinates( const location = isReactTouchEvent(evt) ? evt.changedTouches[0] : (evt as React.MouseEvent); - svg = svg || getParentSVG(location); - const matrix = getTransformationMatrix(svg as SVGGraphicsElement); + const matrix = getTransformationMatrix( + (svg as SVGGraphicsElement) || getParentSVG(location), + ); return { x: transformTarget(location.clientX, matrix, "x"), y: transformTarget(location.clientY, matrix, "y"), diff --git a/packages/victory-core/src/victory-util/timer.ts b/packages/victory-core/src/victory-util/timer.ts index d0db7ce13..d3d32fe3f 100644 --- a/packages/victory-core/src/victory-util/timer.ts +++ b/packages/victory-core/src/victory-util/timer.ts @@ -47,11 +47,10 @@ export default class Timer { } subscribe(callback: TimerCallback, duration: number) { - duration = this.shouldAnimate ? duration : 0; const subscriptionID = this.subscribers.push({ startTime: now(), callback, - duration, + duration: this.shouldAnimate ? duration : 0, }); this.activeSubscriptions++; this.start(); diff --git a/packages/victory-core/src/victory-util/transitions.ts b/packages/victory-core/src/victory-util/transitions.ts index dd6d0a8f2..70b14d055 100644 --- a/packages/victory-core/src/victory-util/transitions.ts +++ b/packages/victory-core/src/victory-util/transitions.ts @@ -137,34 +137,39 @@ function getInitialChildProps(animate, data): TransitionProps { // eslint-disable-next-line max-params function getChildBeforeLoad(animate, child, data, cb): TransitionProps { - animate = assign({}, animate, { onEnd: cb }); - if (animate && animate.onLoad && !animate.onLoad.duration) { - return { animate, data }; + const newAnimate = assign({}, animate, { onEnd: cb }); + + if (newAnimate && newAnimate.onLoad && !newAnimate.onLoad.duration) { + return { animate: newAnimate, data }; } const before = - animate.onLoad && animate.onLoad.before ? animate.onLoad.before : identity; + newAnimate.onLoad && newAnimate.onLoad.before + ? newAnimate.onLoad.before + : identity; // If nodes need to exit, transform them with the provided onLoad.before function. - data = data.map((datum, idx) => { + const newData = data.map((datum, idx) => { return assign({}, datum, before(datum, idx, data)); }); - return { animate, data, clipWidth: 0 }; + return { animate: newAnimate, data: newData, clipWidth: 0 }; } // eslint-disable-next-line max-params function getChildOnLoad(animate, data, cb): TransitionProps { - animate = assign({}, animate, { onEnd: cb }); - if (animate && animate.onLoad && !animate.onLoad.duration) { + const newAnimate = assign({}, animate, { onEnd: cb }); + let newData = data; + + if (newAnimate && newAnimate.onLoad && !newAnimate.onLoad.duration) { return { animate, data }; } const after = animate.onLoad && animate.onLoad.after ? animate.onLoad.after : identity; // If nodes need to exit, transform them with the provided onLoad.after function. - data = data.map((datum, idx) => { + newData = data.map((datum, idx) => { return assign({}, datum, after(datum, idx, data)); }); - return { animate, data }; + return { animate: newAnimate, data: newData }; } // eslint-disable-next-line max-params, max-len @@ -178,7 +183,8 @@ function getChildPropsOnExit( // Whether or not _this_ child has exiting nodes, we want the exit- // transition for all children to have the same duration, delay, etc. const onExit = animate && animate.onExit; - animate = assign({}, animate, onExit); + const newAnimate = assign({}, animate, onExit); + let newData = data; if (exitingNodes) { // After the exit transition occurs, trigger the animations for @@ -189,7 +195,7 @@ function getChildPropsOnExit( ? animate.onExit.before : identity; // If nodes need to exit, transform them with the provided onExit.before function. - data = data.map((datum, idx) => { + newData = data.map((datum, idx) => { const key = (datum.key || idx).toString(); return exitingNodes[key] ? assign({}, datum, before(datum, idx, data)) @@ -197,7 +203,7 @@ function getChildPropsOnExit( }); } - return { animate, data }; + return { animate: newAnimate, data: newData }; } // eslint-disable-next-line max-params,max-len @@ -208,10 +214,12 @@ function getChildPropsBeforeEnter( enteringNodes, cb, ): TransitionProps { + let newAnimate = animate; + let newData = data; if (enteringNodes) { // Perform a normal animation here, except - when it finishes - trigger // the transition for entering nodes. - animate = assign({}, animate, { onEnd: cb }); + newAnimate = assign({}, animate, { onEnd: cb }); const before = animate.onEnter && animate.onEnter.before ? animate.onEnter.before @@ -219,7 +227,7 @@ function getChildPropsBeforeEnter( // We want the entering nodes to be included in the transition target // domain. However, we may not want these nodes to be displayed initially, // so perform the `onEnter.before` transformation on each node. - data = data.map((datum, idx) => { + newData = data.map((datum, idx) => { const key = (datum.key || idx).toString(); return enteringNodes[key] ? assign({}, datum, before(datum, idx, data)) @@ -227,7 +235,7 @@ function getChildPropsBeforeEnter( }); } - return { animate, data }; + return { animate: newAnimate, data: newData }; } // eslint-disable-next-line max-params, max-len @@ -240,25 +248,26 @@ function getChildPropsOnEnter( // Whether or not _this_ child has entering nodes, we want the entering- // transition for all children to have the same duration, delay, etc. const onEnter = animate && animate.onEnter; - animate = assign({}, animate, onEnter); + const newAnimate = assign({}, animate, onEnter); + let newData = data; if (enteringNodes) { // Old nodes have been transitioned to their new values, and the // domain should encompass the nodes that will now enter. So perform // the `onEnter.after` transformation on each node. - animate.onEnd = cb; + newAnimate.onEnd = cb; const after = - animate.onEnter && animate.onEnter.after - ? animate.onEnter.after + newAnimate.onEnter && newAnimate.onEnter.after + ? newAnimate.onEnter.after : identity; - data = data.map((datum, idx) => { + newData = data.map((datum, idx) => { const key = getDatumKey(datum, idx); return enteringNodes[key] ? assign({}, datum, after(datum, idx, data)) : datum; }); } - return { animate, data }; + return { animate: newAnimate, data: newData }; } /** diff --git a/packages/victory-core/src/victory-util/wrapper.tsx b/packages/victory-core/src/victory-util/wrapper.tsx index 23e7fc606..3bf7a4332 100644 --- a/packages/victory-core/src/victory-util/wrapper.tsx +++ b/packages/victory-core/src/victory-util/wrapper.tsx @@ -102,11 +102,12 @@ export function getDataFromChildren(props, childComponents) { const iteratee = (child, childName, parent) => { const childProps = assign({}, child.props, parentProps); let childData; + let childElement = child; if (!Data.isDataComponent(child)) { return null; } else if (child.type && isFunction(child.type.getData)) { - child = parent ? React.cloneElement(child, parent.props) : child; - childData = child.type.getData(childProps); + childElement = parent ? React.cloneElement(child, parent.props) : child; + childData = childElement.type.getData(childProps); } else { childData = Data.getData(childProps); } @@ -135,8 +136,10 @@ export function getData(props, childComponents) { if (props.data) { return Data.getData(props); } - childComponents = childComponents || React.Children.toArray(props.children); - return getDataFromChildren(props, childComponents); + return getDataFromChildren( + props, + childComponents || React.Children.toArray(props.children), + ); } export function getWidth(props, groupLength?, seriesLength?) { @@ -145,12 +148,12 @@ export function getWidth(props, groupLength?, seriesLength?) { ? Helpers.getRange(props, "y") : Helpers.getRange(props, "x"); const extent = Math.abs(range[1] - range[0]); - seriesLength = + const seriesLengthValue = seriesLength !== undefined ? seriesLength : (Array.isArray(datasets[0]) && datasets[0].length) || 1; - groupLength = groupLength || datasets.length; - const bars = groupLength * seriesLength; + const groupLengthValue = groupLength || datasets.length; + const bars = groupLengthValue * seriesLengthValue; const barRatio = 0.5; return Math.round((barRatio * extent) / bars); } @@ -241,10 +244,10 @@ export function getDomainFromChildren(props, axis, childComponents) { } export function getDomain(props, axis, childComponents) { - childComponents = childComponents || React.Children.toArray(props.children); + const children = childComponents || React.Children.toArray(props.children); const propsDomain = Domain.getDomainFromProps(props, axis); - const domainPadding = getDefaultDomainPadding(props, axis, childComponents); + const domainPadding = getDefaultDomainPadding(props, axis, children); let domain; if (propsDomain) { @@ -256,7 +259,7 @@ export function getDomain(props, axis, childComponents) { const dataDomain = dataset ? Domain.getDomainFromData(props, axis, dataset)! : []; - const childDomain = getDomainFromChildren(props, axis, childComponents); + const childDomain = getDomainFromChildren(props, axis, children); const min = minDomain || Collection.getMinValue([...dataDomain, ...childDomain]); const max = @@ -428,20 +431,12 @@ export function getCategoryAndAxisStringsFromChildren( } export function getStringsFromChildren(props, childComponents) { - childComponents = childComponents || React.Children.toArray(props.children); + const children = childComponents || React.Children.toArray(props.children); - const xStrings = getCategoryAndAxisStringsFromChildren( - props, - "x", - childComponents, - ); - const yStrings = getCategoryAndAxisStringsFromChildren( - props, - "y", - childComponents, - ); + const xStrings = getCategoryAndAxisStringsFromChildren(props, "x", children); + const yStrings = getCategoryAndAxisStringsFromChildren(props, "y", children); - const dataStrings = getStringsFromData(childComponents); + const dataStrings = getStringsFromData(children); return { x: uniq(flatten([...xStrings, ...dataStrings.x])), diff --git a/packages/victory-create-container/src/create-container.js b/packages/victory-create-container/src/create-container.js index d1ba80e87..40072162f 100644 --- a/packages/victory-create-container/src/create-container.js +++ b/packages/victory-create-container/src/create-container.js @@ -52,8 +52,8 @@ const combineDefaultEvents = (defaultEvents) => { // by combining any events that have the same target const eventsByTarget = groupBy(defaultEvents, "target"); const events = toPairs(eventsByTarget).map(([target, eventsArray]) => { - eventsArray = eventsArray.filter(Boolean); - return isEmpty(eventsArray) + const newEventsArray = eventsArray.filter(Boolean); + return isEmpty(newEventsArray) ? null : { target, diff --git a/packages/victory-errorbar/src/helper-methods.tsx b/packages/victory-errorbar/src/helper-methods.tsx index b77d9e561..220468e22 100644 --- a/packages/victory-errorbar/src/helper-methods.tsx +++ b/packages/victory-errorbar/src/helper-methods.tsx @@ -214,13 +214,13 @@ export const getBaseProps = (initialProps, fallbackProps) => { return data.reduce((childProps, datum, index) => { const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index; const { x, y } = Helpers.scalePoint(assign({}, props, { scale }), datum); - datum = formatDataFromDomain(datum, domain); - const errorX = getErrors(props, datum, "x"); - const errorY = getErrors(props, datum, "y"); + const formattedDatum = formatDataFromDomain(datum, domain); + const errorX = getErrors(props, formattedDatum, "x"); + const errorY = getErrors(props, formattedDatum, "y"); const dataProps = { borderWidth, data, - datum, + datum: formattedDatum, errorX: horizontal ? errorY : errorX, errorY: horizontal ? errorX : errorY, groupComponent, diff --git a/packages/victory-legend/src/helper-methods.ts b/packages/victory-legend/src/helper-methods.ts index 928f04e93..3435ed2c9 100644 --- a/packages/victory-legend/src/helper-methods.ts +++ b/packages/victory-legend/src/helper-methods.ts @@ -1,5 +1,6 @@ import { defaults, assign, groupBy, keys, sum, range, isNil } from "lodash"; import { Helpers, Style, TextSize } from "victory-core"; +import { VictoryLegendProps } from "./victory-legend"; const getColorScale = (props) => { const { colorScale } = props; @@ -16,9 +17,8 @@ const getLabelStyles = (props) => { }); }; -const getStyles = (props, styleObject) => { +const getStyles = (props, styleObject: VictoryLegendProps["style"] = {}) => { const style = props.style || {}; - styleObject = styleObject || {}; const parentStyleProps = { height: "100%", width: "100%" }; return { parent: defaults(style.parent, styleObject.parent, parentStyleProps), @@ -125,14 +125,8 @@ const getTitleDimensions = (props) => { const getOffset = (datum, rowHeights, columnWidths) => { const { column, row } = datum; return { - x: range(column).reduce((memo, curr) => { - memo += columnWidths[curr]; - return memo; - }, 0), - y: range(row).reduce((memo, curr) => { - memo += rowHeights[curr]; - return memo; - }, 0), + x: range(column).reduce((memo, curr) => memo + columnWidths[curr], 0), + y: range(row).reduce((memo, curr) => memo + rowHeights[curr], 0), }; }; diff --git a/packages/victory-polar-axis/src/helper-methods.ts b/packages/victory-polar-axis/src/helper-methods.ts index 697875ee4..88ea1f042 100644 --- a/packages/victory-polar-axis/src/helper-methods.ts +++ b/packages/victory-polar-axis/src/helper-methods.ts @@ -101,12 +101,14 @@ export const getScale = (props: VictoryPolarAxisProps) => { return scale; }; -export const getStyles = (props: VictoryPolarAxisProps, styleObject) => { +export const getStyles = ( + props: VictoryPolarAxisProps, + styleObject: VictoryPolarAxisProps["style"] = {}, +) => { if (props.disableInlineStyles) { return {}; } const style = props.style || {}; - styleObject = styleObject || {}; const parentStyleProps = { height: "auto", width: "100%" }; return { parent: defaults(parentStyleProps, style.parent, styleObject.parent), diff --git a/packages/victory-selection-container/src/selection-helpers.tsx b/packages/victory-selection-container/src/selection-helpers.tsx index 466c08ceb..f023ce84e 100644 --- a/packages/victory-selection-container/src/selection-helpers.tsx +++ b/packages/victory-selection-container/src/selection-helpers.tsx @@ -25,14 +25,16 @@ class SelectionHelpersClass { const iteratee = (child, childName, parent) => { const blacklist = props.selectionBlacklist || []; + let childElement; if (!Data.isDataComponent(child) || includes(blacklist, childName)) { return null; } else if (child.type && isFunction(child.type.getData)) { - child = parent ? React.cloneElement(child, parent.props) : child; - const childData = child.props && child.type.getData(child.props); + childElement = parent ? React.cloneElement(child, parent.props) : child; + const childData = + childElement.props && childElement.type.getData(childElement.props); return childData ? { childName, data: childData } : null; } - const childData = getData(child.props); + const childData = getData(childElement.props); return childData ? { childName, data: childData } : null; }; return Helpers.reduceChildren( @@ -45,14 +47,13 @@ class SelectionHelpersClass { filterDatasets(props, datasets) { const filtered = datasets.reduce((memo, dataset) => { const selectedData = this.getSelectedData(props, dataset.data); - memo = selectedData + return selectedData ? memo.concat({ childName: dataset.childName, eventKey: selectedData.eventKey, data: selectedData.data, }) : memo; - return memo; }, []); return filtered.length ? filtered : null; } diff --git a/packages/victory-shared-events/src/victory-shared-events.js b/packages/victory-shared-events/src/victory-shared-events.js index 20f1afa98..b6bbdf02d 100644 --- a/packages/victory-shared-events/src/victory-shared-events.js +++ b/packages/victory-shared-events/src/victory-shared-events.js @@ -166,12 +166,8 @@ export default class VictorySharedEvents extends React.Component { applyExternalMutations(props, externalMutations) { if (!isEmpty(externalMutations)) { const callbacks = props.externalEventMutations.reduce( - (memo, mutation) => { - memo = isFunction(mutation.callback) - ? memo.concat(mutation.callback) - : memo; - return memo; - }, + (memo, mutation) => + isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo, [], ); const compiledCallbacks = callbacks.length diff --git a/packages/victory-stack/src/helper-methods.tsx b/packages/victory-stack/src/helper-methods.tsx index 919e9c1bd..bc2e36b34 100644 --- a/packages/victory-stack/src/helper-methods.tsx +++ b/packages/victory-stack/src/helper-methods.tsx @@ -26,22 +26,22 @@ function fillData(props, datasets) { let indexOffset = 0; const isDate = dataset[0] && dataset[0]._x instanceof Date; const filledInData = xArr.map((x: number | Date, index) => { - x = Number(x); + let parsedX: number | Date = Number(x); const datum = dataset[index - indexOffset]; if (datum) { const x1 = isDate ? datum._x.getTime() : datum._x; - if (x1 === x) { + if (x1 === parsedX) { return datum; } indexOffset++; const y = fillInMissingData ? 0 : null; - x = isDate ? new Date(x) : x; - return { x, y, _x: x, _y: y }; + parsedX = isDate ? new Date(parsedX) : parsedX; + return { x: parsedX, y, _x: parsedX, _y: y }; } const y = fillInMissingData ? 0 : null; - x = isDate ? new Date(x) : x; - return { x, y, _x: x, _y: y }; + parsedX = isDate ? new Date(parsedX) : parsedX; + return { x: parsedX, y, _x: parsedX, _y: y }; }); return filledInData; @@ -117,20 +117,28 @@ function stackData(props, childComponents) { return datasets.map((d, i) => addLayoutData(props, datasets, i)); } -export function getCalculatedProps(props, childComponents) { - childComponents = childComponents || React.Children.toArray(props.children); +export function getCalculatedProps(initialProps, childComponents) { + const children = + childComponents || React.Children.toArray(initialProps.children); const role = "stack"; - props = Helpers.modifyProps(props, fallbackProps, role); + const props = Helpers.modifyProps(initialProps, fallbackProps, role); const style = Wrapper.getStyle(props.theme, props.style, role); - const categories = - props.categories || Wrapper.getCategories(props, childComponents); - const datasets = props.datasets || stackData(props, childComponents); - const children = childComponents.map((c, i) => { + const categories = props.categories || Wrapper.getCategories(props, children); + const datasets = props.datasets || stackData(props, children); + const clonedChildren = children.map((c, i) => { return React.cloneElement(c, { data: datasets[i] }); }); const domain = { - x: Wrapper.getDomain(assign({}, props, { categories }), "x", children), - y: Wrapper.getDomain(assign({}, props, { categories }), "y", children), + x: Wrapper.getDomain( + assign({}, props, { categories }), + "x", + clonedChildren, + ), + y: Wrapper.getDomain( + assign({}, props, { categories }), + "y", + clonedChildren, + ), }; const range = props.range || { x: Helpers.getRange(props, "x"), @@ -224,18 +232,18 @@ function getColorScale(props, child) { : colorScaleOptions; } -export function getChildren(props, childComponents, calculatedProps) { - props = Helpers.modifyProps(props, fallbackProps, "stack"); - childComponents = childComponents || React.Children.toArray(props.children); - calculatedProps = - calculatedProps || getCalculatedProps(props, childComponents); - const { datasets } = calculatedProps; - const childProps = getChildProps(props, calculatedProps); +export function getChildren(initialProps, childComponents, calculatedProps) { + const props = Helpers.modifyProps(initialProps, fallbackProps, "stack"); + const children = childComponents || React.Children.toArray(props.children); + const newCalculatedProps = + calculatedProps || getCalculatedProps(props, children); + const { datasets } = newCalculatedProps; + const childProps = getChildProps(props, newCalculatedProps); const parentName = props.name || "stack"; - return childComponents.map((child, index) => { + return children.map((child, index) => { const role = child.type && child.type.role; const data = datasets[index]; - const style = Wrapper.getChildStyle(child, index, calculatedProps); + const style = Wrapper.getChildStyle(child, index, newCalculatedProps); const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels; diff --git a/packages/victory-voronoi-container/src/victory-voronoi-container.js b/packages/victory-voronoi-container/src/victory-voronoi-container.js index 46f70086f..8bdc3e5ae 100644 --- a/packages/victory-voronoi-container/src/victory-voronoi-container.js +++ b/packages/victory-voronoi-container/src/victory-voronoi-container.js @@ -146,8 +146,7 @@ export const voronoiContainerMixin = (base) => const styleArray = textArray.length ? textArray.map(() => style) : [style]; - memo = memo.concat(styleArray); - return memo; + return memo.concat(styleArray); }, []); } @@ -182,8 +181,7 @@ export const voronoiContainerMixin = (base) => if (t === null || t === undefined) { return memo; } - memo = memo.concat(`${t}`.split("\n")); - return memo; + return memo.concat(`${t}`.split("\n")); }, []); // remove properties from first point to make datum diff --git a/stories/data.js b/stories/data.js index 7e41659ca..0a8c9e829 100644 --- a/stories/data.js +++ b/stories/data.js @@ -13,8 +13,7 @@ import seedrandom from "seedrandom"; // { x: 360, y: 7 } // ]; -const getTimeData = (num, seed) => { - seed = seed || "getData"; +const getTimeData = (num, seed = "getData") => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 10; const current = 1523389495000; @@ -26,15 +25,13 @@ const getTimeData = (num, seed) => { }); }; -const getData = (num, seed, max = 10) => { - seed = seed || "getData"; +const getData = (num, seed = "getData", max = 10) => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * max; return range(num).map((v) => ({ x: v + 1, y: rand() })); }; -const getDataWithBaseline = (num, seed, max = 10) => { - seed = seed || "getData"; +const getDataWithBaseline = (num, seed = "getData", max = 10) => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * max; return range(num).map((v) => ({ x: v + 1, y: rand(), y0: rand() })); @@ -55,37 +52,32 @@ const getDescendingSmallData = () => { ]; }; -const getStringData = (num, seed) => { - seed = seed || "getData"; +const getStringData = (num, seed = "getData") => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 10; return range(num).map((v) => ({ x: `#${v + 1}`, y: rand() })); }; -const getLogData = (num, seed) => { - seed = seed || "getData"; +const getLogData = (num, seed = "getData") => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 100000; return range(num).map((v) => ({ x: v + 1, y: rand() })); }; -const getMixedData = (num, seed) => { - seed = seed || "getMixedData"; +const getMixedData = (num, seed = "getMixedData") => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 10 - 5; return range(num).map((v) => ({ x: v + 1, y: rand() })); }; -const getFourQuadrantData = (num, seed) => { - seed = seed || "getMixedData"; +const getFourQuadrantData = (num, seed = "getMixedData") => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 10 - 5; return range(num).map((v) => ({ x: v - Math.round(num / 2), y: rand() })); }; -const getArrayData = (num, samples) => { +const getArrayData = (num, samples = 10) => { const seed = "getData"; - samples = samples || 10; const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 10; return range(num).map((v) => { diff --git a/stories/victory-axis.stories.js b/stories/victory-axis.stories.js index 5a4c3b812..bdb4db304 100644 --- a/stories/victory-axis.stories.js +++ b/stories/victory-axis.stories.js @@ -33,14 +33,11 @@ const getTimeValues = (num) => { }); }; -const getValues = (num, min, step) => { - min = min || 0; - step = step || 1; +const getValues = (num, min = 0, step = 1) => { return range(num).map((v) => v * step + min); }; -const getRandomValues = (num, seed) => { - seed = seed || "random"; +const getRandomValues = (num, seed = "random") => { const baseSeed = seedrandom(seed); const rand = () => Math.round(baseSeed.quick() * 100); const result = range(num).map(() => rand()); diff --git a/stories/victory-box-plot.stories.js b/stories/victory-box-plot.stories.js index 435544b36..38f982603 100644 --- a/stories/victory-box-plot.stories.js +++ b/stories/victory-box-plot.stories.js @@ -10,9 +10,8 @@ import seedrandom from "seedrandom"; import { getArrayData } from "./data"; import styled from "styled-components"; -const getRepeatData = (num, samples) => { +const getRepeatData = (num, samples = 10) => { const seed = "getRepeatData"; - samples = samples || 10; const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 10; return range(num).reduce((memo, curr) => { @@ -24,8 +23,7 @@ const getRepeatData = (num, samples) => { }, []); }; -const getData = (num, seed) => { - seed = seed || "getData"; +const getData = (num, seed = "getData") => { const baseSeed = seedrandom(seed); const rand = () => Math.round(1 + baseSeed.quick() * 5); return range(num).map((v) => { diff --git a/stories/victory-candlestick.stories.js b/stories/victory-candlestick.stories.js index 14d7561f8..89ed488ba 100644 --- a/stories/victory-candlestick.stories.js +++ b/stories/victory-candlestick.stories.js @@ -16,8 +16,7 @@ const sampleData = [ { x: 3, open: 50, close: 80, high: 90, low: 20 }, { x: 4, open: 70, close: 22, high: 70, low: 5 }, ]; -const getTimeData = (num, seed) => { - seed = seed || "getTimeData"; +const getTimeData = (num, seed = "getTimeData") => { const baseSeed = seedrandom(seed); const current = 1523389495000; return range(num).map((v) => { @@ -35,8 +34,7 @@ const getTimeData = (num, seed) => { }); }; -const getData = (num, seed) => { - seed = seed || "getData"; +const getData = (num, seed = "getData") => { const baseSeed = seedrandom(seed); return range(num).map((v) => { const low = 2 + baseSeed.quick() * 5; @@ -114,7 +112,6 @@ export const WickStrokeWidth = () => { { - seed = seed || "getData"; +const getData = (num, symmetric, seed = "getData") => { const baseSeed = seedrandom(seed); const rand = () => baseSeed.quick() * 3; return range(num).map((v) => { diff --git a/stories/victory-polar-axis.stories.js b/stories/victory-polar-axis.stories.js index 493ca2f18..3a8c8ba72 100644 --- a/stories/victory-polar-axis.stories.js +++ b/stories/victory-polar-axis.stories.js @@ -34,14 +34,11 @@ const getTimeValues = (num) => { }); }; -const getValues = (num, min, step) => { - min = min || 0; - step = step || 1; +const getValues = (num, min = 0, step = 1) => { return range(num).map((v) => v * step + min); }; -const getRandomValues = (num, seed) => { - seed = seed || "random"; +const getRandomValues = (num, seed = "random") => { const baseSeed = seedrandom(seed); const rand = () => Math.round(baseSeed.quick() * 100); const result = range(num).map(() => rand()); From e42ba3134cb7ea807cce2bd4d5937ff9bde313de Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Fri, 19 Jan 2024 11:44:56 +0000 Subject: [PATCH 24/29] Migrate victory-voronoi to TypeScript (#2726) --- .changeset/long-files-itch.md | 5 ++ packages/victory-voronoi/src/index.d.ts | 46 ---------------- packages/victory-voronoi/src/index.js | 2 - packages/victory-voronoi/src/index.ts | 2 + ...ronoi.test.js => victory-voronoi.test.tsx} | 21 ++++---- ...victory-voronoi.js => victory-voronoi.tsx} | 52 +++++++++++++------ .../src/{voronoi.js => voronoi.tsx} | 45 +++++++--------- 7 files changed, 73 insertions(+), 100 deletions(-) create mode 100644 .changeset/long-files-itch.md delete mode 100644 packages/victory-voronoi/src/index.d.ts delete mode 100644 packages/victory-voronoi/src/index.js create mode 100644 packages/victory-voronoi/src/index.ts rename packages/victory-voronoi/src/{victory-voronoi.test.js => victory-voronoi.test.tsx} (94%) rename packages/victory-voronoi/src/{victory-voronoi.js => victory-voronoi.tsx} (55%) rename packages/victory-voronoi/src/{voronoi.js => voronoi.tsx} (75%) diff --git a/.changeset/long-files-itch.md b/.changeset/long-files-itch.md new file mode 100644 index 000000000..8e0800008 --- /dev/null +++ b/.changeset/long-files-itch.md @@ -0,0 +1,5 @@ +--- +"victory-voronoi": patch +--- + +Migrate victory-voronoi to TypeScript diff --git a/packages/victory-voronoi/src/index.d.ts b/packages/victory-voronoi/src/index.d.ts deleted file mode 100644 index 34016d612..000000000 --- a/packages/victory-voronoi/src/index.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import * as React from "react"; -import { - EventPropTypeInterface, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryCommonPrimitiveProps, - VictoryDatableProps, - VictoryLabelableProps, - VictoryMultiLabelableProps, - VictoryStyleInterface, -} from "victory-core"; - -export type VictoryVoronoiSortOrderType = "ascending" | "descending"; - -export interface VictoryVoronoiProps - extends Omit, - VictoryDatableProps, - VictoryLabelableProps, - VictoryMultiLabelableProps { - events?: EventPropTypeInterface< - string, - string | number | (string | number)[] - >[]; - type?: number; - sortKey?: StringOrNumberOrCallback | string[]; - sortOrder?: VictoryVoronoiSortOrderType; - size?: number | { (data: any): number }; - style?: VictoryStyleInterface; -} - -export interface VoronoiProps extends VictoryCommonPrimitiveProps { - circleComponent?: React.ReactElement; - clipId?: number | string; - clipPathComponent?: React.ReactElement; - datum?: any; - groupComponent?: React.ReactElement; - pathComponent?: React.ReactElement; - polygon?: []; - size?: number; - x?: number; - y?: number; -} - -export class VictoryVoronoi extends React.Component {} - -export class Voronoi extends React.Component {} diff --git a/packages/victory-voronoi/src/index.js b/packages/victory-voronoi/src/index.js deleted file mode 100644 index adc24834f..000000000 --- a/packages/victory-voronoi/src/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as VictoryVoronoi } from "./victory-voronoi"; -export { default as Voronoi } from "./voronoi"; diff --git a/packages/victory-voronoi/src/index.ts b/packages/victory-voronoi/src/index.ts new file mode 100644 index 000000000..fdee50a62 --- /dev/null +++ b/packages/victory-voronoi/src/index.ts @@ -0,0 +1,2 @@ +export * from "./victory-voronoi"; +export * from "./voronoi"; diff --git a/packages/victory-voronoi/src/victory-voronoi.test.js b/packages/victory-voronoi/src/victory-voronoi.test.tsx similarity index 94% rename from packages/victory-voronoi/src/victory-voronoi.test.js rename to packages/victory-voronoi/src/victory-voronoi.test.tsx index 79938eb5b..11a49f073 100644 --- a/packages/victory-voronoi/src/victory-voronoi.test.js +++ b/packages/victory-voronoi/src/victory-voronoi.test.tsx @@ -1,7 +1,7 @@ import React from "react"; import { random, range } from "lodash"; import { calculateD3Path } from "../../../test/helpers"; -import { VictoryVoronoi, Voronoi } from "victory-voronoi"; +import { VictoryVoronoi, VictoryVoronoiProps, Voronoi } from "victory-voronoi"; import { fireEvent, render, screen } from "@testing-library/react"; describe("components/victory-voronoi", () => { @@ -19,8 +19,8 @@ describe("components/victory-voronoi", () => { it("renders an svg with the correct width and height", () => { const { container } = render(); const svg = container.querySelector("svg"); - expect(svg.style.width).toEqual("100%"); - expect(svg.style.height).toEqual("100%"); + expect(svg?.style.width).toEqual("100%"); + expect(svg?.style.height).toEqual("100%"); }); it("renders an svg with the correct viewbox", () => { @@ -33,7 +33,7 @@ describe("components/victory-voronoi", () => { describe("component rendering with data", () => { it("renders the correct d3 path", () => { - const props = { + const props: VictoryVoronoiProps = { width: 400, height: 300, padding: 50, @@ -68,7 +68,7 @@ describe("components/victory-voronoi", () => { const renderedDataProps = screen .getAllByTestId("voronoi-1") - .map((node) => JSON.parse(node.getAttribute("data-props-json"))); + .map((node) => JSON.parse(node.getAttribute("data-props-json") || "")); expect(renderedDataProps.map((props) => props.datum._x)).toEqual([ 0, 1, 2, 3, 4, ]); @@ -91,7 +91,7 @@ describe("components/victory-voronoi", () => { const renderedDataProps = screen .getAllByTestId("voronoi-1") - .map((node) => JSON.parse(node.getAttribute("data-props-json"))); + .map((node) => JSON.parse(node.getAttribute("data-props-json") || "")); expect(renderedDataProps.map((props) => props.datum._x)).toEqual([ 4, 3, 2, 1, 0, @@ -125,7 +125,7 @@ describe("components/victory-voronoi", () => { />, ); const svg = container.querySelector("svg"); - fireEvent.click(svg); + fireEvent.click(svg!); expect(clickHandler).toBeCalled(); // the first argument is the standard evt object expect(Object.keys(clickHandler.mock.calls[0][1])).toEqual( @@ -164,7 +164,7 @@ describe("components/victory-voronoi", () => { const clickHandler = jest.fn(); const { container } = render( { const labels = container.querySelectorAll("text"); - // TODO: figure out why there's no labels rendering? - expect(labels).toHaveLength(0); + expect(labels).toHaveLength(1); labels.forEach((node, index) => { clickHandler.mockClear(); @@ -211,7 +210,7 @@ describe("components/victory-voronoi", () => { dataComponent={ `${datum.x}`} - tabIndex={({ index }) => index + 6} + tabIndex={({ index }) => Number(index) + 6} /> } />, diff --git a/packages/victory-voronoi/src/victory-voronoi.js b/packages/victory-voronoi/src/victory-voronoi.tsx similarity index 55% rename from packages/victory-voronoi/src/victory-voronoi.js rename to packages/victory-voronoi/src/victory-voronoi.tsx index 5785c6644..f25f51a7d 100644 --- a/packages/victory-voronoi/src/victory-voronoi.js +++ b/packages/victory-voronoi/src/victory-voronoi.tsx @@ -1,6 +1,5 @@ import React from "react"; import { - PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents, @@ -9,20 +8,46 @@ import { DefaultTransitions, Data, Domain, - CommonProps, UserProps, + EventPropTypeInterface, + EventsMixinClass, + VictoryCommonProps, + VictoryDatableProps, + VictoryLabelableProps, + VictoryMultiLabelableProps, + VictoryStyleInterface, } from "victory-core"; -import Voronoi from "./voronoi"; +import { Voronoi } from "./voronoi"; import { getBaseProps } from "./helper-methods"; +export type VictoryVoronoiSortOrderType = "ascending" | "descending"; + +export interface VictoryVoronoiProps + extends Omit, + VictoryDatableProps, + VictoryLabelableProps, + VictoryMultiLabelableProps { + events?: EventPropTypeInterface< + string, + string | number | (string | number)[] + >[]; + type?: number; + sortOrder?: VictoryVoronoiSortOrderType; + size?: number | { (data: any): number }; + style?: VictoryStyleInterface; +} + const fallbackProps = { width: 450, height: 300, padding: 50, }; -class VictoryVoronoi extends React.Component { - static animationWhitelist = [ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +interface VictoryVoronoiBase extends EventsMixinClass {} + +class VictoryVoronoiBase extends React.Component { + static animationWhitelist: (keyof VictoryVoronoiProps)[] = [ "data", "domain", "height", @@ -37,13 +62,7 @@ class VictoryVoronoi extends React.Component { static role = "voronoi"; static defaultTransitions = DefaultTransitions.discreteTransitions(); - static propTypes = { - ...CommonProps.baseProps, - ...CommonProps.dataProps, - size: CustomPropTypes.nonNegative, - }; - - static defaultProps = { + static defaultProps: VictoryVoronoiProps = { containerComponent: , dataComponent: , labelComponent: , @@ -56,8 +75,9 @@ class VictoryVoronoi extends React.Component { static getDomain = Domain.getDomain; static getData = Data.getData; - static getBaseProps = (props) => getBaseProps(props, fallbackProps); - static expectedComponents = [ + static getBaseProps = (props: VictoryVoronoiProps) => + getBaseProps(props, fallbackProps); + static expectedComponents: (keyof VictoryVoronoiProps)[] = [ "dataComponent", "labelComponent", "groupComponent", @@ -69,7 +89,7 @@ class VictoryVoronoi extends React.Component { return !!this.props.animate; } - render() { + render(): React.ReactElement { const { animationWhitelist, role } = VictoryVoronoi; const props = Helpers.modifyProps(this.props, fallbackProps, role); @@ -87,4 +107,4 @@ class VictoryVoronoi extends React.Component { } } -export default addEvents(VictoryVoronoi); +export const VictoryVoronoi = addEvents(VictoryVoronoiBase); diff --git a/packages/victory-voronoi/src/voronoi.js b/packages/victory-voronoi/src/voronoi.tsx similarity index 75% rename from packages/victory-voronoi/src/voronoi.js rename to packages/victory-voronoi/src/voronoi.tsx index 2824d43cd..22380f8dc 100644 --- a/packages/victory-voronoi/src/voronoi.js +++ b/packages/victory-voronoi/src/voronoi.tsx @@ -1,24 +1,35 @@ -/* eslint no-magic-numbers: ["error", { "ignore": [2] }]*/ import React from "react"; -import PropTypes from "prop-types"; import { assign } from "lodash"; import { Helpers, - CommonProps, ClipPath, Path, Circle, UserProps, + VictoryCommonPrimitiveProps, } from "victory-core"; -const getVoronoiPath = (props) => { +export interface VoronoiProps extends VictoryCommonPrimitiveProps { + circleComponent?: React.ReactElement; + clipId?: number | string; + clipPathComponent?: React.ReactElement; + datum?: any; + groupComponent?: React.ReactElement; + pathComponent?: React.ReactElement; + polygon?: []; + size?: number; + x?: number; + y?: number; +} + +const getVoronoiPath = (props: VoronoiProps) => { const { polygon } = props; return Array.isArray(polygon) && polygon.length - ? `M ${props.polygon.join("L")} Z` + ? `M ${props.polygon?.join("L")} Z` : ""; }; -const evaluateProps = (props) => { +function evaluateProps(props: T) { /** * Potential evaluated props are: * `aria-label` @@ -33,7 +44,7 @@ const evaluateProps = (props) => { const style = Helpers.evaluateStyle(props.style, props); const tabIndex = Helpers.evaluateProp(props.tabIndex, props); return assign({}, props, { ariaLabel, id, size, style, tabIndex }); -}; +} const defaultProps = { pathComponent: , @@ -44,9 +55,8 @@ const defaultProps = { shapeRendering: "auto", }; -const Voronoi = (initialProps) => { +export const Voronoi = (initialProps: VoronoiProps) => { const props = evaluateProps({ ...defaultProps, ...initialProps }); - const { ariaLabel, role, @@ -58,6 +68,7 @@ const Voronoi = (initialProps) => { size, tabIndex, } = props; + const voronoiPath = getVoronoiPath(props); const sharedProps = { "aria-label": ariaLabel, @@ -99,19 +110,3 @@ const Voronoi = (initialProps) => { d: voronoiPath, }); }; - -Voronoi.propTypes = { - ...CommonProps.primitiveProps, - circleComponent: PropTypes.element, - clipId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - clipPathComponent: PropTypes.element, - datum: PropTypes.object, - groupComponent: PropTypes.element, - pathComponent: PropTypes.element, - polygon: PropTypes.array, - size: PropTypes.number, - x: PropTypes.number, - y: PropTypes.number, -}; - -export default Voronoi; From 3cd3cea17928cdd9fc02763c1049f00e3b73fd1e Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Fri, 19 Jan 2024 06:29:46 -0600 Subject: [PATCH 25/29] Migrate victory-tooltip to typescript (#2725) --- .changeset/tender-bees-talk.md | 6 + packages/victory-core/src/exports.test.ts | 1 + packages/victory-core/src/types/callbacks.ts | 13 +- .../src/victory-util/user-props.ts | 14 + packages/victory-tooltip/package.json | 3 + .../src/{flyout.test.js => flyout.test.tsx} | 6 +- .../src/{flyout.js => flyout.tsx} | 122 ++++++--- packages/victory-tooltip/src/index.d.ts | 92 ------- packages/victory-tooltip/src/index.js | 2 - packages/victory-tooltip/src/index.ts | 2 + ...oltip.test.js => victory-tooltip.test.tsx} | 5 +- ...victory-tooltip.js => victory-tooltip.tsx} | 258 +++++++++--------- pnpm-lock.yaml | 3 + 13 files changed, 265 insertions(+), 262 deletions(-) create mode 100644 .changeset/tender-bees-talk.md rename packages/victory-tooltip/src/{flyout.test.js => flyout.test.tsx} (92%) rename packages/victory-tooltip/src/{flyout.js => flyout.tsx} (60%) delete mode 100644 packages/victory-tooltip/src/index.d.ts delete mode 100644 packages/victory-tooltip/src/index.js create mode 100644 packages/victory-tooltip/src/index.ts rename packages/victory-tooltip/src/{victory-tooltip.test.js => victory-tooltip.test.tsx} (98%) rename packages/victory-tooltip/src/{victory-tooltip.js => victory-tooltip.tsx} (76%) diff --git a/.changeset/tender-bees-talk.md b/.changeset/tender-bees-talk.md new file mode 100644 index 000000000..ba72ebc5f --- /dev/null +++ b/.changeset/tender-bees-talk.md @@ -0,0 +1,6 @@ +--- +"victory-core": patch +"victory-tooltip": patch +--- + +Migrate victory-tooltip to typescript diff --git a/packages/victory-core/src/exports.test.ts b/packages/victory-core/src/exports.test.ts index ffe4a9d47..5a237528f 100644 --- a/packages/victory-core/src/exports.test.ts +++ b/packages/victory-core/src/exports.test.ts @@ -408,6 +408,7 @@ describe("victory-core", () => { "getTransitionPropsFactory": [Function], }, "UserProps": Object { + "assert": [Function], "getSafeUserProps": [Function], "withSafeUserProps": [Function], }, diff --git a/packages/victory-core/src/types/callbacks.ts b/packages/victory-core/src/types/callbacks.ts index d1aba3206..aceb973d3 100644 --- a/packages/victory-core/src/types/callbacks.ts +++ b/packages/victory-core/src/types/callbacks.ts @@ -1,4 +1,4 @@ -import { D3Scale, Datum, ID } from "./prop-types"; +import { D3Scale, Datum, ID, ScalePropType } from "./prop-types"; import { BlockProps, OrientationTypes } from "../victory-theme/types"; /** @@ -16,10 +16,13 @@ export interface CallbackArgs { index?: ID; x?: number; y?: number; - scale?: { - x?: D3Scale; - y?: D3Scale; - }; + scale?: + | ScalePropType + | D3Scale + | { + x?: ScalePropType | D3Scale; + y?: ScalePropType | D3Scale; + }; tick?: any; ticks?: any; text?: any; diff --git a/packages/victory-core/src/victory-util/user-props.ts b/packages/victory-core/src/victory-util/user-props.ts index 2e86ca01a..4bb860c9e 100644 --- a/packages/victory-core/src/victory-util/user-props.ts +++ b/packages/victory-core/src/victory-util/user-props.ts @@ -55,6 +55,20 @@ const testIfSafeProp = (key: string): key is SafeAttribute => { return false; }; +/** + * Asserts that value is not null or undefined, throwing an error if it is. + * @param value The value to assert + * @param message The error message to throw + */ +export function assert( + value: T, + message?: string, +): asserts value is NonNullable { + if (value === undefined || value === null) { + throw new Error(message); + } +} + /** * getSafeUserProps - function that takes in a props object and removes any * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST diff --git a/packages/victory-tooltip/package.json b/packages/victory-tooltip/package.json index 55310c9e5..fb27de47d 100644 --- a/packages/victory-tooltip/package.json +++ b/packages/victory-tooltip/package.json @@ -24,6 +24,9 @@ "prop-types": "^15.8.1", "victory-core": "^36.8.2" }, + "devDependencies": { + "victory-tooltip": "*" + }, "peerDependencies": { "react": ">=16.6.0" }, diff --git a/packages/victory-tooltip/src/flyout.test.js b/packages/victory-tooltip/src/flyout.test.tsx similarity index 92% rename from packages/victory-tooltip/src/flyout.test.js rename to packages/victory-tooltip/src/flyout.test.tsx index a793efa5f..811d1a07f 100644 --- a/packages/victory-tooltip/src/flyout.test.js +++ b/packages/victory-tooltip/src/flyout.test.tsx @@ -1,6 +1,8 @@ import React from "react"; -import { Flyout } from "victory-tooltip"; import { render } from "@testing-library/react"; +import { Flyout } from "victory-tooltip"; + +import { SVGWrapper } from "../../../test/helpers"; describe("victory-primitives/flyout", () => { const baseProps = { @@ -17,7 +19,7 @@ describe("victory-primitives/flyout", () => { describe("rendering", () => { it("renders a flyout path", () => { const { container } = render(, { - wrapper: "svg", + wrapper: SVGWrapper, }); const path = container.querySelector("path"); diff --git a/packages/victory-tooltip/src/flyout.js b/packages/victory-tooltip/src/flyout.tsx similarity index 60% rename from packages/victory-tooltip/src/flyout.js rename to packages/victory-tooltip/src/flyout.tsx index d323439c8..bc1615307 100644 --- a/packages/victory-tooltip/src/flyout.js +++ b/packages/victory-tooltip/src/flyout.tsx @@ -1,17 +1,67 @@ -/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/ import React from "react"; -import PropTypes from "prop-types"; -import { Helpers, CommonProps, Path, UserProps } from "victory-core"; -import { isPlainObject, assign } from "lodash"; +import { + Helpers, + Path, + UserProps, + VictoryCommonProps, + OrientationTypes, + VictoryStyleObject, + StringOrNumberOrCallback, +} from "victory-core"; -const getVerticalPath = (props) => { +export interface FlyoutProps extends VictoryCommonProps { + active?: boolean; + center?: { + x: number; + y: number; + }; + className?: string; + clipPath?: string; + cornerRadius?: number; + data?: any[]; + datum?: object; + dx?: number; + dy?: number; + events?: object; + id?: StringOrNumberOrCallback; + index?: number; + orientation?: OrientationTypes; + pathComponent?: React.ReactElement; + pointerLength?: number; + pointerWidth?: number; + role?: string; + shapeRendering?: string; + style?: VictoryStyleObject; + transform?: string; + x?: number; + y?: number; +} + +interface FlyoutPathProps { + center: { + x: number; + y: number; + }; + cornerRadius: number; + dx?: number; + dy?: number; + height: number; + orientation: OrientationTypes; + pointerLength: number; + pointerWidth: number; + width: number; + x: number; + y: number; +} + +const getVerticalPath = (props: FlyoutPathProps) => { const { pointerWidth, cornerRadius, orientation, width, height, center } = props; const sign = orientation === "bottom" ? 1 : -1; const x = props.x + (props.dx || 0); const y = props.y + (props.dy || 0); - const centerX = isPlainObject(center) && center.x; - const centerY = isPlainObject(center) && center.y; + const centerX = center.x; + const centerY = center.y; const pointerEdge = centerY + sign * (height / 2); const oppositeEdge = centerY - sign * (height / 2); const rightEdge = centerX + width / 2; @@ -35,14 +85,14 @@ const getVerticalPath = (props) => { z`; }; -const getHorizontalPath = (props) => { +const getHorizontalPath = (props: FlyoutPathProps) => { const { pointerWidth, cornerRadius, orientation, width, height, center } = props; const sign = orientation === "left" ? 1 : -1; const x = props.x + (props.dx || 0); const y = props.y + (props.dy || 0); - const centerX = isPlainObject(center) && center.x; - const centerY = isPlainObject(center) && center.y; + const centerX = center.x; + const centerY = center.y; const pointerEdge = centerX - sign * (width / 2); const oppositeEdge = centerX + sign * (width / 2); const bottomEdge = centerY + height / 2; @@ -66,14 +116,14 @@ const getHorizontalPath = (props) => { z`; }; -const getFlyoutPath = (props) => { +const getFlyoutPath = (props: FlyoutPathProps) => { const orientation = props.orientation || "top"; return orientation === "left" || orientation === "right" ? getHorizontalPath(props) : getVerticalPath(props); }; -const evaluateProps = (props) => { +const evaluateProps = (props: FlyoutProps) => { /** * Potential evaluated props are: * `id` @@ -82,7 +132,7 @@ const evaluateProps = (props) => { const id = Helpers.evaluateProp(props.id, props); const style = Helpers.evaluateStyle(props.style, props); - return assign({}, props, { id, style }); + return { ...props, id, style }; }; const defaultProps = { @@ -91,15 +141,36 @@ const defaultProps = { shapeRendering: "auto", }; -const Flyout = (initialProps) => { +export const Flyout: React.FC = (initialProps) => { const props = evaluateProps({ ...defaultProps, ...initialProps }); const userProps = UserProps.getSafeUserProps(props); - return React.cloneElement(props.pathComponent, { + // check for required props for this subcomponent + // they should be passed in from the wrapper + UserProps.assert(props.height, "Flyout props[height] is undefined"); + UserProps.assert(props.width, "Flyout props[width] is undefined"); + UserProps.assert(props.x, "Flyout props[x] is undefined"); + UserProps.assert(props.y, "Flyout props[y] is undefined"); + + const flyoutPathProps: FlyoutPathProps = { + center: props.center || { x: 0, y: 0 }, + cornerRadius: props.cornerRadius || 0, + dx: props.dx, + dy: props.dy, + height: props.height, + orientation: props.orientation || "top", + pointerLength: props.pointerLength || 0, + pointerWidth: props.pointerWidth || 0, + width: props.width, + x: props.x, + y: props.y, + }; + + return React.cloneElement(props.pathComponent!, { ...props.events, ...userProps, style: props.style, - d: getFlyoutPath(props), + d: getFlyoutPath(flyoutPathProps), className: props.className, shapeRendering: props.shapeRendering, role: props.role, @@ -107,22 +178,3 @@ const Flyout = (initialProps) => { clipPath: props.clipPath, }); }; - -Flyout.propTypes = { - ...CommonProps.primitiveProps, - center: PropTypes.shape({ x: PropTypes.number, y: PropTypes.number }), - cornerRadius: PropTypes.number, - datum: PropTypes.object, - dx: PropTypes.number, - dy: PropTypes.number, - height: PropTypes.number, - orientation: PropTypes.oneOf(["top", "bottom", "left", "right"]), - pathComponent: PropTypes.element, - pointerLength: PropTypes.number, - pointerWidth: PropTypes.number, - width: PropTypes.number, - x: PropTypes.number, - y: PropTypes.number, -}; - -export default Flyout; diff --git a/packages/victory-tooltip/src/index.d.ts b/packages/victory-tooltip/src/index.d.ts deleted file mode 100644 index 56a92f1e6..000000000 --- a/packages/victory-tooltip/src/index.d.ts +++ /dev/null @@ -1,92 +0,0 @@ -import * as React from "react"; -import { - OrientationTypes, - NumberOrCallback, - StringOrNumberOrCallback, - VictoryCommonProps, - VictoryLabelableProps, - VictoryThemeDefinition, - VictoryStyleObject, - VictoryLabelStyleObject, - PaddingOrCallback, - EventPropTypeInterface, -} from "victory-core"; - -export interface VictoryTooltipProps extends VictoryLabelableProps { - active?: boolean; - activateData?: boolean; - activePoints?: any[]; - angle?: string | number; - center?: { x: number | undefined; y: number | undefined }; - centerOffset?: { - x?: NumberOrCallback; - y?: NumberOrCallback; - }; - constrainToVisibleArea?: boolean; - cornerRadius?: NumberOrCallback; - datum?: {}; - data?: any[]; - dx?: NumberOrCallback; - dy?: NumberOrCallback; - groupComponent?: React.ReactElement; - height?: number; - horizontal?: boolean; - events?: { [key: string]: (event: React.SyntheticEvent) => void }; - flyoutHeight?: NumberOrCallback; - flyoutWidth?: NumberOrCallback; - flyoutStyle?: VictoryStyleObject; - flyoutComponent?: React.ReactElement; - flyoutPadding?: PaddingOrCallback; - index?: number | string; - orientation?: OrientationTypes | ((...args: any[]) => OrientationTypes); - pointerLength?: NumberOrCallback; - pointerOrientation?: - | OrientationTypes - | ((...args: any[]) => OrientationTypes); - pointerWidth?: NumberOrCallback; - renderInPortal?: boolean; - style?: VictoryLabelStyleObject | VictoryLabelStyleObject[]; - text?: StringOrNumberOrCallback | string[] | number[]; - theme?: VictoryThemeDefinition; - width?: number; - x?: number; - y?: number; -} - -export interface FlyoutProps extends VictoryCommonProps { - active?: boolean; - center?: { - x?: number; - y?: number; - }; - className?: string; - cornerRadius?: number; - data?: any[]; - datum?: object; - dx?: number; - dy?: number; - events?: object; - height?: number; - id?: string | number; - index?: number; - orientation?: OrientationTypes; - pathComponent?: React.ReactElement; - pointerLength?: number; - pointerWidth?: number; - role?: string; - shapeRendering?: string; - style?: VictoryStyleObject; - transform?: string; - width?: number; - x?: number; - y?: number; -} - -export class Flyout extends React.Component {} - -export class VictoryTooltip extends React.Component { - static defaultEvents: EventPropTypeInterface< - string, - StringOrNumberOrCallback - >[]; -} diff --git a/packages/victory-tooltip/src/index.js b/packages/victory-tooltip/src/index.js deleted file mode 100644 index 3e290c3e2..000000000 --- a/packages/victory-tooltip/src/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as VictoryTooltip } from "./victory-tooltip"; -export { default as Flyout } from "./flyout"; diff --git a/packages/victory-tooltip/src/index.ts b/packages/victory-tooltip/src/index.ts new file mode 100644 index 000000000..c5e666721 --- /dev/null +++ b/packages/victory-tooltip/src/index.ts @@ -0,0 +1,2 @@ +export * from "./victory-tooltip"; +export * from "./flyout"; diff --git a/packages/victory-tooltip/src/victory-tooltip.test.js b/packages/victory-tooltip/src/victory-tooltip.test.tsx similarity index 98% rename from packages/victory-tooltip/src/victory-tooltip.test.js rename to packages/victory-tooltip/src/victory-tooltip.test.tsx index cb6c918d0..322a9e8a1 100644 --- a/packages/victory-tooltip/src/victory-tooltip.test.js +++ b/packages/victory-tooltip/src/victory-tooltip.test.tsx @@ -1,13 +1,12 @@ import React from "react"; -import { Flyout, VictoryTooltip } from "victory-tooltip"; -import { VictoryContainer, VictoryLabel } from "victory-core"; import { fireEvent, screen, render } from "@testing-library/react"; +import { VictoryContainer, VictoryLabel } from "victory-core"; +import { Flyout, VictoryTooltip } from "victory-tooltip"; describe("components/victory-tooltip", () => { const flyoutId = "flyout-1"; const labelId = "label-1"; - /** @type {VictoryTooltipProps} */ const baseProps = { x: 0, y: 0, diff --git a/packages/victory-tooltip/src/victory-tooltip.js b/packages/victory-tooltip/src/victory-tooltip.tsx similarity index 76% rename from packages/victory-tooltip/src/victory-tooltip.js rename to packages/victory-tooltip/src/victory-tooltip.tsx index 0335422b2..6038b1e99 100644 --- a/packages/victory-tooltip/src/victory-tooltip.js +++ b/packages/victory-tooltip/src/victory-tooltip.tsx @@ -1,109 +1,95 @@ +/* eslint-disable react/prop-types */ import React from "react"; -import PropTypes from "prop-types"; import { - PropTypes as CustomPropTypes, TextSize, Helpers, LabelHelpers, VictoryLabel, VictoryTheme, VictoryPortal, + VictoryLabelableProps, + VictoryLabelProps, + VictoryLabelStyleObject, + NumberOrCallback, + PaddingOrCallback, + VictoryStyleObject, + OrientationTypes, + VictoryThemeDefinition, } from "victory-core"; -import Flyout from "./flyout"; import { assign, defaults, uniqueId, isPlainObject, orderBy } from "lodash"; +import { Flyout } from "./flyout"; + const fallbackProps = { cornerRadius: 5, pointerLength: 10, pointerWidth: 10, }; -export default class VictoryTooltip extends React.Component { +export interface VictoryTooltipProps + extends VictoryLabelableProps, + VictoryLabelProps { + activateData?: boolean; + active?: boolean; + activePoints?: any[]; + angle?: number; + center?: { x?: number; y?: number }; + centerOffset?: { + x?: NumberOrCallback; + y?: NumberOrCallback; + }; + constrainToVisibleArea?: boolean; + cornerRadius?: NumberOrCallback; + events?: any; + height?: number; + horizontal?: boolean; + flyoutComponent?: React.ReactElement; + flyoutHeight?: NumberOrCallback; + flyoutPadding?: PaddingOrCallback; + flyoutStyle?: VictoryStyleObject; + flyoutWidth?: NumberOrCallback; + id?: number | string; + index?: number | string; + orientation?: OrientationTypes | ((...args: any[]) => OrientationTypes); + pointerLength?: NumberOrCallback; + pointerOrientation?: + | OrientationTypes + | ((...args: any[]) => OrientationTypes); + pointerWidth?: NumberOrCallback; + style?: + | (VictoryLabelStyleObject & { + angle?: number; + }) + | VictoryLabelStyleObject[]; + theme?: VictoryThemeDefinition; + width?: number; +} + +type InternalEvaluatedProps = VictoryTooltipProps & { + centerOffset: { x: number; y: number }; + cornerRadius?: number; + dx?: string | number; + dy?: string | number; + flyoutHeight: number; + flyoutPadding: { + top: number; + bottom: number; + left: number; + right: number; + }; + flyoutWidth: number; + orientation: OrientationTypes; + pointerLength?: number; + pointerWidth?: number; + // TODO: This is a hack to get around the fact that the type of + // style is used in akward ways in the functions + style: any; + text: string | string[]; +}; + +export class VictoryTooltip extends React.Component { static displayName = "VictoryTooltip"; static role = "tooltip"; - static propTypes = { - activateData: PropTypes.bool, - active: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]), - activePoints: PropTypes.array, - angle: PropTypes.number, - center: PropTypes.shape({ - x: CustomPropTypes.nonNegative, - y: CustomPropTypes.nonNegative, - }), - centerOffset: PropTypes.shape({ - x: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - y: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - }), - constrainToVisibleArea: PropTypes.bool, - cornerRadius: PropTypes.oneOfType([ - CustomPropTypes.nonNegative, - PropTypes.func, - ]), - data: PropTypes.array, - datum: PropTypes.object, - dx: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - dy: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), - events: PropTypes.object, - flyoutComponent: PropTypes.element, - flyoutHeight: PropTypes.oneOfType([ - CustomPropTypes.nonNegative, - PropTypes.func, - ]), - flyoutPadding: PropTypes.oneOfType([ - PropTypes.func, - PropTypes.number, - PropTypes.shape({ - top: PropTypes.number, - bottom: PropTypes.number, - left: PropTypes.number, - right: PropTypes.number, - }), - ]), - flyoutStyle: PropTypes.object, - flyoutWidth: PropTypes.oneOfType([ - CustomPropTypes.nonNegative, - PropTypes.func, - ]), - groupComponent: PropTypes.element, - height: PropTypes.number, - horizontal: PropTypes.bool, - id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - index: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - labelComponent: PropTypes.element, - orientation: PropTypes.oneOfType([ - PropTypes.oneOf(["top", "bottom", "left", "right"]), - PropTypes.func, - ]), - pointerLength: PropTypes.oneOfType([ - CustomPropTypes.nonNegative, - PropTypes.func, - ]), - pointerOrientation: PropTypes.oneOfType([ - PropTypes.oneOf(["top", "bottom", "left", "right"]), - PropTypes.func, - ]), - pointerWidth: PropTypes.oneOfType([ - CustomPropTypes.nonNegative, - PropTypes.func, - ]), - polar: PropTypes.bool, - renderInPortal: PropTypes.bool, - scale: PropTypes.shape({ - x: CustomPropTypes.scale, - y: CustomPropTypes.scale, - }), - style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), - text: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.number, - PropTypes.func, - PropTypes.array, - ]), - theme: PropTypes.object, - width: PropTypes.number, - x: PropTypes.number, - y: PropTypes.number, - }; static defaultProps = { active: false, @@ -113,7 +99,7 @@ export default class VictoryTooltip extends React.Component { groupComponent: , }; - static defaultEvents = (props) => { + static defaultEvents = (props: VictoryTooltipProps) => { const activate = props.activateData ? [ { target: "labels", mutation: () => ({ active: true }) }, @@ -141,25 +127,27 @@ export default class VictoryTooltip extends React.Component { ]; }; - constructor(props) { + id: string | number; + + constructor(props: VictoryTooltipProps) { super(props); this.id = props.id === undefined ? uniqueId("tooltip-") : props.id; } - getDefaultOrientation(props) { + getDefaultOrientation(props: VictoryTooltipProps): OrientationTypes { const { datum, horizontal, polar } = props; if (!polar) { const positive = horizontal ? "right" : "top"; const negative = horizontal ? "left" : "bottom"; return datum && datum.y < 0 ? negative : positive; } - return this.getPolarOrientation(props, datum); + return this.getPolarOrientation(props); } - getPolarOrientation(props, datum) { - const degrees = LabelHelpers.getDegrees(props, datum); + getPolarOrientation(props: VictoryTooltipProps): OrientationTypes { + const degrees = LabelHelpers.getDegrees(props, props.datum); const placement = props.labelPlacement || "vertical"; - if (placement === " vertical") { + if (placement === "vertical") { return this.getVerticalOrientations(degrees); } else if (placement === "parallel") { return degrees < 90 || degrees > 270 ? "right" : "left"; @@ -167,7 +155,7 @@ export default class VictoryTooltip extends React.Component { return degrees > 180 ? "bottom" : "top"; } - getVerticalOrientations(degrees) { + getVerticalOrientations(degrees: number): OrientationTypes { // eslint-disable-next-line no-magic-numbers if (degrees < 45 || degrees > 315) { return "right"; @@ -205,14 +193,19 @@ export default class VictoryTooltip extends React.Component { return { style, flyoutStyle }; } - getEvaluatedProps(props) { + getEvaluatedProps(props: VictoryTooltipProps): InternalEvaluatedProps { const { cornerRadius, centerOffset, dx, dy } = props; const active = Helpers.evaluateProp(props.active, props); - const text = Helpers.evaluateProp( - props.text, - assign({}, props, { active }), - ); + + let text = Helpers.evaluateProp(props.text, assign({}, props, { active })); + if (text === undefined || text === null) { + text = ""; + } + if (typeof text === "number") { + text = text.toString(); + } + const { style, flyoutStyle } = this.getStyles( assign({}, props, { active, text }), ); @@ -269,24 +262,32 @@ export default class VictoryTooltip extends React.Component { }); const offsetX = - isPlainObject(centerOffset) && centerOffset.x !== undefined + isPlainObject(centerOffset) && centerOffset?.x !== undefined ? Helpers.evaluateProp(centerOffset.x, evaluatedProps) : 0; const offsetY = - isPlainObject(centerOffset) && centerOffset.y !== undefined + isPlainObject(centerOffset) && centerOffset?.y !== undefined ? Helpers.evaluateProp(centerOffset.y, evaluatedProps) : 0; - return assign({}, evaluatedProps, { + return { + ...evaluatedProps, centerOffset: { x: offsetX, y: offsetY }, dx: dx !== undefined ? Helpers.evaluateProp(dx, evaluatedProps) : 0, dy: dy !== undefined ? Helpers.evaluateProp(dy, evaluatedProps) : 0, cornerRadius: Helpers.evaluateProp(cornerRadius, evaluatedProps), - }); + }; } - getCalculatedValues(props) { + getCalculatedValues(props: InternalEvaluatedProps): { + style: any; + flyoutStyle?: VictoryStyleObject; + labelSize: { width: number; height: number }; + flyoutDimensions: { height: number; width: number }; + flyoutCenter: { x: number; y: number }; + transform?: string; + } { const { style, text, flyoutStyle, flyoutHeight, flyoutWidth } = props; const labelSize = TextSize.approximateTextSize(text, style); const flyoutDimensions = { height: flyoutHeight, width: flyoutWidth }; @@ -302,7 +303,7 @@ export default class VictoryTooltip extends React.Component { }; } - getTransform(props) { + getTransform(props): string | undefined { const { x, y, style } = props; const labelStyle = style || {}; const angle = @@ -310,8 +311,7 @@ export default class VictoryTooltip extends React.Component { return angle ? `rotate(${angle} ${x} ${y})` : undefined; } - // eslint-disable-next-line complexity - getDefaultAngle(props) { + getDefaultAngle(props): number { const { polar, labelPlacement, orientation, datum } = props; if (!polar || !labelPlacement || labelPlacement === "vertical") { return 0; @@ -319,7 +319,8 @@ export default class VictoryTooltip extends React.Component { const degrees = LabelHelpers.getDegrees(props, datum); const sign = (degrees > 90 && degrees < 180) || degrees > 270 ? 1 : -1; const labelRotation = labelPlacement === "perpendicular" ? 0 : 90; - let angle; + + let angle = 0; if (degrees === 0 || degrees === 180) { angle = orientation === "top" && degrees === 180 ? 270 : 90; } else if (degrees > 0 && degrees < 180) { @@ -424,6 +425,7 @@ export default class VictoryTooltip extends React.Component { flyoutPadding, } = props; const cornerRadius = Helpers.evaluateProp(props.cornerRadius, props); + const getHeight = () => { const calculatedHeight = labelSize.height + flyoutPadding.top + flyoutPadding.bottom; @@ -434,6 +436,7 @@ export default class VictoryTooltip extends React.Component { : 2 * cornerRadius + pointerWidth; return Math.max(minHeight, calculatedHeight); }; + const getWidth = () => { const calculatedWidth = labelSize.width + flyoutPadding.left + flyoutPadding.right; @@ -444,17 +447,18 @@ export default class VictoryTooltip extends React.Component { : 2 * cornerRadius; return Math.max(minWidth, calculatedWidth); }; + return { flyoutHeight: flyoutHeight ? Helpers.evaluateProp(flyoutHeight, props) - : getHeight(props, labelSize, orientation), + : getHeight(), flyoutWidth: flyoutWidth ? Helpers.evaluateProp(flyoutWidth, props) - : getWidth(props, labelSize, orientation), + : getWidth(), }; } - getLabelProps(props, calculatedValues) { + getLabelProps(props: InternalEvaluatedProps, calculatedValues) { const { flyoutCenter, style, labelSize, dy = 0, dx = 0 } = calculatedValues; const { text, datum, activePoints, labelComponent, index, flyoutPadding } = props; @@ -469,7 +473,7 @@ export default class VictoryTooltip extends React.Component { const sign = textAnchor === "end" ? -1 : 1; return flyoutCenter.x - sign * (labelSize.width / 2); }; - return defaults({}, labelComponent.props, { + return defaults({}, labelComponent!.props, { key: `${this.id}-label-${index}`, text, datum, @@ -485,7 +489,11 @@ export default class VictoryTooltip extends React.Component { }); } - getPointerOrientation(point, center, flyoutDimensions) { + getPointerOrientation( + point: { x: number; y: number }, + center: { x: number; y: number }, + flyoutDimensions: { height: number; width: number }, + ): string { const edges = { bottom: center.y + flyoutDimensions.height / 2, top: center.y - flyoutDimensions.height / 2, @@ -509,7 +517,7 @@ export default class VictoryTooltip extends React.Component { return orderBy(gaps, "val", "desc")[0].side; } - getFlyoutProps(props, calculatedValues) { + getFlyoutProps(props: InternalEvaluatedProps, calculatedValues) { const { flyoutDimensions, flyoutStyle, flyoutCenter } = calculatedValues; const { x, @@ -529,7 +537,7 @@ export default class VictoryTooltip extends React.Component { props.pointerOrientation, props, ); - return defaults({}, flyoutComponent.props, { + return defaults({}, flyoutComponent!.props, { x, y, dx, @@ -543,7 +551,11 @@ export default class VictoryTooltip extends React.Component { events, orientation: pointerOrientation || - this.getPointerOrientation({ x, y }, flyoutCenter, flyoutDimensions), + this.getPointerOrientation( + { x: x!, y: y! }, + flyoutCenter, + flyoutDimensions, + ), key: `${this.id}-tooltip-${index}`, width: flyoutDimensions.width, height: flyoutDimensions.height, @@ -553,34 +565,34 @@ export default class VictoryTooltip extends React.Component { } // Overridden in victory-core-native - renderTooltip(props) { + renderTooltip(props: VictoryTooltipProps): React.ReactElement | null { const active = Helpers.evaluateProp(props.active, props); const { renderInPortal } = props; if (!active) { - return renderInPortal ? {null} : null; + return renderInPortal ? : null; } const evaluatedProps = this.getEvaluatedProps(props); const { flyoutComponent, labelComponent, groupComponent } = evaluatedProps; const calculatedValues = this.getCalculatedValues(evaluatedProps); const children = [ React.cloneElement( - flyoutComponent, + flyoutComponent!, this.getFlyoutProps(evaluatedProps, calculatedValues), ), React.cloneElement( - labelComponent, + labelComponent!, this.getLabelProps(evaluatedProps, calculatedValues), ), ]; const tooltip = React.cloneElement( - groupComponent, + groupComponent!, { role: "presentation", transform: calculatedValues.transform }, children, ); return renderInPortal ? {tooltip} : tooltip; } - render() { + render(): React.ReactElement | null { const props = Helpers.modifyProps(this.props, fallbackProps, "tooltip"); return this.renderTooltip(props); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fcde3ca40..6e7b10054 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -693,10 +693,13 @@ importers: lodash: ^4.17.19 prop-types: ^15.8.1 victory-core: ^36.8.2 + victory-tooltip: '*' dependencies: lodash: 4.17.21 prop-types: 15.8.1 victory-core: link:../victory-core + devDependencies: + victory-tooltip: 'link:' packages/victory-vendor: specifiers: From 1da45d319d924cf6995797a2b033da48da3cf4bc Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Fri, 19 Jan 2024 16:44:32 +0000 Subject: [PATCH 26/29] Migrate victory-voronoi-container to TypeScript (#2727) --- .changeset/olive-bananas-stare.md | 5 ++ .../victory-voronoi-container/src/index.d.ts | 44 ------------ .../victory-voronoi-container/src/index.js | 5 -- .../victory-voronoi-container/src/index.ts | 2 + ...ainer.js => victory-voronoi-container.tsx} | 70 +++++++++---------- ...{voronoi-helpers.js => voronoi-helpers.ts} | 54 +++++++------- 6 files changed, 67 insertions(+), 113 deletions(-) create mode 100644 .changeset/olive-bananas-stare.md delete mode 100644 packages/victory-voronoi-container/src/index.d.ts delete mode 100644 packages/victory-voronoi-container/src/index.js create mode 100644 packages/victory-voronoi-container/src/index.ts rename packages/victory-voronoi-container/src/{victory-voronoi-container.js => victory-voronoi-container.tsx} (82%) rename packages/victory-voronoi-container/src/{voronoi-helpers.js => voronoi-helpers.ts} (93%) diff --git a/.changeset/olive-bananas-stare.md b/.changeset/olive-bananas-stare.md new file mode 100644 index 000000000..e1494608f --- /dev/null +++ b/.changeset/olive-bananas-stare.md @@ -0,0 +1,5 @@ +--- +"victory-voronoi-container": patch +--- + +Migrate victory-voronoi-container to TypeScript diff --git a/packages/victory-voronoi-container/src/index.d.ts b/packages/victory-voronoi-container/src/index.d.ts deleted file mode 100644 index 341c1826a..000000000 --- a/packages/victory-voronoi-container/src/index.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as React from "react"; -import { PaddingProps, VictoryContainerProps } from "victory-core"; - -export interface VictoryVoronoiContainerProps extends VictoryContainerProps { - activateData?: boolean; - activateLabels?: boolean; - disable?: boolean; - labels?: (point: any, index: number, points: any[]) => string; - labelComponent?: React.ReactElement; - mouseFollowTooltips?: boolean; - onActivated?: (points: any[], props: VictoryVoronoiContainerProps) => void; - onDeactivated?: (points: any[], props: VictoryVoronoiContainerProps) => void; - radius?: number; - voronoiBlacklist?: (string | RegExp)[]; - voronoiDimension?: "x" | "y"; - voronoiPadding?: PaddingProps; -} - -export class VictoryVoronoiContainer extends React.Component< - VictoryVoronoiContainerProps, - any -> {} - -export const VoronoiHelpers: { - withinBounds(props: any, point: any): any; - getDatasets(props: any): any; - findPoints(datasets: any, point: any): any; - withinRadius(point: any, mousePosition: any, radius: any): any; - getVoronoiPoints(props: any, mousePosition: any): any; - getActiveMutations(props: any, point: any): any; - getInactiveMutations(props: any, point: any): any; - getParentMutation( - activePoints: any, - mousePosition: any, - parentSVG: any, - vIndex: any, - ): any; - onActivated(props: any, points: any): any; - onDeactivated(props: any, points: any): any; - onMouseLeave(evt: any, targetProps: any): any; - onMouseMove(evt: any, targetProps: any): any; -}; - -export const voronoiContainerMixin: (base: Function) => Function; diff --git a/packages/victory-voronoi-container/src/index.js b/packages/victory-voronoi-container/src/index.js deleted file mode 100644 index bde28af9b..000000000 --- a/packages/victory-voronoi-container/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { - voronoiContainerMixin, - default as VictoryVoronoiContainer, -} from "./victory-voronoi-container"; -export { default as VoronoiHelpers } from "./voronoi-helpers"; diff --git a/packages/victory-voronoi-container/src/index.ts b/packages/victory-voronoi-container/src/index.ts new file mode 100644 index 000000000..313e652a9 --- /dev/null +++ b/packages/victory-voronoi-container/src/index.ts @@ -0,0 +1,2 @@ +export * from "./victory-voronoi-container"; +export * from "./voronoi-helpers"; diff --git a/packages/victory-voronoi-container/src/victory-voronoi-container.js b/packages/victory-voronoi-container/src/victory-voronoi-container.tsx similarity index 82% rename from packages/victory-voronoi-container/src/victory-voronoi-container.js rename to packages/victory-voronoi-container/src/victory-voronoi-container.tsx index 8bdc3e5ae..f2ed14ad3 100644 --- a/packages/victory-voronoi-container/src/victory-voronoi-container.js +++ b/packages/victory-voronoi-container/src/victory-voronoi-container.tsx @@ -1,44 +1,41 @@ /* eslint-disable react/no-multi-comp */ -import PropTypes from "prop-types"; import React from "react"; import { defaults, isFunction, pick } from "lodash"; import { VictoryTooltip } from "victory-tooltip"; import { VictoryContainer, Helpers, - PropTypes as CustomPropTypes, + VictoryContainerProps, + PaddingProps, } from "victory-core"; -import VoronoiHelpers from "./voronoi-helpers"; +import { VoronoiHelpers } from "./voronoi-helpers"; -export const voronoiContainerMixin = (base) => - class VictoryVoronoiContainer extends base { +type ComponentClass = { new (props: TProps): React.Component }; + +export interface VictoryVoronoiContainerProps extends VictoryContainerProps { + activateData?: boolean; + activateLabels?: boolean; + disable?: boolean; + labels?: (point: any, index: number, points: any[]) => string; + labelComponent?: React.ReactElement; + mouseFollowTooltips?: boolean; + onActivated?: (points: any[], props: VictoryVoronoiContainerProps) => void; + onDeactivated?: (points: any[], props: VictoryVoronoiContainerProps) => void; + radius?: number; + voronoiBlacklist?: (string | RegExp)[]; + voronoiDimension?: "x" | "y"; + voronoiPadding?: PaddingProps; +} + +export function voronoiContainerMixin< + TBase extends ComponentClass, + TProps extends VictoryVoronoiContainerProps, +>(Base: TBase) { + // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." + return class VictoryVoronoiContainer extends Base { static displayName = "VictoryVoronoiContainer"; - static propTypes = { - ...VictoryContainer.propTypes, - activateData: PropTypes.bool, - activateLabels: PropTypes.bool, - disable: PropTypes.bool, - labelComponent: PropTypes.element, - labels: PropTypes.func, - mouseFollowTooltips: PropTypes.bool, - onActivated: PropTypes.func, - onDeactivated: PropTypes.func, - radius: PropTypes.number, - voronoiBlacklist: PropTypes.arrayOf( - PropTypes.oneOfType([PropTypes.string, CustomPropTypes.regExp]), - ), - voronoiDimension: PropTypes.oneOf(["x", "y"]), - voronoiPadding: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - top: PropTypes.number, - bottom: PropTypes.number, - left: PropTypes.number, - right: PropTypes.number, - }), - ]), - }; - static defaultProps = { + + static defaultProps: VictoryVoronoiContainerProps = { ...VictoryContainer.defaultProps, activateData: true, activateLabels: true, @@ -46,7 +43,7 @@ export const voronoiContainerMixin = (base) => voronoiPadding: 5, }; - static defaultEvents = (props) => { + static defaultEvents = (props: VictoryVoronoiContainerProps) => { return [ { target: "parent", @@ -233,15 +230,14 @@ export const voronoiContainerMixin = (base) => } // Overrides method in VictoryContainer - getChildren(props) { + getChildren(props: VictoryVoronoiContainerProps) { return [ ...React.Children.toArray(props.children), this.getTooltip(props), ]; } }; +} -export default voronoiContainerMixin(VictoryContainer); -// @ts-expect-error IMPORTANT: when converting this file to TypeScript, you must export the type as well: -// export const VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer); -// export type VictoryVoronoiContainer = typeof VictoryVoronoiContainer; +export const VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer); +export type VictoryVoronoiContainer = typeof VictoryVoronoiContainer; diff --git a/packages/victory-voronoi-container/src/voronoi-helpers.js b/packages/victory-voronoi-container/src/voronoi-helpers.ts similarity index 93% rename from packages/victory-voronoi-container/src/voronoi-helpers.js rename to packages/victory-voronoi-container/src/voronoi-helpers.ts index 6f15bd373..25364f544 100644 --- a/packages/victory-voronoi-container/src/voronoi-helpers.js +++ b/packages/victory-voronoi-container/src/voronoi-helpers.ts @@ -1,18 +1,20 @@ import { Collection, Selection, Data, Helpers } from "victory-core"; import { assign, - throttle, isFunction, isEmpty, includes, isString, isRegExp, + throttle, } from "lodash"; import isEqual from "react-fast-compare"; import Delaunay from "delaunay-find/lib/index.js"; import React from "react"; -const VoronoiHelpers = { +const ON_MOUSE_MOVE_THROTTLE_MS = 32; + +class VoronoiHelpersClass { withinBounds(props, point) { const { width, height, polar, origin, scale } = props; const padding = Helpers.getPadding(props, "voronoiPadding"); @@ -29,7 +31,7 @@ const VoronoiHelpers = { y >= padding.top && y <= height - padding.bottom ); - }, + } getDatasets(props) { const minDomain = { @@ -37,7 +39,7 @@ const VoronoiHelpers = { y: Collection.getMinValue(props.domain.y), }; const children = React.Children.toArray(props.children); - const addMeta = (data, name, child) => { + const addMeta = (data, name?, child?) => { const continuous = child && child.type && child.type.continuous; const style = child ? child.props && child.props.style : props.style; return data.map((datum, index) => { @@ -91,13 +93,13 @@ const VoronoiHelpers = { }; return Helpers.reduceChildren(children, iteratee, props); - }, + } findPoints(datasets, point) { return datasets.filter((d) => { return point._voronoiX === d._voronoiX && point._voronoiY === d._voronoiY; }); - }, + } withinRadius(point, mousePosition, radius) { if (!point) { @@ -110,7 +112,7 @@ const VoronoiHelpers = { const distanceSquared = Math.pow(x - point[0], 2) + Math.pow(y - point[1], 2); return distanceSquared < Math.pow(radius, 2); - }, + } getVoronoiPoints(props, mousePosition) { const datasets = this.getDatasets(props); @@ -129,7 +131,7 @@ const VoronoiHelpers = { ? this.findPoints(datasets, datasets[index]) : []; return { points, index }; - }, + } getActiveMutations(props, point) { const { childName, continuous } = point; @@ -155,7 +157,7 @@ const VoronoiHelpers = { mutation: () => ({ active: true }), }; }); - }, + } getInactiveMutations(props, point) { const { childName, continuous } = point; @@ -180,10 +182,10 @@ const VoronoiHelpers = { mutation: () => null, }; }); - }, + } // eslint-disable-next-line max-params - getParentMutation(activePoints, mousePosition, parentSVG, vIndex) { + getParentMutation(activePoints, mousePosition?, parentSVG?, vIndex?) { return [ { target: "parent", @@ -191,21 +193,21 @@ const VoronoiHelpers = { mutation: () => ({ activePoints, mousePosition, parentSVG, vIndex }), }, ]; - }, + } onActivated(props, points) { if (isFunction(props.onActivated)) { props.onActivated(points, props); } - }, + } onDeactivated(props, points) { if (isFunction(props.onDeactivated)) { props.onDeactivated(points, props); } - }, + } - onMouseLeave(evt, targetProps) { + onMouseLeave = (evt, targetProps) => { const activePoints = targetProps.activePoints || []; this.onDeactivated(targetProps, activePoints); const inactiveMutations = activePoints.length @@ -214,9 +216,9 @@ const VoronoiHelpers = { ) : []; return this.getParentMutation([]).concat(...inactiveMutations); - }, + }; - onMouseMove(evt, targetProps) { + private handleMouseMove = (evt, targetProps) => { // eslint-disable-line max-statements const activePoints = targetProps.activePoints || []; const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); @@ -256,14 +258,12 @@ const VoronoiHelpers = { ) : []; return parentMutations.concat(...inactiveMutations, ...activeMutations); - }, -}; + }; + + onMouseMove = throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, { + leading: true, + trailing: false, + }); +} -export default { - onMouseLeave: VoronoiHelpers.onMouseLeave.bind(VoronoiHelpers), - onMouseMove: throttle( - VoronoiHelpers.onMouseMove.bind(VoronoiHelpers), - 32, // eslint-disable-line no-magic-numbers - { leading: true, trailing: false }, - ), -}; +export const VoronoiHelpers = new VoronoiHelpersClass(); From 0d848e6f87649f2009f1871d171f5c5a5cde6b1c Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Fri, 19 Jan 2024 11:08:52 -0600 Subject: [PATCH 27/29] Update site with latest version and nearform links (#2728) --- docs/README.md | 58 +---- docs/package.json | 2 +- docs/yarn.lock | 524 ++++++++++++++++++++++++++-------------------- 3 files changed, 300 insertions(+), 284 deletions(-) diff --git a/docs/README.md b/docs/README.md index 9560dd083..295b0ac63 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@

Victory Documentation Site

-[Documentation site](https://formidable.com/open-source/victory/) for [victory](https://github.com/FormidableLabs/victory) built with [react-static](https://github.com/nozzle/react-static), and deployed with [formideploy](https://github.com/FormidableLabs/formideploy) +[Documentation site](https://formidable.com/open-source/victory/) for [victory](https://github.com/FormidableLabs/victory) built with [react-static](https://github.com/nozzle/react-static). ## Getting Started @@ -25,62 +25,14 @@ Once it builds successfully, serve it: ```bash yarn serve ``` -The staging and production sites are served from a nested path, e.g. `https://formidable.com/open-source/victory`. This step is important for validating that both the `basePath` used by the static HTML output and the `basename` used by the client-side router are working as expected. +The staging and production sites are served from a nested path, e.g. `https://commerce.nearform.com/open-source/victory`. This step is important for validating that both the `basePath` used by the static HTML output and the `basename` used by the client-side router are working as expected. ## Deployment -### Staging - -_Only for project administrators._ - -Our CI deploys to staging for each PR using surge.sh at the following URL: - -`https://formidable-com-victory-staging-${PR_NUMBER}.surge.sh/open-source/victory` - -To test things out locally find the `Surge.sh` entry in 1password in the IC vault and make up some pretend values for a PR number in `FORMIDEPLOY_PULL_REQUEST`: - -```sh -$ cd docs -$ yarn clean && \ - yarn build -$ SURGE_LOGIN= \ - SURGE_TOKEN= \ - FORMIDEPLOY_PULL_REQUEST=12 \ - yarn deploy:stage -``` - ### Production -_Only for project administrators._ - -Our CI is configured to deploy the production build in `dist` to `formidable.com/open-source/victory`. This will happen automatically when a branch with docs changes that was opened by an internal collaborator is merged into the `main` branch of this repo. This section discusses kicking the tires locally: - -First, install the AWS CLI: - -```sh -$ brew install awscli -``` - -Then, set up `aws-vault` with the AWS access and secret keys for "CI" in the `AWS IAM (victory-ci)` entry in the IC vault: - -```sh -$ brew cask install aws-vault -$ aws-vault add fmd-victory-ci -# Enter AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY values. -``` - -_note_ if these keys do not already exist in the IC vault, they will need to be created. Please reach out to a member of the cloud team for help. - -Then build for production and deploy with dry run to check things: - -```sh -$ cd docs -$ yarn clean && \ - yarn build -$ aws-vault exec fmd-victory-ci --no-session -- \ - yarn deploy:prod --dryrun -``` +This site is deployed with Vercel infrastructure and is automated with a repository trigger in the Formidable Labs Vercel account. -### Notes +The site is directly accessible at [https://victory-rose.vercel.app/open-source/victory](https://victory-rose.vercel.app/open-source/victory). -Docs PRs that originate from forks will not trigger staging or production builds of the docs site. To trigger a docs update based on a forked PR, someone with write access to the repo should open a new PR based on the changes and close the original with a reference. [Here's a handy git alias for creating a new branch based on a pr](https://gist.github.com/gvaughn/f3c7897a51e52138eac1) +The `commerce.nearform.com` site uses a rewrite to host it under the path [https://commerce.nearform.com/open-source/victory/](https://commerce.nearform.com/open-source/victory/). diff --git a/docs/package.json b/docs/package.json index 9858ff449..3fa12effe 100644 --- a/docs/package.json +++ b/docs/package.json @@ -50,7 +50,7 @@ "styled-components": "^5.1.0", "styled-normalize": "^8.0.6", "unist-util-visit": "^1.4.0", - "victory": "^36.4.0" + "victory": "^36.8.2" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/docs/yarn.lock b/docs/yarn.lock index 396bb6d4c..e8ef4ac29 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -880,6 +880,57 @@ version "1.1.1" resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" +"@types/d3-array@^3.0.3": + version "3.2.1" + resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.2.1.tgz#1f6658e3d2006c4fceac53fde464166859f8b8c5" + integrity sha512-Y2Jn2idRrLzUfAKV2LyRImR+y4oa2AntrgID95SHJxuMUrkNXmanDSed71sRNZysveJVt1hLLemQZIady0FpEg== + +"@types/d3-color@*": + version "3.1.3" + resolved "https://registry.yarnpkg.com/@types/d3-color/-/d3-color-3.1.3.tgz#368c961a18de721da8200e80bf3943fb53136af2" + integrity sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A== + +"@types/d3-ease@^3.0.0": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@types/d3-ease/-/d3-ease-3.0.2.tgz#e28db1bfbfa617076f7770dd1d9a48eaa3b6c51b" + integrity sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA== + +"@types/d3-interpolate@^3.0.1": + version "3.0.4" + resolved "https://registry.yarnpkg.com/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz#412b90e84870285f2ff8a846c6eb60344f12a41c" + integrity sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA== + dependencies: + "@types/d3-color" "*" + +"@types/d3-path@*": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@types/d3-path/-/d3-path-3.0.2.tgz#4327f4a05d475cf9be46a93fc2e0f8d23380805a" + integrity sha512-WAIEVlOCdd/NKRYTsqCpOMHQHemKBEINf8YXMYOtXH0GA7SY0dqMB78P3Uhgfy+4X+/Mlw2wDtlETkN6kQUCMA== + +"@types/d3-scale@^4.0.2": + version "4.0.8" + resolved "https://registry.yarnpkg.com/@types/d3-scale/-/d3-scale-4.0.8.tgz#d409b5f9dcf63074464bf8ddfb8ee5a1f95945bb" + integrity sha512-gkK1VVTr5iNiYJ7vWDI+yUFFlszhNMtVeneJ6lUTKPjprsvLLI9/tgEGiXJOnlINJA8FyA88gfnQsHbybVZrYQ== + dependencies: + "@types/d3-time" "*" + +"@types/d3-shape@^3.1.0": + version "3.1.6" + resolved "https://registry.yarnpkg.com/@types/d3-shape/-/d3-shape-3.1.6.tgz#65d40d5a548f0a023821773e39012805e6e31a72" + integrity sha512-5KKk5aKGu2I+O6SONMYSNflgiP0WfZIQvVUMan50wHsLG1G94JlxEVnCpQARfTtzytuY0p/9PXXZb3I7giofIA== + dependencies: + "@types/d3-path" "*" + +"@types/d3-time@*", "@types/d3-time@^3.0.0": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@types/d3-time/-/d3-time-3.0.3.tgz#3c186bbd9d12b9d84253b6be6487ca56b54f88be" + integrity sha512-2p6olUZ4w3s+07q3Tm2dbiMZy5pCDfYwtLXXHUnVzXgQlZ/OyPtUz6OL382BkOuGlLXqfT+wqv8Fw2v8/0geBw== + +"@types/d3-timer@^3.0.0": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@types/d3-timer/-/d3-timer-3.0.2.tgz#70bbda77dc23aa727413e22e214afa3f0e852f70" + integrity sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw== + "@types/glob@^7.1.1": version "7.1.2" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.2.tgz#06ca26521353a545d94a0adc74f38a59d232c987" @@ -6333,10 +6384,15 @@ react-dom@^16.8.0, react-dom@^16.9.0: prop-types "^15.6.2" scheduler "^0.19.1" -react-fast-compare@^2.0.0, react-fast-compare@^2.0.2: +react-fast-compare@^2.0.2: version "2.0.4" resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9" +react-fast-compare@^3.2.0: + version "3.2.2" + resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49" + integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ== + react-ga@^2.4.1: version "2.7.0" resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.7.0.tgz#24328f157f31e8cffbf4de74a3396536679d8d7c" @@ -8078,252 +8134,260 @@ vfile@^2.0.0: unist-util-stringify-position "^1.0.0" vfile-message "^1.0.0" -victory-area@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-area/-/victory-area-36.4.0.tgz#6e034d9b0e28bfa55b35dcac79f8c90ef53abcaa" - integrity sha512-eLjWqIV5bKIhQuXAMWLRTbjwOTxYllsfzVZyHVBT26MJ8iQzDQjcebi2uM7KHnzGY/6uOcDBzZAwAV/+eQ+pBg== +victory-area@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-area/-/victory-area-36.8.2.tgz#faebe606252fb7f78b1f149031e044ec48e05536" + integrity sha512-LBx4x+j1TgDT0cCb9WM1K4CsmPbYCbsCxMXrlf0QY0MlaQxj7t6xkbB0HknnKm7EHsaiy1rYn3BCizj4pqm0YA== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" + victory-vendor "^36.8.2" -victory-axis@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-axis/-/victory-axis-36.4.0.tgz#9c0766ae552fb724d7b862c5efc65e8bb1cb5ebf" - integrity sha512-eKZJTUwcjBzsEkvmu8nptNioUb9XFfi8mcYzCk5S8WZk/ATz/YkuPw68qEL1+5Qwuk7m6d/qP9Oa1jEYEX1T2g== +victory-axis@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-axis/-/victory-axis-36.8.2.tgz#885bdbe7ef8462f1351211cf858d24def088bd80" + integrity sha512-uG14Jpx0o6BGjpCR9uxgDFkc0bV1b2vgCfPakCP2ZF0wGUtMScBQIkioG4M2KU8O2/k6LMluJIYzpC3WP5UXHQ== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-bar@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-bar/-/victory-bar-36.4.0.tgz#a4fc7c21eb5bd0f111bb19b36473fed08e748657" - integrity sha512-8eiKgXBTRkuNVw/NHl8storTGNFRVG5/RC2ceOR8G44HTYHdkG9Y7DwVxn6gNe7uZKOVKVIsEi5kJwNyE8w1eg== +victory-bar@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-bar/-/victory-bar-36.8.2.tgz#336e27013e6cfa41e4644dd7838f7502b36352c3" + integrity sha512-rjdZXVjiaYYjXukMR5GwiioBZKqMfCEo0IgTEu2d2MT3wNUhPaXCmrqZ1NRBW8W+ULI33TwISXK42TifRF9IGA== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" + victory-vendor "^36.8.2" -victory-box-plot@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-box-plot/-/victory-box-plot-36.4.0.tgz#64597018782edbc59e6a9dcb9804ff34ee6a9a16" - integrity sha512-iIaGjo7vLZjHQ0zYl9fBKcMy6NzLxfAn6ylRl8hYPl886yI8LrmWfDq5IDx2CMoCHXfzSROZU9jco/jMrEis2g== +victory-box-plot@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-box-plot/-/victory-box-plot-36.8.2.tgz#f991d9c52542e03b298a920e9f61c68997f0ca18" + integrity sha512-GN/2pJnuCsJHrLNT8XKVm82myZWtD8wg5ksG7k2xxhwosnAEWmaACsqUp7lB55pgSFFoWQ8xPfLTsm7ZuMv7Ag== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" + victory-vendor "^36.8.2" -victory-brush-container@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-brush-container/-/victory-brush-container-36.4.0.tgz#60ba2c21aad1d71d7965d4a92b64f90b89dbf788" - integrity sha512-7fjwcbhzC6q1Nxx+GRFEeYupm5El/sTjqIRk1l/a4ACLNJApF+FpH6DPXZ47pBY2qpWQeq4e5hP3zd5BBm6t1w== +victory-brush-container@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-brush-container/-/victory-brush-container-36.8.2.tgz#ad69983229a250ad60c0e0b2ff8450a177862c8f" + integrity sha512-dIZGLF5lre3MmtBWo93Ao/qnkuFff1SyhRyAxN8pcfIJg+V5ndgok5lNhJMR3pr6tbS/enw7hMufAgJYIUxgpQ== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-core "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-core "^36.8.2" -victory-brush-line@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-brush-line/-/victory-brush-line-36.4.0.tgz#a2fbe615d823bc6377f0ccc2905bf6356de570f7" - integrity sha512-Rychs64FkW/pWG3ilf96+Nl9HZ+Pf1C7X4elgYZyIhbRlnl19HkkcW4C9YvYiLTTvruGkbIan5GMLtcvGjkX8g== +victory-brush-line@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-brush-line/-/victory-brush-line-36.8.2.tgz#62685b75d791b19c74ed89195ddc8c5c443facb1" + integrity sha512-0IivU6Bdmf1UsC09yXGSI2owMrzuHvfosIqJSRXPmqxf4t2shn28t1bjkBPRGFJjz8UOL5YLuuW8qxa0wWJzbw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-core "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-core "^36.8.2" -victory-candlestick@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-candlestick/-/victory-candlestick-36.4.0.tgz#0721fb040dc2bdf7bfd39c1db97a4be7014fd428" - integrity sha512-e5+2BkwMhVvzmIkcmfuorjBi6KZlhQXs+2kCSQYUBC2UbTni6FNrM/AmxhjRvqTo9tAg4jo7KBN20wTqn/PPcg== +victory-candlestick@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-candlestick/-/victory-candlestick-36.8.2.tgz#dae311a3f4f501cb2224ab0954d49de62f780bb7" + integrity sha512-UkmHcKOpUajVFRLH+O32RkQy1+DqLTRu41Qe3h4r2JCJdFVxOwHabpqQ7XP4umF2x9ZLg8rbNZg/a2wR6/B6ww== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-canvas@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-canvas/-/victory-canvas-36.4.0.tgz#57bafd48d45f14ac6b72ca64d1b8ae285dc506b4" - integrity sha512-bw+fu0obggOJQ8OJgKTZ/R0mzJeUVlFhVj4KPz6gUJlddYc9T0FpDCfKI84fNp2WWFF7zztxTUEZti57RQVeDQ== +victory-canvas@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-canvas/-/victory-canvas-36.8.2.tgz#76fbd1aec35a28650b652e55228347a22db849a6" + integrity sha512-2/QWCAgIzUinXKn+xERYcbQ+pUgbAHptwn2c3ZgX9FxEpgS9tdAphyu4bHXuLk3gZ7OXaCa2Scn3Ch+8wj1UMg== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-bar "^36.8.2" + victory-core "^36.8.2" -victory-chart@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-chart/-/victory-chart-36.4.0.tgz#03dc49a1d6cf9d4b3297bced5d7ff23f13e6005e" - integrity sha512-KplPECIjsaZxOF2lhfa5X6l02WnCGqzLdZ9SJVy9RuNdQc6ZBS8odeyNnj7X3PgHIbmlAjRNprrjvgB2OpLK2g== +victory-chart@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-chart/-/victory-chart-36.8.2.tgz#dfff420702bdbddf2977a9fb86187038188c80d2" + integrity sha512-Oijd31G9hIwmJtazvAWDLLM7O8CFhlo8qtLLAJkvvPd+nr0Q2FHr5EE23nlcOYfZsJqqYAO++SEcwoK4veRw1g== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-axis "^36.4.0" - victory-core "^36.4.0" - victory-polar-axis "^36.4.0" - victory-shared-events "^36.4.0" - -victory-core@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-core/-/victory-core-36.4.0.tgz#9fef7175a21a0c07b428bc37e0cf2ae2cdebb0d4" - integrity sha512-gyAkCa/Ux5xgGJp6E3Q9g5oQWcSwdtH3qXYn5AZiyBBz/u2wc9Hoeh+ZVoGuXT0/4VOuqsEcZcf4yaiEFhkbOg== + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-axis "^36.8.2" + victory-core "^36.8.2" + victory-polar-axis "^36.8.2" + victory-shared-events "^36.8.2" + +victory-core@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-core/-/victory-core-36.8.2.tgz#e80d298633f098ec8c44e4e621083f2d23d4baca" + integrity sha512-kr35sKanc4hgEUGJ/tiucdm9eQM5QQc/m9rJkzM+cp74cMC8/HXI51XiBKEUT1YWiKdu96p3r3u+V3I7p+y5tw== dependencies: lodash "^4.17.21" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-vendor "^36.8.2" -victory-create-container@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-create-container/-/victory-create-container-36.4.0.tgz#ff2d1cfe74a1243dbdf09148c190227533a38ac7" - integrity sha512-Chf88iyXqAs+d/AMTbFQgTVdHPAOlAOyTOneINMp85O1RO9qC24F8qf0rdOd8h/8mIY+yKTlM7TVuGUTbMgXzQ== +victory-create-container@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-create-container/-/victory-create-container-36.8.2.tgz#d1e7bf8ac756b79d0d5b0e22f2070351bc0e0c5e" + integrity sha512-GA65xVwpktB5xABweNyKGplg48cRiLmO6w6UMHEPcdOXb65zfdiyN0Gq6OxurV+dUiHr89UUeWy1yBOYcYJRCA== dependencies: lodash "^4.17.19" - victory-brush-container "^36.4.0" - victory-core "^36.4.0" - victory-cursor-container "^36.4.0" - victory-selection-container "^36.4.0" - victory-voronoi-container "^36.4.0" - victory-zoom-container "^36.4.0" - -victory-cursor-container@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-cursor-container/-/victory-cursor-container-36.4.0.tgz#af2fd33e874730924f0038b0d043dd593fd41ee6" - integrity sha512-OKVhLilJjQByzGLyBiGvsc3XBUuBqyBmjMyMMK95nsrvs2AJ89N93+xJwSQmq051HpqXgmtCER28cQRetuE4Zg== + victory-brush-container "^36.8.2" + victory-core "^36.8.2" + victory-cursor-container "^36.8.2" + victory-selection-container "^36.8.2" + victory-voronoi-container "^36.8.2" + victory-zoom-container "^36.8.2" + +victory-cursor-container@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-cursor-container/-/victory-cursor-container-36.8.2.tgz#b956e63fcb5d13d5c503c972a1e2dc24e940fadc" + integrity sha512-1g+pmjnYyFamAkwjK4KWmz+/80GBAueQLHgyGjwGkrkDRWWjx2XNh9bRoi+erXIOdKtimOhlDMYSjgvrha6eNw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-errorbar@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-errorbar/-/victory-errorbar-36.4.0.tgz#bac73edfeb8e2c8956b0569dddcc6eaeaff6723c" - integrity sha512-j3z7tVlIvTPpF8EpRmif1plVPepg56JC9rGl6QMwU+D+Ee9e0Pp+EQRU+fC02qUZy4jxKjvyTLz4KNL8zglBfA== +victory-errorbar@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-errorbar/-/victory-errorbar-36.8.2.tgz#90689c5cd23ab11b8a89f22bd6cd5a47551f71c6" + integrity sha512-G5m+PrYLkHBNaolpTWXSXoQUfhdnNWiTTnhOZqwyT624Rdsy04Z3nVPOVhi1ruWC84jHu4wM4XIUrUorGlorFA== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-group@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-group/-/victory-group-36.4.0.tgz#ce729b2d930d68fddc91040ae1c37e927471dd06" - integrity sha512-KC7qItp9OFEjZVQq5/opqQiNAn6OaZWcA+yv6dYF8KcmSzKRPsT62Y4aYzfoE6+wtkcSOMHwdgWT3tY8K7AQXA== +victory-group@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-group/-/victory-group-36.8.2.tgz#9d48824d8afadf3180bc401855ccc619fbf4450e" + integrity sha512-sYF8qIxsPEbKl3EbiFbpJCWfB8wztR8bbbjRL2w4PHixNmXIe8vjYUXBUNQn0WLmr7yENY02Arr0ts8hOMCPIw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-core "^36.4.0" - victory-shared-events "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-core "^36.8.2" + victory-shared-events "^36.8.2" -victory-histogram@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-histogram/-/victory-histogram-36.4.0.tgz#d18d02b5f57c8daeed263614a46f13de9f3748a7" - integrity sha512-gbdo0VPUPugj9ZI61wBwsbHpPu+sNVYLc471lu1I2gg+mq6+/IIAEEeFf3wlap37FuKZkIik+Ec8Z7OilTIUPA== +victory-histogram@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-histogram/-/victory-histogram-36.8.2.tgz#9707433bddc0a7967bcb8311d9e03fd6c5816335" + integrity sha512-+FsbXF7fzzik5es66JPId1JiHm9C8CH5Ul9FAn0avxf6NncnuVXQ/H/Neg5txfjDPrIly/MxcZ7QTEgYnfTJNw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-bar "^36.4.0" - victory-core "^36.4.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-bar "^36.8.2" + victory-core "^36.8.2" + victory-vendor "^36.8.2" -victory-legend@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-legend/-/victory-legend-36.4.0.tgz#eb9026bbdb3c056aa567d80de11b2ddbf2af3c0d" - integrity sha512-vEhijn2G2lRXt/giuN5FzgIWGNwHvVN7+kJjgvqUCrBcb3FhTdEW+7uP+yru4NWaOgYtivBmL7iC1tsz3K72Pg== +victory-legend@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-legend/-/victory-legend-36.8.2.tgz#116e3c3dbc576583451c368fd8e22e707e0df209" + integrity sha512-boTPtlF6CTPd9tRBF8zdiFm3tO7rfmF/WiPgOqZVHq+wU/R6d8grWFntJSpoYl/AZbMJLvp1526dW5S8aCsSTQ== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-line@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-line/-/victory-line-36.4.0.tgz#ec36b4489ebfd60ffaaadc3dfe2e9c67539dc2b9" - integrity sha512-o5q0RrGQB5L6snp89xW73KNogZLh5sXPAkXDivcUpSngLgZuPBg0oiPmLKh35WxJ90hhIuZ8Ql+uSr9fHJv85A== +victory-line@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-line/-/victory-line-36.8.2.tgz#beec44c9ce332a7f318b9e8162b17d97bd2c52fc" + integrity sha512-ZK60REFU/8R6wEksI4rrrgAUJeBS8DfbLTc9oAAVC91uLWgkykDjrkT7Oe2bXww2BuiWde7uYZm49oGngydNrw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" + victory-vendor "^36.8.2" -victory-pie@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-pie/-/victory-pie-36.4.0.tgz#a6d5fb4820f3839413886d50531577030bd8754b" - integrity sha512-mOW5NPqfG2zzOwGQLLprFQpNlRXnuaS05yKftB+yGKZqXUcyItkhM4itz6ZIePu16a//c/5szWUhlt44fJvPiw== +victory-pie@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-pie/-/victory-pie-36.8.2.tgz#2da2fbd3b7289b962f45e0e8fee67e50d2487ca7" + integrity sha512-+Y0h1+CFYFH/3Bwl0JFQKJb0sqmExIknDF6wQG3+t50Ye81L8qPrXupilt1L/6Zmc9UhVW1XWBCcAKU3iC2Osw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - victory-vendor "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" + victory-vendor "^36.8.2" -victory-polar-axis@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-polar-axis/-/victory-polar-axis-36.4.0.tgz#b41cc70cbc0fc12b7ae4a9ad16cf07137d2ad176" - integrity sha512-eiWep+5oXgwRA0xzwuQE8do1yvcyOqQWXtAUNQzDEEwqHcg1Lar+O9IC/OwlXtO4YTkOzcpAc7ageUbIZIIABA== +victory-polar-axis@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-polar-axis/-/victory-polar-axis-36.8.2.tgz#3cab4f36448672333d9ee2d72b1dab15cea359fa" + integrity sha512-3vL0iS4RN8EKwCTORl3aKWnWC3SJd8V0xn4epb7O8Zqnx9jbxMTUpq1AlfZvzm3GlcR50vm8DtnnkH6z3lLcyw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-scatter@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-scatter/-/victory-scatter-36.4.0.tgz#f996787dbc542140749cc2941398c68e543a2008" - integrity sha512-9uCpXsAk97B4Q8Z8T5qWS7r/XNZ+6wewKlcbWNLQ23LUGivix/oJq7IyB1q4R1QtxldJ4kBsSGegg4NF5oBnlg== +victory-scatter@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-scatter/-/victory-scatter-36.8.2.tgz#b7c3c7fa59489acf50a5e0a6698b6fe92746a277" + integrity sha512-Za6UBANmIv9ffAZ/eeZO7WDKB7CGXkGpnlVWPv2tIV+80C2TtuORUWe6aUmMImdk3gJHWjp2fELYnJs4WLwzMQ== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-selection-container@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-selection-container/-/victory-selection-container-36.4.0.tgz#15714cdd094dcba8ca69ce1275643b5a080383a1" - integrity sha512-mYHGpf1vk2yYftSMUUQ0R+jXCjSMg5efzpus1z8RYLVWGHHeyzSWlRpdmYDOY9lWu20QId1gqYRWOSvVLa+Pbw== +victory-selection-container@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-selection-container/-/victory-selection-container-36.8.2.tgz#64fecddf3e750b203603e0650e485daf46092e3a" + integrity sha512-sf5vShOQKCbIydx8F2uvWQitddTZbjuHVmf8n7fH7DefxQRCc1xB8M1gk+4qEaBCmYM75de5AAD5vtaVG0ZwJQ== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-shared-events@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-shared-events/-/victory-shared-events-36.4.0.tgz#fd485375f975a80ea8835345cf699c3aff6a5d66" - integrity sha512-Kb/rxxw3JY6ojiy0NOxivzC/OQ6E5IsKnLxHKTV261io0QxzPCEV7G11lv/3dc6aJEXhXGbHzKh3dcWsGqnMfA== +victory-shared-events@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-shared-events/-/victory-shared-events-36.8.2.tgz#b65216624f89f58eaa9f1e7e7637ce48c05ccfe9" + integrity sha512-WKpcAC5g6s297lYtOq723UARVhVYc+bDrhm1Nup9qv+YPnM7sltQWQ+cEMO93Nine9SSMb03Dq1cXJILH+h06Q== dependencies: json-stringify-safe "^5.0.1" lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-core "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-core "^36.8.2" -victory-stack@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-stack/-/victory-stack-36.4.0.tgz#724b530bc75d50630385760518a74a8781649474" - integrity sha512-/QgwzBhnASorVVs1XySXJTNY/mGdA9PyPiXlmq/H37tqAFL5S4DmkrAQKtp92lVlpd+H1iwp4q9mNG03x974HA== +victory-stack@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-stack/-/victory-stack-36.8.2.tgz#fd2c0beb9e35413db9b3a768cd0120081666a8d6" + integrity sha512-9bLtUd6DlIHaRdKNJE51rxKIOQLMonhSSd0+KkXMJ8pn5cPBjoWc2UpQ0oXzi7TO5ODClYng8nOlMMAJwfgKRw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-core "^36.4.0" - victory-shared-events "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-core "^36.8.2" + victory-shared-events "^36.8.2" -victory-tooltip@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-tooltip/-/victory-tooltip-36.4.0.tgz#8d9a6e6dd8222da89adfaf0691a808c3690dfd64" - integrity sha512-OHaGKEGs9aW2ZAuGTodmZJHAy8QMbkEmIWhd5AtDmpczbqRSAqmuGsOS5blzjYwnmZ24hvHBCoGEj78Ryk+Xsw== +victory-tooltip@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-tooltip/-/victory-tooltip-36.8.2.tgz#7340017604ee2d01ddc323013ab92eb9d96bd953" + integrity sha512-rLKw9wQJ+2OaYIID6TRpqGPFHBn4lMth+mP1RweHHsUIoovxhEFFa6thapkVdWsIWIvU0W4AQP3eTCmMV5dPxw== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - -victory-vendor@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-vendor/-/victory-vendor-36.4.0.tgz#ee986392f545d268e868d2b46de2a6db93c604a7" - integrity sha512-FbERt20G1qu5qPxZqBlkWcf9Sl/gyqYVmhHadLPj0nMcvCf+vgZUVe/NLYI45ey2JtS3jvciQ9lCWjcNXY+G9Q== - dependencies: + prop-types "^15.8.1" + victory-core "^36.8.2" + +victory-vendor@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-vendor/-/victory-vendor-36.8.2.tgz#523e97a78ac8af73c526eb9fd3921d6972100600" + integrity sha512-NfSQi7ISCdBbDpn3b6rg+8RpFZmWIM9mcks48BbogHE2F6h1XKdA34oiCKP5hP1OGvTotDRzsexiJKzrK4Exuw== + dependencies: + "@types/d3-array" "^3.0.3" + "@types/d3-ease" "^3.0.0" + "@types/d3-interpolate" "^3.0.1" + "@types/d3-scale" "^4.0.2" + "@types/d3-shape" "^3.1.0" + "@types/d3-time" "^3.0.0" + "@types/d3-timer" "^3.0.0" d3-array "^3.1.6" d3-ease "^3.0.1" d3-interpolate "^3.0.1" @@ -8332,69 +8396,69 @@ victory-vendor@^36.4.0: d3-time "^3.0.0" d3-timer "^3.0.1" -victory-voronoi-container@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-voronoi-container/-/victory-voronoi-container-36.4.0.tgz#8ce48c2ac31c18a49f1f4ae0dcbc6fdfc23a067c" - integrity sha512-oOpO+Q4lu4PSPwEDlcNMNpKfUNb2Hb8bfwWbhrje9rmvePVTw0JRic1pqOd8gsxD6Wa0gtIodLjOgtPQZSgD0w== +victory-voronoi-container@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-voronoi-container/-/victory-voronoi-container-36.8.2.tgz#b6d1298b9a2a69e0b1fe936b436eb044e267700d" + integrity sha512-lB6u47z7ndGuSURhDXaYlGhL+jRaQIIsWqyIQK9HueWhxlErcI45kdXijjhRORy9kSsvxLZteOJOflF5Ri3rHg== dependencies: delaunay-find "0.0.6" lodash "^4.17.19" - prop-types "^15.5.8" - react-fast-compare "^2.0.0" - victory-core "^36.4.0" - victory-tooltip "^36.4.0" + prop-types "^15.8.1" + react-fast-compare "^3.2.0" + victory-core "^36.8.2" + victory-tooltip "^36.8.2" -victory-voronoi@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-voronoi/-/victory-voronoi-36.4.0.tgz#aa82ef1c6fac851d492cac5c0d86b1342e048cb2" - integrity sha512-yPo1+lx+B5fdXA7wPpp+zieYtodffoZppZe+SiScx/vOxC4jIWelnSPDTChpMw6ArIujGnP97dHwU6ssnDdHUQ== +victory-voronoi@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-voronoi/-/victory-voronoi-36.8.2.tgz#7272ddce6d83017370f412658312668a32ffcd00" + integrity sha512-m8bIdpkyV8KDGueItK1ka0ODxWNZGf/OmRsdsA8wKisQ6iThM/HxxhfHbxUPfNUmLxZj3JqTvKtjjeK/bSM7cQ== dependencies: d3-voronoi "^1.1.4" lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" -victory-zoom-container@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory-zoom-container/-/victory-zoom-container-36.4.0.tgz#4139d42f943db1648ead9f58218772b9ad374c5a" - integrity sha512-Tgs+wINnkkqUuuuV6ZghkwgmFnZfX1HJkRL+cafDDjJAazQEpuIYTGj9MA15kN29MbhUl5PMNvsDpKpVCTYLWw== +victory-zoom-container@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory-zoom-container/-/victory-zoom-container-36.8.2.tgz#2fee70b51d4ce248ad5ee38c9b1d2dd98bf164aa" + integrity sha512-4kgr/gFi//htBzSzHPJMDQqUYLTGN9z7xs5Ct351y6WXIhMK/6lHEONe349/FxlT+feBb0Whq56B0eeJZP4HcQ== dependencies: lodash "^4.17.19" - prop-types "^15.5.8" - victory-core "^36.4.0" - -victory@^36.4.0: - version "36.4.0" - resolved "https://registry.yarnpkg.com/victory/-/victory-36.4.0.tgz#3661c0302c82bfca5ad63cebc3e329dcad55f352" - integrity sha512-W1Rem6iyTxObEjhpvc642Z9hzarI8y/I6hiNHlTSBuXWG8KS/eZd3ZENyKRdzeatHS4ltLWaPDVZ9xOGKyQ5lQ== - dependencies: - victory-area "^36.4.0" - victory-axis "^36.4.0" - victory-bar "^36.4.0" - victory-box-plot "^36.4.0" - victory-brush-container "^36.4.0" - victory-brush-line "^36.4.0" - victory-candlestick "^36.4.0" - victory-canvas "^36.4.0" - victory-chart "^36.4.0" - victory-core "^36.4.0" - victory-create-container "^36.4.0" - victory-cursor-container "^36.4.0" - victory-errorbar "^36.4.0" - victory-group "^36.4.0" - victory-histogram "^36.4.0" - victory-legend "^36.4.0" - victory-line "^36.4.0" - victory-pie "^36.4.0" - victory-polar-axis "^36.4.0" - victory-scatter "^36.4.0" - victory-selection-container "^36.4.0" - victory-shared-events "^36.4.0" - victory-stack "^36.4.0" - victory-tooltip "^36.4.0" - victory-voronoi "^36.4.0" - victory-voronoi-container "^36.4.0" - victory-zoom-container "^36.4.0" + prop-types "^15.8.1" + victory-core "^36.8.2" + +victory@^36.8.2: + version "36.8.2" + resolved "https://registry.yarnpkg.com/victory/-/victory-36.8.2.tgz#96961597a3203f00d4ef97d757d9ee9b44a42462" + integrity sha512-IxXM+mRtS1OlMVjFUEMvlmFIO82mP0iFgr3bOJuff75bqI2ItlhrFBzT6iI14gyG4OxoMTficBNJz8hKGGzhDw== + dependencies: + victory-area "^36.8.2" + victory-axis "^36.8.2" + victory-bar "^36.8.2" + victory-box-plot "^36.8.2" + victory-brush-container "^36.8.2" + victory-brush-line "^36.8.2" + victory-candlestick "^36.8.2" + victory-canvas "^36.8.2" + victory-chart "^36.8.2" + victory-core "^36.8.2" + victory-create-container "^36.8.2" + victory-cursor-container "^36.8.2" + victory-errorbar "^36.8.2" + victory-group "^36.8.2" + victory-histogram "^36.8.2" + victory-legend "^36.8.2" + victory-line "^36.8.2" + victory-pie "^36.8.2" + victory-polar-axis "^36.8.2" + victory-scatter "^36.8.2" + victory-selection-container "^36.8.2" + victory-shared-events "^36.8.2" + victory-stack "^36.8.2" + victory-tooltip "^36.8.2" + victory-voronoi "^36.8.2" + victory-voronoi-container "^36.8.2" + victory-zoom-container "^36.8.2" vm-browserify@^1.0.1: version "1.1.2" From 2f9e08166ce142c6aeb21061c617f4911a9e5f6a Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Tue, 23 Jan 2024 14:30:05 +0000 Subject: [PATCH 28/29] Migrate victory-create-container to TypeScript (#2731) --- .changeset/eight-bananas-itch.md | 5 ++ ...reate-container.js => create-container.ts} | 49 +++++++++++++------ .../victory-create-container/src/index.d.ts | 19 ------- .../victory-create-container/src/index.js | 5 -- .../victory-create-container/src/index.ts | 1 + 5 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 .changeset/eight-bananas-itch.md rename packages/victory-create-container/src/{create-container.js => create-container.ts} (83%) delete mode 100644 packages/victory-create-container/src/index.d.ts delete mode 100644 packages/victory-create-container/src/index.js create mode 100644 packages/victory-create-container/src/index.ts diff --git a/.changeset/eight-bananas-itch.md b/.changeset/eight-bananas-itch.md new file mode 100644 index 000000000..4a272adc8 --- /dev/null +++ b/.changeset/eight-bananas-itch.md @@ -0,0 +1,5 @@ +--- +"victory-create-container": patch +--- + +Migrate victory-create-container to TypeScript diff --git a/packages/victory-create-container/src/create-container.js b/packages/victory-create-container/src/create-container.ts similarity index 83% rename from packages/victory-create-container/src/create-container.js rename to packages/victory-create-container/src/create-container.ts index 40072162f..95c998449 100644 --- a/packages/victory-create-container/src/create-container.js +++ b/packages/victory-create-container/src/create-container.ts @@ -1,3 +1,4 @@ +import React from "react"; import { toPairs, groupBy, @@ -6,7 +7,6 @@ import { flow, isEmpty, isFunction, - keys, } from "lodash"; import { VictoryContainer, Log } from "victory-core"; import { voronoiContainerMixin } from "victory-voronoi-container"; @@ -15,16 +15,25 @@ import { selectionContainerMixin } from "victory-selection-container"; import { brushContainerMixin } from "victory-brush-container"; import { cursorContainerMixin } from "victory-cursor-container"; -const ensureArray = (thing) => { +export type ContainerType = + | "brush" + | "cursor" + | "selection" + | "voronoi" + | "zoom"; + +type MixinFunction = (...args: any[]) => any; + +function ensureArray(thing: T): [] | T | T[] { if (!thing) { return []; } else if (!Array.isArray(thing)) { return [thing]; } return thing; -}; +} -const combineEventHandlers = (eventHandlersArray) => { +const combineEventHandlers = (eventHandlersArray: any[]) => { // takes an array of event handler objects and produces one eventHandlers object // creates a custom combinedHandler() for events with multiple conflicting handlers return eventHandlersArray.reduce((localHandlers, finalHandlers) => { @@ -47,7 +56,7 @@ const combineEventHandlers = (eventHandlersArray) => { }); }; -const combineDefaultEvents = (defaultEvents) => { +const combineDefaultEvents = (defaultEvents: any[]) => { // takes a defaultEvents array and returns one equal or lesser length, // by combining any events that have the same target const eventsByTarget = groupBy(defaultEvents, "target"); @@ -66,12 +75,14 @@ const combineDefaultEvents = (defaultEvents) => { return events.filter(Boolean); }; -const combineContainerMixins = (mixins, Container) => { +export const combineContainerMixins = ( + mixins: MixinFunction[], + Container: React.ComponentType, +) => { // similar to Object.assign(A, B), this function will decide conflicts in favor mixinB. // this applies to propTypes and defaultProps. // getChildren will call A's getChildren() and pass the resulting children to B's. // defaultEvents attempts to resolve any conflicts between A and B's defaultEvents. - const Classes = mixins.map((mixin) => mixin(Container)); const instances = Classes.map((Class) => new Class()); const NaiveCombinedContainer = flow(mixins)(Container); @@ -114,7 +125,10 @@ const combineContainerMixins = (mixins, Container) => { }; }; -const checkBehaviorName = (behavior, behaviors) => { +const checkBehaviorName = ( + behavior: ContainerType, + behaviors: ContainerType[], +) => { if (behavior && !includes(behaviors, behavior)) { Log.warn( `"${behavior}" is not a valid behavior. Choose from [${behaviors.join( @@ -124,10 +138,17 @@ const checkBehaviorName = (behavior, behaviors) => { } }; -const makeCreateContainerFunction = - (mixinMap, Container) => - (behaviorA, behaviorB, ...invalid) => { - const behaviors = keys(mixinMap); +export const makeCreateContainerFunction = + ( + mixinMap: Record, + Container: React.ComponentType, + ) => + ( + behaviorA: ContainerType, + behaviorB: ContainerType, + ...invalid: ContainerType[] + ) => { + const behaviors = Object.keys(mixinMap) as ContainerType[]; checkBehaviorName(behaviorA, behaviors); checkBehaviorName(behaviorB, behaviors); @@ -148,7 +169,7 @@ const makeCreateContainerFunction = return combineContainerMixins([...firstMixins, ...secondMixins], Container); }; -const createContainer = makeCreateContainerFunction( +export const createContainer = makeCreateContainerFunction( { zoom: [zoomContainerMixin], voronoi: [voronoiContainerMixin], @@ -158,5 +179,3 @@ const createContainer = makeCreateContainerFunction( }, VictoryContainer, ); - -export { createContainer, makeCreateContainerFunction, combineContainerMixins }; diff --git a/packages/victory-create-container/src/index.d.ts b/packages/victory-create-container/src/index.d.ts deleted file mode 100644 index e39a797c6..000000000 --- a/packages/victory-create-container/src/index.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as React from "react"; - -export type ContainerType = - | "brush" - | "cursor" - | "selection" - | "voronoi" - | "zoom"; -export function createContainer( - c1: ContainerType, - c2: ContainerType, -): React.ComponentType; - -export function combineContainerMixins(mixins: any, Container: any): any; - -export const makeCreateContainerFunction: ( - mixinMap: any, - Container: any, -) => (behaviorA: any, behaviorB: any) => any; diff --git a/packages/victory-create-container/src/index.js b/packages/victory-create-container/src/index.js deleted file mode 100644 index 3a1c18681..000000000 --- a/packages/victory-create-container/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { - combineContainerMixins, - makeCreateContainerFunction, - createContainer, -} from "./create-container"; diff --git a/packages/victory-create-container/src/index.ts b/packages/victory-create-container/src/index.ts new file mode 100644 index 000000000..5f9b97723 --- /dev/null +++ b/packages/victory-create-container/src/index.ts @@ -0,0 +1 @@ +export * from "./create-container"; From 185627635883d5959f3870bb3d07d0333ae784d9 Mon Sep 17 00:00:00 2001 From: Kenan Yusuf Date: Tue, 23 Jan 2024 14:30:24 +0000 Subject: [PATCH 29/29] Migrate victory-zoom-container to TypeScript (#2730) --- .changeset/silver-weeks-attend.md | 5 ++ .../victory-zoom-container/src/index.d.ts | 57 -------------- packages/victory-zoom-container/src/index.js | 5 -- packages/victory-zoom-container/src/index.ts | 2 + ...ontainer.js => victory-zoom-container.tsx} | 77 ++++++++++--------- .../src/{zoom-helpers.js => zoom-helpers.ts} | 6 +- 6 files changed, 51 insertions(+), 101 deletions(-) create mode 100644 .changeset/silver-weeks-attend.md delete mode 100644 packages/victory-zoom-container/src/index.d.ts delete mode 100644 packages/victory-zoom-container/src/index.js create mode 100644 packages/victory-zoom-container/src/index.ts rename packages/victory-zoom-container/src/{victory-zoom-container.js => victory-zoom-container.tsx} (81%) rename packages/victory-zoom-container/src/{zoom-helpers.js => zoom-helpers.ts} (99%) diff --git a/.changeset/silver-weeks-attend.md b/.changeset/silver-weeks-attend.md new file mode 100644 index 000000000..c58f44637 --- /dev/null +++ b/.changeset/silver-weeks-attend.md @@ -0,0 +1,5 @@ +--- +"victory-zoom-container": patch +--- + +Migrate victory-zoom-container to TypeScript diff --git a/packages/victory-zoom-container/src/index.d.ts b/packages/victory-zoom-container/src/index.d.ts deleted file mode 100644 index 486ccdf97..000000000 --- a/packages/victory-zoom-container/src/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -import * as React from "react"; -import { DomainTuple, VictoryContainerProps } from "victory-core"; - -export type ZoomDimensionType = "x" | "y"; - -export interface VictoryZoomContainerProps extends VictoryContainerProps { - allowPan?: boolean; - allowZoom?: boolean; - clipContainerComponent?: React.ReactElement; - disable?: boolean; - downsample?: number | boolean; - minimumZoom?: { x?: number; y?: number }; - onZoomDomainChange?: ( - domain: { x: DomainTuple; y: DomainTuple }, - props: VictoryZoomContainerProps, - ) => void; - zoomDimension?: ZoomDimensionType; - zoomDomain?: { x?: DomainTuple; y?: DomainTuple }; -} - -export class VictoryZoomContainer extends React.Component< - VictoryZoomContainerProps, - any -> {} - -export const RawZoomHelpers: { - checkDomainEquality(a: any, b: any): any; - scale(currentDomain: any, evt: any, props: any, axis: any): any; - getScaledDomain(currentDomain: any, factor: any, percent: any): any; - getMinimumDomain(point: any, props: any, axis: any): any; - zoommingOut(evt: any): any; - getScaleFactor(evt: any): any; - getScalePercent(evt: any, props: any, axis: any): any; - getPosition(evt: any, props: any, originalDomain: any): any; - pan(currentDomain: any, originalDomain: any, delta: any): any; - getDomainScale(domain: any, scale: any, axis: any): any; - handleAnimation(ctx: any): any; - getLastDomain(targetProps: any, originalDomain: any): any; - getDomain(props: any): any; - onMouseDown(evt: any, targetProps: any): any; - onMouseUp(evt: any, targetProps: any): any; - onMouseLeave(evt: any, targetProps: any): any; - onMouseMove(evt: any, targetProps: any, eventKey: any, ctx: any): any; - onWheel(evt: any, targetProps: any, eventKey: any, ctx: any): any; -}; - -export const ZoomHelpers: Pick< - typeof RawZoomHelpers, - | "checkDomainEquality" - | "onMouseDown" - | "onMouseUp" - | "onMouseLeave" - | "onMouseMove" - | "onWheel" ->; - -export const zoomContainerMixin: (base: Function) => Function; diff --git a/packages/victory-zoom-container/src/index.js b/packages/victory-zoom-container/src/index.js deleted file mode 100644 index f194a4fb5..000000000 --- a/packages/victory-zoom-container/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { - zoomContainerMixin, - default as VictoryZoomContainer, -} from "./victory-zoom-container"; -export { default as ZoomHelpers, RawZoomHelpers } from "./zoom-helpers"; diff --git a/packages/victory-zoom-container/src/index.ts b/packages/victory-zoom-container/src/index.ts new file mode 100644 index 000000000..1a87c305d --- /dev/null +++ b/packages/victory-zoom-container/src/index.ts @@ -0,0 +1,2 @@ +export * from "./victory-zoom-container"; +export * from "./zoom-helpers"; diff --git a/packages/victory-zoom-container/src/victory-zoom-container.js b/packages/victory-zoom-container/src/victory-zoom-container.tsx similarity index 81% rename from packages/victory-zoom-container/src/victory-zoom-container.js rename to packages/victory-zoom-container/src/victory-zoom-container.tsx index 0f3b0e039..87d8502cd 100644 --- a/packages/victory-zoom-container/src/victory-zoom-container.js +++ b/packages/victory-zoom-container/src/victory-zoom-container.tsx @@ -1,39 +1,43 @@ -import PropTypes from "prop-types"; import React from "react"; import { defaults, isFunction } from "lodash"; -import ZoomHelpers from "./zoom-helpers"; +import { ZoomHelpers } from "./zoom-helpers"; import { VictoryContainer, VictoryClipContainer, Data, - PropTypes as CustomPropTypes, + VictoryContainerProps, + DomainTuple, } from "victory-core"; const DEFAULT_DOWNSAMPLE = 150; -export const zoomContainerMixin = (base) => - class VictoryZoomContainer extends base { +export type ZoomDimensionType = "x" | "y"; + +export interface VictoryZoomContainerProps extends VictoryContainerProps { + allowPan?: boolean; + allowZoom?: boolean; + clipContainerComponent?: React.ReactElement; + disable?: boolean; + downsample?: number | boolean; + minimumZoom?: { x?: number; y?: number }; + onZoomDomainChange?: ( + domain: { x: DomainTuple; y: DomainTuple }, + props: VictoryZoomContainerProps, + ) => void; + zoomDimension?: ZoomDimensionType; + zoomDomain?: { x?: DomainTuple; y?: DomainTuple }; +} + +type ComponentClass = { new (props: TProps): React.Component }; + +export function zoomContainerMixin< + TBase extends ComponentClass, + TProps extends VictoryZoomContainerProps, +>(Base: TBase) { + // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." + return class VictoryZoomContainer extends Base { static displayName = "VictoryZoomContainer"; - static propTypes = { - ...VictoryContainer.propTypes, - allowPan: PropTypes.bool, - allowZoom: PropTypes.bool, - clipContainerComponent: PropTypes.element.isRequired, - disable: PropTypes.bool, - downsample: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]), - minimumZoom: PropTypes.shape({ - x: PropTypes.number, - y: PropTypes.number, - }), - onZoomDomainChange: PropTypes.func, - zoomDimension: PropTypes.oneOf(["x", "y"]), - zoomDomain: PropTypes.shape({ - x: CustomPropTypes.domain, - y: CustomPropTypes.domain, - }), - }; - static defaultProps = { ...VictoryContainer.defaultProps, clipContainerComponent: , @@ -42,7 +46,7 @@ export const zoomContainerMixin = (base) => zoomActive: false, }; - static defaultEvents = (props) => { + static defaultEvents = (props: TProps) => { return [ { target: "parent", @@ -100,7 +104,7 @@ export const zoomContainerMixin = (base) => ]; }; - clipDataComponents(children, props) { + clipDataComponents(children: React.ReactElement[], props) { const { scale, clipContainerComponent, polar, origin, horizontal } = props; const rangeX = horizontal ? scale.y.range() : scale.x.range(); @@ -122,7 +126,9 @@ export const zoomContainerMixin = (base) => if (!Data.isDataComponent(child)) { return child; } - return React.cloneElement(child, { groupComponent }); + return React.cloneElement(child as React.ReactElement, { + groupComponent, + }); }); } @@ -179,10 +185,12 @@ export const zoomContainerMixin = (base) => } modifyChildren(props) { - const childComponents = React.Children.toArray(props.children); - // eslint-disable-next-line max-statements + const childComponents = React.Children.toArray( + props.children, + ) as React.ReactElement[]; + return childComponents.map((child) => { - const role = child.type && child.type.role; + const role = child.type && (child.type as any).role; const isDataComponent = Data.isDataComponent(child); const { currentDomain, zoomActive, allowZoom } = props; const originalDomain = defaults({}, props.originalDomain, props.domain); @@ -227,13 +235,12 @@ export const zoomContainerMixin = (base) => } // Overrides method in VictoryContainer - getChildren(props) { + getChildren(props: TProps) { const children = this.modifyChildren(props); return this.clipDataComponents(children, props); } }; +} -export default zoomContainerMixin(VictoryContainer); -// @ts-expect-error IMPORTANT: when converting this file to TypeScript, you must export the type as well: -// export const VictoryZoomContainer = zoomContainerMixin(VictoryContainer); -// export type VictoryZoomContainer = typeof VictoryZoomContainer; +export const VictoryZoomContainer = zoomContainerMixin(VictoryContainer); +export type VictoryZoomContainer = typeof VictoryZoomContainer; diff --git a/packages/victory-zoom-container/src/zoom-helpers.js b/packages/victory-zoom-container/src/zoom-helpers.ts similarity index 99% rename from packages/victory-zoom-container/src/zoom-helpers.js rename to packages/victory-zoom-container/src/zoom-helpers.ts index 70b946ca2..7d2ad950c 100644 --- a/packages/victory-zoom-container/src/zoom-helpers.js +++ b/packages/victory-zoom-container/src/zoom-helpers.ts @@ -3,7 +3,7 @@ import { Children } from "react"; import { Selection, Collection, Wrapper } from "victory-core"; import { throttle, isFunction, defaults, delay } from "lodash"; -const RawZoomHelpers = { +export const RawZoomHelpers = { checkDomainEquality(a, b) { const checkDimension = (dim) => { const val1 = a && a[dim]; @@ -361,9 +361,7 @@ const RawZoomHelpers = { }, }; -export { RawZoomHelpers }; // allow victory-native to extend these helpers - -export default { +export const ZoomHelpers = { checkDomainEquality: RawZoomHelpers.checkDomainEquality.bind(RawZoomHelpers), onMouseDown: RawZoomHelpers.onMouseDown.bind(RawZoomHelpers), onMouseUp: RawZoomHelpers.onMouseUp.bind(RawZoomHelpers),