0.13.0-rc • Published 2 years ago

ngx-drawing-board v0.13.0-rc

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Ngx-drawing-board

GitHub license npm version

Angular library to draw, resize and drag shapes with a mouse on canvas

Contents

Getting started

Step 1: Install ngx-drawing-board:

npm install ngx-drawing-board --save

Step 2: Import NgxDrawingBoardModule:

import { NgxDrawingBoardModule } from 'ngx-drawing-board';

@NgModule({
  ...
  imports: [..., NgxDrawingBoardModule],
  ...
})
export class SomeModule {}

Usage

  <ngx-drawing-board
    [data]="[]"
    [shape]="'ellipse'"
    [width]="1024"
    [height]="724"
  >
  </ngx-drawing-board>

API

Inputs

InputTypeDefaultRequiredDescription
dataIElement[]noList where all drawn elements are stored
widthnumber600noWidth of canvas
heightnumber600noHeight of canvas
shapeShape"rectangle"noCurrent drawing shape
backgroundImagestring""noCanvas background image
backgroundColorstring"#ffffff"noCanvas background color
initialElementColorstring"transparent"noDrawing element initial color
gridConfigIGridConfig{ enabled: true }noSettings for canvas background grid
fitCanvasToImagebooleantruenoMakes canvas the same size as provided background image
gridSizeMouseStepbooleanfalsenoEquals mouse step while drawing to grid size

Outputs

OutputArgumentsDescription
(onAddElement)IOutputEventFires when new element has been drawn on canvas
(onClickElement)IOutputClickEventFires when element has been clicked
(onFocusElement)IOutputEventFires when element gets focus
(onBlurElement)IOutputEventFires when selected element looses focus
(onMouseEnterElement)IOutputEventFires when mouse enteres element
(onMouseLeaveElement)IOutputEventFires when mouse leaves element
(onResizeStart)IOutputEventFires when element's resizing has started
(onResizing)IOutputEventFires when element is being resized
(onResizeEnd)IOutputEventFires when element's resizing is over
(onDragStart)IOutputEventFires when element's dragging has started
(onDragging)IOutputEventFires when element is being draged
(onDragEnd)IOutputEventFires when element's dragging is over

Types

  interface IElement {
    x: number,
    y: number,
    width: number,
    height: number,
    shape: Shape,
    color: string,
    text?: IElementText,
    border?: IElementBorder,
    imageSrc?: CanvasImageSource,
  }
  
  interface IElementText {
    value: string,
    color?: string,
    fontWeight?: 100 | 200 | 300 | 400 | 500 | 600,
    fontFamily?: string,
    fontStyle?: string,
    fontSize?: string,
    align?: 'left' | 'center' | 'right',
  }

  interface IElementBorder {
    color?: string,
    width?: number,
  }

  interface IGridConfig {
    enabled?: boolean,
    cellSize?: number,
    strokeWidth?: number,
    strokeColor?: string,
  }

  interface IOutputEvent {
    index: number,
    element: IElement
  }

  interface IOutputClickEvent {
    index: number,
    element: IElement
    clickCoords: IPoint
  }

  type Shape = 'rectangle' | 'ellipse' | 'triangle' | 'image';

License

The MIT License (see the LICENSE file for the full text)

0.13.0-rc

2 years ago

0.12.0-rc

2 years ago

0.11.0-rc

2 years ago

0.10.1-rc

2 years ago

0.10.0-rc

2 years ago

0.9.0-rc

2 years ago

0.8.0-rc

2 years ago

0.7.0-rc

2 years ago

0.6.0-rc

2 years ago

0.5.0-rc

2 years ago

0.4.0-rc

2 years ago

0.3.0-rc

2 years ago

0.2.0-rc

2 years ago