Skip to content

Commit 3c2c0bf

Browse files
committed
Saving chart as PNG: filename is chart title or chart id
1 parent 33eb49c commit 3c2c0bf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/firefly/js/charts/ui/PlotlyWrapper.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
*/
44

55
import React, {Component, PropTypes} from 'react';
6+
import {get} from 'lodash';
67
import {getPlotLy} from '../PlotlyConfig.js';
78
import {logError} from '../../util/WebUtil.js';
89
import Enum from 'enum';
910

1011
const PLOTLY_BASE_ID= 'plotly-plot';
1112
var counter= 0;
12-
var downloadCounter = 0;
13-
14-
1513

1614
export const RenderType= new Enum([ 'RESIZE', 'UPDATE', 'RESTYLE', 'RELAYOUT', 'RESTYLE_AND_RELAYOUT', 'NEW_PLOT'],
1715
{ ignoreCase: true });
1816

1917

20-
2118
const defaultConfig= {
2219
displaylogo: false,
2320
modeBarButtonsToRemove :[
@@ -31,10 +28,10 @@ export function downloadChart(chartId) {
3128
getPlotLy().then( (Plotly) => {
3229
const chartDiv = document.getElementById(chartId);
3330
if (chartId && chartDiv) {
34-
downloadCounter++;
31+
const filename = get(chartDiv, 'layout.title') || chartId;
3532
Plotly.downloadImage(chartDiv, {
3633
format: 'png',
37-
filename: `plotly-${chartId.replace(/\-.*$/, downloadCounter)}`
34+
filename
3835
});
3936
} else {
4037
logError(`Image download has failed for chart id ${chartId}`);

0 commit comments

Comments
 (0)