Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.
Pouya Kary edited this page Jun 22, 2016 · 17 revisions

min-header

Welcome

Graph gives you a real-time interactive notebook as well as a plugin system, so that you can program and automate graphs, create special renderings, use graph for scientifical analysis or even use it for hobby and to explore the world of graphs. As Graph runs on JavaScript, you have all the power of JavaScript to write your plugins or writing commands in the notebook.

Note

The core of the Graph works very differently that how it behaves. The API introduced in this article is based on an abstraction layer that normalizes the underlying core to be a natural high level abstraction. All the core tools of the Graph are available under the KaryGraph namespace. Using the functionality provided by the core system commands is dangerous and may cause damage however because of the implementation design they are unavoidable. Unless you're contributing to the core we ask you not to use anything within that namespace. API that is provided to you is simple, very dynamic, and safe in error handling and very optimized. By not using the API you will end up having a same functioning API but with different design and functions and it will create compatibility problems across the community. So we dearly ask you not to use any of the KaryGraph namespace tools in your plugins and notebooks.

API

Environment

Graph

Reset

Removes all the dots and resets the whole environment

reset( ): void

Notebook

Clear Screen

Cleans the notebook screen

cls( ): void

Say

Prints what ever you want on the notebook screen

say( input: any ): void

Core API

Dot

New Dot

This function creates a dot and places it at a random coordinate.

newdot( ): Dot

// generates a dot at some random coordinates
var dot = newdot( )

New Dots

This function generates a specified number of dots by iterating over the newdot( ) function.

newdots( howManyDots: number ): Array<Dots>

// create an array of 5 new dots just added to the screen
let dots = newdots( 5 )

New Dot At

Creates a dot at the coordinates (x, y)

newdotat( x: number, y: number ): Dot

// you can create a dot like....
var dot = newdotat( 50, 100 )

Get Dot

This function gets a dot based on it's number id.

getdot( id: number ): Dot

// gets the dot object for dot with id 5
let dot = getdot( 5 )

Get Dots

Gets an array of dots based on the array of ids

getdots( ...ids: Array<number> ): Array<Dot>

var a: Array<Dot> = getdots( 2, 5, 7 )

Connections

Connect

Connects an array of dots in order

connect( ...dotOrId: Array<Dot|number> )

// this connects 1 to 2 and 2 to 3
let dot3 = getdot( 3 )
connect( 1, 2, dot3 )
screen shot 2016-06-22 at 6 53 27 pm

Disconnect

Disconnects two dots from each other.

disconnect( dot1: number | Dot, dot2: number | Dot ): boolean

// you can use both dot id or dot object to disconnect each dot from
// each other assuming 1 and 2 are connected to each other.
var dot1 = getdot( 1 )
disconnect( dot1, 2 )

Movements

Move

Lets you move a dot to coordinates (x, y)

move( dot: number|Dot, x: number, y: number )

// moving dot 1 to x=50, y=50
move( 1, 50, 50 )

// moving dot 5 to x=20, y=100
let a = getdot( 5 )
move( a, 20, 100 )

Clone this wiki locally