Skip to content

Use display names for aesthetics in stat error messages.#463

Open
teunbrand wants to merge 11 commits into
posit-dev:mainfrom
teunbrand:stat_errors_aesthetic_names
Open

Use display names for aesthetics in stat error messages.#463
teunbrand wants to merge 11 commits into
posit-dev:mainfrom
teunbrand:stat_errors_aesthetic_names

Conversation

@teunbrand
Copy link
Copy Markdown
Collaborator

@teunbrand teunbrand commented Jun 2, 2026

This PR aims to fix #435.

The main change is that the Mappings struct now has a context field that optionally holds an AestheticContext. The benefit it twofold:

  1. We don't have to pass these around separately, reducing the number of arguments in functions.
  2. We can emit user-facing display names for aesthetics in messages anywhere we have access to layer mappings.

The only downside is that we move from a single plot-wide source of truth about AestheticContext, to layer-level sources of truth. This is more of a theoretical than practical objection though and I think it is worth it.

teunbrand and others added 11 commits June 2, 2026 10:03
Mappings now carries an optional AestheticContext field (set once during
transform_to_internal). This eliminates the need to pass aesthetic_ctx as
a separate parameter through ~30 stat/geom/execute function signatures.

Added display_name() and internal_name() convenience methods on Mappings
for translating between internal and user-facing aesthetic names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These functions now get context from the layer's Mappings directly,
removing another set of explicit AestheticContext threading.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
add_discrete_columns_to_partition_by and flip_dataframe_position_columns
now get AestheticContext from the layer's Mappings instead of requiring
it as a separate parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The writer's validate_layer_columns now uses layer.mappings.display_name()
instead of receiving a separate AestheticContext parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread src/plot/types.rs

/// Set the aesthetic context. Must only be called once.
pub fn set_context(&mut self, ctx: super::AestheticContext) {
debug_assert!(self.context.is_none(), "aesthetic context already set");
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This gives a sort of 'soft immutability' to the context field, which helps preserving its role as a source of thruth.

@teunbrand teunbrand marked this pull request as ready for review June 2, 2026 12:14
@teunbrand teunbrand requested a review from thomasp85 June 2, 2026 12:14
@thomasp85
Copy link
Copy Markdown
Collaborator

I am going to push back on this for the reason that we might end up with a dynamic AestheticContext due to interactivity. I'm not 100% sure it will materialise but it feels wrong and premature to do this work now before we have figured it out

@teunbrand
Copy link
Copy Markdown
Collaborator Author

Is the objection against (1) the 'soft immutability' or (2) against bundling mapping with aesthetic context?

If (1), I'd argue that this is just a 1 LOC guard that we can relieve once the need arises.
If (2), whether I'd agree will heavily depend on how interactivity is implemented. If interactively is purely the business of the writer, then the RenderContext struct is the authoritative source, not the layer mapping. Otherwise yeah it might get somewhat murkt,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve stat errors using aesthetic_ctx

2 participants