@scality/core-ui 0.161.0 → 0.162.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/README.md +15 -15
- package/dist/components/accordion/Accordion.component.d.ts +0 -1
- package/dist/components/accordion/Accordion.component.d.ts.map +1 -1
- package/dist/components/barchartv2/Barchart.component.d.ts +55 -0
- package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -0
- package/dist/components/barchartv2/Barchart.component.js +76 -0
- package/dist/components/barchartv2/utils.d.ts +95 -0
- package/dist/components/barchartv2/utils.d.ts.map +1 -0
- package/dist/components/barchartv2/utils.js +305 -0
- package/dist/components/buttonv2/Buttonv2.component.d.ts +1 -1
- package/dist/components/buttonv2/Buttonv2.component.d.ts.map +1 -1
- package/dist/components/constrainedtext/Constrainedtext.component.d.ts +2 -1
- package/dist/components/constrainedtext/Constrainedtext.component.d.ts.map +1 -1
- package/dist/components/constrainedtext/Constrainedtext.component.js +5 -4
- package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts +0 -1
- package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts.map +1 -1
- package/dist/components/date/FormattedDateTime.d.ts +1 -0
- package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
- package/dist/components/date/FormattedDateTime.js +5 -0
- package/dist/components/emptytable/Emptytable.component.d.ts +0 -1
- package/dist/components/emptytable/Emptytable.component.d.ts.map +1 -1
- package/dist/components/emptytable/Emptytable.component.js +1 -0
- package/dist/components/error-pages/ErrorPage401.component.d.ts +0 -1
- package/dist/components/error-pages/ErrorPage401.component.d.ts.map +1 -1
- package/dist/components/error-pages/ErrorPage404.component.d.ts +0 -1
- package/dist/components/error-pages/ErrorPage404.component.d.ts.map +1 -1
- package/dist/components/error-pages/ErrorPage500.component.d.ts +0 -1
- package/dist/components/error-pages/ErrorPage500.component.d.ts.map +1 -1
- package/dist/components/error-pages/ErrorPageAuth.component.d.ts.map +1 -1
- package/dist/components/form/Form.component.d.ts +2 -2
- package/dist/components/form/Form.component.d.ts.map +1 -1
- package/dist/components/infomessage/InfoMessage.component.d.ts +0 -1
- package/dist/components/infomessage/InfoMessage.component.d.ts.map +1 -1
- package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.d.ts.map +1 -1
- package/dist/components/layout/Layout.component.d.ts.map +1 -1
- package/dist/components/layout/v2/panels.d.ts.map +1 -1
- package/dist/components/modal/Modal.component.js +2 -2
- package/dist/components/navbar/Navbar.component.js +2 -2
- package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts +0 -1
- package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts.map +1 -1
- package/dist/components/searchinput/SearchInput.component.d.ts +1 -2
- package/dist/components/searchinput/SearchInput.component.d.ts.map +1 -1
- package/dist/components/selectv2/Selectv2.component.d.ts +5 -5
- package/dist/components/selectv2/Selectv2.component.d.ts.map +1 -1
- package/dist/components/statuswrapper/Statuswrapper.component.d.ts +0 -1
- package/dist/components/statuswrapper/Statuswrapper.component.d.ts.map +1 -1
- package/dist/components/tablev2/Search.js +2 -2
- package/dist/components/tablev2/SingleSelectableContent.d.ts +1 -2
- package/dist/components/tablev2/SingleSelectableContent.d.ts.map +1 -1
- package/dist/components/tablev2/TableCommon.d.ts +2 -2
- package/dist/components/tablev2/TableCommon.d.ts.map +1 -1
- package/dist/components/tablev2/TableSync.d.ts +8 -0
- package/dist/components/tablev2/TableSync.d.ts.map +1 -0
- package/dist/components/tablev2/TableSync.js +11 -0
- package/dist/components/tablev2/Tablev2.component.d.ts +2 -1
- package/dist/components/tablev2/Tablev2.component.d.ts.map +1 -1
- package/dist/components/tablev2/Tablev2.component.js +10 -9
- package/dist/components/tabsv2/ScrollButton.d.ts +1 -2
- package/dist/components/tabsv2/ScrollButton.d.ts.map +1 -1
- package/dist/components/tabsv2/ScrollButton.js +2 -2
- package/dist/components/tabsv2/Tabsv2.component.d.ts +2 -2
- package/dist/components/tabsv2/Tabsv2.component.d.ts.map +1 -1
- package/dist/components/tabsv2/Tabsv2.component.js +2 -2
- package/dist/components/text/Text.component.d.ts +0 -1
- package/dist/components/text/Text.component.d.ts.map +1 -1
- package/dist/components/textarea/TextArea.component.d.ts +3 -3
- package/dist/components/textarea/TextArea.component.d.ts.map +1 -1
- package/dist/components/textbadge/TextBadge.component.d.ts +0 -1
- package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
- package/dist/components/toast/Toast.component.d.ts +1 -1
- package/dist/components/toast/Toast.component.d.ts.map +1 -1
- package/dist/components/toast/ToastProvider.d.ts.map +1 -1
- package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +1 -2
- package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +1 -1
- package/dist/components/vegachartv2/VegaChartV2.component.d.ts +1 -2
- package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +1 -1
- package/dist/components/vegachartv2/VegaChartV2.component.js +2 -2
- package/dist/icons/branding.d.ts.map +1 -1
- package/dist/icons/scality-loading.d.ts.map +1 -1
- package/dist/next.d.ts +1 -0
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +1 -0
- package/dist/style/theme.d.ts +19 -0
- package/dist/style/theme.d.ts.map +1 -1
- package/dist/style/theme.js +18 -1
- package/package.json +6 -3
- package/setupTests.js +6 -0
- package/src/lib/components/accordion/Accordion.component.tsx +1 -1
- package/src/lib/components/barchartv2/Barchart.component.test.tsx +383 -0
- package/src/lib/components/barchartv2/Barchart.component.tsx +309 -0
- package/src/lib/components/barchartv2/utils.test.ts +782 -0
- package/src/lib/components/barchartv2/utils.ts +486 -0
- package/src/lib/components/buttonv2/Buttonv2.component.tsx +1 -1
- package/src/lib/components/constrainedtext/Constrainedtext.component.tsx +22 -3
- package/src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx +0 -1
- package/src/lib/components/date/FormattedDateTime.tsx +6 -0
- package/src/lib/components/emptytable/Emptytable.component.tsx +1 -1
- package/src/lib/components/error-pages/ErrorPage401.component.tsx +0 -1
- package/src/lib/components/error-pages/ErrorPage404.component.tsx +0 -1
- package/src/lib/components/error-pages/ErrorPage500.component.tsx +0 -1
- package/src/lib/components/error-pages/ErrorPageAuth.component.tsx +0 -1
- package/src/lib/components/form/Form.component.tsx +1 -1
- package/src/lib/components/infomessage/InfoMessage.component.tsx +0 -1
- package/src/lib/components/lateralnavbarlayout/LateralNavbarLayout.component.tsx +0 -1
- package/src/lib/components/layout/Layout.component.tsx +0 -1
- package/src/lib/components/layout/v2/panels.tsx +1 -1
- package/src/lib/components/modal/Modal.component.tsx +2 -2
- package/src/lib/components/navbar/Navbar.component.tsx +2 -2
- package/src/lib/components/scrollbarwrapper/ScrollbarWrapper.component.tsx +0 -1
- package/src/lib/components/searchinput/SearchInput.component.tsx +0 -1
- package/src/lib/components/selectv2/Selectv2.component.tsx +11 -9
- package/src/lib/components/sidebar/Sidebar.component.tsx +1 -1
- package/src/lib/components/statuswrapper/Statuswrapper.component.tsx +0 -1
- package/src/lib/components/tablev2/Search.tsx +2 -2
- package/src/lib/components/tablev2/SingleSelectableContent.tsx +2 -2
- package/src/lib/components/tablev2/TableCommon.tsx +1 -1
- package/src/lib/components/tablev2/TableSync.test.tsx +31 -0
- package/src/lib/components/tablev2/TableSync.tsx +36 -0
- package/src/lib/components/tablev2/Tablev2.component.tsx +11 -9
- package/src/lib/components/tabsv2/ScrollButton.tsx +2 -2
- package/src/lib/components/tabsv2/Tabsv2.component.tsx +6 -6
- package/src/lib/components/text/Text.component.tsx +4 -5
- package/src/lib/components/textarea/TextArea.component.tsx +3 -2
- package/src/lib/components/textbadge/TextBadge.component.tsx +0 -1
- package/src/lib/components/toast/Toast.component.tsx +1 -1
- package/src/lib/components/toast/ToastProvider.tsx +3 -1
- package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +1 -1
- package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +2 -2
- package/src/lib/icons/branding.tsx +0 -2
- package/src/lib/icons/scality-loading.tsx +0 -2
- package/src/lib/next.ts +5 -0
- package/src/lib/style/theme.ts +24 -1
- package/stories/BarChart/barchart.stories.tsx +655 -0
- package/stories/areachart.stories.tsx +0 -1
- package/stories/tablev2.stories.tsx +41 -0
- package/tsconfig.json +5 -2
package/README.md
CHANGED
|
@@ -8,13 +8,13 @@ Core-UI is a component library containing all components, layouts, icons and the
|
|
|
8
8
|
|
|
9
9
|
#### Manual installation
|
|
10
10
|
|
|
11
|
-
- Add
|
|
11
|
+
- Add `@scality/core-ui` in the `package.json`'s dependencies of your project.
|
|
12
12
|
|
|
13
13
|
```json
|
|
14
14
|
"@scality/core-ui": "0.115.0",
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
-
|
|
17
|
+
- `@scality/core-ui` requires the peerDependencies below. Make sure that you have them in the `package.json`'s dependencies.
|
|
18
18
|
|
|
19
19
|
```json
|
|
20
20
|
"@fortawesome/fontawesome-free": "^5.10.2",
|
|
@@ -53,7 +53,7 @@ npm install
|
|
|
53
53
|
|
|
54
54
|
### Usage
|
|
55
55
|
|
|
56
|
-
- Import a component from
|
|
56
|
+
- Import a component from `@scality/core-ui/dist/next'` or `@scality/core-ui`
|
|
57
57
|
|
|
58
58
|
- Use props to change its appearance and behaviour
|
|
59
59
|
|
|
@@ -61,8 +61,12 @@ npm install
|
|
|
61
61
|
import { Button } from '@scality/core-ui/dist/next';
|
|
62
62
|
import { Icon } from '@scality/core-ui';
|
|
63
63
|
|
|
64
|
-
<Button
|
|
65
|
-
|
|
64
|
+
<Button
|
|
65
|
+
variant="primary"
|
|
66
|
+
onClick={handleClick}
|
|
67
|
+
label="Save"
|
|
68
|
+
icon={<Icon name="Save" />}
|
|
69
|
+
/>;
|
|
66
70
|
```
|
|
67
71
|
|
|
68
72
|
To learn more about the available components, you can read the [documentation](https://scality.github.io/core-ui/)
|
|
@@ -73,17 +77,15 @@ Components are themable by using the [styled-components theming concept](https:/
|
|
|
73
77
|
Wrap your app in a `ThemeProvider` and provide it a theme :
|
|
74
78
|
|
|
75
79
|
```jsx
|
|
76
|
-
|
|
77
80
|
import { ThemeProvider } from 'styled-components';
|
|
78
81
|
import { Layout } from '@scality/core-ui';
|
|
79
82
|
import { coreUIAvailableThemes as themes } from '@scality/core-ui/dist/style/theme';
|
|
80
83
|
|
|
81
84
|
<ThemeProvider theme={themes.darkRebrand}>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</ThemeProvider
|
|
86
|
-
|
|
85
|
+
<Layout sidebar={sidebar} navbar={navbar}>
|
|
86
|
+
...
|
|
87
|
+
</Layout>
|
|
88
|
+
</ThemeProvider>;
|
|
87
89
|
```
|
|
88
90
|
|
|
89
91
|
There is 2 default theme available in Core-UI : you can find them [here](https://github.com/scality/core-ui/pull/684#:~:text=https%3A//github.com/scality/core%2Dui/blob/development/1.0/src/lib/style/theme.ts)
|
|
@@ -93,7 +95,6 @@ There is 2 default theme available in Core-UI : you can find them [here](https:/
|
|
|
93
95
|
You can also modify or create a new theme. In this case make sure to respect this type :
|
|
94
96
|
|
|
95
97
|
```tsx
|
|
96
|
-
|
|
97
98
|
export type CoreUITheme = {
|
|
98
99
|
statusHealthy: string;
|
|
99
100
|
statusHealthyRGB: string;
|
|
@@ -119,7 +120,6 @@ export type CoreUITheme = {
|
|
|
119
120
|
textReverse: string;
|
|
120
121
|
textLink: string;
|
|
121
122
|
};
|
|
122
|
-
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
<br />
|
|
@@ -272,7 +272,7 @@ git push origin <branch-name>
|
|
|
272
272
|
|
|
273
273
|
then create a `Pull Request`.
|
|
274
274
|
Pull request needs to be approved by at least one reviewer.
|
|
275
|
-
After your PR is approved you can comment `/approve`
|
|
275
|
+
After your PR is approved you can comment `/approve`
|
|
276
276
|
|
|
277
277
|
### Release
|
|
278
278
|
|
|
@@ -282,7 +282,7 @@ In the Core-UI repo, follow these steps :
|
|
|
282
282
|
1. Go on `Releases` then `Draft a new release`
|
|
283
283
|
2. In the select menu `Choose a tag` : Create a new tag (the current tag increment by 1).
|
|
284
284
|
3. You can now `Generate release notes` : it will add all the PR infos since the last release. \
|
|
285
|
-
You can add details if necessary.
|
|
285
|
+
You can add details if necessary.
|
|
286
286
|
4. `Publish release`
|
|
287
287
|
5. It will create a PR that need to be approved.
|
|
288
288
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/accordion/Accordion.component.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Accordion.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/accordion/Accordion.component.tsx"],"names":[],"mappings":"AAUA,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAgDF,eAAO,MAAM,SAAS,sDAOnB,cAAc,4CA4DhB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ChartColors } from '../../style/theme';
|
|
2
|
+
import { UnitRange } from './utils';
|
|
3
|
+
export type TimeType = {
|
|
4
|
+
type: 'time';
|
|
5
|
+
timeRange: {
|
|
6
|
+
startDate: Date;
|
|
7
|
+
endDate: Date;
|
|
8
|
+
interval: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type Point = {
|
|
12
|
+
key: string | number;
|
|
13
|
+
values: {
|
|
14
|
+
label: string;
|
|
15
|
+
value: number;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
export type BarchartBars = readonly {
|
|
19
|
+
readonly label: string;
|
|
20
|
+
/**
|
|
21
|
+
* When using a time type, the data should be an array of [Date, value]
|
|
22
|
+
* so use Date instead of timestamp for transformation data in format fn
|
|
23
|
+
*/
|
|
24
|
+
readonly data: readonly (readonly [string | Date, number | string])[];
|
|
25
|
+
}[];
|
|
26
|
+
export type BarchartTooltipFn<T extends BarchartBars> = (currentPoint: {
|
|
27
|
+
category: string | number;
|
|
28
|
+
values: {
|
|
29
|
+
label: T[number]['label'];
|
|
30
|
+
value: number;
|
|
31
|
+
isHovered: boolean;
|
|
32
|
+
}[];
|
|
33
|
+
}) => React.ReactNode;
|
|
34
|
+
export type BarchartSortFn<T extends BarchartBars> = (pointA: Record<T[number]['label'], number> & {
|
|
35
|
+
category: string | number;
|
|
36
|
+
}, pointB: Record<T[number]['label'], number> & {
|
|
37
|
+
category: string | number;
|
|
38
|
+
}) => 1 | -1 | 0;
|
|
39
|
+
export type BarchartProps<T extends BarchartBars> = {
|
|
40
|
+
type: 'category' | TimeType;
|
|
41
|
+
bars: T;
|
|
42
|
+
colorSet: Record<T[number]['label'], ChartColors | (string & {})>;
|
|
43
|
+
tooltip?: BarchartTooltipFn<T>;
|
|
44
|
+
defaultSort?: BarchartSortFn<T>;
|
|
45
|
+
unitRange?: UnitRange;
|
|
46
|
+
helpTooltip?: string;
|
|
47
|
+
stacked?: boolean;
|
|
48
|
+
title?: string;
|
|
49
|
+
secondaryTitle?: string;
|
|
50
|
+
rightTitle?: React.ReactNode;
|
|
51
|
+
height?: number;
|
|
52
|
+
isLoading?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export declare const Barchart: <T extends BarchartBars>(props: BarchartProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
55
|
+
//# sourceMappingURL=Barchart.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAe,WAAW,EAAY,MAAM,mBAAmB,CAAC;AAMvE,OAAO,EAAwB,SAAS,EAAgB,MAAM,SAAS,CAAC;AAiBxE,MAAM,MAAM,QAAQ,GA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AAA;CAAE,KACvE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAEhB,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,YAAY,IAAI;IAClD,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAiHF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,SAAS,aAAa,CAAC,CAAC,CAAC,4CAgHvE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Bar, BarChart, CartesianGrid, ReferenceLine, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
|
|
4
|
+
import styled, { useTheme } from 'styled-components';
|
|
5
|
+
import { spacing, Stack, Wrap } from '../../spacing';
|
|
6
|
+
import { chartColors, fontSize } from '../../style/theme';
|
|
7
|
+
import { Box } from '../box/Box';
|
|
8
|
+
import { ConstrainedText } from '../constrainedtext/Constrainedtext.component';
|
|
9
|
+
import { IconHelp } from '../iconhelper/IconHelper';
|
|
10
|
+
import { Loader } from '../loader/Loader.component';
|
|
11
|
+
import { Text } from '../text/Text.component';
|
|
12
|
+
import { renderTooltipContent, useChartData } from './utils';
|
|
13
|
+
const CHART_CONSTANTS = {
|
|
14
|
+
TICK_WIDTH_OFFSET: 5,
|
|
15
|
+
BAR_SIZE: 12,
|
|
16
|
+
MIN_POINT_SIZE: 1,
|
|
17
|
+
DEFAULT_HEIGHT: 200,
|
|
18
|
+
CHART_MARGIN: {
|
|
19
|
+
left: 0,
|
|
20
|
+
right: 0,
|
|
21
|
+
top: 0,
|
|
22
|
+
bottom: 0,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/* ---------------------------------- COMPONENTS ---------------------------------- */
|
|
26
|
+
const CustomTick = ({ x, y, payload, visibleTicksCount, width, }) => {
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const tickWidth = width / visibleTicksCount - CHART_CONSTANTS.TICK_WIDTH_OFFSET;
|
|
29
|
+
const centerX = x - tickWidth / 2;
|
|
30
|
+
return (_jsx("foreignObject", { x: centerX, y: y, width: tickWidth, color: theme.textSecondary, overflow: "visible", children: _jsx(ConstrainedText, { text: _jsx(Text, { variant: "Smaller", color: "textSecondary", children: String(payload.value) }), centered: true, tooltipStyle: {
|
|
31
|
+
backgroundColor: theme.backgroundLevel1,
|
|
32
|
+
padding: spacing.r10,
|
|
33
|
+
borderRadius: spacing.r8,
|
|
34
|
+
border: `1px solid ${theme.border}`,
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
} }) }));
|
|
37
|
+
};
|
|
38
|
+
const StyledResponsiveContainer = styled(ResponsiveContainer) `
|
|
39
|
+
// Avoid tooltip over constrained text to be cut off
|
|
40
|
+
& .recharts-surface {
|
|
41
|
+
overflow: visible;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
const ChartHeader = ({ title, secondaryTitle, helpTooltip, rightTitle, }) => {
|
|
45
|
+
return (_jsxs(Wrap, { children: [_jsxs(Stack, { gap: "r4", children: [_jsx(Text, { variant: "ChartTitle", children: title }), helpTooltip && (_jsx(IconHelp, { tooltipMessage: helpTooltip, title: helpTooltip })), secondaryTitle && (_jsx(Text, { color: "textSecondary", style: {
|
|
46
|
+
marginLeft: spacing.r8,
|
|
47
|
+
}, children: secondaryTitle }))] }), rightTitle && _jsx(Text, { children: rightTitle })] }));
|
|
48
|
+
};
|
|
49
|
+
const Loading = ({ height }) => {
|
|
50
|
+
return (_jsx(Box, { height: height, style: {
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
justifyContent: 'center',
|
|
53
|
+
display: 'flex',
|
|
54
|
+
}, children: _jsx(Loader, { size: "larger", children: _jsx(Text, { children: "Loading Chart Data..." }) }) }));
|
|
55
|
+
};
|
|
56
|
+
/* ---------------------------------- MAIN COMPONENT ---------------------------------- */
|
|
57
|
+
export const Barchart = (props) => {
|
|
58
|
+
const theme = useTheme();
|
|
59
|
+
const [hoveredValue, setHoveredValue] = useState();
|
|
60
|
+
const { height = CHART_CONSTANTS.DEFAULT_HEIGHT, bars, type = 'category', colorSet, unitRange, stacked, defaultSort, tooltip, title, secondaryTitle, helpTooltip, rightTitle, isLoading, } = props;
|
|
61
|
+
const { rechartsBars, unitLabel, roundReferenceValue, rechartsData } = useChartData(bars, type, colorSet, stacked, defaultSort, unitRange);
|
|
62
|
+
return (_jsxs(Stack, { direction: "vertical", gap: "r8", children: [_jsx(ChartHeader, { title: title, secondaryTitle: secondaryTitle, helpTooltip: helpTooltip, rightTitle: rightTitle }), isLoading ? (_jsx(Loading, { height: height })) : (_jsx(StyledResponsiveContainer, { width: "100%", height: height, children: _jsxs(BarChart, { data: rechartsData, accessibilityLayer: true, barSize: CHART_CONSTANTS.BAR_SIZE, height: height, margin: CHART_CONSTANTS.CHART_MARGIN, children: [_jsx(CartesianGrid, { vertical: false, horizontal: false, fill: theme.backgroundLevel1 }), rechartsBars.map((bar) => {
|
|
63
|
+
const { fill, dataKey, stackId } = bar;
|
|
64
|
+
return (_jsx(Bar, { dataKey: dataKey, fill: chartColors[fill] || fill, minPointSize: CHART_CONSTANTS.MIN_POINT_SIZE, stackId: stackId, onMouseOver: () => setHoveredValue(dataKey), onMouseLeave: () => setHoveredValue(undefined) }, dataKey));
|
|
65
|
+
}), _jsx(YAxis, { tickCount: 1, unit: ` ${unitLabel}`, domain: [0, roundReferenceValue], tickFormatter: (value) => new Intl.NumberFormat('fr-FR').format(value.toFixed(0)) // Add a space as thousand separator
|
|
66
|
+
, axisLine: false, tick: {
|
|
67
|
+
fill: theme.textSecondary,
|
|
68
|
+
fontSize: fontSize.smaller,
|
|
69
|
+
}, tickLine: false, label: {
|
|
70
|
+
fill: theme.textSecondary,
|
|
71
|
+
}, orientation: "right" }), _jsx(ReferenceLine, { y: roundReferenceValue, fill: theme.border, strokeWidth: 0.5 }), _jsx(XAxis, { dataKey: "category", tick: (props) => _jsx(CustomTick, { ...props }), type: "category", interval: 0, allowDataOverflow: true, tickLine: {
|
|
72
|
+
stroke: theme.textSecondary,
|
|
73
|
+
}, axisLine: {
|
|
74
|
+
stroke: theme.textSecondary,
|
|
75
|
+
} }), _jsx(Tooltip, { content: (props) => renderTooltipContent(props, tooltip, hoveredValue), cursor: false })] }) }))] }));
|
|
76
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { BarchartProps, BarchartBars, BarchartTooltipFn } from './Barchart.component';
|
|
2
|
+
import { TooltipContentProps } from 'recharts';
|
|
3
|
+
import { ChartColors } from '../../style/theme';
|
|
4
|
+
export declare const getRoundReferenceValue: (value: number) => number;
|
|
5
|
+
export declare const getMaxBarValue: (data: {
|
|
6
|
+
[key: string]: string | number;
|
|
7
|
+
}[], stacked?: boolean) => number;
|
|
8
|
+
/**
|
|
9
|
+
* Transforms time-based data into chart format
|
|
10
|
+
*/
|
|
11
|
+
export declare const transformTimeData: <T extends BarchartBars>(bars: T, type: {
|
|
12
|
+
type: "time";
|
|
13
|
+
timeRange: {
|
|
14
|
+
startDate: Date;
|
|
15
|
+
endDate: Date;
|
|
16
|
+
interval: number;
|
|
17
|
+
};
|
|
18
|
+
}, barDataKeys: string[]) => {
|
|
19
|
+
[key: string]: string | number;
|
|
20
|
+
}[];
|
|
21
|
+
/**
|
|
22
|
+
* Transforms category-based data into chart format
|
|
23
|
+
*/
|
|
24
|
+
export declare const transformCategoryData: <T extends BarchartBars>(bars: T, barDataKeys: string[]) => {
|
|
25
|
+
[key: string]: string | number;
|
|
26
|
+
}[];
|
|
27
|
+
/**
|
|
28
|
+
* Applies custom sorting to chart data
|
|
29
|
+
*/
|
|
30
|
+
export declare const applySortingToData: <T extends BarchartBars>(data: {
|
|
31
|
+
[key: string]: string | number;
|
|
32
|
+
}[], barDataKeys: string[], defaultSort: BarchartProps<T>["defaultSort"]) => {
|
|
33
|
+
[key: string]: string | number;
|
|
34
|
+
}[];
|
|
35
|
+
/**
|
|
36
|
+
* Converts prometheus data to recharts data format
|
|
37
|
+
* @param bars - The bars to convert
|
|
38
|
+
* @param type - The chart type (category or time)
|
|
39
|
+
* @returns Recharts data format
|
|
40
|
+
*/
|
|
41
|
+
export declare const formatPrometheusDataToRechartsDataAndBars: <T extends BarchartBars>(bars: T, type: BarchartProps<T>["type"], colorSet: Record<T[number]["label"], ChartColors | (string & {})>, stacked?: boolean, defaultSort?: BarchartProps<T>["defaultSort"]) => {
|
|
42
|
+
data: {
|
|
43
|
+
[key: string]: string | number;
|
|
44
|
+
}[];
|
|
45
|
+
rechartsBars: {
|
|
46
|
+
dataKey: string;
|
|
47
|
+
fill: string;
|
|
48
|
+
stackId?: string;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
export type UnitRange = {
|
|
52
|
+
threshold: number;
|
|
53
|
+
label: string;
|
|
54
|
+
}[];
|
|
55
|
+
export declare const computeUnitLabelAndRoundReferenceValue: (data: any, maxValue: number, unitRange: UnitRange | undefined) => {
|
|
56
|
+
unitLabel: string;
|
|
57
|
+
roundReferenceValue: number;
|
|
58
|
+
rechartsData: any;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Return the unit label base on the current dataset, and the valueBase which is used to convert the data
|
|
62
|
+
* @param {any} unitRange
|
|
63
|
+
* @param {any} maxValue the maximum value among the data set
|
|
64
|
+
* @returns {any}
|
|
65
|
+
*/
|
|
66
|
+
export declare function getUnitLabel(unitRange: {
|
|
67
|
+
threshold: number;
|
|
68
|
+
label: string;
|
|
69
|
+
}[], maxValue: number): {
|
|
70
|
+
valueBase: number;
|
|
71
|
+
unitLabel: string;
|
|
72
|
+
};
|
|
73
|
+
export declare const sortStackedBars: (rechartsBars: {
|
|
74
|
+
dataKey: string;
|
|
75
|
+
fill: string;
|
|
76
|
+
stackId?: string;
|
|
77
|
+
}[], data: {
|
|
78
|
+
[key: string]: string | number;
|
|
79
|
+
}[], stacked?: boolean) => {
|
|
80
|
+
dataKey: string;
|
|
81
|
+
fill: string;
|
|
82
|
+
stackId?: string;
|
|
83
|
+
}[];
|
|
84
|
+
export declare const renderTooltipContent: <T extends BarchartBars>(props: TooltipContentProps<number, string>, tooltip: BarchartTooltipFn<T> | undefined, hoveredValue: string | undefined) => import("react").ReactNode;
|
|
85
|
+
export declare const useChartData: <T extends BarchartBars>(bars: T, type: BarchartProps<T>["type"], colorSet: Record<T[number]["label"], ChartColors | (string & {})>, stacked?: boolean, defaultSort?: BarchartProps<T>["defaultSort"], unitRange?: UnitRange) => {
|
|
86
|
+
rechartsBars: {
|
|
87
|
+
dataKey: string;
|
|
88
|
+
fill: string;
|
|
89
|
+
stackId?: string;
|
|
90
|
+
}[];
|
|
91
|
+
unitLabel: string;
|
|
92
|
+
roundReferenceValue: number;
|
|
93
|
+
rechartsData: any;
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/utils.ts"],"names":[],"mappings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a,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YACpB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,YACvD,OAAO,gBACH,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,cACjC,SAAS;;iBA7KI,MAAM;cAAQ,MAAM;kBAAY,MAAM;;;;;CAkMhE,CAAC"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { DAY_MONTH_FORMATER, TIME_FORMATER } from '../date/FormattedDateTime';
|
|
2
|
+
import { chartColors } from '../../style/theme';
|
|
3
|
+
export const getRoundReferenceValue = (value) => {
|
|
4
|
+
if (value <= 0)
|
|
5
|
+
return 10; // Default for zero or negative values
|
|
6
|
+
// Get the magnitude (10^n where n is the number of digits - 1)
|
|
7
|
+
const magnitude = Math.pow(10, Math.floor(Math.log10(value)));
|
|
8
|
+
// Normalized value between 1 and 10
|
|
9
|
+
const normalized = value / magnitude;
|
|
10
|
+
// Round to nice numbers based on normalized value
|
|
11
|
+
if (normalized <= 1)
|
|
12
|
+
return magnitude;
|
|
13
|
+
if (normalized <= 2.5)
|
|
14
|
+
return 2.5 * magnitude;
|
|
15
|
+
if (normalized <= 5)
|
|
16
|
+
return 5 * magnitude;
|
|
17
|
+
return 10 * magnitude;
|
|
18
|
+
};
|
|
19
|
+
export const getMaxBarValue = (data, stacked) => {
|
|
20
|
+
const values = data.map((item) => {
|
|
21
|
+
// If stacked, we need to filter out category and sum the values in the same object
|
|
22
|
+
if (stacked) {
|
|
23
|
+
// Get objects keys except category
|
|
24
|
+
const filterOutCategory = Object.keys(item).filter((key) => key !== 'category');
|
|
25
|
+
// Sum the values in the same object (corresponding to one bar) based on the keys
|
|
26
|
+
const sumValues = filterOutCategory.reduce((acc, curr) => {
|
|
27
|
+
return acc + Number(item[curr]);
|
|
28
|
+
}, 0);
|
|
29
|
+
return sumValues;
|
|
30
|
+
}
|
|
31
|
+
//filter out the category key
|
|
32
|
+
const numberValues = Object.keys(item)
|
|
33
|
+
.filter((key) => key !== 'category')
|
|
34
|
+
.map((key) => Number(item[key]));
|
|
35
|
+
// Get the max value among the values in the object (corresponding to one bar)
|
|
36
|
+
return Math.max(...numberValues);
|
|
37
|
+
});
|
|
38
|
+
return Math.max(...values);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Generates time ranges between start and end dates based on the given interval
|
|
42
|
+
* @param startDate - Start date
|
|
43
|
+
* @param endDate - End date
|
|
44
|
+
* @param interval - Interval in milliseconds
|
|
45
|
+
* @returns Array of time ranges with start and end properties as Date objects
|
|
46
|
+
*/
|
|
47
|
+
const generateTimeRanges = (startDate, endDate, interval) => {
|
|
48
|
+
const ranges = [];
|
|
49
|
+
if (!startDate || !endDate || !interval) {
|
|
50
|
+
return ranges;
|
|
51
|
+
}
|
|
52
|
+
let currentDate = new Date(startDate.getTime());
|
|
53
|
+
while (currentDate.getTime() <= endDate.getTime()) {
|
|
54
|
+
const rangeEnd = new Date(currentDate.getTime() + interval);
|
|
55
|
+
ranges.push({
|
|
56
|
+
start: new Date(currentDate.getTime()),
|
|
57
|
+
end: rangeEnd,
|
|
58
|
+
});
|
|
59
|
+
currentDate = new Date(currentDate.getTime() + interval);
|
|
60
|
+
}
|
|
61
|
+
return ranges;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Formats a date based on the interval
|
|
65
|
+
* @param date - Date object
|
|
66
|
+
* @param interval - Interval in milliseconds
|
|
67
|
+
* @returns Formatted string
|
|
68
|
+
*/
|
|
69
|
+
const formatDate = (date, interval) => {
|
|
70
|
+
if (interval > 24 * 60 * 60 * 1000) {
|
|
71
|
+
return (DAY_MONTH_FORMATER.format(date).replace(/[ ,]/g, '') +
|
|
72
|
+
' ' +
|
|
73
|
+
TIME_FORMATER.format(date));
|
|
74
|
+
}
|
|
75
|
+
else if (interval === 24 * 60 * 60 * 1000) {
|
|
76
|
+
// Daily or longer intervals - use day format
|
|
77
|
+
return DAY_MONTH_FORMATER.format(date).replace(/[ ,]/g, '');
|
|
78
|
+
}
|
|
79
|
+
else if (interval >= 60 * 1000) {
|
|
80
|
+
//Handle hourly and minute intervals - use minute format
|
|
81
|
+
return TIME_FORMATER.format(date);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Second intervals or less - use full timestamp
|
|
85
|
+
return date.toISOString();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Finds the time range that contains the given date
|
|
90
|
+
* @param date - Data point date
|
|
91
|
+
* @param ranges - Array of time ranges
|
|
92
|
+
* @returns The range that contains the date, or null if not found
|
|
93
|
+
*/
|
|
94
|
+
const findRangeForDate = (date, ranges) => {
|
|
95
|
+
const timestamp = date.getTime();
|
|
96
|
+
return (ranges.find((range) => timestamp >= range.start.getTime() && timestamp < range.end.getTime()) || null);
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Transforms time-based data into chart format
|
|
100
|
+
*/
|
|
101
|
+
export const transformTimeData = (bars, type, barDataKeys) => {
|
|
102
|
+
const timeRanges = generateTimeRanges(type.timeRange.startDate, type.timeRange.endDate, type.timeRange.interval);
|
|
103
|
+
const categoryMap = new Map();
|
|
104
|
+
// Initialize all ranges with zeros
|
|
105
|
+
timeRanges.forEach((range) => {
|
|
106
|
+
const categoryDisplay = formatDate(range.start, type.timeRange.interval);
|
|
107
|
+
const initialData = {
|
|
108
|
+
category: categoryDisplay,
|
|
109
|
+
};
|
|
110
|
+
barDataKeys.forEach((dataKey) => {
|
|
111
|
+
initialData[dataKey] = 0;
|
|
112
|
+
});
|
|
113
|
+
categoryMap.set(range.start.getTime(), initialData);
|
|
114
|
+
});
|
|
115
|
+
// Populate with actual data
|
|
116
|
+
bars.forEach((bar) => {
|
|
117
|
+
bar.data.forEach(([dateValue, value]) => {
|
|
118
|
+
// Convert to Date if it's not already a Date object
|
|
119
|
+
const date = dateValue instanceof Date
|
|
120
|
+
? dateValue
|
|
121
|
+
: new Date(dateValue);
|
|
122
|
+
const range = findRangeForDate(date, timeRanges);
|
|
123
|
+
if (range) {
|
|
124
|
+
const existingData = categoryMap.get(range.start.getTime());
|
|
125
|
+
existingData[bar.label] = value;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
return Array.from(categoryMap.values());
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Transforms category-based data into chart format
|
|
133
|
+
*/
|
|
134
|
+
export const transformCategoryData = (bars, barDataKeys) => {
|
|
135
|
+
const categoryMap = new Map();
|
|
136
|
+
bars.forEach((bar) => {
|
|
137
|
+
bar.data.forEach(([key, value]) => {
|
|
138
|
+
const categoryKey = String(key);
|
|
139
|
+
if (!categoryMap.has(categoryKey)) {
|
|
140
|
+
const newData = {
|
|
141
|
+
category: categoryKey,
|
|
142
|
+
};
|
|
143
|
+
barDataKeys.forEach((dataKey) => {
|
|
144
|
+
newData[dataKey] = 0;
|
|
145
|
+
});
|
|
146
|
+
categoryMap.set(categoryKey, newData);
|
|
147
|
+
}
|
|
148
|
+
const existingData = categoryMap.get(categoryKey);
|
|
149
|
+
existingData[bar.label] = value;
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
return Array.from(categoryMap.values());
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Applies custom sorting to chart data
|
|
156
|
+
*/
|
|
157
|
+
export const applySortingToData = (data, barDataKeys, defaultSort) => {
|
|
158
|
+
const points = data.map((item) => {
|
|
159
|
+
const point = { category: item.category };
|
|
160
|
+
barDataKeys.forEach((dataKey) => {
|
|
161
|
+
point[dataKey] = Number(item[dataKey]) || 0;
|
|
162
|
+
});
|
|
163
|
+
return point;
|
|
164
|
+
});
|
|
165
|
+
points.sort(defaultSort);
|
|
166
|
+
return points.map((point) => {
|
|
167
|
+
const dataItem = {
|
|
168
|
+
category: point.category,
|
|
169
|
+
};
|
|
170
|
+
barDataKeys.forEach((dataKey) => {
|
|
171
|
+
dataItem[dataKey] = point[dataKey];
|
|
172
|
+
});
|
|
173
|
+
return dataItem;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const getRechartsBarsAndBarDataKeys = (bars, colorSet, stacked) => {
|
|
177
|
+
const rechartsBars = [];
|
|
178
|
+
const barDataKeys = [];
|
|
179
|
+
bars.forEach((bar) => {
|
|
180
|
+
const colorName = colorSet[bar.label];
|
|
181
|
+
const rechartsBar = {
|
|
182
|
+
dataKey: bar.label,
|
|
183
|
+
fill: chartColors[colorName] || colorName,
|
|
184
|
+
stackId: stacked ? 'stacked' : undefined,
|
|
185
|
+
};
|
|
186
|
+
rechartsBars.push(rechartsBar);
|
|
187
|
+
barDataKeys.push(bar.label);
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
rechartsBars,
|
|
191
|
+
barDataKeys,
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Converts prometheus data to recharts data format
|
|
196
|
+
* @param bars - The bars to convert
|
|
197
|
+
* @param type - The chart type (category or time)
|
|
198
|
+
* @returns Recharts data format
|
|
199
|
+
*/
|
|
200
|
+
export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet, stacked, defaultSort) => {
|
|
201
|
+
const { rechartsBars, barDataKeys } = getRechartsBarsAndBarDataKeys(bars, colorSet, stacked);
|
|
202
|
+
let data = type !== 'category' && type.type === 'time'
|
|
203
|
+
? transformTimeData(bars, type, barDataKeys)
|
|
204
|
+
: transformCategoryData(bars, barDataKeys);
|
|
205
|
+
if (type === 'category' && defaultSort) {
|
|
206
|
+
data = applySortingToData(data, barDataKeys, defaultSort);
|
|
207
|
+
}
|
|
208
|
+
const sortedRechartsBars = sortStackedBars(rechartsBars, data, stacked);
|
|
209
|
+
return {
|
|
210
|
+
rechartsBars: sortedRechartsBars,
|
|
211
|
+
data,
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
export const computeUnitLabelAndRoundReferenceValue = (data, maxValue, unitRange) => {
|
|
215
|
+
if (!unitRange) {
|
|
216
|
+
const roundReferenceValue = getRoundReferenceValue(maxValue);
|
|
217
|
+
return { unitLabel: '', roundReferenceValue, rechartsData: data };
|
|
218
|
+
}
|
|
219
|
+
const { valueBase, unitLabel } = getUnitLabel(unitRange !== null && unitRange !== void 0 ? unitRange : [], maxValue);
|
|
220
|
+
const topValue = Math.ceil(maxValue / valueBase / 10) * 10;
|
|
221
|
+
const roundReferenceValue = getRoundReferenceValue(topValue);
|
|
222
|
+
const rechartsData = data.map((dataPoint) => {
|
|
223
|
+
const normalizedDataPoint = { ...dataPoint };
|
|
224
|
+
Object.entries(dataPoint).forEach(([key, value]) => {
|
|
225
|
+
if (key !== 'category' && typeof value === 'number') {
|
|
226
|
+
normalizedDataPoint[key] = value / valueBase;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return normalizedDataPoint;
|
|
230
|
+
});
|
|
231
|
+
return { unitLabel, roundReferenceValue, rechartsData };
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Return the unit label base on the current dataset, and the valueBase which is used to convert the data
|
|
235
|
+
* @param {any} unitRange
|
|
236
|
+
* @param {any} maxValue the maximum value among the data set
|
|
237
|
+
* @returns {any}
|
|
238
|
+
*/
|
|
239
|
+
export function getUnitLabel(unitRange, maxValue) {
|
|
240
|
+
// first sort the unitRange
|
|
241
|
+
unitRange.sort((unitA, unitB) => {
|
|
242
|
+
return unitA.threshold - unitB.threshold;
|
|
243
|
+
});
|
|
244
|
+
let index = unitRange.findIndex((range) => range.threshold > maxValue);
|
|
245
|
+
// last unit
|
|
246
|
+
if (index === -1) {
|
|
247
|
+
index = unitRange.length;
|
|
248
|
+
}
|
|
249
|
+
if (index === 0) {
|
|
250
|
+
return {
|
|
251
|
+
valueBase: unitRange[index].threshold,
|
|
252
|
+
unitLabel: unitRange[index].label,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
// if the threshold is 0, we use 1 as the value base to avoid division by 0
|
|
257
|
+
valueBase: unitRange[index - 1].threshold || 1,
|
|
258
|
+
unitLabel: unitRange[index - 1].label,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
// Sort stacked bars by their average values in descending order
|
|
262
|
+
// This ensures the largest bars appear at the bottom of the stack
|
|
263
|
+
export const sortStackedBars = (rechartsBars, data, stacked) => {
|
|
264
|
+
if (!stacked) {
|
|
265
|
+
return rechartsBars;
|
|
266
|
+
}
|
|
267
|
+
const barAverages = rechartsBars.map((bar) => {
|
|
268
|
+
const values = data
|
|
269
|
+
.map((item) => Number(item[bar.dataKey]) || 0)
|
|
270
|
+
.filter((value) => !isNaN(value));
|
|
271
|
+
const average = values.length > 0 ? values.reduce((a, b) => a + b, 0) / values.length : 0;
|
|
272
|
+
return { ...bar, average };
|
|
273
|
+
});
|
|
274
|
+
// Sort by average in descending order (largest first, which will be at bottom in stack)
|
|
275
|
+
barAverages.sort((a, b) => b.average - a.average);
|
|
276
|
+
// Remove the average property and keep only the bar data
|
|
277
|
+
return barAverages.map(({ average, ...bar }) => bar);
|
|
278
|
+
};
|
|
279
|
+
export const renderTooltipContent = (props, tooltip, hoveredValue) => {
|
|
280
|
+
const { active, payload, label } = props;
|
|
281
|
+
if (!active || !tooltip) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
const tooltipValues = payload.map((item) => ({
|
|
285
|
+
label: item.name,
|
|
286
|
+
value: item.value,
|
|
287
|
+
isHovered: item.name === hoveredValue,
|
|
288
|
+
}));
|
|
289
|
+
const currentPoint = {
|
|
290
|
+
category: label,
|
|
291
|
+
values: tooltipValues,
|
|
292
|
+
};
|
|
293
|
+
return tooltip(currentPoint);
|
|
294
|
+
};
|
|
295
|
+
export const useChartData = (bars, type, colorSet, stacked, defaultSort, unitRange) => {
|
|
296
|
+
const { data, rechartsBars } = formatPrometheusDataToRechartsDataAndBars(bars, type, colorSet, stacked, defaultSort);
|
|
297
|
+
const maxValue = getMaxBarValue(data, stacked);
|
|
298
|
+
const { unitLabel, roundReferenceValue, rechartsData } = computeUnitLabelAndRoundReferenceValue(data, maxValue, unitRange);
|
|
299
|
+
return {
|
|
300
|
+
rechartsBars,
|
|
301
|
+
unitLabel,
|
|
302
|
+
roundReferenceValue,
|
|
303
|
+
rechartsData,
|
|
304
|
+
};
|
|
305
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ButtonHTMLAttributes } from 'react';
|
|
2
2
|
import { Loader } from '../loader/Loader.component';
|
|
3
3
|
import { Props as TooltipProps } from '../tooltip/Tooltip.component';
|
|
4
4
|
export declare const FocusVisibleStyle: import("styled-components").FlattenInterpolation<import("styled-components").ThemeProps<import("styled-components").DefaultTheme>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Buttonv2.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/Buttonv2.component.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Buttonv2.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/Buttonv2.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAI7C,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAW,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE9E,eAAO,MAAM,iBAAiB,oIAI7B,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,IAAI,CACtB,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,MAAM,GAAG,OAAO,CACjB,GAAG;IACF,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,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