@mbao01/common 0.0.44 → 0.0.45

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 (110) hide show
  1. package/dist/types/components/Chart/Chart.d.ts +2 -0
  2. package/dist/types/components/Chart/ChartContext.d.ts +2 -0
  3. package/dist/types/components/Chart/components/ChartLegend.d.ts +4 -0
  4. package/dist/types/components/Chart/components/ChartStyle.d.ts +2 -0
  5. package/dist/types/components/Chart/components/ChartTooltip.d.ts +4 -0
  6. package/dist/types/components/Chart/components/index.d.ts +3 -0
  7. package/dist/types/components/Chart/constants.d.ts +22 -0
  8. package/dist/types/components/Chart/helpers.d.ts +11 -0
  9. package/dist/types/components/Chart/hooks/index.d.ts +1 -0
  10. package/dist/types/components/Chart/hooks/useChart/index.d.ts +1 -0
  11. package/dist/types/components/Chart/hooks/useChart/useChart.d.ts +1 -0
  12. package/dist/types/components/Chart/index.d.ts +2 -0
  13. package/dist/types/components/Chart/stories/args/activeShapeArgs.d.ts +2 -0
  14. package/dist/types/components/Chart/stories/args/animationArgs.d.ts +12 -0
  15. package/dist/types/components/Chart/stories/args/areaArgs.d.ts +2 -0
  16. package/dist/types/components/Chart/stories/args/areaChartArgs.d.ts +2 -0
  17. package/dist/types/components/Chart/stories/args/barArgs.d.ts +5 -0
  18. package/dist/types/components/Chart/stories/args/barChartArgs.d.ts +2 -0
  19. package/dist/types/components/Chart/stories/args/cartesianChartArgs.d.ts +2 -0
  20. package/dist/types/components/Chart/stories/args/cartesianSharedArgs.d.ts +11 -0
  21. package/dist/types/components/Chart/stories/args/chartArgs.d.ts +6 -0
  22. package/dist/types/components/Chart/stories/args/dotArgs.d.ts +10 -0
  23. package/dist/types/components/Chart/stories/args/events.d.ts +804 -0
  24. package/dist/types/components/Chart/stories/args/labelListArgs.d.ts +2 -0
  25. package/dist/types/components/Chart/stories/args/legendArgs.d.ts +3 -0
  26. package/dist/types/components/Chart/stories/args/lineArgs.d.ts +2 -0
  27. package/dist/types/components/Chart/stories/args/lineChartArgs.d.ts +2 -0
  28. package/dist/types/components/Chart/stories/args/pieArgs.d.ts +2 -0
  29. package/dist/types/components/Chart/stories/args/pieChartArgs.d.ts +2 -0
  30. package/dist/types/components/Chart/stories/args/polarChartArgs.d.ts +2 -0
  31. package/dist/types/components/Chart/stories/args/polarSharedArgs.d.ts +2 -0
  32. package/dist/types/components/Chart/stories/args/radarArgs.d.ts +2 -0
  33. package/dist/types/components/Chart/stories/args/radarChartArgs.d.ts +2 -0
  34. package/dist/types/components/Chart/stories/args/radialBarArgs.d.ts +2 -0
  35. package/dist/types/components/Chart/stories/args/radialBarChartArgs.d.ts +2 -0
  36. package/dist/types/components/Chart/stories/args/rectangleArgs.d.ts +9 -0
  37. package/dist/types/components/Chart/stories/args/referenceSharedArgs.d.ts +4 -0
  38. package/dist/types/components/Chart/stories/args/sectorArgs.d.ts +7 -0
  39. package/dist/types/components/Chart/stories/args/sharedAxisArgs.d.ts +2 -0
  40. package/dist/types/components/Chart/stories/args/stylesArgs.d.ts +6 -0
  41. package/dist/types/components/Chart/stories/args/textArgs.d.ts +2 -0
  42. package/dist/types/components/Chart/stories/args/tooltipArgs.d.ts +4 -0
  43. package/dist/types/components/Chart/stories/args/types.d.ts +13 -0
  44. package/dist/types/components/Chart/stories/args/xAxisArgs.d.ts +2 -0
  45. package/dist/types/components/Chart/stories/args/yAxisArgs.d.ts +2 -0
  46. package/dist/types/components/Chart/stories/examples/AreaChart.d.ts +16 -0
  47. package/dist/types/components/Chart/stories/examples/BarChart.d.ts +20 -0
  48. package/dist/types/components/Chart/stories/examples/LineChart.d.ts +16 -0
  49. package/dist/types/components/Chart/stories/examples/PieChart.d.ts +19 -0
  50. package/dist/types/components/Chart/stories/examples/RadarChart.d.ts +24 -0
  51. package/dist/types/components/Chart/stories/examples/RadialChart.d.ts +17 -0
  52. package/dist/types/components/Chart/stories/examples/Tooltip.d.ts +15 -0
  53. package/dist/types/components/Chart/stories/helpers/index.d.ts +9 -0
  54. package/dist/types/components/Chart/types.d.ts +37 -0
  55. package/package.json +5 -3
  56. package/src/components/Chart/Chart.tsx +26 -0
  57. package/src/components/Chart/ChartContext.tsx +4 -0
  58. package/src/components/Chart/components/ChartLegend.tsx +52 -0
  59. package/src/components/Chart/components/ChartStyle.tsx +32 -0
  60. package/src/components/Chart/components/ChartTooltip.tsx +126 -0
  61. package/src/components/Chart/components/index.ts +3 -0
  62. package/src/components/Chart/constants.ts +78 -0
  63. package/src/components/Chart/helpers.ts +27 -0
  64. package/src/components/Chart/hooks/index.ts +1 -0
  65. package/src/components/Chart/hooks/useChart/index.ts +1 -0
  66. package/src/components/Chart/hooks/useChart/useChart.ts +12 -0
  67. package/src/components/Chart/index.ts +2 -0
  68. package/src/components/Chart/stories/args/activeShapeArgs.ts +34 -0
  69. package/src/components/Chart/stories/args/animationArgs.ts +67 -0
  70. package/src/components/Chart/stories/args/areaArgs.ts +16 -0
  71. package/src/components/Chart/stories/args/areaChartArgs.ts +19 -0
  72. package/src/components/Chart/stories/args/barArgs.ts +123 -0
  73. package/src/components/Chart/stories/args/barChartArgs.ts +65 -0
  74. package/src/components/Chart/stories/args/cartesianChartArgs.ts +42 -0
  75. package/src/components/Chart/stories/args/cartesianSharedArgs.ts +136 -0
  76. package/src/components/Chart/stories/args/chartArgs.ts +244 -0
  77. package/src/components/Chart/stories/args/dotArgs.ts +46 -0
  78. package/src/components/Chart/stories/args/events.ts +343 -0
  79. package/src/components/Chart/stories/args/index.ts +178 -0
  80. package/src/components/Chart/stories/args/labelListArgs.ts +124 -0
  81. package/src/components/Chart/stories/args/legendArgs.ts +205 -0
  82. package/src/components/Chart/stories/args/lineArgs.ts +87 -0
  83. package/src/components/Chart/stories/args/lineChartArgs.ts +17 -0
  84. package/src/components/Chart/stories/args/pieArgs.ts +18 -0
  85. package/src/components/Chart/stories/args/pieChartArgs.ts +7 -0
  86. package/src/components/Chart/stories/args/polarChartArgs.ts +86 -0
  87. package/src/components/Chart/stories/args/polarSharedArgs.ts +42 -0
  88. package/src/components/Chart/stories/args/radarArgs.ts +26 -0
  89. package/src/components/Chart/stories/args/radarChartArgs.ts +26 -0
  90. package/src/components/Chart/stories/args/radialBarArgs.ts +36 -0
  91. package/src/components/Chart/stories/args/radialBarChartArgs.ts +16 -0
  92. package/src/components/Chart/stories/args/rectangleArgs.ts +35 -0
  93. package/src/components/Chart/stories/args/referenceSharedArgs.ts +75 -0
  94. package/src/components/Chart/stories/args/sectorArgs.ts +106 -0
  95. package/src/components/Chart/stories/args/sharedAxisArgs.ts +332 -0
  96. package/src/components/Chart/stories/args/stylesArgs.ts +258 -0
  97. package/src/components/Chart/stories/args/textArgs.ts +97 -0
  98. package/src/components/Chart/stories/args/tooltipArgs.ts +41 -0
  99. package/src/components/Chart/stories/args/types.ts +23 -0
  100. package/src/components/Chart/stories/args/xAxisArgs.ts +109 -0
  101. package/src/components/Chart/stories/args/yAxisArgs.ts +73 -0
  102. package/src/components/Chart/stories/examples/AreaChart.tsx +156 -0
  103. package/src/components/Chart/stories/examples/BarChart.tsx +425 -0
  104. package/src/components/Chart/stories/examples/LineChart.tsx +144 -0
  105. package/src/components/Chart/stories/examples/PieChart.tsx +238 -0
  106. package/src/components/Chart/stories/examples/RadarChart.tsx +261 -0
  107. package/src/components/Chart/stories/examples/RadialChart.tsx +239 -0
  108. package/src/components/Chart/stories/examples/Tooltip.tsx +68 -0
  109. package/src/components/Chart/stories/helpers/index.tsx +75 -0
  110. package/src/components/Chart/types.ts +39 -0
