Skip to content

Commit

Permalink
remove isInternal from frontend code
Browse files Browse the repository at this point in the history
  • Loading branch information
neindochoh committed Oct 9, 2023
1 parent 758854d commit b799e25
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 67 deletions.
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
5 changes: 1 addition & 4 deletions src/stores/dataset/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,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
2 changes: 1 addition & 1 deletion src/widgets/Histogram/Histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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]
);
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 b799e25

Please sign in to comment.