MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / extractElementData

Function extractElementData

chapter24/docs/d3-graphviz.js:73–170  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

71 }
72
73 function extractElementData(element) {
74 var datum = {};
75 var tag = element.node().nodeName;
76 datum.tag = tag;
77 if (tag == '#text') {
78 datum.text = element.text();
79 } else if (tag == '#comment') {
80 datum.comment = element.text();
81 }
82 datum.attributes = {};
83 var attributes = element.node().attributes;
84 if (attributes) {
85 for (var i = 0; i < attributes.length; i++) {
86 var attribute = attributes[i];
87 var name = attribute.name;
88 var value = attribute.value;
89 datum.attributes[name] = value;
90 }
91 }
92 var transform = element.node().transform;
93 if (transform && transform.baseVal.numberOfItems != 0) {
94 var matrix = transform.baseVal.consolidate().matrix;
95 datum.translation = {
96 x: matrix.e,
97 y: matrix.f
98 };
99 datum.scale = matrix.a;
100 }
101 if (tag == 'ellipse') {
102 datum.center = {
103 x: datum.attributes.cx,
104 y: datum.attributes.cy
105 };
106 }
107 if (tag == 'polygon') {
108 var points = element.attr('points').split(' ');
109 var x = points.map(function (p) {
110 return p.split(',')[0];
111 });
112 var y = points.map(function (p) {
113 return p.split(',')[1];
114 });
115 var xmin = Math.min.apply(null, x);
116 var xmax = Math.max.apply(null, x);
117 var ymin = Math.min.apply(null, y);
118 var ymax = Math.max.apply(null, y);
119 var bbox = {
120 x: xmin,
121 y: ymin,
122 width: xmax - xmin,
123 height: ymax - ymin
124 };
125 datum.bbox = bbox;
126 datum.center = {
127 x: (xmin + xmax) / 2,
128 y: (ymin + ymax) / 2
129 };
130 }

Callers 2

extractAllElementsDataFunction · 0.70
attributeElementFunction · 0.70

Calls 2

nodeMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected