UNPKG

@amaui/ui-react

Version:
138 lines (137 loc) 12.6 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const utils_1 = require("@amaui/utils"); const style_react_1 = require("@amaui/style-react"); const Chart_1 = __importDefault(require("../Chart")); const Line_1 = __importDefault(require("../Line")); const Type_1 = __importDefault(require("../Type")); const Surface_1 = __importDefault(require("../Surface")); const BubbleChartItem_1 = __importDefault(require("../BubbleChartItem")); const utils_2 = require("../utils"); const useStyle = (0, style_react_1.style)(theme => ({ root: { '& .amaui-Chart-legend-icon': { position: 'relative', background: 'none !important', border: '2px solid currentColor', '&::before': { content: "''", position: 'absolute', top: '0', left: '0', height: '100%', width: '100%', borderRadius: 'inherit', background: 'currentColor', opacity: '0.14' } } }, append_wrapper: { userSelect: 'none', pointerEvents: 'none' }, append: { padding: `${theme.methods.space.value(1.5, 'px')} ${theme.methods.space.value(2.5, 'px')}`, borderRadius: theme.methods.shape.radius.value(1.5, 'px') }, append_icon: { width: '8px', height: '8px', borderRadius: theme.methods.shape.radius.value(40, 'px') } }), { name: 'amaui-BubbleChart' }); const BubbleChart = react_1.default.forwardRef((props_, ref) => { var _a, _b, _c, _d; const theme = (0, style_react_1.useAmauiTheme)(); const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.amauiBubbleChart) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]); const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]); const Chart = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Chart) || Chart_1.default; }, [theme]); const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]); const Surface = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Surface) || Surface_1.default; }, [theme]); const BubbleChartItem = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.BubbleChartItem) || BubbleChartItem_1.default; }, [theme]); const { tonal = true, color = 'primary', names, values, animate, animateTimeout, tooltipRender: tooltipRender_, tooltipGroupRender: tooltipGroupRender_, className } = props, other = __rest(props, ["tonal", "color", "names", "values", "animate", "animateTimeout", "tooltipRender", "tooltipGroupRender", "className"]); const { classes } = useStyle(); const tooltipRender = (0, utils_1.is)('function', tooltipRender_) ? tooltipRender_ : (values_) => { const { values: values__ } = values_; return { element: ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ tonal: tonal, color: color, elevation: 1, gap: 0.5, direction: 'column', Component: Surface, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('BubbleChart', theme) && [ 'amaui-BubbleChart-append' ], classes.append ]) }, { children: [(0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center' }, { children: (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: values__ === null || values__ === void 0 ? void 0 : values__[3] })) })), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.4, direction: 'column' }, { children: [(0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center' }, { children: [(0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: (names === null || names === void 0 ? void 0 : names.y) || 'y' })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: values__ === null || values__ === void 0 ? void 0 : values__[1] }))] })), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center' }, { children: [(0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: (names === null || names === void 0 ? void 0 : names.x) || 'x' })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: values__ === null || values__ === void 0 ? void 0 : values__[0] }))] })), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center' }, { children: [(0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: (names === null || names === void 0 ? void 0 : names.size) || 'Size' })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: values__ === null || values__ === void 0 ? void 0 : values__[2] }))] }))] }))] }))) }; }; const tooltipGroupRender = (0, utils_1.is)('function', tooltipGroupRender_) ? tooltipGroupRender_ : (groups, groupsSorted) => { return ((0, jsx_runtime_1.jsx)(Line, Object.assign({ tonal: tonal, color: color, elevation: 1, gap: 0.25, direction: 'column', Component: Surface, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('BubbleChart', theme) && [ 'amaui-BubbleChart-append' ], classes.append ]) }, { children: (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'column', style: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center' }, { children: [(0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: "Label" })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: (names === null || names === void 0 ? void 0 : names.y) || 'y' })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: (names === null || names === void 0 ? void 0 : names.x) || 'x' })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', style: { fontWeight: 600 } }, { children: (names === null || names === void 0 ? void 0 : names.size) || 'Size' }))] })), (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 1, direction: 'column' }, { children: groupsSorted.map((group, index) => { var _a, _b; return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'column', style: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsx)("span", { className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('BubbleChart', theme) && [ 'amaui-BubbleChart-append-icon' ], classes.append_icon ]), style: { background: !theme.palette.color[group] ? group : theme.palette.color[group][((_b = (_a = groups[group][0]) === null || _a === void 0 ? void 0 : _a.item) === null || _b === void 0 ? void 0 : _b.tone) || 'main'] } }), (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 0, direction: 'column', style: { width: '100%' } }, { children: groups[group].map((item, index_) => { var _a, _b, _c, _d; return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', style: { width: '100%' } }, { children: [(0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: (_a = item === null || item === void 0 ? void 0 : item.values) === null || _a === void 0 ? void 0 : _a[3] })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: (_b = item === null || item === void 0 ? void 0 : item.values) === null || _b === void 0 ? void 0 : _b[1] })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: (_c = item === null || item === void 0 ? void 0 : item.values) === null || _c === void 0 ? void 0 : _c[0] })), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: (_d = item === null || item === void 0 ? void 0 : item.values) === null || _d === void 0 ? void 0 : _d[2] }))] }), index_)); }) }))] }), index)); }) }))] })) }))); }; values.sort((a, b) => { var _a, _b; return ((_a = a.values) === null || _a === void 0 ? void 0 : _a[2]) - ((_b = b.values) === null || _b === void 0 ? void 0 : _b[2]); }); const minSize = (_b = (_a = values[0]) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b[2]; const maxSize = (_d = (_c = values[values.length - 1]) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[2]; return ((0, jsx_runtime_1.jsx)(Chart, Object.assign({ ref: ref, tonal: tonal, color: color, values: values, pointsVisibility: 'hidden', elementTooltip: true, tooltipRender: tooltipRender, tooltipGroupRender: tooltipGroupRender, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('BubbleChart', theme) && [ 'amaui-BubbleChart-root' ], className, classes.root ]) }, other, { children: (0, utils_1.is)('array', values) && values.map((item, index) => ((0, jsx_runtime_1.jsx)(BubbleChartItem, Object.assign({ animate: animate, animateTimeout: animateTimeout, minSize: minSize, maxSize: maxSize }, item), index))) }))); }); BubbleChart.displayName = 'amaui-BubbleChart'; exports.default = BubbleChart;