From 75be158adb5993c433b4976eb0b2b6fdb8fad35c Mon Sep 17 00:00:00 2001 From: Dominik Haentsch Date: Mon, 26 Feb 2024 16:13:19 +0100 Subject: [PATCH] fix computation of filtered values in color tf factory --- .../dataset/colorTransferFunctionFactory.tsx | 10 ++++++-- src/stores/dataset/dataset.ts | 24 +++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/stores/dataset/colorTransferFunctionFactory.tsx b/src/stores/dataset/colorTransferFunctionFactory.tsx index a868bfa2..a82cebeb 100644 --- a/src/stores/dataset/colorTransferFunctionFactory.tsx +++ b/src/stores/dataset/colorTransferFunctionFactory.tsx @@ -18,16 +18,22 @@ export const makeColumnsColorTransferFunctions = ( const colors = useColors.getState(); return columns.reduce((a, column) => { + const values = data[column.key]; + const filteredValues = new Array(filteredIndices.length); + for (let i = 0; i < filteredIndices.length; ++i) { + filteredValues[i] = data[column.key][filteredIndices[i]]; + } + a[column.key] = { full: createColorTransferFunction( - data[column.key], + values, column.type, colors.robust, colors.continuousInts, colors.continuousCategories ), filtered: createColorTransferFunction( - filteredIndices.map((i) => data[column.key][i]), + filteredValues, column.type, colors.robust, colors.continuousInts, diff --git a/src/stores/dataset/dataset.ts b/src/stores/dataset/dataset.ts index ee536e23..d5ffa824 100644 --- a/src/stores/dataset/dataset.ts +++ b/src/stores/dataset/dataset.ts @@ -472,19 +472,19 @@ export const useDataset = create( set({ columnRelevance, isComputingRelevance: false }); }, - recomputeColorTransferFunctions: async () => { - const columnsToCompute = get() - .columns.filter((c) => isScalar(c.type) || isCategorical(c.type)) - .map((c) => c.key); - - const newTransferFunctions = makeColumnsColorTransferFunctions( - get().columns.filter(({ key }) => columnsToCompute.includes(key)), - get().columnData, - get().filteredIndices - ); + recomputeColorTransferFunctions: () => { + set(({ columns, columnData, filteredIndices }) => { + const columnsToCompute = columns + .filter((c) => isScalar(c.type) || isCategorical(c.type)) + .map((c) => c.key); - set({ - colorTransferFunctions: newTransferFunctions, + return { + colorTransferFunctions: makeColumnsColorTransferFunctions( + columns.filter(({ key }) => columnsToCompute.includes(key)), + columnData, + filteredIndices + ), + }; }); }, clearLoadingError: () => {