@headless-adminapp/fluent 1.4.2 → 1.4.4

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AreaChart = AreaChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const react_1 = require("react");
7
8
  const recharts_1 = require("recharts");
8
9
  const CustomTooltipContent_1 = require("./CustomTooltipContent");
@@ -10,12 +11,13 @@ const formatters_1 = require("./formatters");
10
11
  const renderers_1 = require("./renderers");
11
12
  function AreaChart({ dataset, chartInfo, }) {
12
13
  const id = (0, react_1.useId)();
14
+ const locale = (0, locale_1.useLocale)();
13
15
  const xAxis = chartInfo.xAxis;
14
16
  const yAxis = chartInfo.yAxis;
15
17
  const areas = chartInfo.areas;
16
- const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(xAxis.tick);
17
- const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(yAxis.tick);
18
- return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.AreaChart, { data: dataset[0], children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderXAxis)(xAxis), (0, renderers_1.renderYAxis)(yAxis), (0, renderers_1.renderAreas)(areas, id), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
18
+ const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, xAxis.tick);
19
+ const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, yAxis.tick);
20
+ return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.AreaChart, { data: dataset[0], children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderXAxis)(locale, xAxis), (0, renderers_1.renderYAxis)(locale, yAxis), (0, renderers_1.renderAreas)(areas, id), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
19
21
  stroke: react_components_1.tokens.colorNeutralBackground6,
20
22
  opacity: 0.5,
21
23
  }, content: ({ active, payload, label }) => ((0, jsx_runtime_1.jsx)(CustomTooltipContent_1.CustomTooltipContent, { xAxisFormatter: xAxisFullFormatter, yAxisFormatter: yAxisFullFormatter, active: active, payload: payload, label: label })) })] }) }));
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BarChart = BarChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const recharts_1 = require("recharts");
7
8
  const CustomTooltipContent_1 = require("./CustomTooltipContent");
8
9
  const formatters_1 = require("./formatters");
9
10
  const renderers_1 = require("./renderers");
10
11
  function BarChart({ dataset, chartInfo, }) {
12
+ const locale = (0, locale_1.useLocale)();
11
13
  const xAxis = chartInfo.xAxis;
12
14
  const yAxis = chartInfo.yAxis;
13
15
  const bars = chartInfo.bars;
14
- const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(xAxis.tick);
15
- const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(yAxis.tick);
16
- return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.BarChart, { data: dataset[0], stackOffset: chartInfo.stackOffset, children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(yAxis), (0, renderers_1.renderXAxis)(xAxis), (0, renderers_1.renderBars)(bars, dataset), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
16
+ const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, xAxis.tick);
17
+ const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, yAxis.tick);
18
+ return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.BarChart, { data: dataset[0], stackOffset: chartInfo.stackOffset, children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(locale, yAxis), (0, renderers_1.renderXAxis)(locale, xAxis), (0, renderers_1.renderBars)(bars, dataset), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
17
19
  fill: react_components_1.tokens.colorNeutralBackground6,
18
20
  opacity: 0.2,
19
21
  }, content: ({ active, payload, label }) => ((0, jsx_runtime_1.jsx)(CustomTooltipContent_1.CustomTooltipContent, { xAxisFormatter: xAxisFullFormatter, yAxisFormatter: yAxisFullFormatter, active: active, payload: payload, label: label })) })] }) }));
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComposedChart = ComposedChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const react_1 = require("react");
7
8
  const recharts_1 = require("recharts");
8
9
  const CustomTooltipContent_1 = require("./CustomTooltipContent");
@@ -10,13 +11,32 @@ const formatters_1 = require("./formatters");
10
11
  const renderers_1 = require("./renderers");
