Skip to content

feat: add configurable line width, align LineStyle with MarkerStyle#18

Open
zao111222333 wants to merge 2 commits intodonkeyteethUX:mainfrom
zao111222333:main
Open

feat: add configurable line width, align LineStyle with MarkerStyle#18
zao111222333 wants to merge 2 commits intodonkeyteethUX:mainfrom
zao111222333:main

Conversation

@zao111222333
Copy link
Contributor

This PR follows the same design direction as MarkerStyle and refactors LineStyle into a styling struct that supports both line type and width.

Previously, line styling was focused on pattern selection only. With this change, LineStyle becomes a more complete and extensible API for series lines and reference lines, making line configuration more consistent with the existing marker styling model.

Key changes:

  • Introduce a LineStyle struct that stores both width and line type
  • Reuse the shared size abstraction so line widths can be defined in pixels or world units
  • Update series and reference-line rendering so custom line widths are actually applied
  • Adjust builders and related APIs to keep line styling ergonomic and consistent

Overall, this makes line styling match the MarkerStyle approach more closely and provides a clearer foundation for future styling extensions.

@zao111222333
Copy link
Contributor Author

commit-56277 adds anti-aliasing for shader-rendered lines.

I discovered this while working on a local PlotWidget implementation for the tiny-skia CPU backend, which I plan to submit in a follow-up PR. Compared with the canvas path, the existing shader path rendered diagonal lines with visibly hard edges.

This change replaces the previous hard-edged polyline-strip approach with a screen-space analytic AA path:

  1. Each polyline segment is rendered as an independent quad instead of a single continuous triangle strip.
  2. In the vertex shader, the segment is transformed into screen-space basis vectors:
    • tangent_px for the along-line direction
    • normal_px for the perpendicular direction
  3. The generated quad is expanded by the true half line width plus a small AA fringe (LINE_AA_RADIUS_PX = 1.0).
  4. The vertex shader passes local screen-space coordinates to the fragment shader:
    • local_x_px
    • local_y_px
    • half_width_px

The fragment shader then computes stroke coverage analytically:

  • local_x_px is clamped to the segment extent to handle caps correctly.
  • The pixel-space distance from the fragment to the ideal stroked segment is computed.
  • That distance is converted into alpha with a soft ~1 px falloff.
let distance_to_stroke_px = length(vec2<f32>(cap_dx_px, in.local_y_px));
let edge_alpha = clamp(in.half_width_px + 0.5 - distance_to_stroke_px, 0.0, 1.0);

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.

1 participant