Skip to main content
100%

Alignment of text labels - 2

✓ Published0🌍 Public
EEE2dev
Last edited Nov 7, 2017
Created on Oct 29, 2017

This example demonstrates how text labels and axis ticks can smoothly transition to new positions when the underlying scale is rescaled. The visualization shows a set of categories along a point scale, where random data values are generated and the labels animate to their new y-positions while respecting constraints: labels do not overlap vertically, remain within the frame, and shift left or right depending on available space. The code uses D3 v4 with SVG and transitions via `d3.transition()`, updating the axis with `d3.axisLeft` and repositioning label groups using `.attr("transform", ...)`. A toggle button triggers the transition between original and rescaled states.

AI-generated description

This is an example how to compute the position of text labels when the axis is rescaled. The text labels and the ticks of the axis are transitioned to the destination while satisfying:

  • that the labels do not vertically overlap with each other
  • that the labels stay vertically within a give frame
  • that the labels are transitioned left or right of the new element depending on the empty space

see also: https://bl.ocks.org/ee2dev/fc880e1cfbb80f649878f3d5b9e8ed93

Similar vizzes