@ssa-ui-kit/core 1.1.7 → 1.1.8

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.
Files changed (129) hide show
  1. package/dist/components/Charts/BarLineComplexChart/BarLIneComplexChart.context.d.ts +3 -0
  2. package/dist/components/Charts/BarLineComplexChart/BarLineComplexChart.d.ts +2 -0
  3. package/dist/components/Charts/BarLineComplexChart/BarLineComplexChartInternal.d.ts +2 -0
  4. package/dist/components/Charts/BarLineComplexChart/BarLineComplexChartTooltip.d.ts +2 -0
  5. package/dist/components/Charts/BarLineComplexChart/__mock__/data.d.ts +3 -0
  6. package/dist/components/Charts/BarLineComplexChart/colorPalette.d.ts +1 -0
  7. package/dist/components/Charts/BarLineComplexChart/index.d.ts +1 -0
  8. package/dist/components/Charts/BarLineComplexChart/types.d.ts +28 -0
  9. package/dist/components/Charts/BarLineComplexChart/useChartInfo.d.ts +10 -0
  10. package/dist/components/{PieChart → Charts/PieChart}/PieChartLegendMarker.d.ts +1 -1
  11. package/dist/components/{PieChart → Charts/PieChart}/styles.d.ts +1 -1
  12. package/dist/components/{PieChart → Charts/PieChart}/types.d.ts +1 -1
  13. package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/types.d.ts +3 -3
  14. package/dist/components/Charts/hooks/index.d.ts +1 -0
  15. package/dist/components/Charts/hooks/usePlotlyDefaultConfig.d.ts +10 -0
  16. package/dist/components/Charts/index.d.ts +3 -0
  17. package/dist/components/Input/InputStatusError.d.ts +3 -1
  18. package/dist/components/Input/InputStatusSuccess.d.ts +3 -1
  19. package/dist/components/Input/types.d.ts +2 -0
  20. package/dist/components/Pagination/Pagination.d.ts +1 -1
  21. package/dist/components/Pagination/types.d.ts +2 -0
  22. package/dist/components/Tooltip/types.d.ts +5 -3
  23. package/dist/components/WidgetCard/WidgetCard.d.ts +1 -1
  24. package/dist/components/WidgetCard/WidgetCardBase.d.ts +2 -0
  25. package/dist/components/WidgetCard/WithWidgetCard.d.ts +1 -1
  26. package/dist/components/WidgetCard/types.d.ts +2 -0
  27. package/dist/components/index.d.ts +1 -2
  28. package/dist/contexts/Translation/TranslationContext.d.ts +9 -0
  29. package/dist/contexts/Translation/config.d.ts +3 -0
  30. package/dist/contexts/Translation/index.d.ts +2 -0
  31. package/dist/contexts/Translation/types.d.ts +8 -0
  32. package/dist/contexts/index.d.ts +1 -0
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.js +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/types/json.d.ts +5 -0
  37. package/jest-setup.ts +3 -0
  38. package/package.json +6 -3
  39. package/src/components/Charts/BarLineComplexChart/BarLIneComplexChart.context.tsx +54 -0
  40. package/src/components/Charts/BarLineComplexChart/BarLineComplexChart.stories.tsx +47 -0
  41. package/src/components/Charts/BarLineComplexChart/BarLineComplexChart.tsx +26 -0
  42. package/src/components/Charts/BarLineComplexChart/BarLineComplexChartInternal.tsx +118 -0
  43. package/src/components/Charts/BarLineComplexChart/BarLineComplexChartTooltip.tsx +43 -0
  44. package/src/components/Charts/BarLineComplexChart/__mock__/data.ts +141 -0
  45. package/src/components/Charts/BarLineComplexChart/colorPalette.ts +23 -0
  46. package/src/components/Charts/BarLineComplexChart/index.ts +1 -0
  47. package/src/components/Charts/BarLineComplexChart/types.ts +36 -0
  48. package/src/components/Charts/BarLineComplexChart/useChartInfo.ts +68 -0
  49. package/src/components/{PieChart → Charts/PieChart}/types.ts +1 -1
  50. package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/stories/SegmentedPieChart.stories.tsx +1 -1
  51. package/src/components/Charts/hooks/index.ts +1 -0
  52. package/src/components/Charts/hooks/usePlotlyDefaultConfig.ts +39 -0
  53. package/src/components/Charts/index.ts +3 -0
  54. package/src/components/Input/Input.tsx +8 -2
  55. package/src/components/Input/InputStatusError.tsx +6 -2
  56. package/src/components/Input/InputStatusSuccess.tsx +6 -2
  57. package/src/components/Input/types.ts +2 -0
  58. package/src/components/Pagination/Pagination.stories.tsx +12 -0
  59. package/src/components/Pagination/Pagination.tsx +9 -4
  60. package/src/components/Pagination/components/RowsPerPageDropdown/RowsPerPageDropdown.tsx +1 -1
  61. package/src/components/Pagination/styles.tsx +1 -2
  62. package/src/components/Pagination/types.ts +2 -0
  63. package/src/components/ProgressInfo/ProgressInfo.tsx +1 -1
  64. package/src/components/Tooltip/types.ts +5 -2
  65. package/src/components/Tooltip/useTooltip.tsx +4 -2
  66. package/src/components/WidgetCard/WidgetCard.tsx +5 -1
  67. package/src/components/WidgetCard/WidgetCardBase.tsx +4 -2
  68. package/src/components/WidgetCard/WithWidgetCard.tsx +1 -1
  69. package/src/components/WidgetCard/types.ts +2 -0
  70. package/src/components/index.ts +1 -2
  71. package/src/contexts/Translation/TranslationContext.tsx +53 -0
  72. package/src/contexts/Translation/config.ts +3 -0
  73. package/src/contexts/Translation/index.ts +2 -0
  74. package/src/contexts/Translation/types.ts +9 -0
  75. package/src/contexts/index.ts +1 -0
  76. package/src/index.ts +1 -0
  77. package/src/types/json.ts +7 -0
  78. package/tsbuildcache +1 -1
  79. package/tsconfig.build.json +2 -0
  80. package/tsconfig.json +2 -0
  81. package/webpack.config.js +1 -0
  82. /package/dist/components/{PieChart → Charts/PieChart}/PieChart.d.ts +0 -0
  83. /package/dist/components/{PieChart → Charts/PieChart}/PieChartBases.d.ts +0 -0
  84. /package/dist/components/{PieChart → Charts/PieChart}/PieChartHeader.d.ts +0 -0
  85. /package/dist/components/{PieChart → Charts/PieChart}/PieChartLegend.d.ts +0 -0
  86. /package/dist/components/{PieChart → Charts/PieChart}/PieChartLegendList.d.ts +0 -0
  87. /package/dist/components/{PieChart → Charts/PieChart}/PieChartLegendListItem.d.ts +0 -0
  88. /package/dist/components/{PieChart → Charts/PieChart}/colorPalettes.d.ts +0 -0
  89. /package/dist/components/{PieChart → Charts/PieChart}/index.d.ts +0 -0
  90. /package/dist/components/{PieChart → Charts/PieChart}/stories/fixtures.d.ts +0 -0
  91. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChart.d.ts +0 -0
  92. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChartContext.d.ts +0 -0
  93. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/colorPalettes.d.ts +0 -0
  94. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTitle.d.ts +0 -0
  95. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTooltip.d.ts +0 -0
  96. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/LegendItem.d.ts +0 -0
  97. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/index.d.ts +0 -0
  98. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/index.d.ts +0 -0
  99. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/useData.d.ts +0 -0
  100. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/index.d.ts +0 -0
  101. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/stories/fixtures.d.ts +0 -0
  102. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/utils.d.ts +0 -0
  103. /package/src/components/{PieChart → Charts/PieChart}/PieChart.spec.tsx +0 -0
  104. /package/src/components/{PieChart → Charts/PieChart}/PieChart.stories.tsx +0 -0
  105. /package/src/components/{PieChart → Charts/PieChart}/PieChart.tsx +0 -0
  106. /package/src/components/{PieChart → Charts/PieChart}/PieChartBases.tsx +0 -0
  107. /package/src/components/{PieChart → Charts/PieChart}/PieChartHeader.tsx +0 -0
  108. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegend.tsx +0 -0
  109. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegendList.tsx +0 -0
  110. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegendListItem.tsx +0 -0
  111. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegendMarker.tsx +0 -0
  112. /package/src/components/{PieChart → Charts/PieChart}/colorPalettes.ts +0 -0
  113. /package/src/components/{PieChart → Charts/PieChart}/index.ts +0 -0
  114. /package/src/components/{PieChart → Charts/PieChart}/stories/fixtures.ts +0 -0
  115. /package/src/components/{PieChart → Charts/PieChart}/styles.ts +0 -0
  116. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChart.spec.tsx +0 -0
  117. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChart.tsx +0 -0
  118. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChartContext.tsx +0 -0
  119. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/colorPalettes.ts +0 -0
  120. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTitle.tsx +0 -0
  121. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTooltip.tsx +0 -0
  122. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/LegendItem.tsx +0 -0
  123. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/index.ts +0 -0
  124. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/index.ts +0 -0
  125. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/useData.ts +0 -0
  126. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/index.ts +0 -0
  127. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/stories/fixtures.ts +0 -0
  128. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/types.ts +0 -0
  129. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/utils.ts +0 -0
