Skip to content

Commit

Permalink
fix: set domain to (0, 1) when no data is present (#1619)
Browse files Browse the repository at this point in the history
* fix: set domain to (0, 1) when no data is present

Fixes #1614

If no data is present, a scale has a domain of (0, 1) but if we
remove the data (set it to an empty array) afterwards, we set it
to (-inf, +inf) which causes rendering issues and make the bqplot
figure unable to restore itself.
It is more consistent to behave like no data was passed in, and use
(0, 1) for the domain.

* Update snapshots

---------

Co-authored-by: martinRenou <martin.renou@gmail.com>
  • Loading branch information
maartenbreddels and martinRenou committed Jul 26, 2023
1 parent dff8257 commit 1057c6b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions js/src/LinearScaleModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ export class LinearScaleModel extends ScaleModel {

update_domain() {
const that = this;
// if all domains are empty, we reset to the default domain of (0, 1)
if (
_.every(this.domains, (d) => {
return d.length === 0;
})
) {
this.domain = this.reverse ? [1, 0] : [0, 1];
this.trigger('domain_changed', this.domain);
return;
}

This comment has been minimized.

Copy link
@martinRenou

martinRenou Feb 19, 2024

Author Member

This breaks the case where the domain is not set.

We're looking into having streaming data in ipydatagrid. In that case the front-end does not have access to the full data and cannot compute the domain.

This comment has been minimized.

Copy link
@maartenbreddels

maartenbreddels Feb 19, 2024

Author Member

Yes, this is fixed in 4d08e55

This comment has been minimized.

Copy link
@maartenbreddels

maartenbreddels Feb 19, 2024

Author Member

Which I did not release yet btw!

This comment has been minimized.

Copy link
@martinRenou

martinRenou Feb 19, 2024

Author Member

Nevermind, I realize it's fine when min and max are set #1638

Let's release it!

const min = !this.min_from_data
? this.min
: d3.min(
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions ui-tests/tests/notebooks/lines_update.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@
"source": [
"lines.labels_visibility = 'label'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7444d361-f8f3-4641-88ef-fbe84450bfb3",
"metadata": {},
"outputs": [],
"source": [
"lines.x, lines.y = [], []"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "481f09e7-f7a9-4393-8388-a608b216ef41",
"metadata": {},
"outputs": [],
"source": [
"lines.x, lines.y = np.arange(len(y1)), [y1, y2, y3, y4]"
]
}
],
"metadata": {
Expand Down

0 comments on commit 1057c6b

Please sign in to comment.