added text wrapping

This commit is contained in:
Lorenz Padberg 2022-06-15 16:45:06 +02:00
parent 14b2ce0176
commit 7ddcd13b10
1 changed files with 62 additions and 43 deletions

View File

@ -111,7 +111,7 @@ export default {
}, },
{ {
id: 10, id: 10,
title: 'Analyse', title: 'Analyse des letzten Falles',
slug: 'analyse', slug: 'analyse',
type: 'learnpath.Circle', type: 'learnpath.Circle',
translation_key: '2ca5ba7a-98b8-4511-ba50-bc190714886d', translation_key: '2ca5ba7a-98b8-4511-ba50-bc190714886d',
@ -168,18 +168,8 @@ export default {
let pieGenerator = d3.pie() let pieGenerator = d3.pie()
let pieData = pieGenerator(pieWeights) let pieData = pieGenerator(pieWeights)
_.forEach(pieData, function (pie) { _.forEach(pieData, function (pie) {
let index = parseInt(pie.index) pie.done = circle.learning_sequences.length == 0 ? false : circle.learning_sequences[parseInt(pie.index)].done
console.log(circle)
if (circle.learning_sequences.length == 0) {
pie.done = false
}
else {
pie.done = circle.learning_sequences[parseInt(pie.index)].done
}
}) })
circle.pieData = pieData circle.pieData = pieData
}) })
return internalCircles return internalCircles
@ -192,8 +182,6 @@ export default {
}, },
mounted() { mounted() {
console.log(this.circles)
const circleWidth = 200 const circleWidth = 200
const radius = (circleWidth * 0.7) / 2 const radius = (circleWidth * 0.7) / 2
const blue900 = '#00224D', const blue900 = '#00224D',
@ -205,7 +193,6 @@ export default {
sky500 = '#41B5FA' sky500 = '#41B5FA'
// Create append pie charts to the main svg // Create append pie charts to the main svg
const circle_groups = this.svg const circle_groups = this.svg
.selectAll('.circle') .selectAll('.circle')
@ -218,11 +205,16 @@ export default {
return 'translate(' + x_coord + ', 200)' return 'translate(' + x_coord + ', 200)'
}) })
.on('mouseover', function (d, i) { .on('mouseover', function (d, i) {
d3.select(this).selectAll('.learningSegmentArc').transition().duration('200').attr('fill', d => {return d.done ? sky400 : gray100}) d3.select(this).selectAll('.learningSegmentArc').transition().duration('200').attr('fill', d => {
return d.done ? sky400 : gray100
})
}) })
.on('mouseout', function (d, i) { .on('mouseout', function (d, i) {
d3.select(this).selectAll('.learningSegmentArc').transition().duration('200').attr('fill', d => {return d.done ? sky500 : gray300}) d3.select(this).selectAll('.learningSegmentArc').transition().duration('200').attr('fill', d => {
return d.done ? sky500 : gray300
}) })
})
.attr('role', 'button')
const arcGenerator = d3 const arcGenerator = d3
.arc() .arc()
@ -248,8 +240,9 @@ export default {
.attr('fill', gray300) .attr('fill', gray300)
arcs.transition().duration('1000').attr('fill', d => {return d.done ? sky500 : gray300}) arcs.transition().duration('1000').attr('fill', d => {
return d.done ? sky500 : gray300
})
//Draw arc paths //Draw arc paths
@ -263,6 +256,7 @@ export default {
.attr('y', radius + 30) .attr('y', radius + 30)
.attr('class', 'circlesText text-xl font-bold') .attr('class', 'circlesText text-xl font-bold')
.style('text-anchor', 'middle') .style('text-anchor', 'middle')
.call(wrap, 200-20);
const topicTitles = this.svg const topicTitles = this.svg
.selectAll('.topicTitles') .selectAll('.topicTitles')
@ -295,6 +289,33 @@ export default {
.attr('stroke-width', 1.76) .attr('stroke-width', 1.76)
topicLines.transition().duration('1000').attr('y2', 350) topicLines.transition().duration('1000').attr('y2', 350)
function wrap(text, width) {
text.each(function () {
let text = d3.select(this),
words = text.text().split(/\s+/).reverse(),
word,
line = [],
lineNumber = 0,
lineHeight = 1.1, // ems
y = text.attr('y'),
dy = 0,//parseFloat(text.attr('dy')),
tspan = text.text(null).append('tspan').attr('x', 0).attr('y', y).attr('dy', dy + 'em');
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(' '));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(' '));
line = [word];
tspan = text.append('tspan').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
}
}
});
}
}, },
} }
</script> </script>
@ -308,7 +329,6 @@ export default {
vertical-align: top; vertical-align: top;
overflow: hidden; overflow: hidden;
background: white; background: white;
} }
.svg-content { .svg-content {
@ -317,7 +337,6 @@ export default {
top: 0; top: 0;
left: 0; left: 0;
background: white; background: white;
} }
</style> </style>