MenesesGHZ/polynomial-regression-js

add points directly by clicking on the graph

Opened this issue · 2 comments

Currently, we click on points on the grid and then they get added to the graph. Is there any way we can modify this such that we can add points by directly clicking on the graph itself?

Yes, it can be done by just adding to the Graph.js component the same logic as the Drawer.js component.

Drawer.js logic:

onMouseMove(e){
this.setState({ x: parseFloat((e.nativeEvent.offsetX/this.width).toFixed(3)),
y: parseFloat(((this.height-e.nativeEvent.offsetY)/this.height).toFixed(3))},
()=>{if(this.state.hoverMode) this.addCoord()}
);
}

addCoord(){
const coord = {x:this.state.x,
y:this.state.y};
this.props.addCoord(coord);
}