@trackunit/react-chart-components 2.6.49-alpha-7317206cecd.0 → 2.6.50

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/index.cjs.js CHANGED
@@ -573,6 +573,7 @@ const BarChart = ({ series, loading = false, onClick, className, style, "data-te
573
573
  };
574
574
  const cvaChartRoot$1 = cssClassVarianceUtilities.cva({ base: ["flex", "flex-col", "items-center", "h-full"] });
575
575
 
576
+ const CHART_DEFAULT_OTHER_ID = "defaultOther";
576
577
  /**
577
578
  * Limits the data set to the given limit.
578
579
  * If the data set is larger than the limit, the data set is limited to the limit and the rest of the data is added to the "Others" group.
@@ -588,13 +589,18 @@ const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
588
589
  const sortedData = autoSortData ? data.toSorted((a, b) => (b.value ?? 0) - (a.value ?? 0)) : data;
589
590
  if (sortedData.length > limit) {
590
591
  const result = sortedData.slice(0, limit);
592
+ const tail = sortedData.slice(limit);
593
+ const othersOriginal = Object.assign({}, tail[0]?.original, {
594
+ defaultOther: true,
595
+ ids: tail.map(item => item.id),
596
+ });
591
597
  result.push({
592
- id: "defaultOther",
598
+ id: CHART_DEFAULT_OTHER_ID,
593
599
  name: othersName ?? "Others",
594
600
  selected: false,
595
- value: sortedData.slice(limit).reduce((acc, curr) => acc + (curr.value ?? 0), 0),
601
+ value: tail.reduce((acc, curr) => acc + (curr.value ?? 0), 0),
596
602
  color: uiDesignTokens.DEFAULT_CHART_OTHER,
597
- original: { defaultOther: true },
603
+ original: othersOriginal,
598
604
  });
599
605
  return result;
600
606
  }
@@ -663,8 +669,8 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
663
669
  chartRef.current = chart;
664
670
  }, []);
665
671
  const handleChartClick = react.useCallback((evt) => {
666
- if (onClick && data) {
667
- const clickedEntry = data.find(x => {
672
+ if (onClick) {
673
+ const clickedEntry = limitedData.find(x => {
668
674
  if (evt.data === null || evt.data === undefined || typeof evt.data !== "object" || !("id" in evt.data)) {
669
675
  return false;
670
676
  }
@@ -674,7 +680,7 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
674
680
  onClick(clickedEntry);
675
681
  }
676
682
  }
677
- }, [onClick, data]);
683
+ }, [onClick, limitedData]);
678
684
  const handleChartMouseOver = react.useCallback(() => {
679
685
  setIsHovering(true);
680
686
  }, []);
@@ -799,6 +805,7 @@ const cvaChart = cssClassVarianceUtilities.cva({
799
805
  const cvaLegend = cssClassVarianceUtilities.cva({ base: ["flex", "overflow-auto", "justify-start", "flex-col", "flex-1"] });
800
806
 
801
807
  exports.BarChart = BarChart;
808
+ exports.CHART_DEFAULT_OTHER_ID = CHART_DEFAULT_OTHER_ID;
802
809
  exports.Chart = Chart;
803
810
  exports.DonutChart = DonutChart;
804
811
  exports.EChart = EChart;
package/index.esm.js CHANGED
@@ -552,6 +552,7 @@ const BarChart = ({ series, loading = false, onClick, className, style, "data-te
552
552
  };
553
553
  const cvaChartRoot$1 = cva({ base: ["flex", "flex-col", "items-center", "h-full"] });
554
554
 
555
+ const CHART_DEFAULT_OTHER_ID = "defaultOther";
555
556
  /**
556
557
  * Limits the data set to the given limit.
557
558
  * If the data set is larger than the limit, the data set is limited to the limit and the rest of the data is added to the "Others" group.
@@ -567,13 +568,18 @@ const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
567
568
  const sortedData = autoSortData ? data.toSorted((a, b) => (b.value ?? 0) - (a.value ?? 0)) : data;
568
569
  if (sortedData.length > limit) {
569
570
  const result = sortedData.slice(0, limit);
571
+ const tail = sortedData.slice(limit);
572
+ const othersOriginal = Object.assign({}, tail[0]?.original, {
573
+ defaultOther: true,
574
+ ids: tail.map(item => item.id),
575
+ });
570
576
  result.push({
571
- id: "defaultOther",
577
+ id: CHART_DEFAULT_OTHER_ID,
572
578
  name: othersName ?? "Others",
573
579
  selected: false,
574
- value: sortedData.slice(limit).reduce((acc, curr) => acc + (curr.value ?? 0), 0),
580
+ value: tail.reduce((acc, curr) => acc + (curr.value ?? 0), 0),
575
581
  color: DEFAULT_CHART_OTHER,
576
- original: { defaultOther: true },
582
+ original: othersOriginal,
577
583
  });
578
584
  return result;
579
585
  }
@@ -642,8 +648,8 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
642
648
  chartRef.current = chart;
643
649
  }, []);
644
650
  const handleChartClick = useCallback((evt) => {
645
- if (onClick && data) {
646
- const clickedEntry = data.find(x => {
651
+ if (onClick) {
652
+ const clickedEntry = limitedData.find(x => {
647
653
  if (evt.data === null || evt.data === undefined || typeof evt.data !== "object" || !("id" in evt.data)) {
648
654
  return false;
649
655
  }
@@ -653,7 +659,7 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
653
659
  onClick(clickedEntry);
654
660
  }
655
661
  }
656
- }, [onClick, data]);
662
+ }, [onClick, limitedData]);
657
663
  const handleChartMouseOver = useCallback(() => {
658
664
  setIsHovering(true);
659
665
  }, []);
@@ -777,4 +783,4 @@ const cvaChart = cva({
777
783
  });
778
784
  const cvaLegend = cva({ base: ["flex", "overflow-auto", "justify-start", "flex-col", "flex-1"] });
779
785
 
780
- export { BarChart, Chart, DonutChart, EChart, LegendItem, useChartColor, useChartNumberFormat };
786
+ export { BarChart, CHART_DEFAULT_OTHER_ID, Chart, DonutChart, EChart, LegendItem, useChartColor, useChartNumberFormat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-chart-components",
3
- "version": "2.6.49-alpha-7317206cecd.0",
3
+ "version": "2.6.50",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -9,12 +9,12 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "echarts": "5.6.0",
12
- "@trackunit/date-and-time-utils": "1.14.32-alpha-7317206cecd.0",
13
- "@trackunit/react-date-and-time-hooks": "2.6.48-alpha-7317206cecd.0",
14
- "@trackunit/ui-design-tokens": "1.15.21-alpha-7317206cecd.0",
15
- "@trackunit/shared-utils": "1.16.34-alpha-7317206cecd.0",
16
- "@trackunit/css-class-variance-utilities": "2.0.1-alpha-7317206cecd.0",
17
- "@trackunit/react-components": "2.13.2-alpha-7317206cecd.0"
12
+ "@trackunit/date-and-time-utils": "1.14.33",
13
+ "@trackunit/react-date-and-time-hooks": "2.6.49",
14
+ "@trackunit/ui-design-tokens": "1.15.22",
15
+ "@trackunit/shared-utils": "1.16.35",
16
+ "@trackunit/css-class-variance-utilities": "2.0.2",
17
+ "@trackunit/react-components": "2.13.3"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@apollo/client": "^3.13.8",
package/src/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from "./EChart/EChart";
5
5
  export * from "./LegendItem/LegendItem";
6
6
  export * from "./utils/useChartColor";
7
7
  export * from "./utils/useChartNumberFormat";
8
+ export { CHART_DEFAULT_OTHER_ID } from "./utils/useLimitDataSet";
@@ -1,8 +1,11 @@
1
1
  import { ChartData } from "../DonutChart/DonutChart";
2
+ export declare const CHART_DEFAULT_OTHER_ID = "defaultOther";
3
+ type ChartTailOthersOriginal = {
4
+ defaultOther?: boolean;
5
+ ids?: Array<string>;
6
+ };
2
7
  type LimitDataSetReturn<TProps extends object> = {
3
- limitedData: Array<ChartData<TProps & {
4
- defaultOther?: boolean;
5
- }>>;
8
+ limitedData: Array<ChartData<TProps & ChartTailOthersOriginal>>;
6
9
  limitedDataWithoutOthers: Array<ChartData<TProps>>;
7
10
  };
8
11
  /**