@@ -0,0 +1,78 @@
1
+ import type { Theme } from "../../utilities";
2
+ import { cva } from "../../libs";
3
+
4
+ export const THEMES = {
5
+ light: "",
6
+ dark: ".dark",
7
+ } satisfies Record<Theme, string>;
8
+
9
+ export const getChartClasses = cva(
10
+ "flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-base-content [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-base-content/20 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-base-content/20 [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-base-content/20 [&_.recharts-radial-bar-background-sector]:fill-base-200 [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-base-200 [&_.recharts-reference-line_[stroke='#ccc']]:stroke-base-content/20 [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none"
11
+ );
12
+
13
+ export const getChartLegendContainerClasses = cva("flex items-center justify-center gap-4", {
14
+ variants: {
15
+ verticalAlign: {
16
+ top: "pb-3",
17
+ bottom: "pt-3",
18
+ middle: "",
19
+ },
20
+ },
21
+ });
22
+
23
+ export const getChartLegendItemClasses = cva("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3");
24
+
25
+ export const getChartLegendMarkerClasses = cva("h-2 w-2 shrink-0 rounded-[2px]");
26
+
27
+ export const getChartTooltipContainerClasses = cva(
28
+ "grid min-w-[8rem] items-start gap-1.5 rounded-md border border-border/50 bg-base-100 px-2.5 py-1.5 text-xs shadow-xl"
29
+ );
30
+
31
+ export const getChartTooltipItemClasses = cva(
32
+ "flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-base-content",
33
+ {
34
+ variants: {
35
+ indicator: {
36
+ dot: "items-center",
37
+ line: "",
38
+ dashed: "",
39
+ },
40
+ },
41
+ }
42
+ );
43
+
44
+ export const getChartTooltipItemLabelClasses = cva(
45
+ "flex flex-1 justify-between leading-none items-center",
46
+ {
47
+ variants: {
48
+ nestLabel: {
49
+ true: "items-end",
50
+ },
51
+ },
52
+ }
53
+ );
54
+
55
+ export const getChartTooltipItemValueClasses = cva("font-mono font-medium tabular-nums");
56
+
57
+ export const getChartTooltipItemIndicatorClasses = cva(
58
+ "shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",
59
+ {
60
+ variants: {
61
+ indicator: {
62
+ dot: "h-2.5 w-2.5",
63
+ line: "w-1",
64
+ dashed: "w-0 border-[1.5px] border-dashed bg-transparent",
65
+ },
66
+ nestLabel: {
67
+ true: "",
68
+ },
69
+ },
70
+ compoundVariants: [
71
+ {
72
+ indicator: "dashed",
73
+ nestLabel: true,
74
+ className: "my-0.5",
75
+ },
76
+ ],
77
+ }
78
+ );
@@ -0,0 +1,27 @@
1
+ import { type ChartConfig } from "./types";
2
+
3
+ // Helper to extract item config from a payload.
4
+ export const getPayloadConfigFromPayload = (config: ChartConfig, payload: unknown, key: string) => {
5
+ if (typeof payload !== "object" || payload === null) {
6
+ return undefined;
7
+ }
8
+
9
+ const payloadPayload =
10
+ "payload" in payload && typeof payload.payload === "object" && payload.payload !== null
11
+ ? payload.payload
12
+ : undefined;
13
+
14
+ let configLabelKey: string = key;
15
+
16
+ if (key in payload && typeof payload[key as keyof typeof payload] === "string") {
17
+ configLabelKey = payload[key as keyof typeof payload] as string;
18
+ } else if (
19
+ payloadPayload &&
20
+ key in payloadPayload &&
21
+ typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
22
+ ) {
23
+ configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
24
+ }
25
+
26
+ return configLabelKey in config ? config[configLabelKey] : config[key];
27
+ };
@@ -0,0 +1 @@
1
+ export { useChart } from "./useChart";
@@ -0,0 +1 @@
1
+ export { useChart } from "./useChart";
@@ -0,0 +1,12 @@
1
+ import { useContext } from "react";
2
+ import { ChartContext } from "../../ChartContext";
3
+
4
+ export const useChart = () => {
5
+ const context = useContext(ChartContext);
6
+
7
+ if (!context) {
8
+ throw new Error("useChart must be used within a <Chart />");
9
+ }
10
+
11
+ return context;
12
+ };
@@ -0,0 +1,2 @@
1
+ export { Chart } from "./Chart";
2
+ export * from "./components";
@@ -0,0 +1,34 @@
1
+ import { type ArgTypes } from "@storybook/react";
2
+
3
+ export const activeShapeArgs: ArgTypes = {
4
+ activeIndex: {
5
+ description:
6
+ "The index of the individual shapes of the graph element to be marked as active, and render props.activeShape",
7
+ table: {
8
+ category: "General",
9
+ },
10
+ control: "number",
11
+ },
12
+ shape: {
13
+ description: "The customized shape to be rendered.",
14
+ table: {
15
+ type: {
16
+ summary: "Function | boolean | ReactElement | object",
17
+ },
18
+ defaultValue: undefined,
19
+ category: "General",
20
+ },
21
+ control: "object",
22
+ },
23
+ activeShape: {
24
+ description: "The customized shape to be rendered if activeIndex or activeTooltipIndex match",
25
+ table: {
26
+ type: {
27
+ summary: "Function | boolean | ReactElement | object",
28
+ },
29
+ defaultValue: undefined,
30
+ category: "General",
31
+ },
32
+ control: "object",
33
+ },
34
+ };
@@ -0,0 +1,67 @@
1
+ /*
2
+ * This file both exports the documentation of shared props separately, to be reused in places where only single props
3
+ * are documented, as well as grouped in case a whole group is needed.
4
+ */
5
+
6
+ import { type ArgTypes } from "@storybook/react";
7
+
8
+ export const animateNewValues: ArgTypes[0] = { table: { category: "Animation" } };
9
+ export const animationBegin: ArgTypes[0] = {
10
+ description: "Specifies when the animation should begin, the unit of this option is ms.",
11
+ type: { name: "number" },
12
+ table: {
13
+ defaultValue: {
14
+ summary: "0",
15
+ },
16
+ category: "Animation",
17
+ },
18
+ control: "number",
19
+ };
20
+ export const animationDuration: ArgTypes[0] = {
21
+ description: "Specifies the duration of animation, the unit of this option is ms.",
22
+ table: {
23
+ type: {
24
+ summary: "number",
25
+ },
26
+ category: "Animation",
27
+ },
28
+ control: "number",
29
+ };
30
+ export const animationEasing: ArgTypes[0] = {
31
+ description: "The type of easing function.",
32
+ table: {
33
+ type: {
34
+ summary: "'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear'",
35
+ },
36
+ category: "Animation",
37
+ },
38
+ control: "select",
39
+ options: ["ease", "ease-in", "ease-out", "ease-in-out", "linear"],
40
+ };
41
+
42
+ export const isAnimationActive: ArgTypes[0] = {
43
+ description:
44
+ "If set false, animation of component will be disabled. This is `true` in CSR, and `false` in SSR",
45
+ table: {
46
+ type: {
47
+ summary: "boolean",
48
+ },
49
+ defaultValue: {
50
+ detail: "true in CSR, and false in SSR",
51
+ },
52
+ category: "Animation",
53
+ },
54
+ control: "boolean",
55
+ };
56
+
57
+ /**
58
+ * Caveat: If any prop is added here, it would falsely be add to the documentation of the component where this group
59
+ * is used. If the group is to be extended, then only single props should be imported by each component that does not
60
+ * use all of them.
61
+ * */
62
+ export const animationArgs: ArgTypes = {
63
+ animationBegin,
64
+ animationEasing,
65
+ animationDuration,
66
+ isAnimationActive,
67
+ };
@@ -0,0 +1,16 @@
1
+ import { type Args } from "@storybook/react";
2
+ import { lineArgs } from "./lineArgs";
3
+
4
+ export const areaArgs: Args = {
5
+ ...lineArgs,
6
+ fillOpacity: {
7
+ description: "The opacity of the fill.",
8
+ table: {
9
+ type: {
10
+ summary: "number",
11
+ },
12
+ category: "Style",
13
+ },
14
+ control: "number",
15
+ },
16
+ };
@@ -0,0 +1,19 @@
1
+ import { type ArgTypes } from "@storybook/react";
2
+ import { cartesianChartArgs } from "./cartesianChartArgs";
3
+
4
+ export const areaChartArgs: ArgTypes = {
5
+ ...cartesianChartArgs,
6
+ baseValue: {
7
+ description: "The base value of area.",
8
+ table: {
9
+ type: {
10
+ summary: "number | 'dataMin' | 'dataMax' | 'auto'",
11
+ },
12
+ defaultValue: {
13
+ summary: "'auto'",
14
+ },
15
+ category: "Area",
16
+ },
17
+ control: "text",
18
+ },
19
+ };
@@ -0,0 +1,123 @@
1
+ import { ArgTypes } from "@storybook/react";
2
+ import { animationArgs } from "./animationArgs";
3
+ import { cartesianSharedArgs, data } from "./cartesianSharedArgs";
4
+ import { legendType } from "./legendArgs";
5
+
6
+ /**
7
+ * MultiSelect Docs: {@link: https://shadcn-extension.vercel.app/docs/multi-select}
8
+ */
9
+ export const barArgs: ArgTypes = {
10
+ ...cartesianSharedArgs,
11
+ ...animationArgs,
12
+ data,
13
+ legendType,
14
+ layout: {
15
+ description: "The layout of bar in the chart, usually inherited from parent.",
16
+ table: {
17
+ type: {
18
+ summary: "'horizontal' | 'vertical'",
19
+ },
20
+ category: "Bar",
21
+ },
22
+ control: "radio",
23
+ options: ["horizontal", "vertical"],
24
+ },
25
+ label: {
26
+ description:
27
+ "If false set, labels will not be drawn. If true set, labels will be drawn which have the props calculated internally. If object set, labels will be drawn which have the props mergered by the internal calculated props and the option. If ReactElement set, the option can be the custom label element. If set a function, the function will be called to render customized label.",
28
+ table: {
29
+ type: {
30
+ summary: "boolean | Object | ReactElement | Function",
31
+ },
32
+ category: "Bar",
33
+ },
34
+ control: "object",
35
+ },
36
+ barSize: {
37
+ description:
38
+ "The width or height of each bar. If the barSize is not specified, the size of bar will be calculated by the barCategoryGap, barGap and the quantity of bar groups.",
39
+ table: {
40
+ type: {
41
+ summary: "number | Percentage",
42
+ },
43
+ category: "Bar",
44
+ },
45
+ control: "text",
46
+ },
47
+ maxBarSize: {
48
+ description:
49
+ "The maximum width of bar in a horizontal BarChart, or maximum height in a vertical BarChart.",
50
+ table: {
51
+ type: {
52
+ summary: "number",
53
+ },
54
+ category: "Bar",
55
+ },
56
+ control: "number",
57
+ },
58
+ minPointSize: {
59
+ description:
60
+ "The minimal height of a bar in a horizontal BarChart, or the minimal width of a bar in a vertical BarChart.\n By default, 0 values are not shown. To visualize a 0 (or close to zero) point, set the minimal point size to a pixel\n value like 3. In stacked bar charts, minPointSize might not be respected for tightly packed values. So we strongly recommend not using this props in stacked BarChart. You may provide a function to conditionally change this prop based on Bar value.",
61
+ table: {
62
+ type: {
63
+ summary: "number | Function",
64
+ },
65
+ category: "Bar",
66
+ },
67
+ control: "number",
68
+ },
69
+ background: {
70
+ description:
71
+ "If false set, background of bars will not be drawn. If true set, background of bars will be drawn which have the props calculated internally. If object set, background of bars will be drawn which have the props mergered by the internal calculated props and the option. If ReactElement set, the option can be the custom background element. If set a function, the function will be called to render customized background.",
72
+ table: {
73
+ type: {
74
+ summary: "boolean | Object | ReactElement | Function",
75
+ },
76
+ category: "Bar",
77
+ },
78
+ control: "object",
79
+ },
80
+ shape: {
81
+ description:
82
+ "If set a ReactElement, the shape of bar can be customized. If set a function, the function will be called to render customized shape.",
83
+ table: {
84
+ type: {
85
+ summary: "ReactElement | Function",
86
+ },
87
+ category: "Bar",
88
+ },
89
+ },
90
+ activeBar: {
91
+ description:
92
+ "The active bar is shown when a user enters a bar chart and this chart has tooltip. If set to false, no active bar will be drawn. If set to true, active bar will be drawn with the props calculated internally. If passed an object, active bar will be drawn, and the internally calculated props will be merged with the key value pairs of the passed object. If passed a ReactElement, the option can be the custom active bar element. If passed a function, the function will be called to render a customized active bar.",
93
+ table: {
94
+ type: {
95
+ summary: "boolean | Object | ReactElement | Function",
96
+ },
97
+ category: "Bar",
98
+ },
99
+ control: "object",
100
+ },
101
+ stackId: {
102
+ description:
103
+ "The stack id of bar, when two bars have the same value axis and same stackId, then the two bars are stacked in order.",
104
+ table: {
105
+ type: {
106
+ summary: "string | number",
107
+ },
108
+ category: "Bar",
109
+ },
110
+ control: "text",
111
+ },
112
+ name: {
113
+ description:
114
+ "The name of data. This option will be used in tooltip and legend to represent a bar. If no value was set to this option, the value of dataKey will be used alternatively.",
115
+ table: {
116
+ type: {
117
+ summary: "string",
118
+ },
119
+ category: "Bar",
120
+ },
121
+ control: "text",
122
+ },
123
+ };
@@ -0,0 +1,65 @@
1
+ import { type ArgTypes } from "@storybook/react";
2
+ import { categoricalChartArgs } from "./chartArgs";
3
+
4
+ export const barChartArgs: ArgTypes = {
5
+ ...categoricalChartArgs,
6
+ barCategoryGap: {
7
+ description:
8
+ "The gap between two bar categories, which can be a percent value or a fixed value.",
9
+ table: {
10
+ type: {
11
+ summary: "Percentage | number",
12
+ },
13
+ defaultValue: {
14
+ summary: "'10%'",
15
+ },
16
+ category: "Bar",
17
+ },
18
+ control: "text",
19
+ },
20
+ barGap: {
21
+ description: "The gap between two bars in the same category.",
22
+ table: {
23
+ type: {
24
+ summary: "number",
25
+ },
26
+ defaultValue: {
27
+ summary: "4",
28
+ },
29
+ category: "Bar",
30
+ },
31
+ control: "number",
32
+ },
33
+ barSize: {
34
+ description: `The width or height of each bar. If the barSize is not specified, the size of the bar
35
+ will be calculated by the barCategoryGap, barGap and the quantity of bar groups.`,
36
+ table: {
37
+ type: {
38
+ summary: "number | Percentage",
39
+ },
40
+ category: "Bar",
41
+ },
42
+ control: "text",
43
+ },
44
+ maxBarSize: {
45
+ description: "The maximum size of bar.",
46
+ table: {
47
+ type: {
48
+ summary: "number",
49
+ },
50
+ category: "Bar",
51
+ },
52
+ control: "number",
53
+ },
54
+ layout: {
55
+ description: "The layout of bar in the chart, usually inherited from parent.",
56
+ table: {
57
+ type: {
58
+ summary: "'horizontal' | 'vertical'",
59
+ },
60
+ category: "Bar",
61
+ },
62
+ control: "radio",
63
+ options: ["horizontal", "vertical"],
64
+ },
65
+ };
@@ -0,0 +1,42 @@
1
+ import { type ArgTypes } from "@storybook/react";
2
+ import { categoricalChartArgs } from "./chartArgs";
3
+
4
+ export const cartesianChartArgs: ArgTypes = {
5
+ ...categoricalChartArgs,
6
+ layout: {
7
+ description: "The layout of areas, bars, lines in the chart.",
8
+ table: {
9
+ type: {
10
+ summary: "'horizontal' | 'vertical'",
11
+ },
12
+ defaultValue: {
13
+ summary: "'horizontal'",
14
+ },
15
+ category: "General",
16
+ },
17
+ control: "radio",
18
+ options: ["horizontal", "vertical"],
19
+ },
20
+ stackOffset: {
21
+ description: `Determines how values are stacked:
22
+
23
+ - \`none\` is the default, it adds values on top of each other. No smarts. Negative values will overlap.
24
+ - \`expand\` make it so that the values always add up to 1 - so the chart will look like a rectangle.
25
+ - \`wiggle\` and \`silhouette\` tries to keep the chart centered.
26
+ - \`sign\` stacks positive values above zero and negative values below zero. Similar to \`none\` but handles negatives.
27
+ - \`positive\` ignores all negative values, and then behaves like \`none\`.
28
+
29
+ Also see https://d3js.org/d3-shape/stack#stack-offsets
30
+ (note that the \`diverging\` offset in d3 is named \`sign\` in recharts)
31
+ `,
32
+ table: {
33
+ type: {
34
+ summary: "'expand' | 'none' | 'wiggle' | 'silhouette' | 'sign' | 'positive'",
35
+ },
36
+ defaultValue: { summary: "'none'" },
37
+ category: "General",
38
+ },
39
+ control: "radio",
40
+ options: ["sign", "expand", "none", "wiggle", "silhouette", "positive"],
41
+ },
42
+ };
@@ -0,0 +1,136 @@
1
+ import { type ArgTypes } from "@storybook/react";
2
+
3
+ export const dataKey: ArgTypes[0] = {
4
+ description: `The key or getter of a group of data.
5
+ It could be an accessor function such as (row)=>value`,
6
+ table: {
7
+ type: { summary: "string | number | Function" },
8
+ category: "General",
9
+ },
10
+ control: "text",
11
+ };
12
+
13
+ export const nameKey: ArgTypes[0] = {
14
+ description: "The key of each sector's name.",
15
+ table: {
16
+ type: { summary: "string" },
17
+ category: "General",
18
+ },
19
+ control: "text",
20
+ };
21
+
22
+ export const activeShape: ArgTypes[0] = {
23
+ description: "",
24
+ table: {
25
+ type: {
26
+ summary: "Object | ReactElement | Function | boolean",
27
+ },
28
+ category: "General",
29
+ },
30
+ control: "object",
31
+ };
32
+
33
+ export const trapezoids: ArgTypes[0] = {
34
+ description: "The coordinates of all trapezoids in the chart, usually calculated internally",
35
+ table: {
36
+ type: {
37
+ summary: "Array",
38
+ detail: "[{x: 12, y: 12, upperWidth: 240, lowerWidth: 22, height: 80}]",
39
+ },
40
+ },
41
+ control: "object",
42
+ };
43
+
44
+ export const xAxisId: ArgTypes[0] = {
45
+ description: "The id of x-axis which is corresponding to the data.",
46
+ table: {
47
+ type: {
48
+ summary: "string | number",
49
+ },
50
+ category: "General",
51
+ },
52
+ control: "text",
53
+ };
54
+ export const yAxisId: ArgTypes[0] = {
55
+ description: "The id of y-axis which is corresponding to the data.",
56
+ table: {
57
+ type: {
58
+ summary: "string | number",
59
+ },
60
+ category: "General",
61
+ },
62
+ control: "text",
63
+ };
64
+ export const zAxisId: ArgTypes[0] = {
65
+ description: "The id of z-axis which is corresponding to the data.",
66
+ table: {
67
+ type: {
68
+ summary: "string | number",
69
+ },
70
+ category: "General",
71
+ },
72
+ control: "text",
73
+ };
74
+
75
+ export const cartesianSharedArgs: ArgTypes = {
76
+ dataKey,
77
+ id: {
78
+ description: `The unique id of this component, which will be used to generate unique clip path id internally.
79
+ This props is suggested to be set in SSR.`,
80
+ type: {
81
+ name: "string",
82
+ },
83
+ table: {
84
+ category: "General",
85
+ },
86
+ control: "text",
87
+ },
88
+ name: {
89
+ description: `The name of data. This option will be used in tooltip and legend to represent a line.
90
+ If no value was set to this option, the value of dataKey will be used alternatively.`,
91
+ table: {
92
+ type: {
93
+ summary: "string | number",
94
+ },
95
+ category: "General",
96
+ },
97
+ control: "text",
98
+ },
99
+ unit: {
100
+ description: "The unit of data. This option will be used in tooltip.",
101
+ table: {
102
+ type: {
103
+ summary: "string | number",
104
+ },
105
+ category: "General",
106
+ },
107
+ control: "text",
108
+ },
109
+ xAxisId,
110
+ yAxisId,
111
+ };
112
+
113
+ export const data: ArgTypes[0] = {
114
+ description: `The source data, in which each element is an object.
115
+ This can be defined either on the chart element (ScatterChart, LineChart, etc) or on the graphical item (Scatter, Line).
116
+ The object shape is flexible, with no pre-defined properties;
117
+ The dataKey props then define which properties from this object render where.`,
118
+ table: {
119
+ category: "General",
120
+ type: {
121
+ summary: "array of objects",
122
+ },
123
+ },
124
+ };
125
+
126
+ export const layout: ArgTypes[0] = {
127
+ description: "The layout of line, usually inherited from parent.",
128
+ table: {
129
+ type: {
130
+ summary: "'horizontal' | 'vertical'",
131
+ },
132
+ category: "Internal",
133
+ },
134
+ control: "radio",
135
+ options: ["horizontal", "vertical"],
136
+ };