function rotateX(svgcontainer, heightChart, classedAs) {
function delay(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
function rotateOneNode(node, svgcontainer, heightChart) {
let origLegendHeight = node.node().getBBox().height;
let tickwidth;
if (node.selectAll("g.tick").size() > 1) {
tickwidth =
getTransformation(
d3.select(node.selectAll("g.tick")._groups[0][1]).attr("transform")
).translateX -
getTransformation(
d3.select(node.selectAll("g.tick")._groups[0][0]).attr("transform")
).translateX;
} else {
tickwidth =
getTransformation(
d3.select(node.selectAll("g.tick")._groups[0][0]).attr("transform")
).translateX * 2;
}
node.selectAll("g.tick text").call(addStaticText);
node.selectAll("g.tick text").call(wrap, tickwidth);
let maxwidth = 0;
let maxheight = 0;
node.selectAll("g.tick text").attr("transform", function (d) {
let coordx = this.getBBox().width;
if (maxwidth < coordx) {
maxwidth = coordx;
}
let coordy = this.getBBox().height;
if (maxheight < coordy) {
maxheight = coordy;
}
});
//2. Schritt
//Wenn immer noch zu breit dann rotieren
//console.log("Stufe 2");
if (maxwidth > tickwidth) {
node.selectAll("g.tick text").call(wrap, Math.min(150, maxwidth));
node.selectAll("g.tick text").style("text-anchor", "start");
node.selectAll("g.tick text").attr("transform", function (d) {
var moveleft = -this.getBBox().height / 2 - 8;
return "rotate(90), translate(10," + moveleft + ")";
});
}
}
delay(200).then(() => {
let xAxis;
//if no class is provided, the axis is selected using id = xAxis
if (typeof classedAs == "undefined") {
xAxis = svgcontainer.select("#xAxis");
let origLegendHeight = xAxis.node().getBBox().height;
rotateOneNode(xAxis, svgcontainer, heightChart);
//Höhe der Grafik den neuen Begebenheiten anpassen (height und viewBox)
let newlegendHeight = xAxis.node().getBBox().height;
let newHeightChart = heightChart + newlegendHeight - origLegendHeight;
//svgcontainer.attr("height", newHeightChart);
let viewBox = svgcontainer.attr("viewBox").split(",");
viewBox[3] = newHeightChart.toString();
svgcontainer.attr("viewBox", viewBox.join(","));
}
//if a class is provided, the class is used to select all xAxis'
else {
xAxis = svgcontainer.selectAll("." + classedAs);
let origLegendHeight = [];
let newLegendHeight = [];
xAxis.each(function (d, i) {
origLegendHeight.push(d3.select(this).node().getBBox().height);
rotateOneNode(d3.select(this), svgcontainer, heightChart);
newLegendHeight.push(d3.select(this).node().getBBox().height);
});
let newHeightChart =
heightChart + d3.max(newLegendHeight) - d3.max(origLegendHeight);
let viewBox = svgcontainer.attr("viewBox").split(",");
viewBox[3] = newHeightChart.toString();
svgcontainer.attr("viewBox", viewBox.join(","));
}
});
}