Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion remotion-composer/src/components/charts/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const BarChart: React.FC<BarChartProps> = ({
{ extrapolateLeft: "clamp", extrapolateRight: "clamp" }
)}
>
{formatNumber(datum.value)}
{formatValue(datum.value)}
</text>
)}

Expand Down Expand Up @@ -282,3 +282,9 @@ function formatNumber(n: number): string {
if (Number.isInteger(n)) return String(n);
return n.toFixed(1);
}

function formatValue(n: number): string {
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;
return String(n);
}
21 changes: 21 additions & 0 deletions tests/contracts/test_bar_chart_format_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path


REPO_ROOT = Path(__file__).resolve().parents[2]


def test_bar_chart_value_labels_preserve_fractional_input_precision() -> None:
"""Value labels must not reuse the one-decimal axis tick formatter."""
source = (
REPO_ROOT / "remotion-composer/src/components/charts/BarChart.tsx"
).read_text(encoding="utf-8")

value_label = source[source.index("{/* Value label */}") : source.index(
"{/* Label */}", source.index("{/* Value label */}")
)]
assert "{formatValue(datum.value)}" in value_label
assert "{formatNumber(datum.value)}" not in value_label

formatter = source[source.index("function formatValue") :]
assert "return String(n);" in formatter
assert "return n.toFixed(1);" not in formatter
Loading