@economic/taco 2.55.1-footer.0 → 2.57.0-charts.0

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/taco.js CHANGED
@@ -19610,8 +19610,8 @@ function mixValues(target, follow, lead, progress2, shouldCrossfadeOpacity, isOn
19610
19610
  }
19611
19611
  for (var i3 = 0; i3 < numBorders; i3++) {
19612
19612
  var borderLabel = "border".concat(borders[i3], "Radius");
19613
- var followRadius = getRadius(follow, borderLabel);
19614
- var leadRadius = getRadius(lead, borderLabel);
19613
+ var followRadius = getRadius$1(follow, borderLabel);
19614
+ var leadRadius = getRadius$1(lead, borderLabel);
19615
19615
  if (followRadius === void 0 && leadRadius === void 0)
19616
19616
  continue;
19617
19617
  followRadius || (followRadius = 0);
@@ -19630,7 +19630,7 @@ function mixValues(target, follow, lead, progress2, shouldCrossfadeOpacity, isOn
19630
19630
  target.rotate = mix(follow.rotate || 0, lead.rotate || 0, progress2);
19631
19631
  }
19632
19632
  }
19633
- function getRadius(values, radiusName) {
19633
+ function getRadius$1(values, radiusName) {
19634
19634
  var _a;
19635
19635
  return (_a = values[radiusName]) !== null && _a !== void 0 ? _a : values.borderRadius;
19636
19636
  }
@@ -31994,10 +31994,9 @@ function useTableDataLoader(fetchPage, fetchAll, options = { pageSize: DEFAULT_P
31994
31994
  const _lastUsedSearch = React__default.useRef();
31995
31995
  const _lastUsedHiddenColumns = React__default.useRef([]);
31996
31996
  const _lastUsedPageIndex = React__default.useRef();
31997
- const _forceReset = React__default.useRef(false);
31998
31997
  const loadPage = async (pageIndex, sorting, filters, hiddenColumns) => {
31999
31998
  let reset = false;
32000
- if (_forceReset.current || JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current)) {
31999
+ if (JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current)) {
32001
32000
  _pendingPageRequests.current = {};
32002
32001
  reset = true;
32003
32002
  }
@@ -32006,7 +32005,6 @@ function useTableDataLoader(fetchPage, fetchAll, options = { pageSize: DEFAULT_P
32006
32005
  } else {
32007
32006
  _pendingPageRequests.current[pageIndex] = true;
32008
32007
  }
32009
- _forceReset.current = false;
32010
32008
  _lastUsedPageIndex.current = pageIndex;
32011
32009
  _lastUsedSorting.current = sorting;
32012
32010
  _lastUsedFilters.current = filters;
@@ -32050,12 +32048,41 @@ function useTableDataLoader(fetchPage, fetchAll, options = { pageSize: DEFAULT_P
32050
32048
  } catch {
32051
32049
  }
32052
32050
  };
32051
+ const reloadCurrentPages = async (pageIndex, sorting, filters, hiddenColumns) => {
32052
+ _lastUsedPageIndex.current;
32053
+ const pageIndexes = pageIndex === 0 ? [0, 1] : [pageIndex - 1, pageIndex];
32054
+ if (length.current !== void 0) {
32055
+ const pageCount = Math.ceil(length.current / pageSize);
32056
+ if (pageIndex + 1 < pageCount) {
32057
+ pageIndexes.push(pageIndex + 1);
32058
+ }
32059
+ }
32060
+ _pendingPageRequests.current = pageIndexes.reduce((accum, index2) => ({ ...accum, [index2]: true }), {});
32061
+ _lastUsedPageIndex.current = pageIndex;
32062
+ _lastUsedSorting.current = sorting;
32063
+ _lastUsedFilters.current = filters;
32064
+ _lastUsedHiddenColumns.current = hiddenColumns;
32065
+ try {
32066
+ const responses = await Promise.all(
32067
+ pageIndexes.map((pageIndex2) => fetchPage(pageIndex2, pageSize, sorting, filters, hiddenColumns))
32068
+ );
32069
+ length.current = responses[0].length;
32070
+ const nextData = Array(length.current).fill(void 0);
32071
+ responses.forEach((response, index2) => {
32072
+ const startIndex = pageIndexes[index2] * pageSize;
32073
+ nextData.splice(startIndex, pageSize, ...response.data);
32074
+ });
32075
+ setData(nextData);
32076
+ } catch {
32077
+ } finally {
32078
+ _pendingPageRequests.current = {};
32079
+ }
32080
+ };
32053
32081
  const invalidate = async () => {
32054
- _forceReset.current = true;
32055
32082
  if (_lastUsedSearch.current) {
32056
32083
  return loadAll(_lastUsedSorting.current, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
32057
32084
  } else {
32058
- return loadPage(
32085
+ return reloadCurrentPages(
32059
32086
  _lastUsedPageIndex.current ?? 0,
32060
32087
  _lastUsedSorting.current,
32061
32088
  _lastUsedFilters.current,
@@ -32067,7 +32094,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = { pageSize: DEFAULT_P
32067
32094
  if (_lastUsedSearch.current) {
32068
32095
  return loadAll(sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
32069
32096
  } else {
32070
- return loadPage(_lastUsedPageIndex.current ?? 0, sorting, _lastUsedFilters.current, _lastUsedHiddenColumns.current);
32097
+ return reloadCurrentPages(
32098
+ _lastUsedPageIndex.current ?? 0,
32099
+ sorting,
32100
+ _lastUsedFilters.current,
32101
+ _lastUsedHiddenColumns.current
32102
+ );
32071
32103
  }
32072
32104
  };
32073
32105
  const handleFilter = async (filters) => {
@@ -32361,9 +32393,10 @@ function useTableSettingsListener(table, onChangeSettings) {
32361
32393
  state.sorting
32362
32394
  ]);
32363
32395
  }
32364
- function useTableShortcutsListener(table, shortcuts) {
32396
+ function useTableShortcutsListener(table, tableRef, shortcuts, localShortcuts = false) {
32365
32397
  const meta = table.options.meta;
32366
32398
  const rows = table.getRowModel().rows;
32399
+ const listenerTarget = localShortcuts ? tableRef.current : document;
32367
32400
  React__default.useEffect(() => {
32368
32401
  const shortcutKeys = Object.keys(shortcuts ?? {});
32369
32402
  const globalHandlers = [];
@@ -32396,18 +32429,38 @@ function useTableShortcutsListener(table, shortcuts) {
32396
32429
  });
32397
32430
  }
32398
32431
  globalHandlers.forEach((handler) => {
32399
- document.addEventListener("keydown", handler);
32432
+ listenerTarget == null ? void 0 : listenerTarget.addEventListener("keydown", handler);
32400
32433
  });
32401
32434
  return () => {
32402
32435
  globalHandlers.forEach((handler) => {
32403
- document.removeEventListener("keydown", handler);
32436
+ listenerTarget == null ? void 0 : listenerTarget.removeEventListener("keydown", handler);
32404
32437
  });
32405
32438
  };
32406
32439
  }, [shortcuts, meta.rowActive.rowActiveIndex, rows.length]);
32407
32440
  }
32441
+ function useLazyDebouncedEffect(effect, deps, ms = 200) {
32442
+ const readyRef = React__default.useRef(false);
32443
+ const timeoutRef = React__default.useRef();
32444
+ React__default.useEffect(() => {
32445
+ if (readyRef.current) {
32446
+ timeoutRef.current = setTimeout(effect, ms);
32447
+ } else {
32448
+ readyRef.current = true;
32449
+ }
32450
+ return () => {
32451
+ clearTimeout(timeoutRef.current);
32452
+ };
32453
+ }, deps);
32454
+ React__default.useEffect(
32455
+ () => () => {
32456
+ readyRef.current = false;
32457
+ },
32458
+ []
32459
+ );
32460
+ }
32408
32461
  function useTableSortingListener$1(table, onSort) {
32409
32462
  const sorting = table.getState().sorting;
32410
- useLazyEffect(() => {
32463
+ useLazyDebouncedEffect(() => {
32411
32464
  if (table.options.enableSorting && typeof onSort === "function") {
32412
32465
  onSort(sorting);
32413
32466
  if (table.options.enableRowSelection) {
@@ -32425,6 +32478,9 @@ function useTableServerLoadingListener(table, loadPage) {
32425
32478
  const hiddenColumns = getHiddenColumns(table.getState().columnVisibility);
32426
32479
  const search = meta.search.enableGlobalFilter ? table.getState().globalFilter : void 0;
32427
32480
  loadPage(0, sorting, columnFilters, hiddenColumns, search);
32481
+ if (meta.server._experimentalDataLoader2) {
32482
+ loadPage(1, sorting, columnFilters, hiddenColumns, search);
32483
+ }
32428
32484
  }
32429
32485
  }, []);
32430
32486
  }
@@ -32444,7 +32500,7 @@ function useTableRowDrop(isEnabled = false, onRowDrop) {
32444
32500
  };
32445
32501
  }
32446
32502
  const DEFAULT_EMPTY_ARRAY = [];
32447
- function useTableManager(props, meta, internalColumns) {
32503
+ function useTableManager(props, ref, meta, internalColumns) {
32448
32504
  var _a;
32449
32505
  const localization = useLocalization();
32450
32506
  const safeId = props.id.replace(".", "_");
@@ -32543,7 +32599,7 @@ function useTableManager(props, meta, internalColumns) {
32543
32599
  useTableSearchListener(instance);
32544
32600
  useTableServerLoadingListener(instance, server.loadPage);
32545
32601
  useTableSettingsListener(instance, setSettings);
32546
- useTableShortcutsListener(instance, props.shortcuts);
32602
+ useTableShortcutsListener(instance, ref, props.shortcuts, props.enableLocalKeyboardShortcuts);
32547
32603
  useTableSortingListener$1(instance, props.onChangeSort);
32548
32604
  return {
32549
32605
  id: safeId,
@@ -32733,9 +32789,10 @@ function getCellWidthPadding(fontSize) {
32733
32789
  return "16px";
32734
32790
  }
32735
32791
  }
32736
- function useTableGlobalShortcuts(table, tableRef, scrollToIndex) {
32792
+ function useTableGlobalShortcuts(table, tableRef, scrollToIndex, localShortcuts = false) {
32737
32793
  const tableMeta = table.options.meta;
32738
32794
  const rows = table.getRowModel().rows;
32795
+ const listenerTarget = localShortcuts ? tableRef.current : document;
32739
32796
  React__default.useEffect(
32740
32797
  () => {
32741
32798
  const handleKeyDown = (event) => {
@@ -32750,9 +32807,9 @@ function useTableGlobalShortcuts(table, tableRef, scrollToIndex) {
32750
32807
  tableMeta.rowClick.handleKeyDown(event, (_a = rows[tableMeta.rowActive.rowActiveIndex]) == null ? void 0 : _a.original);
32751
32808
  }
32752
32809
  };
32753
- document.addEventListener("keydown", handleKeyDown);
32810
+ listenerTarget == null ? void 0 : listenerTarget.addEventListener("keydown", handleKeyDown);
32754
32811
  return () => {
32755
- document.removeEventListener("keydown", handleKeyDown);
32812
+ listenerTarget == null ? void 0 : listenerTarget.removeEventListener("keydown", handleKeyDown);
32756
32813
  };
32757
32814
  },
32758
32815
  // scrollToIndex function changes when row count changes, so it is important to update handlers
@@ -33596,7 +33653,7 @@ function RowWithServerLoading(props) {
33596
33653
  }
33597
33654
  const Skeleton = React__default.forwardRef(function Skeleton2(props, ref) {
33598
33655
  const { cellsCount, index: index2 } = props;
33599
- return /* @__PURE__ */ React__default.createElement("tr", { "data-row-index": index2, ref }, Array(cellsCount).fill(null).map((_, index22) => /* @__PURE__ */ React__default.createElement("td", { key: index22 }, /* @__PURE__ */ React__default.createElement("span", { className: "bg-grey-100 text-grey-700 h-4 w-full text-center text-xs" }))));
33656
+ return /* @__PURE__ */ React__default.createElement("tr", { "data-row-index": index2, "data-row-id": index2, ref }, Array(cellsCount).fill(null).map((_, index22) => /* @__PURE__ */ React__default.createElement("td", { key: index22 }, /* @__PURE__ */ React__default.createElement("span", { className: "bg-grey-100 text-grey-700 h-4 w-full text-center text-xs" }))));
33600
33657
  });
33601
33658
  function getScrollPaddingEndOffset(table) {
33602
33659
  const tableMeta = table.options.meta;
@@ -34058,7 +34115,7 @@ const INTERNAL_RENDERERS = {
34058
34115
  };
34059
34116
  function useTable$1(props, externalRef, renderers, meta, options) {
34060
34117
  const ref = useMergedRef(externalRef);
34061
- const manager = useTableManager(props, meta, INTERNAL_RENDERERS);
34118
+ const manager = useTableManager(props, ref, meta, INTERNAL_RENDERERS);
34062
34119
  const renderer2 = useTableRenderer(
34063
34120
  renderers,
34064
34121
  manager.instance,
@@ -34068,7 +34125,7 @@ function useTable$1(props, externalRef, renderers, meta, options) {
34068
34125
  options
34069
34126
  );
34070
34127
  const { style, stylesheet } = useTableStyle(manager.id, manager.instance);
34071
- useTableGlobalShortcuts(manager.instance, ref, renderer2.scrollToIndex);
34128
+ useTableGlobalShortcuts(manager.instance, ref, renderer2.scrollToIndex, props.enableLocalKeyboardShortcuts);
34072
34129
  useTableRef(manager.instance, ref);
34073
34130
  useTableRowActiveListener(manager.instance, ref);
34074
34131
  return {
@@ -61488,7 +61545,7 @@ var symbolFactories = {
61488
61545
  symbolTriangle,
61489
61546
  symbolWye
61490
61547
  };
61491
- var RADIAN$2 = Math.PI / 180;
61548
+ var RADIAN$3 = Math.PI / 180;
61492
61549
  var getSymbolFactory = function getSymbolFactory2(type) {
61493
61550
  var name = "symbol".concat(upperFirst(type));
61494
61551
  return symbolFactories[name] || symbolCircle;
@@ -61505,7 +61562,7 @@ var calculateAreaSize = function calculateAreaSize2(size2, sizeType, type) {
61505
61562
  case "square":
61506
61563
  return size2 * size2;
61507
61564
  case "star": {
61508
- var angle = 18 * RADIAN$2;
61565
+ var angle = 18 * RADIAN$3;
61509
61566
  return 1.25 * size2 * size2 * (Math.tan(angle) - Math.tan(angle * 2) * Math.pow(Math.tan(angle), 2));
61510
61567
  }
61511
61568
  case "triangle":
@@ -63977,7 +64034,7 @@ function _iterableToArrayLimit$b(r2, l2) {
63977
64034
  function _arrayWithHoles$c(arr) {
63978
64035
  if (Array.isArray(arr)) return arr;
63979
64036
  }
63980
- var ResponsiveContainer$1 = /* @__PURE__ */ forwardRef(function(_ref, ref) {
64037
+ var ResponsiveContainer = /* @__PURE__ */ forwardRef(function(_ref, ref) {
63981
64038
  var aspect = _ref.aspect, _ref$initialDimension = _ref.initialDimension, initialDimension = _ref$initialDimension === void 0 ? {
63982
64039
  width: -1,
63983
64040
  height: -1
@@ -69115,7 +69172,7 @@ function _toPrimitive$y(t3, r2) {
69115
69172
  }
69116
69173
  return ("string" === r2 ? String : Number)(t3);
69117
69174
  }
69118
- var getLegendProps$1 = function getLegendProps(_ref) {
69175
+ var getLegendProps = function getLegendProps2(_ref) {
69119
69176
  var children = _ref.children, formattedGraphicalItems = _ref.formattedGraphicalItems, legendWidth = _ref.legendWidth, legendContent = _ref.legendContent;
69120
69177
  var legendItem = findChildByType(children, Legend$2);
69121
69178
  if (!legendItem) {
@@ -69458,7 +69515,7 @@ var getBarPosition = function getBarPosition2(_ref3) {
69458
69515
  var appendOffsetOfLegend = function appendOffsetOfLegend2(offset2, _unused, props, legendBox) {
69459
69516
  var children = props.children, width = props.width, margin = props.margin;
69460
69517
  var legendWidth = width - (margin.left || 0) - (margin.right || 0);
69461
- var legendProps = getLegendProps$1({
69518
+ var legendProps = getLegendProps({
69462
69519
  children,
69463
69520
  legendWidth
69464
69521
  });
@@ -70132,14 +70189,14 @@ function _iterableToArrayLimit$6(r2, l2) {
70132
70189
  function _arrayWithHoles$7(arr) {
70133
70190
  if (Array.isArray(arr)) return arr;
70134
70191
  }
70135
- var RADIAN$1 = Math.PI / 180;
70192
+ var RADIAN$2 = Math.PI / 180;
70136
70193
  var radianToDegree = function radianToDegree2(angleInRadian) {
70137
70194
  return angleInRadian * 180 / Math.PI;
70138
70195
  };
70139
70196
  var polarToCartesian = function polarToCartesian2(cx, cy, radius, angle) {
70140
70197
  return {
70141
- x: cx + Math.cos(-RADIAN$1 * angle) * radius,
70142
- y: cy + Math.sin(-RADIAN$1 * angle) * radius
70198
+ x: cx + Math.cos(-RADIAN$2 * angle) * radius,
70199
+ y: cy + Math.sin(-RADIAN$2 * angle) * radius
70143
70200
  };
70144
70201
  };
70145
70202
  var getMaxRadius = function getMaxRadius2(width, height) {
@@ -70647,7 +70704,7 @@ var getAttrsOfCartesianLabel = function getAttrsOfCartesianLabel2(props) {
70647
70704
  var isPolar = function isPolar2(viewBox) {
70648
70705
  return "cx" in viewBox && isNumber(viewBox.cx);
70649
70706
  };
70650
- function Label(_ref4) {
70707
+ function Label$1(_ref4) {
70651
70708
  var _ref4$offset = _ref4.offset, offset2 = _ref4$offset === void 0 ? 5 : _ref4$offset, restProps = _objectWithoutProperties$d(_ref4, _excluded$d);
70652
70709
  var props = _objectSpread$s({
70653
70710
  offset: offset2
@@ -70680,7 +70737,7 @@ function Label(_ref4) {
70680
70737
  breakAll: textBreakAll
70681
70738
  }), label);
70682
70739
  }
70683
- Label.displayName = "Label";
70740
+ Label$1.displayName = "Label";
70684
70741
  var parseViewBox = function parseViewBox2(props) {
70685
70742
  var cx = props.cx, cy = props.cy, angle = props.angle, startAngle = props.startAngle, endAngle = props.endAngle, r2 = props.r, radius = props.radius, innerRadius = props.innerRadius, outerRadius = props.outerRadius, x3 = props.x, y4 = props.y, top = props.top, left = props.left, width = props.width, height = props.height, clockWise = props.clockWise, labelViewBox = props.labelViewBox;
70686
70743
  if (labelViewBox) {
@@ -70733,40 +70790,40 @@ var parseLabel = function parseLabel2(label, viewBox) {
70733
70790
  return null;
70734
70791
  }
70735
70792
  if (label === true) {
70736
- return /* @__PURE__ */ React__default.createElement(Label, {
70793
+ return /* @__PURE__ */ React__default.createElement(Label$1, {
70737
70794
  key: "label-implicit",
70738
70795
  viewBox
70739
70796
  });
70740
70797
  }
70741
70798
  if (isNumOrStr(label)) {
70742
- return /* @__PURE__ */ React__default.createElement(Label, {
70799
+ return /* @__PURE__ */ React__default.createElement(Label$1, {
70743
70800
  key: "label-implicit",
70744
70801
  viewBox,
70745
70802
  value: label
70746
70803
  });
70747
70804
  }
70748
70805
  if (/* @__PURE__ */ isValidElement(label)) {
70749
- if (label.type === Label) {
70806
+ if (label.type === Label$1) {
70750
70807
  return /* @__PURE__ */ cloneElement(label, {
70751
70808
  key: "label-implicit",
70752
70809
  viewBox
70753
70810
  });
70754
70811
  }
70755
- return /* @__PURE__ */ React__default.createElement(Label, {
70812
+ return /* @__PURE__ */ React__default.createElement(Label$1, {
70756
70813
  key: "label-implicit",
70757
70814
  content: label,
70758
70815
  viewBox
70759
70816
  });
70760
70817
  }
70761
70818
  if (isFunction(label)) {
70762
- return /* @__PURE__ */ React__default.createElement(Label, {
70819
+ return /* @__PURE__ */ React__default.createElement(Label$1, {
70763
70820
  key: "label-implicit",
70764
70821
  content: label,
70765
70822
  viewBox
70766
70823
  });
70767
70824
  }
70768
70825
  if (isObject(label)) {
70769
- return /* @__PURE__ */ React__default.createElement(Label, _extends$o({
70826
+ return /* @__PURE__ */ React__default.createElement(Label$1, _extends$o({
70770
70827
  viewBox
70771
70828
  }, label, {
70772
70829
  key: "label-implicit"
@@ -70781,7 +70838,7 @@ var renderCallByParent$1 = function renderCallByParent(parentProps, viewBox) {
70781
70838
  }
70782
70839
  var children = parentProps.children;
70783
70840
  var parentViewBox = parseViewBox(parentProps);
70784
- var explicitChildren = findAllByType(children, Label).map(function(child, index2) {
70841
+ var explicitChildren = findAllByType(children, Label$1).map(function(child, index2) {
70785
70842
  return /* @__PURE__ */ cloneElement(child, {
70786
70843
  viewBox: viewBox || parentViewBox,
70787
70844
  // eslint-disable-next-line react/no-array-index-key
@@ -70794,8 +70851,8 @@ var renderCallByParent$1 = function renderCallByParent(parentProps, viewBox) {
70794
70851
  var implicitLabel = parseLabel(parentProps.label, viewBox || parentViewBox);
70795
70852
  return [implicitLabel].concat(_toConsumableArray$8(explicitChildren));
70796
70853
  };
70797
- Label.parseViewBox = parseViewBox;
70798
- Label.renderCallByParent = renderCallByParent$1;
70854
+ Label$1.parseViewBox = parseViewBox;
70855
+ Label$1.renderCallByParent = renderCallByParent$1;
70799
70856
  var lastExports = requireLast();
70800
70857
  const last = /* @__PURE__ */ getDefaultExportFromCjs(lastExports);
70801
70858
  function _typeof$w(o2) {
@@ -70932,11 +70989,11 @@ function LabelList(_ref) {
70932
70989
  var idProps = isNil(id2) ? {} : {
70933
70990
  id: "".concat(id2, "-").concat(index2)
70934
70991
  };
70935
- return /* @__PURE__ */ React__default.createElement(Label, _extends$n({}, filterProps(entry, true), others, idProps, {
70992
+ return /* @__PURE__ */ React__default.createElement(Label$1, _extends$n({}, filterProps(entry, true), others, idProps, {
70936
70993
  parentViewBox: entry.parentViewBox,
70937
70994
  value,
70938
70995
  textBreakAll,
70939
- viewBox: Label.parseViewBox(isNil(clockWise) ? entry : _objectSpread$r(_objectSpread$r({}, entry), {}, {
70996
+ viewBox: Label$1.parseViewBox(isNil(clockWise) ? entry : _objectSpread$r(_objectSpread$r({}, entry), {}, {
70940
70997
  clockWise
70941
70998
  })),
70942
70999
  key: "label-".concat(index2),
@@ -71065,12 +71122,12 @@ var getDeltaAngle2 = function getDeltaAngle3(startAngle, endAngle) {
71065
71122
  var getTangentCircle = function getTangentCircle2(_ref) {
71066
71123
  var cx = _ref.cx, cy = _ref.cy, radius = _ref.radius, angle = _ref.angle, sign2 = _ref.sign, isExternal = _ref.isExternal, cornerRadius = _ref.cornerRadius, cornerIsExternal = _ref.cornerIsExternal;
71067
71124
  var centerRadius = cornerRadius * (isExternal ? 1 : -1) + radius;
71068
- var theta = Math.asin(cornerRadius / centerRadius) / RADIAN$1;
71125
+ var theta = Math.asin(cornerRadius / centerRadius) / RADIAN$2;
71069
71126
  var centerAngle = cornerIsExternal ? angle : angle + sign2 * theta;
71070
71127
  var center = polarToCartesian(cx, cy, centerRadius, centerAngle);
71071
71128
  var circleTangency = polarToCartesian(cx, cy, radius, centerAngle);
71072
71129
  var lineTangencyAngle = cornerIsExternal ? angle - sign2 * theta : angle;
71073
- var lineTangency = polarToCartesian(cx, cy, centerRadius * Math.cos(theta * RADIAN$1), lineTangencyAngle);
71130
+ var lineTangency = polarToCartesian(cx, cy, centerRadius * Math.cos(theta * RADIAN$2), lineTangencyAngle);
71074
71131
  return {
71075
71132
  center,
71076
71133
  circleTangency,
@@ -73650,7 +73707,7 @@ var PolarRadiusAxis = /* @__PURE__ */ function(_PureComponent) {
73650
73707
  }
73651
73708
  return /* @__PURE__ */ React__default.createElement(Layer, {
73652
73709
  className: clsx("recharts-polar-radius-axis", this.props.className)
73653
- }, axisLine && this.renderAxisLine(), tick && this.renderTicks(), Label.renderCallByParent(this.props, this.getViewBox()));
73710
+ }, axisLine && this.renderAxisLine(), tick && this.renderTicks(), Label$1.renderCallByParent(this.props, this.getViewBox()));
73654
73711
  }
73655
73712
  }], [{
73656
73713
  key: "renderTickItem",
@@ -73820,7 +73877,7 @@ function _toPrimitive$l(t3, r2) {
73820
73877
  }
73821
73878
  return String(t3);
73822
73879
  }
73823
- var RADIAN = Math.PI / 180;
73880
+ var RADIAN$1 = Math.PI / 180;
73824
73881
  var eps = 1e-5;
73825
73882
  var PolarAngleAxis = /* @__PURE__ */ function(_PureComponent) {
73826
73883
  function PolarAngleAxis2() {
@@ -73860,7 +73917,7 @@ var PolarAngleAxis = /* @__PURE__ */ function(_PureComponent) {
73860
73917
  key: "getTickTextAnchor",
73861
73918
  value: function getTickTextAnchor(data) {
73862
73919
  var orientation = this.props.orientation;
73863
- var cos2 = Math.cos(-data.coordinate * RADIAN);
73920
+ var cos2 = Math.cos(-data.coordinate * RADIAN$1);
73864
73921
  var textAnchor;
73865
73922
  if (cos2 > eps) {
73866
73923
  textAnchor = orientation === "outer" ? "start" : "end";
@@ -74779,7 +74836,7 @@ var Pie = /* @__PURE__ */ function(_PureComponent) {
74779
74836
  ref: function ref(_ref3) {
74780
74837
  _this5.pieRef = _ref3;
74781
74838
  }
74782
- }, this.renderSectors(), label && this.renderLabels(sectors), Label.renderCallByParent(this.props, null, false), (!isAnimationActive || isAnimationFinished) && LabelList.renderCallByParent(this.props, sectors, false));
74839
+ }, this.renderSectors(), label && this.renderLabels(sectors), Label$1.renderCallByParent(this.props, null, false), (!isAnimationActive || isAnimationFinished) && LabelList.renderCallByParent(this.props, sectors, false));
74783
74840
  }
74784
74841
  }], [{
74785
74842
  key: "getDerivedStateFromProps",
@@ -77231,7 +77288,7 @@ function ReferenceLineImpl(props) {
77231
77288
  });
77232
77289
  return /* @__PURE__ */ React__default.createElement(Layer, {
77233
77290
  className: clsx("recharts-reference-line", className)
77234
- }, renderLine(shape, lineProps), Label.renderCallByParent(props, rectWithCoords({
77291
+ }, renderLine(shape, lineProps), Label$1.renderCallByParent(props, rectWithCoords({
77235
77292
  x1,
77236
77293
  y1,
77237
77294
  x2: x22,
@@ -77444,7 +77501,7 @@ var ReferenceDot = /* @__PURE__ */ function(_React$Component) {
77444
77501
  });
77445
77502
  return /* @__PURE__ */ React__default.createElement(Layer, {
77446
77503
  className: clsx("recharts-reference-dot", className)
77447
- }, ReferenceDot2.renderDot(shape, dotProps), Label.renderCallByParent(this.props, {
77504
+ }, ReferenceDot2.renderDot(shape, dotProps), Label$1.renderCallByParent(this.props, {
77448
77505
  x: cx - r2,
77449
77506
  y: cy - r2,
77450
77507
  width: 2 * r2,
@@ -77669,7 +77726,7 @@ var ReferenceArea = /* @__PURE__ */ function(_React$Component) {
77669
77726
  className: clsx("recharts-reference-area", className)
77670
77727
  }, ReferenceArea2.renderRect(shape, _objectSpread$7(_objectSpread$7({
77671
77728
  clipPath
77672
- }, filterProps(this.props, true)), rect)), Label.renderCallByParent(this.props, rect));
77729
+ }, filterProps(this.props, true)), rect)), Label$1.renderCallByParent(this.props, rect));
77673
77730
  }
77674
77731
  }]);
77675
77732
  }(React__default.Component);
@@ -78352,7 +78409,7 @@ var CartesianAxis = /* @__PURE__ */ function(_Component) {
78352
78409
  ref: function ref(_ref2) {
78353
78410
  _this3.layerReference = _ref2;
78354
78411
  }
78355
- }, axisLine && this.renderAxisLine(), this.renderTicks(finalTicks, this.state.fontSize, this.state.letterSpacing), Label.renderCallByParent(this.props));
78412
+ }, axisLine && this.renderAxisLine(), this.renderTicks(finalTicks, this.state.fontSize, this.state.letterSpacing), Label$1.renderCallByParent(this.props));
78356
78413
  }
78357
78414
  }], [{
78358
78415
  key: "renderTickItem",
@@ -81885,7 +81942,7 @@ var generateCategoricalChart = function generateCategoricalChart2(_ref6) {
81885
81942
  var _this$props2 = _this.props, children = _this$props2.children, width = _this$props2.width, height = _this$props2.height;
81886
81943
  var margin = _this.props.margin || {};
81887
81944
  var legendWidth = width - (margin.left || 0) - (margin.right || 0);
81888
- var props = getLegendProps$1({
81945
+ var props = getLegendProps({
81889
81946
  children,
81890
81947
  formattedGraphicalItems,
81891
81948
  legendWidth,
@@ -82650,7 +82707,7 @@ var BarChart$1 = generateCategoricalChart({
82650
82707
  }],
82651
82708
  formatAxisMap: formatAxisMap2
82652
82709
  });
82653
- var PieChart = generateCategoricalChart({
82710
+ var PieChart$1 = generateCategoricalChart({
82654
82711
  chartName: "PieChart",
82655
82712
  GraphicalChild: Pie,
82656
82713
  validateTooltipEventTypes: ["item"],
@@ -82686,6 +82743,79 @@ var AreaChart$1 = generateCategoricalChart({
82686
82743
  }],
82687
82744
  formatAxisMap: formatAxisMap2
82688
82745
  });
82746
+ function getAxisProps(scale2, tickFormatter, dataKey) {
82747
+ return {
82748
+ axisLine: false,
82749
+ dataKey,
82750
+ fontSize: 11,
82751
+ scale: scale2,
82752
+ tickLine: false,
82753
+ tickMargin: 8,
82754
+ tickFormatter
82755
+ };
82756
+ }
82757
+ function ChartContainer(props) {
82758
+ const { onSetWidth: handleSetWidth, ...attributes } = props;
82759
+ const ref = React__default.useRef(null);
82760
+ React__default.useLayoutEffect(() => {
82761
+ if (ref.current && typeof handleSetWidth === "function") {
82762
+ const rect = ref.current.getBoundingClientRect();
82763
+ handleSetWidth(rect.width);
82764
+ }
82765
+ }, [ref]);
82766
+ const className = clsx("flex justify-center mx-auto", attributes.className);
82767
+ return /* @__PURE__ */ React__default.createElement("div", { ...attributes, className, ref }, /* @__PURE__ */ React__default.createElement(ResponsiveContainer, null, props.children));
82768
+ }
82769
+ function Tooltip(props) {
82770
+ const { active, payload = [], style, title } = props;
82771
+ if (active && payload.length) {
82772
+ return /* @__PURE__ */ React__default.createElement("div", { className: "border-grey-300 z-20 flex flex-col gap-y-1 rounded-md border bg-white px-2 py-1.5 text-xs shadow-sm" }, title ? /* @__PURE__ */ React__default.createElement("span", { className: "font-bold" }, title) : null, /* @__PURE__ */ React__default.createElement("dl", { className: "m-0 grid grid-cols-[max-content_max-content] gap-x-4 gap-y-0.5", style }, payload.map((entry, index2) => {
82773
+ const color2 = entry.color ?? entry.payload.color;
82774
+ const formatter = entry.formatter ?? entry.payload.formatter;
82775
+ const unit2 = entry.unit ?? entry.payload.unit;
82776
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, { key: `${entry.name}-${index2}` }, /* @__PURE__ */ React__default.createElement("dt", { className: "text-grey-700 mb-0 flex items-center gap-1 font-normal" }, /* @__PURE__ */ React__default.createElement("span", { className: "-mt-px h-2.5 w-2.5 rounded-sm", style: { background: color2 } }), entry.name), /* @__PURE__ */ React__default.createElement("dd", { className: "mb-0 text-right font-bold tabular-nums text-black" }, (formatter == null ? void 0 : formatter(entry.value ?? "", entry.name ?? "", entry, index2, entry.payload)) ?? entry.value, " ", unit2 ? /* @__PURE__ */ React__default.createElement("span", { className: "text-grey-700" }, unit2) : null));
82777
+ })));
82778
+ }
82779
+ return null;
82780
+ }
82781
+ function Legend$1(props) {
82782
+ const { hoverIndex, items, onHover: handleHover, onToggle: handleToggle } = props;
82783
+ const handleMouseEnter = (item, index2) => {
82784
+ if (item.isHidden) {
82785
+ return;
82786
+ }
82787
+ handleHover(index2);
82788
+ };
82789
+ const handleMouseLeave = () => handleHover(void 0);
82790
+ const handleClick = (item) => {
82791
+ if (!item.isHidden) {
82792
+ handleHover(void 0);
82793
+ }
82794
+ handleToggle(item.dataKey);
82795
+ };
82796
+ const moreButton = (moreButtonText) => /* @__PURE__ */ React__default.createElement(Button$4, { appearance: "transparent", className: "text-grey-700 !h-5 !min-h-[1.25rem] !px-1.5 text-xs" }, moreButtonText);
82797
+ return /* @__PURE__ */ React__default.createElement(OverflowGroup, { className: "w-full gap-x-1", moreButton }, items.map((item, index2) => {
82798
+ const className = clsx("mr-1 flex h-3 w-3 rounded-sm", {
82799
+ [`bg-${item.color}`]: !item.isHidden,
82800
+ border: item.isHidden
82801
+ });
82802
+ return /* @__PURE__ */ React__default.createElement(
82803
+ "button",
82804
+ {
82805
+ key: item.label,
82806
+ className: "hover:bg-grey-200 focus-visible:yt-focus flex items-center rounded px-1 !text-xs",
82807
+ onClick: (event) => {
82808
+ event == null ? void 0 : event.preventDefault();
82809
+ handleClick(item);
82810
+ },
82811
+ onMouseEnter: () => handleMouseEnter(item, index2),
82812
+ onMouseLeave: () => handleMouseLeave()
82813
+ },
82814
+ /* @__PURE__ */ React__default.createElement("span", { className }, hoverIndex === index2 ? /* @__PURE__ */ React__default.createElement(Icon$1, { name: "tick-bold", className: clsx("!h-full !w-full", { "text-white": !item.isHidden }) }) : null),
82815
+ item.label
82816
+ );
82817
+ }));
82818
+ }
82689
82819
  const THEME_COLORS = {
82690
82820
  transparent: "transparent",
82691
82821
  current: "currentColor",
@@ -82821,266 +82951,291 @@ const mapColor = (palette, prefix2 = "") => {
82821
82951
  }, {});
82822
82952
  };
82823
82953
  const colors = mapColor(THEME_COLORS);
82824
- const getThemeColor = (color2) => colors[color2];
82825
- function Legend$1(props) {
82826
- const { activeIndex, onMouseEnter, onMouseLeave, onClick, payload, layout, activeItems } = props;
82827
- const [hoverIndex, setHoverIndex] = useState(null);
82828
- const handleMouseEnter = (entry, index2) => {
82829
- setHoverIndex(index2);
82830
- if (activeItems[entry.dataKey]) onMouseEnter(entry, index2);
82831
- };
82832
- const handleMouseLeave = () => {
82833
- onMouseLeave();
82834
- setHoverIndex(null);
82835
- };
82836
- const moreButton = (moreButtonText) => /* @__PURE__ */ React__default.createElement(Button$4, { appearance: "transparent", className: "text-grey-700" }, moreButtonText);
82837
- return /* @__PURE__ */ React__default.createElement("div", { className: "mx-auto w-auto max-w-full overflow-hidden" }, /* @__PURE__ */ React__default.createElement("div", { className: clsx("mb-0 ml-0 flex justify-center", { "flex-col": layout === "vertical" }) }, /* @__PURE__ */ React__default.createElement(OverflowGroup, { className: "w-full items-center py-1", moreButton }, payload.map((entry, index2) => /* @__PURE__ */ React__default.createElement(
82838
- "span",
82839
- {
82840
- key: `${entry.dataKey}-${index2}`,
82841
- className: clsx(" hover:bg-grey-100 cursor-pointer px-[8px] py-[2px] hover:rounded-[4px]", {
82842
- "bg-grey-100 rounded": activeIndex === index2
82843
- }),
82844
- onMouseEnter: () => handleMouseEnter(entry, index2),
82845
- onMouseLeave: handleMouseLeave,
82846
- onClick: onClick ? () => onClick(entry) : void 0
82847
- },
82848
- /* @__PURE__ */ React__default.createElement("span", { className: "text-grey-700 flex items-center gap-[4px]" }, /* @__PURE__ */ React__default.createElement(
82849
- "span",
82850
- {
82851
- className: clsx("-mt-px ml-1 flex h-3 w-3 rounded-sm", {
82852
- "border-grey-300 border !bg-white": !activeItems[entry.dataKey]
82853
- }),
82854
- style: { backgroundColor: entry.color }
82855
- },
82856
- hoverIndex === index2 && activeItems[entry.dataKey] && /* @__PURE__ */ React__default.createElement(Icon$1, { name: "tick-bold", className: "!h-full !w-full text-white" })
82857
- ), entry.value)
82858
- )))));
82859
- }
82860
- const Tooltip = ({ active, formatter, payload, style, singlePieDonutChart }) => {
82861
- const getColor = (entry) => {
82862
- if (singlePieDonutChart) {
82863
- return getThemeColor(entry.payload.color);
82954
+ const getThemeColor = (color2, def = "") => colors[color2 ?? def];
82955
+ const getInverseThemeColor = (themeColor) => {
82956
+ const [color2, number2] = String(themeColor).split("-");
82957
+ const shade = Number(number2);
82958
+ if (shade) {
82959
+ if (shade > 500) {
82960
+ return getThemeColor(`${color2}-100`);
82961
+ } else {
82962
+ if (shade === 500 && (color2 === "red" || color2 === "blue" || color2 === "brown" || color2 === "purple" || color2 === "green")) {
82963
+ return "white";
82964
+ }
82965
+ return getThemeColor(`${color2}-900`);
82864
82966
  }
82865
- return entry.color ?? entry.payload.fill ?? "blue-500";
82866
- };
82867
- if (active && payload && payload.length) {
82868
- return /* @__PURE__ */ React__default.createElement(
82869
- "dl",
82870
- {
82871
- className: "z-20 grid grid-cols-[max-content_max-content] gap-x-4 rounded-md bg-white p-4 text-xs shadow-[0px_0px_1px_rgba(0,0,0,0.1),_0px_6px_18px_rgba(47,51,68,0.2)]",
82872
- style
82873
- },
82874
- payload.map((entry, index2) => /* @__PURE__ */ React__default.createElement(React__default.Fragment, { key: `${entry.name}-${index2}` }, /* @__PURE__ */ React__default.createElement(
82875
- "dt",
82876
- { className: "text-grey-700 mb-0 flex items-center gap-1 font-normal" },
82877
- /* @__PURE__ */ React__default.createElement("span", { className: "-mt-px h-2.5 w-2.5 rounded-sm", style: { background: getColor(entry) } }),
82878
- // We use entry.payload.label because the payload structure differs between a Donut chart with a single pie
82879
- // and one with multiple pies.
82880
- singlePieDonutChart ? entry.payload.label : entry.name
82881
- ), /* @__PURE__ */ React__default.createElement("dd", { className: "mb-0 text-right font-bold text-black " }, formatter ? formatter(entry.value) : entry.value)))
82882
- );
82883
82967
  }
82884
- return null;
82968
+ return color2 === "black" ? "white" : "black";
82885
82969
  };
82886
- const getCartesianGridProps = () => ({
82887
- vertical: false
82888
- });
82889
- const getXAxisProps = (props) => ({
82890
- axisLine: false,
82891
- dataKey: props.accessor,
82892
- fontSize: 12,
82893
- scale: props.xAxisScale,
82894
- tickLine: false,
82895
- tickFormatter: props.xAxisTickFormat
82896
- });
82897
- const getYAxisProps = (props) => ({
82898
- axisLine: false,
82899
- fontSize: 12,
82900
- scale: props.yAxisScale,
82901
- tickLine: false,
82902
- tickFormatter: props.yAxisTickFormat
82903
- });
82904
- const getLegendProps2 = (props) => ({
82905
- content: /* @__PURE__ */ React__default.createElement(Legend$1, { ...props })
82906
- });
82907
- const getTooltipProps = (props = void 0) => ({
82908
- content: /* @__PURE__ */ React__default.createElement(Tooltip, { ...props }),
82909
- wrapperStyle: { outline: "none" }
82910
- });
82911
- const ResponsiveContainer = (props) => /* @__PURE__ */ React__default.createElement(ResponsiveContainer$1, { className: "!h-[calc(100%-1px)] !w-[calc(100%-1px)]", ...props });
82912
- const Area = (_) => null;
82913
- const AreaChart = function AreaChart2(externalProps) {
82914
- const { children, data, formatter, ...props } = externalProps;
82915
- const [hoveredArea, setHoveredArea] = useState(null);
82916
- const [activeAreas, setActiveAreas] = useState(() => {
82917
- const areas = {};
82918
- React__default.Children.forEach(children, (child) => {
82919
- areas[child.props.accessor] = true;
82970
+ function useChart(children, options) {
82971
+ const [activeIndex, setActiveIndex] = React__default.useState();
82972
+ const [hiddenItems, toggleItem] = useChartDataHiddenState();
82973
+ const localization = useLocalization();
82974
+ const defaultFormatter2 = (value) => new Intl.NumberFormat(localization.locale).format(value);
82975
+ const { items, shapes } = React__default.useMemo(() => {
82976
+ const items2 = React__default.Children.toArray(children).filter((child) => React__default.isValidElement(child)).map((child) => {
82977
+ const dataKey = child.props.dataKey ?? child.props.label;
82978
+ return {
82979
+ ...child.props,
82980
+ dataKey,
82981
+ formatter: child.props.formatter ?? (options == null ? void 0 : options.formatter) ?? defaultFormatter2,
82982
+ isHidden: !!hiddenItems[dataKey],
82983
+ unit: child.props.unit ?? (options == null ? void 0 : options.unit)
82984
+ };
82920
82985
  });
82921
- return areas;
82922
- });
82923
- const handleLegendClick = (entry) => {
82924
- setHoveredArea(null);
82925
- setActiveAreas({ ...activeAreas, [entry.dataKey]: !activeAreas[entry.dataKey] });
82926
- };
82927
- return /* @__PURE__ */ React__default.createElement(ResponsiveContainer, null, /* @__PURE__ */ React__default.createElement(AreaChart$1, { data, margin: { top: 10, right: 0, left: -25, bottom: 0 } }, /* @__PURE__ */ React__default.createElement(CartesianGrid, { ...getCartesianGridProps() }), /* @__PURE__ */ React__default.createElement(XAxis, { ...getXAxisProps(props) }), /* @__PURE__ */ React__default.createElement(YAxis, { ...getYAxisProps(props) }), /* @__PURE__ */ React__default.createElement(
82928
- Legend$2,
82929
- {
82930
- ...getLegendProps2({
82931
- onClick: handleLegendClick,
82932
- onMouseEnter: (entry) => setHoveredArea(entry.dataKey),
82933
- onMouseLeave: () => setHoveredArea(null),
82934
- activeItems: activeAreas
82935
- })
82936
- }
82937
- ), /* @__PURE__ */ React__default.createElement(Tooltip$1, { ...getTooltipProps(), formatter }), React__default.Children.map(children, (child) => /* @__PURE__ */ React__default.createElement(
82938
- Area$1,
82939
- {
82940
- activeDot: {
82941
- fill: getThemeColor(child.props.color ?? "blue-300")
82942
- },
82943
- isAnimationActive: false,
82944
- dataKey: child.props.accessor,
82945
- dot: false,
82946
- fill: getThemeColor(child.props.color ?? "grey-100"),
82947
- name: child.props.label,
82948
- strokeWidth: 2,
82949
- stroke: getThemeColor(child.props.color ?? "grey-300"),
82950
- stackId: child.props.stackId,
82951
- hide: !activeAreas[child.props.accessor],
82952
- opacity: hoveredArea && child.props.accessor !== hoveredArea ? 0.3 : 1
82953
- }
82954
- ))));
82955
- };
82956
- AreaChart.Area = Area;
82957
- const Bar = (_) => null;
82958
- const getXAxisVerticalProps = (props) => ({
82959
- ...getXAxisProps(props),
82960
- ...{ type: "number", dataKey: void 0 }
82961
- });
82962
- const getYAxisVerticalProps = (props) => ({
82963
- ...getYAxisProps(props),
82964
- ...{ dataKey: props.accessor, type: "category" }
82965
- });
82966
- const BarChart = function BarChart2(externalProps) {
82967
- const { children, data, formatter, layout = "horizontal", ...props } = externalProps;
82968
- const [activeIndex, setActiveIndex] = React__default.useState(void 0);
82969
- const [hoveredBar, setHoveredBar] = useState(null);
82970
- const [activeBars, setActiveBars] = useState(() => {
82971
- const keys2 = {};
82972
- React__default.Children.forEach(children, (child) => {
82973
- keys2[child.props.accessor] = true;
82986
+ const shapes2 = items2.filter((item) => !hiddenItems[item.dataKey]).map((item) => {
82987
+ const color2 = getThemeColor(item.color, "blue-500");
82988
+ return {
82989
+ activeDot: {
82990
+ strokeWidth: 1
82991
+ },
82992
+ color: color2,
82993
+ dataKey: item.dataKey,
82994
+ dot: {
82995
+ fillOpacity: 0.6
82996
+ },
82997
+ isAnimationActive: false,
82998
+ fill: color2,
82999
+ fillOpacity: 0.65,
83000
+ formatter: item.formatter,
83001
+ name: item.label,
83002
+ stroke: color2,
83003
+ strokeWidth: 1.5,
83004
+ unit: item.unit
83005
+ };
82974
83006
  });
82975
- return keys2;
82976
- });
82977
- const stacks = {};
82978
- React__default.Children.forEach(children, (child) => {
82979
- if (child.props.stackId) {
82980
- if (!stacks[child.props.stackId]) {
82981
- stacks[child.props.stackId] = [child.props.accessor];
83007
+ return { items: items2, shapes: shapes2 };
83008
+ }, [children, hiddenItems]);
83009
+ return { items, shapes, activeIndex, setActiveIndex, toggleItem };
83010
+ }
83011
+ function useChartDataHiddenState() {
83012
+ const [state, setState] = React__default.useState({});
83013
+ function toggle(name) {
83014
+ setState((currentState) => {
83015
+ const nextState = { ...currentState };
83016
+ if (currentState[name]) {
83017
+ delete nextState[name];
82982
83018
  } else {
82983
- stacks[child.props.stackId].push(child.props.accessor);
83019
+ nextState[name] = true;
82984
83020
  }
82985
- }
82986
- });
82987
- const handleLegendClick = (entry) => {
82988
- setHoveredBar(null);
82989
- setActiveBars({ ...activeBars, [entry.dataKey]: !activeBars[entry.dataKey] });
82990
- };
82991
- const handleLegendHover = (entry, index2) => {
82992
- setHoveredBar(entry.dataKey);
82993
- setActiveIndex(index2);
82994
- };
82995
- return /* @__PURE__ */ React__default.createElement(ResponsiveContainer, null, /* @__PURE__ */ React__default.createElement(
82996
- BarChart$1,
83021
+ return nextState;
83022
+ });
83023
+ }
83024
+ return [state, toggle];
83025
+ }
83026
+ function AreaChart(props) {
83027
+ const {
83028
+ children,
83029
+ data,
83030
+ dataKey,
83031
+ showDots = false,
83032
+ showLegend = false,
83033
+ showXAxis = true,
83034
+ showYAxis = false,
83035
+ stacked = false,
83036
+ tooltipTitle,
83037
+ type = "natural",
83038
+ xAxisScale,
83039
+ xAxisTickFormatter,
83040
+ yAxisScale,
83041
+ yAxisTickFormatter,
83042
+ ...attributes
83043
+ } = props;
83044
+ const className = clsx("aspect-video", attributes.className);
83045
+ const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83046
+ return /* @__PURE__ */ React__default.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React__default.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-area" }, /* @__PURE__ */ React__default.createElement(
83047
+ AreaChart$1,
82997
83048
  {
82998
- layout,
82999
83049
  data,
83000
- margin: { top: 10, right: 0, left: layout === "vertical" ? 0 : -25, bottom: 0 },
83001
- onMouseMove: (chartState) => setActiveIndex(chartState.activeTooltipIndex),
83002
- onMouseLeave: () => setActiveIndex(void 0)
83050
+ margin: { bottom: 10, left: 10, right: 10, top: 10 },
83051
+ stackOffset: stacked === "expand" ? "expand" : void 0
83003
83052
  },
83004
- /* @__PURE__ */ React__default.createElement(CartesianGrid, { ...getCartesianGridProps() }),
83053
+ /* @__PURE__ */ React__default.createElement(CartesianGrid, { vertical: false }),
83054
+ /* @__PURE__ */ React__default.createElement(Tooltip$1, { content: /* @__PURE__ */ React__default.createElement(Tooltip, { title: tooltipTitle }) }),
83005
83055
  /* @__PURE__ */ React__default.createElement(
83006
83056
  XAxis,
83007
83057
  {
83008
- ...layout === "vertical" ? getXAxisVerticalProps(props) : getXAxisProps(props)
83058
+ ...getAxisProps(xAxisScale, xAxisTickFormatter, dataKey),
83059
+ hide: !showXAxis
83009
83060
  }
83010
83061
  ),
83062
+ /* @__PURE__ */ React__default.createElement(YAxis, { ...getAxisProps(yAxisScale, yAxisTickFormatter), hide: !showYAxis }),
83063
+ shapes.map((shape) => /* @__PURE__ */ React__default.createElement(
83064
+ Area$1,
83065
+ {
83066
+ key: shape.dataKey,
83067
+ ...shape,
83068
+ dot: showDots ? shape.dot : false,
83069
+ stackId: stacked ? "stack" : void 0,
83070
+ type
83071
+ }
83072
+ ))
83073
+ )), showLegend ? /* @__PURE__ */ React__default.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83074
+ }
83075
+ function Area(_) {
83076
+ return null;
83077
+ }
83078
+ AreaChart.Area = Area;
83079
+ const BAR_WIDTH = 20;
83080
+ function BarChart(props) {
83081
+ const isHorizontal = props.layout === "horizontal";
83082
+ const {
83083
+ children,
83084
+ data,
83085
+ dataKey,
83086
+ showLabels = false,
83087
+ showLegend = false,
83088
+ showXAxis = !isHorizontal,
83089
+ showYAxis = isHorizontal,
83090
+ stacked = false,
83091
+ xAxisScale,
83092
+ xAxisTickFormatter,
83093
+ yAxisScale,
83094
+ yAxisTickFormatter,
83095
+ ...attributes
83096
+ } = props;
83097
+ const className = clsx("aspect-video", attributes.className);
83098
+ const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83099
+ return /* @__PURE__ */ React__default.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React__default.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-bar" }, /* @__PURE__ */ React__default.createElement(
83100
+ BarChart$1,
83101
+ {
83102
+ data,
83103
+ barCategoryGap: "15%",
83104
+ barGap: "7.5%",
83105
+ margin: { bottom: 10, left: isHorizontal ? -15 : 10, right: 10, top: 10 },
83106
+ layout: isHorizontal ? "vertical" : void 0,
83107
+ stackOffset: stacked === "expand" ? "expand" : void 0
83108
+ },
83109
+ /* @__PURE__ */ React__default.createElement(CartesianGrid, { horizontal: !isHorizontal, vertical: false }),
83110
+ /* @__PURE__ */ React__default.createElement(Tooltip$1, { content: /* @__PURE__ */ React__default.createElement(Tooltip, null) }),
83011
83111
  /* @__PURE__ */ React__default.createElement(
83012
- YAxis,
83112
+ XAxis,
83013
83113
  {
83014
- ...layout === "vertical" ? getYAxisVerticalProps(props) : getYAxisProps(props)
83114
+ ...getAxisProps(xAxisScale, xAxisTickFormatter, isHorizontal ? void 0 : dataKey),
83115
+ hide: !showXAxis,
83116
+ type: isHorizontal ? "number" : void 0
83015
83117
  }
83016
83118
  ),
83017
83119
  /* @__PURE__ */ React__default.createElement(
83018
- Legend$2,
83120
+ YAxis,
83019
83121
  {
83020
- ...getLegendProps2({
83021
- onClick: handleLegendClick,
83022
- onMouseEnter: handleLegendHover,
83023
- onMouseLeave: () => setHoveredBar(null),
83024
- activeItems: activeBars
83025
- })
83122
+ ...getAxisProps(yAxisScale, yAxisTickFormatter, isHorizontal ? dataKey : void 0),
83123
+ hide: !showYAxis,
83124
+ type: isHorizontal ? "category" : void 0
83026
83125
  }
83027
83126
  ),
83028
- /* @__PURE__ */ React__default.createElement(Tooltip$1, { ...getTooltipProps(), formatter }),
83029
- React__default.Children.map(children, (child) => /* @__PURE__ */ React__default.createElement(
83127
+ shapes.map((shape, index2) => /* @__PURE__ */ React__default.createElement(
83030
83128
  Bar$1,
83031
83129
  {
83032
- isAnimationActive: false,
83033
- barSize: 16,
83034
- dataKey: child.props.accessor,
83035
- name: child.props.label,
83036
- onMouseEnter: (_, index2) => setActiveIndex(index2),
83037
- onMouseLeave: () => setActiveIndex(void 0),
83038
- fill: getThemeColor(child.props.color ? `${child.props.color}` : `blue-300`),
83039
- radius: getBarRadius(stacks, child.props.accessor, child.props.stackId, activeBars),
83040
- stackId: child.props.stackId,
83041
- style: child.props.stackId ? { stroke: "#fff", strokeWidth: "2px" } : void 0,
83042
- hide: !activeBars[child.props.accessor]
83130
+ key: shape.dataKey,
83131
+ ...shape,
83132
+ activeBar: { fillOpacity: 1, strokeWidth: 0 },
83133
+ strokeWidth: 0,
83134
+ maxBarSize: BAR_WIDTH,
83135
+ radius: getRadius(index2, shapes.length, !!stacked, isHorizontal),
83136
+ stackId: stacked ? "stack" : void 0
83043
83137
  },
83044
- data.map((_, index2) => /* @__PURE__ */ React__default.createElement(
83045
- Cell,
83138
+ showLabels ? /* @__PURE__ */ React__default.createElement(
83139
+ LabelList,
83046
83140
  {
83047
- key: `cell-${index2}`,
83048
- opacity: hoveredBar && child.props.accessor !== hoveredBar || activeIndex !== void 0 && activeIndex !== index2 ? 0.3 : 1
83141
+ position: isHorizontal ? "insideRight" : "top",
83142
+ formatter: shape.formatter,
83143
+ offset: isHorizontal ? 6 : 8,
83144
+ fill: isHorizontal ? getInverseThemeColor(shape.color ?? "") : "black",
83145
+ fontSize: 11
83049
83146
  }
83050
- ))
83147
+ ) : null
83051
83148
  ))
83052
- ));
83053
- };
83054
- BarChart.Bar = Bar;
83055
- const getBarRadius = (stacks, accessor, stackId, activeBars) => {
83056
- if (stackId && Array.isArray(stacks[stackId])) {
83057
- const length = stacks[stackId].length - 1;
83058
- const index2 = stacks[stackId].indexOf(accessor);
83059
- if (Object.entries(activeBars).filter((item) => item[0] !== accessor).every((item) => !item[1])) {
83060
- return [3, 3, 0, 0];
83149
+ )), showLegend ? /* @__PURE__ */ React__default.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83150
+ }
83151
+ function getRadius(index2, length, stacked, isHorizontal) {
83152
+ if (stacked) {
83153
+ if (index2 === 0) {
83154
+ return isHorizontal ? [3, 0, 0, 3] : [0, 0, 3, 3];
83061
83155
  }
83062
- if (activeBars[stacks[stackId][index2 + 1]] === false) {
83063
- return [index2 === 0 ? 0 : 3, index2 === 0 ? 0 : 3, index2 === length - 1 ? 0 : 3, index2 === length - 1 ? 0 : 3];
83156
+ if (index2 === length - 1) {
83157
+ return isHorizontal ? [0, 3, 3, 0] : [3, 3, 0, 0];
83064
83158
  }
83065
- if (index2 !== 0 && index2 !== length) {
83066
- return 0;
83067
- }
83068
- return [index2 === 0 ? 0 : 3, index2 === 0 ? 0 : 3, index2 === length ? 0 : 3, index2 === length ? 0 : 3];
83159
+ return 0;
83069
83160
  }
83070
83161
  return 3;
83071
- };
83072
- const Legend = ({
83073
- legendPosition,
83074
- hoveredItem,
83075
- selectedItem,
83076
- data,
83077
- onClick,
83078
- setHoveredItem,
83079
- formatter,
83080
- total,
83081
- visibleItems,
83082
- label
83083
- }) => {
83162
+ }
83163
+ function Bar(_) {
83164
+ return null;
83165
+ }
83166
+ BarChart.Bar = Bar;
83167
+ const PIE_ACTIVE_WIDTH = 10;
83168
+ const PIE_ACTIVE_WIDTH_OFFSET = 2;
83169
+ function usePieChart(children, options) {
83170
+ const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children, options);
83171
+ const [radius, _setRadius] = React__default.useState(0);
83172
+ function setRadius(width) {
83173
+ _setRadius((width - 2 * (PIE_ACTIVE_WIDTH + PIE_ACTIVE_WIDTH_OFFSET)) / 2);
83174
+ }
83175
+ const pieProps = {
83176
+ activeIndex,
83177
+ activeShape: (props) => /* @__PURE__ */ React__default.createElement(ActiveShape$1, { ...props }),
83178
+ children: shapes.map((shape) => /* @__PURE__ */ React__default.createElement(Cell, { key: shape.dataKey, color: shape.color, fill: shape.fill })),
83179
+ // data props
83180
+ data: items.filter((item) => !item.isHidden),
83181
+ dataKey: "value",
83182
+ nameKey: "label",
83183
+ // style props
83184
+ isAnimationActive: false,
83185
+ startAngle: 90,
83186
+ endAngle: -270,
83187
+ stroke: "0",
83188
+ labelLine: false,
83189
+ outerRadius: radius
83190
+ };
83191
+ return { pieProps, radius, setRadius, items, activeIndex, setActiveIndex, toggleItem, shapes };
83192
+ }
83193
+ const PIE_CHART_HOVER = 10;
83194
+ const PIE_CHART_HOVER_OFFSET = 2;
83195
+ function ActiveShape$1(props) {
83196
+ const { outerRadius = 0, ...attributes } = props;
83197
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Sector, { ...attributes, outerRadius }), /* @__PURE__ */ React__default.createElement(
83198
+ Sector,
83199
+ {
83200
+ ...attributes,
83201
+ innerRadius: outerRadius + PIE_CHART_HOVER_OFFSET,
83202
+ outerRadius: outerRadius + PIE_CHART_HOVER,
83203
+ opacity: 0.4
83204
+ }
83205
+ ));
83206
+ }
83207
+ const DONUT_WIDTH$1 = 20;
83208
+ function DonutChart(props) {
83209
+ const { children, formatter, showLegend = false, showTotal = false, tooltipTitle, unit: unit2, ...attributes } = props;
83210
+ const { pieProps, radius, setRadius, items, activeIndex, setActiveIndex, toggleItem } = usePieChart(children, {
83211
+ formatter,
83212
+ unit: unit2
83213
+ });
83214
+ const className = clsx("aspect-square", attributes.className);
83215
+ return /* @__PURE__ */ React__default.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, showTotal ? /* @__PURE__ */ React__default.createElement(
83216
+ Total,
83217
+ {
83218
+ formatter,
83219
+ items,
83220
+ unit: unit2,
83221
+ style: { top: radius / 2 - 2, width: radius + DONUT_WIDTH$1 }
83222
+ }
83223
+ ) : null, /* @__PURE__ */ React__default.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-donut", onSetWidth: setRadius }, /* @__PURE__ */ React__default.createElement(PieChart$1, null, /* @__PURE__ */ React__default.createElement(Tooltip$1, { content: /* @__PURE__ */ React__default.createElement(Tooltip, { title: tooltipTitle }) }), /* @__PURE__ */ React__default.createElement(Pie, { ...pieProps, innerRadius: radius - DONUT_WIDTH$1 }))), showLegend ? /* @__PURE__ */ React__default.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83224
+ }
83225
+ function Segment$2(_) {
83226
+ return null;
83227
+ }
83228
+ DonutChart.Segment = Segment$2;
83229
+ function Total(props) {
83230
+ const { formatter, items, unit: unit2, ...attributes } = props;
83231
+ const localization = useLocalization();
83232
+ const total = React__default.useMemo(() => {
83233
+ const total2 = items.filter((item) => !item.isHidden).reduce((acc, curr) => acc + curr.value, 0);
83234
+ return (formatter == null ? void 0 : formatter(total2)) ?? new Intl.NumberFormat(localization.locale).format(total2);
83235
+ }, [items]);
83236
+ return /* @__PURE__ */ React__default.createElement("div", { ...attributes, className: "absolute-center-x flex aspect-square flex-col items-center justify-center rounded-full" }, /* @__PURE__ */ React__default.createElement("span", { className: "truncate text-2xl font-bold tabular-nums" }, total), unit2 ? /* @__PURE__ */ React__default.createElement("span", { className: "text-grey-700 -mb-1 -mt-0.5 truncate text-xs" }, unit2) : null);
83237
+ }
83238
+ const Legend = ({ hoveredItem, selectedItem, data, onClick, setHoveredItem, formatter, total, label }) => {
83084
83239
  const isTotalLegendSelected = selectedItem.length === data.length;
83085
83240
  const isTotalLegendHovered = hoveredItem.length === data.length;
83086
83241
  const handleMouseLeave = () => setHoveredItem([]);
@@ -83094,49 +83249,22 @@ const Legend = ({
83094
83249
  {
83095
83250
  key: isTotal ? "total" : `${itemData.label}-${index2}`,
83096
83251
  className: clsx("mr-2 flex cursor-pointer gap-2 rounded pl-0 pr-1", {
83097
- "bg-grey-100": isHovered && (!isTotal || legendPosition === "right"),
83098
- "bg-grey-200": isSelected && (!isTotal || legendPosition === "right")
83252
+ "bg-grey-100": isHovered,
83253
+ "bg-grey-200": isSelected
83099
83254
  }),
83100
83255
  onClick: () => onClick(isTotal ? data : itemData),
83101
83256
  onMouseEnter: () => setHoveredItem(isTotal ? data.map((item) => item.id) : [itemData.id]),
83102
83257
  onMouseLeave: handleMouseLeave
83103
83258
  },
83104
- legendPosition === "bottom" ? /* @__PURE__ */ React__default.createElement("div", { className: "flex items-center gap-1" }, /* @__PURE__ */ React__default.createElement(
83105
- "span",
83106
- {
83107
- className: clsx("ml-1 h-3 w-3 rounded-sm", {
83108
- "border-grey-300 border !bg-white": !visibleItems[itemData.id]
83109
- }),
83110
- style: { backgroundColor: getThemeColor(itemData.color) }
83111
- },
83112
- visibleItems[itemData.id] && isHovered && /* @__PURE__ */ React__default.createElement(Icon$1, { name: "tick-bold", className: "mb-2.5 !h-full !w-full text-white" })
83113
- ), /* @__PURE__ */ React__default.createElement("div", null, itemData.label)) : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
83114
- "span",
83115
- {
83116
- className: "ml-1 mt-1 h-9 w-2 rounded-[1px]",
83117
- style: { backgroundColor: getThemeColor(itemData.color) }
83118
- }
83119
- ), /* @__PURE__ */ React__default.createElement("div", null, itemData.label, /* @__PURE__ */ React__default.createElement("span", { className: "-mt-1 flex w-full text-lg font-bold" }, formatter ? formatter(itemData.value) : itemData.value)))
83259
+ /* @__PURE__ */ React__default.createElement("span", { className: "ml-1 mt-1 h-9 w-2 rounded-[1px]", style: { backgroundColor: getThemeColor(itemData.color) } }),
83260
+ /* @__PURE__ */ React__default.createElement("div", null, itemData.label, /* @__PURE__ */ React__default.createElement("span", { className: "-mt-1 flex w-full text-lg font-bold" }, formatter ? formatter(itemData.value) : itemData.value))
83120
83261
  );
83121
83262
  };
83122
- const moreButton = (moreButtonText) => /* @__PURE__ */ React__default.createElement(Button$4, { appearance: "transparent", className: "text-grey-700" }, moreButtonText);
83123
- const className = clsx("flex-grow pl-4", {
83124
- "w-full": legendPosition === "bottom"
83125
- });
83126
- return /* @__PURE__ */ React__default.createElement("div", { className }, /* @__PURE__ */ React__default.createElement(
83127
- "ul",
83128
- {
83129
- className: clsx(
83130
- "mb-0 ml-0 mt-4 flex justify-center space-y-1",
83131
- legendPosition === "right" ? "flex-col gap-1" : "flex-row"
83132
- )
83133
- },
83134
- legendPosition === "right" ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, renderLegendItem(null), data.map(renderLegendItem)) : /* @__PURE__ */ React__default.createElement(OverflowGroup, { className: "w-full items-center py-1", moreButton }, data.map(renderLegendItem))
83135
- ));
83263
+ return /* @__PURE__ */ React__default.createElement("div", { className: "flex-grow pl-4" }, /* @__PURE__ */ React__default.createElement("ul", { className: "mb-0 ml-0 mt-4 flex flex-col justify-center gap-1 space-y-1" }, renderLegendItem(null), data.map(renderLegendItem)));
83136
83264
  };
83137
- const DONUT_WIDTH = 16;
83265
+ const DONUT_WIDTH = 24;
83138
83266
  const HOVER_DONUT_WIDTH = 10;
83139
- const CenteredLabel = ({ radius, legendPosition, label, total, formatter, showLegend }) => {
83267
+ const CenteredLabel = ({ radius, label, total, formatter }) => {
83140
83268
  const totalInset = HOVER_DONUT_WIDTH + DONUT_WIDTH + DONUT_WIDTH;
83141
83269
  const diameter = radius * 2;
83142
83270
  return /* @__PURE__ */ React__default.createElement(
@@ -83146,8 +83274,8 @@ const CenteredLabel = ({ radius, legendPosition, label, total, formatter, showLe
83146
83274
  style: {
83147
83275
  top: `calc(${radius}px - (3rem / 2))`,
83148
83276
  // h-12 is 3rem
83149
- left: legendPosition === "right" ? `${totalInset}px` : `calc(50%-${diameter - 2 * totalInset})`,
83150
- width: showLegend ? `${diameter - 2 * totalInset}px` : `${diameter}px`
83277
+ left: `${totalInset}px`,
83278
+ width: `${diameter - 2 * totalInset}px`
83151
83279
  }
83152
83280
  },
83153
83281
  /* @__PURE__ */ React__default.createElement("span", { className: "w-full truncate text-lg font-bold" }, formatter ? formatter(total) : total),
@@ -83176,42 +83304,28 @@ const ActiveShape = (props) => {
83176
83304
  endAngle,
83177
83305
  innerRadius: outerRadius + 2,
83178
83306
  outerRadius: outerRadius + HOVER_DONUT_WIDTH,
83179
- fill: id2 !== void 0 ? getThemeColor(pieColors[id2]) ?? getThemeColor("blue-500") : getThemeColor("blue-500"),
83180
- opacity: 0.3
83307
+ fill: id2 !== void 0 ? getThemeColor(pieColors[id2], "blue-500") : getThemeColor("blue-500"),
83308
+ opacity: 0.4
83181
83309
  }
83182
83310
  ));
83183
83311
  };
83184
- const Segment = (_) => null;
83185
- const DonutChart = function DonutChart2({
83186
- children,
83187
- formatter,
83188
- onClick,
83189
- showLegend = false,
83190
- legendPosition = "bottom",
83191
- label
83192
- }) {
83312
+ const Segment$1 = (_) => null;
83313
+ const LegacyDonutChart = function LegacyDonutChart2({ children, formatter, onClick, label }) {
83193
83314
  const ref = React__default.useRef(null);
83194
83315
  const [radius, setRadius] = React__default.useState(0);
83195
83316
  const [hoveredItem, setHoveredItem] = React__default.useState([]);
83196
83317
  const [selectedItem, setSelectedItem] = React__default.useState([]);
83197
- const [visibleItems, setVisibleItems] = React__default.useState(() => {
83198
- const keys2 = {};
83199
- React__default.Children.forEach(children, (child) => {
83200
- keys2[child.props.id] = true;
83201
- });
83202
- return keys2;
83203
- });
83204
83318
  React__default.useEffect(() => {
83205
83319
  var _a;
83206
83320
  if (ref.current) {
83207
83321
  const rect = (_a = ref.current.parentElement) == null ? void 0 : _a.getBoundingClientRect();
83208
83322
  if (rect) {
83209
- const width = showLegend ? rect.width / 2 : rect.width;
83323
+ const width = rect.width / 2;
83210
83324
  const max2 = rect.height < width ? rect.height : width;
83211
83325
  setRadius(max2 / 2);
83212
83326
  }
83213
83327
  }
83214
- }, [showLegend]);
83328
+ }, [ref.current]);
83215
83329
  const diameter = radius * 2;
83216
83330
  const data = React__default.Children.map(children, (child) => ({
83217
83331
  id: child.props.id,
@@ -83219,34 +83333,27 @@ const DonutChart = function DonutChart2({
83219
83333
  label: child.props.label,
83220
83334
  value: child.props.value
83221
83335
  }));
83222
- const displayedData = data.filter((child) => visibleItems[child.id]);
83223
- const total = displayedData.reduce((accum, entry) => accum + entry.value, 0);
83224
- const showTooltip = (!showLegend || legendPosition === "bottom") && displayedData.length > 0;
83336
+ const total = data.reduce((accum, entry) => accum + entry.value, 0);
83225
83337
  const handleLegendClick = (entry) => {
83226
- if (legendPosition === "bottom" && !Array.isArray(entry)) {
83227
- setVisibleItems({ ...visibleItems, [entry.id]: !visibleItems[entry.id] });
83228
- } else {
83229
- const nextSelectedItem = Array.isArray(entry) ? entry.map((entryItem) => entryItem.id) : [entry.id];
83230
- const isCurrentSegmentActive = selectedItem.slice().sort().join(",") === nextSelectedItem.sort().join(",");
83231
- if (onClick && !isCurrentSegmentActive) {
83232
- onClick(entry);
83233
- }
83234
- setSelectedItem(isCurrentSegmentActive ? [] : nextSelectedItem);
83338
+ const nextSelectedItem = Array.isArray(entry) ? entry.map((entryItem) => entryItem.id) : [entry.id];
83339
+ const isCurrentSegmentActive = selectedItem.slice().sort().join(",") === nextSelectedItem.sort().join(",");
83340
+ if (onClick && !isCurrentSegmentActive) {
83341
+ onClick(entry);
83235
83342
  }
83343
+ setSelectedItem(isCurrentSegmentActive ? [] : nextSelectedItem);
83236
83344
  };
83237
83345
  const handlePieClick = React__default.useCallback(
83238
83346
  (pieId) => {
83239
83347
  if (onClick && pieId !== void 0) {
83240
- const pieProps = displayedData.find((item) => item.id === pieId);
83348
+ const pieProps = data.find((item) => item.id === pieId);
83241
83349
  onClick(pieProps);
83242
83350
  }
83243
83351
  },
83244
- [onClick, displayedData]
83352
+ [onClick, data]
83245
83353
  );
83246
- const singlePieDonutChart = displayedData.length === 1;
83247
83354
  const activeShapeColor = React__default.useMemo(() => {
83248
83355
  const getSegmentColor = (item) => item.reduce((colors2, itemId) => {
83249
- const visibleHoveredItem = displayedData.find((dataItem) => dataItem.id === itemId);
83356
+ const visibleHoveredItem = data.find((dataItem) => dataItem.id === itemId);
83250
83357
  if (visibleHoveredItem) {
83251
83358
  colors2[visibleHoveredItem.id] = visibleHoveredItem.color;
83252
83359
  }
@@ -83254,20 +83361,20 @@ const DonutChart = function DonutChart2({
83254
83361
  }, {});
83255
83362
  const hoveredSegmentColor = getSegmentColor(hoveredItem);
83256
83363
  const selectedSegmentColor = getSegmentColor(selectedItem);
83257
- return legendPosition === "bottom" || hoveredItem.length !== 0 ? hoveredSegmentColor : selectedSegmentColor;
83258
- }, [hoveredItem, selectedItem, legendPosition]);
83364
+ return hoveredItem.length !== 0 ? hoveredSegmentColor : selectedSegmentColor;
83365
+ }, [hoveredItem, selectedItem]);
83259
83366
  if (ref.current && !radius) {
83260
83367
  return null;
83261
83368
  }
83262
83369
  const getActiveIndex = () => {
83263
83370
  if (hoveredItem.length > 0) {
83264
- return hoveredItem.map((itemId) => displayedData.findIndex((element) => element.id === itemId));
83371
+ return hoveredItem.map((itemId) => data.findIndex((element) => element.id === itemId));
83265
83372
  }
83266
- return selectedItem.map((selectedItemId) => displayedData.findIndex((element) => element.id === selectedItemId));
83373
+ return selectedItem.map((selectedItemId) => data.findIndex((element) => element.id === selectedItemId));
83267
83374
  };
83268
83375
  const content = () => {
83269
83376
  const elements = React__default.Children.toArray(children).filter(
83270
- (child) => React__default.isValidElement(child) && visibleItems[child.props.id]
83377
+ (child) => React__default.isValidElement(child)
83271
83378
  );
83272
83379
  return elements.length > 0 ? elements.map((child, index2) => {
83273
83380
  return /* @__PURE__ */ React__default.createElement(
@@ -83280,112 +83387,112 @@ const DonutChart = function DonutChart2({
83280
83387
  );
83281
83388
  }) : /* @__PURE__ */ React__default.createElement(Cell, { key: "empty-chart", name: "", fill: getThemeColor("grey-200") });
83282
83389
  };
83283
- return /* @__PURE__ */ React__default.createElement(
83284
- "div",
83390
+ return /* @__PURE__ */ React__default.createElement("div", { className: "relative flex h-full w-full", ref }, /* @__PURE__ */ React__default.createElement(CenteredLabel, { radius, label, total, formatter }), /* @__PURE__ */ React__default.createElement(PieChart$1, { data, height: diameter, width: diameter, style: { transform: "rotate(90deg) scale(-1,1)" } }, /* @__PURE__ */ React__default.createElement(
83391
+ Pie,
83285
83392
  {
83286
- className: clsx("relative h-full w-full", {
83287
- [`flex `]: showLegend,
83288
- "flex-col items-center": legendPosition === "bottom"
83289
- }),
83290
- ref
83393
+ isAnimationActive: false,
83394
+ activeIndex: getActiveIndex(),
83395
+ activeShape: /* @__PURE__ */ React__default.createElement(ActiveShape, { pieColors: activeShapeColor, onClick: handlePieClick }),
83396
+ data: data.length > 0 ? data : [],
83397
+ dataKey: "value",
83398
+ innerRadius: radius - HOVER_DONUT_WIDTH - DONUT_WIDTH,
83399
+ onMouseEnter: (segment) => data.length > 0 && setHoveredItem([segment.id]),
83400
+ onMouseLeave: () => setHoveredItem([]),
83401
+ outerRadius: radius - HOVER_DONUT_WIDTH,
83402
+ stroke: "0",
83403
+ rootTabIndex: -1
83404
+ },
83405
+ content()
83406
+ )), /* @__PURE__ */ React__default.createElement(
83407
+ Legend,
83408
+ {
83409
+ data,
83410
+ onClick: handleLegendClick,
83411
+ total,
83412
+ setHoveredItem,
83413
+ label,
83414
+ hoveredItem,
83415
+ selectedItem,
83416
+ formatter
83417
+ }
83418
+ ));
83419
+ };
83420
+ LegacyDonutChart.Segment = Segment$1;
83421
+ function LineChart(props) {
83422
+ const {
83423
+ children,
83424
+ data,
83425
+ dataKey,
83426
+ showDots = false,
83427
+ showLegend = false,
83428
+ showXAxis = true,
83429
+ showYAxis = false,
83430
+ tooltipTitle,
83431
+ type = "natural",
83432
+ xAxisScale,
83433
+ xAxisTickFormatter,
83434
+ yAxisScale,
83435
+ yAxisTickFormatter,
83436
+ ...attributes
83437
+ } = props;
83438
+ const className = clsx("aspect-video", attributes.className);
83439
+ const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83440
+ return /* @__PURE__ */ React__default.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React__default.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-area" }, /* @__PURE__ */ React__default.createElement(
83441
+ LineChart$1,
83442
+ {
83443
+ data,
83444
+ margin: { bottom: 10, left: 10, right: 10, top: 10 }
83291
83445
  },
83446
+ /* @__PURE__ */ React__default.createElement(CartesianGrid, { vertical: false }),
83447
+ /* @__PURE__ */ React__default.createElement(Tooltip$1, { content: /* @__PURE__ */ React__default.createElement(Tooltip, { title: tooltipTitle }) }),
83292
83448
  /* @__PURE__ */ React__default.createElement(
83293
- CenteredLabel,
83449
+ XAxis,
83294
83450
  {
83295
- radius,
83296
- legendPosition,
83297
- label,
83298
- total,
83299
- formatter,
83300
- showLegend
83451
+ ...getAxisProps(xAxisScale, xAxisTickFormatter, dataKey),
83452
+ hide: !showXAxis
83301
83453
  }
83302
83454
  ),
83303
- /* @__PURE__ */ React__default.createElement(PieChart, { data, height: diameter, width: diameter, style: { transform: "rotate(90deg) scale(-1,1)" } }, showTooltip ? /* @__PURE__ */ React__default.createElement(
83304
- Tooltip$1,
83305
- {
83306
- ...getTooltipProps({
83307
- style: { transform: "rotate(90deg) scale(-1,1)" },
83308
- singlePieDonutChart
83309
- })
83310
- }
83311
- ) : null, /* @__PURE__ */ React__default.createElement(
83312
- Pie,
83313
- {
83314
- isAnimationActive: false,
83315
- activeIndex: getActiveIndex(),
83316
- activeShape: /* @__PURE__ */ React__default.createElement(ActiveShape, { pieColors: activeShapeColor, onClick: handlePieClick }),
83317
- data: displayedData.length > 0 ? displayedData : [],
83318
- dataKey: "value",
83319
- innerRadius: radius - HOVER_DONUT_WIDTH - DONUT_WIDTH,
83320
- onMouseEnter: (segment) => displayedData.length > 0 && setHoveredItem([segment.id]),
83321
- onMouseLeave: () => setHoveredItem([]),
83322
- outerRadius: radius - HOVER_DONUT_WIDTH,
83323
- paddingAngle: 2,
83324
- rootTabIndex: -1
83325
- },
83326
- content()
83327
- )),
83328
- showLegend && /* @__PURE__ */ React__default.createElement(
83329
- Legend,
83330
- {
83331
- data,
83332
- visibleItems,
83333
- onClick: handleLegendClick,
83334
- total,
83335
- setHoveredItem,
83336
- label,
83337
- legendPosition,
83338
- hoveredItem,
83339
- selectedItem,
83340
- formatter
83341
- }
83342
- )
83343
- );
83344
- };
83345
- DonutChart.Segment = Segment;
83346
- const Line = (_) => null;
83347
- const LineChart = function LineChart2(externalProps) {
83348
- const { children, data, formatter, ...props } = externalProps;
83349
- const [hoveredLine, setHoveredLine] = useState(null);
83350
- const [activeLines, setActiveLines] = useState(() => {
83351
- const keys2 = {};
83352
- React__default.Children.forEach(children, (child) => {
83353
- keys2[child.props.accessor] = true;
83354
- });
83355
- return keys2;
83455
+ /* @__PURE__ */ React__default.createElement(YAxis, { ...getAxisProps(yAxisScale, yAxisTickFormatter), hide: !showYAxis }),
83456
+ shapes.map((shape) => /* @__PURE__ */ React__default.createElement(Line$1, { key: shape.dataKey, ...shape, dot: showDots ? shape.dot : false, type }))
83457
+ )), showLegend ? /* @__PURE__ */ React__default.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83458
+ }
83459
+ function Line(_) {
83460
+ return null;
83461
+ }
83462
+ LineChart.Line = Line;
83463
+ function PieChart(props) {
83464
+ const { children, formatter, showLabels = false, showLegend = false, tooltipTitle, unit: unit2, ...attributes } = props;
83465
+ const { pieProps, setRadius, items, activeIndex, setActiveIndex, toggleItem } = usePieChart(children, {
83466
+ formatter,
83467
+ unit: unit2
83356
83468
  });
83357
- const handleLegendClick = (entry) => {
83358
- setHoveredLine(null);
83359
- setActiveLines({ ...activeLines, [entry.dataKey]: !activeLines[entry.dataKey] });
83360
- };
83361
- return /* @__PURE__ */ React__default.createElement(ResponsiveContainer, null, /* @__PURE__ */ React__default.createElement(LineChart$1, { data, margin: { top: 10, right: 0, left: -25, bottom: 0 } }, /* @__PURE__ */ React__default.createElement(CartesianGrid, { ...getCartesianGridProps() }), /* @__PURE__ */ React__default.createElement(XAxis, { ...getXAxisProps(props) }), /* @__PURE__ */ React__default.createElement(YAxis, { ...getYAxisProps(props) }), /* @__PURE__ */ React__default.createElement(
83362
- Legend$2,
83363
- {
83364
- ...getLegendProps2({
83365
- onClick: handleLegendClick,
83366
- onMouseEnter: (entry) => setHoveredLine(entry.dataKey),
83367
- onMouseLeave: () => setHoveredLine(null),
83368
- activeItems: activeLines
83369
- })
83370
- }
83371
- ), /* @__PURE__ */ React__default.createElement(Tooltip$1, { ...getTooltipProps(), formatter }), React__default.Children.map(children, (child) => /* @__PURE__ */ React__default.createElement(
83372
- Line$1,
83469
+ const className = clsx("aspect-square", attributes.className);
83470
+ return /* @__PURE__ */ React__default.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React__default.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-pie", onSetWidth: setRadius }, /* @__PURE__ */ React__default.createElement(PieChart$1, null, /* @__PURE__ */ React__default.createElement(Tooltip$1, { content: /* @__PURE__ */ React__default.createElement(Tooltip, { title: tooltipTitle }) }), /* @__PURE__ */ React__default.createElement(Pie, { ...pieProps, label: showLabels ? /* @__PURE__ */ React__default.createElement(Label, null) : void 0 }))), showLegend ? /* @__PURE__ */ React__default.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83471
+ }
83472
+ function Segment(_) {
83473
+ return null;
83474
+ }
83475
+ PieChart.Segment = Segment;
83476
+ const RADIAN = Math.PI / 180;
83477
+ function Label(props) {
83478
+ var _a, _b;
83479
+ const { cx, cy, midAngle, name, innerRadius, outerRadius } = props;
83480
+ const radius = innerRadius + (outerRadius - innerRadius) * 0.7;
83481
+ const x3 = cx + radius * Math.cos(-midAngle * RADIAN);
83482
+ const y4 = cy + radius * Math.sin(-midAngle * RADIAN);
83483
+ return /* @__PURE__ */ React__default.createElement(
83484
+ "text",
83373
83485
  {
83374
- activeDot: {
83375
- fill: getThemeColor(child.props.color ?? "blue-300")
83376
- },
83377
- dataKey: child.props.accessor,
83378
- isAnimationActive: false,
83379
- dot: false,
83380
- name: child.props.label,
83381
- stroke: getThemeColor(child.props.color ?? "blue-300"),
83382
- strokeWidth: 2,
83383
- hide: !activeLines[child.props.accessor],
83384
- opacity: hoveredLine && child.props.accessor !== hoveredLine ? 0.3 : 1
83385
- }
83386
- ))));
83387
- };
83388
- LineChart.Line = Line;
83486
+ x: x3,
83487
+ y: y4,
83488
+ fontSize: 12,
83489
+ fill: getInverseThemeColor(((_b = (_a = props.payload) == null ? void 0 : _a.payload) == null ? void 0 : _b.color) ?? ""),
83490
+ textAnchor: "middle",
83491
+ dominantBaseline: "middle"
83492
+ },
83493
+ name
83494
+ );
83495
+ }
83389
83496
  const Button3 = React__default.forwardRef(function Button23(props, ref) {
83390
83497
  const { ...attributes } = props;
83391
83498
  const className = clsx(getButtonClasses(), props.className);
@@ -83989,43 +84096,57 @@ Navigation24.Link = Link3;
83989
84096
  Navigation24.Section = Section;
83990
84097
  Navigation24.Content = Content;
83991
84098
  const DATASET_SIZE_MULTIPLIER = 15;
84099
+ function getDataKey(sorting, filters, hiddenColumns, search) {
84100
+ return [JSON.stringify(sorting), JSON.stringify(filters), JSON.stringify(hiddenColumns), JSON.stringify(search)].join("_");
84101
+ }
83992
84102
  function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_PAGE_SIZE$1 }) {
83993
84103
  const { pageSize } = options;
83994
84104
  const DATASET_SIZE = DATASET_SIZE_MULTIPLIER * pageSize;
83995
84105
  const length = React__default.useRef(0);
83996
84106
  const [data, setData] = React__default.useState({ rows: [], pages: [], cache: {}, lastFetchedPage: void 0 });
83997
84107
  const _pendingPageRequests = React__default.useRef({});
83998
- const _lastRequestId = React__default.useRef();
83999
84108
  const _lastUsedSorting = React__default.useRef([]);
84000
84109
  const _lastUsedFilters = React__default.useRef([]);
84001
- const _lastUsedSearch = React__default.useRef();
84002
84110
  const _lastUsedHiddenColumns = React__default.useRef([]);
84003
- async function loadPage(pageIndex, sorting, filters, hiddenColumns, search, reset = false) {
84004
- if (_pendingPageRequests.current[pageIndex] && !reset) {
84005
- return;
84006
- }
84007
- const hasChangedData = JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current) || search !== _lastUsedSearch.current;
84008
- if (data.cache[pageIndex] && data.cache[pageIndex][0] && !hasChangedData && !reset) {
84009
- return;
84111
+ const _lastUsedSearch = React__default.useRef();
84112
+ async function loadPage(pageIndex, sorting, filters, hiddenColumns, search) {
84113
+ const hasDataChanged = JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current) || JSON.stringify(hiddenColumns) !== JSON.stringify(_lastUsedHiddenColumns.current) || search !== _lastUsedSearch.current;
84114
+ if (hasDataChanged) {
84115
+ _lastUsedSorting.current = sorting;
84116
+ _lastUsedFilters.current = filters;
84117
+ _lastUsedSearch.current = search;
84118
+ _lastUsedHiddenColumns.current = hiddenColumns;
84119
+ _pendingPageRequests.current = {};
84120
+ } else {
84121
+ if (_pendingPageRequests.current[pageIndex]) {
84122
+ return;
84123
+ }
84124
+ if (data.cache[pageIndex] && data.cache[pageIndex][0]) {
84125
+ return;
84126
+ }
84010
84127
  }
84011
- const requestId = nanoid();
84012
- _pendingPageRequests.current[pageIndex] = true;
84128
+ const dataKey = getDataKey(sorting, filters, hiddenColumns, search);
84129
+ _pendingPageRequests.current[pageIndex] = dataKey;
84013
84130
  try {
84014
- _lastRequestId.current = requestId;
84015
84131
  const response = await fetchPage(pageIndex, pageSize, sorting, filters, hiddenColumns, search);
84132
+ if (dataKey !== _pendingPageRequests.current[pageIndex]) {
84133
+ return;
84134
+ }
84016
84135
  length.current = response.length;
84017
84136
  setData((currentData) => {
84018
- if (_lastRequestId.current !== requestId) {
84019
- return currentData;
84020
- }
84021
84137
  const direction = getDirection(pageIndex, currentData.pages);
84022
- const nextPages = getPages(pageIndex, currentData.lastFetchedPage, reset ? [] : currentData.pages, direction);
84138
+ const nextPages = getPages(
84139
+ pageIndex,
84140
+ currentData.lastFetchedPage,
84141
+ hasDataChanged ? [] : currentData.pages,
84142
+ direction
84143
+ );
84023
84144
  _lastUsedSorting.current = sorting;
84024
84145
  _lastUsedFilters.current = filters;
84025
84146
  _lastUsedSearch.current = search;
84026
84147
  _lastUsedHiddenColumns.current = hiddenColumns;
84027
84148
  let nextCache;
84028
- if (reset || hasChangedData || !direction) {
84149
+ if (hasDataChanged || !direction) {
84029
84150
  nextCache = nextPages.reduce((acc, p2) => ({ ...acc, [p2]: Array(pageSize).fill(void 0) }), {});
84030
84151
  } else {
84031
84152
  nextCache = { ...currentData.cache };
@@ -84044,7 +84165,9 @@ function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_
84044
84165
  lastFetchedPage: pageIndex
84045
84166
  };
84046
84167
  });
84047
- delete _pendingPageRequests.current[pageIndex];
84168
+ requestAnimationFrame(() => {
84169
+ delete _pendingPageRequests.current[pageIndex];
84170
+ });
84048
84171
  } catch {
84049
84172
  }
84050
84173
  }
@@ -84075,35 +84198,61 @@ function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_
84075
84198
  _pendingPageRequests.current = {};
84076
84199
  }
84077
84200
  };
84201
+ async function reloadCurrentPages(currentPageIndex, sorting, filters, hiddenColumns, search) {
84202
+ const index2 = data.pages.indexOf(currentPageIndex);
84203
+ const pageIndexes = [data.pages[index2 - 1], currentPageIndex, data.pages[index2 + 1]].filter((x3) => x3 !== void 0);
84204
+ const dataKey = getDataKey(sorting, filters, hiddenColumns, search);
84205
+ _pendingPageRequests.current = pageIndexes.reduce((accum, index22) => ({ ...accum, [index22]: dataKey }), {});
84206
+ try {
84207
+ const responses = await Promise.all(
84208
+ pageIndexes.map((pageIndex) => fetchPage(pageIndex, pageSize, sorting, filters, hiddenColumns, search))
84209
+ );
84210
+ length.current = responses[0].length;
84211
+ const nextPages = pageIndexes;
84212
+ _lastUsedSorting.current = sorting;
84213
+ _lastUsedFilters.current = filters;
84214
+ _lastUsedSearch.current = search;
84215
+ _lastUsedHiddenColumns.current = hiddenColumns;
84216
+ const nextCache = nextPages.reduce(
84217
+ (acc, p2, index22) => ({ ...acc, [p2]: responses[index22].data }),
84218
+ {}
84219
+ );
84220
+ const rows = Object.values(nextCache).reduce((acc, p2) => acc.concat(p2), []);
84221
+ setData({
84222
+ cache: nextCache,
84223
+ pages: nextPages,
84224
+ rows,
84225
+ lastFetchedPage: pageIndexes[pageIndexes.length - 1]
84226
+ });
84227
+ requestAnimationFrame(() => {
84228
+ _pendingPageRequests.current = {};
84229
+ });
84230
+ } catch {
84231
+ }
84232
+ }
84078
84233
  const invalidate = async () => {
84079
- _pendingPageRequests.current = {};
84080
- return loadPage(
84234
+ return reloadCurrentPages(
84081
84235
  getCurrentPage(data.pages),
84082
84236
  _lastUsedSorting.current,
84083
84237
  _lastUsedFilters.current,
84084
84238
  _lastUsedHiddenColumns.current,
84085
- _lastUsedSearch.current,
84086
- true
84239
+ _lastUsedSearch.current
84087
84240
  );
84088
84241
  };
84089
84242
  const handleSort = async (sorting) => {
84090
- _pendingPageRequests.current = {};
84091
- return loadPage(
84243
+ return reloadCurrentPages(
84092
84244
  getCurrentPage(data.pages),
84093
84245
  sorting,
84094
84246
  _lastUsedFilters.current,
84095
84247
  _lastUsedHiddenColumns.current,
84096
- _lastUsedSearch.current,
84097
- true
84248
+ _lastUsedSearch.current
84098
84249
  );
84099
84250
  };
84100
84251
  const handleFilter = async (filters, hiddenColumns) => {
84101
- _pendingPageRequests.current = {};
84102
- return loadPage(0, _lastUsedSorting.current, filters, hiddenColumns, _lastUsedSearch.current, true);
84252
+ return loadPage(0, _lastUsedSorting.current, filters, hiddenColumns, _lastUsedSearch.current);
84103
84253
  };
84104
84254
  const handleSearch = async (search, hiddenColumns) => {
84105
- _pendingPageRequests.current = {};
84106
- return loadPage(0, _lastUsedSorting.current, _lastUsedFilters.current, hiddenColumns, search, true);
84255
+ return loadPage(0, _lastUsedSorting.current, _lastUsedFilters.current, hiddenColumns, search);
84107
84256
  };
84108
84257
  return [
84109
84258
  {
@@ -84213,6 +84362,7 @@ export {
84213
84362
  IconButton,
84214
84363
  Input,
84215
84364
  Layout,
84365
+ LegacyDonutChart,
84216
84366
  LineChart,
84217
84367
  List$1 as List,
84218
84368
  Listbox,
@@ -84226,6 +84376,7 @@ export {
84226
84376
  OverflowGroup,
84227
84377
  PaginatedTable,
84228
84378
  Pagination,
84379
+ PieChart,
84229
84380
  Popover,
84230
84381
  Progress,
84231
84382
  Provider,