0.2.8 • Published 3 months ago

ng-gd v0.2.8

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

NgGd

The easy way to manage the canvas. Support object and clicks events to the objects This library was generated with Angular CLI Angular 17

Build

Run ng build ng-gd to build the lib. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library with ng build ng-gd, go to the dist folder cd dist/ng-gd and run npm publish.

Versions

Library versionAngular
2.0.817
2.0.015, 15.2

*Feature shadow in objects.

Usage

install the lib

npm i ng-gd

declare in a module program

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";

import { AppComponent } from "./app.component";
import { NgGdService } from "ng-gd";

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

create a canvas in html

<canvas #canvas width="640" height="480"></canvas>

declare vars in your component class and call the lib;

import {
  NgGdService,
  Point,
  NodeObject,
} from 'ng-gd';

export class App implements OnInit {
gd = inject(NgGdService);
private ctx!: CanvasRenderingContext2D;
@ViewChild('canvas', { static: true }) canvas!: ElementRef<HTMLCanvasElement>;
}

ngOnInit(): void {
    this.ctx = this.canvas.nativeElement.getContext('2d')!;
    this.gd.start(640,480);
    this.gd.setDarkMode();
    this.gd.addNode({ x: 150, y: 150 }, "one", "this is the node one", false, 10, 10);
    this.gd.clear(this.ctx);
    this.gd.draw(this.ctx);
}

If you have problems with go another page and return use after view init for refresh.

Demo objects in stackblitz

Demo charts in stackblitz

Demo chart with map function in stackblitz

Demo ZOrder in GitHub

Demo ZOrder in stackblitz

List gd service commands

start(width: number, height: number) Start gd lib required for start.

getLabels(): Get all labels.

findLabelByText(text: string):LabelObject Get a label for your text.

findByName(text: string): ArcObject | CandlestickObject | CircleObject | ConnectionObject | LabelObject | LineChartObject | ShapeObject Find a object by name assign the name of the object first.

getConnections() Get all connections.

getNodes() Get all nodes.

castingMultiplesSides(id: number) Get a multiples sides object with id number.

castingLine(id:number) Get a line Object.

castingRectangle(id: number) Get a rectangle object.

castingCircle(id: number) Get a circle object.

castingNode(id:number) Get a node object.

castingLabel(id: number) Get a label object.

castingConnection(id: number) Get connection object.

casting(id) Get a any object with casting.

getMousePoint(ctx: CanvasRenderingContext2D, x: number, y: number) Return a position the mouse.

setDarkMode() Change the background color to black and ink white.

setLightMode() Change the background color to white and ink black.

canvasSetSize(width: number, height: number) Change canvas size for the library not the canvas.

resetMouse() Reset last position.

clear(ctx: CanvasRenderingContext2D) Clear the canvas.

clearObjects() Delete all objects in the library.

addCandleChart(point: Point, candleStick: Candlestick[], width: number, height: number, bullColor: string | CanvasGradient | CanvasPattern, bearColor: string | CanvasGradient | CanvasPattern, distance: number) Create a candle chart.

addPieChart(ctx: CanvasRenderingContext2D, point: Point, size: number, values: number[], color: (string | CanvasGradient | CanvasPattern)[], distance: number, start?: number, labels?: string[]) Create a pie chart.

addGraphBars(ctx: CanvasRenderingContext2D, point: Point, width: number, values: number[], color: (string | CanvasGradient | CanvasPattern)[], distance: number) Create graph bars.

addLineChart(point: Point, values: number[], dist: number, color : string| CanvasGradient | CanvasPattern,marks?:boolean): LineChartObject Create a line for chart.

addAxisY(ctx: CanvasRenderingContext2D, point: Point, dist: number, steps: number, labels: string[], fontSize: number, angleGrades?: number, distance?: number,adjustLabel?:Point[]) Create a y axis.

addAxisX(ctx: CanvasRenderingContext2D, point: Point, dist: number, steps: number, labels: string[], fontSize: number, angleGrades?: number, distance?: number,adjustLabel?:Point[]) Create a x axis.

addCandleStick(point: Point, candleStick: Candlestick, width: number, height: number, bullColor: string | CanvasGradient | CanvasPattern, bearColor: string | CanvasGradient | CanvasPattern): Candle_stick Create a candle stick.

addMultiplesSides(point: Point, sides: number, radius: number, color?: string| CanvasGradient | CanvasPattern, borderColor?: string | CanvasGradient | CanvasPattern) Create a figure with 5 sides minimum.

addTriangle(first: Point, second: Point, third: Point, color?: string, borderColor?: string,shadow?:boolean) Create a triangle.

addCircle(point: Point, radius: number, color?: string, borderColor?: string,shadow?:boolean) Create a circle.

addRectangle(point: Point, width: number, height: number, angle:number,color?: string, borderColor?: string,shadow?:boolean) Create a rectangle.