11
12
  function ComposedChart({ dataset, chartInfo, }) {
12
13
  const id = (0, react_1.useId)();
14
+ const locale = (0, locale_1.useLocale)();
13
15
  const xAxis = chartInfo.xAxis;
14
16
  const yAxis = chartInfo.yAxis;
15
- const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(xAxis.tick);
16
- const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(yAxis.tick);
17
- return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.ComposedChart, { data: dataset[0], children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(yAxis), (0, renderers_1.renderXAxis)(xAxis, !!chartInfo.bars?.length), (0, renderers_1.renderLines)(chartInfo.lines ?? []), (0, renderers_1.renderAreas)(chartInfo.areas ?? [], id), (0, renderers_1.renderBars)(chartInfo.bars ?? [], dataset), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
17
+ const rightYAxis = chartInfo.rightYAxis;
18
+ const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, xAxis.tick);
19
+ const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, yAxis.tick);
20
+ const rightYAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, rightYAxis?.tick ?? yAxis.tick);
21
+ const yAxisIdMapping = (0, react_1.useMemo)(() => {
22
+ const mapping = {};
23
+ chartInfo.bars?.forEach((bar) => {
24
+ mapping[bar.dataKey] = bar.yAxisId ?? 'left';
25
+ });
26
+ chartInfo.areas?.forEach((area) => {
27
+ mapping[area.dataKey] = area.yAxisId ?? 'left';
28
+ });
29
+ chartInfo.lines?.forEach((line) => {
30
+ mapping[line.dataKey] = line.yAxisId ?? 'left';
31
+ });
32
+ return mapping;
33
+ }, [chartInfo]);
34
+ const yAxisIdResolver = (0, react_1.useCallback)((dataKey) => {
35
+ return yAxisIdMapping[dataKey] ?? 'left';
36
+ }, [yAxisIdMapping]);
37
+ return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.ComposedChart, { data: dataset[0], children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(locale, yAxis), !!rightYAxis && (0, renderers_1.renderYAxis)(locale, rightYAxis, 'right'), (0, renderers_1.renderXAxis)(locale, xAxis, !!chartInfo.bars?.length), (0, renderers_1.renderLines)(chartInfo.lines ?? []), (0, renderers_1.renderAreas)(chartInfo.areas ?? [], id), (0, renderers_1.renderBars)(chartInfo.bars ?? [], dataset), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
18
38
  stroke: react_components_1.tokens.colorNeutralBackground6,
19
39
  opacity: 0.5,
20
- }, content: ({ active, payload, label }) => ((0, jsx_runtime_1.jsx)(CustomTooltipContent_1.CustomTooltipContent, { xAxisFormatter: xAxisFullFormatter, yAxisFormatter: yAxisFullFormatter, active: active, payload: payload, label: label })) })] }) }));
40
+ }, content: ({ active, payload, label }) => ((0, jsx_runtime_1.jsx)(CustomTooltipContent_1.CustomTooltipContent, { xAxisFormatter: xAxisFullFormatter, yAxisFormatter: yAxisFullFormatter, yAxisIdResolver: yAxisIdResolver, rightYAxisFormatter: rightYAxisFullFormatter, active: active, payload: payload, label: label })) })] }) }));
21
41
  }
22
42
  exports.default = ComposedChart;
@@ -1,7 +1,9 @@
1
- export declare const CustomTooltipContent: ({ active, payload, label, xAxisFormatter, yAxisFormatter, }: {
1
+ export declare const CustomTooltipContent: ({ active, payload, label, xAxisFormatter, yAxisFormatter, rightYAxisFormatter, yAxisIdResolver, }: {
2
2
  active?: boolean;
3
3
  payload?: any[];
4
4
  label: string;
5
5
  xAxisFormatter: (value: unknown) => string;
6
6
  yAxisFormatter: (value: unknown) => string;
7
+ rightYAxisFormatter?: (value: unknown) => string;
8
+ yAxisIdResolver?: (dataKey: string) => "left" | "right";
7
9
  }) => import("react/jsx-runtime").JSX.Element | null;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomTooltipContent = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
- const CustomTooltipContent = ({ active, payload, label, xAxisFormatter, yAxisFormatter, }) => {
6
+ const CustomTooltipContent = ({ active, payload, label, xAxisFormatter, yAxisFormatter, rightYAxisFormatter, yAxisIdResolver, }) => {
7
7
  if (!active || !payload?.length) {
8
8
  return null;
9
9
  }
@@ -20,6 +20,8 @@ const CustomTooltipContent = ({ active, payload, label, xAxisFormatter, yAxisFor
20
20
  height: 8,
21
21
  background: item.color,
22
22
  borderRadius: 4,
23
- } }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4, marginLeft: 8 }, children: item.name }), (0, jsx_runtime_1.jsx)("div", { style: { flex: 1, minWidth: 50 } }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: yAxisFormatter(item.value) })] }, item.name + String(index)))) })] }));
23
+ } }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4, marginLeft: 8 }, children: item.name }), (0, jsx_runtime_1.jsx)("div", { style: { flex: 1, minWidth: 50 } }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: yAxisIdResolver?.(item.dataKey) === 'right'
24
+ ? (rightYAxisFormatter ?? yAxisFormatter)(item.value)
25
+ : yAxisFormatter(item.value) })] }, item.name + String(index)))) })] }));
24
26
  };
25
27
  exports.CustomTooltipContent = CustomTooltipContent;
@@ -3,21 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunnelChart = FunnelChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const react_1 = require("react");
7
8
  const recharts_1 = require("recharts");
8
9
  const constants_1 = require("./constants");
9
10
  const formatters_1 = require("./formatters");
10
11
  const FunnelCustomTooltipContent_1 = require("./FunnelCustomTooltipContent");
