Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS: migrate victory-brush-container and victory-brush-line #2393

Merged
merged 13 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/victory-brush-container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"peerDependencies": {
"react": ">=16.6.0"
},
"devDependencies": {
"victory-brush-container": "*"
},
"scripts": {
"### THESE SCRIPTS ARE GENERATED ###": "true",
"### DO NOT MODIFY THESE MANUALLY ###": "true",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Helpers from "victory-brush-container/lib/brush-helpers";
import { BrushHelpers } from "victory-brush-container";

describe("containers/brush-helpers", () => {
const { withinBounds, constrainBox } = Helpers;
// eslint-disable-next-line @typescript-eslint/unbound-method
const { withinBounds, constrainBox } = BrushHelpers;
describe("withinBounds", () => {
it("returns true when within bounds", () => {
const point = { x: 1, y: 1 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import { Selection } from "victory-core";
import { assign, throttle, isFunction, defaults, mapValues } from "lodash";
import isEqual from "react-fast-compare";
export interface BrushHelpers {
getDimension(props): any;
withinBounds(point, bounds, padding?): any;
getDomainBox(props, fullDomain, selectedDomain?): any;
getHandles(props, domainBox): any;
getActiveHandles(point, props, domainBox): any;
getResizeMutation(box, handles): any;
getMinimumDomain(): any;
getDefaultBrushArea(targetProps, cachedDomain, evt): any;
getSelectionMutation(point, box, brushDimension): any;
panBox(props, point): any;
constrainBox(box, fullDomainBox): any;
constrainPoint(point, fullDomainBox): any;
hasMoved(props): any;
onMouseDown(evt, targetProps): any;
onGlobalMouseMove(evt, targetProps): any;
onGlobalMouseUp(evt, targetProps): any;
}
scottrippey marked this conversation as resolved.
Show resolved Hide resolved

const Helpers = {
const Helpers: BrushHelpers = {
getDimension(props) {
const { horizontal, brushDimension } = props;
if (!horizontal || !brushDimension) {
Expand Down Expand Up @@ -99,7 +117,7 @@ const Helpers = {
: memo;
return memo;
},
[],
[] as string[],
);
return activeHandles.length && activeHandles;
},
Expand Down Expand Up @@ -405,7 +423,6 @@ const Helpers = {
x1: targetProps.x1,
y1: targetProps.y1,
scale,
horizontal,
});

const mutatedProps = { x2, y2, currentDomain, parentSVG };
Expand Down Expand Up @@ -452,7 +469,11 @@ const Helpers = {
: targetProps.defaultBrushArea;
const defaultBrushHasArea =
defaultBrushArea !== undefined && defaultBrushArea !== "none";
const mutatedProps = { isPanning: false, isSelecting: false };
const mutatedProps: {
scottrippey marked this conversation as resolved.
Show resolved Hide resolved
isPanning: boolean;
isSelecting: boolean;
currentDomain?: any;
} = { isPanning: false, isSelecting: false };

// if the mouse hasn't moved since a mouseDown event, select the default brush area
if ((allowResize || defaultBrushHasArea) && (x1 === x2 || y1 === y2)) {
Expand Down Expand Up @@ -496,7 +517,7 @@ const Helpers = {
},
};

export default {
export const BrushHelpers = {
...Helpers,
onMouseDown: Helpers.onMouseDown.bind(Helpers),
onGlobalMouseUp: Helpers.onGlobalMouseUp.bind(Helpers),
Expand Down
5 changes: 0 additions & 5 deletions packages/victory-brush-container/src/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/victory-brush-container/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./victory-brush-container";
export * from "./brush-helpers";
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
import PropTypes from "prop-types";
import React from "react";
import { VictoryContainer, Selection, Rect } from "victory-core";
import BrushHelpers from "./brush-helpers";
import {
VictoryContainer,
Selection,
Rect,
DomainTuple,
VictoryContainerProps,
} from "victory-core";
import { BrushHelpers } from "./brush-helpers";
import { assign, defaults } from "lodash";
import isEqual from "react-fast-compare";
export interface VictoryBrushContainerProps extends VictoryContainerProps {
allowDrag?: boolean;
allowDraw?: boolean;
allowResize?: boolean;
brushComponent?: React.ReactElement;
brushDimension?: "x" | "y";
brushDomain?: { x?: DomainTuple; y?: DomainTuple };
brushStyle?: React.CSSProperties;
defaultBrushArea?: "all" | "none" | "disable" | "move";
disable?: boolean;
handleComponent?: React.ReactElement;
handleStyle?: React.CSSProperties;
handleWidth?: number;
onBrushCleared?: (
domain: { x: DomainTuple; y: DomainTuple },
props: VictoryBrushContainerProps,
) => void;
onBrushDomainChange?: (
domain: { x: DomainTuple; y: DomainTuple },
props: VictoryBrushContainerProps,
) => void;
onBrushDomainChangeEnd?: (
domain: { x: DomainTuple; y: DomainTuple },
props: VictoryBrushContainerProps,
) => void;
}

export const brushContainerMixin = (base) =>
type Constructor = new (...ars: any[]) => React.Component;
ramenhog marked this conversation as resolved.
Show resolved Hide resolved

export const brushContainerMixin = <TBase extends Constructor>(base: TBase) =>
class VictoryBrushContainer extends base {
static displayName = "VictoryBrushContainer";
static propTypes = {
Expand Down Expand Up @@ -176,7 +210,7 @@ export const brushContainerMixin = (base) =>
: memo;
return memo;
},
[],
[] as React.ReactElement[],
);
return handles.length ? handles : null;
}
Expand All @@ -201,4 +235,4 @@ export const brushContainerMixin = (base) =>
}
};

export default brushContainerMixin(VictoryContainer);
export const VictoryBrushContainer = brushContainerMixin(VictoryContainer);
3 changes: 2 additions & 1 deletion packages/victory-core/src/victory-util/selection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { Collection, VictoryCommonProps } from "./index";
import type { DomainPropType, ScaleXYPropType } from "../types/prop-types";
import { Tuple } from "../../lib";
scottrippey marked this conversation as resolved.
Show resolved Hide resolved

// Private Functions

Expand Down Expand Up @@ -83,7 +84,7 @@ export function getSVGEventCoordinates(
export function getDomainCoordinates(
props: Pick<VictoryCommonProps, "scale" | "horizontal">,
domain?: DomainPropType,
): DomainPropType {
): { x: Tuple<number>; y: Tuple<number> } {
scottrippey marked this conversation as resolved.
Show resolved Hide resolved
const { horizontal } = props;
const scale = props.scale as ScaleXYPropType;
// FIXME: add support for DomainTuple: [number, number]
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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