Skip to content

Commit

Permalink
fix(node-dist-vis): Fix edge filtering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
axdanbol committed Oct 23, 2024
1 parent 7efe04f commit 431f0d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libs/node-dist-vis/src/lib/deckgl/edges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export function createEdgesLayer(
return createColorAccessor(cellTypeAccessor(), map);
});
const filterValueAccessor = computed(() => {
const nodeIndex = edges().getCellIDFor;
const filterFn = nodeFilter().includes;
return createNodeFilterAccessor(cellTypeAccessor(), filterFn);
return createNodeFilterAccessor(cellTypeAccessor(), nodeIndex, filterFn);
});

return computed(() => {
Expand Down
8 changes: 6 additions & 2 deletions libs/node-dist-vis/src/lib/deckgl/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, Signal } from '@angular/core';
import { COORDINATE_SYSTEM } from '@deck.gl/core/typed';
import { AccessorContext, COORDINATE_SYSTEM } from '@deck.gl/core/typed';
import { DataFilterExtension, DataFilterExtensionProps } from '@deck.gl/extensions/typed';
import { PointCloudLayer } from '@deck.gl/layers/typed';
import { ColorMapView } from '../models/color-map';
Expand All @@ -20,6 +20,10 @@ function getNodeSize(mode: ViewMode): number {
return mode === 'inspect' ? INSPECT_NODE_SIZE : DEFAULT_NODE_SIZE;
}

function getIndex(_obj: unknown, info: AccessorContext<unknown>): number {
return info.index;
}

export function createNodesLayer(
mode: Signal<ViewMode>,
nodes: Signal<NodesView>,
Expand All @@ -39,7 +43,7 @@ export function createNodesLayer(
const filterValueAccessor = computed(() => {
const accessor = nodes().getCellTypeFor;
const filterFn = nodeFilter().includes;
return createNodeFilterAccessor(accessor, filterFn);
return createNodeFilterAccessor(accessor, getIndex, filterFn);
});

return computed(() => {
Expand Down
4 changes: 3 additions & 1 deletion libs/node-dist-vis/src/lib/deckgl/utils/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export const FILTER_RANGE: [number, number] = [0, 2];

export function createNodeFilterAccessor<T>(
accessor: AccessorFunction<T, string>,
indexAccessor: AccessorFunction<T, number>,
filterFn: NodeFilterPredFn,
): AccessorFunction<T, number> {
return (obj, info) => {
const type = accessor(obj, info);
const result = filterFn(type, info.index);
const index = indexAccessor(obj, info);
const result = filterFn(type, index);
return result ? FILTER_INCLUDE_VALUE : FILTER_EXCLUDE_VALUE;
};
}

0 comments on commit 431f0d7

Please sign in to comment.