@@ -0,0 +1,5 @@
1
+ export type JSONValue = string | number | boolean | JSONObject | JSONArray;
2
+ export interface JSONObject {
3
+ [x: string]: JSONValue;
4
+ }
5
+ export type JSONArray = Array<JSONValue>;
package/jest-setup.ts CHANGED
@@ -15,3 +15,6 @@ global.render = customRender;
15
15
 
16
16
  expect.addSnapshotSerializer(createSerializer());
17
17
  expect.extend(matchers);
18
+
19
+ window.URL.createObjectURL = jest.fn();
20
+ window.HTMLCanvasElement.prototype.getContext = jest.fn();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/core",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -27,16 +27,19 @@
27
27
  "dotenv": "^16.0.3",
28
28
  "js-tokens": "^4.0.0",
29
29
  "loose-envify": "^1.4.0",
30
+ "plotly.js": "2.35.2",
31
+ "react-plotly.js": "2.6.0",
30
32
  "scheduler": "^0.23.0",
31
33
  "uuid": "^9.0.0",
32
- "@ssa-ui-kit/hooks": "^1.0.0",
33
- "@ssa-ui-kit/utils": "^1.0.0"
34
+ "@ssa-ui-kit/utils": "^1.0.0",
35
+ "@ssa-ui-kit/hooks": "^1.0.0"
34
36
  },