11
12
  function FunnelChart({ dataset, chartInfo, }) {
13
+ const locale = (0, locale_1.useLocale)();
12
14
  const item = chartInfo;
13
- const nameFormatter = (0, formatters_1.createLongAxisFormatter)({
15
+ const nameFormatter = (0, formatters_1.createLongAxisFormatter)(locale, {
14
16
  type: 'category',
15
17
  options: item.nameTick?.options,
16
18
  });
17
19
  const nameFormatterRef = (0, react_1.useRef)(nameFormatter);
18
20
  nameFormatterRef.current = nameFormatter;
19
21
  const data = dataset[0];
20
- const valueFormatter = (0, formatters_1.createLongAxisFormatter)(item.dataTick);
22
+ const valueFormatter = (0, formatters_1.createLongAxisFormatter)(locale, item.dataTick);
21
23
  const transformedData = (0, react_1.useMemo)(() => {
22
24
  if (!data?.length) {
23
25
  return [];
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunnelCustomTooltipContent = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const formatters_1 = require("./formatters");
7
8
  const FunnelCustomTooltipContent = ({ active, payload, valueFormatter, }) => {
9
+ const locale = (0, locale_1.useLocale)();
8
10
  if (!active || !payload?.length) {
9
11
  return null;
10
12
  }
@@ -22,6 +24,8 @@ const FunnelCustomTooltipContent = ({ active, payload, valueFormatter, }) => {
22
24
  height: 8,
23
25
  background: firstPayload.payload.fill,
24
26
  borderRadius: 4,
25
- } }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4, marginLeft: 8 }, children: valueFormatter(firstPayload.value) }), (0, jsx_runtime_1.jsx)("div", { style: { flex: 1, minWidth: 50 } }), (0, jsx_runtime_1.jsxs)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: [(0, formatters_1.formatNumber)(firstPayload.payload.perc * 100, { maxDigit: 2 }), "%"] })] }) })] }));
27
+ } }), (0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4, marginLeft: 8 }, children: valueFormatter(firstPayload.value) }), (0, jsx_runtime_1.jsx)("div", { style: { flex: 1, minWidth: 50 } }), (0, jsx_runtime_1.jsxs)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: [(0, formatters_1.formatNumber)(locale, firstPayload.payload.perc * 100, {
28
+ maxDigit: 2,
29
+ }), "%"] })] }) })] }));
26
30
  };
27
31
  exports.FunnelCustomTooltipContent = FunnelCustomTooltipContent;
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LineChart = LineChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const recharts_1 = require("recharts");
7
8
  const CustomTooltipContent_1 = require("./CustomTooltipContent");
8
9
  const formatters_1 = require("./formatters");
9
10
  const renderers_1 = require("./renderers");
10
11
  function LineChart({ dataset, chartInfo, }) {
12
+ const locale = (0, locale_1.useLocale)();
11
13
  const xAxis = chartInfo.xAxis;
12
14
  const yAxis = chartInfo.yAxis;
13
15
  const lines = chartInfo.lines;
14
- const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(xAxis.tick);
15
- const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(yAxis.tick);
16
- return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.LineChart, { data: dataset[0], children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(yAxis), (0, renderers_1.renderXAxis)(xAxis), (0, renderers_1.renderLines)(lines), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
16
+ const xAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, xAxis.tick);
17
+ const yAxisFullFormatter = (0, formatters_1.createLongAxisFormatter)(locale, yAxis.tick);
18
+ return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.LineChart, { data: dataset[0], children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(locale, yAxis), (0, renderers_1.renderXAxis)(locale, xAxis), (0, renderers_1.renderLines)(lines), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
17
19
  stroke: react_components_1.tokens.colorNeutralBackground6,
18
20
  opacity: 0.5,
19
21
  }, content: ({ active, payload, label }) => ((0, jsx_runtime_1.jsx)(CustomTooltipContent_1.CustomTooltipContent, { xAxisFormatter: xAxisFullFormatter, yAxisFormatter: yAxisFullFormatter, active: active, payload: payload, label: label })) })] }) }));
@@ -4,6 +4,7 @@ exports.barSizeInTime = void 0;
4
4
  exports.OhlcChart = OhlcChart;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_components_1 = require("@fluentui/react-components");
7
+ const locale_1 = require("@headless-adminapp/app/locale");
7
8
  const insights_1 = require("@headless-adminapp/core/experience/insights");
8
9
  const react_1 = require("react");
9
10
  const recharts_1 = require("recharts");
@@ -29,6 +30,7 @@ const barSizeInTime = (interval) => {
29
30
  };
30
31
  exports.barSizeInTime = barSizeInTime;
31
32
  function OhlcChart({ dataset, chartInfo, }) {
33
+ const locale = (0, locale_1.useLocale)();
32
34
  const bar = chartInfo.bars[0];
33
35
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
36
  const data = dataset[bar.dataIndex ?? 0];
@@ -43,10 +45,10 @@ function OhlcChart({ dataset, chartInfo, }) {
43
45
  return [dataMin, dataMax];
44
46
  }, [bar, chartInfo.yAxis.domain, data]);
45
47
  const xAxis = chartInfo.xAxis;
