Git Product home page Git Product logo

react-picture-annotation's Introduction

React Picture Annotation

GitHub license Travis (.com) npm Greenkeeper badge

A simple annotation component.

rect

Install

# npm
npm install react-picture-annotation

# yarn
yarn add react-picture-annotation

Basic Example

Edit react-picture-annotation-example

const App = () => {
  const [pageSize, setPageSize] = useState({
    width: window.innerWidth,
    height: window.innerHeight
  });
  const onResize = () => {
    setPageSize({ width: window.innerWidth, height: window.innerHeight });
  };

  useEffect(() => {
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, []);

  const onSelect = selectedId => console.log(selectedId);
  const onChange = data => console.log(data);

  return (
    <div className="App">
      <ReactPictureAnnotation
        image="https://source.unsplash.com/random/800x600"
        onSelect={onSelect}
        onChange={onChange}
        width={pageSize.width}
        height={pageSize.height}
      />
    </div>
  );
};

const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);

Props

AnnotationData not required

TYPE

Array<IAnnotation>

see IAnnotation

COMMENT

Control the marked areas on the page.

selectedId not required

TYPE

string | null;

COMMENT

Control the selected shape.

onChange required

TYPE

(annotationData: IAnnotation[]) => void

COMMENT

Called every time the shape changes.

onSelected required

TYPE

(id: string | null) => void

COMMENT

Called each time the selection is changed.

width required

TYPE

number;

COMMENT

Width of the canvas.

height required

TYPE

number;

COMMENT

Height of the canvas.

image required

TYPE

string;

COMMENT

Image to be annotated.

inputElement not required

TYPE

(value: string, onChange: (value: string) => void, onDelete: () => void) =>
  React.ReactElement;

COMMENT

Customizable input control.

EXAMPLE

<ReactPictureAnnotation
  {...props}
  inputElement={inputProps => <MyInput {...inputProps} />}
/>

Types

IAnnotation

{
  id:"to identify this shape",    // required,
  comment:"string type comment",  // not required
  mark:{
    type:"RECT",                  // now only support rect

    // The number of pixels in the upper left corner of the image
    x:0,
    y:0,

    // The size of tag
    width:0,
    height:0
  }
}

Licence

MIT License

react-picture-annotation's People

Contributors

kunduin avatar greenkeeper[bot] avatar komalmadhu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.