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.
- package/README.md +46 -0
- package/dist/impaktapps-design.es.js +35770 -0
- package/dist/style.css +1 -0
- package/package.json +64 -0
- package/src/component/BarGraph/BarGraph.tsx +34 -0
- package/src/component/BarGraph/DrawBarGraph.tsx +123 -0
- package/src/component/BarGraph/DrawHorizontalBarGraph.tsx +169 -0
- package/src/component/BarGraph/HorizontalBarGraph.tsx +26 -0
- package/src/component/BottomAxis.tsx +32 -0
- package/src/component/LeftAxis.tsx +32 -0
- package/src/component/Legend.tsx +55 -0
- package/src/component/LineGraph/DrawLineGraph.tsx +86 -0
- package/src/component/LineGraph/LineGraph.tsx +17 -0
- package/src/component/PieGraph/DrawPieGraph.tsx +113 -0
- package/src/component/PieGraph/PieGraph.tsx +30 -0
- package/src/component/ProgressBar/ProgressBar.tsx +210 -0
- package/src/component/ProgressBar/style.css +40 -0
- package/src/component/SpeedoMeter/SpeedoMeter.tsx +48 -0
- package/src/component/ToolTip.tsx +39 -0
- package/src/index.ts +6 -0
- package/src/interface/interface.ts +13 -0
- package/src/lib/index.ts +6 -0
- package/src/utils/finalDataProvider.ts +282 -0
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import"https://fonts.googleapis.com/css2?family=Roboto;600&display=swap";.container{margin:0;box-sizing:border-box;font-family:Roboto,sans-serif}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "impaktapps-design",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@babel/core": "^7.16.12",
|
|
6
|
+
"@visx/visx": "^3.1.2",
|
|
7
|
+
"@vitejs/plugin-react": "^1.1.4",
|
|
8
|
+
"babel-loader": "^8.2.3",
|
|
9
|
+
"latest-version": "^7.0.0",
|
|
10
|
+
"react-d3-speedometer": "^1.1.0",
|
|
11
|
+
"react": "^18.2.0",
|
|
12
|
+
"react-dom": "^18.2.0",
|
|
13
|
+
"react-scripts": "^2.1.3"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite",
|
|
17
|
+
"build": "tsc && vite build",
|
|
18
|
+
"preview": "vite preview"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://git.act21.io/lovely/incentivo/-/tree/Grapho_In_Development"
|
|
23
|
+
},
|
|
24
|
+
"eslintConfig": {
|
|
25
|
+
"extends": [
|
|
26
|
+
"react-app",
|
|
27
|
+
"react-app/jest"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"browserslist": {
|
|
34
|
+
"production": [
|
|
35
|
+
">0.2%",
|
|
36
|
+
"not dead",
|
|
37
|
+
"not op_mini all"
|
|
38
|
+
],
|
|
39
|
+
"development": [
|
|
40
|
+
"last 1 chrome version",
|
|
41
|
+
"last 1 firefox version",
|
|
42
|
+
"last 1 safari version"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"author": "Satendra Raghav",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"src"
|
|
50
|
+
],
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^17.0.12",
|
|
53
|
+
"@types/react": "^18.0.28",
|
|
54
|
+
"@types/react-dom": "^18.0.11",
|
|
55
|
+
"typescript": "^4.5.5",
|
|
56
|
+
"@types/jest": "^27.5.2",
|
|
57
|
+
"vite": "^2.7.13",
|
|
58
|
+
"vite-plugin-dts": "^0.9.9"
|
|
59
|
+
},
|
|
60
|
+
"main": "./dist/impaktapps-design.umd.js",
|
|
61
|
+
"module": "./dist/impaktapps-design.es.js",
|
|
62
|
+
"types": "./dist/impaktapps-design.d.ts",
|
|
63
|
+
"description": "This is Act21 product powered by ImpaktApps, this is mainly develop to provide different ready to use UI components."
|
|
64
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DrawBarGraph from "./DrawBarGraph";
|
|
3
|
+
import { ParentSize } from "@visx/responsive";
|
|
4
|
+
import { finalDataProvider } from "../../utils/finalDataProvider";
|
|
5
|
+
|
|
6
|
+
const BarGraph = ({ value }:any) => {
|
|
7
|
+
const barData:any = finalDataProvider("BarGraph",value)
|
|
8
|
+
let GraphRender = (
|
|
9
|
+
<ParentSize>
|
|
10
|
+
{(parent) => (
|
|
11
|
+
<DrawBarGraph
|
|
12
|
+
parentWidth={parent.width}
|
|
13
|
+
parentHeight={barData?.style?.containerStyle?.height}
|
|
14
|
+
margin= {{ top: barData?.style?.labelStyle?.margin?.top||10, right: barData?.style?.labelStyle?.margin?.right||10,bottom: barData?.style?.labelStyle?.margin?.bottom||20 ,left: barData?.style?.labelStyle?.margin?.left||60 }}
|
|
15
|
+
value={barData}
|
|
16
|
+
parentRef={parent.ref}
|
|
17
|
+
resizeParent={parent.resize}
|
|
18
|
+
/>
|
|
19
|
+
)}
|
|
20
|
+
</ParentSize>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return <div style={barData?.style?.containerStyle}>
|
|
24
|
+
{barData?.main?.header && <div style={{ fontWeight: 500,
|
|
25
|
+
textAlign: "left",
|
|
26
|
+
fontFamily: "inherit",
|
|
27
|
+
marginBottom:"20px",
|
|
28
|
+
padding: "15px 0 1px 20px",
|
|
29
|
+
fontSize: "18px",
|
|
30
|
+
color: "#121926",...barData?.style?.headerStyle}}>{barData?.main?.header}</div> }
|
|
31
|
+
{GraphRender}
|
|
32
|
+
</div>;
|
|
33
|
+
};
|
|
34
|
+
export default BarGraph;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Group } from "@visx/group";
|
|
3
|
+
import { Bar } from "@visx/shape";
|
|
4
|
+
import { scaleLinear, scaleBand } from "@visx/scale";
|
|
5
|
+
import { defaultStyles,useTooltip, useTooltipInPortal } from "@visx/tooltip";
|
|
6
|
+
import { localPoint } from "@visx/event";
|
|
7
|
+
import ToolTip from "../ToolTip";
|
|
8
|
+
import BottomAxis from "../BottomAxis";
|
|
9
|
+
import LeftAxis from "../LeftAxis";
|
|
10
|
+
|
|
11
|
+
const DrawBarGraph = ({
|
|
12
|
+
value,
|
|
13
|
+
parentWidth,
|
|
14
|
+
parentHeight,
|
|
15
|
+
margin
|
|
16
|
+
}: any) => {
|
|
17
|
+
const data:any[] = value?.main?.data;
|
|
18
|
+
const arr =
|
|
19
|
+
value.main?.xAxisValue && value.main?.yAxisValue
|
|
20
|
+
? [value.cosntent.xAxisValue, value.main?.yAxisValue]
|
|
21
|
+
: Object.keys(data[0]);
|
|
22
|
+
const {
|
|
23
|
+
tooltipData,
|
|
24
|
+
tooltipLeft,
|
|
25
|
+
tooltipTop,
|
|
26
|
+
tooltipOpen,
|
|
27
|
+
showTooltip,
|
|
28
|
+
hideTooltip,
|
|
29
|
+
}: any = useTooltip();
|
|
30
|
+
const { containerRef } = useTooltipInPortal({
|
|
31
|
+
detectBounds: true,
|
|
32
|
+
scroll: true,
|
|
33
|
+
});
|
|
34
|
+
const handleMouse = (event: any, datum: any) => {
|
|
35
|
+
showTooltip({
|
|
36
|
+
tooltipLeft: event.clientX,
|
|
37
|
+
tooltipTop: event.clientY,
|
|
38
|
+
tooltipData: [datum[arr[0]], datum[arr[1]]],
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const xMax:number = parentWidth - margin.left - margin.right;;
|
|
42
|
+
const yMax:number = parentHeight - margin.top - margin.bottom;
|
|
43
|
+
const x = (d: any) => d[arr[0]];
|
|
44
|
+
const y = (d: any) => +d[arr[1]];
|
|
45
|
+
const xScale = scaleBand({
|
|
46
|
+
range: [0, xMax],
|
|
47
|
+
round: true,
|
|
48
|
+
domain: data.map(x),
|
|
49
|
+
padding: 0.4,
|
|
50
|
+
});
|
|
51
|
+
const tempValue = data.reduce((total: any, curValue: any) => {
|
|
52
|
+
return total + curValue[arr[1]];
|
|
53
|
+
}, 0);
|
|
54
|
+
let averageValue = tempValue / data.length;
|
|
55
|
+
const yScale = scaleLinear({
|
|
56
|
+
range: [yMax, 0],
|
|
57
|
+
round: true,
|
|
58
|
+
domain: [0, Math.max(...data.map(y))],
|
|
59
|
+
});
|
|
60
|
+
function compose(scale: any, accessor: any) {
|
|
61
|
+
return (data: any) => scale(accessor(data));
|
|
62
|
+
}
|
|
63
|
+
const xPoint = compose(xScale, x);
|
|
64
|
+
|
|
65
|
+
const yPoint = compose(yScale, y);
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<svg ref={containerRef} width={parentWidth} height={parentHeight}>
|
|
69
|
+
<Group
|
|
70
|
+
left={value.style?.labelStyle?.leftLabelMargin}
|
|
71
|
+
top={value.style?.labelStyle?.topLabelMargin}
|
|
72
|
+
>
|
|
73
|
+
{value.main?.axisLeft && (
|
|
74
|
+
<LeftAxis value={value} yScale={yScale} parentWidth={parentWidth} />
|
|
75
|
+
)}
|
|
76
|
+
{data.map((d: any) => {
|
|
77
|
+
const barHeight = yMax - yPoint(d);
|
|
78
|
+
const fillBarColor =
|
|
79
|
+
averageValue / 2 > d[arr[1]]
|
|
80
|
+
? value.style?.barStyle?.lowValueColor
|
|
81
|
+
: averageValue < d[arr[1]]
|
|
82
|
+
? value.style?.barStyle?.highValueColor
|
|
83
|
+
: value.style?.barStyle?.mediumValueColor;
|
|
84
|
+
return (
|
|
85
|
+
<>
|
|
86
|
+
<Bar
|
|
87
|
+
key={`bar-${barHeight}`}
|
|
88
|
+
x={xPoint(d)}
|
|
89
|
+
y={yMax - barHeight}
|
|
90
|
+
radius={value.style?.barStyle?.barRadius || 0}
|
|
91
|
+
height={barHeight}
|
|
92
|
+
width={xScale.bandwidth()}
|
|
93
|
+
fill={fillBarColor}
|
|
94
|
+
onMouseOver={(e) => handleMouse(e, d)}
|
|
95
|
+
onMouseOut={hideTooltip}
|
|
96
|
+
/>
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
99
|
+
})}
|
|
100
|
+
{value.main?.axisBottom && (
|
|
101
|
+
<BottomAxis
|
|
102
|
+
data={data}
|
|
103
|
+
value={value}
|
|
104
|
+
yMax={yMax}
|
|
105
|
+
xScale={xScale}
|
|
106
|
+
parentWidth={parentWidth}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
</Group>
|
|
110
|
+
</svg>
|
|
111
|
+
{tooltipOpen && (
|
|
112
|
+
<ToolTip
|
|
113
|
+
style={{...value?.style}}
|
|
114
|
+
top={tooltipTop}
|
|
115
|
+
left={tooltipLeft}
|
|
116
|
+
tooltipData={tooltipData}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
</>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export default DrawBarGraph;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BarStackHorizontal } from "@visx/shape";
|
|
3
|
+
import { SeriesPoint } from "@visx/shape/lib/types";
|
|
4
|
+
import { Group } from "@visx/group";
|
|
5
|
+
// import { AxisBottom, AxisLeft } from "@visx/axis";
|
|
6
|
+
import {
|
|
7
|
+
CityTemperature,
|
|
8
|
+
} from "@visx/mock-data/lib/mocks/cityTemperature";
|
|
9
|
+
import { scaleBand, scaleLinear, scaleOrdinal } from "@visx/scale";
|
|
10
|
+
// import { timeParse, timeFormat } from "@visx/vendor/d3-time-format";
|
|
11
|
+
import { withTooltip, Tooltip, defaultStyles } from "@visx/tooltip";
|
|
12
|
+
import { WithTooltipProvidedProps } from "@visx/tooltip/lib/enhancers/withTooltip";
|
|
13
|
+
import BottomAxis from "../BottomAxis";
|
|
14
|
+
import LeftAxis from "../LeftAxis";
|
|
15
|
+
|
|
16
|
+
type CityName = "New York" | "San Francisco" | "Austin";
|
|
17
|
+
|
|
18
|
+
type TooltipData = {
|
|
19
|
+
bar: SeriesPoint<CityTemperature>;
|
|
20
|
+
key: CityName;
|
|
21
|
+
index: number;
|
|
22
|
+
height: number;
|
|
23
|
+
width: number;
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
color: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type BarStackHorizontalProps = {
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
margin: { top: number; right: number; bottom: number; left: number };
|
|
33
|
+
events?: boolean;
|
|
34
|
+
barValue: any;
|
|
35
|
+
};
|
|
36
|
+
export default withTooltip<BarStackHorizontalProps, TooltipData>(
|
|
37
|
+
({
|
|
38
|
+
width=600,
|
|
39
|
+
height=400,
|
|
40
|
+
events = false,
|
|
41
|
+
margin,
|
|
42
|
+
tooltipOpen,
|
|
43
|
+
tooltipLeft,
|
|
44
|
+
tooltipTop,
|
|
45
|
+
tooltipData,
|
|
46
|
+
hideTooltip,
|
|
47
|
+
showTooltip,
|
|
48
|
+
barValue,
|
|
49
|
+
}: BarStackHorizontalProps & WithTooltipProvidedProps<TooltipData>) => {
|
|
50
|
+
const xMax = width - margin.left - margin.right;
|
|
51
|
+
const yMax = height - margin.top - margin.bottom;
|
|
52
|
+
const tooltipStyles = {
|
|
53
|
+
...defaultStyles,
|
|
54
|
+
padding: "12px",
|
|
55
|
+
minWidth: 60,
|
|
56
|
+
backgroundColor: "rgba(0,0,0,0.9)",
|
|
57
|
+
color: "white",
|
|
58
|
+
};
|
|
59
|
+
const data: any[] = barValue?.main?.data;
|
|
60
|
+
console.log(data);
|
|
61
|
+
const keys = Object.keys(data[0]).filter((y) => y !== "y") as CityName[];
|
|
62
|
+
|
|
63
|
+
const temperatureTotals = data.reduce((allTotals, currentDate) => {
|
|
64
|
+
const totalTemperature = keys.reduce((dailyTotal, k) => {
|
|
65
|
+
dailyTotal += Number(currentDate[k]);
|
|
66
|
+
return dailyTotal;
|
|
67
|
+
}, 0);
|
|
68
|
+
allTotals.push(totalTemperature);
|
|
69
|
+
return allTotals;
|
|
70
|
+
}, [] as number[]);
|
|
71
|
+
|
|
72
|
+
const getDate = (d: any) => d.y;
|
|
73
|
+
|
|
74
|
+
// scales
|
|
75
|
+
const temperatureScale = scaleLinear<number>({
|
|
76
|
+
domain: [0, Math.max(...temperatureTotals)],
|
|
77
|
+
nice: true,
|
|
78
|
+
});
|
|
79
|
+
const dateScale = scaleBand<string>({
|
|
80
|
+
domain: data.map(getDate),
|
|
81
|
+
padding: 0.2,
|
|
82
|
+
});
|
|
83
|
+
const colorScale = scaleOrdinal<CityName, string>({
|
|
84
|
+
domain: keys,
|
|
85
|
+
range: [barValue.style.barStyle.color],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
let tooltipTimeout: number;
|
|
89
|
+
temperatureScale.rangeRound([0, xMax]);
|
|
90
|
+
dateScale.rangeRound([yMax, 0]);
|
|
91
|
+
|
|
92
|
+
return width < 10 ? null : (
|
|
93
|
+
<div>
|
|
94
|
+
<svg width={width} height={height}>
|
|
95
|
+
<rect
|
|
96
|
+
width={width }
|
|
97
|
+
height={height}
|
|
98
|
+
// width={barValue?.style?.containerStyle?.width || 600}
|
|
99
|
+
// height={barValue?.style?.containerStyle?.height || 400}
|
|
100
|
+
fill={barValue?.style?.containerStyle?.background || "#eaedff"}
|
|
101
|
+
rx={14}
|
|
102
|
+
/>
|
|
103
|
+
<Group top={margin.top} left={margin.left}>
|
|
104
|
+
<BarStackHorizontal<CityTemperature, CityName>
|
|
105
|
+
data={data}
|
|
106
|
+
keys={keys}
|
|
107
|
+
height={yMax}
|
|
108
|
+
y={getDate}
|
|
109
|
+
xScale={temperatureScale}
|
|
110
|
+
yScale={dateScale}
|
|
111
|
+
color={colorScale}
|
|
112
|
+
>
|
|
113
|
+
{(barStacks) =>
|
|
114
|
+
barStacks.map((barStack) =>
|
|
115
|
+
barStack.bars.map((bar) => (
|
|
116
|
+
<rect
|
|
117
|
+
key={`barstack-horizontal-${barStack.index}-${bar.index}`}
|
|
118
|
+
x={bar.x}
|
|
119
|
+
y={bar.y}
|
|
120
|
+
width={bar.width}
|
|
121
|
+
height={bar.height}
|
|
122
|
+
fill={bar.color}
|
|
123
|
+
onClick={() => {
|
|
124
|
+
if (events) alert(`clicked: ${JSON.stringify(bar)}`);
|
|
125
|
+
}}
|
|
126
|
+
onMouseLeave={() => {
|
|
127
|
+
tooltipTimeout = window.setTimeout(() => {
|
|
128
|
+
hideTooltip();
|
|
129
|
+
}, 300);
|
|
130
|
+
}}
|
|
131
|
+
onMouseMove={() => {
|
|
132
|
+
if (tooltipTimeout) clearTimeout(tooltipTimeout);
|
|
133
|
+
const top = bar.y + margin.top;
|
|
134
|
+
const left = bar.x + bar.width + margin.left;
|
|
135
|
+
showTooltip({
|
|
136
|
+
tooltipData: bar,
|
|
137
|
+
tooltipTop: top,
|
|
138
|
+
tooltipLeft: left,
|
|
139
|
+
});
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
))
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
</BarStackHorizontal>
|
|
146
|
+
<LeftAxis value={barValue} yScale={dateScale} parentWidth={500} />
|
|
147
|
+
<BottomAxis
|
|
148
|
+
data={data}
|
|
149
|
+
value={barValue}
|
|
150
|
+
yMax={yMax}
|
|
151
|
+
xScale={temperatureScale}
|
|
152
|
+
parentWidth={500}
|
|
153
|
+
/>
|
|
154
|
+
</Group>
|
|
155
|
+
</svg>
|
|
156
|
+
{tooltipOpen && tooltipData && (
|
|
157
|
+
<Tooltip top={tooltipTop} left={tooltipLeft} style={tooltipStyles}>
|
|
158
|
+
<div style={{ marginBottom: "5px" }}>
|
|
159
|
+
{tooltipData.bar.data[tooltipData.key]}
|
|
160
|
+
</div>
|
|
161
|
+
<div style={{ color: colorScale(tooltipData.key) }}>
|
|
162
|
+
<strong>{getDate(tooltipData.bar.data)}</strong>
|
|
163
|
+
</div>
|
|
164
|
+
</Tooltip>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { finalDataProvider } from "../../utils/finalDataProvider";
|
|
3
|
+
import DrawHorizontalBarGraph from "./DrawHorizontalBarGraph";
|
|
4
|
+
import { ParentSize } from "@visx/responsive";
|
|
5
|
+
|
|
6
|
+
const HorizontalBarGraph = ({ value }:any) => {
|
|
7
|
+
const barData:any = finalDataProvider("HorizontalBarGraph",value)
|
|
8
|
+
|
|
9
|
+
let GraphRender = (
|
|
10
|
+
<ParentSize>
|
|
11
|
+
{(parent:any) => (
|
|
12
|
+
<DrawHorizontalBarGraph
|
|
13
|
+
width={parent.width}
|
|
14
|
+
height={parseInt(barData?.style?.containerStyle?.height||400)}
|
|
15
|
+
margin= {{ top: barData?.style?.labelStyle?.margin?.top||10, right: barData?.style?.labelStyle?.margin?.right||10,bottom: barData?.style?.labelStyle?.margin?.bottom||20 ,left: barData?.style?.labelStyle?.margin?.left||60 }}
|
|
16
|
+
barValue={barData}
|
|
17
|
+
/>
|
|
18
|
+
)}
|
|
19
|
+
</ParentSize>
|
|
20
|
+
);
|
|
21
|
+
return <div style={barData.style.containerStyle}>
|
|
22
|
+
{barData.main?.header && <div style={barData.style.headerStyle}>{barData?.main?.header}</div> }
|
|
23
|
+
{GraphRender}
|
|
24
|
+
</div>;
|
|
25
|
+
};
|
|
26
|
+
export default HorizontalBarGraph;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { AxisBottom } from "@visx/axis";
|
|
3
|
+
import { bottomAxisProps } from '../interface/interface';
|
|
4
|
+
const BottomAxis = ({data,yMax,value,xScale,parentWidth}:bottomAxisProps) => {
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<AxisBottom
|
|
8
|
+
numTicks={data.length}
|
|
9
|
+
top={yMax}
|
|
10
|
+
hideTicks={value.main?.hideTicks}
|
|
11
|
+
hideAxisLine={value.main?.hideBottomAxisLine}
|
|
12
|
+
strokeWidth={value.style?.labelStyle?.bottomAxisWidth}
|
|
13
|
+
scale={xScale}
|
|
14
|
+
stroke={value.style?.labelStyle?.tickColor}
|
|
15
|
+
labelOffset={value.style?.labelStyle?.bottomLabelOffset}
|
|
16
|
+
label={value.main?.bottomLabel}
|
|
17
|
+
labelProps={{
|
|
18
|
+
fill: value.style?.labelStyle?.labelColor,
|
|
19
|
+
fontSize: value.style?.labelStyle?.fontSize,
|
|
20
|
+
fontWeight: value.style?.labelStyle?.fontWeight,
|
|
21
|
+
fontFamily: value.style?.labelStyle?.fontWeight,
|
|
22
|
+
}}
|
|
23
|
+
tickStroke={value.style?.labelStyle?.tickColor}
|
|
24
|
+
tickLabelProps={() => ({
|
|
25
|
+
fill: value.style?.labelStyle?.tickLabelColor,
|
|
26
|
+
fontSize: value.style?.labelStyle?.tickFontSize ||11,
|
|
27
|
+
textAnchor: "middle",
|
|
28
|
+
})}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
export default BottomAxis
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { AxisLeft} from "@visx/axis";
|
|
3
|
+
import { leftAxisProps } from '../interface/interface';
|
|
4
|
+
const LeftAxis = ({value,yScale,parentWidth}:leftAxisProps) => {
|
|
5
|
+
return (
|
|
6
|
+
<AxisLeft
|
|
7
|
+
numTicks={value.main?.numTicks}
|
|
8
|
+
scale={yScale}
|
|
9
|
+
top={0}
|
|
10
|
+
label={value.main?.leftLabel}
|
|
11
|
+
tickStroke={value.style?.labelStyle?.tickColor}
|
|
12
|
+
strokeWidth={value.style?.labelStyle?.rightAxisWidth}
|
|
13
|
+
hideTicks={value.main?.hideLeftTicks}
|
|
14
|
+
labelOffset={value.style?.labelStyle?.leftLabelOffset}
|
|
15
|
+
labelProps={{
|
|
16
|
+
fill: value.style?.labelStyle?.labelColor,
|
|
17
|
+
fontSize: value.style?.labelStyle?.fontSize,
|
|
18
|
+
fontWeight: value.style?.labelStyle?.fontWeight,
|
|
19
|
+
fontFamily: value.style?.labelStyle?.fontWeight,
|
|
20
|
+
}}
|
|
21
|
+
hideAxisLine={value.main?.hideLeftAxisLine}
|
|
22
|
+
tickLabelProps={(e) => ({
|
|
23
|
+
fill: value.style?.labelStyle?.tickLabelColor,
|
|
24
|
+
fontSize:11,
|
|
25
|
+
textAnchor: "end",
|
|
26
|
+
dy: "0.33em"
|
|
27
|
+
})}
|
|
28
|
+
/>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default LeftAxis
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { LegendOrdinal, LegendItem, LegendLabel } from "@visx/legend";
|
|
3
|
+
import { scaleOrdinal } from "@visx/scale";
|
|
4
|
+
export function Legend({ value }: any) {
|
|
5
|
+
const legendGlyphSize = value?.main?.legend?.colorRectWidth || 15;
|
|
6
|
+
const ordinalColorScale = scaleOrdinal({
|
|
7
|
+
domain: value?.main?.tooltipDataKey,
|
|
8
|
+
range: value?.style?.pieStyle?.colorRange,
|
|
9
|
+
});
|
|
10
|
+
return (
|
|
11
|
+
<div className="legend" style={value?.style?.legendStyle?.legend}>
|
|
12
|
+
<div className="title" style={value?.style?.legendStyle?.legendTitle}>
|
|
13
|
+
{value?.main?.legend?.legendTitle}
|
|
14
|
+
</div>
|
|
15
|
+
<LegendOrdinal
|
|
16
|
+
scale={ordinalColorScale}
|
|
17
|
+
labelFormat={(label: any) => `${label.toUpperCase()}`}
|
|
18
|
+
>
|
|
19
|
+
{(labels) => (
|
|
20
|
+
<div
|
|
21
|
+
style={{
|
|
22
|
+
display: "flex",
|
|
23
|
+
flexDirection: value?.main?.legend?.direction || "row",
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
{labels.map((label: any, i: number) => (
|
|
27
|
+
<LegendItem
|
|
28
|
+
key={`legend-quantile-${i}`}
|
|
29
|
+
margin="0 5px"
|
|
30
|
+
onClick={(events) => {
|
|
31
|
+
if (events) alert(`clicked: ${JSON.stringify(label)}`);
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<svg width={legendGlyphSize} height={legendGlyphSize}>
|
|
35
|
+
<rect
|
|
36
|
+
fill={label.value}
|
|
37
|
+
width={legendGlyphSize}
|
|
38
|
+
height={legendGlyphSize}
|
|
39
|
+
/>
|
|
40
|
+
</svg>
|
|
41
|
+
<LegendLabel
|
|
42
|
+
align={`${value?.main?.legend?.align || "left"}`}
|
|
43
|
+
margin="0 0 0 4px"
|
|
44
|
+
>
|
|
45
|
+
{label.text}
|
|
46
|
+
</LegendLabel>
|
|
47
|
+
</LegendItem>
|
|
48
|
+
))}
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
</LegendOrdinal>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
export default Legend;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
AnimatedAxis,
|
|
4
|
+
AnimatedLineSeries,
|
|
5
|
+
XYChart,
|
|
6
|
+
Tooltip,
|
|
7
|
+
AnimatedGrid
|
|
8
|
+
} from "@visx/xychart";
|
|
9
|
+
import Legend from "../Legend";
|
|
10
|
+
const DrawGraph = ({ value }:any) => {
|
|
11
|
+
const data = value?.main?.data;
|
|
12
|
+
const arr = (value.main.xAxisValue && value.main.yAxisValue) ? [value.main.xAxisValue,value.main.yAxisValue] : Object.keys(data[0][0]);
|
|
13
|
+
const accessors = { xAccessor: (d:any) => d[arr[0]], yAccessor: (d:any) => d[arr[1]] };
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
{value.main.legendAvailable &&
|
|
19
|
+
<Legend value={value}/>
|
|
20
|
+
}
|
|
21
|
+
<XYChart height={parseInt(value.style?.containerStyle?.height)} xScale={{ type: "band" }} yScale={{ type: "linear" }}>
|
|
22
|
+
<AnimatedAxis orientation="left" hideAxisLine={value.main.hideLeftAxisLine}
|
|
23
|
+
label={value.main.leftLabel}
|
|
24
|
+
left={value.style?.labelStyle?.leftLabelMargin||70}
|
|
25
|
+
labelOffset={value.style?.labelStyle?.leftLabelOffset||32}
|
|
26
|
+
// fill={value.style?.labelStyle?.labelColor}
|
|
27
|
+
labelProps={{
|
|
28
|
+
fill: value.style?.labelStyle?.labelColor,
|
|
29
|
+
fontSize:value.style?.labelStyle?.fontSize
|
|
30
|
+
}}
|
|
31
|
+
tickLabelProps={(e) => ({
|
|
32
|
+
fill: value.style?.labelStyle?.labelColor})}
|
|
33
|
+
/>
|
|
34
|
+
<AnimatedAxis orientation="bottom" hideAxisLine={value.main.hideBottomAxisLine}
|
|
35
|
+
label={value.main.bottomLabel}
|
|
36
|
+
labelProps={{
|
|
37
|
+
fill: value.style?.labelStyle?.labelColor,
|
|
38
|
+
fontSize:value.style?.labelStyle?.fontSize
|
|
39
|
+
}}
|
|
40
|
+
tickLabelProps={(e) => ({
|
|
41
|
+
fill: value.style?.labelStyle?.labelColor})}
|
|
42
|
+
labelOffset={value.style?.labelStyle?.bottomLabelOffset||32}
|
|
43
|
+
// fill={value.style?.labelStyle?.labelColor}
|
|
44
|
+
/>
|
|
45
|
+
<AnimatedGrid
|
|
46
|
+
columns={value.main.grid}
|
|
47
|
+
numTicks={value.main.numHidden?0:value.main?.data[0].length-1} />
|
|
48
|
+
{
|
|
49
|
+
value.main?.data.map((elem:any, i:number) => {
|
|
50
|
+
return (
|
|
51
|
+
<AnimatedLineSeries
|
|
52
|
+
dataKey={value.main.tooltipDataKey[i]}
|
|
53
|
+
data={elem}
|
|
54
|
+
fill={value.style?.lineStyle?.lineAreaColor}
|
|
55
|
+
fillOpacity={value.style?.lineStyle?.lineAreaOpacity}
|
|
56
|
+
|
|
57
|
+
floodColor={"green"}
|
|
58
|
+
floodOpacity={1}
|
|
59
|
+
stroke={value.style?.lineStyle?.colorRange[i]}
|
|
60
|
+
{...accessors}
|
|
61
|
+
/>)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
<Tooltip
|
|
65
|
+
snapTooltipToDatumX
|
|
66
|
+
snapTooltipToDatumY
|
|
67
|
+
showVerticalCrosshair
|
|
68
|
+
showSeriesGlyphs
|
|
69
|
+
renderTooltip={({ tooltipData, colorScale }:any) => (
|
|
70
|
+
//@ts-ignore
|
|
71
|
+
<div>
|
|
72
|
+
|
|
73
|
+
<div style={{
|
|
74
|
+
color:colorScale(tooltipData.nearestDatum.key) }}>
|
|
75
|
+
{tooltipData?.nearestDatum?.key}
|
|
76
|
+
</div>
|
|
77
|
+
{accessors.xAccessor(tooltipData?.nearestDatum?.datum)}
|
|
78
|
+
{accessors.yAccessor(tooltipData?.nearestDatum?.datum)}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
/>
|
|
82
|
+
</XYChart></>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default DrawGraph;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DrawLineGraph from "./DrawLineGraph";
|
|
3
|
+
import { finalDataProvider } from "../../utils/finalDataProvider";
|
|
4
|
+
|
|
5
|
+
const LineGraph = ({ value }:any) => {
|
|
6
|
+
const lineData = finalDataProvider("LineGraph", value);
|
|
7
|
+
return (
|
|
8
|
+
<div style={lineData?.style?.containerStyle}>
|
|
9
|
+
{lineData?.main?.header && (
|
|
10
|
+
<div style={lineData?.style?.headerStyle}>{lineData?.main?.header}</div>
|
|
11
|
+
)}
|
|
12
|
+
<DrawLineGraph value={lineData} />
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default LineGraph;
|