@tecsinapse/react-charts 0.1.0 → 1.3.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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 TecSinapse
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# TecSinapse Design System
|
|
4
|
+
|
|
5
|
+
[](https://github.com/tecsinapse/design-system/) [](./LICENSE.md) [](CODE_OF_CONDUCT.md)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[TecSinapse Design System](https://tecsinapse.github.io/design-system) is the hybrid implementation of the [TecSinapse](https://www.tecsinapse.com.br/) Design System.
|
|
9
|
+
Our primary goal is to create a system that can be used to build a wide variety of TecSinapase websites and apps, while providing a consistent and inclusive user experience to our end users.
|
|
10
|
+
In addition, the design system and component library should be easy to use for developers and designers.
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
Here are a few helpful links for getting started:
|
|
17
|
+
|
|
18
|
+
- [Documentation](https://tecsinapse.github.io/design-system) - Learn how to use and view the components in Storybook.
|
|
19
|
+
- [Getting started](https://tecsinapse.github.io/design-system/?path=/docs/introduction-getting-started--page) - Set up a new app with our DS or add it to an existing project.
|
|
20
|
+
- [Design Principles](https://tecsinapse.github.io/design-system/?path=/docs/introduction-design-principles--page) - Discover the guiding principles behind design.
|
|
21
|
+
- [Theming](https://tecsinapse.github.io/design-system/?path=/docs/advanced-theme--page) - Learn about our foundations such as colors, spacing, and typography.
|
|
22
|
+
- [Contribute](https://tecsinapse.github.io/design-system/?path=/docs/introduction-contributing--page) - File a bug report, suggest a change, or open a pull request.
|
|
23
|
+
|
|
24
|
+
## Packages
|
|
25
|
+
|
|
26
|
+
| Package | Content | Version |
|
|
27
|
+
|-----------------------------------------------------------------|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
28
|
+
| **[@tecsinapse/react-core](./packages/react-core)** | the core hybrid React component library | [](https://badge.fury.io/js/%40tecsinapse%2Freact-core) |
|
|
29
|
+
| **[@tecsinapse/react-web-kit](./packages/react-web-kit)** | the React component library focused on web | [](https://badge.fury.io/js/%40tecsinapse%2Freact-web-kit) |
|
|
30
|
+
| **[@tecsinapse/react-native-kit](./packages/react-native-kit)** | the React native component library focused on mobile | [](https://badge.fury.io/js/%40tecsinapse%2Freact-native-kit) |
|
|
31
|
+
| **[@tecsinapse/react-charts](./packages/react-charts)** | Charts for React based on SVG | [](https://badge.fury.io/js/%40tecsinapse%2Freact-charts) |
|
|
32
|
+
|
|
33
|
+
## Code of conduct
|
|
34
|
+
|
|
35
|
+
We want to foster an inclusive and friendly community around our Open Source efforts. This project follows the Contributor Covenant Code of Conduct. Please, [read it and follow it](./CODE_OF_CONDUCT.md).
|
|
36
|
+
|
|
37
|
+
If you feel another member of the community violated our code or you are experiencing problems participating in our community because of another individual's behavior, please get in touch with our maintainers.
|
|
38
|
+
|
|
39
|
+
## How to make local changes available for other projects?
|
|
40
|
+
|
|
41
|
+
At times, it may be necessary to test changes directly in a product, and not in the design system, and for this to work in a less laborious way, we can follow the steps below:
|
|
42
|
+
|
|
43
|
+
3 terminal tabs should open:
|
|
44
|
+
- In one run the JS code watch:
|
|
45
|
+
```
|
|
46
|
+
yarn build:watch
|
|
47
|
+
```
|
|
48
|
+
- In another run the watch of the TS code watch
|
|
49
|
+
```
|
|
50
|
+
yarn build:declarations:watch
|
|
51
|
+
```
|
|
52
|
+
- On another run yalc push (this script updates linked local projects)
|
|
53
|
+
```
|
|
54
|
+
yarn yalc:push
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
With that, all changes will be in yalc locally.
|
|
58
|
+
|
|
59
|
+
To access in your application, see this [example](https://github.com/tecsinapse/vendas-web-poc-playground#tools) in topic "**Yalc link Design System:**"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Maintainers
|
|
63
|
+
|
|
64
|
+
- [Beatriz Silva](mailto:beatriz.silva@tecsinapse.com.br)
|
|
65
|
+
- [Denner Vidal](mailto:denner.vidal@tecsinapse.com.br)
|
|
66
|
+
- [Gabriel Sanches](mailto:gabriel.sanches@tecsinapse.com.br)
|
|
67
|
+
- [Lucas Ramos](mailto:lucas.ramos@tecsinapse.com.br)
|
|
68
|
+
- [Nilson Antonio](mailto:nilson.antonio@tecsinapse.com.br)
|
|
69
|
+
- [Ryan Correa](mailto:ryan.correa@tecsinapse.com.br)
|
|
70
|
+
|
|
71
|
+
## Contributing
|
|
72
|
+
|
|
73
|
+
If you have ideas for how we could improve this readme or the project in general, [let us know](https://github.com/tecsinapse/design-system/issues)!
|
|
74
|
+
|
|
75
|
+
## About TecSinapse
|
|
76
|
+
|
|
77
|
+
[TecSinapse](https://www.tecsinapse.com.br/) is a specialist in the automotive industry for over 15 years.
|
|
78
|
+
We operate with diverse integrated solutions, from client prospecting to after-sales, plus market indicators tools and process improvement for complete management.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var styled = require('./styled.js');
|
|
5
|
+
|
|
6
|
+
const Dot = ({ color }) => {
|
|
7
|
+
return /* @__PURE__ */ React.createElement(styled.Circle, { color }, /* @__PURE__ */ React.createElement(styled.CircleDot, null));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = Dot;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styled = require('@emotion/native');
|
|
4
|
+
var reactNative = require('react-native');
|
|
5
|
+
var constants = require('../../styles/constants.js');
|
|
6
|
+
|
|
7
|
+
const Circle = styled(reactNative.View)`
|
|
8
|
+
background-color: ${({ color }) => color};
|
|
9
|
+
width: ${constants.iconSize.micro};
|
|
10
|
+
height: ${constants.iconSize.micro};
|
|
11
|
+
border-radius: ${constants.borderRadius.pill};
|
|
12
|
+
justify-content: center;
|
|
13
|
+
align-items: center;
|
|
14
|
+
margin-right: ${constants.spacing.centi};
|
|
15
|
+
`;
|
|
16
|
+
const CircleDot = styled(reactNative.View)`
|
|
17
|
+
background-color: #fff;
|
|
18
|
+
width: 4px;
|
|
19
|
+
height: 4px;
|
|
20
|
+
border-radius: ${constants.borderRadius.pill};
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
exports.Circle = Circle;
|
|
24
|
+
exports.CircleDot = CircleDot;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var Dot = require('../Dot/Dot.js');
|
|
5
|
+
var styled = require('./styled.js');
|
|
6
|
+
var functions = require('../../styles/functions.js');
|
|
7
|
+
|
|
8
|
+
const Label = ({ columns, data, chartConfig }) => {
|
|
9
|
+
const valueFont = functions.getFontFamilyAndWeight(chartConfig?.fontFamily, "bold");
|
|
10
|
+
const labelFont = functions.getFontFamilyAndWeight(chartConfig?.fontFamily, "regular");
|
|
11
|
+
return /* @__PURE__ */ React.createElement(styled.Container, { columns }, /* @__PURE__ */ React.createElement(Dot, { color: data.color }), /* @__PURE__ */ React.createElement(styled.Text, { font: labelFont, expand: true }, data.label), /* @__PURE__ */ React.createElement(styled.Text, { font: valueFont, flexEnd: true }, data.value));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports = Label;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styled = require('@emotion/native');
|
|
4
|
+
var reactNative = require('react-native');
|
|
5
|
+
var constants = require('../../styles/constants.js');
|
|
6
|
+
|
|
7
|
+
const flexBasis = (columns) => styled.css({ flexBasis: `${100 / columns - 2}%` });
|
|
8
|
+
const Container = styled(reactNative.View)(
|
|
9
|
+
({ columns }) => styled.css`
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: row;
|
|
12
|
+
align-items: center;
|
|
13
|
+
margin-bottom: ${constants.spacing.centi};
|
|
14
|
+
${flexBasis(columns)}
|
|
15
|
+
`
|
|
16
|
+
);
|
|
17
|
+
const expandStyles = (expand) => expand && styled.css`
|
|
18
|
+
flex: 1;
|
|
19
|
+
`;
|
|
20
|
+
const flexEndStyles = (flexEnd) => flexEnd && styled.css`
|
|
21
|
+
justify-content: flex-end;
|
|
22
|
+
`;
|
|
23
|
+
const Text = styled(reactNative.Text)(({ font, expand = false, flexEnd = false }) => {
|
|
24
|
+
const { fontFamily, fontWeight } = font;
|
|
25
|
+
return styled.css`
|
|
26
|
+
font-size: 14px;
|
|
27
|
+
font-family: ${fontFamily};
|
|
28
|
+
font-weight: ${fontWeight};
|
|
29
|
+
${expandStyles(expand)}
|
|
30
|
+
${flexEndStyles(flexEnd)}
|
|
31
|
+
`;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.Container = Container;
|
|
35
|
+
exports.Text = Text;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactNativeSvg = require('react-native-svg');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var reactNativeSvgCharts = require('react-native-svg-charts');
|
|
6
|
+
var Label = require('../Label/Label.js');
|
|
7
|
+
var functions = require('./functions.js');
|
|
8
|
+
var styled = require('./styled.js');
|
|
9
|
+
|
|
10
|
+
const PieChart = ({
|
|
11
|
+
data,
|
|
12
|
+
dimension = 200,
|
|
13
|
+
radius = 32,
|
|
14
|
+
label,
|
|
15
|
+
sub,
|
|
16
|
+
labelProps,
|
|
17
|
+
subProps,
|
|
18
|
+
columns = 1,
|
|
19
|
+
chartConfig
|
|
20
|
+
}) => {
|
|
21
|
+
const inner = 90 - radius * 100 / (dimension / 2);
|
|
22
|
+
const chart = data.map((item, index) => ({
|
|
23
|
+
value: item.value,
|
|
24
|
+
svg: {
|
|
25
|
+
fill: item.color,
|
|
26
|
+
...functions.getCallback(item.value, item.label, item.onPress)
|
|
27
|
+
},
|
|
28
|
+
...functions.getFeatured(item.featured ?? false),
|
|
29
|
+
key: `pie-${index}`
|
|
30
|
+
}));
|
|
31
|
+
const sum = data.reduce((prev, curr) => prev + curr.value, 0);
|
|
32
|
+
const {
|
|
33
|
+
textAnchor,
|
|
34
|
+
alignmentBaseline,
|
|
35
|
+
fontSize = 32,
|
|
36
|
+
fontWeight,
|
|
37
|
+
fontFamily,
|
|
38
|
+
fill,
|
|
39
|
+
y = sub ? -5 : void 0
|
|
40
|
+
} = functions.getTextStyles(labelProps, "bold", chartConfig);
|
|
41
|
+
const {
|
|
42
|
+
textAnchor: textAnchorSub,
|
|
43
|
+
alignmentBaseline: alignmentBaselineSub,
|
|
44
|
+
fontSize: fontSizeSub = 14,
|
|
45
|
+
fontWeight: fontWeightSub,
|
|
46
|
+
fontFamily: fontFamilySub,
|
|
47
|
+
fill: fillSub,
|
|
48
|
+
y: ySub = 16
|
|
49
|
+
} = functions.getTextStyles(subProps, "bold", chartConfig);
|
|
50
|
+
return /* @__PURE__ */ React.createElement(styled.Container, null, /* @__PURE__ */ React.createElement(
|
|
51
|
+
reactNativeSvgCharts.PieChart,
|
|
52
|
+
{
|
|
53
|
+
style: { width: dimension, height: dimension, flex: 1 },
|
|
54
|
+
data: chart,
|
|
55
|
+
padAngle: 0,
|
|
56
|
+
innerRadius: `${inner}%`
|
|
57
|
+
},
|
|
58
|
+
/* @__PURE__ */ React.createElement(
|
|
59
|
+
reactNativeSvg.Text,
|
|
60
|
+
{
|
|
61
|
+
textAnchor,
|
|
62
|
+
alignmentBaseline,
|
|
63
|
+
fontSize,
|
|
64
|
+
fontWeight,
|
|
65
|
+
fontFamily,
|
|
66
|
+
fill,
|
|
67
|
+
y
|
|
68
|
+
},
|
|
69
|
+
label ?? sum
|
|
70
|
+
),
|
|
71
|
+
sub && /* @__PURE__ */ React.createElement(
|
|
72
|
+
reactNativeSvg.Text,
|
|
73
|
+
{
|
|
74
|
+
textAnchor: textAnchorSub,
|
|
75
|
+
alignmentBaseline: alignmentBaselineSub,
|
|
76
|
+
fontSize: fontSizeSub,
|
|
77
|
+
fontWeight: fontWeightSub,
|
|
78
|
+
fontFamily: fontFamilySub,
|
|
79
|
+
fill: fillSub,
|
|
80
|
+
y: ySub
|
|
81
|
+
},
|
|
82
|
+
sub
|
|
83
|
+
)
|
|
84
|
+
), /* @__PURE__ */ React.createElement(styled.LabelsContainer, null, data.map((item) => /* @__PURE__ */ React.createElement(
|
|
85
|
+
Label,
|
|
86
|
+
{
|
|
87
|
+
data: item,
|
|
88
|
+
columns,
|
|
89
|
+
key: item.label,
|
|
90
|
+
chartConfig
|
|
91
|
+
}
|
|
92
|
+
))));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
module.exports = PieChart;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactNative = require('react-native');
|
|
4
|
+
var constants = require('../../styles/constants.js');
|
|
5
|
+
var functions = require('../../styles/functions.js');
|
|
6
|
+
|
|
7
|
+
const getCallback = (value, label, fn) => {
|
|
8
|
+
if (!fn)
|
|
9
|
+
return {};
|
|
10
|
+
return reactNative.Platform.OS === "web" ? {
|
|
11
|
+
onClick: () => fn?.(value, label)
|
|
12
|
+
} : {
|
|
13
|
+
onPress: () => fn?.(value, label)
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const getFeatured = (featured) => ({
|
|
17
|
+
arc: { outerRadius: featured ? "100%" : "90%" }
|
|
18
|
+
});
|
|
19
|
+
const getTextStyles = (styles, defaultFontWeight, chartConfig) => {
|
|
20
|
+
const {
|
|
21
|
+
textAnchor = "middle",
|
|
22
|
+
alignmentBaseline = "middle",
|
|
23
|
+
fontSize,
|
|
24
|
+
fill = constants.fontColor.dark,
|
|
25
|
+
y
|
|
26
|
+
} = styles || {};
|
|
27
|
+
return {
|
|
28
|
+
textAnchor,
|
|
29
|
+
alignmentBaseline,
|
|
30
|
+
fontSize,
|
|
31
|
+
fill,
|
|
32
|
+
y,
|
|
33
|
+
...functions.getFontFamilyAndWeight(
|
|
34
|
+
chartConfig?.fontFamily,
|
|
35
|
+
styles?.fontWeight ?? defaultFontWeight
|
|
36
|
+
)
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.getCallback = getCallback;
|
|
41
|
+
exports.getFeatured = getFeatured;
|
|
42
|
+
exports.getTextStyles = getTextStyles;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styled = require('@emotion/native');
|
|
4
|
+
var reactNative = require('react-native');
|
|
5
|
+
|
|
6
|
+
const Container = styled(reactNative.View)`
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
flex: 1;
|
|
12
|
+
`;
|
|
13
|
+
const LabelsContainer = styled(reactNative.View)`
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: row;
|
|
16
|
+
flex-wrap: wrap;
|
|
17
|
+
justify-content: space-between;
|
|
18
|
+
width: 100%;
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
exports.Container = Container;
|
|
22
|
+
exports.LabelsContainer = LabelsContainer;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var PieChart = require('./components/PieChart/PieChart.js');
|
|
4
|
+
var constants = require('./styles/constants.js');
|
|
5
|
+
var functions = require('./styles/functions.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.PieChart = PieChart;
|
|
10
|
+
exports.borderRadius = constants.borderRadius;
|
|
11
|
+
exports.fontColor = constants.fontColor;
|
|
12
|
+
exports.fontStack = constants.fontStack;
|
|
13
|
+
exports.fontWeight = constants.fontWeight;
|
|
14
|
+
exports.iconSize = constants.iconSize;
|
|
15
|
+
exports.nativeFontStack = constants.nativeFontStack;
|
|
16
|
+
exports.spacing = constants.spacing;
|
|
17
|
+
exports.getFontFamilyAndWeight = functions.getFontFamilyAndWeight;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fontColor = {
|
|
4
|
+
light: "#fff",
|
|
5
|
+
medium: "#85807a",
|
|
6
|
+
dark: "#353231",
|
|
7
|
+
// default
|
|
8
|
+
orange: "#f89907"
|
|
9
|
+
};
|
|
10
|
+
const spacing = {
|
|
11
|
+
nano: "2px",
|
|
12
|
+
micro: "4px",
|
|
13
|
+
mili: "8px",
|
|
14
|
+
centi: "12px",
|
|
15
|
+
deca: "16px",
|
|
16
|
+
kilo: "24px",
|
|
17
|
+
mega: "32px",
|
|
18
|
+
giga: "40px",
|
|
19
|
+
tera: "48px",
|
|
20
|
+
peta: "56px",
|
|
21
|
+
hexa: "64px"
|
|
22
|
+
};
|
|
23
|
+
const iconSize = {
|
|
24
|
+
micro: "12px",
|
|
25
|
+
mili: "14px",
|
|
26
|
+
centi: "16px",
|
|
27
|
+
// '1rem'
|
|
28
|
+
deca: "18px",
|
|
29
|
+
// '1.5rem'
|
|
30
|
+
kilo: "24px",
|
|
31
|
+
// '1.6rem'
|
|
32
|
+
mega: "32px"
|
|
33
|
+
// '2rem'
|
|
34
|
+
};
|
|
35
|
+
const borderRadius = {
|
|
36
|
+
nano: "2px",
|
|
37
|
+
micro: "4px",
|
|
38
|
+
mili: "8px",
|
|
39
|
+
centi: "16px",
|
|
40
|
+
deca: "24px",
|
|
41
|
+
pill: "999999px"
|
|
42
|
+
// also circle
|
|
43
|
+
};
|
|
44
|
+
const fontStack = {
|
|
45
|
+
default: "Lato",
|
|
46
|
+
mono: "Consolas, monaco, monospace"
|
|
47
|
+
};
|
|
48
|
+
const fontWeight = {
|
|
49
|
+
regular: "400",
|
|
50
|
+
bold: "700",
|
|
51
|
+
black: "900"
|
|
52
|
+
};
|
|
53
|
+
const nativeFontStack = {
|
|
54
|
+
black: "Lato-Black",
|
|
55
|
+
bold: "Lato-Bold",
|
|
56
|
+
regular: "Lato-Regular"
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.borderRadius = borderRadius;
|
|
60
|
+
exports.fontColor = fontColor;
|
|
61
|
+
exports.fontStack = fontStack;
|
|
62
|
+
exports.fontWeight = fontWeight;
|
|
63
|
+
exports.iconSize = iconSize;
|
|
64
|
+
exports.nativeFontStack = nativeFontStack;
|
|
65
|
+
exports.spacing = spacing;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactNative = require('react-native');
|
|
4
|
+
var constants = require('./constants.js');
|
|
5
|
+
|
|
6
|
+
const getFontFamilyAndWeight = (fontFamily, weight) => reactNative.Platform.OS === "web" ? {
|
|
7
|
+
fontFamily: fontFamily ? fontFamily[weight] : constants.fontStack.default,
|
|
8
|
+
fontWeight: constants.fontWeight[weight]
|
|
9
|
+
} : {
|
|
10
|
+
fontFamily: fontFamily ? fontFamily[weight] : constants.nativeFontStack[weight],
|
|
11
|
+
fontWeight: constants.fontWeight[weight]
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.getFontFamilyAndWeight = getFontFamilyAndWeight;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import styled from '@emotion/native';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { iconSize, borderRadius, spacing } from '../../styles/constants.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const Circle = styled(View)`
|
|
6
6
|
background-color: ${({ color }) => color};
|
|
7
7
|
width: ${iconSize.micro};
|
|
8
8
|
height: ${iconSize.micro};
|
|
@@ -11,10 +11,11 @@ export const Circle = styled(View)<{ color: string }>`
|
|
|
11
11
|
align-items: center;
|
|
12
12
|
margin-right: ${spacing.centi};
|
|
13
13
|
`;
|
|
14
|
-
|
|
15
|
-
export const CircleDot = styled(View)`
|
|
14
|
+
const CircleDot = styled(View)`
|
|
16
15
|
background-color: #fff;
|
|
17
16
|
width: 4px;
|
|
18
17
|
height: 4px;
|
|
19
18
|
border-radius: ${borderRadius.pill};
|
|
20
19
|
`;
|
|
20
|
+
|
|
21
|
+
export { Circle, CircleDot };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Dot from '../Dot/Dot.js';
|
|
3
|
+
import { Container, Text } from './styled.js';
|
|
4
|
+
import { getFontFamilyAndWeight } from '../../styles/functions.js';
|
|
5
|
+
|
|
6
|
+
const Label = ({ columns, data, chartConfig }) => {
|
|
7
|
+
const valueFont = getFontFamilyAndWeight(chartConfig?.fontFamily, "bold");
|
|
8
|
+
const labelFont = getFontFamilyAndWeight(chartConfig?.fontFamily, "regular");
|
|
9
|
+
return /* @__PURE__ */ React.createElement(Container, { columns }, /* @__PURE__ */ React.createElement(Dot, { color: data.color }), /* @__PURE__ */ React.createElement(Text, { font: labelFont, expand: true }, data.label), /* @__PURE__ */ React.createElement(Text, { font: valueFont, flexEnd: true }, data.value));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { Label as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import styled, { css } from '@emotion/native';
|
|
2
|
+
import { View, Text as Text$1 } from 'react-native';
|
|
3
|
+
import { spacing } from '../../styles/constants.js';
|
|
4
|
+
|
|
5
|
+
const flexBasis = (columns) => css({ flexBasis: `${100 / columns - 2}%` });
|
|
6
|
+
const Container = styled(View)(
|
|
7
|
+
({ columns }) => css`
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: row;
|
|
10
|
+
align-items: center;
|
|
11
|
+
margin-bottom: ${spacing.centi};
|
|
12
|
+
${flexBasis(columns)}
|
|
13
|
+
`
|
|
14
|
+
);
|
|
15
|
+
const expandStyles = (expand) => expand && css`
|
|
16
|
+
flex: 1;
|
|
17
|
+
`;
|
|
18
|
+
const flexEndStyles = (flexEnd) => flexEnd && css`
|
|
19
|
+
justify-content: flex-end;
|
|
20
|
+
`;
|
|
21
|
+
const Text = styled(Text$1)(({ font, expand = false, flexEnd = false }) => {
|
|
22
|
+
const { fontFamily, fontWeight } = font;
|
|
23
|
+
return css`
|
|
24
|
+
font-size: 14px;
|
|
25
|
+
font-family: ${fontFamily};
|
|
26
|
+
font-weight: ${fontWeight};
|
|
27
|
+
${expandStyles(expand)}
|
|
28
|
+
${flexEndStyles(flexEnd)}
|
|
29
|
+
`;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export { Container, Text };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Text } from 'react-native-svg';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { PieChart as PieChart$1 } from 'react-native-svg-charts';
|
|
4
|
+
import Label from '../Label/Label.js';
|
|
5
|
+
import { getCallback, getFeatured, getTextStyles } from './functions.js';
|
|
6
|
+
import { Container, LabelsContainer } from './styled.js';
|
|
7
|
+
|
|
8
|
+
const PieChart = ({
|
|
9
|
+
data,
|
|
10
|
+
dimension = 200,
|
|
11
|
+
radius = 32,
|
|
12
|
+
label,
|
|
13
|
+
sub,
|
|
14
|
+
labelProps,
|
|
15
|
+
subProps,
|
|
16
|
+
columns = 1,
|
|
17
|
+
chartConfig
|
|
18
|
+
}) => {
|
|
19
|
+
const inner = 90 - radius * 100 / (dimension / 2);
|
|
20
|
+
const chart = data.map((item, index) => ({
|
|
21
|
+
value: item.value,
|
|
22
|
+
svg: {
|
|
23
|
+
fill: item.color,
|
|
24
|
+
...getCallback(item.value, item.label, item.onPress)
|
|
25
|
+
},
|
|
26
|
+
...getFeatured(item.featured ?? false),
|
|
27
|
+
key: `pie-${index}`
|
|
28
|
+
}));
|
|
29
|
+
const sum = data.reduce((prev, curr) => prev + curr.value, 0);
|
|
30
|
+
const {
|
|
31
|
+
textAnchor,
|
|
32
|
+
alignmentBaseline,
|
|
33
|
+
fontSize = 32,
|
|
34
|
+
fontWeight,
|
|
35
|
+
fontFamily,
|
|
36
|
+
fill,
|
|
37
|
+
y = sub ? -5 : void 0
|
|
38
|
+
} = getTextStyles(labelProps, "bold", chartConfig);
|
|
39
|
+
const {
|
|
40
|
+
textAnchor: textAnchorSub,
|
|
41
|
+
alignmentBaseline: alignmentBaselineSub,
|
|
42
|
+
fontSize: fontSizeSub = 14,
|
|
43
|
+
fontWeight: fontWeightSub,
|
|
44
|
+
fontFamily: fontFamilySub,
|
|
45
|
+
fill: fillSub,
|
|
46
|
+
y: ySub = 16
|
|
47
|
+
} = getTextStyles(subProps, "bold", chartConfig);
|
|
48
|
+
return /* @__PURE__ */ React.createElement(Container, null, /* @__PURE__ */ React.createElement(
|
|
49
|
+
PieChart$1,
|
|
50
|
+
{
|
|
51
|
+
style: { width: dimension, height: dimension, flex: 1 },
|
|
52
|
+
data: chart,
|
|
53
|
+
padAngle: 0,
|
|
54
|
+
innerRadius: `${inner}%`
|
|
55
|
+
},
|
|
56
|
+
/* @__PURE__ */ React.createElement(
|
|
57
|
+
Text,
|
|
58
|
+
{
|
|
59
|
+
textAnchor,
|
|
60
|
+
alignmentBaseline,
|
|
61
|
+
fontSize,
|
|
62
|
+
fontWeight,
|
|
63
|
+
fontFamily,
|
|
64
|
+
fill,
|
|
65
|
+
y
|
|
66
|
+
},
|
|
67
|
+
label ?? sum
|
|
68
|
+
),
|
|
69
|
+
sub && /* @__PURE__ */ React.createElement(
|
|
70
|
+
Text,
|
|
71
|
+
{
|
|
72
|
+
textAnchor: textAnchorSub,
|
|
73
|
+
alignmentBaseline: alignmentBaselineSub,
|
|
74
|
+
fontSize: fontSizeSub,
|
|
75
|
+
fontWeight: fontWeightSub,
|
|
76
|
+
fontFamily: fontFamilySub,
|
|
77
|
+
fill: fillSub,
|
|
78
|
+
y: ySub
|
|
79
|
+
},
|
|
80
|
+
sub
|
|
81
|
+
)
|
|
82
|
+
), /* @__PURE__ */ React.createElement(LabelsContainer, null, data.map((item) => /* @__PURE__ */ React.createElement(
|
|
83
|
+
Label,
|
|
84
|
+
{
|
|
85
|
+
data: item,
|
|
86
|
+
columns,
|
|
87
|
+
key: item.label,
|
|
88
|
+
chartConfig
|
|
89
|
+
}
|
|
90
|
+
))));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { PieChart as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { fontColor } from '../../styles/constants.js';
|
|
3
|
+
import { getFontFamilyAndWeight } from '../../styles/functions.js';
|
|
4
|
+
|
|
5
|
+
const getCallback = (value, label, fn) => {
|
|
6
|
+
if (!fn)
|
|
7
|
+
return {};
|
|
8
|
+
return Platform.OS === "web" ? {
|
|
9
|
+
onClick: () => fn?.(value, label)
|
|
10
|
+
} : {
|
|
11
|
+
onPress: () => fn?.(value, label)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const getFeatured = (featured) => ({
|
|
15
|
+
arc: { outerRadius: featured ? "100%" : "90%" }
|
|
16
|
+
});
|
|
17
|
+
const getTextStyles = (styles, defaultFontWeight, chartConfig) => {
|
|
18
|
+
const {
|
|
19
|
+
textAnchor = "middle",
|
|
20
|
+
alignmentBaseline = "middle",
|
|
21
|
+
fontSize,
|
|
22
|
+
fill = fontColor.dark,
|
|
23
|
+
y
|
|
24
|
+
} = styles || {};
|
|
25
|
+
return {
|
|
26
|
+
textAnchor,
|
|
27
|
+
alignmentBaseline,
|
|
28
|
+
fontSize,
|
|
29
|
+
fill,
|
|
30
|
+
y,
|
|
31
|
+
...getFontFamilyAndWeight(
|
|
32
|
+
chartConfig?.fontFamily,
|
|
33
|
+
styles?.fontWeight ?? defaultFontWeight
|
|
34
|
+
)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { getCallback, getFeatured, getTextStyles };
|