@redsift/charts 8.0.0 → 8.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/coverage/clover.xml +1070 -0
- package/coverage/coverage-final.json +60 -0
- package/coverage/lcov-report/ChartEmptyState/ChartEmptyState.tsx.html +679 -0
- package/coverage/lcov-report/ChartEmptyState/index.html +146 -0
- package/coverage/lcov-report/ChartEmptyState/index.ts.html +91 -0
- package/coverage/lcov-report/ChartEmptyState/styles.ts.html +184 -0
- package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChart.tsx.html +775 -0
- package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartAxisBottom.tsx.html +259 -0
- package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartBar.tsx.html +421 -0
- package/coverage/lcov-report/HorizontalBarChart/index.html +191 -0
- package/coverage/lcov-report/HorizontalBarChart/index.ts.html +94 -0
- package/coverage/lcov-report/HorizontalBarChart/styles.ts.html +451 -0
- package/coverage/lcov-report/HorizontalBarChart/types.ts.html +433 -0
- package/coverage/lcov-report/PieChart/PieChart.tsx.html +1105 -0
- package/coverage/lcov-report/PieChart/PieChartArc.tsx.html +412 -0
- package/coverage/lcov-report/PieChart/index.html +176 -0
- package/coverage/lcov-report/PieChart/index.ts.html +94 -0
- package/coverage/lcov-report/PieChart/styles.ts.html +616 -0
- package/coverage/lcov-report/PieChart/types.ts.html +472 -0
- package/coverage/lcov-report/PieChart.tsx.html +1045 -0
- package/coverage/lcov-report/PieChartArc.tsx.html +271 -0
- package/coverage/lcov-report/StaticPieChart.tsx.html +286 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/components/Arc/Arc.tsx.html +304 -0
- package/coverage/lcov-report/components/Arc/index.html +146 -0
- package/coverage/lcov-report/components/Arc/index.ts.html +94 -0
- package/coverage/lcov-report/components/Arc/styles.ts.html +208 -0
- package/coverage/lcov-report/components/Arcs/Arcs.tsx.html +427 -0
- package/coverage/lcov-report/components/Arcs/index.html +146 -0
- package/coverage/lcov-report/components/Arcs/index.ts.html +94 -0
- package/coverage/lcov-report/components/Arcs/styles.ts.html +106 -0
- package/coverage/lcov-report/components/Axis/Axis.tsx.html +754 -0
- package/coverage/lcov-report/components/Axis/computeTicks.ts.html +481 -0
- package/coverage/lcov-report/components/Axis/index.html +176 -0
- package/coverage/lcov-report/components/Axis/index.ts.html +94 -0
- package/coverage/lcov-report/components/Axis/styles.ts.html +148 -0
- package/coverage/lcov-report/components/Axis/types.ts.html +253 -0
- package/coverage/lcov-report/components/Bar/Bar.tsx.html +421 -0
- package/coverage/lcov-report/components/Bar/index.html +161 -0
- package/coverage/lcov-report/components/Bar/index.ts.html +94 -0
- package/coverage/lcov-report/components/Bar/styles.ts.html +247 -0
- package/coverage/lcov-report/components/Bar/types.ts.html +178 -0
- package/coverage/lcov-report/components/BarChart/BarChart.tsx.html +355 -0
- package/coverage/lcov-report/components/BarChart/EmptyBarChart.tsx.html +259 -0
- package/coverage/lcov-report/components/BarChart/LoadingBarChart.tsx.html +145 -0
- package/coverage/lcov-report/components/BarChart/RenderedBarChart.tsx.html +496 -0
- package/coverage/lcov-report/components/BarChart/index.html +206 -0
- package/coverage/lcov-report/components/BarChart/index.ts.html +94 -0
- package/coverage/lcov-report/components/BarChart/styles.ts.html +190 -0
- package/coverage/lcov-report/components/BarChart/utils.ts.html +145 -0
- package/coverage/lcov-report/components/ChartContainer/ChartContainer.tsx.html +433 -0
- package/coverage/lcov-report/components/ChartContainer/index.html +146 -0
- package/coverage/lcov-report/components/ChartContainer/index.ts.html +94 -0
- package/coverage/lcov-report/components/ChartContainer/intl/index.html +116 -0
- package/coverage/lcov-report/components/ChartContainer/intl/index.ts.html +106 -0
- package/coverage/lcov-report/components/ChartContainer/styles.ts.html +211 -0
- package/coverage/lcov-report/components/DataPoint/DataPoint.tsx.html +442 -0
- package/coverage/lcov-report/components/DataPoint/index.html +146 -0
- package/coverage/lcov-report/components/DataPoint/index.ts.html +94 -0
- package/coverage/lcov-report/components/DataPoint/styles.ts.html +109 -0
- package/coverage/lcov-report/components/Dot/Dot.tsx.html +232 -0
- package/coverage/lcov-report/components/Dot/index.html +146 -0
- package/coverage/lcov-report/components/Dot/index.ts.html +94 -0
- package/coverage/lcov-report/components/Dot/styles.ts.html +184 -0
- package/coverage/lcov-report/components/Legend/Legend.tsx.html +268 -0
- package/coverage/lcov-report/components/Legend/index.html +146 -0
- package/coverage/lcov-report/components/Legend/index.ts.html +94 -0
- package/coverage/lcov-report/components/Legend/styles.ts.html +130 -0
- package/coverage/lcov-report/components/LegendItem/LegendItem.tsx.html +403 -0
- package/coverage/lcov-report/components/LegendItem/index.html +146 -0
- package/coverage/lcov-report/components/LegendItem/index.ts.html +94 -0
- package/coverage/lcov-report/components/LegendItem/styles.ts.html +205 -0
- package/coverage/lcov-report/components/PieChart/EmptyPieChart.tsx.html +343 -0
- package/coverage/lcov-report/components/PieChart/LoadingPieChart.tsx.html +145 -0
- package/coverage/lcov-report/components/PieChart/PieChart.tsx.html +388 -0
- package/coverage/lcov-report/components/PieChart/RenderedPieChart.tsx.html +571 -0
- package/coverage/lcov-report/components/PieChart/index.html +221 -0
- package/coverage/lcov-report/components/PieChart/index.ts.html +94 -0
- package/coverage/lcov-report/components/PieChart/styles.ts.html +376 -0
- package/coverage/lcov-report/components/PieChart/types.ts.html +352 -0
- package/coverage/lcov-report/components/PieChart/utils.ts.html +199 -0
- package/coverage/lcov-report/components/ScatterPlot/EmptyScatterPlot.tsx.html +295 -0
- package/coverage/lcov-report/components/ScatterPlot/LoadingScatterPlot.tsx.html +145 -0
- package/coverage/lcov-report/components/ScatterPlot/RenderedScatterPlot.tsx.html +910 -0
- package/coverage/lcov-report/components/ScatterPlot/ScatterPlot.tsx.html +379 -0
- package/coverage/lcov-report/components/ScatterPlot/index.html +221 -0
- package/coverage/lcov-report/components/ScatterPlot/index.ts.html +94 -0
- package/coverage/lcov-report/components/ScatterPlot/styles.ts.html +196 -0
- package/coverage/lcov-report/components/ScatterPlot/types.ts.html +376 -0
- package/coverage/lcov-report/components/ScatterPlot/utils.ts.html +388 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hooks/index.html +176 -0
- package/coverage/lcov-report/hooks/index.ts.html +97 -0
- package/coverage/lcov-report/hooks/useBrush.tsx.html +430 -0
- package/coverage/lcov-report/hooks/useColor.tsx.html +163 -0
- package/coverage/lcov-report/hooks/useFormatCategoricalData.tsx.html +289 -0
- package/coverage/lcov-report/hooks/useZoom.tsx.html +235 -0
- package/coverage/lcov-report/index.html +311 -0
- package/coverage/lcov-report/index.ts.html +94 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/styles.ts.html +631 -0
- package/coverage/lcov-report/types.ts.html +457 -0
- package/coverage/lcov.info +2272 -0
- package/dist/index.js +6326 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +98 -0
- package/index.ts +1 -0
- package/jest.config.js +3 -0
- package/package.json +2 -3
- package/rollup.config.js +13 -0
- package/src/components/Arc/Arc.test.tsx +92 -0
- package/src/components/Arc/Arc.tsx +73 -0
- package/src/components/Arc/index.ts +3 -0
- package/src/components/Arc/styles.ts +41 -0
- package/src/components/Arc/types.ts +18 -0
- package/src/components/Arcs/Arcs.stories.tsx +177 -0
- package/src/components/Arcs/Arcs.tsx +114 -0
- package/src/components/Arcs/index.ts +3 -0
- package/src/components/Arcs/styles.ts +7 -0
- package/src/components/Arcs/types.ts +26 -0
- package/src/components/Axis/Axis.stories.tsx +297 -0
- package/src/components/Axis/Axis.tsx +223 -0
- package/src/components/Axis/computeTicks.ts +132 -0
- package/src/components/Axis/index.ts +3 -0
- package/src/components/Axis/styles.ts +21 -0
- package/src/components/Axis/types.ts +56 -0
- package/src/components/Bar/Bar.stories.tsx +152 -0
- package/src/components/Bar/Bar.test.tsx +158 -0
- package/src/components/Bar/Bar.tsx +112 -0
- package/src/components/Bar/index.ts +3 -0
- package/src/components/Bar/styles.ts +54 -0
- package/src/components/Bar/types.ts +31 -0
- package/src/components/BarChart/BarChart.stories.tsx +80 -0
- package/src/components/BarChart/BarChart.test.tsx +189 -0
- package/src/components/BarChart/BarChart.tsx +90 -0
- package/src/components/BarChart/EmptyBarChart.tsx +58 -0
- package/src/components/BarChart/LoadingBarChart.tsx +20 -0
- package/src/components/BarChart/RenderedBarChart.tsx +137 -0
- package/src/components/BarChart/__snapshots__/BarChart.test.tsx.snap +6932 -0
- package/src/components/BarChart/index.ts +3 -0
- package/src/components/BarChart/styles.ts +35 -0
- package/src/components/BarChart/types.ts +58 -0
- package/src/components/BarChart/utils.ts +20 -0
- package/src/components/ChartContainer/ChartContainer.stories.tsx +81 -0
- package/src/components/ChartContainer/ChartContainer.test.tsx +75 -0
- package/src/components/ChartContainer/ChartContainer.tsx +116 -0
- package/src/components/ChartContainer/index.ts +3 -0
- package/src/components/ChartContainer/intl/en-US.json +3 -0
- package/src/components/ChartContainer/intl/fr-FR.json +3 -0
- package/src/components/ChartContainer/intl/index.ts +7 -0
- package/src/components/ChartContainer/styles.ts +42 -0
- package/src/components/ChartContainer/types.ts +24 -0
- package/src/components/DataPoint/DataPoint.tsx +119 -0
- package/src/components/DataPoint/index.ts +3 -0
- package/src/components/DataPoint/styles.ts +8 -0
- package/src/components/DataPoint/types.ts +33 -0
- package/src/components/Dot/Dot.stories.tsx +157 -0
- package/src/components/Dot/Dot.test.tsx +136 -0
- package/src/components/Dot/Dot.tsx +49 -0
- package/src/components/Dot/index.ts +3 -0
- package/src/components/Dot/styles.ts +33 -0
- package/src/components/Dot/types.ts +16 -0
- package/src/components/Legend/Legend.stories.tsx +108 -0
- package/src/components/Legend/Legend.tsx +61 -0
- package/src/components/Legend/index.ts +3 -0
- package/src/components/Legend/styles.ts +15 -0
- package/src/components/Legend/types.ts +27 -0
- package/src/components/LegendItem/LegendItem.test.tsx +69 -0
- package/src/components/LegendItem/LegendItem.tsx +106 -0
- package/src/components/LegendItem/index.ts +3 -0
- package/src/components/LegendItem/styles.ts +40 -0
- package/src/components/LegendItem/types.ts +30 -0
- package/src/components/PieChart/EmptyPieChart.tsx +86 -0
- package/src/components/PieChart/LoadingPieChart.tsx +20 -0
- package/src/components/PieChart/PieChart.stories.tsx +91 -0
- package/src/components/PieChart/PieChart.test.tsx +201 -0
- package/src/components/PieChart/PieChart.tsx +101 -0
- package/src/components/PieChart/RenderedPieChart.tsx +162 -0
- package/src/components/PieChart/__snapshots__/PieChart.stories.storyshot +7843 -0
- package/src/components/PieChart/__snapshots__/PieChart.test.tsx.snap +20540 -0
- package/src/components/PieChart/index.ts +3 -0
- package/src/components/PieChart/styles.ts +97 -0
- package/src/components/PieChart/types.ts +89 -0
- package/src/components/PieChart/utils.ts +38 -0
- package/src/components/ScatterPlot/EmptyScatterPlot.tsx +70 -0
- package/src/components/ScatterPlot/LoadingScatterPlot.tsx +20 -0
- package/src/components/ScatterPlot/RenderedScatterPlot.tsx +275 -0
- package/src/components/ScatterPlot/ScatterPlot.stories.tsx +95 -0
- package/src/components/ScatterPlot/ScatterPlot.test.tsx +44 -0
- package/src/components/ScatterPlot/ScatterPlot.tsx +98 -0
- package/src/components/ScatterPlot/__snapshots__/ScatterPlot.test.tsx.snap +88352 -0
- package/src/components/ScatterPlot/index.ts +3 -0
- package/src/components/ScatterPlot/styles.ts +37 -0
- package/src/components/ScatterPlot/types.ts +97 -0
- package/src/components/ScatterPlot/utils.ts +101 -0
- package/src/config.ts +10 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useBrush.tsx +115 -0
- package/src/hooks/useColor.tsx +26 -0
- package/src/hooks/useFormatCategoricalData.tsx +68 -0
- package/src/hooks/useZoom.tsx +50 -0
- package/src/index.ts +15 -0
- package/src/scheme.ts +221 -0
- package/src/types/data.ts +52 -0
- package/src/types/index.ts +5 -0
- package/src/types/legend.ts +19 -0
- package/src/types/scale.ts +79 -0
- package/src/types/size.ts +17 -0
- package/src/types/theme.ts +27 -0
- package/tsconfig.json +3 -0
- package/index.js +0 -2606
- package/index.js.map +0 -1
- /package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React, { forwardRef, RefObject, useEffect, useRef } from 'react';
|
|
2
|
+
import { arc as d3arc, pie as d3pie, sum as d3sum } from 'd3';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
LabelVariant,
|
|
6
|
+
ArcDatum,
|
|
7
|
+
CategoryData,
|
|
8
|
+
CategoryDatum,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import { PieChartLabelVariant, PieChartProps, PieChartVariant } from './types';
|
|
11
|
+
import { StyledPieChartCenterText, StyledPieChart } from './styles';
|
|
12
|
+
import { Arcs } from '../Arcs';
|
|
13
|
+
import { useFormatCategoricalData } from '../../hooks';
|
|
14
|
+
import { Legend } from '../Legend';
|
|
15
|
+
import { sizeToDimension } from './utils';
|
|
16
|
+
import { PieChart } from './PieChart';
|
|
17
|
+
|
|
18
|
+
interface RenderedPieChartProps
|
|
19
|
+
extends Required<Pick<PieChartProps, 'data'>>,
|
|
20
|
+
Omit<PieChartProps, 'data'> {}
|
|
21
|
+
|
|
22
|
+
export const RenderedPieChart = forwardRef<
|
|
23
|
+
HTMLDivElement,
|
|
24
|
+
RenderedPieChartProps
|
|
25
|
+
>((props, ref) => {
|
|
26
|
+
const {
|
|
27
|
+
caping,
|
|
28
|
+
className,
|
|
29
|
+
data: propsData,
|
|
30
|
+
id,
|
|
31
|
+
isSliceSelected,
|
|
32
|
+
labelDecorator,
|
|
33
|
+
labelVariant,
|
|
34
|
+
middleText,
|
|
35
|
+
onSliceClick,
|
|
36
|
+
others,
|
|
37
|
+
size,
|
|
38
|
+
sliceProps,
|
|
39
|
+
sliceRole,
|
|
40
|
+
subtext,
|
|
41
|
+
text,
|
|
42
|
+
theme,
|
|
43
|
+
tooltipVariant,
|
|
44
|
+
variant,
|
|
45
|
+
...forwardedProps
|
|
46
|
+
} = props;
|
|
47
|
+
|
|
48
|
+
const cache = useRef<CategoryData>();
|
|
49
|
+
|
|
50
|
+
const isDonut =
|
|
51
|
+
variant === PieChartVariant.donut ||
|
|
52
|
+
variant === PieChartVariant.spacedDonut;
|
|
53
|
+
|
|
54
|
+
const { data, colorScale } = useFormatCategoricalData({
|
|
55
|
+
data: propsData,
|
|
56
|
+
theme: theme!,
|
|
57
|
+
caping,
|
|
58
|
+
others,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
cache.current = data;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const { width, height, smallFontSize, fontSize, innerRadius } =
|
|
66
|
+
sizeToDimension(size!);
|
|
67
|
+
const externalRadiusPadding = 8;
|
|
68
|
+
|
|
69
|
+
const createPie = d3pie<CategoryDatum>()
|
|
70
|
+
.value((d) => d.value)
|
|
71
|
+
.sort(null);
|
|
72
|
+
const createArc = d3arc<ArcDatum>()
|
|
73
|
+
.innerRadius(isDonut ? innerRadius : 0)
|
|
74
|
+
.outerRadius(width / 2 - externalRadiusPadding);
|
|
75
|
+
const pieData = createPie(data);
|
|
76
|
+
const previousPieData = cache.current ? createPie(cache.current) : undefined;
|
|
77
|
+
const total = d3sum(data, (d) => d.value);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<StyledPieChart
|
|
81
|
+
{...forwardedProps}
|
|
82
|
+
className={className}
|
|
83
|
+
id={id}
|
|
84
|
+
ref={ref as RefObject<HTMLDivElement>}
|
|
85
|
+
>
|
|
86
|
+
<div className={`${PieChart.className}__chart-wrapper`}>
|
|
87
|
+
{text ? (
|
|
88
|
+
<StyledPieChartCenterText
|
|
89
|
+
$maxWidth={innerRadius * 2}
|
|
90
|
+
$textSize={fontSize}
|
|
91
|
+
$smallTextSize={smallFontSize}
|
|
92
|
+
>
|
|
93
|
+
{subtext ? <b>{text}</b> : <span>{text}</span>}
|
|
94
|
+
{middleText ? <b>{middleText}</b> : null}
|
|
95
|
+
<span>{subtext}</span>
|
|
96
|
+
</StyledPieChartCenterText>
|
|
97
|
+
) : null}
|
|
98
|
+
<svg width={width} height={height}>
|
|
99
|
+
<Arcs
|
|
100
|
+
arcs={pieData
|
|
101
|
+
.filter((datum) => datum.data.value)
|
|
102
|
+
.map((datum, index) => {
|
|
103
|
+
const percent = datum.data.value / total;
|
|
104
|
+
const from = previousPieData
|
|
105
|
+
? previousPieData[index]
|
|
106
|
+
: {
|
|
107
|
+
data: {
|
|
108
|
+
key: '',
|
|
109
|
+
value: 0,
|
|
110
|
+
},
|
|
111
|
+
startAngle: 0,
|
|
112
|
+
endAngle: 0,
|
|
113
|
+
padAngle: 0,
|
|
114
|
+
value: 0,
|
|
115
|
+
index: index,
|
|
116
|
+
};
|
|
117
|
+
const to = { ...datum, data: { ...datum.data, percent } };
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
color: colorScale?.(to.data.key),
|
|
121
|
+
createArc,
|
|
122
|
+
previousData: from,
|
|
123
|
+
id: `id${id}__bar-${index}`,
|
|
124
|
+
index,
|
|
125
|
+
isSelected: isSliceSelected!(to),
|
|
126
|
+
key: `id${id}__bar-${index}`,
|
|
127
|
+
data: to,
|
|
128
|
+
};
|
|
129
|
+
})}
|
|
130
|
+
hasLabels={labelVariant === PieChartLabelVariant.internal}
|
|
131
|
+
hasStroke={
|
|
132
|
+
variant === PieChartVariant.spaced ||
|
|
133
|
+
variant === PieChartVariant.spacedDonut
|
|
134
|
+
}
|
|
135
|
+
labelDecorator={labelDecorator}
|
|
136
|
+
onClick={onSliceClick}
|
|
137
|
+
role={sliceRole}
|
|
138
|
+
sliceProps={sliceProps}
|
|
139
|
+
tooltipVariant={tooltipVariant}
|
|
140
|
+
transform={`translate(${width / 2} ${height / 2})`}
|
|
141
|
+
/>
|
|
142
|
+
</svg>
|
|
143
|
+
</div>
|
|
144
|
+
{labelVariant !== PieChartLabelVariant.none &&
|
|
145
|
+
labelVariant !== PieChartLabelVariant.internal ? (
|
|
146
|
+
<Legend
|
|
147
|
+
data={data.map((d) => ({
|
|
148
|
+
...d,
|
|
149
|
+
color: colorScale?.(d.key)!,
|
|
150
|
+
}))}
|
|
151
|
+
variant={
|
|
152
|
+
labelVariant === PieChartLabelVariant.externalLabelValue
|
|
153
|
+
? LabelVariant.value
|
|
154
|
+
: labelVariant === PieChartLabelVariant.externalLabelPercent
|
|
155
|
+
? LabelVariant.percent
|
|
156
|
+
: LabelVariant.label
|
|
157
|
+
}
|
|
158
|
+
/>
|
|
159
|
+
) : null}
|
|
160
|
+
</StyledPieChart>
|
|
161
|
+
);
|
|
162
|
+
});
|