HAHS.
Back to Catalog

Sort

interaction

Also known as: reorder, order by, sort by column, rank order

Show rankingEnable explorationCompare CategoricalNumericalTemporal

Description

Sorting reorders the visual elements of a chart (bars, rows, columns, marks) according to a data attribute, transforming an arbitrary arrangement into a meaningful one. In a bar chart, sorting bars from tallest to shortest instantly reveals the ranking structure that would be invisible in an alphabetical ordering. In a heatmap, reordering rows and columns by similarity can expose latent clusters. Sorting is deceptively simple, but it is one of the most powerful cognitive aids in visualization because it exploits the human visual system’s ability to detect monotonic trends and rank-order outliers at a glance.

Yi et al. (2007) classify sorting under the “reconfigure” interaction intent — changing the spatial arrangement of data marks to reveal a different aspect of the data without changing the data itself or the visual encoding. The key insight is that the same data, with the same bar lengths, tells a very different story depending on order. An alphabetically sorted bar chart of countries’ GDP per capita hides the fact that Luxembourg and Norway are outliers; a value-sorted version makes this immediately obvious.

Interactive sort is especially important in tables and table-like visualizations (heatmaps, matrix views) where the user might want to sort by any column. Clicking a column header to toggle ascending/descending sort is one of the most familiar interaction patterns on the web, and it transfers naturally to visualization contexts. The transition between sort orders, when animated, helps the user track individual elements and understand how the reordering affects relative positions.

Sort — try it yourself

When to Use

  • When the chart has a categorical axis (bar chart, dot plot) and the default ordering (alphabetical, insertion order) does not reveal the ranking pattern.
  • In tables and table-like visualizations where the user may want to sort by any column.
  • In heatmaps where reordering rows/columns by clustering or similarity reveals block structure.
  • When the user’s task is explicitly about ranking (“which items are highest?”, “which are lowest?”).
  • When comparing multiple sort criteria (sort by revenue, then by growth rate) reveals different stories.

When NOT to Use

  • When the axis has an inherent meaningful order that should be preserved — e.g., time on a timeline, stages in a process, ordinal scales like “low/medium/high.”
  • When the chart has only 2-3 items — sorting is trivial and the interaction adds unnecessary complexity.
  • In scatter plots where both axes are continuous — sorting along one axis would distort the 2D spatial encoding.
  • When animated reordering would be disorienting due to too many elements moving simultaneously (more than ~50).

How It Works

  1. The user clicks a sort control — a column header, a “Sort by” dropdown, or a toggle button indicating the sort attribute and direction.
  2. The system computes the new ordering of the data items according to the selected attribute (ascending or descending).
  3. The marks are repositioned along the reordered axis. If animation is enabled, each mark smoothly transitions to its new position, helping the user track individual items.
  4. The axis labels update to reflect the new ordering.
  5. Clicking the same sort control again toggles the direction (ascending ↔ descending).
  6. A visual indicator (arrow icon, highlighted header) shows which attribute is currently active and in which direction.

Variations

  • Click-header sort: Clicking a column header sorts by that column. Standard in data tables.
  • Dropdown sort: A dropdown menu lets the user choose the sort attribute. Useful when there are many sortable dimensions.
  • Multi-level sort: Sort by a primary attribute, then break ties by a secondary attribute (e.g., sort by category, then by value within each category).
  • Cluster sort: Reorder using a clustering algorithm (e.g., hierarchical clustering on a heatmap) rather than a single attribute.
  • Manual drag sort: The user manually drags items to reorder them, useful for custom priority ordering.
  • Animated sort: Bars or rows slide to their new positions with a smooth transition, preserving object constancy.

Code Reference

// D3.js animated bar chart sort
let ascending = true;
d3.select("#sort-btn").on("click", () => {
  ascending = !ascending;
  const sorted = [...data].sort((a, b) =>
    ascending ? a.value - b.value : b.value - a.value
  );
  xScale.domain(sorted.map(d => d.name));
  svg.selectAll("rect")
    .transition().duration(600)
    .attr("x", d => xScale(d.name));
  svg.select(".x-axis")
    .transition().duration(600)
    .call(d3.axisBottom(xScale));
});