Added appearance panel in graph webview (#1555)

This commit is contained in:
meestahp
2025-12-04 05:47:11 -05:00
committed by GitHub
parent 0fa0176e1b
commit 5ef292382e
3 changed files with 37 additions and 7 deletions

View File

@@ -724,6 +724,7 @@
"default": false,
"description": "Whether to open the graph on startup."
}
}
},
"keybindings": [

View File

@@ -11,12 +11,14 @@ export default async function activate(
) {
let panel: vscode.WebviewPanel | undefined = undefined;
vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration('foam.graph.style')) {
const style = getGraphStyle();
panel.webview.postMessage({
type: 'didUpdateStyle',
payload: style,
});
if (panel) {
if (event.affectsConfiguration('foam.graph.style')) {
const style = getGraphStyle();
panel.webview.postMessage({
type: 'didUpdateStyle',
payload: style,
});
}
}
});

View File

@@ -1,9 +1,25 @@
const CONTAINER_ID = 'graph';
let nodeFontSizeController = null;
const initGUI = () => {
const gui = new dat.gui.GUI();
const nodeTypeFilterFolder = gui.addFolder('Filter by type');
const nodeTypeFilterControllers = new Map();
const appearanceFolder = gui.addFolder('Appearance');
appearanceFolder
.add(model, 'textFade', 0, 5)
.step(0.1)
.name('Text Fade')
.onFinishChange(v => {
const invertedValue = 5 - v;
getNodeLabelOpacity.domain([invertedValue, invertedValue + 0.8]);
});
nodeFontSizeController = appearanceFolder
.add(model, 'nodeFontSizeMultiplier', 0.5, 3)
.step(0.1)
.name('Node Font Size');
const forcesFolder = gui.addFolder('Forces');
forcesFolder
@@ -136,6 +152,8 @@ let model = {
note: true,
tag: true,
},
textFade: 1.2,
nodeFontSizeMultiplier: 1,
forces: {
collide: 2,
repel: 30,
@@ -301,7 +319,7 @@ function initDataviz(channel) {
}
const size = getNodeSize(info.neighbors.length);
const { fill, border } = getNodeColor(node.id, model);
const fontSize = model.style.fontSize / globalScale;
const fontSize = (model.style.fontSize * model.nodeFontSizeMultiplier) / globalScale;
const nodeState = getNodeState(node.id, model);
const textColor = fill.copy({
opacity:
@@ -668,6 +686,15 @@ try {
const style = message.payload;
Actions.updateStyle(style);
break;
case 'didUpdateNodeFontSizeMultiplier':
const multiplier = message.payload;
if (typeof multiplier === 'number') {
model.nodeFontSizeMultiplier = multiplier;
if (nodeFontSizeController) {
nodeFontSizeController.updateDisplay();
}
}
break;
}
});
} catch {