Newer
Older
/**
import ManagedData from "./structures/manageddata";
import { PLUGIN_PATH, COLOR_PALETTE } from "../../config";
export const GRAPH_NODES = "nodes";
export const GRAPH_LINKS = "links";
export const IMAGE_SIZE = 12;
export const IMAGE_SRC = PLUGIN_PATH + "datasets/images/";
export const JSON_CONFIG = PLUGIN_PATH + "datasets/aud1v2.json";
export const STOP_PHYSICS_DELAY = 5000; // ms
export class PREVIOUSGraph extends ManagedData {
constructor(data) {
super(Graph.addIdentifiers(data));
this.calculateNodeTypes();
this.physicsStopTimeoutId = undefined;
}
restartSimulation() {
if (this.physicsStopTimeoutId !== undefined) {
clearTimeout(this.physicsStopTimeoutId);
}
this.data = Graph.addIdentifiers(this.getCleanData(this.data, false));
this.triggerOnChange();
// Deactivate physics after a short delay
this.physicsStopTimeoutId = setTimeout(() => {
this.stopPhysics();
this.storeCurrentData("Physics stopped", false);
this.physicsStopTimeoutId = undefined;
}, this.physicsDelay);
for (var i = 0; i < links.length; i++) {
var link = links[i];
if (
linkdeleteLink[LINK_SOURCE][NODE_ID] === sourceId &&
link[LINK_TARGET][NODE_ID] === targetId
) {
return true;
}
}
return false;
getCleanLink(link, simulationParameters) {
// Assuming that all nodes are valid, there are two possible formats
// 1. source and target are node objects
if (link[LINK_SOURCE][NODE_ID] !== undefined) {
// Source and target nodes
// Node ids will be converted to complete node objects on running graphs, gotta convert back
cleanLink[LINK_SOURCE] = link[LINK_SOURCE][NODE_ID];
cleanLink[LINK_TARGET] = link[LINK_TARGET][NODE_ID];
} else {
// 2. source and target are just node ids
cleanLink[LINK_SOURCE] = link[LINK_SOURCE];
cleanLink[LINK_TARGET] = link[LINK_TARGET];
}
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
existsNodeId(nodeId) {
var nodes = this.data[GRAPH_NODES];
for (var i = 0; i < nodes.length; i++) {
if (nodes[i][NODE_ID] === nodeId) {
return true;
}
}
return false;
}
getUnusedNodeId() {
var id;
do {
id = this.getRandomString();
} while (this.existsNodeId(id));
return id;
}
getRandomString(length = 8) {
// Move to global helpers
// Based on: https://stackoverflow.com/a/1349426/7376120
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
var result = "";
for (var i = 0; i < length; i++) {
result += characters.charAt(
Math.floor(Math.random() * charactersLength)
);
}
return result;
}
static toStr(item) {
if (item === undefined) {
return "UNDEFINED";
}
if (item.node) {
);
} else {
return "UNDEFINED";
}
}