Skip to content

Commit

Permalink
fix: Heatmap sorting (apache#31752)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Jan 9, 2025
1 parent 5acd038 commit a477d84
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import {
QueryFormColumn,
QueryFormData,
QueryFormOrderBy,
buildQueryContext,
ensureIsArray,
Expand All @@ -26,26 +27,28 @@ import {
getXAxisColumn,
} from '@superset-ui/core';
import { rankOperator } from '@superset-ui/chart-controls';
import { HeatmapFormData } from './types';

export default function buildQuery(formData: HeatmapFormData) {
export default function buildQuery(formData: QueryFormData) {
const { groupby, normalize_across, sort_x_axis, sort_y_axis, x_axis } =
formData;
const metric = getMetricLabel(formData.metric);
const columns = [
...ensureIsArray(getXAxisColumn(formData)),
...ensureIsArray(groupby),
];
const orderby: QueryFormOrderBy[] = [
[
const orderby: QueryFormOrderBy[] = [];
if (sort_x_axis) {
orderby.push([
sort_x_axis.includes('value') ? metric : columns[0],
sort_x_axis.includes('asc'),
],
[
]);
}
if (sort_y_axis) {
orderby.push([
sort_y_axis.includes('value') ? metric : columns[1],
sort_y_axis.includes('asc'),
],
];
]);
}
const group_by =
normalize_across === 'x'
? getColumnLabel(x_axis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ const config: ControlPanelConfig = {
label: t('Sort X Axis'),
choices: sortAxisChoices,
renderTrigger: false,
clearable: false,
default: 'alpha_asc',
clearable: true,
},
},
],
Expand All @@ -63,8 +62,7 @@ const config: ControlPanelConfig = {
label: t('Sort Y Axis'),
choices: sortAxisChoices,
renderTrigger: false,
clearable: false,
default: 'alpha_asc',
clearable: true,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ export default function transformProps(
),
label: {
show: showValues,
formatter: (params: CallbackDataParams) =>
valueFormatter(params.value?.[2]),
formatter: (params: CallbackDataParams) => {
const paramsValue = params.value as (string | number)[];
return valueFormatter(paramsValue?.[2] as number | null | undefined);
},
},
},
];
Expand All @@ -178,9 +180,10 @@ export default function transformProps(
yAxisLabel,
metricLabel,
);
const x = params.value?.[0];
const y = params.value?.[1];
const value = params.value?.[2];
const paramsValue = params.value as (string | number)[];
const x = paramsValue?.[0];
const y = paramsValue?.[1];
const value = paramsValue?.[2] as number | null | undefined;
const formattedX = xAxisFormatter(x);
const formattedY = yAxisFormatter(y);
const formattedValue = valueFormatter(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export interface HeatmapFormData extends QueryFormData {
showLegend?: boolean;
showPercentage?: boolean;
showValues?: boolean;
sortXAxis: string;
sortYAxis: string;
sortXAxis?: string;
sortYAxis?: string;
timeFormat?: string;
xAxis: QueryFormColumn;
xscaleInterval: number;
Expand Down

0 comments on commit a477d84

Please sign in to comment.