Skip to content

Commit

Permalink
url embed, fix gexf parser
Browse files Browse the repository at this point in the history
  • Loading branch information
l-pa committed Apr 21, 2020
1 parent afd2b84 commit 6f6feeb
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 146 deletions.
102 changes: 0 additions & 102 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"react": "^16.10.2",
"react-color": "^2.17.3",
"react-dom": "^16.10.2",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0",
"styled-components": "^4.4.1"
},
Expand Down
41 changes: 22 additions & 19 deletions public/libs/plugins/gexf-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(undefined) {
(function (undefined) {
/**
* GEXF Library
* =============
Expand Down Expand Up @@ -212,7 +212,7 @@
metas.lastmodifieddate = _xml.els.meta.getAttribute("lastmodifieddate");

// Other information
_helpers.nodeListEach(_xml.els.meta.childNodes, function(child) {
_helpers.nodeListEach(_xml.els.meta.childNodes, function (child) {
metas[child.tagName.toLowerCase()] = child.textContent;
});

Expand All @@ -225,7 +225,7 @@

// Iterating through attributes
if (_xml.els.model[cls])
_helpers.nodeListEach(_xml.els.model[cls], function(attr) {
_helpers.nodeListEach(_xml.els.model[cls], function (attr) {
// Properties
const properties = {
id: attr.getAttribute("id") || attr.getAttribute("for"),
Expand All @@ -252,7 +252,7 @@
const attvalues_els = node_or_edge.getElementsByTagName("attvalue");

// Getting Node Indicated Attributes
const ah = _helpers.nodeListToHash(attvalues_els, function(el) {
const ah = _helpers.nodeListToHash(attvalues_els, function (el) {
const attributes = _helpers.namedNodeMapToObject(el.attributes);
const key = attributes.id || attributes.for;

Expand All @@ -261,7 +261,7 @@
});

// Iterating through model
model.map(function(a) {
model.map(function (a) {
// Default value?
data[a.id] =
!(a.id in ah) && "defaultValue" in a
Expand All @@ -277,7 +277,7 @@
const nodes = [];

// Iteration through nodes
_helpers.nodeListEach(_xml.els.nodes, function(n) {
_helpers.nodeListEach(_xml.els.nodes, function (n) {
// Basic properties
const properties = {
id: n.getAttribute("id"),
Expand Down Expand Up @@ -305,7 +305,7 @@
const color_el = _helpers.getFirstElementByTagNS(node, "viz", "color");

if (color_el) {
const color = ["r", "g", "b", "a"].map(function(c) {
const color = ["r", "g", "b", "a"].map(function (c) {
return color_el.getAttribute(c);
});

Expand All @@ -315,17 +315,20 @@
// Position
const pos_el = _helpers.getFirstElementByTagNS(node, "viz", "position");

viz.position = {};
if (pos_el) {
viz.position = {};

["x", "y", "z"].map(function(p) {
["x", "y", "z"].map(function (p) {
viz.position[p] = +pos_el.getAttribute(p);
});
} else {
viz.position.x = Math.random();
viz.position.y = Math.random();
}

// Size
const size_el = _helpers.getFirstElementByTagNS(node, "viz", "size");
if (size_el) viz.size = +size_el.getAttribute("value");
else viz.size = 1;

// Shape
const shape_el = _helpers.getFirstElementByTagNS(node, "viz", "shape");
Expand All @@ -339,7 +342,7 @@
const edges = [];

// Iteration through edges
_helpers.nodeListEach(_xml.els.edges, function(e) {
_helpers.nodeListEach(_xml.els.edges, function (e) {
// Creating the edge
const properties = _helpers.namedNodeMapToObject(e.attributes);
if (!("type" in properties)) {
Expand All @@ -366,7 +369,7 @@
const color_el = _helpers.getFirstElementByTagNS(edge, "viz", "color");

if (color_el) {
const color = ["r", "g", "b", "a"].map(function(c) {
const color = ["r", "g", "b", "a"].map(function (c) {
return color_el.getAttribute(c);
});

Expand Down Expand Up @@ -418,7 +421,7 @@

// Fetching GEXF with XHR
function fetch(gexf_url, callback) {
const xhr = (function() {
const xhr = (function () {
if (window.XMLHttpRequest) return new XMLHttpRequest();

let names;
Expand All @@ -435,7 +438,7 @@
for (i in names)
try {
return new ActiveXObject(names[i]);
} catch (e) {}
} catch (e) { }
}

return null;
Expand All @@ -451,11 +454,11 @@
// We'll be parsing the response string then.
if (xhr.overrideMimeType) {
xhr.overrideMimeType("text/xml");
getResult = function(r) {
getResult = function (r) {
return r.responseXML;
};
} else {
getResult = function(r) {
getResult = function (r) {
const p = new DOMParser();
return p.parseFromString(r.responseText, "application/xml");
};
Expand All @@ -464,7 +467,7 @@
xhr.open("GET", gexf_url, async);

if (async)
xhr.onreadystatechange = function() {
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) callback(getResult(xhr));
};

Expand All @@ -481,7 +484,7 @@
// Fetch and parse the GEXF File
function fetchAndParse(gexf_url, callback, err) {
if (typeof callback === "function") {
return fetch(gexf_url, function(gexf) {
return fetch(gexf_url, function (gexf) {
callback(Graph(gexf, err));
});
}
Expand All @@ -494,7 +497,7 @@
*/
if (typeof this.gexf !== "undefined")
throw 'gexf: error - a variable called "gexf" already ' +
"exists in the global scope";
"exists in the global scope";

this.gexf = {
// Functions
Expand Down
Loading

0 comments on commit 6f6feeb

Please sign in to comment.