Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(timeseries charts): adjust legend width by padding #32030

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

eschutho
Copy link
Member

@eschutho eschutho commented Jan 30, 2025

SUMMARY

Small adjustment to add an ellipsis and width to the legend based on the margin so that the legend does not overlap the chart when on the sides. Currently you have to manually adjust the margin to make sure that it all fits. There are still some cases in very small margins where there is still some overlap, and manual adjustment to the margins is necessary.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
Screenshot 2025-01-31 at 3 04 01 PM
After:

Screen.Recording.2025-01-31.at.3.01.42.PM.mov

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@eschutho eschutho marked this pull request as draft January 30, 2025 00:16
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Readability and Maintainability Unexplained magic numbers in legend width calculation ▹ view
Functionality Legend width calculation hardcoded values ▹ view
Files scanned
File Path Reviewed
superset-frontend/packages/superset-ui-chart-controls/src/types.ts
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts

Explore our documentation to understand the languages and file types we support and the files we ignore.

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Current Korbit Configuration

General Settings
Setting Value
Review Schedule Automatic excluding drafts
Max Issue Count 10
Automatic PR Descriptions
Issue Categories
Category Enabled
Naming
Database Operations
Documentation
Logging
Error Handling
Systems and Environment
Objects and Data Structures
Readability and Maintainability
Asynchronous Processing
Design Patterns
Third-Party Libraries
Performance
Security
Functionality

Feedback and Support

Note

Korbit Pro is free for open source projects 🎉

Looking to add Korbit to your team? Get started with a free 2 week trial here

