Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uiw/react-heat-map

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uiw/react-heat-map - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

21

cjs/index.js

@@ -7,9 +7,11 @@ "use strict";

exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {};
exports.default = HeatMap;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

@@ -24,3 +26,8 @@ var _react = _interopRequireDefault(require("react"));

if (key in exports && exports[key] === _SVG[key]) return;
exports[key] = _SVG[key];
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _SVG[key];
}
});
});

@@ -36,10 +43,8 @@

className = props.className,
others = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
others = (0, _objectWithoutProperties2.default)(props, _excluded);
var cls = [className, prefixCls].filter(Boolean).join(' ');
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SVG.default, (0, _extends2.default)({
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SVG.default, (0, _objectSpread2.default)({
className: cls
}, others));
}
module.exports = exports.default;
//# sourceMappingURL=index.js.map

@@ -5,5 +5,11 @@ "use strict";

exports.__esModule = true;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LablesMonth = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _react = _interopRequireWildcard(require("react"));

@@ -29,3 +35,3 @@

if (monthLables === false || colNum < 1) return [];
return [].concat(Array(colNum * 7)).map(function (_, idx) {
return (0, _toConsumableArray2.default)(Array(colNum * 7)).map(function (_, idx) {
if (idx / 7 % 1 === 0) {

@@ -51,3 +57,3 @@ var date = new Date(startDate.getTime() + idx * _utils.oneDayTime);

return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
children: [].concat(data).map(function (item, idx) {
children: (0, _toConsumableArray2.default)(data).map(function (item, idx) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", {

@@ -54,0 +60,0 @@ "data-size": rectSize,

@@ -5,5 +5,11 @@ "use strict";

exports.__esModule = true;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LablesWeek = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _react = _interopRequireWildcard(require("react"));

@@ -24,3 +30,3 @@

return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
children: [].concat(Array(7)).map(function (_, idx) {
children: (0, _toConsumableArray2.default)(Array(7)).map(function (_, idx) {
if (weekLables && weekLables[idx]) {

@@ -27,0 +33,0 @@ return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", {

@@ -7,8 +7,10 @@ "use strict";

exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Legend;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

@@ -36,3 +38,3 @@ var _react = _interopRequireWildcard(require("react"));

legendRender = _ref.legendRender,
props = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
var size = legendCellSize || rectSize;

@@ -42,3 +44,3 @@ return (0, _react.useMemo)(function () {

children: Object.keys(panelColors || {}).map(function (num, key) {
var rectProps = (0, _extends2.default)({}, props, {
var rectProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
key: key,

@@ -52,3 +54,3 @@ x: (size + 1) * key + leftPad,

if (legendRender) return legendRender(rectProps);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Rect.Rect, (0, _extends2.default)({}, rectProps));
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Rect.Rect, (0, _objectSpread2.default)({}, rectProps));
})

@@ -58,4 +60,2 @@ });

}
module.exports = exports.default;
//# sourceMappingURL=Legend.js.map

@@ -5,6 +5,8 @@ "use strict";

exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Rect = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

@@ -16,3 +18,3 @@ var _react = _interopRequireDefault(require("react"));

var Rect = function Rect(props) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", (0, _extends2.default)({}, props));
return /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", (0, _objectSpread2.default)({}, props));
};

@@ -19,0 +21,0 @@

@@ -7,9 +7,15 @@ "use strict";

exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SVG;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));

@@ -59,15 +65,18 @@

} : _ref$panelColors,
other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
other = (0, _objectWithoutProperties2.default)(_ref, _excluded);
var _useState = (0, _react.useState)(0),
gridNum = _useState[0],
setGridNum = _useState[1];
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
gridNum = _useState2[0],
setGridNum = _useState2[1];
var _useState2 = (0, _react.useState)(!!weekLables ? 28 : 5),
leftPad = _useState2[0],
setLeftPad = _useState2[1];
var _useState3 = (0, _react.useState)(!!weekLables ? 28 : 5),
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
leftPad = _useState4[0],
setLeftPad = _useState4[1];
var _useState3 = (0, _react.useState)(!!monthLables ? 20 : 5),
topPad = _useState3[0],
setTopPad = _useState3[1];
var _useState5 = (0, _react.useState)(!!monthLables ? 20 : 5),
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
topPad = _useState6[0],
setTopPad = _useState6[1];

@@ -104,5 +113,5 @@ var svgRef = /*#__PURE__*/_react.default.createRef();

}, [startDate]);
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", (0, _extends2.default)({
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", (0, _objectSpread2.default)((0, _objectSpread2.default)({
ref: svgRef
}, other, {
}, other), {}, {
children: [legendCellSize !== 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Legend.default, {

@@ -129,8 +138,8 @@ legendRender: legendRender,

}), /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
transform: "translate(" + leftPad + ", " + topPad + ")",
children: gridNum > 0 && [].concat(Array(gridNum)).map(function (_, idx) {
transform: "translate(".concat(leftPad, ", ").concat(topPad, ")"),
children: gridNum > 0 && (0, _toConsumableArray2.default)(Array(gridNum)).map(function (_, idx) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
"data-column": idx,
children: [].concat(Array(7)).map(function (_, cidx) {
var dayProps = (0, _extends2.default)({}, rectProps, {
children: (0, _toConsumableArray2.default)(Array(7)).map(function (_, cidx) {
var dayProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, rectProps), {}, {
key: cidx,

@@ -145,3 +154,3 @@ fill: '#EBEDF0',

var date = (0, _utils.getDateToString)(currentDate);
var dataProps = (0, _extends2.default)({}, data[date], {
var dataProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data[date]), {}, {
date: date,

@@ -164,3 +173,3 @@ row: cidx,

if (rectRender && typeof rectRender === 'function') {
var elm = rectRender((0, _extends2.default)({}, dayProps, {
var elm = rectRender((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dayProps), {}, {
key: cidx

@@ -174,3 +183,3 @@ }), dataProps);

return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Rect.Rect, (0, _extends2.default)({}, dayProps, {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Rect.Rect, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, dayProps), {}, {
"data-date": date,

@@ -187,4 +196,2 @@ "data-index": dataProps.index,

}
module.exports = exports.default;
//# sourceMappingURL=SVG.js.map
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isValidDate = isValidDate;

@@ -18,10 +20,7 @@ exports.getDateToString = getDateToString;

function getDateToString(date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
return "".concat(date.getFullYear(), "/").concat(date.getMonth() + 1, "/").concat(date.getDate());
}
function formatData(data) {
if (data === void 0) {
data = [];
}
function formatData() {
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var result = {};

@@ -39,7 +38,4 @@ data.forEach(function (item) {

function numberSort(keys) {
if (keys === void 0) {
keys = [];
}
function numberSort() {
var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
return keys.sort(function (x, y) {

@@ -51,11 +47,6 @@ if (x < y) return -1;else if (x > y) return 1;

function existColor(num, nums, panelColors) {
if (num === void 0) {
num = 0;
}
if (panelColors === void 0) {
panelColors = {};
}
function existColor() {
var num = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var nums = arguments.length > 1 ? arguments[1] : undefined;
var panelColors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var color = '';

@@ -62,0 +53,0 @@

@@ -1,17 +0,47 @@

import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {};
exports.default = HeatMap;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireDefault(require("react"));
var _SVG = _interopRequireWildcard(require("./SVG"));
Object.keys(_SVG).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _SVG[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _SVG[key];
}
});
});
require("./style/index.css");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["prefixCls", "className"];
import React from 'react';
import SVG from './SVG';
import "./style/index.css";
import { jsx as _jsx } from "react/jsx-runtime";
export * from './SVG';
export default function HeatMap(props) {
var _props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? 'w-heatmap' : _props$prefixCls,
className = props.className,
others = _objectWithoutPropertiesLoose(props, _excluded);
function HeatMap(props) {
var {
prefixCls = 'w-heatmap',
className
} = props,
others = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
var cls = [className, prefixCls].filter(Boolean).join(' ');
return /*#__PURE__*/_jsx(SVG, _extends({
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SVG.default, (0, _extends2.default)({
className: cls

@@ -18,0 +48,0 @@ }, others));

@@ -1,21 +0,30 @@

import React, { Fragment, useMemo } from 'react';
import { oneDayTime } from './utils';
import { jsx as _jsx } from "react/jsx-runtime";
export var LablesMonth = function LablesMonth(_ref) {
var _ref$monthLables = _ref.monthLables,
monthLables = _ref$monthLables === void 0 ? [] : _ref$monthLables,
_ref$rectSize = _ref.rectSize,
rectSize = _ref$rectSize === void 0 ? 0 : _ref$rectSize,
_ref$space = _ref.space,
space = _ref$space === void 0 ? 0 : _ref$space,
_ref$leftPad = _ref.leftPad,
leftPad = _ref$leftPad === void 0 ? 0 : _ref$leftPad,
_ref$colNum = _ref.colNum,
colNum = _ref$colNum === void 0 ? 0 : _ref$colNum,
startDate = _ref.startDate;
var data = useMemo(function () {
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LablesMonth = void 0;
var _react = _interopRequireWildcard(require("react"));
var _utils = require("./utils");
var _jsxRuntime = require("react/jsx-runtime");
var LablesMonth = _ref => {
var {
monthLables = [],
rectSize = 0,
space = 0,
leftPad = 0,
colNum = 0,
startDate
} = _ref;
var data = (0, _react.useMemo)(() => {
if (monthLables === false || colNum < 1) return [];
return [].concat(Array(colNum * 7)).map(function (_, idx) {
return [...Array(colNum * 7)].map((_, idx) => {
if (idx / 7 % 1 === 0) {
var date = new Date(startDate.getTime() + idx * oneDayTime);
var date = new Date(startDate.getTime() + idx * _utils.oneDayTime);
var month = date.getMonth();

@@ -25,6 +34,6 @@ return {

index: idx,
month: month,
month,
day: date.getDate(),
monthStr: monthLables[month],
date: date
date
};

@@ -34,21 +43,19 @@ }

return null;
}).filter(Boolean).filter(function (item, idx, list) {
return list[idx - 1] && list[idx - 1].month !== item.month;
});
}).filter(Boolean).filter((item, idx, list) => list[idx - 1] && list[idx - 1].month !== item.month);
}, [colNum, monthLables, startDate]);
return useMemo(function () {
return /*#__PURE__*/_jsx(Fragment, {
children: [].concat(data).map(function (item, idx) {
return /*#__PURE__*/_jsx("text", {
"data-size": rectSize,
x: leftPad + space + space,
y: 15,
dx: item.col * (rectSize + space),
textAnchor: "start",
children: item.monthStr
}, idx);
})
});
}, [data, leftPad, rectSize, space]);
return (0, _react.useMemo)(() => /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
children: [...data].map((item, idx) => {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", {
"data-size": rectSize,
x: leftPad + space + space,
y: 15,
dx: item.col * (rectSize + space),
textAnchor: "start",
children: item.monthStr
}, idx);
})
}), [data, leftPad, rectSize, space]);
};
exports.LablesMonth = LablesMonth;
//# sourceMappingURL=LablesMonth.js.map

@@ -1,29 +0,38 @@

import React, { Fragment, useMemo } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
export var LablesWeek = function LablesWeek(_ref) {
var _ref$weekLables = _ref.weekLables,
weekLables = _ref$weekLables === void 0 ? [] : _ref$weekLables,
_ref$rectSize = _ref.rectSize,
rectSize = _ref$rectSize === void 0 ? 0 : _ref$rectSize,
_ref$topPad = _ref.topPad,
topPad = _ref$topPad === void 0 ? 0 : _ref$topPad,
_ref$space = _ref.space,
space = _ref$space === void 0 ? 0 : _ref$space;
return useMemo(function () {
return /*#__PURE__*/_jsx(Fragment, {
children: [].concat(Array(7)).map(function (_, idx) {
if (weekLables && weekLables[idx]) {
return /*#__PURE__*/_jsx("text", {
x: 15,
y: topPad,
dy: (idx + 1) * (rectSize + space) - 5,
children: weekLables[idx]
}, idx);
}
"use strict";
return null;
})
});
}, [rectSize, space, topPad, weekLables]);
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LablesWeek = void 0;
var _react = _interopRequireWildcard(require("react"));
var _jsxRuntime = require("react/jsx-runtime");
var LablesWeek = _ref => {
var {
weekLables = [],
rectSize = 0,
topPad = 0,
space = 0
} = _ref;
return (0, _react.useMemo)(() => /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
children: [...Array(7)].map((_, idx) => {
if (weekLables && weekLables[idx]) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", {
x: 15,
y: topPad,
dy: (idx + 1) * (rectSize + space) - 5,
children: weekLables[idx]
}, idx);
}
return null;
})
}), [rectSize, space, topPad, weekLables]);
};
exports.LablesWeek = LablesWeek;
//# sourceMappingURL=LablesWeek.js.map

@@ -1,41 +0,51 @@

import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Legend;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
var _Rect = require("./Rect");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["panelColors", "leftPad", "topPad", "space", "rectSize", "legendCellSize", "legendRender"];
import React, { Fragment, useMemo } from 'react';
import { Rect } from './Rect';
import { jsx as _jsx } from "react/jsx-runtime";
export default function Legend(_ref) {
var panelColors = _ref.panelColors,
_ref$leftPad = _ref.leftPad,
leftPad = _ref$leftPad === void 0 ? 0 : _ref$leftPad,
_ref$topPad = _ref.topPad,
topPad = _ref$topPad === void 0 ? 0 : _ref$topPad,
_ref$space = _ref.space,
space = _ref$space === void 0 ? 0 : _ref$space,
_ref$rectSize = _ref.rectSize,
rectSize = _ref$rectSize === void 0 ? 0 : _ref$rectSize,
_ref$legendCellSize = _ref.legendCellSize,
legendCellSize = _ref$legendCellSize === void 0 ? 0 : _ref$legendCellSize,
legendRender = _ref.legendRender,
props = _objectWithoutPropertiesLoose(_ref, _excluded);
function Legend(_ref) {
var {
panelColors,
leftPad = 0,
topPad = 0,
space = 0,
rectSize = 0,
legendCellSize = 0,
legendRender
} = _ref,
props = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
var size = legendCellSize || rectSize;
return useMemo(function () {
return /*#__PURE__*/_jsx(Fragment, {
children: Object.keys(panelColors || {}).map(function (num, key) {
var rectProps = _extends({}, props, {
key: key,
x: (size + 1) * key + leftPad,
y: topPad + rectSize * 8 + 6,
fill: panelColors[Number(num)],
width: size,
height: size
});
if (legendRender) return legendRender(rectProps);
return /*#__PURE__*/_jsx(Rect, _extends({}, rectProps));
})
});
}, [panelColors, props, size, leftPad, topPad, rectSize, legendRender]);
return (0, _react.useMemo)(() => /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
children: Object.keys(panelColors || {}).map((num, key) => {
var rectProps = (0, _extends2.default)({}, props, {
key,
x: (size + 1) * key + leftPad,
y: topPad + rectSize * 8 + 6,
fill: panelColors[Number(num)],
width: size,
height: size
});
if (legendRender) return legendRender(rectProps);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Rect.Rect, (0, _extends2.default)({}, rectProps));
})
}), [panelColors, props, size, leftPad, topPad, rectSize, legendRender]);
}
//# sourceMappingURL=Legend.js.map

@@ -1,7 +0,19 @@

import _extends from "@babel/runtime/helpers/esm/extends";
import React from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
export var Rect = function Rect(props) {
return /*#__PURE__*/_jsx("rect", _extends({}, props));
};
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Rect = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _jsxRuntime = require("react/jsx-runtime");
var Rect = props => /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", (0, _extends2.default)({}, props));
exports.Rect = Rect;
//# sourceMappingURL=Rect.js.map

@@ -1,67 +0,66 @@

import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SVG;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
var _LablesWeek = require("./LablesWeek");
var _LablesMonth = require("./LablesMonth");
var _Rect = require("./Rect");
var _utils = require("./utils");
var _Legend = _interopRequireDefault(require("./Legend"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["rectSize", "legendCellSize", "space", "startDate", "endDate", "rectProps", "rectRender", "legendRender", "value", "weekLables", "monthLables", "panelColors"];
import React, { useEffect, useMemo, useState } from 'react';
import { LablesWeek } from './LablesWeek';
import { LablesMonth } from './LablesMonth';
import { Rect } from './Rect';
import { formatData, getDateToString, existColor, numberSort, isValidDate, oneDayTime } from './utils';
import Legend from './Legend';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export default function SVG(props) {
function SVG(props) {
var _ref = props || {},
_ref$rectSize = _ref.rectSize,
rectSize = _ref$rectSize === void 0 ? 11 : _ref$rectSize,
_ref$legendCellSize = _ref.legendCellSize,
legendCellSize = _ref$legendCellSize === void 0 ? 11 : _ref$legendCellSize,
_ref$space = _ref.space,
space = _ref$space === void 0 ? 2 : _ref$space,
_ref$startDate = _ref.startDate,
startDate = _ref$startDate === void 0 ? new Date() : _ref$startDate,
endDate = _ref.endDate,
rectProps = _ref.rectProps,
rectRender = _ref.rectRender,
legendRender = _ref.legendRender,
_ref$value = _ref.value,
value = _ref$value === void 0 ? [] : _ref$value,
_ref$weekLables = _ref.weekLables,
weekLables = _ref$weekLables === void 0 ? ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] : _ref$weekLables,
_ref$monthLables = _ref.monthLables,
monthLables = _ref$monthLables === void 0 ? ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] : _ref$monthLables,
_ref$panelColors = _ref.panelColors,
panelColors = _ref$panelColors === void 0 ? {
0: '#EBEDF0',
8: '#7BC96F',
4: '#C6E48B',
12: '#239A3B',
32: '#196127'
} : _ref$panelColors,
other = _objectWithoutPropertiesLoose(_ref, _excluded);
{
rectSize = 11,
legendCellSize = 11,
space = 2,
startDate = new Date(),
endDate,
rectProps,
rectRender,
legendRender,
value = [],
weekLables = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
monthLables = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
panelColors = {
0: '#EBEDF0',
8: '#7BC96F',
4: '#C6E48B',
12: '#239A3B',
32: '#196127'
}
} = _ref,
other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
var _useState = useState(0),
gridNum = _useState[0],
setGridNum = _useState[1];
var [gridNum, setGridNum] = (0, _react.useState)(0);
var [leftPad, setLeftPad] = (0, _react.useState)(!!weekLables ? 28 : 5);
var [topPad, setTopPad] = (0, _react.useState)(!!monthLables ? 20 : 5);
var _useState2 = useState(!!weekLables ? 28 : 5),
leftPad = _useState2[0],
setLeftPad = _useState2[1];
var svgRef = /*#__PURE__*/_react.default.createRef();
var _useState3 = useState(!!monthLables ? 20 : 5),
topPad = _useState3[0],
setTopPad = _useState3[1];
var svgRef = /*#__PURE__*/React.createRef();
var nums = useMemo(function () {
return numberSort(Object.keys(panelColors).map(function (item) {
return parseInt(item, 10);
}));
}, [panelColors]);
var data = useMemo(function () {
return formatData(value);
}, [value]);
useEffect(function () {
return setLeftPad(!!weekLables ? 28 : 5);
}, [weekLables]);
useEffect(function () {
var nums = (0, _react.useMemo)(() => (0, _utils.numberSort)(Object.keys(panelColors).map(item => parseInt(item, 10))), [panelColors]);
var data = (0, _react.useMemo)(() => (0, _utils.formatData)(value), [value]);
(0, _react.useEffect)(() => setLeftPad(!!weekLables ? 28 : 5), [weekLables]);
(0, _react.useEffect)(() => {
if (svgRef.current) {

@@ -72,17 +71,17 @@ var width = svgRef.current.clientWidth - leftPad || 0;

}, [rectSize, svgRef, space, leftPad]);
useEffect(function () {
(0, _react.useEffect)(() => {
setTopPad(!!monthLables ? 20 : 5);
}, [monthLables]);
var initStartDate = useMemo(function () {
if (isValidDate(startDate)) {
return !startDate.getDay() ? startDate : new Date(startDate.getTime() - startDate.getDay() * oneDayTime);
var initStartDate = (0, _react.useMemo)(() => {
if ((0, _utils.isValidDate)(startDate)) {
return !startDate.getDay() ? startDate : new Date(startDate.getTime() - startDate.getDay() * _utils.oneDayTime);
} else {
var newDate = new Date();
return new Date(newDate.getTime() - newDate.getDay() * oneDayTime);
return new Date(newDate.getTime() - newDate.getDay() * _utils.oneDayTime);
}
}, [startDate]);
return /*#__PURE__*/_jsxs("svg", _extends({
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", (0, _extends2.default)({
ref: svgRef
}, other, {
children: [legendCellSize !== 0 && /*#__PURE__*/_jsx(Legend, {
children: [legendCellSize !== 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Legend.default, {
legendRender: legendRender,

@@ -95,3 +94,3 @@ panelColors: panelColors,

space: space
}), /*#__PURE__*/_jsx(LablesWeek, {
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LablesWeek.LablesWeek, {
weekLables: weekLables,

@@ -101,3 +100,3 @@ rectSize: rectSize,

topPad: topPad
}), /*#__PURE__*/_jsx(LablesMonth, {
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LablesMonth.LablesMonth, {
monthLables: monthLables,

@@ -109,9 +108,9 @@ rectSize: rectSize,

startDate: initStartDate
}), /*#__PURE__*/_jsx("g", {
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
transform: "translate(" + leftPad + ", " + topPad + ")",
children: gridNum > 0 && [].concat(Array(gridNum)).map(function (_, idx) {
return /*#__PURE__*/_jsx("g", {
children: gridNum > 0 && [...Array(gridNum)].map((_, idx) => {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
"data-column": idx,
children: [].concat(Array(7)).map(function (_, cidx) {
var dayProps = _extends({}, rectProps, {
children: [...Array(7)].map((_, cidx) => {
var dayProps = (0, _extends2.default)({}, rectProps, {
key: cidx,

@@ -124,7 +123,5 @@ fill: '#EBEDF0',

});
var currentDate = new Date(initStartDate.getTime() + oneDayTime * (idx * 7 + cidx));
var date = getDateToString(currentDate);
var dataProps = _extends({}, data[date], {
var currentDate = new Date(initStartDate.getTime() + _utils.oneDayTime * (idx * 7 + cidx));
var date = (0, _utils.getDateToString)(currentDate);
var dataProps = (0, _extends2.default)({}, data[date], {
date: date,

@@ -141,3 +138,3 @@ row: cidx,

if (date && data[date] && panelColors && Object.keys(panelColors).length > 0) {
dayProps.fill = existColor(data[date].count || 0, nums, panelColors);
dayProps.fill = (0, _utils.existColor)(data[date].count || 0, nums, panelColors);
} else if (panelColors && panelColors[0]) {

@@ -148,7 +145,7 @@ dayProps.fill = panelColors[0];

if (rectRender && typeof rectRender === 'function') {
var elm = rectRender(_extends({}, dayProps, {
var elm = rectRender((0, _extends2.default)({}, dayProps, {
key: cidx
}), dataProps);
if (elm && /*#__PURE__*/React.isValidElement(elm)) {
if (elm && /*#__PURE__*/_react.default.isValidElement(elm)) {
return elm;

@@ -158,3 +155,3 @@ }

return /*#__PURE__*/_jsx(Rect, _extends({}, dayProps, {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Rect.Rect, (0, _extends2.default)({}, dayProps, {
"data-date": date,

@@ -161,0 +158,0 @@ "data-index": dataProps.index,

@@ -1,9 +0,24 @@

export var oneDayTime = 24 * 60 * 60 * 1000;
export function isValidDate(date) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isValidDate = isValidDate;
exports.getDateToString = getDateToString;
exports.formatData = formatData;
exports.numberSort = numberSort;
exports.existColor = existColor;
exports.oneDayTime = void 0;
var oneDayTime = 24 * 60 * 60 * 1000;
exports.oneDayTime = oneDayTime;
function isValidDate(date) {
return date instanceof Date && !isNaN(date.getTime());
}
export function getDateToString(date) {
function getDateToString(date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}
export function formatData(data) {
function formatData(data) {
if (data === void 0) {

@@ -14,3 +29,3 @@ data = [];

var result = {};
data.forEach(function (item) {
data.forEach(item => {
if (item.date && isValidDate(new Date(item.date))) {

@@ -25,3 +40,4 @@ item.date = getDateToString(new Date(item.date));

export function numberSort(keys) {
function numberSort(keys) {
if (keys === void 0) {

@@ -31,3 +47,3 @@ keys = [];

return keys.sort(function (x, y) {
return keys.sort((x, y) => {
if (x < y) return -1;else if (x > y) return 1;

@@ -37,3 +53,4 @@ return 0;

}
export function existColor(num, nums, panelColors) {
function existColor(num, nums, panelColors) {
if (num === void 0) {

@@ -40,0 +57,0 @@ num = 0;

{
"name": "@uiw/react-heat-map",
"version": "1.4.0",
"version": "1.4.1",
"description": "React component create calendar heatmap to visualize time series data, a la github contribution graph.",

@@ -52,10 +52,10 @@ "homepage": "https://uiwjs.github.io/react-heat-map/",

"@kkt/scope-plugin-options": "6.11.0",
"@types/react": "17.0.19",
"@types/react": "17.0.20",
"@types/react-dom": "17.0.9",
"@uiw/react-code-preview": "1.12.1",
"@uiw/react-github-corners": "1.4.0",
"@uiw/react-code-preview": "1.12.3",
"@uiw/react-github-corners": "1.5.1",
"@uiw/react-markdown-preview": "3.3.0",
"@uiw/react-tooltip": "4.9.4",
"@uiw/reset.css": "1.0.5",
"compile-less-cli": "1.8.1",
"compile-less-cli": "1.8.8",
"husky": "7.0.2",

@@ -67,4 +67,4 @@ "kkt": "6.11.0",

"react-dom": "17.0.2",
"rehype-attr": "1.4.2",
"tsbb": "3.0.0"
"rehype-attr": "2.0.1",
"tsbb": "3.1.2"
},

@@ -71,0 +71,0 @@ "eslintConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc