@economic/taco 2.57.0-charts.6 → 2.57.0-charts.8

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.cjs CHANGED
@@ -82799,6 +82799,47 @@ function Tooltip(props) {
82799
82799
  }
82800
82800
  return null;
82801
82801
  }
82802
+ function Legend$1(props) {
82803
+ const { hoverIndex, items, onHover: handleHover, onToggle: handleToggle } = props;
82804
+ const handleMouseEnter = (item, index2) => {
82805
+ if (item.isHidden) {
82806
+ return;
82807
+ }
82808
+ handleHover(index2);
82809
+ };
82810
+ const handleMouseLeave = () => handleHover(void 0);
82811
+ const handleClick = (item) => {
82812
+ if (!item.isHidden) {
82813
+ handleHover(void 0);
82814
+ }
82815
+ handleToggle(item.dataKey);
82816
+ };
82817
+ const moreButton = (moreButtonText) => /* @__PURE__ */ React.createElement(Button$4, { appearance: "transparent", className: "text-grey-700 !h-5 !min-h-[1.25rem] !px-1.5 text-xs" }, moreButtonText);
82818
+ return /* @__PURE__ */ React.createElement(OverflowGroup, { className: "mt-3 w-full gap-x-1", moreButton }, items.map((item, index2) => {
82819
+ const className = clsx("mr-1 flex h-3 w-3 rounded-sm", {
82820
+ border: item.isHidden
82821
+ });
82822
+ let style;
82823
+ if (!item.isHidden) {
82824
+ style = { backgroundColor: item.color };
82825
+ }
82826
+ return /* @__PURE__ */ React.createElement(
82827
+ "button",
82828
+ {
82829
+ key: item.label,
82830
+ className: "hover:bg-grey-200 focus-visible:yt-focus flex items-center rounded px-1 !text-xs",
82831
+ onClick: (event) => {
82832
+ event == null ? void 0 : event.preventDefault();
82833
+ handleClick(item);
82834
+ },
82835
+ onMouseEnter: () => handleMouseEnter(item, index2),
82836
+ onMouseLeave: () => handleMouseLeave()
82837
+ },
82838
+ /* @__PURE__ */ React.createElement("span", { className, style }, hoverIndex === index2 ? /* @__PURE__ */ React.createElement(Icon$1, { name: "tick-bold", className: clsx("!h-full !w-full", { "text-white": !item.isHidden }) }) : null),
82839
+ item.label
82840
+ );
82841
+ }));
82842
+ }
82802
82843
  const THEME_COLORS = {
82803
82844
  transparent: "transparent",
82804
82845
  current: "currentColor",
@@ -82935,7 +82976,8 @@ const mapColor = (palette, prefix2 = "") => {
82935
82976
  };
82936
82977
  const colors = mapColor(THEME_COLORS);
82937
82978
  const getThemeColor = (color2, def = "") => colors[color2 ?? def];
82938
- const getInverseThemeColor = (themeColor) => {
82979
+ const getInverseThemeColor = (hexCode) => {
82980
+ const themeColor = Object.keys(colors)[Object.values(colors).indexOf(hexCode)];
82939
82981
  const [color2, number2] = String(themeColor).split("-");
82940
82982
  const shade = Number(number2);
82941
82983
  if (shade) {
@@ -82950,47 +82992,6 @@ const getInverseThemeColor = (themeColor) => {
82950
82992
  }
82951
82993
  return color2 === "black" ? "white" : "black";
82952
82994
  };
82953
- function Legend$1(props) {
82954
- const { hoverIndex, items, onHover: handleHover, onToggle: handleToggle } = props;
82955
- const handleMouseEnter = (item, index2) => {
82956
- if (item.isHidden) {
82957
- return;
82958
- }
82959
- handleHover(index2);
82960
- };
82961
- const handleMouseLeave = () => handleHover(void 0);
82962
- const handleClick = (item) => {
82963
- if (!item.isHidden) {
82964
- handleHover(void 0);
82965
- }
82966
- handleToggle(item.dataKey);
82967
- };
82968
- const moreButton = (moreButtonText) => /* @__PURE__ */ React.createElement(Button$4, { appearance: "transparent", className: "text-grey-700 !h-5 !min-h-[1.25rem] !px-1.5 text-xs" }, moreButtonText);
82969
- return /* @__PURE__ */ React.createElement(OverflowGroup, { className: "mt-2.5 w-full gap-x-1", moreButton }, items.map((item, index2) => {
82970
- const className = clsx("mr-1 flex h-3 w-3 rounded-sm", {
82971
- border: item.isHidden
82972
- });
82973
- let style;
82974
- if (!item.isHidden) {
82975
- style = { backgroundColor: getThemeColor(item.color) };
82976
- }
82977
- return /* @__PURE__ */ React.createElement(
82978
- "button",
82979
- {
82980
- key: item.label,
82981
- className: "hover:bg-grey-200 focus-visible:yt-focus flex items-center rounded px-1 !text-xs",
82982
- onClick: (event) => {
82983
- event == null ? void 0 : event.preventDefault();
82984
- handleClick(item);
82985
- },
82986
- onMouseEnter: () => handleMouseEnter(item, index2),
82987
- onMouseLeave: () => handleMouseLeave()
82988
- },
82989
- /* @__PURE__ */ React.createElement("span", { className, style }, hoverIndex === index2 ? /* @__PURE__ */ React.createElement(Icon$1, { name: "tick-bold", className: clsx("!h-full !w-full", { "text-white": !item.isHidden }) }) : null),
82990
- item.label
82991
- );
82992
- }));
82993
- }
82994
82995
  function useChart(children, options) {
82995
82996
  const [activeIndex, setActiveIndex] = React.useState();
82996
82997
  const [hiddenItems, toggleItem] = useChartDataHiddenState();
@@ -83002,28 +83003,28 @@ function useChart(children, options) {
83002
83003
  return {
83003
83004
  ...child.props,
83004
83005
  dataKey,
83006
+ color: getThemeColor(child.props.color, "blue-300"),
83005
83007
  formatter: child.props.formatter ?? (options == null ? void 0 : options.formatter) ?? defaultFormatter2,
83006
83008
  isHidden: !!hiddenItems[dataKey],
83007
83009
  unit: child.props.unit ?? (options == null ? void 0 : options.unit)
83008
83010
  };
83009
83011
  });
83010
83012
  const shapes2 = items2.filter((item) => !hiddenItems[item.dataKey]).map((item) => {
83011
- const color2 = getThemeColor(item.color, "blue-300");
83012
83013
  return {
83013
83014
  activeDot: {
83014
83015
  strokeWidth: 1
83015
83016
  },
83016
- color: color2,
83017
+ color: item.color,
83017
83018
  dataKey: item.dataKey,
83018
83019
  dot: {
83019
83020
  fillOpacity: 0.8
83020
83021
  },
83021
83022
  isAnimationActive: false,
83022
- fill: color2,
83023
- fillOpacity: 0.75,
83023
+ fill: item.color,
83024
+ fillOpacity: 0.8,
83024
83025
  formatter: item.formatter,
83025
83026
  name: item.label,
83026
- stroke: color2,
83027
+ stroke: item.color,
83027
83028
  strokeWidth: 1.5,
83028
83029
  unit: item.unit
83029
83030
  };
@@ -83067,7 +83068,7 @@ function AreaChart(props) {
83067
83068
  yAxisWidth,
83068
83069
  ...attributes
83069
83070
  } = props;
83070
- const className = clsx("relative aspect-video", { "pb-6": showLegend }, customClassName);
83071
+ const className = clsx("relative aspect-video", { "pb-8": showLegend }, customClassName);
83071
83072
  const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83072
83073
  return /* @__PURE__ */ React.createElement("div", { className, "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartWrapper, { ...attributes, className: "h-full w-full", "data-taco": "chart-area" }, /* @__PURE__ */ React.createElement(
83073
83074
  AreaChart$1,
@@ -83135,7 +83136,7 @@ function BarChart(props) {
83135
83136
  yAxisWidth,
83136
83137
  ...attributes
83137
83138
  } = props;
83138
- const className = clsx("relative aspect-video", { "pb-6": showLegend }, customClassName);
83139
+ const className = clsx("relative aspect-video", { "pb-8": showLegend }, customClassName);
83139
83140
  const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83140
83141
  return /* @__PURE__ */ React.createElement("div", { className, "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartWrapper, { ...attributes, className: "h-full w-full", "data-taco": "chart-bar" }, /* @__PURE__ */ React.createElement(
83141
83142
  BarChart$1,
@@ -83265,7 +83266,7 @@ function DonutChart(props) {
83265
83266
  unit: unit2
83266
83267
  });
83267
83268
  const className = clsx("aspect-square", attributes.className);
83268
- return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, showTotal ? /* @__PURE__ */ React.createElement(
83269
+ return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartWrapper, { ...attributes, className, "data-taco": "chart-donut", onSetWidth: setRadius }, /* @__PURE__ */ React.createElement(PieChart$1, null, /* @__PURE__ */ React.createElement(Tooltip$1, { content: /* @__PURE__ */ React.createElement(Tooltip$3, { title: tooltipTitle }) }), /* @__PURE__ */ React.createElement(Pie, { ...pieProps, innerRadius: radius - DONUT_WIDTH$1 }))), showTotal ? /* @__PURE__ */ React.createElement(
83269
83270
  Total,
83270
83271
  {
83271
83272
  formatter,
@@ -83273,7 +83274,7 @@ function DonutChart(props) {
83273
83274
  unit: unit2,
83274
83275
  style: { top: radius / 2 - 2, width: radius + DONUT_WIDTH$1 }
83275
83276
  }
83276
- ) : null, /* @__PURE__ */ React.createElement(ChartWrapper, { ...attributes, className, "data-taco": "chart-donut", onSetWidth: setRadius }, /* @__PURE__ */ React.createElement(PieChart$1, null, /* @__PURE__ */ React.createElement(Tooltip$1, { content: /* @__PURE__ */ React.createElement(Tooltip, { title: tooltipTitle }) }), /* @__PURE__ */ React.createElement(Pie, { ...pieProps, innerRadius: radius - DONUT_WIDTH$1 }))), showLegend ? /* @__PURE__ */ React.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83277
+ ) : null, showLegend ? /* @__PURE__ */ React.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83277
83278
  }
83278
83279
  function Segment$2(_) {
83279
83280
  return null;
@@ -83290,9 +83291,10 @@ function Total(props) {
83290
83291
  "div",
83291
83292
  {
83292
83293
  ...attributes,
83293
- className: "absolute-center-x flex aspect-square flex-col items-center justify-center rounded-full pt-[2px]"
83294
+ className: "absolute-center-x flex aspect-square flex-col items-center justify-center overflow-hidden rounded-full pt-[2px]",
83295
+ "data-taco": "chart-donut-total"
83294
83296
  },
83295
- /* @__PURE__ */ React.createElement("span", { className: "truncate text-2xl font-bold tabular-nums" }, total),
83297
+ /* @__PURE__ */ React.createElement(Tooltip$3, { title: total }, /* @__PURE__ */ React.createElement("span", { className: "w-full truncate text-center font-bold tabular-nums" }, total)),
83296
83298
  unit2 ? /* @__PURE__ */ React.createElement("span", { className: "text-grey-700 -mb-1 -mt-0.5 truncate text-xs" }, unit2) : null
83297
83299
  );
83298
83300
  }
@@ -83499,7 +83501,7 @@ function LineChart(props) {
83499
83501
  yAxisWidth,
83500
83502
  ...attributes
83501
83503
  } = props;
83502
- const className = clsx("relative aspect-video", { "pb-6": showLegend }, customClassName);
83504
+ const className = clsx("relative aspect-video", { "pb-8": showLegend }, customClassName);
83503
83505
  const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83504
83506
  return /* @__PURE__ */ React.createElement("div", { className, "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartWrapper, { ...attributes, className: "h-full w-full", "data-taco": "chart-line" }, /* @__PURE__ */ React.createElement(
83505
83507
  LineChart$1,