@@ -446,6 +447,10 @@ export function getLegendProps(
switch (orientation) {
case LegendOrientation.Left:
legend.left = 0;
legend.textStyle = {
overflow: 'truncate',
width: Math.max((padding?.left || 205) - 45, 10),
Copy link

Choose a reason for hiding this comment

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

Unexplained magic numbers in legend width calculation category Readability and Maintainability

Tell me more
What is the issue?

Magic numbers (205, 45, 10) are used in the width calculation without explanation of their significance.

Why this matters

Future maintainers won't understand what these numbers represent or why they were chosen, making it difficult to modify or debug the logic.

Suggested change ∙ Feature Preview
// Extract magic numbers into named constants at the top of the file
const DEFAULT_LEGEND_WIDTH = 205;
const LEGEND_ICON_WIDTH = 45;
const MIN_LEGEND_TEXT_WIDTH = 10;

// Then use in the code
Math.max((padding?.left || DEFAULT_LEGEND_WIDTH) - LEGEND_ICON_WIDTH, MIN_LEGEND_TEXT_WIDTH)

Report a problem with this comment

💬 Chat with Korbit by mentioning @korbit-ai.

Comment on lines 450 to 461
legend.textStyle = {
overflow: 'truncate',
width: Math.max((padding?.left || 205) - 45, 10),
};
Copy link

Choose a reason for hiding this comment

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

Legend width calculation hardcoded values category Functionality

Tell me more
What is the issue?

The legend text width calculation has a hardcoded fallback value of 205 and a fixed subtraction of 45 pixels, which may not be suitable for all chart sizes and configurations.

Why this matters

Using fixed values for layout calculations can lead to text overflow or underutilized space in different chart sizes and configurations. This reduces the flexibility and responsiveness of the chart legend.

Suggested change ∙ Feature Preview

Use dynamic values based on the chart container size or make these values configurable through the chart configuration. Example:

legend.textStyle = {
  overflow: 'truncate',
  width: Math.max((padding?.left || padding?.default || containerWidth * 0.2) - padding?.textMargin || 10, 10),
};

Report a problem with this comment

💬 Chat with Korbit by mentioning @korbit-ai.

Copy link
Contributor

@dpgaspar Processing your ephemeral environment request here. Action: up.

Copy link
Contributor

@eschutho Processing your ephemeral environment request here. Action: up.

@eschutho eschutho changed the title chore: adjust legend width by padding chore: [timeseries charts] adjust legend width by padding Jan 31, 2025
@eschutho eschutho changed the title chore: [timeseries charts] adjust legend width by padding chore(timeseries charts): adjust legend width by padding Jan 31, 2025
@eschutho eschutho force-pushed the elizabeth/fix-legend-overflow branch from dfcee49 to 033bfd9 Compare January 31, 2025 23:30
@eschutho eschutho marked this pull request as ready for review January 31, 2025 23:31
@dosubot dosubot bot added the viz:charts:timeseries Related to Timeseries label Jan 31, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Functionality Zero-width legend risk ▹ view
Files scanned
File Path Reviewed
superset-frontend/packages/superset-ui-chart-controls/src/types.ts
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts

Explore our documentation to understand the languages and file types we support and the files we ignore.

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Current Korbit Configuration

General Settings
Setting Value
Review Schedule Automatic excluding drafts
Max Issue Count 10
Automatic PR Descriptions
Issue Categories
Category Enabled
Documentation
Logging
Error Handling
Readability and Maintainability
Design Patterns
Performance
Security
Functionality

Feedback and Support

Note

Korbit Pro is free for open source projects 🎉

Looking to add Korbit to your team? Get started with a free 2 week trial here

@@ -443,13 +444,30 @@ export function getLegendProps(
borderColor: theme.colors.grayscale.base,
},
};
const MIN_LEGEND_WIDTH = 0;
Copy link

Choose a reason for hiding this comment

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

Zero-width legend risk category Functionality

Tell me more
What is the issue?

Setting MIN_LEGEND_WIDTH to 0 could cause legends to disappear completely when padding minus MARGIN_GUTTER is 0 or negative.

Why this matters

When the padding is less than or equal to MARGIN_GUTTER (45px), the legend width will be 0, making the legend text invisible and breaking the layout functionality intended by the developer.

Suggested change ∙ Feature Preview

Set a reasonable minimum width to ensure legends remain visible and functional:

const MIN_LEGEND_WIDTH = 100; // or another appropriate minimum width value

Report a problem with this comment

💬 Chat with Korbit by mentioning @korbit-ai.

@eschutho eschutho removed testenv-up viz:charts:timeseries Related to Timeseries labels Feb 1, 2025
Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

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

Looks good. Curious about that big margin when the legend is on top or the bottom? Is it intended?

const MIN_LEGEND_WIDTH = 0;
const MARGIN_GUTTER = 45;
const getLegendWidth = (paddingWidth: number) =>
Math.max(paddingWidth - MARGIN_GUTTER, MIN_LEGEND_WIDTH);
Copy link
Member

Choose a reason for hiding this comment

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

I kinda agree with bot's comment above - maybe we should set a minimal width value where the legend is still readable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I tried out a few different min widths, but the problem is that when applying a min width, then we have the same overlap issue with the chart. So either way, there will be a UI issue, and a larger padding will need to be set. Someone needs to explicitly set a 0 padding in order for this to apply. If you think having the overlap is better than a readable legend, we can def do that.

@eschutho
Copy link
Member Author

eschutho commented Feb 3, 2025

Looks good. Curious about that big margin when the legend is on top or the bottom? Is it intended?

Oh, good eye. That was just because I had set the margin to 200 in the video. This is the margin top when not entered:
Screenshot 2025-02-03 at 2 06 44 PM

@eschutho eschutho merged commit 8984f88 into master Feb 3, 2025
68 of 85 checks passed
@eschutho eschutho deleted the elizabeth/fix-legend-overflow branch February 3, 2025 22:11
@michael-s-molina michael-s-molina added the v5.0 Label added by the release manager to track PRs to be included in the 5.0 branch label Feb 4, 2025
michael-s-molina pushed a commit that referenced this pull request Feb 12, 2025
sfirke pushed a commit to sfirke/superset that referenced this pull request Feb 12, 2025
sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Mar 21, 2025
awilliamsTT pushed a commit to awilliamsTT/superset that referenced this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages plugins preset-io size/M v5.0 Label added by the release manager to track PRs to be included in the 5.0 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants