Skip to content

Commit

Permalink
Merge pull request #259 from Renumics/feature/respect-order-attribute…
Browse files Browse the repository at this point in the history
…-in-spotlight-datasets

Feature/respect order attribute in spotlight datasets
  • Loading branch information
neindochoh authored Oct 9, 2023
2 parents d3b38aa + 0c53002 commit 9ac4ea2
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 84 deletions.
8 changes: 7 additions & 1 deletion renumics/spotlight_plugins/core/hdf5_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ def __del__(self) -> None:

@property
def column_names(self) -> List[str]:
return self._table.keys()
column_names = self._table.keys()
orders = {
name: self._table.get_column_attributes(name).get("order") or -1
for name in column_names
}
column_names.sort(key=lambda name: orders[name], reverse=True)
return column_names

@property
def intermediate_dtypes(self) -> DTypeMap:
Expand Down
2 changes: 1 addition & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export {
export { default as api } from './api';

export type { App } from './stores/pluginStore';
export { useDataset, convertValue, compareColumnOrder } from './stores/dataset';
export { useDataset, convertValue } from './stores/dataset';
export { useColors } from './stores/colors';
export { isAudio, isBoolean, getNullValue, isCategorical } from './datatypes';
export type {
Expand Down
6 changes: 1 addition & 5 deletions src/stores/dataset/colorTransferFunctionFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ export const makeColumnsColorTransferFunctions = (
filteredMask: boolean[]
): ColumnsTransferFunctions => {
return columns
.filter(
(column) =>
!column.isInternal &&
(isScalarColumn(column) || isCategoricalColumn(column))
)
.filter((column) => isScalarColumn(column) || isCategoricalColumn(column))
.reduce((a, column) => {
a[column.key] = {
full: makeApplicableColorTransferFunctions(
Expand Down
5 changes: 0 additions & 5 deletions src/stores/dataset/columnFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ export function makeColumn(column: Column, index: number): DataColumn {
optional: column.optional,
description: column.description ?? '',
tags: _.uniq(column.tags),

// we access some internal columns like __id__ by their name
// therefore, if we set the key to something different than column.name
// we have to check for isInternal and use column.name for it
isInternal: column.name.startsWith('__'),
};

return col;
Expand Down
18 changes: 2 additions & 16 deletions src/stores/dataset/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ export function convertValue(value: any, type: DataType) {
return value;
}

export function compareColumnOrder(a: DataColumn, b: DataColumn) {
if (a.isInternal && !b.isInternal) {
return 1;
} else if (b.isInternal && !a.isInternal) {
return -1;
}
return a.name.localeCompare(b.name);
}

const fetchTable = async (): Promise<{
uid: string;
generationID: number;
Expand Down Expand Up @@ -164,10 +155,8 @@ const fetchTable = async (): Promise<{

const length = _.max(table.columns.map((col) => col.values?.length ?? 0)) ?? 0;

const sortedColumns = columns.sort(compareColumnOrder);

const dataframe: DataFrame = {
columns: sortedColumns,
columns,
length,
data: columnData,
};
Expand Down Expand Up @@ -434,10 +423,7 @@ export const useDataset = create(
},
recomputeColorTransferFunctions: async () => {
const columnsToCompute = get()
.columns.filter(
(c) =>
!c.isInternal && (isScalar(c.type) || isCategorical(c.type))
)
.columns.filter((c) => isScalar(c.type) || isCategorical(c.type))
.map((c) => c.key);

const newTransferFunctions = makeColumnsColorTransferFunctions(
Expand Down
1 change: 0 additions & 1 deletion src/types/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface DataColumn {
type: datatypes.DataType;
editable: boolean;
optional: boolean;
isInternal: boolean;
description: string;
tags: string[];
}
Expand Down
6 changes: 2 additions & 4 deletions src/widgets/Histogram/Histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ const Histogram: Widget = () => {
const columnKeys = useMemo(
() =>
columns
.filter((col) => !col.isInternal && validTypes.includes(col.type.kind))
.filter((col) => validTypes.includes(col.type.kind))
.map((col) => col.key),
[columns]
);
const defaultColumnKey = useMemo(
() =>
columns
.filter(
(col) => !col.isInternal && defaultTypes.includes(col.type.kind)
)
.filter((col) => defaultTypes.includes(col.type.kind))
.map((col) => col.key)[0],
[columns]
);
Expand Down
24 changes: 6 additions & 18 deletions src/widgets/ScatterplotView/ScatterplotView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ const ScatterplotView: Widget = () => {

// compute z-scores for all number columns and order them descending
const remainingColumns = Object.values(allColumns).filter(
(col) =>
isNumberColumn(col) &&
!col.isInternal &&
!defaultColumns.includes(col.key)
(col) => isNumberColumn(col) && !defaultColumns.includes(col.key)
) as NumberColumn[];
const interestingColumns = sortColumnsByZScore(
rowIndex,
Expand Down Expand Up @@ -327,33 +324,24 @@ const ScatterplotView: Widget = () => {
const placeableColumns = useMemo(
() =>
Object.values(allColumns)
.filter(
(col) =>
['int', 'float', 'bool'].includes(col.type.kind) &&
!col.isInternal
)
.filter((col) => ['int', 'float', 'bool'].includes(col.type.kind))
.map((col) => col.key),
[allColumns]
);
const colorableColumns = useMemo(
() =>
Object.values(allColumns)
.filter(
(col) =>
['int', 'float', 'str', 'bool', 'Category'].includes(
col.type.kind
) && !col.isInternal
.filter((col) =>
['int', 'float', 'str', 'bool', 'Category'].includes(col.type.kind)
)
.map((col) => col.key),
[allColumns]
);
const scaleableColumns = useMemo(
() =>
Object.values(allColumns)
.filter(
(col: DataColumn) =>
['int', 'float', 'bool'].includes(col.type.kind) &&
!col.isInternal
.filter((col: DataColumn) =>
['int', 'float', 'bool'].includes(col.type.kind)
)
.map((col) => col.key),
[allColumns]
Expand Down
32 changes: 9 additions & 23 deletions src/widgets/SimilarityMap/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ const columnTypeSelector = (d: Dataset): { [key: string]: DataType } =>
return a;
}, {});

const columnIsInternalSelector = (d: Dataset): { [key: string]: boolean } =>
d.columns.reduce((a: { [key: string]: boolean }, c: DataColumn) => {
a[c.key] = c.isInternal;
return a;
}, {});

const SettingsMenu = ({
colorBy,
sizeBy,
Expand All @@ -77,7 +71,6 @@ const SettingsMenu = ({
onChangePCANormalization,
}: Props) => {
const columnType = useDataset(columnTypeSelector, shallow);
const columnIsInternal = useDataset(columnIsInternalSelector, shallow);

const changePlaceBy = useCallback(
(keys: string[]): void => {
Expand All @@ -88,27 +81,20 @@ const SettingsMenu = ({

const colorableColumns = useMemo(
() =>
Object.entries(columnType)
.filter(
([key, type]) =>
['int', 'float', 'str', 'bool', 'Category'].includes(
type.kind
) && !columnIsInternal[key]
Object.values(columnType)
.filter((type) =>
['int', 'float', 'str', 'bool', 'Category'].includes(type.kind)
)
.map(([key]) => key),
[columnIsInternal, columnType]
.map((type) => type.kind),
[columnType]
);

const scaleableColumns = useMemo(
() =>
Object.entries(columnType)
.filter(
([key, type]) =>
['int', 'float', 'bool'].includes(type.kind) &&
!columnIsInternal[key]
)
.map(([key]) => key),
[columnIsInternal, columnType]
Object.values(columnType)
.filter((type) => ['int', 'float', 'bool'].includes(type.kind))
.map((type) => type.kind),
[columnType]
);

const reductionParameterMenu =
Expand Down
15 changes: 5 additions & 10 deletions src/widgets/SimilarityMap/SimilarityMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const SimilarityMap: Widget = () => {
return undefined;
}
const availableColumns = fullColumns
.filter((col) => !col.isInternal)
.filter((col) =>
['int', 'float', 'str', 'bool', 'Category'].includes(col.type.kind)
)
Expand Down Expand Up @@ -165,11 +164,10 @@ const SimilarityMap: Widget = () => {

const embeddableColumnKeys = useMemo(() => {
return fullColumns
.filter(
(col) =>
['int', 'bool', 'float', 'Category', 'Embedding'].includes(
col.type.kind
) && !col.isInternal
.filter((col) =>
['int', 'bool', 'float', 'Category', 'Embedding'].includes(
col.type.kind
)
)
.map((c) => c.key);
}, [fullColumns]);
Expand Down Expand Up @@ -355,10 +353,7 @@ const SimilarityMap: Widget = () => {
// compute z-scores for all number columns and order them descending
//
const remainingColumns = fullColumns.filter(
(col) =>
isNumberColumn(col) &&
!col.isInternal &&
!defaultColumns.includes(col)
(col) => isNumberColumn(col) && !defaultColumns.includes(col)
) as NumberColumn[];
const interestingColumns = sortColumnsByZScore(
rowIndex,
Expand Down

0 comments on commit 9ac4ea2

Please sign in to comment.