react-grid-heatmapjs
Version:
React for the user interface, Tailwind CSS for styling, and CSS Grid for layout. A heatmap is a data visualization technique that uses color to represent the magnitude of values within a two-dimensional grid or matrix.
763 lines (759 loc) • 26.3 kB
JavaScript
import Z from "react";
var X = { exports: {} }, I = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var je;
function ur() {
if (je)
return I;
je = 1;
var R = Z, m = Symbol.for("react.element"), C = Symbol.for("react.fragment"), g = Object.prototype.hasOwnProperty, b = R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, j = { key: !0, ref: !0, __self: !0, __source: !0 };
function h(o, s, c) {
var f, y = {}, _ = null, T = null;
c !== void 0 && (_ = "" + c), s.key !== void 0 && (_ = "" + s.key), s.ref !== void 0 && (T = s.ref);
for (f in s)
g.call(s, f) && !j.hasOwnProperty(f) && (y[f] = s[f]);
if (o && o.defaultProps)
for (f in s = o.defaultProps, s)
y[f] === void 0 && (y[f] = s[f]);
return { $$typeof: m, type: o, key: _, ref: T, props: y, _owner: b.current };
}
return I.Fragment = C, I.jsx = h, I.jsxs = h, I;
}
var $ = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var we;
function lr() {
return we || (we = 1, process.env.NODE_ENV !== "production" && function() {
var R = Z, m = Symbol.for("react.element"), C = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), b = Symbol.for("react.strict_mode"), j = Symbol.for("react.profiler"), h = Symbol.for("react.provider"), o = Symbol.for("react.context"), s = Symbol.for("react.forward_ref"), c = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), y = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), T = Symbol.for("react.offscreen"), Q = Symbol.iterator, Ce = "@@iterator";
function Oe(e) {
if (e === null || typeof e != "object")
return null;
var r = Q && e[Q] || e[Ce];
return typeof r == "function" ? r : null;
}
var k = R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function E(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
Se("error", e, t);
}
}
function Se(e, r, t) {
{
var n = k.ReactDebugCurrentFrame, u = n.getStackAddendum();
u !== "" && (r += "%s", t = t.concat([u]));
var l = t.map(function(i) {
return String(i);
});
l.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, l);
}
}
var Pe = !1, ke = !1, De = !1, Fe = !1, Ne = !1, ee;
ee = Symbol.for("react.module.reference");
function Ae(e) {
return !!(typeof e == "string" || typeof e == "function" || e === g || e === j || Ne || e === b || e === c || e === f || Fe || e === T || Pe || ke || De || typeof e == "object" && e !== null && (e.$$typeof === _ || e.$$typeof === y || e.$$typeof === h || e.$$typeof === o || e.$$typeof === s || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === ee || e.getModuleId !== void 0));
}
function Ie(e, r, t) {
var n = e.displayName;
if (n)
return n;
var u = r.displayName || r.name || "";
return u !== "" ? t + "(" + u + ")" : t;
}
function re(e) {
return e.displayName || "Context";
}
function O(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && E("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case g:
return "Fragment";
case C:
return "Portal";
case j:
return "Profiler";
case b:
return "StrictMode";
case c:
return "Suspense";
case f:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case o:
var r = e;
return re(r) + ".Consumer";
case h:
var t = e;
return re(t._context) + ".Provider";
case s:
return Ie(e, e.render, "ForwardRef");
case y:
var n = e.displayName || null;
return n !== null ? n : O(e.type) || "Memo";
case _: {
var u = e, l = u._payload, i = u._init;
try {
return O(i(l));
} catch {
return null;
}
}
}
return null;
}
var P = Object.assign, N = 0, te, ne, ae, ie, oe, se, ue;
function le() {
}
le.__reactDisabledLog = !0;
function $e() {
{
if (N === 0) {
te = console.log, ne = console.info, ae = console.warn, ie = console.error, oe = console.group, se = console.groupCollapsed, ue = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: le,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
N++;
}
}
function We() {
{
if (N--, N === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: P({}, e, {
value: te
}),
info: P({}, e, {
value: ne
}),
warn: P({}, e, {
value: ae
}),
error: P({}, e, {
value: ie
}),
group: P({}, e, {
value: oe
}),
groupCollapsed: P({}, e, {
value: se
}),
groupEnd: P({}, e, {
value: ue
})
});
}
N < 0 && E("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var U = k.ReactCurrentDispatcher, q;
function W(e, r, t) {
{
if (q === void 0)
try {
throw Error();
} catch (u) {
var n = u.stack.trim().match(/\n( *(at )?)/);
q = n && n[1] || "";
}
return `
` + q + e;
}
}
var B = !1, Y;
{
var Ye = typeof WeakMap == "function" ? WeakMap : Map;
Y = new Ye();
}
function ce(e, r) {
if (!e || B)
return "";
{
var t = Y.get(e);
if (t !== void 0)
return t;
}
var n;
B = !0;
var u = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var l;
l = U.current, U.current = null, $e();
try {
if (r) {
var i = function() {
throw Error();
};
if (Object.defineProperty(i.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(i, []);
} catch (S) {
n = S;
}
Reflect.construct(e, [], i);
} else {
try {
i.call();
} catch (S) {
n = S;
}
e.call(i.prototype);
}
} else {
try {
throw Error();
} catch (S) {
n = S;
}
e();
}
} catch (S) {
if (S && n && typeof S.stack == "string") {
for (var a = S.stack.split(`
`), x = n.stack.split(`
`), v = a.length - 1, p = x.length - 1; v >= 1 && p >= 0 && a[v] !== x[p]; )
p--;
for (; v >= 1 && p >= 0; v--, p--)
if (a[v] !== x[p]) {
if (v !== 1 || p !== 1)
do
if (v--, p--, p < 0 || a[v] !== x[p]) {
var w = `
` + a[v].replace(" at new ", " at ");
return e.displayName && w.includes("<anonymous>") && (w = w.replace("<anonymous>", e.displayName)), typeof e == "function" && Y.set(e, w), w;
}
while (v >= 1 && p >= 0);
break;
}
}
} finally {
B = !1, U.current = l, We(), Error.prepareStackTrace = u;
}
var F = e ? e.displayName || e.name : "", Re = F ? W(F) : "";
return typeof e == "function" && Y.set(e, Re), Re;
}
function Me(e, r, t) {
return ce(e, !1);
}
function Le(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function M(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return ce(e, Le(e));
if (typeof e == "string")
return W(e);
switch (e) {
case c:
return W("Suspense");
case f:
return W("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case s:
return Me(e.render);
case y:
return M(e.type, r, t);
case _: {
var n = e, u = n._payload, l = n._init;
try {
return M(l(u), r, t);
} catch {
}
}
}
return "";
}
var L = Object.prototype.hasOwnProperty, fe = {}, de = k.ReactDebugCurrentFrame;
function V(e) {
if (e) {
var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
de.setExtraStackFrame(t);
} else
de.setExtraStackFrame(null);
}
function Ve(e, r, t, n, u) {
{
var l = Function.call.bind(L);
for (var i in e)
if (l(e, i)) {
var a = void 0;
try {
if (typeof e[i] != "function") {
var x = Error((n || "React class") + ": " + t + " type `" + i + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[i] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw x.name = "Invariant Violation", x;
}
a = e[i](r, i, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (v) {
a = v;
}
a && !(a instanceof Error) && (V(u), E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, i, typeof a), V(null)), a instanceof Error && !(a.message in fe) && (fe[a.message] = !0, V(u), E("Failed %s type: %s", t, a.message), V(null));
}
}
}
var Ue = Array.isArray;
function H(e) {
return Ue(e);
}
function qe(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function Be(e) {
try {
return ve(e), !1;
} catch {
return !0;
}
}
function ve(e) {
return "" + e;
}
function pe(e) {
if (Be(e))
return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", qe(e)), ve(e);
}
var A = k.ReactCurrentOwner, He = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, me, he, J;
J = {};
function Je(e) {
if (L.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function ze(e) {
if (L.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function Ge(e, r) {
if (typeof e.ref == "string" && A.current && r && A.current.stateNode !== r) {
var t = O(A.current.type);
J[t] || (E('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', O(A.current.type), e.ref), J[t] = !0);
}
}
function Ke(e, r) {
{
var t = function() {
me || (me = !0, E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function Xe(e, r) {
{
var t = function() {
he || (he = !0, E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var Ze = function(e, r, t, n, u, l, i) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: m,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: i,
// Record the component responsible for creating this element.
_owner: l
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(a, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(a, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: u
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function Qe(e, r, t, n, u) {
{
var l, i = {}, a = null, x = null;
t !== void 0 && (pe(t), a = "" + t), ze(r) && (pe(r.key), a = "" + r.key), Je(r) && (x = r.ref, Ge(r, u));
for (l in r)
L.call(r, l) && !He.hasOwnProperty(l) && (i[l] = r[l]);
if (e && e.defaultProps) {
var v = e.defaultProps;
for (l in v)
i[l] === void 0 && (i[l] = v[l]);
}
if (a || x) {
var p = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && Ke(i, p), x && Xe(i, p);
}
return Ze(e, a, x, u, n, A.current, i);
}
}
var z = k.ReactCurrentOwner, be = k.ReactDebugCurrentFrame;
function D(e) {
if (e) {
var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
be.setExtraStackFrame(t);
} else
be.setExtraStackFrame(null);
}
var G;
G = !1;
function K(e) {
return typeof e == "object" && e !== null && e.$$typeof === m;
}
function ye() {
{
if (z.current) {
var e = O(z.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function er(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var ge = {};
function rr(e) {
{
var r = ye();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function _e(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = rr(r);
if (ge[t])
return;
ge[t] = !0;
var n = "";
e && e._owner && e._owner !== z.current && (n = " It was passed a child from " + O(e._owner.type) + "."), D(e), E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), D(null);
}
}
function Ee(e, r) {
{
if (typeof e != "object")
return;
if (H(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
K(n) && _e(n, r);
}
else if (K(e))
e._store && (e._store.validated = !0);
else if (e) {
var u = Oe(e);
if (typeof u == "function" && u !== e.entries)
for (var l = u.call(e), i; !(i = l.next()).done; )
K(i.value) && _e(i.value, r);
}
}
}
function tr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === s || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === y))
t = r.propTypes;
else
return;
if (t) {
var n = O(r);
Ve(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !G) {
G = !0;
var u = O(r);
E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function nr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
D(e), E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), D(null);
break;
}
}
e.ref !== null && (D(e), E("Invalid attribute `ref` supplied to `React.Fragment`."), D(null));
}
}
function xe(e, r, t, n, u, l) {
{
var i = Ae(e);
if (!i) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var x = er(u);
x ? a += x : a += ye();
var v;
e === null ? v = "null" : H(e) ? v = "array" : e !== void 0 && e.$$typeof === m ? (v = "<" + (O(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : v = typeof e, E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", v, a);
}
var p = Qe(e, r, t, u, l);
if (p == null)
return p;
if (i) {
var w = r.children;
if (w !== void 0)
if (n)
if (H(w)) {
for (var F = 0; F < w.length; F++)
Ee(w[F], e);
Object.freeze && Object.freeze(w);
} else
E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Ee(w, e);
}
return e === g ? nr(p) : tr(p), p;
}
}
function ar(e, r, t) {
return xe(e, r, t, !0);
}
function ir(e, r, t) {
return xe(e, r, t, !1);
}
var or = ir, sr = ar;
$.Fragment = g, $.jsx = or, $.jsxs = sr;
}()), $;
}
process.env.NODE_ENV === "production" ? X.exports = ur() : X.exports = lr();
var d = X.exports;
function Te({ label: R, variant: m }) {
return /* @__PURE__ */ d.jsxs("div", { className: "flex gap-1 items-center", children: [
/* @__PURE__ */ d.jsx(
"span",
{
className: "w-2 h-2 rounded-full",
style: { background: m }
}
),
/* @__PURE__ */ d.jsx("p", { className: "text-gray-500 text-sm whitespace-nowrap", children: R })
] });
}
function cr(R) {
const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(R);
if (!m)
throw new Error("Could not parse Hex Color");
const C = parseInt(m[1], 16), g = parseInt(m[2], 16), b = parseInt(m[3], 16), j = C / 255, h = g / 255, o = b / 255, s = Math.max(j, h, o), c = Math.min(j, h, o);
let f = (s + c) / 2, y = f, _ = f;
if (s === c)
return { h: 0, s: 0, l: _ };
const T = s - c;
switch (y = _ > 0.5 ? T / (2 - s - c) : T / (s + c), s) {
case j:
f = (h - o) / T + (h < o ? 6 : 0);
break;
case h:
f = (o - j) / T + 2;
break;
case o:
f = (j - h) / T + 4;
break;
}
return f /= 6, y = y * 100, y = Math.round(y), _ = _ * 100, _ = Math.round(_), f = Math.round(360 * f), { h: f, s: y, l: _ };
}
function fr(R, m, C, g) {
const b = cr(g), j = m - R, h = 100 - (C - R) / j * 100;
return `hsl(${b.h},${b.s}%,${h < 20 ? 20 : h}%)`;
}
const vr = ({
series: R,
xaxis: m,
title: C,
legends: g,
colorRange: b,
chartStyle: j
}) => {
var h;
return /* @__PURE__ */ d.jsxs("div", { children: [
/* @__PURE__ */ d.jsxs("div", { className: "flex items-center justify-between", children: [
/* @__PURE__ */ d.jsx("h2", { className: "font-sans text-base font-bold", children: C }),
/* @__PURE__ */ d.jsx("div", { className: "flex gap-3", children: g ? g == null ? void 0 : g.map((o) => /* @__PURE__ */ d.jsx(
Te,
{
variant: o.color,
label: o.name
},
o.name
)) : b == null ? void 0 : b.map((o) => /* @__PURE__ */ d.jsx(
Te,
{
variant: o.color,
label: o.name
},
o.name
)) })
] }),
/* @__PURE__ */ d.jsx("div", { className: "grid place-items-center w-full mt-9 px-12", children: /* @__PURE__ */ d.jsxs(
"div",
{
className: "grid items-center justify-items-end gap-x-2 grid-cols-[minmax(auto,_5.125rem)_minmax(auto,_46.875rem)_minmax(auto,_5.125rem)]",
style: { ...j },
children: [
R == null ? void 0 : R.map((o) => /* @__PURE__ */ d.jsxs(Z.Fragment, { children: [
/* @__PURE__ */ d.jsx("div", { className: "flex", children: /* @__PURE__ */ d.jsx("p", { className: "text-xs text-end", children: o.name }) }),
/* @__PURE__ */ d.jsx("div", { className: "flex w-full", children: o.data.map((s) => {
const c = (b == null ? void 0 : b.find(
(f) => f.from <= s && f.to >= s
)) || {
from: 0,
to: s,
color: "#000000",
name: "error"
};
return /* @__PURE__ */ d.jsxs(
"div",
{
className: "flex flex-1 p-1 border relative cursor-pointer group",
children: [
/* @__PURE__ */ d.jsx(
"div",
{
className: "absolute bottom-0 right-0 -translate-x-3 -translate-y-3 pointer-events-none z-10 transition-opacity rounded-full bg-white p-1 grid min-w-[30px] place-items-center border-2 text-sm text-gray-500 shadow-lg aspect-square md:opacity-0 group-hover:opacity-100 ",
style: { borderColor: c.color || "#afafaf" },
children: s
}
),
/* @__PURE__ */ d.jsx(
"div",
{
className: "aspect-square rounded-sm w-full",
style: {
background: fr(
c == null ? void 0 : c.from,
c == null ? void 0 : c.to,
s,
c == null ? void 0 : c.color
)
}
}
)
]
},
s + o.name
);
}) }),
/* @__PURE__ */ d.jsx("div", { className: "flex justify-self-start", children: /* @__PURE__ */ d.jsx("p", { className: "text-xs ", children: o.total }) })
] }, JSON.stringify(o))),
/* @__PURE__ */ d.jsx("div", {}),
/* @__PURE__ */ d.jsx("div", { className: "mt-2 w-full flex justify-between gap-1", children: (h = m.labels) == null ? void 0 : h.map((o, s) => {
var c;
return /* @__PURE__ */ d.jsxs("div", { className: "w-full mt-1 text-center", children: [
/* @__PURE__ */ d.jsx("p", { children: o }),
/* @__PURE__ */ d.jsx("p", { children: (c = m == null ? void 0 : m.totals) == null ? void 0 : c[s] })
] }, o);
}) }),
/* @__PURE__ */ d.jsx("div", {})
]
}
) })
] });
};
export {
vr as HeatMap
};