@fluentui/react-charting 5.24.14 → 5.24.16

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.
Files changed (59) hide show
  1. package/CHANGELOG.json +58 -1
  2. package/CHANGELOG.md +22 -2
  3. package/dist/react-charting.d.ts +27 -18
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +2 -1
  7. package/lib/Utilities.js +19 -1
  8. package/lib/Utilities.js.map +1 -1
  9. package/lib/components/CommonComponents/CartesianChart.base.js +6 -6
  10. package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
  11. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +31 -2
  12. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  13. package/lib/components/GanttChart/GanttChart.base.js +210 -158
  14. package/lib/components/GanttChart/GanttChart.base.js.map +1 -1
  15. package/lib/components/GanttChart/GanttChart.types.d.ts +23 -13
  16. package/lib/components/GanttChart/GanttChart.types.js.map +1 -1
  17. package/lib/components/ScatterChart/ScatterChart.base.js +15 -9
  18. package/lib/components/ScatterChart/ScatterChart.base.js.map +1 -1
  19. package/lib/types/IDataPoint.d.ts +4 -5
  20. package/lib/types/IDataPoint.js.map +1 -1
  21. package/lib/utilities/utilities.d.ts +6 -0
  22. package/lib/utilities/utilities.js +10 -0
  23. package/lib/utilities/utilities.js.map +1 -1
  24. package/lib-amd/Utilities.js +9 -0
  25. package/lib-amd/Utilities.js.map +1 -1
  26. package/lib-amd/components/CommonComponents/CartesianChart.base.js +6 -6
  27. package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
  28. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +31 -2
  29. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  30. package/lib-amd/components/GanttChart/GanttChart.base.js +210 -158
  31. package/lib-amd/components/GanttChart/GanttChart.base.js.map +1 -1
  32. package/lib-amd/components/GanttChart/GanttChart.types.d.ts +23 -13
  33. package/lib-amd/components/GanttChart/GanttChart.types.js.map +1 -1
  34. package/lib-amd/components/ScatterChart/ScatterChart.base.js +14 -8
  35. package/lib-amd/components/ScatterChart/ScatterChart.base.js.map +1 -1
  36. package/lib-amd/types/IDataPoint.d.ts +4 -5
  37. package/lib-amd/types/IDataPoint.js.map +1 -1
  38. package/lib-amd/utilities/utilities.d.ts +6 -0
  39. package/lib-amd/utilities/utilities.js +12 -1
  40. package/lib-amd/utilities/utilities.js.map +1 -1
  41. package/lib-commonjs/Utilities.js +9 -0
  42. package/lib-commonjs/Utilities.js.map +1 -1
  43. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +6 -6
  44. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
  45. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +31 -2
  46. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  47. package/lib-commonjs/components/GanttChart/GanttChart.base.js +210 -158
  48. package/lib-commonjs/components/GanttChart/GanttChart.base.js.map +1 -1
  49. package/lib-commonjs/components/GanttChart/GanttChart.types.d.ts +23 -13
  50. package/lib-commonjs/components/GanttChart/GanttChart.types.js.map +1 -1
  51. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js +14 -8
  52. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js.map +1 -1
  53. package/lib-commonjs/types/IDataPoint.d.ts +4 -5
  54. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  55. package/lib-commonjs/utilities/utilities.d.ts +6 -0
  56. package/lib-commonjs/utilities/utilities.js +12 -1
  57. package/lib-commonjs/utilities/utilities.js.map +1 -1
  58. package/package.json +2 -2
  59. package/src/components/GanttChart/GanttChart.types.ts +24 -13
@@ -10,39 +10,35 @@ var index_2 = require("../CommonComponents/index");
10
10
  var index_3 = require("../../utilities/index");
11
11
  var image_export_utils_1 = require("../../utilities/image-export-utils");
12
12
  var chart_utilities_1 = require("@fluentui/chart-utilities");
13
+ var DEFAULT_BAR_HEIGHT = 24;
14
+ var MIN_BAR_HEIGHT = 1;
13
15
  exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
14
16
  var _b, _c;
15
- var _d = _a.useUTC, useUTC = _d === void 0 ? true : _d, _e = _a.yAxisCategoryOrder, yAxisCategoryOrder = _e === void 0 ? 'default' : _e, props = tslib_1.__rest(_a, ["useUTC", "yAxisCategoryOrder"]);
16
- var _barHeight = React.useRef(0);
17
+ var _d = _a.useUTC, useUTC = _d === void 0 ? true : _d, _e = _a.yAxisCategoryOrder, yAxisCategoryOrder = _e === void 0 ? 'default' : _e, _f = _a.maxBarHeight, maxBarHeight = _f === void 0 ? 24 : _f, props = tslib_1.__rest(_a, ["useUTC", "yAxisCategoryOrder", "maxBarHeight"]);
18
+ var _barHeight = React.useRef(DEFAULT_BAR_HEIGHT);
17
19
  var _calloutId = React.useRef((0, react_1.getId)('callout'));
