@onesy/ui-react
Version:
UI for React
298 lines (297 loc) • 14 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _compilerRuntime = require("react/compiler-runtime");
var _react = _interopRequireDefault(require("react"));
var _utils = require("@onesy/utils");
var _styleReact = require("@onesy/style-react");
var _Chart = _interopRequireDefault(require("../Chart"));
var _Line = _interopRequireDefault(require("../Line"));
var _Type = _interopRequireDefault(require("../Type"));
var _Surface = _interopRequireDefault(require("../Surface"));
var _BubbleChartItem = _interopRequireDefault(require("../BubbleChartItem"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
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) { (0, _defineProperty2.default)(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; }
const useStyle = (0, _styleReact.style)(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_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3, _theme$elements4, _theme$elements5, _values$, _values;
const $ = (0, _compilerRuntime.c)(10);
const theme = (0, _styleReact.useOnesyTheme)();
const l = theme.l;
const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesyBubbleChart) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
const Chart = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Chart) || _Chart.default;
const Type = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Type) || _Type.default;
const Surface = (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.Surface) || _Surface.default;
const BubbleChartItem = (theme === null || theme === void 0 || (_theme$elements5 = theme.elements) === null || _theme$elements5 === void 0 ? void 0 : _theme$elements5.BubbleChartItem) || _BubbleChartItem.default;
const {
tonal: t0,
color: t1,
names,
values,
animate,
animateTimeout,
tooltipRender: tooltipRender_,
tooltipGroupRender: tooltipGroupRender_,
className
} = props,
other = (0, _objectWithoutProperties2.default)(props, _excluded);
const tonal = t0 === undefined ? true : t0;
const color = t1 === undefined ? "primary" : t1;
const {
classes
} = useStyle();
const tooltipRender = (0, _utils.is)("function", tooltipRender_) ? tooltipRender_ : values_ => {
const {
values: values__
} = values_;
return {
element: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
tonal: tonal,
color: color,
elevation: 1,
gap: 0.5,
direction: "column",
Component: Surface,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)("BubbleChart", theme) && ["onesy-BubbleChart-append"], classes.append]),
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
gap: 1,
direction: "row",
align: "center",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: values__ === null || values__ === void 0 ? void 0 : values__[3]
})
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 0.4,
direction: "column",
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "row",
align: "center",
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: (names === null || names === void 0 ? void 0 : names.y) || "y"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: values__ === null || values__ === void 0 ? void 0 : values__[1]
})]
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "row",
align: "center",
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: (names === null || names === void 0 ? void 0 : names.x) || "x"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: values__ === null || values__ === void 0 ? void 0 : values__[0]
})]
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "row",
align: "center",
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: (names === null || names === void 0 ? void 0 : names.size) || "Size"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: values__ === null || values__ === void 0 ? void 0 : values__[2]
})]
})]
})]
})
};
};
const tooltipGroupRender = (0, _utils.is)("function", tooltipGroupRender_) ? tooltipGroupRender_ : (groups, groupsSorted) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
tonal: tonal,
color: color,
elevation: 1,
gap: 0.25,
direction: "column",
Component: Surface,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)("BubbleChart", theme) && ["onesy-BubbleChart-append"], classes.append]),
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "column",
style: {
width: "100%"
},
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "row",
align: "center",
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: l("Label")
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: (names === null || names === void 0 ? void 0 : names.y) || "y"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: (names === null || names === void 0 ? void 0 : names.x) || "x"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
style: {
fontWeight: 600
},
children: (names === null || names === void 0 ? void 0 : names.size) || l("Size")
})]
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
gap: 1,
direction: "column",
children: groupsSorted.map((group, index) => {
var _groups$group$;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "column",
style: {
width: "100%"
},
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)("BubbleChart", theme) && ["onesy-BubbleChart-append-icon"], classes.append_icon]),
style: {
background: !theme.palette.color[group] ? group : theme.palette.color[group][((_groups$group$ = groups[group][0]) === null || _groups$group$ === void 0 || (_groups$group$ = _groups$group$.item) === null || _groups$group$ === void 0 ? void 0 : _groups$group$.tone) || "main"]
}
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
gap: 0,
direction: "column",
style: {
width: "100%"
},
children: groups[group].map((item, index_) => {
var _item$values, _item$values2, _item$values3, _item$values4;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 1,
direction: "row",
style: {
width: "100%"
},
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: item === null || item === void 0 || (_item$values = item.values) === null || _item$values === void 0 ? void 0 : _item$values[3]
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: item === null || item === void 0 || (_item$values2 = item.values) === null || _item$values2 === void 0 ? void 0 : _item$values2[1]
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: item === null || item === void 0 || (_item$values3 = item.values) === null || _item$values3 === void 0 ? void 0 : _item$values3[0]
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "b3",
children: item === null || item === void 0 || (_item$values4 = item.values) === null || _item$values4 === void 0 ? void 0 : _item$values4[2]
})]
}, index_);
})
})]
}, index);
})
})]
})
});
values.sort(_temp);
const minSize = (_values$ = values[0]) === null || _values$ === void 0 || (_values$ = _values$.values) === null || _values$ === void 0 ? void 0 : _values$[2];
const maxSize = (_values = values[values.length - 1]) === null || _values === void 0 || (_values = _values.values) === null || _values === void 0 ? void 0 : _values[2];
const t2 = "hidden";
const t3 = true;
const t4 = (0, _styleReact.classNames)([(0, _utils2.staticClassName)("BubbleChart", theme) && ["onesy-BubbleChart-root"], className, classes.root]);
const t5 = (0, _utils.is)("array", values) && values.map((item_0, index_0) => /*#__PURE__*/(0, _jsxRuntime.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__*/(0, _jsxRuntime.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';
var _default = exports.default = BubbleChart;
function _temp(a, b) {
var _a$values, _b$values;
return ((_a$values = a.values) === null || _a$values === void 0 ? void 0 : _a$values[2]) - ((_b$values = b.values) === null || _b$values === void 0 ? void 0 : _b$values[2]);
}