Home

Awesome

<p align="center"> <img height="256px" width="256px" style="text-align: center;" src="https://cdn.jsdelivr.net/gh/mostafazke/ng-whiteboard@development/projects/demo/src/assets/icons/icon-512x512.png"> </p>

<center>ng-whiteboard</center>

<center>Lightweight angular whiteboard</center>

Build Status npm version License: MIT Downloads codecov

Demo

https://mostafazke.github.io/ng-whiteboard

Features

And more to come...

Installation

  1. Install ng-whiteboard via:

    yarn add ng-whiteboard --save
    

    or

    npm install ng-whiteboard --save
    
  2. Add the module to your project

    import { NgWhiteboardModule } from 'ng-whiteboard';
    ...
    
    @NgModule({
        imports: [
            ...
            NgWhiteboardModule
        ]
        ...
    )}
    
  3. Insert the Whiteboard Component element in the html.

    <ng-whiteboard></ng-whiteboard>
    

Options

InputTypeDefaultDescription
[data][WhiteboardElement][]The whiteboard data
[options]WhiteboardOptionsnullcomponent configuration object, properties described below
[drawingEnabled]booleantrueEnable mouse/touch interactions
[selectedTool]ToolsEnumToolsEnum.BRUSHThe current selected tool
[canvasWidth]number800The width of whiteboard canvas
[canvasHeight]number600The height of whiteboard canvas
[fullScreen]booleantrueif true change (canvasWidth, canvasHeight) to fit the parentainer
[strokeColor]string#000000The default stroke color
[backgroundColor]string#FFFFFFThe default background color
[fill]string#333333The default fill color
[strokeWidth]number2The default stroke width
[zoom]number1Zoom level
[fontFamily]stringsans-serifThe default font family
[fontSize]number24The default font size
[center]booleantrueCenter the canvas in parent component, works with fullScreen: false
[x]number0if center is false, set the X axis
[y]number0if center is false, set the Y axis
[enableGrid]booleanfalseEnable the grid pattern
[gridSize]number10Set the grid inner boxes size
[snapToGrid]booleanfalseEnable snaping to grid
[lineJoin]LineJoinEnum .ROUNDLineJoinEnumThe default Line join
[lineCap]LineCapEnum .ROUNDLineCapEnumThe default Line cap
[dasharray]string''The default dash-array
[dashoffset]number0The default dash-offset

Outputs

NameDescriptionArguments
(ready)Emitted when the component is readyNone
(dataChange)Emitted when the data is changedWhiteboardElement[]
(clear)Emitted when the canvas is clearedNone
(undo)Emitted when the user undo an actionNone
(redo)Emitted when the user redo an actionNone
(imageAdded)Emitted when the user add an image to the canvasNone
(save)Emitted when the user save the canvasbase64 image
(selectElement)Emitted when the user select/deselect an elementWhiteboardElement / null
(deleteElement)Emitted when the user delete an elementWhiteboardElement
(toolChanged)Emitted when the user change the toolToolsEnum

Methods

NameDescriptionArgumentsDefaults
saveSave the current board[format]: string, [name]: string[format]: 'base64', [name]: 'New board'
addImageAdd images to the boardimage: (string; ArrayBuffer)None
eraseClean the whiteboardNoneNone
undoUndo last actionNoneNone
redoRedo last actionNoneNone

to use these Methods inject NgWhiteboardService in your project

import { NgWhiteboardService, FormatType } from 'ng-whiteboard';
...

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
   styleUrls: ['./app.component.scss']
   ...
)}

  constructor(private whiteboardService: NgWhiteboardService) {
   this.whiteboardService.save(FormatType.Base64);
  }

Contributing

The project is open for contributors! Please file an issue or make a PR:)