victory-bar 37.3.1 → 37.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import React from "react";
2
2
  import { Data, Domain, EventPropTypeInterface, NumberOrCallback, StringOrNumberOrCallback, VictoryCommonProps, VictoryDatableProps, VictoryMultiLabelableProps, VictoryStyleInterface, EventsMixinClass } from "victory-core";
3
- export declare type VictoryBarCornerRadiusKey = "top" | "bottom" | "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
4
- export declare type VictoryBarCornerRadiusObject = Partial<Record<VictoryBarCornerRadiusKey, NumberOrCallback>>;
5
- export declare type VictoryBarTTargetType = "data" | "labels" | "parent";
6
- export declare type VictoryBarAlignmentType = "start" | "middle" | "end";
3
+ export type VictoryBarCornerRadiusKey = "top" | "bottom" | "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
4
+ export type VictoryBarCornerRadiusObject = Partial<Record<VictoryBarCornerRadiusKey, NumberOrCallback>>;
5
+ export type VictoryBarTTargetType = "data" | "labels" | "parent";
6
+ export type VictoryBarAlignmentType = "start" | "middle" | "end";
7
7
  export interface VictoryBarProps extends VictoryCommonProps, VictoryDatableProps, VictoryMultiLabelableProps {
8
8
  alignment?: VictoryBarAlignmentType;
9
9
  barRatio?: number;
@@ -64,6 +64,7 @@ declare class VictoryBarBase extends React.Component<VictoryBarProps> {
64
64
  static getData: typeof Data.getData;
65
65
  static getBaseProps(props: VictoryBarProps): any;
66
66
  static expectedComponents: (keyof VictoryBarProps)[];
67
+ static shouldRenderDatum: () => boolean;
67
68
  shouldAnimate(): boolean;
68
69
  render(): React.ReactElement;
69
70
  }
@@ -93,9 +94,9 @@ export declare const VictoryBar: {
93
94
  getAllEvents(props: any): any;
94
95
  getComponentProps(component: React.ReactNode, type: string, index: string | number): any;
95
96
  renderContainer(component: any, children: any): React.DetailedReactHTMLElement<any, HTMLElement>;
96
- animateComponent(props: import("victory-core").EventMixinCommonProps, defaultAnimationWhitelist: string[]): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
97
+ animateComponent(props: import("victory-core").EventMixinCommonProps, defaultAnimationWhitelist: string[]): React.ReactElement;
97
98
  renderContinuousData(props: import("victory-core").EventMixinCommonProps): React.DetailedReactHTMLElement<any, HTMLElement>;
98
- renderData(props: any, shouldRenderDatum?: ((datum: any) => boolean) | undefined): React.DetailedReactHTMLElement<any, HTMLElement>;
99
+ renderData(props: any, shouldRenderDatum?: (datum: any) => boolean): React.DetailedReactHTMLElement<any, HTMLElement>;
99
100
  context: unknown;
100
101
  setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<import("victory-core").EventMixinCommonProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
101
102
  forceUpdate(callback?: (() => void) | undefined): void;
@@ -112,17 +113,17 @@ export declare const VictoryBar: {
112
113
  UNSAFE_componentWillReceiveProps?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextContext: any): void;
113
114
  componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
114
115
  UNSAFE_componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
115
- componentEvents: import("victory-core/lib/victory-util/events").ComponentEvent[];
116
+ componentEvents: Array<import("@/victory-core/lib/victory-util/events").ComponentEvent>;
116
117
  getSharedEventState: (key: string, value: string) => unknown;
117
118
  baseProps: Record<string, object>;
118
119
  dataKeys: string[];
119
120
  hasEvents: unknown;
120
121
  events: unknown;
121
122
  };
122
- getBaseProps?(props: import("victory-core").EventMixinCommonProps): Record<string, object>;
123
- role?: string | undefined;
123
+ getBaseProps?(props: import("victory-core").EventMixinCommonProps): import("victory-core").EventMixinCalculatedValues["baseProps"];
124
+ role?: import("victory-core").VictoryComponentRole;
124
125
  expectedComponents?: string[] | undefined;
125
- getChildren?: ((props: import("victory-core").EventMixinCommonProps, childComponents?: React.ReactNode[] | undefined, calculatedProps?: import("victory-core").EventMixinCommonProps | undefined) => void) | undefined;
126
+ getChildren?: ((props: import("victory-core").EventMixinCommonProps, childComponents?: Array<React.ReactNode>, calculatedProps?: import("victory-core").EventMixinCommonProps | undefined) => void) | undefined;
126
127
  animationWhitelist?: string[] | undefined;
127
128
  } & typeof VictoryBarBase;
