Skip to content

Conversation

@kjgoodrick
Copy link
Contributor

📝 Summary

With this PR it possible to manually swap the color of the triangle in the mo.stat UI element. Previously the color was always green for increases and always red for decreases, but sometimes a decrease is "good" and one may want to display a green downwards facing triangle.

🔍 Description of Changes

The stat function now has a color argument that accepts the literals "positive" (green) or "negative" (red) to allow the user to set the color manually. If not specified the color will be as it is now, green for increase and red for decrease.

📋 Checklist

@vercel
Copy link

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Nov 18, 2025 1:03am

@Light2Dark
Copy link
Contributor

Light2Dark commented Nov 14, 2025

Thanks! Feel free to disagree, would it be more intuitive if the API is just
reverse_color=True or invert_color?

@kjgoodrick
Copy link
Contributor Author

Thanks for suggesting that, I do think it’s less confusing to use reverse_color. I will update the PR.

@Light2Dark
Copy link
Contributor

@mscolnick, fyi on the API change.

@Light2Dark
Copy link
Contributor

thank you! using var will raise pre-commit issues, we should use let / const instead. this snippet should help clean it up.

  const fillColors = {
    increase: "var(--grass-8)",
    decrease: "var(--red-8)",
  };

  const strokeColors = {
    increase: "var(--grass-9)",
    decrease: "var(--red-9)",
  };

...
             <TriangleIcon
                className="w-4 h-4 mr-1 p-0.5"
                fill={reverseColor ? fillColors.decrease : fillColors.increase}
                stroke={
                  reverseColor ? strokeColors.decrease : strokeColors.increase
                }
              />

Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution — concept makes sense, but I have a comment on the API.

caption: Optional[str] = None,
direction: Optional[Literal["increase", "decrease"]] = None,
bordered: bool = False,
reverse_color: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is too imperative. We should prefer something more semantic or declarative.

For example, goal: Literal["increase", "decrease"],

mo.stat(value=10, direction="increase", goal="increase")

which leaves room for the "goal" to affect other behaviors in the future instead of just reversing a color. This is more legible than reverse_color=True (Reverse color of what? Why do I want to reverse colors).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this suggestion, after reading it I totally agree. I have updated the PR changing the parameter name to target_direction to make it clear that the target is associated with the direction. To keep the current behavior I set the default target to "increase". This has also simplified the implementation, so great comment.

@akshayka akshayka requested a review from dmadisetti November 16, 2025 16:54
Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is better! One comment

Comment on lines 28 to 33
direction: the direction of the statistic,
either `increase` or `decrease`
bordered: whether to display a border around the statistic
target_direction: The target direction of the statistic,
either `increase` or `decrease`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for target_direction could benefit from being more verbose. Without more context it is difficult to understand the difference between direction and target_direction

Clarified the target_direction parameter description.
Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, this looks great to me!

@dmadisetti, can you review this from an API owner's perspective?

@dmadisetti dmadisetti changed the title Change stat color feat: Contextually change stat color Nov 18, 2025
@dmadisetti dmadisetti merged commit 3c21a97 into marimo-team:main Nov 18, 2025
25 of 37 checks passed
@dmadisetti dmadisetti added the enhancement New feature or request label Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants