pace-chart-lib 0.0.7 → 0.0.9
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/README.md +10 -10
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +46 -0
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +2285 -0
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +169 -0
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +47 -0
- package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
- package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.js +403 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +0 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +0 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
- package/dist/Components1/Charts/Core/Common.type.d.ts +8 -0
- package/dist/Components1/Charts/Core/Common.type.js +9 -0
- package/dist/Components1/Charts/Core/CommonFunctions.d.ts +12 -0
- package/dist/Components1/Charts/Core/CommonFunctions.js +512 -0
- package/dist/Components1/Charts/Core/DefaultProperties.d.ts +586 -0
- package/dist/Components1/Charts/Core/DefaultProperties.js +585 -0
- package/dist/Services/ErrorLog.d.ts +1 -0
- package/dist/Services/ErrorLog.js +3 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.js +497 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.js +491 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.js +520 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.js +553 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.js +519 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.js +553 -0
- package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.d.ts +12 -0
- package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.js +9 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +623 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +4897 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +0 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +0 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.d.ts +173 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.js +49 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.js +486 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.js +498 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.js +417 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.js +1014 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.js +479 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.js +451 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.js +535 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.js +512 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.js +532 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.js +512 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.d.ts +12 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.js +9 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.js +498 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.js +498 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.js +479 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.js +479 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.js +474 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.js +464 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.d.ts +0 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.js +0 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.js +452 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.js +554 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.js +513 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.js +508 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.js +395 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.js +608 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.d.ts +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.js +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +92 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +815 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.d.ts +108 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.js +32 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.d.ts +26 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.js +15021 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.js +391 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.js +367 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.js +569 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.js +212 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.js +401 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.js +313 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.js +719 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.js +807 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.js +514 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.js +282 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.js +207 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.js +476 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.js +420 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.d.ts +10 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.js +106 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.js +507 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.js +246 -0
- package/dist/components/Charts/Core/Common.type.d.ts +0 -0
- package/dist/components/Charts/Core/Common.type.js +0 -0
- package/dist/components/Charts/Core/Common.types.d.ts +369 -0
- package/dist/components/Charts/Core/Common.types.js +133 -0
- package/dist/components/Charts/Core/CommonFunctions.d.ts +236 -0
- package/dist/components/Charts/Core/CommonFunctions.js +1778 -0
- package/dist/components/Charts/Core/DefaultChartDataProperties.d.ts +65 -0
- package/dist/components/Charts/Core/DefaultChartDataProperties.js +64 -0
- package/dist/components/Charts/Core/DefaultProperties.d.ts +0 -0
- package/dist/components/Charts/Core/DefaultProperties.js +0 -0
- package/dist/components/Charts/Core/DefaultProperties.type.d.ts +586 -0
- package/dist/components/Charts/Core/DefaultProperties.type.js +585 -0
- package/dist/components/Charts/Core/DefaultProperties.types.d.ts +592 -0
- package/dist/components/Charts/Core/DefaultProperties.types.js +592 -0
- package/dist/index.d.ts +34 -2
- package/dist/index.js +40 -2
- package/package.json +40 -29
- package/dist/components/charts/linechart/LineChart.d.ts +0 -12
- package/dist/components/charts/linechart/LineChart.js +0 -5
- /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.d.ts +0 -0
- /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.js +0 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Pending Task -> Custom Annotations on charts
|
|
3
|
+
//#region imports
|
|
4
|
+
import * as d3 from "d3";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import { fontStyleOptions, } from "../../Core/Common.types";
|
|
7
|
+
import { calculateLegendsMaxPossibleWidth, convertStringToNumber, drawChartTitle, firstFunctionBeforeRender, generalizedChartData, getNumberWithFormatFunction, hideTooltipOnMouseOut, initChartArea, initLegendListWithTotalValueAllowance, initSvg, marginCalculationsForChartsWithoutAxis, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
|
|
8
|
+
import { chartMargins } from "../../Core/DefaultProperties.types";
|
|
9
|
+
import { connectorStyle } from "../ChartsWithoutAxisTypes.types";
|
|
10
|
+
import { logError } from "../../../../Services/ErrorLog";
|
|
11
|
+
//#endregion
|
|
12
|
+
const fileName = "DonutChart.tsx";
|
|
13
|
+
const DonutChart = ({ data, formatOptions, chartId, }) => {
|
|
14
|
+
const svgRef = useRef();
|
|
15
|
+
const seriesData = generalizedChartData(data);
|
|
16
|
+
let chartFormatOptions;
|
|
17
|
+
let width; // svg total width
|
|
18
|
+
let height; // svg total height
|
|
19
|
+
let chartTitleHeight = 40; // Height of the chart title
|
|
20
|
+
let margins = chartMargins; // Margins for the chart
|
|
21
|
+
let maxLegendDimensions = [0, 0]; // to calculate margins [width, height]
|
|
22
|
+
let innerHeight; // Height of the chart excluding margins
|
|
23
|
+
let innerWidth; // Width of the chart excluding margins
|
|
24
|
+
let radius; // Radius of the pie chart
|
|
25
|
+
let innerRadius; // Inner radius of the pie chart
|
|
26
|
+
let legendListWidth; // Width of the legend list
|
|
27
|
+
let chartAreaTagG; // Group element for the chart area
|
|
28
|
+
let pieChartData; //Data output by d3.pie function
|
|
29
|
+
let pieTotalValue; // Required for % calculations also appeding total to svg
|
|
30
|
+
let outsideDataLabelFlag = false; // Flag to check if any data label is outside
|
|
31
|
+
let svg; // D3 selection of the SVG element
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
drawChart();
|
|
34
|
+
}, [formatOptions]);
|
|
35
|
+
const drawChart = () => {
|
|
36
|
+
({ chartFormatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
|
|
37
|
+
loopOverSeriesData();
|
|
38
|
+
maxLegendDimensions = calculateLegendsMaxPossibleWidth(chartFormatOptions, seriesData);
|
|
39
|
+
({ margins, innerHeight, innerWidth, legendListWidth, chartTitleHeight } =
|
|
40
|
+
marginCalculationsForChartsWithoutAxis(chartFormatOptions, width, height, maxLegendDimensions, margins));
|
|
41
|
+
defineChartRadius();
|
|
42
|
+
initSvg(svgRef, width, height, chartFormatOptions); // Initialize SVG with width, height and background color
|
|
43
|
+
chartAreaTagG = initChartArea(svg, margins);
|
|
44
|
+
drawChartTitle(svgRef, chartTitleHeight, width, chartFormatOptions);
|
|
45
|
+
initLegendListWithTotalValueAllowance(chartFormatOptions, svg, seriesData, width, height, legendListWidth, chartTitleHeight, chartId, margins, false);
|
|
46
|
+
initPieChartData();
|
|
47
|
+
drawDonutChart();
|
|
48
|
+
drawDonutDataLabels();
|
|
49
|
+
drawTotalValue();
|
|
50
|
+
};
|
|
51
|
+
const loopOverSeriesData = () => {
|
|
52
|
+
try {
|
|
53
|
+
pieTotalValue = 0;
|
|
54
|
+
data.forEach((d) => {
|
|
55
|
+
d.properties.dataLabelPosition == "2"
|
|
56
|
+
? (outsideDataLabelFlag = true)
|
|
57
|
+
: null;
|
|
58
|
+
pieTotalValue += d.data[0].value;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
logError(fileName, "loopOverSeriesData", error);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const defineChartRadius = () => {
|
|
66
|
+
try {
|
|
67
|
+
radius = Math.min(innerHeight * 0.4, innerWidth * 0.4);
|
|
68
|
+
outsideDataLabelFlag ? (radius = radius * 0.9) : null;
|
|
69
|
+
innerRadius = Math.min((convertStringToNumber(chartFormatOptions.plotArea.innerRadius) / 100) *
|
|
70
|
+
radius, radius);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logError(fileName, "defineChartRadius", error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const initPieChartData = () => {
|
|
77
|
+
try {
|
|
78
|
+
let rotationAngle = convertStringToNumber(chartFormatOptions.plotArea.rotation);
|
|
79
|
+
const pie = d3
|
|
80
|
+
?.pie()
|
|
81
|
+
.value((d) => d.data[0].value)
|
|
82
|
+
.startAngle(((rotationAngle ?? 0) * (Math.PI / 180)) % 360)
|
|
83
|
+
.endAngle((((rotationAngle ?? 0) + 360) * (Math.PI / 180)) % 360);
|
|
84
|
+
let pieData = pie(data);
|
|
85
|
+
pieChartData = pieData?.map((d, i) => ({
|
|
86
|
+
...d,
|
|
87
|
+
x0: d.startAngle,
|
|
88
|
+
x1: d.endAngle,
|
|
89
|
+
y0: 0,
|
|
90
|
+
y1: radius,
|
|
91
|
+
depth: 2, // Set depth to 2 to simulate hierarchical level for consistent arc rendering (e.g., in sunburst or partition layouts)
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
logError(fileName, "initPieChartData", error);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const drawDonutChart = () => {
|
|
99
|
+
try {
|
|
100
|
+
const arc = d3
|
|
101
|
+
.arc()
|
|
102
|
+
.innerRadius(innerRadius) // Donut inner radius
|
|
103
|
+
.outerRadius(radius);
|
|
104
|
+
const arcOver = d3
|
|
105
|
+
.arc()
|
|
106
|
+
.innerRadius(innerRadius)
|
|
107
|
+
.outerRadius(radius + 10); // Slightly bigger on hover
|
|
108
|
+
chartAreaTagG
|
|
109
|
+
.append("g")
|
|
110
|
+
.attr("class", "parentGroup")
|
|
111
|
+
.attr("fill-opacity", chartFormatOptions.plotArea.opacity)
|
|
112
|
+
.attr("transform", `${getPiePosition()}`)
|
|
113
|
+
.selectAll("path")
|
|
114
|
+
.data(pieChartData)
|
|
115
|
+
.enter()
|
|
116
|
+
.append("path")
|
|
117
|
+
.attr("class", (d) => "path " + d.data.legend)
|
|
118
|
+
.attr("hoverId", (d) => d.data.legend.replace(/ /g, "-"))
|
|
119
|
+
.attr("fill", (d) => d.data.properties.color !== "#ffffff"
|
|
120
|
+
? d.data.properties.color
|
|
121
|
+
: "none")
|
|
122
|
+
.attr("d", (d) => arc(d))
|
|
123
|
+
.on("mouseover.arc", function (d) {
|
|
124
|
+
d3.select(this).transition().duration(100).attr("d", arcOver);
|
|
125
|
+
})
|
|
126
|
+
.on("mousemove.text", (d) => {
|
|
127
|
+
showTooltipOnMouseMove([
|
|
128
|
+
{
|
|
129
|
+
key: chartFormatOptions.yAxisTitle.yAxisTitleText,
|
|
130
|
+
value: chartFormatOptions.toolTip.toolTipNumberFormat == ",.0%"
|
|
131
|
+
? (Math.abs(d.currentTarget.__data__.data.data[0].value /
|
|
132
|
+
pieTotalValue) * 100).toFixed(convertStringToNumber(chartFormatOptions.toolTip.toolTipDecimalPrecision)) + "%"
|
|
133
|
+
: getNumberWithFormatFunction("None", chartFormatOptions.toolTip.toolTipNumberFormat, chartFormatOptions.toolTip.toolTipDecimalPrecision)(d.currentTarget.__data__.data.data[0].value),
|
|
134
|
+
},
|
|
135
|
+
{ key: "Legend", value: d.currentTarget.__data__.data.legend },
|
|
136
|
+
], chartFormatOptions);
|
|
137
|
+
})
|
|
138
|
+
.on("mouseout.text", () => {
|
|
139
|
+
hideTooltipOnMouseOut();
|
|
140
|
+
})
|
|
141
|
+
.on("mouseout.arc", function (d) {
|
|
142
|
+
d3.select(this).transition().duration(100).attr("d", arc);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
logError(fileName, "drawDonutChart", error);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const getPiePosition = () => {
|
|
150
|
+
try {
|
|
151
|
+
return `translate(${innerWidth / 2},${innerHeight / 2})`;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
logError(fileName, "getPiePosition", error);
|
|
155
|
+
return "";
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const getDataLabelTransformString = (d) => {
|
|
159
|
+
try {
|
|
160
|
+
const midAngle = (d.startAngle + d.endAngle) / 2;
|
|
161
|
+
// Adjust label radius (between innerRadius and outerRadius)
|
|
162
|
+
const labelRadius = (innerRadius + radius) / 2; // midpoint between inner and outer radius
|
|
163
|
+
const x = Math.cos(midAngle - Math.PI / 2) * labelRadius;
|
|
164
|
+
const y = Math.sin(midAngle - Math.PI / 2) * labelRadius;
|
|
165
|
+
// Optional rotation logic
|
|
166
|
+
let rotate = ((midAngle * 180) / Math.PI) % 360;
|
|
167
|
+
let angle = 0;
|
|
168
|
+
rotate > 180 && rotate < 360 ? (angle = 90) : (angle = -90);
|
|
169
|
+
rotate += angle;
|
|
170
|
+
return `translate(${x},${y}) rotate(${rotate})`;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
logError(fileName, "getDataLabelTransformString", error);
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const drawDonutDataLabels = () => {
|
|
178
|
+
try {
|
|
179
|
+
if (chartFormatOptions.plotArea.dataLabels) {
|
|
180
|
+
// Code for inside data labels
|
|
181
|
+
chartAreaTagG
|
|
182
|
+
.append("g")
|
|
183
|
+
.attr("class", "parentGroup")
|
|
184
|
+
.attr("transform", `${getPiePosition()}`)
|
|
185
|
+
.attr("pointer-events", "none")
|
|
186
|
+
.attr("text-anchor", "middle")
|
|
187
|
+
.selectAll("text")
|
|
188
|
+
.data(pieChartData.filter((d) => d.data.properties.dataLabelPosition == "1"))
|
|
189
|
+
.enter()
|
|
190
|
+
.append("text")
|
|
191
|
+
.attr("hoverId", (d) => d.data.legend.replace(/ /g, "-"))
|
|
192
|
+
.attr("font-size", (d) => d.data.properties?.labelFontSize ?? 11)
|
|
193
|
+
.attr("fill", (d) => d.data.properties?.labelFontColor ?? "#000000")
|
|
194
|
+
.attr("font-style", (d) => d.data.properties?.labelFontStyle?.includes(fontStyleOptions.italic)
|
|
195
|
+
? fontStyleOptions.italic
|
|
196
|
+
: "")
|
|
197
|
+
.attr("text-decoration", (d) => d.data.properties?.labelFontStyle?.includes(fontStyleOptions.underline)
|
|
198
|
+
? fontStyleOptions.underline
|
|
199
|
+
: "")
|
|
200
|
+
.attr("font-weight", (d) => d.data.properties?.labelFontStyle?.includes(fontStyleOptions.bold)
|
|
201
|
+
? fontStyleOptions.bold
|
|
202
|
+
: "")
|
|
203
|
+
.attr("font-family", (d) => d.data.properties?.labelFont ?? "Helvetica")
|
|
204
|
+
.attr("transform", (d) => getDataLabelTransformString(d))
|
|
205
|
+
.attr("dy", "-0.35em")
|
|
206
|
+
.attr("text-anchor", "middle")
|
|
207
|
+
.attr("alignment-baseline", "middle")
|
|
208
|
+
.text((d) => {
|
|
209
|
+
const { plotArea } = chartFormatOptions;
|
|
210
|
+
if (plotArea.dataLabelName) {
|
|
211
|
+
return d.data.legend;
|
|
212
|
+
}
|
|
213
|
+
return "";
|
|
214
|
+
});
|
|
215
|
+
chartAreaTagG
|
|
216
|
+
.append("g")
|
|
217
|
+
.attr("class", "parentGroup")
|
|
218
|
+
.attr("transform", `${getPiePosition()}`)
|
|
219
|
+
.attr("pointer-events", "none")
|
|
220
|
+
.attr("text-anchor", "middle")
|
|
221
|
+
.selectAll("text")
|
|
222
|
+
.data(pieChartData.filter((d) => d.data.properties.dataLabelPosition == "1"))
|
|
223
|
+
.enter()
|
|
224
|
+
.append("text")
|
|
225
|
+
.attr("hoverId", (d) => d.data.legend.replace(/ /g, "-"))
|
|
226
|
+
.attr("font-size", (d) => d.data.properties?.valueFontSize ?? 11)
|
|
227
|
+
.attr("fill", (d) => d.data.properties?.valueFontColor ?? "#000000")
|
|
228
|
+
.attr("font-style", (d) => d.data.properties?.valueFontStyle?.includes(fontStyleOptions.italic)
|
|
229
|
+
? fontStyleOptions.italic
|
|
230
|
+
: "")
|
|
231
|
+
.attr("text-decoration", (d) => d.data.properties?.valueFontStyle?.includes(fontStyleOptions.underline)
|
|
232
|
+
? fontStyleOptions.underline
|
|
233
|
+
: "")
|
|
234
|
+
.attr("font-weight", (d) => d.data.properties?.valueFontStyle?.includes(fontStyleOptions.bold)
|
|
235
|
+
? fontStyleOptions.bold
|
|
236
|
+
: "300")
|
|
237
|
+
.attr("font-family", (d) => d.data.properties?.valueFont ?? "Helvetica")
|
|
238
|
+
.attr("transform", (d) => getDataLabelTransformString(d))
|
|
239
|
+
.attr("text-anchor", "middle")
|
|
240
|
+
.attr("alignment-baseline", "middle")
|
|
241
|
+
.attr("dy", "1.00em")
|
|
242
|
+
.text((d) => {
|
|
243
|
+
if (chartFormatOptions.plotArea.dataLabelValue) {
|
|
244
|
+
const dataValue = d.data.data[0].value;
|
|
245
|
+
if (chartFormatOptions.plotArea.dataLabelName &&
|
|
246
|
+
chartFormatOptions.plotArea.dataLabelValue &&
|
|
247
|
+
dataValue !== undefined) {
|
|
248
|
+
if (chartFormatOptions.plotArea.dataLabelNumberFormat === ",.0%") {
|
|
249
|
+
return ((Math.abs(dataValue / pieTotalValue) * 100).toFixed(convertStringToNumber(chartFormatOptions.plotArea.dataLabelDecimalPrecision) ?? 0) + "%");
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return getNumberWithFormatFunction(chartFormatOptions.plotArea.plotAreaDisplayUnits, chartFormatOptions.plotArea.dataLabelNumberFormat, chartFormatOptions.plotArea.dataLabelDecimalPrecision)(dataValue);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return dataValue;
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
.append("tspan")
|
|
259
|
+
.attr("x", 0)
|
|
260
|
+
.attr("y", chartFormatOptions.plotArea.dataLabelValue
|
|
261
|
+
? chartFormatOptions.plotArea.dataLabelName
|
|
262
|
+
? "2.45em"
|
|
263
|
+
: "0.1em"
|
|
264
|
+
: null)
|
|
265
|
+
.attr("font-weight", (d) => d.data.properties?.valueFontStyle?.includes(fontStyleOptions.bold)
|
|
266
|
+
? fontStyleOptions.bold
|
|
267
|
+
: "300")
|
|
268
|
+
.attr("fill-opacity", 0.5)
|
|
269
|
+
.text((d) => {
|
|
270
|
+
const dataValue = Math.abs(d.data.data[0].value);
|
|
271
|
+
if (chartFormatOptions.plotArea.plotAreaAbsoluteValue &&
|
|
272
|
+
dataValue !== undefined) {
|
|
273
|
+
return d3.format(".2s")(dataValue);
|
|
274
|
+
}
|
|
275
|
+
return "";
|
|
276
|
+
});
|
|
277
|
+
// Code for outside data labels
|
|
278
|
+
let outerRadius = d3
|
|
279
|
+
.arc()
|
|
280
|
+
.startAngle((d) => d.x0)
|
|
281
|
+
.endAngle((d) => d.x1)
|
|
282
|
+
.innerRadius((d) => (d.depth > 1 ? d.y1 - 1 + radius / 7 : 0))
|
|
283
|
+
.outerRadius((d) => (d.depth > 1 ? d.y1 - 1 + radius / 7 : 0));
|
|
284
|
+
let innerRadius = d3
|
|
285
|
+
.arc()
|
|
286
|
+
.startAngle((d) => d.x0)
|
|
287
|
+
.endAngle((d) => d.x1)
|
|
288
|
+
.innerRadius((d) => (d.depth > 2 ? d.y0 : 0))
|
|
289
|
+
.outerRadius((d) => d.y1 + radius / 1.5);
|
|
290
|
+
chartAreaTagG
|
|
291
|
+
.selectAll("polyline")
|
|
292
|
+
.data(pieChartData.filter((d) => d.data.properties.dataLabelPosition == "2"))
|
|
293
|
+
.join("polyline")
|
|
294
|
+
.attr("transform", getPiePosition())
|
|
295
|
+
.style("stroke", (d) => chartFormatOptions.connector.connectorColorOption == "Uniform"
|
|
296
|
+
? chartFormatOptions.connector.connectorUniformLineColor
|
|
297
|
+
: d.data.properties.color)
|
|
298
|
+
.style("fill", "none")
|
|
299
|
+
.style("stroke-dasharray", chartFormatOptions.connector.connectorStyle === connectorStyle.solid
|
|
300
|
+
? 0
|
|
301
|
+
: chartFormatOptions.connector.connectorStyle ===
|
|
302
|
+
connectorStyle.dotted
|
|
303
|
+
? 1
|
|
304
|
+
: 4)
|
|
305
|
+
.style("stroke-width", chartFormatOptions.connector.connectorLineThickness)
|
|
306
|
+
.attr("points", (d) => {
|
|
307
|
+
const posA = innerRadius.centroid(d);
|
|
308
|
+
const posB = outerRadius.centroid(d);
|
|
309
|
+
let midangle = d.x0 + (d.x1 - d.x0) / 2;
|
|
310
|
+
midangle = midangle % (2 * Math.PI);
|
|
311
|
+
const xC = radius * 1.1 * (midangle < Math.PI ? 1 : -1);
|
|
312
|
+
const yC = posB[1];
|
|
313
|
+
return [posA, posB, [xC, yC]]
|
|
314
|
+
.map((point) => point.join(",")) // convert to "x,y"
|
|
315
|
+
.join(" "); // join as "x1,y1 x2,y2 x3,y3"
|
|
316
|
+
});
|
|
317
|
+
chartAreaTagG
|
|
318
|
+
.append("g")
|
|
319
|
+
.attr("transform", getPiePosition())
|
|
320
|
+
.selectAll("foreignObject")
|
|
321
|
+
.data(pieChartData.filter((d) => d.data.properties.dataLabelPosition == "2"))
|
|
322
|
+
.join("foreignObject")
|
|
323
|
+
.attr("width", 80)
|
|
324
|
+
.attr("height", 60)
|
|
325
|
+
.attr("x", (d) => {
|
|
326
|
+
let midangle = d.x0 + (d.x1 - d.x0) / 2;
|
|
327
|
+
midangle = midangle % (2 * Math.PI);
|
|
328
|
+
const textWidth = 80;
|
|
329
|
+
const xOffset = midangle < Math.PI ? 0 : -textWidth;
|
|
330
|
+
return radius * 1.1 * (midangle < Math.PI ? 1 : -1) + xOffset;
|
|
331
|
+
})
|
|
332
|
+
.attr("y", (d) => outerRadius.centroid(d)[1] - 30)
|
|
333
|
+
.append("xhtml:div")
|
|
334
|
+
.attr("hoverId", (d) => d.data.legend.replace(/ /g, "-"))
|
|
335
|
+
.style("display", "flex")
|
|
336
|
+
.style("flex-direction", "column")
|
|
337
|
+
.style("justify-content", "center")
|
|
338
|
+
.style("align-items", "center")
|
|
339
|
+
.style("height", "60px")
|
|
340
|
+
.html((d) => {
|
|
341
|
+
try {
|
|
342
|
+
let value = d.data.data[0].value.toString();
|
|
343
|
+
if (d.data.data[0].value !== undefined) {
|
|
344
|
+
value =
|
|
345
|
+
chartFormatOptions.plotArea.dataLabelNumberFormat === ",.0%"
|
|
346
|
+
? (Math.abs(d.data.data[0].value / pieTotalValue) * 100).toFixed(convertStringToNumber(chartFormatOptions.plotArea.dataLabelDecimalPrecision)) + "%"
|
|
347
|
+
: getNumberWithFormatFunction(chartFormatOptions.plotArea.plotAreaDisplayUnits, chartFormatOptions.plotArea.dataLabelNumberFormat, chartFormatOptions.plotArea.dataLabelDecimalPrecision)(d.data.data[0].value);
|
|
348
|
+
}
|
|
349
|
+
let htmlString = "";
|
|
350
|
+
if (chartFormatOptions.plotArea.dataLabelName) {
|
|
351
|
+
htmlString += `<span style="
|
|
352
|
+
font-size: ${d.data.properties.labelFontSize}px;
|
|
353
|
+
color: ${d.data.properties.labelFontColor};
|
|
354
|
+
font-style: ${d.data.properties.labelFontStyle.includes(fontStyleOptions.italic)
|
|
355
|
+
? fontStyleOptions.italic
|
|
356
|
+
: ""};
|
|
357
|
+
text-decoration: ${d.data.properties.labelFontStyle.includes(fontStyleOptions.underline)
|
|
358
|
+
? fontStyleOptions.underline
|
|
359
|
+
: ""};
|
|
360
|
+
font-weight: ${d.data.properties.labelFontStyle.includes(fontStyleOptions.bold)
|
|
361
|
+
? fontStyleOptions.bold
|
|
362
|
+
: ""};
|
|
363
|
+
font-family: ${d.data.properties.labelFont};
|
|
364
|
+
display: block; white-space: nowrap; width:80px; overflow:hidden; text-overflow:ellipsis; text-align: center;">
|
|
365
|
+
${d.data.legend}
|
|
366
|
+
</span>`;
|
|
367
|
+
}
|
|
368
|
+
if (chartFormatOptions.plotArea.dataLabelValue &&
|
|
369
|
+
d.data.data[0].value !== undefined) {
|
|
370
|
+
htmlString += `<span style="
|
|
371
|
+
font-size: ${d.data.properties.valueFontSize}px;
|
|
372
|
+
color: ${d.data.properties.valueFontColor};
|
|
373
|
+
font-style: ${d.data.properties.valueFontStyle.includes(fontStyleOptions.italic)
|
|
374
|
+
? fontStyleOptions.italic
|
|
375
|
+
: ""};
|
|
376
|
+
text-decoration: ${d.data.properties.valueFontStyle.includes(fontStyleOptions.underline)
|
|
377
|
+
? fontStyleOptions.underline
|
|
378
|
+
: ""};
|
|
379
|
+
font-weight: ${d.data.properties.valueFontStyle.includes(fontStyleOptions.bold)
|
|
380
|
+
? fontStyleOptions.bold
|
|
381
|
+
: "300"};
|
|
382
|
+
font-family: ${d.data.properties.valueFont};
|
|
383
|
+
display: block;">
|
|
384
|
+
${value}
|
|
385
|
+
</span>`;
|
|
386
|
+
}
|
|
387
|
+
if (chartFormatOptions.plotArea.plotAreaAbsoluteValue &&
|
|
388
|
+
d.data[0].value !== undefined) {
|
|
389
|
+
htmlString += `<span style="
|
|
390
|
+
font-size: ${d.data.properties.valueFontSize}px;
|
|
391
|
+
color: ${d.data.properties.valueFontColor};
|
|
392
|
+
font-style: ${d.data.properties.valueFontStyle.includes(fontStyleOptions.italic)
|
|
393
|
+
? fontStyleOptions.italic
|
|
394
|
+
: ""};
|
|
395
|
+
text-decoration: ${d.data.properties.valueFontStyle.includes(fontStyleOptions.underline)
|
|
396
|
+
? fontStyleOptions.underline
|
|
397
|
+
: ""};
|
|
398
|
+
font-weight: ${d.data.properties.valueFontStyle.includes(fontStyleOptions.bold)
|
|
399
|
+
? fontStyleOptions.bold
|
|
400
|
+
: "300"};
|
|
401
|
+
font-family: ${d.data.properties.valueFont};
|
|
402
|
+
display: block;">
|
|
403
|
+
${d3.format(".2s")(d.data[0].value)}
|
|
404
|
+
</span>`;
|
|
405
|
+
}
|
|
406
|
+
return htmlString;
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
logError(fileName, "drawDonutDataLabels", error);
|
|
410
|
+
return "";
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
catch (error) {
|
|
416
|
+
logError(fileName, "drawDonutDataLabels", error);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
const drawTotalValue = () => {
|
|
420
|
+
try {
|
|
421
|
+
if (chartFormatOptions.total &&
|
|
422
|
+
chartFormatOptions.total.totalVisibility) {
|
|
423
|
+
let total = pieTotalValue;
|
|
424
|
+
let fontStyle = chartFormatOptions.total.totalFontStyle;
|
|
425
|
+
chartAreaTagG
|
|
426
|
+
.append("g")
|
|
427
|
+
.attr("transform", getPiePosition())
|
|
428
|
+
.attr("pointer-events", "none")
|
|
429
|
+
.attr("text-anchor", "middle")
|
|
430
|
+
.append("text")
|
|
431
|
+
.style("fill", chartFormatOptions.total.totalColor !== "#ffffff"
|
|
432
|
+
? chartFormatOptions.total.totalColor
|
|
433
|
+
: "none")
|
|
434
|
+
.style("font-family", chartFormatOptions.total.totalFontFamily)
|
|
435
|
+
.style("font-size", chartFormatOptions.total.totalFontSize)
|
|
436
|
+
.style("font-style", fontStyle.includes(fontStyleOptions.italic)
|
|
437
|
+
? fontStyleOptions.italic
|
|
438
|
+
: "")
|
|
439
|
+
.style("text-decoration", fontStyle.includes(fontStyleOptions.underline)
|
|
440
|
+
? fontStyleOptions.underline
|
|
441
|
+
: "")
|
|
442
|
+
.style("font-weight", fontStyle.includes(fontStyleOptions.bold)
|
|
443
|
+
? fontStyleOptions.bold
|
|
444
|
+
: "")
|
|
445
|
+
.attr("text-anchor", "middle")
|
|
446
|
+
.attr("visibility", chartFormatOptions.plotArea.dataLabelValue ? "visible" : "hidden")
|
|
447
|
+
.text(chartFormatOptions.total.editTotalText)
|
|
448
|
+
.append("tspan")
|
|
449
|
+
.attr("x", 0)
|
|
450
|
+
.attr("y", "1.3em")
|
|
451
|
+
.attr("font-weight", fontStyle.includes(fontStyleOptions.bold)
|
|
452
|
+
? fontStyleOptions.bold
|
|
453
|
+
: 300)
|
|
454
|
+
// .attr("fill-opacity", 0.5)
|
|
455
|
+
.text(chartFormatOptions.total.totalNumberFormat === ",.0%" ||
|
|
456
|
+
chartFormatOptions.total.totalNumberFormat === "Percentage"
|
|
457
|
+
? "100%"
|
|
458
|
+
: getNumberWithFormatFunction(chartFormatOptions.total.totalDisplayUnits, chartFormatOptions.total.totalNumberFormat, chartFormatOptions.total.totalDecimalPrecision)(total));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
logError(fileName, "drawTotalValue", error);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
// return (
|
|
466
|
+
// <div style={{ width: "100%", height: "100%" }}>
|
|
467
|
+
// <svg
|
|
468
|
+
// className="chartSVG"
|
|
469
|
+
// style={{ width: "100%", height: "100%" }}
|
|
470
|
+
// ref={svgRef}
|
|
471
|
+
// ></svg>
|
|
472
|
+
// </div>
|
|
473
|
+
// );
|
|
474
|
+
return (_jsxs("div", { style: { width: "100%", height: "100%" }, children: [_jsx("div", { id: "chartTooltipDiv" }), _jsx("svg", { className: "chartSVG", ref: svgRef, id: chartId, style: { width: "100%", height: "100%" } })] }));
|
|
475
|
+
};
|
|
476
|
+
export default DonutChart;
|