Skip to content

Commit

Permalink
About Page, CSV Rendering, Graph Plots saving as PNG and SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
zain55337 committed Sep 4, 2023
1 parent 9962d09 commit d596ecb
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 39 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module.exports = {
plugins: ["react", "jest"],
rules: {
"import/no-extraneous-dependencies": ["error", { devDependencies: true }],
"no-param-reassign": 0,
},
};
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"chart.js": "^2.9.4",
"copy-webpack-plugin": "^5.1.2",
"file-loader": "^6.2.0",
"file-saver": "^2.0.5",
"html-to-image": "^1.11.11",
"jquery": "3.5.0",
"mathjs": "^9.5.2",
"mini-css-extract-plugin": "^1.6.2",
Expand Down
3 changes: 2 additions & 1 deletion src/javascript/components/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,8 @@ const About = () => {
<a href="https://github.com/luox-app/luox/">
https://github.com/luox-app/luox/
</a>
) under an MIT License.
) under the GNU General Public License
v3.0.
</p>
</div>
</li>
Expand Down
84 changes: 60 additions & 24 deletions src/javascript/components/CVGPlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import React, { useState } from "react";
import PropTypes from "prop-types";
import Plot from "react-plotly.js";
import Pagination from "react-js-pagination";
import { saveAs } from "file-saver";
import * as htmlToImage from "html-to-image";
import { Button } from "react-bootstrap";
import hueBG from "../../images/hueBG.png";

