Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom graph styling support #438

Merged
merged 18 commits into from
Jan 13, 2021
Merged

Add custom graph styling support #438

merged 18 commits into from
Jan 13, 2021

Conversation

jmg-duarte
Copy link
Member

@jmg-duarte jmg-duarte commented Jan 11, 2021

This PR addresses #436

The implementation makes use of the webview communication mechanism to
switch messages between the webview and the graph.
It works as follows:

  • When the webview is loaded, it now sends a single request to VSCode,
    the request asks VSCode for the graph style
  • When VSCode answers with the style, the graph style is updated and
    the webview loading process continues as normal.

The style change does not modify the API, in fact it makes use of the
shadiest programming tatic ever, global variables to remain
compatible.

The style object currently supports four base fields:

  • background: string
  • fontSize: int
  • highlightedForeground: string
  • node: object
    • note: string
    • nonExistingNote: string
    • unknown: string

For an ugly example, see below:
image

José Duarte added 4 commits January 11, 2021 16:09
The implementation makes use of the webview communication mechanism to
switch messages between the webview and the graph.
It works as follows:

- When the webview is loaded, it now sends a single request to VSCode,
the request asks VSCode for the graph style
- When VSCode answers with the style, the graph style is updated and
the webview loading process continues as normal.

The style change does not modify the API, in fact it makes use of the
shadiest programming tatic ever, *global variables* to remain
compatible.

The style object *currently* supports four base fields:
- background: string
- fontSize: int
- highlightedForeground: string
- node: object
  - note: string
  - nonExistingNote: string
  - unknown: string
packages/foam-vscode/package.json Outdated Show resolved Hide resolved
packages/foam-vscode/src/features/dataviz.ts Outdated Show resolved Hide resolved
packages/foam-vscode/static/graphs/default/graph.js Outdated Show resolved Hide resolved
packages/foam-vscode/src/features/dataviz.ts Outdated Show resolved Hide resolved
packages/foam-vscode/static/graphs/default/graph.js Outdated Show resolved Hide resolved
@@ -300,6 +336,15 @@ try {
Actions.selectNode(noteId);
}
break;
case "graphStyle":
const style = message.payload;
updateStyle(style);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm... I think here you need a slightly different approach, to be in line with the other actions (and I think it will also simplify the code).

Because style is now part of the model (that is, it can be changed by the app), I would:

  • add it to the model itself (and the style code in initDataviz needs to reference the model, not the style global)
  • make updateStyle an action, and in its implementation make the changes to the style in the model

If the design doesn't make sense to you let's chat.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By model, do you mean this?

let model = {
selectedNodes: new Set(),
hoverNode: null,
focusNodes: new Set(),
focusLinks: new Set(),
nodeInfo: {},
data: {
nodes: [],
links: []
}
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.
actions are used to update the model.
the model is rendered by the view (which was initialized once in initGraph, the force-graph library doesn't have a clear separation between model and view, but it's still good enough for us)

Copy link
Member Author

@jmg-duarte jmg-duarte Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New commits fix this, please review

@jmg-duarte
Copy link
Member Author

That CI fail is weird...

Copy link
Collaborator

@riccardoferretti riccardoferretti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. I added a couple of suggestions, and you can now remove the webviewStyleRequest message.

Once those changes are in place feel free to merge!

packages/foam-vscode/src/features/dataviz.ts Outdated Show resolved Hide resolved
@@ -23,6 +33,7 @@ const feature: FoamFeature = {
noteAddedListener.dispose();
noteUpdatedListener.dispose();
noteDeletedListener.dispose();
panel = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
panel = undefined;
panel.dispose();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are totally right, I misunderstood what was happening here

packages/foam-vscode/src/features/dataviz.ts Outdated Show resolved Hide resolved
@jmg-duarte jmg-duarte merged commit 792e66b into foambubble:master Jan 13, 2021
@jmg-duarte jmg-duarte deleted the feature/custom-graph-styling branch January 13, 2021 17:56
@riccardoferretti riccardoferretti added this to the 0.8.0 milestone Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants