@servicetitan/marketing-ui 5.9.0 → 5.11.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/ads/ads-stat.js +21 -10
- package/dist/components/ads/ads-stat.js.map +1 -1
- package/dist/components/charts/funnel-chart/components/funnel-chart.js +118 -6
- package/dist/components/charts/funnel-chart/components/funnel-chart.js.map +1 -1
- package/dist/components/charts/funnel-chart/components/funnel-chart.module.less.d.ts +9 -0
- package/dist/components/charts/funnel-chart/components/funnel-svg.js +62 -12
- package/dist/components/charts/funnel-chart/components/funnel-svg.js.map +1 -1
- package/dist/components/charts/funnel-chart/index.js +1 -0
- package/dist/components/charts/funnel-chart/index.js.map +1 -1
- package/dist/components/charts/funnel-chart/utils/const.js +1 -0
- package/dist/components/charts/funnel-chart/utils/const.js.map +1 -1
- package/dist/components/charts/funnel-chart/utils/interface.js +2 -1
- package/dist/components/charts/funnel-chart/utils/interface.js.map +1 -1
- package/dist/components/charts/line-chart/components/body.js +105 -16
- package/dist/components/charts/line-chart/components/body.js.map +1 -1
- package/dist/components/charts/line-chart/components/body.module.less.d.ts +4 -0
- package/dist/components/charts/line-chart/components/container.js +12 -4
- package/dist/components/charts/line-chart/components/container.js.map +1 -1
- package/dist/components/charts/line-chart/components/hover-popover.js +56 -13
- package/dist/components/charts/line-chart/components/hover-popover.js.map +1 -1
- package/dist/components/charts/line-chart/components/hover-popover.module.less.d.ts +5 -0
- package/dist/components/charts/line-chart/components/sidebar.js +35 -5
- package/dist/components/charts/line-chart/components/sidebar.js.map +1 -1
- package/dist/components/charts/line-chart/components/sidebar.module.less.d.ts +13 -0
- package/dist/components/charts/line-chart/components/stuff.js +73 -32
- package/dist/components/charts/line-chart/components/stuff.js.map +1 -1
- package/dist/components/charts/line-chart/components/stuff.module.less.d.ts +6 -0
- package/dist/components/charts/line-chart/components/svg-bars.js +58 -26
- package/dist/components/charts/line-chart/components/svg-bars.js.map +1 -1
- package/dist/components/charts/line-chart/components/svg-body.js +52 -11
- package/dist/components/charts/line-chart/components/svg-body.js.map +1 -1
- package/dist/components/charts/line-chart/components/svg-lines.js +46 -27
- package/dist/components/charts/line-chart/components/svg-lines.js.map +1 -1
- package/dist/components/charts/line-chart/components/svg.module.less.d.ts +5 -0
- package/dist/components/charts/line-chart/index.js +1 -0
- package/dist/components/charts/line-chart/index.js.map +1 -1
- package/dist/components/charts/line-chart/stores/line-chart.store.js +98 -137
- package/dist/components/charts/line-chart/stores/line-chart.store.js.map +1 -1
- package/dist/components/charts/line-chart/stores/svg.store.js +66 -108
- package/dist/components/charts/line-chart/stores/svg.store.js.map +1 -1
- package/dist/components/charts/line-chart/utils/const.js +8 -7
- package/dist/components/charts/line-chart/utils/const.js.map +1 -1
- package/dist/components/charts/line-chart/utils/formatters.js +13 -11
- package/dist/components/charts/line-chart/utils/formatters.js.map +1 -1
- package/dist/components/charts/line-chart/utils/interfaces.js +2 -1
- package/dist/components/charts/line-chart/utils/interfaces.js.map +1 -1
- package/dist/components/charts/line-chart/utils/internal-interfaces.js +2 -1
- package/dist/components/charts/line-chart/utils/internal-interfaces.js.map +1 -1
- package/dist/components/charts/line-chart/utils/key.js +2 -1
- package/dist/components/charts/line-chart/utils/key.js.map +1 -1
- package/dist/components/charts/line-chart/utils/labels.js +50 -46
- package/dist/components/charts/line-chart/utils/labels.js.map +1 -1
- package/dist/components/charts/pie-chart/components/pie-chart.js +60 -6
- package/dist/components/charts/pie-chart/components/pie-chart.js.map +1 -1
- package/dist/components/charts/pie-chart/components/pie-chart.module.less.d.ts +3 -0
- package/dist/components/charts/pie-chart/components/pie.js +176 -39
- package/dist/components/charts/pie-chart/components/pie.js.map +1 -1
- package/dist/components/charts/pie-chart/index.js +2 -0
- package/dist/components/charts/pie-chart/index.js.map +1 -1
- package/dist/components/charts/pie-chart/utils/const.js +55 -39
- package/dist/components/charts/pie-chart/utils/const.js.map +1 -1
- package/dist/components/charts/pie-chart/utils/interface.js +2 -1
- package/dist/components/charts/pie-chart/utils/interface.js.map +1 -1
- package/dist/components/image-cropper/image-cropper.js +74 -88
- package/dist/components/image-cropper/image-cropper.js.map +1 -1
- package/dist/components/stat/stat-card.js +68 -22
- package/dist/components/stat/stat-card.js.map +1 -1
- package/dist/components/stat/stat-card.module.less.d.ts +5 -0
- package/dist/components/stat/stat-extended-card.js +76 -4
- package/dist/components/stat/stat-extended-card.js.map +1 -1
- package/dist/components/ui/action-button/action-button.js +33 -7
- package/dist/components/ui/action-button/action-button.js.map +1 -1
- package/dist/components/ui/action-button/action-button.module.less.d.ts +9 -0
- package/dist/components/ui/action-button/index.js +1 -0
- package/dist/components/ui/action-button/index.js.map +1 -1
- package/dist/components/ui/centered-spinner/centered-spinner.js +20 -2
- package/dist/components/ui/centered-spinner/centered-spinner.js.map +1 -1
- package/dist/components/ui/date-range-picker/date-range-picker.js +71 -35
- package/dist/components/ui/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/components/ui/date-range-picker/date-range-picker.module.less.d.ts +4 -0
- package/dist/components/ui/disabled-button.js +12 -3
- package/dist/components/ui/disabled-button.js.map +1 -1
- package/dist/components/ui/label-with-hint/label-with-hint.js +23 -1
- package/dist/components/ui/label-with-hint/label-with-hint.js.map +1 -1
- package/dist/components/ui/line-text/index.js +1 -0
- package/dist/components/ui/line-text/index.js.map +1 -1
- package/dist/components/ui/line-text/line-text.js +71 -12
- package/dist/components/ui/line-text/line-text.js.map +1 -1
- package/dist/components/ui/line-text/line-text.module.less.d.ts +6 -0
- package/dist/components/ui/title-popover/index.js +1 -0
- package/dist/components/ui/title-popover/index.js.map +1 -1
- package/dist/components/ui/title-popover/title-popover.js +78 -69
- package/dist/components/ui/title-popover/title-popover.js.map +1 -1
- package/dist/components/ui/title-popover/title-popover.module.less.d.ts +3 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/ads-texts.js +2 -1
- package/dist/utils/ads-texts.js.map +1 -1
- package/dist/utils/date/date-range-picker-options.js +90 -68
- package/dist/utils/date/date-range-picker-options.js.map +1 -1
- package/dist/utils/date/date-range-picker-state.js +42 -43
- package/dist/utils/date/date-range-picker-state.js.map +1 -1
- package/dist/utils/date/date-tenant.js +4 -6
- package/dist/utils/date/date-tenant.js.map +1 -1
- package/dist/utils/date/date.js +5 -9
- package/dist/utils/date/date.js.map +1 -1
- package/dist/utils/date/index.js +1 -0
- package/dist/utils/date/index.js.map +1 -1
- package/dist/utils/format-big-numbers.js +11 -6
- package/dist/utils/format-big-numbers.js.map +1 -1
- package/dist/utils/formatters.js +8 -7
- package/dist/utils/formatters.js.map +1 -1
- package/dist/utils/helpers.js +9 -12
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/marketing-parner-handlers.js +9 -12
- package/dist/utils/marketing-parner-handlers.js.map +1 -1
- package/dist/utils/string-case.js +1 -0
- package/dist/utils/string-case.js.map +1 -1
- package/dist/utils/use-client-rect.js +19 -19
- package/dist/utils/use-client-rect.js.map +1 -1
- package/dist/utils/use-target-range-store.js +7 -6
- package/dist/utils/use-target-range-store.js.map +1 -1
- package/package.json +11 -11
- package/dist/components/charts/funnel-chart/funnel-chart.stories.js +0 -76
- package/dist/components/charts/funnel-chart/funnel-chart.stories.js.map +0 -1
- package/dist/components/charts/line-chart/line-chart.stories.js +0 -225
- package/dist/components/charts/line-chart/line-chart.stories.js.map +0 -1
- package/dist/components/charts/pie-chart/pie-chart.stories.js +0 -22
- package/dist/components/charts/pie-chart/pie-chart.stories.js.map +0 -1
- package/dist/components/image-cropper/image-cropper.stories.js +0 -39
- package/dist/components/image-cropper/image-cropper.stories.js.map +0 -1
- package/dist/components/stat/stat-cards.stories.js +0 -16
- package/dist/components/stat/stat-cards.stories.js.map +0 -1
- package/dist/components/stat/stat-extended-card.stories.js +0 -12
- package/dist/components/stat/stat-extended-card.stories.js.map +0 -1
- package/dist/components/ui/action-button/action-button.stories.js +0 -11
- package/dist/components/ui/action-button/action-button.stories.js.map +0 -1
- package/dist/components/ui/centered-spinner/centered-spinner.stories.js +0 -12
- package/dist/components/ui/centered-spinner/centered-spinner.stories.js.map +0 -1
- package/dist/components/ui/date-range-picker/date-range-picker.stories.js +0 -18
- package/dist/components/ui/date-range-picker/date-range-picker.stories.js.map +0 -1
- package/dist/components/ui/label-with-hint/label-with-hint.stories.js +0 -12
- package/dist/components/ui/label-with-hint/label-with-hint.stories.js.map +0 -1
- package/dist/components/ui/line-text/line-text-body.stories.js +0 -11
- package/dist/components/ui/line-text/line-text-body.stories.js.map +0 -1
- package/dist/components/ui/line-text/line-text-head.stories.js +0 -11
- package/dist/components/ui/line-text/line-text-head.stories.js.map +0 -1
- package/dist/components/ui/title-popover/title-popover.stories.js +0 -17
- package/dist/components/ui/title-popover/title-popover.stories.js.map +0 -1
- package/dist/utils/__tests__/format-big-numbers.test.js +0 -16
- package/dist/utils/__tests__/format-big-numbers.test.js.map +0 -1
- package/dist/utils/__tests__/formatters.test.js +0 -45
- package/dist/utils/__tests__/formatters.test.js.map +0 -1
- package/dist/utils/__tests__/helpers.test.js +0 -31
- package/dist/utils/__tests__/helpers.test.js.map +0 -1
- package/dist/utils/__tests__/string-case.test.js +0 -20
- package/dist/utils/__tests__/string-case.test.js.map +0 -1
- package/dist/utils/date/__mocks__/date-mock.js +0 -19
- package/dist/utils/date/__mocks__/date-mock.js.map +0 -1
- package/dist/utils/date/__tests__/date-range-picker.test.js +0 -93
- package/dist/utils/date/__tests__/date-range-picker.test.js.map +0 -1
- package/dist/utils/date/__tests__/date-tenant.test.js +0 -29
- package/dist/utils/date/__tests__/date-tenant.test.js.map +0 -1
|
@@ -5,12 +5,66 @@ import { BodyText, Stack, StatusLight } from '@servicetitan/design-system';
|
|
|
5
5
|
import { convertSessionsToPieces, radiusRelativeDefault } from '../utils/const';
|
|
6
6
|
import { Pie } from './pie';
|
|
7
7
|
import * as Styles from './pie-chart.module.less';
|
|
8
|
-
const PieTitles = ({ title, pieces })
|
|
9
|
-
return
|
|
8
|
+
const PieTitles = ({ title, pieces })=>{
|
|
9
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
10
|
+
className: classNames(Styles.titleWrapper, 'of-y-auto p-t-2'),
|
|
11
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
12
|
+
children: [
|
|
13
|
+
!!pieces.length && /*#__PURE__*/ _jsx(Stack.Item, {
|
|
14
|
+
className: "p-l-1 p-b-1",
|
|
15
|
+
children: /*#__PURE__*/ _jsx(BodyText, {
|
|
16
|
+
bold: true,
|
|
17
|
+
children: title
|
|
18
|
+
})
|
|
19
|
+
}),
|
|
20
|
+
pieces.map((piece)=>/*#__PURE__*/ _jsxs(Stack, {
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
children: [
|
|
23
|
+
/*#__PURE__*/ _jsx(StatusLight, {
|
|
24
|
+
color: piece.color
|
|
25
|
+
}),
|
|
26
|
+
/*#__PURE__*/ _jsx(BodyText, {
|
|
27
|
+
className: "c-neutral-90",
|
|
28
|
+
size: "medium",
|
|
29
|
+
children: piece.title
|
|
30
|
+
})
|
|
31
|
+
]
|
|
32
|
+
}, piece.title))
|
|
33
|
+
]
|
|
34
|
+
})
|
|
35
|
+
});
|
|
10
36
|
};
|
|
11
|
-
export const PieChart = ({ height, width, title, sections, popoverContent, content, radiusRelative = radiusRelativeDefault, popoverDirection = 'rb', hideTitles = false
|
|
12
|
-
const pieces = useMemo(()
|
|
13
|
-
|
|
14
|
-
|
|
37
|
+
export const PieChart = ({ height, width, title, sections, popoverContent, content, radiusRelative = radiusRelativeDefault, popoverDirection = 'rb', hideTitles = false })=>{
|
|
38
|
+
const pieces = useMemo(()=>convertSessionsToPieces(sections, radiusRelative), [
|
|
39
|
+
sections,
|
|
40
|
+
radiusRelative
|
|
41
|
+
]);
|
|
42
|
+
const style = useMemo(()=>({
|
|
43
|
+
height,
|
|
44
|
+
width
|
|
45
|
+
}), [
|
|
46
|
+
height,
|
|
47
|
+
width
|
|
48
|
+
]);
|
|
49
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
50
|
+
className: "d-f flex-row",
|
|
51
|
+
style: style,
|
|
52
|
+
children: [
|
|
53
|
+
/*#__PURE__*/ _jsx(Pie, {
|
|
54
|
+
title: title,
|
|
55
|
+
pieces: pieces,
|
|
56
|
+
content: content,
|
|
57
|
+
popoverContent: popoverContent,
|
|
58
|
+
popoverDirection: popoverDirection,
|
|
59
|
+
radiusRelative: radiusRelative,
|
|
60
|
+
hideTitles: hideTitles
|
|
61
|
+
}),
|
|
62
|
+
!hideTitles && /*#__PURE__*/ _jsx(PieTitles, {
|
|
63
|
+
title: title,
|
|
64
|
+
pieces: pieces
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
});
|
|
15
68
|
};
|
|
69
|
+
|
|
16
70
|
//# sourceMappingURL=pie-chart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/pie-chart/components/pie-chart.tsx"],"sourcesContent":["import { useMemo, FC } from 'react';\nimport classNames from 'classnames';\nimport { BodyText, Stack, StatusLight } from '@servicetitan/design-system';\nimport { PieChartProps, PiePiece } from '../utils/interface';\nimport { convertSessionsToPieces, radiusRelativeDefault } from '../utils/const';\nimport { Pie } from './pie';\nimport * as Styles from './pie-chart.module.less';\n\nconst PieTitles: FC<{ title: string; pieces: PiePiece[] }> = ({ title, pieces }) => {\n return (\n <div className={classNames(Styles.titleWrapper, 'of-y-auto p-t-2')}>\n <div>\n {!!pieces.length && (\n <Stack.Item className=\"p-l-1 p-b-1\">\n <BodyText bold>{title}</BodyText>\n </Stack.Item>\n )}\n {pieces.map(piece => (\n <Stack key={piece.title} alignItems=\"center\">\n <StatusLight color={piece.color} />\n <BodyText className=\"c-neutral-90\" size=\"medium\">\n {piece.title}\n </BodyText>\n </Stack>\n ))}\n </div>\n </div>\n );\n};\n\nexport const PieChart: FC<PieChartProps> = ({\n height,\n width,\n title,\n sections,\n popoverContent,\n content,\n radiusRelative = radiusRelativeDefault,\n popoverDirection = 'rb',\n hideTitles = false,\n}) => {\n const pieces = useMemo(\n () => convertSessionsToPieces(sections, radiusRelative),\n [sections, radiusRelative]\n );\n const style = useMemo(() => ({ height, width }), [height, width]);\n\n return (\n <div className=\"d-f flex-row\" style={style}>\n <Pie\n title={title}\n pieces={pieces}\n content={content}\n popoverContent={popoverContent}\n popoverDirection={popoverDirection}\n radiusRelative={radiusRelative}\n hideTitles={hideTitles}\n />\n {!hideTitles && <PieTitles title={title} pieces={pieces} />}\n </div>\n );\n};\n"],"names":["useMemo","classNames","BodyText","Stack","StatusLight","convertSessionsToPieces","radiusRelativeDefault","Pie","Styles","PieTitles","title","pieces","div","className","titleWrapper","length","Item","bold","map","piece","alignItems","color","size","PieChart","height","width","sections","popoverContent","content","radiusRelative","popoverDirection","hideTitles","style"],"mappings":";AAAA,SAASA,OAAO,QAAY,QAAQ;AACpC,OAAOC,gBAAgB,aAAa;AACpC,SAASC,QAAQ,EAAEC,KAAK,EAAEC,WAAW,QAAQ,8BAA8B;AAE3E,SAASC,uBAAuB,EAAEC,qBAAqB,QAAQ,iBAAiB;AAChF,SAASC,GAAG,QAAQ,QAAQ;AAC5B,YAAYC,YAAY,0BAA0B;AAElD,MAAMC,YAAuD,CAAC,EAAEC,KAAK,EAAEC,MAAM,EAAE;IAC3E,qBACI,KAACC;QAAIC,WAAWZ,WAAWO,OAAOM,YAAY,EAAE;kBAC5C,cAAA,MAACF;;gBACI,CAAC,CAACD,OAAOI,MAAM,kBACZ,KAACZ,MAAMa,IAAI;oBAACH,WAAU;8BAClB,cAAA,KAACX;wBAASe,IAAI;kCAAEP;;;gBAGvBC,OAAOO,GAAG,CAACC,CAAAA,sBACR,MAAChB;wBAAwBiB,YAAW;;0CAChC,KAAChB;gCAAYiB,OAAOF,MAAME,KAAK;;0CAC/B,KAACnB;gCAASW,WAAU;gCAAeS,MAAK;0CACnCH,MAAMT,KAAK;;;uBAHRS,MAAMT,KAAK;;;;AAU3C;AAEA,OAAO,MAAMa,WAA8B,CAAC,EACxCC,MAAM,EACNC,KAAK,EACLf,KAAK,EACLgB,QAAQ,EACRC,cAAc,EACdC,OAAO,EACPC,iBAAiBvB,qBAAqB,EACtCwB,mBAAmB,IAAI,EACvBC,aAAa,KAAK,EACrB;IACG,MAAMpB,SAASX,QACX,IAAMK,wBAAwBqB,UAAUG,iBACxC;QAACH;QAAUG;KAAe;IAE9B,MAAMG,QAAQhC,QAAQ,IAAO,CAAA;YAAEwB;YAAQC;QAAM,CAAA,GAAI;QAACD;QAAQC;KAAM;IAEhE,qBACI,MAACb;QAAIC,WAAU;QAAemB,OAAOA;;0BACjC,KAACzB;gBACGG,OAAOA;gBACPC,QAAQA;gBACRiB,SAASA;gBACTD,gBAAgBA;gBAChBG,kBAAkBA;gBAClBD,gBAAgBA;gBAChBE,YAAYA;;YAEf,CAACA,4BAAc,KAACtB;gBAAUC,OAAOA;gBAAOC,QAAQA;;;;AAG7D,EAAE"}
|
|
@@ -4,52 +4,189 @@ import { tokens } from '@servicetitan/tokens/core';
|
|
|
4
4
|
import { BodyText, Popover, Stack, StatusLight } from '@servicetitan/design-system';
|
|
5
5
|
import { useClientRect } from '../../../../utils/use-client-rect';
|
|
6
6
|
const chartPadding = 8;
|
|
7
|
-
const px = (value)
|
|
8
|
-
const PiePieceSvg = ({ piece: { id, color, opacity, points, text, path }, selected })
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const px = (value)=>`${value !== null && value !== void 0 ? value : 0}px`;
|
|
8
|
+
const PiePieceSvg = ({ piece: { id, color, opacity, points, text, path }, selected })=>points && path ? /*#__PURE__*/ _jsxs("g", {
|
|
9
|
+
id: id,
|
|
10
|
+
children: [
|
|
11
|
+
!!selected && /*#__PURE__*/ _jsx("path", {
|
|
12
|
+
d: path,
|
|
13
|
+
fill: tokens.colorWhite,
|
|
14
|
+
stroke: tokens.colorBlue200,
|
|
15
|
+
strokeOpacity: "50%",
|
|
16
|
+
strokeWidth: "3",
|
|
17
|
+
paintOrder: "stroke"
|
|
18
|
+
}),
|
|
19
|
+
/*#__PURE__*/ _jsx("path", {
|
|
20
|
+
d: path,
|
|
21
|
+
fill: color
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ _jsx("svg", {
|
|
24
|
+
x: points[4][0] - 10,
|
|
25
|
+
y: points[4][1] - (points[4][1] > 0 ? 3 : 1),
|
|
26
|
+
width: 20,
|
|
27
|
+
height: 6,
|
|
28
|
+
children: /*#__PURE__*/ _jsx("text", {
|
|
29
|
+
x: "50%",
|
|
30
|
+
y: "50%",
|
|
31
|
+
fontSize: 4,
|
|
32
|
+
fontWeight: 600,
|
|
33
|
+
fill: opacity > 0.3 ? tokens.colorWhite : tokens.colorBlack,
|
|
34
|
+
dominantBaseline: "middle",
|
|
35
|
+
textAnchor: "middle",
|
|
36
|
+
children: text
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
]
|
|
40
|
+
}) : null;
|
|
41
|
+
const PiePieceHover = ({ piece, onMouse })=>{
|
|
42
|
+
const onMouseEnter = useCallback(()=>onMouse(piece.id, true), [
|
|
43
|
+
onMouse,
|
|
44
|
+
piece.id
|
|
45
|
+
]);
|
|
46
|
+
const onMouseLeave = useCallback(()=>onMouse(piece.id, false), [
|
|
47
|
+
onMouse,
|
|
48
|
+
piece.id
|
|
49
|
+
]);
|
|
50
|
+
return /*#__PURE__*/ _jsx("path", {
|
|
51
|
+
d: piece.path,
|
|
52
|
+
fill: "white",
|
|
53
|
+
opacity: "0",
|
|
54
|
+
onMouseEnter: onMouseEnter,
|
|
55
|
+
onMouseLeave: onMouseLeave
|
|
56
|
+
});
|
|
13
57
|
};
|
|
14
|
-
const PieSvg = ({ pieces, selectedIndex, radiusRelative })
|
|
15
|
-
|
|
16
|
-
|
|
58
|
+
const PieSvg = ({ pieces, selectedIndex, radiusRelative })=>/*#__PURE__*/ _jsxs("svg", {
|
|
59
|
+
className: "position-absolute",
|
|
60
|
+
style: {
|
|
61
|
+
inset: px(chartPadding)
|
|
62
|
+
},
|
|
63
|
+
viewBox: `-${radiusRelative} -${radiusRelative} ` + `${radiusRelative * 2} ${radiusRelative * 2}`,
|
|
64
|
+
children: [
|
|
65
|
+
pieces.map((p, index)=>p.path ? /*#__PURE__*/ _jsx(PiePieceSvg, {
|
|
66
|
+
piece: p,
|
|
67
|
+
selected: index === selectedIndex
|
|
68
|
+
}, p.id) : null),
|
|
69
|
+
selectedIndex >= 0 && selectedIndex < pieces.length && /*#__PURE__*/ _jsx("use", {
|
|
70
|
+
xlinkHref: pieces[selectedIndex].id
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
const PieSvgHover = ({ pieces, onMouse, radiusRelative })=>/*#__PURE__*/ _jsx("svg", {
|
|
75
|
+
className: "position-absolute z-global-nav",
|
|
76
|
+
style: {
|
|
77
|
+
inset: px(chartPadding)
|
|
78
|
+
},
|
|
79
|
+
viewBox: `-${radiusRelative} -${radiusRelative} ` + `${radiusRelative * 2} ${radiusRelative * 2}`,
|
|
80
|
+
children: pieces.map((p)=>p.path ? /*#__PURE__*/ _jsx(PiePieceHover, {
|
|
81
|
+
piece: p,
|
|
82
|
+
onMouse: onMouse
|
|
83
|
+
}, p.id) : null)
|
|
84
|
+
});
|
|
85
|
+
export const Pie = ({ pieces, popoverContent: PopoverContent, content: PieContent, radiusRelative, hideTitles, popoverDirection })=>{
|
|
17
86
|
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
18
87
|
const [rect, ref] = useClientRect();
|
|
19
|
-
const onMouse = useCallback((id, isEnter)
|
|
20
|
-
setSelectedIndex(isEnter ? pieces.findIndex(p
|
|
21
|
-
}, [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
88
|
+
const onMouse = useCallback((id, isEnter)=>{
|
|
89
|
+
setSelectedIndex(isEnter ? pieces.findIndex((p)=>p.id === id) : -1);
|
|
90
|
+
}, [
|
|
91
|
+
pieces,
|
|
92
|
+
setSelectedIndex
|
|
93
|
+
]);
|
|
94
|
+
const container = useMemo(()=>{
|
|
95
|
+
var _rect_height;
|
|
96
|
+
const height = (_rect_height = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _rect_height !== void 0 ? _rect_height : 0;
|
|
25
97
|
return {
|
|
26
98
|
height,
|
|
27
99
|
internal: height ? height - chartPadding * 2 : 0,
|
|
28
|
-
styles: height
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
: {},
|
|
100
|
+
styles: height ? {
|
|
101
|
+
width: px(Math.max(250, height)),
|
|
102
|
+
overflow: 'hidden'
|
|
103
|
+
} : {}
|
|
34
104
|
};
|
|
35
|
-
}, [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
105
|
+
}, [
|
|
106
|
+
rect
|
|
107
|
+
]);
|
|
108
|
+
const triggersStyles = useMemo(()=>container.height ? pieces.map((p)=>p.points ? {
|
|
39
109
|
key: p.key,
|
|
40
|
-
top: px(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
110
|
+
top: px(container.height * (radiusRelative + p.points[4][1]) / (radiusRelative * 2)),
|
|
111
|
+
left: px(container.height * (radiusRelative + p.points[4][0]) / (radiusRelative * 2) + 20)
|
|
112
|
+
} : {
|
|
113
|
+
top: '',
|
|
114
|
+
left: ''
|
|
115
|
+
}) : [], [
|
|
116
|
+
pieces,
|
|
117
|
+
container,
|
|
118
|
+
radiusRelative
|
|
119
|
+
]);
|
|
120
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
121
|
+
ref: ref,
|
|
122
|
+
style: container.styles,
|
|
123
|
+
className: "position-relative",
|
|
124
|
+
children: pieces.every((p)=>!p.path) ? /*#__PURE__*/ _jsx(Stack, {
|
|
125
|
+
className: "h-100",
|
|
126
|
+
justifyContent: "center",
|
|
127
|
+
alignItems: "center",
|
|
128
|
+
children: "No Data"
|
|
129
|
+
}) : /*#__PURE__*/ _jsxs(Fragment, {
|
|
130
|
+
children: [
|
|
131
|
+
triggersStyles.filter((ts)=>!!ts.left && !!ts.top).map((ts, ind)=>{
|
|
132
|
+
var _pieces_ind, _pieces_ind1, _pieces_ind2;
|
|
133
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
134
|
+
style: ts,
|
|
135
|
+
className: "position-absolute",
|
|
136
|
+
children: (!!PopoverContent || !hideTitles) && /*#__PURE__*/ _jsx(Popover, {
|
|
137
|
+
portal: true,
|
|
138
|
+
trigger: /*#__PURE__*/ _jsx("span", {
|
|
139
|
+
children: " "
|
|
140
|
+
}),
|
|
141
|
+
open: selectedIndex === ind,
|
|
142
|
+
direction: popoverDirection,
|
|
143
|
+
padding: "s",
|
|
144
|
+
width: "auto",
|
|
145
|
+
children: selectedIndex === ind && /*#__PURE__*/ _jsxs(Stack, {
|
|
146
|
+
direction: "column",
|
|
147
|
+
"data-cy": `customer-lead-rate-section-${ts.key}-popover`,
|
|
148
|
+
children: [
|
|
149
|
+
!hideTitles && /*#__PURE__*/ _jsxs(Stack, {
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
children: [
|
|
152
|
+
/*#__PURE__*/ _jsx(StatusLight, {
|
|
153
|
+
color: pieces[ind].color
|
|
154
|
+
}),
|
|
155
|
+
/*#__PURE__*/ _jsx(BodyText, {
|
|
156
|
+
size: "small",
|
|
157
|
+
bold: true,
|
|
158
|
+
children: pieces[ind].title
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
}),
|
|
162
|
+
!!PopoverContent && /*#__PURE__*/ _jsx(Stack.Item, {
|
|
163
|
+
className: "m-l-1",
|
|
164
|
+
children: /*#__PURE__*/ _jsx(PopoverContent, {
|
|
165
|
+
index: ind,
|
|
166
|
+
data: (_pieces_ind = pieces[ind]) === null || _pieces_ind === void 0 ? void 0 : _pieces_ind.data,
|
|
167
|
+
text: (_pieces_ind1 = pieces[ind]) === null || _pieces_ind1 === void 0 ? void 0 : _pieces_ind1.text,
|
|
168
|
+
value: (_pieces_ind2 = pieces[ind]) === null || _pieces_ind2 === void 0 ? void 0 : _pieces_ind2.value
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
]
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
}, ts.left + ts.top);
|
|
175
|
+
}),
|
|
176
|
+
!!PieContent && /*#__PURE__*/ _jsx(PieContent, {}),
|
|
177
|
+
/*#__PURE__*/ _jsx(PieSvg, {
|
|
178
|
+
pieces: pieces,
|
|
179
|
+
selectedIndex: selectedIndex,
|
|
180
|
+
radiusRelative: radiusRelative
|
|
181
|
+
}),
|
|
182
|
+
/*#__PURE__*/ _jsx(PieSvgHover, {
|
|
183
|
+
pieces: pieces,
|
|
184
|
+
onMouse: onMouse,
|
|
185
|
+
radiusRelative: radiusRelative
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
})
|
|
189
|
+
});
|
|
54
190
|
};
|
|
191
|
+
|
|
55
192
|
//# sourceMappingURL=pie.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie.js","sourceRoot":"","sources":["../../../../../src/components/charts/pie-chart/components/pie.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAM,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAEpF,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAGlE,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,EAAE,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,IAAI,CAAC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I,EAAE,MAAA,MAAM,CAAC,GAAG,CAAC,0CAAE,IAAI,EACvB,IAAI,EAAE,MAAA,MAAM,CAAC,GAAG,CAAC,0CAAE,IAAI,EACvB,KAAK,EAAE,MAAA,MAAM,CAAC,GAAG,CAAC,0CAAE,KAAK,GAC3B,GACO,CAChB,IACG,CACX,GACK,CACb,IApCK,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAqCpB,CACT,CAAA;iBAAA,CAAC,EACL,CAAC,CAAC,UAAU,IAAI,KAAC,UAAU,KAAG,EAC/B,KAAC,MAAM,IACH,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,cAAc,GAChC,EACF,KAAC,WAAW,IACR,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,GAChC,IACK,CACd,GACC,CACT,CAAC;AACN,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/pie-chart/components/pie.tsx"],"sourcesContent":["import { useCallback, useMemo, useState, FC, Fragment } from 'react';\nimport { tokens } from '@servicetitan/tokens/core';\nimport { BodyText, Popover, Stack, StatusLight } from '@servicetitan/design-system';\n\nimport { useClientRect } from '../../../../utils/use-client-rect';\nimport { PieChartPopoverContentType, PiePiece, PopoverDirection } from '../utils/interface';\n\nconst chartPadding = 8;\nconst px = (value?: number) => `${value ?? 0}px`;\n\nconst PiePieceSvg: FC<{\n piece: PiePiece;\n selected?: boolean;\n}> = ({ piece: { id, color, opacity, points, text, path }, selected }) =>\n points && path ? (\n <g id={id}>\n {!!selected && (\n <path\n d={path}\n fill={tokens.colorWhite}\n stroke={tokens.colorBlue200}\n strokeOpacity=\"50%\"\n strokeWidth=\"3\"\n paintOrder=\"stroke\"\n />\n )}\n <path d={path} fill={color} />\n\n <svg\n x={points[4][0] - 10}\n y={points[4][1] - (points[4][1] > 0 ? 3 : 1)}\n width={20}\n height={6}\n >\n <text\n x=\"50%\"\n y=\"50%\"\n fontSize={4}\n fontWeight={600}\n fill={opacity > 0.3 ? tokens.colorWhite : tokens.colorBlack}\n dominantBaseline=\"middle\"\n textAnchor=\"middle\"\n >\n {text}\n </text>\n </svg>\n </g>\n ) : null;\n\nconst PiePieceHover: FC<{\n piece: PiePiece;\n onMouse(id: string, isEnter: boolean): void;\n}> = ({ piece, onMouse }) => {\n const onMouseEnter = useCallback(() => onMouse(piece.id, true), [onMouse, piece.id]);\n const onMouseLeave = useCallback(() => onMouse(piece.id, false), [onMouse, piece.id]);\n\n return (\n <path\n d={piece.path}\n fill=\"white\"\n opacity=\"0\"\n onMouseEnter={onMouseEnter}\n onMouseLeave={onMouseLeave}\n />\n );\n};\n\nconst PieSvg: FC<{\n pieces: PiePiece[];\n selectedIndex: number;\n radiusRelative: number;\n}> = ({ pieces, selectedIndex, radiusRelative }) => (\n <svg\n className=\"position-absolute\"\n style={{ inset: px(chartPadding) }}\n viewBox={\n `-${radiusRelative} -${radiusRelative} ` + `${radiusRelative * 2} ${radiusRelative * 2}`\n }\n >\n {pieces.map((p, index) =>\n p.path ? <PiePieceSvg piece={p} key={p.id} selected={index === selectedIndex} /> : null\n )}\n\n {selectedIndex >= 0 && selectedIndex < pieces.length && (\n <use xlinkHref={pieces[selectedIndex].id} />\n )}\n </svg>\n);\n\nconst PieSvgHover: FC<{\n pieces: PiePiece[];\n radiusRelative: number;\n onMouse(id: string, isEnter: boolean): void;\n}> = ({ pieces, onMouse, radiusRelative }) => (\n <svg\n className=\"position-absolute z-global-nav\"\n style={{ inset: px(chartPadding) }}\n viewBox={\n `-${radiusRelative} -${radiusRelative} ` + `${radiusRelative * 2} ${radiusRelative * 2}`\n }\n >\n {pieces.map(p =>\n p.path ? <PiePieceHover piece={p} key={p.id} onMouse={onMouse} /> : null\n )}\n </svg>\n);\n\nexport const Pie: FC<{\n title: string;\n pieces: PiePiece[];\n radiusRelative: number;\n content?: FC;\n popoverContent?: PieChartPopoverContentType;\n hideTitles?: boolean;\n popoverDirection?: PopoverDirection;\n}> = ({\n pieces,\n popoverContent: PopoverContent,\n content: PieContent,\n radiusRelative,\n hideTitles,\n popoverDirection,\n}) => {\n const [selectedIndex, setSelectedIndex] = useState(-1);\n const [rect, ref] = useClientRect();\n\n const onMouse = useCallback(\n (id: string, isEnter: boolean) => {\n setSelectedIndex(isEnter ? pieces.findIndex(p => p.id === id) : -1);\n },\n [pieces, setSelectedIndex]\n );\n\n const container = useMemo(() => {\n const height = rect?.height ?? 0;\n\n return {\n height,\n internal: height ? height - chartPadding * 2 : 0,\n styles: height\n ? {\n width: px(Math.max(250, height)),\n overflow: 'hidden',\n }\n : {},\n };\n }, [rect]);\n\n const triggersStyles = useMemo(\n () =>\n container.height\n ? pieces.map(p =>\n p.points\n ? {\n key: p.key,\n top: px(\n (container.height * (radiusRelative + p.points[4][1])) /\n (radiusRelative * 2)\n ),\n left: px(\n (container.height * (radiusRelative + p.points[4][0])) /\n (radiusRelative * 2) +\n 20\n ),\n }\n : { top: '', left: '' }\n )\n : [],\n [pieces, container, radiusRelative]\n );\n\n return (\n <div ref={ref} style={container.styles} className=\"position-relative\">\n {pieces.every(p => !p.path) ? (\n <Stack className=\"h-100\" justifyContent=\"center\" alignItems=\"center\">\n No Data\n </Stack>\n ) : (\n <Fragment>\n {triggersStyles\n .filter(ts => !!ts.left && !!ts.top)\n .map((ts, ind) => (\n <div key={ts.left + ts.top} style={ts} className=\"position-absolute\">\n {(!!PopoverContent || !hideTitles) && (\n <Popover\n portal\n trigger={<span> </span>}\n open={selectedIndex === ind}\n direction={popoverDirection}\n padding=\"s\"\n width=\"auto\"\n >\n {selectedIndex === ind && (\n <Stack\n direction=\"column\"\n data-cy={`customer-lead-rate-section-${ts.key}-popover`}\n >\n {!hideTitles && (\n <Stack alignItems=\"center\">\n <StatusLight color={pieces[ind].color} />\n <BodyText size=\"small\" bold>\n {pieces[ind].title}\n </BodyText>\n </Stack>\n )}\n {!!PopoverContent && (\n <Stack.Item className=\"m-l-1\">\n <PopoverContent\n index={ind}\n data={pieces[ind]?.data}\n text={pieces[ind]?.text}\n value={pieces[ind]?.value}\n />\n </Stack.Item>\n )}\n </Stack>\n )}\n </Popover>\n )}\n </div>\n ))}\n {!!PieContent && <PieContent />}\n <PieSvg\n pieces={pieces}\n selectedIndex={selectedIndex}\n radiusRelative={radiusRelative}\n />\n <PieSvgHover\n pieces={pieces}\n onMouse={onMouse}\n radiusRelative={radiusRelative}\n />\n </Fragment>\n )}\n </div>\n );\n};\n"],"names":["useCallback","useMemo","useState","Fragment","tokens","BodyText","Popover","Stack","StatusLight","useClientRect","chartPadding","px","value","PiePieceSvg","piece","id","color","opacity","points","text","path","selected","g","d","fill","colorWhite","stroke","colorBlue200","strokeOpacity","strokeWidth","paintOrder","svg","x","y","width","height","fontSize","fontWeight","colorBlack","dominantBaseline","textAnchor","PiePieceHover","onMouse","onMouseEnter","onMouseLeave","PieSvg","pieces","selectedIndex","radiusRelative","className","style","inset","viewBox","map","p","index","length","use","xlinkHref","PieSvgHover","Pie","popoverContent","PopoverContent","content","PieContent","hideTitles","popoverDirection","setSelectedIndex","rect","ref","isEnter","findIndex","container","internal","styles","Math","max","overflow","triggersStyles","key","top","left","div","every","justifyContent","alignItems","filter","ts","ind","portal","trigger","span","open","direction","padding","data-cy","size","bold","title","Item","data"],"mappings":";AAAA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,EAAMC,QAAQ,QAAQ,QAAQ;AACrE,SAASC,MAAM,QAAQ,4BAA4B;AACnD,SAASC,QAAQ,EAAEC,OAAO,EAAEC,KAAK,EAAEC,WAAW,QAAQ,8BAA8B;AAEpF,SAASC,aAAa,QAAQ,oCAAoC;AAGlE,MAAMC,eAAe;AACrB,MAAMC,KAAK,CAACC,QAAmB,GAAGA,kBAAAA,mBAAAA,QAAS,EAAE,EAAE,CAAC;AAEhD,MAAMC,cAGD,CAAC,EAAEC,OAAO,EAAEC,EAAE,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAA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C5C,AAAC,CAAA,CAAC,CAACa,kBAAkB,CAACG,UAAS,mBAC5B,KAAC3D;4BACGmF,MAAM;4BACNC,uBAAS,KAACC;0CAAK;;4BACfC,MAAM7C,kBAAkByC;4BACxBK,WAAW3B;4BACX4B,SAAQ;4BACR5D,OAAM;sCAELa,kBAAkByC,qBACf,MAACjF;gCACGsF,WAAU;gCACVE,WAAS,CAAC,2BAA2B,EAAER,GAAGR,GAAG,CAAC,QAAQ,CAAC;;oCAEtD,CAACd,4BACE,MAAC1D;wCAAM8E,YAAW;;0DACd,KAAC7E;gDAAYQ,OAAO8B,MAAM,CAAC0C,IAAI,CAACxE,KAAK;;0DACrC,KAACX;gDAAS2F,MAAK;gDAAQC,IAAI;0DACtBnD,MAAM,CAAC0C,IAAI,CAACU,KAAK;;;;oCAI7B,CAAC,CAACpC,gCACC,KAACvD,MAAM4F,IAAI;wCAAClD,WAAU;kDAClB,cAAA,KAACa;4CACGP,OAAOiC;4CACPY,IAAI,GAAEtD,cAAAA,MAAM,CAAC0C,IAAI,cAAX1C,kCAAAA,YAAasD,IAAI;4CACvBjF,IAAI,GAAE2B,eAAAA,MAAM,CAAC0C,IAAI,cAAX1C,mCAAAA,aAAa3B,IAAI;4CACvBP,KAAK,GAAEkC,eAAAA,MAAM,CAAC0C,IAAI,cAAX1C,mCAAAA,aAAalC,KAAK;;;;;;uBA7B/C2E,GAAGN,IAAI,GAAGM,GAAGP,GAAG;;gBAuCjC,CAAC,CAAChB,4BAAc,KAACA;8BAClB,KAACnB;oBACGC,QAAQA;oBACRC,eAAeA;oBACfC,gBAAgBA;;8BAEpB,KAACW;oBACGb,QAAQA;oBACRJ,SAASA;oBACTM,gBAAgBA;;;;;AAMxC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/charts/pie-chart/index.ts"],"sourcesContent":["export { PieChart } from './components/pie-chart';\nexport { PieChartSection, PieChartPopoverContentType } from './utils/interface';\n"],"names":["PieChart","PieChartSection","PieChartPopoverContentType"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,yBAAyB;AAClD,SAASC,eAAe,EAAEC,0BAA0B,QAAQ,oBAAoB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { formatNumber } from 'accounting';
|
|
2
2
|
export const radiusRelativeDefault = 50;
|
|
3
3
|
const radiusInt = 20;
|
|
4
|
-
const getRadiusExt = (radiusRelative)
|
|
5
|
-
const getRadiusMid = (radiusRelative)
|
|
4
|
+
const getRadiusExt = (radiusRelative)=>radiusRelative - 5; // need to have some space to stroke selected piece
|
|
5
|
+
const getRadiusMid = (radiusRelative)=>3 * radiusRelative / 4;
|
|
6
6
|
const angleInitial = -0.5;
|
|
7
7
|
const lowestOpacity = 0.1;
|
|
8
|
-
const formatValue = (val)
|
|
8
|
+
const formatValue = (val)=>{
|
|
9
9
|
if (!val) {
|
|
10
10
|
return '0%';
|
|
11
11
|
}
|
|
@@ -16,70 +16,86 @@ const formatValue = (val) => {
|
|
|
16
16
|
const valueDecimal = Math.max(Math.floor(val * 10) - valueMain * 10, 1);
|
|
17
17
|
return `0.${valueDecimal}%`;
|
|
18
18
|
};
|
|
19
|
-
const convertPointsToPath = (points, wideAngle, radiusExt)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`L ${points[2][0]},${points[2][1]} ` +
|
|
23
|
-
`A ${radiusInt},${radiusInt} 0 ${wideAngle ? 1 : 0} 0 ${points[3][0]},${points[3][1]} ` +
|
|
24
|
-
`L ${points[0][0]},${points[0][1]} `;
|
|
25
|
-
export const convertSessionsToPieces = (sections, radiusRelative) => {
|
|
26
|
-
const total = sections.reduce((sum, curr) => sum + curr.value, 0);
|
|
19
|
+
const convertPointsToPath = (points, wideAngle, radiusExt)=>`M ${points[3][0]},${points[3][1]} ` + `L ${points[0][0]},${points[0][1]} ` + `A ${radiusExt},${radiusExt} 0 ${wideAngle ? 1 : 0} 1 ${points[1][0]},${points[1][1]} ` + `L ${points[2][0]},${points[2][1]} ` + `A ${radiusInt},${radiusInt} 0 ${wideAngle ? 1 : 0} 0 ${points[3][0]},${points[3][1]} ` + `L ${points[0][0]},${points[0][1]} `;
|
|
20
|
+
export const convertSessionsToPieces = (sections, radiusRelative)=>{
|
|
21
|
+
const total = sections.reduce((sum, curr)=>sum + curr.value, 0);
|
|
27
22
|
const opacityStep = (1 - lowestOpacity) / (Math.max(sections.length, 2) - 1);
|
|
28
23
|
let angleSum = 0;
|
|
29
24
|
const radiusExt = getRadiusExt(radiusRelative);
|
|
30
25
|
const radiusMid = getRadiusMid(radiusRelative);
|
|
31
|
-
const pieces = sections
|
|
32
|
-
.slice()
|
|
33
|
-
.sort((a, b) => b.value - a.value)
|
|
34
|
-
.map((s, index) => {
|
|
35
|
-
var _a;
|
|
26
|
+
const pieces = sections.slice().sort((a, b)=>b.value - a.value).map((s, index)=>{
|
|
36
27
|
const percent = total ? s.value / total : 0;
|
|
37
28
|
const angle = 2 * Math.PI * percent;
|
|
38
29
|
const angleStart = angleInitial + angleSum;
|
|
39
30
|
const angleMid = angleStart + angle / 2;
|
|
40
31
|
const angleEnd = angleStart + angle;
|
|
41
32
|
const opacity = 1 - opacityStep * index;
|
|
42
|
-
const points = s.value
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
const points = s.value ? [
|
|
34
|
+
[
|
|
35
|
+
radiusExt * Math.sin(angleStart),
|
|
36
|
+
-1 * radiusExt * Math.cos(angleStart)
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
radiusExt * Math.sin(angleEnd),
|
|
40
|
+
-1 * radiusExt * Math.cos(angleEnd)
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
radiusInt * Math.sin(angleEnd),
|
|
44
|
+
-1 * radiusInt * Math.cos(angleEnd)
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
radiusInt * Math.sin(angleStart),
|
|
48
|
+
-1 * radiusInt * Math.cos(angleStart)
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
radiusMid * Math.sin(angleMid),
|
|
52
|
+
-1 * radiusMid * Math.cos(angleMid)
|
|
49
53
|
]
|
|
50
|
-
|
|
54
|
+
] : undefined;
|
|
51
55
|
angleSum += angle;
|
|
56
|
+
var _s_color;
|
|
52
57
|
return {
|
|
53
58
|
id: `pie${index}-${Math.round(Math.random() * 10000)}`,
|
|
54
59
|
key: s.key,
|
|
55
60
|
title: s.title,
|
|
56
61
|
text: formatValue(percent * 100),
|
|
57
62
|
data: s.data,
|
|
58
|
-
color: (
|
|
63
|
+
color: (_s_color = s.color) !== null && _s_color !== void 0 ? _s_color : `rgba(0,76,195,${opacity.toFixed(2)})`,
|
|
59
64
|
opacity,
|
|
60
65
|
value: s.value,
|
|
61
66
|
points,
|
|
62
|
-
path: points
|
|
63
|
-
? convertPointsToPath(points, angleEnd - angleStart >= Math.PI, radiusExt)
|
|
64
|
-
: undefined,
|
|
67
|
+
path: points ? convertPointsToPath(points, angleEnd - angleStart >= Math.PI, radiusExt) : undefined
|
|
65
68
|
};
|
|
66
69
|
});
|
|
67
|
-
if (sections.filter(s
|
|
68
|
-
const piece = pieces.find(p
|
|
70
|
+
if (sections.filter((s)=>!!s.value).length === 1) {
|
|
71
|
+
const piece = pieces.find((p)=>!!p.points);
|
|
69
72
|
if (piece) {
|
|
70
73
|
piece.points = [
|
|
71
|
-
[
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
[
|
|
74
|
+
[
|
|
75
|
+
-radiusExt,
|
|
76
|
+
radiusExt
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
radiusExt,
|
|
80
|
+
radiusExt
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
radiusInt,
|
|
84
|
+
-radiusInt
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
-radiusInt,
|
|
88
|
+
-radiusInt
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
0,
|
|
92
|
+
0
|
|
93
|
+
]
|
|
76
94
|
];
|
|
77
|
-
piece.path =
|
|
78
|
-
`M ${-radiusExt},${0} ` +
|
|
79
|
-
`A ${radiusExt},${radiusExt} 0 1 1 ${radiusExt},${0} ` +
|
|
80
|
-
`A ${radiusExt},${radiusExt} 0 1 1 ${-radiusExt},${0} `;
|
|
95
|
+
piece.path = `M ${-radiusExt},${0} ` + `A ${radiusExt},${radiusExt} 0 1 1 ${radiusExt},${0} ` + `A ${radiusExt},${radiusExt} 0 1 1 ${-radiusExt},${0} `;
|
|
81
96
|
}
|
|
82
97
|
}
|
|
83
98
|
return pieces;
|
|
84
99
|
};
|
|
100
|
+
|
|
85
101
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/pie-chart/utils/const.ts"],"sourcesContent":["import { PiecePoints, PieChartSection, PiePiece } from './interface';\nimport { formatNumber } from 'accounting';\n\nexport const radiusRelativeDefault = 50;\nconst radiusInt = 20;\nconst getRadiusExt = (radiusRelative: number) => radiusRelative - 5; // need to have some space to stroke selected piece\nconst getRadiusMid = (radiusRelative: number) => (3 * radiusRelative) / 4;\n\nconst angleInitial = -0.5;\nconst lowestOpacity = 0.1;\n\nconst formatValue = (val: number): string => {\n if (!val) {\n return '0%';\n }\n\n const valueMain = val ? Math.abs(Math.round(val)) : 0;\n\n if (valueMain > 0) {\n return formatNumber(valueMain, 0) + '%';\n }\n\n const valueDecimal = Math.max(Math.floor(val * 10) - valueMain * 10, 1);\n\n return `0.${valueDecimal}%`;\n};\n\nconst convertPointsToPath = (points: PiecePoints, wideAngle: boolean, radiusExt: number): string =>\n `M ${points[3][0]},${points[3][1]} ` +\n `L ${points[0][0]},${points[0][1]} ` +\n `A ${radiusExt},${radiusExt} 0 ${wideAngle ? 1 : 0} 1 ${points[1][0]},${points[1][1]} ` +\n `L ${points[2][0]},${points[2][1]} ` +\n `A ${radiusInt},${radiusInt} 0 ${wideAngle ? 1 : 0} 0 ${points[3][0]},${points[3][1]} ` +\n `L ${points[0][0]},${points[0][1]} `;\n\nexport const convertSessionsToPieces = <T>(\n sections: PieChartSection<T>[],\n radiusRelative: number\n): PiePiece<T>[] => {\n const total = sections.reduce((sum, curr) => sum + curr.value, 0);\n const opacityStep = (1 - lowestOpacity) / (Math.max(sections.length, 2) - 1);\n let angleSum = 0;\n const radiusExt = getRadiusExt(radiusRelative);\n const radiusMid = getRadiusMid(radiusRelative);\n\n const pieces = sections\n .slice()\n .sort((a, b) => b.value - a.value)\n .map((s, index) => {\n const percent = total ? s.value / total : 0;\n const angle = 2 * Math.PI * percent;\n const angleStart = angleInitial + angleSum;\n const angleMid = angleStart + angle / 2;\n const angleEnd = angleStart + angle;\n const opacity = 1 - opacityStep * index;\n\n const points: PiecePoints | undefined = s.value\n ? [\n [radiusExt * Math.sin(angleStart), -1 * radiusExt * Math.cos(angleStart)],\n [radiusExt * Math.sin(angleEnd), -1 * radiusExt * Math.cos(angleEnd)],\n [radiusInt * Math.sin(angleEnd), -1 * radiusInt * Math.cos(angleEnd)],\n [radiusInt * Math.sin(angleStart), -1 * radiusInt * Math.cos(angleStart)],\n [radiusMid * Math.sin(angleMid), -1 * radiusMid * Math.cos(angleMid)],\n ]\n : undefined;\n\n angleSum += angle;\n\n return {\n id: `pie${index}-${Math.round(Math.random() * 10000)}`,\n key: s.key,\n title: s.title,\n text: formatValue(percent * 100),\n data: s.data,\n color: s.color ?? `rgba(0,76,195,${opacity.toFixed(2)})`,\n opacity,\n value: s.value,\n points,\n path: points\n ? convertPointsToPath(points, angleEnd - angleStart >= Math.PI, radiusExt)\n : undefined,\n };\n });\n\n if (sections.filter(s => !!s.value).length === 1) {\n const piece = pieces.find(p => !!p.points);\n\n if (piece) {\n piece.points = [\n [-radiusExt, radiusExt],\n [radiusExt, radiusExt],\n [radiusInt, -radiusInt],\n [-radiusInt, -radiusInt],\n [0, 0],\n ];\n\n piece.path =\n `M ${-radiusExt},${0} ` +\n `A ${radiusExt},${radiusExt} 0 1 1 ${radiusExt},${0} ` +\n `A ${radiusExt},${radiusExt} 0 1 1 ${-radiusExt},${0} `;\n }\n }\n\n return pieces;\n};\n"],"names":["formatNumber","radiusRelativeDefault","radiusInt","getRadiusExt","radiusRelative","getRadiusMid","angleInitial","lowestOpacity","formatValue","val","valueMain","Math","abs","round","valueDecimal","max","floor","convertPointsToPath","points","wideAngle","radiusExt","convertSessionsToPieces","sections","total","reduce","sum","curr","value","opacityStep","length","angleSum","radiusMid","pieces","slice","sort","a","b","map","s","index","percent","angle","PI","angleStart","angleMid","angleEnd","opacity","sin","cos","undefined","id","random","key","title","text","data","color","toFixed","path","filter","piece","find","p"],"mappings":"AACA,SAASA,YAAY,QAAQ,aAAa;AAE1C,OAAO,MAAMC,wBAAwB,GAAG;AACxC,MAAMC,YAAY;AAClB,MAAMC,eAAe,CAACC,iBAA2BA,iBAAiB,GAAG,mDAAmD;AACxH,MAAMC,eAAe,CAACD,iBAA2B,AAAC,IAAIA,iBAAkB;AAExE,MAAME,eAAe,CAAC;AACtB,MAAMC,gBAAgB;AAEtB,MAAMC,cAAc,CAACC;IACjB,IAAI,CAACA,KAAK;QACN,OAAO;IACX;IAEA,MAAMC,YAAYD,MAAME,KAAKC,GAAG,CAACD,KAAKE,KAAK,CAACJ,QAAQ;IAEpD,IAAIC,YAAY,GAAG;QACf,OAAOV,aAAaU,WAAW,KAAK;IACxC;IAEA,MAAMI,eAAeH,KAAKI,GAAG,CAACJ,KAAKK,KAAK,CAACP,MAAM,MAAMC,YAAY,IAAI;IAErE,OAAO,CAAC,EAAE,EAAEI,aAAa,CAAC,CAAC;AAC/B;AAEA,MAAMG,sBAAsB,CAACC,QAAqBC,WAAoBC,YAClE,CAAC,EAAE,EAAEF,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAEA,MAAM,CAAC,EAAE,CAAC,EAAE,CA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,cAAchC,KAAK+B,EAAE,EAAEtB,aAC9D6B;QACV;IACJ;IAEJ,IAAI3B,SAASqC,MAAM,CAACrB,CAAAA,IAAK,CAAC,CAACA,EAAEX,KAAK,EAAEE,MAAM,KAAK,GAAG;QAC9C,MAAM+B,QAAQ5B,OAAO6B,IAAI,CAACC,CAAAA,IAAK,CAAC,CAACA,EAAE5C,MAAM;QAEzC,IAAI0C,OAAO;YACPA,MAAM1C,MAAM,GAAG;gBACX;oBAAC,CAACE;oBAAWA;iBAAU;gBACvB;oBAACA;oBAAWA;iBAAU;gBACtB;oBAAClB;oBAAW,CAACA;iBAAU;gBACvB;oBAAC,CAACA;oBAAW,CAACA;iBAAU;gBACxB;oBAAC;oBAAG;iBAAE;aACT;YAED0D,MAAMF,IAAI,GACN,CAAC,EAAE,EAAE,CAACtC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,GACvB,CAAC,EAAE,EAAEA,UAAU,CAAC,EAAEA,UAAU,OAAO,EAAEA,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,GACtD,CAAC,EAAE,EAAEA,UAAU,CAAC,EAAEA,UAAU,OAAO,EAAE,CAACA,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/D;IACJ;IAEA,OAAOY;AACX,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/charts/pie-chart/utils/interface.ts"],"sourcesContent":["import { FC } from 'react';\n\nexport interface PieChartSection<T> {\n key?: string;\n title: string;\n value: number;\n color?: string;\n data?: T;\n}\n\nexport type PieChartPopoverContentType<T = any> = FC<{\n index: number;\n value: number;\n data?: T;\n text: string;\n}>;\n\nexport interface PieChartProps<T = any> {\n title: string;\n sections: PieChartSection<T>[];\n popoverContent?: PieChartPopoverContentType<T>;\n popoverDirection?: PopoverDirection;\n content?: FC<T>;\n height?: number;\n width?: number;\n radiusRelative?: number;\n hideTitles?: boolean;\n}\n\nexport type PiecePoint = [number, number];\nexport type PiecePoints = [PiecePoint, PiecePoint, PiecePoint, PiecePoint, PiecePoint];\n\nexport interface PiePiece<T = undefined> {\n id: string;\n title: string;\n color: string;\n text: string;\n data?: T;\n opacity: number;\n value: number;\n points?: PiecePoints;\n path?: string;\n key?: string;\n}\n\nexport type PopoverDirection =\n | 't'\n | 'tr'\n | 'tl'\n | 'r'\n | 'rt'\n | 'rb'\n | 'b'\n | 'br'\n | 'bl'\n | 'l'\n | 'lt'\n | 'lb'\n | 'c';\n"],"names":[],"mappings":"AA6CA,WAaU"}
|