@lobehub/charts
Version:
React modern charts components built on recharts
72 lines • 5.01 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _templateObject;
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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
import { Tooltip } from '@lobehub/ui';
import { keyframes } from 'antd-style';
import { Fragment, memo } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var Calendar = /*#__PURE__*/memo(function (_ref) {
var weeks = _ref.weeks,
maxLevel = _ref.maxLevel,
enableAnimation = _ref.enableAnimation,
colorScale = _ref.colorScale,
blockSize = _ref.blockSize,
blockRadius = _ref.blockRadius,
blockMargin = _ref.blockMargin,
labelHeight = _ref.labelHeight,
showTooltip = _ref.showTooltip,
customTooltip = _ref.customTooltip,
labels = _ref.labels,
onValueChange = _ref.onValueChange;
return /*#__PURE__*/_jsx(_Fragment, {
children: weeks.map(function (week, weekIndex) {
return week.map(function (activity, dayIndex) {
if (!activity) {
return null;
}
if (activity.level < 0 || activity.level > maxLevel) {
throw new RangeError("Provided activity level ".concat(activity.level, " for ").concat(activity.date, " is out of range. It must be between 0 and ").concat(maxLevel, "."));
}
var style = enableAnimation ? {
animation: "".concat(keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n fill: var(--lobe-heatmaps-loading);\n }\n 50% {\n fill: var(--lobe-heatmaps-loading-active);\n }\n 100% {\n fill: var(--lobe-heatmaps-loading);\n }\n "]))), " 1.75s ease-in-out infinite"),
animationDelay: "".concat(weekIndex * 20 + dayIndex * 20, "ms")
} : undefined;
var block = /*#__PURE__*/_jsx("rect", {
"data-date": activity.date,
"data-level": activity.level,
fill: colorScale[activity.level],
height: blockSize,
onClick: function onClick() {
return onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(activity);
},
rx: blockRadius,
ry: blockRadius,
style: _objectSpread({
cursor: onValueChange ? 'pointer' : undefined
}, style),
width: blockSize,
x: 0,
y: labelHeight + (blockSize + blockMargin) * dayIndex
});
return /*#__PURE__*/_jsx(Fragment, {
children: showTooltip ? /*#__PURE__*/_jsx(Tooltip, {
title: customTooltip ? customTooltip(activity) : labels.tooltip ? labels.tooltip.replace('{{count}}', String(activity.count)).replace('{{date}}', String(activity.date)) : "".concat(activity.count, " activities on ").concat(activity.date),
children: block
}) : block
}, activity.date);
});
}).map(function (week, x) {
return /*#__PURE__*/_jsx("g", {
transform: "translate(".concat((blockSize + blockMargin) * x, ", 0)"),
children: week
}, x);
})
});
});
export default Calendar;