impaktapps-design 0.0.1 → 0.0.2
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/dist/impaktapps-design.es.js +1545 -1519
- package/package.json +1 -1
- package/src/component/BarGraph/BarGraph.tsx +2 -4
- package/src/component/BarGraph/DrawBarGraph.tsx +118 -98
- package/src/component/BarGraph/DrawHorizontalBarGraph.tsx +1 -19
- package/src/component/ToolTip.tsx +10 -8
- package/src/interface/interface.ts +28 -2
package/package.json
CHANGED
|
@@ -9,12 +9,10 @@ const BarGraph = ({ value }:any) => {
|
|
|
9
9
|
<ParentSize>
|
|
10
10
|
{(parent) => (
|
|
11
11
|
<DrawBarGraph
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
width={parent.width||400}
|
|
13
|
+
height={barData?.style?.containerStyle?.height|400}
|
|
14
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
15
|
value={barData}
|
|
16
|
-
parentRef={parent.ref}
|
|
17
|
-
resizeParent={parent.resize}
|
|
18
16
|
/>
|
|
19
17
|
)}
|
|
20
18
|
</ParentSize>
|
|
@@ -1,24 +1,57 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Group } from "@visx/group";
|
|
3
|
-
import {
|
|
4
|
-
import { scaleLinear,
|
|
5
|
-
import { defaultStyles,useTooltip, useTooltipInPortal } from "@visx/tooltip";
|
|
6
|
-
import { localPoint } from "@visx/event";
|
|
7
|
-
import ToolTip from "../ToolTip";
|
|
8
|
-
import BottomAxis from "../BottomAxis";
|
|
3
|
+
import { BarGroup } from "@visx/shape";
|
|
4
|
+
import { scaleBand, scaleLinear, scaleOrdinal } from "@visx/scale";
|
|
9
5
|
import LeftAxis from "../LeftAxis";
|
|
6
|
+
import BottomAxis from "../BottomAxis";
|
|
7
|
+
import { BarGroupProps } from "../../interface/interface";
|
|
8
|
+
import { useTooltip } from "@visx/tooltip";
|
|
9
|
+
import ToolTip from "../ToolTip";
|
|
10
|
+
|
|
11
|
+
type barValuesType = any;
|
|
12
|
+
const defaultMargin = { top: 20, right: 0, bottom: 40, left:40 };
|
|
13
|
+
export default function DrawBarGraph({
|
|
14
|
+
width,
|
|
15
|
+
height,
|
|
16
|
+
events = false,
|
|
17
|
+
margin = defaultMargin,
|
|
18
|
+
value
|
|
19
|
+
}: BarGroupProps) {
|
|
20
|
+
const data:any[] = value.main?.data;
|
|
21
|
+
const keys = Object.keys(data[0]).filter((d) => d !== "label") as barValuesType[];
|
|
10
22
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
// accessors
|
|
24
|
+
const getDate = (d: any) => d.label;
|
|
25
|
+
|
|
26
|
+
// scales
|
|
27
|
+
const dateScale = scaleBand<string>({
|
|
28
|
+
domain: data.map(getDate),
|
|
29
|
+
padding: 0.2
|
|
30
|
+
});
|
|
31
|
+
const cityScale = scaleBand<string>({
|
|
32
|
+
domain: keys,
|
|
33
|
+
padding: 0.1
|
|
34
|
+
});
|
|
35
|
+
const tempScale = scaleLinear<number>({
|
|
36
|
+
domain: [
|
|
37
|
+
0,
|
|
38
|
+
Math.max(...data.map((d:any) => Math.max(...keys.map((key) => Number(d[key])))))
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
const colorScale = scaleOrdinal<string, string>({
|
|
42
|
+
domain: keys,
|
|
43
|
+
range: [value.style?.barStyle?.color?.firstBarColor||"#aeeef8" ,
|
|
44
|
+
value.style?.barStyle?.color?.secondBarColor||"e5fd3d" ,
|
|
45
|
+
value.style?.barStyle?.color?.thirdBarColor||"#9caff6" ]
|
|
46
|
+
});
|
|
47
|
+
// bounds
|
|
48
|
+
const xMax = width - margin.left - margin.right;
|
|
49
|
+
const yMax = height - margin.top - margin.bottom;
|
|
50
|
+
|
|
51
|
+
// update scale output dimensions
|
|
52
|
+
dateScale.rangeRound([0, xMax]);
|
|
53
|
+
cityScale.rangeRound([0, dateScale.bandwidth()]);
|
|
54
|
+
tempScale.range([yMax, 0]);
|
|
22
55
|
const {
|
|
23
56
|
tooltipData,
|
|
24
57
|
tooltipLeft,
|
|
@@ -27,97 +60,84 @@ margin
|
|
|
27
60
|
showTooltip,
|
|
28
61
|
hideTooltip,
|
|
29
62
|
}: any = useTooltip();
|
|
30
|
-
const { containerRef } = useTooltipInPortal({
|
|
31
|
-
detectBounds: true,
|
|
32
|
-
scroll: true,
|
|
33
|
-
});
|
|
34
63
|
const handleMouse = (event: any, datum: any) => {
|
|
64
|
+
console.log(datum)
|
|
35
65
|
showTooltip({
|
|
36
66
|
tooltipLeft: event.clientX,
|
|
37
67
|
tooltipTop: event.clientY,
|
|
38
|
-
tooltipData: [datum
|
|
68
|
+
tooltipData: [datum.key,datum.value,datum.color],
|
|
69
|
+
// [datum["label"], datum["v1"]],
|
|
39
70
|
});
|
|
40
71
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
return width < 10 ? null : (
|
|
73
|
+
<div>
|
|
74
|
+
<svg width={width} height={height}>
|
|
75
|
+
<rect
|
|
76
|
+
x={0}
|
|
77
|
+
y={0}
|
|
78
|
+
width={width}
|
|
79
|
+
height={height}
|
|
80
|
+
fill={value.style.containerStyle.background||"#612efb"}
|
|
81
|
+
rx={14}
|
|
82
|
+
/>
|
|
83
|
+
<Group top={margin.top} left={margin.left}>
|
|
84
|
+
<LeftAxis value={value} yScale={tempScale} parentWidth={width} />
|
|
85
|
+
<BarGroup
|
|
86
|
+
data={data}
|
|
87
|
+
keys={keys}
|
|
88
|
+
height={yMax}
|
|
89
|
+
x0={getDate}
|
|
90
|
+
x0Scale={dateScale}
|
|
91
|
+
x1Scale={cityScale}
|
|
92
|
+
yScale={tempScale}
|
|
93
|
+
color={colorScale}
|
|
72
94
|
>
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
{(barGroups) =>
|
|
96
|
+
barGroups.map((barGroup) => (
|
|
97
|
+
<Group
|
|
98
|
+
key={`bar-group-${barGroup.index}-${barGroup.x0}`}
|
|
99
|
+
left={barGroup.x0}
|
|
100
|
+
>
|
|
101
|
+
{barGroup.bars.map((bar) => (
|
|
102
|
+
<rect
|
|
103
|
+
key={`bar-group-bar-${barGroup.index}-${bar.index}-${bar.value}-${bar.key}`}
|
|
104
|
+
x={bar.x}
|
|
105
|
+
y={bar.y}
|
|
106
|
+
width={bar.width}
|
|
107
|
+
height={bar.height}
|
|
108
|
+
fill={bar.color}
|
|
109
|
+
rx={4}
|
|
110
|
+
onMouseOver={(e) => handleMouse(e, bar)}
|
|
111
|
+
onMouseOut={hideTooltip}
|
|
112
|
+
onClick={() => {
|
|
113
|
+
if (!events) return;
|
|
114
|
+
const { key, value } = bar;
|
|
115
|
+
alert(JSON.stringify({ key, value }));
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
))}
|
|
119
|
+
</Group>
|
|
120
|
+
))
|
|
121
|
+
}
|
|
122
|
+
</BarGroup>
|
|
123
|
+
</Group>
|
|
124
|
+
<BottomAxis
|
|
125
|
+
yMax={yMax + margin.top}
|
|
126
|
+
value={value}
|
|
127
|
+
left={margin.left}
|
|
128
|
+
xScale={dateScale}
|
|
129
|
+
parentWidth={width}
|
|
130
|
+
/>
|
|
131
|
+
|
|
132
|
+
</svg>
|
|
133
|
+
{tooltipOpen &&
|
|
112
134
|
<ToolTip
|
|
113
|
-
style={{...value?.style}}
|
|
135
|
+
style={{...value?.style,tooltipbackground:tooltipData[2]}}
|
|
114
136
|
top={tooltipTop}
|
|
115
137
|
left={tooltipLeft}
|
|
116
138
|
tooltipData={tooltipData}
|
|
117
139
|
/>
|
|
118
|
-
|
|
119
|
-
|
|
140
|
+
}
|
|
141
|
+
</div>
|
|
120
142
|
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default DrawBarGraph;
|
|
143
|
+
}
|
|
@@ -12,27 +12,9 @@ import { withTooltip, Tooltip, defaultStyles } from "@visx/tooltip";
|
|
|
12
12
|
import { WithTooltipProvidedProps } from "@visx/tooltip/lib/enhancers/withTooltip";
|
|
13
13
|
import BottomAxis from "../BottomAxis";
|
|
14
14
|
import LeftAxis from "../LeftAxis";
|
|
15
|
+
import { BarStackHorizontalProps, CityName, TooltipData } from "../../interface/interface";
|
|
15
16
|
|
|
16
|
-
type CityName = "New York" | "San Francisco" | "Austin";
|
|
17
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
18
|
export default withTooltip<BarStackHorizontalProps, TooltipData>(
|
|
37
19
|
({
|
|
38
20
|
width=600,
|
|
@@ -8,27 +8,29 @@ const ToolTip = ({ style, top, left, tooltipData }: tooltipProps) => {
|
|
|
8
8
|
});
|
|
9
9
|
return (
|
|
10
10
|
<TooltipInPortal
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
key={Math.random()}
|
|
12
|
+
top={top} left={left}
|
|
13
|
+
>
|
|
13
14
|
<div
|
|
14
15
|
style={{
|
|
15
|
-
|
|
16
|
-
// paddingleft: "10px",
|
|
17
|
-
height: "auto",
|
|
16
|
+
height: "50px",
|
|
18
17
|
textAlign:"center",
|
|
19
18
|
background:"black",
|
|
19
|
+
padding:"10px",
|
|
20
20
|
boxShadow:"2px 2px 5px black",
|
|
21
21
|
color:"#6c5efb",
|
|
22
|
-
padding:"
|
|
22
|
+
// padding:"5px",
|
|
23
|
+
backgroundColor:style?.tooltipbackground||"black",
|
|
23
24
|
...style?.tooltipStyle,
|
|
25
|
+
margin:"-20px",
|
|
24
26
|
}}
|
|
25
27
|
>
|
|
26
|
-
<div style={{
|
|
28
|
+
<div style={{padding:"4px 10px",backgroundColor:"black",color:"white",borderRadius:"5px"}}>
|
|
27
29
|
{tooltipData[0]}
|
|
28
30
|
</div>
|
|
29
31
|
|
|
30
32
|
|
|
31
|
-
<div style={{marginTop:"10px"}}>
|
|
33
|
+
<div style={{marginTop:"10px",fontWeight:700}}>
|
|
32
34
|
{tooltipData[1]}
|
|
33
35
|
</div>
|
|
34
36
|
</div>
|
|
@@ -4,10 +4,36 @@ export interface leftAxisProps {
|
|
|
4
4
|
parentWidth: number
|
|
5
5
|
}
|
|
6
6
|
export interface bottomAxisProps {
|
|
7
|
-
|
|
7
|
+
left?:number, data?: any[], yMax: number, value: any, xScale: any, parentWidth: number
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface tooltipProps {
|
|
11
11
|
style:any,
|
|
12
12
|
top:any,left:any,tooltipData:any
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
export type BarGroupProps = {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
margin?: { top: number; right: number; bottom: number; left: number };
|
|
18
|
+
events?: boolean;
|
|
19
|
+
value:any
|
|
20
|
+
};
|
|
21
|
+
export type CityName = "v1" | "v2" | "v3";
|
|
22
|
+
export type TooltipData = {
|
|
23
|
+
bar: any;
|
|
24
|
+
key: CityName;
|
|
25
|
+
index: number;
|
|
26
|
+
height: number;
|
|
27
|
+
width: number;
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
color: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type BarStackHorizontalProps = {
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
margin: { top: number; right: number; bottom: number; left: number };
|
|
37
|
+
events?: boolean;
|
|
38
|
+
barValue: any;
|
|
39
|
+
};
|