npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-drawing-grid

v1.0.1

Published

A Angular library for drawing and interacting with a grid using the HTML5 canvas.

Downloads

17

Readme

MIT commitizen PRs styled with prettier

Feature

✅ Lightning fast drawing ✅ Hackable

A flexible and straightforward library for drawing and interacting seamless with a grid using the HTML5 canvas. Try it out here: https://davidddo.github.io/ngx-drawing-grid/ or run the demo localy via npm start

Installation

npm install ngx-drawing-grid

Usage

Inject the DrawingGridModule module into your root module:

import { NgModule } from '@angular/core';
import { DrawingGridModule } from 'ngx-drawing-grid';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [DrawingGridModule],
  bootstrap: [AppComponent],
})
export class AppModule {}

You can now access the DrawingGridService in order to modify the pixels of the grid.

import { Component, ElementRef, OnInit } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DrawingGridService, Pixel, PaintingMode } from 'drawing-grid';

@Component({
  selector: 'app-root',
  template: `
    <ng-container *ngIf="width && height">
      <drawing-grid
        [width]="width"
        [height]="height"
        [pixelSize]="pixelSize"
        (mouseDown)="onMouseDown($event)"
        (mouseMove)="onMouseMove($event)"
        (mouseUp)="onMouseUp($event)"
        (contextMenu)="onContextMenu($event)">
      </drawing-grid>
    </ng-container>
  `
})
export class AppComponent implements OnInit {
  private readonly destroy$: Subject<void> = new Subject<void>();

  width: number;
  height: number;
  pixelSize = 28;

  private paintingMode: PaintingMode;

  constructor(
    private host: ElementRef,
    private gridService: DrawingGridService,
  ) {}

  ngOnInit() {
    this.gridService.paintingMode$.pipe(takeUntil(this.destroy$)).subscribe((paintingMode) => {
      this.paintingMode = paintingMode;
    });

    this.width = this.host.nativeElement.clientWidth;
    this.height = this.host.nativeElement.clientHeight;
  }
  
  ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
  }

  onMouseDown(pixel: Pixel) {
    this.fillPixel(pixel.x, pixel.y);
  }

  onMouseMove(pixel: Pixel) {
    this.fillPixel(pixel.x, pixel.y);
  }

  onMouseUp(pixel: Pixel) {}

  onContextMenu(pixel: Pixel) {
    this.gridService.clearPixel(pixel.x, pixel.y);
  }

  private fillPixel(x: number, y: number) {
    if (this.paintingMode === PaintingMode.ERASE) {
      this.gridService.clearPixel(x, y);
      return;
    }

    this.gridService.fillPixel(x, y, 'black');
  }
}

DrawingGridComponent Inputs

  • width - The width of the canvas. The value will also be used for calculating the amount of pixels on the x-axis if the input xNodes is undefined
  • height - The height of the canvas. The value will also be used for calculating the amount of pixels on the y-axis if the input yNodes is undefined
  • xNodes - The amount of pixels on the y-axis
  • yNodes - The amount of pixels on the y-axis
  • pixelSize - The size of a pixel
  • fillStyle - The fillstyle of the grid
  • disabled - Disables or enables the canvas. If it is set to true the events will not get emitted

DrawingGridComponent Output Events

  • mouseDown - Gets emitted when the mouse has been pressed
  • mouseMove - Gets emitted when the mouse has been pressed and is moving
  • mouseUp - Gets emitted when the mouse has been released
  • contextMenu - Gets emitted when the right mouse button has been pressed

Each output event from the DrawingGridComponent will return the current Pixel where the mouse is located on

DrawingGridService API

  • isMouseLocked$ - Observe whether the mouse is currently locked or not. If the value is true either the left or right mouse button is currently pressed by the user
  • paintingMode$ - Observe the current set painting mode
  • pixels$ - Observe the pixels of the drawing grid
  • fillPixel() - Update the fillstyle of a specific pixel
  • clearPixel() - Resets the fillstyle of a specific pixel
  • getPixel() - Returns the pixel at the given x and y coordinates
  • getPixelById()- Returns the pixel which is associated with the given id

Icon made by Flat Icons from www.flaticon.com