-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-orgchart.js
More file actions
172 lines (149 loc) · 5.12 KB
/
make-orgchart.js
File metadata and controls
172 lines (149 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import {readFileSync,writeFileSync} from "fs";
import {JSDOM} from "jsdom";
import { execSync } from "child_process";
var sourceFile = "www/mwg/#dev/orgchart-source.svg",
destSVG = "www/mwg/orgchart.svg",
destSVGZ = "www/mwg/orgchart.svgz";
var remapping = {
"amf-holdings": {
"logo_path": "partners/holdings/amf-holdings-black.svgz"
},
"amfirst": {
"logo_path": "partners/amfirst/color.svgz",
"website": "https://www.amfirstinsco.com"
},
"new-providence-life": {
"logo_path": "partners/npl/color.svgz",
"website": "https://newprovidencelife.com"
},
"oic-holdings": {
"logo_path": "partners/holdings/oic-holdings-black.svgz"
},
"amfirst-ltd": {
"logo_path": "partners/amfirst-ltd/color.svgz"
},
"info-lockbox": {
"logo_path": "partners/lockbox/info-black.svgz",
"website": "https://insurancelockbox.com"
},
"amf-services": {
"logo_path": "partners/holdings/amf-services-black.svgz"
},
"amfirst-life": {
"logo_path": "partners/amfirst-life/center-color.svgz",
"website": "https://amfirstlife.com"
},
"monitor-life": {
"logo_path": "partners/monitor-life/color.svgz",
"website": "https://monitorlife.com"
},
"london-america": {
"logo_path": "partners/london-america/color.svgz"
},
"tpm-life": {
"logo_path": "partners/tpm/color.svgz",
"website": "https://tpmins.com"
},
"amfirst-specialty": {
"logo_path": "partners/amfirst-specialty/color.svgz"
},
"afic-administrators": {
"logo_path": "partners/holdings/afic-administrators-black.svgz"
},
"amfirst-capital": {
"logo_path": "partners/amfirst-capital/color.svgz"
},
"amfirst-holdings": {
"logo_path": "partners/amfirst-holdings/black.svgz"
},
"ps112-capital": {
"logo_path": "partners/ps112-capital/square-color.svg"
},
"custom-administrators": {
"logo_path": "partners/custom-administrators/color.svg",
}
}
var xml = readFileSync(sourceFile, 'utf8'),
dom = new JSDOM(xml, { contentType: "text/xml"}),
document = dom.window.document,
svg = document.querySelector("svg"),
defs = `
<defs>
<style>
.fill-black path {fill:#333;}
line,polyline {stroke:#333; fill:none;}
text, foreignObject {
font-family:'Roboto-Regular','Helvetica Neue', Arial, sans-serif;
font-size: 6.2818px;
text-align: center;
}
foreignObject p {margin:0;}
a:hover {cursor: pointer;}
</style>
</defs>`;
svg.setAttribute("version", "1.1");
svg.setAttribute("xml_space", "preserve");
svg.setAttribute("xmlns_xlink", "http://www.w3.org/1999/xlink");
document.querySelector("defs")?.remove();
svg.insertAdjacentHTML('afterbegin', defs);
document.querySelectorAll("rect").forEach(rect => {
if (!remapping[rect.id]) {
console.warn(`No properties found for ${rect.id}`);
process.exit(1);
}
var properties = remapping[rect.id],
image_url = `https://cdn.cremadesignstudio.com/mwg/${properties.logo_path}`;
rect.removeAttribute("class");
rect.removeAttribute("opacity");
rect.setAttribute("xlink_href", image_url);
});
document.querySelectorAll("line, polyline").forEach(line => {
line.removeAttribute("class");
line.removeAttribute("fill");
line.removeAttribute("stroke");
});
document.querySelectorAll("text").forEach(text => {
text.removeAttribute("class");
text.removeAttribute("font-family");
text.removeAttribute("font-size");
});
var xmlString = dom.window.document.querySelector("svg").outerHTML;
xmlString = xmlString.replaceAll("rect", "image");
xmlString = xmlString.replaceAll("xml_space", "xml:space");
xmlString = xmlString.replaceAll("xmlns_xlink", "xmlns:xlink");
xmlString = xmlString.replaceAll("xlink_href", "xlink:href");
xmlString = xmlString.replaceAll(" ", "\t");
console.log("Writing SVG to", destSVG);
writeFileSync(destSVG, xmlString);
try {
console.log("Writing SVGZ to", destSVGZ);
execSync(
`svgo --config svgo.config.cjs ${destSVG} -o - | gzip -cfq9 >| ${destSVGZ}`,
{ stdio: "inherit", shell: true }
);
} catch (err) {
console.error("Error running SVGO/gzip:", err);
process.exit(1);
}
// console.log(xmlString);
/*/
Possible other actions...
1. In Illustrator file, move text and lines to different layers?
2. Remove id and data-name from text
3. Move all lines and polylines together
4. Move all text together
5. Pretty print xml code
LINE BY LINE REPLACEMENTS
REPLACEMENT A
<line x1="278.33" y1="165.74" x2="278.33" y2="67.6" fill="none" stroke="#000" stroke-width=".83"/>
becomes
<line x1="278.33" y1="165.74" x2="278.33" y2="67.6" stroke-width=".83"/>
REPLACEMENT B
<polyline points="189.98 275.93 189.98 252.79 64.79 252.79 64.79 263.53" fill="none" stroke="#000" stroke-width=".83"/>
becomes
<polyline points="189.98 275.93 189.98 252.79 64.79 252.79 64.79 263.53" stroke-width=".83"/>
REPLACEMENT C
<text transform="translate(138.79 342.55)" font-family="SFProText-Regular, 'SFProText Regular'" font-size="7.44"><tspan x="0" y="0">Puerto Rico Domiciled Company</tspan><tspan x="24.77" y="8.92">Owned 100% by</tspan><tspan x="21.47" y="17.85">AMF Holdings, Inc.</tspan></text>
becomes
<text transform="translate(138.79 342.55)"><tspan x="0" y="0">Puerto Rico Domiciled Company</tspan><tspan x="24.77" y="8.92">Owned 100% by</tspan><tspan x="21.47" y="17.85">AMF Holdings, Inc.</tspan></text>
/*/