forked from tremorlabs/tremor
/
ScatterChart.stories.tsx
130 lines (114 loc) · 3.43 KB
/
ScatterChart.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from "react";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { Card, ScatterChart, Title } from "components";
import {
simpleScatterChartData as data,
simpleScatterChartData2 as data2,
} from "./helpers/testDataScatterChart";
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
title: "Tremor/ChartElements/ScatterChart",
component: ScatterChart,
} as ComponentMeta<typeof ScatterChart>;
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const ResponsiveTemplate: ComponentStory<typeof ScatterChart> = (args) => {
if (args.onValueChange?.length === 0) {
args.onValueChange = undefined;
}
return (
<>
<Title>Mobile</Title>
<div className="w-64">
<Card>
<ScatterChart {...args} />
</Card>
</div>
<Title className="mt-5">Desktop</Title>
<Card>
<ScatterChart {...args} />
</Card>
</>
);
};
const DefaultTemplate: ComponentStory<typeof ScatterChart> = ({ ...args }) => (
<Card>
<ScatterChart {...args} />
</Card>
);
const args = { x: "x", y: "y", size: "z", category: "location" };
export const DefaultResponsive = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
DefaultResponsive.args = {
...args,
data,
};
export const WithNoSize = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithNoSize.args = {
...args,
data,
size: undefined,
};
export const WithCustomeSizeRange = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithCustomeSizeRange.args = {
...args,
data,
sizeRange: [1, 10],
};
export const WithCustomColor = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithCustomColor.args = {
...args,
data,
colors: ["red", "green", "blue", "yellow"],
};
export const WithCustomValueFormatters = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithCustomValueFormatters.args = {
...args,
data,
valueFormatter: {
x: (x) => `${x} m`,
y: (y) => `${y} cm`,
size: (size) => `${size} kg`,
},
};
export const WithAutoMinXValue = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithAutoMinXValue.args = {
...args,
data,
autoMinXValue: true,
};
export const WithNoData = DefaultTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithNoData.args = {
...args,
};
export const WithNoDataText = DefaultTemplate.bind({});
WithNoDataText.args = {
...args,
noDataText: "No data, try again later.",
};
export const WithOnValueChange = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithOnValueChange.args = {
...args,
data,
onValueChange: (value) => alert(JSON.stringify(value)),
};
export const WithExampleDatas = ResponsiveTemplate.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
WithExampleDatas.args = {
data: data2,
x: "gdpPercap",
y: "lifeExp",
category: "continent",
size: "population",
valueFormatter: {
x: (x) => `${x} $`,
y: (y) => `${y} yrs`,
},
colors: ["red", "green", "blue"],
};