Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Share chart button#7802
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
Uh oh!
There was an error while loading. Please reload this page.
Share chart button #7802
Changes from all commits
42c96018ce5512ad9ddfc100da7b82f5437fddd50eba91b11717fc268774b9c13b8f12a44f6ef836d24c1f47ebd83deac2852dc1f4a71e43ff34976e5933bdc1b7122c28c434da868bebf8971aada548c0ee9501299d9a55a7a7afFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| 'use strict'; | ||
| var d3 = require('@plotly/d3'); | ||
| var _ = require('../../lib')._; | ||
| /** | ||
| * Show a styled confirmation dialog before sharing a chart with Plotly Cloud. | ||
| * | ||
| * The dialog is appended to the plot's positioning container (.svg-container) | ||
| * so it is centered over the plot rather than the whole viewport. It can be | ||
| * dismissed by clicking Cancel, clicking the backdrop, or pressing Escape. | ||
| * | ||
| * @param {DOM node} gd - the graph div, used to scope the dialog to the plot | ||
| * @param {string} serverUrl - destination shown in the dialog message | ||
| * @param {function} onConfirm - called when the user confirms the upload | ||
| */ | ||
| module.exports = function confirmCloudDialog(gd, serverUrl, onConfirm) { | ||
| var container = d3.select(gd._fullLayout._paperdiv.node()); | ||
| // Never stack dialogs - drop any that is already open. | ||
| container.selectAll('.plotly-cloud-dialog').remove(); | ||
| var overlay = container | ||
| .append('div') | ||
| .classed('plotly-cloud-dialog', true); | ||
| var dialog = overlay.append('div') | ||
| .classed('plotly-cloud-dialog-box', true); | ||
| dialog.append('div') | ||
| .classed('plotly-cloud-dialog-title', true) | ||
| .text(_(gd, 'Share with Plotly Cloud')); | ||
| dialog.append('div') | ||
| .classed('plotly-cloud-dialog-message', true) | ||
| .text(_(gd, 'This chart and its data will be sent to') + ' ' + serverUrl + '.'); | ||
| var buttons = dialog.append('div') | ||
| .classed('plotly-cloud-dialog-buttons', true); | ||
| function close() { | ||
| overlay.remove(); | ||
| document.removeEventListener('keydown', onKeydown); | ||
| } | ||
| function onKeydown(e) { | ||
| if(e.key === 'Escape' || e.keyCode === 27) close(); | ||
| } | ||
| document.addEventListener('keydown', onKeydown); | ||
| // Clicking the backdrop (but not the dialog box) cancels. | ||
| overlay.on('click', function() { | ||
| if(d3.event.target === overlay.node()) close(); | ||
| }); | ||
| buttons.append('button') | ||
| .classed('plotly-cloud-dialog-btn', true) | ||
| .classed('plotly-cloud-dialog-btn--cancel', true) | ||
| .text(_(gd, 'Cancel')) | ||
| .on('click', close); | ||
| buttons.append('button') | ||
| .classed('plotly-cloud-dialog-btn', true) | ||
| .classed('plotly-cloud-dialog-btn--confirm', true) | ||
| .text(_(gd, 'Share')) | ||
| .on('click', function() { | ||
| close(); | ||
| onConfirm(); | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| .plotly-cloud-dialog { | ||
| font-family: 'Open Sans', verdana, arial, sans-serif; // Because not all contexts have this specified. | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| z-index: 1001; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| background-color: rgba(0, 0, 0, 0.4); | ||
| .plotly-cloud-dialog-box { | ||
| box-sizing: border-box; | ||
| min-width: 300px; | ||
| max-width: 420px; | ||
| padding: 20px 24px; | ||
| background-color: $color-bg-light; | ||
| border: 1px solid $color-bg-darker; | ||
| border-radius: 4px; | ||
| box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); | ||
| font-size: 13px; | ||
| color: #2a3f5f; | ||
| } | ||
| .plotly-cloud-dialog-title { | ||
| font-size: 16px; | ||
| font-weight: bold; | ||
| margin-bottom: 12px; | ||
| } | ||
| .plotly-cloud-dialog-message { | ||
| line-height: 1.5; | ||
| overflow-wrap: break-word; | ||
| word-wrap: break-word; | ||
| } | ||
| .plotly-cloud-dialog-buttons { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| margin-top: 20px; | ||
| } | ||
| .plotly-cloud-dialog-btn { | ||
| font-family: inherit; | ||
| font-size: 13px; | ||
| padding: 7px 16px; | ||
| margin-left: 8px; | ||
| border-radius: 3px; | ||
| border: 1px solid transparent; | ||
| cursor: pointer; | ||
| &:focus-visible { | ||
| outline: 2px solid $color-brand-primary; | ||
| outline-offset: 1px; | ||
| } | ||
| } | ||
| .plotly-cloud-dialog-btn--cancel { | ||
| background-color: $color-bg-light; | ||
| border-color: $color-bg-darker; | ||
| color: $color-muted-text; | ||
| &:hover { | ||
| background-color: $color-bg-base; | ||
| } | ||
| } | ||
| .plotly-cloud-dialog-btn--confirm { | ||
| background-color: $color-brand-primary; | ||
| color: $color-bg-light; | ||
| &:hover { | ||
| background-color: $color-brand-accent; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,6 +6,7 @@ var formatLocale = require('d3-format').formatLocale; | ||
| var isNumeric = require('fast-isnumeric'); | ||
| var b64encode = require('base64-arraybuffer'); | ||
| var version = require('../version').version; | ||
| var Registry = require('../registry'); | ||
| var PlotSchema = require('../plot_api/plot_schema'); | ||
| var Template = require('../plot_api/plot_template'); | ||
| @@ -36,6 +37,7 @@ plots.fontAttrs = require('./font_attributes'); | ||
| plots.layoutAttributes = require('./layout_attributes'); | ||
| var commandModule = require('./command'); | ||
| const { server } = require('karma'); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import of a dev-dependency is not used in the source code. | ||
| plots.executeAPICommand = commandModule.executeAPICommand; | ||
| plots.computeAPICommandBindings = commandModule.computeAPICommandBindings; | ||
| plots.manageCommandObserver = commandModule.manageCommandObserver; | ||
| @@ -200,37 +202,40 @@ function positionPlayWithData(gd, container) { | ||
| } | ||
| } | ||
| plots.sendDataToCloud = function(gd) { | ||
| var baseUrl = (window.PLOTLYENV || {}).BASE_URL || gd._context.plotlyServerURL; | ||
| if(!baseUrl) return; | ||
| plots.sendDataToCloud = function(gd, serverURL) { | ||
| gd.emit('plotly_beforeexport'); | ||
| var hiddenformDiv = d3.select(gd) | ||
| .append('div') | ||
| .attr('id', 'hiddenform') | ||
| .style('display', 'none'); | ||
| // Build the request body: the chart JSON plus the plotly.js version used to | ||
| // generate it, so Cloud can host the chart with a compatible plotly.js version. | ||
| var chart = plots.graphJson(gd, false, 'keepdata', 'object'); | ||
marthacryan marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| chart.version = version; | ||
| // Open the Cloud login page in a new tab. We keep a reference so we can post | ||
| // the chart back to it once Cloud reports that authentication succeeded. | ||
| var cloudWindow = window.open(serverURL, '_blank'); | ||
| if(!cloudWindow) { | ||
| console.error('Unable to open Plotly Cloud (the popup may have been blocked)'); | ||
| gd.emit('plotly_exportfail'); | ||
| return; | ||
| } | ||
| var hiddenform = hiddenformDiv | ||
| .append('form') | ||
| .attr({ | ||
| action: baseUrl + '/external', | ||
| method: 'post', | ||
| target: '_blank' | ||
| }); | ||
| var handleMessage = function(event) { | ||
| // Only trust messages coming from the Cloud origin. | ||
| if(event.origin !== serverURL) return; | ||
| var hiddenformInput = hiddenform | ||
| .append('input') | ||
| .attr({ | ||
| type: 'text', | ||
| name: 'data' | ||
| }); | ||
| if(event.data && event.data.type === 'CHART_AUTH_SUCCESS') { | ||
| cloudWindow.postMessage({ | ||
| type: 'chart', | ||
| chart: chart | ||
| }, serverURL); | ||
| window.removeEventListener('message', handleMessage); | ||
| gd.emit('plotly_afterexport'); | ||
| } | ||
| }; | ||
| hiddenformInput.node().value = plots.graphJson(gd, false, 'keepdata'); | ||
| hiddenform.node().submit(); | ||
| hiddenformDiv.remove(); | ||
| window.addEventListener('message', handleMessage); | ||
| gd.emit('plotly_afterexport'); | ||
| return false; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.