ts-graphviz
Advanced tools
Comparing version 1.5.6-dev.ef6c929b6 to 1.6.1-dev.9b20eb739
/// <reference types="node" /> | ||
import { Layout, Options } from '../types/index.js'; | ||
export { Format, Options } from '../types/index.js'; | ||
export { Format, Layout, Options } from '../types/index.js'; | ||
@@ -5,0 +5,0 @@ /** |
@@ -7,5 +7,15 @@ import { | ||
} from '../../common/index.js'; | ||
import { $keywords } from '../../utils/index.js'; | ||
type Format = 'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json'; | ||
type Layout = 'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork'; | ||
type Format = Format.values; | ||
declare namespace Format { | ||
type values = keyof $values; | ||
interface $values extends $keywords<'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json'> {} | ||
} | ||
type Layout = Layout.values; | ||
declare namespace Layout { | ||
type values = keyof $values; | ||
interface $values | ||
extends $keywords<'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork'> {} | ||
} | ||
/** | ||
@@ -12,0 +22,0 @@ * NeatoOptions interface provides options for the neato layout. |
@@ -0,2 +1,3 @@ | ||
export { $keywords } from './utils/index.js'; | ||
export * from './common/index.js'; | ||
export * from './core/index.js'; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* @hidden | ||
*/ | ||
type $keywords<T extends string> = { | ||
[key in T]: key; | ||
}; | ||
type F<A extends any[], O> = (...args: A) => O; | ||
@@ -22,2 +29,2 @@ type IO<I, O> = F<[I], O>; | ||
export { F, IO, filter, map, pipe }; | ||
export { $keywords, F, IO, filter, map, pipe }; |
{ | ||
"name": "ts-graphviz", | ||
"version": "1.5.6-dev.ef6c929b6", | ||
"version": "1.6.1-dev.9b20eb739", | ||
"author": "kamiazya <yuki@kamiazya.tech>", | ||
@@ -21,3 +21,3 @@ "description": "Graphviz library for TypeScript.", | ||
"type": "github", | ||
"url": "https://github.com/sponsors/kamiazya" | ||
"url": "https://github.com/sponsors/ts-graphviz" | ||
}, | ||
@@ -24,0 +24,0 @@ "main": "./lib/index.cjs", |
@@ -506,2 +506,76 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d6485f9858ed4b3e8ef76611a2896bc4)](https://app.codacy.com/gh/ts-graphviz/ts-graphviz?utm_source=github.com&utm_medium=referral&utm_content=ts-graphviz/ts-graphviz&utm_campaign=Badge_Grade_Settings) | ||
### Extending the Type System 🧰 | ||
> The status of this feature is ![beta](https://img.shields.io/badge/-beta-orange). | ||
With ts-graphviz, you can extend the library's type system to customize graph visualization solutions to meet specific needs. | ||
> **Note** To allow for customization, types are named with the `$` symbol. | ||
> | ||
> If you want to extend a type definition in cases not listed below, check the source code to see if you can extend it with `$...`. | ||
> | ||
> If not, please create an issue or pull request. | ||
#### Use Case: Specifying Custom Graph Layout and Output Formats | ||
```ts | ||
import { $keywords } from 'ts-graphviz'; | ||
import { toFile } from 'ts-graphviz/adapter'; | ||
// 1. Declare the 'ts-graphviz/adapter' module. | ||
declare module 'ts-graphviz/adapter' { | ||
export namespace Layout { | ||
// 2. Define the $values interface in the Layout namespace. | ||
// 3. Inherit from $keywords<'my-custom-algorithm'> and specify the name of the new layout engine in <...>. | ||
export interface $values extends $keywords<'my-custom-algorithm'> {} | ||
} | ||
export namespace Format { | ||
// 4. Define the $values interface in the Format namespace. | ||
// 5. Inherit from $keywords<'mp4'> and specify the name of the new output format in <...>. | ||
export interface $values extends $keywords<'mp4'> {} | ||
} | ||
} | ||
toFile('digraph { a -> b }', '/path/to/file', { | ||
layout: 'my-custom-algorithm', | ||
format: 'mp4', | ||
}); | ||
``` | ||
#### Use Case: Adding Custom Attributes | ||
```ts | ||
import { digraph, toDot, attribute as _, $keywords } from 'ts-graphviz'; | ||
// 1. Declare the 'ts-graphviz' module. | ||
declare module 'ts-graphviz' { | ||
export namespace GraphAttributeKey { | ||
// 2. Define the $values interface in the GraphAttributeKey namespace. | ||
// 3. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>. | ||
export interface $values extends $keywords<'hoge'> {} | ||
} | ||
export namespace Attribute { | ||
// 4. Define the $keys interface in the Attribute namespace. | ||
// 5. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>. | ||
export interface $keys extends $keywords<'hoge'> {} | ||
// 6. Define the $types interface in the Attribute namespace. | ||
// 7. Specify the new attribute in the key and define its corresponding value in the value. | ||
export interface $types { | ||
hoge: string; | ||
} | ||
} | ||
} | ||
console.log( | ||
toDot( | ||
digraph((g) => { | ||
g.set(_.hoge, 'fuga'); | ||
}), | ||
), | ||
); | ||
``` | ||
## Who's using `ts-graphviz` 📜 | ||
@@ -580,8 +654,12 @@ | ||
Please support core member [kamiazya](https://github.com/sponsors/kamiazya). | ||
Please support [ts-graphviz](https://github.com/sponsors/ts-graphviz). | ||
> **Note** Even just a dollar is enough motivation for me to develop 😊 | ||
Our goal for ts-graphviz is to attract 10 sponsors who can provide ongoing support to help cover development and maintenance costs, | ||
and help us continue expanding and improving the library. By achieving this goal, we can ensure that ts-graphviz remains a valuable resource | ||
for developers who need to analyze and visualize complex graph structures, while also fostering a strong and supportive community of users and sponsors. | ||
> **Note** Even just a dollar is enough motivation to develop 😊 | ||
## License ⚖️ | ||
This software is released under the MIT License, see [LICENSE](https://github.com/ts-graphviz/ts-graphviz/blob/main/LICENSE). |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
594602
19105
664