-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can't get you component to work #7
Comments
So just an update and clarification. It does show me a canvas with the background image but I can't draw on it. Accourding to your readme I should be able to draw lines on the canvas with the following code:
|
Oke so I did get te storybook version of your component to run. I needed a component that could draw polygons over an image. I will cut the code down to that specific requirement and build other functionality from there. |
@FlyingApe I am using the same code as your snippet above. How were you able to draw lines on the canvas? For me, the code compiles properly but it does not allow me to draw any lines or polygons on the canvas. |
Hi @edisonmoy, I'm not sure if you still need help on this, but I was able to draw the polygons by wrapping the example in the README into the Changing the example like this should do the trick: //components/DrawCanvas.js
import React, { Suspense } from 'react';
import type from 'prop-types';
import { CircularProgress } from '@material-ui/core';
import Canvas from 'react-canvas-polygons';
import Input from './input';
class DrawCanvas extends React.PureComponent {
handleCleanCanva = () => this.canva.cleanCanvas();
render() {
const { imageInfo, initialData } = this.props;
const imageInfoLength = Object.keys(imageInfo).length === 0;
return(
<Suspense fallback={<CircularProgress color="secondary" />}>
<button variant="outlined" style={{ marginBottom: '20px' }}
onClick={this.handleCleanCanva}
>
Clean Canvas
</button>
{imageInfoLength &&
<CircularProgress color="secondary" />
}
<Input render={ state => (
<Canvas
ref={canva => this.canva = canva}
height={240}
width={300}
imgSrc="https://ric-bucket.s3.amazonaws.com/device_5c05ee0cb669e165879e622a/sensorview.jpg"
brushSize={Number(state.brush)}
color={state.color}
tool={state.tool}
onDataUpdate={(data) => console.log('data updates: ', data)}
onFinishDraw={() => console.log('finish draw')}
initialData={initialData}
/>
)} />
</Suspense>
);
}
}
export default DrawCanvas;
DrawCanvas.propTypes = {
tool: type.string,
imageInfo: type.object,
}; |
I've noticed that component starts to work when import React, { useEffect, useState } from "react";
import Canvas from "react-canvas-polygons";
export const DrawCanvas = React.forwardRef(({ imageInfo }: any, ref) => {
const [tool, setTool] = useState("Line");
useEffect(() => {
const timeout = setTimeout(() => setTool("Polygon"), 1000);
return () => clearTimeout(timeout);
}, []);
return (
<Canvas
ref={ref}
imgSrc="https://images.globalindustrial.com/images/enlarge/695511.jpg?t=1628284125430"
height={800}
width={800}
tool={tool}
onCompleteDraw={console.log.bind(console)}
/>
);
}); But surprisingly, the |
As suggested by @kirill-konshin |
Hi @kirill-konshin @love4bugs, I am trying to place the clean button but when I clean it I am getting the following error. Could you please help me wher I am doing mistakes. My current code: export const Draw2 = React.forwardRef(({ imageInfo }, ref) => {
}); Thank you |
@atikaakmal It's too late for you. I wrote an example code for everyone who doesn't understand how this library work. @aeciolevy Your library works very well on my project. In my opinion you should rewrite your document and give more example |
I am so sorry guys, I have sent add a filter to GitHub e-mails in |
He I'm interrested in trying out this component you've build but i'm having trouble getting it to work. I'm setting it up like you're saying in the README file. My editor tells me this statement "import Canvas from 'react-canvas-polygons';" has a problem:
module "d:/14.ReactDev/draw-testing/draw-test1/node_modules/react-canvas-polygons/build/index"
Could not find a declaration file for module 'react-canvas-polygons'. 'd:/14.ReactDev/draw-testing/draw-test1/node_modules/react-canvas-polygons/build/index.js' implicitly has an 'any' type.
Try
npm install @types/react-canvas-polygons
if it exists or add a new declaration (.d.ts) file containingdeclare module 'react-canvas-polygons';
ts(7016)No quick fixes available
I'm unable to fix this.
The text was updated successfully, but these errors were encountered: