Skip to content

Commit 21f322b

Browse files
committed
Updates the network style (clear the cache of all memoize functions) after adding/removing nodes -- #12
1 parent 8964ac7 commit 21f322b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/client/components/network-editor/bottom-drawer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { NetworkEditorController } from './controller';
99
import DataTable, { DEF_SORT_FN, PRECISION, roundNumber } from './data-table';
1010
import DataDetailsPanel from './data-details-panel';
1111
import SearchBar from './search-bar';
12+
import { updateNetworkStyle } from './network-style';
1213
import { motifName, motifTrackLinkOut, resultId } from '../util';
1314
import { useUIStateStore } from './store';
1415

@@ -307,9 +308,11 @@ export function BottomDrawer({ controller, open, leftDrawerOpen, isMobile, isTab
307308
// Update the network
308309
if (checked) {
309310
controller.addToNetwork([{ ...row, transcriptionFactors: [tfs[0]] }]);
311+
updateNetworkStyle();
310312
await controller.applyLayout();
311313
} else {
312314
controller.removeFromNetwork([row]);
315+
updateNetworkStyle();
313316
}
314317
};
315318
const onRowClick = (row) => {
@@ -338,9 +341,11 @@ export function BottomDrawer({ controller, open, leftDrawerOpen, isMobile, isTab
338341
row = { ...row, transcriptionFactors: [tf] };
339342
if (checked) {
340343
controller.addToNetwork([row]);
344+
updateNetworkStyle();
341345
await controller.applyLayout();
342346
} else {
343347
controller.removeFromNetwork([row]);
348+
updateNetworkStyle();
344349
}
345350
};
346351

src/client/components/network-editor/network-style.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ function getMinMaxValues(cy, attr) {
6262
};
6363
}
6464

65+
// So we can update all memoize functions when necessary
66+
let memoizeFunctions = [];
6567

6668
export const nodeLabel = _.memoize(node => {
6769
const label = node.data('label');
@@ -71,13 +73,17 @@ export const nodeLabel = _.memoize(node => {
7173
return name;
7274
}, node => node.id());
7375

74-
export const clusterColor = (clusterNumber) => {
76+
export function clusterColor(clusterNumber) {
7577
const colorNumber = clusterNumber % CLUSTER_COLORS.length;
7678
const color = chroma(CLUSTER_COLORS[colorNumber]);
7779
return color.hex();
78-
};
80+
}
81+
82+
export function updateNetworkStyle() {
83+
memoizeFunctions?.forEach(f => f.cache.clear());
84+
}
7985

80-
export const createNetworkStyle = (cy) => {
86+
export function createNetworkStyle(cy) {
8187
const { min:minNES, max:maxNES } = getMinMaxValues(cy, 'NES');
8288
const magNES = Math.max(Math.abs(maxNES), Math.abs(minNES));
8389

@@ -108,6 +114,9 @@ export const createNetworkStyle = (cy) => {
108114
return clusterColor(cluster);
109115
}, e => e.id());
110116

117+
// Clear the memoize array
118+
memoizeFunctions = [nodeLabel, getNodeColor, getNodeShape, getNodeSize, getNodeFontSize, getEdgeColor];
119+
111120
return {
112121
maxNES,
113122
minNES,
@@ -210,6 +219,6 @@ export const createNetworkStyle = (cy) => {
210219
},
211220
]
212221
};
213-
};
222+
}
214223

215224
export default createNetworkStyle;

0 commit comments

Comments
 (0)