@economic/taco 2.57.0-charts.0 → 2.57.0-charts.10

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
@@ -82761,18 +82761,21 @@ var AreaChart$1 = generateCategoricalChart({
82761
82761
  }],
82762
82762
  formatAxisMap: formatAxisMap2
82763
82763
  });
82764
- function getAxisProps(scale2, tickFormatter, dataKey) {
82764
+ function getAxisProps(scale2, tickFormatter, dataKey, width) {
82765
+ const isYAxis = dataKey === void 0;
82765
82766
  return {
82766
82767
  axisLine: false,
82767
82768
  dataKey,
82768
82769
  fontSize: 11,
82770
+ interval: "preserveStartEnd",
82769
82771
  scale: scale2,
82770
82772
  tickLine: false,
82771
- tickMargin: 8,
82772
- tickFormatter
82773
+ tickMargin: isYAxis ? 2 : 6,
82774
+ tickFormatter,
82775
+ width: width ?? 55
82773
82776
  };
82774
82777
  }
82775
- function ChartContainer(props) {
82778
+ function ChartWrapper(props) {
82776
82779
  const { onSetWidth: handleSetWidth, ...attributes } = props;
82777
82780
  const ref = React.useRef(null);
82778
82781
  React.useLayoutEffect(() => {
@@ -82781,7 +82784,7 @@ function ChartContainer(props) {
82781
82784
  handleSetWidth(rect.width);
82782
82785
  }
82783
82786
  }, [ref]);
82784
- const className = clsx("flex justify-center mx-auto", attributes.className);
82787
+ const className = clsx("flex justify-center m-auto", attributes.className);
82785
82788
  return /* @__PURE__ */ React.createElement("div", { ...attributes, className, ref }, /* @__PURE__ */ React.createElement(ResponsiveContainer, null, props.children));
82786
82789
  }
82787
82790
  function Tooltip(props) {
@@ -82812,11 +82815,14 @@ function Legend$1(props) {
82812
82815
  handleToggle(item.dataKey);
82813
82816
  };
82814
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);
82815
- return /* @__PURE__ */ React.createElement(OverflowGroup, { className: "w-full gap-x-1", moreButton }, items.map((item, index2) => {
82818
+ return /* @__PURE__ */ React.createElement(OverflowGroup, { className: "mt-3 w-full gap-x-1", moreButton }, items.map((item, index2) => {
82816
82819
  const className = clsx("mr-1 flex h-3 w-3 rounded-sm", {
82817
- [`bg-${item.color}`]: !item.isHidden,
82818
82820
  border: item.isHidden
82819
82821
  });
82822
+ let style;
82823
+ if (!item.isHidden) {
82824
+ style = { backgroundColor: item.color };
82825
+ }
82820
82826
  return /* @__PURE__ */ React.createElement(
82821
82827
  "button",
82822
82828
  {
@@ -82829,7 +82835,7 @@ function Legend$1(props) {
82829
82835
  onMouseEnter: () => handleMouseEnter(item, index2),
82830
82836
  onMouseLeave: () => handleMouseLeave()
82831
82837
  },
82832
- /* @__PURE__ */ React.createElement("span", { className }, hoverIndex === index2 ? /* @__PURE__ */ React.createElement(Icon$1, { name: "tick-bold", className: clsx("!h-full !w-full", { "text-white": !item.isHidden }) }) : null),
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),
82833
82839
  item.label
82834
82840
  );
82835
82841
  }));
@@ -82970,7 +82976,8 @@ const mapColor = (palette, prefix2 = "") => {
82970
82976
  };
82971
82977
  const colors = mapColor(THEME_COLORS);
82972
82978
  const getThemeColor = (color2, def = "") => colors[color2 ?? def];
82973
- const getInverseThemeColor = (themeColor) => {
82979
+ const getInverseThemeColor = (hexCode) => {
82980
+ const themeColor = Object.keys(colors)[Object.values(colors).indexOf(hexCode)];
82974
82981
  const [color2, number2] = String(themeColor).split("-");
82975
82982
  const shade = Number(number2);
82976
82983
  if (shade) {
@@ -82996,28 +83003,28 @@ function useChart(children, options) {
82996
83003
  return {
82997
83004
  ...child.props,
82998
83005
  dataKey,
83006
+ color: getThemeColor(child.props.color, "blue-300"),
82999
83007
  formatter: child.props.formatter ?? (options == null ? void 0 : options.formatter) ?? defaultFormatter2,
83000
83008
  isHidden: !!hiddenItems[dataKey],
83001
83009
  unit: child.props.unit ?? (options == null ? void 0 : options.unit)
83002
83010
  };
83003
83011
  });
83004
83012
  const shapes2 = items2.filter((item) => !hiddenItems[item.dataKey]).map((item) => {
83005
- const color2 = getThemeColor(item.color, "blue-500");
83006
83013
  return {
83007
83014
  activeDot: {
83008
83015
  strokeWidth: 1
83009
83016
  },
83010
- color: color2,
83017
+ color: item.color,
83011
83018
  dataKey: item.dataKey,
83012
83019
  dot: {
83013
- fillOpacity: 0.6
83020
+ fillOpacity: 0.8
83014
83021
  },
83015
83022
  isAnimationActive: false,
83016
- fill: color2,
83017
- fillOpacity: 0.65,
83023
+ fill: item.color,
83024
+ fillOpacity: 0.8,
83018
83025
  formatter: item.formatter,
83019
83026
  name: item.label,
83020
- stroke: color2,
83027
+ stroke: item.color,
83021
83028
  strokeWidth: 1.5,
83022
83029
  unit: item.unit
83023
83030
  };
@@ -83044,6 +83051,7 @@ function useChartDataHiddenState() {
83044
83051
  function AreaChart(props) {
83045
83052
  const {
83046
83053
  children,
83054
+ className: customClassName,
83047
83055
  data,
83048
83056
  dataKey,
83049
83057
  showDots = false,
@@ -83057,15 +83065,22 @@ function AreaChart(props) {
83057
83065
  xAxisTickFormatter,
83058
83066
  yAxisScale,
83059
83067
  yAxisTickFormatter,
83068
+ yAxisWidth,
83060
83069
  ...attributes
83061
83070
  } = props;
83062
- const className = clsx("aspect-video", attributes.className);
83071
+ const className = clsx("relative aspect-video", { "pb-8": showLegend }, customClassName);
83063
83072
  const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83064
- return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-area" }, /* @__PURE__ */ React.createElement(
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(
83065
83074
  AreaChart$1,
83066
83075
  {
83067
83076
  data,
83068
- margin: { bottom: 10, left: 10, right: 10, top: 10 },
83077
+ margin: {
83078
+ bottom: 0,
83079
+ // ensures dots on the edges of the chart don't get cropped
83080
+ left: 4,
83081
+ right: 4,
83082
+ top: 4
83083
+ },
83069
83084
  stackOffset: stacked === "expand" ? "expand" : void 0
83070
83085
  },
83071
83086
  /* @__PURE__ */ React.createElement(CartesianGrid, { vertical: false }),
@@ -83077,13 +83092,20 @@ function AreaChart(props) {
83077
83092
  hide: !showXAxis
83078
83093
  }
83079
83094
  ),
83080
- /* @__PURE__ */ React.createElement(YAxis, { ...getAxisProps(yAxisScale, yAxisTickFormatter), hide: !showYAxis }),
83095
+ /* @__PURE__ */ React.createElement(
83096
+ YAxis,
83097
+ {
83098
+ ...getAxisProps(yAxisScale, yAxisTickFormatter, void 0, yAxisWidth),
83099
+ hide: !showYAxis
83100
+ }
83101
+ ),
83081
83102
  shapes.map((shape) => /* @__PURE__ */ React.createElement(
83082
83103
  Area$1,
83083
83104
  {
83084
83105
  key: shape.dataKey,
83085
83106
  ...shape,
83086
83107
  dot: showDots ? shape.dot : false,
83108
+ fillOpacity: 0.4,
83087
83109
  stackId: stacked ? "stack" : void 0,
83088
83110
  type
83089
83111
  }
@@ -83094,11 +83116,12 @@ function Area(_) {
83094
83116
  return null;
83095
83117
  }
83096
83118
  AreaChart.Area = Area;
83097
- const BAR_WIDTH = 20;
83119
+ const BAR_WIDTH = 18;
83098
83120
  function BarChart(props) {
83099
83121
  const isHorizontal = props.layout === "horizontal";
83100
83122
  const {
83101
83123
  children,
83124
+ className: customClassName,
83102
83125
  data,
83103
83126
  dataKey,
83104
83127
  showLabels = false,
@@ -83110,17 +83133,24 @@ function BarChart(props) {
83110
83133
  xAxisTickFormatter,
83111
83134
  yAxisScale,
83112
83135
  yAxisTickFormatter,
83136
+ yAxisWidth,
83113
83137
  ...attributes
83114
83138
  } = props;
83115
- const className = clsx("aspect-video", attributes.className);
83139
+ const className = clsx("relative aspect-video", { "pb-8": showLegend }, customClassName);
83116
83140
  const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83117
- return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-bar" }, /* @__PURE__ */ React.createElement(
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(
83118
83142
  BarChart$1,
83119
83143
  {
83120
83144
  data,
83121
83145
  barCategoryGap: "15%",
83122
83146
  barGap: "7.5%",
83123
- margin: { bottom: 10, left: isHorizontal ? -15 : 10, right: 10, top: 10 },
83147
+ margin: {
83148
+ bottom: 0,
83149
+ left: 0,
83150
+ right: 0,
83151
+ // ensures labels on top of bars don't get cropped
83152
+ top: isHorizontal ? 0 : 10
83153
+ },
83124
83154
  layout: isHorizontal ? "vertical" : void 0,
83125
83155
  stackOffset: stacked === "expand" ? "expand" : void 0
83126
83156
  },
@@ -83137,8 +83167,14 @@ function BarChart(props) {
83137
83167
  /* @__PURE__ */ React.createElement(
83138
83168
  YAxis,
83139
83169
  {
83140
- ...getAxisProps(yAxisScale, yAxisTickFormatter, isHorizontal ? dataKey : void 0),
83170
+ ...getAxisProps(
83171
+ yAxisScale,
83172
+ yAxisTickFormatter,
83173
+ isHorizontal ? dataKey : void 0,
83174
+ yAxisWidth
83175
+ ),
83141
83176
  hide: !showYAxis,
83177
+ minTickGap: isHorizontal ? 1 : 5,
83142
83178
  type: isHorizontal ? "category" : void 0
83143
83179
  }
83144
83180
  ),
@@ -83148,17 +83184,17 @@ function BarChart(props) {
83148
83184
  key: shape.dataKey,
83149
83185
  ...shape,
83150
83186
  activeBar: { fillOpacity: 1, strokeWidth: 0 },
83151
- strokeWidth: 0,
83152
83187
  maxBarSize: BAR_WIDTH,
83153
83188
  radius: getRadius(index2, shapes.length, !!stacked, isHorizontal),
83154
- stackId: stacked ? "stack" : void 0
83189
+ stackId: stacked ? "stack" : void 0,
83190
+ strokeWidth: 0
83155
83191
  },
83156
83192
  showLabels ? /* @__PURE__ */ React.createElement(
83157
83193
  LabelList,
83158
83194
  {
83159
83195
  position: isHorizontal ? "insideRight" : "top",
83160
83196
  formatter: shape.formatter,
83161
- offset: isHorizontal ? 6 : 8,
83197
+ offset: 6,
83162
83198
  fill: isHorizontal ? getInverseThemeColor(shape.color ?? "") : "black",
83163
83199
  fontSize: 11
83164
83200
  }
@@ -83230,15 +83266,16 @@ function DonutChart(props) {
83230
83266
  unit: unit2
83231
83267
  });
83232
83268
  const className = clsx("aspect-square", attributes.className);
83233
- return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, showTotal ? /* @__PURE__ */ React.createElement(
83269
+ console.log("radius", radius);
83270
+ 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(
83234
83271
  Total,
83235
83272
  {
83236
83273
  formatter,
83237
83274
  items,
83238
83275
  unit: unit2,
83239
- style: { top: radius / 2 - 2, width: radius + DONUT_WIDTH$1 }
83276
+ style: { top: radius + DONUT_WIDTH$1 / 2, width: radius + DONUT_WIDTH$1 * 2 }
83240
83277
  }
83241
- ) : null, /* @__PURE__ */ React.createElement(ChartContainer, { ...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);
83278
+ ) : null, showLegend ? /* @__PURE__ */ React.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83242
83279
  }
83243
83280
  function Segment$2(_) {
83244
83281
  return null;
@@ -83251,7 +83288,16 @@ function Total(props) {
83251
83288
  const total2 = items.filter((item) => !item.isHidden).reduce((acc, curr) => acc + curr.value, 0);
83252
83289
  return (formatter == null ? void 0 : formatter(total2)) ?? new Intl.NumberFormat(localization.locale).format(total2);
83253
83290
  }, [items]);
83254
- return /* @__PURE__ */ React.createElement("div", { ...attributes, className: "absolute-center-x flex aspect-square flex-col items-center justify-center rounded-full" }, /* @__PURE__ */ React.createElement("span", { className: "truncate text-2xl font-bold tabular-nums" }, total), unit2 ? /* @__PURE__ */ React.createElement("span", { className: "text-grey-700 -mb-1 -mt-0.5 truncate text-xs" }, unit2) : null);
83291
+ return /* @__PURE__ */ React.createElement(
83292
+ "div",
83293
+ {
83294
+ ...attributes,
83295
+ className: "absolute-center flex aspect-video flex-col items-center justify-center overflow-hidden rounded-full",
83296
+ "data-taco": "chart-donut-total"
83297
+ },
83298
+ /* @__PURE__ */ React.createElement(Tooltip$3, { title: total }, /* @__PURE__ */ React.createElement("span", { className: "w-full truncate text-center font-bold tabular-nums" }, total)),
83299
+ unit2 ? /* @__PURE__ */ React.createElement("span", { className: "text-grey-700 -mb-1 -mt-0.5 truncate text-xs" }, unit2) : null
83300
+ );
83255
83301
  }
83256
83302
  const Legend = ({ hoveredItem, selectedItem, data, onClick, setHoveredItem, formatter, total, label }) => {
83257
83303
  const isTotalLegendSelected = selectedItem.length === data.length;
@@ -83280,7 +83326,7 @@ const Legend = ({ hoveredItem, selectedItem, data, onClick, setHoveredItem, form
83280
83326
  };
83281
83327
  return /* @__PURE__ */ React.createElement("div", { className: "flex-grow pl-4" }, /* @__PURE__ */ React.createElement("ul", { className: "mb-0 ml-0 mt-4 flex flex-col justify-center gap-1 space-y-1" }, renderLegendItem(null), data.map(renderLegendItem)));
83282
83328
  };
83283
- const DONUT_WIDTH = 24;
83329
+ const DONUT_WIDTH = 16;
83284
83330
  const HOVER_DONUT_WIDTH = 10;
83285
83331
  const CenteredLabel = ({ radius, label, total, formatter }) => {
83286
83332
  const totalInset = HOVER_DONUT_WIDTH + DONUT_WIDTH + DONUT_WIDTH;
@@ -83417,6 +83463,7 @@ const LegacyDonutChart = function LegacyDonutChart2({ children, formatter, onCli
83417
83463
  onMouseEnter: (segment) => data.length > 0 && setHoveredItem([segment.id]),
83418
83464
  onMouseLeave: () => setHoveredItem([]),
83419
83465
  outerRadius: radius - HOVER_DONUT_WIDTH,
83466
+ paddingAngle: 2.5,
83420
83467
  stroke: "0",
83421
83468
  rootTabIndex: -1
83422
83469
  },
@@ -83439,6 +83486,7 @@ LegacyDonutChart.Segment = Segment$1;
83439
83486
  function LineChart(props) {
83440
83487
  const {
83441
83488
  children,
83489
+ className: customClassName,
83442
83490
  data,
83443
83491
  dataKey,
83444
83492
  showDots = false,
@@ -83451,15 +83499,22 @@ function LineChart(props) {
83451
83499
  xAxisTickFormatter,
83452
83500
  yAxisScale,
83453
83501
  yAxisTickFormatter,
83502
+ yAxisWidth,
83454
83503
  ...attributes
83455
83504
  } = props;
83456
- const className = clsx("aspect-video", attributes.className);
83505
+ const className = clsx("relative aspect-video", { "pb-8": showLegend }, customClassName);
83457
83506
  const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children);
83458
- return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-area" }, /* @__PURE__ */ React.createElement(
83507
+ 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(
83459
83508
  LineChart$1,
83460
83509
  {
83461
83510
  data,
83462
- margin: { bottom: 10, left: 10, right: 10, top: 10 }
83511
+ margin: {
83512
+ bottom: 0,
83513
+ // ensures dots on the edges of the chart don't get cropped
83514
+ left: 4,
83515
+ right: 4,
83516
+ top: 4
83517
+ }
83463
83518
  },
83464
83519
  /* @__PURE__ */ React.createElement(CartesianGrid, { vertical: false }),
83465
83520
  /* @__PURE__ */ React.createElement(Tooltip$1, { content: /* @__PURE__ */ React.createElement(Tooltip, { title: tooltipTitle }) }),
@@ -83470,7 +83525,13 @@ function LineChart(props) {
83470
83525
  hide: !showXAxis
83471
83526
  }
83472
83527
  ),
83473
- /* @__PURE__ */ React.createElement(YAxis, { ...getAxisProps(yAxisScale, yAxisTickFormatter), hide: !showYAxis }),
83528
+ /* @__PURE__ */ React.createElement(
83529
+ YAxis,
83530
+ {
83531
+ ...getAxisProps(yAxisScale, yAxisTickFormatter, void 0, yAxisWidth),
83532
+ hide: !showYAxis
83533
+ }
83534
+ ),
83474
83535
  shapes.map((shape) => /* @__PURE__ */ React.createElement(Line$1, { key: shape.dataKey, ...shape, dot: showDots ? shape.dot : false, type }))
83475
83536
  )), showLegend ? /* @__PURE__ */ React.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83476
83537
  }
@@ -83485,7 +83546,7 @@ function PieChart(props) {
83485
83546
  unit: unit2
83486
83547
  });
83487
83548
  const className = clsx("aspect-square", attributes.className);
83488
- return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartContainer, { ...attributes, className, "data-taco": "chart-pie", 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, label: showLabels ? /* @__PURE__ */ React.createElement(Label, null) : void 0 }))), showLegend ? /* @__PURE__ */ React.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83549
+ return /* @__PURE__ */ React.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React.createElement(ChartWrapper, { ...attributes, className, "data-taco": "chart-pie", 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, label: showLabels ? /* @__PURE__ */ React.createElement(Label, null) : void 0 }))), showLegend ? /* @__PURE__ */ React.createElement(Legend$1, { items, hoverIndex: activeIndex, onHover: setActiveIndex, onToggle: toggleItem }) : null);
83489
83550
  }
83490
83551
  function Segment(_) {
83491
83552
  return null;