-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: globally switch between continuous and discrete coloring of ints
- Loading branch information
1 parent
3bb12ed
commit ded266b
Showing
11 changed files
with
104 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,40 @@ | ||
import { | ||
DataType, | ||
isCategorical, | ||
isFloat, | ||
isNumerical, | ||
isScalar, | ||
} from '../../datatypes'; | ||
import { | ||
createCategoricalTransferFunction, | ||
createConstantTransferFunction, | ||
createContinuousTransferFunction, | ||
createColorTransferFunction, | ||
TransferFunction, | ||
} from '../../hooks/useColorTransferFunction'; | ||
import _ from 'lodash'; | ||
Check warning on line 5 in src/stores/dataset/colorTransferFunctionFactory.tsx GitHub Actions / 🔍 Check
|
||
import { useColors } from '../../stores/colors'; | ||
import { | ||
ColumnData, | ||
DataColumn, | ||
DataStatistics, | ||
isCategoricalColumn, | ||
isScalarColumn, | ||
TableData, | ||
} from '../../types'; | ||
import { Dataset } from './dataset'; | ||
|
||
export const makeApplicableColorTransferFunctions = ( | ||
type: DataType, | ||
data: ColumnData, | ||
stats?: DataStatistics | ||
): TransferFunction[] => { | ||
const transferFunctions: TransferFunction[] = []; | ||
|
||
if ((isCategorical(type) || isScalar(type)) && !isFloat(type)) { | ||
const uniqueValues = _.uniq(data); | ||
const transFn = createCategoricalTransferFunction(uniqueValues, type); | ||
transferFunctions.push(transFn); | ||
} | ||
|
||
if (isNumerical(type)) { | ||
const useRobustColoring = useColors.getState().useRobustColorScales; | ||
|
||
const min = useRobustColoring ? stats?.p5 : stats?.min; | ||
const max = useRobustColoring ? stats?.p95 : stats?.max; | ||
|
||
transferFunctions.push( | ||
createContinuousTransferFunction(min || 0, max || 1, type) | ||
); | ||
} | ||
|
||
transferFunctions.push(createConstantTransferFunction(type)); | ||
|
||
return transferFunctions; | ||
}; | ||
import { DataColumn, TableData } from '../../types'; | ||
import { useColors } from '../colors'; | ||
|
||
type ColumnsTransferFunctions = Record< | ||
string, | ||
{ full: TransferFunction[]; filtered: TransferFunction[] } | ||
{ full: TransferFunction; filtered: TransferFunction } | ||
>; | ||
|
||
export const makeColumnsColorTransferFunctions = ( | ||
columns: DataColumn[], | ||
data: TableData, | ||
stats: Dataset['columnStats'], | ||
filteredMask: boolean[] | ||
): ColumnsTransferFunctions => { | ||
return columns | ||
.filter((column) => isScalarColumn(column) || isCategoricalColumn(column)) | ||
.reduce((a, column) => { | ||
a[column.key] = { | ||
full: makeApplicableColorTransferFunctions( | ||
column.type, | ||
data[column.key], | ||
stats.full[column.key] | ||
), | ||
filtered: makeApplicableColorTransferFunctions( | ||
column.type, | ||
data[column.key].filter((_, i) => filteredMask[i]), | ||
stats.filtered[column.key] | ||
), | ||
}; | ||
return a; | ||
}, {} as ColumnsTransferFunctions); | ||
const colors = useColors.getState(); | ||
|
||
return columns.reduce((a, column) => { | ||
a[column.key] = { | ||
full: createColorTransferFunction( | ||
data[column.key], | ||
column.type, | ||
colors.robust, | ||
colors.continuousInts, | ||
colors.continuousCategories | ||
), | ||
filtered: createColorTransferFunction( | ||
data[column.key].filter((_, i) => filteredMask[i]), | ||
column.type, | ||
colors.robust, | ||
colors.continuousInts, | ||
colors.continuousCategories | ||
), | ||
}; | ||
return a; | ||
}, {} as ColumnsTransferFunctions); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters