impaktapps-design 0.0.1

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.
@@ -0,0 +1,113 @@
1
+ import React from "react";
2
+ import { Group } from "@visx/group";
3
+ import { scaleOrdinal } from "@visx/scale";
4
+ import { Pie } from "@visx/shape";
5
+ import { Text } from "@visx/text";
6
+ import { useTooltip } from "@visx/tooltip";
7
+ import Legend from "../Legend";
8
+ import ToolTip from "../ToolTip";
9
+
10
+ const DrawPieGraph = ({ value, parentWidth, parentHeight }: any) => {
11
+ const letters = value?.main?.data;
12
+ const arr =
13
+ value?.main?.xAxisValue && value?.main?.yAxisValue
14
+ ? [value?.main?.xAxisValue, value?.main?.yAxisValue]
15
+ : Object.keys(letters[0]);
16
+ const frequency = (d: any) => d[arr[1]];
17
+ const getLetterFrequencyColor = scaleOrdinal({
18
+ domain: letters.map((l:[any]) => l[arr[0]]),
19
+ range: value?.style?.pieStyle?.colorRange,
20
+ });
21
+
22
+ const {
23
+ tooltipData,
24
+ tooltipLeft,
25
+ tooltipTop,
26
+ tooltipOpen,
27
+ showTooltip,
28
+ hideTooltip,
29
+ }: any = useTooltip();
30
+ const handleMouse = (event: any, datum: any) => {
31
+ showTooltip({
32
+ tooltipLeft: event.clientX,
33
+ tooltipTop: event.clientY,
34
+ tooltipData: [datum[arr[0]], datum[arr[1]]],
35
+ });
36
+ };
37
+
38
+ const innerWidth = parentWidth - 40;
39
+ const innerHeight = parentHeight - 40;
40
+ const centerX = innerWidth / 2;
41
+ const centerY = innerHeight / 2;
42
+ const left = centerX + 20;
43
+ const top = centerY + 20;
44
+ const pieSortValues = (a: number, b: number) => a - b;
45
+ return (
46
+ <>
47
+ {value?.main?.legendAvailable && (
48
+ <Legend
49
+ value={value}
50
+ />
51
+ )}
52
+ <svg
53
+ width={parentWidth}
54
+ height={parentHeight}
55
+ className="pieGraphContainer"
56
+ >
57
+ <Group top={top} left={left}>
58
+ <Pie
59
+ data={letters}
60
+ pieSortValues={pieSortValues}
61
+ pieValue={frequency}
62
+ outerRadius={value?.style?.pieStyle?.outerRadius}
63
+ innerRadius={value?.style?.pieStyle?.innerRadius}
64
+ cornerRadius={value?.style?.pieStyle?.cornerRadius}
65
+ padAngle={value?.style?.pieStyle?.padAngle}
66
+ >
67
+ {(pie) => {
68
+ return pie.arcs.map((arc, index) => {
69
+ const letter = value?.style?.pieStyle?.showPieLabel?arc.data[arr[0]]:arc.data[arr[1]];
70
+ const [centriodX, centriodY] = pie.path.centroid(arc);
71
+ const arcPath = pie.path(arc);
72
+ const arcFill: any = getLetterFrequencyColor(letter);
73
+ return (
74
+ <g
75
+ key={`arc-${letter}-${index}`}
76
+ onMouseOut={hideTooltip}
77
+ onMouseOver={(e) => handleMouse(e, arc.data)}
78
+ className="pieTooltipHolder"
79
+ >
80
+
81
+ <path
82
+ //@ts-ignore
83
+ d={arcPath} fill={arcFill} />
84
+ <Text
85
+ x={centriodX}
86
+ y={centriodY}
87
+ dy={"0.33em"}
88
+ fontSize={14}
89
+ fill={ value?.style?.pieStyle?.pieLabelColor||"white"}
90
+ textAnchor={"middle"}
91
+ pointerEvents={"none"}
92
+ >
93
+ {letter}
94
+ </Text>
95
+ </g>
96
+ );
97
+ });
98
+ }}
99
+ </Pie>
100
+ </Group>
101
+ </svg>
102
+ {tooltipOpen && (
103
+ <ToolTip
104
+ style={value?.style}
105
+ top={tooltipTop}
106
+ left={tooltipLeft}
107
+ tooltipData={tooltipData}
108
+ />
109
+ )}
110
+ </>
111
+ );
112
+ };
113
+ export default DrawPieGraph;
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import DrawPieGraph from "./DrawPieGraph";
3
+ import { ParentSize } from "@visx/responsive";
4
+ import { finalDataProvider } from "../../utils/finalDataProvider";
5
+
6
+ const PieGraph = ({ value }: any) => {
7
+ const pieData: any = finalDataProvider("PieGraph", value);
8
+ let PieRender = (
9
+ <ParentSize>
10
+ {(parent) => (
11
+ <DrawPieGraph
12
+ parentWidth={parent.width}
13
+ parentHeight={parseInt(pieData.style.containerStyle.height)}
14
+ //@ts-ignore
15
+ parentRef={parent.ref}
16
+ resizeParent={parent.resize}
17
+ value={pieData}
18
+ />
19
+ )}
20
+ </ParentSize>
21
+ );
22
+ return (
23
+ <div style={pieData.style.containerStyle}>
24
+ {pieData?.main?.header && <div style={pieData.style.headerStyle}>{pieData?.main?.header}</div>}
25
+ {PieRender}
26
+ </div>
27
+ );
28
+ };
29
+
30
+ export default PieGraph;
@@ -0,0 +1,210 @@
1
+ import React, { useState , useEffect } from "react";
2
+ import "./style.css";
3
+
4
+ const ProgressBar = ({value} : any) => {
5
+ const [progress, setProgress] = useState(
6
+ (value?.main?.data?.achieved / value?.main?.data?.total) *
7
+ 100
8
+ );
9
+ useEffect(()=>{
10
+ setProgress( (value?.main?.data?.achieved / value?.main?.data?.total) *
11
+ 100)
12
+ },[value.main.data])
13
+ const getColor = () => {
14
+ if (progress < 40) {
15
+ return ["#e2b6b6","#ff0000"];
16
+ }
17
+ if (progress < 70) {
18
+ // return "#ffa500";
19
+ return ["#b6bce2","#3f51b5"];
20
+ } else {
21
+ return ["#b6e2c2","#2ecc71"];
22
+ }
23
+ };
24
+ if(value?.main?.developOnlyProgresBar){
25
+ return (<div
26
+ style={{
27
+ height: "6px",
28
+ margin: "auto",
29
+ borderRadius: "10px",
30
+ backgroundColor:value?.style?.progressBarColor|| getColor()[1],
31
+
32
+ marginBottom: "20px",
33
+ }}
34
+ >
35
+ <div
36
+ className="progress-bar-fill"
37
+ style={{
38
+ width: `${progress}%`,
39
+ backgroundColor:value?.style?.progressBarFillColor|| getColor()[1],
40
+ // backgroundColor: "#3f51b5",
41
+ height: "100%",
42
+ borderRadius: "10px",
43
+ marginBottom: "20px",
44
+ // backgroundColor: "#2ecc71",
45
+ transition: "width 0.5 ease-out",
46
+ }}
47
+ ></div>
48
+ </div>)
49
+ }
50
+ return (
51
+ <div
52
+ className="container"
53
+ style={{
54
+ backgroundColor: "white",
55
+ borderRadius: "20px",
56
+ width: "auto",
57
+ height: "auto",
58
+ margin: "auto",
59
+ padding: " 40px none",
60
+ // border: "1px solid black",
61
+ }}
62
+ >
63
+ <div
64
+ style={{
65
+ borderBottom: "1px solid #e3e8ef",
66
+ padding: "25px 0px 25px 25px",
67
+ fontWeight: 700,
68
+ textAlign: "left",
69
+ fontFamily: "inherit",
70
+ fontSize: "18px",
71
+ color: "#121926",
72
+ }}
73
+ >
74
+ {value?.main?.heading}
75
+ </div>
76
+ <div
77
+ style={{ paddingBottom: "25px", paddingTop: "25px", height: "auto" }}
78
+ >
79
+ <div
80
+ style={{
81
+ // width: "70%",
82
+ width: "90%",
83
+ height: "6px",
84
+ margin: "auto",
85
+ borderRadius: "10px",
86
+ marginBottom: "30px",
87
+ }}
88
+ >
89
+ <div
90
+ style={{
91
+ textAlign: "center",
92
+ fontWeight: 700,
93
+ marginBottom: "20px",
94
+ fontSize: "24px",
95
+ }}
96
+ >
97
+ {progress.toFixed(2)}%
98
+ </div>
99
+ <div
100
+ style={{
101
+ // width: "70%",
102
+ // width:"90%",
103
+ height: "6px",
104
+ margin: "auto",
105
+ borderRadius: "10px",
106
+ backgroundColor: getColor()[0],
107
+
108
+ marginBottom: "20px",
109
+ }}
110
+ >
111
+ <div
112
+ className="progress-bar-fill"
113
+ style={{
114
+ width: `${progress}%`,
115
+ backgroundColor: getColor()[1],
116
+ // backgroundColor: "#3f51b5",
117
+ height: "100%",
118
+ borderRadius: "10px",
119
+ marginBottom: "20px",
120
+ // backgroundColor: "#2ecc71",
121
+ transition: "width 0.5 ease-out",
122
+ }}
123
+ ></div>
124
+ </div>
125
+ </div>
126
+ <div
127
+ style={{
128
+ display: "flex",
129
+ paddingTop: "40px",
130
+ width: "90%",
131
+ margin: "auto",
132
+ }}
133
+ >
134
+ <div style={{ width: "33.33%" }}>
135
+ <div
136
+ style={{
137
+ textAlign:"left",
138
+ color: "#697586",
139
+ fontSize: "10px",
140
+ marginBottom: "10px",
141
+ }}
142
+ >
143
+ {value?.main?.bottomLabel_1||"Target"}
144
+ </div>
145
+ <div
146
+ style={{
147
+ color: "#121926",
148
+ textAlign:"left",
149
+ fontWeight: 500,
150
+ }}
151
+ >
152
+ {value?.main?.data?.total||value?.main?.data?.bottomLabel_1_value}
153
+ </div>
154
+ </div>
155
+ <div style={{ width: "33.33%" }}>
156
+ <div
157
+ style={{
158
+ textAlign:"center",
159
+ color: "#697586",
160
+ fontSize: "10px",
161
+ marginBottom: "10px",
162
+ }}
163
+ >
164
+ {value?.main?.bottomLabel_2||"Achieved"}
165
+ </div>
166
+ <div
167
+ style={{
168
+ textAlign:"center",
169
+ color: "#121926",
170
+ fontWeight: 500,
171
+ }}
172
+ >
173
+ {value?.main?.data?.achieved||value?.main?.data?.bottomLabel_2_value}
174
+ </div>
175
+ </div>
176
+ <div style={{ width: "33.33%" }}>
177
+ <div
178
+ style={{
179
+ textAlign:"right",
180
+ color: "#697586",
181
+ fontSize: "10px",
182
+ marginBottom: "10px",
183
+ }}
184
+ >
185
+ {value?.main?.bottomLabel_3||"Average"}
186
+ </div>
187
+ <div
188
+ style={{
189
+ textAlign:"right",
190
+ color: "#121926",
191
+ fontWeight: 500,
192
+ }}
193
+ >
194
+ {value?.main?.daysCount?
195
+ Math.round(
196
+ (value?.main?.data?.achieved / value?.main?.daysCount)
197
+ )+ value?.main?.bottomLabel_3_averageLabel||"/day"
198
+ :value?.main?.data?.bottomLabel_3_value
199
+ }
200
+ </div>
201
+ </div>
202
+ </div>
203
+ </div>
204
+ </div>
205
+ );
206
+ };
207
+
208
+ export default ProgressBar;
209
+
210
+
@@ -0,0 +1,40 @@
1
+ @import url("https://fonts.googleapis.com/css2?family=Roboto;600&display=swap");
2
+
3
+ .container {
4
+ margin: 0;
5
+ box-sizing: border-box;
6
+ /* background-color: #eef6f8; */
7
+ font-family: "Roboto", sans-serif;
8
+ }
9
+
10
+ /* body{
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ }
15
+
16
+ .container {
17
+ width: 200px;
18
+ margin-top: 100px;
19
+ }
20
+
21
+ .progress-bar{
22
+ width: 100%;
23
+ height: 30px;
24
+ border-radius: 10px;
25
+ background-color: #003441;
26
+ margin-bottom: 10px;
27
+ }
28
+
29
+ .progress-bar-fill{
30
+ height: 100%;
31
+ border-radius: 10px;
32
+ background-color: #2ecc71;
33
+
34
+ }
35
+ .progress-label{
36
+ margin-top: 10px;
37
+ font-size: 24px;
38
+ font-weight: bold;
39
+ color: #444444;
40
+ } */
@@ -0,0 +1,48 @@
1
+ import React from "react";
2
+ import ReactSpeedometer from "react-d3-speedometer";
3
+
4
+ const SpeedoMeter = ({ value }: any) => {
5
+ return (
6
+ <div style={{ ...value?.style?.containerStyle }}>
7
+ {value?.main?.header && (
8
+ <div
9
+ style={{
10
+ fontWeight: 700,
11
+ textAlign: "left",
12
+ fontFamily: "inherit",
13
+ fontSize: "18px",
14
+ color: "#121926",
15
+ ...value?.style?.headerStyle,
16
+ }}
17
+ >
18
+ {value.main.header}
19
+ </div>
20
+ )}
21
+ <div style={{ width: "100%", display: "flex", justifyContent: "center" }}>
22
+ <ReactSpeedometer
23
+ // needleTransition=''
24
+ segmentColors={value?.style?.segmentColors}
25
+ maxValue={value?.main?.data?.maxValue || 500}
26
+ width={value?.style?.width || 500}
27
+ needleHeightRatio={value?.style?.needleHeightRatio || 0.7}
28
+ currentValueText={value?.main?.currentValueText}
29
+ customSegmentLabels={value?.main?.customSegmentLabel}
30
+ ringWidth={value?.style?.ringWidth || 37}
31
+ needleTransitionDuration={
32
+ value?.style?.needleTransitionDuration || 5333
33
+ }
34
+ needleTransition={value?.style?.needleTransition || "easeElastic"}
35
+ value={value?.main?.data?.value || 473}
36
+ needleColor={value?.style?.needleColor || "red"}
37
+ minValue={value?.main?.data?.minValue || 0}
38
+ startColor={value?.style?.startColor || "red"}
39
+ segments={value?.main?.segments || 5}
40
+ endColor={value?.style?.endColor || "green"}
41
+ textColor={value?.style?.textColor || "black"}
42
+ />
43
+ </div>
44
+ </div>
45
+ );
46
+ };
47
+
48
+ export default SpeedoMeter;
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import { useTooltipInPortal } from "@visx/tooltip";
3
+ import { tooltipProps } from "../interface/interface";
4
+ const ToolTip = ({ style, top, left, tooltipData }: tooltipProps) => {
5
+ const { TooltipInPortal } = useTooltipInPortal({
6
+ detectBounds: true,
7
+ scroll: true,
8
+ });
9
+ return (
10
+ <TooltipInPortal
11
+
12
+ key={Math.random()} top={top} left={left}>
13
+ <div
14
+ style={{
15
+ width: "100%",
16
+ // paddingleft: "10px",
17
+ height: "auto",
18
+ textAlign:"center",
19
+ background:"black",
20
+ boxShadow:"2px 2px 5px black",
21
+ color:"#6c5efb",
22
+ padding:"15px",
23
+ ...style?.tooltipStyle,
24
+ }}
25
+ >
26
+ <div style={{paddingBottom:"2px",color:"white"}}>
27
+ {tooltipData[0]}
28
+ </div>
29
+
30
+
31
+ <div style={{marginTop:"10px"}}>
32
+ {tooltipData[1]}
33
+ </div>
34
+ </div>
35
+ </TooltipInPortal>
36
+ );
37
+ };
38
+
39
+ export default ToolTip;
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export {default as BarGraph} from "./component/BarGraph/BarGraph"
2
+ export {default as PieGraph} from "./component/PieGraph/PieGraph"
3
+ export {default as LineGraph} from "./component/LineGraph/LineGraph"
4
+ export {default as HorizontalBarGraph} from "./component/BarGraph/HorizontalBarGraph"
5
+ export {default as ProgressBar} from "./component/ProgressBar/ProgressBar"
6
+ export {default as SpeedoMeter} from "./component/SpeedoMeter/SpeedoMeter"
@@ -0,0 +1,13 @@
1
+ export interface leftAxisProps {
2
+ value: any
3
+ yScale: any
4
+ parentWidth: number
5
+ }
6
+ export interface bottomAxisProps {
7
+ data: any[], yMax: number, value: any, xScale: any, parentWidth: number
8
+ }
9
+
10
+ export interface tooltipProps {
11
+ style:any,
12
+ top:any,left:any,tooltipData:any
13
+ }
@@ -0,0 +1,6 @@
1
+ export {default as BarGraph} from "../component/BarGraph/BarGraph"
2
+ export {default as PieGraph} from "../component/PieGraph/PieGraph"
3
+ export {default as LineGraph} from "../component/LineGraph/LineGraph"
4
+ export {default as HorizontalBarGraph} from "../component/BarGraph/HorizontalBarGraph"
5
+ export {default as ProgressBar} from "../component/ProgressBar/ProgressBar"
6
+ export {default as SpeedoMeter} from "../component/SpeedoMeter/SpeedoMeter"