pace-chart-lib 0.0.7 → 0.0.8
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,1014 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
//#region Imports
|
|
3
|
+
import * as d3 from "d3";
|
|
4
|
+
import * as d3Annotation from "d3-svg-annotation";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import { logError } from "../../../../Services/ErrorLog";
|
|
7
|
+
import { drawLegends, generalizedChartData, hideTooltipOnMouseOut, lineMarkers, onHoverMarkerForAreaChartFamily, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
|
|
8
|
+
import { addDataTable, customYscaleLabelFormatting, dataTablePreCalculation, firstFunctionBeforeRender, getNumberWithFormat, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis, initYaxisRight, marginCalculation, prepareDataForSeriesLabel, responsiveSecondaryYaxisLabel, responsiveXaxisLabel, responsiveYaxisLabel, setChartTitle, setDateFormats, setXaxistitle, yAxistitle, yAxistitleRight, getCurveType, getStackedData, commonAnnotationsForCustomChart, } from "../ChartsWithAxisFunctions";
|
|
9
|
+
import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
|
|
10
|
+
import { staticLineStyle, } from "../../Core/Common.types";
|
|
11
|
+
const CustomColumnChart = ({ title, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
|
|
12
|
+
// adding variables as per requirement
|
|
13
|
+
let columnWidth = 0; // for column width calculation
|
|
14
|
+
let stackChartData = [];
|
|
15
|
+
const chartType = actualChartTypes.customColumnChart;
|
|
16
|
+
const svgRef = useRef();
|
|
17
|
+
const seriesData = generalizedChartData(data.ChartData, data.DimensionList);
|
|
18
|
+
const dimensionList = data.DimensionList;
|
|
19
|
+
const barChart = false;
|
|
20
|
+
let isSecondaryAxisDrawn = false;
|
|
21
|
+
const isNormalizedChart = false;
|
|
22
|
+
let isPrimaryAxisDrawn = true;
|
|
23
|
+
let customYaxisMinValue = parseFloat(formatOptions.yAxisLabel.yAxisMinText);
|
|
24
|
+
let customYaxisMaxValue = parseFloat(formatOptions.yAxisLabel.yAxisMaxText);
|
|
25
|
+
let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
|
|
26
|
+
let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
|
|
27
|
+
let margin;
|
|
28
|
+
let yLabel;
|
|
29
|
+
let xLabel;
|
|
30
|
+
let yTitle;
|
|
31
|
+
let xTitle;
|
|
32
|
+
let dimensionHeightWidthArray;
|
|
33
|
+
let chartTitleHeight;
|
|
34
|
+
let secondaryAxisTitleWidth;
|
|
35
|
+
let legendMargin;
|
|
36
|
+
let secondaryYLabel;
|
|
37
|
+
let maxNumberForPrimaryAxis;
|
|
38
|
+
let maxNumberForSecondaryAxis;
|
|
39
|
+
let innerWidth;
|
|
40
|
+
let innerHeight;
|
|
41
|
+
let width;
|
|
42
|
+
let height;
|
|
43
|
+
let dataTable;
|
|
44
|
+
let dataTableHeight;
|
|
45
|
+
let svg;
|
|
46
|
+
let gTag;
|
|
47
|
+
let yScaleLeft;
|
|
48
|
+
let yScaleRight;
|
|
49
|
+
let xScale;
|
|
50
|
+
let xScaleForLegends;
|
|
51
|
+
let seriesLabels;
|
|
52
|
+
let calculatedRange;
|
|
53
|
+
let seriesLabelWidth;
|
|
54
|
+
let stackAreaChartDataForPrimaryAxis = [];
|
|
55
|
+
let stackAreaChartDataForSecondaryAxis = [];
|
|
56
|
+
let stackColumnChartDataForPrimaryAxis = [];
|
|
57
|
+
let stackColumnChartDataForSecondaryAxis = [];
|
|
58
|
+
let primaryStackAxisData = [];
|
|
59
|
+
let secondaryStackAxisData = [];
|
|
60
|
+
let primaryStackAreaAxisData = [];
|
|
61
|
+
let primaryStackColumnAxisData = [];
|
|
62
|
+
let secondaryStackAreaAxisData = [];
|
|
63
|
+
let secondaryStackColumnAxisData = [];
|
|
64
|
+
let stackColumnData = [];
|
|
65
|
+
let stackAreaData = [];
|
|
66
|
+
let yAxisLeft;
|
|
67
|
+
let xAxis;
|
|
68
|
+
let yAxisRight;
|
|
69
|
+
let filteredDimension;
|
|
70
|
+
let filteredData = [];
|
|
71
|
+
let requiredData = [];
|
|
72
|
+
let scrollPosition = 0;
|
|
73
|
+
const visibleBars = 2;
|
|
74
|
+
let chartJSON = {
|
|
75
|
+
dimensionList: dimensionList,
|
|
76
|
+
chartType: chartType,
|
|
77
|
+
chartData: [],
|
|
78
|
+
formatOptions: formatOptions,
|
|
79
|
+
legendList: [],
|
|
80
|
+
secondaryAxisDrawn: false,
|
|
81
|
+
yMaxLeft: 0,
|
|
82
|
+
yMaxRight: 0,
|
|
83
|
+
yMinLeft: 0,
|
|
84
|
+
yMinRight: 0,
|
|
85
|
+
hideZeroValues: false,
|
|
86
|
+
formattedDimensionListMap: new Map(),
|
|
87
|
+
};
|
|
88
|
+
//#region UseEffect
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
try {
|
|
91
|
+
createCustomColumnChart();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
logError("CustomColumnchart", "createCustomColumnChart", error);
|
|
95
|
+
}
|
|
96
|
+
}, [formatOptions]);
|
|
97
|
+
//#endregion
|
|
98
|
+
const createCustomColumnChart = () => {
|
|
99
|
+
({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
|
|
100
|
+
preProcessChartData(); // preaparing data related to chart creation
|
|
101
|
+
// Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
|
|
102
|
+
({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } =
|
|
103
|
+
customYscaleLabelFormatting(
|
|
104
|
+
// for calculating primary/secondary axis max number so that we can calculate margin accordinglt
|
|
105
|
+
formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
|
|
106
|
+
({
|
|
107
|
+
margin,
|
|
108
|
+
yLabel,
|
|
109
|
+
xLabel,
|
|
110
|
+
yTitle,
|
|
111
|
+
xTitle,
|
|
112
|
+
dimensionHeightWidthArray,
|
|
113
|
+
chartTitleHeight,
|
|
114
|
+
secondaryAxisTitleWidth,
|
|
115
|
+
legendMargin,
|
|
116
|
+
secondaryYLabel,
|
|
117
|
+
} = marginCalculation(
|
|
118
|
+
// for all margin related calculations
|
|
119
|
+
width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart));
|
|
120
|
+
setSVGContainer(margin); // for innerWidth/height static width/height
|
|
121
|
+
({ dataTable, dataTableHeight } = dataTablePreCalculation(
|
|
122
|
+
// calculations for data tables
|
|
123
|
+
formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
|
|
124
|
+
initSvg(
|
|
125
|
+
// for svg creation
|
|
126
|
+
svg, width, height, formatOptions);
|
|
127
|
+
gTag = initChartArea(svg, margin); // creating chart area
|
|
128
|
+
initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
|
|
129
|
+
initScale();
|
|
130
|
+
initAxis();
|
|
131
|
+
initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
|
|
132
|
+
if (isSecondaryAxisDrawn) {
|
|
133
|
+
initYaxisRight(gTag, formatOptions, dataTableHeight, secondaryYLabel, yAxisRight, innerHeight, innerWidth);
|
|
134
|
+
}
|
|
135
|
+
horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
|
|
136
|
+
if (formatOptions.dataTableProperties &&
|
|
137
|
+
formatOptions.dataTableProperties.dataTable) {
|
|
138
|
+
if (formatOptions.xAxisLabel.xAxisPosition != "1")
|
|
139
|
+
formatOptions.xAxisLabel.xAxisLabelVisibility = false;
|
|
140
|
+
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);
|
|
141
|
+
}
|
|
142
|
+
setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
|
|
143
|
+
yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
|
|
144
|
+
yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
|
|
145
|
+
setChartTitle(svg, formatOptions, width, chartTitleHeight);
|
|
146
|
+
drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, null
|
|
147
|
+
// legendShape.rectangle
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
const preProcessChartData = () => {
|
|
151
|
+
const allChartData = [];
|
|
152
|
+
const legendList = [];
|
|
153
|
+
let formatedDimesionList = [];
|
|
154
|
+
let yMaxLeft = -Infinity;
|
|
155
|
+
let yMinLeft = Infinity;
|
|
156
|
+
let yMaxRight = -Infinity;
|
|
157
|
+
let yMinRight = Infinity;
|
|
158
|
+
let tempChartData = [];
|
|
159
|
+
seriesData.forEach((series, i) => {
|
|
160
|
+
if (![actualChartTypes.stackColumn, actualChartTypes.stackArea].includes(series.properties.type)) {
|
|
161
|
+
tempChartData.push(series);
|
|
162
|
+
series.properties.type !== actualChartTypes.line &&
|
|
163
|
+
legendList.push(series.legend);
|
|
164
|
+
}
|
|
165
|
+
else if (!legendList.includes("stackLegend")) {
|
|
166
|
+
legendList.push(`stackLegend`);
|
|
167
|
+
}
|
|
168
|
+
// Determine stack chart data for both axes
|
|
169
|
+
if (series.properties.axis === "Secondary") {
|
|
170
|
+
secondaryStackAxisData.push(series);
|
|
171
|
+
if (series.properties.type == actualChartTypes.stackColumn) {
|
|
172
|
+
secondaryStackColumnAxisData.push(series);
|
|
173
|
+
}
|
|
174
|
+
if (series.properties.type == actualChartTypes.stackArea) {
|
|
175
|
+
secondaryStackAreaAxisData.push(series);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (series.properties.axis === "Primary") {
|
|
179
|
+
primaryStackAxisData.push(series);
|
|
180
|
+
if (series.properties.type == actualChartTypes.stackColumn) {
|
|
181
|
+
primaryStackColumnAxisData.push(series);
|
|
182
|
+
}
|
|
183
|
+
if (series.properties.type == actualChartTypes.stackArea) {
|
|
184
|
+
primaryStackAreaAxisData.push(series);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//to determine Y min/max values
|
|
188
|
+
series.data.forEach((point) => {
|
|
189
|
+
// add chart type for individual series
|
|
190
|
+
point.type = series.properties.type;
|
|
191
|
+
point.axis = series.properties.axis;
|
|
192
|
+
point.labelPosition = series.properties.dataLabelPosition;
|
|
193
|
+
point.labelColor = series.properties.labelColor;
|
|
194
|
+
allChartData.push(point);
|
|
195
|
+
if (series.properties.axis === "Secondary") {
|
|
196
|
+
isSecondaryAxisDrawn = true;
|
|
197
|
+
yMaxRight = Math.max(yMaxRight, point.value);
|
|
198
|
+
yMinRight = Math.min(yMinRight, point.value);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
yMaxLeft = Math.max(yMaxLeft, point.value);
|
|
202
|
+
yMinLeft = Math.min(yMinLeft, point.value);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
chartJSON.chartData = tempChartData;
|
|
207
|
+
chartJSON.legendList = legendList;
|
|
208
|
+
chartJSON.yMaxLeft = yMaxLeft;
|
|
209
|
+
chartJSON.yMinLeft = yMinLeft;
|
|
210
|
+
chartJSON.yMaxRight = yMaxRight;
|
|
211
|
+
chartJSON.yMinRight = yMinRight;
|
|
212
|
+
// Apply formatted dimensions
|
|
213
|
+
let xAxisObject = xAxisObj[0];
|
|
214
|
+
formatedDimesionList =
|
|
215
|
+
(xAxisObject.groupBy == "NA" || xAxisObject.groupBy == undefined) &&
|
|
216
|
+
xAxisObject.dataType === "DATE"
|
|
217
|
+
? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d[0])
|
|
218
|
+
: chartJSON.dimensionList;
|
|
219
|
+
chartJSON.dimensionList.forEach((dim, i) => {
|
|
220
|
+
chartJSON.formattedDimensionListMap.set(dim, formatedDimesionList[i]);
|
|
221
|
+
});
|
|
222
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
223
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
filteredDimension = chartJSON.dimensionList;
|
|
227
|
+
}
|
|
228
|
+
if (formatOptions.plotArea.hideZeroValues) {
|
|
229
|
+
chartJSON.hideZeroValues = true;
|
|
230
|
+
}
|
|
231
|
+
// check and add data to filteredData for stack type charts
|
|
232
|
+
checkAndupdateInputData(primaryStackAreaAxisData, primaryStackColumnAxisData, secondaryStackAreaAxisData, secondaryStackColumnAxisData);
|
|
233
|
+
// check and update ymax values if stack chart is present w.r.t axes
|
|
234
|
+
if (primaryStackAxisData.length > 0) {
|
|
235
|
+
let valueArray = [];
|
|
236
|
+
let stackDataForPrimaryAxis = getStackedData(filteredDimension, primaryStackAxisData, false);
|
|
237
|
+
stackDataForPrimaryAxis.forEach((d) => {
|
|
238
|
+
valueArray.push(d.total);
|
|
239
|
+
});
|
|
240
|
+
chartJSON.yMaxLeft = Math.max(chartJSON.yMaxLeft, Math.max(...valueArray));
|
|
241
|
+
chartJSON.yMinLeft = Math.min(chartJSON.yMinLeft, Math.min(...valueArray));
|
|
242
|
+
}
|
|
243
|
+
if (secondaryStackAxisData.length > 0) {
|
|
244
|
+
let valueArray = [];
|
|
245
|
+
let stackDataForSecondaryAxis = getStackedData(filteredDimension, secondaryStackAxisData, false);
|
|
246
|
+
stackDataForSecondaryAxis.forEach((d) => {
|
|
247
|
+
valueArray.push(d.total);
|
|
248
|
+
});
|
|
249
|
+
chartJSON.yMaxRight = Math.max(chartJSON.yMaxRight, Math.max(...valueArray));
|
|
250
|
+
chartJSON.yMinRight = Math.min(chartJSON.yMinRight, Math.min(...valueArray));
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const checkAndupdateInputData = (primaryStackAreaAxisData, primaryStackColumnAxisData, secondaryStackAreaAxisData, secondaryStackColumnAxisData) => {
|
|
254
|
+
let tempStackAreaChartDataForPrimaryAxis = getStackedData(filteredDimension, primaryStackAreaAxisData, false);
|
|
255
|
+
let tempStackAreaChartDataForSecondaryAxis = getStackedData(filteredDimension, secondaryStackAreaAxisData, false);
|
|
256
|
+
let tempStackColumnChartDataForPrimaryAxis = getStackedData(filteredDimension, primaryStackColumnAxisData, false);
|
|
257
|
+
let tempStackColumnChartDataForSecondaryAxis = getStackedData(filteredDimension, secondaryStackColumnAxisData, false);
|
|
258
|
+
requiredData = [];
|
|
259
|
+
stackAreaChartDataForPrimaryAxis = [];
|
|
260
|
+
stackAreaChartDataForSecondaryAxis = [];
|
|
261
|
+
stackColumnChartDataForPrimaryAxis = [];
|
|
262
|
+
stackColumnChartDataForSecondaryAxis = [];
|
|
263
|
+
// appending addtional properties to stack area chart data
|
|
264
|
+
if (primaryStackAreaAxisData.length) {
|
|
265
|
+
primaryStackAreaAxisData.forEach((d) => {
|
|
266
|
+
stackAreaChartDataForPrimaryAxis.push({
|
|
267
|
+
properties: {
|
|
268
|
+
axis: d.properties.axis,
|
|
269
|
+
type: d.properties.type,
|
|
270
|
+
legend: d.properties.legend,
|
|
271
|
+
},
|
|
272
|
+
stackData: tempStackAreaChartDataForPrimaryAxis,
|
|
273
|
+
data: primaryStackAreaAxisData,
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (secondaryStackAreaAxisData.length) {
|
|
278
|
+
secondaryStackAreaAxisData.forEach((d) => {
|
|
279
|
+
stackAreaChartDataForSecondaryAxis.push({
|
|
280
|
+
properties: {
|
|
281
|
+
axis: d.properties.axis,
|
|
282
|
+
type: d.properties.type,
|
|
283
|
+
legend: d.properties.legend,
|
|
284
|
+
},
|
|
285
|
+
stackData: tempStackAreaChartDataForSecondaryAxis,
|
|
286
|
+
data: secondaryStackAreaAxisData,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (primaryStackColumnAxisData.length) {
|
|
291
|
+
primaryStackColumnAxisData.forEach((d) => {
|
|
292
|
+
stackAreaChartDataForSecondaryAxis.push({
|
|
293
|
+
properties: {
|
|
294
|
+
axis: d.properties.axis,
|
|
295
|
+
type: d.properties.type,
|
|
296
|
+
legend: d.properties.legend,
|
|
297
|
+
},
|
|
298
|
+
stackData: tempStackColumnChartDataForPrimaryAxis,
|
|
299
|
+
data: primaryStackColumnAxisData,
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (secondaryStackColumnAxisData.length) {
|
|
304
|
+
secondaryStackColumnAxisData.forEach((d) => {
|
|
305
|
+
stackColumnChartDataForSecondaryAxis.push({
|
|
306
|
+
properties: {
|
|
307
|
+
axis: d.properties.axis,
|
|
308
|
+
type: d.properties.type,
|
|
309
|
+
legend: d.properties.legend,
|
|
310
|
+
},
|
|
311
|
+
stackData: tempStackColumnChartDataForSecondaryAxis,
|
|
312
|
+
data: secondaryStackColumnAxisData,
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
// push these results in filteredData
|
|
317
|
+
requiredData.push(...chartJSON.chartData, ...stackAreaChartDataForPrimaryAxis, ...stackAreaChartDataForSecondaryAxis, ...stackColumnChartDataForPrimaryAxis, ...stackColumnChartDataForSecondaryAxis);
|
|
318
|
+
};
|
|
319
|
+
const initScale = () => {
|
|
320
|
+
// rounding the ymin & ymax
|
|
321
|
+
let yAxisLabelArray = responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray;
|
|
322
|
+
chartJSON.yMaxLeft = yAxisLabelArray[yAxisLabelArray.length - 1];
|
|
323
|
+
chartJSON.yMinLeft = yAxisLabelArray[0];
|
|
324
|
+
if (isPrimaryAxisDrawn) {
|
|
325
|
+
yScaleLeft = d3
|
|
326
|
+
.scaleLinear()
|
|
327
|
+
.domain([
|
|
328
|
+
customYaxisMinValue !== undefined &&
|
|
329
|
+
!Number.isNaN(customYaxisMinValue)
|
|
330
|
+
? customYaxisMinValue
|
|
331
|
+
: chartJSON.yMinLeft < 0
|
|
332
|
+
? chartJSON.yMinLeft * 1.1
|
|
333
|
+
: chartJSON.yMinLeft * 0.9,
|
|
334
|
+
chartJSON.yMaxLeft <= 0
|
|
335
|
+
? 0
|
|
336
|
+
: customYaxisMaxValue !== undefined &&
|
|
337
|
+
!Number.isNaN(customYaxisMaxValue)
|
|
338
|
+
? customYaxisMaxValue
|
|
339
|
+
: chartJSON.yMaxLeft * 1.1,
|
|
340
|
+
])
|
|
341
|
+
.range([
|
|
342
|
+
dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
|
|
343
|
+
0,
|
|
344
|
+
]);
|
|
345
|
+
}
|
|
346
|
+
if (isSecondaryAxisDrawn) {
|
|
347
|
+
// rounding the ymin & ymax
|
|
348
|
+
let secondaryYAxisLabelArray = responsiveSecondaryYaxisLabel(secondaryCustomYaxisMaxValue
|
|
349
|
+
? secondaryCustomYaxisMaxValue
|
|
350
|
+
: chartJSON.yMaxRight, secondaryCustomYaxisMinValue
|
|
351
|
+
? secondaryCustomYaxisMinValue
|
|
352
|
+
: chartJSON.yMinRight, formatOptions, chartJSON).secondaryYAxisLabelArray;
|
|
353
|
+
chartJSON.yMaxRight =
|
|
354
|
+
secondaryYAxisLabelArray[secondaryYAxisLabelArray.length - 1];
|
|
355
|
+
chartJSON.yMinRight = secondaryYAxisLabelArray[0];
|
|
356
|
+
yScaleRight = d3
|
|
357
|
+
.scaleLinear()
|
|
358
|
+
.domain([
|
|
359
|
+
chartJSON.yMinRight >= 0
|
|
360
|
+
? (secondaryCustomYaxisMinValue ||
|
|
361
|
+
secondaryCustomYaxisMinValue == 0) &&
|
|
362
|
+
!Number.isNaN(secondaryCustomYaxisMinValue)
|
|
363
|
+
? secondaryCustomYaxisMinValue
|
|
364
|
+
: 0
|
|
365
|
+
: (secondaryCustomYaxisMinValue ||
|
|
366
|
+
secondaryCustomYaxisMinValue == 0) &&
|
|
367
|
+
!Number.isNaN(secondaryCustomYaxisMinValue)
|
|
368
|
+
? secondaryCustomYaxisMinValue
|
|
369
|
+
: chartJSON.yMinRight * 1.1,
|
|
370
|
+
chartJSON.yMaxRight <= 0
|
|
371
|
+
? (secondaryCustomYaxisMaxValue ||
|
|
372
|
+
secondaryCustomYaxisMaxValue == 0) &&
|
|
373
|
+
!Number.isNaN(secondaryCustomYaxisMaxValue)
|
|
374
|
+
? secondaryCustomYaxisMaxValue
|
|
375
|
+
: 0
|
|
376
|
+
: (secondaryCustomYaxisMaxValue ||
|
|
377
|
+
secondaryCustomYaxisMaxValue == 0) &&
|
|
378
|
+
!Number.isNaN(secondaryCustomYaxisMaxValue)
|
|
379
|
+
? secondaryCustomYaxisMaxValue
|
|
380
|
+
: chartJSON.yMaxRight * 1.1,
|
|
381
|
+
])
|
|
382
|
+
.range([
|
|
383
|
+
dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
|
|
384
|
+
0,
|
|
385
|
+
]);
|
|
386
|
+
}
|
|
387
|
+
calculatedRange = [0, innerWidth];
|
|
388
|
+
if (formatOptions.seriesLabel.seriesLabelVisibility) {
|
|
389
|
+
let labelObj = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, yScaleRight, isSecondaryAxisDrawn);
|
|
390
|
+
seriesLabels = labelObj.labelArray;
|
|
391
|
+
formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
|
|
392
|
+
(seriesLabelWidth = labelObj.heightWidth[0]);
|
|
393
|
+
formatOptions.seriesLabel.seriesLabelPosition == "Right"
|
|
394
|
+
? (calculatedRange = [0, innerWidth - labelObj.heightWidth[0]])
|
|
395
|
+
: (calculatedRange = [labelObj.heightWidth[0], innerWidth]);
|
|
396
|
+
}
|
|
397
|
+
getXScale();
|
|
398
|
+
};
|
|
399
|
+
const getXScale = () => {
|
|
400
|
+
columnWidth =
|
|
401
|
+
(0.51 +
|
|
402
|
+
(0.61 * (100 - parseFloat(formatOptions.plotArea.plotAreaGapWidth))) /
|
|
403
|
+
100) *
|
|
404
|
+
(innerWidth / filteredDimension.length);
|
|
405
|
+
xScaleForLegends = d3
|
|
406
|
+
.scaleBand()
|
|
407
|
+
// .domain(barLegendList.map((d) => d.legend))
|
|
408
|
+
.domain(chartJSON.legendList)
|
|
409
|
+
.range([0, columnWidth])
|
|
410
|
+
.paddingInner(chartJSON.legendList.length > 1
|
|
411
|
+
? (0.3 * parseFloat(formatOptions.plotArea.plotAreaSeriesWidth)) / 100
|
|
412
|
+
: 0);
|
|
413
|
+
xScale = d3
|
|
414
|
+
.scalePoint()
|
|
415
|
+
.domain(filteredDimension)
|
|
416
|
+
.range(calculatedRange)
|
|
417
|
+
.padding(0.5);
|
|
418
|
+
};
|
|
419
|
+
const initAxis = () => {
|
|
420
|
+
getXAxis();
|
|
421
|
+
if (isPrimaryAxisDrawn) {
|
|
422
|
+
yAxisLeft = d3
|
|
423
|
+
.axisLeft(yScaleLeft)
|
|
424
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
|
|
425
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
426
|
+
? formatOptions.plotArea.gridLinesHorizontal
|
|
427
|
+
? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
|
|
428
|
+
: 0
|
|
429
|
+
: 0)
|
|
430
|
+
.tickValues(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray)
|
|
431
|
+
.ticks(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).customTickValue ??
|
|
432
|
+
(dataTableHeight > 0
|
|
433
|
+
? (innerHeight - dataTableHeight) / 30
|
|
434
|
+
: innerHeight / 30))
|
|
435
|
+
.tickSizeOuter(0);
|
|
436
|
+
}
|
|
437
|
+
if (isSecondaryAxisDrawn) {
|
|
438
|
+
yAxisRight = d3
|
|
439
|
+
.axisRight(yScaleRight)
|
|
440
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.secondaryYAxisLabel.secondaryYAxisDisplayUnits, formatOptions.secondaryYAxisLabel.secondaryYAxisNumberFormat, formatOptions.secondaryYAxisLabel
|
|
441
|
+
.secondaryYAxisLabelDecimalPrecision))
|
|
442
|
+
.tickValues(responsiveSecondaryYaxisLabel(secondaryCustomYaxisMaxValue
|
|
443
|
+
? secondaryCustomYaxisMaxValue
|
|
444
|
+
: chartJSON.yMaxRight, chartJSON.yMinRight, formatOptions, chartJSON).secondaryYAxisLabelArray)
|
|
445
|
+
.ticks(responsiveSecondaryYaxisLabel(secondaryCustomYaxisMaxValue
|
|
446
|
+
? secondaryCustomYaxisMaxValue
|
|
447
|
+
: chartJSON.yMaxRight, chartJSON.yMinRight, formatOptions, chartJSON).secondaryCustomTickValue ?? innerHeight / 30)
|
|
448
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
449
|
+
? formatOptions.plotArea.gridLinesHorizontal
|
|
450
|
+
? -innerWidth
|
|
451
|
+
: 0
|
|
452
|
+
: 0)
|
|
453
|
+
.tickSizeOuter(0);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const getXAxis = () => {
|
|
457
|
+
xAxis = d3
|
|
458
|
+
.axisBottom(xScale)
|
|
459
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
460
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
461
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
462
|
+
? -(dataTableHeight > 0
|
|
463
|
+
? innerHeight - dataTableHeight
|
|
464
|
+
: innerHeight)
|
|
465
|
+
: parseFloat(formatOptions.plotArea.ticksHeight) *
|
|
466
|
+
((dataTableHeight > 0
|
|
467
|
+
? innerHeight - dataTableHeight
|
|
468
|
+
: innerHeight) /
|
|
469
|
+
100) *
|
|
470
|
+
(formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
|
|
471
|
+
: 0
|
|
472
|
+
: 0)
|
|
473
|
+
.tickSizeOuter(0)
|
|
474
|
+
.tickValues(responsiveXaxisLabel(filteredDimension, innerWidth));
|
|
475
|
+
};
|
|
476
|
+
const getChartType = (lineData) => {
|
|
477
|
+
// Bind dummy data to ensure a single group is created
|
|
478
|
+
lineData.forEach((data) => {
|
|
479
|
+
switch (data.properties.type) {
|
|
480
|
+
case actualChartTypes.column:
|
|
481
|
+
drawColumnChart(data);
|
|
482
|
+
break;
|
|
483
|
+
case actualChartTypes.line:
|
|
484
|
+
drawLineChart([data]);
|
|
485
|
+
break;
|
|
486
|
+
case actualChartTypes.area:
|
|
487
|
+
drawAreaChart([data]);
|
|
488
|
+
break;
|
|
489
|
+
case actualChartTypes.stackColumn:
|
|
490
|
+
stackColumnData = createStackData(data);
|
|
491
|
+
drawStackColumnChart();
|
|
492
|
+
break;
|
|
493
|
+
case actualChartTypes.stackArea:
|
|
494
|
+
stackAreaData = createStackData(data);
|
|
495
|
+
drawStackAreaChart(data);
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
const drawColumnChart = (data) => {
|
|
501
|
+
// Step 1: Outer group for the whole chart
|
|
502
|
+
let column = gTag.selectAll(".parentGroup").data([data], (d) => d.legend); // use key so exit works
|
|
503
|
+
column = column
|
|
504
|
+
.enter()
|
|
505
|
+
.append("g")
|
|
506
|
+
.attr("class", `column parentGroup`)
|
|
507
|
+
.merge(column);
|
|
508
|
+
// Step 2: JOIN each data point inside the series
|
|
509
|
+
let columnGroups = column
|
|
510
|
+
.selectAll(".column-group")
|
|
511
|
+
.data(data.data, (d) => d.legend + d.dimension); // key on dimension + legend
|
|
512
|
+
// Step 3: ENTER - one group per bar (optional if you need transform)
|
|
513
|
+
let columnGroupsEnter = columnGroups
|
|
514
|
+
.enter()
|
|
515
|
+
.append("g")
|
|
516
|
+
.attr("class", "column-group")
|
|
517
|
+
.attr("hoverId", (d) => d.legend.includes("-")
|
|
518
|
+
? d.legend.replace("-", "`").split("`")[1].replace(/ /g, "-")
|
|
519
|
+
: d.legend.replace(/ /g, "-"))
|
|
520
|
+
.attr("transform", (d) => `translate(${xScale(d.dimension)}, 0)`);
|
|
521
|
+
// // ✨ Add this to handle UPDATE:
|
|
522
|
+
columnGroups.attr("transform", (d) => `translate(${xScale(d.dimension) - columnWidth / 2}, 0)`);
|
|
523
|
+
// // Merge ENTER + UPDATE
|
|
524
|
+
columnGroupsEnter
|
|
525
|
+
.merge(columnGroups)
|
|
526
|
+
.attr("transform", (d) => `translate(${xScale(d.dimension) - columnWidth / 2}, 0)`);
|
|
527
|
+
// Step 4: Draw the rects
|
|
528
|
+
columnGroupsEnter
|
|
529
|
+
.append("rect")
|
|
530
|
+
.attr("x", (d) => xScaleForLegends(d.legend))
|
|
531
|
+
.attr("width", xScaleForLegends.bandwidth())
|
|
532
|
+
.attr("y", (d) => {
|
|
533
|
+
const yScale = data.properties.axis === "Primary" ? yScaleLeft : yScaleRight;
|
|
534
|
+
return d.value > 0 ? yScale(d.value) : yScale(0);
|
|
535
|
+
})
|
|
536
|
+
.attr("height", (d) => {
|
|
537
|
+
const yScale = data.properties.axis === "Primary" ? yScaleLeft : yScaleRight;
|
|
538
|
+
return Math.abs(yScale(d.value) - yScale(0));
|
|
539
|
+
})
|
|
540
|
+
.attr("fill", data.properties.color)
|
|
541
|
+
.attr("stroke-dasharray", (d) => (d.stackBorderStyle === 2 ? "5,3" : "0"))
|
|
542
|
+
.attr("stroke-width", (d) => `${d.stackBorderWidth}px`)
|
|
543
|
+
.attr("stroke", (d) => data.properties.stackBorderStyle === 0
|
|
544
|
+
? "none"
|
|
545
|
+
: formatOptions.column.stackBorderVisibility
|
|
546
|
+
? data.properties.stackBorderStyle
|
|
547
|
+
: "none")
|
|
548
|
+
.style("clip-path", "inset(0px) fill-box")
|
|
549
|
+
.style("shape-rendering", "crispEdges")
|
|
550
|
+
.attr("visibility", (d) => d.value === 0 && formatOptions.xAxisLabel.hideZeroValues
|
|
551
|
+
? "hidden"
|
|
552
|
+
: "visible")
|
|
553
|
+
.on("mousemove", (event, d) => {
|
|
554
|
+
showTooltipOnMouseMove([
|
|
555
|
+
{
|
|
556
|
+
key: formatOptions.xAxisTitle.xAxisTitleText.includes("~$~")
|
|
557
|
+
? formatOptions.xAxisTitle.xAxisTitleText.split("~$~")[1]
|
|
558
|
+
: formatOptions.xAxisTitle.xAxisTitleText,
|
|
559
|
+
value: chartJSON.formattedDimensionListMap.get(Array.isArray(d.dimension) ? d.dimension[0] : d.dimension),
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
key: formatOptions.yAxisTitle.yAxisTitleText || d.value,
|
|
563
|
+
value: getNumberWithFormat([
|
|
564
|
+
actualChartTypes.stackLine100,
|
|
565
|
+
actualChartTypes.stackArea100,
|
|
566
|
+
"",
|
|
567
|
+
].includes(chartType)
|
|
568
|
+
? d[1] - d[0]
|
|
569
|
+
: d.value, formatOptions.toolTip.toolTipDisplayUnits, formatOptions.toolTip.toolTipNumberFormat, formatOptions.toolTip.toolTipDecimalPrecision),
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
key: "Legend",
|
|
573
|
+
value: d.legend.includes("~$~")
|
|
574
|
+
? d.legend.split("~$~")[1]
|
|
575
|
+
: d.legend,
|
|
576
|
+
},
|
|
577
|
+
], formatOptions, event);
|
|
578
|
+
})
|
|
579
|
+
.on("mouseout", hideTooltipOnMouseOut);
|
|
580
|
+
// Step 5: EXIT - remove old bars
|
|
581
|
+
columnGroups.exit().remove();
|
|
582
|
+
};
|
|
583
|
+
const drawLineChart = (lineData) => {
|
|
584
|
+
lineData.forEach((lData) => {
|
|
585
|
+
lData.data.forEach((cData) => {
|
|
586
|
+
cData.hideZero = lData.properties.hideZeroValues;
|
|
587
|
+
cData.axis = lData.properties.axis;
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
const lineGenerator = d3
|
|
591
|
+
.line()
|
|
592
|
+
.x((d) => xScale(d.dimension)
|
|
593
|
+
? xScale(d.dimension)
|
|
594
|
+
: null)
|
|
595
|
+
.y((d) => d.axis == "Primary"
|
|
596
|
+
? yScaleLeft(d.value)
|
|
597
|
+
: yScaleRight(d.value))
|
|
598
|
+
.defined((d) => (d.hideZero ? Boolean(d.value) : true))
|
|
599
|
+
.curve(getCurveType(formatOptions));
|
|
600
|
+
// Bind dummy data to ensure a single group is created
|
|
601
|
+
let lines = gTag.selectAll(".parentGroup").data([lineData]);
|
|
602
|
+
lines = lines
|
|
603
|
+
.enter()
|
|
604
|
+
.append("g")
|
|
605
|
+
.attr("class", "lines parentGroup")
|
|
606
|
+
.merge(lines);
|
|
607
|
+
// JOIN: one group per line
|
|
608
|
+
let lineGroups = lines.selectAll(".line-group").data((d) => d);
|
|
609
|
+
// ENTER: create group for each new line
|
|
610
|
+
let lineGroupsEnter = lineGroups
|
|
611
|
+
.enter()
|
|
612
|
+
.append("g")
|
|
613
|
+
.attr("class", "line-group");
|
|
614
|
+
// Append path to new groups
|
|
615
|
+
lineGroupsEnter
|
|
616
|
+
.attr("hoverId", (d) => d.legend.replace(/ /g, "-"))
|
|
617
|
+
.append("path")
|
|
618
|
+
.attr("class", "line")
|
|
619
|
+
.attr("fill", "none");
|
|
620
|
+
// ENTER + UPDATE
|
|
621
|
+
lineGroupsEnter
|
|
622
|
+
.merge(lineGroups)
|
|
623
|
+
.select("path")
|
|
624
|
+
.attr("d", (d) => lineGenerator(d.data))
|
|
625
|
+
.attr("stroke", (d) => d.properties.color !== "#ffffff" ? d.properties.color : "none")
|
|
626
|
+
.attr("stroke-dasharray", (d) => {
|
|
627
|
+
switch (d.properties.lineStyle) {
|
|
628
|
+
case staticLineStyle.dotted:
|
|
629
|
+
return "0,3";
|
|
630
|
+
case staticLineStyle.dashed:
|
|
631
|
+
return "20,10,5,5,5,10";
|
|
632
|
+
default:
|
|
633
|
+
return "";
|
|
634
|
+
}
|
|
635
|
+
})
|
|
636
|
+
.attr("stroke-linecap", (d) => d.properties.lineStyle === staticLineStyle.dotted ? "round" : "")
|
|
637
|
+
.attr("stroke-width", (d) => d.properties.lineStyle !== "None" ? d.properties.lineWidth : "0");
|
|
638
|
+
// EXIT: remove old groups
|
|
639
|
+
lineGroups.exit().remove();
|
|
640
|
+
//Markers
|
|
641
|
+
lineMarkers(lines, lineData, "CombiLine", xScale, yScaleLeft, yScaleRight, null, formatOptions, chartJSON, secondaryCustomYaxisMaxValue, secondaryCustomYaxisMinValue, customYaxisMinValue, customYaxisMaxValue, false);
|
|
642
|
+
};
|
|
643
|
+
const drawAreaChart = (lineData) => {
|
|
644
|
+
const areaGenerator = d3
|
|
645
|
+
.area()
|
|
646
|
+
.x((d) => xScale(d.dimension)
|
|
647
|
+
? xScale(d.dimension)
|
|
648
|
+
: null)
|
|
649
|
+
.y0((d) =>
|
|
650
|
+
// d.axis == "Primary" ?
|
|
651
|
+
yScaleLeft(0)
|
|
652
|
+
// : yScaleRight(0)
|
|
653
|
+
)
|
|
654
|
+
.y1((d) =>
|
|
655
|
+
// d.axis == "Primary" ?
|
|
656
|
+
yScaleLeft(d.value)
|
|
657
|
+
// : yScaleRight((d as TDataPoint).value)
|
|
658
|
+
)
|
|
659
|
+
.defined((d) => (d.hideZero ? Boolean(d.value) : true))
|
|
660
|
+
.curve(getCurveType(formatOptions));
|
|
661
|
+
// Bind dummy data to ensure a single group is created
|
|
662
|
+
let areas = gTag.selectAll(".parentGroup").data([lineData]);
|
|
663
|
+
let focus = gTag.append("g").attr("class", "focusClass");
|
|
664
|
+
areas = areas
|
|
665
|
+
.enter()
|
|
666
|
+
.append("g")
|
|
667
|
+
.attr("class", "areas parentGroup")
|
|
668
|
+
.merge(areas);
|
|
669
|
+
// JOIN: one group per line
|
|
670
|
+
let areaGroups = areas.selectAll(".area-group").data((d) => d);
|
|
671
|
+
// ENTER: create group for each new line
|
|
672
|
+
let areaGroupsEnter = areaGroups
|
|
673
|
+
.enter()
|
|
674
|
+
.append("g")
|
|
675
|
+
.attr("class", "area-group");
|
|
676
|
+
// Append path to new groups
|
|
677
|
+
areaGroupsEnter
|
|
678
|
+
.attr("hoverId", (d) => d.legend.replace(/ /g, "-"))
|
|
679
|
+
.append("path")
|
|
680
|
+
.attr("class", "area")
|
|
681
|
+
.attr("fill", (d) => d.properties.color !== "#ffffff" ? d.properties.color : "none")
|
|
682
|
+
.style("fill-opacity", formatOptions.plotArea.fillOpacity);
|
|
683
|
+
// ENTER + UPDATE
|
|
684
|
+
areaGroupsEnter
|
|
685
|
+
.merge(areaGroups)
|
|
686
|
+
.select("path")
|
|
687
|
+
.attr("d", (d) => areaGenerator(d.data))
|
|
688
|
+
.attr("stroke", (d) => d.properties.areaBorderColor !== "#ffffff"
|
|
689
|
+
? d.properties.areaBorderColor
|
|
690
|
+
: "none")
|
|
691
|
+
.attr("stroke-dasharray", (d) => {
|
|
692
|
+
switch (d.properties.lineStyle) {
|
|
693
|
+
case "dotted":
|
|
694
|
+
return "0,3";
|
|
695
|
+
case "dashed":
|
|
696
|
+
return "20,10,5,5,5,10";
|
|
697
|
+
default:
|
|
698
|
+
return "";
|
|
699
|
+
}
|
|
700
|
+
})
|
|
701
|
+
.attr("stroke-linecap", (d) => d.properties.lineStyle === "dotted" ? "round" : "")
|
|
702
|
+
.attr("stroke-width", (d) => d.properties.lineStyle !== "None" &&
|
|
703
|
+
formatOptions.plotArea.plotAreaHideLineAndMarkers
|
|
704
|
+
? d.properties.lineWidth
|
|
705
|
+
: "0");
|
|
706
|
+
onHoverMarkerForAreaChartFamily(formatOptions, areas, focus, filteredDimension, lineData, xScale, yScaleLeft, chartType);
|
|
707
|
+
// EXIT: remove old groups
|
|
708
|
+
areaGroups.exit().remove();
|
|
709
|
+
//Markers
|
|
710
|
+
// lineMarkers(
|
|
711
|
+
// areas,
|
|
712
|
+
// lineData,
|
|
713
|
+
// chartType,
|
|
714
|
+
// xScale,
|
|
715
|
+
// yScaleLeft,
|
|
716
|
+
// undefined,
|
|
717
|
+
// null,
|
|
718
|
+
// formatOptions,
|
|
719
|
+
// chartJSON,
|
|
720
|
+
// secondaryCustomYaxisMaxValue,
|
|
721
|
+
// secondaryCustomYaxisMinValue,
|
|
722
|
+
// customYaxisMinValue,
|
|
723
|
+
// customYaxisMaxValue
|
|
724
|
+
// );
|
|
725
|
+
};
|
|
726
|
+
const drawStackAreaChart = (data) => {
|
|
727
|
+
const areaGenerator = d3
|
|
728
|
+
.area()
|
|
729
|
+
.x((d) => xScale(d.data.dimension)
|
|
730
|
+
? xScale(d.data.dimension)
|
|
731
|
+
: null)
|
|
732
|
+
.y0((d) => d.data.axis == "Primary" ? yScaleLeft(0) : yScaleRight(0))
|
|
733
|
+
.y1((d) => d.data.axis == "Primary"
|
|
734
|
+
? d[1] > 0
|
|
735
|
+
? yScaleLeft(d[1])
|
|
736
|
+
: yScaleLeft(d[0])
|
|
737
|
+
: d[1] > 0
|
|
738
|
+
? yScaleRight(d[1])
|
|
739
|
+
: yScaleRight(d[0]))
|
|
740
|
+
.defined((d) => (d.hideZero ? Boolean(d.key) : true))
|
|
741
|
+
.curve(getCurveType(formatOptions));
|
|
742
|
+
// Bind dummy data to ensure a single group is created
|
|
743
|
+
let areas = gTag.selectAll(".parentGroup").data([stackAreaData]);
|
|
744
|
+
let focus = gTag.append("g").attr("class", "focusClass");
|
|
745
|
+
areas = areas
|
|
746
|
+
.enter()
|
|
747
|
+
.append("g")
|
|
748
|
+
.attr("class", "areas parentGroup")
|
|
749
|
+
.merge(areas);
|
|
750
|
+
// JOIN: one group per line
|
|
751
|
+
let areaGroups = areas.selectAll(".area-group").data((d) => d);
|
|
752
|
+
// ENTER: create group for each new line
|
|
753
|
+
let areaGroupsEnter = areaGroups
|
|
754
|
+
// .data((d) => d.stackData)
|
|
755
|
+
.enter()
|
|
756
|
+
.append("g")
|
|
757
|
+
.attr("class", (d) => "area-group " + d.key.replace(/ /g, "-"));
|
|
758
|
+
// .attr("class", (d) => d.key.replace(/ /g, "-"));
|
|
759
|
+
areaGroupsEnter
|
|
760
|
+
.attr("hoverId", (d) => d.key.includes("~$~")
|
|
761
|
+
? d.key.split("~$~")[1].replace(/ /g, "-")
|
|
762
|
+
: d.key.replace(/ /g, "-"))
|
|
763
|
+
.append("path")
|
|
764
|
+
.attr("class", "area")
|
|
765
|
+
.attr("fill", (d) => (d.color !== "#ffffff" ? d.color : "none"));
|
|
766
|
+
// ENTER + UPDATE
|
|
767
|
+
areaGroupsEnter
|
|
768
|
+
.merge(areaGroups)
|
|
769
|
+
.select("path")
|
|
770
|
+
.attr("d", (d, i) => areaGenerator(d))
|
|
771
|
+
.style("opacity", formatOptions.plotArea.fillOpacity)
|
|
772
|
+
.attr("stroke", (d) => (d.color !== "#ffffff" ? d.color : "none"))
|
|
773
|
+
// .style("visibility", (d,i) => (this.individualLegendStyle[i].hideZero && d[i].data[d.key] === 0) ? "hidden" : "visible")
|
|
774
|
+
.attr("stroke-dasharray", (d, i) => seriesData[i].properties.lineStyle === "dotted"
|
|
775
|
+
? "0,3"
|
|
776
|
+
: seriesData[i].properties.lineStyle === "dashed"
|
|
777
|
+
? "20,10,5,5,5,10"
|
|
778
|
+
: "")
|
|
779
|
+
.attr("stroke-linecap", (d, i) => seriesData[i].properties.lineStyle === "dotted" ? "round" : "")
|
|
780
|
+
.attr("stroke-width", (d, i) => seriesData[i].properties.lineStyle !== "None"
|
|
781
|
+
? seriesData[i].properties.lineWidth
|
|
782
|
+
: "0");
|
|
783
|
+
// onHoverMarkerForAreaChartFamily(formatOptions, areas, focus, filteredDimension, lineData, xScale, yScaleLeft, chartType);
|
|
784
|
+
// EXIT: remove old groups
|
|
785
|
+
areaGroups.exit().remove();
|
|
786
|
+
// Markers
|
|
787
|
+
lineMarkers(areas, data.data, "CombiStackArea", xScale, yScaleLeft, yScaleRight, null, formatOptions, chartJSON, secondaryCustomYaxisMaxValue, secondaryCustomYaxisMinValue, customYaxisMinValue, customYaxisMaxValue, false);
|
|
788
|
+
};
|
|
789
|
+
const drawStackColumnChart = () => {
|
|
790
|
+
let stackColumns = gTag.selectAll(".parentGroup").data([stackColumnData]);
|
|
791
|
+
stackColumns = stackColumns
|
|
792
|
+
.enter()
|
|
793
|
+
.append("g")
|
|
794
|
+
.attr("class", "stackcolumns parentGroup")
|
|
795
|
+
.merge(stackColumns);
|
|
796
|
+
// JOIN: one group per stack series
|
|
797
|
+
let stackColumnGroups = stackColumns
|
|
798
|
+
.selectAll(".stackcolumns-group")
|
|
799
|
+
.data((d) => d);
|
|
800
|
+
// ENTER
|
|
801
|
+
let stackColumnGroupsEnter = stackColumnGroups
|
|
802
|
+
.enter()
|
|
803
|
+
.append("g")
|
|
804
|
+
.attr("class", (d) => "stackcolumns-group ");
|
|
805
|
+
stackColumnGroups = stackColumnGroupsEnter.merge(stackColumnGroups);
|
|
806
|
+
// JOIN rects inside each series
|
|
807
|
+
let rects = stackColumnGroups.selectAll("rect").data((d) => d);
|
|
808
|
+
// ENTER
|
|
809
|
+
rects
|
|
810
|
+
.enter()
|
|
811
|
+
.append("rect")
|
|
812
|
+
.attr("transform", (d) => `translate(${xScale(d.data.dimension) - columnWidth / 2},0)`)
|
|
813
|
+
.merge(rects)
|
|
814
|
+
.attr("hoverId", (d) => d.key.includes("~$~")
|
|
815
|
+
? d.key.split("~$~")[1].replace(/ /g, "-")
|
|
816
|
+
: d.key.replace(/ /g, "-"))
|
|
817
|
+
.attr("x", (d) => xScaleForLegends("stackLegend"))
|
|
818
|
+
.attr("y", (d) => d.data.axis === "Primary" ? yScaleLeft(d[1]) : yScaleRight(d[1]))
|
|
819
|
+
.attr("height", (d) => d.data.axis === "Primary"
|
|
820
|
+
? customYaxisMaxValue && d[1] > customYaxisMaxValue
|
|
821
|
+
? yScaleLeft(d[0]) - yScaleLeft(customYaxisMaxValue)
|
|
822
|
+
: yScaleLeft(d[0]) - yScaleLeft(d[1])
|
|
823
|
+
: secondaryCustomYaxisMaxValue && d[1] > secondaryCustomYaxisMaxValue
|
|
824
|
+
? yScaleRight(d[0]) - yScaleRight(secondaryCustomYaxisMaxValue)
|
|
825
|
+
: yScaleRight(d[0]) - yScaleRight(d[1]))
|
|
826
|
+
.attr("width", xScaleForLegends.bandwidth())
|
|
827
|
+
.attr("fill", (d, i, nodes) => {
|
|
828
|
+
// `nodes[i]` gives access to parent node so we can infer which group (series) we're in
|
|
829
|
+
const seriesIndex = Array.from(seriesData).findIndex((sdata) => sdata.legend === d.key);
|
|
830
|
+
return seriesData[seriesIndex]?.properties?.color || "gray";
|
|
831
|
+
})
|
|
832
|
+
.attr("stroke", (d, i, nodes) => {
|
|
833
|
+
const seriesIndex = Array.from(seriesData).findIndex((sdata) => sdata.legend === d.key);
|
|
834
|
+
const props = seriesData[seriesIndex]?.properties;
|
|
835
|
+
return props?.stackBorderStyle === 0
|
|
836
|
+
? "none"
|
|
837
|
+
: formatOptions.column.stackBorderVisibility
|
|
838
|
+
? props.stackBorderColor
|
|
839
|
+
: "none";
|
|
840
|
+
})
|
|
841
|
+
.attr("stroke-dasharray", (d, i, nodes) => {
|
|
842
|
+
const seriesIndex = Array.from(seriesData).findIndex((sdata) => sdata.legend === d.key);
|
|
843
|
+
return seriesData[seriesIndex]?.properties.stackBorderStyle === 2
|
|
844
|
+
? "5,3"
|
|
845
|
+
: "0";
|
|
846
|
+
})
|
|
847
|
+
.attr("stroke-width", (d, i, nodes) => {
|
|
848
|
+
const seriesIndex = Array.from(seriesData).findIndex((sdata) => sdata.legend === d.key);
|
|
849
|
+
return ((seriesData[seriesIndex]?.properties.stackBorderWidth || 0) + "px");
|
|
850
|
+
})
|
|
851
|
+
.on("mousemove", (event, d) => {
|
|
852
|
+
showTooltipOnMouseMove([
|
|
853
|
+
{
|
|
854
|
+
key: formatOptions.xAxisTitle.xAxisTitleText.includes("~$~")
|
|
855
|
+
? formatOptions.xAxisTitle.xAxisTitleText.split("~$~")[1]
|
|
856
|
+
: formatOptions.xAxisTitle.xAxisTitleText,
|
|
857
|
+
value: chartJSON.formattedDimensionListMap.get(d.data.dimension),
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
key: formatOptions.yAxisTitle.yAxisTitleText || d.value,
|
|
861
|
+
value: getNumberWithFormat(d.data[d.key], formatOptions.toolTip.toolTipDisplayUnits, formatOptions.toolTip.toolTipNumberFormat, formatOptions.toolTip.toolTipDecimalPrecision),
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
key: "Legend",
|
|
865
|
+
value: d.key.includes("~$~") ? d.key.split("~$~")[1] : d.key,
|
|
866
|
+
},
|
|
867
|
+
], formatOptions, event);
|
|
868
|
+
})
|
|
869
|
+
.on("mouseout", hideTooltipOnMouseOut);
|
|
870
|
+
// EXIT: remove old groups
|
|
871
|
+
stackColumnGroups.exit().remove();
|
|
872
|
+
};
|
|
873
|
+
const setSVGContainer = (margin) => {
|
|
874
|
+
innerWidth = width - margin.left - margin.right;
|
|
875
|
+
innerHeight = height - margin.bottom - margin.top;
|
|
876
|
+
};
|
|
877
|
+
const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
|
|
878
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
879
|
+
// Scrollbar parameters
|
|
880
|
+
const scrollMax = seriesData[0].data.length - visibleBars;
|
|
881
|
+
// Scrollbar track & handle
|
|
882
|
+
const scrollbarY = height - 20;
|
|
883
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
884
|
+
// check and add data to filteredData for stack type charts
|
|
885
|
+
checkAndupdateInputData(primaryStackAreaAxisData, primaryStackColumnAxisData, secondaryStackAreaAxisData, secondaryStackColumnAxisData);
|
|
886
|
+
getXScale();
|
|
887
|
+
filteredData = JSON.parse(JSON.stringify(requiredData));
|
|
888
|
+
filteredData.forEach((data, i) => {
|
|
889
|
+
if (data.properties.type === actualChartTypes.stackColumn ||
|
|
890
|
+
data.properties.type === actualChartTypes.stackArea) {
|
|
891
|
+
data.data.forEach((stackData, pos) => {
|
|
892
|
+
filteredData[i].data[pos]["data"] = stackData.data.filter((d) => filteredDimension.includes(d.dimension));
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
else {
|
|
896
|
+
filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension));
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
getXAxis();
|
|
900
|
+
svg
|
|
901
|
+
.append("rect")
|
|
902
|
+
.attr("x", margin.left)
|
|
903
|
+
.attr("y", scrollbarY)
|
|
904
|
+
.attr("width", innerWidth)
|
|
905
|
+
.attr("height", 8)
|
|
906
|
+
.attr("fill", "#ddd")
|
|
907
|
+
.attr("rx", 4);
|
|
908
|
+
const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
|
|
909
|
+
const handle = svg
|
|
910
|
+
.append("rect")
|
|
911
|
+
.attr("x", margin.left)
|
|
912
|
+
.attr("y", scrollbarY)
|
|
913
|
+
.attr("width", handleWidth)
|
|
914
|
+
.attr("height", 8)
|
|
915
|
+
.attr("fill", "#999")
|
|
916
|
+
.attr("rx", 4)
|
|
917
|
+
.style("cursor", "ew-resize")
|
|
918
|
+
.call(d3.drag().on("drag", (event) => {
|
|
919
|
+
let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
|
|
920
|
+
handle.attr("x", x);
|
|
921
|
+
scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
|
|
922
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
923
|
+
// check and add data to filteredData for stack type charts
|
|
924
|
+
checkAndupdateInputData(primaryStackAreaAxisData, primaryStackColumnAxisData, secondaryStackAreaAxisData, secondaryStackColumnAxisData);
|
|
925
|
+
getXScale();
|
|
926
|
+
filteredData = JSON.parse(JSON.stringify(requiredData));
|
|
927
|
+
filteredData.forEach((data, i) => {
|
|
928
|
+
if (data.properties.type === actualChartTypes.stackColumn ||
|
|
929
|
+
data.properties.type === actualChartTypes.stackArea) {
|
|
930
|
+
data.data.forEach((stackData, pos) => (filteredData[i].data[pos]["data"] = stackData.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension));
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
getXAxis();
|
|
937
|
+
drawCustomChart();
|
|
938
|
+
}));
|
|
939
|
+
svg.on("wheel", (event) => {
|
|
940
|
+
event.preventDefault();
|
|
941
|
+
const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
|
|
942
|
+
? event.deltaX
|
|
943
|
+
: event.deltaY;
|
|
944
|
+
scrollPosition += scrollDelta > 0 ? 1 : -1;
|
|
945
|
+
scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
|
|
946
|
+
const x = margin.left +
|
|
947
|
+
((innerWidth - handleWidth) * scrollPosition) / scrollMax;
|
|
948
|
+
handle.attr("x", x);
|
|
949
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
950
|
+
// check and add data to filteredData for stack type charts
|
|
951
|
+
checkAndupdateInputData(primaryStackAreaAxisData, primaryStackColumnAxisData, secondaryStackAreaAxisData, secondaryStackColumnAxisData);
|
|
952
|
+
getXScale();
|
|
953
|
+
filteredData = JSON.parse(JSON.stringify(requiredData));
|
|
954
|
+
filteredData.forEach((data, i) => {
|
|
955
|
+
if (data.properties.type === actualChartTypes.stackColumn ||
|
|
956
|
+
data.properties.type === actualChartTypes.stackArea) {
|
|
957
|
+
data.data.forEach((stackData, pos) => (filteredData[i].data[pos]["data"] = stackData.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension));
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
getXAxis();
|
|
964
|
+
drawCustomChart();
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
filteredData = JSON.parse(JSON.stringify(requiredData));
|
|
969
|
+
}
|
|
970
|
+
drawCustomChart();
|
|
971
|
+
};
|
|
972
|
+
const drawCustomChart = () => {
|
|
973
|
+
getChartType(filteredData);
|
|
974
|
+
initXaxis(gTag, chartJSON, xLabel, formatOptions, xAxisObj[0], dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, columnWidth, xAxisObj[0].dataType, innerWidth, innerHeight, filteredDimension);
|
|
975
|
+
commonAnnotationsForCustomChart(filteredData, xScale, yScaleLeft, yScaleRight, // need to pass secondary axis scale if secondary axis is drawn
|
|
976
|
+
margin, d3Annotation, stackColumnData, stackAreaData, [], //labelExcludeList
|
|
977
|
+
[], // individualLabelColor
|
|
978
|
+
columnWidth, [], //old annotation list
|
|
979
|
+
formatOptions, height, width, innerWidth, filteredDimension, innerHeight, chartId, svg, xScaleForLegends);
|
|
980
|
+
};
|
|
981
|
+
const createStackData = (requiredStackChatData) => {
|
|
982
|
+
let legendList = requiredStackChatData.data.map((d) => d.legend);
|
|
983
|
+
stackChartData = d3
|
|
984
|
+
.stack()
|
|
985
|
+
.keys(legendList)
|
|
986
|
+
.offset(d3.stackOffsetDiverging)(requiredStackChatData.stackData);
|
|
987
|
+
requiredStackChatData.data.forEach((data, index) => data.data.forEach((axisData, position) => {
|
|
988
|
+
axisData["0"] = stackChartData[index][position][0];
|
|
989
|
+
axisData["1"] = stackChartData[index][position][1];
|
|
990
|
+
}));
|
|
991
|
+
//Appending Extra key for tooltip color
|
|
992
|
+
let seriesColor = formatOptions.annotation.annotationSetLabelColor;
|
|
993
|
+
stackChartData.forEach((stackData, j) => {
|
|
994
|
+
stackData.forEach((d) => {
|
|
995
|
+
d["key"] = stackData.key;
|
|
996
|
+
stackData["color"] = JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.color));
|
|
997
|
+
d.data.labelPosition =
|
|
998
|
+
requiredStackChatData.data[j].properties.dataLabelPosition;
|
|
999
|
+
d.data["labelColor"] =
|
|
1000
|
+
seriesColor == "2"
|
|
1001
|
+
? JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.color))
|
|
1002
|
+
: JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.labelColor));
|
|
1003
|
+
d["hideZero"] = JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.hideZeroValues));
|
|
1004
|
+
d.data["axis"] = JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.axis));
|
|
1005
|
+
d.data["color"] = JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.color));
|
|
1006
|
+
d.data["legend"] = `stackLegend`;
|
|
1007
|
+
d.data["type"] = JSON.parse(JSON.stringify(requiredStackChatData.data[j].properties.type));
|
|
1008
|
+
});
|
|
1009
|
+
});
|
|
1010
|
+
return stackChartData;
|
|
1011
|
+
};
|
|
1012
|
+
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%" } })] }));
|
|
1013
|
+
};
|
|
1014
|
+
export default CustomColumnChart;
|