@alfalab/core-components-chart 3.3.3 → 3.4.0
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/Component.js +1 -1
- package/components/Dot/index.css +8 -8
- package/components/Dot/index.js +1 -1
- package/components/Legends/index.css +8 -8
- package/components/Legends/index.js +1 -1
- package/components/Tick/index.css +4 -4
- package/components/Tick/index.js +1 -1
- package/components/TooltipContent/index.css +7 -7
- package/components/TooltipContent/index.js +1 -1
- package/esm/Component.js +1 -1
- package/esm/components/Dot/index.css +8 -8
- package/esm/components/Dot/index.js +1 -1
- package/esm/components/Legends/index.css +8 -8
- package/esm/components/Legends/index.js +1 -1
- package/esm/components/Tick/index.css +4 -4
- package/esm/components/Tick/index.js +1 -1
- package/esm/components/TooltipContent/index.css +7 -7
- package/esm/components/TooltipContent/index.js +1 -1
- package/esm/index.css +5 -5
- package/index.css +5 -5
- package/modern/Component.js +1 -1
- package/modern/components/Dot/index.css +8 -8
- package/modern/components/Dot/index.js +1 -1
- package/modern/components/Legends/index.css +8 -8
- package/modern/components/Legends/index.js +1 -1
- package/modern/components/Tick/index.css +4 -4
- package/modern/components/Tick/index.js +1 -1
- package/modern/components/TooltipContent/index.css +7 -7
- package/modern/components/TooltipContent/index.js +1 -1
- package/modern/index.css +5 -5
- package/moderncssm/Component.d.ts +8 -0
- package/moderncssm/Component.js +251 -0
- package/moderncssm/components/CustomizedLabel.d.ts +4 -0
- package/moderncssm/components/CustomizedLabel.js +11 -0
- package/moderncssm/components/Dot/index.d.ts +5 -0
- package/moderncssm/components/Dot/index.js +43 -0
- package/moderncssm/components/Dot/index.module.css +22 -0
- package/moderncssm/components/Legends/index.d.ts +14 -0
- package/moderncssm/components/Legends/index.js +36 -0
- package/moderncssm/components/Legends/index.module.css +36 -0
- package/moderncssm/components/LinearGradient.d.ts +5 -0
- package/moderncssm/components/LinearGradient.js +5 -0
- package/moderncssm/components/RectBar.d.ts +3 -0
- package/moderncssm/components/RectBar.js +27 -0
- package/moderncssm/components/Tick/index.d.ts +5 -0
- package/moderncssm/components/Tick/index.js +16 -0
- package/moderncssm/components/Tick/index.module.css +18 -0
- package/moderncssm/components/TooltipContent/index.d.ts +11 -0
- package/moderncssm/components/TooltipContent/index.js +26 -0
- package/moderncssm/components/TooltipContent/index.module.css +51 -0
- package/moderncssm/hooks/usePathBar/index.d.ts +14 -0
- package/moderncssm/hooks/usePathBar/index.js +37 -0
- package/moderncssm/hooks/usePathBar/utils/getRadius.d.ts +2 -0
- package/moderncssm/hooks/usePathBar/utils/getRadius.js +6 -0
- package/moderncssm/hooks/useSettings/index.d.ts +19 -0
- package/moderncssm/hooks/useSettings/index.js +43 -0
- package/moderncssm/hooks/useSettings/utils/setComposedChartsMargin.d.ts +12 -0
- package/moderncssm/hooks/useSettings/utils/setComposedChartsMargin.js +12 -0
- package/moderncssm/hooks/useSettings/utils/setDatas.d.ts +5 -0
- package/moderncssm/hooks/useSettings/utils/setDatas.js +32 -0
- package/moderncssm/hooks/useSettings/utils/setGradientCharts.d.ts +3 -0
- package/moderncssm/hooks/useSettings/utils/setGradientCharts.js +35 -0
- package/moderncssm/hooks/useSettings/utils/setLegendMargin.d.ts +4 -0
- package/moderncssm/hooks/useSettings/utils/setLegendMargin.js +14 -0
- package/moderncssm/hooks/useSettings/utils/sortByIndex.d.ts +3 -0
- package/moderncssm/hooks/useSettings/utils/sortByIndex.js +8 -0
- package/moderncssm/icons/Circle.d.ts +8 -0
- package/moderncssm/icons/Circle.js +6 -0
- package/moderncssm/icons/CircleLine.d.ts +8 -0
- package/moderncssm/icons/CircleLine.js +7 -0
- package/moderncssm/icons/FilledCircle.d.ts +8 -0
- package/moderncssm/icons/FilledCircle.js +10 -0
- package/moderncssm/icons/Point.d.ts +8 -0
- package/moderncssm/icons/Point.js +7 -0
- package/moderncssm/icons/StrokeCircle.d.ts +8 -0
- package/moderncssm/icons/StrokeCircle.js +6 -0
- package/moderncssm/index.d.ts +2 -0
- package/moderncssm/index.js +1 -0
- package/moderncssm/index.module.css +19 -0
- package/moderncssm/types/brush.types.d.ts +41 -0
- package/moderncssm/types/brush.types.js +1 -0
- package/moderncssm/types/cartesianGrid.types.d.ts +23 -0
- package/moderncssm/types/cartesianGrid.types.js +1 -0
- package/moderncssm/types/chart.types.d.ts +61 -0
- package/moderncssm/types/chart.types.js +1 -0
- package/moderncssm/types/composedChart.types.d.ts +33 -0
- package/moderncssm/types/composedChart.types.js +1 -0
- package/moderncssm/types/index.d.ts +14 -0
- package/moderncssm/types/index.js +1 -0
- package/moderncssm/types/labelList.types.d.ts +5 -0
- package/moderncssm/types/labelList.types.js +1 -0
- package/moderncssm/types/legend.types.d.ts +30 -0
- package/moderncssm/types/legend.types.js +1 -0
- package/moderncssm/types/options.types.d.ts +59 -0
- package/moderncssm/types/options.types.js +1 -0
- package/moderncssm/types/payload.types.d.ts +29 -0
- package/moderncssm/types/payload.types.js +1 -0
- package/moderncssm/types/responsiveContainer.types.d.ts +10 -0
- package/moderncssm/types/responsiveContainer.types.js +1 -0
- package/moderncssm/types/seria.types.d.ts +72 -0
- package/moderncssm/types/seria.types.js +1 -0
- package/moderncssm/types/tooltip.types.d.ts +70 -0
- package/moderncssm/types/tooltip.types.js +1 -0
- package/moderncssm/types/utils/axis.types.d.ts +68 -0
- package/moderncssm/types/utils/axis.types.js +1 -0
- package/moderncssm/types/utils/coordinates.types.d.ts +11 -0
- package/moderncssm/types/utils/coordinates.types.js +1 -0
- package/moderncssm/types/utils/data.types.d.ts +17 -0
- package/moderncssm/types/utils/data.types.js +1 -0
- package/moderncssm/types/utils/dot.types.d.ts +73 -0
- package/moderncssm/types/utils/dot.types.js +1 -0
- package/moderncssm/types/utils/gradient.types.d.ts +29 -0
- package/moderncssm/types/utils/gradient.types.js +1 -0
- package/moderncssm/types/utils/index.d.ts +7 -0
- package/moderncssm/types/utils/index.js +1 -0
- package/moderncssm/types/utils/tick.types.d.ts +19 -0
- package/moderncssm/types/utils/tick.types.js +1 -0
- package/moderncssm/types/xAxis.types.d.ts +16 -0
- package/moderncssm/types/xAxis.types.js +1 -0
- package/moderncssm/types/yAxis.types.d.ts +8 -0
- package/moderncssm/types/yAxis.types.js +1 -0
- package/package.json +4 -4
- package/src/components/Legends/index.module.css +1 -1
- package/src/components/Tick/index.module.css +1 -1
- package/src/components/TooltipContent/index.module.css +1 -1
- package/src/index.module.css +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { LegendProps } from "../../types/legend.types";
|
|
4
|
+
import { SeriaProps } from "../../types/seria.types";
|
|
5
|
+
import { DataDynamicBooleanProps } from "../../types/utils/data.types";
|
|
6
|
+
interface Props {
|
|
7
|
+
legend: LegendProps;
|
|
8
|
+
series: SeriaProps[];
|
|
9
|
+
id: string;
|
|
10
|
+
charts: DataDynamicBooleanProps;
|
|
11
|
+
toggleChart(item: SeriaProps): void;
|
|
12
|
+
}
|
|
13
|
+
declare const Legends: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLUListElement>>;
|
|
14
|
+
export { Legends };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { Typography } from '@alfalab/core-components-typography/moderncssm';
|
|
4
|
+
import { CircleIcon } from '../../icons/Circle.js';
|
|
5
|
+
import { CircleLineIcon } from '../../icons/CircleLine.js';
|
|
6
|
+
import { FilledCircleIcon } from '../../icons/FilledCircle.js';
|
|
7
|
+
import { StrokeCircleIcon } from '../../icons/StrokeCircle.js';
|
|
8
|
+
import styles from './index.module.css';
|
|
9
|
+
|
|
10
|
+
const icons = {
|
|
11
|
+
circleLine: CircleLineIcon,
|
|
12
|
+
filledCircle: FilledCircleIcon,
|
|
13
|
+
strokeCircle: StrokeCircleIcon,
|
|
14
|
+
circle: CircleIcon,
|
|
15
|
+
};
|
|
16
|
+
const Legends = React.forwardRef(({ legend, series, id, charts, toggleChart }, ref) => {
|
|
17
|
+
const style = {
|
|
18
|
+
textAlign: legend.align || 'center',
|
|
19
|
+
transform: `translateY(${(legend?.marginTop ? legend.marginTop : 0) *
|
|
20
|
+
(legend.verticalAlign === 'top' ? -1 : 1)}px)`,
|
|
21
|
+
};
|
|
22
|
+
return (React.createElement("ul", { ref: ref, className: cn(styles.legendWrap), style: style }, series.map((item) => {
|
|
23
|
+
if (item.hideLegend || item.hide)
|
|
24
|
+
return null;
|
|
25
|
+
const Icon = icons[item.icon] || CircleIcon;
|
|
26
|
+
return (React.createElement("li", { role: 'presentation', key: `${id}-${item.properties.dataKey}`, className: cn(styles.legendItem, charts[`${item.properties.dataKey}`] ? '' : styles.legendUnactive), onClick: () => toggleChart(item) },
|
|
27
|
+
React.createElement("div", { className: cn(styles.legendContent) },
|
|
28
|
+
Icon ? (React.createElement("i", { className: cn(styles.legendIcon) },
|
|
29
|
+
React.createElement(Icon, { fill: item.properties?.fill ||
|
|
30
|
+
item.properties?.stroke ||
|
|
31
|
+
'', height: legend.iconHeight || 16 }))) : null,
|
|
32
|
+
React.createElement(Typography.Text, { view: 'primary-medium', tag: 'span', className: cn(styles.legendValue) }, item.properties.name))));
|
|
33
|
+
})));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { Legends };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
.legendContent {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
flex-wrap: wrap;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.legendWrap {
|
|
10
|
+
width: 100%;
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.legendItem {
|
|
16
|
+
margin-right: var(--gap-32);
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
display: inline-block;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.legendItem:last-child {
|
|
22
|
+
margin-right: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.legendUnactive {
|
|
26
|
+
opacity: 0.3;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.legendIcon {
|
|
30
|
+
margin-right: 13px;
|
|
31
|
+
display: flex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.legendValue {
|
|
35
|
+
text-transform: capitalize;
|
|
36
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const LinearGradient = ({ id, gid, points }) => (React.createElement("linearGradient", { key: `${id}-${gid}`, id: `${id}-${gid}`, x1: '0', y1: '0', x2: '0', y2: '1' }, points.map((point, index) => (React.createElement("stop", { key: `${id}${gid}-${index.toString()}`, offset: `${point.offset}%`, stopColor: point.stopColor, stopOpacity: point.stopOpacity })))));
|
|
4
|
+
|
|
5
|
+
export { LinearGradient };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { usePathBar } from '../hooks/usePathBar/index.js';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
// eslint-disable-next-line complexity
|
|
6
|
+
const getPath = (x, width, height, initHeight, topRadius, bottomRadius, initY) => `
|
|
7
|
+
M${x + ((height !== 0 && bottomRadius) || 0)} ${initY + initHeight || 0}
|
|
8
|
+
Q${x} ${initY + initHeight} ${x} ${initY + initHeight - ((height !== 0 && bottomRadius) || 0)}
|
|
9
|
+
L${x} ${initY + ((height !== 0 && topRadius) || 0)}
|
|
10
|
+
Q${x} ${initY} ${x + ((height !== 0 && topRadius) || 0)} ${initY}
|
|
11
|
+
L${x + width - ((height !== 0 && topRadius) || 0)} ${initY}
|
|
12
|
+
Q${x + width} ${initY} ${x + width} ${initY + (topRadius || 0)}
|
|
13
|
+
L${x + width} ${initY + initHeight - ((height !== 0 && bottomRadius) || 0)}
|
|
14
|
+
Q${x + width} ${initY + initHeight} ${x + width - ((height !== 0 && bottomRadius) || 0)} ${initY + initHeight}
|
|
15
|
+
Z
|
|
16
|
+
`;
|
|
17
|
+
const RectBar = ({ fill, x, y, width, height, radius, background }) => {
|
|
18
|
+
const [initHeight, topRadius, bottomRadius, initY] = usePathBar({
|
|
19
|
+
radius,
|
|
20
|
+
height,
|
|
21
|
+
background,
|
|
22
|
+
y,
|
|
23
|
+
});
|
|
24
|
+
return useMemo(() => (React.createElement("path", { d: getPath(x, width, height, initHeight, topRadius, bottomRadius, initY), stroke: 'none', fill: fill })), [x, width, height, initHeight, topRadius, bottomRadius, initY, fill]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { RectBar };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import styles from './index.module.css';
|
|
4
|
+
|
|
5
|
+
const Tick = ({ y, payload, tickFormatter, xAxis }) => {
|
|
6
|
+
const radius = 4;
|
|
7
|
+
const marginTick = xAxis?.tickMargin &&
|
|
8
|
+
(xAxis.tickMargin > 0 ? xAxis.tickMargin - radius / 2 : xAxis.tickMargin === 0)
|
|
9
|
+
? (radius / 2) * -1
|
|
10
|
+
: null;
|
|
11
|
+
return (React.createElement("g", { className: cn(styles.tick), opacity: '1', textAnchor: 'middle', transform: `translate(${payload.coordinate}, ${y - (typeof marginTick === 'number' ? marginTick : 0) - radius * 2})` },
|
|
12
|
+
React.createElement("text", { className: cn(styles.tickText), y: '30' }, tickFormatter ? tickFormatter(payload.value) : payload.value),
|
|
13
|
+
React.createElement("circle", { r: radius, className: cn(styles.circle) })));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { Tick };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
.tickText {
|
|
4
|
+
fill: var(--color-light-text-primary);
|
|
5
|
+
font-size: 16px;
|
|
6
|
+
line-height: 24px;
|
|
7
|
+
font-weight: 400;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.circle {
|
|
11
|
+
opacity: 0.3;
|
|
12
|
+
fill: var(--color-dark-base-bg-primary);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.circle {
|
|
16
|
+
opacity: 0.3;
|
|
17
|
+
fill: var(--color-dark-base-bg-primary);
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { PayloadProps } from "../../types/payload.types";
|
|
4
|
+
import { SeriaProps } from "../../types/seria.types";
|
|
5
|
+
import { TooltipProps } from "../../types/tooltip.types";
|
|
6
|
+
interface TooltipContentProps extends TooltipProps {
|
|
7
|
+
payload: PayloadProps[];
|
|
8
|
+
series: SeriaProps[];
|
|
9
|
+
}
|
|
10
|
+
declare const TooltipContent: ({ payload, separator, label, tooltipArrowSide, arrow, series, labelFormatter, labelStyle, }: TooltipContentProps) => React.JSX.Element | null;
|
|
11
|
+
export { TooltipContentProps, TooltipContent };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { Typography } from '@alfalab/core-components-typography/moderncssm';
|
|
4
|
+
import styles from './index.module.css';
|
|
5
|
+
|
|
6
|
+
const TooltipContent = ({ payload, separator, label, tooltipArrowSide, arrow, series, labelFormatter, labelStyle, }) => {
|
|
7
|
+
if (!label || payload.length === 0)
|
|
8
|
+
return null;
|
|
9
|
+
return (React.createElement("div", { className: cn(styles.tooltip) },
|
|
10
|
+
arrow && (React.createElement("span", { className: cn(styles.tooltipArrow, tooltipArrowSide ? '' : styles.tooltipArrowRight) })),
|
|
11
|
+
React.createElement("ul", { className: cn(styles.tooltipList) },
|
|
12
|
+
React.createElement("li", { className: cn(styles.tooltipItem), style: labelStyle },
|
|
13
|
+
React.createElement(Typography.Text, { view: 'primary-medium', tag: 'span', weight: 'medium', className: cn(styles.tooltipLabel) }, labelFormatter ? labelFormatter(label) : label)),
|
|
14
|
+
payload.map((entry) => {
|
|
15
|
+
const data = series.find((d) => d.properties.dataKey === entry.dataKey);
|
|
16
|
+
if (data?.hideTooltip || data?.hide)
|
|
17
|
+
return null;
|
|
18
|
+
return (React.createElement("li", { className: cn(styles.tooltipItem), key: entry.dataKey, style: { color: entry.color } },
|
|
19
|
+
React.createElement(Typography.Text, { view: 'primary-medium', tag: 'span', weight: 'medium', className: cn(styles.tooltipValue) },
|
|
20
|
+
entry?.formatter ? entry.formatter(entry.value) : entry.value,
|
|
21
|
+
separator || ' '),
|
|
22
|
+
React.createElement(Typography.Text, { view: 'secondary-large', tag: 'span', className: cn(styles.tooltipName) }, `${entry.name}`)));
|
|
23
|
+
}))));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { TooltipContent };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
.tooltip {
|
|
4
|
+
background-color: var(--color-light-base-bg-primary);
|
|
5
|
+
border: 1px solid var(--color-light-neutral-400);
|
|
6
|
+
box-shadow: var(--shadow-l);
|
|
7
|
+
border-radius: var(--border-radius-m);
|
|
8
|
+
padding: var(--gap-12) var(--gap-16);
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
position: relative;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tooltipList {
|
|
14
|
+
position: relative;
|
|
15
|
+
z-index: 5;
|
|
16
|
+
list-style-type: none;
|
|
17
|
+
padding: 0;
|
|
18
|
+
margin: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.tooltipItem {
|
|
22
|
+
margin-bottom: 10px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.tooltipArrow {
|
|
26
|
+
position: absolute;
|
|
27
|
+
left: 0;
|
|
28
|
+
top: 50%;
|
|
29
|
+
transform: translate(-50%, -50%) scale(1, 1) rotate(45deg);
|
|
30
|
+
width: 10px;
|
|
31
|
+
height: 10px;
|
|
32
|
+
border: 1px solid var(--color-light-neutral-400);
|
|
33
|
+
background-color: var(--color-light-base-bg-primary);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.tooltipArrow:before {
|
|
37
|
+
content: '';
|
|
38
|
+
position: absolute;
|
|
39
|
+
left: -2px;
|
|
40
|
+
top: -2px;
|
|
41
|
+
width: 0;
|
|
42
|
+
height: 0;
|
|
43
|
+
border-style: solid;
|
|
44
|
+
border-width: 0 24px 24px 0;
|
|
45
|
+
border-color: transparent var(--color-light-base-bg-primary) transparent transparent;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.tooltipArrowRight {
|
|
49
|
+
left: 100%;
|
|
50
|
+
transform: translate(-50%, -50%) scale(-1, 1) rotate(45deg);
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RadiusProp } from "../../types/seria.types";
|
|
2
|
+
type usePathBarProps = {
|
|
3
|
+
radius?: RadiusProp;
|
|
4
|
+
height: number;
|
|
5
|
+
background?: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
height: number;
|
|
9
|
+
width: number;
|
|
10
|
+
};
|
|
11
|
+
y?: number;
|
|
12
|
+
};
|
|
13
|
+
declare const usePathBar: (props: usePathBarProps) => number[];
|
|
14
|
+
export { usePathBarProps, usePathBar };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { getRadius } from './utils/getRadius.js';
|
|
3
|
+
|
|
4
|
+
const usePathBar = (props) => {
|
|
5
|
+
const [topRadius, setTopRadius] = useState(0);
|
|
6
|
+
const [bottomRadius, setBottomRadius] = useState(0);
|
|
7
|
+
const [initHeight, setInitHeight] = useState(0);
|
|
8
|
+
const [initY, setInitY] = useState(0);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const { radius, height, background, y } = props;
|
|
11
|
+
const radiusTop = radius?.top ? getRadius(height, radius.top) : 0;
|
|
12
|
+
const radiusBottom = radius?.bottom ? getRadius(height, radius.bottom) : 0;
|
|
13
|
+
const heightCheck = (radius && height !== 0 && height / 2 < (radius?.top || 0)) ||
|
|
14
|
+
height / 2 < (radius?.bottom || 0);
|
|
15
|
+
// eslint-disable-next-line no-nested-ternary
|
|
16
|
+
const heightInit = heightCheck
|
|
17
|
+
? (radiusTop || radiusBottom) && radiusTop + radiusBottom
|
|
18
|
+
: height > 0 && height < 2
|
|
19
|
+
? 2
|
|
20
|
+
: height;
|
|
21
|
+
if (background && y) {
|
|
22
|
+
const yInit = heightCheck
|
|
23
|
+
? background.height + background.y - (radiusTop + radiusBottom)
|
|
24
|
+
: y;
|
|
25
|
+
setInitY(yInit);
|
|
26
|
+
}
|
|
27
|
+
if (radiusTop !== 0)
|
|
28
|
+
setTopRadius(radiusTop);
|
|
29
|
+
if (radiusBottom !== 0)
|
|
30
|
+
setBottomRadius(radiusBottom);
|
|
31
|
+
if (heightInit !== 0)
|
|
32
|
+
setInitHeight(heightInit);
|
|
33
|
+
}, [props]);
|
|
34
|
+
return [initHeight, topRadius, bottomRadius, initY];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { usePathBar };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { OptionsProps } from "../../types/options.types";
|
|
3
|
+
import { DataDynamicBooleanProps, DataDynamicProps } from "../../types/utils/data.types";
|
|
4
|
+
type Settings = [
|
|
5
|
+
{
|
|
6
|
+
state: OptionsProps | null;
|
|
7
|
+
data: DataDynamicProps[];
|
|
8
|
+
charts: DataDynamicBooleanProps;
|
|
9
|
+
filterCount: number;
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
setState: Dispatch<SetStateAction<OptionsProps | null>>;
|
|
13
|
+
setData: Dispatch<SetStateAction<DataDynamicProps[]>>;
|
|
14
|
+
setCharts: Dispatch<SetStateAction<DataDynamicBooleanProps>>;
|
|
15
|
+
setFilterCount: Dispatch<SetStateAction<number>>;
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
declare const useSettings: (options: OptionsProps) => Settings;
|
|
19
|
+
export { useSettings };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { setComposedChartsMargin } from './utils/setComposedChartsMargin.js';
|
|
3
|
+
import { setDatas } from './utils/setDatas.js';
|
|
4
|
+
import { setGradientCharts } from './utils/setGradientCharts.js';
|
|
5
|
+
import { setLegendMargin } from './utils/setLegendMargin.js';
|
|
6
|
+
import { sortByIndex } from './utils/sortByIndex.js';
|
|
7
|
+
|
|
8
|
+
const useSettings = (options) => {
|
|
9
|
+
const [state, setState] = useState(null);
|
|
10
|
+
const [charts, setCharts] = useState({});
|
|
11
|
+
const [data, setData] = useState([]);
|
|
12
|
+
const [filterCount, setFilterCount] = useState(0);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const settings = { ...options };
|
|
15
|
+
const { brush, legend, series, labels, composeChart, xAxis } = settings;
|
|
16
|
+
if (settings.legend?.margin && brush && legend)
|
|
17
|
+
settings.legend.margin.top = setLegendMargin(brush, legend);
|
|
18
|
+
settings.series = setGradientCharts(series);
|
|
19
|
+
const [initData, chartsNames, count] = setDatas(settings.series, labels);
|
|
20
|
+
settings.composeChart.margin = setComposedChartsMargin(composeChart, legend, brush, xAxis);
|
|
21
|
+
settings.series = sortByIndex(settings.series);
|
|
22
|
+
setState(settings);
|
|
23
|
+
setData(initData);
|
|
24
|
+
setCharts(chartsNames);
|
|
25
|
+
setFilterCount(count);
|
|
26
|
+
}, [options]);
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
state,
|
|
30
|
+
data,
|
|
31
|
+
charts,
|
|
32
|
+
filterCount,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
setState,
|
|
36
|
+
setData,
|
|
37
|
+
setCharts,
|
|
38
|
+
setFilterCount,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { useSettings };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BrushProps } from "../../../types/brush.types";
|
|
2
|
+
import { ComposedChartProps } from "../../../types/composedChart.types";
|
|
3
|
+
import { LegendProps } from "../../../types/legend.types";
|
|
4
|
+
import { XAxisProps } from "../../../types/xAxis.types";
|
|
5
|
+
type ComposedChartsMarginResultProps = {
|
|
6
|
+
top: number;
|
|
7
|
+
bottom: number;
|
|
8
|
+
left: number;
|
|
9
|
+
right: number;
|
|
10
|
+
};
|
|
11
|
+
declare const setComposedChartsMargin: (composeChart: ComposedChartProps, legend: LegendProps | undefined, brush: BrushProps | undefined, xAxis: XAxisProps) => ComposedChartsMarginResultProps;
|
|
12
|
+
export { setComposedChartsMargin };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const setComposedChartsMargin = (composeChart, legend, brush, xAxis) => ({
|
|
2
|
+
top: (composeChart?.initMargin?.top || 0) +
|
|
3
|
+
(legend?.verticalAlign === 'top' && legend?.marginTop ? Math.abs(legend.marginTop) : 0),
|
|
4
|
+
bottom: (composeChart?.initMargin?.bottom || 0) +
|
|
5
|
+
(xAxis?.tickMargin || 0) +
|
|
6
|
+
(brush?.brushMargin || 0) +
|
|
7
|
+
(legend?.verticalAlign !== 'top' && legend?.marginTop ? legend.marginTop : 0),
|
|
8
|
+
left: composeChart?.initMargin?.left || 0,
|
|
9
|
+
right: composeChart?.initMargin?.right || 0,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { setComposedChartsMargin };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SeriaProps } from "../../../types/seria.types";
|
|
2
|
+
import { DataDynamicBooleanProps, DataDynamicProps } from "../../../types/utils/data.types";
|
|
3
|
+
type DatasResultProps = [DataDynamicProps[], DataDynamicBooleanProps, number];
|
|
4
|
+
declare const setDatas: (series: SeriaProps[], labels: Array<string | number>) => DatasResultProps;
|
|
5
|
+
export { setDatas };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const setDatas = (series, labels) => {
|
|
2
|
+
const initData = [];
|
|
3
|
+
const chartsNames = {};
|
|
4
|
+
let count = 0;
|
|
5
|
+
for (let i = 0; i < series.length; i++) {
|
|
6
|
+
const { properties: { dataKey = '' } = {}, data: seriaData = [], hideLegend, hide, } = series[i];
|
|
7
|
+
if (!hideLegend && !hide)
|
|
8
|
+
count += 1;
|
|
9
|
+
labels.map((label) => {
|
|
10
|
+
const item = seriaData.find((d) => d.label === label);
|
|
11
|
+
if (item) {
|
|
12
|
+
const obj = {
|
|
13
|
+
label,
|
|
14
|
+
};
|
|
15
|
+
obj[`${dataKey}`] = item.value;
|
|
16
|
+
if (!chartsNames[`${dataKey}`])
|
|
17
|
+
chartsNames[`${dataKey}`] = true;
|
|
18
|
+
const index = initData
|
|
19
|
+
.map((dataItem) => dataItem.label)
|
|
20
|
+
.indexOf(label);
|
|
21
|
+
if (index === -1)
|
|
22
|
+
initData.push(obj);
|
|
23
|
+
else
|
|
24
|
+
initData[index] = { ...initData[index], ...obj };
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return [initData, chartsNames, count];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { setDatas };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const setGradientCharts = (series) => {
|
|
2
|
+
const filterSeries = series.filter((item) => item.chart !== 'gradient');
|
|
3
|
+
return filterSeries.reduce((accum, item) => {
|
|
4
|
+
const { chart, data: dataSeria, offset, fill } = item;
|
|
5
|
+
if (chart === 'area') {
|
|
6
|
+
let newData = null;
|
|
7
|
+
if (offset) {
|
|
8
|
+
newData = dataSeria.map((d) => {
|
|
9
|
+
const { label, value } = d;
|
|
10
|
+
return {
|
|
11
|
+
label,
|
|
12
|
+
value: Math.ceil(value - value * offset),
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
accum.push({
|
|
17
|
+
...item,
|
|
18
|
+
zIndex: -100,
|
|
19
|
+
chart: 'gradient',
|
|
20
|
+
hideLegend: true,
|
|
21
|
+
hideTooltip: true,
|
|
22
|
+
properties: {
|
|
23
|
+
...item.properties,
|
|
24
|
+
dataKey: `${item.properties.dataKey}-gradient`,
|
|
25
|
+
fill,
|
|
26
|
+
},
|
|
27
|
+
data: newData || item.data,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
accum.push(item);
|
|
31
|
+
return accum;
|
|
32
|
+
}, []);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { setGradientCharts };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const setLegendMargin = (brush, legend) => {
|
|
2
|
+
let top = 0;
|
|
3
|
+
if (typeof brush?.brushMargin !== 'number' || !legend?.verticalAlign)
|
|
4
|
+
return top;
|
|
5
|
+
if (legend.verticalAlign === 'top') {
|
|
6
|
+
top = legend.marginTop ? Number(legend.marginTop * -1) : 0;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
top = legend?.marginTop ? legend.marginTop + (brush?.brushMargin || 0) : brush?.brushMargin;
|
|
10
|
+
}
|
|
11
|
+
return top;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { setLegendMargin };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const CircleIcon = ({ fill = '#FF5C5C', height = 16 }) => (React.createElement("svg", { xmlns: 'http://www.w3.org/2000/svg', height: height, viewBox: '0 0 16 16', fill: 'none' },
|
|
4
|
+
React.createElement("circle", { cx: '8', cy: '8', r: '8', fill: fill })));
|
|
5
|
+
|
|
6
|
+
export { CircleIcon };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const CircleLineIcon = ({ fill = '#FF5C5C', height = 16 }) => (React.createElement("svg", { xmlns: 'http://www.w3.org/2000/svg', height: height, viewBox: '0 0 22 12', fill: 'none' },
|
|
4
|
+
React.createElement("circle", { cx: '11', cy: '6', r: '6', fill: fill }),
|
|
5
|
+
React.createElement("rect", { y: '5', width: '22', height: '2', fill: fill })));
|
|
6
|
+
|
|
7
|
+
export { CircleLineIcon };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const FilledCircleIcon = ({ fill = '#5A8ECF', height = 16 }) => (React.createElement("svg", { xmlns: 'http://www.w3.org/2000/svg', height: height, viewBox: '0 0 22 22', fill: 'none' },
|
|
4
|
+
React.createElement("circle", { cx: '11', cy: '11', r: '10', fill: 'url(#paint0_linear)', stroke: fill, strokeWidth: '2' }),
|
|
5
|
+
React.createElement("defs", null,
|
|
6
|
+
React.createElement("linearGradient", { id: 'paint0_linear', x1: '11', y1: '1', x2: '11', y2: '21', gradientUnits: 'userSpaceOnUse' },
|
|
7
|
+
React.createElement("stop", { stopColor: fill, stopOpacity: '0.2' }),
|
|
8
|
+
React.createElement("stop", { offset: '1', stopColor: fill, stopOpacity: '0' })))));
|
|
9
|
+
|
|
10
|
+
export { FilledCircleIcon };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const PointIcon = ({ fill = '#5A8ECF', height = 16 }) => (React.createElement("svg", { height: height, viewBox: '0 0 18 18' },
|
|
4
|
+
React.createElement("circle", { cx: '9', cy: '9', r: '9', strokeWidth: '1', fill: fill, fillOpacity: '0.4' }),
|
|
5
|
+
React.createElement("circle", { cx: '9', cy: '9', r: '3', strokeWidth: '2', stroke: '#fff', fill: fill })));
|
|
6
|
+
|
|
7
|
+
export { PointIcon };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const StrokeCircleIcon = ({ fill = '#5A8ECF', height = 16 }) => (React.createElement("svg", { xmlns: 'http://www.w3.org/2000/svg', height: height, viewBox: '0 0 22 22', fill: 'none' },
|
|
4
|
+
React.createElement("circle", { cx: '11', cy: '11', r: '10', stroke: fill, strokeWidth: '2', strokeDasharray: '8 8' })));
|
|
5
|
+
|
|
6
|
+
export { StrokeCircleIcon };
|