Utilisateur:Vincent.schmid/Common.js
De Mythemes
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
- Opera : appuyez sur Ctrl + F5.
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.cytoscapeGraphml = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
module.exports = function (cy, $, options) {
function xmlToString(xmlData) {
var xmlString;
//IE
if (window.ActiveXObject) {
xmlString = xmlData.xml;
}
// code for Mozilla, Firefox, Opera, etc.
else {
xmlString = (new XMLSerializer()).serializeToString(xmlData);
}
return xmlString;
}
function getEleData(ele) {
var type = ele.isNode() ? "node" : "edge";
var attrs = ["css", "data", "position"];
var result = {};
for (var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
var opt = options[type][attr];
if (!opt)
result[attr] = {};
else if ($.isArray(opt)) {
result[attr] = {};
for (var j = 0; j < opt.length; j++) {
var el = opt[i];
if (ele[attr](el))
result[attr][el] = ele[attr](el);
}
} else {
var eleAttr = ele[attr]();
result[attr] = {};
for (var key in eleAttr)
if ($.inArray(key, options[type].discludeds) < 0 && key != "parent")
result[attr][key] = {value: eleAttr[key], attrType: attr};
}
}
return $.extend(result.css, result.data, result.position);
}
function parseNode(ele, xml) {
var node = $('<node />', xml).attr({id: ele.id()}).appendTo(xml);
var eleData = getEleData(ele);
for (var key in eleData)
$('<data />', node).attr({type: eleData[key].attrType, key: key}).text(eleData[key].value).appendTo(node);
if (ele.isParent()) {
var subgraph = $('<graph />', node).attr({id: ele.id() + ':'}).appendTo(node);
ele.children().each(function (child) {
parseNode(child, subgraph);
});
}
return node;
}
options.node.discludeds.push("id");
options.edge.discludeds.push("id", "source", "target");
var xmlDoc = $.parseXML(
'<?xml version="1.0" encoding="UTF-8"?>\n' +
'<graphml xmlns="http://graphml.graphdrawing.org/xmlns"\n' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n' +
'xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns\n' +
'http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">\n' +
' <graph>\n' +
' </graph>\n' +
' </graphml>\n'
);
var $xml = $(xmlDoc);
var $graph = $xml.find("graph");
cy.nodes().orphans().forEach(function (ele) {
parseNode(ele, $graph);
});
cy.edges().forEach(function (ele) {
var edge = $('<edge />', $graph).attr({id: ele.id(), source: ele.source().id(), target: ele.target().id()}).appendTo($graph);
var eleData = getEleData(ele);
for (var key in eleData)
$('<data />', edge).attr({key: key}).text(eleData[key].value).appendTo(edge);
});
return xmlToString(xmlDoc);
};
},{}],2:[function(_dereq_,module,exports){
module.exports = function (cy, $, options, cyGraphML) {
function renderNode($graph, $parent) {
$graph.children("node").each(function () {
var $node = $(this);
var settings = {
data: {id: $node.attr("id")},
css: {},
position: {}
};
if($parent !== null)
settings["data"]["parent"] = $parent.attr("id");
$node.children('data').each(function () {
var $data = $(this);
settings["data"][$data.attr("key")] = $data.text();
});
cy.add({
group: "nodes",
data: settings.data,
css: settings.css,
position: settings.position
});
$node.children("graph").each(function () {
var $graph = $(this);
renderNode($graph, $node);
});
});
}
cy.batch(function () {
xml = $.parseXML(cyGraphML);
$xml = $(xml);
$graphs = $xml.find("graph").first();
$graphs.each(function () {
var $graph = $(this);
renderNode($graph, null);
$graph.find("edge").each(function () {
var $edge = $(this);
var settings = {
data: {id: $edge.attr("id"), source: $edge.attr("source"), target: $edge.attr("target")},
css: {},
position: {}
};
$edge.find('data').each(function () {
var $data = $(this);
settings["data"][$data.attr("key")] = $data.text();
});
cy.add({
group: "edges",
data: settings.data,
css: settings.css
});
});
});
var layoutOptT = typeof options.layoutBy;
if (layoutOptT == "string")
cy.layout({name: options.layoutBy}).run();
else if (layoutOptT == "function")
options.layoutBy();
});
};
},{}],3:[function(_dereq_,module,exports){
;
(function () {
'use strict';
// registers the extension on a cytoscape lib ref
var register = function (cytoscape, $) {
if (!cytoscape || !$) {
return;
} // can't register if cytoscape unspecified
var exporter = _dereq_("./exporter");
var importer = _dereq_("./importer");
var options = {
node: {
css: false,
data: true,
position: true,
discludeds: []
},
edge: {
css: false,
data: true,
discludeds: []
},
layoutBy: "cose" // string of layout name or layout function
};
cytoscape('core', 'graphml', function (cyGraphML) {
var cy = this;
var res;
switch (typeof cyGraphML) {
case "string": // import
res = importer(cy, $, options, cyGraphML);
break;
case "object": // set options
$.extend(true, options, cyGraphML);
res = cy;
break;
case "undefined": // export
res = exporter(cy, $, options);
break;
default:
console.log("Functionality(argument) of .graphml() is not recognized.");
}
return res;
});
};
if (typeof module !== 'undefined' && module.exports) { // expose as a commonjs module
module.exports = register;
}
if (typeof define !== 'undefined' && define.amd) { // expose as an amd/requirejs module
define('cytoscape-graphml', function () {
return register;
});
}
if (typeof cytoscape !== 'undefined' && typeof $ !== 'undefined') { // expose to global cytoscape (i.e. window.cytoscape)
register(cytoscape, $);
}
})();
},{"./exporter":1,"./importer":2}]},{},[3])(3)
});