Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add dummy 'wheel' event handler to enable scroll zoom on safari#7474

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
archmoj merged 8 commits intomasterfromsafari-scroll-zoom
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
move dummy scroll listener to Events.init()
  • Loading branch information
@emilykl
emilykl committedJul 17, 2025
commite6618c678a90fa0fcda1bb959b6fe2d98d53a6e8
10 changes: 10 additions & 0 deletionssrc/lib/events.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,6 +59,16 @@ var Events = {
internalEv.emit(event, data);
};

/*
* Add a dummy event handler for 'wheel' event for Safari
* to enable mouse wheel zoom.
* https://github.com/d3/d3/issues/3035
* https://github.com/plotly/plotly.js/issues/7452
*/
if(typeof plotObj.addEventListener === 'function') {
plotObj.addEventListener("wheel", () => {});
}
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is theif block necessary? CanplotObj be undefined?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@camdecoster There's severaltests which pass an empty object ({}) asplotObj, which was leading to anerror causing the test to fail.

I'm not sure ifplotObj is supposed to be a DOM object or if other types are allowed.

Copy link
ContributorAuthor

@emilyklemilyklJul 18, 2025
edited
Loading

Choose a reason for hiding this comment

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

Looks like in the actual code (tests aside),Events.init() is only called inone place, and the argument is the output ofgetGraphDiv(), which cannot benull orundefined but it could theoretically be some other type besides a DOM element.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I wonder if we should modify the tests rather than adding thisif statement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just use the optional chaining operator? I think that would essentially do the same thing as theif block, but is more compact and you wouldn't have to update any tests.
plotObj?.addEventListener("wheel", () => {});

emilykl reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Nice, TIL.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@camdecoster I've reverted to theif statement due to the conditional chaining operator not being supported in our build pipeline (see#7477) -- are you OK with me merging as it is currently?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this code will work fine.


return plotObj;
},

Expand Down
6 changes: 0 additions & 6 deletionssrc/plot_api/plot_api.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,12 +64,6 @@ function _doPlot(gd, data, layout, config) {
// Events.init is idempotent and bails early if gd has already been init'd
Events.init(gd);

// Add dummy event handler for 'wheel' event for Safari
// to enable mouse wheel zoom
// https://github.com/d3/d3/issues/3035
// https://github.com/plotly/plotly.js/issues/7452
d3.select(gd).on('wheel', function() {});

if(Lib.isPlainObject(data)) {
var obj = data;
data = obj.data;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp