score:1
You are over complicating how you set the axis labels. When rotating labels, labels are rotated from the coordinate system origin - not the text anchor. We can see this better if we compare the labels as is and if we remove the transform and just use the x,y attributes you specify:
.attr('x', 0)
.attr('y', function(d, i) {
return i * cellSize;
})
//.attr('transform', function(d, i) {
// return 'translate(-25, 11)';
//})
We can see all labels being rotated together around a common point. A hint that something might be awry in the label placement also comes from the code that dynamically sets a y
value and a fixed x
value for to place values that differ only in x
values.
We can simplify this, instead of setting x, y, and transform, let's just set transform. First we'll modify the coordinate system so that the origin of each labels coordinate system is where it is anchored. Then we'll rotate:
.attr('transform', function(d, i) {
return 'translate('+(i*cellSize)+',2) rotate(-65)';
})
We'll also want to update the update function:
t.selectAll('.colLabel')
.attr('transform', function(d, i) {
return 'translate('+(sorted.indexOf(i)*cellSize)+',2) rotate(-65)';
})
Giving us:
The other issue, the spacing of the y axis labels, you are updating the x position of the labels when you sort. This is un-necessary, the labels only need to move vertically, we can remove the transform change and just use:
t.selectAll('.rowLabel')
.attr('y', function(d, i) {
return sorted.indexOf(i) * cellSize;
})
Here's an updated plunkr.
Source: stackoverflow.com
Related Query
- Place the labels on the axes correctly in D3.js
- how to correctly place the text labels in d3.js?
- How to correctly add labels to the d3 pie chart?
- plotting the points x and y, the axes y and x are not shown correctly
- How to place data labels just above or below the data points in d3.js line chart?
- Placing labels at the center of nodes in d3.js
- d3.js: Align text labels between ticks on the axis
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- Labels / text on the nodes of a D3 force directed graph
- How to put labels on the edges in the Dendrogram example?
- How to place text on the circle when using D3.js force layout?
- labels inside the heatmap rects
- How do I hide the text labels in d3 when the nodes are too small?
- How to add a legend and labels to the pie chart?
- How to make the NVD3 discreteBarChart labels on the X axis to adapt to the width or to the number of labels?
- D3 refresh axes labels
- dimple.js How can I change the labels of a chart axis without changing the data?
- D3 curved labels in the center of arc
- Removing the raised corners from d3.js axes to create flat axis
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- How to place marker head in the middle of the links
- How can I add labels inside the points in a scatterplot?
- How to make grid lines when axes are aligned at the middle?
- adding input text box on clicking the data labels d3.js
- Why are the labels on my D3 axis inconsistent (e.g. month, day)?
- Stacked Bar Chart using d3.js stack layout; the bar sections not always in correct place
- How can I construct coordinate axes where the origin has a single label?
- How to make labels appear only when the chart is zoomed in
- Get X and Y axes values from the mouse position in d3.js
- How do you move number labels further away from the x-axis in d3.js?
More Query from same tag
- What does it mean to scale a projection in d3?
- d3.js visibility-zone calculations or how to draw geo rectangle
- dc.js/d3.js - min/max value from group per category
- Referencing JavaScript library in GWT for JavaScript Code
- How to programatically add new children to a deeply nested object
- Mouseevent div cover div on chart
- d3 accessor of hierarchical array of objects
- d3 grouped bar chart creation issue
- Marker is not displaying when it is generated dynamically using jquery
- Show the tooltip inside a div in a D3 stacked area chart
- nested donuts, partial sum of the values in the 2nd dimension array
- D3 circle pack - Adding labels to nodes
- data is undefined after importing from a csv file with d3
- Why is the vertical scrollbar always visible
- How to convert pixel to translate value in d3?
- migrating to d3 v4 cause duplicates on drag
- Using XML attributes in d3.js
- How to filter JavaScript object based on property condition?
- d3 and webpack: __WEBPACK_IMPORTED_MODULE_0_d3__.scaleLinear is not a function
- Can I use d3.scales to evenly distribute circles of varying size
- Custom time interval infinitely looping
- d3.js Date vs Half hour heat map not working
- d3.event.pageX & d3.mouse(this)[0]
- My D3.js code cause new data to be added as a new graph, I want it to be appended to an existing graph. What did I do wrong?
- Drawing link with d3 and d3-flextree plugin
- d3 force-directed layout expands on reheat
- D3.js does not display anything on the screen
- d3.geom.voronoi() does not return enaugh polygons
- Error with .compose using dc.js
- Add lines to SVG donut