-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize types to match jsdoc, export Graph type
- Loading branch information
Showing
2 changed files
with
158 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,106 @@ | ||
import { instance } from "@viz-js/viz"; | ||
import { type Graph } from "@viz-js/viz"; | ||
|
||
instance().then(viz => { | ||
viz.render({}); | ||
let graph: Graph; | ||
|
||
viz.render({ | ||
edges: [ | ||
{ tail: "a", head: "b" } | ||
] | ||
}); | ||
graph = {}; | ||
|
||
viz.render({ | ||
directed: false, | ||
strict: false, | ||
name: "G", | ||
graphAttributes: { | ||
label: "Test" | ||
}, | ||
edgeAttributes: { | ||
color: "green" | ||
}, | ||
nodeAttributes: { | ||
shape: "circle" | ||
}, | ||
nodes: [ | ||
{ name: "a", attributes: { label: "A" } } | ||
], | ||
edges: [ | ||
{ tail: "a", head: "b", attributes: { label: "test" } } | ||
], | ||
subgraphs: [ | ||
{ | ||
name: "cluster1", | ||
graphAttributes: { | ||
color: "green" | ||
}, | ||
edgeAttributes: { | ||
color: "blue" | ||
}, | ||
nodeAttributes: { | ||
color: "red" | ||
}, | ||
subgraphs: [ | ||
{ | ||
nodes: [ | ||
{ name: "b" } | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
graph = { | ||
edges: [ | ||
{ tail: "a", head: "b" } | ||
] | ||
}; | ||
|
||
viz.render({ | ||
graphAttributes: { | ||
width: 2, | ||
abc: true, | ||
label: { html: "<b>test</b>" } | ||
}, | ||
nodes: [ | ||
{ | ||
name: "a", | ||
attributes: { | ||
width: 2, | ||
abc: true, | ||
label: { html: "<b>test</b>" } | ||
graph = { | ||
directed: false, | ||
strict: false, | ||
name: "G", | ||
graphAttributes: { | ||
label: "Test" | ||
}, | ||
edgeAttributes: { | ||
color: "green" | ||
}, | ||
nodeAttributes: { | ||
shape: "circle" | ||
}, | ||
nodes: [ | ||
{ name: "a", attributes: { label: "A" } } | ||
], | ||
edges: [ | ||
{ tail: "a", head: "b", attributes: { label: "test" } } | ||
], | ||
subgraphs: [ | ||
{ | ||
name: "cluster1", | ||
graphAttributes: { | ||
color: "green" | ||
}, | ||
edgeAttributes: { | ||
color: "blue" | ||
}, | ||
nodeAttributes: { | ||
color: "red" | ||
}, | ||
subgraphs: [ | ||
{ | ||
nodes: [ | ||
{ name: "b" } | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
|
||
graph = { | ||
graphAttributes: { | ||
width: 2, | ||
abc: true, | ||
label: { html: "<b>test</b>" } | ||
}, | ||
nodes: [ | ||
{ | ||
name: "a", | ||
attributes: { | ||
width: 2, | ||
abc: true, | ||
label: { html: "<b>test</b>" } | ||
} | ||
] | ||
}); | ||
} | ||
] | ||
}; | ||
|
||
graph = { | ||
graphAttributes: { | ||
// @ts-expect-error | ||
blah: null | ||
} | ||
}; | ||
|
||
viz.render({ | ||
graphAttributes: { | ||
graph = { | ||
graphAttributes: { | ||
// @ts-expect-error | ||
label: { stuff: "abc" } | ||
} | ||
}; | ||
|
||
graph = { | ||
subgraphs: [ | ||
{ | ||
// @ts-expect-error | ||
blah: null | ||
directed: false | ||
} | ||
}); | ||
] | ||
}; | ||
|
||
viz.render({ | ||
graphAttributes: { | ||
graph = { | ||
subgraphs: [ | ||
{ | ||
// @ts-expect-error | ||
label: { stuff: "abc" } | ||
strict: true | ||
} | ||
}); | ||
|
||
viz.render({ | ||
subgraphs: [ | ||
{ | ||
// @ts-expect-error | ||
directed: false | ||
} | ||
] | ||
}); | ||
|
||
viz.render({ | ||
subgraphs: [ | ||
{ | ||
// @ts-expect-error | ||
strict: true | ||
} | ||
] | ||
}); | ||
] | ||
}; | ||
|
||
// @ts-expect-error | ||
viz.render({ a: "b" }); | ||
}); | ||
// @ts-expect-error | ||
graph = { a: "b" }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,97 @@ | ||
type HTMLString = { html: string }; | ||
export function instance(): Promise<Viz>; | ||
|
||
type AttributeValue = string | number | boolean | HTMLString; | ||
export const graphvizVersion: string; | ||
|
||
type Attributes = { [key: string]: AttributeValue }; | ||
export const formats: string[]; | ||
|
||
type Node = { | ||
name: string, | ||
attributes?: Attributes | ||
export const engines: string[]; | ||
|
||
export {}; | ||
|
||
export type Graph = { | ||
name?: string; | ||
strict?: boolean; | ||
directed?: boolean; | ||
graphAttributes?: Attributes; | ||
nodeAttributes?: Attributes; | ||
edgeAttributes?: Attributes; | ||
nodes?: Node[]; | ||
edges?: Edge[]; | ||
subgraphs?: Subgraph[]; | ||
}; | ||
|
||
type Edge = { | ||
tail: string, | ||
head: string, | ||
attributes?: Attributes | ||
type Attributes = { | ||
[name: string]: AttributeValue; | ||
}; | ||
|
||
type Graph = { | ||
name?: string, | ||
graphAttributes?: Attributes, | ||
nodeAttributes?: Attributes, | ||
edgeAttributes?: Attributes, | ||
nodes?: Node[], | ||
edges?: Edge[], | ||
subgraphs?: Graph[] | ||
type AttributeValue = string | number | boolean | HTMLString; | ||
|
||
type HTMLString = { | ||
html: string; | ||
}; | ||
|
||
type Header = { | ||
strict?: boolean, | ||
directed?: boolean | ||
type Node = { | ||
name: string; | ||
attributes?: Attributes; | ||
}; | ||
|
||
export type RenderInputObject = Header & Graph; | ||
type Edge = { | ||
tail: string; | ||
head: string; | ||
attributes?: Attributes; | ||
}; | ||
|
||
type RenderInput = string | RenderInputObject; | ||
type Subgraph = { | ||
name?: string; | ||
graphAttributes?: Attributes; | ||
nodeAttributes?: Attributes; | ||
edgeAttributes?: Attributes; | ||
nodes?: Node[]; | ||
edges?: Edge[]; | ||
subgraphs?: Subgraph[]; | ||
}; | ||
|
||
export type RenderOptions = { | ||
format?: string; | ||
engine?: string; | ||
yInvert?: boolean; | ||
reduce?: boolean; | ||
graphAttributes?: Attributes; | ||
nodeAttributes?: Attributes; | ||
edgeAttributes?: Attributes; | ||
format?: string; | ||
engine?: string; | ||
yInvert?: boolean; | ||
reduce?: boolean; | ||
graphAttributes?: Attributes; | ||
nodeAttributes?: Attributes; | ||
edgeAttributes?: Attributes; | ||
}; | ||
|
||
export type RenderError = { | ||
level?: "error" | "warning"; | ||
message: string; | ||
}; | ||
export type RenderResult = SuccessResult | FailureResult; | ||
|
||
type SuccessResult = { | ||
status: "success"; | ||
output: string; | ||
errors: RenderError[]; | ||
status: "success"; | ||
output: string; | ||
errors: RenderError[]; | ||
}; | ||
|
||
type FailureResult = { | ||
status: "failure"; | ||
output: undefined; | ||
errors: RenderError[]; | ||
status: "failure"; | ||
output: undefined; | ||
errors: RenderError[]; | ||
}; | ||
|
||
export type RenderResult = SuccessResult | FailureResult; | ||
export type RenderError = { | ||
level?: "error" | "warning"; | ||
message: string; | ||
}; | ||
|
||
declare class Viz { | ||
get graphvizVersion(): string; | ||
|
||
get formats(): string[]; | ||
|
||
get engines(): string[]; | ||
|
||
render(input: RenderInput, options?: RenderOptions): RenderResult; | ||
renderString(input: RenderInput, options?: RenderOptions): string; | ||
renderSVGElement(input: RenderInput, options?: RenderOptions): SVGSVGElement; | ||
renderJSON(input: RenderInput, options?: RenderOptions): object; | ||
} | ||
export {}; | ||
render(input: string | Graph, options?: RenderOptions): RenderResult; | ||
|
||
export function instance(): Promise<Viz>; | ||
renderString(src: any, options?: RenderOptions): string; | ||
|
||
export const graphvizVersion: string; | ||
renderSVGElement(src: any, options?: RenderOptions): SVGSVGElement; | ||
|
||
export const formats: string[]; | ||
|
||
export const engines: string[]; | ||
renderJSON(src: any, options?: RenderOptions): object; | ||
} |