Skip to content

fix: remove whitespace and title overlapping#1330

Open
rajnisht7 wants to merge 22 commits into
fossasia:devfrom
rajnisht7:remove-whitespace-adjustment
Open

fix: remove whitespace and title overlapping#1330
rajnisht7 wants to merge 22 commits into
fossasia:devfrom
rajnisht7:remove-whitespace-adjustment

Conversation

@rajnisht7

@rajnisht7 rajnisht7 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Description

currently there is enough whitespace in the panes between graph and the box and the title also overlaps with the modbar
this PR resolves this issue

Motivation and Context

as there is enough space it makes the visual the bad and overlapping makes difficult to identify

How Has This Been Tested?

executed the server
verified the changes

Screenshots:

Before:

image image image

After:

image image image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactor or cleanup (changes to existing code for improved readability or performance)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by Sourcery

Adjust plot layout configuration to improve spacing and title positioning in graph panes.

Bug Fixes:

  • Prevent plot titles from overlapping with the mode bar by updating layout title and margin settings.
  • Reduce excessive top whitespace in plot panes by setting appropriate top margins based on the presence of a title.

Copilot AI review requested due to automatic review settings May 26, 2026 19:53
@sourcery-ai

sourcery-ai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Plotly layout handling in PlotPane to reduce excess whitespace and prevent the plot title from overlapping the modbar by normalizing the layout, converting string titles to objects, and setting top margins and title vertical position based on title presence.

File-Level Changes

Change Details Files
Normalize and adjust Plotly layout to control whitespace and title positioning.
  • Introduce a local layout object defaulting to an empty object when content.layout is undefined.
  • Ensure plot titles are always treated as objects by converting string titles into { text: ... } form.
  • Initialize layout.margin if missing and set a higher top margin and vertical y position when a title text is present to avoid overlap with the modbar.
  • Apply a smaller default top margin when no title text is present to reduce excess whitespace.
js/panes/PlotPane.js

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!

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates PlotPane’s Plotly layout handling to normalize layout.title and adjust top margin based on title presence.

Changes:

  • Introduces a local layout variable derived from content.layout.
  • Normalizes string titles into { text } objects and adjusts layout.margin.t / layout.title.y.
  • Keeps Plotly’s re-render mechanism via datarevision.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread js/panes/PlotPane.js Outdated
Comment thread js/panes/PlotPane.js
Comment thread js/panes/PlotPane.js Outdated

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • The new layout variable is only passed by reference to content.layout when content.layout is already defined; if it's undefined you end up modifying a separate object and still pass the original content.layout to Plotly.react, so consider either initializing content.layout up front or operating on content.layout directly to avoid this discrepancy.
  • When setting layout.margin.t and converting the title from string to object, you currently overwrite any existing margin.t or title object configuration; it would be safer to only apply these defaults when the respective properties are not already set so that custom layouts are preserved.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `layout` variable is only passed by reference to `content.layout` when `content.layout` is already defined; if it's undefined you end up modifying a separate object and still pass the original `content.layout` to `Plotly.react`, so consider either initializing `content.layout` up front or operating on `content.layout` directly to avoid this discrepancy.
- When setting `layout.margin.t` and converting the title from string to object, you currently overwrite any existing `margin.t` or `title` object configuration; it would be safer to only apply these defaults when the respective properties are not already set so that custom layouts are preserved.

## Individual Comments

### Comment 1
<location path="js/panes/PlotPane.js" line_range="25-28" />
<code_context>
   const maxsmoothvalue = 100;
   const [smoothWidgetActive, setSmoothWidgetActive] = useState(false);
   const [smoothvalue, setSmoothValue] = useState(1);
+  let layout = content.layout || {};

   // private events
</code_context>
<issue_to_address>
**issue (bug_risk):** Layout normalization is done on a local variable but not used consistently when calling Plotly/react or setting datarevision.

Because `layout` is normalized and mutated while `Plotly.react` and `datarevision` still use `content.layout`, you can end up both throwing (when `content.layout` is falsy) and not applying the normalized title/margin to the rendered plot.

To fix this, make a single canonical layout object and use it everywhere, e.g. either:

```js
let layout = content.layout || {};
layout.datarevision = props.version;
// title / margin normalization on `layout`...
Plotly.react(contentID, data.concat(smooth_data), layout, { ... });
```

or:

```js
content.layout = content.layout || {};
const layout = content.layout;
layout.datarevision = props.version;
// title / margin normalization on `layout`...
Plotly.react(contentID, data.concat(smooth_data), content.layout, { ... });
```
</issue_to_address>

