I don't know why this happens, when I first load my chart the text can't be ellipsised. But after I went to another page and back again, it worked fine. Is there something wrong with my code.
tickVertical
.selectAll('text')
.each(function () {
// @ts-ignore
const self = select(this);
// @ts-ignore
let textLength = self.node().getComputedTextLength();
let text = self.text();
while (textLength > 50 && text.length > 0) {
text = text.slice(0, -1);
self.text(text + '...');
// @ts-ignore
textLength = self.node().getComputedTextLength();
}
})
.attr('fill', 'white')
.attr('font-size', '8px')
.each(function (d: any) {
select(this).append('title').text(d);
});
The bug from each method, after I console.log the text and textlength is 0.