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