Skip to content

Commit 663564b

Browse files
authored
Merge pull request #62 from grahamannett/graham/layoutToggle
Graham/layout toggle allows
2 parents 36ef922 + 9da7e7e commit 663564b

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/graph/graphFunctions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { GraphQueryResult } from '../db/db_types';
1515
export class GraphUtils {
1616
public db: StigDB;
1717
public cy: cytoscape.Core;
18-
public positionsSaved: boolean = false;
18+
public skipLayout: boolean = false;
1919

2020
constructor(cy: cytoscape.Core, db: StigDB) {
2121
this.cy = cy;
@@ -149,7 +149,7 @@ export class GraphUtils {
149149
*/
150150
private addMetadataToNodes(metadata: object, nodes: cytoscape.CollectionReturnValue) {
151151
if (metadata == null) return;
152-
this.positionsSaved = true;
152+
this.skipLayout = true;
153153

154154
nodes.map(node => {
155155
let obj = metadata.find(x => x.id === node.id());
@@ -338,7 +338,10 @@ export class GraphUtils {
338338
* @memberof GraphUtils
339339
*/
340340
public myLayout(layout_type: keyof LayoutsType): void {
341-
if (this.positionsSaved) return;
341+
if (this.skipLayout) {
342+
this.skipLayout = !this.skipLayout;
343+
return;
344+
}
342345
const layout = this.cy.layout(layouts[layout_type]);
343346
layout.run();
344347
// layout.promiseOn('layoutstop').then((event) => {

src/main.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ export class main {
328328
}
329329
} else {
330330
// edge
331-
// input_data.type
331+
// input_data.type
332332
let relationship_file = "";
333333

334334
// objects that shouldn't be related to other objects or only require the fundamental relationship types
335-
let common = ["artifact", "autonomous-system", "directory", "domain-name", "email-addr",
335+
let common = ["artifact", "autonomous-system", "directory", "domain-name", "email-addr",
336336
"email-message", "file", "grouping", "ipv4-addr", "ipv6-addr", "language-content",
337337
"location", "mac-addr", "mutex", "network-traffic", "note", "observed-data",
338-
"opinion", "process", "report", "software", "url", "user-account", "vulnerability",
338+
"opinion", "process", "report", "software", "url", "user-account", "vulnerability",
339339
"windows-registry-key", "x509-certificate"];
340340

341341
let target_obj_type = (input_data.source_ref).slice(0,-38);
@@ -346,7 +346,7 @@ export class main {
346346
} else {
347347
relationship_file = target_obj_type + "-relationship";
348348
}
349-
349+
350350
editor.buildWidget(ele, relationship_file , input_data);
351351
}
352352
$('button#btn-export-single').button('option', 'disabled', false);
@@ -399,7 +399,7 @@ export class main {
399399
if (ele.source().data('raw_data') === undefined || ele.target().data('raw_data') === undefined) {
400400
return;
401401
}
402-
402+
403403
const input_data = ele.data('raw_data');
404404
if (input_data === undefined) {
405405

@@ -487,7 +487,6 @@ export class main {
487487
// this.result
488488
// addToGraph(JSON.parse(e.target.result))
489489
addToGraph(JSON.parse(r.result as string));
490-
graph_utils.myLayout(StigSettings.Instance.layout.toLowerCase());
491490
};
492491
r.readAsText(f);
493492
}
@@ -556,8 +555,8 @@ export class main {
556555
let ourres = '';
557556
try {
558557
const formdata: StixObject = editor.editor.getValue();
559-
db.updateDB(formdata).then((r) => {
560-
result = r;
558+
db.updateDB(formdata).then((r) => {
559+
result = r;
561560
// ourres = result[0]['type'];
562561
});
563562
} catch (e) {
@@ -568,7 +567,7 @@ export class main {
568567
$('button.btn-commit').button('option', 'disabled', true);
569568
$('.message-status').html(`Committed 1 object to the database.`);
570569
});
571-
570+
572571
/***********************************************************************************
573572
*
574573
* Widget Bar Code
@@ -679,34 +678,34 @@ export class main {
679678
}
680679
],
681680
}));
682-
681+
683682
function makePopper(ele) {
684683
let ref = ele.popperRef(); // used only for positioning
685-
684+
686685
ele.tippy = tippy(ref, { // tippy options:
687686
content: () => {
688687
let content = document.createElement('div');
689-
688+
690689
content.innerHTML = ele.id();
691-
690+
692691
return content;
693692
},
694693
trigger: 'manual' // probably want manual mode
695694
});
696695
}
697-
696+
698697
cy.ready(function() {
699698
cy.elements().forEach(function(ele) {
700699
makePopper(ele);
701700
});
702701
});
703-
702+
704703
cy.elements().unbind('mouseover');
705704
cy.elements().bind('mouseover', (event) => event.target.tippy.show());
706-
705+
707706
cy.elements().unbind('mouseout');
708707
cy.elements().bind('mouseout', (event) => event.target.tippy.hide());
709-
708+
710709
});
711710
//*/
712711
}

0 commit comments

Comments
 (0)