@economic/taco 2.57.0-charts.11 → 2.57.0-charts.13
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 +19 -14
- package/dist/taco.cjs.map +1 -1
- package/dist/taco.d.ts +58 -1
- package/dist/taco.js +19 -14
- package/dist/taco.js.map +1 -1
- package/package.json +2 -2
package/dist/taco.d.ts
CHANGED
@@ -163,8 +163,17 @@ export declare interface AreaChartAreaProps<TData extends object> extends ChartC
|
|
163
163
|
}
|
164
164
|
|
165
165
|
export declare interface AreaChartProps<TData extends object> extends ChartProps<TData>, default_2.ComponentProps<'div'> {
|
166
|
+
/** Show dots for each data point
|
167
|
+
* @default false
|
168
|
+
*/
|
166
169
|
showDots?: boolean;
|
170
|
+
/** Stack areas on top of one another, instead of other each other. 'expand' fills the available space
|
171
|
+
* @default false
|
172
|
+
*/
|
167
173
|
stacked?: boolean | 'expand';
|
174
|
+
/** Interpolation type of the line
|
175
|
+
* @default natural
|
176
|
+
*/
|
168
177
|
type?: CurveType;
|
169
178
|
}
|
170
179
|
|
@@ -240,8 +249,17 @@ export declare interface BarChartBarProps<TData extends object> extends ChartChi
|
|
240
249
|
}
|
241
250
|
|
242
251
|
export declare interface BarChartProps<TData extends object> extends ChartProps<TData>, default_2.ComponentProps<'div'> {
|
243
|
-
|
252
|
+
/** Orientation of the bars
|
253
|
+
* @default false
|
254
|
+
*/
|
255
|
+
orientation?: 'horizontal' | 'vertical';
|
256
|
+
/** Show bar values as labels next to/inside the bar
|
257
|
+
* @default vertical
|
258
|
+
*/
|
244
259
|
showLabels?: boolean;
|
260
|
+
/** Stack bars on top of one another, instead of other each other. 'expand' fills the available space
|
261
|
+
* @default false
|
262
|
+
*/
|
245
263
|
stacked?: boolean | 'expand';
|
246
264
|
}
|
247
265
|
|
@@ -451,16 +469,39 @@ declare interface ChartChildProps<TData extends object> {
|
|
451
469
|
}
|
452
470
|
|
453
471
|
declare interface ChartProps<TData extends object> {
|
472
|
+
/** Data to show in chart, should be an array of objects */
|
454
473
|
data: TData[];
|
474
|
+
/** Key in data to use for X Axis */
|
455
475
|
dataKey: keyof TData;
|
476
|
+
/** Show a legend below the chart, hidden by default
|
477
|
+
* @default false
|
478
|
+
*/
|
456
479
|
showLegend?: boolean;
|
480
|
+
/** Show the X Axis, shown by default
|
481
|
+
* @default true
|
482
|
+
*/
|
457
483
|
showXAxis?: boolean;
|
484
|
+
/** Show the Y Axis, shown by default
|
485
|
+
* @default false
|
486
|
+
*/
|
458
487
|
showYAxis?: boolean;
|
488
|
+
/** Add a title to the Tooltip show when hovering data */
|
459
489
|
tooltipTitle?: TooltipTitle;
|
490
|
+
/**
|
491
|
+
* @default auto
|
492
|
+
*/
|
460
493
|
xAxisScale?: ScaleType | Function;
|
494
|
+
/** Format the value shown for each tick on the X Axis */
|
461
495
|
xAxisTickFormatter?: TickFormatter;
|
496
|
+
/**
|
497
|
+
* @default auto
|
498
|
+
*/
|
462
499
|
yAxisScale?: ScaleType | Function;
|
500
|
+
/** Format the value shown for each tick on the Y Axis */
|
463
501
|
yAxisTickFormatter?: TickFormatter;
|
502
|
+
/** Adjust the width of the Y Axis to reduce whitespace
|
503
|
+
* @default 55
|
504
|
+
*/
|
464
505
|
yAxisWidth?: number;
|
465
506
|
}
|
466
507
|
|
@@ -1097,6 +1138,9 @@ export declare namespace DonutChart {
|
|
1097
1138
|
}
|
1098
1139
|
|
1099
1140
|
export declare interface DonutChartProps<TData extends object> extends Omit<PieChartProps<TData>, 'showLabels'> {
|
1141
|
+
/** Show total value in center of Donut
|
1142
|
+
* @default false
|
1143
|
+
*/
|
1100
1144
|
showTotal?: boolean;
|
1101
1145
|
}
|
1102
1146
|
|
@@ -1884,7 +1928,13 @@ export declare interface LineChartAreaProps<TData extends object> extends ChartC
|
|
1884
1928
|
}
|
1885
1929
|
|
1886
1930
|
export declare interface LineChartProps<TData extends object> extends ChartProps<TData>, default_2.ComponentProps<'div'> {
|
1931
|
+
/** Show dots for each data point
|
1932
|
+
* @default false
|
1933
|
+
*/
|
1887
1934
|
showDots?: boolean;
|
1935
|
+
/** Interpolation type of the line
|
1936
|
+
* @default natural
|
1937
|
+
*/
|
1888
1938
|
type?: CurveType;
|
1889
1939
|
}
|
1890
1940
|
|
@@ -2478,8 +2528,15 @@ export declare namespace PieChart {
|
|
2478
2528
|
}
|
2479
2529
|
|
2480
2530
|
export declare interface PieChartProps<TData extends object> extends Pick<ChartProps<TData>, 'showLegend' | 'tooltipTitle'>, default_2.ComponentProps<'div'> {
|
2531
|
+
/** Format the displayed value
|
2532
|
+
* @default Intl.NumberFormat
|
2533
|
+
*/
|
2481
2534
|
formatter?: ChartValueFormatter;
|
2535
|
+
/** Show labels inside each segment
|
2536
|
+
* @default false
|
2537
|
+
*/
|
2482
2538
|
showLabels?: boolean;
|
2539
|
+
/** Text representation of data, used in tooltips and totals */
|
2483
2540
|
unit?: string;
|
2484
2541
|
}
|
2485
2542
|
|
package/dist/taco.js
CHANGED
@@ -8017,7 +8017,7 @@ const defaultLocalisationTexts = {
|
|
8017
8017
|
}
|
8018
8018
|
};
|
8019
8019
|
const defaultLocalizationContext = {
|
8020
|
-
locale: "
|
8020
|
+
locale: "da-DK",
|
8021
8021
|
texts: defaultLocalisationTexts,
|
8022
8022
|
formatting: {
|
8023
8023
|
date: "dd.mm.yy"
|
@@ -82978,7 +82978,10 @@ function useChart(children, options) {
|
|
82978
82978
|
const [activeIndex, setActiveIndex] = React__default.useState();
|
82979
82979
|
const [hiddenItems, toggleItem] = useChartDataHiddenState();
|
82980
82980
|
const localization = useLocalization();
|
82981
|
-
const defaultFormatter2 = (value) => new Intl.NumberFormat(localization.locale).format(
|
82981
|
+
const defaultFormatter2 = (value) => new Intl.NumberFormat(localization.locale, { minimumFractionDigits: 2, trailingZeroDisplay: "stripIfInteger" }).format(
|
82982
|
+
value
|
82983
|
+
);
|
82984
|
+
const globalFormatter = (options == null ? void 0 : options.formatter) ?? defaultFormatter2;
|
82982
82985
|
const { items, shapes } = React__default.useMemo(() => {
|
82983
82986
|
const items2 = React__default.Children.toArray(children).filter((child) => React__default.isValidElement(child)).map((child) => {
|
82984
82987
|
const dataKey = child.props.dataKey ?? child.props.label;
|
@@ -82986,7 +82989,7 @@ function useChart(children, options) {
|
|
82986
82989
|
...child.props,
|
82987
82990
|
dataKey,
|
82988
82991
|
color: getThemeColor(child.props.color, "blue-300"),
|
82989
|
-
formatter: child.props.formatter ??
|
82992
|
+
formatter: child.props.formatter ?? globalFormatter,
|
82990
82993
|
isHidden: !!hiddenItems[dataKey],
|
82991
82994
|
unit: child.props.unit ?? (options == null ? void 0 : options.unit)
|
82992
82995
|
};
|
@@ -83013,7 +83016,7 @@ function useChart(children, options) {
|
|
83013
83016
|
});
|
83014
83017
|
return { items: items2, shapes: shapes2 };
|
83015
83018
|
}, [children, hiddenItems]);
|
83016
|
-
return { items, shapes, activeIndex, setActiveIndex, toggleItem };
|
83019
|
+
return { items, shapes, activeIndex, setActiveIndex, globalFormatter, toggleItem };
|
83017
83020
|
}
|
83018
83021
|
function useChartDataHiddenState() {
|
83019
83022
|
const [state, setState] = React__default.useState({});
|
@@ -83100,7 +83103,7 @@ function Area(_) {
|
|
83100
83103
|
AreaChart.Area = Area;
|
83101
83104
|
const BAR_WIDTH = 18;
|
83102
83105
|
function BarChart(props) {
|
83103
|
-
const isHorizontal = props.
|
83106
|
+
const isHorizontal = props.orientation === "horizontal";
|
83104
83107
|
const {
|
83105
83108
|
children,
|
83106
83109
|
className: customClassName,
|
@@ -83204,7 +83207,7 @@ BarChart.Bar = Bar;
|
|
83204
83207
|
const PIE_ACTIVE_WIDTH = 10;
|
83205
83208
|
const PIE_ACTIVE_WIDTH_OFFSET = 2;
|
83206
83209
|
function usePieChart(children, options) {
|
83207
|
-
const { items, shapes, activeIndex, setActiveIndex, toggleItem } = useChart(children, options);
|
83210
|
+
const { items, shapes, activeIndex, setActiveIndex, globalFormatter, toggleItem } = useChart(children, options);
|
83208
83211
|
const [radius, _setRadius] = React__default.useState(0);
|
83209
83212
|
function setRadius(width) {
|
83210
83213
|
_setRadius((width - 2 * (PIE_ACTIVE_WIDTH + PIE_ACTIVE_WIDTH_OFFSET)) / 2);
|
@@ -83225,7 +83228,7 @@ function usePieChart(children, options) {
|
|
83225
83228
|
labelLine: false,
|
83226
83229
|
outerRadius: radius
|
83227
83230
|
};
|
83228
|
-
return { pieProps, radius, setRadius, items, activeIndex, setActiveIndex, toggleItem, shapes };
|
83231
|
+
return { pieProps, radius, setRadius, items, activeIndex, setActiveIndex, globalFormatter, toggleItem, shapes };
|
83229
83232
|
}
|
83230
83233
|
const PIE_CHART_HOVER = 10;
|
83231
83234
|
const PIE_CHART_HOVER_OFFSET = 2;
|
@@ -83244,15 +83247,18 @@ function ActiveShape$1(props) {
|
|
83244
83247
|
const DONUT_WIDTH$1 = 20;
|
83245
83248
|
function DonutChart(props) {
|
83246
83249
|
const { children, formatter, showLegend = false, showTotal = false, tooltipTitle, unit: unit2, ...attributes } = props;
|
83247
|
-
const { pieProps, radius, setRadius, items, activeIndex, setActiveIndex, toggleItem } = usePieChart(
|
83248
|
-
|
83249
|
-
|
83250
|
-
|
83250
|
+
const { pieProps, radius, setRadius, items, activeIndex, setActiveIndex, globalFormatter, toggleItem } = usePieChart(
|
83251
|
+
children,
|
83252
|
+
{
|
83253
|
+
formatter,
|
83254
|
+
unit: unit2
|
83255
|
+
}
|
83256
|
+
);
|
83251
83257
|
const className = clsx("aspect-square", attributes.className);
|
83252
83258
|
return /* @__PURE__ */ React__default.createElement("div", { className: "relative", "data-taco": "chart-wrapper" }, /* @__PURE__ */ React__default.createElement(ChartWrapper, { ...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 }))), showTotal ? /* @__PURE__ */ React__default.createElement(
|
83253
83259
|
Total,
|
83254
83260
|
{
|
83255
|
-
formatter,
|
83261
|
+
formatter: globalFormatter,
|
83256
83262
|
items,
|
83257
83263
|
unit: unit2,
|
83258
83264
|
style: { top: radius + DONUT_WIDTH$1 / 2, width: radius + DONUT_WIDTH$1 * 2 }
|
@@ -83265,10 +83271,9 @@ function Segment$2(_) {
|
|
83265
83271
|
DonutChart.Segment = Segment$2;
|
83266
83272
|
function Total(props) {
|
83267
83273
|
const { formatter, items, unit: unit2, ...attributes } = props;
|
83268
|
-
const localization = useLocalization();
|
83269
83274
|
const total = React__default.useMemo(() => {
|
83270
83275
|
const total2 = items.filter((item) => !item.isHidden).reduce((acc, curr) => acc + curr.value, 0);
|
83271
|
-
return
|
83276
|
+
return formatter(total2);
|
83272
83277
|
}, [items]);
|
83273
83278
|
return /* @__PURE__ */ React__default.createElement(
|
83274
83279
|
"div",
|