rusackas commented on code in PR #36302:
URL: https://github.com/apache/superset/pull/36302#discussion_r2578301842
##########
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts:
##########
@@ -38,13 +39,104 @@ import { HeatmapChartProps, HeatmapTransformedProps } from
'./types';
import { getDefaultTooltip } from '../utils/tooltip';
import { Refs } from '../types';
import { parseAxisBound } from '../utils/controls';
-import { NULL_STRING } from '../constants';
import { getPercentFormatter } from '../utils/formatters';
type EChartsOption = ComposeOption<HeatmapSeriesOption>;
const DEFAULT_ECHARTS_BOUNDS = [0, 200];
+/**
+ * Extract unique values for an axis from the data.
+ * Filters out null and undefined values.
+ *
+ * @param data - The dataset to extract values from
+ * @param columnName - The column to extract unique values from
+ * @returns Array of unique values from the specified column
+ */
+function extractUniqueValues(
+ data: Record<string, DataRecordValue>[],
+ columnName: string,
+): DataRecordValue[] {
+ const uniqueSet = new Set<DataRecordValue>();
+ data.forEach(row => {
+ const value = row[columnName];
+ if (value !== null && value !== undefined) {
+ uniqueSet.add(value);
+ }
+ });
+ return Array.from(uniqueSet);
+}
+
+/**
+ * Sort axis values based on the sort configuration.
+ * Supports alphabetical (with numeric awareness) and metric value-based
sorting.
+ *
+ * @param values - The unique values to sort
+ * @param data - The full dataset
+ * @param sortOption - Sort option string (e.g., 'alpha_asc', 'value_desc')
+ * @param metricLabel - Label of the metric for value-based sorting
+ * @param axisColumn - Column name for the axis being sorted
+ * @returns Sorted array of values
+ */
+function sortAxisValues(
+ values: DataRecordValue[],
+ data: Record<string, DataRecordValue>[],
+ sortOption: string | undefined,
+ metricLabel: string,
+ axisColumn: string,
+): DataRecordValue[] {
+ if (!sortOption) {
+ // No sorting specified, return values as they appear in the data
+ return values;
+ }
+
+ const isAscending = sortOption.includes('asc');
+ const isValueSort = sortOption.includes('value');
+
+ if (isValueSort) {
+ // Sort by metric value - aggregate metric values for each axis category
+ const valueMap = new Map<DataRecordValue, number>();
+ data.forEach(row => {
+ const axisValue = row[axisColumn];
+ const metricValue = row[metricLabel];
+ if (
+ axisValue !== null &&
+ axisValue !== undefined &&
+ typeof metricValue === 'number'
+ ) {
+ const current = valueMap.get(axisValue) || 0;
+ valueMap.set(axisValue, current + metricValue);
+ }
+ });
+
+ return values.sort((a, b) => {
+ const aValue = valueMap.get(a) || 0;
+ const bValue = valueMap.get(b) || 0;
+ return isAscending ? aValue - bValue : bValue - aValue;
+ });
+ }
+
+ // Alphabetical/lexicographic sort
+ return values.sort((a, b) => {
Review Comment:
```suggestion
return [...values].sort((a, b) => {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]