35
37
  "devDependencies": {
36
38
  "@emotion/jest": "^11.11.0",
37
39
  "@nivo/line": "0.84.0",
38
40
  "@playwright/test": "^1.48.0",
39
41
  "@testing-library/jest-dom": "^5.16.5",
42
+ "@types/react-plotly.js": "2.6.3",
40
43
  "@types/testing-library__jest-dom": "^5.14.6",
41
44
  "@types/uuid": "^9.0.3",
42
45
  "resolve-tspaths": "^0.8.16",
@@ -0,0 +1,54 @@
1
+ import { createContext, useContext, useEffect, useState } from 'react';
2
+ import {
3
+ BarLineComplexChartPContextProps,
4
+ BarLineComplexChartPContextProviderProps,
5
+ ChartItem,
6
+ } from './types';
7
+
8
+ const BarLineComplexChartContext =
9
+ createContext<BarLineComplexChartPContextProps>({
10
+ filteredData: [],
11
+ data: [],
12
+ lineShape: undefined,
13
+ maxVisibleBars: 5,
14
+ maxVisibleLines: 3,
15
+ setFilteredData: () => {
16
+ // no-op
17
+ },
18
+ setData: () => {
19
+ // no-op
20
+ },
21
+ });
22
+
23
+ export const useBarLineComplexChartContext = () =>
24
+ useContext(BarLineComplexChartContext);
25
+
26
+ export const BarLineComplexChartContextProvider = ({
27
+ children,
28
+ lineShape,
29
+ maxVisibleBars,
30
+ maxVisibleLines,
31
+ data: initialData = [],
32
+ }: BarLineComplexChartPContextProviderProps) => {
33
+ const [data, setData] = useState<ChartItem[]>(initialData);
34
+ const [filteredData, setFilteredData] = useState<ChartItem[]>([]);
35
+
36
+ useEffect(() => {
37
+ const filtered = data.filter((item) => item.selected);
38
+ setFilteredData(filtered);
39
+ }, [data]);
40
+ return (
41
+ <BarLineComplexChartContext.Provider
42
+ value={{
43
+ data,
44
+ lineShape,
45
+ maxVisibleBars,
46
+ maxVisibleLines,
47
+ filteredData,
48
+ setData,
49
+ setFilteredData,
50
+ }}>
51
+ {children}
52
+ </BarLineComplexChartContext.Provider>
53
+ );
54
+ };
@@ -0,0 +1,47 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { TranslationProvider } from '@contexts';
3
+ import { BarLineComplexChart } from './BarLineComplexChart';
4
+ import { mockData, mockDataWithDifferentLineType } from './__mock__/data';
5
+ import { BarLineComplexChartProps } from './types';
6
+
7
+ export default {
8
+ title: 'Charts/BarLineComplexChart',
9
+ component: BarLineComplexChart,
10
+ decorators: [
11
+ (Story) => (
12
+ <TranslationProvider>
13
+ <Story />
14
+ </TranslationProvider>
15
+ ),
16
+ ],
17
+ } as Meta<BarLineComplexChartProps>;
18
+
19
+ type Args = StoryObj<Partial<BarLineComplexChartProps>>;
20
+
21
+ export const Default: Args = {
22
+ render: ({ ...args }) => (
23
+ <BarLineComplexChart
24
+ data={mockData}
25
+ width="670px"
26
+ height="220px"
27
+ cardProps={{
28
+ title: 'Bar & Line Complex Chart',
29
+ }}
30
+ {...args}
31
+ />
32
+ ),
33
+ };
34
+
35
+ export const WithSpline: Args = {
36
+ ...Default,
37
+ args: {
38
+ lineShape: 'spline',
39
+ },
40
+ };
41
+
42
+ export const Custom: Args = {
43
+ ...Default,
44
+ args: {
45
+ data: mockDataWithDifferentLineType,
46
+ },
47
+ };
@@ -0,0 +1,26 @@
1
+ import { BarLineComplexChartProps } from './types';
2
+ import { useTooltip } from '@components/Tooltip/useTooltip';
3
+ import { TooltipContext } from '@components/Tooltip/useTooltipContext';
4
+ import { BarLineComplexChartInternal } from './BarLineComplexChartInternal';
5
+ import { BarLineComplexChartContextProvider } from './BarLIneComplexChart.context';
6
+
7
+ export const BarLineComplexChart = ({
8
+ data,
9
+ lineShape = 'linear',
10
+ maxVisibleBars = 5, // need to be implemented
11
+ maxVisibleLines = 3, // need to be implemented
12
+ ...rest
13
+ }: BarLineComplexChartProps) => {
14
+ const tooltip = useTooltip({});
15
+ return (
16
+ <BarLineComplexChartContextProvider
17
+ data={data}
18
+ lineShape={lineShape}
19
+ maxVisibleBars={maxVisibleBars}
20
+ maxVisibleLines={maxVisibleLines}>
21
+ <TooltipContext.Provider value={tooltip}>
22
+ <BarLineComplexChartInternal {...rest} />
23
+ </TooltipContext.Provider>
24
+ </BarLineComplexChartContextProvider>
25
+ );
26
+ };
@@ -0,0 +1,118 @@
1
+ import Plot from 'react-plotly.js';
2
+ import { useTheme } from '@emotion/react';
3
+ import { WithWidgetCard } from '@components/WidgetCard';
4
+ import { BarLineComplexChartProps } from './types';
5
+ import { PieChartHeader } from '../PieChart/PieChartHeader';
6
+ import { usePlotlyDefaultConfig } from '../hooks';
7
+ import { useChartInfo } from './useChartInfo';
8
+ import { BarLineComplexChartTooltip } from './BarLineComplexChartTooltip';
9
+
10
+ export const BarLineComplexChartInternal = ({
11
+ features = ['header'],
12
+ cardProps,
13
+ width = '670px',
14
+ height = '220px',
15
+ ...props
16
+ }: Omit<
17
+ BarLineComplexChartProps,
18
+ 'data' | 'lineShape' | 'maxVisibleBars' | 'maxVisibleLines'
19
+ >) => {
20
+ const theme = useTheme();
21
+ const plotlyDefaultLayoutConfig = usePlotlyDefaultConfig();
22
+ const { transformedChartData, tooltipContentRef } = useChartInfo();
23
+ return (
24
+ <WithWidgetCard
25
+ features={features}
26
+ cardProps={{
27
+ headerContent: <PieChartHeader features={features} />,
28
+ width,
29
+ height,
30
+ ...cardProps,
31
+ }}>
32
+ <Plot
33
+ divId={'bar-line-complex-chart-graph'}
34
+ css={{ width, maxWidth: '100%', height: `calc(${height} - 50px)` }}
35
+ data={transformedChartData}
36
+ layout={{
37
+ margin: {
38
+ b: 0,
39
+ l: 0,
40
+ r: 30,
41
+ t: 20,
42
+ pad: 10,
43
+ },
44
+ barmode: 'group',
45
+ autosize: false,
46
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
47
+ // @ts-ignore
48
+ barcornerradius: 15,
49
+ bargroupgap: 0.2,
50
+ yaxis: {
51
+ showgrid: true,
52
+ rangemode: 'nonnegative',
53
+ zeroline: false,
54
+ },
55
+ yaxis2: {
56
+ showgrid: true,
57
+ overlaying: 'y',
58
+ side: 'right',
59
+ tickfont: {
60
+ color: theme.colors.greyDarker60,
61
+ },
62
+ zeroline: false,
63
+ },
64
+ xaxis: {
65
+ showgrid: true,
66
+ type: 'date',
67
+ hoverformat: '%B',
68
+ tickformat: '%b',
69
+ zeroline: false,
70
+ dtick: 31 * 24 * 60 * 60 * 1000,
71
+ },
72
+ legend: {
73
+ orientation: 'h',
74
+ yanchor: 'top',
75
+ xanchor: 'center',
76
+ valign: 'bottom',
77
+ itemclick: 'toggle',
78
+ bgcolor: 'rgba(255, 255, 255, 0)',
79
+ y: -0.22,
80
+ x: 0.5,
81
+ },
82
+ ...plotlyDefaultLayoutConfig.layout,
83
+ }}
84
+ config={{
85
+ ...plotlyDefaultLayoutConfig.config,
86
+ modeBarButtons: [
87
+ // [
88
+ // {
89
+ // name: 'filtering',
90
+ // icon: {
91
+ // svg: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
92
+ // <path d="M2.73438 2.5C2.605 2.5 2.5 2.605 2.5 2.73438V4.60938C2.5 4.66281 2.51846 4.71461 2.55127 4.75586L8.125 11.723V15.9116C8.125 16.0067 8.182 16.0915 8.26965 16.1276L11.5509 17.4826C11.58 17.4943 11.6106 17.5 11.6406 17.5C11.6866 17.5 11.7313 17.4864 11.7706 17.4606C11.8358 17.417 11.875 17.3439 11.875 17.2656V11.723L17.4487 4.75586C17.4815 4.71461 17.5 4.66281 17.5 4.60938V2.73438C17.5 2.605 17.395 2.5 17.2656 2.5H2.73438ZM2.96875 2.96875H17.0312V4.52698L11.528 11.4062H8.47198L2.96875 4.52698V2.96875ZM8.59375 11.875H11.4062V16.9159L8.59375 15.755V11.875Z" fill="#2B2D31" fill-opacity="0.6"/>
93
+ // <path fill-rule="evenodd" clip-rule="evenodd" d="M2.73438 2.25C2.46693 2.25 2.25 2.46693 2.25 2.73438V4.60938C2.25 4.7201 2.28853 4.82714 2.35605 4.91203L7.875 11.8107V15.6701C7.875 15.6701 7.86214 16.0606 7.91666 16.1667C7.98574 16.3011 8.17447 16.3588 8.17447 16.3588L11.4555 17.7137L11.4574 17.7145C11.5169 17.7385 11.5794 17.75 11.6406 17.75C11.7368 17.75 11.8288 17.7214 11.9076 17.6698L11.9096 17.6684C12.0438 17.5786 12.125 17.4277 12.125 17.2656V11.8107L17.6444 4.91149C17.7119 4.8266 17.75 4.7201 17.75 4.60938V2.73438C17.75 2.46693 17.5331 2.25 17.2656 2.25H2.73438ZM16.7812 3.21875H3.21875V4.43928L8.59214 11.1562H11.4079L16.7812 4.43928V3.21875ZM8.84375 12.125V15.5877L11.1562 16.5422V12.125H8.84375Z" fill="#2B2D31" fill-opacity="0.6"/>
94
+ // </svg>`,
95
+ // },
96
+ // title: 'Filtering',
97
+ // click: handleFilterClick,
98
+ // attr: 'filtering-icon',
99
+ // gravity: '1',
100
+ // },
101
+ // ],
102
+ [
103
+ 'zoom2d',
104
+ 'pan2d',
105
+ 'select2d',
106
+ 'zoomIn2d',
107
+ 'zoomOut2d',
108
+ 'autoScale2d',
109
+ 'resetScale2d',
110
+ ],
111
+ ],
112
+ }}
113
+ {...props}
114
+ />
115
+ <BarLineComplexChartTooltip ref={tooltipContentRef} />
116
+ </WithWidgetCard>
117
+ );
118
+ };
@@ -0,0 +1,43 @@
1
+ import { forwardRef } from 'react';
2
+ import TooltipContent from '@components/TooltipContent';
3
+ import { TooltipContentProps } from '@components/Tooltip/types';
4
+ import Wrapper from '@components/Wrapper';
5
+
6
+ export const BarLineComplexChartTooltip = forwardRef<
7
+ HTMLDivElement,
8
+ Omit<TooltipContentProps, 'children'>
9
+ >(function BarLineComplexChartTooltipContent(props, refProp) {
10
+ return (
11
+ <TooltipContent ref={refProp} {...props}>
12
+ <Wrapper
13
+ css={{
14
+ flexDirection: 'column',
15
+ alignItems: 'flex-start',
16
+ '& label': {
17
+ marginLeft: 0,
18
+ },
19
+ '& input+div': {
20
+ height: 28,
21
+ '&:before': {
22
+ top: 4,
23
+ },
24
+ },
25
+ }}>
26
+ {/* <Checkbox
27
+ key={`bar-line-filter--checkbox-${permission.name}`}
28
+ register={register}
29
+ name={...}
30
+ text={''}
31
+ onChange={...}
32
+ ref={undefined}
33
+ externalState={...}
34
+ css={{
35
+ marginBottom: 0,
36
+ '& input + div': { height: 44, '&:before': { top: 12 } },
37
+ '& input:focus + div': { boxShadow: 'none' },
38
+ }}
39
+ /> */}
40
+ </Wrapper>
41
+ </TooltipContent>
42
+ );
43
+ });
@@ -0,0 +1,141 @@
1
+ import { ChartItem } from '../types';
2
+
3
+ const axisXTimestamps = [
4
+ 1388572800000, 1391260800000, 1393670400000, 1396348800000, 1398940800000,
5
+ 1401619200000, 1404211200000, 1406899200000, 1409577600000, 1412179200000,
6
+ 1414857600000, 1417545600000,
7
+ ];
8
+
9
+ export const mockData: ChartItem[] = [
10
+ {
11
+ x: axisXTimestamps,
12
+ y: [10, 12, 8, 15, 20, 18, 25, 22, 13, 16, 30, 24],
13
+ name: 'Department 1',
14
+ type: 'bar',
15
+ selected: false,
16
+ },
17
+ {
18
+ x: axisXTimestamps,
19
+ y: [7, 5, 12, 11, 5, 6, 19, 11, 9, 10, 17, 18],
20
+ name: 'Department 2',
21
+ type: 'bar',
22
+ selected: true,
23
+ },
24
+ {
25
+ x: axisXTimestamps,
26
+ y: [15, 18, 7, 20, 16, 12, 7, 18, 6, 14, 12, 15],
27
+ name: 'Department 3',
28
+ type: 'bar',
29
+ selected: true,
30
+ },
31
+ {
32
+ x: axisXTimestamps,
33
+ y: [14, 14, 19, 13, 9, 14, 23, 20, 24, 21, 8, 19],
34
+ name: 'Department 4',
35
+ type: 'bar',
36
+ selected: false,
37
+ },
38
+ {
39
+ x: axisXTimestamps,
40
+ y: [3, 8, 9, 6, 4, 11, 10, 8, 16, 7, 11, 9],
41
+ name: 'Department 5',
42
+ type: 'bar',
43
+ selected: true,
44
+ },
45
+ {
46
+ x: axisXTimestamps,
47
+ y: [3, 5, 7, 6, 4, 6, 7, 8, 6, 7, 8, 9],
48
+ name: 'Min',
49
+ type: 'scatter',
50
+ selected: true,
51
+ },
52
+ {
53
+ x: axisXTimestamps,
54
+ y: [9.8, 11.4, 11.0, 13.0, 10.8, 12.2, 16.8, 15.8, 13.6, 13.6, 15.6, 16.2],
55
+ name: 'Average',
56
+ type: 'scatter',
57
+ selected: true,
58
+ },
59
+ {
60
+ x: axisXTimestamps,
61
+ y: [15, 18, 19, 20, 20, 18, 25, 22, 24, 21, 30, 24],
62
+ name: 'Max',
63
+ type: 'scatter',
64
+ line: {
65
+ shape: 'linear',
66
+ },
67
+ selected: false,
68
+ },
69
+ ];
70
+
71
+ export const mockDataWithDifferentLineType: ChartItem[] = [
72
+ {
73
+ x: axisXTimestamps,
74
+ y: [10, 12, 8, 15, 20, 18, 25, 22, 13, 16, 30, 24],
75
+ name: 'Department 1',
76
+ type: 'bar',
77
+ marker: {
78
+ line: {
79
+ width: 1,
80
+ color: '#ED995D',
81
+ },
82
+ },
83
+ selected: true,
84
+ },
85
+ {
86
+ x: axisXTimestamps,
87
+ y: [7, 5, 12, 11, 5, 6, 19, 11, 9, 10, 17, 18],
88
+ name: 'Department 2',
89
+ type: 'bar',
90
+ selected: true,
91
+ },
92
+ {
93
+ x: axisXTimestamps,
94
+ y: [15, 18, 7, 20, 16, 12, 7, 18, 6, 14, 12, 15],
95
+ name: 'Department 3',
96
+ type: 'bar',
97
+ selected: true,
98
+ },
99
+ {
100
+ x: axisXTimestamps,
101
+ y: [14, 14, 19, 13, 9, 14, 23, 20, 24, 21, 8, 19],
102
+ name: 'Department 4',
103
+ type: 'bar',
104
+ selected: true,
105
+ },
106
+ {
107
+ x: axisXTimestamps,
108
+ y: [3, 8, 9, 6, 4, 11, 10, 8, 16, 7, 11, 9],
109
+ name: 'Department 5',
110
+ type: 'bar',
111
+ selected: true,
112
+ },
113
+ {
114
+ x: axisXTimestamps,
115
+ y: [3, 5, 7, 6, 4, 6, 7, 8, 6, 7, 8, 9],
116
+ name: 'Min',
117
+ type: 'scatter',
118
+ line: {
119
+ shape: 'linear',
120
+ },
121
+ selected: true,
122
+ },
123
+ {
124
+ x: axisXTimestamps,
125
+ y: [9.8, 11.4, 11.0, 13.0, 10.8, 12.2, 16.8, 15.8, 13.6, 13.6, 15.6, 16.2],
126
+ name: 'Average',
127
+ type: 'scatter',
128
+ line: {
129
+ shape: 'spline',
130
+ dash: 'dot',
131
+ },
132
+ selected: true,
133
+ },
134
+ {
135
+ x: axisXTimestamps,
136
+ y: [15, 18, 19, 20, 20, 18, 25, 22, 24, 21, 30, 24],
137
+ name: 'Max',
138
+ type: 'scatter',
139
+ selected: true,
140
+ },
141
+ ];
@@ -0,0 +1,23 @@
1
+ export const colorPalette = [
2
+ '#4178E1',
3
+ '#44B3FC',
4
+ '#A078F5',
5
+ '#41BBBB',
6
+ '#5288E7',
7
+ '#6C94F7',
8
+ '#55D6D2',
9
+ '#ED995D',
10
+ '#EB7556',
11
+ '#F28885',
12
+ '#EDBA5D',
13
+ '#F2A65E',
14
+ '#D95F59',
15
+ '#F2D16B',
16
+ '#85C7F2',
17
+ '#85C7F2',
18
+ '#7B47EB',
19
+ '#4178E1',
20
+ '#6A98F0',
21
+ '#5A67D8',
22
+ '#3C4ECF',
23
+ ];
@@ -0,0 +1 @@
1
+ export * from './BarLineComplexChart';
@@ -0,0 +1,36 @@
1
+ import { PlotParams } from 'react-plotly.js';
2
+ import { PieChartProps } from '../PieChart';
3
+
4
+ export type ChartItem = Plotly.Data & {
5
+ selected?: boolean;
6
+ };
7
+
8
+ export interface BarLineComplexChartProps extends Omit<PlotParams, 'layout'> {
9
+ layout?: PlotParams['layout'];
10
+ cardProps?: PieChartProps['cardProps'];
11
+ features?: Array<'header'>;
12
+ data: ChartItem[];
13
+ lineShape?: Plotly.ScatterLine['shape'];
14
+ width?: string;
15
+ height?: string;
16
+ maxVisibleBars?: number;
17
+ maxVisibleLines?: number;
18
+ }
19
+
20
+ export interface BarLineComplexChartPContextProps {
21
+ data: ChartItem[];
22
+ filteredData: ChartItem[];
23
+ lineShape?: Plotly.ScatterLine['shape'];
24
+ maxVisibleBars?: number;
25
+ maxVisibleLines?: number;
26
+ setFilteredData: React.Dispatch<React.SetStateAction<ChartItem[]>>;
27
+ setData: React.Dispatch<React.SetStateAction<ChartItem[]>>;
28
+ }
29
+
30
+ export interface BarLineComplexChartPContextProviderProps
31
+ extends Pick<
32
+ BarLineComplexChartProps,
33
+ 'data' | 'lineShape' | 'maxVisibleBars' | 'maxVisibleLines'
34
+ > {
35
+ children: React.ReactNode;
36
+ }
@@ -0,0 +1,68 @@
1
+ import { MutableRefObject, useEffect, useRef } from 'react';
2
+ import { pathOr } from '@ssa-ui-kit/utils';
3
+ import { useTooltipContext } from '@components/Tooltip/useTooltipContext';
4
+ import { colorPalette } from './colorPalette';
5
+ import { useBarLineComplexChartContext } from './BarLIneComplexChart.context';
6
+
7
+ interface UseChartInfo {
8
+ (): {
9
+ transformedChartData: Plotly.Data[];
10
+ tooltipContentRef: MutableRefObject<HTMLDivElement | null>;
11
+ handleFilterClick: (gd: Plotly.PlotlyHTMLElement, ev: MouseEvent) => void;
12
+ };
13
+ }
14
+
15
+ export const useChartInfo: UseChartInfo = () => {
16
+ const { setIsOpen, isOpen, context } = useTooltipContext();
17
+ const { data, lineShape } = useBarLineComplexChartContext();
18
+ const tooltipContentRef = useRef<HTMLDivElement | null>(null);
19
+
20
+ useEffect(() => {
21
+ return () => {
22
+ context.refs.setReference(null);
23
+ context.refs.setFloating(null);
24
+ };
25
+ }, []);
26
+
27
+ const transformedChartData = data.map((item, index) => {
28
+ const markerColor = pathOr<typeof item, string[]>(colorPalette[index], [
29
+ 'marker',
30
+ 'color',
31
+ ])(item);
32
+ const extraParams: Plotly.Data = {
33
+ mode: 'markers',
34
+ marker: {
35
+ color: markerColor,
36
+ symbol: '',
37
+ },
38
+ yaxis: 'y2',
39
+ connectgaps: true,
40
+ };
41
+ if (!('hovertemplate' in item)) {
42
+ extraParams.hovertemplate = `${item.name}: %{y:}` + '<extra></extra>';
43
+ }
44
+ if (item.type === 'scatter') {
45
+ extraParams.mode = 'lines';
46
+ extraParams.line = {
47
+ shape: lineShape,
48
+ };
49
+ }
50
+ return {
51
+ ...extraParams,
52
+ ...item,
53
+ };
54
+ }) as unknown as Plotly.Data[];
55
+
56
+ const handleFilterClick: Plotly.ButtonClickEvent = (
57
+ gd: Plotly.PlotlyHTMLElement,
58
+ ) => {
59
+ setIsOpen(!isOpen);
60
+ if (!isOpen) {
61
+ const filteringIcon = gd.querySelector('[data-attr=filtering-icon]');
62
+ context.refs.setReference(filteringIcon as HTMLElement);
63
+ context.refs.setFloating(tooltipContentRef.current as HTMLElement);
64
+ }
65
+ };
66
+
67
+ return { transformedChartData, tooltipContentRef, handleFilterClick };
68
+ };
@@ -1,6 +1,6 @@
1
1
  import { SerializedStyles } from '@emotion/react';
2
2
  import { ResponsivePie, MayHaveLabel } from '@nivo/pie';
3
- import { CommonProps, WidgetCardProps } from '../..';
3
+ import { CommonProps, WidgetCardProps } from '../../..';
4
4
 
5
5
  export type PieChartFeatures =
6
6
  | 'header'
@@ -8,7 +8,7 @@ import {
8
8
  import { SegmentedPieChart } from '../SegmentedPieChart';
9
9
 
10
10
  export default {
11
- title: 'Widgets/SegmentedPieChart',
11
+ title: 'Charts/SegmentedPieChart',
12
12
  component: SegmentedPieChart,
13
13
  } as Meta<typeof SegmentedPieChart>;
14
14
 
@@ -0,0 +1 @@
1
+ export * from './usePlotlyDefaultConfig';
@@ -0,0 +1,39 @@
1
+ import { PlotParams } from 'react-plotly.js';
2
+ import { useTheme } from '@emotion/react';
3
+
4
+ interface UsePlotlyDefaultConfig {
5
+ (): {
6
+ layout: PlotParams['layout'];
7
+ config: PlotParams['config'];
8
+ emptyBar: PlotParams['data'][0];
9
+ };
10
+ }
11
+
12
+ export const usePlotlyDefaultConfig: UsePlotlyDefaultConfig = () => {
13
+ const theme = useTheme();
14
+
15
+ return {
16
+ layout: {
17
+ font: {
18
+ family: "'Manrope',sans-serif",
19
+ size: 10,
20
+ },
21
+ autosize: true,
22
+ hovermode: 'x unified',
23
+ } as PlotParams['layout'],
24
+ config: {
25
+ responsive: true,
26
+ autosizable: true,
27
+ displaylogo: false,
28
+ } as PlotParams['config'],
29
+ emptyBar: {
30
+ type: 'bar',
31
+ yaxis: 'y2',
32
+ marker: {
33
+ color: theme.colors.greyLighter,
34
+ },
35
+ hovertemplate: '<b>No data yet!</b><extra></extra>',
36
+ showlegend: false,
37
+ } as PlotParams['data'][0],
38
+ };
39
+ };
@@ -0,0 +1,3 @@
1
+ export * from './PieChart';
2
+ export * from './SegmentedPieChart';
3
+ export * from './BarLineComplexChart';