Skip to content

Commit 7a24455

Browse files
authored
Merge pull request #614 from jpogran/cytoscape
(613) Puppet Node Graph Feature Rewrite
2 parents 1e12698 + d15782a commit 7a24455

File tree

12 files changed

+404
-247
lines changed

12 files changed

+404
-247
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- ([GH-614](https://github.com/lingua-pupuli/puppet-vscode/issues/614)) Puppet Node Graph Feature Rewrite
12+
913
## [0.24.0] - 2020-02-28
1014

1115
### Fixed

assets/css/main.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#cy {
2+
width: 100%;
3+
height: 100%;
4+
position: absolute;
5+
top: 0px;
6+
left: 0px;
7+
}
8+
9+
10+
body{
11+
overflow-x: hidden;
12+
height: 100%;
13+
}

assets/js/main.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
var cy;
2+
3+
function generate_cy_stylesheet(cy) {
4+
// This is a bit of a hack but it works
5+
html_style = document.getElementsByTagName('html')[0].style;
6+
7+
// From https://js.cytoscape.org/#core/style
8+
cy.style()
9+
.fromJson([
10+
{
11+
selector: 'node',
12+
style: {
13+
label: "data(id)",
14+
shape: "round-rectangle",
15+
"background-color": html_style.getPropertyValue('--vscode-button-background'),
16+
"background-width": "90%",
17+
"background-height": "90%",
18+
width: "228",
19+
height: "128",
20+
"border-width": "0",
21+
}
22+
},
23+
{
24+
selector: 'label',
25+
style: {
26+
color: html_style.getPropertyValue('--vscode-button-foreground'),
27+
'font-family': '"Segoe UI", Arial, Helvetica, sans-serif',
28+
'font-size': '28vh',
29+
'text-valign': 'center',
30+
'text-halign': 'center'
31+
}
32+
},
33+
{
34+
selector: ':selected',
35+
style: {
36+
'border-width': '4',
37+
'border-color': html_style.getPropertyValue('--vscode-editor-hoverHighlightBackground'),
38+
'background-color': html_style.getPropertyValue('--vscode-button-hoverBackground'),
39+
'line-color': html_style.getPropertyValue('--vscode-minimap-errorHighlight'),
40+
'target-arrow-color': html_style.getPropertyValue('--vscode-minimap-errorHighlight'),
41+
'source-arrow-color': html_style.getPropertyValue('--vscode-minimap-errorHighlight')
42+
}
43+
},
44+
{
45+
selector: 'edge',
46+
style: {
47+
'target-arrow-shape': 'triangle',
48+
'curve-style': 'bezier',
49+
'control-point-step-size': 40,
50+
width: 10
51+
}
52+
}
53+
])
54+
.update(); // indicate the end of your new stylesheet so that it can be updated on elements
55+
}
56+
57+
function init() {
58+
vscode = acquireVsCodeApi();
59+
60+
cy = cytoscape({
61+
container: document.getElementById('cy'),
62+
wheelSensitivity: 0.15,
63+
maxZoom: 5,
64+
minZoom: 0.2,
65+
selectionType: 'single'
66+
});
67+
68+
generate_cy_stylesheet(cy);
69+
70+
vscode.postMessage({ command: 'initialized' });
71+
}
72+
73+
window.addEventListener('message', event => {
74+
const message = event.data;
75+
if(message.redraw == true){
76+
cy.remove('*');
77+
}
78+
79+
nodeGraph = message.content;
80+
81+
try {
82+
nodeGraph.vertices.forEach(element => {
83+
cy.add({
84+
data: { id: element.label }
85+
});
86+
});
87+
88+
nodeGraph.edges.forEach(element => {
89+
cy.add({
90+
data: {
91+
id: element.source + element.target,
92+
source: element.source,
93+
target: element.target
94+
}
95+
});
96+
});
97+
} catch (error) {
98+
vscode.postMessage({
99+
command: 'error',
100+
errorMsg: `Error building node graph from json graph data: ${error}`
101+
});
102+
}
103+
104+
cy.layout({
105+
avoidOverlap: true,
106+
name: 'breadthfirst',
107+
circle: false,
108+
nodeDimensionsIncludeLabels: true,
109+
spacingFactor: 1.5,
110+
animate: true
111+
}).run();
112+
});

package-lock.json

Lines changed: 25 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343
],
4444
"engines": {
45-
"vscode": "^1.30.0"
45+
"vscode": "^1.38.0"
4646
},
4747
"categories": [
4848
"Linters",
@@ -68,7 +68,6 @@
6868
"onCommand:extension.puppetShowConnectionMenu",
6969
"onCommand:extension.puppetLint",
7070
"onCommand:extension.puppetParserValidate",
71-
"onCommand:extension.puppetShowNodeGraphToSide",
7271
"onCommand:extension.puppetResource",
7372
"onCommand:extension.pdkNewModule",
7473
"onCommand:extension.pdkNewClass",
@@ -186,7 +185,7 @@
186185
"title": "Puppet Resource"
187186
},
188187
{
189-
"command": "extension.puppetShowNodeGraphToSide",
188+
"command": "puppet.puppetShowNodeGraphToSide",
190189
"title": "Open Node Graph to the Side",
191190
"category": "Puppet",
192191
"icon": {
@@ -230,7 +229,7 @@
230229
"when": "editorLangId == 'puppet'"
231230
},
232231
{
233-
"command": "extension.puppetShowNodeGraphToSide",
232+
"command": "puppet.puppetShowNodeGraphToSide",
234233
"when": "editorLangId == 'puppet'"
235234
}
236235
],
@@ -262,7 +261,7 @@
262261
},
263262
{
264263
"when": "editorLangId == 'puppet'",
265-
"command": "extension.puppetShowNodeGraphToSide",
264+
"command": "puppet.puppetShowNodeGraphToSide",
266265
"group": "puppet"
267266
},
268267
{
@@ -294,7 +293,7 @@
294293
},
295294
{
296295
"when": "editorLangId == 'puppet'",
297-
"command": "extension.puppetShowNodeGraphToSide",
296+
"command": "puppet.puppetShowNodeGraphToSide",
298297
"group": "puppet"
299298
},
300299
{
@@ -535,13 +534,14 @@
535534
"@types/glob": "^7.1.1",
536535
"@types/mocha": "^5.2.7",
537536
"@types/node": "^12.0.8",
538-
"@types/vscode": "^1.30.0",
537+
"@types/vscode": "^1.38.0",
539538
"glob": "^7.1.4",
540539
"mocha": "^6.2.2",
541540
"tslint": "^5.17.0",
542541
"typescript": "^3.5.2",
543542
"vsce": "^1.63.0",
544-
"vscode-test": "^1.0.2"
543+
"vscode-test": "^1.0.2",
544+
"cytoscape": "3.14.0"
545545
},
546546
"dependencies": {
547547
"jsonc-parser": "~2.1.0",

psakefile.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ task VendorEditorSyntax {
8989
Invoke-RestMethod -Uri $uri -OutFile $syntaxFilePath -ErrorAction Stop
9090
}
9191

92+
task VendorCytoscape {
93+
$cyto = Join-Path $PSScriptRoot 'node_modules\cytoscape\dist'
94+
$vendorCytoPath = (Join-Path $PSScriptRoot 'vendor\cytoscape')
95+
Copy-Item -Path $cyto -Recurse -Destination $vendorCytoPath
96+
}
97+
9298
task CompileTypeScript {
9399
exec { tsc -p ./ }
94100
}
@@ -97,7 +103,7 @@ task Bump {
97103
exec { npm version --no-git-tag-version $packageVersion }
98104
}
99105

100-
task Vendor -depends VendorEditorServices, VendorEditorSyntax
106+
task Vendor -depends VendorEditorServices, VendorEditorSyntax, VendorCytoscape
101107

102108
task Build -depends Clean, Vendor, CompileTypeScript
103109

src/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class AggregateConfiguration implements IAggregateConfiguration {
143143
if (settings.editorService.tcp.address === '127.0.0.1' ||
144144
settings.editorService.tcp.address === 'localhost' ||
145145
settings.editorService.tcp.address === '') {
146-
return ConnectionType.Local;
146+
return ConnectionType.Remote;
147147
} else {
148148
return ConnectionType.Remote;
149149
}

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { IFeature } from './feature';
77
import { BoltFeature } from './feature/BoltFeature';
88
import { DebuggingFeature } from './feature/DebuggingFeature';
99
import { FormatDocumentFeature } from './feature/FormatDocumentFeature';
10-
import { NodeGraphFeature } from './feature/NodeGraphFeature';
1110
import { UpdateConfigurationFeature } from './feature/UpdateConfigurationFeature';
1211
import { PDKFeature } from './feature/PDKFeature';
1312
import { PuppetResourceFeature } from './feature/PuppetResourceFeature';
@@ -21,6 +20,7 @@ import { OutputChannelLogger } from './logging/outputchannel';
2120
import { legacySettings, SettingsFromWorkspace } from './settings';
2221
import { reporter } from './telemetry';
2322
import { PuppetModuleHoverFeature } from './feature/PuppetModuleHoverFeature';
23+
import { PuppetNodeGraphFeature } from './feature/PuppetNodeGraphFeature';
2424

2525
const axios = require('axios');
2626

@@ -72,6 +72,7 @@ export function activate(context: vscode.ExtensionContext) {
7272
return;
7373
}
7474

75+
7576
if (checkInstallDirectory(configSettings, logger) === false){
7677
// If this returns false, then we needed a local directory
7778
// but did not find it, so we should abort here
@@ -96,7 +97,7 @@ export function activate(context: vscode.ExtensionContext) {
9697
}
9798

9899
extensionFeatures.push(new FormatDocumentFeature(puppetLangID, connectionHandler, configSettings, logger, extContext));
99-
extensionFeatures.push(new NodeGraphFeature(puppetLangID, connectionHandler, logger, extContext));
100+
extensionFeatures.push(new PuppetNodeGraphFeature(puppetLangID, connectionHandler, logger, extContext));
100101
extensionFeatures.push(new PuppetResourceFeature(extContext, connectionHandler, logger));
101102
extensionFeatures.push(new DebuggingFeature(debugType, configSettings, extContext, logger));
102103

0 commit comments

Comments
 (0)