score:3
Accepted answer
The problem is that the text is already devoid of space when you try to a split on the basis of whitespace (for second time on-wards).
So instead of doing
words = text.text().split(/\s+/).reverse(),
do it this way
words = d3.select(this).data()[0].name.split(/\s+/).reverse(),
working example here
score:1
The problem is that you are using wrap
again and again in the same text. This is what I did:
First, I changed the class of any new text to newText
:
nodeEnter.append("text")
.attr("x", function(d) {
return d._children ? -0 : 8;
})
.attr("y", 3)
.attr("dy", "0em")
.attr("text-anchor", "middle")
.attr("class", "newText")
.text(function(d) {
return d.name;
})
wrap(d3.selectAll('.newText'),150);
And then, in the function click, I changed the class of all texts:
function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
}
d3.selectAll("text").attr("class", "text");
update(d);
}
Source: stackoverflow.com
Related Query
- Text does not stay wrapped on d3 tree nodes
- NVD3 chart fails to calculate legend text length in Chrome, since Window.getComputedStyle does not return font-size correctly
- d3 (v4) tree layout and typescript: Property 'x' does not exist on type 'HierarchyNode<IOrgChartNode>'
- D3.js text element does not display unicode character correctly
- Why does forceNetwork in networkd3 R display all nodes not in edgelist?
- Using foreignObjects to wrap text of Nodes in a D3 Tree
- Display the text inside the nodes in Tree graph in d3.js
- Text appended to path does not show
- How do I prevent node text to move away or not overlap on my tree in D3.js?
- tree.nodeSize() not working in D3 tree graph to inc. the space between nodes
- d3 tree tooltip does not appear
- radio button in conjunction with c3 does not show text
- Tree not updating nodes position when adding a new sibling
- Increase spacing/padding between each nodes in D3 Collapsible tree chart to avoid node and text overlaping
- the lines' points x1, x2, y1, y2 do not coincide with nodes in a radial tree
- Arrow is not touching to nodes in d3.js tree view in mobile and touch screen
- How does text on SVG not update but text on a div does?
- Why does D3 not update the text
- d3: update of chart via exit/remove/merge does not process changed label text properly
- Arrows are not touching to nodes in d3.js in tree layout
- Why does the text not appear inside the svg rects
- d3.js code rendering only nodes and not links. Also need a way to add text to nodes and links
- D3 version 4 tree view with rectangle nodes links not showing up
- d3.js partition.nodes(root) does not set the nodes x or dx values
- D3 - tree nodes not built from external JSON file
- d3.js tree layout need to expand as nodes open, not compress
- SVG foreignObject contents do not display unless plain text
- Importing local json file using d3.json does not work
- D3 Tree Layout Separation Between Nodes using NodeSize
- d3.js how to dynamically add nodes to a tree
More Query from same tag
- d3js tree chart not fitting on canvas
- d3.js bar chart is not updating based on click event
- How to fix problem with nvd3 events on firefox?
- SVG symbols do not fire onload event (only in firefox). I look for a workaround
- d3.js multi y-axis line chart
- Why do the SVG properties of an SVG element sometimes show up as accessible and sometimes not?
- How make linear interpolation?
- How to catch onDestroy in Angular2 for component that is removed
- D3 v4 moving both circle and text at the same time
- How to pass a value to line generation function in D3
- DC.js - trigger elastic resize when criteria are met
- add custom elements based on css styles not images to chart D3.js
- Incorrect SVG group being deleted
- Updating or deleting d3.slider with variation of visualization
- Circle points are not aligned with area shape
- How to build a 3rd party package in ember v2.6?
- d3.js pie chart not showing
- D3 x-axis not showing any data (datetime)
- Deep clone a function in javascript
- How to set d3 stroke width
- How to display sum total for currently selected series in NVD3.js Pie Chart?
- Position of tree after node expansion
- D3 chart display change with options
- Heatmap dc.js - provide the color range manually
- code failing with $ not defined: Uncaught reference error and Uncaught TypeError: Cannot read property 'getAttribute' of null
- D3 mouseover transitions gets "stuck"
- d3.js: Transition callback is not called for enter()
- How to access object properties in a JSON file using literals obtained from the same file
- D3.js X axis as index number
- How to create a zoomable, pannable, scrollable map with selectable graticles?