@fluentui/react-charts 0.0.0-nightly-20250825-0406.1 → 0.0.0-nightly-20250826-2140.1
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.md +15 -48
- package/dist/index.d.ts +1 -9
- package/lib/components/AreaChart/AreaChart.js +1 -4
- package/lib/components/AreaChart/AreaChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.js +9 -13
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +16 -32
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlyColorAdapter.js +1 -1
- package/lib/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +199 -293
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js +1 -6
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib/components/DonutChart/useDonutChartStyles.styles.js +4 -21
- package/lib/components/DonutChart/useDonutChartStyles.styles.js.map +1 -1
- package/lib/components/DonutChart/useDonutChartStyles.styles.raw.js +3 -16
- package/lib/components/DonutChart/useDonutChartStyles.styles.raw.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +4 -23
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib/components/HeatMapChart/HeatMapChart.js +114 -175
- package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +6 -26
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.js +30 -49
- package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -1
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js +3 -19
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib/components/ScatterChart/useScatterChartStyles.styles.raw.js +2 -14
- package/lib/components/ScatterChart/useScatterChartStyles.styles.raw.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +4 -27
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +44 -61
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib/utilities/utilities.js +29 -0
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/components/AreaChart/AreaChart.js +1 -4
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +9 -13
- package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +15 -31
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +198 -301
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js +1 -6
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.js +4 -32
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.raw.js +3 -16
- package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +3 -22
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +113 -174
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +5 -25
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.js +30 -49
- package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +2 -28
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.raw.js +1 -13
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +3 -26
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +43 -60
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +32 -0
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +12 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ChartTypes, getAccessibleDataObject, getColorContrast, getTypeOfAxis, resolveCSSVariables, XAxisTypes, YAxisType, createNumericYAxis, domainRangeOfXStringAxis, createStringYAxis, useRtl
|
|
2
|
+
import { ChartTypes, getAccessibleDataObject, getColorContrast, getTypeOfAxis, resolveCSSVariables, XAxisTypes, YAxisType, createNumericYAxis, domainRangeOfXStringAxis, createStringYAxis, useRtl } from '../../utilities/index';
|
|
3
3
|
import { formatToLocaleString } from '@fluentui/chart-utilities';
|
|
4
4
|
import { CartesianChart } from '../CommonComponents/index';
|
|
5
5
|
import { useId } from '@fluentui/react-utilities';
|
|
@@ -10,13 +10,7 @@ import { scaleLinear as d3ScaleLinear } from 'd3-scale';
|
|
|
10
10
|
import { format as d3Format } from 'd3-format';
|
|
11
11
|
import { timeFormat as d3TimeFormat } from 'd3-time-format';
|
|
12
12
|
import { toImage } from '../../utilities/image-export-utils';
|
|
13
|
-
export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props
|
|
14
|
-
xAxisCategoryOrder: 'default',
|
|
15
|
-
yAxisCategoryOrder: 'default',
|
|
16
|
-
data: [],
|
|
17
|
-
domainValuesForColorScale: [],
|
|
18
|
-
rangeValuesForColorScale: []
|
|
19
|
-
}, forwardedRef)=>{
|
|
13
|
+
export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
20
14
|
const classes = useHeatMapChartStyles(props);
|
|
21
15
|
const _stringXAxisDataPoints = React.useRef([]);
|
|
22
16
|
const _stringYAxisDataPoints = React.useRef([]);
|
|
@@ -141,16 +135,16 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
141
135
|
return color === tokens.colorNeutralForeground1 ? tokens.colorNeutralBackground1 : tokens.colorNeutralForeground1;
|
|
142
136
|
};
|
|
143
137
|
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
* This is the function which is responsible for
|
|
139
|
+
* drawing the rectangle in the graph and also
|
|
140
|
+
* attaching dom events to that rectangles
|
|
141
|
+
*/ const _createRectangles = ()=>{
|
|
148
142
|
const rectangles = [];
|
|
149
143
|
const yAxisDataPoints = _stringYAxisDataPoints.current.slice().reverse();
|
|
150
144
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
* yAxisDataPoint is noting but the DataPoint
|
|
146
|
+
* which will be rendered on the y-axis
|
|
147
|
+
*/ yAxisDataPoints.forEach((yAxisDataPoint)=>{
|
|
154
148
|
let index = 0;
|
|
155
149
|
_stringXAxisDataPoints.current.forEach((xAxisDataPoint)=>{
|
|
156
150
|
var _dataSet_current_yAxisDataPoint_index, _dataSet_current_yAxisDataPoint_index1;
|
|
@@ -159,9 +153,9 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
159
153
|
if (((_dataSet_current_yAxisDataPoint_index = _dataSet.current[yAxisDataPoint][index]) === null || _dataSet_current_yAxisDataPoint_index === void 0 ? void 0 : _dataSet_current_yAxisDataPoint_index.x) === xAxisDataPoint && typeof ((_dataSet_current_yAxisDataPoint_index1 = _dataSet.current[yAxisDataPoint][index]) === null || _dataSet_current_yAxisDataPoint_index1 === void 0 ? void 0 : _dataSet_current_yAxisDataPoint_index1.value) === 'number') {
|
|
160
154
|
var _cartesianChartRef_current;
|
|
161
155
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
* dataPointObject is an object where it contains information on single
|
|
157
|
+
* data point such as x, y , value, rectText property of the rectangle
|
|
158
|
+
*/ const dataPointObject = _dataSet.current[yAxisDataPoint][index];
|
|
165
159
|
let styleRules = '';
|
|
166
160
|
let foregroundColor = tokens.colorNeutralForeground1;
|
|
167
161
|
if ((_cartesianChartRef_current = cartesianChartRef.current) === null || _cartesianChartRef_current === void 0 ? void 0 : _cartesianChartRef_current.chartContainer) {
|
|
@@ -225,30 +219,30 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
225
219
|
return rectangles;
|
|
226
220
|
};
|
|
227
221
|
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
222
|
+
* when the legend is hovered we need to highlight
|
|
223
|
+
* all the rectangles which fall under that category
|
|
224
|
+
* and un-highlight the rest of them
|
|
225
|
+
* @param legendTitle
|
|
226
|
+
*/ const _onLegendHover = (legendTitle)=>{
|
|
233
227
|
setActiveLegend(legendTitle);
|
|
234
228
|
};
|
|
235
229
|
/**
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
230
|
+
* when the mouse is out from the legend , we need
|
|
231
|
+
* to show the graph in initial mode.
|
|
232
|
+
*/ const _onLegendLeave = ()=>{
|
|
239
233
|
setActiveLegend('');
|
|
240
234
|
};
|
|
241
235
|
/**
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
* @param legendTitle
|
|
237
|
+
* when the legend is clicked we need to highlight
|
|
238
|
+
* all the rectangles which fall under that category
|
|
239
|
+
* and un highlight the rest of them
|
|
240
|
+
*/ const _onLegendClick = (legendTitle)=>{
|
|
247
241
|
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
242
|
+
* check if the legend is already selceted,
|
|
243
|
+
* if yes, un-select the legend, else
|
|
244
|
+
* set the selected legend state to legendTitle
|
|
245
|
+
*/ if (selectedLegend === legendTitle) {
|
|
252
246
|
setSelectedLegend('');
|
|
253
247
|
} else {
|
|
254
248
|
setSelectedLegend(legendTitle);
|
|
@@ -319,13 +313,19 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
319
313
|
yAxisStringFormatter
|
|
320
314
|
]);
|
|
321
315
|
/**
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
316
|
+
* This function will return the final sorted and formatted x-axis points
|
|
317
|
+
* which will be rendered on the x-axis
|
|
318
|
+
* @param points
|
|
319
|
+
* @returns x-axis points
|
|
320
|
+
*/ const _getXAxisDataPoints = React.useCallback((points)=>{
|
|
327
321
|
let xAxisPoints = [];
|
|
328
|
-
const unFormattedXAxisDataPoints =
|
|
322
|
+
const unFormattedXAxisDataPoints = Object.keys(points).sort((a, b)=>{
|
|
323
|
+
if (_xAxisType.current === XAxisTypes.DateAxis || _xAxisType.current === XAxisTypes.NumericAxis) {
|
|
324
|
+
return +a - +b;
|
|
325
|
+
} else {
|
|
326
|
+
return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
329
|
xAxisPoints = unFormattedXAxisDataPoints.map((xPoint)=>{
|
|
330
330
|
if (_xAxisType.current === XAxisTypes.DateAxis) {
|
|
331
331
|
return _getStringFormattedDate(xPoint, props.xAxisDateFormatString);
|
|
@@ -343,13 +343,19 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
343
343
|
props.xAxisNumberFormatString
|
|
344
344
|
]);
|
|
345
345
|
/**
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
346
|
+
* This function will return the final sorted and formatted y-axis points
|
|
347
|
+
* which will be rendered on the y-axis
|
|
348
|
+
* @param points
|
|
349
|
+
* @returns yaxis points
|
|
350
|
+
*/ const _getYAxisDataPoints = React.useCallback((points)=>{
|
|
351
351
|
let yAxisPoints = [];
|
|
352
|
-
const unFormattedYAxisDataPoints =
|
|
352
|
+
const unFormattedYAxisDataPoints = Object.keys(points).sort((a, b)=>{
|
|
353
|
+
if (_yAxisType.current === YAxisType.DateAxis || _yAxisType.current === YAxisType.NumericAxis) {
|
|
354
|
+
return +a - +b;
|
|
355
|
+
} else {
|
|
356
|
+
return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
353
359
|
yAxisPoints = unFormattedYAxisDataPoints.map((yPoint)=>{
|
|
354
360
|
if (_yAxisType.current === YAxisType.DateAxis) {
|
|
355
361
|
return _getStringFormattedDate(yPoint, props.yAxisDateFormatString);
|
|
@@ -367,24 +373,24 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
367
373
|
props.yAxisNumberFormatString
|
|
368
374
|
]);
|
|
369
375
|
/**
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
376
|
+
* This will create a new data set based on the prop
|
|
377
|
+
* @data
|
|
378
|
+
* We will be using This data set to contsruct our rectangles
|
|
379
|
+
* in the chart, we use this data set becuase, when we loop in this
|
|
380
|
+
* data and build the heat map, it will support accessibility as
|
|
381
|
+
* specified in the figma
|
|
382
|
+
*/ const _createNewDataSet = React.useCallback((data, xAxisDateFormatString, xAxisNumberFormatString, yAxisDateFormatString, yAxisNumberFormatString)=>{
|
|
377
383
|
/**
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
384
|
+
* please do not destructure any of the props here,
|
|
385
|
+
* instead send them as parameter to this functions so that
|
|
386
|
+
* this functions get called whenever the prop changes
|
|
387
|
+
*/ const flattenData = [];
|
|
382
388
|
/**
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
* below for each loop will store all the datapoints in the one array.
|
|
390
|
+
* basically it will flatten the nestesd array (data prop) into single array
|
|
391
|
+
* of object. where each object contains x, y, rectText , value and legend propety of single
|
|
392
|
+
* data point.
|
|
393
|
+
*/ data.forEach((item)=>{
|
|
388
394
|
item.data.forEach((point)=>{
|
|
389
395
|
flattenData.push({
|
|
390
396
|
...point,
|
|
@@ -401,13 +407,13 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
401
407
|
uniqueXPoints[posX] = '1';
|
|
402
408
|
uniqueYPoints[posY] = '1';
|
|
403
409
|
/** we will check if the property(posY) is already there in object, if Yes,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
410
|
+
* then we will append the item in the Array related to the pos, if not
|
|
411
|
+
* then we will simply append the item in the new Array and
|
|
412
|
+
* assign that array to the property (posY) in the Object
|
|
413
|
+
* and finally we will get the array of Objects associated to each
|
|
414
|
+
* property (which is nothing but y data point) and object in the
|
|
415
|
+
* array are noting but x data points associated to the property y
|
|
416
|
+
*/ if (yPoints[posY]) {
|
|
411
417
|
yPoints[posY] = [
|
|
412
418
|
...yPoints[posY],
|
|
413
419
|
item
|
|
@@ -419,12 +425,21 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
419
425
|
}
|
|
420
426
|
});
|
|
421
427
|
/**
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
yPoints[item]
|
|
427
|
-
|
|
428
|
+
* we will now sort(ascending) the array's of y data point based on the x value
|
|
429
|
+
* sorting is important to achive the accessibility order of the
|
|
430
|
+
* rectangles and then format the x and y datapoints respectively
|
|
431
|
+
*/ Object.keys(yPoints).forEach((item)=>{
|
|
432
|
+
yPoints[item].sort((a, b)=>{
|
|
433
|
+
if (_xAxisType.current === XAxisTypes.StringAxis) {
|
|
434
|
+
return props.sortOrder === 'none' ? 0 : a.x.toLowerCase() > b.x.toLowerCase() ? 1 : -1;
|
|
435
|
+
} else if (_xAxisType.current === XAxisTypes.DateAxis) {
|
|
436
|
+
return a.x.getTime() - b.x.getTime();
|
|
437
|
+
} else if (_xAxisType.current === XAxisTypes.NumericAxis) {
|
|
438
|
+
return +a.x > +b.x ? 1 : -1;
|
|
439
|
+
} else {
|
|
440
|
+
return a.x > b.x ? 1 : -1;
|
|
441
|
+
}
|
|
442
|
+
}).forEach((datapoint)=>{
|
|
428
443
|
if (_xAxisType.current === XAxisTypes.DateAxis) {
|
|
429
444
|
datapoint.x = _getStringFormattedDate(datapoint.x, xAxisDateFormatString);
|
|
430
445
|
}
|
|
@@ -446,14 +461,14 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
446
461
|
});
|
|
447
462
|
});
|
|
448
463
|
/**
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
464
|
+
* if y-axis data points are of type date or number or if we have string formatter,
|
|
465
|
+
* then we need to change data points to their respective string
|
|
466
|
+
* format, becuase in the private variable this._stringYAxisDatapoints, points will be stored in
|
|
467
|
+
* string format. and in here `yPoint` are not so we need to change, so that
|
|
468
|
+
* function `this._createRectangles` should work perfetcly while looping, and if we don't change
|
|
469
|
+
* then `this._createRectangles` will fail while looping, causing the error
|
|
470
|
+
* Cannot read property 'forEach' of undefined
|
|
471
|
+
*/ Object.keys(yPoints).forEach((yPoint)=>{
|
|
457
472
|
if (_yAxisType.current === YAxisType.DateAxis) {
|
|
458
473
|
yPoints[_getStringFormattedDate(yPoint, yAxisDateFormatString)] = yPoints[yPoint];
|
|
459
474
|
} else if (_yAxisType.current === YAxisType.NumericAxis) {
|
|
@@ -463,16 +478,16 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
463
478
|
}
|
|
464
479
|
});
|
|
465
480
|
/**
|
|
466
|
-
|
|
467
|
-
|
|
481
|
+
* assigning new data set
|
|
482
|
+
*/ const dataSet = yPoints;
|
|
468
483
|
/**
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
484
|
+
* These are the Y axis data points which will get rendered in the
|
|
485
|
+
* Y axis in graph
|
|
486
|
+
*/ const yAxisPoints = _getYAxisDataPoints(uniqueYPoints);
|
|
472
487
|
/**
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
488
|
+
* These are the x axis data points which will get rendered in the
|
|
489
|
+
* x axis in the graph
|
|
490
|
+
*/ const xAxisPoints = _getXAxisDataPoints(uniqueXPoints);
|
|
476
491
|
return {
|
|
477
492
|
dataSet,
|
|
478
493
|
yAxisPoints,
|
|
@@ -494,16 +509,16 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
494
509
|
return d3Format(formatString || '.2~s')(+point);
|
|
495
510
|
};
|
|
496
511
|
/**
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
512
|
+
* This function checks if the given legend is highlighted or not.
|
|
513
|
+
* A legend can be highlighted in 2 ways:
|
|
514
|
+
* 1. selection: if the user clicks on it
|
|
515
|
+
* 2. hovering: if there is no selected legend and the user hovers over it
|
|
516
|
+
*/ const _legendHighlighted = (legendTitle)=>{
|
|
502
517
|
return selectedLegend === legendTitle || selectedLegend === '' && activeLegend === legendTitle;
|
|
503
518
|
};
|
|
504
519
|
/**
|
|
505
|
-
|
|
506
|
-
|
|
520
|
+
* This function checks if none of the legends is selected or hovered.
|
|
521
|
+
*/ const _noLegendHighlighted = ()=>{
|
|
507
522
|
return selectedLegend === '' && activeLegend === '';
|
|
508
523
|
};
|
|
509
524
|
const _getAriaLabel = (point)=>{
|
|
@@ -523,82 +538,6 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
|
|
|
523
538
|
const numDataPoints = props.data.reduce((acc, curr)=>acc + curr.data.length, 0);
|
|
524
539
|
return (chartTitle ? `${chartTitle}. ` : '') + `Heat map chart with ${numDataPoints} data points. `;
|
|
525
540
|
};
|
|
526
|
-
const _getOrderedXAxisLabels = (points)=>{
|
|
527
|
-
if (!_shouldOrderXAxisLabelsByCategoryOrder()) {
|
|
528
|
-
// Keep the original ordering logic as the default behavior to ensure backward compatibility
|
|
529
|
-
return Object.keys(points).sort((a, b)=>{
|
|
530
|
-
if (_xAxisType.current === XAxisTypes.DateAxis || _xAxisType.current === XAxisTypes.NumericAxis) {
|
|
531
|
-
return +a - +b;
|
|
532
|
-
} else {
|
|
533
|
-
return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
return sortAxisCategories(_mapCategoryToValues(), props.xAxisCategoryOrder);
|
|
538
|
-
};
|
|
539
|
-
const _getOrderedYAxisLabels = (points)=>{
|
|
540
|
-
if (!_shouldOrderYAxisLabelsByCategoryOrder()) {
|
|
541
|
-
// Keep the original ordering logic as the default behavior to ensure backward compatibility
|
|
542
|
-
return Object.keys(points).sort((a, b)=>{
|
|
543
|
-
if (_yAxisType.current === YAxisType.DateAxis || _yAxisType.current === YAxisType.NumericAxis) {
|
|
544
|
-
return +a - +b;
|
|
545
|
-
} else {
|
|
546
|
-
return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
return sortAxisCategories(_mapCategoryToValues(true), props.yAxisCategoryOrder);
|
|
551
|
-
};
|
|
552
|
-
const _getOrderedXPoints = (xPoints)=>{
|
|
553
|
-
if (!_shouldOrderXAxisLabelsByCategoryOrder()) {
|
|
554
|
-
return xPoints.sort((a, b)=>{
|
|
555
|
-
if (_xAxisType.current === XAxisTypes.StringAxis) {
|
|
556
|
-
return props.sortOrder === 'none' ? 0 : a.x.toLowerCase() > b.x.toLowerCase() ? 1 : -1;
|
|
557
|
-
} else if (_xAxisType.current === XAxisTypes.DateAxis) {
|
|
558
|
-
return a.x.getTime() - b.x.getTime();
|
|
559
|
-
} else if (_xAxisType.current === XAxisTypes.NumericAxis) {
|
|
560
|
-
return +a.x > +b.x ? 1 : -1;
|
|
561
|
-
} else {
|
|
562
|
-
return a.x > b.x ? 1 : -1;
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
const result = [];
|
|
567
|
-
const xValueToPoints = {};
|
|
568
|
-
xPoints.forEach((point)=>{
|
|
569
|
-
const xValue = point.x;
|
|
570
|
-
if (!xValueToPoints[xValue]) {
|
|
571
|
-
xValueToPoints[xValue] = [];
|
|
572
|
-
}
|
|
573
|
-
xValueToPoints[xValue].push(point);
|
|
574
|
-
});
|
|
575
|
-
const xAxisLabels = _getOrderedXAxisLabels({});
|
|
576
|
-
xAxisLabels.forEach((xValue)=>{
|
|
577
|
-
if (xValueToPoints[xValue]) {
|
|
578
|
-
result.push(...xValueToPoints[xValue]);
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
return result;
|
|
582
|
-
};
|
|
583
|
-
const _shouldOrderXAxisLabelsByCategoryOrder = ()=>{
|
|
584
|
-
return _xAxisType.current === XAxisTypes.StringAxis && props.xAxisCategoryOrder !== 'default';
|
|
585
|
-
};
|
|
586
|
-
const _shouldOrderYAxisLabelsByCategoryOrder = ()=>{
|
|
587
|
-
return _yAxisType.current === YAxisType.StringAxis && props.yAxisCategoryOrder !== 'default';
|
|
588
|
-
};
|
|
589
|
-
const _mapCategoryToValues = (isYAxis = false)=>{
|
|
590
|
-
const categoryToValues = {};
|
|
591
|
-
props.data.forEach((item)=>{
|
|
592
|
-
item.data.forEach((point)=>{
|
|
593
|
-
const category = isYAxis ? point.y : point.x;
|
|
594
|
-
if (!categoryToValues[category]) {
|
|
595
|
-
categoryToValues[category] = [];
|
|
596
|
-
}
|
|
597
|
-
categoryToValues[category].push(point.value);
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
return categoryToValues;
|
|
601
|
-
};
|
|
602
541
|
const updatePosition = (newX, newY)=>{
|
|
603
542
|
const threshold = 1; // Set a threshold for movement
|
|
604
543
|
const { x, y } = clickPosition;
|