@takaro/lib-components 0.4.9 → 0.4.11
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.
- package/package.json +13 -6
- package/src/components/actions/Button/__snapshots__/Button.test.tsx.snap +1 -1
- package/src/components/actions/IconButton/__snapshots__/IconButton.test.tsx.snap +1 -1
- package/src/components/charts/AreaChart/AreaChart.stories.tsx +11 -7
- package/src/components/charts/AreaChart/index.tsx +114 -63
- package/src/components/charts/BarChart/BarChart.stories.tsx +33 -10
- package/src/components/charts/BarChart/index.tsx +280 -147
- package/src/components/charts/EmptyChart.tsx +45 -0
- package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +15 -9
- package/src/components/charts/GeoMercator/index.tsx +15 -172
- package/src/components/charts/Heatmap/Heatmap.stories.tsx +167 -33
- package/src/components/charts/Heatmap/index.tsx +427 -193
- package/src/components/charts/LineChart/LineChart.stories.tsx +77 -3
- package/src/components/charts/LineChart/index.tsx +200 -79
- package/src/components/charts/PieChart/PieChart.stories.tsx +128 -20
- package/src/components/charts/PieChart/index.tsx +353 -59
- package/src/components/charts/PointHighlight.tsx +2 -2
- package/src/components/charts/RadarChart/RadarChart.stories.tsx +14 -5
- package/src/components/charts/RadarChart/index.tsx +94 -45
- package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +26 -1
- package/src/components/charts/RadialBarChart/index.tsx +100 -34
- package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +19 -2
- package/src/components/charts/RadialLineChart/index.tsx +116 -26
- package/src/components/charts/index.tsx +0 -26
- package/src/components/charts/util.ts +50 -12
- package/src/components/data/CountryList/index.tsx +146 -0
- package/src/components/data/Stats/Sparkline.tsx +48 -0
- package/src/components/data/Stats/Stat.tsx +15 -4
- package/src/components/data/Stats/context.tsx +1 -1
- package/src/components/data/Stats/index.tsx +8 -3
- package/src/components/data/index.ts +3 -0
- package/src/components/feedback/IconTooltip/index.tsx +9 -6
- package/src/components/feedback/ProgressBar/ProgressBar.stories.tsx +13 -14
- package/src/components/feedback/ProgressBar/index.tsx +1 -1
- package/src/components/inputs/DurationField/__tests__/Generic.test.tsx +12 -0
- package/src/components/visual/Card/CardTitle.tsx +7 -1
- package/src/components/visual/Card/index.tsx +0 -4
- package/src/helpers/formatNumber.ts +6 -0
- package/src/helpers/index.ts +1 -0
- package/vite.config.mts +4 -0
- package/src/components/charts/echarts/EChartsArea.stories.tsx +0 -139
- package/src/components/charts/echarts/EChartsArea.tsx +0 -139
- package/src/components/charts/echarts/EChartsBar.stories.tsx +0 -141
- package/src/components/charts/echarts/EChartsBar.tsx +0 -133
- package/src/components/charts/echarts/EChartsBase.tsx +0 -264
- package/src/components/charts/echarts/EChartsFunnel.stories.tsx +0 -164
- package/src/components/charts/echarts/EChartsFunnel.tsx +0 -114
- package/src/components/charts/echarts/EChartsHeatmap.stories.tsx +0 -168
- package/src/components/charts/echarts/EChartsHeatmap.tsx +0 -141
- package/src/components/charts/echarts/EChartsLine.stories.tsx +0 -132
- package/src/components/charts/echarts/EChartsLine.tsx +0 -111
- package/src/components/charts/echarts/EChartsPie.stories.tsx +0 -131
- package/src/components/charts/echarts/EChartsPie.tsx +0 -124
- package/src/components/charts/echarts/EChartsRadialBar.stories.tsx +0 -124
- package/src/components/charts/echarts/EChartsRadialBar.tsx +0 -118
- package/src/components/charts/echarts/EChartsScatter.stories.tsx +0 -166
- package/src/components/charts/echarts/EChartsScatter.tsx +0 -135
- package/src/components/charts/echarts/index.ts +0 -26
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takaro/lib-components",
|
|
3
|
-
"version": "0.4.9",
|
|
4
|
-
"private": false,
|
|
5
3
|
"description": "Takaro UI is a simple and customizable component library to build React apps faster within the Takaro eco system",
|
|
4
|
+
"version": "0.4.11",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"dnd-core": "16.0.1"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@storybook/react": "10.0.6",
|
|
10
|
+
"vitest": "4.0.8"
|
|
11
|
+
},
|
|
6
12
|
"license": "AGPL-3.0-or-later",
|
|
7
13
|
"main": "src/index.ts",
|
|
8
|
-
"
|
|
14
|
+
"private": false,
|
|
9
15
|
"scripts": {
|
|
10
16
|
"build": "storybook build -c ../../.storybook",
|
|
11
17
|
"start:dev": "storybook dev --no-open -c ../../.storybook -p 13002",
|
|
12
|
-
"test:
|
|
13
|
-
"test:
|
|
14
|
-
}
|
|
18
|
+
"test:snapshot": "vitest -u",
|
|
19
|
+
"test:unit": "CI=true vitest"
|
|
20
|
+
},
|
|
21
|
+
"types": "src/index.ts"
|
|
15
22
|
}
|
|
@@ -12,9 +12,10 @@ export default {
|
|
|
12
12
|
component: AreaChart,
|
|
13
13
|
args: {
|
|
14
14
|
showBrush: true,
|
|
15
|
-
showGrid: true,
|
|
16
15
|
axisXLabel: '',
|
|
17
16
|
axisYLabel: 'Close Price',
|
|
17
|
+
grid: 'none',
|
|
18
|
+
animate: true,
|
|
18
19
|
},
|
|
19
20
|
} as Meta<AreaChartProps<AppleStock>>;
|
|
20
21
|
|
|
@@ -33,10 +34,12 @@ export const Default: StoryFn<AreaChartProps<AppleStock>> = (args) => {
|
|
|
33
34
|
xAccessor={getDate}
|
|
34
35
|
yAccessor={getStockValue}
|
|
35
36
|
data={appleStock}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
axis={{
|
|
38
|
+
labelX: args.axis?.labelX,
|
|
39
|
+
labelY: args.axis?.labelY,
|
|
40
|
+
}}
|
|
41
|
+
grid={args.grid}
|
|
42
|
+
animate={args.animate}
|
|
40
43
|
/>
|
|
41
44
|
</Wrapper>
|
|
42
45
|
);
|
|
@@ -87,9 +90,10 @@ export const PingExample: StoryFn = () => {
|
|
|
87
90
|
name="Ping"
|
|
88
91
|
xAccessor={getDate}
|
|
89
92
|
yAccessor={getLatency}
|
|
90
|
-
|
|
93
|
+
tooltip={{
|
|
94
|
+
accessor: tooltipAccessor,
|
|
95
|
+
}}
|
|
91
96
|
data={generateData()}
|
|
92
|
-
showBrush={false}
|
|
93
97
|
/>
|
|
94
98
|
</div>
|
|
95
99
|
</Card.Body>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ParentSize } from '@visx/responsive';
|
|
4
|
-
import { GridColumns } from '@visx/grid';
|
|
4
|
+
import { GridColumns, GridRows } from '@visx/grid';
|
|
5
5
|
import { Group } from '@visx/group';
|
|
6
6
|
import { AreaClosed, Bar } from '@visx/shape';
|
|
7
7
|
import { max, extent, bisector } from '@visx/vendor/d3-array';
|
|
@@ -14,21 +14,23 @@ import { timeFormat } from '@visx/vendor/d3-time-format';
|
|
|
14
14
|
import { PatternLines } from '@visx/pattern';
|
|
15
15
|
import { Brush } from '@visx/brush';
|
|
16
16
|
import { Bounds } from '@visx/brush/lib/types';
|
|
17
|
+
import { motion } from 'framer-motion';
|
|
17
18
|
|
|
18
19
|
import { useTheme } from '../../../hooks';
|
|
19
20
|
import { useGradients } from '../useGradients';
|
|
20
|
-
import {
|
|
21
|
+
import { ChartProps, InnerChartProps, getDefaultTooltipStyles, TooltipConfig, BrushConfig } from '../util';
|
|
21
22
|
import { BrushHandle } from '../BrushHandle';
|
|
22
23
|
import { PointHighlight } from '../PointHighlight';
|
|
24
|
+
import { EmptyChart } from '../EmptyChart';
|
|
23
25
|
|
|
24
26
|
export interface AreaChartProps<T> extends ChartProps {
|
|
25
27
|
data: T[];
|
|
26
28
|
xAccessor: (d: T) => Date;
|
|
27
29
|
yAccessor: (d: T) => number;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/** Tooltip configuration */
|
|
31
|
+
tooltip?: TooltipConfig<T>;
|
|
32
|
+
/** Brush/zoom configuration */
|
|
33
|
+
brush?: BrushConfig;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const formatDate = timeFormat("%b %d, '%y");
|
|
@@ -37,48 +39,41 @@ const defaultMargin = { top: 20, left: 50, bottom: 20, right: 5 };
|
|
|
37
39
|
const defaultBrushMargin = { top: 10, bottom: 15, left: 50, right: 5 };
|
|
38
40
|
const defaultShowAxisX = true;
|
|
39
41
|
const defaultShowAxisY = true;
|
|
40
|
-
const defaultShowGrid = true;
|
|
41
42
|
|
|
42
43
|
export const AreaChart = <T,>({
|
|
43
44
|
data,
|
|
44
45
|
xAccessor,
|
|
45
46
|
yAccessor,
|
|
46
|
-
tooltipAccessor,
|
|
47
|
-
margin = defaultMargin,
|
|
48
|
-
showGrid = defaultShowGrid,
|
|
49
|
-
showBrush = false,
|
|
50
|
-
brushMargin = defaultBrushMargin,
|
|
51
47
|
name,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
grid = 'none',
|
|
49
|
+
axis,
|
|
50
|
+
tooltip,
|
|
51
|
+
brush,
|
|
52
|
+
animate = true,
|
|
53
|
+
margin = defaultMargin,
|
|
56
54
|
}: AreaChartProps<T>) => {
|
|
57
|
-
|
|
58
|
-
if (!data || data.length === 0) return null;
|
|
55
|
+
const hasData = data && data.length > 0;
|
|
59
56
|
|
|
60
|
-
// TODO: handle loading state
|
|
61
57
|
return (
|
|
62
58
|
<ParentSize>
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/>
|
|
81
|
-
)}
|
|
59
|
+
{hasData
|
|
60
|
+
? (parent) => (
|
|
61
|
+
<Chart<T>
|
|
62
|
+
name={name}
|
|
63
|
+
xAccessor={xAccessor}
|
|
64
|
+
yAccessor={yAccessor}
|
|
65
|
+
data={data}
|
|
66
|
+
width={parent.width}
|
|
67
|
+
height={parent.height}
|
|
68
|
+
grid={grid}
|
|
69
|
+
axis={axis}
|
|
70
|
+
tooltip={tooltip}
|
|
71
|
+
brush={brush}
|
|
72
|
+
animate={animate}
|
|
73
|
+
margin={margin}
|
|
74
|
+
/>
|
|
75
|
+
)
|
|
76
|
+
: () => <EmptyChart />}
|
|
82
77
|
</ParentSize>
|
|
83
78
|
);
|
|
84
79
|
};
|
|
@@ -89,19 +84,25 @@ const Chart = <T,>({
|
|
|
89
84
|
data,
|
|
90
85
|
xAccessor,
|
|
91
86
|
yAccessor,
|
|
92
|
-
tooltipAccessor,
|
|
93
87
|
width,
|
|
94
88
|
height,
|
|
95
89
|
margin = defaultMargin,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
grid = 'none',
|
|
91
|
+
axis,
|
|
92
|
+
tooltip,
|
|
93
|
+
brush,
|
|
94
|
+
animate = true,
|
|
99
95
|
name,
|
|
100
|
-
showAxisX = defaultShowAxisX,
|
|
101
|
-
showAxisY = defaultShowAxisY,
|
|
102
|
-
axisYLabel,
|
|
103
|
-
axisXLabel,
|
|
104
96
|
}: InnerAreaChartProps<T>) => {
|
|
97
|
+
const showAxisX = axis?.showX ?? defaultShowAxisX;
|
|
98
|
+
const showAxisY = axis?.showY ?? defaultShowAxisY;
|
|
99
|
+
const axisXLabel = axis?.labelX;
|
|
100
|
+
const axisYLabel = axis?.labelY;
|
|
101
|
+
const tooltipAccessor = tooltip?.accessor;
|
|
102
|
+
|
|
103
|
+
// Extract brush configuration
|
|
104
|
+
const showBrush = brush?.enabled ?? false;
|
|
105
|
+
const brushMargin = brush?.margin ?? defaultBrushMargin;
|
|
105
106
|
const PATTERN_ID = `${name}-brush_pattern`;
|
|
106
107
|
const theme = useTheme();
|
|
107
108
|
const gradients = useGradients(name);
|
|
@@ -219,21 +220,27 @@ const Chart = <T,>({
|
|
|
219
220
|
<div>
|
|
220
221
|
<svg width={width} height={height}>
|
|
221
222
|
{gradients.chart.gradient}
|
|
222
|
-
{gradients.background.gradient}
|
|
223
|
-
<rect x={0} y={0} width={width} height={height} fill={`url(#${gradients.background.id})`} rx={14} />
|
|
224
|
-
{showGrid && (
|
|
225
|
-
<GridColumns
|
|
226
|
-
top={margin.top}
|
|
227
|
-
left={margin.left}
|
|
228
|
-
scale={xScale}
|
|
229
|
-
height={yMax}
|
|
230
|
-
strokeDasharray="1,5"
|
|
231
|
-
stroke={theme.colors.backgroundAccent}
|
|
232
|
-
strokeOpacity={0.2}
|
|
233
|
-
pointerEvents="none"
|
|
234
|
-
/>
|
|
235
|
-
)}
|
|
236
223
|
<Group id="chart" top={margin.top} left={margin.left}>
|
|
224
|
+
{(grid === 'y' || grid === 'xy') && (
|
|
225
|
+
<GridRows
|
|
226
|
+
scale={yScale}
|
|
227
|
+
width={xMax}
|
|
228
|
+
stroke={theme.colors.backgroundAccent}
|
|
229
|
+
strokeOpacity={1}
|
|
230
|
+
strokeDasharray="2,2"
|
|
231
|
+
pointerEvents="none"
|
|
232
|
+
/>
|
|
233
|
+
)}
|
|
234
|
+
{(grid === 'x' || grid === 'xy') && (
|
|
235
|
+
<GridColumns
|
|
236
|
+
scale={xScale}
|
|
237
|
+
height={yMax}
|
|
238
|
+
stroke={theme.colors.backgroundAccent}
|
|
239
|
+
strokeOpacity={1}
|
|
240
|
+
strokeDasharray="2,2"
|
|
241
|
+
pointerEvents="none"
|
|
242
|
+
/>
|
|
243
|
+
)}
|
|
237
244
|
<AreaClosed<T>
|
|
238
245
|
x={(d) => xScale(xAccessor(d)) ?? 0}
|
|
239
246
|
y={(d) => yScale(yAccessor(d)) ?? 0}
|
|
@@ -243,7 +250,29 @@ const Chart = <T,>({
|
|
|
243
250
|
stroke={theme.colors.primary}
|
|
244
251
|
fill={`url(#${gradients.chart.id})`}
|
|
245
252
|
curve={curveMonotoneX}
|
|
246
|
-
|
|
253
|
+
>
|
|
254
|
+
{({ path }) => {
|
|
255
|
+
const pathData = path(filteredData) || '';
|
|
256
|
+
return (
|
|
257
|
+
<motion.path
|
|
258
|
+
d={pathData}
|
|
259
|
+
stroke={theme.colors.primary}
|
|
260
|
+
strokeWidth={1}
|
|
261
|
+
fill={`url(#${gradients.chart.id})`}
|
|
262
|
+
initial={animate ? { pathLength: 0, opacity: 0 } : { pathLength: 1, opacity: 1 }}
|
|
263
|
+
animate={{ pathLength: 1, opacity: 1 }}
|
|
264
|
+
transition={
|
|
265
|
+
animate
|
|
266
|
+
? {
|
|
267
|
+
pathLength: { duration: 1, ease: 'easeInOut' },
|
|
268
|
+
opacity: { duration: 0.8, ease: 'easeInOut' },
|
|
269
|
+
}
|
|
270
|
+
: { duration: 0 }
|
|
271
|
+
}
|
|
272
|
+
/>
|
|
273
|
+
);
|
|
274
|
+
}}
|
|
275
|
+
</AreaClosed>
|
|
247
276
|
</Group>
|
|
248
277
|
<Bar
|
|
249
278
|
x={margin.left}
|
|
@@ -273,7 +302,29 @@ const Chart = <T,>({
|
|
|
273
302
|
stroke={`url(#${gradients.chart.id})`}
|
|
274
303
|
fill={`url(#${gradients.chart.id})`}
|
|
275
304
|
curve={curveMonotoneX}
|
|
276
|
-
|
|
305
|
+
>
|
|
306
|
+
{({ path }) => {
|
|
307
|
+
const pathData = path(data) || '';
|
|
308
|
+
return (
|
|
309
|
+
<motion.path
|
|
310
|
+
d={pathData}
|
|
311
|
+
stroke={`url(#${gradients.chart.id})`}
|
|
312
|
+
strokeWidth={1}
|
|
313
|
+
fill={`url(#${gradients.chart.id})`}
|
|
314
|
+
initial={animate ? { pathLength: 0, opacity: 0 } : { pathLength: 1, opacity: 1 }}
|
|
315
|
+
animate={{ pathLength: 1, opacity: 1 }}
|
|
316
|
+
transition={
|
|
317
|
+
animate
|
|
318
|
+
? {
|
|
319
|
+
pathLength: { duration: 0.5, ease: 'easeInOut' },
|
|
320
|
+
opacity: { duration: 0.4, ease: 'easeInOut' },
|
|
321
|
+
}
|
|
322
|
+
: { duration: 0 }
|
|
323
|
+
}
|
|
324
|
+
/>
|
|
325
|
+
);
|
|
326
|
+
}}
|
|
327
|
+
</AreaClosed>
|
|
277
328
|
<PatternLines
|
|
278
329
|
id={PATTERN_ID}
|
|
279
330
|
height={8}
|
|
@@ -334,7 +385,7 @@ const Chart = <T,>({
|
|
|
334
385
|
tickLabelProps={{
|
|
335
386
|
fill: theme.colors.textAlt,
|
|
336
387
|
fontSize: theme.fontSize.small,
|
|
337
|
-
textAnchor: '
|
|
388
|
+
textAnchor: 'middle',
|
|
338
389
|
}}
|
|
339
390
|
tickFormat={tickFormatDate}
|
|
340
391
|
labelProps={{
|
|
@@ -4,28 +4,51 @@ import { BarChart, BarChartProps } from '.';
|
|
|
4
4
|
import { styled } from '../../../styled';
|
|
5
5
|
import letterFrequency, { LetterFrequency } from '@visx/mock-data/lib/mocks/letterFrequency';
|
|
6
6
|
|
|
7
|
-
export default {
|
|
8
|
-
title: 'Charts/BarChart',
|
|
9
|
-
component: BarChart,
|
|
10
|
-
} as Meta<BarChartProps<LetterFrequency>>;
|
|
11
|
-
|
|
12
7
|
const Wrapper = styled.div`
|
|
13
8
|
height: 50vh;
|
|
14
9
|
width: 100%;
|
|
15
10
|
`;
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const getLetter = (d: LetterFrequency) => d.letter;
|
|
13
|
+
const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: 'Charts/BarChart',
|
|
17
|
+
component: BarChart,
|
|
18
|
+
args: {
|
|
19
|
+
name: 'letterFrequency',
|
|
20
|
+
grid: 'xy',
|
|
21
|
+
barWidth: 0.6,
|
|
22
|
+
tooltip: {
|
|
23
|
+
enabled: true,
|
|
24
|
+
accessor: (d: LetterFrequency) => `${d.letter}: ${getLetterFrequency(d).toFixed(1)}%`,
|
|
25
|
+
},
|
|
26
|
+
brush: {
|
|
27
|
+
enabled: false,
|
|
28
|
+
},
|
|
29
|
+
axis: {
|
|
30
|
+
showX: true,
|
|
31
|
+
showY: true,
|
|
32
|
+
labelX: 'Letter',
|
|
33
|
+
labelY: 'Frequency (%)',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
argTypes: {
|
|
37
|
+
barWidth: {
|
|
38
|
+
control: { type: 'range', min: 0.1, max: 1, step: 0.05 },
|
|
39
|
+
description: 'Bar width as percentage (0-1). 1.0 = bars touch (no gaps)',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} as Meta<BarChartProps<LetterFrequency>>;
|
|
20
43
|
|
|
44
|
+
export const Default: StoryFn<BarChartProps<LetterFrequency>> = (args) => {
|
|
21
45
|
return (
|
|
22
46
|
<Wrapper>
|
|
23
47
|
<BarChart<LetterFrequency>
|
|
24
|
-
|
|
48
|
+
{...args}
|
|
25
49
|
xAccessor={getLetter}
|
|
26
50
|
yAccessor={getLetterFrequency}
|
|
27
51
|
data={letterFrequency}
|
|
28
|
-
showBrush={true}
|
|
29
52
|
/>
|
|
30
53
|
</Wrapper>
|
|
31
54
|
);
|