victory-bar 36.7.0 → 36.8.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/victory-bar.js +278 -415
  3. package/dist/victory-bar.min.js +1 -1
  4. package/es/bar-helper-methods.d.ts +7 -0
  5. package/es/bar-helper-methods.js +7 -3
  6. package/es/bar.d.ts +20 -0
  7. package/es/bar.js +15 -34
  8. package/es/geometry-helper-methods.d.ts +91 -0
  9. package/es/geometry-helper-methods.js +4 -13
  10. package/es/helper-methods.d.ts +8 -0
  11. package/es/index.d.ts +6 -73
  12. package/es/index.js +2 -2
  13. package/es/path-helper-methods.d.ts +7 -0
  14. package/es/path-helper-methods.js +2 -2
  15. package/es/victory-bar.d.ts +129 -0
  16. package/es/victory-bar.js +24 -42
  17. package/lib/bar-helper-methods.d.ts +7 -0
  18. package/lib/bar-helper-methods.js +8 -3
  19. package/lib/bar.d.ts +20 -0
  20. package/lib/bar.js +14 -34
  21. package/lib/geometry-helper-methods.d.ts +91 -0
  22. package/lib/geometry-helper-methods.js +3 -10
  23. package/lib/helper-methods.d.ts +8 -0
  24. package/lib/index.d.ts +6 -73
  25. package/lib/index.js +39 -17
  26. package/lib/path-helper-methods.d.ts +7 -0
  27. package/lib/path-helper-methods.js +2 -2
  28. package/lib/victory-bar.d.ts +129 -0
  29. package/lib/victory-bar.js +26 -47
  30. package/package.json +3 -3
  31. package/src/{bar-helper-methods.js → bar-helper-methods.ts} +36 -11
  32. package/src/{bar.js → bar.tsx} +44 -41
  33. package/src/geometry-helper-methods.ts +103 -0
  34. package/src/{helper-methods.js → helper-methods.ts} +2 -2
  35. package/src/{index.js → index.ts} +2 -2
  36. package/src/{path-helper-methods.js → path-helper-methods.ts} +11 -8
  37. package/src/{victory-bar.js → victory-bar.tsx} +57 -32
  38. package/es/v37/victory-bar-v1.d.ts +0 -24
  39. package/es/v37/victory-bar-v1.js +0 -102
  40. package/es/v37/victory-bar-v2.d.ts +0 -24
  41. package/es/v37/victory-bar-v2.js +0 -97
  42. package/es/v37/victory-bar.stories.d.ts +0 -19
  43. package/es/v37/victory-bar.stories.js +0 -22
  44. package/lib/v37/victory-bar-v1.d.ts +0 -24
  45. package/lib/v37/victory-bar-v1.js +0 -123
  46. package/lib/v37/victory-bar-v2.d.ts +0 -24
  47. package/lib/v37/victory-bar-v2.js +0 -114
  48. package/lib/v37/victory-bar.stories.d.ts +0 -19
  49. package/lib/v37/victory-bar.stories.js +0 -45
  50. package/src/geometry-helper-methods.js +0 -113
  51. package/src/index.d.ts +0 -73
  52. package/src/v37/victory-bar-v1.tsx +0 -129
  53. package/src/v37/victory-bar-v2.tsx +0 -96
  54. package/src/v37/victory-bar.stories.tsx +0 -28