128
129
  export {};
@@ -28,7 +28,7 @@ const defaultData = [{
28
28
  y: 4
29
29
  }];
30
30
 
31
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
31
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
32
32
 
33
33
  /**
34
34
  * Draw SVG bar charts with React. VictoryBar is a composable component, so it doesn"t include axes
@@ -92,7 +92,9 @@ class VictoryBarBase extends _react.default.Component {
92
92
  return (0, _helperMethods.getBaseProps)(props, fallbackProps);
93
93
  }
94
94
  static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
95
-
95
+ // passed to addEvents.renderData to prevent data props with undefined _x or _y from excluding data from render.
96
+ // used when inside of VictoryZoomContainer
97
+ static shouldRenderDatum = () => true;
96
98
  // Overridden in native versions
97
99
  shouldAnimate() {
98
100
  return !!this.props.animate;
@@ -106,7 +108,15 @@ class VictoryBarBase extends _react.default.Component {
106
108
  if (this.shouldAnimate()) {
107
109
  return this.animateComponent(props, animationWhitelist);
108
110
  }
109
- const children = this.renderData(props);
111
+ let children;
112
+ // when inside a zoom container (the only place VictoryClipContainer is used), all data
113
+ // should be renderable so bars won't dissappear before they've fully exited the container's bounds
114
+ // see https://github.com/FormidableLabs/victory/pull/2970
115
+ if (props.groupComponent.type === _victoryCore.VictoryClipContainer) {
116
+ children = this.renderData(props, VictoryBarBase.shouldRenderDatum);
117
+ } else {
118
+ children = this.renderData(props);
119
+ }
110
120
  const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children;
111
121
  return _victoryCore.UserProps.withSafeUserProps(component, props);
112
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-bar",
3
- "version": "37.3.1",
3
+ "version": "37.3.3",
4
4
  "description": "Bar Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -21,8 +21,8 @@
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "lodash": "^4.17.19",
24
- "victory-core": "37.3.1",
25
- "victory-vendor": "37.3.1"
24
+ "victory-core": "37.3.3",
25
+ "victory-vendor": "37.3.3"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": ">=16.6.0"
@@ -190,38 +190,10 @@
190
190
  "pnpm-lock.yaml"
191
191
  ]
192
192
  },
193
- "format": {
194
- "command": "nps format:pkg",
195
- "files": [
196
- "src/**",
197
- "*.json",
198
- "../../.prettierignore",
199
- "../../.prettierrc.json"
200
- ],
201
- "output": [],
202
- "packageLocks": [
203
- "pnpm-lock.yaml"
204
- ]
205
- },
206
- "format:fix": {
207
- "command": "pnpm run format || nps format:pkg:fix",
208
- "files": [
209
- "src/**",
210
- "*.json",
211
- "../../.prettierignore",
212
- "../../.prettierrc.json"
213
- ],
214
- "output": [],
215
- "packageLocks": [
216
- "pnpm-lock.yaml"
217
- ]
218
- },
219
193
  "lint": {
220
- "command": "nps lint:pkg",
194
+ "command": "eslint src",
221
195
  "files": [
222
- "src/**",
223
- "../../.eslintignore",
224
- "../../.eslintrc.js"
196
+ "src/**"
225
197
  ],
226
198
  "output": [],
227
199
  "dependencies": [
@@ -236,11 +208,9 @@
236
208
  ]
237
209
  },
238
210
  "lint:fix": {
239
- "command": "pnpm run lint || nps lint:pkg:fix",
211
+ "command": "eslint --fix src",
240
212
  "files": [
241
- "src/**",
242
- "../../.eslintignore",
243
- "../../.eslintrc.js"
213
+ "src/**"
244
214
  ],
245
215
  "output": [],
246
216
  "dependencies": [
@@ -287,8 +257,6 @@
287
257
  "check": "wireit",
288
258
  "types:check": "wireit",
289
259
  "types:create": "wireit",
290
- "format": "wireit",
291
- "format:fix": "wireit",
292
260
  "lint": "wireit",
293
261
  "lint:fix": "wireit",
294
262
  "jest": "wireit"
@@ -1,4 +1,4 @@
1
- import { isPlainObject } from "lodash";
1
+ import isPlainObject from "lodash/isPlainObject";
2
2
  import { Helpers, VictoryStyleObject } from "victory-core";
3
3
  import { BarProps } from "./bar";
4
4
  import {
package/src/bar.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { forwardRef } from "react";
2
- import { defaults } from "lodash";
2
+ import defaults from "lodash/defaults";
3
3
  import {
4
4
  Helpers,
5
5
  NumberOrCallback,
@@ -74,37 +74,36 @@ const defaultProps: Partial<BarProps> = {
74
74
  shapeRendering: "auto",
75
75
  };
76
76
 
77
- // eslint-disable-next-line prefer-arrow-callback
78
- export const Bar = forwardRef<SVGPathElement, BarProps>(function Bar(
79
- initialProps,
80
- ref,
81
- ) {
82
- const props = evaluateProps(defaults({}, initialProps, defaultProps));
83
- const { polar, origin, style, barWidth, cornerRadius } = props;
77
+ export const Bar = forwardRef<SVGPathElement, BarProps>(
78
+ // eslint-disable-next-line prefer-arrow-callback
79
+ function Bar(initialProps, ref) {
80
+ const props = evaluateProps(defaults({}, initialProps, defaultProps));
81
+ const { polar, origin, style, barWidth, cornerRadius } = props;
84
82
 
85
- const path = polar
86
- ? getPolarBarPath(props, cornerRadius)
87
- : getBarPath(props, barWidth, cornerRadius);
88
- const defaultTransform =
89
- polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined;
83
+ const path = polar
84
+ ? getPolarBarPath(props, cornerRadius)
85
+ : getBarPath(props, barWidth, cornerRadius);
86
+ const defaultTransform =
87
+ polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined;
90
88
 
91
- if (!props.pathComponent) {
92
- return null;
93
- }
89
+ if (!props.pathComponent) {
90
+ return null;
91
+ }
94
92
 
95
- return React.cloneElement(props.pathComponent, {
96
- ...props.events,
97
- "aria-label": props.ariaLabel,
98
- style,
99
- d: path,
100
- className: props.className,
101
- clipPath: props.clipPath,
102
- desc: props.desc,
103
- index: props.index,
104
- role: props.role,
105
- shapeRendering: props.shapeRendering,
106
- transform: props.transform || defaultTransform,
107
- tabIndex: props.tabIndex,
108
- ref,
109
- });
110
- });
93
+ return React.cloneElement(props.pathComponent, {
94
+ ...props.events,
95
+ "aria-label": props.ariaLabel,
96
+ style,
97
+ d: path,
98
+ className: props.className,
99
+ clipPath: props.clipPath,
100
+ desc: props.desc,
101
+ index: props.index,
102
+ role: props.role,
103
+ shapeRendering: props.shapeRendering,
104
+ transform: props.transform || defaultTransform,
105
+ tabIndex: props.tabIndex,
106
+ ref,
107
+ });
108
+ },
109
+ );
@@ -66,7 +66,6 @@ export const circle = (center: Center, radius: number) => ({
66
66
  // Left-most point is returned as 0th element of array
67
67
  // Right-most point is returned as 1st elemennt of array
68
68
  intersection(circle1: { center: Center; radius: number }) {
69
- // eslint-disable-line max-statements
70
69
  const P0 = this.center;
71
70
  const P1 = circle1.center;
72
71
  const r0 = this.radius;
@@ -5,6 +5,7 @@ import {
5
5
  Helpers,
6
6
  LabelHelpers,
7
7
  Scale,
8
+ VictoryClipContainer,
8
9
  } from "victory-core";
9
10
 
10
11
  export const getBarPosition = (props, datum) => {
@@ -61,6 +62,12 @@ const getCalculatedValues = (props) => {
61
62
  let data = Data.getData(props);
62
63
  data = Data.formatDataFromDomain(data, domain, 0);
63
64
 
65
+ // when inside a zoom container, reset the _x and _y properties of each datum to the original
66
+ // x and y property values so they will not be clipped. See https://github.com/FormidableLabs/victory/pull/2970
67
+ if (props.groupComponent.type === VictoryClipContainer) {
68
+ data = data.map((datum) => ({ ...datum, _x: datum.x, _y: datum.y }));
69
+ }
70
+
64
71
  return { style, data, scale, domain, origin };
65
72
  };
66
73
 
@@ -119,7 +119,6 @@ const mapPointsToPath = (coords, cornerRadius, direction) => {
119
119
  const getVerticalBarPoints = (position, sign, cr) => {
120
120
  const { x0, x1, y0, y1 } = position;
121
121
 
122
- // eslint-disable-next-line max-statements, max-len
123
122
  const getHalfPoints = (side) => {
124
123
  const isLeft = side === "Left";
125
124
  const signL = isLeft ? 1 : -1;
@@ -177,7 +176,6 @@ const getHorizontalBarPoints = (position, sign, cr) => {
177
176
  const x0 = position.x0 < position.x1 ? position.x0 : position.x1;
178
177
  const x1 = position.x0 < position.x1 ? position.x1 : position.x0;
179
178
 
180
- // eslint-disable-next-line max-statements, max-len
181
179
  const getHalfPoints = (side) => {
182
180
  const isTop = side === "top";
183
181
  const signL = isTop ? -1 : 1;
@@ -234,7 +232,6 @@ const getHorizontalBarPoints = (position, sign, cr) => {
234
232
  ];
235
233
  };
236
234
 
237
- // eslint-disable-next-line max-params
238
235
  export const getVerticalBarPath = (props, width, cornerRadius) => {
239
236
  const position = getPosition(props, width);
240
237
 
@@ -244,7 +241,6 @@ export const getVerticalBarPath = (props, width, cornerRadius) => {
244
241
  return mapPointsToPath(points, cornerRadius, direction);
245
242
  };
246
243
 
247
- // eslint-disable-next-line max-params
248
244
  export const getHorizontalBarPath = (props, width, cornerRadius) => {
249
245
  const position = getPosition(props, width);
250
246
 
@@ -310,7 +306,6 @@ export const getVerticalPolarBarPath = (props: BarProps, cornerRadius) => {
310
306
  };
311
307
  };
312
308
 
313
- // eslint-disable-next-line max-statements
314
309
  const getTopPath = () => {
315
310
  const { topRight, topLeft } = cornerRadius;
316
311
  const arcLength = r2 * Math.abs(end - start);
@@ -360,7 +355,6 @@ export const getVerticalPolarBarPath = (props: BarProps, cornerRadius) => {
360
355
  }));
361
356
  };
362
357
 
363
- // eslint-disable-next-line max-statements
364
358
  const getBottomPath = () => {
365
359
  const { bottomRight, bottomLeft } = cornerRadius;
366
360
  const arcLength = r1 * Math.abs(end - start);
@@ -13,6 +13,7 @@ import {
13
13
  EventPropTypeInterface,
14
14
  NumberOrCallback,
15
15
  StringOrNumberOrCallback,
16
+ VictoryClipContainer,
16
17
  VictoryCommonProps,
17
18
  VictoryDatableProps,
18
19
  VictoryMultiLabelableProps,
@@ -66,7 +67,7 @@ const defaultData = [
66
67
  { x: 4, y: 4 },
67
68
  ];
68
69
 
69
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
70
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
70
71
  interface VictoryBarBase extends EventsMixinClass<VictoryBarProps> {}
71
72
 
72
73
  /**
@@ -127,7 +128,9 @@ class VictoryBarBase extends React.Component<VictoryBarProps> {
127
128
  "groupComponent",
128
129
  "containerComponent",
129
130
  ];
130
-
131
+ // passed to addEvents.renderData to prevent data props with undefined _x or _y from excluding data from render.
132
+ // used when inside of VictoryZoomContainer
133
+ static shouldRenderDatum = () => true;
131
134
  // Overridden in native versions
132
135
  shouldAnimate() {
133
136
  return !!this.props.animate;
@@ -141,7 +144,15 @@ class VictoryBarBase extends React.Component<VictoryBarProps> {
141
144
  return this.animateComponent(props, animationWhitelist);
142
145
  }
143
146
 
144
- const children = this.renderData(props);
147
+ let children;
148
+ // when inside a zoom container (the only place VictoryClipContainer is used), all data
149
+ // should be renderable so bars won't dissappear before they've fully exited the container's bounds
150
+ // see https://github.com/FormidableLabs/victory/pull/2970
151
+ if (props.groupComponent.type === VictoryClipContainer) {
152
+ children = this.renderData(props, VictoryBarBase.shouldRenderDatum);
153
+ } else {
154
+ children = this.renderData(props);
155
+ }
145
156
 
146
157
  const component = props.standalone
147
158
  ? this.renderContainer(props.containerComponent, children)