UNPKG

@onesy/ui-react

Version:
283 lines 9.79 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["tonal", "color", "names", "values", "animate", "animateTimeout", "tooltipRender", "tooltipGroupRender", "className"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { c as _c } from "react/compiler-runtime"; import React from 'react'; import { is } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import ChartElement from '../Chart'; import LineElement from '../Line'; import TypeElement from '../Type'; import SurfaceElement from '../Surface'; import BubbleChartItemElement from '../BubbleChartItem'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: { '& .onesy-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: 'onesy-BubbleChart' }); const BubbleChart = props_ => { const $ = _c(10); const theme = useOnesyTheme(); const l = theme.l; const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyBubbleChart?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const Chart = theme?.elements?.Chart || ChartElement; const Type = theme?.elements?.Type || TypeElement; const Surface = theme?.elements?.Surface || SurfaceElement; const BubbleChartItem = theme?.elements?.BubbleChartItem || BubbleChartItemElement; const { tonal: t0, color: t1, names, values, animate, animateTimeout, tooltipRender: tooltipRender_, tooltipGroupRender: tooltipGroupRender_, className } = props, other = _objectWithoutProperties(props, _excluded); const tonal = t0 === undefined ? true : t0; const color = t1 === undefined ? "primary" : t1; const { classes } = useStyle(); const tooltipRender = is("function", tooltipRender_) ? tooltipRender_ : values_ => { const { values: values__ } = values_; return { element: /*#__PURE__*/_jsxs(Line, { tonal: tonal, color: color, elevation: 1, gap: 0.5, direction: "column", Component: Surface, className: classNames([staticClassName("BubbleChart", theme) && ["onesy-BubbleChart-append"], classes.append]), children: [/*#__PURE__*/_jsx(Line, { gap: 1, direction: "row", align: "center", children: /*#__PURE__*/_jsx(Type, { version: "b3", children: values__?.[3] }) }), /*#__PURE__*/_jsxs(Line, { gap: 0.4, direction: "column", children: [/*#__PURE__*/_jsxs(Line, { gap: 1, direction: "row", align: "center", children: [/*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: names?.y || "y" }), /*#__PURE__*/_jsx(Type, { version: "b3", children: values__?.[1] })] }), /*#__PURE__*/_jsxs(Line, { gap: 1, direction: "row", align: "center", children: [/*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: names?.x || "x" }), /*#__PURE__*/_jsx(Type, { version: "b3", children: values__?.[0] })] }), /*#__PURE__*/_jsxs(Line, { gap: 1, direction: "row", align: "center", children: [/*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: names?.size || "Size" }), /*#__PURE__*/_jsx(Type, { version: "b3", children: values__?.[2] })] })] })] }) }; }; const tooltipGroupRender = is("function", tooltipGroupRender_) ? tooltipGroupRender_ : (groups, groupsSorted) => /*#__PURE__*/_jsx(Line, { tonal: tonal, color: color, elevation: 1, gap: 0.25, direction: "column", Component: Surface, className: classNames([staticClassName("BubbleChart", theme) && ["onesy-BubbleChart-append"], classes.append]), children: /*#__PURE__*/_jsxs(Line, { gap: 1, direction: "column", style: { width: "100%" }, children: [/*#__PURE__*/_jsxs(Line, { gap: 1, direction: "row", align: "center", children: [/*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: l("Label") }), /*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: names?.y || "y" }), /*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: names?.x || "x" }), /*#__PURE__*/_jsx(Type, { version: "b3", style: { fontWeight: 600 }, children: names?.size || l("Size") })] }), /*#__PURE__*/_jsx(Line, { gap: 1, direction: "column", children: groupsSorted.map((group, index) => /*#__PURE__*/_jsxs(Line, { gap: 1, direction: "column", style: { width: "100%" }, children: [/*#__PURE__*/_jsx("span", { className: classNames([staticClassName("BubbleChart", theme) && ["onesy-BubbleChart-append-icon"], classes.append_icon]), style: { background: !theme.palette.color[group] ? group : theme.palette.color[group][groups[group][0]?.item?.tone || "main"] } }), /*#__PURE__*/_jsx(Line, { gap: 0, direction: "column", style: { width: "100%" }, children: groups[group].map((item, index_) => /*#__PURE__*/_jsxs(Line, { gap: 1, direction: "row", style: { width: "100%" }, children: [/*#__PURE__*/_jsx(Type, { version: "b3", children: item?.values?.[3] }), /*#__PURE__*/_jsx(Type, { version: "b3", children: item?.values?.[1] }), /*#__PURE__*/_jsx(Type, { version: "b3", children: item?.values?.[0] }), /*#__PURE__*/_jsx(Type, { version: "b3", children: item?.values?.[2] })] }, index_)) })] }, index)) })] }) }); values.sort(_temp); const minSize = values[0]?.values?.[2]; const maxSize = values[values.length - 1]?.values?.[2]; const t2 = "hidden"; const t3 = true; const t4 = classNames([staticClassName("BubbleChart", theme) && ["onesy-BubbleChart-root"], className, classes.root]); const t5 = is("array", values) && values.map((item_0, index_0) => /*#__PURE__*/_jsx(BubbleChartItem, _objectSpread({ animate: animate, animateTimeout: animateTimeout, minSize: minSize, maxSize: maxSize }, item_0), index_0)); let t6; if ($[0] !== Chart || $[1] !== color || $[2] !== other || $[3] !== t4 || $[4] !== t5 || $[5] !== tonal || $[6] !== tooltipGroupRender || $[7] !== tooltipRender || $[8] !== values) { t6 = /*#__PURE__*/_jsx(Chart, _objectSpread(_objectSpread({ tonal: tonal, color: color, values: values, pointsVisibility: t2, elementTooltip: t3, tooltipRender: tooltipRender, tooltipGroupRender: tooltipGroupRender, className: t4 }, other), {}, { children: t5 })); $[0] = Chart; $[1] = color; $[2] = other; $[3] = t4; $[4] = t5; $[5] = tonal; $[6] = tooltipGroupRender; $[7] = tooltipRender; $[8] = values; $[9] = t6; } else { t6 = $[9]; } return t6; }; BubbleChart.displayName = 'onesy-BubbleChart'; export default BubbleChart; function _temp(a, b) { return a.values?.[2] - b.values?.[2]; }