chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height * 2]);
const { nodes, links } = sankey(data);
const node = svg
.selectAll("g")
.attr("transform", d => `translate(${d})`)
.data(nodes)
.join("g");
node
.append("rect")
.attr("stroke", "#000")
.attr("x", d => d.x0)
.attr("y", d => d.y0)
.attr("height", d => d.y1 - d.y0)
.attr("width", d => 20)
.attr("fill", color)
.attr("id", function(d, i) {
d.id = i;
return "rect-" + i;
})
.append("title")
.text(function(d, i) {
return `Подсистема: ${nodes[i].appName}\nСХД: ${nodes[i].dbName}\nСущность: ${nodes[i].entityName}\nОписание: ${nodes[i].entityDesc}`;
});
node
.append("text")
.attr("font-family", "'Source Sans Pro', sans-serif")
.attr("font-size", 8)
.attr("x", d => (d.x0 < width / 2 ? d.x1 + 6 : d.x0 - 6))
.attr("y", d => (d.y1 + d.y0) / 2)
.attr("dy", "0.35em")
.attr("text-anchor", d => (d.x0 < width / 2 ? "start" : "end"))
.text(function(d, i) {
return `Подсистема: ${nodes[i].appName}`;
})
.attr("id", function(d, i) {
d.id = i;
return "text-" + i;
})
.append("svg:tspan")
.attr("x", d => (d.x0 < width / 2 ? d.x1 + 6 : d.x0 - 6))
.attr("y", d => (d.y1 + d.y0) / 2 + 12)
.attr("id", function(d, i) {
d.id = i;
return "text-shd-" + i;
})
.text(function(d, i) {
return nodes[i].dbName === "" ? "" : `СХД: ${nodes[i].dbName}`
})
.append("svg:tspan")
.attr("x", d => (d.x0 < width / 2 ? d.x1 + 6 : d.x0 - 6))
.attr("y", d => (d.y1 + d.y0) / 2 + 20)
.attr("id", function(d, i) {
d.id = i;
return "text-tbl-" + i;
})
.text(function(d, i) {
return nodes[i].entityName === "" ? "" : `Сущность: ${nodes[i].entityName}`
});
node.on("click", highlight_node_links)
//=========================================================
const link = svg
.append("g")
.attr("fill", "none")
.attr("stroke-opacity", 0.5)
.attr("transform", d => `translate(${d})`)
.selectAll("g")
.data(links)
.join("g")
.style("mix-blend-mode", "multiply");
if (edgeColor === "path") {
const gradient = link
.append("linearGradient")
.attr("id", d => (d.uid = DOM.uid("link")).id)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", d => d.source.x1)
.attr("x2", d => d.target.x0);
gradient
.append("stop")
.attr("offset", "0%")
.attr("stop-color", d => color(d.source));
gradient
.append("stop")
.attr("offset", "100%")
.attr("stop-color", d => color(d.target));
}
link
.append("path")
.attr("transform", d => `translate(${d})`)
.attr("d", d3.sankeyLinkHorizontal())
.attr("id", function(d, i) {
d.id = i;
return "link-" + i;
})
.attr("stroke", d =>
edgeColor === "none"
? "#aaa"
: edgeColor === "path"
? d.uid
: edgeColor === "input"
? color(d.source)
: color(d.target)
)
.attr("stroke-width", d => Math.max(1, d.width));
link
.append("title")
//.text(d => `${d.source.name} → ${d.target.name}`);
.text(function(d, i) {
if (links[i].srcTaskName === "null") {
return `${d.source.name} → ${d.target.name}`
}
return `Задача:${links[i].srcTaskName}\nОписание:${links[i].srcTaskDesc}\nВремя запуска:${links[i].srcStartedAt}\nВремя завершения:${links[i].srcEndedAt}`;
})
//=========================================================
svg.call(d3.zoom()
.extent([[0, 0], [width, height]])
.scaleExtent([1, 8])
.on("zoom", zoomed1));
function zoomed({transform}) {
node.attr("transform", d => `translate(${transform.apply(d)})`);
link.attr("transform", d => `translate(${transform.apply(d)})`);
}
function zoomed1({transform}) {
node.attr("transform", transform);
link.attr("transform", transform);
}
function highlightNodes(node, name) {
let opacity = 0.3;
if (node.name == name) {
opacity = 1;
}
node.sourceLinks.forEach(function(link) {
if (link.target.name == name) {
opacity = 1;
}
});
node.targetLinks.forEach(function(link) {
if (link.source.name == name) {
opacity = 1;
}
});
return opacity;
}
return svg.node();
}