18
- var margins = React.useRef({});
19
- var _bars = React.useRef([]);
20
- var _xAxisType = React.useRef(index_3.XAxisTypes.DateAxis);
21
- var _yAxisType = React.useRef(index_3.YAxisType.StringAxis);
20
+ var _margins = React.useRef({});
22
21
  var _calloutAnchorPoint = React.useRef(null);
23
22
  var _cartesianChartRef = React.useRef(null);
24
23
  var _legendsRef = React.useRef(null);
25
- var _domainMargin = React.useRef(index_3.MIN_DOMAIN_MARGIN);
26
- var _yAxisPadding = React.useRef(0);
27
24
  var _emptyChartId = React.useRef((0, react_1.getId)('Gantt_empty'));
28
- var _legendColorMap = React.useRef({});
29
- var _gradientId = React.useRef((0, react_1.getId)('Gantt_gradient'));
30
- var prevProps = React.useRef({});
31
- var _f = React.useState(''), calloutColor = _f[0], setCalloutColor = _f[1];
32
- var _g = React.useState(false), isCalloutVisible = _g[0], setCalloutVisible = _g[1];
33
- var _h = React.useState(''), hoveredLegend = _h[0], setHoveredLegend = _h[1];
34
- var _j = React.useState(null), calloutTarget = _j[0], setCalloutTarget = _j[1];
35
- var _k = React.useState(''), calloutLegend = _k[0], setCalloutLegend = _k[1];
36
- var _l = React.useState(''), xCalloutValue = _l[0], setXCalloutValue = _l[1];
37
- var _m = React.useState(''), yCalloutValue = _m[0], setYCalloutValue = _m[1];
38
- var _o = React.useState(((_b = props.legendProps) === null || _b === void 0 ? void 0 : _b.selectedLegends) || []), selectedLegends = _o[0], setSelectedLegends = _o[1];
39
- var _p = React.useState(), dataPointCalloutProps = _p[0], setDataPointCalloutProps = _p[1];
25
+ var _legendMap = React.useRef({});
26
+ var _prevProps = React.useRef({});
27
+ var _g = React.useState(''), calloutColor = _g[0], setCalloutColor = _g[1];
28
+ var _h = React.useState(false), isCalloutVisible = _h[0], setCalloutVisible = _h[1];
29
+ var _j = React.useState(''), hoveredLegend = _j[0], setHoveredLegend = _j[1];
30
+ var _k = React.useState(null), calloutTarget = _k[0], setCalloutTarget = _k[1];
31
+ var _l = React.useState(''), calloutLegend = _l[0], setCalloutLegend = _l[1];
32
+ var _m = React.useState(''), xCalloutValue = _m[0], setXCalloutValue = _m[1];
33
+ var _o = React.useState(''), yCalloutValue = _o[0], setYCalloutValue = _o[1];
34
+ var _p = React.useState(((_b = props.legendProps) === null || _b === void 0 ? void 0 : _b.selectedLegends) || []), selectedLegends = _p[0], setSelectedLegends = _p[1];
35
+ var _q = React.useState(), calloutDataPoint = _q[0], setCalloutDataPoint = _q[1];
40
36
  React.useEffect(function () {
41
37
  var _a, _b, _c;
42
- if (!(0, index_3.areArraysEqual)((_a = prevProps.current.legendProps) === null || _a === void 0 ? void 0 : _a.selectedLegends, (_b = props.legendProps) === null || _b === void 0 ? void 0 : _b.selectedLegends)) {
38
+ if (!(0, index_3.areArraysEqual)((_a = _prevProps.current.legendProps) === null || _a === void 0 ? void 0 : _a.selectedLegends, (_b = props.legendProps) === null || _b === void 0 ? void 0 : _b.selectedLegends)) {
43
39
  setSelectedLegends(((_c = props.legendProps) === null || _c === void 0 ? void 0 : _c.selectedLegends) || []);
44
40
  }
45
- prevProps.current = props;
41
+ _prevProps.current = props;
46
42
  }, [props]);
47
43
  React.useImperativeHandle(props.componentRef, function () {
48
44
  var _a, _b;
@@ -56,29 +52,45 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
56
52
  }, []);
57
53
  var _points = React.useMemo(function () {
58
54
  var _a, _b;
59
- _legendColorMap.current = {};
55
+ _legendMap.current = {};
60
56
  var colorIndex = 0;
61
57
  return ((_b = (_a = props.data) === null || _a === void 0 ? void 0 : _a.map(function (point) {
62
58
  var _a, _b, _c, _d, _e;
63
59
  var legend = "".concat(point.legend);
64
- if (!_legendColorMap.current[legend]) {
65
- var startColor = point.color
60
+ if (!_legendMap.current[legend]) {
61
+ var startColor_1 = point.color
66
62
  ? (0, index_3.getColorFromToken)(point.color, (_a = props.theme) === null || _a === void 0 ? void 0 : _a.isInverted)
67
63
  : (0, index_3.getNextColor)(colorIndex, 0, (_b = props.theme) === null || _b === void 0 ? void 0 : _b.isInverted);
68
- var endColor = startColor;
64
+ var endColor_1 = startColor_1;
69
65
  if (props.enableGradient) {
70
66
  var nextGradient = (0, index_3.getNextGradient)(colorIndex, 0, (_c = props.theme) === null || _c === void 0 ? void 0 : _c.isInverted);
71
- startColor = ((_d = point.gradient) === null || _d === void 0 ? void 0 : _d[0]) || nextGradient[0];
72
- endColor = ((_e = point.gradient) === null || _e === void 0 ? void 0 : _e[1]) || nextGradient[1];
67
+ startColor_1 = ((_d = point.gradient) === null || _d === void 0 ? void 0 : _d[0]) || nextGradient[0];
68
+ endColor_1 = ((_e = point.gradient) === null || _e === void 0 ? void 0 : _e[1]) || nextGradient[1];
73
69
  }
74
- _legendColorMap.current[legend] = [startColor, endColor];
70
+ _legendMap.current[legend] = { id: (0, react_1.getId)('legend'), startColor: startColor_1, endColor: endColor_1 };
75
71
  colorIndex += 1;
76
72
  }
77
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, point), { color: _legendColorMap.current[legend][0] }), (props.enableGradient ? { gradient: _legendColorMap.current[legend] } : {}));
73
+ var _f = _legendMap.current[legend], startColor = _f.startColor, endColor = _f.endColor;
74
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, point), { color: startColor }), (props.enableGradient ? { gradient: [startColor, endColor] } : {}));
78
75
  })) !== null && _b !== void 0 ? _b : []);
