cr-ui-lib 1.1.54 → 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 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
@@ -258,6 +258,7 @@ var LineChart = ({
258
258
  },
259
259
  y: {
260
260
  display: false,
261
+ min: 0,
261
262
  grid: {
262
263
  drawBorder: false,
263
264
  drawTicks: false,
@@ -906,7 +907,8 @@ var MultiLineGraph = ({
906
907
  tooltipPosition = "top",
907
908
  svg = `<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
908
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"/>
909
- </svg>`
910
+ </svg>`,
911
+ tab = "Month"
910
912
  }) => {
911
913
  const chartRef = React.useRef(null);
912
914
  const [chartKey, setChartKey] = React.useState(`chart-${Date.now()}`);
@@ -918,6 +920,29 @@ var MultiLineGraph = ({
918
920
  { line: "#FFA726", point: "#FF6F00" },
919
921
  { line: "#AB47BC", point: "#8E24AA" }
920
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
+ };
921
946
  React.useEffect(() => {
922
947
  const handleResize = () => {
923
948
  setChartKey(`chart-${Date.now()}`);
@@ -950,6 +975,7 @@ var MultiLineGraph = ({
950
975
  y: {
951
976
  display: true,
952
977
  // Set to `false` if you want to hide the y-axis labels
978
+ min: 0,
953
979
  border: {
954
980
  display: false
955
981
  },
@@ -986,11 +1012,7 @@ var MultiLineGraph = ({
986
1012
  return;
987
1013
  }
988
1014
  const label = (_a = dataPoints[0]) == null ? void 0 : _a.label;
989
- const date = new Date(label);
990
- const formattedLabel = date.toLocaleString("en-US", {
991
- month: "long",
992
- year: "numeric"
993
- });
1015
+ const formattedLabel = formatLabel(label);
994
1016
  const dataPointsHtml = dataPoints.map(
995
1017
  (point, index) => `
996
1018
  <div style="display: flex; align-items: center; gap: 8px; margin: ${index > 0 ? "4px" : "0"} 0;">
@@ -1204,7 +1226,8 @@ var SingleLineGraph = ({
1204
1226
  tooltipPosition = "top",
1205
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;">
1206
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"/>
1207
- </svg>`
1229
+ </svg>`,
1230
+ tab = "Month"
1208
1231
  }) => {
1209
1232
  const chartRef = React.useRef(null);
1210
1233
  const [chartKey, setChartKey] = React.useState(`chart-${Date.now()}`);
@@ -1239,6 +1262,7 @@ var SingleLineGraph = ({
1239
1262
  },
1240
1263
  y: {
1241
1264
  display: true,
1265
+ min: 0,
1242
1266
  border: {
1243
1267
  display: false
1244
1268
  },
@@ -1275,11 +1299,35 @@ var SingleLineGraph = ({
1275
1299
  if (!dataPoint) return;
1276
1300
  const value = dataPoint.parsed.y;
1277
1301
  const label2 = dataPoint.label;
1278
- const date = new Date(label2);
1279
- const formattedLabel = date.toLocaleString("en-US", {
1280
- month: "long",
1281
- year: "numeric"
1282
- });
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
+ }
1283
1331
  const arrowSize = 6;
1284
1332
  const innerArrowSize = 5;
1285
1333
  const isAbove = tooltipPosition === "top";
@@ -1506,8 +1554,9 @@ var MultiBarGraph = ({
1506
1554
  xAxisLabels,
1507
1555
  className = "",
1508
1556
  tooltipPosition = "top",
1509
- yAxisMax
1557
+ yAxisMax,
1510
1558
  // CHANGED: Added yAxisMax prop
1559
+ tab = "Month"
1511
1560
  }) => {
1512
1561
  const chartRef = React.useRef(null);
1513
1562
  const defaultColors = [
@@ -1574,11 +1623,35 @@ var MultiBarGraph = ({
1574
1623
  (sum, dataset) => sum + (dataset.data[hoveredPoint.dataIndex] || 0),
1575
1624
  0
1576
1625
  );
1577
- const date = new Date(label);
1578
- const formattedLabel = date.toLocaleString("en-US", {
1579
- month: "long",
1580
- year: "numeric"
1581
- });
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
+ }
1582
1655
  const percentage = totalBarValue > 0 ? (segmentValue / totalBarValue * 100).toFixed(2) : 0;
1583
1656
  const iconHtml = customSvgIcon || getDefaultSvgIcon();
1584
1657
  tooltipEl.innerHTML = `