pace-chart-lib 0.0.6 → 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 -54
- 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,417 @@
|
|
|
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 { drawLegends, generalizedChartData, hideTooltipOnMouseOut, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
|
|
7
|
+
import { addDataTable, customYscaleLabelFormatting, dataTablePreCalculation, firstFunctionBeforeRender, getNumberWithFormat, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis, marginCalculation, responsiveYaxisLabel, setChartTitle, setXaxistitle, yAxistitle, yAxistitleRight, } from "../ChartsWithAxisFunctions";
|
|
8
|
+
import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
|
|
9
|
+
import { staticLegendShape } from "../../Core/Common.types";
|
|
10
|
+
import { responsiveXaxisLabelForNumericValue } from "../../ChartsWithoutAxis/ChartsWithoutAxisFunctions";
|
|
11
|
+
const ColumnHistogramChart = ({ title, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
|
|
12
|
+
// adding variables as per requirement
|
|
13
|
+
const columnWidth = 0; // coz line chartO
|
|
14
|
+
const chartType = actualChartTypes.columnHistogram;
|
|
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 customXaxisMinValue = parseFloat(formatOptions.xAxisLabel.xAxisMinText);
|
|
25
|
+
let customXaxisMaxValue = parseFloat(formatOptions.xAxisLabel.xAxisMaxText);
|
|
26
|
+
let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
|
|
27
|
+
let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
|
|
28
|
+
let margin;
|
|
29
|
+
let yLabel;
|
|
30
|
+
let xLabel;
|
|
31
|
+
let yTitle;
|
|
32
|
+
let xTitle;
|
|
33
|
+
let dimensionHeightWidthArray;
|
|
34
|
+
let chartTitleHeight;
|
|
35
|
+
let secondaryAxisTitleWidth;
|
|
36
|
+
let legendMargin;
|
|
37
|
+
let secondaryYLabel;
|
|
38
|
+
let maxNumberForPrimaryAxis;
|
|
39
|
+
let maxNumberForSecondaryAxis;
|
|
40
|
+
let innerWidth;
|
|
41
|
+
let innerHeight;
|
|
42
|
+
let thresholds;
|
|
43
|
+
let periods = [];
|
|
44
|
+
let bins = [];
|
|
45
|
+
let width;
|
|
46
|
+
let height;
|
|
47
|
+
let dataTable;
|
|
48
|
+
let dataTableHeight;
|
|
49
|
+
let svg;
|
|
50
|
+
let gTag;
|
|
51
|
+
let yScaleLeft;
|
|
52
|
+
let yScaleRight;
|
|
53
|
+
let xScale;
|
|
54
|
+
let xScaleForLegends;
|
|
55
|
+
let seriesLabels;
|
|
56
|
+
let calculatedRange;
|
|
57
|
+
let seriesLabelWidth;
|
|
58
|
+
let yAxisLeft;
|
|
59
|
+
let xAxis;
|
|
60
|
+
let yAxisRight;
|
|
61
|
+
let filteredDimension;
|
|
62
|
+
let filteredData = [];
|
|
63
|
+
let scrollPosition = 0;
|
|
64
|
+
const visibleBars = 2;
|
|
65
|
+
let chartJSON = {
|
|
66
|
+
dimensionList: dimensionList,
|
|
67
|
+
chartType: chartType,
|
|
68
|
+
chartData: [],
|
|
69
|
+
formatOptions: formatOptions,
|
|
70
|
+
legendList: [],
|
|
71
|
+
secondaryAxisDrawn: false,
|
|
72
|
+
yMaxLeft: 0,
|
|
73
|
+
yMaxRight: 0,
|
|
74
|
+
yMinLeft: 0,
|
|
75
|
+
yMinRight: 0,
|
|
76
|
+
hideZeroValues: false,
|
|
77
|
+
formattedDimensionListMap: new Map(),
|
|
78
|
+
};
|
|
79
|
+
//#region UseEffect
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
try {
|
|
82
|
+
createColumnChart();
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
logError("Columnchart", "createColumnChart", error);
|
|
86
|
+
}
|
|
87
|
+
}, [formatOptions]);
|
|
88
|
+
//#endregion
|
|
89
|
+
const createColumnChart = () => {
|
|
90
|
+
({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
|
|
91
|
+
preProcessChartData(); // preaparing data related to chart creation
|
|
92
|
+
// Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
|
|
93
|
+
({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } =
|
|
94
|
+
customYscaleLabelFormatting(
|
|
95
|
+
// for calculating primary/secondary axis max number so that we can calculate margin accordinglt
|
|
96
|
+
formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
|
|
97
|
+
({
|
|
98
|
+
margin,
|
|
99
|
+
yLabel,
|
|
100
|
+
xLabel,
|
|
101
|
+
yTitle,
|
|
102
|
+
xTitle,
|
|
103
|
+
dimensionHeightWidthArray,
|
|
104
|
+
chartTitleHeight,
|
|
105
|
+
secondaryAxisTitleWidth,
|
|
106
|
+
legendMargin,
|
|
107
|
+
secondaryYLabel,
|
|
108
|
+
} = marginCalculation(
|
|
109
|
+
// for all margin related calculations
|
|
110
|
+
width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart));
|
|
111
|
+
setSVGContainer(margin); // for innerWidth/height static width/height
|
|
112
|
+
({ dataTable, dataTableHeight } = dataTablePreCalculation(
|
|
113
|
+
// calculations for data tables
|
|
114
|
+
formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
|
|
115
|
+
initSvg(
|
|
116
|
+
// for svg creation
|
|
117
|
+
svg, width, height, formatOptions);
|
|
118
|
+
gTag = initChartArea(svg, margin); // creating chart area
|
|
119
|
+
initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
|
|
120
|
+
binsCalculation();
|
|
121
|
+
initScale();
|
|
122
|
+
initAxis();
|
|
123
|
+
initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
|
|
124
|
+
horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
|
|
125
|
+
if (formatOptions.dataTableProperties &&
|
|
126
|
+
formatOptions.dataTableProperties.dataTable) {
|
|
127
|
+
if (formatOptions.xAxisLabel.xAxisPosition != "1")
|
|
128
|
+
formatOptions.xAxisLabel.xAxisLabelVisibility = false;
|
|
129
|
+
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);
|
|
130
|
+
}
|
|
131
|
+
setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
|
|
132
|
+
yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
|
|
133
|
+
yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
|
|
134
|
+
setChartTitle(svg, formatOptions, width, chartTitleHeight);
|
|
135
|
+
drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, staticLegendShape.rectangle);
|
|
136
|
+
};
|
|
137
|
+
const preProcessChartData = () => {
|
|
138
|
+
const allChartData = [];
|
|
139
|
+
const legendList = [];
|
|
140
|
+
let formatedDimesionList = [];
|
|
141
|
+
let cumulativeDataPoints = [];
|
|
142
|
+
let yMaxLeft = -Infinity;
|
|
143
|
+
let yMinLeft = Infinity;
|
|
144
|
+
seriesData.forEach((series) => {
|
|
145
|
+
legendList.push(series.legend);
|
|
146
|
+
series.data.forEach((point) => {
|
|
147
|
+
allChartData.push(point);
|
|
148
|
+
yMaxLeft = Math.max(yMaxLeft, point.value);
|
|
149
|
+
yMinLeft = Math.min(yMinLeft, point.value);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
chartJSON.chartData = allChartData;
|
|
153
|
+
chartJSON.legendList = legendList;
|
|
154
|
+
chartJSON.yMaxLeft = yMaxLeft;
|
|
155
|
+
chartJSON.yMinLeft = yMinLeft;
|
|
156
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
157
|
+
filteredData.forEach((d) => d.data.forEach((j) => cumulativeDataPoints.push(j.value)));
|
|
158
|
+
let yMin = (customYaxisMinValue || customYaxisMinValue == 0) ? customYaxisMinValue : 0;
|
|
159
|
+
let yMax = (customYaxisMaxValue || customYaxisMaxValue == 0) ? customYaxisMaxValue : filteredData[0]?.data?.length;
|
|
160
|
+
chartJSON.yMaxLeft = parseFloat(((yMin + "").length > (yMax + "").length) ? (yMin + "") : (yMax + ""));
|
|
161
|
+
chartJSON.xMax = d3.max(cumulativeDataPoints);
|
|
162
|
+
chartJSON.xMin = d3.min(cumulativeDataPoints);
|
|
163
|
+
};
|
|
164
|
+
const binsCalculation = () => {
|
|
165
|
+
switch (formatOptions.bins.binsCalculation) {
|
|
166
|
+
case "Automatic":
|
|
167
|
+
thresholds = innerWidth / 50;
|
|
168
|
+
break;
|
|
169
|
+
case "Number of Bins":
|
|
170
|
+
calculatingPeriodsWithBins(false);
|
|
171
|
+
break;
|
|
172
|
+
case "Bin Width":
|
|
173
|
+
calculatingPeriodsWithBins(true);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const calculatingPeriodsWithBins = (isWithWidth) => {
|
|
177
|
+
let sortedArray = [];
|
|
178
|
+
filteredData.forEach((d) => (sortedArray = d.data.sort(function (a, b) {
|
|
179
|
+
return a.value - b.value;
|
|
180
|
+
})));
|
|
181
|
+
let range = chartJSON.xMax - chartJSON.xMin;
|
|
182
|
+
let tempPeriod;
|
|
183
|
+
if (isWithWidth) {
|
|
184
|
+
parseFloat(formatOptions.bins.binsCalculationValue) <= 2 && (formatOptions.bins.binsCalculationValue = "3");
|
|
185
|
+
tempPeriod = range / parseFloat(formatOptions.bins.binsCalculationValue);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
parseFloat(formatOptions.bins.binsCalculationValue) <= 1 && (formatOptions.bins.binsCalculationValue = "1"); //minimum bins 1
|
|
189
|
+
tempPeriod = range / parseFloat(formatOptions.bins.binsCalculationValue);
|
|
190
|
+
}
|
|
191
|
+
let currentElement = chartJSON.xMin;
|
|
192
|
+
if (isWithWidth) {
|
|
193
|
+
periods = [currentElement];
|
|
194
|
+
while (currentElement < chartJSON.xMax) {
|
|
195
|
+
currentElement += tempPeriod;
|
|
196
|
+
periods.push(currentElement);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
periods = [currentElement];
|
|
201
|
+
while (Math.round(currentElement) < Math.round(chartJSON.xMax)) {
|
|
202
|
+
currentElement += tempPeriod;
|
|
203
|
+
periods.push(Math.round(currentElement));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const initScale = () => {
|
|
208
|
+
xScale = d3
|
|
209
|
+
.scaleLinear()
|
|
210
|
+
.domain([chartJSON.xMin, chartJSON.xMax])
|
|
211
|
+
.range([0, innerWidth]);
|
|
212
|
+
let histogram = d3
|
|
213
|
+
.bin()
|
|
214
|
+
.value((d) => d) // how to extract value from data
|
|
215
|
+
.domain(xScale.domain())
|
|
216
|
+
.thresholds((periods && periods.length) || xScale.ticks(thresholds)); // the numbers of bins
|
|
217
|
+
filteredData.forEach((d) => {
|
|
218
|
+
let tempArray = histogram(d.data.map(val => val.value));
|
|
219
|
+
bins.push(tempArray);
|
|
220
|
+
});
|
|
221
|
+
filteredData.forEach((d, i) => bins[i].forEach((j) => {
|
|
222
|
+
j["name"] = d.properties["legend"];
|
|
223
|
+
j["color"] = d.properties["color"];
|
|
224
|
+
j["opacity"] = d.properties["opacity"];
|
|
225
|
+
})); // Adding additional information from the main data.
|
|
226
|
+
let cumulativeLength = [];
|
|
227
|
+
bins.forEach((d) => d.forEach((j) => cumulativeLength.push(j.length)));
|
|
228
|
+
chartJSON.yMaxLeft = d3.max(cumulativeLength);
|
|
229
|
+
chartJSON.yMinLeft = d3.min(cumulativeLength);
|
|
230
|
+
// rounding the ymin & ymax
|
|
231
|
+
yScaleLeft = d3
|
|
232
|
+
.scaleLinear()
|
|
233
|
+
.range([innerHeight, 0])
|
|
234
|
+
// .domain([0, this.Ymax + 0.2 * this.Ymax])
|
|
235
|
+
.domain([(customYaxisMinValue || customYaxisMinValue == 0) ? customYaxisMinValue : 0, (customYaxisMaxValue || customYaxisMaxValue == 0) ? customYaxisMaxValue : chartJSON.yMaxLeft + 0.2 * chartJSON.yMaxLeft]);
|
|
236
|
+
};
|
|
237
|
+
const initAxis = () => {
|
|
238
|
+
getXAxis();
|
|
239
|
+
if (isPrimaryAxisDrawn) {
|
|
240
|
+
yAxisLeft = d3
|
|
241
|
+
.axisLeft(yScaleLeft)
|
|
242
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
|
|
243
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
244
|
+
? formatOptions.plotArea.gridLinesHorizontal
|
|
245
|
+
? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
|
|
246
|
+
: 0
|
|
247
|
+
: 0)
|
|
248
|
+
.tickValues(responsiveYaxisLabel(chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue, false, innerWidth).yAxisLabelArray)
|
|
249
|
+
.ticks(innerHeight / 50)
|
|
250
|
+
.tickSizeOuter(0);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const getXAxis = () => {
|
|
254
|
+
let xaxisLabelPosition = parseInt(formatOptions.xAxisLabel.xAxisPosition);
|
|
255
|
+
let labelArray = responsiveXaxisLabelForNumericValue(chartJSON.xMax, chartJSON.xMin, innerWidth, formatOptions, customXaxisMinValue, customXaxisMaxValue, innerHeight, false).xAxisLabelArray;
|
|
256
|
+
labelArray.shift();
|
|
257
|
+
xAxis =
|
|
258
|
+
(xaxisLabelPosition == 1 ?
|
|
259
|
+
d3.axisTop(xScale) : d3.axisBottom(xScale))
|
|
260
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.xAxisLabel.xAxisDisplayUnits, formatOptions.xAxisLabel.xAxisNumberFormat, formatOptions.xAxisLabel.xAxisLabelDecimalPrecision, false))
|
|
261
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
262
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
263
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
264
|
+
? -(dataTableHeight > 0
|
|
265
|
+
? innerHeight - dataTableHeight
|
|
266
|
+
: innerHeight)
|
|
267
|
+
: parseFloat(formatOptions.plotArea.ticksHeight) *
|
|
268
|
+
((dataTableHeight > 0
|
|
269
|
+
? innerHeight - dataTableHeight
|
|
270
|
+
: innerHeight) /
|
|
271
|
+
100) *
|
|
272
|
+
(formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
|
|
273
|
+
: 0
|
|
274
|
+
: 0)
|
|
275
|
+
.tickValues(labelArray)
|
|
276
|
+
.ticks(innerWidth / 30)
|
|
277
|
+
.tickSizeOuter(0);
|
|
278
|
+
formatOptions.bins.binsCalculation === "Automatic"
|
|
279
|
+
? xAxis.ticks(thresholds)
|
|
280
|
+
: xAxis.tickValues(periods).ticks(innerWidth / 50);
|
|
281
|
+
};
|
|
282
|
+
const getChartType = (lineData) => {
|
|
283
|
+
gTag
|
|
284
|
+
.append("g")
|
|
285
|
+
.attr("class", "parentGroup")
|
|
286
|
+
.selectAll("#scaling-svg" + chartId + " .rect")
|
|
287
|
+
.data(bins)
|
|
288
|
+
.enter()
|
|
289
|
+
.append("g")
|
|
290
|
+
.selectAll("rect")
|
|
291
|
+
.data((d) => d)
|
|
292
|
+
.enter()
|
|
293
|
+
.append("rect")
|
|
294
|
+
.attr("class", "rect")
|
|
295
|
+
.attr("stroke", formatOptions.bins.binsBorderVisibility && formatOptions.bins.binsBorderColor)
|
|
296
|
+
.attr("stroke-width", formatOptions.bins.binsBorderVisibility && formatOptions.bins.binsBorderThickness)
|
|
297
|
+
.attr("stroke-opacity", formatOptions.bins.binsBorderVisibility && formatOptions.bins.binsBorderOpacity)
|
|
298
|
+
.attr("x", 1)
|
|
299
|
+
.attr("transform", function (d) {
|
|
300
|
+
return ("translate(" + xScale(d.x0) + "," + (yScaleLeft(d.length) > 0 ? yScaleLeft(d.length) : 0) + ")");
|
|
301
|
+
})
|
|
302
|
+
.attr("width", function (d) {
|
|
303
|
+
return xScale(d.x1) - xScale(d.x0) - parseFloat(formatOptions.bins.binsGapWidth) < 0
|
|
304
|
+
? 0
|
|
305
|
+
: xScale(d.x1) - xScale(d.x0) - parseFloat(formatOptions.bins.binsGapWidth);
|
|
306
|
+
})
|
|
307
|
+
.attr("height", function (d) {
|
|
308
|
+
return innerHeight - yScaleLeft(d.length);
|
|
309
|
+
})
|
|
310
|
+
.style("fill", (d) => d.color !== "#ffffff" ? d.color : "none")
|
|
311
|
+
.style("opacity", formatOptions.bins.binsFillOpacity)
|
|
312
|
+
.style("shape-rendering", "crispEdges")
|
|
313
|
+
.on("mousemove", (event, d) => {
|
|
314
|
+
showTooltipOnMouseMove([
|
|
315
|
+
{
|
|
316
|
+
key: formatOptions.xAxisTitle.xAxisTitleText.includes("~$~")
|
|
317
|
+
? formatOptions.xAxisTitle.xAxisTitleText.split("~$~")[1]
|
|
318
|
+
: formatOptions.xAxisTitle.xAxisTitleText,
|
|
319
|
+
value: `${d["x0"]}-${d["x1"]}`
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
key: formatOptions.yAxisTitle.yAxisTitleText,
|
|
323
|
+
value: getNumberWithFormat(formatOptions.toolTip.toolTipNumberFormat == ",.0%" ? Math.abs(d.length / filteredData[0].data.length) : d.length, formatOptions.toolTip.toolTipDisplayUnits, formatOptions.toolTip.toolTipNumberFormat, formatOptions.toolTip.toolTipDecimalPrecision, false),
|
|
324
|
+
},
|
|
325
|
+
], formatOptions, event);
|
|
326
|
+
})
|
|
327
|
+
.on("mouseout", hideTooltipOnMouseOut);
|
|
328
|
+
};
|
|
329
|
+
const setSVGContainer = (margin) => {
|
|
330
|
+
innerWidth = width - margin.left - margin.right;
|
|
331
|
+
innerHeight = height - margin.bottom - margin.top;
|
|
332
|
+
};
|
|
333
|
+
const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
|
|
334
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
335
|
+
// Scrollbar parameters
|
|
336
|
+
const scrollMax = seriesData[0].data.length - visibleBars;
|
|
337
|
+
// Scrollbar track & handle
|
|
338
|
+
const scrollbarY = height - 20;
|
|
339
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
340
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
341
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
342
|
+
getXAxis();
|
|
343
|
+
svg
|
|
344
|
+
.append("rect")
|
|
345
|
+
.attr("x", margin.left)
|
|
346
|
+
.attr("y", scrollbarY)
|
|
347
|
+
.attr("width", innerWidth)
|
|
348
|
+
.attr("height", 8)
|
|
349
|
+
.attr("fill", "#ddd")
|
|
350
|
+
.attr("rx", 4);
|
|
351
|
+
const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
|
|
352
|
+
const handle = svg
|
|
353
|
+
.append("rect")
|
|
354
|
+
.attr("x", margin.left)
|
|
355
|
+
.attr("y", scrollbarY)
|
|
356
|
+
.attr("width", handleWidth)
|
|
357
|
+
.attr("height", 8)
|
|
358
|
+
.attr("fill", "#999")
|
|
359
|
+
.attr("rx", 4)
|
|
360
|
+
.style("cursor", "ew-resize")
|
|
361
|
+
.call(d3.drag().on("drag", (event) => {
|
|
362
|
+
let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
|
|
363
|
+
handle.attr("x", x);
|
|
364
|
+
scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
|
|
365
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
366
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
367
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
368
|
+
getXAxis();
|
|
369
|
+
drawColumnChart();
|
|
370
|
+
}));
|
|
371
|
+
svg.on("wheel", (event) => {
|
|
372
|
+
event.preventDefault();
|
|
373
|
+
const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
|
|
374
|
+
? event.deltaX
|
|
375
|
+
: event.deltaY;
|
|
376
|
+
scrollPosition += scrollDelta > 0 ? 1 : -1;
|
|
377
|
+
scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
|
|
378
|
+
const x = margin.left +
|
|
379
|
+
((innerWidth - handleWidth) * scrollPosition) / scrollMax;
|
|
380
|
+
handle.attr("x", x);
|
|
381
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
382
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
383
|
+
getXAxis();
|
|
384
|
+
drawColumnChart();
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
drawColumnChart();
|
|
388
|
+
};
|
|
389
|
+
const drawColumnChart = () => {
|
|
390
|
+
getChartType(filteredData);
|
|
391
|
+
initXaxis(gTag, chartJSON, xLabel, formatOptions, xAxisObj[0], dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, columnWidth, xAxisObj[0].dataType, innerWidth, innerHeight, filteredDimension);
|
|
392
|
+
// commonAnnotations(
|
|
393
|
+
// seriesData,
|
|
394
|
+
// xScale,
|
|
395
|
+
// yScaleLeft,
|
|
396
|
+
// yScaleRight, // need to pass secondary axis scale if secondary axis is drawn
|
|
397
|
+
// margin,
|
|
398
|
+
// d3Annotation,
|
|
399
|
+
// [], //this.labelExcludeList,
|
|
400
|
+
// [], //this.individualLabelColor,
|
|
401
|
+
// [], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
|
|
402
|
+
// formatOptions,
|
|
403
|
+
// chartType,
|
|
404
|
+
// height,
|
|
405
|
+
// width,
|
|
406
|
+
// innerWidth,
|
|
407
|
+
// filteredDimension,
|
|
408
|
+
// innerHeight,
|
|
409
|
+
// chartId,
|
|
410
|
+
// svg,
|
|
411
|
+
// xScaleForLegends,
|
|
412
|
+
// columnWidth
|
|
413
|
+
// );
|
|
414
|
+
};
|
|
415
|
+
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%" } })] }));
|
|
416
|
+
};
|
|
417
|
+
export default ColumnHistogramChart;
|