Skip to content

Commit 22e8864

Browse files
authored
added doanload chart butt for v8 and v9 charts (#623)
1 parent bd07179 commit 22e8864

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

apps/plotly_examples/src/components/DeclarativeChart.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ const DeclarativeChartBasicExample: React.FC<IDeclarativeChartProps> = ({ width,
169169
setSelectedLegendsState(newValue ?? '');
170170
};
171171

172-
function fileSaver(url: string) {
172+
function fileSaver(url: string, name: string) {
173173
const saveLink = document.createElement('a');
174174
saveLink.href = url;
175-
saveLink.download = 'converted-image.png';
175+
saveLink.download = name;
176176
document.body.appendChild(saveLink);
177177
saveLink.click();
178178
document.body.removeChild(saveLink);
@@ -293,6 +293,19 @@ const DeclarativeChartBasicExample: React.FC<IDeclarativeChartProps> = ({ width,
293293
const renderV8Chart = (chartType: OutputChartType, inputSchema: Schema, chartTitle: string) => (
294294
<>
295295
<Subtitle1 align="center" style={{ marginLeft: '30%' }}>Declarative chart from fluent v8</Subtitle1>
296+
<br/>
297+
<button
298+
onClick={() => {
299+
const start = performance.now();
300+
declarativeChartRef.current?.exportAsImage().then((imgData: string) => {
301+
const end = performance.now();
302+
console.log(`V8 exportAsImage took ${(end - start).toFixed(2)} ms`);
303+
fileSaver(imgData, 'v8-chart-image.png');
304+
});
305+
}}
306+
>
307+
Download V8 Chart as Image
308+
</button>
296309
<div data-testid="chart-container">
297310
<br />
298311
<br />
@@ -329,6 +342,19 @@ const DeclarativeChartBasicExample: React.FC<IDeclarativeChartProps> = ({ width,
329342
const renderV9Chart = (chartType: OutputChartType, inputSchema: Schema, chartTitle: string) => (
330343
<>
331344
<Subtitle2>Charts v9</Subtitle2>
345+
<br/>
346+
<button
347+
onClick={() => {
348+
const start = performance.now();
349+
declarativeChartV9Ref.current?.exportAsImage().then((imgData: string) => {
350+
const end = performance.now();
351+
console.log(`V9 exportAsImage took ${(end - start).toFixed(2)} ms`);
352+
fileSaver(imgData, 'v9-chart-image.png');
353+
});
354+
}}
355+
>
356+
Download V9 Chart as Image
357+
</button>
332358
<div data-testid="chart-container-v9">
333359
<br />
334360
<br />
@@ -499,19 +525,6 @@ const DeclarativeChartBasicExample: React.FC<IDeclarativeChartProps> = ({ width,
499525
)}
500526
</div>
501527
<br />
502-
<button
503-
onClick={() => {
504-
const start = performance.now();
505-
declarativeChartRef.current?.exportAsImage().then((imgData: string) => {
506-
const end = performance.now();
507-
console.log(`exportAsImage took ${(end - start).toFixed(2)} ms`);
508-
fileSaver(imgData);
509-
});
510-
}}
511-
>
512-
Download as Image
513-
</button>
514-
<br />
515528

516529
{/* Render charts in the specified order */}
517530
{getChartsInOrder(chartType, inputSchema, chartTitle, plotlySchemaCopy, plotlyKey).map((chart, index) => (

0 commit comments

Comments
 (0)