addNode(point: Point, name: string, description?: string, net?: boolean, angleLabel?: number, distanceLabel?: number,shadow?:boolean) Add node.

addConnection(point: Point, toPoint: Point, color?: string| CanvasGradient | CanvasPattern, label?: string,shadow?:boolean) Create a connection.

addLine(point: Point, toPoint: Point, steps?: number, color?:(string| CanvasGradient | CanvasPattern)) Create a line steps mark the line like rule.

addLabel(point: Point, text: string, fontSize: number, angle: number,shadow?:boolean) Create a label.

addArc(x: number, y: number, size: number, beginGrades: number, endGrades: number, color?: string| CanvasGradient | CanvasPattern, borderColor?: string| CanvasGradient | CanvasPattern,shadow?:boolean): ArcObject Create a arc object

click(ctx: CanvasRenderingContext2D, event: MouseEvent):{ shape: ShapeObject, action: string } Return a array all objects are clicked with mouse order for ZOrder. Possible events off object.

inPoint Object are clicked.

Line and connection private events

inPointXY Object clicked in first point.

inPointToXY Object clicked in second point.

inRectangle Object clicked in the line.

getClicks() Return a list created for click function speed reasons.

draw(ctx: CanvasRenderingContext2D) Draw all objects.

zoomInPoint(ctx: CanvasRenderingContext2D, x: number, y: number, zoom: number) Zoom in x,y position.

getItem(id:number) Return a object with casting to ShapeObject.

Object properties all object are derived the class ShapeObject.

x:position x. y:position y.

color Object color gd support string,patterns or gradients;

visible Toggle object to visible you turn false the object not draw.

type Variable with string class of the object the easy way to obtain the type class the one object.

possibles values are

label

node

connection

rectangle

circle

triangle

multiplesSides

line

arc

lineChart

candleStick

Objects common functions

drawShape(ctx: CanvasRenderingContext2D) Draw the object in the canvas.

inverseShape(ctx: CanvasRenderingContext2D) Draw the object with background color.

inPoint(x: number, y: number) Return true if the object is in position x,y.

move(x:number,y:number) Move the object to new position.

moveMouse(ctx: CanvasRenderingContext2D, event: MouseEvent) Move the object to mouse position.

Additional functions for LineObject and ConnectionObject

inPointXY(x: number, y: number): boolean If the mouse is over the first point the line or connection.

inPointToXY(x: number, y: number): boolean If the mouse is over the second point the line or connection.

inRectangle(x: number, y: number): boolean If the mouse is over the line.

moveMouseXY(ctx: CanvasRenderingContext2D, event: MouseEvent) Mouse move the first point to new position.

moveMouseToXY(ctx: CanvasRenderingContext2D, event: MouseEvent) Mouse move the second point to new position.

Objects level

toFront() Move the object to fist plane over all objects.

toTop() Move the object to first plane.

toBack() Move the object to last plane.

nextZOrder() Move the object one plane to front.

backZOrder() Move the object one plane to back.

Service renumber is for not let plane withouts objects. for sample .

this.gd.renumberZOrder()

Auxiliary functions.

map(number: number, startInput: number, stopInput: number, startOutput: number, stopOutput: number): number This function is for change range of values for example if you need translate 33 in percentage to grades use this.gd.map(33,0,100,0,360)

move(point: Point, angle: number, distance: number): Point Move point angle and distance.

toRadians(grades: number): number Return degrees in radians.

toDegrees(radian: number): number Return radians in degrees.

distance(from:Point,to:Point):number Distance between two points.

angle(from:Point,to:Point):number Angle from point to point.

For help send email to:luisalejandrofigueredo@gmail.com or:Likedin

0.2.8

3 months ago

0.1.1-rc.1

12 months ago

0.1.1-rc.2

12 months ago

0.1.1-rc.4

12 months ago

0.1.1-rc.6

12 months ago

0.1.1-rc.8

12 months ago

0.1.1-rc.18

12 months ago

0.1.1-rc.14

12 months ago

0.1.1-rc.16

12 months ago

0.1.1-rc.10

12 months ago

0.1.1-rc.12

12 months ago

0.2.0

12 months ago

0.2.6

11 months ago

0.2.2

12 months ago

0.2.4

11 months ago

0.1.1-rc.0

12 months ago

0.0.50

12 months ago

0.0.48

12 months ago

0.0.46

12 months ago

0.0.44

12 months ago

0.0.42

1 year ago

0.0.40

1 year ago

0.0.38

1 year ago

0.0.36

1 year ago

0.0.34

1 year ago

0.0.32

1 year ago

0.0.30

1 year ago

0.0.28

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.19

1 year ago

0.0.17

1 year ago

0.0.15

1 year ago

0.0.13

1 year ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.7

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.1

1 year ago

0.0.0-watch

1 year ago