diff --git a/benchmarking/src/components/chart.js b/benchmarking/src/components/chart.js index d74f6ac..0b97530 100644 --- a/benchmarking/src/components/chart.js +++ b/benchmarking/src/components/chart.js @@ -2,8 +2,7 @@ import React from 'react' import { Line, Bar } from 'react-chartjs-2' import debounceRender from 'react-debounce-render' import platform from 'platform' - -import { downloadAsJson } from '../../../lib/json-download/index.js' +import { saveAs } from 'file-saver' import { datasetNames } from '../data/index.js' import { datasetTemplates, genOptions, beautifyLabels } from './chartOptions.js' @@ -202,7 +201,7 @@ function saveChart(chartRef) { let config = JSON.stringify(myChart, (key, val) => key === '_meta' ? undefined : val ) - downloadAsJson(config, 'config.json') + saveAs(new Blob([config]), 'config.json', { type: 'text/json;charset=utf8' }) } /** diff --git a/lib/json-download/index.js b/lib/json-download/index.js deleted file mode 100644 index 8ae8668..0000000 --- a/lib/json-download/index.js +++ /dev/null @@ -1,15 +0,0 @@ -/* -Taken from: https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser -*/ - -export function downloadAsJson(exportObj, exportName) { - if (typeof exportObj !== 'string') exportObj = JSON.stringify(exportObj) - var dataStr = - 'data:application/json;charset=utf-8,' + encodeURIComponent(exportObj) - var downloadAnchorNode = document.createElement('a') - downloadAnchorNode.setAttribute('href', dataStr) - downloadAnchorNode.setAttribute('download', exportName) - document.body.appendChild(downloadAnchorNode) // required for firefox - downloadAnchorNode.click() - downloadAnchorNode.remove() -}