-
Notifications
You must be signed in to change notification settings - Fork 5
API
Graph provides a real-time interactive notebook as well as a plugin system which you can use to program and automate graphs, create special renderings, do scientific analysis or as a hobby to explore the world of graphs (have fun 😁). Because Graph is based on JavaScript, you can use all the power of JavaScript to write plugins or commands in the notebook.
The API introduced in this article is based on an abstraction layer which normalizes the underlying core to be a natural high level abstraction. All the core tools offered by Graph are available under the KaryGraph
namespace. Using the core system commands is harmful and may cause damage 😱. However, due to the implementation design they are inevitable. Unless you're contributing to the core, we ask you not to use anything within that namespace. The available API is simple, very dynamic and safe in error handling as well as very optimized. By not using the API, you will end up having a same functioning API with different design and functions which causes compatibility issues across the community. In short, simply do not use any of the KaryGraph
namespace tools in your plugins and notebooks.
Removes all dots and resets the environment
reset( ): void
Cleans the notebook screen
cls( ): void
Prints whatever you want on the notebook screen
say( input: any ): void
Creates a dot and places it at a random position
newdot( ): Dot
// stores the randomly generated dot
var dot = newdot( )
Generates a given number of dots
newdots( howManyDots: number ): Array<Dots>
// create an array of 5 new dots just added to the screen
let dots = newdots( 5 )
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 )
Returns a dot based on its number id
getdot( id: number ): Dot
// gets the object of the dot with id 5
let dot = getdot( 5 )
Returns an array of dots based on an array of ids
getdots( ...ids: Array<number> ): Array<Dot>
var a: Array<Dot> = getdots( 2, 5, 7 )
Returns the number of dots
countdots( ): number
Connects an array of dots in order
connect( Array<Dot|number> )
// this connects 1 to 2 and 2 to 3
let dot3 = getdot( 3 )
connect([ 1, 2, dot3 ])
Connects an array of dots like a fan
fan( Array<Dot|number> )
// this connects 1 to 2, 3 and 4
let dot3 = getdot( 3 )
fan([ 1, 2, dot3, 4 ])
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 )
Checks if two dots are connected to each other
hasEdge( dot1: number|Dot, dot2: number|Dot ): boolean
// returns true
newdots ( 2 )
connect ( 1, 2 )
var dot1 = getdot( 1 )
hasEdge ( dot1, 2 )
Moves a dot to coordinates (x, y)
move( dot: number|Dot, x: number, y: number )
// move dot 1 to x=50, y=50
move( 1, 50, 50 )
// move dot 5 to x=20, y=100
let a = getdot( 5 )
move( a, 20, 100 )
Moves a dot to the given x coordinate
movex( dot: number|Dot, x: number )
Moves a dot to the given y coordinate
movey( dot: number|Dot, y: number )
Moves a dot by the given x coordinate
movebx( dot: number|Dot, x: number )
Moves a dot by the given y coordinate
moveby( dot: number|Dot, y: number )
Returns the adjacency matrix of the graph
matrix( ): number[][]
Creates the graph represented by an adjacency matrix
graphfrommatrix( matrix: number[][] )
Returns the order of the graph
order( ): number
Returns the size of the graph
size( ): number
Returns the degree of a vertex
degree( vertex: number|Dot ): number
Checks if two dots are neighbors
neighbors( dot1: number|Dot, dot2: number|Dot ): boolean
Returns the neighborhood of a dot
neighborhood( dot: number|Dot ): Array<Dot>
Checks if graph is an Eulerian Path
eulerianpath( ): boolean
Checks if graph is an Eulerian Cycle
euleriancycle( ): boolean
Rearranges the (tree-based) graph to a tree
sort( )