Skip to content

Commit

Permalink
fixed merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bobular committed Oct 18, 2023
2 parents 19d5087 + 5ed753e commit e27c56b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
10 changes: 10 additions & 0 deletions packages/libs/eda/src/lib/core/utils/trim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { dropRightWhile, dropWhile } from 'lodash';

/**
* Something that should be in lodash! Oh, it nearly is.
*
* Trim an array from the start and end, removing elements for which the filter function returns true
*/
export function trimArray<T>(array: Array<T>, filter: (val: T) => boolean) {
return dropRightWhile(dropWhile(array, filter), filter);
}
25 changes: 15 additions & 10 deletions packages/libs/eda/src/lib/map/analysis/EZTimeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { timeSliderVariableConstraints } from './config/eztimeslider';
import { useUITheme } from '@veupathdb/coreui/lib/components/theming';
import { SiteInformationProps, mapNavigationBackgroundColor } from '..';
import HelpIcon from '@veupathdb/wdk-client/lib/Components/Icon/HelpIcon';
import { trimArray } from '../../core/utils/trim';

interface Props {
studyId: string;
Expand All @@ -48,7 +49,7 @@ export default function EZTimeFilter({
updateConfig,
siteInformation,
}: Props) {
const findEntityAndVariable = useFindEntityAndVariable();
const findEntityAndVariable = useFindEntityAndVariable(filters); // filter sensitivity
const theme = useUITheme();
const [minimized, setMinimized] = useState(true);

Expand Down Expand Up @@ -105,15 +106,19 @@ export default function EZTimeFilter({
// converting data to visx format
const timeFilterData: EZTimeFilterDataProp[] = useMemo(
() =>
!getTimeSliderData.pending && getTimeSliderData.value != null
? zip(getTimeSliderData.value.x, getTimeSliderData.value.y)
.map(([xValue, yValue]) => ({ x: xValue, y: yValue }))
// and a type guard filter to avoid any `!` assertions.
.filter(
(val): val is EZTimeFilterDataProp =>
val.x != null && val.y != null
)
: [],
trimArray(
// remove leading and trailing zeroes (subset sensitivity)
!getTimeSliderData.pending && getTimeSliderData.value != null
? zip(getTimeSliderData.value.x, getTimeSliderData.value.y)
.map(([xValue, yValue]) => ({ x: xValue, y: yValue }))
// and a type guard filter to avoid any `!` assertions.
.filter(
(val): val is EZTimeFilterDataProp =>
val.x != null && val.y != null
)
: [],
({ y }) => y === 0
),
[getTimeSliderData]
);

Expand Down

0 comments on commit e27c56b

Please sign in to comment.