123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- var responseObjects = p5WFS_GetFeature();
- var object = responseObjects[0];
- var nodes = {};
- var nodesArray = [];
- var links = {};
- var linksArray = [];
- var instanceTypes = {};
- var dragged = false;
- const hasTargetArray = node => {
- for (const prop in node)
- if (node[prop].constructor === Array)
- return {array: node[prop], name: prop.split(':').pop().replace(/BI_audit_/, '')};
- return false;
- }
- const getLinks = (array, expansion) => {
- if (array != undefined && expansion !== undefined) {
- array.forEach(element => {
- const rowObject = hasTargetArray(element);
- if (rowObject) {
- for (let i = rowObject.array.length - 2; i >= 0; i--) {
- const target = hasTargetArray(rowObject.array[i]);
- const source = hasTargetArray(rowObject.array[i + 1]);
- let sourceGroup = source.name;
- let targetGroup = target.name;
- if (expansion && expansion.type) {
- if (sourceGroup === expansion.type)
- sourceGroup = source.array[0][expansion.criteria];
- if (targetGroup === expansion.type)
- targetGroup = target.array[0][expansion.criteria];
- }
- if (!links.hasOwnProperty(sourceGroup))
- links[sourceGroup] = {};
- if (links[sourceGroup].hasOwnProperty(targetGroup)) {
- links[sourceGroup][targetGroup]++;
- } else if (targetGroup) {
- links[sourceGroup][targetGroup] = 1;
- }
- }
- }
- })
- }
- };
- const getNodes = (array, expansion) => {
- if (array != undefined && expansion !== undefined) {
- array.forEach(element => {
- const rowObject = hasTargetArray(element);
- if (rowObject)
- rowObject.array.forEach(objectElement => {
- const trackNode = hasTargetArray(objectElement);
- if (trackNode) {
- let group = trackNode.name;
- let expanded = false;
- if (expansion && expansion.type && group === expansion.type) {
- group = trackNode.array[0][expansion.criteria];
- expanded = true;
- }
- nodes[group] = {expanded: expanded, type: trackNode.name};
- instanceTypes[trackNode.array[0].ID] = group;
- }
- });
- });
- }
- };
- const parseNodes = () => {
- for (const node in nodes) {
- if (nodes.hasOwnProperty(node))
- nodesArray.push({name: node, expanded: nodes[node].expanded, type: nodes[node].type});
- }
- };
- const parseLinks = () => {
- for (const link in links) {
- if (links.hasOwnProperty(link)) {
- for (const target in links[link]) {
- if (links[link].hasOwnProperty(target)) {
- linksArray.push({
- source: link,
- target: target,
- value: links[link][target]
- });
- }
- }
- }
- }
- };
- const parseGraph = (expansion) => {
- nodes = {};
- links = {};
- nodesArray = [];
- linksArray = [];
- getNodes(responseObjects[0]["default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row"], expansion);
- parseNodes();
- getLinks(responseObjects[0]["default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row"], expansion);
- parseLinks();
- dataModel = data = {
- nodes: nodesArray,
- links: linksArray
- };
- };
- const redraw = (expansion) => {
- if (dragged)
- return dragged = false;
- parseGraph(expansion);
- draw();
- };
- parseGraph();
|