@apia/charts 1.0.4 → 2.0.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/charts/ChartContext.js +6 -0
- package/dist/charts/ChartContext.js.map +1 -0
- package/dist/charts/ChartRenderer.d.ts +17 -0
- package/dist/charts/ChartRenderer.d.ts.map +1 -0
- package/dist/charts/ChartRenderer.js +175 -0
- package/dist/charts/ChartRenderer.js.map +1 -0
- package/dist/charts/horizontalBars/Bar.js +226 -0
- package/dist/charts/horizontalBars/Bar.js.map +1 -0
- package/dist/charts/horizontalBars/HorizontalBars.js +374 -0
- package/dist/charts/horizontalBars/HorizontalBars.js.map +1 -0
- package/dist/charts/linear/LineChart.js +528 -0
- package/dist/charts/linear/LineChart.js.map +1 -0
- package/dist/charts/linear/Node.js +56 -0
- package/dist/charts/linear/Node.js.map +1 -0
- package/dist/charts/pie/Pie.js +184 -0
- package/dist/charts/pie/Pie.js.map +1 -0
- package/dist/charts/pie/Slice.js +96 -0
- package/dist/charts/pie/Slice.js.map +1 -0
- package/dist/charts/pie/usePieAnimation.js +123 -0
- package/dist/charts/pie/usePieAnimation.js.map +1 -0
- package/dist/charts/types.d.ts +188 -0
- package/dist/charts/types.d.ts.map +1 -0
- package/dist/charts/util/ChartSelector.js +36 -0
- package/dist/charts/util/ChartSelector.js.map +1 -0
- package/dist/charts/util/ColoredLegendItem.js +46 -0
- package/dist/charts/util/ColoredLegendItem.js.map +1 -0
- package/dist/charts/util/EmptyGrid.d.ts +8 -0
- package/dist/charts/util/EmptyGrid.d.ts.map +1 -0
- package/dist/charts/util/EmptyGrid.js +51 -0
- package/dist/charts/util/EmptyGrid.js.map +1 -0
- package/dist/charts/util/LegendContainer.js +53 -0
- package/dist/charts/util/LegendContainer.js.map +1 -0
- package/dist/charts/util/NumberedLegendItem.js +45 -0
- package/dist/charts/util/NumberedLegendItem.js.map +1 -0
- package/dist/charts/util/getBarColor.js +29 -0
- package/dist/charts/util/getBarColor.js.map +1 -0
- package/dist/charts/util/parseMargin.js +11 -0
- package/dist/charts/util/parseMargin.js.map +1 -0
- package/dist/charts/util/useChartStyles.js +35 -0
- package/dist/charts/util/useChartStyles.js.map +1 -0
- package/dist/charts/verticalBars/Bar.js +239 -0
- package/dist/charts/verticalBars/Bar.js.map +1 -0
- package/dist/charts/verticalBars/VerticalBars.js +394 -0
- package/dist/charts/verticalBars/VerticalBars.js.map +1 -0
- package/dist/charts/waterfallBars/WaterfallBar.js +84 -0
- package/dist/charts/waterfallBars/WaterfallBar.js.map +1 -0
- package/dist/charts/waterfallBars/WaterfallBars.js +289 -0
- package/dist/charts/waterfallBars/WaterfallBars.js.map +1 -0
- package/dist/index.d.ts +6 -250
- package/dist/index.js +4 -4263
- package/dist/index.js.map +1 -1
- package/dist/widgets/WidgetContainer.d.ts +10 -0
- package/dist/widgets/WidgetContainer.d.ts.map +1 -0
- package/dist/widgets/WidgetContainer.js +68 -0
- package/dist/widgets/WidgetContainer.js.map +1 -0
- package/dist/widgets/counter/Counter.js +108 -0
- package/dist/widgets/counter/Counter.js.map +1 -0
- package/dist/widgets/custom/useCustomWidget.js +64 -0
- package/dist/widgets/custom/useCustomWidget.js.map +1 -0
- package/dist/widgets/custom/util.js +9 -0
- package/dist/widgets/custom/util.js.map +1 -0
- package/dist/widgets/oxford/Oxford.js +241 -0
- package/dist/widgets/oxford/Oxford.js.map +1 -0
- package/dist/widgets/ring/Ring.js +123 -0
- package/dist/widgets/ring/Ring.js.map +1 -0
- package/dist/widgets/scale/Scale.js +145 -0
- package/dist/widgets/scale/Scale.js.map +1 -0
- package/dist/widgets/speedMeter/SpeedMeter.js +187 -0
- package/dist/widgets/speedMeter/SpeedMeter.js.map +1 -0
- package/dist/widgets/tLight/TLight.js +134 -0
- package/dist/widgets/tLight/TLight.js.map +1 -0
- package/dist/widgets/thermometer/Thermometer.js +144 -0
- package/dist/widgets/thermometer/Thermometer.js.map +1 -0
- package/dist/widgets/thermometer/util.js +31 -0
- package/dist/widgets/thermometer/util.js.map +1 -0
- package/dist/widgets/types.d.ts +41 -0
- package/dist/widgets/types.d.ts.map +1 -0
- package/package.json +30 -43
- package/LICENSE.md +0 -21
- package/README.md +0 -1
- package/cleanDist.json +0 -3
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from '@apia/theme/jsx-runtime';
|
|
2
|
+
import tinycolor from 'tinycolor2';
|
|
3
|
+
import { Box } from '@apia/theme';
|
|
4
|
+
import { localPoint } from '@visx/event';
|
|
5
|
+
import { arrayOrArray, useImperativeComponentEvents } from '@apia/util';
|
|
6
|
+
import { legendContainerMethods } from '../util/LegendContainer.js';
|
|
7
|
+
import { useState, useRef, useContext, useMemo } from 'react';
|
|
8
|
+
import { ChartContext } from '../ChartContext.js';
|
|
9
|
+
import { chartMethods } from '../ChartRenderer.js';
|
|
10
|
+
import { ApiaUtil } from '@apia/components';
|
|
11
|
+
|
|
12
|
+
const Bar = ({
|
|
13
|
+
bar,
|
|
14
|
+
barGroup,
|
|
15
|
+
chart,
|
|
16
|
+
parsedData,
|
|
17
|
+
isSingle,
|
|
18
|
+
setsWithColor
|
|
19
|
+
}) => {
|
|
20
|
+
const column = arrayOrArray(chart.dataSets.data)[bar.index];
|
|
21
|
+
const set = arrayOrArray(column?.sets)[barGroup.index];
|
|
22
|
+
const currentBarColor = setsWithColor.find(
|
|
23
|
+
(innerSet) => innerSet.columnName === column.name && innerSet.key === set.key
|
|
24
|
+
)?.color;
|
|
25
|
+
const [isHighlighted, setIsHighlighted] = useState(false);
|
|
26
|
+
const [isAnyHighlighted, setIsAnyHighlighted] = useState(false);
|
|
27
|
+
const ref = useRef(null);
|
|
28
|
+
useImperativeComponentEvents({
|
|
29
|
+
highlight(barNameColumn) {
|
|
30
|
+
let barName = barNameColumn;
|
|
31
|
+
let columnName = "";
|
|
32
|
+
if (barNameColumn.includes("_$_")) {
|
|
33
|
+
barName = barNameColumn.split("_$_")[0];
|
|
34
|
+
columnName = barNameColumn.split("_$_")[1];
|
|
35
|
+
if (isSingle && barNameColumn !== "" && barNameColumn !== void 0) {
|
|
36
|
+
barName = barNameColumn.split("_$_")[1];
|
|
37
|
+
columnName = barNameColumn.split("_$_")[1];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (barName.split(" - ").length === 1) {
|
|
41
|
+
if (arrayOrArray(chart.dataSets.data).length === 1) {
|
|
42
|
+
setIsHighlighted(barName === parsedData[barGroup.index].columnName);
|
|
43
|
+
setIsAnyHighlighted(
|
|
44
|
+
barName !== parsedData[barGroup.index].columnName && barName !== ""
|
|
45
|
+
);
|
|
46
|
+
if (barName === parsedData[barGroup.index].columnName || columnName === parsedData[barGroup.index].columnName) {
|
|
47
|
+
if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {
|
|
48
|
+
ApiaUtil.instance.tooltips.open({
|
|
49
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
/* @__PURE__ */ jsx(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
style: {
|
|
54
|
+
color: currentBarColor
|
|
55
|
+
},
|
|
56
|
+
children: /* @__PURE__ */ jsx("strong", { children: chart.showAxisXTitle ? parsedData[barGroup.index].columnName : chart.showLegend ? bar.key : "" })
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: bar.value }),
|
|
60
|
+
/* @__PURE__ */ jsx("div", { children: chart.showAxisXTitle && chart.showLegend ? bar.key : "" })
|
|
61
|
+
] }),
|
|
62
|
+
attachToElement: () => ref.current,
|
|
63
|
+
attachToElementAnchorPoint: "center"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
setIsHighlighted(barName === bar.key);
|
|
69
|
+
setIsAnyHighlighted(barName !== bar.key && barName !== "");
|
|
70
|
+
const currentBar = document.querySelector(
|
|
71
|
+
`.${parsedData[barGroup.index].columnName}__${bar.key}`
|
|
72
|
+
);
|
|
73
|
+
if (barName === bar.key && columnName === parsedData[barGroup.index].columnName) {
|
|
74
|
+
if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {
|
|
75
|
+
ApiaUtil.instance.tooltips.open({
|
|
76
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
"div",
|
|
79
|
+
{
|
|
80
|
+
style: {
|
|
81
|
+
color: currentBarColor
|
|
82
|
+
},
|
|
83
|
+
children: /* @__PURE__ */ jsx("strong", { children: chart.showAxisXTitle ? parsedData[barGroup.index].columnName : chart.showLegend ? bar.key : "" })
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: bar.value }),
|
|
87
|
+
/* @__PURE__ */ jsx("div", { children: chart.showAxisXTitle && chart.showLegend ? bar.key : "" })
|
|
88
|
+
] }),
|
|
89
|
+
attachToElement: () => ref.current,
|
|
90
|
+
attachToElementAnchorPoint: "center"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
} else if (barName === bar.key && currentBar && columnName === "") {
|
|
94
|
+
if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {
|
|
95
|
+
ApiaUtil.instance.tooltips.open({
|
|
96
|
+
children: parsedData.map((dat, i) => {
|
|
97
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
98
|
+
/* @__PURE__ */ jsx(
|
|
99
|
+
"div",
|
|
100
|
+
{
|
|
101
|
+
style: {
|
|
102
|
+
color: currentBarColor
|
|
103
|
+
},
|
|
104
|
+
children: /* @__PURE__ */ jsx("strong", { children: chart.showAxisXTitle ? dat.columnName : chart.showLegend ? Object.keys(dat).find(
|
|
105
|
+
(key) => dat[key] === dat[barName]
|
|
106
|
+
) : "" })
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: dat[barName] }),
|
|
110
|
+
/* @__PURE__ */ jsx("div", {}),
|
|
111
|
+
parsedData[i + 1] && /* @__PURE__ */ jsx("hr", {})
|
|
112
|
+
] }, `${dat.columnName}_${dat[barName]}`);
|
|
113
|
+
}),
|
|
114
|
+
attachToMousePosition: true
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} else if (barName.split(" - ").length === 2) {
|
|
120
|
+
setIsHighlighted(
|
|
121
|
+
barName.split(" - ")[0] === bar.key && barName.split(" - ")[1] === set.key
|
|
122
|
+
);
|
|
123
|
+
setIsAnyHighlighted(
|
|
124
|
+
barName.split(" - ")[0] !== bar.key && barName.split(" - ")[0] !== ""
|
|
125
|
+
);
|
|
126
|
+
if (barName.split(" - ")[0] === bar.key && barName.split(" - ")[1] === set.key && columnName === parsedData[barGroup.index].columnName) {
|
|
127
|
+
if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {
|
|
128
|
+
ApiaUtil.instance.tooltips.open({
|
|
129
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
"div",
|
|
132
|
+
{
|
|
133
|
+
style: {
|
|
134
|
+
color: currentBarColor
|
|
135
|
+
},
|
|
136
|
+
children: /* @__PURE__ */ jsx("strong", { children: chart.showAxisXTitle ? parsedData[barGroup.index].columnName : chart.showLegend ? bar.key : "" })
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
chart.showValues && /* @__PURE__ */ jsx("div", { children: bar.value }),
|
|
140
|
+
/* @__PURE__ */ jsx("div", { children: chart.showAxisXTitle && chart.showLegend ? bar.key : "" })
|
|
141
|
+
] }),
|
|
142
|
+
attachToElement: () => ref.current,
|
|
143
|
+
attachToElementAnchorPoint: "center"
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const { chartId } = useContext(ChartContext);
|
|
151
|
+
return /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsxs(
|
|
152
|
+
Box,
|
|
153
|
+
{
|
|
154
|
+
as: "rect",
|
|
155
|
+
className: `chart__barRect ${parsedData[barGroup.index].columnName}__${bar.key}`,
|
|
156
|
+
ref,
|
|
157
|
+
sx: useMemo(
|
|
158
|
+
() => ({
|
|
159
|
+
fill: isAnyHighlighted ? `#${tinycolor(currentBarColor).desaturate(70).toHex()}` : currentBarColor,
|
|
160
|
+
"&:hover": {
|
|
161
|
+
fill: `#${tinycolor(currentBarColor).saturate(25).toHex()}`
|
|
162
|
+
},
|
|
163
|
+
transition: "fill 500ms, opacity 500ms",
|
|
164
|
+
x: bar.x,
|
|
165
|
+
y: bar.y,
|
|
166
|
+
width: bar.width,
|
|
167
|
+
opacity: isAnyHighlighted && !isHighlighted ? 0.15 : 1,
|
|
168
|
+
height: bar.height > 0 ? bar.height : 0
|
|
169
|
+
}),
|
|
170
|
+
[
|
|
171
|
+
bar.height,
|
|
172
|
+
bar.width,
|
|
173
|
+
bar.x,
|
|
174
|
+
bar.y,
|
|
175
|
+
currentBarColor,
|
|
176
|
+
isAnyHighlighted,
|
|
177
|
+
isHighlighted
|
|
178
|
+
]
|
|
179
|
+
),
|
|
180
|
+
onMouseEnter: (ev) => {
|
|
181
|
+
console.log(bar.key, parsedData[barGroup.index].columnName);
|
|
182
|
+
if (!isSingle) {
|
|
183
|
+
legendContainerMethods.highlight(chartId, bar.key);
|
|
184
|
+
} else {
|
|
185
|
+
legendContainerMethods.highlight(
|
|
186
|
+
chartId,
|
|
187
|
+
parsedData[barGroup.index].columnName
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
chartMethods(
|
|
191
|
+
chartId,
|
|
192
|
+
"highlight",
|
|
193
|
+
`${bar.key}_$_${parsedData[barGroup.index].columnName}`
|
|
194
|
+
);
|
|
195
|
+
ev.target.classList?.add("over");
|
|
196
|
+
const point = {
|
|
197
|
+
x: localPoint(ev)?.x,
|
|
198
|
+
y: localPoint(ev)?.y
|
|
199
|
+
};
|
|
200
|
+
if (!point || !chart.showValues)
|
|
201
|
+
return;
|
|
202
|
+
},
|
|
203
|
+
onMouseLeave: (ev) => {
|
|
204
|
+
legendContainerMethods.highlight(chartId, "");
|
|
205
|
+
chartMethods(chartId, "highlight", "");
|
|
206
|
+
ev.target.classList?.remove("over");
|
|
207
|
+
},
|
|
208
|
+
children: [
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
"animate",
|
|
211
|
+
{
|
|
212
|
+
attributeName: "height",
|
|
213
|
+
from: 0,
|
|
214
|
+
to: bar.height,
|
|
215
|
+
dur: "0.5s",
|
|
216
|
+
calcMode: "paced",
|
|
217
|
+
keySplines: "0.5 0 0.5 1;",
|
|
218
|
+
keyTimes: "0; 1"
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ jsx(
|
|
222
|
+
"animate",
|
|
223
|
+
{
|
|
224
|
+
attributeName: "y",
|
|
225
|
+
from: bar.y + bar.height,
|
|
226
|
+
to: bar.y,
|
|
227
|
+
dur: "0.5s",
|
|
228
|
+
calcMode: "paced",
|
|
229
|
+
keySplines: "0.5 0 0.5 1;",
|
|
230
|
+
keyTimes: "0; 1"
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
) });
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export { Bar };
|
|
239
|
+
//# sourceMappingURL=Bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bar.js","sources":["../../../src/charts/verticalBars/Bar.tsx"],"sourcesContent":["import tinycolor from 'tinycolor2';\nimport { BarGroup, BarGroupBar } from '@visx/shape/lib/types';\nimport { TApiaChartColorDisposition, TChartRendererProps } from '../types';\nimport { Box } from '@apia/theme';\nimport { localPoint } from '@visx/event';\nimport { IParsedColumn } from './VerticalBars';\nimport { arrayOrArray, useImperativeComponentEvents } from '@apia/util';\nimport { legendContainerMethods } from '../util/LegendContainer';\nimport { useContext, useState, useMemo, useRef } from 'react';\nimport { ChartContext } from '../ChartContext';\nimport { TChartEvents, chartMethods } from '../ChartRenderer';\nimport { ApiaUtil } from '@apia/components';\n\nexport const Bar = ({\n bar,\n barGroup,\n chart,\n parsedData,\n isSingle,\n setsWithColor,\n}: Pick<TChartRendererProps, 'chart'> & {\n isSingle: boolean;\n bar: BarGroupBar<string>;\n barGroup: BarGroup<string>;\n parsedData: IParsedColumn[];\n setsWithColor: TApiaChartColorDisposition[];\n}) => {\n const column = arrayOrArray(chart.dataSets.data)[bar.index];\n const set = arrayOrArray(column?.sets)[barGroup.index];\n const currentBarColor = setsWithColor.find(\n (innerSet) =>\n innerSet.columnName === column.name && innerSet.key === set.key,\n )?.color;\n const [isHighlighted, setIsHighlighted] = useState(false);\n const [isAnyHighlighted, setIsAnyHighlighted] = useState(false);\n const ref = useRef<SVGPathElement | null>(null);\n useImperativeComponentEvents<TChartEvents>({\n highlight(barNameColumn) {\n let barName = barNameColumn;\n let columnName = '';\n if (barNameColumn.includes('_$_')) {\n barName = barNameColumn.split('_$_')[0];\n columnName = barNameColumn.split('_$_')[1];\n if (isSingle && barNameColumn !== '' && barNameColumn !== undefined) {\n barName = barNameColumn.split('_$_')[1];\n columnName = barNameColumn.split('_$_')[1];\n }\n }\n if (barName.split(' - ').length === 1) {\n if (arrayOrArray(chart.dataSets.data).length === 1) {\n setIsHighlighted(barName === parsedData[barGroup.index].columnName);\n setIsAnyHighlighted(\n barName !== parsedData[barGroup.index].columnName && barName !== '',\n );\n if (\n barName === parsedData[barGroup.index].columnName ||\n columnName === parsedData[barGroup.index].columnName\n ) {\n if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {\n ApiaUtil.instance.tooltips.open({\n children: (\n <>\n <div\n style={{\n color: currentBarColor,\n }}\n >\n <strong>\n {chart.showAxisXTitle\n ? parsedData[barGroup.index].columnName\n : chart.showLegend\n ? bar.key\n : ''}\n </strong>\n </div>\n {chart.showValues && <div>{bar.value}</div>}\n <div>\n {chart.showAxisXTitle && chart.showLegend ? bar.key : ''}\n </div>\n </>\n ),\n attachToElement: () => ref.current as unknown as HTMLElement,\n attachToElementAnchorPoint: 'center',\n });\n }\n }\n } else {\n setIsHighlighted(barName === bar.key);\n setIsAnyHighlighted(barName !== bar.key && barName !== '');\n const currentBar = document.querySelector(\n `.${parsedData[barGroup.index].columnName}__${bar.key}`,\n );\n if (\n barName === bar.key &&\n columnName === parsedData[barGroup.index].columnName\n ) {\n if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {\n ApiaUtil.instance.tooltips.open({\n children: (\n <>\n <div\n style={{\n color: currentBarColor,\n }}\n >\n <strong>\n {chart.showAxisXTitle\n ? parsedData[barGroup.index].columnName\n : chart.showLegend\n ? bar.key\n : ''}\n </strong>\n </div>\n {chart.showValues && <div>{bar.value}</div>}\n <div>\n {chart.showAxisXTitle && chart.showLegend ? bar.key : ''}\n </div>\n </>\n ),\n attachToElement: () => ref.current as unknown as HTMLElement,\n attachToElementAnchorPoint: 'center',\n });\n }\n } else if (barName === bar.key && currentBar && columnName === '') {\n if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {\n ApiaUtil.instance.tooltips.open({\n children: parsedData.map((dat, i) => {\n return (\n <div key={`${dat.columnName}_${dat[barName]}`}>\n <div\n style={{\n color: currentBarColor,\n }}\n >\n <strong>\n {chart.showAxisXTitle\n ? dat.columnName\n : chart.showLegend\n ? Object.keys(dat).find(\n (key) => dat[key] === dat[barName],\n )\n : ''}\n </strong>\n </div>\n {chart.showValues && <div>{dat[barName]}</div>}\n <div>\n {/*{chart.showAxisXTitle && chart.showLegend\n ? Object.keys(dat).find(\n (key) => dat[key] === dat[barName],\n )\n : ''}*/}\n </div>\n {parsedData[i + 1] && <hr />}\n </div>\n );\n }),\n attachToMousePosition: true,\n });\n }\n }\n }\n } else if (barName.split(' - ').length === 2) {\n setIsHighlighted(\n barName.split(' - ')[0] === bar.key &&\n barName.split(' - ')[1] === set.key,\n );\n setIsAnyHighlighted(\n barName.split(' - ')[0] !== bar.key && barName.split(' - ')[0] !== '',\n );\n if (\n barName.split(' - ')[0] === bar.key &&\n barName.split(' - ')[1] === set.key &&\n columnName === parsedData[barGroup.index].columnName\n ) {\n if (chart.showAxisXTitle || chart.showLegend || chart.showValues) {\n ApiaUtil.instance.tooltips.open({\n children: (\n <>\n <div\n style={{\n color: currentBarColor,\n }}\n >\n <strong>\n {chart.showAxisXTitle\n ? parsedData[barGroup.index].columnName\n : chart.showLegend\n ? bar.key\n : ''}\n </strong>\n </div>\n {chart.showValues && <div>{bar.value}</div>}\n <div>\n {chart.showAxisXTitle && chart.showLegend ? bar.key : ''}\n </div>\n </>\n ),\n attachToElement: () => ref.current as unknown as HTMLElement,\n attachToElementAnchorPoint: 'center',\n });\n }\n }\n }\n },\n });\n const { chartId } = useContext(ChartContext);\n\n return (\n <g>\n {/* {chart.showValues && (\n <text\n x={bar.x + bar.width / 2}\n y={bar.y - 5}\n width={bar.width}\n height={bar.height}\n textAnchor=\"middle\"\n style={{\n display: isHighlighted ? 'block' : 'none',\n opacity: isHighlighted ? 1 : 0,\n transition: 'opacity 500ms',\n }}\n >\n {bar.value}\n </text>\n )} */}\n\n <Box\n as=\"rect\"\n className={`chart__barRect ${parsedData[barGroup.index].columnName}__${\n bar.key\n }`}\n ref={ref}\n sx={useMemo(\n () => ({\n fill: isAnyHighlighted\n ? `#${tinycolor(currentBarColor).desaturate(70).toHex()}`\n : currentBarColor,\n '&:hover': {\n fill: `#${tinycolor(currentBarColor).saturate(25).toHex()}`,\n },\n transition: 'fill 500ms, opacity 500ms',\n x: bar.x,\n y: bar.y,\n width: bar.width,\n opacity: isAnyHighlighted && !isHighlighted ? 0.15 : 1,\n height: bar.height > 0 ? bar.height : 0,\n }),\n [\n bar.height,\n bar.width,\n bar.x,\n bar.y,\n currentBarColor,\n isAnyHighlighted,\n isHighlighted,\n ],\n )}\n onMouseEnter={(ev) => {\n console.log(bar.key, parsedData[barGroup.index].columnName);\n\n if (!isSingle) {\n legendContainerMethods.highlight(chartId, bar.key);\n } else {\n legendContainerMethods.highlight(\n chartId,\n parsedData[barGroup.index].columnName,\n );\n }\n chartMethods(\n chartId,\n 'highlight',\n `${bar.key}_$_${parsedData[barGroup.index].columnName}`,\n );\n (ev.target as HTMLElement).classList?.add('over');\n const point = {\n x: localPoint(ev)?.x,\n y: localPoint(ev)?.y,\n };\n if (!point || !chart.showValues) return;\n }}\n onMouseLeave={(ev) => {\n legendContainerMethods.highlight(chartId, '');\n chartMethods(chartId, 'highlight', '');\n\n (ev.target as HTMLElement).classList?.remove('over');\n }}\n >\n <animate\n attributeName=\"height\"\n from={0}\n to={bar.height}\n dur=\"0.5s\"\n calcMode={'paced'}\n keySplines={'0.5 0 0.5 1;'}\n keyTimes={'0; 1'}\n />\n <animate\n attributeName=\"y\"\n from={bar.y + bar.height}\n to={bar.y}\n dur=\"0.5s\"\n calcMode={'paced'}\n keySplines={'0.5 0 0.5 1;'}\n keyTimes={'0; 1'}\n />\n </Box>\n </g>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAaO,MAAM,MAAM,CAAC;AAAA,EAClB,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,aAAA;AACF,CAMM,KAAA;AACJ,EAAA,MAAM,SAAS,YAAa,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAE,IAAI,KAAK,CAAA,CAAA;AAC1D,EAAA,MAAM,MAAM,YAAa,CAAA,MAAA,EAAQ,IAAI,CAAA,CAAE,SAAS,KAAK,CAAA,CAAA;AACrD,EAAA,MAAM,kBAAkB,aAAc,CAAA,IAAA;AAAA,IACpC,CAAC,aACC,QAAS,CAAA,UAAA,KAAe,OAAO,IAAQ,IAAA,QAAA,CAAS,QAAQ,GAAI,CAAA,GAAA;AAAA,GAC7D,EAAA,KAAA,CAAA;AACH,EAAA,MAAM,CAAC,aAAA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OAAA;AAAA,OACnC;AAAA,MACA,YAAA,EAAc,CAAC,EAAO,KAAA;AACpB,QAAuB,sBAAA,CAAA,SAAA,CAAU,SAAS,EAAE,CAAA,CAAA;AAC5C,QAAa,YAAA,CAAA,OAAA,EAAS,aAAa,EAAE,CAAA,CAAA;AAErC,QAAC,EAAG,CAAA,MAAA,CAAuB,SAAW,EAAA,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,OACrD;AAAA,MAEA,QAAA,EAAA;AAAA,wBAAA,GAAA;AAAA,UAAC,SAAA;AAAA,UAAA;AAAA,YACC,aAAc,EAAA,QAAA;AAAA,YACd,IAAM,EAAA,CAAA;AAAA,YACN,IAAI,GAAI,CAAA,MAAA;AAAA,YACR,GAAI,EAAA,MAAA;AAAA,YACJ,QAAU,EAAA,OAAA;AAAA,YACV,UAAY,EAAA,cAAA;AAAA,YACZ,QAAU,EAAA,MAAA;AAAA,WAAA;AAAA,SACZ;AAAA,wBACA,GAAA;AAAA,UAAC,SAAA;AAAA,UAAA;AAAA,YACC,aAAc,EAAA,GAAA;AAAA,YACd,IAAA,EAAM,GAAI,CAAA,CAAA,GAAI,GAAI,CAAA,MAAA;AAAA,YAClB,IAAI,GAAI,CAAA,CAAA;AAAA,YACR,GAAI,EAAA,MAAA;AAAA,YACJ,QAAU,EAAA,OAAA;AAAA,YACV,UAAY,EAAA,cAAA;AAAA,YACZ,QAAU,EAAA,MAAA;AAAA,WAAA;AAAA,SACZ;AAAA,OAAA;AAAA,KAAA;AAAA,GAEJ,EAAA,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from '@apia/theme/jsx-runtime';
|
|
2
|
+
import uniqueId from 'lodash-es/uniqueId';
|
|
3
|
+
import { arrayOrArray, usePanAndZoom, getLabel } from '@apia/util';
|
|
4
|
+
import { parseMargin } from '../util/parseMargin.js';
|
|
5
|
+
import { scaleBand, scaleLog, scaleLinear, scaleOrdinal } from '@visx/scale';
|
|
6
|
+
import { useMemo, useLayoutEffect } from 'react';
|
|
7
|
+
import { Box, Heading } from '@apia/theme';
|
|
8
|
+
import { Grid } from '@visx/visx';
|
|
9
|
+
import { Group } from '@visx/group';
|
|
10
|
+
import { BarGroup } from '@visx/shape';
|
|
11
|
+
import { AxisLeft, AxisBottom } from '@visx/axis';
|
|
12
|
+
import { useChartStyles } from '../util/useChartStyles.js';
|
|
13
|
+
import { Bar } from './Bar.js';
|
|
14
|
+
import { getBarColor } from '../util/getBarColor.js';
|
|
15
|
+
import { LegendContainer } from '../util/LegendContainer.js';
|
|
16
|
+
|
|
17
|
+
function adjustDimensions({
|
|
18
|
+
width,
|
|
19
|
+
height,
|
|
20
|
+
maxWidth
|
|
21
|
+
}) {
|
|
22
|
+
if (width <= maxWidth) {
|
|
23
|
+
return { width, height };
|
|
24
|
+
}
|
|
25
|
+
const ratio = width / height;
|
|
26
|
+
const newWidth = maxWidth;
|
|
27
|
+
const newHeight = Math.floor(newWidth / ratio);
|
|
28
|
+
return { width: newWidth, height: newHeight };
|
|
29
|
+
}
|
|
30
|
+
const getXValue = (d) => d.columnName;
|
|
31
|
+
const VerticalBars = ({
|
|
32
|
+
margin = { top: 20, left: 100, bottom: 24, right: 0 },
|
|
33
|
+
chart,
|
|
34
|
+
className,
|
|
35
|
+
chartId,
|
|
36
|
+
allowZoom
|
|
37
|
+
}) => {
|
|
38
|
+
const effectiveMargin = parseMargin(margin);
|
|
39
|
+
if (!chart.showAxisYTitle && effectiveMargin.left > 50) {
|
|
40
|
+
effectiveMargin.left = 50;
|
|
41
|
+
}
|
|
42
|
+
let innerWidth = chart.ratio.width + (-effectiveMargin.left - effectiveMargin.right) / 2;
|
|
43
|
+
let innerHeight = chart.ratio.height + (chart.showAxisXTitle ? -effectiveMargin.top - effectiveMargin.bottom : (-effectiveMargin.top - effectiveMargin.bottom) / 2);
|
|
44
|
+
if (innerWidth > chart.ratio.maxWidth) {
|
|
45
|
+
const newValues = adjustDimensions({
|
|
46
|
+
height: innerHeight,
|
|
47
|
+
width: innerWidth,
|
|
48
|
+
maxWidth: chart.ratio.maxWidth
|
|
49
|
+
});
|
|
50
|
+
innerWidth = newValues.width;
|
|
51
|
+
innerHeight = newValues.height;
|
|
52
|
+
}
|
|
53
|
+
const styles = useChartStyles(chart.colorSchema);
|
|
54
|
+
const columnas = arrayOrArray(chart.dataSets?.data).filter((column) => !!column.sets).map((column) => {
|
|
55
|
+
return {
|
|
56
|
+
...column,
|
|
57
|
+
sets: column.sets
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
const xValues = arrayOrArray(columnas[0].sets).map(
|
|
61
|
+
(innerCoord) => innerCoord.key
|
|
62
|
+
);
|
|
63
|
+
const columnNames = columnas.map((col) => {
|
|
64
|
+
return col.name;
|
|
65
|
+
});
|
|
66
|
+
const parsedData = xValues.map((x) => {
|
|
67
|
+
const obj = columnas.reduce(
|
|
68
|
+
(acc, column) => {
|
|
69
|
+
return {
|
|
70
|
+
...acc,
|
|
71
|
+
[column.name]: arrayOrArray(column.sets).filter((coord) => {
|
|
72
|
+
return coord.key === x;
|
|
73
|
+
})[0].value
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
{ columnName: x }
|
|
77
|
+
);
|
|
78
|
+
return obj;
|
|
79
|
+
});
|
|
80
|
+
const xScale = scaleBand({
|
|
81
|
+
range: [
|
|
82
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.left,
|
|
83
|
+
chart.ratio.width
|
|
84
|
+
],
|
|
85
|
+
domain: parsedData.map(getXValue),
|
|
86
|
+
padding: 0.2
|
|
87
|
+
});
|
|
88
|
+
const numericXScale = scaleBand({
|
|
89
|
+
range: [
|
|
90
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.left,
|
|
91
|
+
chart.ratio.width
|
|
92
|
+
],
|
|
93
|
+
domain: parsedData.map((_, i) => `${i + 1}`),
|
|
94
|
+
padding: 0.2
|
|
95
|
+
});
|
|
96
|
+
const columnGroupScale = scaleBand({
|
|
97
|
+
domain: columnNames,
|
|
98
|
+
range: [0, xScale.bandwidth()]
|
|
99
|
+
});
|
|
100
|
+
const yScaleLog = scaleLog({
|
|
101
|
+
range: [
|
|
102
|
+
innerHeight,
|
|
103
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top
|
|
104
|
+
],
|
|
105
|
+
domain: [
|
|
106
|
+
1,
|
|
107
|
+
Math.max(
|
|
108
|
+
...parsedData.map(
|
|
109
|
+
(d) => Math.max(...columnNames.map((key) => Number(d[key])))
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
],
|
|
113
|
+
base: 10
|
|
114
|
+
});
|
|
115
|
+
const yScaleLine = scaleLinear({
|
|
116
|
+
range: [
|
|
117
|
+
innerHeight,
|
|
118
|
+
typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top
|
|
119
|
+
],
|
|
120
|
+
domain: [
|
|
121
|
+
0,
|
|
122
|
+
Math.max(
|
|
123
|
+
...parsedData.map(
|
|
124
|
+
(d) => Math.max(...columnNames.map((key) => Number(d[key])))
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
const color = scaleOrdinal({
|
|
130
|
+
domain: columnNames,
|
|
131
|
+
range: columnas.map((col) => col.color)
|
|
132
|
+
});
|
|
133
|
+
const isLogScale = false;
|
|
134
|
+
const yScale = useMemo(() => {
|
|
135
|
+
{
|
|
136
|
+
return yScaleLine;
|
|
137
|
+
}
|
|
138
|
+
}, [isLogScale, yScaleLine, yScaleLog]);
|
|
139
|
+
const id = useMemo(() => `VerticalBars${uniqueId()}`, []);
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
document.querySelectorAll(`#${id} .tickLabel`).forEach((current) => {
|
|
142
|
+
const box = current.getBoundingClientRect();
|
|
143
|
+
if (box.width > 125) {
|
|
144
|
+
current.style.width = "125px";
|
|
145
|
+
current.style.overflow = "hidden";
|
|
146
|
+
current.style.textOverflow = "ellipsis";
|
|
147
|
+
current.style.whiteSpace = "nowrap";
|
|
148
|
+
}
|
|
149
|
+
current.style.transformOrigin = current.getAttribute("x") + "px 14px";
|
|
150
|
+
current.style.transform = `rotate(25deg)`;
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
const { boxRef, elementRef } = usePanAndZoom(
|
|
154
|
+
void 0,
|
|
155
|
+
!allowZoom
|
|
156
|
+
);
|
|
157
|
+
const setsWithColor = arrayOrArray(chart.dataSets.data).map((data, index) => {
|
|
158
|
+
const isSingle = arrayOrArray(chart.dataSets.data).length === 1;
|
|
159
|
+
const dataColor = data.color !== "" && data.color !== void 0 ? data.color : arrayOrArray(
|
|
160
|
+
styles ? styles.schema : [
|
|
161
|
+
"#7ad6f4",
|
|
162
|
+
"#45bdee",
|
|
163
|
+
"#28a7ea",
|
|
164
|
+
"#006cbb",
|
|
165
|
+
"#034698",
|
|
166
|
+
"#032f64"
|
|
167
|
+
]
|
|
168
|
+
).length > 0 ? getBarColor(
|
|
169
|
+
arrayOrArray(
|
|
170
|
+
styles ? styles.schema : [
|
|
171
|
+
"#7ad6f4",
|
|
172
|
+
"#45bdee",
|
|
173
|
+
"#28a7ea",
|
|
174
|
+
"#006cbb",
|
|
175
|
+
"#034698",
|
|
176
|
+
"#032f64"
|
|
177
|
+
]
|
|
178
|
+
),
|
|
179
|
+
index,
|
|
180
|
+
isSingle
|
|
181
|
+
) : "";
|
|
182
|
+
const returnColumnsArray = [];
|
|
183
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
184
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
185
|
+
returnColumnsArray.push({ ...set, columnName: data.name });
|
|
186
|
+
} else {
|
|
187
|
+
returnColumnsArray.push({
|
|
188
|
+
...set,
|
|
189
|
+
color: dataColor,
|
|
190
|
+
columnName: data.name
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return returnColumnsArray;
|
|
195
|
+
});
|
|
196
|
+
const colorReference = arrayOrArray(chart.dataSets.data).map(
|
|
197
|
+
(data, index) => {
|
|
198
|
+
const isSingle = arrayOrArray(chart.dataSets.data).length === 1;
|
|
199
|
+
const dataColor = data.color !== "" && data.color !== void 0 ? data.color : arrayOrArray(
|
|
200
|
+
styles ? styles.schema : [
|
|
201
|
+
"#7ad6f4",
|
|
202
|
+
"#45bdee",
|
|
203
|
+
"#28a7ea",
|
|
204
|
+
"#006cbb",
|
|
205
|
+
"#034698",
|
|
206
|
+
"#032f64"
|
|
207
|
+
]
|
|
208
|
+
).length > 0 ? getBarColor(
|
|
209
|
+
arrayOrArray(
|
|
210
|
+
styles ? styles.schema : [
|
|
211
|
+
"#7ad6f4",
|
|
212
|
+
"#45bdee",
|
|
213
|
+
"#28a7ea",
|
|
214
|
+
"#006cbb",
|
|
215
|
+
"#034698",
|
|
216
|
+
"#032f64"
|
|
217
|
+
]
|
|
218
|
+
),
|
|
219
|
+
index,
|
|
220
|
+
isSingle
|
|
221
|
+
) : "";
|
|
222
|
+
return {
|
|
223
|
+
color: dataColor,
|
|
224
|
+
title: data.name
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
let numberReference = [];
|
|
229
|
+
if (colorReference.length === 1) {
|
|
230
|
+
numberReference = arrayOrArray(
|
|
231
|
+
arrayOrArray(chart.dataSets.data)[0].sets
|
|
232
|
+
).map((data, index) => {
|
|
233
|
+
return {
|
|
234
|
+
color: `${index + 1}`,
|
|
235
|
+
title: data.key
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
arrayOrArray(chart.dataSets.data).map((data) => {
|
|
240
|
+
const returnArray = [];
|
|
241
|
+
arrayOrArray(data.sets).forEach((set) => {
|
|
242
|
+
if (set.color !== "" && set.color !== void 0) {
|
|
243
|
+
returnArray.push({
|
|
244
|
+
color: set.color,
|
|
245
|
+
title: data.name + " - " + set.key
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
return returnArray;
|
|
250
|
+
}).flat().forEach((addRef) => colorReference.push(addRef));
|
|
251
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
252
|
+
/* @__PURE__ */ jsx(
|
|
253
|
+
Box,
|
|
254
|
+
{
|
|
255
|
+
ref: boxRef,
|
|
256
|
+
id,
|
|
257
|
+
className: `${className ?? ""} ${chart.title} chartBox chartContainer`,
|
|
258
|
+
sx: {
|
|
259
|
+
overflow: "hidden"
|
|
260
|
+
},
|
|
261
|
+
children: /* @__PURE__ */ jsxs(
|
|
262
|
+
"svg",
|
|
263
|
+
{
|
|
264
|
+
ref: elementRef,
|
|
265
|
+
className: `_${chartId} chart__svg`,
|
|
266
|
+
height: chart.ratio.height,
|
|
267
|
+
width: chart.ratio.width,
|
|
268
|
+
children: [
|
|
269
|
+
chart.showGrid && /* @__PURE__ */ jsx(
|
|
270
|
+
Grid.Grid,
|
|
271
|
+
{
|
|
272
|
+
xScale,
|
|
273
|
+
yScale,
|
|
274
|
+
left: 0,
|
|
275
|
+
width: chart.ratio.width,
|
|
276
|
+
height: innerHeight,
|
|
277
|
+
numTicksRows: 10,
|
|
278
|
+
numTicksColumns: 10,
|
|
279
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20
|
|
280
|
+
}
|
|
281
|
+
),
|
|
282
|
+
/* @__PURE__ */ jsx(
|
|
283
|
+
Group,
|
|
284
|
+
{
|
|
285
|
+
top: (typeof effectiveMargin === "number" ? effectiveMargin : effectiveMargin.top) - 20,
|
|
286
|
+
children: /* @__PURE__ */ jsx(
|
|
287
|
+
BarGroup,
|
|
288
|
+
{
|
|
289
|
+
data: parsedData,
|
|
290
|
+
keys: columnNames,
|
|
291
|
+
height: innerHeight,
|
|
292
|
+
x0: getXValue,
|
|
293
|
+
x0Scale: xScale,
|
|
294
|
+
x1Scale: columnGroupScale,
|
|
295
|
+
yScale,
|
|
296
|
+
color,
|
|
297
|
+
children: (barGroups) => barGroups.map((barGroup) => {
|
|
298
|
+
return /* @__PURE__ */ jsx(
|
|
299
|
+
Group,
|
|
300
|
+
{
|
|
301
|
+
left: barGroup.x0,
|
|
302
|
+
children: barGroup.bars.map((bar) => {
|
|
303
|
+
const key = `${barGroup.index}-${bar.index}-${bar.key}`;
|
|
304
|
+
return /* @__PURE__ */ jsx(
|
|
305
|
+
Bar,
|
|
306
|
+
{
|
|
307
|
+
isSingle: barGroup.bars.length === 1,
|
|
308
|
+
bar,
|
|
309
|
+
barGroup,
|
|
310
|
+
chart,
|
|
311
|
+
parsedData,
|
|
312
|
+
setsWithColor: setsWithColor.flat()
|
|
313
|
+
},
|
|
314
|
+
key
|
|
315
|
+
);
|
|
316
|
+
})
|
|
317
|
+
},
|
|
318
|
+
`bar-group-${barGroup.index}-${barGroup.x0}`
|
|
319
|
+
);
|
|
320
|
+
})
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
),
|
|
325
|
+
/* @__PURE__ */ jsx(
|
|
326
|
+
AxisLeft,
|
|
327
|
+
{
|
|
328
|
+
scale: yScale,
|
|
329
|
+
left: effectiveMargin.left,
|
|
330
|
+
label: chart.chartType !== "pie2D" && chart.showAxisYTitle ? chart.axisYTitle : "",
|
|
331
|
+
tickComponent: (props) => {
|
|
332
|
+
let value = Number(props.formattedValue?.replace(",", ""));
|
|
333
|
+
let counter = -1;
|
|
334
|
+
const units = ["k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"];
|
|
335
|
+
while (value >= 1e3) {
|
|
336
|
+
value = value / 1e3;
|
|
337
|
+
counter++;
|
|
338
|
+
}
|
|
339
|
+
let stringValue = `${value}`;
|
|
340
|
+
if (stringValue.length > 3) {
|
|
341
|
+
stringValue = stringValue.slice(0, 3);
|
|
342
|
+
}
|
|
343
|
+
if (stringValue.endsWith(".")) {
|
|
344
|
+
stringValue = stringValue.replace(".", "");
|
|
345
|
+
}
|
|
346
|
+
const newValue = `${stringValue}${counter >= 0 ? units[counter] : ""}`;
|
|
347
|
+
return /* @__PURE__ */ jsx(Fragment, { children: chart.showAxisYTitle && /* @__PURE__ */ jsx(
|
|
348
|
+
"text",
|
|
349
|
+
{
|
|
350
|
+
dx: props.dx,
|
|
351
|
+
dy: props.dy,
|
|
352
|
+
fill: props.fill,
|
|
353
|
+
fontSize: props.fontSize,
|
|
354
|
+
textAnchor: props.textAnchor,
|
|
355
|
+
x: props.x,
|
|
356
|
+
y: props.y,
|
|
357
|
+
children: newValue
|
|
358
|
+
}
|
|
359
|
+
) });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
/* @__PURE__ */ jsx(
|
|
364
|
+
AxisBottom,
|
|
365
|
+
{
|
|
366
|
+
top: innerHeight,
|
|
367
|
+
scale: colorReference.length === 1 && numberReference.length > 0 ? numericXScale : xScale,
|
|
368
|
+
label: chart.chartType !== "pie2D" && chart.showAxisXTitle ? chart.axisXTitle : "",
|
|
369
|
+
tickLabelProps: { display: "none" },
|
|
370
|
+
tickLineProps: { display: "none" },
|
|
371
|
+
labelOffset: 0
|
|
372
|
+
}
|
|
373
|
+
)
|
|
374
|
+
]
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
),
|
|
379
|
+
/* @__PURE__ */ jsx(Box, { className: "chartLegend__Wrapper", children: chart.showLegend && colorReference.length !== 0 && /* @__PURE__ */ jsxs(Box, { className: "chart__legend__wrapper", children: [
|
|
380
|
+
/* @__PURE__ */ jsx(Heading, { as: "h6", children: getLabel("mnuLeyends").text }),
|
|
381
|
+
/* @__PURE__ */ jsx(
|
|
382
|
+
LegendContainer,
|
|
383
|
+
{
|
|
384
|
+
id: chartId,
|
|
385
|
+
references: colorReference.length === 1 && numberReference.length > 0 ? numberReference : colorReference,
|
|
386
|
+
useNumbered: colorReference.length === 1
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
] }) })
|
|
390
|
+
] });
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
export { VerticalBars };
|
|
394
|
+
//# sourceMappingURL=VerticalBars.js.map
|