Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve #10

Merged
merged 26 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23,817 changes: 23,817 additions & 0 deletions out.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,930 changes: 2,930 additions & 0 deletions out.txt

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions solve/dot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { quote } from './util';


export class Connection {
constructor(
public from: string,
public connector: string,
public to: string,
public color?: string,
public label?: string
){}

nodeSettings(): Map<string, string> {
const { color, label } = this;
return new Map(Object.entries({
...color?{color}:{},
...label?{label}:{}
}));
}

settingsAnnotation(): string {
return `[${
[...this.nodeSettings()].map(
([key, value]) => `${quote(key)}=${quote(value)}`
).join(",")
}]`
}

toDotDigraphStatement(): string {
return `${
quote(this.from)
}${
this.connector
}${
quote(this.to)
}${this.settingsAnnotation()}`
}
}

interface DigraphStatement {
toDotDigraphStatement(): string
}

export abstract class AbstractDigraph {
constructor(public statements: DigraphStatement[]) {}

}

export class Digraph extends AbstractDigraph {
toDot() {
return `digraph{${this.statements.map(
smt => smt.toDotDigraphStatement()).join(";\n")}}`
}
}

export class Subgraph extends AbstractDigraph {
constructor(public name: string, public override statements: DigraphStatement[]) {
super(statements);
}

toDotDigraphStatement() {
return `subgraph ${quote(this.name)}{${
this.statements.map(
smt => smt.toDotDigraphStatement()).join(";\n")
})`
}
}
Loading