46
- const xAxisFormatter = (0, formatters_1.createAxisFormatter)(xAxis.tick);
47
- const xAxisLongFormatter = (0, formatters_1.createLongAxisFormatter)(chartInfo.xAxis.tick);
48
- const yAxisLongFormatter = (0, formatters_1.createLongAxisFormatter)(chartInfo.yAxis.tick);
49
- return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.ScatterChart, { data: data, children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)({
48
+ const xAxisFormatter = (0, formatters_1.createAxisFormatter)(locale, xAxis.tick);
49
+ const xAxisLongFormatter = (0, formatters_1.createLongAxisFormatter)(locale, chartInfo.xAxis.tick);
50
+ const yAxisLongFormatter = (0, formatters_1.createLongAxisFormatter)(locale, chartInfo.yAxis.tick);
51
+ return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.ScatterChart, { data: data, children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderYAxis)(locale, {
50
52
  ...chartInfo.yAxis,
51
53
  domain,
52
54
  }), (0, jsx_runtime_1.jsx)(recharts_1.XAxis, { dataKey: xAxis.dataKey, name: xAxis.name, tickFormatter: xAxisFormatter, tickLine: false, minTickGap: 10, padding: "gap", axisLine: {
@@ -4,10 +4,12 @@ exports.PieChart = PieChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
6
  const react_components_1 = require("@fluentui/react-components");
7
+ const locale_1 = require("@headless-adminapp/app/locale");
7
8
  const recharts_1 = require("recharts");
8
9
  const constants_1 = require("./constants");
9
10
  const formatters_1 = require("./formatters");
10
11
  function PieChart({ dataset, chartInfo, }) {
12
+ const locale = (0, locale_1.useLocale)();
11
13
  const RADIAN = Math.PI / 180;
12
14
  const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, }) => {
13
15
  const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
@@ -19,8 +21,8 @@ function PieChart({ dataset, chartInfo, }) {
19
21
  return ((0, jsx_runtime_1.jsx)("text", { x: x, y: y, fill: "white", textAnchor: x > cx ? 'start' : 'end', dominantBaseline: "central", fontSize: react_components_1.tokens.fontSizeBase100, children: `${(percent * 100).toFixed(0)}%` }));
20
22
  };
21
23
  const item = chartInfo.pie[0];
22
- const nameFormatter = (0, formatters_1.createLongAxisFormatter)(item.nameTick);
23
- const valueFormatter = (0, formatters_1.createLongAxisFormatter)(item.dataTick);
24
+ const nameFormatter = (0, formatters_1.createLongAxisFormatter)(locale, item.nameTick);
25
+ const valueFormatter = (0, formatters_1.createLongAxisFormatter)(locale, item.dataTick);
24
26
  return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.PieChart, { children: [(0, jsx_runtime_1.jsx)(recharts_1.Pie, { data: dataset[item.dataIndex ?? 0], cx: "50%", cy: "50%", labelLine: false, label: renderCustomizedLabel, outerRadius: 80, dataKey: item.dataKey, nameKey: item.nameKey, blendStroke: true, legendType: "circle", children: dataset[item.dataIndex ?? 0].map((entry, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Cell, { fill: item.colorKey && entry[item.colorKey]
25
27
  ? entry[item.colorKey]
26
28
  : (item.colors ?? constants_1.defaultColors)[index % (item.colors ?? constants_1.defaultColors).length] }, 'cell-' + String(index)))) }), chartInfo.showLegend && ((0, jsx_runtime_1.jsx)(recharts_1.Legend, { align: "right", layout: "vertical", verticalAlign: "top", wrapperStyle: {
@@ -4,14 +4,16 @@ exports.RadarChart = RadarChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
6
  const react_components_1 = require("@fluentui/react-components");
7
+ const locale_1 = require("@headless-adminapp/app/locale");
7
8
  const recharts_1 = require("recharts");
8
9
  const formatters_1 = require("./formatters");
9
10
  function RadarChart({ dataset, chartInfo, }) {
11
+ const locale = (0, locale_1.useLocale)();
10
12
  const data = dataset[0];
11
13
  const radar = chartInfo.radar[0];
12
- const nameFormatter = (0, formatters_1.createLongAxisFormatter)(radar.nameTick);
13
- const valueFormatter = (0, formatters_1.createLongAxisFormatter)(radar.dataTick);
14
- const tickFormatter = (0, formatters_1.createAxisFormatter)(radar.dataTick);
14
+ const nameFormatter = (0, formatters_1.createLongAxisFormatter)(locale, radar.nameTick);
15
+ const valueFormatter = (0, formatters_1.createLongAxisFormatter)(locale, radar.dataTick);
16
+ const tickFormatter = (0, formatters_1.createAxisFormatter)(locale, radar.dataTick);
15
17
  return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.RadarChart, { cx: "50%", cy: "50%", outerRadius: "80%", data: data, children: [(0, jsx_runtime_1.jsx)(recharts_1.PolarGrid, { stroke: react_components_1.tokens.colorNeutralBackground6, opacity: 0.5 }), (0, jsx_runtime_1.jsx)(recharts_1.PolarAngleAxis, { dataKey: radar.nameKey, fontSize: react_components_1.tokens.fontSizeBase100, tickFormatter: nameFormatter }), (0, jsx_runtime_1.jsx)(recharts_1.PolarRadiusAxis, { fontSize: react_components_1.tokens.fontSizeBase100, tickFormatter: tickFormatter }), (0, jsx_runtime_1.jsx)(recharts_1.Radar, { dataKey: radar.dataKey, stroke: radar.color ?? '#8884d8', fill: radar.color ?? '#8884d8', fillOpacity: 0.6 }), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: {
16
18
  stroke: react_components_1.tokens.colorNeutralBackground6,
17
19
  opacity: 0.5,
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ScatterChart = ScatterChart;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_components_1 = require("@fluentui/react-components");
6
+ const locale_1 = require("@headless-adminapp/app/locale");
6
7
  const react_1 = require("react");
7
8
  const recharts_1 = require("recharts");
8
9
  const constants_1 = require("./constants");
9
10
  const formatters_1 = require("./formatters");
10
11
  const renderers_1 = require("./renderers");
11
12
  function ScatterChart({ dataset, chartInfo, }) {
12
- return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.ScatterChart, { children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderXAxis)(chartInfo.xAxis, false, { left: 10, right: 10 }), (0, renderers_1.renderYAxis)(chartInfo.yAxis), (0, jsx_runtime_1.jsx)(recharts_1.ZAxis, { type: "number", dataKey: chartInfo.zAxis.dataKey, range: chartInfo.zAxis.range, name: chartInfo.zAxis.name }), chartInfo.scatters.map((scatter, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Scatter, { yAxisId: "left", name: scatter.dataLabel, data: dataset[scatter.dataIndex ?? 0], dataKey: scatter.dataKey, fill: scatter.color ?? constants_1.defaultColors[index] }, index))), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: false, content: (props) => {
13
+ const locale = (0, locale_1.useLocale)();
14
+ return ((0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: "100%", children: (0, jsx_runtime_1.jsxs)(recharts_1.ScatterChart, { children: [(0, renderers_1.renderGrid)(), (0, renderers_1.renderXAxis)(locale, chartInfo.xAxis, false, { left: 10, right: 10 }), (0, renderers_1.renderYAxis)(locale, chartInfo.yAxis), (0, jsx_runtime_1.jsx)(recharts_1.ZAxis, { type: "number", dataKey: chartInfo.zAxis.dataKey, range: chartInfo.zAxis.range, name: chartInfo.zAxis.name }), chartInfo.scatters.map((scatter, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Scatter, { yAxisId: "left", name: scatter.dataLabel, data: dataset[scatter.dataIndex ?? 0], dataKey: scatter.dataKey, fill: scatter.color ?? constants_1.defaultColors[index] }, index))), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { cursor: false, content: (props) => {
13
15
  if (!props.active || !props.payload?.length) {
14
16
  return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
15
17
  }
@@ -17,6 +19,7 @@ function ScatterChart({ dataset, chartInfo, }) {
17
19
  } })] }) }));
18
20
  }
19
21
  const ScatterTooltipContent = (props) => {
22
+ const locale = (0, locale_1.useLocale)();
20
23
  const chartInfo = props.chartInfo;
21
24
  const dataset = props.dataset;
22
25
  const xAxis = chartInfo.xAxis;
@@ -61,9 +64,9 @@ const ScatterTooltipContent = (props) => {
61
64
  yAxis.dataKey,
62
65
  zAxis.dataKey,
63
66
  ]);
64
- const xAxisFormatter = (0, formatters_1.createLongAxisFormatter)(xAxis.tick);
65
- const yAxisFormatter = (0, formatters_1.createLongAxisFormatter)(yAxis.tick);
66
- const zAxisFormatter = (0, formatters_1.createLongAxisFormatter)(zAxis.tick);
67
+ const xAxisFormatter = (0, formatters_1.createLongAxisFormatter)(locale, xAxis.tick);
68
+ const yAxisFormatter = (0, formatters_1.createLongAxisFormatter)(locale, yAxis.tick);
69
+ const zAxisFormatter = (0, formatters_1.createLongAxisFormatter)(locale, zAxis.tick);
67
70
  return ((0, jsx_runtime_1.jsx)("div", { style: {
68
71
  display: 'flex',
69
72
  flexDirection: 'column',
@@ -1,14 +1,15 @@
1
1
  import { AllAxisTick } from '@headless-adminapp/core/experience/insights';
2
+ import { Locale } from '@headless-adminapp/core/experience/locale';
2
3
  interface FormatNumberOptions {
3
4
  digit?: number;
4
5
  minDigit?: number;
5
6
  maxDigit?: number;
6
7
  }
7
- export declare const formatCurrencyWithSuffix: (input: number | undefined | null, digit?: number | FormatNumberOptions) => string;
8
+ export declare const formatCurrencyWithSuffix: (locale: Locale, input: number | undefined | null, digit?: number | FormatNumberOptions) => string;
8
9
  export declare const formatDate: (input: Date | string | number | undefined | null, format: string) => string;
9
- export declare const formatCurrency: (input: number | undefined | null, digit?: number | FormatNumberOptions) => string;
10
- export declare const formatNumber: (input: number | undefined | null, digit?: number | FormatNumberOptions) => string;
11
- export declare function createAxisFormatter(tick: AllAxisTick): (value: number) => string;
10
+ export declare const formatCurrency: (locale: Locale, input: number | undefined | null, digit?: number | FormatNumberOptions) => string;
11
+ export declare const formatNumber: (locale: Locale, input: number | undefined | null, digit?: number | FormatNumberOptions) => string;
12
+ export declare function createAxisFormatter(locale: Locale, tick: AllAxisTick): (value: number) => string;
12
13
  export type Formatter = (value: unknown) => string;
13
- export declare function createLongAxisFormatter(tick: AllAxisTick): Formatter;
14
+ export declare function createLongAxisFormatter(locale: Locale, tick: AllAxisTick): Formatter;
14
15
  export {};
@@ -28,7 +28,7 @@ function extractNumberInfo(value) {
28
28
  };
29
29
  }
30
30
  }
31
- const formatCurrencyWithSuffix = (input, digit = 2) => {
31
+ const formatCurrencyWithSuffix = (locale, input, digit = 2) => {
32
32
  const suffix = ['K', 'M', 'B', 'T'];
33
33
  if (input === null || input === undefined) {
34
34
  return '';
@@ -37,10 +37,11 @@ const formatCurrencyWithSuffix = (input, digit = 2) => {
37
37
  const sign = Math.sign(input);
38
38
  if (abs >= 1000) {
39
39
  const i = Math.floor(Math.log(abs) / Math.log(1000));
40
- return ((0, exports.formatCurrency)(sign * (abs / Math.pow(1000, i)), digit) + suffix[i - 1]);
40
+ return ((0, exports.formatCurrency)(locale, sign * (abs / Math.pow(1000, i)), digit) +
41
+ suffix[i - 1]);
41
42
  }
42
43
  else {
43
- return (0, exports.formatCurrency)(input, digit);
44
+ return (0, exports.formatCurrency)(locale, input, digit);
44
45
  }
45
46
  };
46
47
  exports.formatCurrencyWithSuffix = formatCurrencyWithSuffix;
@@ -51,28 +52,28 @@ const formatDate = (input, format) => {
51
52
  return (0, dayjs_1.default)(new Date(input)).format(format);
52
53
  };
53
54
  exports.formatDate = formatDate;
54
- const formatCurrency = (input, digit = 2) => {
55
+ const formatCurrency = (locale, input, digit = 2) => {
55
56
  if (input === null || input === undefined) {
56
57
  return '';
57
58
  }
58
59
  const minDigit = typeof digit === 'object' ? digit.minDigit ?? digit.digit : digit;
59
60
  const maxDigit = typeof digit === 'object' ? digit.maxDigit ?? digit.digit : digit;
60
- const formatter = new Intl.NumberFormat('en-IN', {
61
- currency: 'INR',
61
+ const formatter = new Intl.NumberFormat(locale.locale, {
62
62
  style: 'currency',
63
+ currency: locale.currency.currency,
63
64
  minimumFractionDigits: minDigit,
64
65
  maximumFractionDigits: maxDigit,
65
66
  });
66
67
  return formatter.format(input || 0);
67
68
  };
68
69
  exports.formatCurrency = formatCurrency;
69
- const formatNumber = (input, digit = 2) => {
70
+ const formatNumber = (locale, input, digit = 2) => {
70
71
  if (input === null || input === undefined) {
71
72
  return '';
72
73
  }
73
74
  const minDigit = typeof digit === 'object' ? digit.minDigit ?? digit.digit : digit;
74
75
  const maxDigit = typeof digit === 'object' ? digit.maxDigit ?? digit.digit : digit;
75
- const formatter = new Intl.NumberFormat('en-IN', {
76
+ const formatter = new Intl.NumberFormat(locale.locale, {
76
77
  minimumFractionDigits: minDigit,
77
78
  maximumFractionDigits: maxDigit,
78
79
  });
@@ -118,27 +119,27 @@ function createFullTimeAxisFormatter(format) {
118
119
  const formatString = timeLongAxisFormats[format];
119
120
  return (value) => (0, exports.formatDate)(new Date(value), formatString);
120
121
  }
121
- function createNumberAxisFormatter(options) {
122
+ function createNumberAxisFormatter(locale, options) {
122
123
  return (value) => {
123
124
  const info = extractNumberInfo(value);
124
125
  if (!info) {
125
126
  return '';
126
127
  }
127
- return (0, exports.formatNumber)(info.value, options) + info.symbol;
128
+ return (0, exports.formatNumber)(locale, info.value, options) + info.symbol;
128
129
  };
129
130
  }
130
- function createLongNumberAxisFormatter(options) {
131
+ function createLongNumberAxisFormatter(locale, options) {
131
132
  return (value) => {
132
- return (0, exports.formatNumber)(value, options);
133
+ return (0, exports.formatNumber)(locale, value, options);
133
134
  };
134
135
  }
135
- function createCurrencyAxisFormatter() {
136
+ function createCurrencyAxisFormatter(locale) {
136
137
  return (value) => {
137
138
  const info = extractNumberInfo(value);
138
139
  if (!info) {
139
140
  return '';
140
141
  }
141
- return (0, exports.formatCurrency)(info.value, 0) + info.symbol;
142
+ return (0, exports.formatCurrency)(locale, info.value, 0) + info.symbol;
142
143
  };
143
144
  }
144
145
  function createCategoryAxisFormatter(options) {
@@ -152,14 +153,14 @@ function createCategoryAxisFormatter(options) {
152
153
  return typeof value === 'string' ? value : String(value);
153
154
  };
154
155
  }
155
- function createAxisFormatter(tick) {
156
+ function createAxisFormatter(locale, tick) {
156
157
  switch (tick.type) {
157
158
  case 'time':
158
159
  return createTimeAxisFormatter(tick.format);
159
160
  case 'number':
160
- return createNumberAxisFormatter(tick);
161
+ return createNumberAxisFormatter(locale, tick);
161
162
  case 'currency':
162
- return createCurrencyAxisFormatter();
163
+ return createCurrencyAxisFormatter(locale);
163
164
  case 'category':
164
165
  return createCategoryAxisFormatter(tick.options);
165
166
  case 'weekday':
@@ -168,14 +169,14 @@ function createAxisFormatter(tick) {
168
169
  return (value) => String(value);
169
170
  }
170
171
  }
171
- function createLongAxisFormatter(tick) {
172
+ function createLongAxisFormatter(locale, tick) {
172
173
  switch (tick.type) {
173
174
  case 'time':
174
175
  return createFullTimeAxisFormatter(tick.format);
175
176
  case 'number':
176
- return createLongNumberAxisFormatter(tick);
177
+ return createLongNumberAxisFormatter(locale, tick);
177
178
  case 'currency':
178
- return createCurrencyAxisFormatter();
179
+ return createCurrencyAxisFormatter(locale);
179
180
  case 'category':
180
181
  return createCategoryAxisFormatter(tick.options);
181
182
  case 'weekday':
@@ -1,7 +1,8 @@
1
1
  import { AreaInfo, BarInfo, LineInfo, XAxis, YAxis } from '@headless-adminapp/core/experience/insights';
2
+ import { Locale } from '@headless-adminapp/core/experience/locale';
2
3
  import { XAxisProps } from 'recharts';
3
- export declare function renderXAxis(axis: XAxis, forceCategory?: boolean, padding?: XAxisProps['padding']): import("react/jsx-runtime").JSX.Element;
4
- export declare function renderYAxis(axis: YAxis): import("react/jsx-runtime").JSX.Element;
4
+ export declare function renderXAxis(locale: Locale, axis: XAxis, forceCategory?: boolean, padding?: XAxisProps['padding']): import("react/jsx-runtime").JSX.Element;
5
+ export declare function renderYAxis(locale: Locale, axis: YAxis, axisId?: 'left' | 'right'): import("react/jsx-runtime").JSX.Element;
5
6
  export declare function renderGrid(): import("react/jsx-runtime").JSX.Element;
6
7
  export declare function renderLine(line: LineInfo): import("react/jsx-runtime").JSX.Element;
7
8
  export declare function renderLines(lines: LineInfo[]): import("react/jsx-runtime").JSX.Element[];
@@ -14,8 +14,8 @@ const react_components_1 = require("@fluentui/react-components");
14
14
  const react_1 = require("react");
15
15
  const recharts_1 = require("recharts");
16
16
  const formatters_1 = require("./formatters");
17
- function renderXAxis(axis, forceCategory = false, padding = 'gap') {
18
- const xAxisFormatter = (0, formatters_1.createAxisFormatter)(axis.tick);
17
+ function renderXAxis(locale, axis, forceCategory = false, padding = 'gap') {
18
+ const xAxisFormatter = (0, formatters_1.createAxisFormatter)(locale, axis.tick);
19
19
  return ((0, jsx_runtime_1.jsx)(recharts_1.XAxis, { dataKey: axis.dataKey, name: axis.name, tickFormatter: xAxisFormatter, tickLine: false, minTickGap: 10,
20
20
  // padding={{ left: 10, right: 10 }}
21
21
  padding: padding, axisLine: {
@@ -25,9 +25,9 @@ function renderXAxis(axis, forceCategory = false, padding = 'gap') {
25
25
  opacity: 0.5,
26
26
  }, scale: !forceCategory && axis.tick.type === 'time' ? 'time' : 'auto', type: forceCategory || axis.tick.type === 'category' ? 'category' : 'number', domain: axis.domain, height: 16 }));
27
27
  }
28
- function renderYAxis(axis) {
29
- const yAxisFormatter = (0, formatters_1.createAxisFormatter)(axis.tick);
30
- return ((0, jsx_runtime_1.jsx)(recharts_1.YAxis, { yAxisId: "left", dataKey: axis.dataKey, tickFormatter: yAxisFormatter, name: axis.name, tickLine: false, fontSize: react_components_1.tokens.fontSizeBase100, axisLine: false, tickMargin: 0, minTickGap: 0, accentHeight: 0, width: 40, scale: "auto", type: "number", domain: axis.domain, tick: {
28
+ function renderYAxis(locale, axis, axisId = 'left') {
29
+ const yAxisFormatter = (0, formatters_1.createAxisFormatter)(locale, axis.tick);
30
+ return ((0, jsx_runtime_1.jsx)(recharts_1.YAxis, { yAxisId: axisId, dataKey: axis.dataKey, orientation: axisId === 'right' ? 'right' : 'left', tickFormatter: yAxisFormatter, name: axis.name, tickLine: false, fontSize: react_components_1.tokens.fontSizeBase100, axisLine: false, tickMargin: 0, minTickGap: 0, accentHeight: 0, width: 40, scale: "auto", type: "number", domain: axis.domain, tick: {
31
31
  fill: react_components_1.tokens.colorNeutralForeground1,
32
32
  opacity: 0.5,
33
33
  } }));
@@ -37,7 +37,7 @@ function renderGrid() {
37
37
  }
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
39
  function renderLine(line) {
40
- return ((0, jsx_runtime_1.jsx)(recharts_1.Line, { yAxisId: 'left', type: line.curveType, dataKey: line.dataKey, name: line.dataLabel, stroke: line.color, strokeWidth: 2, dot: false, activeDot: {
40
+ return ((0, jsx_runtime_1.jsx)(recharts_1.Line, { yAxisId: line.yAxisId ?? 'left', type: line.curveType, dataKey: line.dataKey, name: line.dataLabel, stroke: line.color, strokeWidth: 2, dot: false, activeDot: {
41
41
  stroke: line.color,
42
42
  } }, line.dataKey));
43
43
  }
@@ -47,7 +47,7 @@ function renderLines(lines) {
47
47
  }
48
48
  // eslint-disable-next-line unused-imports/no-unused-vars
49
49
  function renderArea(area, chartId) {
50
- return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsxs)("linearGradient", { id: chartId + ':' + area.dataKey, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)("stop", { offset: "5%", stopColor: area.color, stopOpacity: 0.8 }), (0, jsx_runtime_1.jsx)("stop", { offset: "95%", stopColor: area.color, stopOpacity: 0 })] }) }), (0, jsx_runtime_1.jsx)(recharts_1.Area, { yAxisId: 'left', type: area.curveType, dataKey: area.dataKey, name: area.dataLabel, stroke: area.color,
50
+ return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsxs)("linearGradient", { id: chartId + ':' + area.dataKey, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)("stop", { offset: "5%", stopColor: area.color, stopOpacity: 0.8 }), (0, jsx_runtime_1.jsx)("stop", { offset: "95%", stopColor: area.color, stopOpacity: 0 })] }) }), (0, jsx_runtime_1.jsx)(recharts_1.Area, { yAxisId: area.yAxisId ?? 'left', type: area.curveType, dataKey: area.dataKey, name: area.dataLabel, stroke: area.color,
51
51
  // fill={area.color}
52
52
  fill: `url(#${chartId}:${area.dataKey})`, strokeWidth: 2, dot: false, activeDot: {
53
53
  stroke: area.color,
@@ -59,7 +59,7 @@ function renderAreas(areas, chartId) {
59
59
  }
60
60
  // eslint-disable-next-line unused-imports/no-unused-vars
61
61
  function renderBar(bar, dataset) {
62
- return ((0, jsx_runtime_1.jsx)(recharts_1.Bar, { yAxisId: 'left', type: bar.curveType, dataKey: bar.dataKey, name: bar.dataLabel, stroke: bar.color, fill: bar.color, strokeWidth: 1, stackId: bar.stackId, radius: bar.radius, barSize: bar.barSize }, bar.dataKey));
62
+ return ((0, jsx_runtime_1.jsx)(recharts_1.Bar, { yAxisId: bar.yAxisId ?? 'left', type: bar.curveType, dataKey: bar.dataKey, name: bar.dataLabel, stroke: bar.color, fill: bar.color, strokeWidth: 1, stackId: bar.stackId, radius: bar.radius, barSize: bar.barSize }, bar.dataKey));
63
63
  }
64
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
65
  function renderBars(bars, dataset) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/fluent",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -52,5 +52,5 @@
52
52
  "uuid": "11.0.3",
53
53
  "yup": "^1.4.0"
54
54
  },
55
- "gitHead": "150c2a6eee123cdb3cb42b1f42f1b4bea8db2756"
55
+ "gitHead": "ca80572e64d16eafd78c1e511c0f15b563af51e5"
56
56
  }