@@ -1,113 +0,0 @@
1
- /**
2
- * A point in the 2d plane
3
- * @param {number} x - x coordinate
4
- * @param {number} y - y coordinate
5
- * @returns {object} - point object
6
- */
7
- const point = function (x, y) {
8
- return {
9
- x,
10
- y,
11
- distance(p1) {
12
- return Math.sqrt(Math.pow(this.x - p1.x, 2) + Math.pow(this.y - p1.y, 2));
13
- },
14
- // vector addition in 2d plane
15
- add(p1) {
16
- return point(this.x + p1.x, this.y + p1.y);
17
- },
18
- // vector subtraction in 2d
19
- // returns p0 - p1
20
- subtract(p1) {
21
- return point(this.x - p1.x, this.y - p1.y);
22
- },
23
- // multiply a 2d point by a scalar
24
- scalarMult(n) {
25
- return point(this.x * n, this.y * n);
26
- },
27
- scalarDivide(n) {
28
- if (n === 0) {
29
- throw new Error("Division by 0 error");
30
- }
31
- return point(this.x / n, this.y / n);
32
- },
33
- equals(p1) {
34
- return this.x === p1.x && this.y === p1.y;
35
- },
36
- };
37
- };
38
-
39
- /**
40
- * A circle in the 2d plane
41
- * @param {point} center - center of circle
42
- * @param {number} radius - radius of circle
43
- * @returns {object} - point object
44
- */
45
- const circle = function (center, radius) {
46
- return {
47
- center,
48
- radius,
49
- hasIntersection(circle1) {
50
- const P0 = this.center;
51
- const P1 = circle1.center;
52
- const r0 = this.radius;
53
- const r1 = circle1.radius;
54
- const d = P0.distance(P1);
55
-
56
- if (d > r0 + r1) {
57
- return false; // separate circles
58
- }
59
- if (d < Math.abs(r0 - r1)) {
60
- return false; // one circle contains another
61
- }
62
- return true;
63
- },
64
- equals(circle1) {
65
- const P0 = this.center;
66
- const P1 = circle1.center;
67
- const r0 = this.radius;
68
- const r1 = circle1.radius;
69
- return r0 === r1 && P0.equals(P1);
70
- },
71
- // Source: http://paulbourke.net/geometry/circlesphere/
72
- // "Intersection of two circles" by Paul Bourke
73
- // Left-most point is returned as 0th element of array
74
- // Right-most point is returned as 1st elemennt of array
75
- intersection(circle1) {
76
- // eslint-disable-line max-statements
77
- const P0 = this.center;
78
- const P1 = circle1.center;
79
- const r0 = this.radius;
80
- const r1 = circle1.radius;
81
- const d = P0.distance(P1);
82
- if (!this.hasIntersection(circle1) || this.equals(circle1)) {
83
- return [];
84
- }
85
- const a = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d);
86
- const h = Math.sqrt(Math.pow(r0, 2) - Math.pow(a, 2));
87
- const P2 = P0.add(P1.subtract(P0).scalarMult(a).scalarDivide(d));
88
- const { x: x0, y: y0 } = P0;
89
- const { x: x1, y: y1 } = P1;
90
- const { x: x2, y: y2 } = P2;
91
- const P3s = [
92
- point(x2 - (h * (y1 - y0)) / d, y2 + (h * (x1 - x0)) / d),
93
- point(x2 + (h * (y1 - y0)) / d, y2 - (h * (x1 - x0)) / d),
94
- ];
95
- P3s.sort((Point1, Point2) => Point1.x - Point2.x);
96
- return P3s;
97
- },
98
- solveX(y) {
99
- const sqrt = Math.sqrt(
100
- Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2),
101
- );
102
- return [this.center.x - sqrt, this.center.x + sqrt];
103
- },
104
- solveY(x) {
105
- const sqrt = Math.sqrt(
106
- Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2),
107
- );
108
- return [this.center.y - sqrt, this.center.y + sqrt];
109
- },
110
- };
111
- };
112
-
113
- export { circle, point };
package/src/index.d.ts DELETED
@@ -1,73 +0,0 @@
1
- import * as React from "react";
2
- import {
3
- EventPropTypeInterface,
4
- NumberOrCallback,
5
- StringOrNumberOrCallback,
6
- VictoryCommonProps,
7
- VictoryCommonPrimitiveProps,
8
- VictoryDatableProps,
9
- VictoryMultiLabelableProps,
10
- VictoryStyleInterface,
11
- } from "victory-core";
12
-
13
- export type VictoryBarTTargetType = "data" | "labels" | "parent";
14
- export type VictoryBarAlignmentType = "start" | "middle" | "end";
15
-
16
- export interface VictoryBarProps
17
- extends VictoryCommonProps,
18
- VictoryDatableProps,
19
- VictoryMultiLabelableProps {
20
- alignment?: VictoryBarAlignmentType;
21
- barRatio?: number;
22
- barWidth?: NumberOrCallback;
23
- cornerRadius?:
24
- | NumberOrCallback
25
- | {
26
- top?: NumberOrCallback;
27
- topLeft?: NumberOrCallback;
28
- topRight?: NumberOrCallback;
29
- bottom?: NumberOrCallback;
30
- bottomLeft?: NumberOrCallback;
31
- bottomRight?: NumberOrCallback;
32
- };
33
- events?: EventPropTypeInterface<
34
- VictoryBarTTargetType,
35
- number | string | number[] | string[]
36
- >[];
37
- eventKey?: StringOrNumberOrCallback;
38
- horizontal?: boolean;
39
- style?: VictoryStyleInterface;
40
- }
41
-
42
- /**
43
- * Draw SVG bar charts with React. VictoryBar is a composable component, so it doesn"t include axes
44
- * Check out VictoryChart for complete bar charts and more.
45
- */
46
- export class VictoryBar extends React.Component<VictoryBarProps, any> {}
47
-
48
- export interface BarProps extends VictoryCommonPrimitiveProps {
49
- alignment?: VictoryBarAlignmentType;
50
- barOffset?: number[];
51
- barRatio?: number;
52
- barWidth?: NumberOrCallback;
53
- cornerRadius?:
54
- | NumberOrCallback
55
- | {
56
- top?: NumberOrCallback;
57
- topLeft?: NumberOrCallback;
58
- topRight?: NumberOrCallback;
59
- bottom?: NumberOrCallback;
60
- bottomLeft?: NumberOrCallback;
61
- bottomRight?: NumberOrCallback;
62
- };
63
- datum?: any;
64
- getPath?: Function;
65
- horizontal?: boolean;
66
- pathComponent?: React.ReactElement;
67
- width?: number;
68
- x?: number;
69
- y?: number;
70
- y0?: number;
71
- }
72
-
73
- export class Bar extends React.Component<BarProps, any> {}
@@ -1,129 +0,0 @@
1
- /* eslint-disable react/no-multi-comp */
2
- import * as React from "react";
3
- import {
4
- Datum,
5
- NumberOrCallback,
6
- VictoryCommonProps,
7
- VictoryContainer,
8
- VictoryDatableProps,
9
- } from "victory-core";
10
- import {
11
- useData,
12
- useDomain,
13
- useScale,
14
- VictoryProvider,
15
- VictoryProviderProps,
16
- } from "victory-core/es/v37";
17
- import Bar from "../bar";
18
- import { getBarPosition } from "../helper-methods";
19
-
20
- // This is a demo component that uses VictoryProvider to access calculated props and state.
21
- // This component does not include events, animations, or styling.
22
- // To test out, swap out the VictoryBar export in ./index.js and run `pnpm run storybook:server`.
23
-
24
- const defaultProps: VictoryProviderProps = {
25
- data: [
26
- { x: 1, y: 1 },
27
- { x: 2, y: 2 },
28
- { x: 3, y: 3 },
29
- { x: 4, y: 4 },
30
- ],
31
- height: 300,
32
- includeZero: true,
33
- padding: 50,
34
- sortOrder: "ascending" as const,
35
- width: 450,
36
- };
37
-
38
- export type VictoryBarAlignmentType = "start" | "middle" | "end";
39
- export interface VictoryBarProps
40
- extends VictoryCommonProps,
41
- VictoryDatableProps {
42
- alignment?: VictoryBarAlignmentType;
43
- barRatio?: number;
44
- barWidth?: NumberOrCallback;
45
- cornerRadius?:
46
- | NumberOrCallback
47
- | {
48
- top?: NumberOrCallback;
49
- topLeft?: NumberOrCallback;
50
- topRight?: NumberOrCallback;
51
- bottom?: NumberOrCallback;
52
- bottomLeft?: NumberOrCallback;
53
- bottomRight?: NumberOrCallback;
54
- };
55
- dataComponent?: React.ReactElement;
56
- groupComponent?: React.ReactElement;
57
- horizontal?: boolean;
58
- }
59
-
60
- // TODO: This would be a shared helper that allows us to access context values in the base component
61
- export function withContainer<Props extends VictoryCommonProps>(
62
- WrappedComponent: (props: Props) => React.ReactElement,
63
- initialProviderProps: Partial<VictoryProviderProps> = {},
64
- ) {
65
- return (props: Props) => {
66
- const providerProps = {
67
- ...initialProviderProps,
68
- ...props,
69
- };
70
- const { standalone = true, containerComponent = <VictoryContainer /> } =
71
- props;
72
- if (standalone) {
73
- return (
74
- <VictoryProvider {...providerProps}>
75
- {React.cloneElement(
76
- containerComponent,
77
- providerProps,
78
- <WrappedComponent {...props} />,
79
- )}
80
- </VictoryProvider>
81
- );
82
- }
83
- return (
84
- <VictoryProvider {...providerProps}>
85
- <WrappedComponent {...props} />
86
- </VictoryProvider>
87
- );
88
- };
89
- }
90
-
91
- function VictoryBar({
92
- dataComponent = <Bar />,
93
- groupComponent = <g role="presentation" />,
94
- alignment,
95
- barRatio,
96
- barWidth,
97
- cornerRadius,
98
- horizontal = false,
99
- }: VictoryBarProps) {
100
- const scale = useScale();
101
- const data = useData();
102
- const domain = useDomain();
103
-
104
- const children = data.map((datum: Datum, i: number) => {
105
- const { x, y, x0, y0 } = getBarPosition(
106
- { domain, scale, horizontal },
107
- datum,
108
- );
109
- const dataProps = {
110
- index: i,
111
- key: `bar-${i}`,
112
- alignment,
113
- barRatio,
114
- barWidth,
115
- cornerRadius,
116
- scale,
117
- data,
118
- x,
119
- y,
120
- x0,
121
- y0,
122
- datum,
123
- };
124
- return React.cloneElement(dataComponent, dataProps);
125
- });
126
- return React.cloneElement(groupComponent, {}, children);
127
- }
128
-
129
- export default withContainer<VictoryBarProps>(VictoryBar, defaultProps);
@@ -1,96 +0,0 @@
1
- /* eslint-disable react/no-multi-comp */
2
- import * as React from "react";
3
- import { Datum, NumberOrCallback } from "victory-core";
4
- import {
5
- useData,
6
- useDomain,
7
- useScale,
8
- useVictoryProviderSync,
9
- VictoryCalculatedStateProps,
10
- withContainer,
11
- } from "victory-core/es/v37";
12
-
13
- import Bar from "../bar";
14
- import { BarProps } from "..";
15
- import { getBarPosition } from "../helper-methods";
16
-
17
- export type VictoryBarAlignmentType = "start" | "middle" | "end";
18
- export interface VictoryBarProps extends VictoryCalculatedStateProps {
19
- alignment?: VictoryBarAlignmentType;
20
- barRatio?: number;
21
- barWidth?: NumberOrCallback;
22
- cornerRadius?:
23
- | NumberOrCallback
24
- | {
25
- top?: NumberOrCallback;
26
- topLeft?: NumberOrCallback;
27
- topRight?: NumberOrCallback;
28
- bottom?: NumberOrCallback;
29
- bottomLeft?: NumberOrCallback;
30
- bottomRight?: NumberOrCallback;
31
- };
32
- data?: Datum[];
33
- dataComponent?: React.ReactElement;
34
- groupComponent?: React.ReactElement;
35
- horizontal?: boolean;
36
- }
37
-
38
- function VictoryBar({
39
- alignment = "middle",
40
- barRatio,
41
- barWidth,
42
- cornerRadius,
43
- data = [
44
- { x: 1, y: 1 },
45
- { x: 2, y: 2 },
46
- { x: 3, y: 3 },
47
- { x: 4, y: 4 },
48
- ],
49
- dataComponent = <Bar />,
50
- groupComponent = <g role="presentation" />,
51
- includeZero = true,
52
- horizontal = false,
53
- sortOrder = "ascending",
54
- ...props
55
- }: VictoryBarProps) {
56
- // Typescript works best when we provide defaults in the destructured
57
- // component props. However, I am anticipating confusion about which props
58
- // we will need to pass back up to the provider vs. the props that are only
59
- // used in this component.
60
- useVictoryProviderSync({
61
- data,
62
- includeZero,
63
- sortOrder,
64
- ...props,
65
- });
66
- const scale = useScale();
67
- const domain = useDomain();
68
-
69
- // TODO: Do we need to get this from context?
70
- const formattedData = useData();
71
-
72
- const barPositionProps = { domain, scale, horizontal };
73
-
74
- const children = formattedData.map((datum: Datum, i: number) => {
75
- const { x, y, y0 } = getBarPosition(barPositionProps, datum);
76
- const dataProps: BarProps & { key: string } = {
77
- index: i,
78
- key: `bar-${i}`,
79
- alignment,
80
- barRatio,
81
- barWidth,
82
- cornerRadius,
83
- scale,
84
- data,
85
- x,
86
- y,
87
- y0,
88
- datum,
89
- };
90
- return React.cloneElement(dataComponent, dataProps);
91
- });
92
- return React.cloneElement(groupComponent, {}, children);
93
- }
94
-
95
- // @ts-expect-error we need to work out what props this withContainer wrapper accepts
96
- export default withContainer<VictoryBarProps>(VictoryBar);
@@ -1,28 +0,0 @@
1
- /* eslint-disable react/no-multi-comp */
2
- import * as React from "react";
3
- import VictoryBar from "./victory-bar-v2";
4
- import VictoryChart from "victory-chart/es/v37/victory-chart";
5
-
6
- export default {
7
- title: "v37/VictoryBar",
8
- parameters: {
9
- chromatic: { disableSnapshot: true },
10
- },
11
- component: VictoryBar,
12
- };
13
-
14
- export const Demo = (props) => {
15
- return <VictoryBar {...props} />;
16
- };
17
-
18
- Demo.args = {
19
- barRatio: 0.5,
20
- };
21
-
22
- export const WithChart = (props) => {
23
- return (
24
- <VictoryChart {...props}>
25
- <VictoryBar />
26
- </VictoryChart>
27
- );
28
- };