Skip to content

Commit

Permalink
Minor cleanup of code. Removed tabs from export modal since they aren…
Browse files Browse the repository at this point in the history
…'t needed. Removed corresponding test for tab values from ExportModalTest.jsx
  • Loading branch information
Downie committed Nov 6, 2018
1 parent b5276bf commit efaccdd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
19 changes: 13 additions & 6 deletions frontend/src/js/components/modals/ExportModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ class ExportModal extends Component {

constructor(props) {
super(props);

this.minWidth = 512;
this.minHeight = 512;
this.maxWidth = 4096;
this.maxHeight = 4096;

this.state = {
exportWidth: 1024,
exportHeight: 768,
exportType: 'png'
}

this.handleChangeExt = this.handleChangeExt.bind(this);
this.handleDimensionUpdate = this.handleDimensionUpdate.bind(this);
this.handleDimensionChange = this.handleDimensionChange.bind(this);
Expand Down Expand Up @@ -59,11 +66,11 @@ class ExportModal extends Component {
<input
name="widthInput"
type="number"
min="512"
max="4096"
min={this.minWidth}
max={this.maxWidth}
style={{width: "150px", float: "left"}}
value={this.state.exportWidth}
pattern="[0-9]{5}"
pattern="[0-9]"
className="form-control"
placeholder="width"
onChange={(e) => this.handleDimensionChange(e,"exportWidth")}
Expand All @@ -73,11 +80,11 @@ class ExportModal extends Component {
<input
name="heightInput"
type="number"
min="512"
max="4096"
min={this.minHeight}
max={this.maxHeight}
style={{width: "150px", float: "left"}}
value={this.state.exportHeight}
pattern="[0-9]{5}"
pattern="[0-9]"
className="form-control"
placeholder="height"
onChange={(e) => this.handleDimensionChange(e,"exportHeight")}
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/js/components/modals/SavePlot/SavePlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SavePlot extends Component{
// Update default dimensions to match current window size
this.props.handleDimensionUpdate([this.canvasDiv.width,this.canvasDiv.height]);

this.canvasDiv.toBlob((blob)=>{
this.canvasDiv.toBlob((blob) => {
this.setState({img_url: URL.createObjectURL(blob)})
});
}
Expand All @@ -45,11 +45,13 @@ class SavePlot extends Component{
toast.warn("Enter a filename.", {position: toast.POSITION.BOTTOM_CENTER});
return;
}

var ext = fileName.substr(fileName.lastIndexOf('.') + 1);

if(ext===fileName){
ext = "";// No extension was entered
}

switch(ext){
case "":
ext = this.props.exportType;
Expand Down Expand Up @@ -94,9 +96,7 @@ class SavePlot extends Component{
let canvas = vcs.init(this.canvasDiv);

canvas.plot(variable, graphicMethod, plotInfo.template).then((info) => {
console.log(this.props.exportDimensions);
canvas.screenshot(ext, true, false, fileName, this.props.exportDimensions[0], this.props.exportDimensions[1]).then((result, msg) => {
console.log(this.props.exportDimensions);
console.log(msg);
if(result.success){
const { blob, type } = result;
Expand All @@ -107,7 +107,6 @@ class SavePlot extends Component{
} else {
console.log(result.msg);
}

}).catch((err) => {
console.log(err);
toast.error("Error occurred when saving plot.", {position: toast.POSITION.BOTTOM_CENTER});
Expand Down
10 changes: 1 addition & 9 deletions frontend/test/mocha/components/Modals/ExportModalTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,4 @@ describe("ExportModalTest.jsx", function() {
var export_modal = shallow(<ExportModal {...props} />);
expect(export_modal).to.have.lengthOf(1);
});

it("Switch tab sets correct state", () => {
const props = getProps();
var export_modal = shallow(<ExportModal {...props} />);
expect(export_modal.state().selected_tab).to.equal(0);
export_modal.instance().switchTab(1);
expect(export_modal.state().selected_tab).to.equal(1);
});
});
});

0 comments on commit efaccdd

Please sign in to comment.