### Comment 2
<location path="js/panes/PlotPane.js" line_range="139-155" />
<code_context>
+        layout.title = { text: layout.title };
+      }
+
+      layout.margin = layout.margin || {};
+
+      if (layout.title.text) {
+        layout.margin.t = 65;
+        layout.title.y = 0.9;
+      } else {
+        layout.margin.t = 30;
+      }
+    } else {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Title-based margin logic overwrites any existing top margin configuration.

This always sets `layout.margin.t` to `65` or `30`, overwriting any `margin.t` explicitly provided in `content.layout` (e.g., for legends, annotations, or long titles).

To preserve caller-defined margins while keeping the new defaults, only set `margin.t` when it’s unset:
```js
layout.margin = layout.margin || {};
if (layout.margin.t == null) {
  layout.margin.t = layout.title && layout.title.text ? 65 : 30;
}
```
This lets explicit `margin.t` values take precedence.

```suggestion
    layout.margin = layout.margin || {};

    if (layout.title) {
      if (typeof layout.title === 'string') {
        layout.title = { text: layout.title };
      }

      if (layout.title.text) {
        if (layout.margin.t == null) {
          layout.margin.t = 65;
        }
        layout.title.y = 0.9;
      } else if (layout.margin.t == null) {
        layout.margin.t = 30;
      }
    } else if (layout.margin.t == null) {
      layout.margin.t = 30;
    }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread js/panes/PlotPane.js Outdated
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +139 to +155
if (layout.title) {
if (typeof layout.title === 'string') {
layout.title = { text: layout.title };
}

layout.margin = layout.margin || {};

if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
} else {
layout.margin = layout.margin || {};
layout.margin.t = 30;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Title-based margin logic overwrites any existing top margin configuration.

This always sets layout.margin.t to 65 or 30, overwriting any margin.t explicitly provided in content.layout (e.g., for legends, annotations, or long titles).

To preserve caller-defined margins while keeping the new defaults, only set margin.t when it’s unset:

layout.margin = layout.margin || {};
if (layout.margin.t == null) {
  layout.margin.t = layout.title && layout.title.text ? 65 : 30;
}

This lets explicit margin.t values take precedence.

Suggested change
if (layout.title) {
if (typeof layout.title === 'string') {
layout.title = { text: layout.title };
}
layout.margin = layout.margin || {};
if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
} else {
layout.margin = layout.margin || {};
layout.margin.t = 30;
}
layout.margin = layout.margin || {};
if (layout.title) {
if (typeof layout.title === 'string') {
layout.title = { text: layout.title };
}
if (layout.title.text) {
if (layout.margin.t == null) {
layout.margin.t = 65;
}
layout.title.y = 0.9;
} else if (layout.margin.t == null) {
layout.margin.t = 30;
}
} else if (layout.margin.t == null) {
layout.margin.t = 30;
}

@tonypzy tonypzy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hard-coded values occurs in this PR. These values ​​may need to be adjusted if the Plotly version is updated or the pane layout changes.
i suggest hiding modbar. When the mouse moves to the top of pane, modbar appears.
Let's see what others think of

@vedansh-5 vedansh-5 requested a review from Copilot May 27, 2026 14:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment thread js/panes/PlotPane.js Outdated
Comment thread js/panes/PlotPane.js Outdated
Comment thread js/panes/PlotPane.js Outdated
Comment thread js/panes/PlotPane.js Outdated
@rajnisht7

Copy link
Copy Markdown
Contributor Author

@tonypzy as checked plotly expects numeric value in padding

@Jayantparashar10 Jayantparashar10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

content.layout = content.layout || {}
let layout = content.layout || {};

The || {} fallback on line 2 can never fire. Simplify to:

content.layout = content.layout || {};
const layout = content.layout;

@rajnisht7 rajnisht7 requested a review from tonypzy June 1, 2026 07:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread js/panes/PlotPane.js Outdated
Comment on lines +25 to +26
content.layout = content.layout || {}
let layout = content.layout;
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +148 to +156
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
} else {
layout.margin = layout.margin || {};
layout.margin.t = 30;
}
Comment thread js/panes/PlotPane.js Outdated

@vedansh-5 vedansh-5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@Jayantparashar10 Jayantparashar10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Saksham-Sirohi Saksham-Sirohi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please resolve conflicts and ensure the test pass

Copilot AI review requested due to automatic review settings June 9, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread js/panes/PlotPane.js
Comment on lines +25 to +26
content.layout = content.layout || {};
let layout = content.layout;
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +193 to +209
if (layout.title) {
if (typeof layout.title === 'string') {
layout.title = { text: layout.title };
}

layout.margin = layout.margin || {};

if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
} else {
layout.margin = layout.margin || {};
layout.margin.t = 30;
}
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +198 to +209
layout.margin = layout.margin || {};

if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
} else {
layout.margin = layout.margin || {};
layout.margin.t = 30;
}
@rajnisht7 rajnisht7 requested a review from Copilot June 9, 2026 08:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread js/panes/PlotPane.js
Comment on lines +25 to +26
content.layout = content.layout || {};
let layout = content.layout;
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +198 to +209
layout.margin = layout.margin || {};

if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
} else {
layout.margin = layout.margin || {};
layout.margin.t = 30;
}
Comment thread js/panes/PlotPane.js

@Manik-Khajuria-5 Manik-Khajuria-5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rajnisht7 Can u please address co pilot reviews and also ci test are failing please go through it one more time

Copilot AI review requested due to automatic review settings June 9, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread js/panes/PlotPane.js Outdated
Comment on lines +25 to +26
content.layout = content.layout || {};
const layout = content.layout;
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +198 to +205
layout.margin = layout.margin || {};

if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
Comment thread js/panes/PlotPane.js Outdated
@tonypzy

tonypzy commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

please resolve copilot issues

Copilot AI review requested due to automatic review settings June 11, 2026 11:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread js/panes/PlotPane.js
Comment on lines +25 to +26
content.layout = content.layout || {};
let layout = content.layout;
Comment thread js/panes/PlotPane.js Outdated
Comment on lines +198 to +205
layout.margin = layout.margin || {};

if (layout.title.text) {
layout.margin.t = 65;
layout.title.y = 0.9;
} else {
layout.margin.t = 30;
}
Comment thread js/panes/PlotPane.js Outdated

layout.margin = layout.margin || {};

if (layout.title.text) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants