pace-table-lib 1.0.8 → 1.0.9

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.
@@ -12,3 +12,4 @@ export declare function computeMatrix<T>(rawDataMatrix: number[][], mode: "All"
12
12
  export declare function compareVal(a: number, op: string, b: number): boolean;
13
13
  export declare function applyConditionalFormatting(style: CSSProperties, conFormat?: any): CSSProperties;
14
14
  export declare function applyFormat(obj: any, format: any): void;
15
+ export declare function getPercentageBy(dataValue: any, totalValue: any): number;
@@ -54,6 +54,8 @@ type TableDataTypes = {
54
54
  minValueInRow: number;
55
55
  }[];
56
56
  totalNumberOfRows: number;
57
+ rowDateFormatObj?: any;
58
+ columnDateFormatObj?: any;
57
59
  };
58
60
  type TableStyleConfig = {
59
61
  ToolTip: {
@@ -8032,45 +8032,48 @@ function toDateFromExcel(value) {
8032
8032
  return new Date(ms);
8033
8033
  }
8034
8034
  function formatDate(value, formatKey) {
8035
- const date = toDateFromExcel(value);
8036
- const day = pad(date.getDate());
8037
- const month = pad(date.getMonth() + 1);
8038
- const year = date.getFullYear();
8039
- const shortYear = year.toString().slice(-2);
8040
- const monthShort = MONTHS_SHORT[date.getMonth()];
8041
- const monthFull = MONTHS_FULL[date.getMonth()];
8042
- switch (formatKey) {
8043
- case DATE_FORMAT_OBJ.DD_MM_YYYY:
8044
- return `${day}-${month}-${year}`;
8045
- case DATE_FORMAT_OBJ.MM_DD_YYYY:
8046
- return `${month}-${day}-${year}`;
8047
- case DATE_FORMAT_OBJ.YYYY_MM_DD:
8048
- return `${year}-${month}-${day}`;
8049
- case DATE_FORMAT_OBJ.YYYY:
8050
- return `${year}`;
8051
- case DATE_FORMAT_OBJ.DD_MM:
8052
- return `${day}-${month}`;
8053
- case DATE_FORMAT_OBJ.MMM_YY:
8054
- return `${monthShort}-${shortYear}`;
8055
- case DATE_FORMAT_OBJ.YY_MMM:
8056
- return `${shortYear}-${monthShort}`;
8057
- case DATE_FORMAT_OBJ.MM_YYYY:
8058
- return `${month}-${year}`;
8059
- case DATE_FORMAT_OBJ.YYYY_MM:
8060
- return `${year}-${month}`;
8061
- case DATE_FORMAT_OBJ.MMMM_YYYY:
8062
- return `${monthFull}-${year}`;
8063
- case DATE_FORMAT_OBJ.MMMM_YY:
8064
- return `${monthFull}-${shortYear}`;
8065
- case DATE_FORMAT_OBJ.DD_MMM:
8066
- return `${day}-${monthShort}`;
8067
- case DATE_FORMAT_OBJ.DD_MMM_YY:
8068
- return `${day}-${monthShort}-${shortYear}`;
8069
- case DATE_FORMAT_OBJ.DD_MMM_YYYY:
8070
- return `${day}-${monthShort}-${year}`;
8071
- default:
8072
- throw new Error("Unsupported date format: " + formatKey);
8035
+ try {
8036
+ const date = toDateFromExcel(value);
8037
+ const day = pad(date.getDate());
8038
+ const month = pad(date.getMonth() + 1);
8039
+ const year = date.getFullYear();
8040
+ const shortYear = year.toString().slice(-2);
8041
+ const monthShort = MONTHS_SHORT[date.getMonth()];
8042
+ const monthFull = MONTHS_FULL[date.getMonth()];
8043
+ switch (formatKey) {
8044
+ case DATE_FORMAT_OBJ.DD_MM_YYYY:
8045
+ return `${day}-${month}-${year}`;
8046
+ case DATE_FORMAT_OBJ.MM_DD_YYYY:
8047
+ return `${month}-${day}-${year}`;
8048
+ case DATE_FORMAT_OBJ.YYYY_MM_DD:
8049
+ return `${year}-${month}-${day}`;
8050
+ case DATE_FORMAT_OBJ.YYYY:
8051
+ return `${year}`;
8052
+ case DATE_FORMAT_OBJ.DD_MM:
8053
+ return `${day}-${month}`;
8054
+ case DATE_FORMAT_OBJ.MMM_YY:
8055
+ return `${monthShort}-${shortYear}`;
8056
+ case DATE_FORMAT_OBJ.YY_MMM:
8057
+ return `${shortYear}-${monthShort}`;
8058
+ case DATE_FORMAT_OBJ.MM_YYYY:
8059
+ return `${month}-${year}`;
8060
+ case DATE_FORMAT_OBJ.YYYY_MM:
8061
+ return `${year}-${month}`;
8062
+ case DATE_FORMAT_OBJ.MMMM_YYYY:
8063
+ return `${monthFull}-${year}`;
8064
+ case DATE_FORMAT_OBJ.MMMM_YY:
8065
+ return `${monthFull}-${shortYear}`;
8066
+ case DATE_FORMAT_OBJ.DD_MMM:
8067
+ return `${day}-${monthShort}`;
8068
+ case DATE_FORMAT_OBJ.DD_MMM_YY:
8069
+ return `${day}-${monthShort}-${shortYear}`;
8070
+ case DATE_FORMAT_OBJ.DD_MMM_YYYY:
8071
+ return `${day}-${monthShort}-${year}`;
8072
+ }
8073
+ } catch (error) {
8074
+ console.log(error);
8073
8075
  }
8076
+ return value;
8074
8077
  }
8075
8078
  function formatValue(value, format, decimalValues = 2, displayUnit = DISPLAY_UNITS_OBJ.NONE) {
8076
8079
  try {
@@ -8133,8 +8136,8 @@ function formatValue(value, format, decimalValues = 2, displayUnit = DISPLAY_UNI
8133
8136
  }
8134
8137
  } catch (error) {
8135
8138
  console.error("Error in formatValue:", error);
8136
- return value;
8137
8139
  }
8140
+ return value;
8138
8141
  }
8139
8142
  function getFontStyleObj(stylePayload) {
8140
8143
  let baseStyleObj = {
@@ -8241,6 +8244,14 @@ function applyFormat(obj, format) {
8241
8244
  if (format.hasOwnProperty("decimalPrecision")) obj.decimalPrecision = format.decimalPrecision;
8242
8245
  if (format.hasOwnProperty("displayUnits")) obj.displayUnits = format.displayUnits;
8243
8246
  }
8247
+ function getPercentageBy(dataValue, totalValue) {
8248
+ const num = Number(dataValue);
8249
+ const den = Number(totalValue);
8250
+ if (isNaN(num) || isNaN(den)) return num;
8251
+ if (den === 0) return num;
8252
+ const percentage = num / den;
8253
+ return percentage;
8254
+ }
8244
8255
  const renderDataCell = (label, styles, className, childClassName, toolTip, dataBarBg) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { title: toolTip ?? label, className, style: styles, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: childClassName, style: { fontFamily: styles.fontFamily, textAlign: styles.justifyContent, background: dataBarBg ?? "none" }, children: label }) });
8245
8256
  function StaticTable({
8246
8257
  tableData,
@@ -8410,20 +8421,6 @@ function StaticTable({
8410
8421
  }
8411
8422
  );
8412
8423
  }, [rawDataMatrix, isDataBarOn, KPI.KPIBaseFormat]);
8413
- const percentageMatrix = useMemo(() => {
8414
- console.log("Calculating percentage matrix");
8415
- if (DataField.hasOwnProperty("percentageBy") && DataField.percentageBy?.toLowerCase() !== "absolute")
8416
- return computeMatrix(
8417
- rawDataMatrix,
8418
- DataField.percentageBy,
8419
- (v, min, max) => {
8420
- if (max === min) return 1;
8421
- const pct = (v - min) / (max - min);
8422
- return Math.min(1, Math.max(0, pct));
8423
- }
8424
- );
8425
- console.log(DataField?.percentageBy);
8426
- }, [rawDataMatrix, DataField, DataField?.percentageBy]);
8427
8424
  const cornerCells = useMemo(() => {
8428
8425
  const cells = [];
8429
8426
  const baseStyle = {
@@ -8510,9 +8507,7 @@ function StaticTable({
8510
8507
  DisplayUnits
8511
8508
  );
8512
8509
  if (DataField.hasOwnProperty("percentageBy") && DataField.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8513
- const lastRow = percentageMatrix && percentageMatrix[percentageMatrix.length - 1];
8514
- const lastVal = lastRow && lastRow[lastRow?.length - 1];
8515
- label = formatValue(lastVal, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8510
+ label = formatValue(1, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8516
8511
  }
8517
8512
  cells.push({
8518
8513
  label,
@@ -8586,7 +8581,13 @@ function StaticTable({
8586
8581
  const parent = dimensionMarks[i][0] ?? "";
8587
8582
  if (isFirstOccurrence(dimensionMarks, i, level)) {
8588
8583
  const span = getSpan(dimensionMarks, i, level);
8589
- const colLabel = getCleanString(dimensionMarks[i][level]);
8584
+ let colLabel = getCleanString(dimensionMarks[i][level]);
8585
+ if (tableData.hasOwnProperty("columnDateFormatObj") && tableData?.columnDateFormatObj) {
8586
+ const dFormat = tableData.columnDateFormatObj[level];
8587
+ if (dFormat) {
8588
+ colLabel = formatValue(colLabel, dFormat);
8589
+ }
8590
+ }
8590
8591
  levelStyle.background = parentColorMap[parent];
8591
8592
  const finalStyleForColumn = getFinalStyleObj(STYLE_FOR.COLUMN, levelStyle, colLabel, level);
8592
8593
  headers.push({
@@ -8607,8 +8608,7 @@ function StaticTable({
8607
8608
  let label = formatValue(item.columnTotal, NumberFormat, DataFieldDecimalPrecision, DisplayUnits);
8608
8609
  const innerBg = getBgColorForDataBar(0, idx);
8609
8610
  if (DataField.hasOwnProperty("percentageBy") && DataField.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8610
- const percentageVal = percentageMatrix && percentageMatrix[percentageMatrix?.length - 1][idx];
8611
- label = formatValue(percentageVal, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8611
+ label = formatValue(1, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8612
8612
  }
8613
8613
  headers.push({
8614
8614
  ...dataCellFont,
@@ -8674,7 +8674,13 @@ function StaticTable({
8674
8674
  }
8675
8675
  if (isFirstOccurrence(marks, i, level)) {
8676
8676
  const span = getSpan(marks, i, level);
8677
- const rowLabel = marks[i][level];
8677
+ let rowLabel = marks[i][level];
8678
+ if (tableData.hasOwnProperty("rowDateFormatObj") && tableData?.rowDateFormatObj) {
8679
+ const dFormat = tableData.rowDateFormatObj[level];
8680
+ if (dFormat) {
8681
+ rowLabel = formatValue(rowLabel, dFormat);
8682
+ }
8683
+ }
8678
8684
  const finalStyleForRow = getFinalStyleObj(STYLE_FOR.ROW, baseStyleObj, rowLabel, level, groupIndex);
8679
8685
  headers.push({
8680
8686
  ...finalStyleForRow,
@@ -8699,10 +8705,7 @@ function StaticTable({
8699
8705
  let label = formatValue(row.rowTotal, NumberFormat, DataFieldDecimalPrecision, DisplayUnits);
8700
8706
  const innerBg = getBgColorForDataBar(i, dataBarMatrix[0]?.length - 1);
8701
8707
  if (DataField.hasOwnProperty("percentageBy") && DataField.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8702
- const rowData = (percentageMatrix && percentageMatrix[i]) ?? [0];
8703
- const percentageVal = rowData[rowData?.length - 1];
8704
- label = formatValue(percentageVal, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8705
- console.log(rawDataMatrix);
8708
+ label = formatValue(1, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8706
8709
  }
8707
8710
  headers.push({
8708
8711
  ...dataCellFont,
@@ -8759,90 +8762,55 @@ function StaticTable({
8759
8762
  if (rowIndex < fixedRowCount || columnIndex < fixedColCount) return null;
8760
8763
  const rowIdxHeat = rowIndex - fixedRowCount;
8761
8764
  const colIdxHeat = columnIndex - fixedColCount;
8762
- let pct;
8763
- let innerDivBg = "none";
8764
- if (isDataBarOn) {
8765
- if (showDataBarValOnTooltip) {
8766
- const val = dataBarMatrix[rowIdxHeat]?.[colIdxHeat];
8767
- if (val !== void 0) pct = `${(val * 100).toFixed(2)}%`;
8768
- }
8769
- innerDivBg = getBgColorForDataBar(rowIdxHeat, colIdxHeat);
8770
- }
8771
- const parent = measuresBySlice[rowIdxHeat]?.sliceMark?.[0];
8772
- const parentBg = parent ? parentBandColorMap[parent] : void 0;
8773
- let outerDivBg = "none";
8774
- if (ShowHeatMap) {
8775
- outerDivBg = getBgColorForHetMap(rowIdxHeat, colIdxHeat);
8776
- } else {
8777
- outerDivBg = parentBg ?? dataColors.evenColor;
8778
- }
8779
- const baseStyle = {
8780
- ...style,
8781
- ...dataCellFont,
8782
- background: outerDivBg
8783
- };
8765
+ const isPercentageMode = DataField?.percentageBy?.toLowerCase?.() && DataField.percentageBy.toLowerCase() !== "absolute";
8784
8766
  const isLastRow = rowIndex === rowCount - 1;
8785
8767
  const isLastCol = columnIndex === columnCount - 1;
8768
+ const val = dataBarMatrix[rowIdxHeat]?.[colIdxHeat];
8769
+ const pct = isDataBarOn && showDataBarValOnTooltip && val !== void 0 ? `${(val * 100).toFixed(2)}%` : void 0;
8770
+ const innerDivBg = isDataBarOn ? getBgColorForDataBar(rowIdxHeat, colIdxHeat) : "none";
8771
+ const parent = measuresBySlice[rowIdxHeat]?.sliceMark?.[0];
8772
+ const outerDivBg = ShowHeatMap ? getBgColorForHetMap(rowIdxHeat, colIdxHeat) : parent ? parentBandColorMap[parent] : dataColors.evenColor;
8773
+ const baseStyle = { ...style, ...dataCellFont, background: outerDivBg };
8786
8774
  let rawValue;
8787
8775
  let isBold = true;
8788
8776
  const bgColorForTotals = getBgColorForCell(rowCount - fixedRowCount, dataColors);
8789
8777
  if (isColTotalOn && isRowTotalOn && !headerAtStart && isLastRow && isLastCol) {
8790
8778
  baseStyle.background = bgColorForTotals;
8791
- rawValue = grandTotal;
8792
- if (DataField.hasOwnProperty("percentageBy") && DataField.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8793
- const lastRow = percentageMatrix && percentageMatrix[percentageMatrix.length - 1];
8794
- rawValue = lastRow && lastRow[lastRow?.length - 1];
8795
- }
8779
+ rawValue = isPercentageMode ? 1 : grandTotal;
8796
8780
  } else if (isColTotalOn && !headerAtStart && isLastRow) {
8797
8781
  baseStyle.background = bgColorForTotals;
8798
- rawValue = columnTotalRow[colIdxHeat]?.columnTotal;
8799
- if (DataField.hasOwnProperty("percentageBy") && DataField.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8800
- rawValue = percentageMatrix && percentageMatrix[percentageMatrix.length - 1][colIdxHeat];
8801
- }
8782
+ rawValue = isPercentageMode ? 1 : columnTotalRow[colIdxHeat]?.columnTotal;
8802
8783
  } else if (isRowTotalOn && !headerAtStart && isLastCol) {
8803
- const rowData = (percentageMatrix && percentageMatrix[rowIdxHeat]) ?? [0];
8804
- rawValue = rowData[rowData?.length - 1];
8805
- } else if (DataField.hasOwnProperty("percentageBy") && DataField?.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8806
- rawValue = percentageMatrix && percentageMatrix[rowIdxHeat][colIdxHeat];
8784
+ rawValue = 1;
8785
+ } else if (isPercentageMode) {
8786
+ if (DataField?.percentageBy === "Row-wise") {
8787
+ rawValue = getPercentageBy(measuresBySlice[rowIdxHeat]?.measures?.[colIdxHeat], measuresBySlice[rowIdxHeat].rowTotal);
8788
+ } else {
8789
+ rawValue = getPercentageBy(measuresBySlice[rowIdxHeat]?.measures?.[colIdxHeat], tableData.columnTotalRow[rowIdxHeat].columnTotal);
8790
+ }
8807
8791
  isBold = false;
8808
8792
  } else {
8809
8793
  rawValue = measuresBySlice[rowIdxHeat]?.measures?.[colIdxHeat];
8810
8794
  isBold = false;
8811
8795
  }
8812
8796
  if (rawValue === void 0) return null;
8813
- const dimName = dimensionMarks[colIdxHeat]?.[fixedRowCount - 1] ?? void 0;
8797
+ const dimName = dimensionMarks[colIdxHeat]?.[fixedRowCount - 1];
8814
8798
  const formattingObj = getMeasureFormattingObj(dimName);
8815
8799
  const conditionalFormatObj = getConditionalFormat(rawValue, CONDITIONAL_FORMAT_FOR.VALUE);
8816
8800
  const numberFormat = conditionalFormatObj?.numberFormat ?? formattingObj.numberFormat;
8817
8801
  const decimalPrecision = conditionalFormatObj?.decimalPrecision ?? formattingObj.decimalPrecision;
8818
8802
  const displayUnits = conditionalFormatObj?.displayUnits ?? formattingObj.displayUnits;
8819
- let formattedValue = formatValue(
8820
- rawValue,
8821
- numberFormat,
8822
- decimalPrecision,
8823
- displayUnits
8824
- );
8825
- if (DataField.hasOwnProperty("percentageBy") && DataField?.percentageBy && DataField.percentageBy?.toLowerCase() !== "absolute") {
8826
- formattedValue = formatValue(rawValue, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8827
- }
8828
- let finalStyle = {
8803
+ let formattedValue = formatValue(rawValue, numberFormat, decimalPrecision, displayUnits);
8804
+ if (isPercentageMode) formattedValue = formatValue(rawValue, VALUE_FORMAT_OBJ.PERCENT_SHORT);
8805
+ const finalStyle = {
8829
8806
  ...baseStyle,
8830
- fontWeight: isBold ? "bold" : "normal"
8807
+ fontWeight: isBold ? "bold" : "normal",
8808
+ ...conditionalFormatObj?.fontFamily && { fontFamily: conditionalFormatObj.fontFamily },
8809
+ ...conditionalFormatObj?.fontSize && { fontSize: conditionalFormatObj.fontSize },
8810
+ ...conditionalFormatObj?.backgroundColor && { background: conditionalFormatObj.backgroundColor },
8811
+ ...conditionalFormatObj?.color && { color: conditionalFormatObj.color }
8831
8812
  };
8832
- if (conditionalFormatObj) {
8833
- if (conditionalFormatObj.fontFamily) finalStyle.fontFamily = conditionalFormatObj.fontFamily;
8834
- if (conditionalFormatObj.fontSize) finalStyle.fontSize = conditionalFormatObj.fontSize;
8835
- if (conditionalFormatObj.backgroundColor) finalStyle.background = conditionalFormatObj.backgroundColor;
8836
- if (conditionalFormatObj.color) finalStyle.color = conditionalFormatObj.color;
8837
- }
8838
- return renderDataCell(
8839
- formattedValue,
8840
- finalStyle,
8841
- "data_div",
8842
- "data_label_div",
8843
- pct,
8844
- innerDivBg
8845
- );
8813
+ return renderDataCell(formattedValue, finalStyle, "data_div", "data_label_div", pct, innerDivBg);
8846
8814
  };
8847
8815
  function getBgColorForHetMap(rowIdx, colIdx) {
8848
8816
  return heatColorMatrix[rowIdx][colIdx];