Skip to content

Commit

Permalink
Merge pull request #62 from grahamannett/graham/layoutToggle
Browse files Browse the repository at this point in the history
Graham/layout toggle allows
  • Loading branch information
z-priest authored Aug 3, 2021
2 parents 36ef922 + 9da7e7e commit 663564b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/graph/graphFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { GraphQueryResult } from '../db/db_types';
export class GraphUtils {
public db: StigDB;
public cy: cytoscape.Core;
public positionsSaved: boolean = false;
public skipLayout: boolean = false;

constructor(cy: cytoscape.Core, db: StigDB) {
this.cy = cy;
Expand Down Expand Up @@ -149,7 +149,7 @@ export class GraphUtils {
*/
private addMetadataToNodes(metadata: object, nodes: cytoscape.CollectionReturnValue) {
if (metadata == null) return;
this.positionsSaved = true;
this.skipLayout = true;

nodes.map(node => {
let obj = metadata.find(x => x.id === node.id());
Expand Down Expand Up @@ -338,7 +338,10 @@ export class GraphUtils {
* @memberof GraphUtils
*/
public myLayout(layout_type: keyof LayoutsType): void {
if (this.positionsSaved) return;
if (this.skipLayout) {
this.skipLayout = !this.skipLayout;
return;
}
const layout = this.cy.layout(layouts[layout_type]);
layout.run();
// layout.promiseOn('layoutstop').then((event) => {
Expand Down
33 changes: 16 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,14 @@ export class main {
}
} else {
// edge
// input_data.type
// input_data.type
let relationship_file = "";

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

let target_obj_type = (input_data.source_ref).slice(0,-38);
Expand All @@ -346,7 +346,7 @@ export class main {
} else {
relationship_file = target_obj_type + "-relationship";
}

editor.buildWidget(ele, relationship_file , input_data);
}
$('button#btn-export-single').button('option', 'disabled', false);
Expand Down Expand Up @@ -399,7 +399,7 @@ export class main {
if (ele.source().data('raw_data') === undefined || ele.target().data('raw_data') === undefined) {
return;
}

const input_data = ele.data('raw_data');
if (input_data === undefined) {

Expand Down Expand Up @@ -487,7 +487,6 @@ export class main {
// this.result
// addToGraph(JSON.parse(e.target.result))
addToGraph(JSON.parse(r.result as string));
graph_utils.myLayout(StigSettings.Instance.layout.toLowerCase());
};
r.readAsText(f);
}
Expand Down Expand Up @@ -556,8 +555,8 @@ export class main {
let ourres = '';
try {
const formdata: StixObject = editor.editor.getValue();
db.updateDB(formdata).then((r) => {
result = r;
db.updateDB(formdata).then((r) => {
result = r;
// ourres = result[0]['type'];
});
} catch (e) {
Expand All @@ -568,7 +567,7 @@ export class main {
$('button.btn-commit').button('option', 'disabled', true);
$('.message-status').html(`Committed 1 object to the database.`);
});

/***********************************************************************************
*
* Widget Bar Code
Expand Down Expand Up @@ -679,34 +678,34 @@ export class main {
}
],
}));
function makePopper(ele) {
let ref = ele.popperRef(); // used only for positioning
ele.tippy = tippy(ref, { // tippy options:
content: () => {
let content = document.createElement('div');
content.innerHTML = ele.id();
return content;
},
trigger: 'manual' // probably want manual mode
});
}
cy.ready(function() {
cy.elements().forEach(function(ele) {
makePopper(ele);
});
});
cy.elements().unbind('mouseover');
cy.elements().bind('mouseover', (event) => event.target.tippy.show());
cy.elements().unbind('mouseout');
cy.elements().bind('mouseout', (event) => event.target.tippy.hide());
});
//*/
}
Expand Down

0 comments on commit 663564b

Please sign in to comment.