79
76
  }, [props.data, (_c = props.theme) === null || _c === void 0 ? void 0 : _c.isInverted, props.enableGradient]);
77
+ var _xAxisType = React.useMemo(function () {
78
+ if (_points.length > 0) {
79
+ return (0, index_3.getTypeOfAxis)(_points[0].x.start, true);
80
+ }
81
+ return index_3.XAxisTypes.DateAxis;
82
+ }, [_points]);
83
+ var _yAxisType = React.useMemo(function () {
84
+ if (_points.length > 0) {
85
+ return (0, index_3.getTypeOfAxis)(_points[0].y, false);
86
+ }
87
+ return index_3.YAxisType.StringAxis;
88
+ }, [_points]);
89
+ var _yAxisPadding = React.useMemo(function () {
90
+ return (0, index_3.getScalePadding)(props.yAxisPadding, undefined, 1 / 2);
91
+ }, [props.yAxisPadding]);
80
92
  var _dateFormatOptions = React.useMemo(function () {
81
- if (_xAxisType.current !== index_3.XAxisTypes.DateAxis) {
93
+ if (_xAxisType !== index_3.XAxisTypes.DateAxis) {
82
94
  return undefined;
83
95
  }
84
96
  var lowestFormatLevel = 100;
@@ -90,8 +102,29 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
90
102
  highestFormatLevel = Math.max(highestFormatLevel, startFormatLevel, endFormatLevel);
91
103
  });
92
104
  return (0, chart_utilities_1.getMultiLevelDateTimeFormatOptions)(lowestFormatLevel, highestFormatLevel);
93
- }, [useUTC, _points]);
94
- var _getDomainNRangeValues = React.useCallback(function (points, _margins, containerWidth, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
105
+ }, [useUTC, _points, _xAxisType]);
106
+ var _mapYValueToXValues = React.useCallback(function () {
107
+ var yValueToXValues = {};
108
+ _points.forEach(function (point) {
109
+ if (!yValueToXValues[point.y]) {
110
+ yValueToXValues[point.y] = [];
111
+ }
112
+ yValueToXValues[point.y].push(+point.x.end - +point.x.start);
113
+ });
114
+ return yValueToXValues;
115
+ }, [_points]);
116
+ var _getOrderedYAxisLabels = React.useCallback(function () {
117
+ var yValueToXValues = _mapYValueToXValues();
118
+ if (_yAxisType !== index_3.YAxisType.StringAxis) {
119
+ return Object.keys(yValueToXValues).sort(function (a, b) { return +a - +b; });
120
+ }
121
+ if (yAxisCategoryOrder === 'default') {
122
+ return Object.keys(yValueToXValues).reverse();
123
+ }
124
+ return (0, index_3.sortAxisCategories)(yValueToXValues, yAxisCategoryOrder);
125
+ }, [_mapYValueToXValues, _yAxisType, yAxisCategoryOrder]);
126
+ var _yAxisLabels = React.useMemo(function () { return _getOrderedYAxisLabels(); }, [_getOrderedYAxisLabels]);
127
+ var _getDomainNRangeValues = React.useCallback(function (points, margins, containerWidth, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
95
128
  var xValues = [];
96
129
  points.forEach(function (point) {
97
130
  xValues.push(point.x.start, point.x.end);
@@ -101,36 +134,17 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
101
134
  return {
102
135
  dStartValue: isRTL ? xMax : xMin,
103
136
  dEndValue: isRTL ? xMin : xMax,
104
- rStartValue: _margins.left + (isRTL ? 0 : shiftX),
105
- rEndValue: containerWidth - _margins.right - (isRTL ? shiftX : 0),
137
+ rStartValue: margins.left + (isRTL ? 0 : shiftX),
138
+ rEndValue: containerWidth - margins.right - (isRTL ? shiftX : 0),
106
139
  };
107
140
  }, []);
108
- var _adjustProps = function () {
109
- _barHeight.current = Math.max(props.barHeight || 24, 1);
110
- if (props.data && props.data.length > 0) {
111
- _xAxisType.current = (0, index_3.getTypeOfAxis)(props.data[0].x.start, true);
112
- _yAxisType.current = (0, index_3.getTypeOfAxis)(props.data[0].y, false);
113
- }
114
- _yAxisPadding.current = (0, index_3.getScalePadding)(props.yAxisPadding, undefined, 1 / 2);
115
- };
116
- var _getMargins = React.useCallback(function (_margins) {
117
- margins.current = _margins;
141
+ var _getMargins = React.useCallback(function (margins) {
142
+ _margins.current = margins;
118
143
  }, []);
119
- var _renderContentForOnlyBars = function (point) {
120
- return (React.createElement(index_3.ChartHoverCard, { XValue: point.yAxisCalloutData || point.y.toString(), Legend: point.legend, YValue: point.xAxisCalloutData || _getFormattedXValue(point), color: point.color, culture: props.culture }));
121
- };
122
- var _renderCallout = function (point) {
123
- return point ? _renderContentForOnlyBars(point) : null;
124
- };
125
- var _getCustomizedCallout = function () {
126
- return props.onRenderCalloutPerDataPoint
127
- ? props.onRenderCalloutPerDataPoint(dataPointCalloutProps, _renderCallout)
128
- : null;
129
- };
130
144
  var _getFormattedXValue = React.useCallback(function (point) {
131
145
  var formattedStartX;
132
146
  var formattedEndX;
133
- if (_xAxisType.current === index_3.XAxisTypes.DateAxis) {
147
+ if (_xAxisType === index_3.XAxisTypes.DateAxis) {
134
148
  formattedStartX = (0, chart_utilities_1.formatDateToLocaleString)(point.x.start, props.culture, useUTC, false, _dateFormatOptions);
135
149
  formattedEndX = (0, chart_utilities_1.formatDateToLocaleString)(point.x.end, props.culture, useUTC, false, _dateFormatOptions);
136
150
  }
@@ -139,12 +153,22 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
139
153
  formattedEndX = point.x.end.toString();
140
154
  }
141
155
  return "".concat(formattedStartX, " - ").concat(formattedEndX);
142
- }, [props.culture, useUTC, _dateFormatOptions]);
156
+ }, [props.culture, useUTC, _dateFormatOptions, _xAxisType]);
157
+ var _getCustomizedCallout = React.useCallback(function () {
158
+ var defaultRender = function (point) {
159
+ return point ? (React.createElement(index_3.ChartHoverCard, { XValue: point.yAxisCalloutData || point.y.toString(), Legend: point.legend, YValue: point.xAxisCalloutData || _getFormattedXValue(point), color: point.color, culture: props.culture })) : null;
160
+ };
161
+ return props.onRenderCalloutPerDataPoint
162
+ ? props.onRenderCalloutPerDataPoint(calloutDataPoint, defaultRender)
163
+ : null;
164
+ //eslint-disable-next-line react-hooks/exhaustive-deps
165
+ }, [_getFormattedXValue, calloutDataPoint, props.culture, props.onRenderCalloutPerDataPoint]);
143
166
  var _getAriaLabel = React.useCallback(function (point) {
144
167
  var _a;
145
168
  var xValue = point.xAxisCalloutData || _getFormattedXValue(point);
146
169
  var yValue = point.yAxisCalloutData || point.y;
147
- return ((_a = point.callOutAccessibilityData) === null || _a === void 0 ? void 0 : _a.ariaLabel) || "".concat(yValue, ". ") + "".concat(xValue, ".");
170
+ return (((_a = point.callOutAccessibilityData) === null || _a === void 0 ? void 0 : _a.ariaLabel) ||
171
+ "".concat(yValue, ". ") + (point.legend ? "".concat(point.legend, ", ") : '') + "".concat(xValue, "."));
148
172
  }, [_getFormattedXValue]);
149
173
  var _getHighlightedLegend = React.useCallback(function () {
150
174
  return selectedLegends.length > 0 ? selectedLegends : hoveredLegend ? [hoveredLegend] : [];
@@ -175,7 +199,7 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
175
199
  setCalloutColor(point.color);
176
200
  setXCalloutValue(point.yAxisCalloutData || point.y.toString());
177
201
  setYCalloutValue(point.xAxisCalloutData || _getFormattedXValue(point));
178
- setDataPointCalloutProps(point);
202
+ setCalloutDataPoint(point);
179
203
  }, [_getFormattedXValue, _legendHighlighted, _noLegendHighlighted]);
180
204
  var _onBarFocus = React.useCallback(function (point, focusEvent) {
181
205
  _showCallout(focusEvent.currentTarget, point);
@@ -183,46 +207,9 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
183
207
  var _onBarHover = React.useCallback(function (point, mouseEvent) {
184
208
  _showCallout(mouseEvent.currentTarget, point);
185
209
  }, [_showCallout]);
186
- var _createBars = React.useCallback(function (xScale, yScale) {
187
- var bars = _points.map(function (point, index) {
188
- var shouldHighlight = _noLegendHighlighted() || _legendHighlighted(point.legend);
189
- var startColor = point.color;
190
- var endColor = startColor;
191
- if (props.enableGradient) {
192
- startColor = point.gradient[0];
193
- endColor = point.gradient[1];
194
- }
195
- var gradientId = "".concat(_gradientId.current, "_").concat(index);
196
- var startX = xScale(point.x.start);
197
- var endX = xScale(point.x.end);
198
- var y = (_yAxisType.current === index_3.YAxisType.StringAxis
199
- ? yScale(point.y) + yScale.bandwidth() / 2
200
- : yScale(point.y)) -
201
- _barHeight.current / 2;
202
- return (React.createElement(React.Fragment, { key: index },
203
- props.enableGradient && (React.createElement("defs", null,
204
- React.createElement("linearGradient", { id: gradientId },
205
- React.createElement("stop", { offset: "0", stopColor: startColor }),
206
- React.createElement("stop", { offset: "100%", stopColor: endColor })))),
207
- React.createElement("rect", { x: Math.min(startX, endX), y: y, width: Math.abs(endX - startX), height: _barHeight.current, rx: props.roundCorners ? 3 : 0, fill: props.enableGradient ? "url(#".concat(gradientId, ")") : startColor, opacity: shouldHighlight ? 1 : 0.1, onClick: point.onClick, onMouseOver: function (event) { return _onBarHover(point, event); }, onMouseLeave: _onBarLeave, onFocus: function (event) { return _onBarFocus(point, event); }, onBlur: _onBarLeave, "data-is-focusable": shouldHighlight, role: "img", "aria-label": _getAriaLabel(point) })));
208
- });
209
- return bars;
210
- }, [
211
- _getAriaLabel,
212
- _legendHighlighted,
213
- _noLegendHighlighted,
214
- _onBarFocus,
215
- _onBarHover,
216
- props.enableGradient,
217
- props.roundCorners,
218
- _points,
219
- ]);
220
- var _getGraphData = React.useCallback(function (xScale, yScale, containerHeight, containerWidth, xAxisElement, yAxisElement) {
221
- return (_bars.current = _createBars(xScale, yScale));
222
- }, [_createBars]);
223
- var _onBarLeave = function () {
210
+ var _onBarLeave = React.useCallback(function () {
224
211
  // do nothing
225
- };
212
+ }, []);
226
213
  var _handleChartMouseLeave = React.useCallback(function () {
227
214
  _calloutAnchorPoint.current = null;
228
215
  setCalloutTarget(null);
@@ -231,23 +218,111 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
231
218
  setCalloutColor('');
232
219
  setXCalloutValue('');
233
220
  setYCalloutValue('');
234
- setDataPointCalloutProps(undefined);
221
+ setCalloutDataPoint(undefined);
235
222
  }, []);
236
- var _closeCallout = function () {
223
+ var _closeCallout = React.useCallback(function () {
237
224
  setCalloutVisible(false);
238
- };
239
- var _onLegendHover = function (legend) {
225
+ }, []);
226
+ var _getBarHeight = React.useCallback(function (adjustedValue) {
227
+ var barHeight;
228
+ if (typeof props.barHeight === 'number') {
229
+ barHeight = props.barHeight;
230
+ }
231
+ else {
232
+ barHeight = adjustedValue;
233
+ }
234
+ if (typeof maxBarHeight === 'number') {
235
+ barHeight = Math.min(barHeight, maxBarHeight);
236
+ }
237
+ barHeight = Math.max(barHeight, MIN_BAR_HEIGHT);
238
+ return barHeight;
239
+ }, [maxBarHeight, props.barHeight]);
240
+ var _getOrderedDataPoints = React.useCallback(function () {
241
+ var result = [];
242
+ var yValueToPoints = {};
243
+ _points.forEach(function (point) {
244
+ if (!yValueToPoints[point.y]) {
245
+ yValueToPoints[point.y] = [];
246
+ }
247
+ yValueToPoints[point.y].push(point);
248
+ });
249
+ for (var i = _yAxisLabels.length - 1; i >= 0; i--) {
250
+ var yValue = _yAxisLabels[i];
251
+ if (yValueToPoints[yValue]) {
252
+ result.push.apply(result, yValueToPoints[yValue].sort(function (a, b) { return +a.x.start - +b.x.start; }));
253
+ }
254
+ }
255
+ return result;
256
+ }, [_points, _yAxisLabels]);
257
+ var _createBars = React.useCallback(function (_a) {
258
+ var xScale = _a.xScale, yScale = _a.yScalePrimary;
259
+ var getGradientId = function (legend) {
260
+ var legendId = _legendMap.current["".concat(legend)].id;
261
+ return "".concat(legendId, "_gradient");
262
+ };
263
+ var gradientDefs = [];
264
+ if (props.enableGradient) {
265
+ Object.keys(_legendMap.current).forEach(function (legend, index) {
266
+ var _a = _legendMap.current[legend], startColor = _a.startColor, endColor = _a.endColor;
267
+ gradientDefs.push(React.createElement("linearGradient", { key: index, id: getGradientId(legend) },
268
+ React.createElement("stop", { offset: "0", stopColor: startColor }),
269
+ React.createElement("stop", { offset: "100%", stopColor: endColor })));
270
+ });
271
+ }
272
+ var scaleBandwidth = 0;
273
+ if (_yAxisType === index_3.YAxisType.StringAxis) {
274
+ scaleBandwidth = yScale.bandwidth();
275
+ _barHeight.current = _getBarHeight(scaleBandwidth);
276
+ }
277
+ var points = _getOrderedDataPoints();
278
+ var bars = points.map(function (point, index) {
279
+ var rectStartX = xScale(point.x.start);
280
+ var rectEndX = xScale(point.x.end);
281
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
282
+ var rectY = yScale(point.y) + (scaleBandwidth - _barHeight.current) / 2;
283
+ var shouldHighlight = _noLegendHighlighted() || _legendHighlighted(point.legend);
284
+ return (React.createElement("rect", { key: index, x: Math.min(rectStartX, rectEndX), y: rectY, width: Math.abs(rectEndX - rectStartX), height: _barHeight.current, rx: props.roundCorners ? 3 : 0, fill: props.enableGradient ? "url(#".concat(getGradientId(point.legend), ")") : point.color, opacity: shouldHighlight ? 1 : 0.1, onClick: point.onClick, onMouseOver: function (event) { return _onBarHover(point, event); }, onMouseLeave: _onBarLeave, onFocus: function (event) { return _onBarFocus(point, event); }, onBlur: _onBarLeave, "data-is-focusable": shouldHighlight, role: "img", "aria-label": _getAriaLabel(point) }));
285
+ });
286
+ return (React.createElement("g", null,
287
+ gradientDefs.length > 0 ? React.createElement("defs", null, gradientDefs) : null,
288
+ bars));
289
+ }, [
290
+ _getAriaLabel,
291
+ _getBarHeight,
292
+ _getOrderedDataPoints,
293
+ _legendHighlighted,
294
+ _noLegendHighlighted,
295
+ _onBarFocus,
296
+ _onBarHover,
297
+ _onBarLeave,
298
+ _yAxisType,
299
+ props.enableGradient,
300
+ props.roundCorners,
301
+ ]);
302
+ var _onLegendHover = React.useCallback(function (legend) {
240
303
  setHoveredLegend(legend);
241
- };
242
- var _onLegendLeave = function () {
304
+ }, []);
305
+ var _onLegendLeave = React.useCallback(function () {
243
306
  setHoveredLegend('');
244
- };
245
- var _getLegendData = function () {
307
+ }, []);
308
+ var _onLegendSelectionChange = React.useCallback(function (_selectedLegends, event, currentLegend) {
309
+ var _a, _b;
310
+ if ((_a = props.legendProps) === null || _a === void 0 ? void 0 : _a.canSelectMultipleLegends) {
311
+ setSelectedLegends(_selectedLegends);
312
+ }
313
+ else {
314
+ setSelectedLegends(_selectedLegends.slice(-1));
315
+ }
316
+ if ((_b = props.legendProps) === null || _b === void 0 ? void 0 : _b.onChange) {
317
+ props.legendProps.onChange(_selectedLegends, event, currentLegend);
318
+ }
319
+ }, [props.legendProps]);
320
+ var _getLegendData = React.useCallback(function () {
246
321
  var actions = [];
247
- Object.keys(_legendColorMap.current).forEach(function (legendTitle) {
322
+ Object.keys(_legendMap.current).forEach(function (legendTitle) {
248
323
  var legend = {
249
324
  title: legendTitle,
250
- color: _legendColorMap.current[legendTitle][0],
325
+ color: _legendMap.current[legendTitle].startColor,
251
326
  hoverAction: function () {
252
327
  _handleChartMouseLeave();
253
328
  _onLegendHover(legendTitle);
@@ -260,69 +335,46 @@ exports.GanttChartBase = React.forwardRef(function (_a, forwardedRef) {
260
335
  });
261
336
  var legends = (React.createElement(index_1.Legends, tslib_1.__assign({ legends: actions, enabledWrapLines: props.enabledLegendsWrapLines, overflowProps: props.legendsOverflowProps, focusZonePropsInHoverCard: props.focusZonePropsForLegendsInHoverCard, overflowText: props.legendsOverflowText, onChange: _onLegendSelectionChange, ref: _legendsRef }, props.legendProps)));
262
337
  return legends;
263
- };
264
- var _onLegendSelectionChange = function (_selectedLegends, event, currentLegend) {
265
- var _a, _b;
266
- if ((_a = props.legendProps) === null || _a === void 0 ? void 0 : _a.canSelectMultipleLegends) {
267
- setSelectedLegends(_selectedLegends);
268
- }
269
- else {
270
- setSelectedLegends(_selectedLegends.slice(-1));
271
- }
272
- if ((_b = props.legendProps) === null || _b === void 0 ? void 0 : _b.onChange) {
273
- props.legendProps.onChange(_selectedLegends, event, currentLegend);
274
- }
275
- };
276
- var _getChartTitle = function () {
277
- var chartTitle = props.chartTitle;
278
- return (chartTitle ? "".concat(chartTitle, ". ") : '') + "Gantt chart with ".concat(_points.length, " bars. ");
279
- };
280
- var _isChartEmpty = function () {
281
- return !(props.data && props.data.length > 0);
282
- };
338
+ }, [
339
+ _handleChartMouseLeave,
340
+ _onLegendHover,
341
+ _onLegendLeave,
342
+ _onLegendSelectionChange,
343
+ props.enabledLegendsWrapLines,
344
+ props.focusZonePropsForLegendsInHoverCard,
345
+ props.legendProps,
346
+ props.legendsOverflowProps,
347
+ props.legendsOverflowText,
348
+ ]);
349
+ var _getChartTitle = React.useCallback(function () {
350
+ return (props.chartTitle ? "".concat(props.chartTitle, ". ") : '') + "Gantt chart with ".concat(_points.length, " data points. ");
351
+ }, [_points.length, props.chartTitle]);
352
+ var _isChartEmpty = React.useCallback(function () {
353
+ return _points.length === 0;
354
+ }, [_points.length]);
283
355
  var _getYDomainMargins = React.useCallback(function (containerHeight) {
284
- _domainMargin.current = index_3.MIN_DOMAIN_MARGIN;
356
+ var domainMargin = index_3.MIN_DOMAIN_MARGIN;
285
357
  var ySet = new Set();
286
358
  _points.forEach(function (point) {
287
359
  ySet.add(point.y);
288
360
  });
289
361
  var uniqueY = Array.from(ySet);
290
362
  /** Total height available to render the bars */
291
- var totalHeight = containerHeight - (margins.current.top + index_3.MIN_DOMAIN_MARGIN) - (margins.current.bottom + index_3.MIN_DOMAIN_MARGIN);
292
- if (_yAxisType.current !== index_3.YAxisType.StringAxis) {
293
- _barHeight.current = Math.max(props.barHeight ||
294
- (0, index_3.calculateAppropriateBarWidth)(uniqueY, totalHeight, _yAxisPadding.current), 1);
295
- _domainMargin.current += _barHeight.current / 2;
363
+ var totalHeight = containerHeight - (_margins.current.top + index_3.MIN_DOMAIN_MARGIN) - (_margins.current.bottom + index_3.MIN_DOMAIN_MARGIN);
364
+ if (_yAxisType !== index_3.YAxisType.StringAxis) {
365
+ _barHeight.current = _getBarHeight((0, index_3.calculateAppropriateBarWidth)(uniqueY, totalHeight, _yAxisPadding));
366
+ domainMargin += _barHeight.current / 2;
296
367
  }
297
- return tslib_1.__assign(tslib_1.__assign({}, margins.current), { top: margins.current.top + _domainMargin.current, bottom: margins.current.bottom + _domainMargin.current });
298
- }, [props.barHeight, _points]);
299
- var _getOrderedYAxisLabels = function () {
300
- return (0, index_3.sortAxisCategories)(_mapCategoryToValues(), yAxisCategoryOrder);
301
- };
302
- var _mapCategoryToValues = function () {
303
- var categoryToValues = {};
304
- _points.forEach(function (point) {
305
- if (!categoryToValues[point.y]) {
306
- categoryToValues[point.y] = [];
307
- }
308
- // FIXME
309
- // categoryToValues[point.y].push(point.x.end - point.x.start);
310
- });
311
- return categoryToValues;
312
- };
313
- var _renderBars = React.useCallback(function () {
314
- return React.createElement("g", null, _bars.current);
315
- }, []);
368
+ return tslib_1.__assign(tslib_1.__assign({}, _margins.current), { top: _margins.current.top + domainMargin, bottom: _margins.current.bottom + domainMargin });
369
+ }, [_getBarHeight, _points, _yAxisPadding, _yAxisType]);
316
370
  if (!_isChartEmpty()) {
317
- _adjustProps();
318
- var yAxisLabels = _getOrderedYAxisLabels();
319
- var legendBars = _getLegendData();
371
+ _barHeight.current = _getBarHeight(DEFAULT_BAR_HEIGHT);
320
372
  var calloutProps = tslib_1.__assign({ isCalloutVisible: isCalloutVisible, directionalHint: react_1.DirectionalHint.topAutoEdge, id: "toolTip".concat(_calloutId.current), target: calloutTarget, isBeakVisible: false, gapSpace: 15, color: calloutColor, legend: calloutLegend, XValue: xCalloutValue, YValue: yCalloutValue, onDismiss: _closeCallout, preventDismissOnLostFocus: true }, props.calloutProps);
321
373
  var tickParams = {
322
374
  tickValues: props.tickValues,
323
375
  tickFormat: props.tickFormat,
324
376
  };
325
- return (React.createElement(index_2.CartesianChart, tslib_1.__assign({}, props, { yAxisPadding: _yAxisPadding.current, chartTitle: _getChartTitle(), points: _points, chartType: index_3.ChartTypes.GanttChart, xAxisType: _xAxisType.current, yAxisType: _yAxisType.current, stringDatasetForYAxisDomain: yAxisLabels, calloutProps: calloutProps, tickParams: tickParams, legendBars: legendBars, createYAxis: index_3.createYAxisForHorizontalBarChartWithAxis, getDomainNRangeValues: _getDomainNRangeValues, createStringYAxis: index_3.createStringYAxisForHorizontalBarChartWithAxis, getMinMaxOfYAxis: index_3.findHBCWANumericMinMaxOfY, focusZoneDirection: react_1.FocusZoneDirection.vertical, customizedCallout: _getCustomizedCallout(), getmargins: _getMargins, getYDomainMargins: _getYDomainMargins, getGraphData: _getGraphData, onChartMouseLeave: _handleChartMouseLeave, ref: _cartesianChartRef, useUTC: useUTC, children: _renderBars })));
377
+ return (React.createElement(index_2.CartesianChart, tslib_1.__assign({}, props, { yAxisPadding: _yAxisPadding, chartTitle: _getChartTitle(), points: _points, chartType: index_3.ChartTypes.GanttChart, xAxisType: _xAxisType, yAxisType: _yAxisType, stringDatasetForYAxisDomain: _yAxisLabels, calloutProps: calloutProps, tickParams: tickParams, legendBars: _getLegendData(), createYAxis: index_3.createYAxisForHorizontalBarChartWithAxis, getDomainNRangeValues: _getDomainNRangeValues, createStringYAxis: index_3.createStringYAxisForHorizontalBarChartWithAxis, getMinMaxOfYAxis: index_3.findHBCWANumericMinMaxOfY, focusZoneDirection: react_1.FocusZoneDirection.bidirectional, customizedCallout: _getCustomizedCallout(), getmargins: _getMargins, getYDomainMargins: _getYDomainMargins, onChartMouseLeave: _handleChartMouseLeave, ref: _cartesianChartRef, useUTC: useUTC, children: _createBars })));
326
378
  }
327
379
  else {
328
380
  return (React.createElement("div", { id: _emptyChartId.current, role: 'alert', style: { opacity: '0' }, "aria-label": 'Graph has no data to display' }));