(xml)
| 28 | import * as zrUtil from 'zrender/src/core/util'; |
| 29 | |
| 30 | export function parse(xml) { |
| 31 | let doc; |
| 32 | if (typeof xml === 'string') { |
| 33 | const parser = new DOMParser(); |
| 34 | doc = parser.parseFromString(xml, 'text/xml'); |
| 35 | } |
| 36 | else { |
| 37 | doc = xml; |
| 38 | } |
| 39 | if (!doc || doc.getElementsByTagName('parsererror').length) { |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | const gexfRoot = getChildByTagName(doc, 'gexf'); |
| 44 | |
| 45 | if (!gexfRoot) { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | const graphRoot = getChildByTagName(gexfRoot, 'graph'); |
| 50 | |
| 51 | const attributes = parseAttributes(getChildByTagName(graphRoot, 'attributes')); |
| 52 | const attributesMap = {}; |
| 53 | for (let i = 0; i < attributes.length; i++) { |
| 54 | attributesMap[attributes[i].id] = attributes[i]; |
| 55 | } |
| 56 | |
| 57 | return { |
| 58 | nodes: parseNodes(getChildByTagName(graphRoot, 'nodes'), attributesMap), |
| 59 | links: parseEdges(getChildByTagName(graphRoot, 'edges')) |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | function parseAttributes(parent) { |
| 64 | return parent ? zrUtil.map(getChildrenByTagName(parent, 'attribute'), function (attribDom) { |
no test coverage detected
searching dependent graphs…