Skip to content

Commit

Permalink
Merge pull request #58 from VanFossen/main
Browse files Browse the repository at this point in the history
fixed warning with useEffect
  • Loading branch information
vanfossen authored Jun 27, 2022
2 parents 8fdfb25 + 8f2e41c commit 5ded1dc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/Spectrum.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import "../style/VirtualHendiInterface.css";
import { saveAs } from "file-saver";

function Spectrum({ data }) {
const chartRef = React.createRef();
let d = undefined;
useEffect(() => {
if (data) {
generateSpectrum();
}
});

const generateSpectrum = () => {
return new Dygraph(chartRef.current, data, {
return new Dygraph(document.getElementById("spectrum"), data, {
animatedZooms: true,
xlabel: "Wavelength (cm<sup>-1</sup>)",
ylabel: "Intensity",
Expand All @@ -18,18 +21,14 @@ function Spectrum({ data }) {
});
};

useEffect(() => {
d = generateSpectrum();
}, []);

const downloadSpectrum = () => {
const blob = new Blob([data], { type: "text/plain;charset=utf-8" });
saveAs(blob, "spectrum.csv");
};

return (
<div>
<div id="spectrum" ref={chartRef} />
<div id="spectrum" />
<button onClick={downloadSpectrum}>Download Spectrum</button>
</div>
);
Expand Down

0 comments on commit 5ded1dc

Please sign in to comment.