Skip to content

Commit

Permalink
Return back filter for network diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Jul 15, 2022
1 parent f3b4340 commit da3af5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
32 changes: 24 additions & 8 deletions src/network/main.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { FunctionalComponent } from "preact";
import { useContext, useEffect, useMemo, useState } from "preact/hooks";
import { scaleSqrt } from "d3-scale";
Expand All @@ -7,6 +8,8 @@ import { forceCollide, forceLink, forceManyBody, forceSimulation, forceX, forceY
import { ModuleUID } from "../../types/types";

import { COLOR_BASE } from "../color";
import { useFilter } from "../use-filter";
import { SideBar } from "../sidebar";
import { Chart } from "./chart";

import createRainbowColor from "./color";
Expand All @@ -28,6 +31,8 @@ export const Main: FunctionalComponent = () => {
const [excludedNodes, setExcludedNodes] = useState<ModuleUID[]>([]);
const [selectedNode, setSelectedNode] = useState<string>();

const { getModuleFilterMultiplier, setExcludeFilter, setIncludeFilter } = useFilter();

const getColor = (node: NodeInfo) => {
if (selectedNode != null) {
if (node.uid === selectedNode || data.nodeMetas[selectedNode].importedBy.some(({ uid }) => node.uid === uid)) {
Expand All @@ -45,6 +50,8 @@ export const Main: FunctionalComponent = () => {
for (const node of nodes) {
//if (node.renderedLength === 0) continue;
if (excludedNodes.includes(node.uid)) continue;
const filterMultiplier = getModuleFilterMultiplier(node);
if (filterMultiplier === 0) continue;

const nodeGroup = nodeGroups[node.uid];

Expand All @@ -61,7 +68,7 @@ export const Main: FunctionalComponent = () => {
});
}
return newNodes;
}, [excludedNodes, groupLayers, nodeGroups, nodes, sizeScale]);
}, [excludedNodes, getModuleFilterMultiplier, groupLayers, nodeGroups, nodes, sizeScale]);

const links = useMemo(() => {
const nodesCache: Record<ModuleUID, NetworkNode> = Object.fromEntries(processedNodes.map((d) => [d.uid, d]));
Expand Down Expand Up @@ -116,12 +123,21 @@ export const Main: FunctionalComponent = () => {
}, [nodeGroups, height, links, processedNodes, width]);

return (
<Chart
nodes={animatedNodes}
onNodeExclude={(node) => setExcludedNodes([...excludedNodes, node.uid])}
links={links}
getColor={getColor}
onNodeSelect={(uid) => setSelectedNode(uid === selectedNode ? undefined : uid)}
/>
<>
<SideBar
sizeProperty={"renderedLength"}
availableSizeProperties={["renderedLength"]}
setSizeProperty={() => {}}
onExcludeChange={setExcludeFilter}
onIncludeChange={setIncludeFilter}
/>
<Chart
nodes={animatedNodes}
onNodeExclude={(node) => setExcludedNodes([...excludedNodes, node.uid])}
links={links}
getColor={getColor}
onNodeSelect={(uid) => setSelectedNode(uid === selectedNode ? undefined : uid)}
/>
</>
);
};
16 changes: 14 additions & 2 deletions src/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,23 @@ export const SideBar: FunctionalComponent<SideBarProps> = ({
<div className="module-filters">
<div className="module-filter">
<label htmlFor="module-filter-exclude">Exclude</label>
<input type="text" id="module-filter-exclude" value={excludeValue} onInput={handleExcludeChange} />
<input
type="text"
id="module-filter-exclude"
value={excludeValue}
onInput={handleExcludeChange}
placeholder="RegExp"
/>
</div>
<div className="module-filter">
<label htmlFor="module-filter-include">Include</label>
<input type="text" id="module-filter-include" value={includeValue} onInput={handleIncludeChange} />
<input
type="text"
id="module-filter-include"
value={includeValue}
onInput={handleIncludeChange}
placeholder="RegExp"
/>
</div>
</div>
</aside>
Expand Down

0 comments on commit da3af5e

Please sign in to comment.