Skip to content

Commit

Permalink
inlcude plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyanthropos committed Apr 4, 2023
1 parent bcebb93 commit a95e754
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"lorem-ipsum": "^2.0.4",
"math-expressions": "^2.0.0-alpha59",
"nanoid": "^3.1.31",
"plotly.js-dist-min": "^2.20.0",
"react": "^18.2.0",
"react-copy-to-clipboard": "^5.0.3",
"react-datetime": "^3.2.0",
Expand Down
86 changes: 43 additions & 43 deletions src/Viewer/renderers/chart.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState, useRef, createContext } from 'react';
import { sizeToCSS } from './utils/css';
import useDoenetRender from '../useDoenetRenderer';
// import Plotly from 'plotly.js-dist-min';
import Plotly from 'plotly.js-dist-min';
import VisibilitySensor from 'react-visibility-sensor-v2';


Expand All @@ -28,50 +28,50 @@ export default React.memo(function Chart(props) {
}, [])

//Draw chart after mounting component
// useEffect(() => {

// if (SVs.dataFrame !== null) {

// let colInds;
// if (SVs.colInd !== null) {
// colInds = [SVs.colInd]
// } else {
// colInds = SVs.dataFrame.columnTypes
// .map((v, i) => v === "number" ? i : null)
// .filter(x => x !== null);
// }


// let data = [];

// for (let colInd of colInds) {
// if (SVs.type === "box") {
// data.push({
// y: extractColumn(SVs.dataFrame.data, colInd),
// type: "box",
// name: SVs.dataFrame.columnNames[colInd]
// })
// } else {
// data.push({
// x: extractColumn(SVs.dataFrame.data, colInd),
// type: "histogram",
// name: SVs.dataFrame.columnNames[colInd]
// })
// }
// }

// Plotly.newPlot(name, {
// data
// });
// }

// }, []);


return <>
useEffect(() => {

if (SVs.dataFrame !== null) {

let colInds;
if (SVs.colInd !== null) {
colInds = [SVs.colInd]
} else {
colInds = SVs.dataFrame.columnTypes
.map((v, i) => v === "number" ? i : null)
.filter(x => x !== null);
}


let data = [];

for (let colInd of colInds) {
if (SVs.type === "box") {
data.push({
y: extractColumn(SVs.dataFrame.data, colInd),
type: "box",
name: SVs.dataFrame.columnNames[colInd]
})
} else {
data.push({
x: extractColumn(SVs.dataFrame.data, colInd),
type: "histogram",
name: SVs.dataFrame.columnNames[colInd]
})
}
}

Plotly.newPlot(name, {
data
});
}

}, []);


return (<>
<a name={id} />
<VisibilitySensor partialVisibility={true} onChange={onChangeVisibility}><div id={id} /></VisibilitySensor>
</>;
</>);

})

Expand Down

0 comments on commit a95e754

Please sign in to comment.