add file saver lib
This commit is contained in:
parent
b4b1aac857
commit
3c636b2edf
@ -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' })
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user