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,608 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
//#region Imports
|
|
3
|
+
import * as d3 from "d3";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { logError } from "../../../../Services/ErrorLog";
|
|
6
|
+
import { staticLegendShape } from "../../Core/Common.types";
|
|
7
|
+
import { drawLegends, generalizedChartData, hideTooltipOnMouseOut, showTooltipOnMouseMove } from "../../Core/CommonFunctions";
|
|
8
|
+
import { addDataTable, customYscaleLabelFormatting, dataTablePreCalculation, firstFunctionBeforeRender, getNumberWithFormat, getStackedData, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis, marginCalculation, prepareDataForSeriesLabel, responsiveXaxisLabel, responsiveYaxisLabel, setChartTitle, setDateFormats, setXaxistitle, yAxistitle, yAxistitleRight } from "../ChartsWithAxisFunctions";
|
|
9
|
+
import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
|
|
10
|
+
const WaterfallChart = ({ title, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
|
|
11
|
+
// adding variables as per requirement
|
|
12
|
+
let columnWidth = 0; // coz line chartO
|
|
13
|
+
let colorScale;
|
|
14
|
+
const chartType = actualChartTypes.waterfall;
|
|
15
|
+
const svgRef = useRef();
|
|
16
|
+
const seriesData = generalizedChartData(data.ChartData, data.DimensionList);
|
|
17
|
+
const dimensionList = data.DimensionList;
|
|
18
|
+
const barChart = false;
|
|
19
|
+
const isSecondaryAxisDrawn = false;
|
|
20
|
+
const isNormalizedChart = false;
|
|
21
|
+
let isPrimaryAxisDrawn = true;
|
|
22
|
+
let customYaxisMinValue = parseFloat(formatOptions.yAxisLabel.yAxisMinText);
|
|
23
|
+
let customYaxisMaxValue = parseFloat(formatOptions.yAxisLabel.yAxisMaxText);
|
|
24
|
+
let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
|
|
25
|
+
let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
|
|
26
|
+
let margin;
|
|
27
|
+
let yLabel;
|
|
28
|
+
let xLabel;
|
|
29
|
+
let yTitle;
|
|
30
|
+
let xTitle;
|
|
31
|
+
let dimensionHeightWidthArray;
|
|
32
|
+
let chartTitleHeight;
|
|
33
|
+
let secondaryAxisTitleWidth;
|
|
34
|
+
let legendMargin;
|
|
35
|
+
let secondaryYLabel;
|
|
36
|
+
let maxNumberForPrimaryAxis;
|
|
37
|
+
let maxNumberForSecondaryAxis;
|
|
38
|
+
let innerWidth;
|
|
39
|
+
let innerHeight;
|
|
40
|
+
let width;
|
|
41
|
+
let height;
|
|
42
|
+
let dataTable;
|
|
43
|
+
let dataTableHeight;
|
|
44
|
+
let svg;
|
|
45
|
+
let gTag;
|
|
46
|
+
let yScaleLeft;
|
|
47
|
+
let yScaleRight;
|
|
48
|
+
let xScale;
|
|
49
|
+
let xScaleForLegends;
|
|
50
|
+
let seriesLabels;
|
|
51
|
+
let calculatedRange;
|
|
52
|
+
let seriesLabelWidth;
|
|
53
|
+
let yAxisLeft;
|
|
54
|
+
let xAxis;
|
|
55
|
+
let yAxisRight;
|
|
56
|
+
let filteredDimension;
|
|
57
|
+
let filteredData = [];
|
|
58
|
+
let waterFallData = [];
|
|
59
|
+
let stackTotalData;
|
|
60
|
+
let scrollPosition = 0;
|
|
61
|
+
const visibleBars = 2;
|
|
62
|
+
let chartJSON = {
|
|
63
|
+
dimensionList: dimensionList,
|
|
64
|
+
chartType: chartType,
|
|
65
|
+
chartData: [],
|
|
66
|
+
formatOptions: formatOptions,
|
|
67
|
+
legendList: [],
|
|
68
|
+
secondaryAxisDrawn: false,
|
|
69
|
+
yMaxLeft: 0,
|
|
70
|
+
yMaxRight: 0,
|
|
71
|
+
yMinLeft: 0,
|
|
72
|
+
yMinRight: 0,
|
|
73
|
+
hideZeroValues: false,
|
|
74
|
+
formattedDimensionListMap: new Map(),
|
|
75
|
+
};
|
|
76
|
+
//#region UseEffect
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
try {
|
|
79
|
+
createWaterfallChart();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
logError("WaterfallChart", "createWaterfallChart", error);
|
|
83
|
+
}
|
|
84
|
+
}, [formatOptions]);
|
|
85
|
+
//#endregion
|
|
86
|
+
const createWaterfallChart = () => {
|
|
87
|
+
({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
|
|
88
|
+
preProcessChartData(); // preaparing data related to chart creation
|
|
89
|
+
// Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
|
|
90
|
+
({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } = customYscaleLabelFormatting(
|
|
91
|
+
// for calculating primary/secondary axis max number so that we can calculate margin accordinglt
|
|
92
|
+
formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
|
|
93
|
+
({
|
|
94
|
+
margin,
|
|
95
|
+
yLabel,
|
|
96
|
+
xLabel,
|
|
97
|
+
yTitle,
|
|
98
|
+
xTitle,
|
|
99
|
+
dimensionHeightWidthArray,
|
|
100
|
+
chartTitleHeight,
|
|
101
|
+
secondaryAxisTitleWidth,
|
|
102
|
+
legendMargin,
|
|
103
|
+
secondaryYLabel,
|
|
104
|
+
} = marginCalculation(
|
|
105
|
+
// for all margin related calculations
|
|
106
|
+
width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart));
|
|
107
|
+
setSVGContainer(margin); // for innerWidth/height static width/height
|
|
108
|
+
({ dataTable, dataTableHeight } = dataTablePreCalculation(
|
|
109
|
+
// calculations for data tables
|
|
110
|
+
formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
|
|
111
|
+
initSvg(
|
|
112
|
+
// for svg creation
|
|
113
|
+
svg, width, height, formatOptions);
|
|
114
|
+
gTag = initChartArea(svg, margin); // creating chart area
|
|
115
|
+
initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
|
|
116
|
+
initScale();
|
|
117
|
+
initAxis();
|
|
118
|
+
initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
|
|
119
|
+
// initYaxisRight(
|
|
120
|
+
// gTag,
|
|
121
|
+
// formatOptions,
|
|
122
|
+
// dataTableHeight,
|
|
123
|
+
// secondaryYLabel,
|
|
124
|
+
// yAxisRight,
|
|
125
|
+
// innerHeight,
|
|
126
|
+
// innerWidth
|
|
127
|
+
// );
|
|
128
|
+
horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
|
|
129
|
+
if (formatOptions.dataTableProperties &&
|
|
130
|
+
formatOptions.dataTableProperties.dataTable) {
|
|
131
|
+
if (formatOptions.xAxisLabel.xAxisPosition != "1")
|
|
132
|
+
formatOptions.xAxisLabel.xAxisLabelVisibility = false;
|
|
133
|
+
addDataTable(formatOptions.plotArea.fitChart, svg, gTag, dataTable, columnWidth, yScaleLeft, xScale, xScaleForLegends, undefined, undefined, dataTableHeight, chartType, formatOptions, yLabel, yTitle, chartJSON.dimensionList, innerWidth, calculatedRange, chartJSON.formattedDimensionListMap, chartId, margin, innerHeight);
|
|
134
|
+
}
|
|
135
|
+
setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
|
|
136
|
+
yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
|
|
137
|
+
yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
|
|
138
|
+
setChartTitle(svg, formatOptions, width, chartTitleHeight);
|
|
139
|
+
drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, staticLegendShape.rectangle);
|
|
140
|
+
};
|
|
141
|
+
const preProcessChartData = () => {
|
|
142
|
+
const allChartData = [];
|
|
143
|
+
let formatedDimesionList = [];
|
|
144
|
+
seriesData.forEach((series) => {
|
|
145
|
+
series.data.forEach((point) => {
|
|
146
|
+
allChartData.push(point);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
150
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
151
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
filteredDimension = chartJSON.dimensionList;
|
|
155
|
+
}
|
|
156
|
+
if (formatOptions.plotArea.hideZeroValues) {
|
|
157
|
+
chartJSON.hideZeroValues = true;
|
|
158
|
+
}
|
|
159
|
+
let tempWaterfallChartData = generateWaterFallData();
|
|
160
|
+
// update data if Up/Down < 1.0 * e-9
|
|
161
|
+
let tempData = JSON.parse(JSON.stringify(tempWaterfallChartData));
|
|
162
|
+
tempWaterfallChartData.forEach(data => {
|
|
163
|
+
if (!data.Dimension && ((data.Up < 1e-9 && data.Up !== 0) || (data.Down < 1e-9 && data.Down !== 0))) {
|
|
164
|
+
let index = tempData.findIndex(dta => dta.Legend === data.Legend);
|
|
165
|
+
index !== -1 && tempData.splice(index, 1);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
tempWaterfallChartData = tempData;
|
|
169
|
+
tempWaterfallChartData.forEach((d) => d.dimension ? chartJSON.legendList.push(d.dimension) : chartJSON.legendList.push(d.legend));
|
|
170
|
+
waterFallData = d3.stack().keys(["base", "dimensionTotal", "up", "down"])(tempWaterfallChartData);
|
|
171
|
+
let tempArrayToFindYMax = [];
|
|
172
|
+
let tempDimensionList = [];
|
|
173
|
+
waterFallData.forEach(key => {
|
|
174
|
+
key.key == "base" ? (key["opacity"] = 0) : (key["opacity"] = 1);
|
|
175
|
+
key.forEach(data => tempArrayToFindYMax.push(data));
|
|
176
|
+
if (!tempDimensionList.includes(key.dimension) && key.dimensionTotal === 0 && key.total === 0)
|
|
177
|
+
tempDimensionList.push(key.dimension);
|
|
178
|
+
});
|
|
179
|
+
chartJSON.yMaxLeft = d3.max(tempArrayToFindYMax, (d) => d[1]);
|
|
180
|
+
chartJSON.yMinLeft = d3.min(tempArrayToFindYMax, (d) => d[1]);
|
|
181
|
+
if (formatOptions.xAxisLabel.hideZeroValues) {
|
|
182
|
+
if (tempDimensionList.length > 0) {
|
|
183
|
+
tempDimensionList.forEach(dimension => {
|
|
184
|
+
chartJSON.legendList = chartJSON.legendList.filter(dim => dim !== dimension);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
chartJSON.dimensionList = chartJSON.legendList;
|
|
188
|
+
}
|
|
189
|
+
// Apply formatted dimensions
|
|
190
|
+
let xAxisObject = xAxisObj[0];
|
|
191
|
+
formatedDimesionList =
|
|
192
|
+
(xAxisObject.groupBy == "NA" || xAxisObject.groupBy == undefined) &&
|
|
193
|
+
xAxisObject.dataType === "DATE"
|
|
194
|
+
? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d[0])
|
|
195
|
+
: chartJSON.dimensionList;
|
|
196
|
+
getFormattedDimensionList(tempWaterfallChartData, xAxisObject);
|
|
197
|
+
};
|
|
198
|
+
const getFormattedDimensionList = (tempWaterfallChartData, xAxisObject) => {
|
|
199
|
+
try {
|
|
200
|
+
let tempDimensionList = [];
|
|
201
|
+
let tempDimensionListWithIndex = [];
|
|
202
|
+
let tempFormatedDimesionList = [];
|
|
203
|
+
tempWaterfallChartData && tempWaterfallChartData.forEach((d, i) => {
|
|
204
|
+
if (d.dimension) {
|
|
205
|
+
tempDimensionList.push(d.dimension);
|
|
206
|
+
tempDimensionListWithIndex.push({ dimension: d.dimension, chartDataIndex: i, selfIndex: tempDimensionListWithIndex.length });
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
if ((xAxisObject.groupBy == "NA" || xAxisObject.groupBy == undefined) &&
|
|
210
|
+
xAxisObject.dataType === "DATE") {
|
|
211
|
+
tempFormatedDimesionList = setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d[0]);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
tempFormatedDimesionList = tempDimensionList;
|
|
215
|
+
}
|
|
216
|
+
let formatedDimesionList = JSON.parse(JSON.stringify(chartJSON.legendList));
|
|
217
|
+
tempDimensionListWithIndex.forEach((listItem, i) => {
|
|
218
|
+
formatedDimesionList[listItem.chartDataIndex] = tempFormatedDimesionList[listItem.selfIndex];
|
|
219
|
+
});
|
|
220
|
+
chartJSON.legendList.forEach((d, i) => {
|
|
221
|
+
chartJSON.formattedDimensionListMap.set(d, formatedDimesionList[i]);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const initScale = () => {
|
|
229
|
+
// rounding the ymin & ymax
|
|
230
|
+
let yAxisLabelArray = responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray;
|
|
231
|
+
chartJSON.yMaxLeft = yAxisLabelArray[yAxisLabelArray.length - 1];
|
|
232
|
+
chartJSON.yMinLeft = yAxisLabelArray[0];
|
|
233
|
+
if (isPrimaryAxisDrawn) {
|
|
234
|
+
yScaleLeft = d3
|
|
235
|
+
.scaleLinear()
|
|
236
|
+
.domain([
|
|
237
|
+
customYaxisMinValue !== undefined &&
|
|
238
|
+
!Number.isNaN(customYaxisMinValue)
|
|
239
|
+
? customYaxisMinValue
|
|
240
|
+
: chartJSON.yMinLeft < 0
|
|
241
|
+
? chartJSON.yMinLeft * 1.1
|
|
242
|
+
: chartJSON.yMinLeft * 0.9,
|
|
243
|
+
chartJSON.yMaxLeft <= 0
|
|
244
|
+
? 0
|
|
245
|
+
: customYaxisMaxValue !== undefined &&
|
|
246
|
+
!Number.isNaN(customYaxisMaxValue)
|
|
247
|
+
? customYaxisMaxValue
|
|
248
|
+
: chartJSON.yMaxLeft * 1.1,
|
|
249
|
+
])
|
|
250
|
+
.range([
|
|
251
|
+
dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
|
|
252
|
+
0,
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
calculatedRange = [0, innerWidth];
|
|
256
|
+
if (formatOptions.seriesLabel.seriesLabelVisibility) {
|
|
257
|
+
let labelObj = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, yScaleRight, isSecondaryAxisDrawn);
|
|
258
|
+
seriesLabels = labelObj.labelArray;
|
|
259
|
+
formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
|
|
260
|
+
(seriesLabelWidth = labelObj.heightWidth[0]);
|
|
261
|
+
formatOptions.seriesLabel.seriesLabelPosition == "Right"
|
|
262
|
+
? (calculatedRange = [0, innerWidth - labelObj.heightWidth[0]])
|
|
263
|
+
: (calculatedRange = [labelObj.heightWidth[0], innerWidth]);
|
|
264
|
+
}
|
|
265
|
+
getXScale();
|
|
266
|
+
};
|
|
267
|
+
const getXScale = () => {
|
|
268
|
+
columnWidth =
|
|
269
|
+
(0.51 + (0.61 * (100 - parseFloat(formatOptions.plotArea.plotAreaGapWidth))) / 100) *
|
|
270
|
+
(innerWidth / chartJSON.legendList.length);
|
|
271
|
+
xScale = d3
|
|
272
|
+
.scaleBand()
|
|
273
|
+
.domain(chartJSON.legendList)
|
|
274
|
+
.range(calculatedRange)
|
|
275
|
+
.padding(0.4);
|
|
276
|
+
};
|
|
277
|
+
const initAxis = () => {
|
|
278
|
+
getXAxis();
|
|
279
|
+
if (isPrimaryAxisDrawn) {
|
|
280
|
+
yAxisLeft = d3
|
|
281
|
+
.axisLeft(yScaleLeft)
|
|
282
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
|
|
283
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
284
|
+
? formatOptions.plotArea.gridLinesHorizontal
|
|
285
|
+
? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
|
|
286
|
+
: 0
|
|
287
|
+
: 0)
|
|
288
|
+
.tickValues(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray)
|
|
289
|
+
.ticks(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).customTickValue ??
|
|
290
|
+
(dataTableHeight > 0
|
|
291
|
+
? (innerHeight - dataTableHeight) / 30
|
|
292
|
+
: innerHeight / 30))
|
|
293
|
+
.tickSizeOuter(0);
|
|
294
|
+
}
|
|
295
|
+
colorScale = d3.scaleOrdinal().range([
|
|
296
|
+
"#E25A42",
|
|
297
|
+
formatOptions.plotArea.totalColor,
|
|
298
|
+
formatOptions.plotArea.positiveColor,
|
|
299
|
+
formatOptions.plotArea.negativeColor,
|
|
300
|
+
]);
|
|
301
|
+
};
|
|
302
|
+
const getXAxis = () => {
|
|
303
|
+
xAxis = d3
|
|
304
|
+
.axisBottom(xScale)
|
|
305
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
306
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
307
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
308
|
+
? -(dataTableHeight > 0
|
|
309
|
+
? innerHeight - dataTableHeight
|
|
310
|
+
: innerHeight)
|
|
311
|
+
: parseFloat(formatOptions.plotArea.ticksHeight) *
|
|
312
|
+
((dataTableHeight > 0
|
|
313
|
+
? innerHeight - dataTableHeight
|
|
314
|
+
: innerHeight) /
|
|
315
|
+
100) *
|
|
316
|
+
(formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
|
|
317
|
+
: 0
|
|
318
|
+
: 0)
|
|
319
|
+
.tickSizeOuter(0)
|
|
320
|
+
.tickValues(responsiveXaxisLabel(chartJSON.legendList, innerWidth));
|
|
321
|
+
};
|
|
322
|
+
const getChartType = (lineData) => {
|
|
323
|
+
let totalStackData;
|
|
324
|
+
waterFallData.forEach((K, j) => K.forEach((d) => (d["key"] = K.key)));
|
|
325
|
+
if (stackTotalData) {
|
|
326
|
+
let stackDataLegendList = filteredData.map(name => name.legend);
|
|
327
|
+
// chartJSON.legendList = stackDataLegendList;
|
|
328
|
+
totalStackData = d3.stack().keys(stackDataLegendList)(stackTotalData);
|
|
329
|
+
totalStackData.forEach((d, i) => {
|
|
330
|
+
totalStackData[i]["color"] = filteredData[i].properties.color;
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
totalStackData && totalStackData.forEach(data => {
|
|
334
|
+
data.forEach(j => {
|
|
335
|
+
j["Key"] = data.key;
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
// Bind dummy data to ensure a single group is created
|
|
339
|
+
// Step 1: Loop over the two passes (0 and 1)
|
|
340
|
+
[0, 1].forEach(k => {
|
|
341
|
+
if (k === 1)
|
|
342
|
+
waterFallData = totalStackData;
|
|
343
|
+
if (waterFallData) {
|
|
344
|
+
// OUTER JOIN: parent group for the full waterfall chart
|
|
345
|
+
let parentGroup = gTag
|
|
346
|
+
.selectAll(`.parentGroup-${k}`)
|
|
347
|
+
.data([null]); // dummy single-element array
|
|
348
|
+
parentGroup = parentGroup
|
|
349
|
+
.enter()
|
|
350
|
+
.append("g")
|
|
351
|
+
.attr("class", `parentGroup parentGroup-${k}`)
|
|
352
|
+
.merge(parentGroup);
|
|
353
|
+
// INNER JOIN: join to each bar stack group
|
|
354
|
+
let barGroups = parentGroup
|
|
355
|
+
.selectAll(`.bar-group-${k}`)
|
|
356
|
+
.data(waterFallData);
|
|
357
|
+
const barGroupsEnter = barGroups
|
|
358
|
+
.enter()
|
|
359
|
+
.append("g")
|
|
360
|
+
.attr("class", `bar-group-${k}`)
|
|
361
|
+
.attr("fill", d => d.color ? d.color : colorScale(d.key) !== "#ffffff" ? colorScale(d.key) : "none")
|
|
362
|
+
.attr("opacity", d => d.opacity);
|
|
363
|
+
barGroups = barGroupsEnter.merge(barGroups);
|
|
364
|
+
// JOIN rects inside each bar group
|
|
365
|
+
let rects = barGroups
|
|
366
|
+
.selectAll("rect")
|
|
367
|
+
.data(d => d, d => d.key || d.Key);
|
|
368
|
+
const rectsEnter = rects
|
|
369
|
+
.enter()
|
|
370
|
+
.append("rect")
|
|
371
|
+
.attr("class", "rect")
|
|
372
|
+
.attr("class", d => d.key ? d.key.replace(/ /g, "-") : d.Key.replace(/ /g, "-"))
|
|
373
|
+
.attr("x", d => xScale(d.data.dimension || d.data.legend))
|
|
374
|
+
.attr("y", d => d[1] ? yScaleLeft(d[1]) : 0)
|
|
375
|
+
.attr("height", d => d[1] ? (yScaleLeft(d[0]) - yScaleLeft(d[1])) : 0)
|
|
376
|
+
.attr("width", xScale.bandwidth())
|
|
377
|
+
.attr("visibility", d => k === 0 && d.data.dimension && stackTotalData ? "hidden" : "visible")
|
|
378
|
+
.style("shape-rendering", "crispEdges")
|
|
379
|
+
.on("mousemove", (event, d) => {
|
|
380
|
+
showTooltipOnMouseMove([
|
|
381
|
+
{
|
|
382
|
+
key: d.key === "dimensionTotal" ? "Dimension" : formatOptions.xAxisTitle.xAxisTitleText,
|
|
383
|
+
value: chartJSON.formattedDimensionListMap.get(d.data.dimension),
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
key: formatOptions.yAxisTitle.yAxisTitleText,
|
|
387
|
+
value: (d.key === "up" ? "+" : d.key === "down" ? "-" : "") +
|
|
388
|
+
getNumberWithFormat(d.key === "dimensionTotal" ? d.data.dimensionTotal : d[1] - d[0], formatOptions.toolTip.toolTipDisplayUnits, formatOptions.toolTip.toolTipNumberFormat, formatOptions.toolTip.toolTipDecimalPrecision),
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
key: "Legend",
|
|
392
|
+
value: d.Key
|
|
393
|
+
? d.Key.includes("~$~")
|
|
394
|
+
? d.Key.split("~$~")[1]
|
|
395
|
+
: d.Key
|
|
396
|
+
: d.data.legend
|
|
397
|
+
? d.data.legend.includes("~$~")
|
|
398
|
+
? d.data.legend.split("~$~")[1]
|
|
399
|
+
: d.data.legend
|
|
400
|
+
: "Total",
|
|
401
|
+
},
|
|
402
|
+
], formatOptions);
|
|
403
|
+
})
|
|
404
|
+
.on("mouseout", () => {
|
|
405
|
+
hideTooltipOnMouseOut();
|
|
406
|
+
});
|
|
407
|
+
rects.exit().remove();
|
|
408
|
+
rects = rectsEnter.merge(rects);
|
|
409
|
+
// // LABELS (if enabled)
|
|
410
|
+
if (formatOptions.plotArea.plotAreaDataLabel == "2" && k != 1) {
|
|
411
|
+
const textGroups = barGroups
|
|
412
|
+
.selectAll("text")
|
|
413
|
+
.data(d => d);
|
|
414
|
+
const textEnter = textGroups
|
|
415
|
+
.enter()
|
|
416
|
+
.append("text")
|
|
417
|
+
.text(d => getNumberWithFormat(d[1] - d[0], formatOptions.plotArea.plotAreaDisplayUnits, formatOptions.plotArea.dataLabelNumberFormat, formatOptions.plotArea.dataLabelDecimalPrecision))
|
|
418
|
+
.attr("x", d => xScale(d.data.dimension || d.data.legend) + columnWidth / 2)
|
|
419
|
+
.attr("y", d => d[1] ? yScaleLeft(d[1]) - 15 : 0)
|
|
420
|
+
.style("font-size", "11px")
|
|
421
|
+
.attr("text-anchor", "middle")
|
|
422
|
+
.attr("visibility", d => (d[1] - d[0]) !== 0 && yScaleLeft(d[1]) ? "visible" : "hidden");
|
|
423
|
+
textGroups.exit().remove();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
const setSVGContainer = (margin) => {
|
|
429
|
+
innerWidth = width - margin.left - margin.right;
|
|
430
|
+
innerHeight = height - margin.bottom - margin.top;
|
|
431
|
+
};
|
|
432
|
+
const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
|
|
433
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
434
|
+
// Scrollbar parameters
|
|
435
|
+
const scrollMax = seriesData[0].data.length - visibleBars;
|
|
436
|
+
// Scrollbar track & handle
|
|
437
|
+
const scrollbarY = height - 20;
|
|
438
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
439
|
+
getXScale();
|
|
440
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
441
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
442
|
+
getXAxis();
|
|
443
|
+
svg
|
|
444
|
+
.append("rect")
|
|
445
|
+
.attr("x", margin.left)
|
|
446
|
+
.attr("y", scrollbarY)
|
|
447
|
+
.attr("width", innerWidth)
|
|
448
|
+
.attr("height", 8)
|
|
449
|
+
.attr("fill", "#ddd")
|
|
450
|
+
.attr("rx", 4);
|
|
451
|
+
const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
|
|
452
|
+
const handle = svg
|
|
453
|
+
.append("rect")
|
|
454
|
+
.attr("x", margin.left)
|
|
455
|
+
.attr("y", scrollbarY)
|
|
456
|
+
.attr("width", handleWidth)
|
|
457
|
+
.attr("height", 8)
|
|
458
|
+
.attr("fill", "#999")
|
|
459
|
+
.attr("rx", 4)
|
|
460
|
+
.style("cursor", "ew-resize")
|
|
461
|
+
.call(d3.drag().on("drag", (event) => {
|
|
462
|
+
let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
|
|
463
|
+
handle.attr("x", x);
|
|
464
|
+
scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
|
|
465
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
466
|
+
getXScale();
|
|
467
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
468
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
469
|
+
getXAxis();
|
|
470
|
+
drawColumnChart();
|
|
471
|
+
}));
|
|
472
|
+
svg.on("wheel", (event) => {
|
|
473
|
+
event.preventDefault();
|
|
474
|
+
const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
|
|
475
|
+
? event.deltaX
|
|
476
|
+
: event.deltaY;
|
|
477
|
+
scrollPosition += scrollDelta > 0 ? 1 : -1;
|
|
478
|
+
scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
|
|
479
|
+
const x = margin.left +
|
|
480
|
+
((innerWidth - handleWidth) * scrollPosition) / scrollMax;
|
|
481
|
+
handle.attr("x", x);
|
|
482
|
+
getXScale();
|
|
483
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
484
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
485
|
+
getXAxis();
|
|
486
|
+
drawColumnChart();
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
drawColumnChart();
|
|
490
|
+
};
|
|
491
|
+
const drawColumnChart = () => {
|
|
492
|
+
getChartType(filteredData);
|
|
493
|
+
initXaxis(gTag, chartJSON, xLabel, formatOptions, xAxisObj[0], dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, columnWidth, xAxisObj[0].dataType, innerWidth, innerHeight, chartJSON.legendList);
|
|
494
|
+
// commonAnnotations(
|
|
495
|
+
// seriesData,
|
|
496
|
+
// xScale,
|
|
497
|
+
// yScaleLeft,
|
|
498
|
+
// yScaleRight, // need to pass secondary axis scale if secondary axis is drawn
|
|
499
|
+
// margin,
|
|
500
|
+
// d3Annotation,
|
|
501
|
+
// [], //labelExcludeList,
|
|
502
|
+
// [], //individualLabelColor,
|
|
503
|
+
// [], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
|
|
504
|
+
// formatOptions,
|
|
505
|
+
// chartType,
|
|
506
|
+
// height,
|
|
507
|
+
// width,
|
|
508
|
+
// innerWidth,
|
|
509
|
+
// filteredDimension,
|
|
510
|
+
// innerHeight,
|
|
511
|
+
// chartId,
|
|
512
|
+
// svg,
|
|
513
|
+
// xScaleForLegends,
|
|
514
|
+
// columnWidth
|
|
515
|
+
// );
|
|
516
|
+
};
|
|
517
|
+
const generateWaterFallData = () => {
|
|
518
|
+
try {
|
|
519
|
+
if (seriesData.length < 1)
|
|
520
|
+
return [];
|
|
521
|
+
if (chartJSON.dimensionList.length < 2)
|
|
522
|
+
return [];
|
|
523
|
+
let tempWaterFallData = [];
|
|
524
|
+
let dataRequiredForWaterfall = []; //JSON.parse(JSON.stringify(chartData));
|
|
525
|
+
let dataRequiredForStackTotal = []; //JSON.parse(JSON.stringify(chartData));
|
|
526
|
+
let seriesSlice = yAxisObj[0].legendData;
|
|
527
|
+
if (seriesSlice.length > 1) {
|
|
528
|
+
// seriesSlice.forEach(key => {
|
|
529
|
+
let tempSliceArr = seriesSlice[0].actualName;
|
|
530
|
+
seriesData.forEach(entry => {
|
|
531
|
+
if (tempSliceArr === entry.properties.currentLegend) {
|
|
532
|
+
dataRequiredForWaterfall.push(entry);
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
dataRequiredForStackTotal.push(entry);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
if (dataRequiredForWaterfall.length > 0) {
|
|
540
|
+
filteredData = dataRequiredForWaterfall;
|
|
541
|
+
}
|
|
542
|
+
let sum = 0;
|
|
543
|
+
let tempC = 0;
|
|
544
|
+
for (let i = 0; i < filteredData.length; ++i) {
|
|
545
|
+
sum = sum + filteredData[i].data[0].value;
|
|
546
|
+
}
|
|
547
|
+
let str = "";
|
|
548
|
+
for (let j = 1; j < filteredDimension.length; ++j) {
|
|
549
|
+
let waterFallArr1 = {};
|
|
550
|
+
waterFallArr1["dimension"] = filteredDimension[j - 1]; //2013
|
|
551
|
+
waterFallArr1["total"] = sum;
|
|
552
|
+
waterFallArr1["base"] = 0;
|
|
553
|
+
waterFallArr1["dimensionTotal"] = sum;
|
|
554
|
+
waterFallArr1["up"] = 0;
|
|
555
|
+
waterFallArr1["down"] = 0;
|
|
556
|
+
tempWaterFallData.push(waterFallArr1);
|
|
557
|
+
for (let k = 0; k < filteredData.length; ++k) {
|
|
558
|
+
let waterFallArr = {};
|
|
559
|
+
for (let x = 0; x < k; x++) {
|
|
560
|
+
str = str + " ";
|
|
561
|
+
}
|
|
562
|
+
tempC =
|
|
563
|
+
filteredData[k].data[j].value -
|
|
564
|
+
filteredData[k].data[j - 1].value;
|
|
565
|
+
if (tempC !== 0) {
|
|
566
|
+
waterFallArr["legend"] =
|
|
567
|
+
str + filteredData[k].properties.legend;
|
|
568
|
+
waterFallArr["dimensionTotal"] = 0;
|
|
569
|
+
if (tempC < 0) {
|
|
570
|
+
waterFallArr["base"] = sum + tempC;
|
|
571
|
+
waterFallArr["down"] = -tempC;
|
|
572
|
+
waterFallArr["up"] = 0;
|
|
573
|
+
waterFallArr["total"] = sum - tempC;
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
waterFallArr["base"] = sum;
|
|
577
|
+
waterFallArr["down"] = 0;
|
|
578
|
+
waterFallArr["up"] = tempC;
|
|
579
|
+
waterFallArr["total"] = sum + tempC;
|
|
580
|
+
}
|
|
581
|
+
sum = sum + tempC;
|
|
582
|
+
tempWaterFallData.push(waterFallArr);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// }
|
|
586
|
+
}
|
|
587
|
+
//last dimension entry
|
|
588
|
+
let waterFallArr2 = {};
|
|
589
|
+
waterFallArr2["dimension"] = filteredDimension[filteredDimension.length - 1];
|
|
590
|
+
waterFallArr2["dimensionTotal"] = sum;
|
|
591
|
+
waterFallArr2["base"] = 0;
|
|
592
|
+
waterFallArr2["total"] = sum;
|
|
593
|
+
waterFallArr2["up"] = 0;
|
|
594
|
+
waterFallArr2["down"] = 0;
|
|
595
|
+
tempWaterFallData.push(waterFallArr2);
|
|
596
|
+
if (dataRequiredForStackTotal.length > 0) {
|
|
597
|
+
filteredData = dataRequiredForStackTotal;
|
|
598
|
+
stackTotalData = getStackedData(filteredDimension, dataRequiredForStackTotal, false);
|
|
599
|
+
}
|
|
600
|
+
return tempWaterFallData;
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
throw error;
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
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%" } })] }));
|
|
607
|
+
};
|
|
608
|
+
export default WaterfallChart;
|
|
File without changes
|
|
File without changes
|