This is an automated email from the ASF dual-hosted git repository. michaelsmolina pushed a commit to branch 4.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 85efe2525cbf88fd2d4ad00b2e1314ccdabc36a0 Author: Michael S. Molina <[email protected]> AuthorDate: Fri Mar 1 13:08:30 2024 -0500 fix: Heatmap numeric sorting (#27360) (cherry picked from commit fe2f5a7be9fb6218aa72ab9173481fd21fa40b20) --- .../plugins/legacy-plugin-chart-heatmap/src/Heatmap.js | 15 ++++++--------- .../legacy-plugin-chart-heatmap/src/transformProps.js | 8 ++++++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/Heatmap.js b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/Heatmap.js index 18493f0602..ef2c76ad68 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/Heatmap.js +++ b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/Heatmap.js @@ -177,15 +177,12 @@ function Heatmap(element, props) { } } - function ordScale(k, rangeBands, sortMethod) { + function ordScale(k, rangeBands, sortMethod, formatter) { let domain = {}; - const actualKeys = {}; // hack to preserve type of keys when number records.forEach(d => { domain[d[k]] = (domain[d[k]] || 0) + d.v; - actualKeys[d[k]] = d[k]; }); - // Not using object.keys() as it converts to strings - const keys = Object.keys(actualKeys).map(s => actualKeys[s]); + const keys = Object.keys(domain).map(k => formatter(k)); if (sortMethod === 'alpha_asc') { domain = keys.sort(cmp); } else if (sortMethod === 'alpha_desc') { @@ -252,10 +249,10 @@ function Heatmap(element, props) { const fp = getNumberFormatter(NumberFormats.PERCENT_2_POINT); - const xScale = ordScale('x', null, sortXAxis); - const yScale = ordScale('y', null, sortYAxis); - const xRbScale = ordScale('x', [0, hmWidth], sortXAxis); - const yRbScale = ordScale('y', [hmHeight, 0], sortYAxis); + const xScale = ordScale('x', null, sortXAxis, xAxisFormatter); + const yScale = ordScale('y', null, sortYAxis, yAxisFormatter); + const xRbScale = ordScale('x', [0, hmWidth], sortXAxis, xAxisFormatter); + const yRbScale = ordScale('y', [hmHeight, 0], sortYAxis, yAxisFormatter); const X = 0; const Y = 1; const heatmapDim = [xRbScale.domain().length, yRbScale.domain().length]; diff --git a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/transformProps.js b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/transformProps.js index 0ec12b6c4d..8b925f2974 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/transformProps.js +++ b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/transformProps.js @@ -57,11 +57,15 @@ export default function transformProps(chartProps) { const xAxisFormatter = coltypes[0] === GenericDataType.Temporal ? getTimeFormatter(timeFormat) - : String; + : coltypes[0] === GenericDataType.Numeric + ? Number + : String; const yAxisFormatter = coltypes[1] === GenericDataType.Temporal ? getTimeFormatter(timeFormat) - : String; + : coltypes[1] === GenericDataType.Numeric + ? Number + : String; return { width, height,
