@tecsinapse/react-charts 0.0.2 → 1.0.0
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/LICENSE.md +21 -0
- package/README.md +78 -0
- package/dist/cjs/components/Dot/Dot.js +10 -0
- package/dist/cjs/components/Dot/styled.js +24 -0
- package/dist/cjs/components/Label/Label.js +14 -0
- package/dist/cjs/components/Label/styled.js +35 -0
- package/dist/cjs/components/PieChart/PieChart.js +95 -0
- package/dist/cjs/components/PieChart/functions.js +42 -0
- package/dist/cjs/components/PieChart/styled.js +22 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/styles/constants.js +65 -0
- package/dist/cjs/styles/functions.js +14 -0
- package/dist/esm/components/Dot/Dot.js +8 -0
- package/{src/components/Dot/styled.ts → dist/esm/components/Dot/styled.js} +5 -4
- package/dist/esm/components/Label/Label.js +12 -0
- package/dist/esm/components/Label/styled.js +32 -0
- package/dist/esm/components/PieChart/PieChart.js +93 -0
- package/dist/esm/components/PieChart/functions.js +38 -0
- package/{src/components/PieChart/styled.ts → dist/esm/components/PieChart/styled.js} +4 -3
- package/dist/esm/index.js +3 -0
- package/dist/esm/styles/constants.js +57 -0
- package/dist/esm/styles/functions.js +12 -0
- package/dist/types/components/Dot/styled.d.ts +16 -0
- package/dist/types/components/Label/styled.d.ts +23 -0
- package/dist/{components → types/components}/PieChart/functions.d.ts +4 -4
- package/dist/types/components/PieChart/styled.d.ts +14 -0
- package/dist/types/index.d.ts +3 -3
- package/{src/types/font.ts → dist/types/types/font.d.ts} +3 -4
- package/dist/types/{pie.d.ts → types/pie.d.ts} +1 -1
- package/dist/types/types/svg.d.ts +11 -0
- package/package.json +24 -79
- package/dist/components/Dot/Dot.js +0 -24
- package/dist/components/Dot/Dot.js.map +0 -1
- package/dist/components/Dot/index.js +0 -16
- package/dist/components/Dot/index.js.map +0 -1
- package/dist/components/Dot/styled.d.ts +0 -16
- package/dist/components/Dot/styled.js +0 -35
- package/dist/components/Dot/styled.js.map +0 -1
- package/dist/components/Label/Label.js +0 -40
- package/dist/components/Label/Label.js.map +0 -1
- package/dist/components/Label/index.js +0 -16
- package/dist/components/Label/index.js.map +0 -1
- package/dist/components/Label/styled.d.ts +0 -23
- package/dist/components/Label/styled.js +0 -59
- package/dist/components/Label/styled.js.map +0 -1
- package/dist/components/PieChart/PieChart.js +0 -97
- package/dist/components/PieChart/PieChart.js.map +0 -1
- package/dist/components/PieChart/functions.js +0 -50
- package/dist/components/PieChart/functions.js.map +0 -1
- package/dist/components/PieChart/index.js +0 -16
- package/dist/components/PieChart/index.js.map +0 -1
- package/dist/components/PieChart/styled.d.ts +0 -14
- package/dist/components/PieChart/styled.js +0 -30
- package/dist/components/PieChart/styled.js.map +0 -1
- package/dist/components/index.js +0 -14
- package/dist/components/index.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -45
- package/dist/index.js.map +0 -1
- package/dist/styles/constants.js +0 -63
- package/dist/styles/constants.js.map +0 -1
- package/dist/styles/functions.js +0 -21
- package/dist/styles/functions.js.map +0 -1
- package/dist/styles/index.js +0 -32
- package/dist/styles/index.js.map +0 -1
- package/dist/types/font.d.ts +0 -6
- package/dist/types/font.js +0 -6
- package/dist/types/font.js.map +0 -1
- package/dist/types/index.js +0 -45
- package/dist/types/index.js.map +0 -1
- package/dist/types/pie.js +0 -6
- package/dist/types/pie.js.map +0 -1
- package/dist/types/svg.d.ts +0 -11
- package/dist/types/svg.js +0 -6
- package/dist/types/svg.js.map +0 -1
- package/src/components/Dot/Dot.tsx +0 -12
- package/src/components/Dot/index.ts +0 -1
- package/src/components/Label/Label.tsx +0 -31
- package/src/components/Label/index.ts +0 -1
- package/src/components/Label/styled.ts +0 -47
- package/src/components/PieChart/PieChart.tsx +0 -122
- package/src/components/PieChart/functions.ts +0 -70
- package/src/components/PieChart/index.ts +0 -1
- package/src/components/index.ts +0 -1
- package/src/index.ts +0 -3
- package/src/styles/constants.ts +0 -55
- package/src/styles/functions.ts +0 -17
- package/src/styles/index.ts +0 -2
- package/src/types/pie.ts +0 -7
- package/src/types/svg.ts +0 -31
- /package/dist/{components → types/components}/Dot/Dot.d.ts +0 -0
- /package/dist/{components → types/components}/Dot/index.d.ts +0 -0
- /package/dist/{components → types/components}/Label/Label.d.ts +0 -0
- /package/dist/{components → types/components}/Label/index.d.ts +0 -0
- /package/dist/{components → types/components}/PieChart/PieChart.d.ts +0 -0
- /package/dist/{components → types/components}/PieChart/index.d.ts +0 -0
- /package/dist/{components → types/components}/index.d.ts +0 -0
- /package/dist/{styles → types/styles}/constants.d.ts +0 -0
- /package/dist/{styles → types/styles}/functions.d.ts +0 -0
- /package/dist/{styles → types/styles}/index.d.ts +0 -0
- /package/{src/types/index.ts → dist/types/types/index.d.ts} +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import styled, { css } from '@emotion/native';
|
|
2
|
-
import { Text as RNText, View } from 'react-native';
|
|
3
|
-
import { spacing } from '../../styles';
|
|
4
|
-
|
|
5
|
-
const flexBasis = (columns: number) =>
|
|
6
|
-
css({ flexBasis: `${100 / columns - 2}%` });
|
|
7
|
-
|
|
8
|
-
export const Container = styled(View)<{ columns: number }>(
|
|
9
|
-
({ columns }) =>
|
|
10
|
-
css`
|
|
11
|
-
display: flex;
|
|
12
|
-
flex-direction: row;
|
|
13
|
-
align-items: center;
|
|
14
|
-
margin-bottom: ${spacing.centi};
|
|
15
|
-
${flexBasis(columns)}
|
|
16
|
-
`
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const expandStyles = (expand?: boolean) =>
|
|
20
|
-
expand &&
|
|
21
|
-
css`
|
|
22
|
-
flex: 1;
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
const flexEndStyles = (flexEnd?: boolean) =>
|
|
26
|
-
flexEnd &&
|
|
27
|
-
css`
|
|
28
|
-
justify-content: flex-end;
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
export const Text = styled(RNText)<{
|
|
32
|
-
font: {
|
|
33
|
-
fontFamily: string;
|
|
34
|
-
fontWeight: string;
|
|
35
|
-
};
|
|
36
|
-
expand?: boolean;
|
|
37
|
-
flexEnd?: boolean;
|
|
38
|
-
}>(({ font, expand = false, flexEnd = false }) => {
|
|
39
|
-
const { fontFamily, fontWeight } = font;
|
|
40
|
-
return css`
|
|
41
|
-
font-size: 14px;
|
|
42
|
-
font-family: ${fontFamily};
|
|
43
|
-
font-weight: ${fontWeight};
|
|
44
|
-
${expandStyles(expand)}
|
|
45
|
-
${flexEndStyles(flexEnd)}
|
|
46
|
-
`;
|
|
47
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Text } from 'react-native-svg';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { PieChart as PChart } from 'react-native-svg-charts';
|
|
4
|
-
import { Label } from '../Label';
|
|
5
|
-
import { FontFamily, PieChartData, SvgTextType } from '../../types';
|
|
6
|
-
import { getCallback, getFeatured, getTextStyles } from './functions';
|
|
7
|
-
import { Container, LabelsContainer } from './styled';
|
|
8
|
-
|
|
9
|
-
export interface PieChartProps {
|
|
10
|
-
data: PieChartData[];
|
|
11
|
-
/** Chart width/height (square view, in px) */
|
|
12
|
-
dimension?: number;
|
|
13
|
-
/** Chart pie area radius (in px) */
|
|
14
|
-
radius?: number;
|
|
15
|
-
label?: string;
|
|
16
|
-
/** You should specify at least fontFamily */
|
|
17
|
-
labelProps?: SvgTextType;
|
|
18
|
-
sub?: string;
|
|
19
|
-
/** You should specify at least fontFamily */
|
|
20
|
-
subProps?: SvgTextType;
|
|
21
|
-
/** Number of label columns */
|
|
22
|
-
columns?: number;
|
|
23
|
-
/** This should be used if you have a custom font configuration */
|
|
24
|
-
chartConfig?: {
|
|
25
|
-
fontFamily: FontFamily;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const PieChart: React.FC<PieChartProps> = ({
|
|
30
|
-
data,
|
|
31
|
-
dimension = 200,
|
|
32
|
-
radius = 32,
|
|
33
|
-
label,
|
|
34
|
-
sub,
|
|
35
|
-
labelProps,
|
|
36
|
-
subProps,
|
|
37
|
-
columns = 1,
|
|
38
|
-
chartConfig,
|
|
39
|
-
}) => {
|
|
40
|
-
/** 90 is to compensate the outerRadius featured option */
|
|
41
|
-
const inner = 90 - (radius * 100) / (dimension / 2);
|
|
42
|
-
|
|
43
|
-
const chart = data.map((item, index) => ({
|
|
44
|
-
value: item.value,
|
|
45
|
-
svg: {
|
|
46
|
-
fill: item.color,
|
|
47
|
-
...getCallback(item.value, item.label, item.onPress),
|
|
48
|
-
},
|
|
49
|
-
...getFeatured(item.featured ?? false),
|
|
50
|
-
key: `pie-${index}`,
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
const sum = data.reduce((prev, curr) => prev + curr.value, 0);
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
textAnchor,
|
|
57
|
-
alignmentBaseline,
|
|
58
|
-
fontSize = 32,
|
|
59
|
-
fontWeight,
|
|
60
|
-
fontFamily,
|
|
61
|
-
fill,
|
|
62
|
-
y = sub ? -5 : undefined,
|
|
63
|
-
} = getTextStyles(labelProps, 'bold', chartConfig);
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
textAnchor: textAnchorSub,
|
|
67
|
-
alignmentBaseline: alignmentBaselineSub,
|
|
68
|
-
fontSize: fontSizeSub = 14,
|
|
69
|
-
fontWeight: fontWeightSub,
|
|
70
|
-
fontFamily: fontFamilySub,
|
|
71
|
-
fill: fillSub,
|
|
72
|
-
y: ySub = 16,
|
|
73
|
-
} = getTextStyles(subProps, 'bold', chartConfig);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Container>
|
|
77
|
-
<PChart
|
|
78
|
-
style={{ width: dimension, height: dimension, flex: 1 }}
|
|
79
|
-
data={chart}
|
|
80
|
-
padAngle={0}
|
|
81
|
-
innerRadius={`${inner}%`}
|
|
82
|
-
>
|
|
83
|
-
<Text
|
|
84
|
-
textAnchor={textAnchor}
|
|
85
|
-
alignmentBaseline={alignmentBaseline}
|
|
86
|
-
fontSize={fontSize}
|
|
87
|
-
fontWeight={fontWeight}
|
|
88
|
-
fontFamily={fontFamily}
|
|
89
|
-
fill={fill}
|
|
90
|
-
y={y}
|
|
91
|
-
>
|
|
92
|
-
{label ?? sum}
|
|
93
|
-
</Text>
|
|
94
|
-
{sub && (
|
|
95
|
-
<Text
|
|
96
|
-
textAnchor={textAnchorSub}
|
|
97
|
-
alignmentBaseline={alignmentBaselineSub}
|
|
98
|
-
fontSize={fontSizeSub}
|
|
99
|
-
fontWeight={fontWeightSub}
|
|
100
|
-
fontFamily={fontFamilySub}
|
|
101
|
-
fill={fillSub}
|
|
102
|
-
y={ySub}
|
|
103
|
-
>
|
|
104
|
-
{sub}
|
|
105
|
-
</Text>
|
|
106
|
-
)}
|
|
107
|
-
</PChart>
|
|
108
|
-
<LabelsContainer>
|
|
109
|
-
{data.map(item => (
|
|
110
|
-
<Label
|
|
111
|
-
data={item}
|
|
112
|
-
columns={columns}
|
|
113
|
-
key={item.label}
|
|
114
|
-
chartConfig={chartConfig}
|
|
115
|
-
/>
|
|
116
|
-
))}
|
|
117
|
-
</LabelsContainer>
|
|
118
|
-
</Container>
|
|
119
|
-
);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export default PieChart;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import {
|
|
3
|
-
AlignmentBaseline,
|
|
4
|
-
FontFamily,
|
|
5
|
-
FontWeight,
|
|
6
|
-
SvgTextType,
|
|
7
|
-
TextAnchor,
|
|
8
|
-
} from '../../types';
|
|
9
|
-
import { fontColor, getFontFamilyAndWeight } from '../../styles';
|
|
10
|
-
|
|
11
|
-
type CallbackReturn =
|
|
12
|
-
| Record<string, unknown>
|
|
13
|
-
| { onClick: () => undefined }
|
|
14
|
-
| { onPress: () => undefined };
|
|
15
|
-
|
|
16
|
-
export const getCallback = (
|
|
17
|
-
value: number,
|
|
18
|
-
label?: string,
|
|
19
|
-
fn?: (value: number, label?: string) => void
|
|
20
|
-
): CallbackReturn => {
|
|
21
|
-
if (!fn) return {};
|
|
22
|
-
return Platform.OS === 'web'
|
|
23
|
-
? {
|
|
24
|
-
onClick: () => fn?.(value, label),
|
|
25
|
-
}
|
|
26
|
-
: {
|
|
27
|
-
onPress: () => fn?.(value, label),
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type FeaturedType = { arc: { outerRadius: string } };
|
|
32
|
-
|
|
33
|
-
export const getFeatured = (featured: boolean): FeaturedType => ({
|
|
34
|
-
arc: { outerRadius: featured ? '100%' : '90%' },
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
type TextStylesReturn = {
|
|
38
|
-
fontFamily: string;
|
|
39
|
-
y: number | undefined;
|
|
40
|
-
fontSize: number | undefined;
|
|
41
|
-
textAnchor: TextAnchor;
|
|
42
|
-
fill: string;
|
|
43
|
-
alignmentBaseline: AlignmentBaseline;
|
|
44
|
-
fontWeight: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const getTextStyles = (
|
|
48
|
-
styles: SvgTextType | undefined,
|
|
49
|
-
defaultFontWeight: FontWeight,
|
|
50
|
-
chartConfig: { fontFamily: FontFamily } | undefined
|
|
51
|
-
): TextStylesReturn => {
|
|
52
|
-
const {
|
|
53
|
-
textAnchor = 'middle',
|
|
54
|
-
alignmentBaseline = 'middle',
|
|
55
|
-
fontSize,
|
|
56
|
-
fill = fontColor.dark,
|
|
57
|
-
y,
|
|
58
|
-
} = styles || {};
|
|
59
|
-
return {
|
|
60
|
-
textAnchor,
|
|
61
|
-
alignmentBaseline,
|
|
62
|
-
fontSize,
|
|
63
|
-
fill,
|
|
64
|
-
y,
|
|
65
|
-
...getFontFamilyAndWeight(
|
|
66
|
-
chartConfig?.fontFamily,
|
|
67
|
-
styles?.fontWeight ?? defaultFontWeight
|
|
68
|
-
),
|
|
69
|
-
};
|
|
70
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as PieChart } from './PieChart';
|
package/src/components/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PieChart } from './PieChart';
|
package/src/index.ts
DELETED
package/src/styles/constants.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export const fontColor = {
|
|
2
|
-
light: '#fff',
|
|
3
|
-
medium: '#85807a',
|
|
4
|
-
dark: '#353231', // default
|
|
5
|
-
orange: '#f89907',
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const spacing = {
|
|
9
|
-
nano: '2px',
|
|
10
|
-
micro: '4px',
|
|
11
|
-
mili: '8px',
|
|
12
|
-
centi: '12px',
|
|
13
|
-
deca: '16px',
|
|
14
|
-
kilo: '24px',
|
|
15
|
-
mega: '32px',
|
|
16
|
-
giga: '40px',
|
|
17
|
-
tera: '48px',
|
|
18
|
-
peta: '56px',
|
|
19
|
-
hexa: '64px',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const iconSize = {
|
|
23
|
-
micro: '12px',
|
|
24
|
-
mili: '14px',
|
|
25
|
-
centi: '16px', // '1rem'
|
|
26
|
-
deca: '18px', // '1.5rem'
|
|
27
|
-
kilo: '24px', // '1.6rem'
|
|
28
|
-
mega: '32px', // '2rem'
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const borderRadius = {
|
|
32
|
-
nano: '2px',
|
|
33
|
-
micro: '4px',
|
|
34
|
-
mili: '8px',
|
|
35
|
-
centi: '16px',
|
|
36
|
-
deca: '24px',
|
|
37
|
-
pill: '999999px', // also circle
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const fontStack = {
|
|
41
|
-
default: 'Lato',
|
|
42
|
-
mono: 'Consolas, monaco, monospace',
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const fontWeight = {
|
|
46
|
-
regular: '400',
|
|
47
|
-
bold: '700',
|
|
48
|
-
black: '900',
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const nativeFontStack = {
|
|
52
|
-
black: 'Lato-Black',
|
|
53
|
-
bold: 'Lato-Bold',
|
|
54
|
-
regular: 'Lato-Regular',
|
|
55
|
-
};
|
package/src/styles/functions.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import { fontStack, fontWeight, nativeFontStack } from './constants';
|
|
3
|
-
import { FontFamily, FontWeight } from '../types';
|
|
4
|
-
|
|
5
|
-
export const getFontFamilyAndWeight = (
|
|
6
|
-
fontFamily: FontFamily | undefined,
|
|
7
|
-
weight: FontWeight
|
|
8
|
-
): { fontFamily: string; fontWeight: string } =>
|
|
9
|
-
Platform.OS === 'web'
|
|
10
|
-
? {
|
|
11
|
-
fontFamily: fontFamily ? fontFamily[weight] : fontStack.default,
|
|
12
|
-
fontWeight: fontWeight[weight],
|
|
13
|
-
}
|
|
14
|
-
: {
|
|
15
|
-
fontFamily: fontFamily ? fontFamily[weight] : nativeFontStack[weight],
|
|
16
|
-
fontWeight: fontWeight[weight],
|
|
17
|
-
};
|
package/src/styles/index.ts
DELETED
package/src/types/pie.ts
DELETED
package/src/types/svg.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FontWeight } from './font';
|
|
2
|
-
|
|
3
|
-
export type AlignmentBaseline =
|
|
4
|
-
| 'baseline'
|
|
5
|
-
| 'text-bottom'
|
|
6
|
-
| 'alphabetic'
|
|
7
|
-
| 'ideographic'
|
|
8
|
-
| 'middle'
|
|
9
|
-
| 'central'
|
|
10
|
-
| 'mathematical'
|
|
11
|
-
| 'text-top'
|
|
12
|
-
| 'bottom'
|
|
13
|
-
| 'center'
|
|
14
|
-
| 'top'
|
|
15
|
-
| 'text-before-edge'
|
|
16
|
-
| 'text-after-edge'
|
|
17
|
-
| 'before-edge'
|
|
18
|
-
| 'after-edge'
|
|
19
|
-
| 'hanging';
|
|
20
|
-
|
|
21
|
-
export type TextAnchor = 'start' | 'middle' | 'end';
|
|
22
|
-
|
|
23
|
-
export type SvgTextType = {
|
|
24
|
-
textAnchor?: TextAnchor;
|
|
25
|
-
alignmentBaseline?: AlignmentBaseline;
|
|
26
|
-
fontSize?: number;
|
|
27
|
-
fontWeight?: FontWeight;
|
|
28
|
-
// fontFamily: string;
|
|
29
|
-
fill?: string;
|
|
30
|
-
y?: number;
|
|
31
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|