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