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,452 @@
|
|
|
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 { staticLegendShape, staticLineStyle, } from "../../Core/Common.types";
|
|
8
|
+
import { drawLegends, generalizedChartData, lineMarkers } from "../../Core/CommonFunctions";
|
|
9
|
+
import { addDataTable, commonAnnotations, customYscaleLabelFormatting, dataTablePreCalculation, drawSeriesLabels, firstFunctionBeforeRender, getCurveType, getNumberWithFormat, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis, initYaxisRight, marginCalculation, prepareDataForSeriesLabel, responsiveSecondaryYaxisLabel, responsiveXaxisLabel, responsiveYaxisLabel, setChartTitle, setDateFormats, setXaxistitle, yAxistitle, yAxistitleRight, } from "../ChartsWithAxisFunctions";
|
|
10
|
+
import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
|
|
11
|
+
const LineChart = ({ title, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
|
|
12
|
+
// adding variables as per requirement
|
|
13
|
+
const barWidth = 0; // coz line chart
|
|
14
|
+
const chartType = actualChartTypes.line;
|
|
15
|
+
const svgRef = useRef();
|
|
16
|
+
const seriesData = generalizedChartData(data.ChartData, data.DimensionList);
|
|
17
|
+
const dimensionList = data.DimensionList;
|
|
18
|
+
const barChart = false;
|
|
19
|
+
let isSecondaryAxisDrawn = false;
|
|
20
|
+
const isNormalizedChart = false;
|
|
21
|
+
let isPrimaryAxisDrawn = true;
|
|
22
|
+
let customYaxisMinValue = parseFloat(formatOptions.yAxisLabel.yAxisMinText);
|
|
23
|
+
let customYaxisMaxValue = parseFloat(formatOptions.yAxisLabel.yAxisMaxText);
|
|
24
|
+
let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
|
|
25
|
+
let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
|
|
26
|
+
let margin;
|
|
27
|
+
let yLabel;
|
|
28
|
+
let xLabel;
|
|
29
|
+
let yTitle;
|
|
30
|
+
let xTitle;
|
|
31
|
+
let dimensionHeightWidthArray;
|
|
32
|
+
let chartTitleHeight;
|
|
33
|
+
let secondaryAxisTitleWidth;
|
|
34
|
+
let legendMargin;
|
|
35
|
+
let secondaryYLabel;
|
|
36
|
+
let maxNumberForPrimaryAxis;
|
|
37
|
+
let maxNumberForSecondaryAxis;
|
|
38
|
+
let innerWidth;
|
|
39
|
+
let innerHeight;
|
|
40
|
+
let width;
|
|
41
|
+
let height;
|
|
42
|
+
let dataTable;
|
|
43
|
+
let dataTableHeight;
|
|
44
|
+
let svg;
|
|
45
|
+
let gTag;
|
|
46
|
+
let yScaleLeft;
|
|
47
|
+
let yScaleRight;
|
|
48
|
+
let xScale;
|
|
49
|
+
let seriesLabels;
|
|
50
|
+
let calculatedRange;
|
|
51
|
+
let seriesLabelWidth;
|
|
52
|
+
let yAxisLeft;
|
|
53
|
+
let xAxis;
|
|
54
|
+
let yAxisRight;
|
|
55
|
+
let filteredDimension;
|
|
56
|
+
let filteredData = [];
|
|
57
|
+
let scrollPosition = 0;
|
|
58
|
+
const visibleBars = 2;
|
|
59
|
+
let chartJSON = {
|
|
60
|
+
dimensionList: dimensionList,
|
|
61
|
+
chartType: chartType,
|
|
62
|
+
chartData: [],
|
|
63
|
+
formatOptions: formatOptions,
|
|
64
|
+
legendList: [],
|
|
65
|
+
secondaryAxisDrawn: false,
|
|
66
|
+
yMaxLeft: 0,
|
|
67
|
+
yMaxRight: 0,
|
|
68
|
+
yMinLeft: 0,
|
|
69
|
+
yMinRight: 0,
|
|
70
|
+
hideZeroValues: false,
|
|
71
|
+
formattedDimensionListMap: new Map(),
|
|
72
|
+
};
|
|
73
|
+
//#region UseEffect
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
try {
|
|
76
|
+
createLineChart();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
logError("Linechart", "createLineChart", error);
|
|
80
|
+
}
|
|
81
|
+
}, [formatOptions]);
|
|
82
|
+
//#endregion
|
|
83
|
+
const createLineChart = () => {
|
|
84
|
+
({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
|
|
85
|
+
preProcessChartData(); // preaparing data related to chart creation
|
|
86
|
+
// Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
|
|
87
|
+
({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } =
|
|
88
|
+
customYscaleLabelFormatting(
|
|
89
|
+
// for calculating primary/secondary axis max number so that we can calculate margin accordinglt
|
|
90
|
+
formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
|
|
91
|
+
({
|
|
92
|
+
margin,
|
|
93
|
+
yLabel,
|
|
94
|
+
xLabel,
|
|
95
|
+
yTitle,
|
|
96
|
+
xTitle,
|
|
97
|
+
dimensionHeightWidthArray,
|
|
98
|
+
chartTitleHeight,
|
|
99
|
+
secondaryAxisTitleWidth,
|
|
100
|
+
legendMargin,
|
|
101
|
+
secondaryYLabel,
|
|
102
|
+
} = marginCalculation(
|
|
103
|
+
// for all margin related calculations
|
|
104
|
+
width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart));
|
|
105
|
+
setSVGContainer(margin); // for innerWidth/height static width/height
|
|
106
|
+
({ dataTable, dataTableHeight } = dataTablePreCalculation(
|
|
107
|
+
// calculations for data tables
|
|
108
|
+
formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
|
|
109
|
+
initSvg(
|
|
110
|
+
// for svg creation
|
|
111
|
+
svg, width, height, formatOptions);
|
|
112
|
+
gTag = initChartArea(svg, margin); // creating chart area
|
|
113
|
+
initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
|
|
114
|
+
initScale();
|
|
115
|
+
initAxis();
|
|
116
|
+
initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
|
|
117
|
+
if (isSecondaryAxisDrawn) {
|
|
118
|
+
initYaxisRight(gTag, formatOptions, dataTableHeight, secondaryYLabel, yAxisRight, innerHeight, innerWidth);
|
|
119
|
+
}
|
|
120
|
+
horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
|
|
121
|
+
if (formatOptions.dataTableProperties &&
|
|
122
|
+
formatOptions.dataTableProperties.dataTable) {
|
|
123
|
+
if (formatOptions.xAxisLabel.xAxisPosition != "1")
|
|
124
|
+
formatOptions.xAxisLabel.xAxisLabelVisibility = false;
|
|
125
|
+
addDataTable(formatOptions.plotArea.fitChart, svg, gTag, dataTable, barWidth, yScaleLeft, xScale, undefined, undefined, undefined, dataTableHeight, "Line", formatOptions, yLabel, yTitle, chartJSON.dimensionList, innerWidth, calculatedRange, chartJSON.formattedDimensionListMap, chartId, margin, innerHeight);
|
|
126
|
+
}
|
|
127
|
+
setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
|
|
128
|
+
yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
|
|
129
|
+
yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
|
|
130
|
+
setChartTitle(svg, formatOptions, width, chartTitleHeight);
|
|
131
|
+
drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, staticLegendShape.line);
|
|
132
|
+
};
|
|
133
|
+
const preProcessChartData = () => {
|
|
134
|
+
const allChartData = [];
|
|
135
|
+
const legendList = [];
|
|
136
|
+
let formatedDimesionList = [];
|
|
137
|
+
let yMaxLeft = -Infinity;
|
|
138
|
+
let yMinLeft = Infinity;
|
|
139
|
+
let yMaxRight = -Infinity;
|
|
140
|
+
let yMinRight = Infinity;
|
|
141
|
+
seriesData.forEach((series) => {
|
|
142
|
+
legendList.push(series.legend);
|
|
143
|
+
series.data.forEach((point) => {
|
|
144
|
+
allChartData.push(point);
|
|
145
|
+
if (series.properties.axis === "Secondary") {
|
|
146
|
+
isSecondaryAxisDrawn = true;
|
|
147
|
+
yMaxRight = Math.max(yMaxRight, point.value);
|
|
148
|
+
yMinRight = Math.min(yMinRight, point.value);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
yMaxLeft = Math.max(yMaxLeft, point.value);
|
|
152
|
+
yMinLeft = Math.min(yMinLeft, point.value);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
chartJSON.chartData = allChartData;
|
|
157
|
+
chartJSON.legendList = legendList;
|
|
158
|
+
chartJSON.yMaxLeft = yMaxLeft;
|
|
159
|
+
chartJSON.yMinLeft = yMinLeft;
|
|
160
|
+
chartJSON.yMaxRight = yMaxRight;
|
|
161
|
+
chartJSON.yMinRight = yMinRight;
|
|
162
|
+
// Apply formatted dimensions
|
|
163
|
+
let xAxisObject = xAxisObj[0];
|
|
164
|
+
formatedDimesionList =
|
|
165
|
+
(xAxisObject.groupBy == "NA" || xAxisObject.groupBy == undefined) &&
|
|
166
|
+
xAxisObject.dataType === "DATE"
|
|
167
|
+
? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d[0])
|
|
168
|
+
: chartJSON.dimensionList;
|
|
169
|
+
chartJSON.dimensionList.forEach((dim, i) => {
|
|
170
|
+
chartJSON.formattedDimensionListMap.set(dim, formatedDimesionList[i]);
|
|
171
|
+
});
|
|
172
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
173
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
174
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
filteredDimension = chartJSON.dimensionList;
|
|
178
|
+
}
|
|
179
|
+
if (formatOptions.plotArea.hideZeroValues) {
|
|
180
|
+
chartJSON.hideZeroValues = true;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const initScale = () => {
|
|
184
|
+
// rounding the ymin & ymax
|
|
185
|
+
let yAxisLabelArray = responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray;
|
|
186
|
+
chartJSON.yMaxLeft = yAxisLabelArray[yAxisLabelArray.length - 1];
|
|
187
|
+
chartJSON.yMinLeft = yAxisLabelArray[0];
|
|
188
|
+
if (isPrimaryAxisDrawn) {
|
|
189
|
+
yScaleLeft = d3
|
|
190
|
+
.scaleLinear()
|
|
191
|
+
.domain([
|
|
192
|
+
customYaxisMinValue !== undefined &&
|
|
193
|
+
!Number.isNaN(customYaxisMinValue)
|
|
194
|
+
? customYaxisMinValue
|
|
195
|
+
: chartJSON.yMinLeft < 0
|
|
196
|
+
? chartJSON.yMinLeft * 1.1
|
|
197
|
+
: chartJSON.yMinLeft * 0.9,
|
|
198
|
+
chartJSON.yMaxLeft <= 0
|
|
199
|
+
? 0
|
|
200
|
+
: customYaxisMaxValue !== undefined &&
|
|
201
|
+
!Number.isNaN(customYaxisMaxValue)
|
|
202
|
+
? customYaxisMaxValue
|
|
203
|
+
: chartJSON.yMaxLeft * 1.1,
|
|
204
|
+
])
|
|
205
|
+
.range([
|
|
206
|
+
dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
|
|
207
|
+
0,
|
|
208
|
+
]);
|
|
209
|
+
}
|
|
210
|
+
if (isSecondaryAxisDrawn) {
|
|
211
|
+
yScaleRight = d3
|
|
212
|
+
.scaleLinear()
|
|
213
|
+
.domain([
|
|
214
|
+
chartJSON.yMinRight >= 0
|
|
215
|
+
? (secondaryCustomYaxisMinValue ||
|
|
216
|
+
secondaryCustomYaxisMinValue == 0) &&
|
|
217
|
+
!Number.isNaN(secondaryCustomYaxisMinValue)
|
|
218
|
+
? secondaryCustomYaxisMinValue
|
|
219
|
+
: 0
|
|
220
|
+
: (secondaryCustomYaxisMinValue ||
|
|
221
|
+
secondaryCustomYaxisMinValue == 0) &&
|
|
222
|
+
!Number.isNaN(secondaryCustomYaxisMinValue)
|
|
223
|
+
? secondaryCustomYaxisMinValue
|
|
224
|
+
: chartJSON.yMinRight * 1.1,
|
|
225
|
+
chartJSON.yMaxRight <= 0
|
|
226
|
+
? secondaryCustomYaxisMaxValue
|
|
227
|
+
? secondaryCustomYaxisMaxValue
|
|
228
|
+
: 0
|
|
229
|
+
: secondaryCustomYaxisMaxValue
|
|
230
|
+
? secondaryCustomYaxisMaxValue
|
|
231
|
+
: chartJSON.yMaxRight * 1.1,
|
|
232
|
+
])
|
|
233
|
+
.range([
|
|
234
|
+
dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
|
|
235
|
+
0,
|
|
236
|
+
]);
|
|
237
|
+
}
|
|
238
|
+
calculatedRange = [0, innerWidth];
|
|
239
|
+
if (formatOptions.seriesLabel.seriesLabelVisibility) {
|
|
240
|
+
let labelObj = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, yScaleRight, isSecondaryAxisDrawn);
|
|
241
|
+
seriesLabels = labelObj.labelArray;
|
|
242
|
+
formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
|
|
243
|
+
(seriesLabelWidth = labelObj.heightWidth[0]);
|
|
244
|
+
formatOptions.seriesLabel.seriesLabelPosition == "Right"
|
|
245
|
+
? (calculatedRange = [0, innerWidth - labelObj.heightWidth[0]])
|
|
246
|
+
: (calculatedRange = [labelObj.heightWidth[0], innerWidth]);
|
|
247
|
+
}
|
|
248
|
+
getXScale();
|
|
249
|
+
};
|
|
250
|
+
const getXScale = () => {
|
|
251
|
+
xScale = d3
|
|
252
|
+
.scalePoint()
|
|
253
|
+
.domain(filteredDimension)
|
|
254
|
+
.range(calculatedRange)
|
|
255
|
+
.padding(0.5);
|
|
256
|
+
};
|
|
257
|
+
const initAxis = () => {
|
|
258
|
+
getXAxis();
|
|
259
|
+
if (isPrimaryAxisDrawn) {
|
|
260
|
+
yAxisLeft = d3
|
|
261
|
+
.axisLeft(yScaleLeft)
|
|
262
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
|
|
263
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
264
|
+
? formatOptions.plotArea.gridLinesHorizontal
|
|
265
|
+
? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
|
|
266
|
+
: 0
|
|
267
|
+
: 0)
|
|
268
|
+
.tickValues(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray)
|
|
269
|
+
.ticks(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).customTickValue ??
|
|
270
|
+
(dataTableHeight > 0
|
|
271
|
+
? (innerHeight - dataTableHeight) / 30
|
|
272
|
+
: innerHeight / 30))
|
|
273
|
+
.tickSizeOuter(0);
|
|
274
|
+
}
|
|
275
|
+
if (isSecondaryAxisDrawn) {
|
|
276
|
+
yAxisRight = d3
|
|
277
|
+
.axisRight(yScaleRight)
|
|
278
|
+
.tickFormat((d) => getNumberWithFormat(d, formatOptions.secondaryYAxisLabel.secondaryYAxisDisplayUnits, formatOptions.secondaryYAxisLabel.secondaryYAxisNumberFormat, formatOptions.secondaryYAxisLabel
|
|
279
|
+
.secondaryYAxisLabelDecimalPrecision))
|
|
280
|
+
.tickValues(responsiveSecondaryYaxisLabel(secondaryCustomYaxisMaxValue
|
|
281
|
+
? secondaryCustomYaxisMaxValue
|
|
282
|
+
: chartJSON.yMaxRight, chartJSON.yMinRight, formatOptions, chartJSON).secondaryYAxisLabelArray)
|
|
283
|
+
.ticks(responsiveSecondaryYaxisLabel(secondaryCustomYaxisMaxValue
|
|
284
|
+
? secondaryCustomYaxisMaxValue
|
|
285
|
+
: chartJSON.yMaxRight, chartJSON.yMinRight, formatOptions, chartJSON).secondaryCustomTickValue ?? innerHeight / 30)
|
|
286
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
287
|
+
? formatOptions.plotArea.gridLinesHorizontal
|
|
288
|
+
? -innerWidth
|
|
289
|
+
: 0
|
|
290
|
+
: 0)
|
|
291
|
+
.tickSizeOuter(0);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const getXAxis = () => {
|
|
295
|
+
xAxis = d3
|
|
296
|
+
.axisBottom(xScale)
|
|
297
|
+
.tickSize(formatOptions.plotArea.gridLinesVisibility
|
|
298
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
299
|
+
? formatOptions.plotArea.gridLinesVertical
|
|
300
|
+
? -(dataTableHeight > 0
|
|
301
|
+
? innerHeight - dataTableHeight
|
|
302
|
+
: innerHeight)
|
|
303
|
+
: parseFloat(formatOptions.plotArea.ticksHeight) *
|
|
304
|
+
((dataTableHeight > 0
|
|
305
|
+
? innerHeight - dataTableHeight
|
|
306
|
+
: innerHeight) /
|
|
307
|
+
100) *
|
|
308
|
+
(formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
|
|
309
|
+
: 0
|
|
310
|
+
: 0)
|
|
311
|
+
.tickSizeOuter(0)
|
|
312
|
+
.tickValues(responsiveXaxisLabel(filteredDimension, innerWidth));
|
|
313
|
+
};
|
|
314
|
+
const getChartType = (lineData) => {
|
|
315
|
+
lineData.forEach((lData) => {
|
|
316
|
+
lData.data.forEach((cData) => {
|
|
317
|
+
cData.hideZero = lData.properties.hideZeroValues;
|
|
318
|
+
cData.axis = lData.properties.axis;
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
const lineGenerator = d3
|
|
322
|
+
.line()
|
|
323
|
+
.x((d) => xScale(d.dimension)
|
|
324
|
+
? xScale(d.dimension)
|
|
325
|
+
: null)
|
|
326
|
+
.y((d) => d.axis == "Primary"
|
|
327
|
+
? yScaleLeft(d.value)
|
|
328
|
+
: yScaleRight(d.value))
|
|
329
|
+
.defined((d) => (d.hideZero ? Boolean(d.value) : true))
|
|
330
|
+
.curve(getCurveType(formatOptions));
|
|
331
|
+
// Bind dummy data to ensure a single group is created
|
|
332
|
+
let lines = gTag.selectAll(".parentGroup").data([lineData]);
|
|
333
|
+
lines = lines
|
|
334
|
+
.enter()
|
|
335
|
+
.append("g")
|
|
336
|
+
.attr("class", "lines parentGroup")
|
|
337
|
+
.merge(lines);
|
|
338
|
+
// JOIN: one group per line
|
|
339
|
+
let lineGroups = lines.selectAll(".line-group").data((d) => d);
|
|
340
|
+
// ENTER: create group for each new line
|
|
341
|
+
let lineGroupsEnter = lineGroups
|
|
342
|
+
.enter()
|
|
343
|
+
.append("g")
|
|
344
|
+
.attr("class", "line-group");
|
|
345
|
+
// Append path to new groups
|
|
346
|
+
lineGroupsEnter
|
|
347
|
+
.attr("hoverId", (d) => d.legend.replace(/ /g, "-"))
|
|
348
|
+
.append("path")
|
|
349
|
+
.attr("class", "line")
|
|
350
|
+
.attr("fill", "none");
|
|
351
|
+
// ENTER + UPDATE
|
|
352
|
+
lineGroupsEnter
|
|
353
|
+
.merge(lineGroups)
|
|
354
|
+
.select("path")
|
|
355
|
+
.attr("d", (d) => lineGenerator(d.data))
|
|
356
|
+
.attr("stroke", (d) => d.properties.color !== "#ffffff" ? d.properties.color : "none")
|
|
357
|
+
.attr("stroke-dasharray", (d) => {
|
|
358
|
+
switch (d.properties.lineStyle) {
|
|
359
|
+
case staticLineStyle.dotted:
|
|
360
|
+
return "0,3";
|
|
361
|
+
case staticLineStyle.dashed:
|
|
362
|
+
return "20,10,5,5,5,10";
|
|
363
|
+
default:
|
|
364
|
+
return "";
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
.attr("stroke-linecap", (d) => d.properties.lineStyle === staticLineStyle.dotted ? "round" : "")
|
|
368
|
+
.attr("stroke-width", (d) => d.properties.lineStyle !== "None" ? d.properties.lineWidth : "0");
|
|
369
|
+
// EXIT: remove old groups
|
|
370
|
+
lineGroups.exit().remove();
|
|
371
|
+
//Markers
|
|
372
|
+
lineMarkers(lines, lineData, "None", xScale, yScaleLeft, yScaleRight, null, formatOptions, chartJSON, secondaryCustomYaxisMaxValue, secondaryCustomYaxisMinValue, customYaxisMinValue, customYaxisMaxValue, false);
|
|
373
|
+
};
|
|
374
|
+
const setSVGContainer = (margin) => {
|
|
375
|
+
innerWidth = width - margin.left - margin.right;
|
|
376
|
+
innerHeight = height - margin.bottom - margin.top;
|
|
377
|
+
};
|
|
378
|
+
const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
|
|
379
|
+
if (!formatOptions.plotArea.fitChart) {
|
|
380
|
+
// Scrollbar parameters
|
|
381
|
+
const scrollMax = seriesData[0].data.length - visibleBars;
|
|
382
|
+
// Scrollbar track & handle
|
|
383
|
+
const scrollbarY = height - 20;
|
|
384
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
385
|
+
getXScale();
|
|
386
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
387
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
388
|
+
getXAxis();
|
|
389
|
+
svg
|
|
390
|
+
.append("rect")
|
|
391
|
+
.attr("x", margin.left)
|
|
392
|
+
.attr("y", scrollbarY)
|
|
393
|
+
.attr("width", innerWidth)
|
|
394
|
+
.attr("height", 8)
|
|
395
|
+
.attr("fill", "#ddd")
|
|
396
|
+
.attr("rx", 4);
|
|
397
|
+
const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
|
|
398
|
+
const handle = svg
|
|
399
|
+
.append("rect")
|
|
400
|
+
.attr("x", margin.left)
|
|
401
|
+
.attr("y", scrollbarY)
|
|
402
|
+
.attr("width", handleWidth)
|
|
403
|
+
.attr("height", 8)
|
|
404
|
+
.attr("fill", "#999")
|
|
405
|
+
.attr("rx", 4)
|
|
406
|
+
.style("cursor", "ew-resize")
|
|
407
|
+
.call(d3.drag().on("drag", (event) => {
|
|
408
|
+
let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
|
|
409
|
+
handle.attr("x", x);
|
|
410
|
+
scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
|
|
411
|
+
filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
|
|
412
|
+
getXScale();
|
|
413
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
414
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
415
|
+
getXAxis();
|
|
416
|
+
drawLineChart();
|
|
417
|
+
}));
|
|
418
|
+
svg.on("wheel", (event) => {
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
|
|
421
|
+
? event.deltaX
|
|
422
|
+
: event.deltaY;
|
|
423
|
+
scrollPosition += scrollDelta > 0 ? 1 : -1;
|
|
424
|
+
scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
|
|
425
|
+
const x = margin.left +
|
|
426
|
+
((innerWidth - handleWidth) * scrollPosition) / scrollMax;
|
|
427
|
+
handle.attr("x", x);
|
|
428
|
+
getXScale();
|
|
429
|
+
filteredData = JSON.parse(JSON.stringify(seriesData));
|
|
430
|
+
filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
|
|
431
|
+
getXAxis();
|
|
432
|
+
drawLineChart();
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
drawLineChart();
|
|
436
|
+
};
|
|
437
|
+
const drawLineChart = () => {
|
|
438
|
+
// filteredData.forEach((data) => getChartType([data]));
|
|
439
|
+
getChartType(filteredData);
|
|
440
|
+
initXaxis(gTag, chartJSON, xLabel, formatOptions, xAxisObj[0], dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, barWidth, xAxisObj[0].dataType, innerWidth, innerHeight, filteredDimension);
|
|
441
|
+
commonAnnotations(seriesData, xScale, yScaleLeft, yScaleRight, // need to pass secondary axis scale if secondary axis is drawn
|
|
442
|
+
margin, d3Annotation, [], //this.labelExcludeList,
|
|
443
|
+
[], //this.individualLabelColor,
|
|
444
|
+
[], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
|
|
445
|
+
formatOptions, chartType, height, width, innerWidth, filteredDimension, innerHeight, chartId, svg);
|
|
446
|
+
let newSeriesLabelArray = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, yScaleRight, isSecondaryAxisDrawn).labelArray;
|
|
447
|
+
// adding series labels ( appending legends at the end of line : by default) in plot area
|
|
448
|
+
drawSeriesLabels(formatOptions, gTag, newSeriesLabelArray);
|
|
449
|
+
};
|
|
450
|
+
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%" } })] }));
|
|
451
|
+
};
|
|
452
|
+
export default LineChart;
|