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

graph: fix PNG download button #4759

Merged
merged 3 commits into from
Mar 11, 2021
Merged

graph: fix PNG download button #4759

merged 3 commits into from
Mar 11, 2021

Conversation

psybuzz
Copy link
Contributor

@psybuzz psybuzz commented Mar 9, 2021

The "Download as PNG" button in the Graph dashboard was broken
during the Polymer 2 -> 3 migration. Before, <tf-graph-minimap>
relied on assumptions that <tf-graph-controls> would provide an
<a> tag for downloading in the DOM. This is broken functionally
because the element is not accessible from another shadow subtree.

This fixes the download button by properly plumbing a 'click' event
handler from the controls to trigger code in the minimap.

Manually tested that clicking the button properly opens or saves
a PNG to the filesystem using Chrome and Firefox.

Googlers, see test sync cl/362151624

Fixes #3714

For reviewers, the component tree structure looks like:

- <tf-graph-dashboard>
  - <tf-graph-controls>
  - <tf-graph-board>
    - <tf-graph>
      - <tf-graph-scene>
        - <tf-graph-minimap>

image

@google-cla google-cla bot added the cla: yes label Mar 9, 2021
@psybuzz psybuzz force-pushed the pz-g-png branch 2 times, most recently from 037149a to bdf139a Compare March 9, 2021 21:47
@psybuzz psybuzz requested a review from wchargin March 9, 2021 21:50
Copy link
Contributor

@wchargin wchargin left a comment

Choose a reason for hiding this comment

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

Recommend test-syncing this, but the code looks good to me.

@@ -199,6 +201,11 @@ class TfGraphApp extends LegacyElementMixin(PolymerElement) {
}
}
_fit() {
(this.$$('#graphboard') as any).fit();
((this.$$('#graphboard') as unknown) as TfGraphBoard).fit();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to cast through unknowns here? It works fine for me
locally if casting directly to TfGraphBoard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah true, it was actually unnecessary. Even with as TfGraphBoard, the internal sync seems to not like this, so I've set it back to as any for now.

On that note, I still haven't figured out how to trigger the internal check in OSS, as simply adding compiler option declaration: true doesn't do the trick.

const element = document.createElement('a');
element.href = URL.createObjectURL(blob);
element.download = filename;
element.click();
Copy link
Contributor

Choose a reason for hiding this comment

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

I’ve tested this and it seems to work for me, but I’m a bit surprised.
I expected a synthetic e.click() event to not trigger a download.
Do you know what I’m misunderstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that el.click(), while synthetic, still triggers the browser's "default behavior", as well as any 'click' listeners registered on the element. I'm not sure that really answers the root of your question, I looked briefly at the spec but didn't see anything definitive. Similar to download, calling .click on other types of elements may trigger native behaviors such as page navigation, opening the browser file selector dialog, submitting a form, etc.

@@ -1131,6 +1130,8 @@ export class TfGraphControls extends LegacyElementMixin(PolymerElement) {
})
_legendOpened: boolean = true;

private _downloadFilename = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this default to 'graph.png' for consistency with the setter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@psybuzz
Copy link
Contributor Author

psybuzz commented Mar 11, 2021

Added a test sync cl to the description: cl/362151624

Ended up needing to go back to as any for a few things.

Thanks for the review!

@psybuzz psybuzz merged commit 0ee9959 into master Mar 11, 2021
@psybuzz psybuzz deleted the pz-g-png branch March 11, 2021 02:10
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.

Graph "Download PNG" button not working with TensorBoard 2.2.2
2 participants