Skip to content

Commit

Permalink
allow more than 1 sequence column when a window column is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Slavetinsky committed Oct 20, 2023
1 parent da7bb39 commit 286c509
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/lenses/SequenceLens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ const SequenceView: Lens = ({ values, columns, syncKey }) => {
[isXSynchronized, xExtents, localXExtents]
);

const clampedWindow = useMemo(() => {
if (!window) return undefined;
const clampedWindows = useMemo(() => {
if (!window) return [];
const [start, end] = window;
return [
Math.max(start, displayedXExtents[0]),
Math.min(end, displayedXExtents[1]),
] as [number, number];
[
Math.max(start, displayedXExtents[0]),
Math.min(end, displayedXExtents[1]),
],
] as [number, number][];
}, [displayedXExtents, window]);

const resetPlot = useCallback(() => {
Expand All @@ -198,7 +200,7 @@ const SequenceView: Lens = ({ values, columns, syncKey }) => {
onChangeXExtents={setLocalAndGlobalXAxisExtents}
syncKey={syncKey}
yDomains={yDomains}
highlightedRegions={clampedWindow ? [clampedWindow] : []}
highlightedRegions={clampedWindows}
/>
</ViewerWrapper>
) : (
Expand Down Expand Up @@ -235,22 +237,10 @@ SequenceView.displayName = 'Lineplot';
SequenceView.minHeight = 45;
SequenceView.multi = true;
SequenceView.filterAllowedColumns = (allColumns, selectedColumns) => {
const sequenceColumnsCount = selectedColumns.filter(
(col) => col.type.kind === 'Sequence1D'
).length;
const windowColumnsCount = selectedColumns.filter(
(col) => col.type.kind === 'Window'
).length;

console.log({ sequenceColumnsCount, windowColumnsCount });

// only allow adding a window column if there is only one sequence column
// if a windowColumn is already selected only allow one sequence column to be added
if (sequenceColumnsCount > 1 || windowColumnsCount > 0)
// allow max 1 window column
if (selectedColumns.some((col) => col.type.kind === 'Window'))
return allColumns.filter((col) => col.type.kind === 'Sequence1D');

if (sequenceColumnsCount === 1 && windowColumnsCount === 1) return [];

return allColumns.filter((col) => ['Sequence1D', 'Window'].includes(col.type.kind));
};
SequenceView.isSatisfied = (columns) => {
Expand Down

0 comments on commit 286c509

Please sign in to comment.