我已经找到了一些例子,但很难找到任何工作,如果有人有更清楚或一些见解将非常感激.
var wrap = function() {
var self = d3.select(this),
textLength = self.node().getComputedTextLength(),
text = self.text();
while (textLength > (50) && text.length > 0) {
text = text.slice(0, -1);
self.text(text + '...');
textLength = self.node().getComputedTextLength();
}
};
const y = d3.scaleBand()
.range([height, 0], .1)
.domain(data.map(function (d) {
return d.name; <----- wrap need to somehow attach to this
})
);
Run Code Online (Sandbox Code Playgroud)