Skip to content

Commit

Permalink
scalar: use ObjectURL for SVG link for durability (#1979)
Browse files Browse the repository at this point in the history
Data uri in the link for download has given us some trouble with
encoding and length limitations. We want to use the ObjectURL like
PR #1610 that is more durable to aforementioned limitations.

Related to #1601.
  • Loading branch information
stephanwlee committed Mar 8, 2019
1 parent 9893f4b commit e46bab9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tensorboard/plugins/scalar/tf_scalar_dashboard/tf-scalar-card.html
Expand Up @@ -80,7 +80,9 @@
title="Fit domain to data"
></paper-icon-button>
<template is="dom-if" if="[[showDownloadLinks]]">
<paper-menu-button on-paper-dropdown-open="_updateDownloadLink">
<paper-menu-button
on-paper-dropdown-open="_updateDownloadLink"
on-paper-dropdown-close="_removeDownloadLink">
<paper-icon-button
class="dropdown-trigger"
slot="dropdown-trigger"
Expand Down Expand Up @@ -314,11 +316,13 @@
},
_updateDownloadLink() {
const svgStr = this.$$('tf-line-chart-data-loader').exportAsSvgString();
// The SVG code string may include hash characters, such as an
// attribute `clipPath="url(#foo)"`. Thus, we base64-encode the
// data so that such a hash is not interpreted as a fragment
// specifier, truncating the SVG. (See issue #1874.)
this.$$('#svgLink').href = `data:image/svg+xml;base64,${btoa(svgStr)}`;
const bytes = new TextEncoder().encode(svgStr);
const blob = new Blob([bytes], {type: 'image/svg+xml'});
this.$$('#svgLink').setAttribute('href', URL.createObjectURL(blob));
},
_removeDownloadLink() {
URL.revokeObjectURL(this.$$('#svgLink').href);
this.$$('#svgLink').removeAttribute('href');
},
_runsFromData(data) {
return data.map((datum) => datum.run);
Expand Down

0 comments on commit e46bab9

Please sign in to comment.