cr-ui-lib 1.1.55 → 1.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +88 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -87,8 +87,9 @@ interface MultiLineGraphProps {
|
|
|
87
87
|
/** Determines the default position of the tooltip. Defaults to 'top'. */
|
|
88
88
|
tooltipPosition?: "top" | "bottom";
|
|
89
89
|
svg?: string;
|
|
90
|
+
tab?: "Month" | "Week" | "Day" | "Hourly" | null;
|
|
90
91
|
}
|
|
91
|
-
declare const MultiLineGraph: ({ datasets, xAxisLabels, className, tooltipPosition, svg, }: MultiLineGraphProps) => JSX.Element;
|
|
92
|
+
declare const MultiLineGraph: ({ datasets, xAxisLabels, className, tooltipPosition, svg, tab, }: MultiLineGraphProps) => JSX.Element;
|
|
92
93
|
|
|
93
94
|
interface SingleLineGraphProps {
|
|
94
95
|
data: number[];
|
|
@@ -99,11 +100,12 @@ interface SingleLineGraphProps {
|
|
|
99
100
|
labelPopupTitle?: string;
|
|
100
101
|
lineColor?: string;
|
|
101
102
|
className?: string;
|
|
102
|
-
/** Determines the default position of the tooltip. Defaults to 'top'. */
|
|
103
103
|
tooltipPosition?: "top" | "bottom";
|
|
104
104
|
svg?: string;
|
|
105
|
+
/** NEW — Determines label formatting logic */
|
|
106
|
+
tab?: "Month" | "Week" | "Day" | "Hourly" | null;
|
|
105
107
|
}
|
|
106
|
-
declare const SingleLineGraph: ({ data, label, lineColor, gradientColor1, gradientColor0, pointLabelColor, labelPopupTitle, className, tooltipPosition, svg, }: SingleLineGraphProps) => JSX.Element;
|
|
108
|
+
declare const SingleLineGraph: ({ data, label, lineColor, gradientColor1, gradientColor0, pointLabelColor, labelPopupTitle, className, tooltipPosition, svg, tab, }: SingleLineGraphProps) => JSX.Element;
|
|
107
109
|
|
|
108
110
|
interface DataSet {
|
|
109
111
|
data: number[];
|
|
@@ -118,8 +120,9 @@ interface MultiBarGraphProps {
|
|
|
118
120
|
tooltipPosition?: "top" | "bottom";
|
|
119
121
|
/** The maximum value for the Y-axis. Defaults to undefined, allowing Chart.js to auto-calculate. */
|
|
120
122
|
yAxisMax?: number;
|
|
123
|
+
tab?: "Month" | "Week" | "Day" | "Hourly" | null;
|
|
121
124
|
}
|
|
122
|
-
declare const MultiBarGraph: ({ datasets, xAxisLabels, className, tooltipPosition, yAxisMax, }: MultiBarGraphProps) => JSX.Element;
|
|
125
|
+
declare const MultiBarGraph: ({ datasets, xAxisLabels, className, tooltipPosition, yAxisMax, tab, }: MultiBarGraphProps) => JSX.Element;
|
|
123
126
|
|
|
124
127
|
interface CommonInputProps extends React$1.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement> {
|
|
125
128
|
label?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -87,8 +87,9 @@ interface MultiLineGraphProps {
|
|
|
87
87
|
/** Determines the default position of the tooltip. Defaults to 'top'. */
|
|
88
88
|
tooltipPosition?: "top" | "bottom";
|
|
89
89
|
svg?: string;
|
|
90
|
+
tab?: "Month" | "Week" | "Day" | "Hourly" | null;
|
|
90
91
|
}
|
|
91
|
-
declare const MultiLineGraph: ({ datasets, xAxisLabels, className, tooltipPosition, svg, }: MultiLineGraphProps) => JSX.Element;
|
|
92
|
+
declare const MultiLineGraph: ({ datasets, xAxisLabels, className, tooltipPosition, svg, tab, }: MultiLineGraphProps) => JSX.Element;
|
|
92
93
|
|
|
93
94
|
interface SingleLineGraphProps {
|
|
94
95
|
data: number[];
|
|
@@ -99,11 +100,12 @@ interface SingleLineGraphProps {
|
|
|
99
100
|
labelPopupTitle?: string;
|
|
100
101
|
lineColor?: string;
|
|
101
102
|
className?: string;
|
|
102
|
-
/** Determines the default position of the tooltip. Defaults to 'top'. */
|
|
103
103
|
tooltipPosition?: "top" | "bottom";
|
|
104
104
|
svg?: string;
|
|
105
|
+
/** NEW — Determines label formatting logic */
|
|
106
|
+
tab?: "Month" | "Week" | "Day" | "Hourly" | null;
|
|
105
107
|
}
|
|
106
|
-
declare const SingleLineGraph: ({ data, label, lineColor, gradientColor1, gradientColor0, pointLabelColor, labelPopupTitle, className, tooltipPosition, svg, }: SingleLineGraphProps) => JSX.Element;
|
|
108
|
+
declare const SingleLineGraph: ({ data, label, lineColor, gradientColor1, gradientColor0, pointLabelColor, labelPopupTitle, className, tooltipPosition, svg, tab, }: SingleLineGraphProps) => JSX.Element;
|
|
107
109
|
|
|
108
110
|
interface DataSet {
|
|
109
111
|
data: number[];
|
|
@@ -118,8 +120,9 @@ interface MultiBarGraphProps {
|
|
|
118
120
|
tooltipPosition?: "top" | "bottom";
|
|
119
121
|
/** The maximum value for the Y-axis. Defaults to undefined, allowing Chart.js to auto-calculate. */
|
|
120
122
|
yAxisMax?: number;
|
|
123
|
+
tab?: "Month" | "Week" | "Day" | "Hourly" | null;
|
|
121
124
|
}
|
|
122
|
-
declare const MultiBarGraph: ({ datasets, xAxisLabels, className, tooltipPosition, yAxisMax, }: MultiBarGraphProps) => JSX.Element;
|
|
125
|
+
declare const MultiBarGraph: ({ datasets, xAxisLabels, className, tooltipPosition, yAxisMax, tab, }: MultiBarGraphProps) => JSX.Element;
|
|
123
126
|
|
|
124
127
|
interface CommonInputProps extends React$1.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement> {
|
|
125
128
|
label?: string;
|
package/dist/index.js
CHANGED
|
@@ -907,7 +907,8 @@ var MultiLineGraph = ({
|
|
|
907
907
|
tooltipPosition = "top",
|
|
908
908
|
svg = `<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
909
909
|
<path d="M10.0833 0.75H1.91667C1.275 0.75 0.755833 1.275 0.755833 1.91667L0.75 10.0833C0.75 10.725 1.275 11.25 1.91667 11.25H10.0833C10.725 11.25 11.25 10.725 11.25 10.0833V1.91667C11.25 1.275 10.725 0.75 10.0833 0.75ZM10.0833 10.0833H1.91667V1.91667H10.0833V10.0833ZM5.125 8.91667H6.875V6.875H8.91667V5.125H6.875V3.08333H5.125V5.125H3.08333V6.875H5.125V8.91667Z" fill="#4683B4"/>
|
|
910
|
-
</svg
|
|
910
|
+
</svg>`,
|
|
911
|
+
tab = "Month"
|
|
911
912
|
}) => {
|
|
912
913
|
const chartRef = React.useRef(null);
|
|
913
914
|
const [chartKey, setChartKey] = React.useState(`chart-${Date.now()}`);
|
|
@@ -919,6 +920,29 @@ var MultiLineGraph = ({
|
|
|
919
920
|
{ line: "#FFA726", point: "#FF6F00" },
|
|
920
921
|
{ line: "#AB47BC", point: "#8E24AA" }
|
|
921
922
|
];
|
|
923
|
+
const formatLabel = (label) => {
|
|
924
|
+
const date = new Date(label);
|
|
925
|
+
switch (tab) {
|
|
926
|
+
case "Month":
|
|
927
|
+
return date.toLocaleString("en-US", { month: "long", year: "numeric" });
|
|
928
|
+
case "Week":
|
|
929
|
+
const start = new Date(date.getFullYear(), 0, 1);
|
|
930
|
+
const diff = (date.getTime() - start.getTime()) / (1e3 * 60 * 60 * 24);
|
|
931
|
+
const weekNum = Math.ceil((diff + start.getDay() + 1) / 7);
|
|
932
|
+
return `Week: ${date.toLocaleDateString("en-US")} (W${weekNum})`;
|
|
933
|
+
case "Day":
|
|
934
|
+
return `Day: ${date.toLocaleDateString("en-US")}`;
|
|
935
|
+
case "Hourly":
|
|
936
|
+
return `Hourly: ${date.toLocaleDateString(
|
|
937
|
+
"en-US"
|
|
938
|
+
)} ${date.toLocaleTimeString("en-US", {
|
|
939
|
+
hour: "numeric",
|
|
940
|
+
minute: "2-digit"
|
|
941
|
+
})}`;
|
|
942
|
+
default:
|
|
943
|
+
return label;
|
|
944
|
+
}
|
|
945
|
+
};
|
|
922
946
|
React.useEffect(() => {
|
|
923
947
|
const handleResize = () => {
|
|
924
948
|
setChartKey(`chart-${Date.now()}`);
|
|
@@ -988,11 +1012,7 @@ var MultiLineGraph = ({
|
|
|
988
1012
|
return;
|
|
989
1013
|
}
|
|
990
1014
|
const label = (_a = dataPoints[0]) == null ? void 0 : _a.label;
|
|
991
|
-
const
|
|
992
|
-
const formattedLabel = date.toLocaleString("en-US", {
|
|
993
|
-
month: "long",
|
|
994
|
-
year: "numeric"
|
|
995
|
-
});
|
|
1015
|
+
const formattedLabel = formatLabel(label);
|
|
996
1016
|
const dataPointsHtml = dataPoints.map(
|
|
997
1017
|
(point, index) => `
|
|
998
1018
|
<div style="display: flex; align-items: center; gap: 8px; margin: ${index > 0 ? "4px" : "0"} 0;">
|
|
@@ -1206,7 +1226,8 @@ var SingleLineGraph = ({
|
|
|
1206
1226
|
tooltipPosition = "top",
|
|
1207
1227
|
svg = ` <svg width="10" height="10" viewBox="0 0 9 10" fill="none" xmlns="http://www.w3.org/2000/svg" style="margin-right: 4px;">
|
|
1208
1228
|
<path d="M0.416687 3.36663H2.16669V9.08329H0.416687V3.36663ZM3.68335 0.916626H5.31669V9.08329H3.68335V0.916626ZM6.95002 5.58329H8.58335V9.08329H6.95002V5.58329Z" fill="#4683B4"/>
|
|
1209
|
-
</svg
|
|
1229
|
+
</svg>`,
|
|
1230
|
+
tab = "Month"
|
|
1210
1231
|
}) => {
|
|
1211
1232
|
const chartRef = React.useRef(null);
|
|
1212
1233
|
const [chartKey, setChartKey] = React.useState(`chart-${Date.now()}`);
|
|
@@ -1278,11 +1299,35 @@ var SingleLineGraph = ({
|
|
|
1278
1299
|
if (!dataPoint) return;
|
|
1279
1300
|
const value = dataPoint.parsed.y;
|
|
1280
1301
|
const label2 = dataPoint.label;
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1302
|
+
let tabType = tab;
|
|
1303
|
+
if (!tabType) {
|
|
1304
|
+
if (/^\w+:\s+\w+\s+\d{4}$/i.test(label2)) tabType = "Month";
|
|
1305
|
+
else if (/^Week:/i.test(label2)) tabType = "Week";
|
|
1306
|
+
else if (/^\d{2}\/\d{2}\/\d{2}$/i.test(label2)) tabType = "Day";
|
|
1307
|
+
else if (/AM|PM/i.test(label2)) tabType = "Hourly";
|
|
1308
|
+
else tabType = "Month";
|
|
1309
|
+
}
|
|
1310
|
+
let formattedLabel = label2;
|
|
1311
|
+
try {
|
|
1312
|
+
if (tabType === "Month") {
|
|
1313
|
+
const match = label2.match(/([A-Za-z]+)\s+(\d{4})/);
|
|
1314
|
+
if (match) formattedLabel = `${match[1]} ${match[2]}`;
|
|
1315
|
+
} else if (tabType === "Week") {
|
|
1316
|
+
const match = label2.match(/(\d{2}\/\d{2}\/\d{2})/);
|
|
1317
|
+
if (match) formattedLabel = `Week of ${match[1]}`;
|
|
1318
|
+
} else if (tabType === "Day") {
|
|
1319
|
+
const date = new Date(label2);
|
|
1320
|
+
formattedLabel = date.toLocaleDateString("en-US", {
|
|
1321
|
+
month: "short",
|
|
1322
|
+
day: "2-digit",
|
|
1323
|
+
year: "numeric"
|
|
1324
|
+
});
|
|
1325
|
+
} else if (tabType === "Hourly") {
|
|
1326
|
+
formattedLabel = label2.replace(/Hourly:\s*/i, "");
|
|
1327
|
+
}
|
|
1328
|
+
} catch {
|
|
1329
|
+
formattedLabel = label2;
|
|
1330
|
+
}
|
|
1286
1331
|
const arrowSize = 6;
|
|
1287
1332
|
const innerArrowSize = 5;
|
|
1288
1333
|
const isAbove = tooltipPosition === "top";
|
|
@@ -1509,8 +1554,9 @@ var MultiBarGraph = ({
|
|
|
1509
1554
|
xAxisLabels,
|
|
1510
1555
|
className = "",
|
|
1511
1556
|
tooltipPosition = "top",
|
|
1512
|
-
yAxisMax
|
|
1557
|
+
yAxisMax,
|
|
1513
1558
|
// CHANGED: Added yAxisMax prop
|
|
1559
|
+
tab = "Month"
|
|
1514
1560
|
}) => {
|
|
1515
1561
|
const chartRef = React.useRef(null);
|
|
1516
1562
|
const defaultColors = [
|
|
@@ -1577,11 +1623,35 @@ var MultiBarGraph = ({
|
|
|
1577
1623
|
(sum, dataset) => sum + (dataset.data[hoveredPoint.dataIndex] || 0),
|
|
1578
1624
|
0
|
|
1579
1625
|
);
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1626
|
+
let tabType = tab;
|
|
1627
|
+
if (!tabType) {
|
|
1628
|
+
if (/^\w+:\s+\w+\s+\d{4}$/i.test(label)) tabType = "Month";
|
|
1629
|
+
else if (/^Week:/i.test(label)) tabType = "Week";
|
|
1630
|
+
else if (/^\d{2}\/\d{2}\/\d{2}$/i.test(label)) tabType = "Day";
|
|
1631
|
+
else if (/AM|PM/i.test(label)) tabType = "Hourly";
|
|
1632
|
+
else tabType = "Month";
|
|
1633
|
+
}
|
|
1634
|
+
let formattedLabel = label;
|
|
1635
|
+
try {
|
|
1636
|
+
if (tabType === "Month") {
|
|
1637
|
+
const match = label.match(/([A-Za-z]+)\s+(\d{4})/);
|
|
1638
|
+
if (match) formattedLabel = `${match[1]} ${match[2]}`;
|
|
1639
|
+
} else if (tabType === "Week") {
|
|
1640
|
+
const match = label.match(/(\d{2}\/\d{2}\/\d{2})/);
|
|
1641
|
+
if (match) formattedLabel = `Week of ${match[1]}`;
|
|
1642
|
+
} else if (tabType === "Day") {
|
|
1643
|
+
const date = new Date(label);
|
|
1644
|
+
formattedLabel = date.toLocaleDateString("en-US", {
|
|
1645
|
+
month: "short",
|
|
1646
|
+
day: "2-digit",
|
|
1647
|
+
year: "numeric"
|
|
1648
|
+
});
|
|
1649
|
+
} else if (tabType === "Hourly") {
|
|
1650
|
+
formattedLabel = label.replace(/Hourly:\s*/i, "");
|
|
1651
|
+
}
|
|
1652
|
+
} catch {
|
|
1653
|
+
formattedLabel = label;
|
|
1654
|
+
}
|
|
1585
1655
|
const percentage = totalBarValue > 0 ? (segmentValue / totalBarValue * 100).toFixed(2) : 0;
|
|
1586
1656
|
const iconHtml = customSvgIcon || getDefaultSvgIcon();
|
|
1587
1657
|
tooltipEl.innerHTML = `
|