@scality/core-ui 0.175.0 → 0.177.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/dist/components/barchartv2/Barchart.component.d.ts +4 -5
- package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
- package/dist/components/barchartv2/Barchart.component.js +23 -27
- package/dist/components/barchartv2/BarchartTooltip.d.ts +4 -3
- package/dist/components/barchartv2/BarchartTooltip.d.ts.map +1 -1
- package/dist/components/barchartv2/BarchartTooltip.js +10 -12
- package/dist/components/barchartv2/utils.d.ts +6 -1
- package/dist/components/barchartv2/utils.d.ts.map +1 -1
- package/dist/components/barchartv2/utils.js +34 -8
- package/dist/components/chartlegend/ChartLegendWrapper.js +1 -1
- package/dist/components/charttooltip/ChartTooltip.d.ts +29 -0
- package/dist/components/charttooltip/ChartTooltip.d.ts.map +1 -1
- package/dist/components/charttooltip/ChartTooltip.js +105 -1
- package/dist/components/date/FormattedDateTime.d.ts +23 -8
- package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
- package/dist/components/date/FormattedDateTime.js +51 -7
- package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts.map +1 -1
- package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.js +27 -1
- package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts +1 -1
- package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts.map +1 -1
- package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.js +19 -59
- package/dist/components/globalhealthbar/components/HealthBarXAxis.js +1 -1
- package/dist/components/globalhealthbar/useHealthBarData.d.ts +1 -0
- package/dist/components/globalhealthbar/useHealthBarData.d.ts.map +1 -1
- package/dist/components/globalhealthbar/useHealthBarData.js +1 -0
- package/dist/components/globalhealthbar/useHealthBarData.spec.js +2 -0
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +2 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.js +45 -47
- package/dist/components/linetimeseriechart/utils.d.ts +1 -1
- package/dist/components/linetimeseriechart/utils.d.ts.map +1 -1
- package/dist/components/linetimeseriechart/utils.js +13 -13
- package/dist/style/theme.js +1 -1
- package/package.json +1 -1
- package/src/lib/components/barchartv2/Barchart.component.test.tsx +23 -25
- package/src/lib/components/barchartv2/Barchart.component.tsx +41 -39
- package/src/lib/components/barchartv2/BarchartTooltip.test.tsx +33 -3
- package/src/lib/components/barchartv2/BarchartTooltip.tsx +33 -24
- package/src/lib/components/barchartv2/utils.test.ts +72 -17
- package/src/lib/components/barchartv2/utils.ts +40 -12
- package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +1 -1
- package/src/lib/components/charttooltip/ChartTooltip.tsx +174 -1
- package/src/lib/components/date/FormattedDateTime.tsx +73 -8
- package/src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component.tsx +56 -11
- package/src/lib/components/globalhealthbar/components/GlobalHealthBarTooltip.tsx +75 -117
- package/src/lib/components/globalhealthbar/components/HealthBarXAxis.tsx +1 -1
- package/src/lib/components/globalhealthbar/useHealthBarData.spec.tsx +2 -0
- package/src/lib/components/globalhealthbar/useHealthBarData.ts +2 -0
- package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +101 -90
- package/src/lib/components/linetimeseriechart/utils.test.ts +30 -68
- package/src/lib/components/linetimeseriechart/utils.ts +13 -17
- package/src/lib/style/theme.ts +1 -1
- package/stories/BarChart/barchart.stories.tsx +23 -8
- package/stories/formattedate.stories.tsx +2 -0
- package/stories/linetimeseriechart.stories.tsx +1 -0
|
@@ -41,6 +41,7 @@ export type BarchartSortFn<T extends BarchartBars> = (pointA: Record<T[number]['
|
|
|
41
41
|
}) => 1 | -1 | 0;
|
|
42
42
|
export type BarchartProps<T extends BarchartBars> = {
|
|
43
43
|
type: CategoryType | TimeType;
|
|
44
|
+
title: string;
|
|
44
45
|
bars?: T;
|
|
45
46
|
tooltip?: BarchartTooltipFn<T>;
|
|
46
47
|
defaultSort?: BarchartSortFn<T>;
|
|
@@ -54,7 +55,6 @@ export type BarchartProps<T extends BarchartBars> = {
|
|
|
54
55
|
* @default 'default'
|
|
55
56
|
*/
|
|
56
57
|
stackedBarSort?: 'default' | 'legend';
|
|
57
|
-
title?: string;
|
|
58
58
|
secondaryTitle?: string;
|
|
59
59
|
rightTitle?: React.ReactNode;
|
|
60
60
|
height?: number;
|
|
@@ -72,12 +72,11 @@ interface CustomTickProps {
|
|
|
72
72
|
type: TimeType;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @param interval - Interval in milliseconds
|
|
75
|
+
* Get the format of the date based on the duration
|
|
76
|
+
* @param duration - Duration in milliseconds
|
|
78
77
|
* @returns Formatted string
|
|
79
78
|
*/
|
|
80
|
-
export declare const formatDate: (
|
|
79
|
+
export declare const formatDate: (duration: number) => "time" | "day-month-abbreviated" | "chart-long-term-date";
|
|
81
80
|
export declare const CustomTick: ({ x, y, payload, visibleTicksCount, width, type, }: CustomTickProps) => import("react/jsx-runtime").JSX.Element;
|
|
82
81
|
export declare const StyledResponsiveContainer: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("recharts").ResponsiveContainerProps & import("react").RefAttributes<HTMLDivElement>>, import("styled-components").DefaultTheme, {}, never>;
|
|
83
82
|
export declare const Barchart: <T extends BarchartBars>(props: BarchartProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"AAsBA,OAAO,EAAY,SAAS,EAAgB,MAAM,SAAS,CAAC;AAkB5D,MAAM,MA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,eAAO,MAAM,yBAAyB,0OAMrC,CAAC;AAyEF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,SAAS,aAAa,CAAC,CAAC,CAAC,4CAmJvE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { useState } from 'react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef } from 'react';
|
|
3
3
|
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
|
|
4
4
|
import styled, { useTheme } from 'styled-components';
|
|
5
5
|
import { spacing, Stack, Wrap } from '../../spacing';
|
|
@@ -12,7 +12,7 @@ import { IconHelp } from '../iconhelper/IconHelper';
|
|
|
12
12
|
import { Loader } from '../loader/Loader.component';
|
|
13
13
|
import { Text } from '../text/Text.component';
|
|
14
14
|
import { BarchartTooltip } from './BarchartTooltip';
|
|
15
|
-
import { useChartData } from './utils';
|
|
15
|
+
import { getTicks, useChartData } from './utils';
|
|
16
16
|
const CHART_CONSTANTS = {
|
|
17
17
|
TICK_WIDTH_OFFSET: 4,
|
|
18
18
|
BAR_SIZE: 12,
|
|
@@ -25,39 +25,32 @@ const CHART_CONSTANTS = {
|
|
|
25
25
|
bottom: 0,
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
|
+
const maxWidthTooltip = { maxWidth: '20rem' };
|
|
28
29
|
/* ---------------------------------- COMPONENTS ---------------------------------- */
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param
|
|
32
|
-
* @param interval - Interval in milliseconds
|
|
31
|
+
* Get the format of the date based on the duration
|
|
32
|
+
* @param duration - Duration in milliseconds
|
|
33
33
|
* @returns Formatted string
|
|
34
34
|
*/
|
|
35
|
-
export const formatDate = (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (interval > 24 * 60 * 60 * 1000) {
|
|
39
|
-
return (_jsxs(_Fragment, { children: [_jsx(FormattedDateTime, { format: "chart-date", value: date }), ' ', _jsx(FormattedDateTime, { format: "time", value: date })] }));
|
|
35
|
+
export const formatDate = (duration) => {
|
|
36
|
+
if (duration <= 24 * 60 * 60 * 1000) {
|
|
37
|
+
return 'time';
|
|
40
38
|
}
|
|
41
|
-
else if (
|
|
42
|
-
|
|
43
|
-
return _jsx(FormattedDateTime, { format: "chart-date", value: date });
|
|
44
|
-
}
|
|
45
|
-
else if (interval >= 60 * 1000) {
|
|
46
|
-
//Hourly and minute intervals - use minute format
|
|
47
|
-
return _jsx(FormattedDateTime, { format: "time", value: date });
|
|
39
|
+
else if (duration <= 7 * 24 * 60 * 60 * 1000) {
|
|
40
|
+
return 'day-month-abbreviated';
|
|
48
41
|
}
|
|
49
42
|
else {
|
|
50
|
-
|
|
51
|
-
return timestamp;
|
|
43
|
+
return 'chart-long-term-date';
|
|
52
44
|
}
|
|
53
45
|
};
|
|
54
46
|
export const CustomTick = ({ x, y, payload, visibleTicksCount, width, type, }) => {
|
|
55
47
|
const theme = useTheme();
|
|
56
48
|
const tickWidth = width / visibleTicksCount - CHART_CONSTANTS.TICK_WIDTH_OFFSET;
|
|
57
49
|
const centerX = x - tickWidth / 2;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
const duration = type.type === 'time'
|
|
51
|
+
? type.timeRange.endDate.getTime() - type.timeRange.startDate.getTime()
|
|
52
|
+
: 0;
|
|
53
|
+
return (_jsx("foreignObject", { x: centerX, y: y - 8, width: tickWidth, color: theme.textSecondary, overflow: "visible", children: _jsx(ConstrainedText, { color: "textSecondary", text: _jsx(Text, { variant: "Smaller", children: type.type === 'time' ? (_jsx(FormattedDateTime, { format: formatDate(duration), value: new Date(payload.value) })) : (String(payload.value)) }), centered: true, tooltipStyle: {
|
|
61
54
|
backgroundColor: theme.backgroundLevel1,
|
|
62
55
|
padding: spacing.r10,
|
|
63
56
|
borderRadius: spacing.r8,
|
|
@@ -68,11 +61,12 @@ export const CustomTick = ({ x, y, payload, visibleTicksCount, width, type, }) =
|
|
|
68
61
|
export const StyledResponsiveContainer = styled(ResponsiveContainer) `
|
|
69
62
|
// Avoid tooltip over constrained text to be cut off
|
|
70
63
|
& .recharts-surface {
|
|
64
|
+
outline: none;
|
|
71
65
|
overflow: visible;
|
|
72
66
|
}
|
|
73
67
|
`;
|
|
74
68
|
const ChartHeader = ({ title, secondaryTitle, helpTooltip, rightTitle, }) => {
|
|
75
|
-
return (_jsxs(Wrap, { children: [_jsxs(Stack, { gap: "r4", children: [_jsx(Text, { variant: "ChartTitle", children: title }), helpTooltip && _jsx(IconHelp, { tooltipMessage: helpTooltip }), secondaryTitle && (_jsx(Text, { color: "textSecondary", style: {
|
|
69
|
+
return (_jsxs(Wrap, { children: [_jsxs(Stack, { gap: "r4", children: [_jsx(Text, { variant: "ChartTitle", children: title }), helpTooltip && (_jsx(IconHelp, { tooltipMessage: helpTooltip, overlayStyle: maxWidthTooltip })), secondaryTitle && (_jsx(Text, { color: "textSecondary", style: {
|
|
76
70
|
marginLeft: spacing.r8,
|
|
77
71
|
}, children: secondaryTitle }))] }), rightTitle && _jsx(Text, { children: rightTitle })] }));
|
|
78
72
|
};
|
|
@@ -95,6 +89,7 @@ export const Barchart = (props) => {
|
|
|
95
89
|
const theme = useTheme();
|
|
96
90
|
const { getColor } = useChartLegend();
|
|
97
91
|
const [hoveredValue, setHoveredValue] = useState();
|
|
92
|
+
const chartRef = useRef(null);
|
|
98
93
|
const { height = CHART_CONSTANTS.DEFAULT_HEIGHT, bars, type = { type: 'category' }, unitRange, stacked, stackedBarSort = 'default', defaultSort, tooltip, title, secondaryTitle, helpTooltip, rightTitle, isLoading, isError, } = props;
|
|
99
94
|
// Create colorSet from ChartLegendWrapper
|
|
100
95
|
const colorSet = bars === null || bars === void 0 ? void 0 : bars.reduce((acc, bar) => {
|
|
@@ -105,14 +100,15 @@ export const Barchart = (props) => {
|
|
|
105
100
|
return acc;
|
|
106
101
|
}, {});
|
|
107
102
|
const { rechartsBars, unitLabel, roundReferenceValue, rechartsData } = useChartData(bars || [], type, colorSet || {}, stacked, defaultSort, unitRange, stackedBarSort);
|
|
108
|
-
|
|
103
|
+
const titleWithUnit = unitLabel ? `${title} (${unitLabel})` : title;
|
|
104
|
+
return (_jsxs(Stack, { direction: "vertical", style: { gap: '0' }, children: [_jsx(ChartHeader, { title: titleWithUnit, secondaryTitle: secondaryTitle, helpTooltip: helpTooltip, rightTitle: rightTitle }), isError || (!bars && !isLoading) ? (_jsx(Error, { height: height })) : isLoading ? (_jsx(Loading, { height: height })) : (_jsx(StyledResponsiveContainer, { ref: chartRef, width: "100%", height: height, children: _jsxs(BarChart, { data: rechartsData, accessibilityLayer: true, barSize: type.type === 'category'
|
|
109
105
|
? type.gap === 0
|
|
110
106
|
? undefined
|
|
111
107
|
: CHART_CONSTANTS.BAR_SIZE
|
|
112
108
|
: CHART_CONSTANTS.BAR_SIZE, height: height, margin: CHART_CONSTANTS.CHART_MARGIN, barCategoryGap: type.type === 'category' ? type.gap : undefined, children: [_jsx(CartesianGrid, { vertical: true, horizontal: true, verticalPoints: [0], horizontalPoints: [0], stroke: theme.border, fill: theme.backgroundLevel4, strokeWidth: 1 }), rechartsBars.map((bar) => {
|
|
113
109
|
const { fill, dataKey, stackId } = bar;
|
|
114
110
|
return (_jsx(Bar, { dataKey: dataKey, fill: chartColors[fill] || fill, minPointSize: stacked ? 0 : CHART_CONSTANTS.MIN_POINT_SIZE, stackId: stackId, isAnimationActive: false, onMouseOver: () => setHoveredValue(dataKey), onMouseLeave: () => setHoveredValue(undefined) }, dataKey));
|
|
115
|
-
}), _jsx(YAxis, {
|
|
111
|
+
}), _jsx(YAxis, { interval: 0, domain: [0, roundReferenceValue], ticks: getTicks(roundReferenceValue, false), tickFormatter: (value) => new Intl.NumberFormat('fr-FR').format(value) // Add a space as thousand separator
|
|
116
112
|
, axisLine: { stroke: theme.border }, tick: {
|
|
117
113
|
fill: theme.textSecondary,
|
|
118
114
|
fontSize: fontSize.smaller,
|
|
@@ -120,5 +116,5 @@ export const Barchart = (props) => {
|
|
|
120
116
|
stroke: theme.border,
|
|
121
117
|
}, axisLine: {
|
|
122
118
|
stroke: theme.border,
|
|
123
|
-
} }), _jsx(Tooltip, { content: (props) => (_jsx(BarchartTooltip, { type: type, colorSet: colorSet, tooltipProps: props, hoveredValue: hoveredValue, tooltip: tooltip, unitLabel: unitLabel })), cursor: false })] }) }))] }));
|
|
119
|
+
} }), _jsx(Tooltip, { content: (props) => (_jsx(BarchartTooltip, { type: type, colorSet: colorSet, tooltipProps: props, hoveredValue: hoveredValue, tooltip: tooltip, unitLabel: unitLabel, chartContainerRef: chartRef })), cursor: false })] }) }))] }));
|
|
124
120
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { BarchartBars, BarchartTooltipFn, CategoryType, TimeType } from './Barchart.component';
|
|
2
1
|
import { TooltipContentProps } from 'recharts';
|
|
3
|
-
|
|
2
|
+
import { BarchartBars, BarchartTooltipFn, CategoryType, TimeType } from './Barchart.component';
|
|
3
|
+
export declare const BarchartTooltip: <T extends BarchartBars>({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, chartContainerRef, }: {
|
|
4
4
|
type: TimeType | CategoryType;
|
|
5
5
|
tooltipProps: TooltipContentProps<number, string>;
|
|
6
6
|
colorSet?: Record<string, string>;
|
|
7
7
|
hoveredValue: string | undefined;
|
|
8
8
|
tooltip?: BarchartTooltipFn<T>;
|
|
9
9
|
unitLabel?: string;
|
|
10
|
-
|
|
10
|
+
chartContainerRef: React.RefObject<HTMLDivElement>;
|
|
11
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
11
12
|
//# sourceMappingURL=BarchartTooltip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarchartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/BarchartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACT,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"BarchartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/BarchartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAS/C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAG9B,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,YAAY,0FAQnD;IACD,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC;IAC9B,YAAY,EAAE,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;CACpD,mDAgEA,CAAC"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { FormattedDateTime } from '../date/FormattedDateTime';
|
|
3
|
-
import { getCurrentPoint } from './utils';
|
|
4
|
-
import { ChartTooltipContainer, ChartTooltipItem, ChartTooltipHeader, ChartTooltipItemsContainer, } from '../charttooltip/ChartTooltip';
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
2
|
import { LegendShape } from '../chartlegend/ChartLegend';
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { ChartTooltipPortal, ChartTooltipHeader, ChartTooltipItem, ChartTooltipItemsContainer, TooltipHeader, } from '../charttooltip/ChartTooltip';
|
|
4
|
+
import { getCurrentPoint } from './utils';
|
|
5
|
+
export const BarchartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, chartContainerRef, }) => {
|
|
6
|
+
const { active, coordinate } = tooltipProps;
|
|
8
7
|
if (!active) {
|
|
9
8
|
return null;
|
|
10
9
|
}
|
|
11
10
|
const currentPoint = getCurrentPoint(tooltipProps, hoveredValue);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
? 'day-month-abbreviated-hour-minute-second'
|
|
17
|
-
: 'long-date-without-weekday', value: new Date(currentPoint.category) })) : (currentPoint.category) }), _jsx(ChartTooltipItemsContainer, { children: currentPoint.values.map((value) => {
|
|
11
|
+
const duration = type.type === 'time'
|
|
12
|
+
? type.timeRange.startDate.getTime() - type.timeRange.endDate.getTime()
|
|
13
|
+
: 0;
|
|
14
|
+
const tooltipContent = tooltip ? (tooltip(currentPoint)) : (_jsxs(_Fragment, { children: [_jsx(ChartTooltipHeader, { children: type.type === 'time' ? (_jsx(TooltipHeader, { duration: duration, value: currentPoint.category })) : (currentPoint.category) }), _jsx(ChartTooltipItemsContainer, { children: currentPoint.values.map((value) => {
|
|
18
15
|
const legendIcon = colorSet && (_jsx(LegendShape, { color: colorSet[value.label], shape: "rectangle", chartColors: colorSet }));
|
|
19
16
|
const formattedValue = Number.isInteger(value.value)
|
|
20
17
|
? `${value.value}`
|
|
@@ -24,4 +21,5 @@ export const BarchartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, to
|
|
|
24
21
|
: formattedValue;
|
|
25
22
|
return (_jsx(ChartTooltipItem, { label: value.label, value: valueWithUnit, isHovered: value.isHovered, legendIcon: legendIcon }, value.label));
|
|
26
23
|
}) })] }));
|
|
24
|
+
return (_jsx(ChartTooltipPortal, { coordinate: coordinate, chartContainerRef: chartContainerRef, isVisible: active, children: tooltipContent }));
|
|
27
25
|
};
|
|
@@ -2,6 +2,7 @@ import { BarchartProps, BarchartBars } from './Barchart.component';
|
|
|
2
2
|
import { TooltipContentProps } from 'recharts';
|
|
3
3
|
import { ChartColors } from '../../style/theme';
|
|
4
4
|
export declare const getRoundReferenceValue: (value: number) => number;
|
|
5
|
+
export declare const getTicks: (topValue: number, isSymmetrical: boolean) => number[];
|
|
5
6
|
export declare const getMaxBarValue: (data: {
|
|
6
7
|
[key: string]: string | number;
|
|
7
8
|
}[], stacked?: boolean) => number;
|
|
@@ -53,6 +54,10 @@ export type UnitRange = {
|
|
|
53
54
|
label: string;
|
|
54
55
|
}[];
|
|
55
56
|
export declare const computeUnitLabelAndRoundReferenceValue: (data: any, maxValue: number, unitRange: UnitRange | undefined) => {
|
|
57
|
+
unitLabel: undefined;
|
|
58
|
+
roundReferenceValue: number;
|
|
59
|
+
rechartsData: any;
|
|
60
|
+
} | {
|
|
56
61
|
unitLabel: string;
|
|
57
62
|
roundReferenceValue: number;
|
|
58
63
|
rechartsData: any;
|
|
@@ -110,7 +115,7 @@ export declare const useChartData: <T extends BarchartBars>(bars: T, type: Barch
|
|
|
110
115
|
fill: string;
|
|
111
116
|
stackId?: string;
|
|
112
117
|
}[];
|
|
113
|
-
unitLabel: string;
|
|
118
|
+
unitLabel: string | undefined;
|
|
114
119
|
roundReferenceValue: number;
|
|
115
120
|
rechartsData: any;
|
|
116
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG7D,eAAO,MAAM,sBAA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C,CAAC,MAAM,CAAC,YACpB,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,YACpC,OAAO,gBACH,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,cACjC,SAAS,mBACJ,SAAS,GAAG,QAAQ;;iBApCZ,MAAM;cAAQ,MAAM;kBAAY,MAAM;;;;;CAuEhE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,YAAY,SAC7C,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,gBAC5B,MAAM,GAAG,SAAS;cAeX,MAAM,GAAG,MAAM;;eAV3B,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;eAClB,MAAM;mBACF,OAAO;;CAWrB,CAAC"}
|
|
@@ -2,23 +2,49 @@ import { chartColors } from '../../style/theme';
|
|
|
2
2
|
import { useChartLegend } from '../chartlegend/ChartLegendWrapper';
|
|
3
3
|
export const getRoundReferenceValue = (value) => {
|
|
4
4
|
if (value <= 0)
|
|
5
|
-
return
|
|
5
|
+
return 1; // Default for zero or negative values
|
|
6
6
|
// Get the magnitude (10^n where n is the number of digits - 1)
|
|
7
7
|
const magnitude = Math.pow(10, Math.floor(Math.log10(value)));
|
|
8
|
+
// Buffer the value by 10% to avoid being too close to the edge of the chart
|
|
9
|
+
const bufferedValue = value * 1.1;
|
|
8
10
|
// Normalized value between 1 and 10
|
|
9
|
-
const normalized =
|
|
11
|
+
const normalized = bufferedValue / magnitude;
|
|
10
12
|
// Round to nice numbers based on normalized value
|
|
13
|
+
// skip 1.5, 3, 4, 7.5 as top value for better chart
|
|
14
|
+
// appearance for small values
|
|
11
15
|
let result;
|
|
12
16
|
if (normalized <= 1)
|
|
13
17
|
result = magnitude;
|
|
14
|
-
else if (normalized <= 2
|
|
15
|
-
result = 2
|
|
18
|
+
else if (normalized <= 2)
|
|
19
|
+
result = 2 * magnitude;
|
|
20
|
+
else if (value > 10 && normalized <= 4)
|
|
21
|
+
result = 4 * magnitude;
|
|
16
22
|
else if (normalized <= 5)
|
|
17
23
|
result = 5 * magnitude;
|
|
24
|
+
else if (value > 10 && normalized <= 7.5)
|
|
25
|
+
result = 7.5 * magnitude;
|
|
18
26
|
else
|
|
19
27
|
result = 10 * magnitude;
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
export const getTicks = (topValue, isSymmetrical) => {
|
|
31
|
+
if (topValue < 10) {
|
|
32
|
+
if (isSymmetrical) {
|
|
33
|
+
return [-topValue, 0, topValue];
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return [0, topValue];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const numberOfTicks = topValue % 3 === 0 ? 4 : 3;
|
|
40
|
+
const tickInterval = topValue / (numberOfTicks - 1);
|
|
41
|
+
const ticks = Array.from({ length: numberOfTicks }, (_, index) => index * tickInterval);
|
|
42
|
+
if (isSymmetrical) {
|
|
43
|
+
// Create negative ticks in order without 0
|
|
44
|
+
const negativeTicks = Array.from({ length: numberOfTicks - 1 }, (_, index) => -(numberOfTicks - 1 - index) * tickInterval);
|
|
45
|
+
ticks.unshift(...negativeTicks);
|
|
46
|
+
}
|
|
47
|
+
return ticks;
|
|
22
48
|
};
|
|
23
49
|
export const getMaxBarValue = (data, stacked) => {
|
|
24
50
|
const values = data.map((item) => {
|
|
@@ -189,10 +215,10 @@ export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet,
|
|
|
189
215
|
export const computeUnitLabelAndRoundReferenceValue = (data, maxValue, unitRange) => {
|
|
190
216
|
if (!unitRange) {
|
|
191
217
|
const roundReferenceValue = getRoundReferenceValue(maxValue);
|
|
192
|
-
return { unitLabel:
|
|
218
|
+
return { unitLabel: undefined, roundReferenceValue, rechartsData: data };
|
|
193
219
|
}
|
|
194
220
|
const { valueBase, unitLabel } = getUnitLabel(unitRange, maxValue);
|
|
195
|
-
const topValue =
|
|
221
|
+
const topValue = maxValue / valueBase;
|
|
196
222
|
const roundReferenceValue = getRoundReferenceValue(topValue);
|
|
197
223
|
const rechartsData = data.map((dataPoint) => {
|
|
198
224
|
const normalizedDataPoint = { ...dataPoint };
|
|
@@ -64,7 +64,7 @@ export const ChartLegendWrapper = ({ children, colorSet, }) => {
|
|
|
64
64
|
return color;
|
|
65
65
|
}, [internalColorSet]);
|
|
66
66
|
const listResources = useCallback(() => {
|
|
67
|
-
return Object.keys(internalColorSet);
|
|
67
|
+
return Object.keys(internalColorSet).sort();
|
|
68
68
|
}, [internalColorSet]);
|
|
69
69
|
const chartLegendState = useMemo(() => ({
|
|
70
70
|
selectedResources,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Middleware } from '@floating-ui/react';
|
|
2
3
|
export declare const ChartTooltipContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
3
4
|
interface ChartTooltipItemProps {
|
|
4
5
|
label: React.ReactNode;
|
|
@@ -9,5 +10,33 @@ interface ChartTooltipItemProps {
|
|
|
9
10
|
export declare const ChartTooltipItem: React.FC<ChartTooltipItemProps>;
|
|
10
11
|
export declare const ChartTooltipHeader: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
11
12
|
export declare const ChartTooltipItemsContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
13
|
+
export declare const ChartTooltipSeparator: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
14
|
+
export type TooltipDateFormat = 'day-month-abbreviated-year-hour-minute' | 'day-month-abbreviated-hour-minute-second' | 'day-month-abbreviated-hour-minute';
|
|
15
|
+
export declare const TooltipHeader: ({ duration, value, }: {
|
|
16
|
+
duration: number;
|
|
17
|
+
value: string | number;
|
|
18
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export interface ChartTooltipPortalProps {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
coordinate?: {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
};
|
|
25
|
+
chartContainerRef: React.RefObject<HTMLDivElement>;
|
|
26
|
+
isVisible?: boolean;
|
|
27
|
+
middleware?: Middleware[];
|
|
28
|
+
offset?: number | (({ placement }: {
|
|
29
|
+
placement: string;
|
|
30
|
+
}) => number);
|
|
31
|
+
customPosition?: (chartRect: DOMRect, coordinate?: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
}) => {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
};
|
|
38
|
+
containerComponent?: React.ComponentType<any>;
|
|
39
|
+
}
|
|
40
|
+
export declare const ChartTooltipPortal: React.FC<ChartTooltipPortalProps>;
|
|
12
41
|
export {};
|
|
13
42
|
//# sourceMappingURL=ChartTooltip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/charttooltip/ChartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ChartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/charttooltip/ChartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAML,UAAU,EACX,MAAM,oBAAoB,CAAC;AAM5B,eAAO,MAAM,qBAAqB,yGAWjC,CAAC;AA+BF,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAe5D,CAAC;AAEF,eAAO,MAAM,kBAAkB,yGAK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import { useEffect, useState, useRef } from 'react';
|
|
4
|
+
import { useFloating, autoUpdate, offset, flip, shift, } from '@floating-ui/react';
|
|
2
5
|
import styled from 'styled-components';
|
|
3
6
|
import { spacing } from '../../spacing';
|
|
4
7
|
import { fontSize, fontWeight } from '../../style/theme';
|
|
8
|
+
import { FormattedDateTime } from '../date/FormattedDateTime';
|
|
5
9
|
export const ChartTooltipContainer = styled.div `
|
|
6
10
|
border: 1px solid ${({ theme }) => theme.border};
|
|
7
11
|
background-color: ${({ theme }) => theme.backgroundLevel1};
|
|
@@ -10,7 +14,8 @@ export const ChartTooltipContainer = styled.div `
|
|
|
10
14
|
font-size: ${fontSize.small};
|
|
11
15
|
padding: ${spacing.r8};
|
|
12
16
|
min-width: 10rem;
|
|
13
|
-
max-width:
|
|
17
|
+
max-width: 40rem;
|
|
18
|
+
|
|
14
19
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
15
20
|
`;
|
|
16
21
|
const TooltipText = styled.div `
|
|
@@ -47,3 +52,102 @@ export const ChartTooltipItemsContainer = styled.div `
|
|
|
47
52
|
gap: ${spacing.r8};
|
|
48
53
|
width: 100%;
|
|
49
54
|
`;
|
|
55
|
+
export const ChartTooltipSeparator = styled.div `
|
|
56
|
+
height: 1px;
|
|
57
|
+
background-color: ${({ theme }) => theme.border};
|
|
58
|
+
margin: ${spacing.r4} 0;
|
|
59
|
+
width: 100%;
|
|
60
|
+
`;
|
|
61
|
+
const getTooltipDateFormat = (duration) => {
|
|
62
|
+
if (duration <= 60 * 60 * 1000) {
|
|
63
|
+
return 'day-month-abbreviated-hour-minute-second';
|
|
64
|
+
}
|
|
65
|
+
else if (duration <= 7 * 24 * 60 * 60 * 1000) {
|
|
66
|
+
return 'day-month-abbreviated-hour-minute';
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return 'day-month-abbreviated-year-hour-minute';
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const TooltipHeader = ({ duration, value, }) => {
|
|
73
|
+
const timeFormat = getTooltipDateFormat(duration);
|
|
74
|
+
return (_jsx(ChartTooltipHeader, { children: _jsx(FormattedDateTime, { format: timeFormat, value: new Date(value) }) }));
|
|
75
|
+
};
|
|
76
|
+
export const ChartTooltipPortal = ({ children, coordinate, chartContainerRef, isVisible = true, middleware, offset: customOffset, customPosition, containerComponent: ContainerComponent = ChartTooltipContainer, }) => {
|
|
77
|
+
const [virtualElement, setVirtualElement] = useState(null);
|
|
78
|
+
const previousPositionRef = useRef(null);
|
|
79
|
+
const [portalContainer, setPortalContainer] = useState(null);
|
|
80
|
+
// Default middleware configuration
|
|
81
|
+
const defaultMiddleware = [
|
|
82
|
+
offset(customOffset || 20),
|
|
83
|
+
flip(),
|
|
84
|
+
shift({ padding: 10 }),
|
|
85
|
+
];
|
|
86
|
+
const { refs, floatingStyles } = useFloating({
|
|
87
|
+
elements: {
|
|
88
|
+
reference: virtualElement,
|
|
89
|
+
},
|
|
90
|
+
placement: 'top',
|
|
91
|
+
middleware: middleware || defaultMiddleware,
|
|
92
|
+
whileElementsMounted: autoUpdate,
|
|
93
|
+
});
|
|
94
|
+
// Create portal container once
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const container = document.createElement('div');
|
|
97
|
+
document.body.appendChild(container);
|
|
98
|
+
setPortalContainer(container);
|
|
99
|
+
return () => {
|
|
100
|
+
document.body.removeChild(container);
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
103
|
+
// Create virtual element from coordinate or custom position
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (chartContainerRef.current) {
|
|
106
|
+
const chartRect = chartContainerRef.current.getBoundingClientRect();
|
|
107
|
+
let tooltipX;
|
|
108
|
+
let tooltipY;
|
|
109
|
+
if (customPosition) {
|
|
110
|
+
// Use custom positioning function
|
|
111
|
+
const position = customPosition(chartRect, coordinate);
|
|
112
|
+
tooltipX = position.x;
|
|
113
|
+
tooltipY = position.y;
|
|
114
|
+
}
|
|
115
|
+
else if (coordinate) {
|
|
116
|
+
// Use default coordinate-based positioning
|
|
117
|
+
tooltipX = chartRect.left + coordinate.x;
|
|
118
|
+
tooltipY = chartRect.top + coordinate.y;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return; // No positioning method available
|
|
122
|
+
}
|
|
123
|
+
// Check if position has changed significantly
|
|
124
|
+
const hasPositionChanged = !previousPositionRef.current ||
|
|
125
|
+
Math.abs(previousPositionRef.current.x - tooltipX) > 5 ||
|
|
126
|
+
Math.abs(previousPositionRef.current.y - tooltipY) > 5;
|
|
127
|
+
if (hasPositionChanged) {
|
|
128
|
+
previousPositionRef.current = { x: tooltipX, y: tooltipY };
|
|
129
|
+
}
|
|
130
|
+
setVirtualElement({
|
|
131
|
+
getBoundingClientRect() {
|
|
132
|
+
return {
|
|
133
|
+
width: 0,
|
|
134
|
+
height: 0,
|
|
135
|
+
x: tooltipX,
|
|
136
|
+
y: tooltipY,
|
|
137
|
+
left: tooltipX,
|
|
138
|
+
top: tooltipY,
|
|
139
|
+
right: tooltipX,
|
|
140
|
+
bottom: tooltipY,
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}, [coordinate, chartContainerRef, customPosition]);
|
|
146
|
+
if (!isVisible || !virtualElement || !portalContainer)
|
|
147
|
+
return null;
|
|
148
|
+
const tooltipContent = (_jsx(ContainerComponent, { ref: refs.setFloating, style: {
|
|
149
|
+
...floatingStyles,
|
|
150
|
+
opacity: isVisible ? 1 : 0,
|
|
151
|
+
}, children: children }));
|
|
152
|
+
return createPortal(tooltipContent, portalContainer);
|
|
153
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description Long date formatter, with weekday, year, month and day. Used for describing long term date.
|
|
3
|
-
* @example Wednesday
|
|
3
|
+
* @example Wednesday 06 October 2025
|
|
4
4
|
*/
|
|
5
5
|
export declare const LONG_DATE_FORMATER: Intl.DateTimeFormat;
|
|
6
6
|
/**
|
|
@@ -15,7 +15,7 @@ export declare const LONG_DATE_FORMATER_WITHOUT_WEEKDAY: Intl.DateTimeFormat;
|
|
|
15
15
|
export declare const DATE_FORMATER: Intl.DateTimeFormat;
|
|
16
16
|
/**
|
|
17
17
|
* @description Day month formatter, with weekday, day and month. Used for describing long term date.
|
|
18
|
-
* @example Wed
|
|
18
|
+
* @example Wed 06 Oct
|
|
19
19
|
*/
|
|
20
20
|
export declare const DAY_MONTH_FORMATER: Intl.DateTimeFormat;
|
|
21
21
|
/**
|
|
@@ -28,16 +28,31 @@ export declare const TIME_SECOND_FORMATER: Intl.DateTimeFormat;
|
|
|
28
28
|
* @example 18:33
|
|
29
29
|
*/
|
|
30
30
|
export declare const TIME_FORMATER: Intl.DateTimeFormat;
|
|
31
|
+
/**
|
|
32
|
+
* @description Day month abbreviated formatter. Used for describing long term date.
|
|
33
|
+
* @example 06 Oct
|
|
34
|
+
*/
|
|
35
|
+
export declare const DAY_MONTH_ABBREVIATED: Intl.DateTimeFormat;
|
|
36
|
+
/**
|
|
37
|
+
* @description Day month abbreviated formatter. Used for describing long term date.
|
|
38
|
+
* @example 06 Oct 25
|
|
39
|
+
*/
|
|
40
|
+
export declare const DAY_MONTH_ABBREVIATED_YEAR: Intl.DateTimeFormat;
|
|
31
41
|
/**
|
|
32
42
|
* @description Day month abbreviated hour minute second formatter. Used for describing long term date.
|
|
33
|
-
* @example
|
|
43
|
+
* @example 06 Oct 18:33:00
|
|
34
44
|
*/
|
|
35
45
|
export declare const DAY_MONTH_ABBREVIATED_HOUR_MINUTE_SECOND: Intl.DateTimeFormat;
|
|
36
46
|
/**
|
|
37
47
|
* @description Day month abbreviated hour minute formatter. Used for describing long term date.
|
|
38
|
-
* @example
|
|
48
|
+
* @example 06 Oct 18:33
|
|
39
49
|
*/
|
|
40
50
|
export declare const DAY_MONTH_ABBREVIATED_HOUR_MINUTE: Intl.DateTimeFormat;
|
|
51
|
+
/**
|
|
52
|
+
* @description Day month abbreviated year hour minute formatter. Used for describing long term date.
|
|
53
|
+
* @example 06 Oct 2025 18:33
|
|
54
|
+
*/
|
|
55
|
+
export declare const DAY_MONTH_ABBREVIATED_YEAR_HOUR_MINUTE: Intl.DateTimeFormat;
|
|
41
56
|
/**
|
|
42
57
|
* @description Year month day formatter, without time. Used for describing long term date.
|
|
43
58
|
* @example 2025-01-01
|
|
@@ -49,7 +64,7 @@ export declare const YEAR_MONTH_DAY_FORMATTER: Intl.DateTimeFormat;
|
|
|
49
64
|
*/
|
|
50
65
|
export declare const MONTH_DAY_FORMATTER: Intl.DateTimeFormat;
|
|
51
66
|
type FormattedDateTimeProps = {
|
|
52
|
-
format: 'date' | 'date-time' | 'date-time-second' | 'time' | 'time-second' | 'relative' | 'day-month-abbreviated-hour-minute' | 'day-month-abbreviated-hour-minute-second' | 'long-date' | 'long-date-without-weekday' | 'chart-date' | 'year-month-day' | 'month-day';
|
|
67
|
+
format: 'date' | 'date-time' | 'date-time-second' | 'time' | 'time-second' | 'relative' | 'day-month-abbreviated-hour-minute' | 'day-month-abbreviated-hour-minute-second' | 'day-month-abbreviated-year-hour-minute' | 'long-date' | 'long-date-without-weekday' | 'chart-date' | 'year-month-day' | 'month-day' | 'day-month-abbreviated' | 'chart-long-term-date';
|
|
53
68
|
value: Date;
|
|
54
69
|
};
|
|
55
70
|
/**
|
|
@@ -61,10 +76,10 @@ type FormattedDateTimeProps = {
|
|
|
61
76
|
* time: '00:00'
|
|
62
77
|
* 'time-second': '00:00:00'
|
|
63
78
|
* relative: '1 month ago'
|
|
64
|
-
* 'day-month-abbreviated-hour-minute': '
|
|
65
|
-
* 'day-month-abbreviated-hour-minute-second': '
|
|
79
|
+
* 'day-month-abbreviated-hour-minute': '06 Oct 18:33'
|
|
80
|
+
* 'day-month-abbreviated-hour-minute-second': '06 Oct 18:33:00'
|
|
66
81
|
* 'long-date': 'Wednesday 6 October 2025'
|
|
67
|
-
* 'chart-date': '
|
|
82
|
+
* 'chart-date': '06 Oct'
|
|
68
83
|
* 'year-month-day': '2025-10-06'
|
|
69
84
|
*/
|
|
70
85
|
export declare const FormattedDateTime: ({ format, value, }: FormattedDateTimeProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormattedDateTime.d.ts","sourceRoot":"","sources":["../../../src/lib/components/date/FormattedDateTime.tsx"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,qBAK7B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kCAAkC,qBAI7C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,qBAKxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,qBAI7B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,qBAK/B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,qBAIxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,wCAAwC,qBAUpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iCAAiC,qBAM5C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,qBAInC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,qBAG9B,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EACF,MAAM,GACN,WAAW,GACX,kBAAkB,GAClB,MAAM,GACN,aAAa,GACb,UAAU,GACV,mCAAmC,GACnC,0CAA0C,GAC1C,WAAW,GACX,2BAA2B,GAC3B,YAAY,GACZ,gBAAgB,GAChB,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"FormattedDateTime.d.ts","sourceRoot":"","sources":["../../../src/lib/components/date/FormattedDateTime.tsx"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,qBAK7B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kCAAkC,qBAI7C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,qBAKxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,qBAI7B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,qBAK/B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,qBAIxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,qBAIhC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,qBAKrC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,wCAAwC,qBAUpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iCAAiC,qBAM5C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,sCAAsC,qBAUlD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,qBAInC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,qBAG9B,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EACF,MAAM,GACN,WAAW,GACX,kBAAkB,GAClB,MAAM,GACN,aAAa,GACb,UAAU,GACV,mCAAmC,GACnC,0CAA0C,GAC1C,wCAAwC,GACxC,WAAW,GACX,2BAA2B,GAC3B,YAAY,GACZ,gBAAgB,GAChB,WAAW,GACX,uBAAuB,GACvB,sBAAsB,CAAC;IAE3B,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAaF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,uBAG3B,sBAAsB,4CA+JxB,CAAC"}
|