Skip to content

ChartView: Add configurable bar sort order #772

@NoopDog

Description

@NoopDog

Summary

The ChartView bar chart currently hardcodes sorting by count descending (highest to lowest) via sortCategoryValueViewsCount. We want to allow configuring the sort order per chart.

Current Behavior

In usePlotOptions hook (src/components/Index/components/EntityView/components/views/ChartView/components/Chart/hooks/UsePlotOptions/hook.ts), bars are always sorted by:

.sort(sortCategoryValueViewsCount)  // count descending, alpha tiebreaker

Desired Behavior

Allow configuring the chart sort order via SelectCategoryConfig. The codebase already has sort infrastructure in src/common/filters/sort/ with:

  • FILTER_SORT enum (ALPHA, COUNT)
  • sortCategoryValueViewsAlpha — alphabetical (case-insensitive)
  • sortCategoryValueViewsCount — count descending with alpha tiebreaker

Suggested Approach

Add a chartSort option to SelectCategoryConfig (or introduce a new enum like CHART_SORT) that supports at minimum:

  • COUNT (default, current behavior) — count descending
  • ALPHA — alphabetical ascending by label

The enum-based approach is preferred over a custom sort function because:

  1. The sort functions and enum pattern already exist in src/common/filters/sort/
  2. Only two meaningful sort dimensions exist (count and label)
  3. Keeps the config serializable and simple

Key files

File Role
src/common/filters/sort/config/types.ts Existing FILTER_SORT enum
src/common/filters/sort/models/utils.ts Existing sort functions
src/common/categories/config/types.ts SelectCategoryConfig — add chartSort here
src/components/.../ChartView/components/Chart/hooks/UsePlotOptions/hook.ts Where sort is applied — parameterize here
src/components/.../ChartView/components/Chart/types.ts ChartProps — thread sort config through

Default should remain COUNT for backward compatibility.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions