MCPcopy
hub / github.com/clientIO/joint / normalizeDataPath

Function normalizeDataPath

packages/joint-core/test/utils.js:62–89  ·  view source on GitHub ↗
(d)

Source from the content-addressed store, hash-verified

60 };
61
62 function normalizeDataPath(d) {
63 var isPartial = d.substr(0, 1) !== 'M';
64 var prepended = '';
65 var appended = '';
66 if (isPartial) {
67 // Need to make some temporary fixes so the browser doesn't throw an invalid path error.
68 if (d.substr(0, 1) === 'A') {
69 // Ensure that there are 7 values present after an 'A'.
70 var matches = d.substr(d.indexOf('A')).match(/[, a-z][0-9]/ig);
71 var numValues = matches && matches.length || 0;
72 if (numValues < 7) {
73 for (var i = 0; i < 7 - numValues; i++) {
74 appended += ' 0';
75 d += ' 0';
76 }
77 }
78 }
79 prepended += 'M 0 0 ';
80 d = 'M 0 0 ' + d;
81 }
82 var normalizedD = V('path').attr('d', d).attr('d');
83 if (isPartial) {
84 // Strip away anything that was prepended or appended.
85 normalizedD = normalizedD.substr(prepended.length);
86 normalizedD = normalizedD.substr(0, normalizedD.length - appended.length);
87 }
88 return normalizedD;
89 }
90
91 function normalizeSvgAttr(name, value) {
92 return V('g').attr(name, value).attr(name);

Callers 1

utils.jsFile · 0.85

Calls 1

VFunction · 0.85

Tested by

no test coverage detected