impaktapps-design 0.2.993-graph.1 → 0.2.993-testTimer.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 +10121 -10238
- package/dist/impaktapps-design.es.js.map +1 -1
- package/dist/impaktapps-design.umd.js +12 -12
- package/dist/impaktapps-design.umd.js.map +1 -1
- package/dist/src/component/BarGraph/DrawHorizontalBarGraph.d.ts +3 -0
- package/dist/src/component/BarGraph/HorizontalBarGraph.d.ts +2 -3
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/component/BarGraph/DrawBarGraph.tsx +7 -35
- package/src/component/BarGraph/DrawHorizontalBarGraph.tsx +111 -130
- package/src/component/BarGraph/HorizontalBarGraph.tsx +22 -300
- package/src/component/BottomAxis.tsx +3 -21
- package/src/component/LeftAxis.tsx +2 -20
- package/src/component/LineGraph/DrawLineGraph.tsx +7 -26
- package/src/component/LineGraph/LineGraph.tsx +1 -1
- package/src/component/PieGraph/DrawPieGraph.tsx +12 -20
- package/src/component/ProgressBar/ProgressBar.tsx +2 -2
- package/src/component/Timer/Timer.tsx +2 -0
- package/src/component/LineGraph/style.css +0 -7
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default _default;
|
|
1
|
+
declare const HorizontalBarGraph: ({ value, theme }: any) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export default HorizontalBarGraph;
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import"https://fonts.googleapis.com/css2?family=Roboto;600&display=swap";.
|
|
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
CHANGED
|
@@ -71,39 +71,12 @@ export default function DrawBarGraph({
|
|
|
71
71
|
range: value.style.barStyle.colorRange,
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
const baseCharacterWidth = 7;
|
|
75
|
-
|
|
76
|
-
let ticksArray: any[] = [];
|
|
77
|
-
ticksArray = tempScale.ticks();
|
|
78
|
-
|
|
79
|
-
const maxLength = Math.max(
|
|
80
|
-
...ticksArray.map((label) => String(label || "").length)
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const calculatedOffset = maxLength * baseCharacterWidth + 10;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const baseCharacterWidthBottom = 5;
|
|
87
|
-
|
|
88
|
-
let ticksArrayBottom: any[] = [];
|
|
89
|
-
ticksArrayBottom = dateScale.domain();
|
|
90
|
-
|
|
91
|
-
const maxLengthBottom = Math.max(
|
|
92
|
-
...ticksArrayBottom.map((label) => String(label || "").length)
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const calculatedOffsetBottom = maxLengthBottom * baseCharacterWidthBottom + 10;
|
|
96
|
-
|
|
97
|
-
margin.left = calculatedOffset+20;
|
|
98
|
-
margin.bottom = value.main?.bottomAxisAngle ? calculatedOffsetBottom+40 : margin.bottom;
|
|
99
|
-
|
|
100
74
|
const xMax = width - margin.left - margin.right;
|
|
101
75
|
const yMax = height - margin.top - margin.bottom;
|
|
102
76
|
|
|
103
77
|
dateScale.rangeRound([0, xMax]);
|
|
104
78
|
cityScale.rangeRound([0, dateScale.bandwidth()]);
|
|
105
79
|
tempScale.range([yMax, 0]);
|
|
106
|
-
|
|
107
80
|
const {
|
|
108
81
|
tooltipData,
|
|
109
82
|
tooltipLeft,
|
|
@@ -141,14 +114,6 @@ export default function DrawBarGraph({
|
|
|
141
114
|
|
|
142
115
|
return width < 10 ? null : (
|
|
143
116
|
<div>
|
|
144
|
-
{value?.main?.legendAvailable && keys.length > 1 && (
|
|
145
|
-
<Legend
|
|
146
|
-
dataKeyArray={keys}
|
|
147
|
-
colorRange={value.style.barStyle.colorRange}
|
|
148
|
-
value={value}
|
|
149
|
-
theme={theme.myTheme}
|
|
150
|
-
/>
|
|
151
|
-
)}
|
|
152
117
|
<svg width={width} height={height}>
|
|
153
118
|
<rect
|
|
154
119
|
x={0}
|
|
@@ -280,6 +245,13 @@ export default function DrawBarGraph({
|
|
|
280
245
|
parentWidth={width}
|
|
281
246
|
/>
|
|
282
247
|
</svg>
|
|
248
|
+
{value?.main?.legendAvailable && keys.length > 1 && (
|
|
249
|
+
<Legend
|
|
250
|
+
dataKeyArray={keys}
|
|
251
|
+
colorRange={value.style.barStyle.colorRange}
|
|
252
|
+
value={value}
|
|
253
|
+
/>
|
|
254
|
+
)}
|
|
283
255
|
{tooltipOpen && (
|
|
284
256
|
<ToolTip
|
|
285
257
|
value={value}
|
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { BarGroupHorizontal, BarStackHorizontal } from "@visx/shape";
|
|
3
|
+
import { SeriesPoint } from "@visx/shape/lib/types";
|
|
2
4
|
import { Group } from "@visx/group";
|
|
3
|
-
import {
|
|
4
|
-
import { BarStack } from "@visx/shape";
|
|
5
|
+
import { CityTemperature } from "@visx/mock-data/lib/mocks/cityTemperature";
|
|
5
6
|
import { scaleBand, scaleLinear, scaleOrdinal } from "@visx/scale";
|
|
6
|
-
import LeftAxis from "../LeftAxis";
|
|
7
7
|
import BottomAxis from "../BottomAxis";
|
|
8
|
-
import { BarGroupProps } from "../../interface/interface";
|
|
9
8
|
import { useTooltip } from "@visx/tooltip";
|
|
9
|
+
import LeftAxis from "../LeftAxis";
|
|
10
|
+
import { Grid } from "@visx/grid";
|
|
11
|
+
import { BarStackHorizontalProps, CityName } from "../../interface/interface";
|
|
10
12
|
import ToolTip from "../ToolTip";
|
|
11
13
|
import Legend from "../Legend";
|
|
12
|
-
import { Grid } from "@visx/grid";
|
|
13
|
-
import { ScaleOrdinal } from "d3-scale";
|
|
14
|
-
import { colors } from "@mui/material";
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
export default function DrawBarGraph({
|
|
15
|
+
export default ({
|
|
18
16
|
theme,
|
|
19
|
-
width,
|
|
20
|
-
height,
|
|
17
|
+
width = 600,
|
|
18
|
+
height = 400,
|
|
21
19
|
events = false,
|
|
22
|
-
margin
|
|
23
|
-
|
|
24
|
-
}:
|
|
25
|
-
const data: any[] = value.main?.data;
|
|
26
|
-
const keys = Object.keys(data[0]).filter(
|
|
27
|
-
(d) => d !== value.main.xAxisValue
|
|
28
|
-
) as any[];
|
|
29
|
-
|
|
20
|
+
margin,
|
|
21
|
+
barValue,
|
|
22
|
+
}: BarStackHorizontalProps) => {
|
|
30
23
|
const [hoveredBar, setHoveredBar] = useState<{
|
|
31
24
|
date: any;
|
|
32
25
|
city: number;
|
|
@@ -35,7 +28,14 @@ export default function DrawBarGraph({
|
|
|
35
28
|
city: null,
|
|
36
29
|
});
|
|
37
30
|
|
|
38
|
-
const
|
|
31
|
+
const xMax = width - margin.left - margin.right;
|
|
32
|
+
const yMax = height - margin.top - margin.bottom;
|
|
33
|
+
const data: any[] = barValue?.main?.data;
|
|
34
|
+
|
|
35
|
+
const keys = Object.keys(data[0]).filter(
|
|
36
|
+
(d) => d !== barValue.main.xAxisValue
|
|
37
|
+
) as any[];
|
|
38
|
+
|
|
39
39
|
const temperatureTotals = data.reduce((allTotals, currentDate) => {
|
|
40
40
|
const totalTemperature = keys.reduce((dailyTotal, k) => {
|
|
41
41
|
dailyTotal += Number(currentDate[k]);
|
|
@@ -45,16 +45,11 @@ export default function DrawBarGraph({
|
|
|
45
45
|
return allTotals;
|
|
46
46
|
}, [] as number[]);
|
|
47
47
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
const cityScale = scaleBand<string>({
|
|
53
|
-
domain: keys,
|
|
54
|
-
});
|
|
55
|
-
const tempScale = scaleLinear<number>({
|
|
48
|
+
const getDate = (d: any) => d[barValue.main.xAxisValue];
|
|
49
|
+
|
|
50
|
+
const temperatureScale = scaleLinear<number>({
|
|
56
51
|
domain:
|
|
57
|
-
|
|
52
|
+
barValue?.main?.type === "HorizontalStackBarGraph"
|
|
58
53
|
? [0, Math.max(...temperatureTotals)]
|
|
59
54
|
: [
|
|
60
55
|
0,
|
|
@@ -66,43 +61,21 @@ export default function DrawBarGraph({
|
|
|
66
61
|
],
|
|
67
62
|
nice: true,
|
|
68
63
|
});
|
|
64
|
+
const dateScale = scaleBand<string>({
|
|
65
|
+
domain: data.map(getDate),
|
|
66
|
+
padding: 0.4,
|
|
67
|
+
});
|
|
68
|
+
const cityScale = scaleBand<string>({
|
|
69
|
+
domain: keys,
|
|
70
|
+
});
|
|
69
71
|
const colorScale = scaleOrdinal<string, string>({
|
|
70
72
|
domain: keys,
|
|
71
|
-
range:
|
|
73
|
+
range: barValue.style.barStyle.colorRange,
|
|
72
74
|
});
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let ticksArray: any[] = [];
|
|
77
|
-
ticksArray = tempScale.ticks();
|
|
78
|
-
|
|
79
|
-
const maxLength = Math.max(
|
|
80
|
-
...ticksArray.map((label) => String(label || "").length)
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const calculatedOffset = maxLength * baseCharacterWidth + 10;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const baseCharacterWidthBottom = 5;
|
|
87
|
-
|
|
88
|
-
let ticksArrayBottom: any[] = [];
|
|
89
|
-
ticksArrayBottom = dateScale.domain();
|
|
90
|
-
|
|
91
|
-
const maxLengthBottom = Math.max(
|
|
92
|
-
...ticksArrayBottom.map((label) => String(label || "").length)
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const calculatedOffsetBottom = maxLengthBottom * baseCharacterWidthBottom + 10;
|
|
96
|
-
|
|
97
|
-
margin.left = calculatedOffset+20;
|
|
98
|
-
margin.bottom = value.main?.bottomAxisAngle ? calculatedOffsetBottom+40 : margin.bottom;
|
|
99
|
-
|
|
100
|
-
const xMax = width - margin.left - margin.right;
|
|
101
|
-
const yMax = height - margin.top - margin.bottom;
|
|
102
|
-
|
|
103
|
-
dateScale.rangeRound([0, xMax]);
|
|
76
|
+
temperatureScale.rangeRound([0, xMax]);
|
|
77
|
+
dateScale.rangeRound([yMax, 0]);
|
|
104
78
|
cityScale.rangeRound([0, dateScale.bandwidth()]);
|
|
105
|
-
tempScale.range([yMax, 0]);
|
|
106
79
|
|
|
107
80
|
const {
|
|
108
81
|
tooltipData,
|
|
@@ -112,12 +85,13 @@ export default function DrawBarGraph({
|
|
|
112
85
|
showTooltip,
|
|
113
86
|
hideTooltip,
|
|
114
87
|
}: any = useTooltip();
|
|
88
|
+
|
|
115
89
|
const handleMouse = (event: any, bar: any, barGroup: any) => {
|
|
116
90
|
setHoveredBar({ date: barGroup, city: bar.index });
|
|
117
91
|
showTooltip({
|
|
118
92
|
tooltipLeft: event.clientX,
|
|
119
93
|
tooltipTop: event.clientY,
|
|
120
|
-
tooltipData: {groupData
|
|
94
|
+
tooltipData: { groupData: data[barGroup.index], highlightedBar: bar },
|
|
121
95
|
});
|
|
122
96
|
};
|
|
123
97
|
const handleMouseOut = (event: any) => {
|
|
@@ -129,40 +103,32 @@ export default function DrawBarGraph({
|
|
|
129
103
|
showTooltip({
|
|
130
104
|
tooltipLeft: event.clientX,
|
|
131
105
|
tooltipTop: event.clientY,
|
|
132
|
-
tooltipData: {groupData: data[bar.index], highlightedBar: bar},
|
|
106
|
+
tooltipData: { groupData: data[bar.index], highlightedBar: bar },
|
|
133
107
|
});
|
|
134
108
|
};
|
|
135
109
|
function calcWidthofBar(date: any): number {
|
|
136
110
|
return date?.bars.reduce(
|
|
137
|
-
(totalWidth, bar) => totalWidth + Math.min(bar.
|
|
111
|
+
(totalWidth, bar) => totalWidth + Math.min(bar.height, 15),
|
|
138
112
|
0
|
|
139
113
|
);
|
|
140
114
|
}
|
|
141
115
|
|
|
142
116
|
return width < 10 ? null : (
|
|
143
117
|
<div>
|
|
144
|
-
{value?.main?.legendAvailable && keys.length > 1 && (
|
|
145
|
-
<Legend
|
|
146
|
-
dataKeyArray={keys}
|
|
147
|
-
colorRange={value.style.barStyle.colorRange}
|
|
148
|
-
value={value}
|
|
149
|
-
theme={theme.myTheme}
|
|
150
|
-
/>
|
|
151
|
-
)}
|
|
152
118
|
<svg width={width} height={height}>
|
|
153
119
|
<rect
|
|
154
120
|
x={0}
|
|
155
121
|
y={0}
|
|
156
122
|
width={width}
|
|
157
123
|
height={height}
|
|
158
|
-
fill={
|
|
124
|
+
fill={barValue.style.containerStyle.background || "#612efb"}
|
|
159
125
|
/>
|
|
160
126
|
<Grid
|
|
161
127
|
top={margin.top}
|
|
162
128
|
left={margin.left}
|
|
163
|
-
xScale={
|
|
164
|
-
yScale={
|
|
165
|
-
width={
|
|
129
|
+
xScale={temperatureScale}
|
|
130
|
+
yScale={dateScale}
|
|
131
|
+
width={xMax}
|
|
166
132
|
height={yMax}
|
|
167
133
|
stroke="black"
|
|
168
134
|
xOffset={dateScale.bandwidth() / 50}
|
|
@@ -174,62 +140,66 @@ export default function DrawBarGraph({
|
|
|
174
140
|
{hoveredBar && (
|
|
175
141
|
<rect
|
|
176
142
|
style={{ display: hoveredBar.date ? "block" : "none" }}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
? hoveredBar?.date?.bars[hoveredBar.city].
|
|
180
|
-
(Math.min(hoveredBar?.date?.bars[0].
|
|
181
|
-
hoveredBar?.date?.bars[0].
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
143
|
+
y={
|
|
144
|
+
barValue.main.type === "HorizontalStackBarGraph"
|
|
145
|
+
? hoveredBar?.date?.bars[hoveredBar.city].y -
|
|
146
|
+
(Math.min(hoveredBar?.date?.bars[0].height, 15) -
|
|
147
|
+
hoveredBar?.date?.bars[0].height) /
|
|
148
|
+
2
|
|
149
|
+
: hoveredBar.date?.y0 -
|
|
150
|
+
(Math.min(hoveredBar?.date?.bars[0].height, 15) -
|
|
151
|
+
hoveredBar?.date?.bars[0].height) || 0
|
|
185
152
|
}
|
|
186
|
-
width={
|
|
187
|
-
|
|
153
|
+
width={xMax}
|
|
154
|
+
height={
|
|
155
|
+
barValue.main.type !== "HorizontalStackBarGraph"
|
|
188
156
|
? calcWidthofBar(hoveredBar?.date)
|
|
189
|
-
: Math.min(hoveredBar?.date?.bars[0].
|
|
157
|
+
: Math.min(hoveredBar?.date?.bars[0].height, 15)
|
|
190
158
|
}
|
|
191
|
-
|
|
192
|
-
fill={value.style?.barStyle?.hoverBackgroundColor}
|
|
159
|
+
fill={barValue.style?.barStyle?.hoverBackgroundColor}
|
|
193
160
|
opacity={1}
|
|
194
161
|
/>
|
|
195
162
|
)}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
<BarStack<any, any>
|
|
163
|
+
{barValue.main.type === "HorizontalStackBarGraph" ? (
|
|
164
|
+
<BarStackHorizontal
|
|
199
165
|
data={data}
|
|
200
166
|
keys={keys}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
167
|
+
height={yMax}
|
|
168
|
+
y={getDate}
|
|
169
|
+
xScale={temperatureScale}
|
|
170
|
+
yScale={dateScale}
|
|
204
171
|
color={colorScale}
|
|
205
172
|
>
|
|
206
173
|
{(barStacks) =>
|
|
207
174
|
barStacks.map((barStack) =>
|
|
208
175
|
barStack.bars.map((bar) => (
|
|
209
176
|
<rect
|
|
210
|
-
key={`
|
|
211
|
-
x={bar.x
|
|
212
|
-
y={bar.y}
|
|
213
|
-
|
|
214
|
-
|
|
177
|
+
key={`barstack-horizontal-${barStack.index}-${bar.index}`}
|
|
178
|
+
x={bar.x}
|
|
179
|
+
y={bar.y - (Math.min(bar.height, 15) - bar.height) / 2}
|
|
180
|
+
width={bar.width}
|
|
181
|
+
height={Math.min(bar.height, 15)}
|
|
215
182
|
fill={bar.color}
|
|
216
183
|
onMouseOver={(e) => stackhHandleMouse(e, bar, barStack)}
|
|
217
184
|
onMouseOut={(e) => handleMouseOut(e)}
|
|
218
|
-
stroke={
|
|
185
|
+
stroke={
|
|
186
|
+
hoveredBar.city === bar.index ? "black" : "transparent"
|
|
187
|
+
}
|
|
219
188
|
/>
|
|
220
189
|
))
|
|
221
190
|
)
|
|
222
191
|
}
|
|
223
|
-
</
|
|
192
|
+
</BarStackHorizontal>
|
|
224
193
|
) : (
|
|
225
|
-
<
|
|
194
|
+
<BarGroupHorizontal
|
|
226
195
|
data={data}
|
|
227
196
|
keys={keys}
|
|
197
|
+
width={xMax}
|
|
228
198
|
height={yMax}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
199
|
+
y0={getDate}
|
|
200
|
+
y0Scale={dateScale}
|
|
201
|
+
y1Scale={cityScale}
|
|
202
|
+
xScale={temperatureScale}
|
|
233
203
|
color={(key, index) => {
|
|
234
204
|
const color = colorScale(key);
|
|
235
205
|
const opColor = `${colorScale(key)}50`;
|
|
@@ -243,46 +213,57 @@ export default function DrawBarGraph({
|
|
|
243
213
|
{(barGroups) =>
|
|
244
214
|
barGroups.map((barGroup) => (
|
|
245
215
|
<Group
|
|
246
|
-
key={`bar-group-${barGroup.index}-${barGroup.
|
|
247
|
-
|
|
216
|
+
key={`bar-group-${barGroup.index}-${barGroup.y0}`}
|
|
217
|
+
top={barGroup.y0}
|
|
248
218
|
>
|
|
249
219
|
{barGroup.bars.map((bar) => {
|
|
250
|
-
const
|
|
251
|
-
const
|
|
220
|
+
const barHeight = Math.min(bar.height, 15);
|
|
221
|
+
const barY =
|
|
252
222
|
bar.index === 0
|
|
253
|
-
? bar.
|
|
254
|
-
: bar.
|
|
223
|
+
? bar.y - (barHeight - bar.height)
|
|
224
|
+
: bar.y;
|
|
255
225
|
return (
|
|
256
226
|
<rect
|
|
257
227
|
key={`bar-group-bar-${barGroup.index}-${bar.index}-${bar.value}-${bar.key}`}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
width={
|
|
261
|
-
height={
|
|
228
|
+
y={barY}
|
|
229
|
+
x={bar.x}
|
|
230
|
+
width={bar.width}
|
|
231
|
+
height={barHeight}
|
|
262
232
|
fill={bar.color}
|
|
263
233
|
onMouseOver={(e) => handleMouse(e, bar, barGroup)}
|
|
264
234
|
onMouseOut={(e) => handleMouseOut(e)}
|
|
265
|
-
stroke={
|
|
235
|
+
stroke={
|
|
236
|
+
hoveredBar.city === bar.index
|
|
237
|
+
? "black"
|
|
238
|
+
: "transparent"
|
|
239
|
+
}
|
|
266
240
|
/>
|
|
267
241
|
);
|
|
268
242
|
})}
|
|
269
243
|
</Group>
|
|
270
244
|
))
|
|
271
245
|
}
|
|
272
|
-
</
|
|
246
|
+
</BarGroupHorizontal>
|
|
273
247
|
)}
|
|
248
|
+
<LeftAxis value={barValue} yScale={dateScale} parentWidth={width} />
|
|
249
|
+
<BottomAxis
|
|
250
|
+
value={barValue}
|
|
251
|
+
yMax={yMax}
|
|
252
|
+
xScale={temperatureScale}
|
|
253
|
+
parentWidth={width}
|
|
254
|
+
/>
|
|
274
255
|
</Group>
|
|
275
|
-
<BottomAxis
|
|
276
|
-
yMax={yMax + margin.top}
|
|
277
|
-
value={value}
|
|
278
|
-
left={margin.left}
|
|
279
|
-
xScale={dateScale}
|
|
280
|
-
parentWidth={width}
|
|
281
|
-
/>
|
|
282
256
|
</svg>
|
|
283
|
-
{
|
|
257
|
+
{barValue?.main?.legendAvailable && keys.length > 1 && (
|
|
258
|
+
<Legend
|
|
259
|
+
dataKeyArray={keys}
|
|
260
|
+
colorRange={barValue.style.barStyle.colorRange}
|
|
261
|
+
value={barValue}
|
|
262
|
+
/>
|
|
263
|
+
)}
|
|
264
|
+
{tooltipOpen && tooltipData && (
|
|
284
265
|
<ToolTip
|
|
285
|
-
value={
|
|
266
|
+
value={barValue}
|
|
286
267
|
theme={theme}
|
|
287
268
|
top={tooltipTop}
|
|
288
269
|
left={tooltipLeft}
|
|
@@ -292,4 +273,4 @@ export default function DrawBarGraph({
|
|
|
292
273
|
)}
|
|
293
274
|
</div>
|
|
294
275
|
);
|
|
295
|
-
}
|
|
276
|
+
};
|