/**
Expand Down Expand Up @@ -59,6 +62,22 @@ if (windowWidth < 500) {
styleHeight = windowWidth;
}

const downloadChart = (downloadType) => {
if (downloadType === "png") {
htmlToImage
.toBlob(document.getElementById("colorVectorGraphics"))
.then(function (blob) {

Check warning on line 69 in src/javascript/components/CVGPlot.jsx

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
saveAs(blob, "colorVectorGraphics.png");
});
} else if (downloadType === "svg") {
htmlToImage
.toSvg(document.getElementById("colorVectorGraphics"))
.then(function (blob) {

Check warning on line 75 in src/javascript/components/CVGPlot.jsx

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
saveAs(blob, "colorVectorGraphics.svg");
});
}
};

const CVGPlot = ({ measurementLabels, refHAB }) => {
const [activePage, setCurrentPage] = useState(1);
const handlePageChange = (pageNumber) => {
Expand Down Expand Up @@ -268,37 +287,54 @@ const CVGPlot = ({ measurementLabels, refHAB }) => {
}

return (
<section className="cvg">
<section className="cvg col-md-12">
<Pagination
activePage={activePage}
itemsCountPerPage={1}
totalItemsCount={totalItemsCount}
pageRangeDisplayed={10}
onChange={handlePageChange}
/>

<Plot
data={data}
style={{ width: styleWidth, height: styleHeight }}
layout={layout}
config={{
toImageButtonOptions: { width: styleWidth, height: styleHeight },
displayModeBar: true,
showLink: false,
modeBarButtonsToRemove: [
"zoom2d",
"pan",
"pan2d",
"sendDataToCloud",
"hoverClosestCartesian",
"hoverCompareCartesian",
"autoScale2d",
"toggleSpikelines",
"toggleHover",
],
displaylogo: false,
}}
/>
<div id="colorVectorGraphics" className="col-md-8 md-offset-2 col-xs-12">
<Plot
data={data}
style={{ width: styleWidth, height: styleHeight }}
layout={layout}
config={{
toImageButtonOptions: { width: styleWidth, height: styleHeight },
displayModeBar: true,
showLink: false,
modeBarButtonsToRemove: [
"zoom2d",
"pan",
"pan2d",
"sendDataToCloud",
"hoverClosestCartesian",
"hoverCompareCartesian",
"autoScale2d",
"toggleSpikelines",
"toggleHover",
],
displaylogo: false,
}}
/>
</div>
<div className="col-md-12 my-1">
<Button
variant="primary"
onClick={() => downloadChart("png")}
className="btn-sm my-1"
>
Download Chart as PNG
</Button>
<Button
variant="success"
onClick={() => downloadChart("svg")}
className="btn-sm mx-3 my-1"
>
Download Chart as SVG
</Button>
</div>
</section>
);
};
Expand Down
49 changes: 47 additions & 2 deletions src/javascript/components/Chart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, { useEffect, useState, useRef } from "react";
import PropTypes from "prop-types";
import { saveAs } from "file-saver";
import * as htmlToImage from "html-to-image";
import { Button } from "react-bootstrap";
import createChart from "../chart";
import { referenceSpectraNames } from "../referenceSpectra";

Expand All @@ -21,6 +24,22 @@ const Chart = ({
setDisplayedReference(value);
};

const downloadChart = (downloadType) => {
if (downloadType === "png") {
htmlToImage
.toBlob(document.getElementById("canvasChart"))
.then(function (blob) {

Check warning on line 31 in src/javascript/components/Chart.jsx

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
saveAs(blob, "canvasChart.png");
});
} else if (downloadType === "svg") {
htmlToImage
.toSvg(document.getElementById("canvasChart"))
.then(function (blob) {

Check warning on line 37 in src/javascript/components/Chart.jsx

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
saveAs(blob, "canvasChart.svg");
});
}
};

useEffect(() => {
let chart;
if (chartRef.current) {
Expand Down Expand Up @@ -133,10 +152,36 @@ const Chart = ({
</div>
<div className="col-md-8 col-xs-12">
{windowWidth < 500 ? (
<canvas width="800" height="800" ref={chartRef} />
<canvas
width="800"
height="800"
ref={chartRef}
id="canvasChart"
/>
) : (
<canvas width="400" height="200" ref={chartRef} />
<canvas
width="400"
height="200"
ref={chartRef}
id="canvasChart"
/>
)}
<div className="col-md-12">
<Button
variant="primary"
onClick={() => downloadChart("png")}
className="btn-sm my-1"
>
Download Chart as PNG
</Button>
<Button
variant="success"
onClick={() => downloadChart("svg")}
className="btn-sm mx-3 my-1"
>
Download Chart as SVG
</Button>
</div>
</div>
</div>
</div>
Expand Down
26 changes: 15 additions & 11 deletions src/javascript/components/ManageCSV.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const ManageCSV = ({
setSelectedRowsSampleCount,
measurementLabels,
setMeasurementLabels,
modalView,
setModalView,
}) => {
const [error, setError] = useState(false);
const [show, setShow] = useState(true);
let selectedRowsArray = [];
const selectedRowsColumnsArray = [];
const selectedColumnsArray = [];
Expand Down Expand Up @@ -43,7 +44,7 @@ const ManageCSV = ({
setError(false);
setSelectedRows(selectedRowsArray);
setSelectedRowsSampleCount(sampleCount);
setShow(false);
setModalView(false);
} else {
setError(true);
}
Expand All @@ -54,7 +55,7 @@ const ManageCSV = ({
setError(false);
setSelectedRows(selectedRowsArray);
setSelectedRowsSampleCount(sampleCount);
setShow(false);
setModalView(false);
} else {
for (let i = 0; i < selectedRowsArray.length; i += 1) {
const rowArray = [];
Expand All @@ -72,7 +73,7 @@ const ManageCSV = ({
setSelectedRows(selectedRowsColumnsArray);
setSelectedRowsSampleCount(selectedColumnsArray.length);
setMeasurementLabels({ ...selectedColumnsArray });
setShow(false);
setModalView(false);
}
} else {
setError(true);
Expand All @@ -81,14 +82,14 @@ const ManageCSV = ({
const useAllRowsColumns = () => {
setSelectedRows(rows);
setSelectedRowsSampleCount(sampleCount);
setShow(false);
setModalView(false);
};
const useAllRowsSelectedColumns = () => {
if (selectedColumnsArray.length > 0) {
if (measurementLabels.length === selectedColumnsArray.length) {
setSelectedRows(rows);
setSelectedRowsSampleCount(sampleCount);
setShow(false);
setModalView(false);
} else {
selectedRowsArray = [];
for (let i = 0; i < rows.length; i += 1) {
Expand All @@ -106,7 +107,7 @@ const ManageCSV = ({
setSelectedRows(selectedRowsArray);
setSelectedRowsSampleCount(selectedColumnsArray.length);
setMeasurementLabels({ ...selectedColumnsArray });
setShow(false);
setModalView(false);
}
} else {
setError(true);
Expand Down Expand Up @@ -135,7 +136,7 @@ const ManageCSV = ({

return (
<>
<Modal size="lg" show={show}>
<Modal size="lg" show={modalView}>
<Modal.Header>
<Modal.Title>Manage Rows</Modal.Title>
</Modal.Header>
Expand All @@ -152,14 +153,14 @@ const ManageCSV = ({
<Button
variant="success"
onClick={useAllRowsColumns}
className="mx-2"
className="mx-2 my-1"
>
Use all Rows and Columns
</Button>
<Button
variant="primary"
onClick={useAllRowsSelectedColumns}
className="mx-2"
className="mx-2 my-1"
>
Use all Rows and Selected Columns
</Button>
Expand All @@ -170,13 +171,14 @@ const ManageCSV = ({
<Button
variant="success"
onClick={useSelectedRowsAllColumns}
className="mx-2"
className="mx-2 my-1"
>
Use Selected Rows and all Columns
</Button>
<Button
variant="primary"
onClick={useSelectedRowsSelectedColumns}
className="my-1"
>
Use Selected Rows and Selected Columns
</Button>
Expand Down Expand Up @@ -256,5 +258,7 @@ ManageCSV.propTypes = {
setSelectedRowsSampleCount: PropTypes.func.isRequired,
measurementLabels: PropTypes.objectOf(PropTypes.string).isRequired,
setMeasurementLabels: PropTypes.func.isRequired,
modalView: PropTypes.bool.isRequired,
setModalView: PropTypes.func.isRequired,
};
export default ManageCSV;
4 changes: 4 additions & 0 deletions src/javascript/components/Upload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Upload = () => {
const [powerMode, setPowerMode] = useState(false);
const [isLoaded, setLoaded] = useState(false);
const [refHAB, setRefHAB] = useState(null);
const [modalView, setModalView] = useState(false);
const fileInput = useRef();

const userModeChange = () => {
Expand Down Expand Up @@ -98,6 +99,7 @@ const Upload = () => {
setRefHAB={setRefHAB}
isLoaded={isLoaded}
setLoaded={setLoaded}
setModalView={setModalView}
/>

<ManageCSV
Expand All @@ -107,6 +109,8 @@ const Upload = () => {
setSelectedRowsSampleCount={setSelectedRowsSampleCount}
measurementLabels={measurementLabels}
setMeasurementLabels={setMeasurementLabels}
modalView={modalView}
setModalView={setModalView}
/>

<Results
Expand Down
Loading

0 comments on commit d596ecb

Please sign in to comment.