@fluentui/react-charting 5.24.6 → 5.24.7
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/CHANGELOG.json +28 -1
- package/CHANGELOG.md +13 -2
- package/dist/react-charting.js +1 -1
- package/dist/react-charting.min.js +1 -1
- package/lib/components/CommonComponents/CartesianChart.base.d.ts +3 -2
- package/lib/components/CommonComponents/CartesianChart.base.js +118 -102
- package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +13 -10
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +15 -24
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.base.js +14 -12
- package/lib/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +13 -17
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
- package/lib/utilities/utilities.d.ts +3 -0
- package/lib/utilities/utilities.js +25 -38
- package/lib/utilities/utilities.js.map +1 -1
- package/lib/utilities/vbc-utils.d.ts +18 -0
- package/lib/utilities/vbc-utils.js +29 -0
- package/lib/utilities/vbc-utils.js.map +1 -1
- package/lib-amd/components/CommonComponents/CartesianChart.base.d.ts +3 -2
- package/lib-amd/components/CommonComponents/CartesianChart.base.js +117 -101
- package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
- package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +13 -10
- package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +14 -23
- package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
- package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js +13 -11
- package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
- package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +12 -16
- package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
- package/lib-amd/utilities/utilities.d.ts +3 -0
- package/lib-amd/utilities/utilities.js +26 -39
- package/lib-amd/utilities/utilities.js.map +1 -1
- package/lib-amd/utilities/vbc-utils.d.ts +18 -0
- package/lib-amd/utilities/vbc-utils.js +34 -1
- package/lib-amd/utilities/vbc-utils.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.base.d.ts +3 -2
- package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +117 -101
- package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +13 -10
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +14 -23
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js +13 -11
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +12 -16
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
- package/lib-commonjs/utilities/utilities.d.ts +3 -0
- package/lib-commonjs/utilities/utilities.js +27 -40
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/lib-commonjs/utilities/vbc-utils.d.ts +18 -0
- package/lib-commonjs/utilities/vbc-utils.js +34 -1
- package/lib-commonjs/utilities/vbc-utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -28,4 +28,33 @@ export var calculateAppropriateBarWidth = function (data, totalWidth, innerPaddi
|
|
|
28
28
|
var barWidth = Math.floor((totalWidth * closestPairDiff * (1 - innerPadding)) / (range + closestPairDiff * (1 - innerPadding)));
|
|
29
29
|
return barWidth;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Calculates the total width available for rendering bars.
|
|
33
|
+
*/
|
|
34
|
+
export var calcTotalWidth = function (containerWidth, margins, extraMargin) {
|
|
35
|
+
if (extraMargin === void 0) { extraMargin = 0; }
|
|
36
|
+
return containerWidth - (margins.left || 0) - (margins.right || 0) - extraMargin * 2;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Calculates the combined size of all bands and the gaps between them, in units relative to the bandwidth.
|
|
40
|
+
*/
|
|
41
|
+
export var calcTotalBandUnits = function (numBands, innerPadding) {
|
|
42
|
+
// inner_padding = space_between_bands / (space_between_bands + bandwidth)
|
|
43
|
+
// => space_between_bands = (inner_padding / (1 - inner_padding)) * bandwidth
|
|
44
|
+
var gapToBandRatio = innerPadding / (1 - innerPadding);
|
|
45
|
+
return numBands + (numBands - 1) * gapToBandRatio;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the total width required to render all bands including the gaps between them.
|
|
49
|
+
*/
|
|
50
|
+
export var calcRequiredWidth = function (bandwidth, numBands, innerPadding) {
|
|
51
|
+
return bandwidth * calcTotalBandUnits(numBands, innerPadding);
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Calculates the maximum possible bandwidth such that the combined widths of all bands
|
|
55
|
+
* and the gaps between them exactly fill the total available width.
|
|
56
|
+
*/
|
|
57
|
+
export var calcBandwidth = function (totalWidth, numBands, innerPadding) {
|
|
58
|
+
return totalWidth / calcTotalBandUnits(numBands, innerPadding);
|
|
59
|
+
};
|
|
31
60
|
//# sourceMappingURL=vbc-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vbc-utils.js","sourceRoot":"../src/","sources":["utilities/vbc-utils.ts"],"names":[],"mappings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GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAC,SAAiB,EAAE,QAAgB,EAAE,YAAoB;IACzF,OAAO,SAAS,GAAG,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,UAAkB,EAAE,QAAgB,EAAE,YAAoB;IACtF,OAAO,UAAU,GAAG,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["import { IMargins } from './utilities';\n\nexport const getClosestPairDiffAndRange = (data: number[] | Date[]): [number, number] | undefined => {\n if (data.length < 2) {\n return;\n }\n data = data.sort((a, b) =>\n a instanceof Date ? (a as Date).getTime() - (b as Date).getTime() : (a as number) - (b as number),\n );\n let minDiff = Number.MAX_VALUE;\n for (let i = 1; i < data.length; i++) {\n const diff =\n data[i] instanceof Date\n ? (data[i] as Date).getTime() - (data[i - 1] as Date).getTime()\n : (data[i] as number) - (data[i - 1] as number);\n minDiff = Math.min(minDiff, diff);\n }\n const range =\n data[0] instanceof Date\n ? (data[data.length - 1] as Date).getTime() - (data[0] as Date).getTime()\n : (data[data.length - 1] as number) - (data[0] as number);\n return [minDiff, range];\n};\n\nexport const calculateAppropriateBarWidth = (data: number[] | Date[], totalWidth: number, innerPadding: number) => {\n const result = getClosestPairDiffAndRange(data);\n if (!result || result[1] === 0) {\n return 16;\n }\n const [closestPairDiff, range] = result;\n // Refer to https://microsoft.github.io/fluentui-charting-contrib/docs/rfcs/fix-overlapping-bars-on-continuous-axes\n // for the derivation of the following formula.\n const barWidth = Math.floor(\n (totalWidth * closestPairDiff * (1 - innerPadding)) / (range + closestPairDiff * (1 - innerPadding)),\n );\n return barWidth;\n};\n\n/**\n * Calculates the total width available for rendering bars.\n */\nexport const calcTotalWidth = (containerWidth: number, margins: IMargins, extraMargin = 0): number => {\n return containerWidth - (margins.left || 0) - (margins.right || 0) - extraMargin * 2;\n};\n\n/**\n * Calculates the combined size of all bands and the gaps between them, in units relative to the bandwidth.\n */\nexport const calcTotalBandUnits = (numBands: number, innerPadding: number) => {\n // inner_padding = space_between_bands / (space_between_bands + bandwidth)\n // => space_between_bands = (inner_padding / (1 - inner_padding)) * bandwidth\n const gapToBandRatio = innerPadding / (1 - innerPadding);\n return numBands + (numBands - 1) * gapToBandRatio;\n};\n\n/**\n * Calculates the total width required to render all bands including the gaps between them.\n */\nexport const calcRequiredWidth = (bandwidth: number, numBands: number, innerPadding: number) => {\n return bandwidth * calcTotalBandUnits(numBands, innerPadding);\n};\n\n/**\n * Calculates the maximum possible bandwidth such that the combined widths of all bands\n * and the gaps between them exactly fill the total available width.\n */\nexport const calcBandwidth = (totalWidth: number, numBands: number, innerPadding: number) => {\n return totalWidth / calcTotalBandUnits(numBands, innerPadding);\n};\n"]}
|
|
@@ -6,8 +6,6 @@ export interface ICartesianChartState {
|
|
|
6
6
|
containerHeight: number;
|
|
7
7
|
_width: number;
|
|
8
8
|
_height: number;
|
|
9
|
-
isRemoveValCalculated?: boolean;
|
|
10
|
-
_removalValueForTextTuncate?: number;
|
|
11
9
|
startFromX: number;
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
@@ -32,6 +30,7 @@ export declare class CartesianChartBase extends React.Component<IModifiedCartesi
|
|
|
32
30
|
private _tickValues;
|
|
33
31
|
private titleMargin;
|
|
34
32
|
private _isFirstRender;
|
|
33
|
+
private _removalValueForTextTuncate;
|
|
35
34
|
private _xScale;
|
|
36
35
|
private isIntegralDataset;
|
|
37
36
|
private _tooltipId;
|
|
@@ -62,4 +61,6 @@ export declare class CartesianChartBase extends React.Component<IModifiedCartesi
|
|
|
62
61
|
private _calculateChartMinWidth;
|
|
63
62
|
private _getChartDescription;
|
|
64
63
|
private _getAxisTitle;
|
|
64
|
+
private _calcMaxLabelWidthWithTransform;
|
|
65
|
+
private _transformXAxisLabels;
|
|
65
66
|
}
|
|
@@ -25,6 +25,13 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
25
25
|
_this.minLegendContainerHeight = 32;
|
|
26
26
|
_this._isRtl = (0, Utilities_1.getRTL)();
|
|
27
27
|
_this._isFirstRender = true;
|
|
28
|
+
/* Used for when WrapXAxisLabels props appeared.
|
|
29
|
+
* To display the total word (space separated words), Need to have more space than usual.
|
|
30
|
+
* This height will get total height need to disaply total word.
|
|
31
|
+
* These value need to be removed from actual svg height/graph height.
|
|
32
|
+
* Defalut value is 0. And this values calculted when 'wrapXAxisLables' or 'showXAxisLablesTooltip' is true.
|
|
33
|
+
*/
|
|
34
|
+
_this._removalValueForTextTuncate = 0;
|
|
28
35
|
_this.isIntegralDataset = true;
|
|
29
36
|
_this.calculateMaxYAxisLabelLength = function (className) {
|
|
30
37
|
var formatTickLabel = function (str) {
|
|
@@ -62,43 +69,14 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
62
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
70
|
_this._getData = function (xScale, yScalePrimary, yScaleSecondary) {
|
|
64
71
|
_this.props.getGraphData &&
|
|
65
|
-
_this.props.getGraphData(xScale, yScalePrimary, _this.state.containerHeight - _this.
|
|
72
|
+
_this.props.getGraphData(xScale, yScalePrimary, _this.state.containerHeight - _this._removalValueForTextTuncate, _this.state.containerWidth, _this.xAxisElement, _this.yAxisElement, yScaleSecondary);
|
|
66
73
|
};
|
|
67
74
|
_this._onChartLeave = function () {
|
|
68
75
|
_this.props.onChartMouseLeave && _this.props.onChartMouseLeave();
|
|
69
76
|
};
|
|
70
77
|
_this._calculateChartMinWidth = function () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!_this.props.wrapXAxisLables &&
|
|
74
|
-
_this.props.rotateXAxisLables &&
|
|
75
|
-
_this.props.xAxisType === index_1.XAxisTypes.StringAxis) {
|
|
76
|
-
var longestLabelWidth = (0, index_1.calculateLongestLabelWidth)(_this._tickValues, ".".concat(_this._classNames.xAxis, " text"));
|
|
77
|
-
labelWidth += Math.ceil(longestLabelWidth * Math.cos(Math.PI / 4));
|
|
78
|
-
}
|
|
79
|
-
// Case: truncated labels
|
|
80
|
-
else if (_this.props.showXAxisLablesTooltip) {
|
|
81
|
-
var tickValues = _this._tickValues.map(function (val) {
|
|
82
|
-
var numChars = _this.props.noOfCharsToTruncate || 4;
|
|
83
|
-
return val.toString().length > numChars ? "".concat(val.toString().slice(0, numChars), "...") : val;
|
|
84
|
-
});
|
|
85
|
-
var longestLabelWidth = (0, index_1.calculateLongestLabelWidth)(tickValues, ".".concat(_this._classNames.xAxis, " text"));
|
|
86
|
-
labelWidth += Math.ceil(longestLabelWidth);
|
|
87
|
-
}
|
|
88
|
-
// Case: wrapped labels
|
|
89
|
-
else if (_this.props.wrapXAxisLables) {
|
|
90
|
-
var words_1 = [];
|
|
91
|
-
_this._tickValues.forEach(function (val) {
|
|
92
|
-
words_1.push.apply(words_1, val.toString().split(/\s+/));
|
|
93
|
-
});
|
|
94
|
-
var longestLabelWidth = (0, index_1.calculateLongestLabelWidth)(words_1, ".".concat(_this._classNames.xAxis, " text"));
|
|
95
|
-
labelWidth += Math.max(Math.ceil(longestLabelWidth), 10);
|
|
96
|
-
}
|
|
97
|
-
// Default case
|
|
98
|
-
else {
|
|
99
|
-
var longestLabelWidth = (0, index_1.calculateLongestLabelWidth)(_this._tickValues, ".".concat(_this._classNames.xAxis, " text"));
|
|
100
|
-
labelWidth += Math.ceil(longestLabelWidth);
|
|
101
|
-
}
|
|
78
|
+
// Adding 10px for padding on both sides
|
|
79
|
+
var labelWidth = _this._calcMaxLabelWidthWithTransform(_this._tickValues) + 10;
|
|
102
80
|
var minChartWidth = _this.margins.left + _this.margins.right + labelWidth * (_this._tickValues.length - 1);
|
|
103
81
|
if ([index_1.ChartTypes.GroupedVerticalBarChart, index_1.ChartTypes.VerticalBarChart, index_1.ChartTypes.VerticalStackedBarChart].includes(_this.props.chartType)) {
|
|
104
82
|
var minDomainMargin = 8;
|
|
@@ -124,13 +102,85 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
124
102
|
: 'values')) +
|
|
125
103
|
'. ');
|
|
126
104
|
};
|
|
105
|
+
_this._calcMaxLabelWidthWithTransform = function (x) {
|
|
106
|
+
// Case: rotated labels
|
|
107
|
+
if (!_this.props.wrapXAxisLables &&
|
|
108
|
+
_this.props.rotateXAxisLables &&
|
|
109
|
+
_this.props.xAxisType === index_1.XAxisTypes.StringAxis) {
|
|
110
|
+
var longestLabelWidth_1 = (0, index_1.calculateLongestLabelWidth)(x, ".".concat(_this._classNames.xAxis, " text"));
|
|
111
|
+
return Math.ceil(longestLabelWidth_1 * Math.cos(Math.PI / 4));
|
|
112
|
+
}
|
|
113
|
+
// Case: truncated labels
|
|
114
|
+
if (_this.props.showXAxisLablesTooltip) {
|
|
115
|
+
var tickValues = x.map(function (val) {
|
|
116
|
+
var numChars = _this.props.noOfCharsToTruncate || 4;
|
|
117
|
+
return val.toString().length > numChars ? "".concat(val.toString().slice(0, numChars), "...") : val;
|
|
118
|
+
});
|
|
119
|
+
var longestLabelWidth_2 = (0, index_1.calculateLongestLabelWidth)(tickValues, ".".concat(_this._classNames.xAxis, " text"));
|
|
120
|
+
return Math.ceil(longestLabelWidth_2);
|
|
121
|
+
}
|
|
122
|
+
// Case: wrapped labels
|
|
123
|
+
if (_this.props.wrapXAxisLables) {
|
|
124
|
+
// FIXME: Calculate the max width of lines instead of words. This requires applying
|
|
125
|
+
// the wrapping transformation earlier to obtain the actual rendered lines.
|
|
126
|
+
var words_1 = [];
|
|
127
|
+
x.forEach(function (val) {
|
|
128
|
+
words_1.push.apply(words_1, val.toString().split(/\s+/));
|
|
129
|
+
});
|
|
130
|
+
// This approach works well in most cases, since overflow typically occurs only when
|
|
131
|
+
// a single word exceeds the specified width — otherwise, the text will wrap as expected.
|
|
132
|
+
var longestLabelWidth_3 = (0, index_1.calculateLongestLabelWidth)(words_1, ".".concat(_this._classNames.xAxis, " text"));
|
|
133
|
+
return Math.max(Math.ceil(longestLabelWidth_3), index_1.DEFAULT_WRAP_WIDTH);
|
|
134
|
+
}
|
|
135
|
+
// Default case
|
|
136
|
+
var longestLabelWidth = (0, index_1.calculateLongestLabelWidth)(x, ".".concat(_this._classNames.xAxis, " text"));
|
|
137
|
+
return Math.ceil(longestLabelWidth);
|
|
138
|
+
};
|
|
139
|
+
_this._transformXAxisLabels = function () {
|
|
140
|
+
var _a, _b, _c;
|
|
141
|
+
_this._removalValueForTextTuncate = 0;
|
|
142
|
+
/*
|
|
143
|
+
* To enable wrapping of x axis tick values or to display complete x axis tick values,
|
|
144
|
+
* we need to calculate how much space it needed to render the text.
|
|
145
|
+
* No need to re-calculate every time the chart renders and same time need to get an update. So using setState.
|
|
146
|
+
* Required space will be calculated first time chart rendering and if any width/height of chart updated.
|
|
147
|
+
* */
|
|
148
|
+
if (_this.props.wrapXAxisLables || _this.props.showXAxisLablesTooltip) {
|
|
149
|
+
var maxXAxisLabelWidth = void 0;
|
|
150
|
+
if (_this.props.xAxisType === index_1.XAxisTypes.StringAxis) {
|
|
151
|
+
if ((((_a = _this.props.datasetForXAxisDomain) === null || _a === void 0 ? void 0 : _a.length) || 0) > 1) {
|
|
152
|
+
maxXAxisLabelWidth = _this._xScale.step();
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
maxXAxisLabelWidth = _this.state.containerWidth;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
var wrapLabelProps = {
|
|
159
|
+
node: _this.xAxisElement,
|
|
160
|
+
xAxis: _this._xScale,
|
|
161
|
+
showXAxisLablesTooltip: _this.props.showXAxisLablesTooltip || false,
|
|
162
|
+
noOfCharsToTruncate: _this.props.noOfCharsToTruncate || 4,
|
|
163
|
+
width: maxXAxisLabelWidth,
|
|
164
|
+
};
|
|
165
|
+
_this._removalValueForTextTuncate = (_b = (0, index_1.createWrapOfXLabels)(wrapLabelProps)) !== null && _b !== void 0 ? _b : 0;
|
|
166
|
+
}
|
|
167
|
+
if (!_this.props.wrapXAxisLables &&
|
|
168
|
+
_this.props.rotateXAxisLables &&
|
|
169
|
+
_this.props.xAxisType === index_1.XAxisTypes.StringAxis) {
|
|
170
|
+
var rotateLabelProps = {
|
|
171
|
+
node: _this.xAxisElement,
|
|
172
|
+
xAxis: _this._xScale,
|
|
173
|
+
};
|
|
174
|
+
var rotatedHeight = (_c = (0, index_1.rotateXAxisLabels)(rotateLabelProps)) !== null && _c !== void 0 ? _c : 0;
|
|
175
|
+
// this.margins.bottom is used as padding here
|
|
176
|
+
_this._removalValueForTextTuncate = rotatedHeight + _this.margins.bottom;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
127
179
|
_this.state = {
|
|
128
180
|
containerHeight: 0,
|
|
129
181
|
containerWidth: 0,
|
|
130
182
|
_width: _this.props.width || 600,
|
|
131
183
|
_height: _this.props.height || 350,
|
|
132
|
-
_removalValueForTextTuncate: 0,
|
|
133
|
-
isRemoveValCalculated: true,
|
|
134
184
|
startFromX: 0,
|
|
135
185
|
};
|
|
136
186
|
_this.idForGraph = (0, Utilities_1.getId)('chart_');
|
|
@@ -218,23 +268,6 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
218
268
|
if (prevProps.height !== this.props.height || prevProps.width !== this.props.width) {
|
|
219
269
|
this._fitParentContainer();
|
|
220
270
|
}
|
|
221
|
-
if (!this.props.wrapXAxisLables &&
|
|
222
|
-
this.props.rotateXAxisLables &&
|
|
223
|
-
this.props.xAxisType === index_1.XAxisTypes.StringAxis) {
|
|
224
|
-
var rotateLabelProps = {
|
|
225
|
-
node: this.xAxisElement,
|
|
226
|
-
xAxis: this._xScale,
|
|
227
|
-
};
|
|
228
|
-
var rotatedHeight = (0, index_1.rotateXAxisLabels)(rotateLabelProps);
|
|
229
|
-
if (this.state.isRemoveValCalculated &&
|
|
230
|
-
this.state._removalValueForTextTuncate !== rotatedHeight + this.margins.bottom &&
|
|
231
|
-
rotatedHeight > 0) {
|
|
232
|
-
this.setState({
|
|
233
|
-
_removalValueForTextTuncate: rotatedHeight + this.margins.bottom,
|
|
234
|
-
isRemoveValCalculated: false,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
271
|
if (chartTypesWithStringYAxis.includes(this.props.chartType) &&
|
|
239
272
|
this.props.showYAxisLables &&
|
|
240
273
|
this.yAxisElement &&
|
|
@@ -294,7 +327,13 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
294
327
|
domainNRangeValues: this.props.getDomainNRangeValues(points, this.props.getDomainMargins ? this.props.getDomainMargins(this.state.containerWidth) : this.margins, this.state.containerWidth, chartType, this._isRtl, this.props.xAxisType, this.props.barwidth, this.props.tickValues,
|
|
295
328
|
// This is only used for Horizontal Bar Chart with Axis for y as string axis
|
|
296
329
|
this.state.startFromX),
|
|
297
|
-
|
|
330
|
+
// FIXME: In XAxisParams, containerHeight is used by HBWA to generate vertical gridlines.
|
|
331
|
+
// Since the x-axis in HBWA is numeric, it typically doesn't require transformation.
|
|
332
|
+
// However, if transformation props are enabled, the updated _removalValueForTextTuncate
|
|
333
|
+
// will only be available in the next render, as it's set after the axis is created.
|
|
334
|
+
// Solution: Delay the creation of gridlines until after the transformation has been applied,
|
|
335
|
+
// or precompute the required height for transformed labels (_removalValueForTextTuncate).
|
|
336
|
+
containerHeight: this.state.containerHeight - this._removalValueForTextTuncate,
|
|
298
337
|
margins: this.margins,
|
|
299
338
|
xAxisElement: this.xAxisElement,
|
|
300
339
|
showRoundOffXTickValues: (_e = this.props.showRoundOffXTickValues) !== null && _e !== void 0 ? _e : true,
|
|
@@ -305,27 +344,8 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
305
344
|
xAxisInnerPadding: this.props.xAxisInnerPadding,
|
|
306
345
|
xAxisOuterPadding: this.props.xAxisOuterPadding,
|
|
307
346
|
containerWidth: this.state.containerWidth,
|
|
308
|
-
hideTickOverlap: this.props.hideTickOverlap
|
|
309
|
-
|
|
310
|
-
!this.props.showXAxisLablesTooltip &&
|
|
311
|
-
!this.props.wrapXAxisLables,
|
|
312
|
-
};
|
|
313
|
-
var YAxisParams = {
|
|
314
|
-
margins: this.props.getYDomainMargins ? this.props.getYDomainMargins(this.state.containerHeight) : this.margins,
|
|
315
|
-
containerWidth: this.state.containerWidth,
|
|
316
|
-
containerHeight: this.state.containerHeight - this.state._removalValueForTextTuncate,
|
|
317
|
-
yAxisElement: this.yAxisElement,
|
|
318
|
-
yAxisTickFormat: this.props.yAxisTickFormat,
|
|
319
|
-
yAxisTickCount: this.props.yAxisTickCount,
|
|
320
|
-
yMinValue: this.props.yMinValue || 0,
|
|
321
|
-
yMaxValue: this.props.yMaxValue || 0,
|
|
322
|
-
tickPadding: 10,
|
|
323
|
-
maxOfYVal: this.props.maxOfYVal,
|
|
324
|
-
yMinMaxValues: this.props.getMinMaxOfYAxis(points, this.props.yAxisType),
|
|
325
|
-
// please note these padding default values must be consistent in here
|
|
326
|
-
// and the parent chart(HBWA/Vertical etc..) for more details refer example
|
|
327
|
-
// http://using-d3js.com/04_07_ordinal_scales.html
|
|
328
|
-
yAxisPadding: this.props.yAxisPadding || 0,
|
|
347
|
+
hideTickOverlap: this.props.hideTickOverlap,
|
|
348
|
+
calcMaxLabelWidth: this._calcMaxLabelWidthWithTransform,
|
|
329
349
|
};
|
|
330
350
|
/**
|
|
331
351
|
* These scales used for 2 purposes.
|
|
@@ -351,25 +371,24 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
351
371
|
}
|
|
352
372
|
this._xScale = xScale;
|
|
353
373
|
this._tickValues = tickValues;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
374
|
+
this._transformXAxisLabels();
|
|
375
|
+
var YAxisParams = {
|
|
376
|
+
margins: this.props.getYDomainMargins ? this.props.getYDomainMargins(this.state.containerHeight) : this.margins,
|
|
377
|
+
containerWidth: this.state.containerWidth,
|
|
378
|
+
containerHeight: this.state.containerHeight - this._removalValueForTextTuncate,
|
|
379
|
+
yAxisElement: this.yAxisElement,
|
|
380
|
+
yAxisTickFormat: this.props.yAxisTickFormat,
|
|
381
|
+
yAxisTickCount: this.props.yAxisTickCount,
|
|
382
|
+
yMinValue: this.props.yMinValue || 0,
|
|
383
|
+
yMaxValue: this.props.yMaxValue || 0,
|
|
384
|
+
tickPadding: 10,
|
|
385
|
+
maxOfYVal: this.props.maxOfYVal,
|
|
386
|
+
yMinMaxValues: this.props.getMinMaxOfYAxis(points, this.props.yAxisType),
|
|
387
|
+
// please note these padding default values must be consistent in here
|
|
388
|
+
// and the parent chart(HBWA/Vertical etc..) for more details refer example
|
|
389
|
+
// http://using-d3js.com/04_07_ordinal_scales.html
|
|
390
|
+
yAxisPadding: this.props.yAxisPadding || 0,
|
|
391
|
+
};
|
|
373
392
|
/**
|
|
374
393
|
* These scales used for 2 purposes.
|
|
375
394
|
* 1. To create x and y axis
|
|
@@ -394,7 +413,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
394
413
|
var YAxisParamsSecondary = {
|
|
395
414
|
margins: this.margins,
|
|
396
415
|
containerWidth: this.state.containerWidth,
|
|
397
|
-
containerHeight: this.state.containerHeight - this.
|
|
416
|
+
containerHeight: this.state.containerHeight - this._removalValueForTextTuncate,
|
|
398
417
|
yAxisElement: this.yAxisElementSecondary,
|
|
399
418
|
yAxisTickFormat: this.props.yAxisTickFormat,
|
|
400
419
|
yAxisTickCount: this.props.yAxisTickCount,
|
|
@@ -467,7 +486,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
467
486
|
var yAxisTitleMaximumAllowedHeight = svgDimensions.height -
|
|
468
487
|
this.margins.bottom -
|
|
469
488
|
this.margins.top -
|
|
470
|
-
this.
|
|
489
|
+
this._removalValueForTextTuncate -
|
|
471
490
|
this.titleMargin;
|
|
472
491
|
var commonSvgToolTipProps = {
|
|
473
492
|
wrapContent: index_1.wrapContent,
|
|
@@ -503,7 +522,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
503
522
|
_this.xAxisElement = e;
|
|
504
523
|
}, id: "xAxisGElement".concat(this.idForGraph),
|
|
505
524
|
// To add wrap of x axis lables feature, need to remove word height from svg height.
|
|
506
|
-
transform: "translate(0, ".concat(svgDimensions.height - this.margins.bottom - this.
|
|
525
|
+
transform: "translate(0, ".concat(svgDimensions.height - this.margins.bottom - this._removalValueForTextTuncate, ")"), className: this._classNames.xAxis }),
|
|
507
526
|
this.props.xAxisTitle !== undefined && this.props.xAxisTitle !== '' && (React.createElement(SVGTooltipText_1.SVGTooltipText, tslib_1.__assign({ content: this.props.xAxisTitle, textProps: {
|
|
508
527
|
x: this.margins.left + this.state.startFromX + xAxisTitleMaximumAllowedWidth / 2,
|
|
509
528
|
y: svgDimensions.height - this.titleMargin,
|
|
@@ -530,8 +549,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
530
549
|
? this.margins.left + this.state.startFromX
|
|
531
550
|
: svgDimensions.width - this.margins.right - this.state.startFromX, ", 0)"), className: this._classNames.yAxis }),
|
|
532
551
|
this.props.secondaryYAxistitle !== undefined && this.props.secondaryYAxistitle !== '' && (React.createElement(SVGTooltipText_1.SVGTooltipText, tslib_1.__assign({ content: this.props.secondaryYAxistitle, textProps: {
|
|
533
|
-
x: (yAxisTitleMaximumAllowedHeight - this.margins.bottom) / 2 +
|
|
534
|
-
this.state._removalValueForTextTuncate,
|
|
552
|
+
x: (yAxisTitleMaximumAllowedHeight - this.margins.bottom) / 2 + this._removalValueForTextTuncate,
|
|
535
553
|
y: this._isRtl
|
|
536
554
|
? this.state.startFromX - this.titleMargin
|
|
537
555
|
: svgDimensions.width - this.margins.right,
|
|
@@ -544,8 +562,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
544
562
|
}, maxWidth: yAxisTitleMaximumAllowedHeight }, commonSvgToolTipProps))))),
|
|
545
563
|
children,
|
|
546
564
|
this.props.yAxisTitle !== undefined && this.props.yAxisTitle !== '' && (React.createElement(SVGTooltipText_1.SVGTooltipText, tslib_1.__assign({ content: this.props.yAxisTitle, textProps: {
|
|
547
|
-
x: (yAxisTitleMaximumAllowedHeight - this.margins.bottom) / 2 +
|
|
548
|
-
this.state._removalValueForTextTuncate,
|
|
565
|
+
x: (yAxisTitleMaximumAllowedHeight - this.margins.bottom) / 2 + this._removalValueForTextTuncate,
|
|
549
566
|
y: this._isRtl
|
|
550
567
|
? svgDimensions.width - this.margins.right / 2 + this.titleMargin
|
|
551
568
|
: this.margins.left / 2 - this.titleMargin,
|
|
@@ -557,8 +574,7 @@ define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Utilities",
|
|
|
557
574
|
this.props.yAxisAnnotation !== undefined &&
|
|
558
575
|
this.props.yAxisAnnotation !== '' &&
|
|
559
576
|
(this.props.secondaryYAxistitle === undefined || this.props.secondaryYAxistitle === '') && (React.createElement(SVGTooltipText_1.SVGTooltipText, tslib_1.__assign({ content: this.props.yAxisAnnotation, textProps: {
|
|
560
|
-
x: (yAxisTitleMaximumAllowedHeight - this.margins.bottom) / 2 +
|
|
561
|
-
this.state._removalValueForTextTuncate,
|
|
577
|
+
x: (yAxisTitleMaximumAllowedHeight - this.margins.bottom) / 2 + this._removalValueForTextTuncate,
|
|
562
578
|
y: this._isRtl
|
|
563
579
|
? this.state.startFromX - this.titleMargin
|
|
564
580
|
: svgDimensions.width - this.margins.right,
|