Skip to content

Commit

Permalink
minor code clarity changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dauglyon committed Oct 30, 2023
1 parent e47c4d4 commit 976fb85
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/features/collections/data_products/Biolog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Pagination } from '../../../common/components/Table';
import { useAppDispatch, useBackoffPolling } from '../../../common/hooks';
import { useAppParam } from '../../params/hooks';
import { useSelectionId } from '../collectionsSlice';
import { HeatMap } from './HeatMap';
import { HeatMap, MAX_HEATMAP_PAGE } from './HeatMap';

export const Biolog: FC<{
collection_id: string;
Expand Down Expand Up @@ -65,7 +65,7 @@ export const Biolog: FC<{
}
}}
/>
<Pagination table={table} maxPage={10000} />
<Pagination table={table} maxPage={MAX_HEATMAP_PAGE} />
</div>
</div>
);
Expand Down Expand Up @@ -174,11 +174,13 @@ const useBiolog = (collection_id: string | undefined) => {
const normVal = (v: number): number =>
!meta ? 0 : (v - meta.min_value) / (meta.max_value - meta.min_value);
if (type === 'float') {
const v = typeof value === 'number' ? value : parseFloat('' + value);
const v =
typeof value === 'number' ? value : parseFloat(value.toString());
return normVal(v);
}
if (type === 'int' || type === 'count') {
const v = typeof value === 'number' ? value : parseInt('' + value);
const v =
typeof value === 'number' ? value : parseInt(value.toString());
return normVal(v);
}
return value ? 1 : 0;
Expand Down
2 changes: 2 additions & 0 deletions src/features/collections/data_products/HeatMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { select } from 'd3-selection';
import { Loader } from '../../../common/components/Loader';
import { Tooltip, useHover } from '../../../common/components/Tooltip';

export const MAX_HEATMAP_PAGE = 10000;

/**
* Generic Collections HeatMap viz, accepts a table with cell values of 0-1
*/
Expand Down
10 changes: 6 additions & 4 deletions src/features/collections/data_products/Microtrait.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Pagination } from '../../../common/components/Table';
import { useAppDispatch, useBackoffPolling } from '../../../common/hooks';
import { useAppParam } from '../../params/hooks';
import { useSelectionId } from '../collectionsSlice';
import { HeatMap } from './HeatMap';
import { HeatMap, MAX_HEATMAP_PAGE } from './HeatMap';

export const Microtrait: FC<{
collection_id: string;
Expand Down Expand Up @@ -63,7 +63,7 @@ export const Microtrait: FC<{
}
}}
/>
<Pagination table={table} maxPage={10000} />
<Pagination table={table} maxPage={MAX_HEATMAP_PAGE} />
</div>
</div>
);
Expand Down Expand Up @@ -176,11 +176,13 @@ const useMicrotrait = (collection_id: string | undefined) => {
const normVal = (v: number): number =>
!meta ? 0 : (v - meta.min_value) / (meta.max_value - meta.min_value);
if (type === 'float') {
const v = typeof value === 'number' ? value : parseFloat('' + value);
const v =
typeof value === 'number' ? value : parseFloat(value.toString());
return normVal(v);
}
if (type === 'int' || type === 'count') {
const v = typeof value === 'number' ? value : parseInt('' + value);
const v =
typeof value === 'number' ? value : parseInt(value.toString());
return normVal(v);
}
return value ? 1 : 0;
Expand Down

0 comments on commit 976fb85

Please sign in to comment.