2020-03-08 09:49:41 +01:00
|
|
|
const createLabel = (vertexText, style) => {
|
|
|
|
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
|
|
svgLabel.setAttribute('style', style.replace('color:', 'fill:'));
|
2020-04-02 19:35:12 +02:00
|
|
|
let rows = [];
|
|
|
|
if (vertexText) {
|
2020-04-25 14:12:04 +02:00
|
|
|
rows = vertexText.split(/\\n|\n|<br\s*\/?>/gi);
|
2020-04-02 19:35:12 +02:00
|
|
|
}
|
2020-03-08 09:49:41 +01:00
|
|
|
|
|
|
|
for (let j = 0; j < rows.length; j++) {
|
|
|
|
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
|
|
|
|
tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
|
|
|
|
tspan.setAttribute('dy', '1em');
|
2020-03-11 20:25:55 +01:00
|
|
|
tspan.setAttribute('x', '0');
|
2020-03-29 14:20:49 +02:00
|
|
|
tspan.textContent = rows[j].trim();
|
2020-03-08 09:49:41 +01:00
|
|
|
svgLabel.appendChild(tspan);
|
|
|
|
}
|
|
|
|
return svgLabel;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default createLabel;
|