Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Feb 20, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

This pull request introduces several enhancements to the legend functionality in Plot. It adds support for inline legends, refactors legend options for better type safety, and improves the handling of symbol legends to avoid redundancy with color legends. It also adds a test case for the new inline legend feature.

New Features:

  • Adds support for inline legends, allowing legends to be displayed directly within the plot area.
  • Adds the ability to inherit the legend option from the top-level plot options.

Enhancements:

  • Refactors legend options to provide more specific interfaces for different legend types (Swatches, Ramp, Opacity, Color, Symbol), improving type safety and organization.
  • Improves symbol legend to avoid displaying a redundant color legend when the symbol channel is also bound to the color scale.

Tests:

  • Adds a new test case for inline color legends with ordinal scales and ramp type.

@pull pull bot added the ⤵️ pull label Feb 20, 2025
@pull pull bot merged commit 1b7e76a into admariner:main Feb 20, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 20, 2025

Reviewer's Guide by Sourcery

This pull request refactors the legend options, adds support for inheriting legend options from the top-level plot options, and prevents redundant color legends when a symbol legend is already encoding color. It also includes a new test case for ordinal color ramp legends with inline plots.

Sequence diagram for creating legends

sequenceDiagram
    participant PlotOptions as PO
    participant createLegends as CL
    participant legendRegistry as LR
    participant value (legend function) as LF
    participant legendOptions as LO

    PO->>CL: createLegends(scales, context, options)
    loop for each [key, value] in legendRegistry
      CL->>LR: Check if key in scales
      alt key in scales
        CL->>PO: inherit(options[key], {legend: options.legend})
        CL->>LF: value(scales[key], legendOptions(context, scales[key], o), (key) => scales[key])
        alt legend != null
          CL->>CL: isSymbolColorLegend(legend)
          alt isSymbolColorLegend(legend) is true
            CL->>CL: hasColor = true
          end
          CL->>CL: legends.push(legend)
        end
      end
    end
    CL-->>PO: Return legends
Loading

File-Level Changes

Change Details Files
Refactors legend options by introducing specific interfaces for different legend types and consolidating them under a single LegendOptions interface.
  • Introduces SwatchesLegendOptions, RampLegendOptions, OpacityLegendOptions, ColorLegendOptions, and SymbolLegendOptions interfaces.
  • Consolidates all legend options under the LegendOptions interface.
  • Moves specific legend options from LegendOptions to their respective interfaces (e.g., ramp-specific options to RampLegendOptions).
src/legends.d.ts
src/plot.d.ts
Adds support for inheriting the legend option from the top-level plot options.
  • Modifies createLegends function to inherit the legend option from the top-level plot options if it is not defined in the scale options.
  • Updates the athletesSortNationality example to use the top-level legend option.
src/legends.js
test/plots/athletes-sort.ts
docs/features/legends.md
Implements a mechanism to avoid displaying redundant color legends when a symbol legend is already encoding color.
  • Introduces legendSymbolColor WeakSet to track symbol legends that also encode color.
  • Adds isSymbolColorLegend function to check if a legend is a symbol legend that also encodes color.
  • Modifies createLegends function to skip color legends if a corresponding symbol legend is present.
src/legends/swatches.js
src/legends.js
Adds a new test case for ordinal color ramp legends with inline plots.
  • Creates a new test function colorLegendOrdinalRampInline in test/plots/legend-color.ts.
  • Adds a corresponding HTML output file test/output/colorLegendOrdinalRampInline.html.
test/plots/legend-color.ts
test/output/colorLegendOrdinalRampInline.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant